blob: 1c0c23d87d6526642ff1a1a7fad2dc007c59b1bd [file] [log] [blame]
Harald Weltedaa1ef32005-07-19 21:44:58 +00001/* Shared library add-on to iptables for NFQ
2 *
3 * (C) 2005 by Harald Welte <laforge@netfilter.org>
4 *
5 * This program is distributed under the terms of GNU GPL v2, 1991
6 *
7 */
8#include <stdio.h>
9#include <string.h>
10#include <stdlib.h>
11#include <getopt.h>
12
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000013#include <xtables.h>
14#include <linux/netfilter/x_tables.h>
15#include <linux/netfilter/xt_NFQUEUE.h>
Harald Weltedaa1ef32005-07-19 21:44:58 +000016
Jan Engelhardt932e6482007-10-04 16:27:30 +000017static void NFQUEUE_help(void)
Harald Weltedaa1ef32005-07-19 21:44:58 +000018{
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"
23);
24}
25
Jan Engelhardt932e6482007-10-04 16:27:30 +000026static const struct option NFQUEUE_opts[] = {
Patrick McHardy500f4832007-09-08 15:59:04 +000027 { "queue-num", 1, NULL, 'F' },
Max Kellermann9ee386a2008-01-29 13:48:05 +000028 { .name = NULL }
Harald Weltedaa1ef32005-07-19 21:44:58 +000029};
30
31static void
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000032parse_num(const char *s, struct xt_NFQ_info *tinfo)
Harald Weltedaa1ef32005-07-19 21:44:58 +000033{
34 unsigned int num;
35
Jan Engelhardt5f2922c2009-01-27 18:43:01 +010036 if (!xtables_strtoui(s, NULL, &num, 0, UINT16_MAX))
Harald Weltedaa1ef32005-07-19 21:44:58 +000037 exit_error(PARAMETER_PROBLEM,
38 "Invalid queue number `%s'\n", s);
39
40 tinfo->queuenum = num & 0xffff;
Harald Weltedaa1ef32005-07-19 21:44:58 +000041}
42
43static int
Jan Engelhardt932e6482007-10-04 16:27:30 +000044NFQUEUE_parse(int c, char **argv, int invert, unsigned int *flags,
45 const void *entry, struct xt_entry_target **target)
Harald Weltedaa1ef32005-07-19 21:44:58 +000046{
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000047 struct xt_NFQ_info *tinfo
48 = (struct xt_NFQ_info *)(*target)->data;
Harald Weltedaa1ef32005-07-19 21:44:58 +000049
50 switch (c) {
51 case 'F':
52 if (*flags)
53 exit_error(PARAMETER_PROBLEM, "NFQUEUE target: "
54 "Only use --queue-num ONCE!");
55 parse_num(optarg, tinfo);
Eric Leblond6fdefcf2005-08-05 18:35:09 +000056 break;
Harald Weltedaa1ef32005-07-19 21:44:58 +000057 default:
58 return 0;
59 }
60
61 return 1;
62}
63
Jan Engelhardt932e6482007-10-04 16:27:30 +000064static void NFQUEUE_print(const void *ip,
65 const struct xt_entry_target *target, int numeric)
Harald Weltedaa1ef32005-07-19 21:44:58 +000066{
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000067 const struct xt_NFQ_info *tinfo =
68 (const struct xt_NFQ_info *)target->data;
Harald Weltedaa1ef32005-07-19 21:44:58 +000069 printf("NFQUEUE num %u", tinfo->queuenum);
70}
71
Jan Engelhardt932e6482007-10-04 16:27:30 +000072static void NFQUEUE_save(const void *ip, const struct xt_entry_target *target)
Harald Weltedaa1ef32005-07-19 21:44:58 +000073{
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000074 const struct xt_NFQ_info *tinfo =
75 (const struct xt_NFQ_info *)target->data;
Harald Weltedaa1ef32005-07-19 21:44:58 +000076
77 printf("--queue-num %u ", tinfo->queuenum);
78}
79
Jan Engelhardt932e6482007-10-04 16:27:30 +000080static struct xtables_target nfqueue_target = {
Jan Engelhardt03d99482008-11-18 12:27:54 +010081 .family = NFPROTO_IPV4,
Harald Weltedaa1ef32005-07-19 21:44:58 +000082 .name = "NFQUEUE",
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020083 .version = XTABLES_VERSION,
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000084 .size = XT_ALIGN(sizeof(struct xt_NFQ_info)),
85 .userspacesize = XT_ALIGN(sizeof(struct xt_NFQ_info)),
Jan Engelhardt932e6482007-10-04 16:27:30 +000086 .help = NFQUEUE_help,
87 .parse = NFQUEUE_parse,
88 .print = NFQUEUE_print,
89 .save = NFQUEUE_save,
90 .extra_opts = NFQUEUE_opts
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000091};
92
Jan Engelhardt932e6482007-10-04 16:27:30 +000093static struct xtables_target nfqueue_target6 = {
Jan Engelhardt03d99482008-11-18 12:27:54 +010094 .family = NFPROTO_IPV6,
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000095 .name = "NFQUEUE",
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020096 .version = XTABLES_VERSION,
Yasuyuki KOZAKAIa2e89cc2007-07-24 07:29:36 +000097 .size = XT_ALIGN(sizeof(struct xt_NFQ_info)),
98 .userspacesize = XT_ALIGN(sizeof(struct xt_NFQ_info)),
Jan Engelhardt932e6482007-10-04 16:27:30 +000099 .help = NFQUEUE_help,
100 .parse = NFQUEUE_parse,
101 .print = NFQUEUE_print,
102 .save = NFQUEUE_save,
103 .extra_opts = NFQUEUE_opts,
Harald Weltedaa1ef32005-07-19 21:44:58 +0000104};
105
106void _init(void)
107{
Jan Engelhardt932e6482007-10-04 16:27:30 +0000108 xtables_register_target(&nfqueue_target);
109 xtables_register_target(&nfqueue_target6);
Harald Weltedaa1ef32005-07-19 21:44:58 +0000110}