br_netfilter.c 29.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/*
 *	Handle firewalling
 *	Linux ethernet bridge
 *
 *	Authors:
6 7
 *	Lennert Buytenhek		<buytenh@gnu.org>
 *	Bart De Schuymer		<bdschuym@pandora.be>
L
Linus Torvalds 已提交
8 9 10 11 12 13 14 15 16 17 18
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License
 *	as published by the Free Software Foundation; either version
 *	2 of the License, or (at your option) any later version.
 *
 *	Lennert dedicates this file to Kerstin Wurdinger.
 */

#include <linux/module.h>
#include <linux/kernel.h>
19
#include <linux/slab.h>
L
Linus Torvalds 已提交
20 21 22
#include <linux/ip.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
23
#include <linux/if_arp.h>
L
Linus Torvalds 已提交
24 25
#include <linux/if_ether.h>
#include <linux/if_vlan.h>
26 27
#include <linux/if_pppox.h>
#include <linux/ppp_defs.h>
L
Linus Torvalds 已提交
28 29 30 31 32
#include <linux/netfilter_bridge.h>
#include <linux/netfilter_ipv4.h>
#include <linux/netfilter_ipv6.h>
#include <linux/netfilter_arp.h>
#include <linux/in_route.h>
33
#include <linux/inetdevice.h>
34

L
Linus Torvalds 已提交
35 36
#include <net/ip.h>
#include <net/ipv6.h>
37
#include <net/route.h>
38
#include <net/netfilter/br_netfilter.h>
39

L
Linus Torvalds 已提交
40 41 42 43 44 45 46 47
#include <asm/uaccess.h>
#include "br_private.h"
#ifdef CONFIG_SYSCTL
#include <linux/sysctl.h>
#endif

#ifdef CONFIG_SYSCTL
static struct ctl_table_header *brnf_sysctl_header;
48 49 50
static int brnf_call_iptables __read_mostly = 1;
static int brnf_call_ip6tables __read_mostly = 1;
static int brnf_call_arptables __read_mostly = 1;
51 52
static int brnf_filter_vlan_tagged __read_mostly = 0;
static int brnf_filter_pppoe_tagged __read_mostly = 0;
53
static int brnf_pass_vlan_indev __read_mostly = 0;
L
Linus Torvalds 已提交
54
#else
55 56 57
#define brnf_call_iptables 1
#define brnf_call_ip6tables 1
#define brnf_call_arptables 1
58 59
#define brnf_filter_vlan_tagged 0
#define brnf_filter_pppoe_tagged 0
60
#define brnf_pass_vlan_indev 0
L
Linus Torvalds 已提交
61 62
#endif

63
#define IS_IP(skb) \
64
	(!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_IP))
65 66

#define IS_IPV6(skb) \
67
	(!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_IPV6))
68 69

#define IS_ARP(skb) \
70
	(!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_ARP))
71

D
Dave Jones 已提交
72
static inline __be16 vlan_proto(const struct sk_buff *skb)
73
{
74
	if (skb_vlan_tag_present(skb))
75 76 77 78 79
		return skb->protocol;
	else if (skb->protocol == htons(ETH_P_8021Q))
		return vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
	else
		return 0;
80 81 82
}

#define IS_VLAN_IP(skb) \
83
	(vlan_proto(skb) == htons(ETH_P_IP) && \
84 85 86
	 brnf_filter_vlan_tagged)

#define IS_VLAN_IPV6(skb) \
87
	(vlan_proto(skb) == htons(ETH_P_IPV6) && \
88 89 90
	 brnf_filter_vlan_tagged)

#define IS_VLAN_ARP(skb) \
91
	(vlan_proto(skb) == htons(ETH_P_ARP) &&	\
92
	 brnf_filter_vlan_tagged)
L
Linus Torvalds 已提交
93

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
static inline __be16 pppoe_proto(const struct sk_buff *skb)
{
	return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN +
			    sizeof(struct pppoe_hdr)));
}

#define IS_PPPOE_IP(skb) \
	(skb->protocol == htons(ETH_P_PPP_SES) && \
	 pppoe_proto(skb) == htons(PPP_IP) && \
	 brnf_filter_pppoe_tagged)

#define IS_PPPOE_IPV6(skb) \
	(skb->protocol == htons(ETH_P_PPP_SES) && \
	 pppoe_proto(skb) == htons(PPP_IPV6) && \
	 brnf_filter_pppoe_tagged)

110 111 112 113 114 115 116 117 118 119 120 121 122
/* largest possible L2 header, see br_nf_dev_queue_xmit() */
#define NF_BRIDGE_MAX_MAC_HEADER_LENGTH (PPPOE_SES_HLEN + ETH_HLEN)

#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
struct brnf_frag_data {
	char mac[NF_BRIDGE_MAX_MAC_HEADER_LENGTH];
	u8 encap_size;
	u8 size;
};

static DEFINE_PER_CPU(struct brnf_frag_data, brnf_frag_data_storage);
#endif

123 124 125 126 127
static struct nf_bridge_info *nf_bridge_info_get(const struct sk_buff *skb)
{
	return skb->nf_bridge;
}

128 129
static inline struct rtable *bridge_parent_rtable(const struct net_device *dev)
{
130 131 132 133
	struct net_bridge_port *port;

	port = br_port_get_rcu(dev);
	return port ? &port->br->fake_rtable : NULL;
134
}
L
Linus Torvalds 已提交
135

136 137
static inline struct net_device *bridge_parent(const struct net_device *dev)
{
138
	struct net_bridge_port *port;
139

140 141
	port = br_port_get_rcu(dev);
	return port ? port->br->dev : NULL;
142
}
L
Linus Torvalds 已提交
143

144 145 146 147 148 149 150 151 152
static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
{
	skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC);
	if (likely(skb->nf_bridge))
		atomic_set(&(skb->nf_bridge->use), 1);

	return skb->nf_bridge;
}

