Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Handle firewalling |
| 3 | * Linux ethernet bridge |
| 4 | * |
| 5 | * Authors: |
| 6 | * Lennert Buytenhek <buytenh@gnu.org> |
| 7 | * Bart De Schuymer (maintainer) <bdschuym@pandora.be> |
| 8 | * |
| 9 | * Changes: |
| 10 | * Apr 29 2003: physdev module support (bdschuym) |
| 11 | * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym) |
| 12 | * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge |
| 13 | * (bdschuym) |
| 14 | * Sep 01 2004: add IPv6 filtering (bdschuym) |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License |
| 18 | * as published by the Free Software Foundation; either version |
| 19 | * 2 of the License, or (at your option) any later version. |
| 20 | * |
| 21 | * Lennert dedicates this file to Kerstin Wurdinger. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/ip.h> |
| 27 | #include <linux/netdevice.h> |
| 28 | #include <linux/skbuff.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 29 | #include <linux/if_arp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/if_ether.h> |
| 31 | #include <linux/if_vlan.h> |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 32 | #include <linux/if_pppox.h> |
| 33 | #include <linux/ppp_defs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/netfilter_bridge.h> |
| 35 | #include <linux/netfilter_ipv4.h> |
| 36 | #include <linux/netfilter_ipv6.h> |
| 37 | #include <linux/netfilter_arp.h> |
| 38 | #include <linux/in_route.h> |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 39 | #include <linux/inetdevice.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <net/ip.h> |
| 42 | #include <net/ipv6.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 43 | #include <net/route.h> |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include "br_private.h" |
| 47 | #ifdef CONFIG_SYSCTL |
| 48 | #include <linux/sysctl.h> |
| 49 | #endif |
| 50 | |
| 51 | #define skb_origaddr(skb) (((struct bridge_skb_cb *) \ |
| 52 | (skb->nf_bridge->data))->daddr.ipv4) |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 53 | #define store_orig_dstaddr(skb) (skb_origaddr(skb) = ip_hdr(skb)->daddr) |
| 54 | #define dnat_took_place(skb) (skb_origaddr(skb) != ip_hdr(skb)->daddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #ifdef CONFIG_SYSCTL |
| 57 | static struct ctl_table_header *brnf_sysctl_header; |
Brian Haley | 9c1ea14 | 2006-09-18 00:03:41 -0700 | [diff] [blame] | 58 | static int brnf_call_iptables __read_mostly = 1; |
| 59 | static int brnf_call_ip6tables __read_mostly = 1; |
| 60 | static int brnf_call_arptables __read_mostly = 1; |
| 61 | static int brnf_filter_vlan_tagged __read_mostly = 1; |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 62 | static int brnf_filter_pppoe_tagged __read_mostly = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #else |
| 64 | #define brnf_filter_vlan_tagged 1 |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 65 | #define brnf_filter_pppoe_tagged 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #endif |
| 67 | |
Dave Jones | b6f99a2 | 2007-03-22 12:27:49 -0700 | [diff] [blame] | 68 | static inline __be16 vlan_proto(const struct sk_buff *skb) |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 69 | { |
| 70 | return vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 71 | } |
| 72 | |
| 73 | #define IS_VLAN_IP(skb) \ |
| 74 | (skb->protocol == htons(ETH_P_8021Q) && \ |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 75 | vlan_proto(skb) == htons(ETH_P_IP) && \ |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 76 | brnf_filter_vlan_tagged) |
| 77 | |
| 78 | #define IS_VLAN_IPV6(skb) \ |
| 79 | (skb->protocol == htons(ETH_P_8021Q) && \ |
| 80 | vlan_proto(skb) == htons(ETH_P_IPV6) &&\ |
| 81 | brnf_filter_vlan_tagged) |
| 82 | |
| 83 | #define IS_VLAN_ARP(skb) \ |
| 84 | (skb->protocol == htons(ETH_P_8021Q) && \ |
| 85 | vlan_proto(skb) == htons(ETH_P_ARP) && \ |
| 86 | brnf_filter_vlan_tagged) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 88 | static inline __be16 pppoe_proto(const struct sk_buff *skb) |
| 89 | { |
| 90 | return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN + |
| 91 | sizeof(struct pppoe_hdr))); |
| 92 | } |
| 93 | |
| 94 | #define IS_PPPOE_IP(skb) \ |
| 95 | (skb->protocol == htons(ETH_P_PPP_SES) && \ |
| 96 | pppoe_proto(skb) == htons(PPP_IP) && \ |
| 97 | brnf_filter_pppoe_tagged) |
| 98 | |
| 99 | #define IS_PPPOE_IPV6(skb) \ |
| 100 | (skb->protocol == htons(ETH_P_PPP_SES) && \ |
| 101 | pppoe_proto(skb) == htons(PPP_IPV6) && \ |
| 102 | brnf_filter_pppoe_tagged) |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* We need these fake structures to make netfilter happy -- |
| 105 | * lots of places assume that skb->dst != NULL, which isn't |
| 106 | * all that unreasonable. |
| 107 | * |
| 108 | * Currently, we fill in the PMTU entry because netfilter |
| 109 | * refragmentation needs it, and the rt_flags entry because |
| 110 | * ipt_REJECT needs it. Future netfilter modules might |
| 111 | * require us to fill additional fields. */ |
| 112 | static struct net_device __fake_net_device = { |
| 113 | .hard_header_len = ETH_HLEN |
| 114 | }; |
| 115 | |
| 116 | static struct rtable __fake_rtable = { |
| 117 | .u = { |
| 118 | .dst = { |
| 119 | .__refcnt = ATOMIC_INIT(1), |
| 120 | .dev = &__fake_net_device, |
| 121 | .path = &__fake_rtable.u.dst, |
| 122 | .metrics = {[RTAX_MTU - 1] = 1500}, |
Patrick McHardy | 42cf93c | 2006-02-21 13:37:35 -0800 | [diff] [blame] | 123 | .flags = DST_NOXFRM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | }, |
| 126 | .rt_flags = 0, |
| 127 | }; |
| 128 | |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 129 | static inline struct net_device *bridge_parent(const struct net_device *dev) |
| 130 | { |
| 131 | struct net_bridge_port *port = rcu_dereference(dev->br_port); |
| 132 | |
| 133 | return port ? port->br->dev : NULL; |
| 134 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Stephen Hemminger | fdeabde | 2006-03-20 22:58:21 -0800 | [diff] [blame] | 136 | static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb) |
| 137 | { |
| 138 | skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC); |
| 139 | if (likely(skb->nf_bridge)) |
| 140 | atomic_set(&(skb->nf_bridge->use), 1); |
| 141 | |
| 142 | return skb->nf_bridge; |
| 143 | } |
| 144 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 145 | static inline void nf_bridge_push_encap_header(struct sk_buff *skb) |
| 146 | { |
| 147 | unsigned int len = nf_bridge_encap_header_len(skb); |
| 148 | |
| 149 | skb_push(skb, len); |
| 150 | skb->network_header -= len; |
| 151 | } |
| 152 | |
| 153 | static inline void nf_bridge_pull_encap_header(struct sk_buff *skb) |
| 154 | { |
| 155 | unsigned int len = nf_bridge_encap_header_len(skb); |
| 156 | |
| 157 | skb_pull(skb, len); |
| 158 | skb->network_header += len; |
| 159 | } |
| 160 | |
| 161 | static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb) |
| 162 | { |
| 163 | unsigned int len = nf_bridge_encap_header_len(skb); |
| 164 | |
| 165 | skb_pull_rcsum(skb, len); |
| 166 | skb->network_header += len; |
| 167 | } |
| 168 | |
Stephen Hemminger | fdeabde | 2006-03-20 22:58:21 -0800 | [diff] [blame] | 169 | static inline void nf_bridge_save_header(struct sk_buff *skb) |
| 170 | { |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 171 | int header_size = ETH_HLEN + nf_bridge_encap_header_len(skb); |
Stephen Hemminger | fdeabde | 2006-03-20 22:58:21 -0800 | [diff] [blame] | 172 | |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 173 | skb_copy_from_linear_data_offset(skb, -header_size, |
| 174 | skb->nf_bridge->data, header_size); |
Stephen Hemminger | fdeabde | 2006-03-20 22:58:21 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Stephen Hemminger | 0731762 | 2006-08-29 17:48:17 -0700 | [diff] [blame] | 177 | /* |
| 178 | * When forwarding bridge frames, we save a copy of the original |
| 179 | * header before processing. |
| 180 | */ |
| 181 | int nf_bridge_copy_header(struct sk_buff *skb) |
| 182 | { |
| 183 | int err; |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 184 | int header_size = ETH_HLEN + nf_bridge_encap_header_len(skb); |
Stephen Hemminger | 0731762 | 2006-08-29 17:48:17 -0700 | [diff] [blame] | 185 | |
| 186 | err = skb_cow(skb, header_size); |
| 187 | if (err) |
| 188 | return err; |
| 189 | |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 190 | skb_copy_to_linear_data_offset(skb, -header_size, |
| 191 | skb->nf_bridge->data, header_size); |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 192 | __skb_push(skb, nf_bridge_encap_header_len(skb)); |
Stephen Hemminger | 0731762 | 2006-08-29 17:48:17 -0700 | [diff] [blame] | 193 | return 0; |
| 194 | } |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | /* PF_BRIDGE/PRE_ROUTING *********************************************/ |
| 197 | /* Undo the changes made for ip6tables PREROUTING and continue the |
| 198 | * bridge PRE_ROUTING hook. */ |
| 199 | static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb) |
| 200 | { |
| 201 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | if (nf_bridge->mask & BRNF_PKT_TYPE) { |
| 204 | skb->pkt_type = PACKET_OTHERHOST; |
| 205 | nf_bridge->mask ^= BRNF_PKT_TYPE; |
| 206 | } |
| 207 | nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING; |
| 208 | |
| 209 | skb->dst = (struct dst_entry *)&__fake_rtable; |
| 210 | dst_hold(skb->dst); |
| 211 | |
| 212 | skb->dev = nf_bridge->physindev; |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 213 | nf_bridge_push_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL, |
| 215 | br_handle_frame_finish, 1); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static void __br_dnat_complain(void) |
| 221 | { |
| 222 | static unsigned long last_complaint; |
| 223 | |
| 224 | if (jiffies - last_complaint >= 5 * HZ) { |
| 225 | printk(KERN_WARNING "Performing cross-bridge DNAT requires IP " |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 226 | "forwarding to be enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | last_complaint = jiffies; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | /* This requires some explaining. If DNAT has taken place, |
| 232 | * we will need to fix up the destination Ethernet address, |
| 233 | * and this is a tricky process. |
| 234 | * |
| 235 | * There are two cases to consider: |
| 236 | * 1. The packet was DNAT'ed to a device in the same bridge |
| 237 | * port group as it was received on. We can still bridge |
| 238 | * the packet. |
| 239 | * 2. The packet was DNAT'ed to a different device, either |
| 240 | * a non-bridged device or another bridge port group. |
| 241 | * The packet will need to be routed. |
| 242 | * |
| 243 | * The correct way of distinguishing between these two cases is to |
| 244 | * call ip_route_input() and to look at skb->dst->dev, which is |
| 245 | * changed to the destination device if ip_route_input() succeeds. |
| 246 | * |
| 247 | * Let us first consider the case that ip_route_input() succeeds: |
| 248 | * |
| 249 | * If skb->dst->dev equals the logical bridge device the packet |
| 250 | * came in on, we can consider this bridging. We then call |
| 251 | * skb->dst->output() which will make the packet enter br_nf_local_out() |
| 252 | * not much later. In that function it is assured that the iptables |
| 253 | * FORWARD chain is traversed for the packet. |
| 254 | * |
| 255 | * Otherwise, the packet is considered to be routed and we just |
| 256 | * change the destination MAC address so that the packet will |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 257 | * later be passed up to the IP stack to be routed. For a redirected |
| 258 | * packet, ip_route_input() will give back the localhost as output device, |
| 259 | * which differs from the bridge device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | * |
| 261 | * Let us now consider the case that ip_route_input() fails: |
| 262 | * |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 263 | * This can be because the destination address is martian, in which case |
| 264 | * the packet will be dropped. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input() |
| 266 | * will fail, while __ip_route_output_key() will return success. The source |
| 267 | * address for __ip_route_output_key() is set to zero, so __ip_route_output_key |
| 268 | * thinks we're handling a locally generated packet and won't care |
| 269 | * if IP forwarding is allowed. We send a warning message to the users's |
| 270 | * log telling her to put IP forwarding on. |
| 271 | * |
| 272 | * ip_route_input() will also fail if there is no route available. |
| 273 | * In that case we just drop the packet. |
| 274 | * |
| 275 | * --Lennert, 20020411 |
| 276 | * --Bart, 20020416 (updated) |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 277 | * --Bart, 20021007 (updated) |
| 278 | * --Bart, 20062711 (updated) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb) |
| 280 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (skb->pkt_type == PACKET_OTHERHOST) { |
| 282 | skb->pkt_type = PACKET_HOST; |
| 283 | skb->nf_bridge->mask |= BRNF_PKT_TYPE; |
| 284 | } |
| 285 | skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING; |
| 286 | |
| 287 | skb->dev = bridge_parent(skb->dev); |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 288 | if (!skb->dev) |
| 289 | kfree_skb(skb); |
| 290 | else { |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 291 | nf_bridge_pull_encap_header(skb); |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 292 | skb->dst->output(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static int br_nf_pre_routing_finish(struct sk_buff *skb) |
| 298 | { |
| 299 | struct net_device *dev = skb->dev; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 300 | struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 302 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | if (nf_bridge->mask & BRNF_PKT_TYPE) { |
| 305 | skb->pkt_type = PACKET_OTHERHOST; |
| 306 | nf_bridge->mask ^= BRNF_PKT_TYPE; |
| 307 | } |
| 308 | nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | if (dnat_took_place(skb)) { |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 310 | if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | struct rtable *rt; |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 312 | struct flowi fl = { |
| 313 | .nl_u = { |
| 314 | .ip4_u = { |
| 315 | .daddr = iph->daddr, |
| 316 | .saddr = 0, |
| 317 | .tos = RT_TOS(iph->tos) }, |
| 318 | }, |
| 319 | .proto = 0, |
| 320 | }; |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 321 | struct in_device *in_dev = in_dev_get(dev); |
| 322 | |
| 323 | /* If err equals -EHOSTUNREACH the error is due to a |
| 324 | * martian destination or due to the fact that |
| 325 | * forwarding is disabled. For most martian packets, |
| 326 | * ip_route_output_key() will fail. It won't fail for 2 types of |
| 327 | * martian destinations: loopback destinations and destination |
| 328 | * 0.0.0.0. In both cases the packet will be dropped because the |
| 329 | * destination is the loopback device and not the bridge. */ |
| 330 | if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev)) |
| 331 | goto free_skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | if (!ip_route_output_key(&rt, &fl)) { |
Bart De Schuymer | 1c011be | 2005-09-14 20:55:16 -0700 | [diff] [blame] | 334 | /* - Bridged-and-DNAT'ed traffic doesn't |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 335 | * require ip_forwarding. */ |
| 336 | if (((struct dst_entry *)rt)->dev == dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | skb->dst = (struct dst_entry *)rt; |
| 338 | goto bridged_dnat; |
| 339 | } |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 340 | /* we are sure that forwarding is disabled, so printing |
| 341 | * this message is no problem. Note that the packet could |
| 342 | * still have a martian destination address, in which case |
| 343 | * the packet could be dropped even if forwarding were enabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | __br_dnat_complain(); |
| 345 | dst_release((struct dst_entry *)rt); |
| 346 | } |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 347 | free_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | kfree_skb(skb); |
| 349 | return 0; |
| 350 | } else { |
| 351 | if (skb->dst->dev == dev) { |
| 352 | bridged_dnat: |
| 353 | /* Tell br_nf_local_out this is a |
| 354 | * bridged frame */ |
| 355 | nf_bridge->mask |= BRNF_BRIDGED_DNAT; |
| 356 | skb->dev = nf_bridge->physindev; |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 357 | nf_bridge_push_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, |
| 359 | skb, skb->dev, NULL, |
| 360 | br_nf_pre_routing_finish_bridge, |
| 361 | 1); |
| 362 | return 0; |
| 363 | } |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 364 | memcpy(eth_hdr(skb)->h_dest, dev->dev_addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | skb->pkt_type = PACKET_HOST; |
| 366 | } |
| 367 | } else { |
| 368 | skb->dst = (struct dst_entry *)&__fake_rtable; |
| 369 | dst_hold(skb->dst); |
| 370 | } |
| 371 | |
| 372 | skb->dev = nf_bridge->physindev; |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 373 | nf_bridge_push_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL, |
| 375 | br_handle_frame_finish, 1); |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | /* Some common code for IPv4/IPv6 */ |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 381 | static struct net_device *setup_pre_routing(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
| 383 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
| 384 | |
| 385 | if (skb->pkt_type == PACKET_OTHERHOST) { |
| 386 | skb->pkt_type = PACKET_HOST; |
| 387 | nf_bridge->mask |= BRNF_PKT_TYPE; |
| 388 | } |
| 389 | |
| 390 | nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING; |
| 391 | nf_bridge->physindev = skb->dev; |
| 392 | skb->dev = bridge_parent(skb->dev); |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 393 | |
| 394 | return skb->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */ |
| 398 | static int check_hbh_len(struct sk_buff *skb) |
| 399 | { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 400 | unsigned char *raw = (u8 *)(ipv6_hdr(skb) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | u32 pkt_len; |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 402 | const unsigned char *nh = skb_network_header(skb); |
| 403 | int off = raw - nh; |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 404 | int len = (raw[1] + 1) << 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | if ((raw + len) - skb->data > skb_headlen(skb)) |
| 407 | goto bad; |
| 408 | |
| 409 | off += 2; |
| 410 | len -= 2; |
| 411 | |
| 412 | while (len > 0) { |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 413 | int optlen = nh[off + 1] + 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 415 | switch (nh[off]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | case IPV6_TLV_PAD0: |
| 417 | optlen = 1; |
| 418 | break; |
| 419 | |
| 420 | case IPV6_TLV_PADN: |
| 421 | break; |
| 422 | |
| 423 | case IPV6_TLV_JUMBO: |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 424 | if (nh[off + 1] != 4 || (off & 3) != 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | goto bad; |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 426 | pkt_len = ntohl(*(__be32 *) (nh + off + 2)); |
Bart De Schuymer | b036648 | 2005-12-19 14:00:08 -0800 | [diff] [blame] | 427 | if (pkt_len <= IPV6_MAXPLEN || |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 428 | ipv6_hdr(skb)->payload_len) |
Bart De Schuymer | b036648 | 2005-12-19 14:00:08 -0800 | [diff] [blame] | 429 | goto bad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | if (pkt_len > skb->len - sizeof(struct ipv6hdr)) |
| 431 | goto bad; |
Bart De Schuymer | b036648 | 2005-12-19 14:00:08 -0800 | [diff] [blame] | 432 | if (pskb_trim_rcsum(skb, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 433 | pkt_len + sizeof(struct ipv6hdr))) |
Bart De Schuymer | b036648 | 2005-12-19 14:00:08 -0800 | [diff] [blame] | 434 | goto bad; |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 435 | nh = skb_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | break; |
| 437 | default: |
| 438 | if (optlen > len) |
| 439 | goto bad; |
| 440 | break; |
| 441 | } |
| 442 | off += optlen; |
| 443 | len -= optlen; |
| 444 | } |
| 445 | if (len == 0) |
| 446 | return 0; |
| 447 | bad: |
| 448 | return -1; |
| 449 | |
| 450 | } |
| 451 | |
| 452 | /* Replicate the checks that IPv6 does on packet reception and pass the packet |
| 453 | * to ip6tables, which doesn't support NAT, so things are fairly simple. */ |
| 454 | static unsigned int br_nf_pre_routing_ipv6(unsigned int hook, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 455 | struct sk_buff *skb, |
| 456 | const struct net_device *in, |
| 457 | const struct net_device *out, |
| 458 | int (*okfn)(struct sk_buff *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { |
| 460 | struct ipv6hdr *hdr; |
| 461 | u32 pkt_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | if (skb->len < sizeof(struct ipv6hdr)) |
| 464 | goto inhdr_error; |
| 465 | |
| 466 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) |
| 467 | goto inhdr_error; |
| 468 | |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 469 | hdr = ipv6_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | if (hdr->version != 6) |
| 472 | goto inhdr_error; |
| 473 | |
| 474 | pkt_len = ntohs(hdr->payload_len); |
| 475 | |
| 476 | if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) { |
| 477 | if (pkt_len + sizeof(struct ipv6hdr) > skb->len) |
| 478 | goto inhdr_error; |
Herbert Xu | b38dfee | 2006-06-09 16:13:01 -0700 | [diff] [blame] | 479 | if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) |
| 480 | goto inhdr_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb)) |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 483 | goto inhdr_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 485 | nf_bridge_put(skb->nf_bridge); |
Stephen Hemminger | fdeabde | 2006-03-20 22:58:21 -0800 | [diff] [blame] | 486 | if (!nf_bridge_alloc(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | return NF_DROP; |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 488 | if (!setup_pre_routing(skb)) |
| 489 | return NF_DROP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
| 491 | NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL, |
| 492 | br_nf_pre_routing_finish_ipv6); |
| 493 | |
| 494 | return NF_STOLEN; |
| 495 | |
| 496 | inhdr_error: |
| 497 | return NF_DROP; |
| 498 | } |
| 499 | |
| 500 | /* Direct IPv6 traffic to br_nf_pre_routing_ipv6. |
| 501 | * Replicate the checks that IPv4 does on packet reception. |
| 502 | * Set skb->dev to the bridge device (i.e. parent of the |
| 503 | * receiving device) to make netfilter happy, the REDIRECT |
| 504 | * target in particular. Save the original destination IP |
| 505 | * address to be able to detect DNAT afterwards. */ |
| 506 | static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb, |
Stephen Hemminger | ee02b3a | 2006-01-06 13:13:29 -0800 | [diff] [blame] | 507 | const struct net_device *in, |
| 508 | const struct net_device *out, |
| 509 | int (*okfn)(struct sk_buff *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
| 511 | struct iphdr *iph; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | struct sk_buff *skb = *pskb; |
Evgeniy Polyakov | e7c243c | 2007-08-24 23:36:29 -0700 | [diff] [blame^] | 513 | __u32 len = nf_bridge_encap_header_len(skb); |
| 514 | |
| 515 | if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) |
| 516 | return NF_STOLEN; |
| 517 | |
| 518 | if (unlikely(!pskb_may_pull(skb, len))) |
| 519 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 521 | if (skb->protocol == htons(ETH_P_IPV6) || IS_VLAN_IPV6(skb) || |
| 522 | IS_PPPOE_IPV6(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | #ifdef CONFIG_SYSCTL |
| 524 | if (!brnf_call_ip6tables) |
| 525 | return NF_ACCEPT; |
| 526 | #endif |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 527 | nf_bridge_pull_encap_header_rcsum(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn); |
| 529 | } |
| 530 | #ifdef CONFIG_SYSCTL |
| 531 | if (!brnf_call_iptables) |
| 532 | return NF_ACCEPT; |
| 533 | #endif |
| 534 | |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 535 | if (skb->protocol != htons(ETH_P_IP) && !IS_VLAN_IP(skb) && |
| 536 | !IS_PPPOE_IP(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return NF_ACCEPT; |
| 538 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 539 | nf_bridge_pull_encap_header_rcsum(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | if (!pskb_may_pull(skb, sizeof(struct iphdr))) |
| 542 | goto inhdr_error; |
| 543 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 544 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (iph->ihl < 5 || iph->version != 4) |
| 546 | goto inhdr_error; |
| 547 | |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 548 | if (!pskb_may_pull(skb, 4 * iph->ihl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | goto inhdr_error; |
| 550 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 551 | iph = ip_hdr(skb); |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 552 | if (ip_fast_csum((__u8 *) iph, iph->ihl) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | goto inhdr_error; |
| 554 | |
| 555 | len = ntohs(iph->tot_len); |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 556 | if (skb->len < len || len < 4 * iph->ihl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | goto inhdr_error; |
| 558 | |
Herbert Xu | b38dfee | 2006-06-09 16:13:01 -0700 | [diff] [blame] | 559 | pskb_trim_rcsum(skb, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 561 | nf_bridge_put(skb->nf_bridge); |
Stephen Hemminger | fdeabde | 2006-03-20 22:58:21 -0800 | [diff] [blame] | 562 | if (!nf_bridge_alloc(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return NF_DROP; |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 564 | if (!setup_pre_routing(skb)) |
| 565 | return NF_DROP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | store_orig_dstaddr(skb); |
| 567 | |
| 568 | NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL, |
| 569 | br_nf_pre_routing_finish); |
| 570 | |
| 571 | return NF_STOLEN; |
| 572 | |
| 573 | inhdr_error: |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 574 | // IP_INC_STATS_BH(IpInHdrErrors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | out: |
| 576 | return NF_DROP; |
| 577 | } |
| 578 | |
| 579 | |
| 580 | /* PF_BRIDGE/LOCAL_IN ************************************************/ |
| 581 | /* The packet is locally destined, which requires a real |
| 582 | * dst_entry, so detach the fake one. On the way up, the |
| 583 | * packet would pass through PRE_ROUTING again (which already |
| 584 | * took place when the packet entered the bridge), but we |
| 585 | * register an IPv4 PRE_ROUTING 'sabotage' hook that will |
| 586 | * prevent this from happening. */ |
| 587 | static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 588 | const struct net_device *in, |
| 589 | const struct net_device *out, |
| 590 | int (*okfn)(struct sk_buff *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
| 592 | struct sk_buff *skb = *pskb; |
| 593 | |
| 594 | if (skb->dst == (struct dst_entry *)&__fake_rtable) { |
| 595 | dst_release(skb->dst); |
| 596 | skb->dst = NULL; |
| 597 | } |
| 598 | |
| 599 | return NF_ACCEPT; |
| 600 | } |
| 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | /* PF_BRIDGE/FORWARD *************************************************/ |
| 603 | static int br_nf_forward_finish(struct sk_buff *skb) |
| 604 | { |
| 605 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
| 606 | struct net_device *in; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 608 | if (skb->protocol != htons(ETH_P_ARP) && !IS_VLAN_ARP(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | in = nf_bridge->physindev; |
| 610 | if (nf_bridge->mask & BRNF_PKT_TYPE) { |
| 611 | skb->pkt_type = PACKET_OTHERHOST; |
| 612 | nf_bridge->mask ^= BRNF_PKT_TYPE; |
| 613 | } |
| 614 | } else { |
| 615 | in = *((struct net_device **)(skb->cb)); |
| 616 | } |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 617 | nf_bridge_push_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 619 | skb->dev, br_forward_finish, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | /* This is the 'purely bridged' case. For IP, we pass the packet to |
| 624 | * netfilter with indev and outdev set to the bridge device, |
| 625 | * but we are still able to filter on the 'real' indev/outdev |
| 626 | * because of the physdev module. For ARP, indev and outdev are the |
| 627 | * bridge ports. */ |
| 628 | static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 629 | const struct net_device *in, |
| 630 | const struct net_device *out, |
| 631 | int (*okfn)(struct sk_buff *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
| 633 | struct sk_buff *skb = *pskb; |
| 634 | struct nf_bridge_info *nf_bridge; |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 635 | struct net_device *parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | int pf; |
| 637 | |
| 638 | if (!skb->nf_bridge) |
| 639 | return NF_ACCEPT; |
| 640 | |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 641 | parent = bridge_parent(out); |
| 642 | if (!parent) |
| 643 | return NF_DROP; |
| 644 | |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 645 | if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb) || |
| 646 | IS_PPPOE_IP(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | pf = PF_INET; |
| 648 | else |
| 649 | pf = PF_INET6; |
| 650 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 651 | nf_bridge_pull_encap_header(*pskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | nf_bridge = skb->nf_bridge; |
| 654 | if (skb->pkt_type == PACKET_OTHERHOST) { |
| 655 | skb->pkt_type = PACKET_HOST; |
| 656 | nf_bridge->mask |= BRNF_PKT_TYPE; |
| 657 | } |
| 658 | |
| 659 | /* The physdev module checks on this */ |
| 660 | nf_bridge->mask |= BRNF_BRIDGED; |
| 661 | nf_bridge->physoutdev = skb->dev; |
| 662 | |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 663 | NF_HOOK(pf, NF_IP_FORWARD, skb, bridge_parent(in), parent, |
| 664 | br_nf_forward_finish); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
| 666 | return NF_STOLEN; |
| 667 | } |
| 668 | |
| 669 | static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 670 | const struct net_device *in, |
| 671 | const struct net_device *out, |
| 672 | int (*okfn)(struct sk_buff *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
| 674 | struct sk_buff *skb = *pskb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | struct net_device **d = (struct net_device **)(skb->cb); |
| 676 | |
| 677 | #ifdef CONFIG_SYSCTL |
| 678 | if (!brnf_call_arptables) |
| 679 | return NF_ACCEPT; |
| 680 | #endif |
| 681 | |
Stephen Hemminger | f8a2602 | 2006-03-20 22:57:46 -0800 | [diff] [blame] | 682 | if (skb->protocol != htons(ETH_P_ARP)) { |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 683 | if (!IS_VLAN_ARP(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | return NF_ACCEPT; |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 685 | nf_bridge_pull_encap_header(*pskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Arnaldo Carvalho de Melo | d0a92be | 2007-03-12 20:56:31 -0300 | [diff] [blame] | 688 | if (arp_hdr(skb)->ar_pln != 4) { |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 689 | if (IS_VLAN_ARP(skb)) |
| 690 | nf_bridge_push_encap_header(*pskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | return NF_ACCEPT; |
| 692 | } |
| 693 | *d = (struct net_device *)in; |
| 694 | NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in, |
| 695 | (struct net_device *)out, br_nf_forward_finish); |
| 696 | |
| 697 | return NF_STOLEN; |
| 698 | } |
| 699 | |
Patrick McHardy | 2bf540b | 2006-12-13 16:54:25 -0800 | [diff] [blame] | 700 | /* PF_BRIDGE/LOCAL_OUT *********************************************** |
| 701 | * |
| 702 | * This function sees both locally originated IP packets and forwarded |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | * IP packets (in both cases the destination device is a bridge |
| 704 | * device). It also sees bridged-and-DNAT'ed packets. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | * |
| 706 | * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged |
| 707 | * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward() |
| 708 | * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority |
| 709 | * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor |
| 710 | * will be executed. |
Patrick McHardy | 2bf540b | 2006-12-13 16:54:25 -0800 | [diff] [blame] | 711 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 713 | const struct net_device *in, |
| 714 | const struct net_device *out, |
| 715 | int (*okfn)(struct sk_buff *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | { |
Patrick McHardy | 2bf540b | 2006-12-13 16:54:25 -0800 | [diff] [blame] | 717 | struct net_device *realindev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | struct sk_buff *skb = *pskb; |
| 719 | struct nf_bridge_info *nf_bridge; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
| 721 | if (!skb->nf_bridge) |
| 722 | return NF_ACCEPT; |
| 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | nf_bridge = skb->nf_bridge; |
Patrick McHardy | 2bf540b | 2006-12-13 16:54:25 -0800 | [diff] [blame] | 725 | if (!(nf_bridge->mask & BRNF_BRIDGED_DNAT)) |
| 726 | return NF_ACCEPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
| 728 | /* Bridged, take PF_BRIDGE/FORWARD. |
| 729 | * (see big note in front of br_nf_pre_routing_finish) */ |
Patrick McHardy | 2bf540b | 2006-12-13 16:54:25 -0800 | [diff] [blame] | 730 | nf_bridge->physoutdev = skb->dev; |
| 731 | realindev = nf_bridge->physindev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Patrick McHardy | 2bf540b | 2006-12-13 16:54:25 -0800 | [diff] [blame] | 733 | if (nf_bridge->mask & BRNF_PKT_TYPE) { |
| 734 | skb->pkt_type = PACKET_OTHERHOST; |
| 735 | nf_bridge->mask ^= BRNF_PKT_TYPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 737 | nf_bridge_push_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Patrick McHardy | 2bf540b | 2006-12-13 16:54:25 -0800 | [diff] [blame] | 739 | NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev, skb->dev, |
| 740 | br_forward_finish); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | return NF_STOLEN; |
| 742 | } |
| 743 | |
Patrick McHardy | 2e2f7ae | 2006-04-04 13:42:35 -0700 | [diff] [blame] | 744 | static int br_nf_dev_queue_xmit(struct sk_buff *skb) |
| 745 | { |
| 746 | if (skb->protocol == htons(ETH_P_IP) && |
| 747 | skb->len > skb->dev->mtu && |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 748 | !skb_is_gso(skb)) |
Patrick McHardy | 2e2f7ae | 2006-04-04 13:42:35 -0700 | [diff] [blame] | 749 | return ip_fragment(skb, br_dev_queue_push_xmit); |
| 750 | else |
| 751 | return br_dev_queue_push_xmit(skb); |
| 752 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | /* PF_BRIDGE/POST_ROUTING ********************************************/ |
| 755 | static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 756 | const struct net_device *in, |
| 757 | const struct net_device *out, |
| 758 | int (*okfn)(struct sk_buff *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | { |
| 760 | struct sk_buff *skb = *pskb; |
| 761 | struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | struct net_device *realoutdev = bridge_parent(skb->dev); |
| 763 | int pf; |
| 764 | |
| 765 | #ifdef CONFIG_NETFILTER_DEBUG |
| 766 | /* Be very paranoid. This probably won't happen anymore, but let's |
| 767 | * keep the check just to be sure... */ |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 768 | if (skb_mac_header(skb) < skb->head || |
| 769 | skb_mac_header(skb) + ETH_HLEN > skb->data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: " |
Stephen Hemminger | 8394e9b | 2006-08-29 17:49:31 -0700 | [diff] [blame] | 771 | "bad mac.raw pointer.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | goto print_error; |
| 773 | } |
| 774 | #endif |
| 775 | |
| 776 | if (!nf_bridge) |
| 777 | return NF_ACCEPT; |
| 778 | |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 779 | if (!realoutdev) |
| 780 | return NF_DROP; |
| 781 | |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 782 | if (skb->protocol == htons(ETH_P_IP) || IS_VLAN_IP(skb) || |
| 783 | IS_PPPOE_IP(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | pf = PF_INET; |
| 785 | else |
| 786 | pf = PF_INET6; |
| 787 | |
| 788 | #ifdef CONFIG_NETFILTER_DEBUG |
| 789 | if (skb->dst == NULL) { |
Stephen Hemminger | 8394e9b | 2006-08-29 17:49:31 -0700 | [diff] [blame] | 790 | printk(KERN_INFO "br_netfilter post_routing: skb->dst == NULL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | goto print_error; |
| 792 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | #endif |
| 794 | |
| 795 | /* We assume any code from br_dev_queue_push_xmit onwards doesn't care |
| 796 | * about the value of skb->pkt_type. */ |
| 797 | if (skb->pkt_type == PACKET_OTHERHOST) { |
| 798 | skb->pkt_type = PACKET_HOST; |
| 799 | nf_bridge->mask |= BRNF_PKT_TYPE; |
| 800 | } |
| 801 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 802 | nf_bridge_pull_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | nf_bridge_save_header(skb); |
| 804 | |
| 805 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
| 806 | if (nf_bridge->netoutdev) |
| 807 | realoutdev = nf_bridge->netoutdev; |
| 808 | #endif |
| 809 | NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL, realoutdev, |
Patrick McHardy | 2e2f7ae | 2006-04-04 13:42:35 -0700 | [diff] [blame] | 810 | br_nf_dev_queue_xmit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
| 812 | return NF_STOLEN; |
| 813 | |
| 814 | #ifdef CONFIG_NETFILTER_DEBUG |
| 815 | print_error: |
| 816 | if (skb->dev != NULL) { |
| 817 | printk("[%s]", skb->dev->name); |
Stephen Hemminger | 178a325 | 2006-02-13 15:43:58 -0800 | [diff] [blame] | 818 | if (realoutdev) |
| 819 | printk("[%s]", realoutdev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 821 | printk(" head:%p, raw:%p, data:%p\n", skb->head, skb_mac_header(skb), |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 822 | skb->data); |
Stephen Hemminger | 8394e9b | 2006-08-29 17:49:31 -0700 | [diff] [blame] | 823 | dump_stack(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | return NF_ACCEPT; |
| 825 | #endif |
| 826 | } |
| 827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | /* IP/SABOTAGE *****************************************************/ |
| 829 | /* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING |
| 830 | * for the second time. */ |
| 831 | static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb, |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 832 | const struct net_device *in, |
| 833 | const struct net_device *out, |
| 834 | int (*okfn)(struct sk_buff *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | { |
| 836 | if ((*pskb)->nf_bridge && |
| 837 | !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) { |
| 838 | return NF_STOP; |
| 839 | } |
| 840 | |
| 841 | return NF_ACCEPT; |
| 842 | } |
| 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | /* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent |
| 845 | * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input. |
| 846 | * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because |
| 847 | * ip_refrag() can return NF_STOLEN. */ |
| 848 | static struct nf_hook_ops br_nf_ops[] = { |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 849 | { .hook = br_nf_pre_routing, |
| 850 | .owner = THIS_MODULE, |
| 851 | .pf = PF_BRIDGE, |
| 852 | .hooknum = NF_BR_PRE_ROUTING, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | .priority = NF_BR_PRI_BRNF, }, |
| 854 | { .hook = br_nf_local_in, |
| 855 | .owner = THIS_MODULE, |
| 856 | .pf = PF_BRIDGE, |
| 857 | .hooknum = NF_BR_LOCAL_IN, |
| 858 | .priority = NF_BR_PRI_BRNF, }, |
| 859 | { .hook = br_nf_forward_ip, |
| 860 | .owner = THIS_MODULE, |
| 861 | .pf = PF_BRIDGE, |
| 862 | .hooknum = NF_BR_FORWARD, |
| 863 | .priority = NF_BR_PRI_BRNF - 1, }, |
| 864 | { .hook = br_nf_forward_arp, |
| 865 | .owner = THIS_MODULE, |
| 866 | .pf = PF_BRIDGE, |
| 867 | .hooknum = NF_BR_FORWARD, |
| 868 | .priority = NF_BR_PRI_BRNF, }, |
| 869 | { .hook = br_nf_local_out, |
| 870 | .owner = THIS_MODULE, |
| 871 | .pf = PF_BRIDGE, |
| 872 | .hooknum = NF_BR_LOCAL_OUT, |
| 873 | .priority = NF_BR_PRI_FIRST, }, |
| 874 | { .hook = br_nf_post_routing, |
| 875 | .owner = THIS_MODULE, |
| 876 | .pf = PF_BRIDGE, |
| 877 | .hooknum = NF_BR_POST_ROUTING, |
| 878 | .priority = NF_BR_PRI_LAST, }, |
| 879 | { .hook = ip_sabotage_in, |
| 880 | .owner = THIS_MODULE, |
| 881 | .pf = PF_INET, |
| 882 | .hooknum = NF_IP_PRE_ROUTING, |
| 883 | .priority = NF_IP_PRI_FIRST, }, |
| 884 | { .hook = ip_sabotage_in, |
| 885 | .owner = THIS_MODULE, |
| 886 | .pf = PF_INET6, |
| 887 | .hooknum = NF_IP6_PRE_ROUTING, |
| 888 | .priority = NF_IP6_PRI_FIRST, }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | }; |
| 890 | |
| 891 | #ifdef CONFIG_SYSCTL |
| 892 | static |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 893 | int brnf_sysctl_call_tables(ctl_table * ctl, int write, struct file *filp, |
| 894 | void __user * buffer, size_t * lenp, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | { |
| 896 | int ret; |
| 897 | |
| 898 | ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); |
| 899 | |
| 900 | if (write && *(int *)(ctl->data)) |
| 901 | *(int *)(ctl->data) = 1; |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | static ctl_table brnf_table[] = { |
| 906 | { |
| 907 | .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES, |
| 908 | .procname = "bridge-nf-call-arptables", |
| 909 | .data = &brnf_call_arptables, |
| 910 | .maxlen = sizeof(int), |
| 911 | .mode = 0644, |
| 912 | .proc_handler = &brnf_sysctl_call_tables, |
| 913 | }, |
| 914 | { |
| 915 | .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES, |
| 916 | .procname = "bridge-nf-call-iptables", |
| 917 | .data = &brnf_call_iptables, |
| 918 | .maxlen = sizeof(int), |
| 919 | .mode = 0644, |
| 920 | .proc_handler = &brnf_sysctl_call_tables, |
| 921 | }, |
| 922 | { |
| 923 | .ctl_name = NET_BRIDGE_NF_CALL_IP6TABLES, |
| 924 | .procname = "bridge-nf-call-ip6tables", |
| 925 | .data = &brnf_call_ip6tables, |
| 926 | .maxlen = sizeof(int), |
| 927 | .mode = 0644, |
| 928 | .proc_handler = &brnf_sysctl_call_tables, |
| 929 | }, |
| 930 | { |
| 931 | .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED, |
| 932 | .procname = "bridge-nf-filter-vlan-tagged", |
| 933 | .data = &brnf_filter_vlan_tagged, |
| 934 | .maxlen = sizeof(int), |
| 935 | .mode = 0644, |
| 936 | .proc_handler = &brnf_sysctl_call_tables, |
| 937 | }, |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 938 | { |
| 939 | .ctl_name = NET_BRIDGE_NF_FILTER_PPPOE_TAGGED, |
| 940 | .procname = "bridge-nf-filter-pppoe-tagged", |
| 941 | .data = &brnf_filter_pppoe_tagged, |
| 942 | .maxlen = sizeof(int), |
| 943 | .mode = 0644, |
| 944 | .proc_handler = &brnf_sysctl_call_tables, |
| 945 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { .ctl_name = 0 } |
| 947 | }; |
| 948 | |
| 949 | static ctl_table brnf_bridge_table[] = { |
| 950 | { |
| 951 | .ctl_name = NET_BRIDGE, |
| 952 | .procname = "bridge", |
| 953 | .mode = 0555, |
| 954 | .child = brnf_table, |
| 955 | }, |
| 956 | { .ctl_name = 0 } |
| 957 | }; |
| 958 | |
| 959 | static ctl_table brnf_net_table[] = { |
| 960 | { |
| 961 | .ctl_name = CTL_NET, |
| 962 | .procname = "net", |
| 963 | .mode = 0555, |
| 964 | .child = brnf_bridge_table, |
| 965 | }, |
| 966 | { .ctl_name = 0 } |
| 967 | }; |
| 968 | #endif |
| 969 | |
Patrick McHardy | 5eb87f4 | 2007-02-07 15:07:22 -0800 | [diff] [blame] | 970 | int __init br_netfilter_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | { |
Patrick McHardy | 5eb87f4 | 2007-02-07 15:07:22 -0800 | [diff] [blame] | 972 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
Patrick McHardy | 5eb87f4 | 2007-02-07 15:07:22 -0800 | [diff] [blame] | 974 | ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
| 975 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | #ifdef CONFIG_SYSCTL |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 978 | brnf_sysctl_header = register_sysctl_table(brnf_net_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | if (brnf_sysctl_header == NULL) { |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 980 | printk(KERN_WARNING |
| 981 | "br_netfilter: can't register to sysctl.\n"); |
Patrick McHardy | 5eb87f4 | 2007-02-07 15:07:22 -0800 | [diff] [blame] | 982 | nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
| 983 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | } |
| 985 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | printk(KERN_NOTICE "Bridge firewalling registered\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | void br_netfilter_fini(void) |
| 991 | { |
Patrick McHardy | 5eb87f4 | 2007-02-07 15:07:22 -0800 | [diff] [blame] | 992 | nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | #ifdef CONFIG_SYSCTL |
| 994 | unregister_sysctl_table(brnf_sysctl_header); |
| 995 | #endif |
| 996 | } |