]>
Commit | Line | Data |
---|---|---|
2e4e6a17 HW |
1 | /* iptables module for using new netfilter netlink queue |
2 | * | |
3 | * (C) 2005 by Harald Welte <[email protected]> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
601e68e1 | 6 | * it under the terms of the GNU General Public License version 2 as |
2e4e6a17 | 7 | * published by the Free Software Foundation. |
601e68e1 | 8 | * |
2e4e6a17 HW |
9 | */ |
10 | ||
11 | #include <linux/module.h> | |
12 | #include <linux/skbuff.h> | |
13 | ||
14 | #include <linux/netfilter.h> | |
15 | #include <linux/netfilter_arp.h> | |
16 | #include <linux/netfilter/x_tables.h> | |
17 | #include <linux/netfilter/xt_NFQUEUE.h> | |
18 | ||
97a2d41c EL |
19 | #include <net/netfilter/nf_queue.h> |
20 | ||
2e4e6a17 | 21 | MODULE_AUTHOR("Harald Welte <[email protected]>"); |
2ae15b64 | 22 | MODULE_DESCRIPTION("Xtables: packet forwarding to netlink"); |
2e4e6a17 HW |
23 | MODULE_LICENSE("GPL"); |
24 | MODULE_ALIAS("ipt_NFQUEUE"); | |
25 | MODULE_ALIAS("ip6t_NFQUEUE"); | |
26 | MODULE_ALIAS("arpt_NFQUEUE"); | |
27 | ||
10662aa3 FW |
28 | static u32 jhash_initval __read_mostly; |
29 | ||
2e4e6a17 | 30 | static unsigned int |
4b560b44 | 31 | nfqueue_tg(struct sk_buff *skb, const struct xt_action_param *par) |
2e4e6a17 | 32 | { |
7eb35586 | 33 | const struct xt_NFQ_info *tinfo = par->targinfo; |
2e4e6a17 HW |
34 | |
35 | return NF_QUEUE_NR(tinfo->queuenum); | |
36 | } | |
37 | ||
5c33448c | 38 | static unsigned int |
39 | nfqueue_tg_v1(struct sk_buff *skb, const struct xt_action_param *par) | |
40 | { | |
41 | const struct xt_NFQ_info_v1 *info = par->targinfo; | |
42 | u32 queue = info->queuenum; | |
43 | ||
97a2d41c EL |
44 | if (info->queues_total > 1) { |
45 | queue = nfqueue_hash(skb, queue, info->queues_total, | |
46 | par->family, jhash_initval); | |
47 | } | |
10662aa3 FW |
48 | return NF_QUEUE_NR(queue); |
49 | } | |
10662aa3 | 50 | |
94b27cc3 FW |
51 | static unsigned int |
52 | nfqueue_tg_v2(struct sk_buff *skb, const struct xt_action_param *par) | |
10662aa3 | 53 | { |
94b27cc3 FW |
54 | const struct xt_NFQ_info_v2 *info = par->targinfo; |
55 | unsigned int ret = nfqueue_tg_v1(skb, par); | |
56 | ||
57 | if (info->bypass) | |
58 | ret |= NF_VERDICT_FLAG_QUEUE_BYPASS; | |
59 | return ret; | |
60 | } | |
61 | ||
62 | static int nfqueue_tg_check(const struct xt_tgchk_param *par) | |
63 | { | |
8746ddcf | 64 | const struct xt_NFQ_info_v3 *info = par->targinfo; |
10662aa3 FW |
65 | u32 maxid; |
66 | ||
97a2d41c EL |
67 | init_hashrandom(&jhash_initval); |
68 | ||
10662aa3 FW |
69 | if (info->queues_total == 0) { |
70 | pr_err("NFQUEUE: number of total queues is 0\n"); | |
d6b00a53 | 71 | return -EINVAL; |
10662aa3 FW |
72 | } |
73 | maxid = info->queues_total - 1 + info->queuenum; | |
74 | if (maxid > 0xffff) { | |
75 | pr_err("NFQUEUE: number of queues (%u) out of range (got %u)\n", | |
76 | info->queues_total, maxid); | |
4a5a5c73 | 77 | return -ERANGE; |
10662aa3 | 78 | } |
8746ddcf | 79 | if (par->target->revision == 2 && info->flags > 1) |
80 | return -EINVAL; | |
81 | if (par->target->revision == 3 && info->flags & ~NFQ_FLAG_MASK) | |
94b27cc3 | 82 | return -EINVAL; |
8746ddcf | 83 | |
d6b00a53 | 84 | return 0; |
10662aa3 FW |
85 | } |
86 | ||
8746ddcf | 87 | static unsigned int |
88 | nfqueue_tg_v3(struct sk_buff *skb, const struct xt_action_param *par) | |
89 | { | |
90 | const struct xt_NFQ_info_v3 *info = par->targinfo; | |
91 | u32 queue = info->queuenum; | |
d9547773 | 92 | int ret; |
8746ddcf | 93 | |
94 | if (info->queues_total > 1) { | |
95 | if (info->flags & NFQ_FLAG_CPU_FANOUT) { | |
96 | int cpu = smp_processor_id(); | |
97 | ||
98 | queue = info->queuenum + cpu % info->queues_total; | |
97a2d41c EL |
99 | } else { |
100 | queue = nfqueue_hash(skb, queue, info->queues_total, | |
101 | par->family, jhash_initval); | |
102 | } | |
8746ddcf | 103 | } |
5c33448c | 104 | |
d9547773 HE |
105 | ret = NF_QUEUE_NR(queue); |
106 | if (info->flags & NFQ_FLAG_BYPASS) | |
107 | ret |= NF_VERDICT_FLAG_QUEUE_BYPASS; | |
108 | ||
109 | return ret; | |
8746ddcf | 110 | } |
111 | ||
d3c5ee6d | 112 | static struct xt_target nfqueue_tg_reg[] __read_mostly = { |
4470bbc7 PM |
113 | { |
114 | .name = "NFQUEUE", | |
61f5abca | 115 | .family = NFPROTO_UNSPEC, |
d3c5ee6d | 116 | .target = nfqueue_tg, |
4470bbc7 PM |
117 | .targetsize = sizeof(struct xt_NFQ_info), |
118 | .me = THIS_MODULE, | |
119 | }, | |
10662aa3 FW |
120 | { |
121 | .name = "NFQUEUE", | |
122 | .revision = 1, | |
f76a47c8 | 123 | .family = NFPROTO_UNSPEC, |
94b27cc3 | 124 | .checkentry = nfqueue_tg_check, |
f76a47c8 | 125 | .target = nfqueue_tg_v1, |
10662aa3 FW |
126 | .targetsize = sizeof(struct xt_NFQ_info_v1), |
127 | .me = THIS_MODULE, | |
128 | }, | |
94b27cc3 FW |
129 | { |
130 | .name = "NFQUEUE", | |
131 | .revision = 2, | |
132 | .family = NFPROTO_UNSPEC, | |
133 | .checkentry = nfqueue_tg_check, | |
134 | .target = nfqueue_tg_v2, | |
135 | .targetsize = sizeof(struct xt_NFQ_info_v2), | |
136 | .me = THIS_MODULE, | |
137 | }, | |
8746ddcf | 138 | { |
139 | .name = "NFQUEUE", | |
140 | .revision = 3, | |
141 | .family = NFPROTO_UNSPEC, | |
142 | .checkentry = nfqueue_tg_check, | |
143 | .target = nfqueue_tg_v3, | |
144 | .targetsize = sizeof(struct xt_NFQ_info_v3), | |
145 | .me = THIS_MODULE, | |
146 | }, | |
2e4e6a17 HW |
147 | }; |
148 | ||
d3c5ee6d | 149 | static int __init nfqueue_tg_init(void) |
2e4e6a17 | 150 | { |
d3c5ee6d | 151 | return xt_register_targets(nfqueue_tg_reg, ARRAY_SIZE(nfqueue_tg_reg)); |
2e4e6a17 HW |
152 | } |
153 | ||
d3c5ee6d | 154 | static void __exit nfqueue_tg_exit(void) |
2e4e6a17 | 155 | { |
d3c5ee6d | 156 | xt_unregister_targets(nfqueue_tg_reg, ARRAY_SIZE(nfqueue_tg_reg)); |
2e4e6a17 HW |
157 | } |
158 | ||
d3c5ee6d JE |
159 | module_init(nfqueue_tg_init); |
160 | module_exit(nfqueue_tg_exit); |