153 154 155 156 157 158 159 160 161 162 163
static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb)
{
	struct nf_bridge_info *nf_bridge = skb->nf_bridge;

	if (atomic_read(&nf_bridge->use) > 1) {
		struct nf_bridge_info *tmp = nf_bridge_alloc(skb);

		if (tmp) {
			memcpy(tmp, nf_bridge, sizeof(struct nf_bridge_info));
			atomic_set(&tmp->use, 1);
		}
164
		nf_bridge_put(nf_bridge);
165 166 167 168 169
		nf_bridge = tmp;
	}
	return nf_bridge;
}

170 171 172 173 174 175 176 177 178 179 180 181
static unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb)
{
	switch (skb->protocol) {
	case __cpu_to_be16(ETH_P_8021Q):
		return VLAN_HLEN;
	case __cpu_to_be16(ETH_P_PPP_SES):
		return PPPOE_SES_HLEN;
	default:
		return 0;
	}
}

182 183 184 185 186 187 188 189 190
static inline void nf_bridge_push_encap_header(struct sk_buff *skb)
{
	unsigned int len = nf_bridge_encap_header_len(skb);

	skb_push(skb, len);
	skb->network_header -= len;
}

static inline void nf_bridge_pull_encap_header(struct sk_buff *skb)
191
{
192 193 194 195 196
	unsigned int len = nf_bridge_encap_header_len(skb);

	skb_pull(skb, len);
	skb->network_header += len;
}
197

198 199 200 201 202 203 204 205
static inline void nf_bridge_pull_encap_header_rcsum(struct sk_buff *skb)
{
	unsigned int len = nf_bridge_encap_header_len(skb);

	skb_pull_rcsum(skb, len);
	skb->network_header += len;
}

206 207 208 209 210
/* When handing a packet over to the IP layer
 * check whether we have a skb that is in the
 * expected format
 */

211
static int br_parse_ip_options(struct sk_buff *skb)
212
{
213
	const struct iphdr *iph;
214 215 216
	struct net_device *dev = skb->dev;
	u32 len;

217 218 219
	if (!pskb_may_pull(skb, sizeof(struct iphdr)))
		goto inhdr_error;

220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
	iph = ip_hdr(skb);

	/* Basic sanity checks */
	if (iph->ihl < 5 || iph->version != 4)
		goto inhdr_error;

	if (!pskb_may_pull(skb, iph->ihl*4))
		goto inhdr_error;

	iph = ip_hdr(skb);
	if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
		goto inhdr_error;

	len = ntohs(iph->tot_len);
	if (skb->len < len) {
		IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INTRUNCATEDPKTS);
		goto drop;
	} else if (len < (iph->ihl*4))
		goto inhdr_error;

	if (pskb_trim_rcsum(skb, len)) {
		IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INDISCARDS);
		goto drop;
	}

245
	memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
246 247 248 249 250
	/* We should really parse IP options here but until
	 * somebody who actually uses IP options complains to
	 * us we'll just silently ignore the options because
	 * we're lazy!
	 */
251 252 253 254 255 256 257 258
	return 0;

inhdr_error:
	IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INHDRERRORS);
drop:
	return -1;
}

259 260
static void nf_bridge_update_protocol(struct sk_buff *skb)
{
261 262
	switch (skb->nf_bridge->orig_proto) {
	case BRNF_PROTO_8021Q:
263
		skb->protocol = htons(ETH_P_8021Q);
264 265
		break;
	case BRNF_PROTO_PPPOE:
266
		skb->protocol = htons(ETH_P_PPP_SES);
267 268 269 270
		break;
	case BRNF_PROTO_UNCHANGED:
		break;
	}
271 272
}

L
Linus Torvalds 已提交
273 274 275
/* PF_BRIDGE/PRE_ROUTING *********************************************/
/* Undo the changes made for ip6tables PREROUTING and continue the
 * bridge PRE_ROUTING hook. */
276
static int br_nf_pre_routing_finish_ipv6(struct sock *sk, struct sk_buff *skb)
L
Linus Torvalds 已提交
277
{
278
	struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
E
Eric Dumazet 已提交
279
	struct rtable *rt;
L
Linus Torvalds 已提交
280

281
	if (nf_bridge->pkt_otherhost) {
L
Linus Torvalds 已提交
282
		skb->pkt_type = PACKET_OTHERHOST;
283
		nf_bridge->pkt_otherhost = false;
L
Linus Torvalds 已提交
284 285 286
	}
	nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;

E
Eric Dumazet 已提交
287 288
	rt = bridge_parent_rtable(nf_bridge->physindev);
	if (!rt) {
289 290 291
		kfree_skb(skb);
		return 0;
	}
292
	skb_dst_set_noref(skb, &rt->dst);
L
Linus Torvalds 已提交
293 294

	skb->dev = nf_bridge->physindev;
295
	nf_bridge_update_protocol(skb);
296
	nf_bridge_push_encap_header(skb);
297 298
	NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, sk, skb,
		       skb->dev, NULL,
L
Linus Torvalds 已提交
299 300 301 302 303
		       br_handle_frame_finish, 1);

	return 0;
}

304 305 306 307 308
/* Obtain the correct destination MAC address, while preserving the original
 * source MAC address. If we already know this address, we just copy it. If we
 * don't, we use the neighbour framework to find out. In both cases, we make
 * sure that br_handle_frame_finish() is called afterwards.
 */
