]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Handle firewalling | |
3 | * Linux ethernet bridge | |
4 | * | |
5 | * Authors: | |
8237908e BDS |
6 | * Lennert Buytenhek <buytenh@gnu.org> |
7 | * Bart De Schuymer <bdschuym@pandora.be> | |
1da177e4 LT |
8 | * |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; either version | |
12 | * 2 of the License, or (at your option) any later version. | |
13 | * | |
14 | * Lennert dedicates this file to Kerstin Wurdinger. | |
15 | */ | |
16 | ||
17 | #include <linux/module.h> | |
18 | #include <linux/kernel.h> | |
5a0e3ad6 | 19 | #include <linux/slab.h> |
1da177e4 LT |
20 | #include <linux/ip.h> |
21 | #include <linux/netdevice.h> | |
22 | #include <linux/skbuff.h> | |
14c85021 | 23 | #include <linux/if_arp.h> |
1da177e4 LT |
24 | #include <linux/if_ether.h> |
25 | #include <linux/if_vlan.h> | |
516299d2 MM |
26 | #include <linux/if_pppox.h> |
27 | #include <linux/ppp_defs.h> | |
1da177e4 LT |
28 | #include <linux/netfilter_bridge.h> |
29 | #include <linux/netfilter_ipv4.h> | |
30 | #include <linux/netfilter_ipv6.h> | |
31 | #include <linux/netfilter_arp.h> | |
32 | #include <linux/in_route.h> | |
f216f082 | 33 | #include <linux/inetdevice.h> |
14c85021 | 34 | |
1da177e4 LT |
35 | #include <net/ip.h> |
36 | #include <net/ipv6.h> | |
14c85021 ACM |
37 | #include <net/route.h> |
38 | ||
1da177e4 | 39 | #include <asm/uaccess.h> |
1da177e4 LT |
40 | #include "br_private.h" |
41 | #ifdef CONFIG_SYSCTL | |
42 | #include <linux/sysctl.h> | |
43 | #endif | |
44 | ||
45 | #define skb_origaddr(skb) (((struct bridge_skb_cb *) \ | |
46 | (skb->nf_bridge->data))->daddr.ipv4) | |
eddc9ec5 ACM |
47 | #define store_orig_dstaddr(skb) (skb_origaddr(skb) = ip_hdr(skb)->daddr) |
48 | #define dnat_took_place(skb) (skb_origaddr(skb) != ip_hdr(skb)->daddr) | |
1da177e4 | 49 | |
1da177e4 LT |
50 | #ifdef CONFIG_SYSCTL |
51 | static struct ctl_table_header *brnf_sysctl_header; | |
9c1ea148 BH |
52 | static int brnf_call_iptables __read_mostly = 1; |
53 | static int brnf_call_ip6tables __read_mostly = 1; | |
54 | static int brnf_call_arptables __read_mostly = 1; | |
47e0e1ca HX |
55 | static int brnf_filter_vlan_tagged __read_mostly = 0; |
56 | static int brnf_filter_pppoe_tagged __read_mostly = 0; | |
1da177e4 | 57 | #else |
47e0e1ca HX |
58 | #define brnf_filter_vlan_tagged 0 |
59 | #define brnf_filter_pppoe_tagged 0 | |
1da177e4 LT |
60 | #endif |
61 | ||
b6f99a21 | 62 | static inline __be16 vlan_proto(const struct sk_buff *skb) |
8b42ec39 SH |
63 | { |
64 | return vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; | |
65 | } | |
66 | ||
67 | #define IS_VLAN_IP(skb) \ | |
68 | (skb->protocol == htons(ETH_P_8021Q) && \ | |
9d6f229f | 69 | vlan_proto(skb) == htons(ETH_P_IP) && \ |
8b42ec39 SH |
70 | brnf_filter_vlan_tagged) |
71 | ||
72 | #define IS_VLAN_IPV6(skb) \ | |
73 | (skb->protocol == htons(ETH_P_8021Q) && \ | |
74 | vlan_proto(skb) == htons(ETH_P_IPV6) &&\ | |
75 | brnf_filter_vlan_tagged) | |
76 | ||
77 | #define IS_VLAN_ARP(skb) \ | |
78 | (skb->protocol == htons(ETH_P_8021Q) && \ | |
79 | vlan_proto(skb) == htons(ETH_P_ARP) && \ | |
80 | brnf_filter_vlan_tagged) | |
1da177e4 | 81 | |
516299d2 MM |
82 | static inline __be16 pppoe_proto(const struct sk_buff *skb) |
83 | { | |
84 | return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN + | |
85 | sizeof(struct pppoe_hdr))); | |
86 | } | |
87 | ||
88 | #define IS_PPPOE_IP(skb) \ | |
89 | (skb->protocol == htons(ETH_P_PPP_SES) && \ | |
90 | pppoe_proto(skb) == htons(PPP_IP) && \ | |
91 | brnf_filter_pppoe_tagged) | |
92 | ||
93 | #define IS_PPPOE_IPV6(skb) \ | |
94 | (skb->protocol == htons(ETH_P_PPP_SES) && \ | |
95 | pppoe_proto(skb) == htons(PPP_IPV6) && \ | |
96 | brnf_filter_pppoe_tagged) | |
97 | ||
631339f1 HX |
98 | static void fake_update_pmtu(struct dst_entry *dst, u32 mtu) |
99 | { | |
100 | } | |
101 | ||
102 | static struct dst_ops fake_dst_ops = { | |
103 | .family = AF_INET, | |
09640e63 | 104 | .protocol = cpu_to_be16(ETH_P_IP), |
631339f1 | 105 | .update_pmtu = fake_update_pmtu, |
631339f1 HX |
106 | .entries = ATOMIC_INIT(0), |
107 | }; | |
108 | ||
4adf0af6 SW |
109 | /* |
110 | * Initialize bogus route table used to keep netfilter happy. | |
1da177e4 LT |
111 | * Currently, we fill in the PMTU entry because netfilter |
112 | * refragmentation needs it, and the rt_flags entry because | |
113 | * ipt_REJECT needs it. Future netfilter modules might | |
4adf0af6 SW |
114 | * require us to fill additional fields. |
115 | */ | |
116 | void br_netfilter_rtable_init(struct net_bridge *br) | |
117 | { | |
118 | struct rtable *rt = &br->fake_rtable; | |
119 | ||
d8d1f30b CG |
120 | atomic_set(&rt->dst.__refcnt, 1); |
121 | rt->dst.dev = br->dev; | |
122 | rt->dst.path = &rt->dst; | |
123 | rt->dst.metrics[RTAX_MTU - 1] = 1500; | |
124 | rt->dst.flags = DST_NOXFRM; | |
125 | rt->dst.ops = &fake_dst_ops; | |
4adf0af6 SW |
126 | } |
127 | ||
128 | static inline struct rtable *bridge_parent_rtable(const struct net_device *dev) | |
129 | { | |
f350a0a8 JP |
130 | if (!br_port_exists(dev)) |
131 | return NULL; | |
132 | return &br_port_get_rcu(dev)->br->fake_rtable; | |
4adf0af6 | 133 | } |
1da177e4 | 134 | |
5dce971a SH |
135 | static inline struct net_device *bridge_parent(const struct net_device *dev) |
136 | { | |
f350a0a8 JP |
137 | if (!br_port_exists(dev)) |
138 | return NULL; | |
5dce971a | 139 | |
f350a0a8 | 140 | return br_port_get_rcu(dev)->br->dev; |
5dce971a | 141 | } |
1da177e4 | 142 | |
fdeabdef SH |
143 | static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb) |
144 | { | |
145 | skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC); | |
146 | if (likely(skb->nf_bridge)) | |
147 | atomic_set(&(skb->nf_bridge->use), 1); | |
148 | ||
149 | return skb->nf_bridge; | |
150 | } | |
151 | ||
2dc2f207 PM |
152 | static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb) |
153 | { | |
154 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; | |
155 | ||
156 | if (atomic_read(&nf_bridge->use) > 1) { | |
157 | struct nf_bridge_info *tmp = nf_bridge_alloc(skb); | |
158 | ||
159 | if (tmp) { | |
160 | memcpy(tmp, nf_bridge, sizeof(struct nf_bridge_info)); | |
161 | atomic_set(&tmp->use, 1); | |
162 | nf_bridge_put(nf_bridge); | |
163 | } | |
164 | nf_bridge = tmp; | |
165 | } | |
166 | return nf_bridge; | |
167 | } | |
168 | ||
fc38582d PM |
169 | static inline void nf_bridge_push_encap_header(struct sk_buff *skb) |
170 | { | |
171 | unsigned int len = nf_bridge_encap_header_len(skb); | |
172 | ||
173 | skb_push(skb, len); | |
174 | skb->network_header -= len; | |
175 | } | |
176 | ||
177 | static inline void nf_bridge_pull_encap_header(struct sk_buff *skb) | |
fdeabdef | 178 | { |
fc38582d PM |
179 | unsigned int len = nf_bridge_encap_header_len(skb); |
180 | ||
181 | skb_pull(skb, len); | |
182 | skb->network_header += len; | |
183 | } | |
fdeabdef | 184 | |
fc38582d PM |
185 | static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb) |
186 | { | |
187 | unsigned int len = nf_bridge_encap_header_len(skb); | |
188 | ||
189 | skb_pull_rcsum(skb, len); | |
190 | skb->network_header += len; | |
191 | } | |
192 | ||
193 | static inline void nf_bridge_save_header(struct sk_buff *skb) | |
194 | { | |
195 | int header_size = ETH_HLEN + nf_bridge_encap_header_len(skb); | |
fdeabdef | 196 | |
d626f62b ACM |
197 | skb_copy_from_linear_data_offset(skb, -header_size, |
198 | skb->nf_bridge->data, header_size); | |
fdeabdef SH |
199 | } |
200 | ||
e179e632 BDS |
201 | static inline void nf_bridge_update_protocol(struct sk_buff *skb) |
202 | { | |
203 | if (skb->nf_bridge->mask & BRNF_8021Q) | |
204 | skb->protocol = htons(ETH_P_8021Q); | |
205 | else if (skb->nf_bridge->mask & BRNF_PPPoE) | |
206 | skb->protocol = htons(ETH_P_PPP_SES); | |
207 | } | |
208 | ||
209 | /* Fill in the header for fragmented IP packets handled by | |
210 | * the IPv4 connection tracking code. | |
07317621 SH |
211 | */ |
212 | int nf_bridge_copy_header(struct sk_buff *skb) | |
213 | { | |
214 | int err; | |
e179e632 | 215 | unsigned int header_size; |
07317621 | 216 | |
e179e632 BDS |
217 | nf_bridge_update_protocol(skb); |
218 | header_size = ETH_HLEN + nf_bridge_encap_header_len(skb); | |
d9cc2048 | 219 | err = skb_cow_head(skb, header_size); |
07317621 SH |
220 | if (err) |
221 | return err; | |
222 | ||
27d7ff46 ACM |
223 | skb_copy_to_linear_data_offset(skb, -header_size, |
224 | skb->nf_bridge->data, header_size); | |
fc38582d | 225 | __skb_push(skb, nf_bridge_encap_header_len(skb)); |
07317621 SH |
226 | return 0; |
227 | } | |
228 | ||
1da177e4 LT |
229 | /* PF_BRIDGE/PRE_ROUTING *********************************************/ |
230 | /* Undo the changes made for ip6tables PREROUTING and continue the | |
231 | * bridge PRE_ROUTING hook. */ | |
232 | static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb) | |
233 | { | |
234 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; | |
511c3f92 | 235 | struct rtable *rt; |
1da177e4 | 236 | |
1da177e4 LT |
237 | if (nf_bridge->mask & BRNF_PKT_TYPE) { |
238 | skb->pkt_type = PACKET_OTHERHOST; | |
239 | nf_bridge->mask ^= BRNF_PKT_TYPE; | |
240 | } | |
241 | nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING; | |
242 | ||
511c3f92 ED |
243 | rt = bridge_parent_rtable(nf_bridge->physindev); |
244 | if (!rt) { | |
4adf0af6 SW |
245 | kfree_skb(skb); |
246 | return 0; | |
247 | } | |
f9181f4f | 248 | skb_dst_set_noref(skb, &rt->dst); |
1da177e4 LT |
249 | |
250 | skb->dev = nf_bridge->physindev; | |
e179e632 | 251 | nf_bridge_update_protocol(skb); |
fc38582d | 252 | nf_bridge_push_encap_header(skb); |
713aefa3 | 253 | NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL, |
1da177e4 LT |
254 | br_handle_frame_finish, 1); |
255 | ||
256 | return 0; | |
257 | } | |
258 | ||
e179e632 BDS |
259 | /* Obtain the correct destination MAC address, while preserving the original |
260 | * source MAC address. If we already know this address, we just copy it. If we | |
261 | * don't, we use the neighbour framework to find out. In both cases, we make | |
262 | * sure that br_handle_frame_finish() is called afterwards. | |
263 | */ | |
264 | static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb) | |
265 | { | |
266 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; | |
267 | struct dst_entry *dst; | |
268 | ||
269 | skb->dev = bridge_parent(skb->dev); | |
270 | if (!skb->dev) | |
271 | goto free_skb; | |
272 | dst = skb_dst(skb); | |
273 | if (dst->hh) { | |
274 | neigh_hh_bridge(dst->hh, skb); | |
275 | skb->dev = nf_bridge->physindev; | |
276 | return br_handle_frame_finish(skb); | |
277 | } else if (dst->neighbour) { | |
278 | /* the neighbour function below overwrites the complete | |
279 | * MAC header, so we save the Ethernet source address and | |
280 | * protocol number. */ | |
281 | skb_copy_from_linear_data_offset(skb, -(ETH_HLEN-ETH_ALEN), skb->nf_bridge->data, ETH_HLEN-ETH_ALEN); | |
282 | /* tell br_dev_xmit to continue with forwarding */ | |
283 | nf_bridge->mask |= BRNF_BRIDGED_DNAT; | |
284 | return dst->neighbour->output(skb); | |
285 | } | |
286 | free_skb: | |
287 | kfree_skb(skb); | |
288 | return 0; | |
289 | } | |
290 | ||
1da177e4 | 291 | /* This requires some explaining. If DNAT has taken place, |
ea2d9b41 | 292 | * we will need to fix up the destination Ethernet address. |
1da177e4 LT |
293 | * |
294 | * There are two cases to consider: | |
295 | * 1. The packet was DNAT'ed to a device in the same bridge | |
296 | * port group as it was received on. We can still bridge | |
297 | * the packet. | |
298 | * 2. The packet was DNAT'ed to a different device, either | |
299 | * a non-bridged device or another bridge port group. | |
300 | * The packet will need to be routed. | |
301 | * | |
302 | * The correct way of distinguishing between these two cases is to | |
303 | * call ip_route_input() and to look at skb->dst->dev, which is | |
304 | * changed to the destination device if ip_route_input() succeeds. | |
305 | * | |
ea2d9b41 | 306 | * Let's first consider the case that ip_route_input() succeeds: |
1da177e4 | 307 | * |
ea2d9b41 BDS |
308 | * If the output device equals the logical bridge device the packet |
309 | * came in on, we can consider this bridging. The corresponding MAC | |
310 | * address will be obtained in br_nf_pre_routing_finish_bridge. | |
1da177e4 LT |
311 | * Otherwise, the packet is considered to be routed and we just |
312 | * change the destination MAC address so that the packet will | |
f216f082 BDS |
313 | * later be passed up to the IP stack to be routed. For a redirected |
314 | * packet, ip_route_input() will give back the localhost as output device, | |
315 | * which differs from the bridge device. | |
1da177e4 | 316 | * |
ea2d9b41 | 317 | * Let's now consider the case that ip_route_input() fails: |
1da177e4 | 318 | * |
f216f082 BDS |
319 | * This can be because the destination address is martian, in which case |
320 | * the packet will be dropped. | |
ea2d9b41 BDS |
321 | * If IP forwarding is disabled, ip_route_input() will fail, while |
322 | * ip_route_output_key() can return success. The source | |
323 | * address for ip_route_output_key() is set to zero, so ip_route_output_key() | |
1da177e4 | 324 | * thinks we're handling a locally generated packet and won't care |
ea2d9b41 BDS |
325 | * if IP forwarding is enabled. If the output device equals the logical bridge |
326 | * device, we proceed as if ip_route_input() succeeded. If it differs from the | |
327 | * logical bridge port or if ip_route_output_key() fails we drop the packet. | |
328 | */ | |
1da177e4 LT |
329 | static int br_nf_pre_routing_finish(struct sk_buff *skb) |
330 | { | |
331 | struct net_device *dev = skb->dev; | |
eddc9ec5 | 332 | struct iphdr *iph = ip_hdr(skb); |
1da177e4 | 333 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
511c3f92 | 334 | struct rtable *rt; |
f216f082 | 335 | int err; |
1da177e4 | 336 | |
1da177e4 LT |
337 | if (nf_bridge->mask & BRNF_PKT_TYPE) { |
338 | skb->pkt_type = PACKET_OTHERHOST; | |
339 | nf_bridge->mask ^= BRNF_PKT_TYPE; | |
340 | } | |
341 | nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING; | |
1da177e4 | 342 | if (dnat_took_place(skb)) { |
f216f082 | 343 | if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) { |
789bc3e5 SH |
344 | struct flowi fl = { |
345 | .nl_u = { | |
346 | .ip4_u = { | |
347 | .daddr = iph->daddr, | |
348 | .saddr = 0, | |
349 | .tos = RT_TOS(iph->tos) }, | |
350 | }, | |
351 | .proto = 0, | |
352 | }; | |
f3abc9b9 | 353 | struct in_device *in_dev = __in_dev_get_rcu(dev); |
f216f082 BDS |
354 | |
355 | /* If err equals -EHOSTUNREACH the error is due to a | |
356 | * martian destination or due to the fact that | |
357 | * forwarding is disabled. For most martian packets, | |
358 | * ip_route_output_key() will fail. It won't fail for 2 types of | |
359 | * martian destinations: loopback destinations and destination | |
360 | * 0.0.0.0. In both cases the packet will be dropped because the | |
361 | * destination is the loopback device and not the bridge. */ | |
362 | if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev)) | |
363 | goto free_skb; | |
1da177e4 | 364 | |
249b6203 | 365 | if (!ip_route_output_key(dev_net(dev), &rt, &fl)) { |
1c011bed | 366 | /* - Bridged-and-DNAT'ed traffic doesn't |
f216f082 BDS |
367 | * require ip_forwarding. */ |
368 | if (((struct dst_entry *)rt)->dev == dev) { | |
adf30907 | 369 | skb_dst_set(skb, (struct dst_entry *)rt); |
1da177e4 LT |
370 | goto bridged_dnat; |
371 | } | |
1da177e4 LT |
372 | dst_release((struct dst_entry *)rt); |
373 | } | |
f216f082 | 374 | free_skb: |
1da177e4 LT |
375 | kfree_skb(skb); |
376 | return 0; | |
377 | } else { | |
adf30907 | 378 | if (skb_dst(skb)->dev == dev) { |
1da177e4 | 379 | bridged_dnat: |
1da177e4 | 380 | skb->dev = nf_bridge->physindev; |
e179e632 | 381 | nf_bridge_update_protocol(skb); |
fc38582d | 382 | nf_bridge_push_encap_header(skb); |
713aefa3 JE |
383 | NF_HOOK_THRESH(NFPROTO_BRIDGE, |
384 | NF_BR_PRE_ROUTING, | |
1da177e4 LT |
385 | skb, skb->dev, NULL, |
386 | br_nf_pre_routing_finish_bridge, | |
387 | 1); | |
388 | return 0; | |
389 | } | |
789bc3e5 | 390 | memcpy(eth_hdr(skb)->h_dest, dev->dev_addr, ETH_ALEN); |
1da177e4 LT |
391 | skb->pkt_type = PACKET_HOST; |
392 | } | |
393 | } else { | |
511c3f92 ED |
394 | rt = bridge_parent_rtable(nf_bridge->physindev); |
395 | if (!rt) { | |
4adf0af6 SW |
396 | kfree_skb(skb); |
397 | return 0; | |
398 | } | |
f9181f4f | 399 | skb_dst_set_noref(skb, &rt->dst); |
1da177e4 LT |
400 | } |
401 | ||
402 | skb->dev = nf_bridge->physindev; | |
e179e632 | 403 | nf_bridge_update_protocol(skb); |
fc38582d | 404 | nf_bridge_push_encap_header(skb); |
713aefa3 | 405 | NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL, |
1da177e4 LT |
406 | br_handle_frame_finish, 1); |
407 | ||
408 | return 0; | |
409 | } | |
410 | ||
411 | /* Some common code for IPv4/IPv6 */ | |
5dce971a | 412 | static struct net_device *setup_pre_routing(struct sk_buff *skb) |
1da177e4 LT |
413 | { |
414 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; | |
415 | ||
416 | if (skb->pkt_type == PACKET_OTHERHOST) { | |
417 | skb->pkt_type = PACKET_HOST; | |
418 | nf_bridge->mask |= BRNF_PKT_TYPE; | |
419 | } | |
420 | ||
421 | nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING; | |
422 | nf_bridge->physindev = skb->dev; | |
423 | skb->dev = bridge_parent(skb->dev); | |
e179e632 BDS |
424 | if (skb->protocol == htons(ETH_P_8021Q)) |
425 | nf_bridge->mask |= BRNF_8021Q; | |
426 | else if (skb->protocol == htons(ETH_P_PPP_SES)) | |
427 | nf_bridge->mask |= BRNF_PPPoE; | |
5dce971a SH |
428 | |
429 | return skb->dev; | |
1da177e4 LT |
430 | } |
431 | ||
432 | /* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */ | |
433 | static int check_hbh_len(struct sk_buff *skb) | |
434 | { | |
0660e03f | 435 | unsigned char *raw = (u8 *)(ipv6_hdr(skb) + 1); |
1da177e4 | 436 | u32 pkt_len; |
d56f90a7 ACM |
437 | const unsigned char *nh = skb_network_header(skb); |
438 | int off = raw - nh; | |
789bc3e5 | 439 | int len = (raw[1] + 1) << 3; |
1da177e4 LT |
440 | |
441 | if ((raw + len) - skb->data > skb_headlen(skb)) | |
442 | goto bad; | |
443 | ||
444 | off += 2; | |
445 | len -= 2; | |
446 | ||
447 | while (len > 0) { | |
d56f90a7 | 448 | int optlen = nh[off + 1] + 2; |
1da177e4 | 449 | |
d56f90a7 | 450 | switch (nh[off]) { |
1da177e4 LT |
451 | case IPV6_TLV_PAD0: |
452 | optlen = 1; | |
453 | break; | |
454 | ||
455 | case IPV6_TLV_PADN: | |
456 | break; | |
457 | ||
458 | case IPV6_TLV_JUMBO: | |
d56f90a7 | 459 | if (nh[off + 1] != 4 || (off & 3) != 2) |
1da177e4 | 460 | goto bad; |
d56f90a7 | 461 | pkt_len = ntohl(*(__be32 *) (nh + off + 2)); |
b0366486 | 462 | if (pkt_len <= IPV6_MAXPLEN || |
0660e03f | 463 | ipv6_hdr(skb)->payload_len) |
b0366486 | 464 | goto bad; |
1da177e4 LT |
465 | if (pkt_len > skb->len - sizeof(struct ipv6hdr)) |
466 | goto bad; | |
b0366486 | 467 | if (pskb_trim_rcsum(skb, |
789bc3e5 | 468 | pkt_len + sizeof(struct ipv6hdr))) |
b0366486 | 469 | goto bad; |
d56f90a7 | 470 | nh = skb_network_header(skb); |
1da177e4 LT |
471 | break; |
472 | default: | |
473 | if (optlen > len) | |
474 | goto bad; | |
475 | break; | |
476 | } | |
477 | off += optlen; | |
478 | len -= optlen; | |
479 | } | |
480 | if (len == 0) | |
481 | return 0; | |
482 | bad: | |
483 | return -1; | |
484 | ||
485 | } | |
486 | ||
487 | /* Replicate the checks that IPv6 does on packet reception and pass the packet | |
488 | * to ip6tables, which doesn't support NAT, so things are fairly simple. */ | |
489 | static unsigned int br_nf_pre_routing_ipv6(unsigned int hook, | |
789bc3e5 SH |
490 | struct sk_buff *skb, |
491 | const struct net_device *in, | |
492 | const struct net_device *out, | |
493 | int (*okfn)(struct sk_buff *)) | |
1da177e4 LT |
494 | { |
495 | struct ipv6hdr *hdr; | |
496 | u32 pkt_len; | |
1da177e4 LT |
497 | |
498 | if (skb->len < sizeof(struct ipv6hdr)) | |
499 | goto inhdr_error; | |
500 | ||
501 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) | |
502 | goto inhdr_error; | |
503 | ||
0660e03f | 504 | hdr = ipv6_hdr(skb); |
1da177e4 LT |
505 | |
506 | if (hdr->version != 6) | |
507 | goto inhdr_error; | |
508 | ||
509 | pkt_len = ntohs(hdr->payload_len); | |
510 | ||
511 | if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) { | |
512 | if (pkt_len + sizeof(struct ipv6hdr) > skb->len) | |
513 | goto inhdr_error; | |
b38dfee3 HX |
514 | if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) |
515 | goto inhdr_error; | |
1da177e4 LT |
516 | } |
517 | if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb)) | |
789bc3e5 | 518 | goto inhdr_error; |
1da177e4 | 519 | |
789bc3e5 | 520 | nf_bridge_put(skb->nf_bridge); |
fdeabdef | 521 | if (!nf_bridge_alloc(skb)) |
1da177e4 | 522 | return NF_DROP; |
5dce971a SH |
523 | if (!setup_pre_routing(skb)) |
524 | return NF_DROP; | |
1da177e4 | 525 | |
e179e632 | 526 | skb->protocol = htons(ETH_P_IPV6); |
713aefa3 | 527 | NF_HOOK(NFPROTO_IPV6, NF_INET_PRE_ROUTING, skb, skb->dev, NULL, |
1da177e4 LT |
528 | br_nf_pre_routing_finish_ipv6); |
529 | ||
530 | return NF_STOLEN; | |
531 | ||
532 | inhdr_error: | |
533 | return NF_DROP; | |
534 | } | |
535 | ||
536 | /* Direct IPv6 traffic to br_nf_pre_routing_ipv6. | |
537 | * Replicate the checks that IPv4 does on packet reception. | |
538 | * Set skb->dev to the bridge device (i.e. parent of the | |
539 | * receiving device) to make netfilter happy, the REDIRECT | |
540 | * target in particular. Save the original destination IP | |
541 | * address to be able to detect DNAT afterwards. */ | |
3db05fea | 542 | static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff *skb, |
ee02b3a6 SH |
543 | const struct net_device *in, |
544 | const struct net_device *out, | |
545 | int (*okfn)(struct sk_buff *)) | |
1da177e4 LT |
546 | { |
547 | struct iphdr *iph; | |
e7c243c9 EP |
548 | __u32 len = nf_bridge_encap_header_len(skb); |
549 | ||
e7c243c9 EP |
550 | if (unlikely(!pskb_may_pull(skb, len))) |
551 | goto out; | |
1da177e4 | 552 | |
516299d2 MM |
553 | if (skb->protocol == htons(ETH_P_IPV6) || IS_VLAN_IPV6(skb) || |
554 | IS_PPPOE_IPV6(skb)) { | |
1da177e4 LT |
555 | #ifdef CONFIG_SYSCTL |
556 | if (!brnf_call_ip6tables) | |
557 | return NF_ACCEPT; | |
558 | #endif | |
fc38582d | 559 | nf_bridge_pull_encap_header_rcsum(skb); |
1da177e4 LT |
560 | return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn); |
561 | } | |
562 | #ifdef CONFIG_SYSCTL | |
563 | if (!brnf_call_iptables) | |
564 | return NF_ACCEPT; | |
565 | #endif | |
566 | ||
516299d2 MM |
567 | if (skb->protocol != htons(ETH_P_IP) && !IS_VLAN_IP(skb) && |
568 | !IS_PPPOE_IP(skb)) | |
1da177e4 LT |
569 | return NF_ACCEPT; |
570 | ||
fc38582d | 571 | nf_bridge_pull_encap_header_rcsum(skb); |
1da177e4 LT |
572 | |
573 | if (!pskb_may_pull(skb, sizeof(struct iphdr))) | |
574 | goto inhdr_error; | |
575 | ||
eddc9ec5 | 576 | iph = ip_hdr(skb); |
1da177e4 LT |
577 | if (iph->ihl < 5 || iph->version != 4) |
578 | goto inhdr_error; | |
579 | ||
789bc3e5 | 580 | if (!pskb_may_pull(skb, 4 * iph->ihl)) |
1da177e4 LT |
581 | goto inhdr_error; |
582 | ||
eddc9ec5 | 583 | iph = ip_hdr(skb); |
789bc3e5 | 584 | if (ip_fast_csum((__u8 *) iph, iph->ihl) != 0) |
1da177e4 LT |
585 | goto inhdr_error; |
586 | ||
587 | len = ntohs(iph->tot_len); | |
789bc3e5 | 588 | if (skb->len < len || len < 4 * iph->ihl) |
1da177e4 LT |
589 | goto inhdr_error; |
590 | ||
b38dfee3 | 591 | pskb_trim_rcsum(skb, len); |
1da177e4 | 592 | |
789bc3e5 | 593 | nf_bridge_put(skb->nf_bridge); |
fdeabdef | 594 | if (!nf_bridge_alloc(skb)) |
1da177e4 | 595 | return NF_DROP; |
5dce971a SH |
596 | if (!setup_pre_routing(skb)) |
597 | return NF_DROP; | |
1da177e4 | 598 | store_orig_dstaddr(skb); |
e179e632 | 599 | skb->protocol = htons(ETH_P_IP); |
1da177e4 | 600 | |
713aefa3 | 601 | NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, skb, skb->dev, NULL, |
1da177e4 LT |
602 | br_nf_pre_routing_finish); |
603 | ||
604 | return NF_STOLEN; | |
605 | ||
606 | inhdr_error: | |
789bc3e5 | 607 | // IP_INC_STATS_BH(IpInHdrErrors); |
1da177e4 LT |
608 | out: |
609 | return NF_DROP; | |
610 | } | |
611 | ||
612 | ||
613 | /* PF_BRIDGE/LOCAL_IN ************************************************/ | |
614 | /* The packet is locally destined, which requires a real | |
615 | * dst_entry, so detach the fake one. On the way up, the | |
616 | * packet would pass through PRE_ROUTING again (which already | |
617 | * took place when the packet entered the bridge), but we | |
618 | * register an IPv4 PRE_ROUTING 'sabotage' hook that will | |
619 | * prevent this from happening. */ | |
3db05fea | 620 | static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff *skb, |
789bc3e5 SH |
621 | const struct net_device *in, |
622 | const struct net_device *out, | |
623 | int (*okfn)(struct sk_buff *)) | |
1da177e4 | 624 | { |
511c3f92 ED |
625 | struct rtable *rt = skb_rtable(skb); |
626 | ||
adf30907 ED |
627 | if (rt && rt == bridge_parent_rtable(in)) |
628 | skb_dst_drop(skb); | |
1da177e4 LT |
629 | |
630 | return NF_ACCEPT; | |
631 | } | |
632 | ||
1da177e4 LT |
633 | /* PF_BRIDGE/FORWARD *************************************************/ |
634 | static int br_nf_forward_finish(struct sk_buff *skb) | |
635 | { | |
636 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; | |
637 | struct net_device *in; | |
1da177e4 | 638 | |
8b42ec39 | 639 | if (skb->protocol != htons(ETH_P_ARP) && !IS_VLAN_ARP(skb)) { |
1da177e4 LT |
640 | in = nf_bridge->physindev; |
641 | if (nf_bridge->mask & BRNF_PKT_TYPE) { | |
642 | skb->pkt_type = PACKET_OTHERHOST; | |
643 | nf_bridge->mask ^= BRNF_PKT_TYPE; | |
644 | } | |
e94c6743 | 645 | nf_bridge_update_protocol(skb); |
1da177e4 LT |
646 | } else { |
647 | in = *((struct net_device **)(skb->cb)); | |
648 | } | |
fc38582d | 649 | nf_bridge_push_encap_header(skb); |
e179e632 | 650 | |
713aefa3 | 651 | NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, in, |
789bc3e5 | 652 | skb->dev, br_forward_finish, 1); |
1da177e4 LT |
653 | return 0; |
654 | } | |
655 | ||
656 | /* This is the 'purely bridged' case. For IP, we pass the packet to | |
657 | * netfilter with indev and outdev set to the bridge device, | |
658 | * but we are still able to filter on the 'real' indev/outdev | |
659 | * because of the physdev module. For ARP, indev and outdev are the | |
660 | * bridge ports. */ | |
3db05fea | 661 | static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff *skb, |
789bc3e5 SH |
662 | const struct net_device *in, |
663 | const struct net_device *out, | |
664 | int (*okfn)(struct sk_buff *)) | |
1da177e4 | 665 | { |
1da177e4 | 666 | struct nf_bridge_info *nf_bridge; |
5dce971a | 667 | struct net_device *parent; |
76108cea | 668 | u_int8_t pf; |
1da177e4 LT |
669 | |
670 | if (!skb->nf_bridge) | |
671 | return NF_ACCEPT; | |
672 | ||
2dc2f207 PM |
673 | /* Need exclusive nf_bridge_info since we might have multiple |
674 | * different physoutdevs. */ | |
675 | if (!nf_bridge_unshare(skb)) | |
676 | return NF_DROP; | |
677 | ||
5dce971a SH |
678 | parent = bridge_parent(out); |
679 | if (!parent) | |
680 | return NF_DROP; | |
681 | ||
516299d2 MM |
682 | if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb) || |
683 | IS_PPPOE_IP(skb)) | |
1da177e4 | 684 | pf = PF_INET; |
a2bd40ad HX |
685 | else if (skb->protocol == htons(ETH_P_IPV6) || IS_VLAN_IPV6(skb) || |
686 | IS_PPPOE_IPV6(skb)) | |
1da177e4 | 687 | pf = PF_INET6; |
a2bd40ad HX |
688 | else |
689 | return NF_ACCEPT; | |
1da177e4 | 690 | |
3db05fea | 691 | nf_bridge_pull_encap_header(skb); |
1da177e4 | 692 | |
1da177e4 LT |
693 | nf_bridge = skb->nf_bridge; |
694 | if (skb->pkt_type == PACKET_OTHERHOST) { | |
695 | skb->pkt_type = PACKET_HOST; | |
696 | nf_bridge->mask |= BRNF_PKT_TYPE; | |
697 | } | |
698 | ||
699 | /* The physdev module checks on this */ | |
700 | nf_bridge->mask |= BRNF_BRIDGED; | |
701 | nf_bridge->physoutdev = skb->dev; | |
e179e632 BDS |
702 | if (pf == PF_INET) |
703 | skb->protocol = htons(ETH_P_IP); | |
704 | else | |
705 | skb->protocol = htons(ETH_P_IPV6); | |
1da177e4 | 706 | |
6e23ae2a | 707 | NF_HOOK(pf, NF_INET_FORWARD, skb, bridge_parent(in), parent, |
5dce971a | 708 | br_nf_forward_finish); |
1da177e4 LT |
709 | |
710 | return NF_STOLEN; | |
711 | } | |
712 | ||
3db05fea | 713 | static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff *skb, |
789bc3e5 SH |
714 | const struct net_device *in, |
715 | const struct net_device *out, | |
716 | int (*okfn)(struct sk_buff *)) | |
1da177e4 | 717 | { |
1da177e4 LT |
718 | struct net_device **d = (struct net_device **)(skb->cb); |
719 | ||
720 | #ifdef CONFIG_SYSCTL | |
721 | if (!brnf_call_arptables) | |
722 | return NF_ACCEPT; | |
723 | #endif | |
724 | ||
f8a26028 | 725 | if (skb->protocol != htons(ETH_P_ARP)) { |
8b42ec39 | 726 | if (!IS_VLAN_ARP(skb)) |
1da177e4 | 727 | return NF_ACCEPT; |
3db05fea | 728 | nf_bridge_pull_encap_header(skb); |
1da177e4 LT |
729 | } |
730 | ||
d0a92be0 | 731 | if (arp_hdr(skb)->ar_pln != 4) { |
fc38582d | 732 | if (IS_VLAN_ARP(skb)) |
3db05fea | 733 | nf_bridge_push_encap_header(skb); |
1da177e4 LT |
734 | return NF_ACCEPT; |
735 | } | |
736 | *d = (struct net_device *)in; | |
fdc9314c | 737 | NF_HOOK(NFPROTO_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in, |
1da177e4 LT |
738 | (struct net_device *)out, br_nf_forward_finish); |
739 | ||
740 | return NF_STOLEN; | |
741 | } | |
742 | ||
c197facc | 743 | #if defined(CONFIG_NF_CONNTRACK_IPV4) || defined(CONFIG_NF_CONNTRACK_IPV4_MODULE) |
2e2f7aef PM |
744 | static int br_nf_dev_queue_xmit(struct sk_buff *skb) |
745 | { | |
e179e632 | 746 | if (skb->nfct != NULL && skb->protocol == htons(ETH_P_IP) && |
6c79bf0f | 747 | skb->len + nf_bridge_mtu_reduction(skb) > skb->dev->mtu && |
89114afd | 748 | !skb_is_gso(skb)) |
2e2f7aef PM |
749 | return ip_fragment(skb, br_dev_queue_push_xmit); |
750 | else | |
751 | return br_dev_queue_push_xmit(skb); | |
752 | } | |
c197facc | 753 | #else |
754 | static int br_nf_dev_queue_xmit(struct sk_buff *skb) | |
755 | { | |
756 | return br_dev_queue_push_xmit(skb); | |
757 | } | |
758 | #endif | |
1da177e4 LT |
759 | |
760 | /* PF_BRIDGE/POST_ROUTING ********************************************/ | |
3db05fea | 761 | static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff *skb, |
789bc3e5 SH |
762 | const struct net_device *in, |
763 | const struct net_device *out, | |
764 | int (*okfn)(struct sk_buff *)) | |
1da177e4 | 765 | { |
3db05fea | 766 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
1da177e4 | 767 | struct net_device *realoutdev = bridge_parent(skb->dev); |
76108cea | 768 | u_int8_t pf; |
1da177e4 | 769 | |
ea2d9b41 | 770 | if (!nf_bridge || !(nf_bridge->mask & BRNF_BRIDGED)) |
81d9ddae PM |
771 | return NF_ACCEPT; |
772 | ||
5dce971a SH |
773 | if (!realoutdev) |
774 | return NF_DROP; | |
775 | ||
516299d2 MM |
776 | if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb) || |
777 | IS_PPPOE_IP(skb)) | |
1da177e4 | 778 | pf = PF_INET; |
a2bd40ad HX |
779 | else if (skb->protocol == htons(ETH_P_IPV6) || IS_VLAN_IPV6(skb) || |
780 | IS_PPPOE_IPV6(skb)) | |
1da177e4 | 781 | pf = PF_INET6; |
a2bd40ad HX |
782 | else |
783 | return NF_ACCEPT; | |
1da177e4 | 784 | |
1da177e4 LT |
785 | /* We assume any code from br_dev_queue_push_xmit onwards doesn't care |
786 | * about the value of skb->pkt_type. */ | |
787 | if (skb->pkt_type == PACKET_OTHERHOST) { | |
788 | skb->pkt_type = PACKET_HOST; | |
789 | nf_bridge->mask |= BRNF_PKT_TYPE; | |
790 | } | |
791 | ||
fc38582d | 792 | nf_bridge_pull_encap_header(skb); |
1da177e4 | 793 | nf_bridge_save_header(skb); |
e179e632 BDS |
794 | if (pf == PF_INET) |
795 | skb->protocol = htons(ETH_P_IP); | |
796 | else | |
797 | skb->protocol = htons(ETH_P_IPV6); | |
1da177e4 | 798 | |
6e23ae2a | 799 | NF_HOOK(pf, NF_INET_POST_ROUTING, skb, NULL, realoutdev, |
2e2f7aef | 800 | br_nf_dev_queue_xmit); |
1da177e4 LT |
801 | |
802 | return NF_STOLEN; | |
1da177e4 LT |
803 | } |
804 | ||
1da177e4 LT |
805 | /* IP/SABOTAGE *****************************************************/ |
806 | /* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING | |
807 | * for the second time. */ | |
3db05fea | 808 | static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff *skb, |
789bc3e5 SH |
809 | const struct net_device *in, |
810 | const struct net_device *out, | |
811 | int (*okfn)(struct sk_buff *)) | |
1da177e4 | 812 | { |
3db05fea HX |
813 | if (skb->nf_bridge && |
814 | !(skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) { | |
1da177e4 LT |
815 | return NF_STOP; |
816 | } | |
817 | ||
818 | return NF_ACCEPT; | |
819 | } | |
820 | ||
ea2d9b41 BDS |
821 | /* For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because |
822 | * br_dev_queue_push_xmit is called afterwards */ | |
1999414a | 823 | static struct nf_hook_ops br_nf_ops[] __read_mostly = { |
1490fd89 CG |
824 | { |
825 | .hook = br_nf_pre_routing, | |
826 | .owner = THIS_MODULE, | |
827 | .pf = PF_BRIDGE, | |
828 | .hooknum = NF_BR_PRE_ROUTING, | |
829 | .priority = NF_BR_PRI_BRNF, | |
830 | }, | |
831 | { | |
832 | .hook = br_nf_local_in, | |
833 | .owner = THIS_MODULE, | |
834 | .pf = PF_BRIDGE, | |
835 | .hooknum = NF_BR_LOCAL_IN, | |
836 | .priority = NF_BR_PRI_BRNF, | |
837 | }, | |
838 | { | |
839 | .hook = br_nf_forward_ip, | |
840 | .owner = THIS_MODULE, | |
841 | .pf = PF_BRIDGE, | |
842 | .hooknum = NF_BR_FORWARD, | |
843 | .priority = NF_BR_PRI_BRNF - 1, | |
844 | }, | |
845 | { | |
846 | .hook = br_nf_forward_arp, | |
847 | .owner = THIS_MODULE, | |
848 | .pf = PF_BRIDGE, | |
849 | .hooknum = NF_BR_FORWARD, | |
850 | .priority = NF_BR_PRI_BRNF, | |
851 | }, | |
1490fd89 CG |
852 | { |
853 | .hook = br_nf_post_routing, | |
854 | .owner = THIS_MODULE, | |
855 | .pf = PF_BRIDGE, | |
856 | .hooknum = NF_BR_POST_ROUTING, | |
857 | .priority = NF_BR_PRI_LAST, | |
858 | }, | |
859 | { | |
860 | .hook = ip_sabotage_in, | |
861 | .owner = THIS_MODULE, | |
862 | .pf = PF_INET, | |
863 | .hooknum = NF_INET_PRE_ROUTING, | |
864 | .priority = NF_IP_PRI_FIRST, | |
865 | }, | |
866 | { | |
867 | .hook = ip_sabotage_in, | |
868 | .owner = THIS_MODULE, | |
869 | .pf = PF_INET6, | |
870 | .hooknum = NF_INET_PRE_ROUTING, | |
871 | .priority = NF_IP6_PRI_FIRST, | |
872 | }, | |
1da177e4 LT |
873 | }; |
874 | ||
875 | #ifdef CONFIG_SYSCTL | |
876 | static | |
8d65af78 | 877 | int brnf_sysctl_call_tables(ctl_table * ctl, int write, |
789bc3e5 | 878 | void __user * buffer, size_t * lenp, loff_t * ppos) |
1da177e4 LT |
879 | { |
880 | int ret; | |
881 | ||
8d65af78 | 882 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
1da177e4 LT |
883 | |
884 | if (write && *(int *)(ctl->data)) | |
885 | *(int *)(ctl->data) = 1; | |
886 | return ret; | |
887 | } | |
888 | ||
889 | static ctl_table brnf_table[] = { | |
890 | { | |
1da177e4 LT |
891 | .procname = "bridge-nf-call-arptables", |
892 | .data = &brnf_call_arptables, | |
893 | .maxlen = sizeof(int), | |
894 | .mode = 0644, | |
6d9f239a | 895 | .proc_handler = brnf_sysctl_call_tables, |
1da177e4 LT |
896 | }, |
897 | { | |
1da177e4 LT |
898 | .procname = "bridge-nf-call-iptables", |
899 | .data = &brnf_call_iptables, | |
900 | .maxlen = sizeof(int), | |
901 | .mode = 0644, | |
6d9f239a | 902 | .proc_handler = brnf_sysctl_call_tables, |
1da177e4 LT |
903 | }, |
904 | { | |
1da177e4 LT |
905 | .procname = "bridge-nf-call-ip6tables", |
906 | .data = &brnf_call_ip6tables, | |
907 | .maxlen = sizeof(int), | |
908 | .mode = 0644, | |
6d9f239a | 909 | .proc_handler = brnf_sysctl_call_tables, |
1da177e4 LT |
910 | }, |
911 | { | |
1da177e4 LT |
912 | .procname = "bridge-nf-filter-vlan-tagged", |
913 | .data = &brnf_filter_vlan_tagged, | |
914 | .maxlen = sizeof(int), | |
915 | .mode = 0644, | |
6d9f239a | 916 | .proc_handler = brnf_sysctl_call_tables, |
516299d2 MM |
917 | }, |
918 | { | |
516299d2 MM |
919 | .procname = "bridge-nf-filter-pppoe-tagged", |
920 | .data = &brnf_filter_pppoe_tagged, | |
921 | .maxlen = sizeof(int), | |
922 | .mode = 0644, | |
6d9f239a | 923 | .proc_handler = brnf_sysctl_call_tables, |
1da177e4 | 924 | }, |
f8572d8f | 925 | { } |
1da177e4 LT |
926 | }; |
927 | ||
b5ccd792 | 928 | static struct ctl_path brnf_path[] = { |
f8572d8f EB |
929 | { .procname = "net", }, |
930 | { .procname = "bridge", }, | |
b5ccd792 | 931 | { } |
1da177e4 LT |
932 | }; |
933 | #endif | |
934 | ||
5eb87f45 | 935 | int __init br_netfilter_init(void) |
1da177e4 | 936 | { |
5eb87f45 | 937 | int ret; |
1da177e4 | 938 | |
5eb87f45 PM |
939 | ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
940 | if (ret < 0) | |
1da177e4 | 941 | return ret; |
1da177e4 | 942 | #ifdef CONFIG_SYSCTL |
b5ccd792 | 943 | brnf_sysctl_header = register_sysctl_paths(brnf_path, brnf_table); |
1da177e4 | 944 | if (brnf_sysctl_header == NULL) { |
789bc3e5 SH |
945 | printk(KERN_WARNING |
946 | "br_netfilter: can't register to sysctl.\n"); | |
5eb87f45 PM |
947 | nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
948 | return -ENOMEM; | |
1da177e4 LT |
949 | } |
950 | #endif | |
1da177e4 | 951 | printk(KERN_NOTICE "Bridge firewalling registered\n"); |
1da177e4 LT |
952 | return 0; |
953 | } | |
954 | ||
955 | void br_netfilter_fini(void) | |
956 | { | |
5eb87f45 | 957 | nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
1da177e4 LT |
958 | #ifdef CONFIG_SYSCTL |
959 | unregister_sysctl_table(brnf_sysctl_header); | |
960 | #endif | |
961 | } |