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