309
static int br_nf_pre_routing_finish_bridge(struct sock *sk, struct sk_buff *skb)
310
{
311
	struct neighbour *neigh;
312 313 314 315 316 317
	struct dst_entry *dst;

	skb->dev = bridge_parent(skb->dev);
	if (!skb->dev)
		goto free_skb;
	dst = skb_dst(skb);
318 319
	neigh = dst_neigh_lookup_skb(dst, skb);
	if (neigh) {
320
		struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
321 322 323 324 325
		int ret;

		if (neigh->hh.hh_len) {
			neigh_hh_bridge(&neigh->hh, skb);
			skb->dev = nf_bridge->physindev;
326
			ret = br_handle_frame_finish(sk, skb);
327 328 329 330 331 332 333
		} else {
			/* the neighbour function below overwrites the complete
			 * MAC header, so we save the Ethernet source address and
			 * protocol number.
			 */
			skb_copy_from_linear_data_offset(skb,
							 -(ETH_HLEN-ETH_ALEN),
334
							 nf_bridge->neigh_header,
335 336 337
							 ETH_HLEN-ETH_ALEN);
			/* tell br_dev_xmit to continue with forwarding */
			nf_bridge->mask |= BRNF_BRIDGED_DNAT;
338
			/* FIXME Need to refragment */
339 340 341 342
			ret = neigh->output(neigh, skb);
		}
		neigh_release(neigh);
		return ret;
343 344 345 346 347 348
	}
free_skb:
	kfree_skb(skb);
	return 0;
}

349 350
static bool daddr_was_changed(const struct sk_buff *skb,
			      const struct nf_bridge_info *nf_bridge)
351
{
352
	return ip_hdr(skb)->daddr != nf_bridge->ipv4_daddr;
353 354
}

L
Linus Torvalds 已提交
355
/* This requires some explaining. If DNAT has taken place,
356
 * we will need to fix up the destination Ethernet address.
357
 * This is also true when SNAT takes place (for the reply direction).
L
Linus Torvalds 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370
 *
 * There are two cases to consider:
 * 1. The packet was DNAT'ed to a device in the same bridge
 *    port group as it was received on. We can still bridge
 *    the packet.
 * 2. The packet was DNAT'ed to a different device, either
 *    a non-bridged device or another bridge port group.
 *    The packet will need to be routed.
 *
 * The correct way of distinguishing between these two cases is to
 * call ip_route_input() and to look at skb->dst->dev, which is
 * changed to the destination device if ip_route_input() succeeds.
 *
371
 * Let's first consider the case that ip_route_input() succeeds:
L
Linus Torvalds 已提交
372
 *
373 374 375
 * If the output device equals the logical bridge device the packet
 * came in on, we can consider this bridging. The corresponding MAC
 * address will be obtained in br_nf_pre_routing_finish_bridge.
L
Linus Torvalds 已提交
376 377
 * Otherwise, the packet is considered to be routed and we just
 * change the destination MAC address so that the packet will
378 379 380
 * later be passed up to the IP stack to be routed. For a redirected
 * packet, ip_route_input() will give back the localhost as output device,
 * which differs from the bridge device.
L
Linus Torvalds 已提交
381
 *
382
 * Let's now consider the case that ip_route_input() fails:
L
Linus Torvalds 已提交
383
 *
384 385
 * This can be because the destination address is martian, in which case
 * the packet will be dropped.
386 387 388
 * If IP forwarding is disabled, ip_route_input() will fail, while
 * ip_route_output_key() can return success. The source
 * address for ip_route_output_key() is set to zero, so ip_route_output_key()
L
Linus Torvalds 已提交
389
 * thinks we're handling a locally generated packet and won't care
390 391 392 393
 * if IP forwarding is enabled. If the output device equals the logical bridge
 * device, we proceed as if ip_route_input() succeeded. If it differs from the
 * logical bridge port or if ip_route_output_key() fails we drop the packet.
 */
394
static int br_nf_pre_routing_finish(struct sock *sk, struct sk_buff *skb)
L
Linus Torvalds 已提交
395 396
{
	struct net_device *dev = skb->dev;
397
	struct iphdr *iph = ip_hdr(skb);
398
	struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
E
Eric Dumazet 已提交
399
	struct rtable *rt;
400
	int err;
401 402 403 404
	int frag_max_size;

	frag_max_size = IPCB(skb)->frag_max_size;
	BR_INPUT_SKB_CB(skb)->frag_max_size = frag_max_size;
L
Linus Torvalds 已提交
405

406
	if (nf_bridge->pkt_otherhost) {
L
Linus Torvalds 已提交
407
		skb->pkt_type = PACKET_OTHERHOST;
408
		nf_bridge->pkt_otherhost = false;
L
Linus Torvalds 已提交
409 410
	}
	nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
411
	if (daddr_was_changed(skb, nf_bridge)) {
412
		if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) {
E
Eric Dumazet 已提交
413
			struct in_device *in_dev = __in_dev_get_rcu(dev);
414 415 416 417 418 419 420 421 422 423

			/* If err equals -EHOSTUNREACH the error is due to a
			 * martian destination or due to the fact that
			 * forwarding is disabled. For most martian packets,
			 * ip_route_output_key() will fail. It won't fail for 2 types of
			 * martian destinations: loopback destinations and destination
			 * 0.0.0.0. In both cases the packet will be dropped because the
			 * destination is the loopback device and not the bridge. */
			if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev))
				goto free_skb;
L
Linus Torvalds 已提交
424

425 426
			rt = ip_route_output(dev_net(dev), iph->daddr, 0,
					     RT_TOS(iph->tos), 0);
427
			if (!IS_ERR(rt)) {
428
				/* - Bridged-and-DNAT'ed traffic doesn't
429
				 *   require ip_forwarding. */
430 431
				if (rt->dst.dev == dev) {
					skb_dst_set(skb, &rt->dst);
L
Linus Torvalds 已提交
432 433
					goto bridged_dnat;
				}
434
				ip_rt_put(rt);
L
Linus Torvalds 已提交
435
			}
