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