Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Handle firewalling |
| 3 | * Linux ethernet bridge |
| 4 | * |
| 5 | * Authors: |
Bart De Schuymer | 8237908 | 2010-04-13 11:40:41 +0200 | [diff] [blame] | 6 | * Lennert Buytenhek <buytenh@gnu.org> |
| 7 | * Bart De Schuymer <bdschuym@pandora.be> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * Lennert dedicates this file to Kerstin Wurdinger. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/ip.h> |
| 21 | #include <linux/netdevice.h> |
| 22 | #include <linux/skbuff.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 23 | #include <linux/if_arp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/if_ether.h> |
| 25 | #include <linux/if_vlan.h> |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 26 | #include <linux/if_pppox.h> |
| 27 | #include <linux/ppp_defs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/netfilter_bridge.h> |
| 29 | #include <linux/netfilter_ipv4.h> |
| 30 | #include <linux/netfilter_ipv6.h> |
| 31 | #include <linux/netfilter_arp.h> |
| 32 | #include <linux/in_route.h> |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 33 | #include <linux/inetdevice.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <net/ip.h> |
| 36 | #include <net/ipv6.h> |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 37 | #include <net/addrconf.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 38 | #include <net/route.h> |
Florian Westphal | 5676864 | 2014-11-13 10:04:16 +0100 | [diff] [blame] | 39 | #include <net/netfilter/br_netfilter.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 <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "br_private.h" |
| 43 | #ifdef CONFIG_SYSCTL |
| 44 | #include <linux/sysctl.h> |
| 45 | #endif |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #ifdef CONFIG_SYSCTL |
| 48 | static struct ctl_table_header *brnf_sysctl_header; |
Brian Haley | 9c1ea14 | 2006-09-18 00:03:41 -0700 | [diff] [blame] | 49 | static int brnf_call_iptables __read_mostly = 1; |
| 50 | static int brnf_call_ip6tables __read_mostly = 1; |
| 51 | static int brnf_call_arptables __read_mostly = 1; |
Bernhard Thaler | f4b3eee | 2015-07-30 06:06:12 +0200 | [diff] [blame^] | 52 | static int brnf_filter_vlan_tagged __read_mostly; |
| 53 | static int brnf_filter_pppoe_tagged __read_mostly; |
| 54 | static int brnf_pass_vlan_indev __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #else |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 56 | #define brnf_call_iptables 1 |
| 57 | #define brnf_call_ip6tables 1 |
| 58 | #define brnf_call_arptables 1 |
Herbert Xu | 47e0e1c | 2009-01-12 00:06:03 +0000 | [diff] [blame] | 59 | #define brnf_filter_vlan_tagged 0 |
| 60 | #define brnf_filter_pppoe_tagged 0 |
Pablo Neira Ayuso | 4981682 | 2012-05-08 19:36:44 +0200 | [diff] [blame] | 61 | #define brnf_pass_vlan_indev 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #endif |
| 63 | |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 64 | #define IS_IP(skb) \ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 65 | (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_IP)) |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 66 | |
| 67 | #define IS_IPV6(skb) \ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 68 | (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_IPV6)) |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 69 | |
| 70 | #define IS_ARP(skb) \ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 71 | (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_ARP)) |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 72 | |
Dave Jones | b6f99a2 | 2007-03-22 12:27:49 -0700 | [diff] [blame] | 73 | static inline __be16 vlan_proto(const struct sk_buff *skb) |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 74 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 75 | if (skb_vlan_tag_present(skb)) |
Jesse Gross | 1393791 | 2010-10-20 13:56:01 +0000 | [diff] [blame] | 76 | return skb->protocol; |
| 77 | else if (skb->protocol == htons(ETH_P_8021Q)) |
| 78 | return vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 79 | else |
| 80 | return 0; |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | #define IS_VLAN_IP(skb) \ |
Jesse Gross | 1393791 | 2010-10-20 13:56:01 +0000 | [diff] [blame] | 84 | (vlan_proto(skb) == htons(ETH_P_IP) && \ |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 85 | brnf_filter_vlan_tagged) |
| 86 | |
| 87 | #define IS_VLAN_IPV6(skb) \ |
Jesse Gross | 1393791 | 2010-10-20 13:56:01 +0000 | [diff] [blame] | 88 | (vlan_proto(skb) == htons(ETH_P_IPV6) && \ |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 89 | brnf_filter_vlan_tagged) |
| 90 | |
| 91 | #define IS_VLAN_ARP(skb) \ |
Jesse Gross | 1393791 | 2010-10-20 13:56:01 +0000 | [diff] [blame] | 92 | (vlan_proto(skb) == htons(ETH_P_ARP) && \ |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 93 | brnf_filter_vlan_tagged) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 95 | static inline __be16 pppoe_proto(const struct sk_buff *skb) |
| 96 | { |
| 97 | return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN + |
| 98 | sizeof(struct pppoe_hdr))); |
| 99 | } |
| 100 | |
| 101 | #define IS_PPPOE_IP(skb) \ |
| 102 | (skb->protocol == htons(ETH_P_PPP_SES) && \ |
| 103 | pppoe_proto(skb) == htons(PPP_IP) && \ |
| 104 | brnf_filter_pppoe_tagged) |
| 105 | |
| 106 | #define IS_PPPOE_IPV6(skb) \ |
| 107 | (skb->protocol == htons(ETH_P_PPP_SES) && \ |
| 108 | pppoe_proto(skb) == htons(PPP_IPV6) && \ |
| 109 | brnf_filter_pppoe_tagged) |
| 110 | |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 111 | /* largest possible L2 header, see br_nf_dev_queue_xmit() */ |
| 112 | #define NF_BRIDGE_MAX_MAC_HEADER_LENGTH (PPPOE_SES_HLEN + ETH_HLEN) |
| 113 | |
Bernhard Thaler | a1bc1b3 | 2015-06-20 00:17:50 +0200 | [diff] [blame] | 114 | #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) || IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 115 | struct brnf_frag_data { |
| 116 | char mac[NF_BRIDGE_MAX_MAC_HEADER_LENGTH]; |
| 117 | u8 encap_size; |
| 118 | u8 size; |
Florian Westphal | d7b5974 | 2015-06-05 13:27:13 +0200 | [diff] [blame] | 119 | u16 vlan_tci; |
| 120 | __be16 vlan_proto; |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | static DEFINE_PER_CPU(struct brnf_frag_data, brnf_frag_data_storage); |
| 124 | #endif |
| 125 | |
Florian Westphal | a9fcc6a | 2015-05-03 22:06:07 +0200 | [diff] [blame] | 126 | static void nf_bridge_info_free(struct sk_buff *skb) |
| 127 | { |
| 128 | if (skb->nf_bridge) { |
| 129 | nf_bridge_put(skb->nf_bridge); |
| 130 | skb->nf_bridge = NULL; |
| 131 | } |
| 132 | } |
| 133 | |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 134 | static inline struct net_device *bridge_parent(const struct net_device *dev) |
| 135 | { |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 136 | struct net_bridge_port *port; |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 137 | |
stephen hemminger | b5ed54e | 2010-11-15 06:38:13 +0000 | [diff] [blame] | 138 | port = br_port_get_rcu(dev); |
| 139 | return port ? port->br->dev : NULL; |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Patrick McHardy | 2dc2f20 | 2008-01-20 06:25:48 -0800 | [diff] [blame] | 142 | static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb) |
| 143 | { |
| 144 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
| 145 | |
| 146 | if (atomic_read(&nf_bridge->use) > 1) { |
| 147 | struct nf_bridge_info *tmp = nf_bridge_alloc(skb); |
| 148 | |
| 149 | if (tmp) { |
| 150 | memcpy(tmp, nf_bridge, sizeof(struct nf_bridge_info)); |
| 151 | atomic_set(&tmp->use, 1); |
Patrick McHardy | 2dc2f20 | 2008-01-20 06:25:48 -0800 | [diff] [blame] | 152 | } |
Changli Gao | 4c3a76a | 2010-08-22 19:03:26 +0000 | [diff] [blame] | 153 | nf_bridge_put(nf_bridge); |
Patrick McHardy | 2dc2f20 | 2008-01-20 06:25:48 -0800 | [diff] [blame] | 154 | nf_bridge = tmp; |
| 155 | } |
| 156 | return nf_bridge; |
| 157 | } |
| 158 | |
Pablo Neira Ayuso | 230ac49 | 2015-06-16 14:07:03 +0200 | [diff] [blame] | 159 | unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb) |
Florian Westphal | 8d04516 | 2015-03-18 20:55:31 +0100 | [diff] [blame] | 160 | { |
| 161 | switch (skb->protocol) { |
| 162 | case __cpu_to_be16(ETH_P_8021Q): |
| 163 | return VLAN_HLEN; |
| 164 | case __cpu_to_be16(ETH_P_PPP_SES): |
| 165 | return PPPOE_SES_HLEN; |
| 166 | default: |
| 167 | return 0; |
| 168 | } |
| 169 | } |
| 170 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 171 | static inline void nf_bridge_pull_encap_header(struct sk_buff *skb) |
| 172 | { |
| 173 | unsigned int len = nf_bridge_encap_header_len(skb); |
| 174 | |
| 175 | skb_pull(skb, len); |
| 176 | skb->network_header += len; |
| 177 | } |
| 178 | |
| 179 | static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb) |
| 180 | { |
| 181 | unsigned int len = nf_bridge_encap_header_len(skb); |
| 182 | |
| 183 | skb_pull_rcsum(skb, len); |
| 184 | skb->network_header += len; |
| 185 | } |
| 186 | |
Bandan Das | 462fb2a | 2010-09-19 09:34:33 +0000 | [diff] [blame] | 187 | /* When handing a packet over to the IP layer |
| 188 | * check whether we have a skb that is in the |
| 189 | * expected format |
| 190 | */ |
| 191 | |
Bernhard Thaler | 77d574e | 2015-05-30 15:29:02 +0200 | [diff] [blame] | 192 | static int br_validate_ipv4(struct sk_buff *skb) |
Bandan Das | 462fb2a | 2010-09-19 09:34:33 +0000 | [diff] [blame] | 193 | { |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 194 | const struct iphdr *iph; |
Bandan Das | 462fb2a | 2010-09-19 09:34:33 +0000 | [diff] [blame] | 195 | struct net_device *dev = skb->dev; |
| 196 | u32 len; |
| 197 | |
Sarveshwar Bandi | 6caab7b | 2012-10-10 01:15:01 +0000 | [diff] [blame] | 198 | if (!pskb_may_pull(skb, sizeof(struct iphdr))) |
| 199 | goto inhdr_error; |
| 200 | |
Bandan Das | 462fb2a | 2010-09-19 09:34:33 +0000 | [diff] [blame] | 201 | iph = ip_hdr(skb); |
Bandan Das | 462fb2a | 2010-09-19 09:34:33 +0000 | [diff] [blame] | 202 | |
| 203 | /* Basic sanity checks */ |
| 204 | if (iph->ihl < 5 || iph->version != 4) |
| 205 | goto inhdr_error; |
| 206 | |
| 207 | if (!pskb_may_pull(skb, iph->ihl*4)) |
| 208 | goto inhdr_error; |
| 209 | |
| 210 | iph = ip_hdr(skb); |
| 211 | if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) |
| 212 | goto inhdr_error; |
| 213 | |
| 214 | len = ntohs(iph->tot_len); |
| 215 | if (skb->len < len) { |
| 216 | IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INTRUNCATEDPKTS); |
| 217 | goto drop; |
| 218 | } else if (len < (iph->ihl*4)) |
| 219 | goto inhdr_error; |
| 220 | |
| 221 | if (pskb_trim_rcsum(skb, len)) { |
| 222 | IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INDISCARDS); |
| 223 | goto drop; |
| 224 | } |
| 225 | |
Eric Dumazet | f8e9881 | 2011-04-12 13:39:14 -0700 | [diff] [blame] | 226 | memset(IPCB(skb), 0, sizeof(struct inet_skb_parm)); |
Herbert Xu | 7677e86 | 2014-10-04 22:18:02 +0800 | [diff] [blame] | 227 | /* We should really parse IP options here but until |
| 228 | * somebody who actually uses IP options complains to |
| 229 | * us we'll just silently ignore the options because |
| 230 | * we're lazy! |
| 231 | */ |
Bandan Das | 462fb2a | 2010-09-19 09:34:33 +0000 | [diff] [blame] | 232 | return 0; |
| 233 | |
| 234 | inhdr_error: |
| 235 | IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INHDRERRORS); |
| 236 | drop: |
| 237 | return -1; |
| 238 | } |
| 239 | |
Pablo Neira Ayuso | 230ac49 | 2015-06-16 14:07:03 +0200 | [diff] [blame] | 240 | void nf_bridge_update_protocol(struct sk_buff *skb) |
Florian Westphal | 4a9d2f2 | 2015-03-05 00:52:34 +0100 | [diff] [blame] | 241 | { |
Florian Westphal | 3eaf402 | 2015-04-02 14:31:44 +0200 | [diff] [blame] | 242 | switch (skb->nf_bridge->orig_proto) { |
| 243 | case BRNF_PROTO_8021Q: |
Florian Westphal | 4a9d2f2 | 2015-03-05 00:52:34 +0100 | [diff] [blame] | 244 | skb->protocol = htons(ETH_P_8021Q); |
Florian Westphal | 3eaf402 | 2015-04-02 14:31:44 +0200 | [diff] [blame] | 245 | break; |
| 246 | case BRNF_PROTO_PPPOE: |
Florian Westphal | 4a9d2f2 | 2015-03-05 00:52:34 +0100 | [diff] [blame] | 247 | skb->protocol = htons(ETH_P_PPP_SES); |
Florian Westphal | 3eaf402 | 2015-04-02 14:31:44 +0200 | [diff] [blame] | 248 | break; |
| 249 | case BRNF_PROTO_UNCHANGED: |
| 250 | break; |
| 251 | } |
Florian Westphal | 4a9d2f2 | 2015-03-05 00:52:34 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 254 | /* Obtain the correct destination MAC address, while preserving the original |
| 255 | * source MAC address. If we already know this address, we just copy it. If we |
| 256 | * don't, we use the neighbour framework to find out. In both cases, we make |
| 257 | * sure that br_handle_frame_finish() is called afterwards. |
| 258 | */ |
Pablo Neira Ayuso | 230ac49 | 2015-06-16 14:07:03 +0200 | [diff] [blame] | 259 | int br_nf_pre_routing_finish_bridge(struct sock *sk, struct sk_buff *skb) |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 260 | { |
David S. Miller | f6b72b6 | 2011-07-14 07:53:20 -0700 | [diff] [blame] | 261 | struct neighbour *neigh; |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 262 | struct dst_entry *dst; |
| 263 | |
| 264 | skb->dev = bridge_parent(skb->dev); |
| 265 | if (!skb->dev) |
| 266 | goto free_skb; |
| 267 | dst = skb_dst(skb); |
David S. Miller | f9d7516 | 2012-07-02 22:12:59 -0700 | [diff] [blame] | 268 | neigh = dst_neigh_lookup_skb(dst, skb); |
| 269 | if (neigh) { |
Florian Westphal | 3833078 | 2015-04-02 14:31:43 +0200 | [diff] [blame] | 270 | struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); |
David S. Miller | f9d7516 | 2012-07-02 22:12:59 -0700 | [diff] [blame] | 271 | int ret; |
| 272 | |
| 273 | if (neigh->hh.hh_len) { |
| 274 | neigh_hh_bridge(&neigh->hh, skb); |
| 275 | skb->dev = nf_bridge->physindev; |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 276 | ret = br_handle_frame_finish(sk, skb); |
David S. Miller | f9d7516 | 2012-07-02 22:12:59 -0700 | [diff] [blame] | 277 | } else { |
| 278 | /* the neighbour function below overwrites the complete |
| 279 | * MAC header, so we save the Ethernet source address and |
| 280 | * protocol number. |
| 281 | */ |
| 282 | skb_copy_from_linear_data_offset(skb, |
| 283 | -(ETH_HLEN-ETH_ALEN), |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 284 | nf_bridge->neigh_header, |
David S. Miller | f9d7516 | 2012-07-02 22:12:59 -0700 | [diff] [blame] | 285 | ETH_HLEN-ETH_ALEN); |
| 286 | /* tell br_dev_xmit to continue with forwarding */ |
Florian Westphal | 72b1e5e | 2015-07-23 16:21:30 +0200 | [diff] [blame] | 287 | nf_bridge->bridged_dnat = 1; |
Herbert Xu | 93fdd47 | 2014-10-05 12:00:22 +0800 | [diff] [blame] | 288 | /* FIXME Need to refragment */ |
David S. Miller | f9d7516 | 2012-07-02 22:12:59 -0700 | [diff] [blame] | 289 | ret = neigh->output(neigh, skb); |
| 290 | } |
| 291 | neigh_release(neigh); |
| 292 | return ret; |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 293 | } |
| 294 | free_skb: |
| 295 | kfree_skb(skb); |
| 296 | return 0; |
| 297 | } |
| 298 | |
Pablo Neira Ayuso | 230ac49 | 2015-06-16 14:07:03 +0200 | [diff] [blame] | 299 | static inline bool |
| 300 | br_nf_ipv4_daddr_was_changed(const struct sk_buff *skb, |
| 301 | const struct nf_bridge_info *nf_bridge) |
Florian Westphal | c055d5b | 2015-03-10 05:08:19 +0100 | [diff] [blame] | 302 | { |
Pablo Neira Ayuso | 230ac49 | 2015-06-16 14:07:03 +0200 | [diff] [blame] | 303 | return ip_hdr(skb)->daddr != nf_bridge->ipv4_daddr; |
Bernhard Thaler | 8cae308 | 2015-05-30 15:26:57 +0200 | [diff] [blame] | 304 | } |
| 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | /* This requires some explaining. If DNAT has taken place, |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 307 | * we will need to fix up the destination Ethernet address. |
Florian Westphal | faecbb4 | 2015-05-20 13:42:25 +0200 | [diff] [blame] | 308 | * This is also true when SNAT takes place (for the reply direction). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | * |
| 310 | * There are two cases to consider: |
| 311 | * 1. The packet was DNAT'ed to a device in the same bridge |
| 312 | * port group as it was received on. We can still bridge |
| 313 | * the packet. |
| 314 | * 2. The packet was DNAT'ed to a different device, either |
| 315 | * a non-bridged device or another bridge port group. |
| 316 | * The packet will need to be routed. |
| 317 | * |
| 318 | * The correct way of distinguishing between these two cases is to |
| 319 | * call ip_route_input() and to look at skb->dst->dev, which is |
| 320 | * changed to the destination device if ip_route_input() succeeds. |
| 321 | * |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 322 | * Let's first consider the case that ip_route_input() succeeds: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | * |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 324 | * If the output device equals the logical bridge device the packet |
| 325 | * came in on, we can consider this bridging. The corresponding MAC |
| 326 | * address will be obtained in br_nf_pre_routing_finish_bridge. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | * Otherwise, the packet is considered to be routed and we just |
| 328 | * change the destination MAC address so that the packet will |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 329 | * later be passed up to the IP stack to be routed. For a redirected |
| 330 | * packet, ip_route_input() will give back the localhost as output device, |
| 331 | * which differs from the bridge device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | * |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 333 | * Let's now consider the case that ip_route_input() fails: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | * |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 335 | * This can be because the destination address is martian, in which case |
| 336 | * the packet will be dropped. |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 337 | * If IP forwarding is disabled, ip_route_input() will fail, while |
| 338 | * ip_route_output_key() can return success. The source |
| 339 | * address for ip_route_output_key() is set to zero, so ip_route_output_key() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | * thinks we're handling a locally generated packet and won't care |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 341 | * if IP forwarding is enabled. If the output device equals the logical bridge |
| 342 | * device, we proceed as if ip_route_input() succeeded. If it differs from the |
| 343 | * logical bridge port or if ip_route_output_key() fails we drop the packet. |
| 344 | */ |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 345 | static int br_nf_pre_routing_finish(struct sock *sk, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
| 347 | struct net_device *dev = skb->dev; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 348 | struct iphdr *iph = ip_hdr(skb); |
Florian Westphal | 3833078 | 2015-04-02 14:31:43 +0200 | [diff] [blame] | 349 | struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); |
Eric Dumazet | 511c3f9 | 2009-06-02 05:14:27 +0000 | [diff] [blame] | 350 | struct rtable *rt; |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 351 | int err; |
Herbert Xu | 93fdd47 | 2014-10-05 12:00:22 +0800 | [diff] [blame] | 352 | |
Bernhard Thaler | 411ffb4 | 2015-05-30 15:28:28 +0200 | [diff] [blame] | 353 | nf_bridge->frag_max_size = IPCB(skb)->frag_max_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Florian Westphal | a1e6795 | 2015-04-02 14:31:45 +0200 | [diff] [blame] | 355 | if (nf_bridge->pkt_otherhost) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | skb->pkt_type = PACKET_OTHERHOST; |
Florian Westphal | a1e6795 | 2015-04-02 14:31:45 +0200 | [diff] [blame] | 357 | nf_bridge->pkt_otherhost = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
Florian Westphal | 72b1e5e | 2015-07-23 16:21:30 +0200 | [diff] [blame] | 359 | nf_bridge->in_prerouting = 0; |
Pablo Neira Ayuso | 230ac49 | 2015-06-16 14:07:03 +0200 | [diff] [blame] | 360 | if (br_nf_ipv4_daddr_was_changed(skb, nf_bridge)) { |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 361 | if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) { |
Eric Dumazet | f3abc9b | 2009-08-24 19:35:38 +0200 | [diff] [blame] | 362 | struct in_device *in_dev = __in_dev_get_rcu(dev); |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 363 | |
| 364 | /* If err equals -EHOSTUNREACH the error is due to a |
| 365 | * martian destination or due to the fact that |
| 366 | * forwarding is disabled. For most martian packets, |
| 367 | * ip_route_output_key() will fail. It won't fail for 2 types of |
| 368 | * martian destinations: loopback destinations and destination |
| 369 | * 0.0.0.0. In both cases the packet will be dropped because the |
| 370 | * destination is the loopback device and not the bridge. */ |
| 371 | if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev)) |
| 372 | goto free_skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
David S. Miller | 78fbfd8 | 2011-03-12 00:00:52 -0500 | [diff] [blame] | 374 | rt = ip_route_output(dev_net(dev), iph->daddr, 0, |
| 375 | RT_TOS(iph->tos), 0); |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 376 | if (!IS_ERR(rt)) { |
Bart De Schuymer | 1c011be | 2005-09-14 20:55:16 -0700 | [diff] [blame] | 377 | /* - Bridged-and-DNAT'ed traffic doesn't |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 378 | * require ip_forwarding. */ |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 379 | if (rt->dst.dev == dev) { |
| 380 | skb_dst_set(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | goto bridged_dnat; |
| 382 | } |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 383 | ip_rt_put(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } |
Bart De Schuymer | f216f08 | 2006-12-05 13:45:21 -0800 | [diff] [blame] | 385 | free_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | kfree_skb(skb); |
| 387 | return 0; |
| 388 | } else { |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 389 | if (skb_dst(skb)->dev == dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | bridged_dnat: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | skb->dev = nf_bridge->physindev; |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 392 | nf_bridge_update_protocol(skb); |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 393 | nf_bridge_push_encap_header(skb); |
Jan Engelhardt | 713aefa | 2010-03-23 04:07:21 +0100 | [diff] [blame] | 394 | NF_HOOK_THRESH(NFPROTO_BRIDGE, |
| 395 | NF_BR_PRE_ROUTING, |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 396 | sk, skb, skb->dev, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | br_nf_pre_routing_finish_bridge, |
| 398 | 1); |
| 399 | return 0; |
| 400 | } |
Joe Perches | 0409114 | 2014-02-23 00:05:26 -0800 | [diff] [blame] | 401 | ether_addr_copy(eth_hdr(skb)->h_dest, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | skb->pkt_type = PACKET_HOST; |
| 403 | } |
| 404 | } else { |
Eric Dumazet | 511c3f9 | 2009-06-02 05:14:27 +0000 | [diff] [blame] | 405 | rt = bridge_parent_rtable(nf_bridge->physindev); |
| 406 | if (!rt) { |
Simon Wunderlich | 4adf0af | 2008-07-30 16:27:55 -0700 | [diff] [blame] | 407 | kfree_skb(skb); |
| 408 | return 0; |
| 409 | } |
Patrick McHardy | f9181f4 | 2010-06-15 17:31:06 +0200 | [diff] [blame] | 410 | skb_dst_set_noref(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | skb->dev = nf_bridge->physindev; |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 414 | nf_bridge_update_protocol(skb); |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 415 | nf_bridge_push_encap_header(skb); |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 416 | NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, sk, skb, |
| 417 | skb->dev, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | br_handle_frame_finish, 1); |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
Pablo Neira Ayuso | 4981682 | 2012-05-08 19:36:44 +0200 | [diff] [blame] | 423 | static struct net_device *brnf_get_logical_dev(struct sk_buff *skb, const struct net_device *dev) |
| 424 | { |
| 425 | struct net_device *vlan, *br; |
| 426 | |
| 427 | br = bridge_parent(dev); |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 428 | if (brnf_pass_vlan_indev == 0 || !skb_vlan_tag_present(skb)) |
Pablo Neira Ayuso | 4981682 | 2012-05-08 19:36:44 +0200 | [diff] [blame] | 429 | return br; |
| 430 | |
dingtianhong | f06c7f9 | 2014-05-09 14:58:05 +0800 | [diff] [blame] | 431 | vlan = __vlan_find_dev_deep_rcu(br, skb->vlan_proto, |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 432 | skb_vlan_tag_get(skb) & VLAN_VID_MASK); |
Pablo Neira Ayuso | 4981682 | 2012-05-08 19:36:44 +0200 | [diff] [blame] | 433 | |
| 434 | return vlan ? vlan : br; |
| 435 | } |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | /* Some common code for IPv4/IPv6 */ |
Pablo Neira Ayuso | 230ac49 | 2015-06-16 14:07:03 +0200 | [diff] [blame] | 438 | struct net_device *setup_pre_routing(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Florian Westphal | 3833078 | 2015-04-02 14:31:43 +0200 | [diff] [blame] | 440 | struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | if (skb->pkt_type == PACKET_OTHERHOST) { |
| 443 | skb->pkt_type = PACKET_HOST; |
Florian Westphal | a1e6795 | 2015-04-02 14:31:45 +0200 | [diff] [blame] | 444 | nf_bridge->pkt_otherhost = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Florian Westphal | 72b1e5e | 2015-07-23 16:21:30 +0200 | [diff] [blame] | 447 | nf_bridge->in_prerouting = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | nf_bridge->physindev = skb->dev; |
Pablo Neira Ayuso | 4981682 | 2012-05-08 19:36:44 +0200 | [diff] [blame] | 449 | skb->dev = brnf_get_logical_dev(skb, skb->dev); |
Florian Westphal | 3eaf402 | 2015-04-02 14:31:44 +0200 | [diff] [blame] | 450 | |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 451 | if (skb->protocol == htons(ETH_P_8021Q)) |
Florian Westphal | 3eaf402 | 2015-04-02 14:31:44 +0200 | [diff] [blame] | 452 | nf_bridge->orig_proto = BRNF_PROTO_8021Q; |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 453 | else if (skb->protocol == htons(ETH_P_PPP_SES)) |
Florian Westphal | 3eaf402 | 2015-04-02 14:31:44 +0200 | [diff] [blame] | 454 | nf_bridge->orig_proto = BRNF_PROTO_PPPOE; |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 455 | |
Florian Westphal | 6b8dbcf | 2013-10-24 21:32:42 +0200 | [diff] [blame] | 456 | /* Must drop socket now because of tproxy. */ |
| 457 | skb_orphan(skb); |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 458 | return skb->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | /* Direct IPv6 traffic to br_nf_pre_routing_ipv6. |
| 462 | * Replicate the checks that IPv4 does on packet reception. |
| 463 | * Set skb->dev to the bridge device (i.e. parent of the |
| 464 | * receiving device) to make netfilter happy, the REDIRECT |
| 465 | * target in particular. Save the original destination IP |
| 466 | * address to be able to detect DNAT afterwards. */ |
Patrick McHardy | 795aa6e | 2013-10-10 09:21:55 +0200 | [diff] [blame] | 467 | static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops, |
| 468 | struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 469 | const struct nf_hook_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
Florian Westphal | faecbb4 | 2015-05-20 13:42:25 +0200 | [diff] [blame] | 471 | struct nf_bridge_info *nf_bridge; |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 472 | struct net_bridge_port *p; |
| 473 | struct net_bridge *br; |
Evgeniy Polyakov | e7c243c | 2007-08-24 23:36:29 -0700 | [diff] [blame] | 474 | __u32 len = nf_bridge_encap_header_len(skb); |
| 475 | |
Evgeniy Polyakov | e7c243c | 2007-08-24 23:36:29 -0700 | [diff] [blame] | 476 | if (unlikely(!pskb_may_pull(skb, len))) |
Herbert Xu | deef4b5 | 2010-12-09 17:38:11 +0000 | [diff] [blame] | 477 | return NF_DROP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 479 | p = br_port_get_rcu(state->in); |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 480 | if (p == NULL) |
Herbert Xu | deef4b5 | 2010-12-09 17:38:11 +0000 | [diff] [blame] | 481 | return NF_DROP; |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 482 | br = p->br; |
| 483 | |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 484 | if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb)) { |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 485 | if (!brnf_call_ip6tables && !br->nf_call_ip6tables) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | return NF_ACCEPT; |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 487 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 488 | nf_bridge_pull_encap_header_rcsum(skb); |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 489 | return br_nf_pre_routing_ipv6(ops, skb, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 491 | |
| 492 | if (!brnf_call_iptables && !br->nf_call_iptables) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | return NF_ACCEPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 495 | if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | return NF_ACCEPT; |
| 497 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 498 | nf_bridge_pull_encap_header_rcsum(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Bernhard Thaler | 77d574e | 2015-05-30 15:29:02 +0200 | [diff] [blame] | 500 | if (br_validate_ipv4(skb)) |
Herbert Xu | deef4b5 | 2010-12-09 17:38:11 +0000 | [diff] [blame] | 501 | return NF_DROP; |
Herbert Xu | 1776206 | 2010-07-05 21:29:28 +0000 | [diff] [blame] | 502 | |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 503 | nf_bridge_put(skb->nf_bridge); |
Stephen Hemminger | fdeabde | 2006-03-20 22:58:21 -0800 | [diff] [blame] | 504 | if (!nf_bridge_alloc(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | return NF_DROP; |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 506 | if (!setup_pre_routing(skb)) |
| 507 | return NF_DROP; |
Florian Westphal | c055d5b | 2015-03-10 05:08:19 +0100 | [diff] [blame] | 508 | |
Florian Westphal | faecbb4 | 2015-05-20 13:42:25 +0200 | [diff] [blame] | 509 | nf_bridge = nf_bridge_info_get(skb); |
| 510 | nf_bridge->ipv4_daddr = ip_hdr(skb)->daddr; |
| 511 | |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 512 | skb->protocol = htons(ETH_P_IP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 514 | NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, state->sk, skb, |
| 515 | skb->dev, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | br_nf_pre_routing_finish); |
| 517 | |
| 518 | return NF_STOLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | |
| 522 | /* PF_BRIDGE/LOCAL_IN ************************************************/ |
| 523 | /* The packet is locally destined, which requires a real |
| 524 | * dst_entry, so detach the fake one. On the way up, the |
| 525 | * packet would pass through PRE_ROUTING again (which already |
| 526 | * took place when the packet entered the bridge), but we |
| 527 | * register an IPv4 PRE_ROUTING 'sabotage' hook that will |
| 528 | * prevent this from happening. */ |
Patrick McHardy | 795aa6e | 2013-10-10 09:21:55 +0200 | [diff] [blame] | 529 | static unsigned int br_nf_local_in(const struct nf_hook_ops *ops, |
| 530 | struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 531 | const struct nf_hook_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Peter Huang (Peng) | a881e96 | 2012-04-19 20:12:51 +0000 | [diff] [blame] | 533 | br_drop_fake_rtable(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | return NF_ACCEPT; |
| 535 | } |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* PF_BRIDGE/FORWARD *************************************************/ |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 538 | static int br_nf_forward_finish(struct sock *sk, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | { |
Florian Westphal | 3833078 | 2015-04-02 14:31:43 +0200 | [diff] [blame] | 540 | struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | struct net_device *in; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 543 | if (!IS_ARP(skb) && !IS_VLAN_ARP(skb)) { |
Florian Westphal | 0b67c43 | 2015-04-01 22:36:27 +0200 | [diff] [blame] | 544 | |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 545 | if (skb->protocol == htons(ETH_P_IP)) |
Bernhard Thaler | 411ffb4 | 2015-05-30 15:28:28 +0200 | [diff] [blame] | 546 | nf_bridge->frag_max_size = IPCB(skb)->frag_max_size; |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 547 | |
| 548 | if (skb->protocol == htons(ETH_P_IPV6)) |
| 549 | nf_bridge->frag_max_size = IP6CB(skb)->frag_max_size; |
Florian Westphal | 0b67c43 | 2015-04-01 22:36:27 +0200 | [diff] [blame] | 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | in = nf_bridge->physindev; |
Florian Westphal | a1e6795 | 2015-04-02 14:31:45 +0200 | [diff] [blame] | 552 | if (nf_bridge->pkt_otherhost) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | skb->pkt_type = PACKET_OTHERHOST; |
Florian Westphal | a1e6795 | 2015-04-02 14:31:45 +0200 | [diff] [blame] | 554 | nf_bridge->pkt_otherhost = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
Bart De Schuymer | e94c674 | 2010-05-13 14:55:34 +0200 | [diff] [blame] | 556 | nf_bridge_update_protocol(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } else { |
| 558 | in = *((struct net_device **)(skb->cb)); |
| 559 | } |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 560 | nf_bridge_push_encap_header(skb); |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 561 | |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 562 | NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_FORWARD, sk, skb, |
| 563 | in, skb->dev, br_forward_finish, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* This is the 'purely bridged' case. For IP, we pass the packet to |
| 569 | * netfilter with indev and outdev set to the bridge device, |
| 570 | * but we are still able to filter on the 'real' indev/outdev |
| 571 | * because of the physdev module. For ARP, indev and outdev are the |
| 572 | * bridge ports. */ |
Patrick McHardy | 795aa6e | 2013-10-10 09:21:55 +0200 | [diff] [blame] | 573 | static unsigned int br_nf_forward_ip(const struct nf_hook_ops *ops, |
| 574 | struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 575 | const struct nf_hook_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | struct nf_bridge_info *nf_bridge; |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 578 | struct net_device *parent; |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 579 | u_int8_t pf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
| 581 | if (!skb->nf_bridge) |
| 582 | return NF_ACCEPT; |
| 583 | |
Patrick McHardy | 2dc2f20 | 2008-01-20 06:25:48 -0800 | [diff] [blame] | 584 | /* Need exclusive nf_bridge_info since we might have multiple |
| 585 | * different physoutdevs. */ |
| 586 | if (!nf_bridge_unshare(skb)) |
| 587 | return NF_DROP; |
| 588 | |
Florian Westphal | 3833078 | 2015-04-02 14:31:43 +0200 | [diff] [blame] | 589 | nf_bridge = nf_bridge_info_get(skb); |
| 590 | if (!nf_bridge) |
| 591 | return NF_DROP; |
| 592 | |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 593 | parent = bridge_parent(state->out); |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 594 | if (!parent) |
| 595 | return NF_DROP; |
| 596 | |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 597 | if (IS_IP(skb) || IS_VLAN_IP(skb) || IS_PPPOE_IP(skb)) |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 598 | pf = NFPROTO_IPV4; |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 599 | else if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb)) |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 600 | pf = NFPROTO_IPV6; |
Herbert Xu | a2bd40a | 2009-01-12 00:06:02 +0000 | [diff] [blame] | 601 | else |
| 602 | return NF_ACCEPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 604 | nf_bridge_pull_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | if (skb->pkt_type == PACKET_OTHERHOST) { |
| 607 | skb->pkt_type = PACKET_HOST; |
Florian Westphal | a1e6795 | 2015-04-02 14:31:45 +0200 | [diff] [blame] | 608 | nf_bridge->pkt_otherhost = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Florian Westphal | 0b67c43 | 2015-04-01 22:36:27 +0200 | [diff] [blame] | 611 | if (pf == NFPROTO_IPV4) { |
Bernhard Thaler | 77d574e | 2015-05-30 15:29:02 +0200 | [diff] [blame] | 612 | if (br_validate_ipv4(skb)) |
Florian Westphal | 0b67c43 | 2015-04-01 22:36:27 +0200 | [diff] [blame] | 613 | return NF_DROP; |
Bernhard Thaler | 411ffb4 | 2015-05-30 15:28:28 +0200 | [diff] [blame] | 614 | IPCB(skb)->frag_max_size = nf_bridge->frag_max_size; |
Florian Westphal | 0b67c43 | 2015-04-01 22:36:27 +0200 | [diff] [blame] | 615 | } |
Herbert Xu | 6b1e960 | 2011-03-18 05:27:28 +0000 | [diff] [blame] | 616 | |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 617 | if (pf == NFPROTO_IPV6) { |
| 618 | if (br_validate_ipv6(skb)) |
| 619 | return NF_DROP; |
| 620 | IP6CB(skb)->frag_max_size = nf_bridge->frag_max_size; |
| 621 | } |
| 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | nf_bridge->physoutdev = skb->dev; |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 624 | if (pf == NFPROTO_IPV4) |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 625 | skb->protocol = htons(ETH_P_IP); |
| 626 | else |
| 627 | skb->protocol = htons(ETH_P_IPV6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 629 | NF_HOOK(pf, NF_INET_FORWARD, NULL, skb, |
| 630 | brnf_get_logical_dev(skb, state->in), |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 631 | parent, br_nf_forward_finish); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | return NF_STOLEN; |
| 634 | } |
| 635 | |
Patrick McHardy | 795aa6e | 2013-10-10 09:21:55 +0200 | [diff] [blame] | 636 | static unsigned int br_nf_forward_arp(const struct nf_hook_ops *ops, |
| 637 | struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 638 | const struct nf_hook_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 640 | struct net_bridge_port *p; |
| 641 | struct net_bridge *br; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | struct net_device **d = (struct net_device **)(skb->cb); |
| 643 | |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 644 | p = br_port_get_rcu(state->out); |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 645 | if (p == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | return NF_ACCEPT; |
Patrick McHardy | 4df53d8 | 2010-07-02 09:32:57 +0200 | [diff] [blame] | 647 | br = p->br; |
| 648 | |
| 649 | if (!brnf_call_arptables && !br->nf_call_arptables) |
| 650 | return NF_ACCEPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 652 | if (!IS_ARP(skb)) { |
Stephen Hemminger | 8b42ec3 | 2006-03-20 22:58:05 -0800 | [diff] [blame] | 653 | if (!IS_VLAN_ARP(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | return NF_ACCEPT; |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 655 | nf_bridge_pull_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Arnaldo Carvalho de Melo | d0a92be | 2007-03-12 20:56:31 -0300 | [diff] [blame] | 658 | if (arp_hdr(skb)->ar_pln != 4) { |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 659 | if (IS_VLAN_ARP(skb)) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 660 | nf_bridge_push_encap_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return NF_ACCEPT; |
| 662 | } |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 663 | *d = state->in; |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 664 | NF_HOOK(NFPROTO_ARP, NF_ARP_FORWARD, state->sk, skb, |
| 665 | state->in, state->out, br_nf_forward_finish); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | return NF_STOLEN; |
| 668 | } |
| 669 | |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 670 | #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) || IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 671 | static int br_nf_push_frag_xmit(struct sock *sk, struct sk_buff *skb) |
Florian Westphal | 8bd63cf | 2015-03-05 00:52:33 +0100 | [diff] [blame] | 672 | { |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 673 | struct brnf_frag_data *data; |
| 674 | int err; |
| 675 | |
| 676 | data = this_cpu_ptr(&brnf_frag_data_storage); |
| 677 | err = skb_cow_head(skb, data->size); |
| 678 | |
| 679 | if (err) { |
Florian Westphal | 8bd63cf | 2015-03-05 00:52:33 +0100 | [diff] [blame] | 680 | kfree_skb(skb); |
| 681 | return 0; |
| 682 | } |
| 683 | |
Florian Westphal | d7b5974 | 2015-06-05 13:27:13 +0200 | [diff] [blame] | 684 | if (data->vlan_tci) { |
| 685 | skb->vlan_tci = data->vlan_tci; |
| 686 | skb->vlan_proto = data->vlan_proto; |
| 687 | } |
| 688 | |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 689 | skb_copy_to_linear_data_offset(skb, -data->size, data->mac, data->size); |
| 690 | __skb_push(skb, data->encap_size); |
| 691 | |
Florian Westphal | a9fcc6a | 2015-05-03 22:06:07 +0200 | [diff] [blame] | 692 | nf_bridge_info_free(skb); |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 693 | return br_dev_queue_push_xmit(sk, skb); |
Florian Westphal | 8bd63cf | 2015-03-05 00:52:33 +0100 | [diff] [blame] | 694 | } |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 695 | #endif |
Florian Westphal | 8bd63cf | 2015-03-05 00:52:33 +0100 | [diff] [blame] | 696 | |
Bernhard Thaler | a1bc1b3 | 2015-06-20 00:17:50 +0200 | [diff] [blame] | 697 | #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) |
Andy Zhou | 49d16b2 | 2015-05-15 14:15:37 -0700 | [diff] [blame] | 698 | static int br_nf_ip_fragment(struct sock *sk, struct sk_buff *skb, |
| 699 | int (*output)(struct sock *, struct sk_buff *)) |
| 700 | { |
| 701 | unsigned int mtu = ip_skb_dst_mtu(skb); |
| 702 | struct iphdr *iph = ip_hdr(skb); |
| 703 | struct rtable *rt = skb_rtable(skb); |
| 704 | struct net_device *dev = rt->dst.dev; |
| 705 | |
| 706 | if (unlikely(((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) || |
| 707 | (IPCB(skb)->frag_max_size && |
| 708 | IPCB(skb)->frag_max_size > mtu))) { |
| 709 | IP_INC_STATS(dev_net(dev), IPSTATS_MIB_FRAGFAILS); |
| 710 | kfree_skb(skb); |
| 711 | return -EMSGSIZE; |
| 712 | } |
| 713 | |
| 714 | return ip_do_fragment(sk, skb, output); |
| 715 | } |
Bernhard Thaler | a1bc1b3 | 2015-06-20 00:17:50 +0200 | [diff] [blame] | 716 | #endif |
Andy Zhou | 49d16b2 | 2015-05-15 14:15:37 -0700 | [diff] [blame] | 717 | |
Florian Westphal | 33b1f31 | 2015-06-05 13:28:38 +0200 | [diff] [blame] | 718 | static unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb) |
| 719 | { |
| 720 | if (skb->nf_bridge->orig_proto == BRNF_PROTO_PPPOE) |
| 721 | return PPPOE_SES_HLEN; |
| 722 | return 0; |
| 723 | } |
| 724 | |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 725 | static int br_nf_dev_queue_xmit(struct sock *sk, struct sk_buff *skb) |
Patrick McHardy | 2e2f7ae | 2006-04-04 13:42:35 -0700 | [diff] [blame] | 726 | { |
Bernhard Thaler | 411ffb4 | 2015-05-30 15:28:28 +0200 | [diff] [blame] | 727 | struct nf_bridge_info *nf_bridge; |
Florian Westphal | 7a8d831 | 2015-03-05 00:52:36 +0100 | [diff] [blame] | 728 | unsigned int mtu_reserved; |
Bandan Das | 462fb2a | 2010-09-19 09:34:33 +0000 | [diff] [blame] | 729 | |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 730 | mtu_reserved = nf_bridge_mtu_reduction(skb); |
| 731 | |
| 732 | if (skb_is_gso(skb) || skb->len + mtu_reserved <= skb->dev->mtu) { |
Florian Westphal | a9fcc6a | 2015-05-03 22:06:07 +0200 | [diff] [blame] | 733 | nf_bridge_info_free(skb); |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 734 | return br_dev_queue_push_xmit(sk, skb); |
Florian Westphal | a9fcc6a | 2015-05-03 22:06:07 +0200 | [diff] [blame] | 735 | } |
Florian Westphal | 7a8d831 | 2015-03-05 00:52:36 +0100 | [diff] [blame] | 736 | |
Bernhard Thaler | 411ffb4 | 2015-05-30 15:28:28 +0200 | [diff] [blame] | 737 | nf_bridge = nf_bridge_info_get(skb); |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 738 | |
| 739 | #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) |
Herbert Xu | 93fdd47 | 2014-10-05 12:00:22 +0800 | [diff] [blame] | 740 | /* This is wrong! We should preserve the original fragment |
| 741 | * boundaries by preserving frag_list rather than refragmenting. |
| 742 | */ |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 743 | if (skb->protocol == htons(ETH_P_IP)) { |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 744 | struct brnf_frag_data *data; |
| 745 | |
Bernhard Thaler | 77d574e | 2015-05-30 15:29:02 +0200 | [diff] [blame] | 746 | if (br_validate_ipv4(skb)) |
Florian Westphal | dd302b5 | 2015-06-30 22:27:51 +0200 | [diff] [blame] | 747 | goto drop; |
Bernhard Thaler | 411ffb4 | 2015-05-30 15:28:28 +0200 | [diff] [blame] | 748 | |
| 749 | IPCB(skb)->frag_max_size = nf_bridge->frag_max_size; |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 750 | |
| 751 | nf_bridge_update_protocol(skb); |
| 752 | |
| 753 | data = this_cpu_ptr(&brnf_frag_data_storage); |
Florian Westphal | d7b5974 | 2015-06-05 13:27:13 +0200 | [diff] [blame] | 754 | |
| 755 | data->vlan_tci = skb->vlan_tci; |
| 756 | data->vlan_proto = skb->vlan_proto; |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 757 | data->encap_size = nf_bridge_encap_header_len(skb); |
| 758 | data->size = ETH_HLEN + data->encap_size; |
| 759 | |
| 760 | skb_copy_from_linear_data_offset(skb, -data->size, data->mac, |
| 761 | data->size); |
| 762 | |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 763 | return br_nf_ip_fragment(sk, skb, br_nf_push_frag_xmit); |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 764 | } |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 765 | #endif |
| 766 | #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) |
| 767 | if (skb->protocol == htons(ETH_P_IPV6)) { |
| 768 | const struct nf_ipv6_ops *v6ops = nf_get_ipv6_ops(); |
| 769 | struct brnf_frag_data *data; |
Bandan Das | 462fb2a | 2010-09-19 09:34:33 +0000 | [diff] [blame] | 770 | |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 771 | if (br_validate_ipv6(skb)) |
Florian Westphal | dd302b5 | 2015-06-30 22:27:51 +0200 | [diff] [blame] | 772 | goto drop; |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 773 | |
| 774 | IP6CB(skb)->frag_max_size = nf_bridge->frag_max_size; |
| 775 | |
| 776 | nf_bridge_update_protocol(skb); |
| 777 | |
| 778 | data = this_cpu_ptr(&brnf_frag_data_storage); |
| 779 | data->encap_size = nf_bridge_encap_header_len(skb); |
| 780 | data->size = ETH_HLEN + data->encap_size; |
| 781 | |
| 782 | skb_copy_from_linear_data_offset(skb, -data->size, data->mac, |
| 783 | data->size); |
| 784 | |
| 785 | if (v6ops) |
| 786 | return v6ops->fragment(sk, skb, br_nf_push_frag_xmit); |
Florian Westphal | dd302b5 | 2015-06-30 22:27:51 +0200 | [diff] [blame] | 787 | |
| 788 | kfree_skb(skb); |
| 789 | return -EMSGSIZE; |
Bernhard Thaler | efb6de9 | 2015-05-30 15:30:16 +0200 | [diff] [blame] | 790 | } |
| 791 | #endif |
Florian Westphal | a9fcc6a | 2015-05-03 22:06:07 +0200 | [diff] [blame] | 792 | nf_bridge_info_free(skb); |
| 793 | return br_dev_queue_push_xmit(sk, skb); |
Florian Westphal | dd302b5 | 2015-06-30 22:27:51 +0200 | [diff] [blame] | 794 | drop: |
| 795 | kfree_skb(skb); |
| 796 | return 0; |
hummerbliss@gmail.com | c197fac | 2009-04-20 17:12:35 +0200 | [diff] [blame] | 797 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | /* PF_BRIDGE/POST_ROUTING ********************************************/ |
Patrick McHardy | 795aa6e | 2013-10-10 09:21:55 +0200 | [diff] [blame] | 800 | static unsigned int br_nf_post_routing(const struct nf_hook_ops *ops, |
| 801 | struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 802 | const struct nf_hook_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
Florian Westphal | 3833078 | 2015-04-02 14:31:43 +0200 | [diff] [blame] | 804 | struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | struct net_device *realoutdev = bridge_parent(skb->dev); |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 806 | u_int8_t pf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Florian Westphal | e4bb9bc | 2015-03-10 10:36:48 +0100 | [diff] [blame] | 808 | /* if nf_bridge is set, but ->physoutdev is NULL, this packet came in |
| 809 | * on a bridge, but was delivered locally and is now being routed: |
| 810 | * |
| 811 | * POST_ROUTING was already invoked from the ip stack. |
| 812 | */ |
| 813 | if (!nf_bridge || !nf_bridge->physoutdev) |
Patrick McHardy | 81d9dda | 2007-11-13 02:58:44 -0800 | [diff] [blame] | 814 | return NF_ACCEPT; |
| 815 | |
Stephen Hemminger | 5dce971 | 2006-02-09 17:09:38 -0800 | [diff] [blame] | 816 | if (!realoutdev) |
| 817 | return NF_DROP; |
| 818 | |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 819 | if (IS_IP(skb) || IS_VLAN_IP(skb) || IS_PPPOE_IP(skb)) |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 820 | pf = NFPROTO_IPV4; |
Florian Westphal | 739e450 | 2012-03-06 01:22:54 +0000 | [diff] [blame] | 821 | else if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb)) |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 822 | pf = NFPROTO_IPV6; |
Herbert Xu | a2bd40a | 2009-01-12 00:06:02 +0000 | [diff] [blame] | 823 | else |
| 824 | return NF_ACCEPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | /* We assume any code from br_dev_queue_push_xmit onwards doesn't care |
| 827 | * about the value of skb->pkt_type. */ |
| 828 | if (skb->pkt_type == PACKET_OTHERHOST) { |
| 829 | skb->pkt_type = PACKET_HOST; |
Florian Westphal | a1e6795 | 2015-04-02 14:31:45 +0200 | [diff] [blame] | 830 | nf_bridge->pkt_otherhost = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 833 | nf_bridge_pull_encap_header(skb); |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 834 | if (pf == NFPROTO_IPV4) |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 835 | skb->protocol = htons(ETH_P_IP); |
| 836 | else |
| 837 | skb->protocol = htons(ETH_P_IPV6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 839 | NF_HOOK(pf, NF_INET_POST_ROUTING, state->sk, skb, |
| 840 | NULL, realoutdev, |
Patrick McHardy | 2e2f7ae | 2006-04-04 13:42:35 -0700 | [diff] [blame] | 841 | br_nf_dev_queue_xmit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
| 843 | return NF_STOLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | /* IP/SABOTAGE *****************************************************/ |
| 847 | /* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING |
| 848 | * for the second time. */ |
Patrick McHardy | 795aa6e | 2013-10-10 09:21:55 +0200 | [diff] [blame] | 849 | static unsigned int ip_sabotage_in(const struct nf_hook_ops *ops, |
| 850 | struct sk_buff *skb, |
David S. Miller | 238e54c | 2015-04-03 20:32:56 -0400 | [diff] [blame] | 851 | const struct nf_hook_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | { |
Florian Westphal | 72b1e5e | 2015-07-23 16:21:30 +0200 | [diff] [blame] | 853 | if (skb->nf_bridge && !skb->nf_bridge->in_prerouting) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | return NF_STOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
| 856 | return NF_ACCEPT; |
| 857 | } |
| 858 | |
Pablo Neira Ayuso | e5de75b | 2015-03-09 12:30:12 +0100 | [diff] [blame] | 859 | /* This is called when br_netfilter has called into iptables/netfilter, |
| 860 | * and DNAT has taken place on a bridge-forwarded packet. |
| 861 | * |
| 862 | * neigh->output has created a new MAC header, with local br0 MAC |
| 863 | * as saddr. |
| 864 | * |
| 865 | * This restores the original MAC saddr of the bridged packet |
| 866 | * before invoking bridge forward logic to transmit the packet. |
| 867 | */ |
| 868 | static void br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb) |
| 869 | { |
Florian Westphal | 3833078 | 2015-04-02 14:31:43 +0200 | [diff] [blame] | 870 | struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); |
Pablo Neira Ayuso | e5de75b | 2015-03-09 12:30:12 +0100 | [diff] [blame] | 871 | |
| 872 | skb_pull(skb, ETH_HLEN); |
Florian Westphal | 72b1e5e | 2015-07-23 16:21:30 +0200 | [diff] [blame] | 873 | nf_bridge->bridged_dnat = 0; |
Pablo Neira Ayuso | e5de75b | 2015-03-09 12:30:12 +0100 | [diff] [blame] | 874 | |
Florian Westphal | e70deec | 2015-04-02 14:31:40 +0200 | [diff] [blame] | 875 | BUILD_BUG_ON(sizeof(nf_bridge->neigh_header) != (ETH_HLEN - ETH_ALEN)); |
| 876 | |
| 877 | skb_copy_to_linear_data_offset(skb, -(ETH_HLEN - ETH_ALEN), |
| 878 | nf_bridge->neigh_header, |
| 879 | ETH_HLEN - ETH_ALEN); |
Pablo Neira Ayuso | e5de75b | 2015-03-09 12:30:12 +0100 | [diff] [blame] | 880 | skb->dev = nf_bridge->physindev; |
Florian Westphal | 7fb48c5 | 2015-05-03 22:05:28 +0200 | [diff] [blame] | 881 | |
| 882 | nf_bridge->physoutdev = NULL; |
David Miller | 7026b1d | 2015-04-05 22:19:04 -0400 | [diff] [blame] | 883 | br_handle_frame_finish(NULL, skb); |
Pablo Neira Ayuso | e5de75b | 2015-03-09 12:30:12 +0100 | [diff] [blame] | 884 | } |
| 885 | |
Pablo Neira Ayuso | 1a4ba64 | 2015-03-10 10:27:18 +0100 | [diff] [blame] | 886 | static int br_nf_dev_xmit(struct sk_buff *skb) |
Pablo Neira Ayuso | e5de75b | 2015-03-09 12:30:12 +0100 | [diff] [blame] | 887 | { |
Florian Westphal | 72b1e5e | 2015-07-23 16:21:30 +0200 | [diff] [blame] | 888 | if (skb->nf_bridge && skb->nf_bridge->bridged_dnat) { |
Pablo Neira Ayuso | e5de75b | 2015-03-09 12:30:12 +0100 | [diff] [blame] | 889 | br_nf_pre_routing_finish_bridge_slow(skb); |
| 890 | return 1; |
| 891 | } |
| 892 | return 0; |
| 893 | } |
Pablo Neira Ayuso | 1a4ba64 | 2015-03-10 10:27:18 +0100 | [diff] [blame] | 894 | |
| 895 | static const struct nf_br_ops br_ops = { |
| 896 | .br_dev_xmit_hook = br_nf_dev_xmit, |
| 897 | }; |
Pablo Neira Ayuso | e5de75b | 2015-03-09 12:30:12 +0100 | [diff] [blame] | 898 | |
Pablo Neira Ayuso | 4b7fd5d | 2014-10-02 11:13:21 +0200 | [diff] [blame] | 899 | void br_netfilter_enable(void) |
| 900 | { |
| 901 | } |
| 902 | EXPORT_SYMBOL_GPL(br_netfilter_enable); |
| 903 | |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 904 | /* For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because |
| 905 | * br_dev_queue_push_xmit is called afterwards */ |
Patrick McHardy | 1999414 | 2007-12-05 01:23:00 -0800 | [diff] [blame] | 906 | static struct nf_hook_ops br_nf_ops[] __read_mostly = { |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 907 | { |
| 908 | .hook = br_nf_pre_routing, |
| 909 | .owner = THIS_MODULE, |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 910 | .pf = NFPROTO_BRIDGE, |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 911 | .hooknum = NF_BR_PRE_ROUTING, |
| 912 | .priority = NF_BR_PRI_BRNF, |
| 913 | }, |
| 914 | { |
| 915 | .hook = br_nf_local_in, |
| 916 | .owner = THIS_MODULE, |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 917 | .pf = NFPROTO_BRIDGE, |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 918 | .hooknum = NF_BR_LOCAL_IN, |
| 919 | .priority = NF_BR_PRI_BRNF, |
| 920 | }, |
| 921 | { |
| 922 | .hook = br_nf_forward_ip, |
| 923 | .owner = THIS_MODULE, |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 924 | .pf = NFPROTO_BRIDGE, |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 925 | .hooknum = NF_BR_FORWARD, |
| 926 | .priority = NF_BR_PRI_BRNF - 1, |
| 927 | }, |
| 928 | { |
| 929 | .hook = br_nf_forward_arp, |
| 930 | .owner = THIS_MODULE, |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 931 | .pf = NFPROTO_BRIDGE, |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 932 | .hooknum = NF_BR_FORWARD, |
| 933 | .priority = NF_BR_PRI_BRNF, |
| 934 | }, |
| 935 | { |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 936 | .hook = br_nf_post_routing, |
| 937 | .owner = THIS_MODULE, |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 938 | .pf = NFPROTO_BRIDGE, |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 939 | .hooknum = NF_BR_POST_ROUTING, |
| 940 | .priority = NF_BR_PRI_LAST, |
| 941 | }, |
| 942 | { |
| 943 | .hook = ip_sabotage_in, |
| 944 | .owner = THIS_MODULE, |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 945 | .pf = NFPROTO_IPV4, |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 946 | .hooknum = NF_INET_PRE_ROUTING, |
| 947 | .priority = NF_IP_PRI_FIRST, |
| 948 | }, |
| 949 | { |
| 950 | .hook = ip_sabotage_in, |
| 951 | .owner = THIS_MODULE, |
Alban Crequy | aa740f4 | 2012-05-14 03:56:36 +0000 | [diff] [blame] | 952 | .pf = NFPROTO_IPV6, |
Cyrill Gorcunov | 1490fd8 | 2009-07-03 20:11:57 +0000 | [diff] [blame] | 953 | .hooknum = NF_INET_PRE_ROUTING, |
| 954 | .priority = NF_IP6_PRI_FIRST, |
| 955 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | }; |
| 957 | |
| 958 | #ifdef CONFIG_SYSCTL |
| 959 | static |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 960 | int brnf_sysctl_call_tables(struct ctl_table *ctl, int write, |
tanxiaojun | 56b148e | 2013-12-19 13:28:13 +0800 | [diff] [blame] | 961 | void __user *buffer, size_t *lenp, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { |
| 963 | int ret; |
| 964 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 965 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
| 967 | if (write && *(int *)(ctl->data)) |
| 968 | *(int *)(ctl->data) = 1; |
| 969 | return ret; |
| 970 | } |
| 971 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 972 | static struct ctl_table brnf_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | .procname = "bridge-nf-call-arptables", |
| 975 | .data = &brnf_call_arptables, |
| 976 | .maxlen = sizeof(int), |
| 977 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 978 | .proc_handler = brnf_sysctl_call_tables, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | }, |
| 980 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | .procname = "bridge-nf-call-iptables", |
| 982 | .data = &brnf_call_iptables, |
| 983 | .maxlen = sizeof(int), |
| 984 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 985 | .proc_handler = brnf_sysctl_call_tables, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | }, |
| 987 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | .procname = "bridge-nf-call-ip6tables", |
| 989 | .data = &brnf_call_ip6tables, |
| 990 | .maxlen = sizeof(int), |
| 991 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 992 | .proc_handler = brnf_sysctl_call_tables, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | }, |
| 994 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | .procname = "bridge-nf-filter-vlan-tagged", |
| 996 | .data = &brnf_filter_vlan_tagged, |
| 997 | .maxlen = sizeof(int), |
| 998 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 999 | .proc_handler = brnf_sysctl_call_tables, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | }, |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 1001 | { |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 1002 | .procname = "bridge-nf-filter-pppoe-tagged", |
| 1003 | .data = &brnf_filter_pppoe_tagged, |
| 1004 | .maxlen = sizeof(int), |
| 1005 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 1006 | .proc_handler = brnf_sysctl_call_tables, |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 1007 | }, |
Pablo Neira Ayuso | 4981682 | 2012-05-08 19:36:44 +0200 | [diff] [blame] | 1008 | { |
| 1009 | .procname = "bridge-nf-pass-vlan-input-dev", |
| 1010 | .data = &brnf_pass_vlan_indev, |
| 1011 | .maxlen = sizeof(int), |
| 1012 | .mode = 0644, |
| 1013 | .proc_handler = brnf_sysctl_call_tables, |
| 1014 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1015 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | #endif |
| 1018 | |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 1019 | static int __init br_netfilter_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
Patrick McHardy | 5eb87f4 | 2007-02-07 15:07:22 -0800 | [diff] [blame] | 1021 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 1023 | ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
Patrick McHardy | 5eb87f4 | 2007-02-07 15:07:22 -0800 | [diff] [blame] | 1024 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | return ret; |
Eric Dumazet | fc66f95 | 2010-10-08 06:37:34 +0000 | [diff] [blame] | 1026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | #ifdef CONFIG_SYSCTL |
Eric W. Biederman | ec8f23c | 2012-04-19 13:44:49 +0000 | [diff] [blame] | 1028 | brnf_sysctl_header = register_net_sysctl(&init_net, "net/bridge", brnf_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | if (brnf_sysctl_header == NULL) { |
Stephen Hemminger | 789bc3e | 2006-03-20 22:57:32 -0800 | [diff] [blame] | 1030 | printk(KERN_WARNING |
| 1031 | "br_netfilter: can't register to sysctl.\n"); |
Geert Uytterhoeven | 9672723 | 2015-02-12 15:17:27 +0100 | [diff] [blame] | 1032 | nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
| 1033 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | } |
| 1035 | #endif |
Pablo Neira Ayuso | 1a4ba64 | 2015-03-10 10:27:18 +0100 | [diff] [blame] | 1036 | RCU_INIT_POINTER(nf_br_ops, &br_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | printk(KERN_NOTICE "Bridge firewalling registered\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 1041 | static void __exit br_netfilter_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | { |
Pablo Neira Ayuso | 1a4ba64 | 2015-03-10 10:27:18 +0100 | [diff] [blame] | 1043 | RCU_INIT_POINTER(nf_br_ops, NULL); |
Patrick McHardy | 5eb87f4 | 2007-02-07 15:07:22 -0800 | [diff] [blame] | 1044 | nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | #ifdef CONFIG_SYSCTL |
Eric W. Biederman | 5dd3df1 | 2012-04-19 13:24:33 +0000 | [diff] [blame] | 1046 | unregister_net_sysctl_table(brnf_sysctl_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | } |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame] | 1049 | |
| 1050 | module_init(br_netfilter_init); |
| 1051 | module_exit(br_netfilter_fini); |
| 1052 | |
| 1053 | MODULE_LICENSE("GPL"); |
| 1054 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@gnu.org>"); |
| 1055 | MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>"); |
| 1056 | MODULE_DESCRIPTION("Linux ethernet netfilter firewall bridge"); |