436
free_skb:
L
Linus Torvalds 已提交
437 438 439
			kfree_skb(skb);
			return 0;
		} else {
E
Eric Dumazet 已提交
440
			if (skb_dst(skb)->dev == dev) {
L
Linus Torvalds 已提交
441 442
bridged_dnat:
				skb->dev = nf_bridge->physindev;
443
				nf_bridge_update_protocol(skb);
444
				nf_bridge_push_encap_header(skb);
445 446
				NF_HOOK_THRESH(NFPROTO_BRIDGE,
					       NF_BR_PRE_ROUTING,
447
					       sk, skb, skb->dev, NULL,
L
Linus Torvalds 已提交
448 449 450 451
					       br_nf_pre_routing_finish_bridge,
					       1);
				return 0;
			}
452
			ether_addr_copy(eth_hdr(skb)->h_dest, dev->dev_addr);
L
Linus Torvalds 已提交
453 454 455
			skb->pkt_type = PACKET_HOST;
		}
	} else {
E
Eric Dumazet 已提交
456 457
		rt = bridge_parent_rtable(nf_bridge->physindev);
		if (!rt) {
458 459 460
			kfree_skb(skb);
			return 0;
		}
461
		skb_dst_set_noref(skb, &rt->dst);
L
Linus Torvalds 已提交
462 463 464
	}

	skb->dev = nf_bridge->physindev;
465
	nf_bridge_update_protocol(skb);
466
	nf_bridge_push_encap_header(skb);
467 468
	NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, sk, skb,
		       skb->dev, NULL,
L
Linus Torvalds 已提交
469 470 471 472 473
		       br_handle_frame_finish, 1);

	return 0;
}

474 475 476 477 478
static struct net_device *brnf_get_logical_dev(struct sk_buff *skb, const struct net_device *dev)
{
	struct net_device *vlan, *br;

	br = bridge_parent(dev);
479
	if (brnf_pass_vlan_indev == 0 || !skb_vlan_tag_present(skb))
480 481
		return br;

482
	vlan = __vlan_find_dev_deep_rcu(br, skb->vlan_proto,
483
				    skb_vlan_tag_get(skb) & VLAN_VID_MASK);
484 485 486 487

	return vlan ? vlan : br;
}

L
Linus Torvalds 已提交
488
/* Some common code for IPv4/IPv6 */
489
static struct net_device *setup_pre_routing(struct sk_buff *skb)
L
Linus Torvalds 已提交
490
{
491
	struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
L
Linus Torvalds 已提交
492 493 494

	if (skb->pkt_type == PACKET_OTHERHOST) {
		skb->pkt_type = PACKET_HOST;
495
		nf_bridge->pkt_otherhost = true;
L
Linus Torvalds 已提交
496 497 498 499
	}

	nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
	nf_bridge->physindev = skb->dev;
500
	skb->dev = brnf_get_logical_dev(skb, skb->dev);
501

502
	if (skb->protocol == htons(ETH_P_8021Q))
503
		nf_bridge->orig_proto = BRNF_PROTO_8021Q;
504
	else if (skb->protocol == htons(ETH_P_PPP_SES))
505
		nf_bridge->orig_proto = BRNF_PROTO_PPPOE;
506

507 508
	/* Must drop socket now because of tproxy. */
	skb_orphan(skb);
509
	return skb->dev;
L
Linus Torvalds 已提交
510 511 512 513 514
}

/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
static int check_hbh_len(struct sk_buff *skb)
{
515
	unsigned char *raw = (u8 *)(ipv6_hdr(skb) + 1);
L
Linus Torvalds 已提交
516
	u32 pkt_len;
517 518
	const unsigned char *nh = skb_network_header(skb);
	int off = raw - nh;
519
	int len = (raw[1] + 1) << 3;
L
Linus Torvalds 已提交
520 521 522 523 524 525 526 527

	if ((raw + len) - skb->data > skb_headlen(skb))
		goto bad;

	off += 2;
	len -= 2;

	while (len > 0) {
528
		int optlen = nh[off + 1] + 2;
L
Linus Torvalds 已提交
529

530
		switch (nh[off]) {
531
		case IPV6_TLV_PAD1:
L
Linus Torvalds 已提交
532 533 534 535 536 537 538
			optlen = 1;
			break;

		case IPV6_TLV_PADN:
			break;

		case IPV6_TLV_JUMBO:
539
			if (nh[off + 1] != 4 || (off & 3) != 2)
L
Linus Torvalds 已提交
540
				goto bad;
541
			pkt_len = ntohl(*(__be32 *) (nh + off + 2));
542
			if (pkt_len <= IPV6_MAXPLEN ||
543
			    ipv6_hdr(skb)->payload_len)
544
				goto bad;
L
Linus Torvalds 已提交
545 546
			if (pkt_len > skb->len - sizeof(struct ipv6hdr))
				goto bad;
547
			if (pskb_trim_rcsum(skb,
548
					    pkt_len + sizeof(struct ipv6hdr)))
549
				goto bad;
550
			nh = skb_network_header(skb);
L
Linus Torvalds 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
			break;
		default:
			if (optlen > len)
				goto bad;
			break;
		}
		off += optlen;
		len -= optlen;
	}
	if (len == 0)
		return 0;
bad:
	return -1;

}

/* Replicate the checks that IPv6 does on packet reception and pass the packet
 * to ip6tables, which doesn't support NAT, so things are fairly simple. */
569
static unsigned int br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops,
570
					   struct sk_buff *skb,
571
					   const struct nf_hook_state *state)
L
Linus Torvalds 已提交
572
{
573
	const struct ipv6hdr *hdr;
L
Linus Torvalds 已提交
574 575 576
	u32 pkt_len;

	if (skb->len < sizeof(struct ipv6hdr))
577
		return NF_DROP;
L
Linus Torvalds 已提交
578 579

	if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
580
		return NF_DROP;
L
Linus Torvalds 已提交
581

582
	hdr = ipv6_hdr(skb);
L
Linus Torvalds 已提交
583 584

	if (hdr->version != 6)
585
		return NF_DROP;
L
Linus Torvalds 已提交
586 587 588 589 590

	pkt_len = ntohs(hdr->payload_len);

	if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
		if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
591
			return NF_DROP;
H
Herbert Xu 已提交
592
		if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr)))
