Skip to content

Commit 3c171f4

Browse files
ummakynesdavem330
authored andcommitted
netfilter: bridge: add connection tracking system
This patch adds basic connection tracking support for the bridge, including initial IPv4 support. This patch register two hooks to deal with the bridge forwarding path, one from the bridge prerouting hook to call nf_conntrack_in(); and another from the bridge postrouting hook to confirm the entry. The conntrack bridge prerouting hook defragments packets before passing them to nf_conntrack_in() to look up for an existing entry, otherwise a new entry is allocated and it is attached to the skbuff. The conntrack bridge postrouting hook confirms new conntrack entries, ie. if this is the first packet seen, then it adds the entry to the hashtable and (if needed) it refragments the skbuff into the original fragments, leaving the geometry as is if possible. Exceptions are linearized skbuffs, eg. skbuffs that are passed up to nfqueue and conntrack helpers, as well as cloned skbuff for the local delivery (eg. tcpdump), also in case of bridge port flooding (cloned skbuff too). The packet defragmentation is done through the ip_defrag() call. This forces us to save the bridge control buffer, reset the IP control buffer area and then restore it after call. This function also bumps the IP fragmentation statistics, it would be probably desiderable to have independent statistics for the bridge defragmentation/refragmentation. The maximum fragment length is stored in the control buffer and it is used to refragment the skbuff from the postrouting path. The new fraglist splitter and fragment transformer APIs are used to implement the bridge refragmentation code. The br_ip_fragment() function drops the packet in case the maximum fragment size seen is larger than the output port MTU. This patchset follows the principle that conntrack should not drop packets, so users can do it through policy via invalid state matching. Like br_netfilter, there is no refragmentation for packets that are passed up for local delivery, ie. prerouting -> input path. There are calls to nf_reset() already in several spots in the stack since time ago already, eg. af_packet, that show that skbuff fraglist handling from the netif_rx path is supported already. The helpers are called from the postrouting hook, before confirmation, from there we may see packet floods to bridge ports. Then, although unlikely, this may result in exercising the helpers many times for each clone. It would be good to explore how to pass all the packets in a list to the conntrack hook to do this handle only once for this case. Thanks to Florian Westphal for handing me over an initial patchset version to add support for conntrack bridge. Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d035f19 commit 3c171f4

File tree

8 files changed

+410
-4
lines changed

8 files changed

+410
-4
lines changed

include/net/netfilter/nf_conntrack_bridge.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ struct nf_ct_bridge_info {
1010
void nf_ct_bridge_register(struct nf_ct_bridge_info *info);
1111
void nf_ct_bridge_unregister(struct nf_ct_bridge_info *info);
1212

13+
struct nf_ct_bridge_frag_data {
14+
char mac[ETH_HLEN];
15+
bool vlan_present;
16+
u16 vlan_tci;
17+
__be16 vlan_proto;
18+
};
19+
1320
#endif

include/net/netfilter/nf_conntrack_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)
6464
return ret;
6565
}
6666

67+
unsigned int nf_confirm(struct sk_buff *skb, unsigned int protoff,
68+
struct nf_conn *ct, enum ip_conntrack_info ctinfo);
69+
6770
void print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
6871
const struct nf_conntrack_l4proto *proto);
6972

net/bridge/br_device.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
5656

5757
br_switchdev_frame_unmark(skb);
5858
BR_INPUT_SKB_CB(skb)->brdev = dev;
59+
BR_INPUT_SKB_CB(skb)->frag_max_size = 0;
5960

6061
skb_reset_mac_header(skb);
6162
eth = eth_hdr(skb);

net/bridge/br_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ struct net_bridge {
425425
struct br_input_skb_cb {
426426
struct net_device *brdev;
427427

428+
u16 frag_max_size;
428429
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
429430
u8 igmp;
430431
u8 mrouters_only:1;

net/bridge/netfilter/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ config NF_LOG_BRIDGE
1919
tristate "Bridge packet logging"
2020
select NF_LOG_COMMON
2121

22+
config NF_CONNTRACK_BRIDGE
23+
tristate "IPv4/IPV6 bridge connection tracking support"
24+
depends on NF_CONNTRACK
25+
default n
26+
help
27+
Connection tracking keeps a record of what packets have passed
28+
through your machine, in order to figure out how they are related
29+
into connections. This is used to enhance packet filtering via
30+
stateful policies. Enable this if you want native tracking from
31+
the bridge. This provides a replacement for the `br_netfilter'
32+
infrastructure.
33+
34+
To compile it as a module, choose M here. If unsure, say N.
35+
2236
endif # NF_TABLES_BRIDGE
2337

2438
menuconfig BRIDGE_NF_EBTABLES

net/bridge/netfilter/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
obj-$(CONFIG_NFT_BRIDGE_REJECT) += nft_reject_bridge.o
77

8+
# connection tracking
9+
obj-$(CONFIG_NF_CONNTRACK_BRIDGE) += nf_conntrack_bridge.o
10+
811
# packet logging
912
obj-$(CONFIG_NF_LOG_BRIDGE) += nf_log_bridge.o
1013

0 commit comments

Comments
 (0)