manpages: do not include v4-only modules in ip6tables manpage
[jleu-iptables.git] / extensions / libxt_NFQUEUE.c
blob3ca2239fb1f3fc269344a07275150cdd4db43335
1 /* Shared library add-on to iptables for NFQ
3 * (C) 2005 by Harald Welte <laforge@netfilter.org>
5 * This program is distributed under the terms of GNU GPL v2, 1991
7 */
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <getopt.h>
13 #include <xtables.h>
14 #include <linux/netfilter/x_tables.h>
15 #include <linux/netfilter/xt_NFQUEUE.h>
17 static void NFQUEUE_help(void)
19 printf(
20 "NFQUEUE target options\n"
21 " --queue-num value Send packet to QUEUE number <value>.\n"
22 " Valid queue numbers are 0-65535\n"
26 static const struct option NFQUEUE_opts[] = {
27 { "queue-num", 1, NULL, 'F' },
28 { .name = NULL }
31 static void
32 parse_num(const char *s, struct xt_NFQ_info *tinfo)
34 unsigned int num;
36 if (!xtables_strtoui(s, NULL, &num, 0, UINT16_MAX))
37 xtables_error(PARAMETER_PROBLEM,
38 "Invalid queue number `%s'\n", s);
40 tinfo->queuenum = num & 0xffff;
43 static int
44 NFQUEUE_parse(int c, char **argv, int invert, unsigned int *flags,
45 const void *entry, struct xt_entry_target **target)
47 struct xt_NFQ_info *tinfo
48 = (struct xt_NFQ_info *)(*target)->data;
50 switch (c) {
51 case 'F':
52 if (*flags)
53 xtables_error(PARAMETER_PROBLEM, "NFQUEUE target: "
54 "Only use --queue-num ONCE!");
55 parse_num(optarg, tinfo);
56 break;
57 default:
58 return 0;
61 return 1;
64 static void NFQUEUE_print(const void *ip,
65 const struct xt_entry_target *target, int numeric)
67 const struct xt_NFQ_info *tinfo =
68 (const struct xt_NFQ_info *)target->data;
69 printf("NFQUEUE num %u", tinfo->queuenum);
72 static void NFQUEUE_save(const void *ip, const struct xt_entry_target *target)
74 const struct xt_NFQ_info *tinfo =
75 (const struct xt_NFQ_info *)target->data;
77 printf("--queue-num %u ", tinfo->queuenum);
80 static struct xtables_target nfqueue_target = {
81 .family = NFPROTO_IPV4,
82 .name = "NFQUEUE",
83 .version = XTABLES_VERSION,
84 .size = XT_ALIGN(sizeof(struct xt_NFQ_info)),
85 .userspacesize = XT_ALIGN(sizeof(struct xt_NFQ_info)),
86 .help = NFQUEUE_help,
87 .parse = NFQUEUE_parse,
88 .print = NFQUEUE_print,
89 .save = NFQUEUE_save,
90 .extra_opts = NFQUEUE_opts
93 static struct xtables_target nfqueue_target6 = {
94 .family = NFPROTO_IPV6,
95 .name = "NFQUEUE",
96 .version = XTABLES_VERSION,
97 .size = XT_ALIGN(sizeof(struct xt_NFQ_info)),
98 .userspacesize = XT_ALIGN(sizeof(struct xt_NFQ_info)),
99 .help = NFQUEUE_help,
100 .parse = NFQUEUE_parse,
101 .print = NFQUEUE_print,
102 .save = NFQUEUE_save,
103 .extra_opts = NFQUEUE_opts,
106 void _init(void)
108 xtables_register_target(&nfqueue_target);
109 xtables_register_target(&nfqueue_target6);