593
			return NF_DROP;
L
Linus Torvalds 已提交
594 595
	}
	if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
596
		return NF_DROP;
L
Linus Torvalds 已提交
597

598
	nf_bridge_put(skb->nf_bridge);
599
	if (!nf_bridge_alloc(skb))
L
Linus Torvalds 已提交
600
		return NF_DROP;
601 602
	if (!setup_pre_routing(skb))
		return NF_DROP;
L
Linus Torvalds 已提交
603

604
	skb->protocol = htons(ETH_P_IPV6);
605 606
	NF_HOOK(NFPROTO_IPV6, NF_INET_PRE_ROUTING, state->sk, skb,
		skb->dev, NULL,
L
Linus Torvalds 已提交
607 608 609 610 611 612 613 614 615 616 617
		br_nf_pre_routing_finish_ipv6);

	return NF_STOLEN;
}

/* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
 * Replicate the checks that IPv4 does on packet reception.
 * Set skb->dev to the bridge device (i.e. parent of the
 * receiving device) to make netfilter happy, the REDIRECT
 * target in particular.  Save the original destination IP
 * address to be able to detect DNAT afterwards. */
618 619
static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
				      struct sk_buff *skb,
620
				      const struct nf_hook_state *state)
L
Linus Torvalds 已提交
621
{
622
	struct nf_bridge_info *nf_bridge;
623 624
	struct net_bridge_port *p;
	struct net_bridge *br;
625 626 627
	__u32 len = nf_bridge_encap_header_len(skb);

	if (unlikely(!pskb_may_pull(skb, len)))
628
		return NF_DROP;
L
Linus Torvalds 已提交
629

630
	p = br_port_get_rcu(state->in);
631
	if (p == NULL)
632
		return NF_DROP;
633 634
	br = p->br;

635
	if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb)) {
636
		if (!brnf_call_ip6tables && !br->nf_call_ip6tables)
L
Linus Torvalds 已提交
637
			return NF_ACCEPT;
638

639
		nf_bridge_pull_encap_header_rcsum(skb);
640
		return br_nf_pre_routing_ipv6(ops, skb, state);
L
Linus Torvalds 已提交
641
	}
642 643

	if (!brnf_call_iptables && !br->nf_call_iptables)
L
Linus Torvalds 已提交
644 645
		return NF_ACCEPT;

646
	if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb))
L
Linus Torvalds 已提交
647 648
		return NF_ACCEPT;

649
	nf_bridge_pull_encap_header_rcsum(skb);
L
Linus Torvalds 已提交
650

651
	if (br_parse_ip_options(skb))
652
		return NF_DROP;
653

654
	nf_bridge_put(skb->nf_bridge);
655
	if (!nf_bridge_alloc(skb))
L
Linus Torvalds 已提交
656
		return NF_DROP;
657 658
	if (!setup_pre_routing(skb))
		return NF_DROP;
659

660 661 662
	nf_bridge = nf_bridge_info_get(skb);
	nf_bridge->ipv4_daddr = ip_hdr(skb)->daddr;

663
	skb->protocol = htons(ETH_P_IP);
L
Linus Torvalds 已提交
664

665 666
	NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, state->sk, skb,
		skb->dev, NULL,
L
Linus Torvalds 已提交
667 668 669 670 671 672 673 674 675 676 677 678 679
		br_nf_pre_routing_finish);

	return NF_STOLEN;
}


/* PF_BRIDGE/LOCAL_IN ************************************************/
/* The packet is locally destined, which requires a real
 * dst_entry, so detach the fake one.  On the way up, the
 * packet would pass through PRE_ROUTING again (which already
 * took place when the packet entered the bridge), but we
 * register an IPv4 PRE_ROUTING 'sabotage' hook that will
 * prevent this from happening. */
680 681
static unsigned int br_nf_local_in(const struct nf_hook_ops *ops,
				   struct sk_buff *skb,
682
				   const struct nf_hook_state *state)
L
Linus Torvalds 已提交
683
{
684
	br_drop_fake_rtable(skb);
L
Linus Torvalds 已提交
685 686 687 688
	return NF_ACCEPT;
}

/* PF_BRIDGE/FORWARD *************************************************/
689
static int br_nf_forward_finish(struct sock *sk, struct sk_buff *skb)
L
Linus Torvalds 已提交
690
{
691
	struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
L
Linus Torvalds 已提交
692 693
	struct net_device *in;

694
	if (!IS_ARP(skb) && !IS_VLAN_ARP(skb)) {
695 696 697 698 699 700 701
		int frag_max_size;

		if (skb->protocol == htons(ETH_P_IP)) {
			frag_max_size = IPCB(skb)->frag_max_size;
			BR_INPUT_SKB_CB(skb)->frag_max_size = frag_max_size;
		}

L
Linus Torvalds 已提交
702
		in = nf_bridge->physindev;
703
		if (nf_bridge->pkt_otherhost) {
L
Linus Torvalds 已提交
704
			skb->pkt_type = PACKET_OTHERHOST;
705
			nf_bridge->pkt_otherhost = false;
L
Linus Torvalds 已提交
706
		}
707
		nf_bridge_update_protocol(skb);
L
Linus Torvalds 已提交
708 709 710
	} else {
		in = *((struct net_device **)(skb->cb));
	}
711
	nf_bridge_push_encap_header(skb);
712

713 714
	NF_HOOK_THRESH(NFPROTO_BRIDGE, NF_BR_FORWARD, sk, skb,
		       in, skb->dev, br_forward_finish, 1);
L
Linus Torvalds 已提交
715 716 717
	return 0;
}

718

L
Linus Torvalds 已提交
719 720 721 722 723
/* This is the 'purely bridged' case.  For IP, we pass the packet to
 * netfilter with indev and outdev set to the bridge device,
 * but we are still able to filter on the 'real' indev/outdev
 * because of the physdev module. For ARP, indev and outdev are the
 * bridge ports. */
724 725
static unsigned int br_nf_forward_ip(const struct nf_hook_ops *ops,
				     struct sk_buff *skb,
726
				     const struct nf_hook_state *state)
L
Linus Torvalds 已提交
727 728
{
	struct nf_bridge_info *nf_bridge;
729
	struct net_device *parent;
730
	u_int8_t pf;
L
Linus Torvalds 已提交
731 732 733 734

	if (!skb->nf_bridge)
		return NF_ACCEPT;

735 736 737 738 739
	/* Need exclusive nf_bridge_info since we might have multiple
	 * different physoutdevs. */
	if (!nf_bridge_unshare(skb))
		return NF_DROP;

740 741 742 743
	nf_bridge = nf_bridge_info_get(skb);
	if (!nf_bridge)
		return NF_DROP;

744
	parent = bridge_parent(state->out);
745 746 747
	if (!parent)
		return NF_DROP;

748
	if (IS_IP(skb) || IS_VLAN_IP(skb) || IS_PPPOE_IP(skb))
749
		pf = NFPROTO_IPV4;
750
	else if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb))
751
		pf = NFPROTO_IPV6;
752 753
	else
		return NF_ACCEPT;
L
Linus Torvalds 已提交
754

755
	nf_bridge_pull_encap_header(skb);
L
Linus Torvalds 已提交
756 757 758

	if (skb->pkt_type == PACKET_OTHERHOST) {
		skb->pkt_type = PACKET_HOST;
759
		nf_bridge->pkt_otherhost = true;
L
Linus Torvalds 已提交
760 761
	}

762 763 764 765 766 767 768 769
	if (pf == NFPROTO_IPV4) {
		int frag_max = BR_INPUT_SKB_CB(skb)->frag_max_size;

		if (br_parse_ip_options(skb))
			return NF_DROP;

		IPCB(skb)->frag_max_size = frag_max;
	}
770

L
Linus Torvalds 已提交
771
	nf_bridge->physoutdev = skb->dev;
772
	if (pf == NFPROTO_IPV4)
773 774 775
		skb->protocol = htons(ETH_P_IP);
	else
		skb->protocol = htons(ETH_P_IPV6);
L
Linus Torvalds 已提交
776

777 778
	NF_HOOK(pf, NF_INET_FORWARD, NULL, skb,
		brnf_get_logical_dev(skb, state->in),
779
		parent,	br_nf_forward_finish);
L
Linus Torvalds 已提交
780 781 782 783

	return NF_STOLEN;
}

784 785
static unsigned int br_nf_forward_arp(const struct nf_hook_ops *ops,
				      struct sk_buff *skb,
786
				      const struct nf_hook_state *state)
L
Linus Torvalds 已提交
787
{
788 789
	struct net_bridge_port *p;
	struct net_bridge *br;
L
Linus Torvalds 已提交
790 791
	struct net_device **d = (struct net_device **)(skb->cb);

792
	p = br_port_get_rcu(state->out);
793 794 795 796 797
	if (p == NULL)
		return NF_ACCEPT;
	br = p->br;

	if (!brnf_call_arptables && !br->nf_call_arptables)
L
Linus Torvalds 已提交
798 799
		return NF_ACCEPT;

800
	if (!IS_ARP(skb)) {
801
		if (!IS_VLAN_ARP(skb))
L
Linus Torvalds 已提交
802
			return NF_ACCEPT;
803
		nf_bridge_pull_encap_header(skb);
L
Linus Torvalds 已提交
804 805
	}

806
	if (arp_hdr(skb)->ar_pln != 4) {
807
		if (IS_VLAN_ARP(skb))
808
			nf_bridge_push_encap_header(skb);
L
Linus Torvalds 已提交
809 810
		return NF_ACCEPT;
	}
811
	*d = state->in;
812 813
	NF_HOOK(NFPROTO_ARP, NF_ARP_FORWARD, state->sk, skb,
		state->in, state->out, br_nf_forward_finish);
L
Linus Torvalds 已提交
814 815 816 817

	return NF_STOLEN;
}

818
#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
819
static int br_nf_push_frag_xmit(struct sock *sk, struct sk_buff *skb)
820
{
821
	struct brnf_frag_data *data;
822 823
	int err;

824 825
	data = this_cpu_ptr(&brnf_frag_data_storage);
	err = skb_cow_head(skb, data->size);
826

827
	if (err) {
828 829 830 831
		kfree_skb(skb);
		return 0;
	}

832 833 834
	skb_copy_to_linear_data_offset(skb, -data->size, data->mac, data->size);
	__skb_push(skb, data->encap_size);

835
	return br_dev_queue_push_xmit(sk, skb);
836 837
}

838
static int br_nf_dev_queue_xmit(struct sock *sk, struct sk_buff *skb)
839
{
840
	int ret;
841
	int frag_max_size;
842
	unsigned int mtu_reserved;
843

844
	if (skb_is_gso(skb) || skb->protocol != htons(ETH_P_IP))
845
		return br_dev_queue_push_xmit(sk, skb);
846 847

	mtu_reserved = nf_bridge_mtu_reduction(skb);
848 849 850
	/* This is wrong! We should preserve the original fragment
	 * boundaries by preserving frag_list rather than refragmenting.
	 */
851
	if (skb->len + mtu_reserved > skb->dev->mtu) {
852 853
		struct brnf_frag_data *data;

854
		frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size;
855 856 857
		if (br_parse_ip_options(skb))
			/* Drop invalid packet */
			return NF_DROP;
858
		IPCB(skb)->frag_max_size = frag_max_size;
859 860 861 862 863 864 865 866 867 868

		nf_bridge_update_protocol(skb);

		data = this_cpu_ptr(&brnf_frag_data_storage);
		data->encap_size = nf_bridge_encap_header_len(skb);
		data->size = ETH_HLEN + data->encap_size;

		skb_copy_from_linear_data_offset(skb, -data->size, data->mac,
						 data->size);

869
		ret = ip_fragment(sk, skb, br_nf_push_frag_xmit);
870
	} else {
871
		ret = br_dev_queue_push_xmit(sk, skb);
872
	}
873 874

	return ret;
875
}
876
#else
877
static int br_nf_dev_queue_xmit(struct sock *sk, struct sk_buff *skb)
878
{
879
        return br_dev_queue_push_xmit(sk, skb);
880 881
}
#endif
L
Linus Torvalds 已提交
882 883

/* PF_BRIDGE/POST_ROUTING ********************************************/
884 885
static unsigned int br_nf_post_routing(const struct nf_hook_ops *ops,
				       struct sk_buff *skb,
886
				       const struct nf_hook_state *state)
L
Linus Torvalds 已提交
887
{
888
	struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
L
Linus Torvalds 已提交
889
	struct net_device *realoutdev = bridge_parent(skb->dev);
890
	u_int8_t pf;
L
Linus Torvalds 已提交
891

892 893 894 895 896 897
	/* if nf_bridge is set, but ->physoutdev is NULL, this packet came in
	 * on a bridge, but was delivered locally and is now being routed:
	 *
	 * POST_ROUTING was already invoked from the ip stack.
	 */
	if (!nf_bridge || !nf_bridge->physoutdev)
898 899
		return NF_ACCEPT;

900 901 902
	if (!realoutdev)
		return NF_DROP;

903
	if (IS_IP(skb) || IS_VLAN_IP(skb) || IS_PPPOE_IP(skb))
904
		pf = NFPROTO_IPV4;
905
	else if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb))
906
		pf = NFPROTO_IPV6;
907 908
	else
		return NF_ACCEPT;
L
Linus Torvalds 已提交
909 910 911 912 913

	/* We assume any code from br_dev_queue_push_xmit onwards doesn't care
	 * about the value of skb->pkt_type. */
	if (skb->pkt_type == PACKET_OTHERHOST) {
		skb->pkt_type = PACKET_HOST;
914
		nf_bridge->pkt_otherhost = true;
L
Linus Torvalds 已提交
915 916
	}

917
	nf_bridge_pull_encap_header(skb);
918
	if (pf == NFPROTO_IPV4)
919 920 921
		skb->protocol = htons(ETH_P_IP);
	else
		skb->protocol = htons(ETH_P_IPV6);
L
Linus Torvalds 已提交
922

923 924
	NF_HOOK(pf, NF_INET_POST_ROUTING, state->sk, skb,
		NULL, realoutdev,
925
		br_nf_dev_queue_xmit);
L
Linus Torvalds 已提交
926 927 928 929 930 931 932

	return NF_STOLEN;
}

/* IP/SABOTAGE *****************************************************/
/* Don't hand locally destined packets to PF_INET(6)/PRE_ROUTING
 * for the second time. */
933 934
static unsigned int ip_sabotage_in(const struct nf_hook_ops *ops,
				   struct sk_buff *skb,
935
				   const struct nf_hook_state *state)
L
Linus Torvalds 已提交
936
{
937 938
	if (skb->nf_bridge &&
	    !(skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
L
Linus Torvalds 已提交
939 940 941 942 943 944
		return NF_STOP;
	}

	return NF_ACCEPT;
}

945 946 947 948 949 950 951 952 953 954 955
/* This is called when br_netfilter has called into iptables/netfilter,
 * and DNAT has taken place on a bridge-forwarded packet.
 *
 * neigh->output has created a new MAC header, with local br0 MAC
 * as saddr.
 *
 * This restores the original MAC saddr of the bridged packet
 * before invoking bridge forward logic to transmit the packet.
 */
static void br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb)
{
956
	struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
957 958 959 960

	skb_pull(skb, ETH_HLEN);
	nf_bridge->mask &= ~BRNF_BRIDGED_DNAT;

961 962 963 964 965
	BUILD_BUG_ON(sizeof(nf_bridge->neigh_header) != (ETH_HLEN - ETH_ALEN));

	skb_copy_to_linear_data_offset(skb, -(ETH_HLEN - ETH_ALEN),
				       nf_bridge->neigh_header,
				       ETH_HLEN - ETH_ALEN);
966
	skb->dev = nf_bridge->physindev;
967
	br_handle_frame_finish(NULL, skb);
968 969
}

970
static int br_nf_dev_xmit(struct sk_buff *skb)
971 972 973 974 975 976 977
{
	if (skb->nf_bridge && (skb->nf_bridge->mask & BRNF_BRIDGED_DNAT)) {
		br_nf_pre_routing_finish_bridge_slow(skb);
		return 1;
	}
	return 0;
}
978 979 980 981

static const struct nf_br_ops br_ops = {
	.br_dev_xmit_hook =	br_nf_dev_xmit,
};
982

983 984 985 986 987
void br_netfilter_enable(void)
{
}
EXPORT_SYMBOL_GPL(br_netfilter_enable);

988 989
/* For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
 * br_dev_queue_push_xmit is called afterwards */
990
static struct nf_hook_ops br_nf_ops[] __read_mostly = {
991 992 993
	{
		.hook = br_nf_pre_routing,
		.owner = THIS_MODULE,
994
		.pf = NFPROTO_BRIDGE,
995 996 997 998 999 1000
		.hooknum = NF_BR_PRE_ROUTING,
		.priority = NF_BR_PRI_BRNF,
	},
	{
		.hook = br_nf_local_in,
		.owner = THIS_MODULE,
1001
		.pf = NFPROTO_BRIDGE,
1002 1003 1004 1005 1006 1007
		.hooknum = NF_BR_LOCAL_IN,
		.priority = NF_BR_PRI_BRNF,
	},
	{
		.hook = br_nf_forward_ip,
		.owner = THIS_MODULE,
1008
		.pf = NFPROTO_BRIDGE,
1009 1010 1011 1012 1013 1014
		.hooknum = NF_BR_FORWARD,
		.priority = NF_BR_PRI_BRNF - 1,
	},
	{
		.hook = br_nf_forward_arp,
		.owner = THIS_MODULE,
1015
		.pf = NFPROTO_BRIDGE,
1016 1017 1018 1019 1020 1021
		.hooknum = NF_BR_FORWARD,
		.priority = NF_BR_PRI_BRNF,
	},
	{
		.hook = br_nf_post_routing,
		.owner = THIS_MODULE,
1022
		.pf = NFPROTO_BRIDGE,
1023 1024 1025 1026 1027 1028
		.hooknum = NF_BR_POST_ROUTING,
		.priority = NF_BR_PRI_LAST,
	},
	{
		.hook = ip_sabotage_in,
		.owner = THIS_MODULE,
1029
		.pf = NFPROTO_IPV4,
1030 1031 1032 1033 1034 1035
		.hooknum = NF_INET_PRE_ROUTING,
		.priority = NF_IP_PRI_FIRST,
	},
	{
		.hook = ip_sabotage_in,
		.owner = THIS_MODULE,
1036
		.pf = NFPROTO_IPV6,
1037 1038 1039
		.hooknum = NF_INET_PRE_ROUTING,
		.priority = NF_IP6_PRI_FIRST,
	},
L
Linus Torvalds 已提交
1040 1041 1042 1043
};

#ifdef CONFIG_SYSCTL
static
1044
int brnf_sysctl_call_tables(struct ctl_table *ctl, int write,
1045
			    void __user *buffer, size_t *lenp, loff_t *ppos)
L
Linus Torvalds 已提交
1046 1047 1048
{
	int ret;

1049
	ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
L
Linus Torvalds 已提交
1050 1051 1052 1053 1054 1055

	if (write && *(int *)(ctl->data))
		*(int *)(ctl->data) = 1;
	return ret;
}

1056
static struct ctl_table brnf_table[] = {
L
Linus Torvalds 已提交
1057 1058 1059 1060 1061
	{
		.procname	= "bridge-nf-call-arptables",
		.data		= &brnf_call_arptables,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
1062
		.proc_handler	= brnf_sysctl_call_tables,
L
Linus Torvalds 已提交
1063 1064 1065 1066 1067 1068
	},
	{
		.procname	= "bridge-nf-call-iptables",
		.data		= &brnf_call_iptables,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
1069
		.proc_handler	= brnf_sysctl_call_tables,
L
Linus Torvalds 已提交
1070 1071 1072 1073 1074 1075
	},
	{
		.procname	= "bridge-nf-call-ip6tables",
		.data		= &brnf_call_ip6tables,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
1076
		.proc_handler	= brnf_sysctl_call_tables,
L
Linus Torvalds 已提交
1077 1078 1079 1080 1081 1082
	},
	{
		.procname	= "bridge-nf-filter-vlan-tagged",
		.data		= &brnf_filter_vlan_tagged,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
1083
		.proc_handler	= brnf_sysctl_call_tables,
1084 1085 1086 1087 1088 1089
	},
	{
		.procname	= "bridge-nf-filter-pppoe-tagged",
		.data		= &brnf_filter_pppoe_tagged,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
1090
		.proc_handler	= brnf_sysctl_call_tables,
L
Linus Torvalds 已提交
1091
	},
1092 1093 1094 1095 1096 1097 1098
	{
		.procname	= "bridge-nf-pass-vlan-input-dev",
		.data		= &brnf_pass_vlan_indev,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= brnf_sysctl_call_tables,
	},
1099
	{ }
L
Linus Torvalds 已提交
1100 1101 1102
};
#endif

1103
static int __init br_netfilter_init(void)
L
Linus Torvalds 已提交
1104
{
1105
	int ret;
L
Linus Torvalds 已提交
1106

1107
	ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
1108
	if (ret < 0)
L
Linus Torvalds 已提交
1109
		return ret;
1110

L
Linus Torvalds 已提交
1111
#ifdef CONFIG_SYSCTL
1112
	brnf_sysctl_header = register_net_sysctl(&init_net, "net/bridge", brnf_table);
L
Linus Torvalds 已提交
1113
	if (brnf_sysctl_header == NULL) {
1114 1115
		printk(KERN_WARNING
		       "br_netfilter: can't register to sysctl.\n");
1116 1117
		nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
		return -ENOMEM;
L
Linus Torvalds 已提交
1118 1119
	}
#endif
1120
	RCU_INIT_POINTER(nf_br_ops, &br_ops);
L
Linus Torvalds 已提交
1121 1122 1123 1124
	printk(KERN_NOTICE "Bridge firewalling registered\n");
	return 0;
}

1125
static void __exit br_netfilter_fini(void)
L
Linus Torvalds 已提交
1126
{
1127
	RCU_INIT_POINTER(nf_br_ops, NULL);
1128
	nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));
L
Linus Torvalds 已提交
1129
#ifdef CONFIG_SYSCTL
1130
	unregister_net_sysctl_table(brnf_sysctl_header);
L
Linus Torvalds 已提交
1131 1132
#endif
}
1133 1134 1135 1136 1137 1138 1139 1140

module_init(br_netfilter_init);
module_exit(br_netfilter_fini);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Lennert Buytenhek <buytenh@gnu.org>");
MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
MODULE_DESCRIPTION("Linux ethernet netfilter firewall bridge");