connection tracking support for bridge
Subsystems (5)
Pablo Neira Ayuso
maintainercover connection tracking support for bridge
Hi,
This patchset add connection tracking support for the bridge family.
Patches from 1 to 6 split the existing refragmentation codebase into smaller functions that allows us to build specific refragmentation routine for the bridge, motivations for this are:
* ip_do_fragment() assumes the skbuff is called from IP stack, hence the control buffer area is assumed to have an IP_CB layout, this forces to save and restore this area.
* ip_do_fragment() assumes that a dst entry is attached to the skbuff which is not the case from the bridge codebase. This would force us to emulate a dst object.
* ip_do_fragment() alters fragmentation geometry to make it fit into the mtu. From the bridge, it is desiderable to leave geometry untouched, simply drop packets if the maximum fragment size is larger than the mtu. There are a few exceptions in this patchset though, such as linearized skbuff (coming from conntrack helpers doing so) where geometry is lost for us, and for cloned skbuffs, either due to port flood or passed up for tap delivery. For both cases, it should be possible with a more code and the cost of introducing more complexity.
These initial patches extract code from the existing refragmentation infrastructure that can be re-used to build a custom refragmentation routine that deals with the bridge specificities. This batch is composed of the following patches:
* Patches 1/10 and 2/10 add the fraglist iterator. This infrastructure extracts the code from ip_do_fragment() to split a fraglist into fragments, then call the output callback for each fragmented skbuff. The API consists of ip_fraglist_init() to start the iterator internal state, then ip_fraglist_prepare() to restore restore the IPv4 header in the fragment and, finally, ip_fraglist_next() to obtain the fragmented skbuff from the fraglist. Similar API is introduced for IPv6.
* Patches 3/10 and 4/10 add the fragment transformer. This infrastructure extracts the code from ip_do_fragment() to split a linearized skbuff into fragmented skbuffs. This is also useful for the skbuff clone case, needed in case of floods to multiple bridge ports or when passing packets to the tap (ie. tcpdump), so this transformer can also deal with fraglists. The API consists of ip6_frag_init() to start the internal state of the transformer and ip6_frag_next() to build and fetch a fragment.
* Patches 5/10 and 6/10 move the IPCB specific code away from these two new APIs, so it can be used from the bridge without saving and restoring the control buffer area.
After preparation patches, this batch adds the conntrack support for the bridge family:
* Patch 7/10 adds infrastructure to register and to unregister the nf_conntrack_bridge module via nf_ct_bridge_register() and nf_ct_bridge_unregister(). This allows us to transparently reuse the ct extension to match on the ct state without changes.
* Patch 8/10 adds IPv4 conntrack support for bridge. This add the nf_conntrack_bridge module which registers two hooks, one at bridge prerouting and another at bridge postrouting. For traffic that is being forwarded, a conntrack entry is created at bridge prerouting and confirmed at bridge postrouting. ARP packets are explicitly untracked. We also follow the "do not drop packets from conntrack", as invalid packets can be just dropped via policy.
* Patch 9/10 adds IPv6 support for conntrack bridge.
* Patch 10/10 enables classic IPv4/IPv6 conntrack to deal with local traffic, ie. when the bridge interface has an IP address, hence packets are passed up to the IP stack for local handling are confirmed by the classic IPv4/IPv6 conntrack hooks. This allows users to define stateful filtering policies from the bridge prerouting chain. For outgoing traffic, the recommended solution is to define the stateful policy from the classic IPv4/IPv6 output hooks.
Users can map different vlans to conntrack zones to avoid conflicts with overlapping conntrack entries via ruleset policy.
Please, apply, thanks!
Pablo Neira Ayuso (10):
net: ipv4: add skbuff fraglist split iterator
net: ipv6: add skbuff fraglist split iterator
net: ipv4: split skbuff into fragments transformer
net: ipv6: split skbuff into fragments transformer
net: ipv4: place cb handling away from fraglist iterator
net: ipv4: place cb handling away from fragment transformer
netfilter: nf_conntrack: allow to register bridge support
netfilter: bridge: add support for conntrack support
netfilter: nf_conntrack_bridge: add support for IPv6
netfilter: nf_conntrack_bridge: register inet conntrack for bridge
include/linux/netfilter_ipv6.h | 50 ++++ include/net/ip.h | 39 +++ include/net/ipv6.h | 44 +++ include/net/netfilter/nf_conntrack.h | 1 + include/net/netfilter/nf_conntrack_bridge.h | 20 ++ include/net/netfilter/nf_conntrack_core.h | 3 + net/bridge/br_device.c | 1 + net/bridge/br_private.h | 1 + net/bridge/netfilter/Kconfig | 14 + net/bridge/netfilter/Makefile | 3 + net/bridge/netfilter/nf_conntrack_bridge.c | 433 ++++++++++++++++++++++++++++ net/ipv4/ip_output.c | 309 ++++++++++++-------- net/ipv6/ip6_output.c | 315 +++++++++++--------- net/ipv6/netfilter.c | 123 ++++++++ net/netfilter/nf_conntrack_proto.c | 126 ++++++-- 15 files changed, 1206 insertions(+), 276 deletions(-) create mode 100644 include/net/netfilter/nf_conntrack_bridge.h create mode 100644 net/bridge/netfilter/nf_conntrack_bridge.c
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 1/10 net: ipv4: add skbuff fraglist split iterator
This patch adds skbuff fraglist split iterator. The API consists of:
* ip_fraglist_init(), that initializes the internal state of the fraglist iterator.
* ip_fraglist_prepare(), that restores the IPv4 on the fragment.
* ip_fraglist_next(), that retrieves the fragment from the fraglist and updates the internal state of the iterator to point to the next fragment in the fraglist.
The ip_fraglist_iter object stores the internal state of the iterator.
This code has been extracted from ip_do_fragment(). Symbols are also exported to allow to reuse this iterator from the bridge codepath for refragmentation.
--- include/net/ip.h | 23 ++++++++++++++ net/ipv4/ip_output.c | 88 ++++++++++++++++++++++++++++++++-------------------- 2 files changed, 78 insertions(+), 33 deletions(-)
include/net/ip.h +23 -0
@@ -165,6 +165,29 @@ int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb);int ip_mc_output (struct net *net,struct sock *sk,struct sk_buff *skb);int ip_do_fragment (struct net *net,struct sock *sk,struct sk_buff *skb,int (*output)(struct net *,struct sock *,struct sk_buff *)); + +struct ip_fraglist_iter { +struct sk_buff *frag_list; +struct sk_buff *frag; +struct iphdr *iph; +int offset; +unsigned int hlen; +}; + +void ip_fraglist_init (struct sk_buff *skb,struct iphdr *iph, +unsigned int hlen,struct ip_fraglist_iter *iter); +void ip_fraglist_prepare (struct sk_buff *skb,struct ip_fraglist_iter *iter); + +static inline struct sk_buff *ip_fraglist_next (struct ip_fraglist_iter *iter) +{ +struct sk_buff *skb = iter->frag; + + iter->frag = skb->next; +skb_mark_not_on_list (skb); + +return skb; +} +void ip_send_check (struct iphdr *ip);int __ip_local_out (struct net *net,struct sock *sk,struct sk_buff *skb);int ip_local_out (struct net *net,struct sock *sk,struct sk_buff *skb);
net/ipv4/ip_output.c +55 -33
123 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/10 net: ipv4: place cb handling away from fragment transformer
In reply to Pablo Neira AyusoDeal with the IPCB() area away from the fragment transformer.
The bridge codebase has its own control buffer layout, move specific IP control buffer into function.
--- net/ipv4/ip_output.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
net/ipv4/ip_output.c +22 -12
@@ -632,6 +632,25 @@ void ip_frag_init(struct sk_buff *skb, unsigned int hlen, }EXPORT_SYMBOL (ip_frag_init); +static void ip_frag_ipcb (struct sk_buff *from,struct sk_buff *to, +bool first_frag,struct ip_frag_state *state) +{ +/* Copy the flags to each fragment. */ +IPCB (to)->flags =IPCB (from)->flags; + +if (IPCB (from)->flags &IPSKB_FRAG_PMTU ) + state->iph->frag_off |=htons (IP_DF ); + +/* ANK: dirty, but effective trick. Upgrade options only if +* the segment to be fragmented was THE FIRST (otherwise, +* options are already fixed) and make it ONCE +* on the initial skb, so that all the following fragments +* will inherit fixed options. +*/ +if (first_frag) +ip_options_fragment (from); +} +struct sk_buff *ip_frag_next (struct sk_buff *skb,struct ip_frag_state *state) {unsigned int len = state->left;
@@ -690,18 +709,6 @@ struct sk_buff *ip_frag_next(struct sk_buff *skb, struct ip_frag_state *state) iph =ip_hdr (skb2); iph->frag_off =htons ((state->offset >>3 )); -if (IPCB (skb)->flags &IPSKB_FRAG_PMTU ) - iph->frag_off |=htons (IP_DF ); - -/* ANK: dirty, but effective trick. Upgrade options only if -* the segment to be fragmented was THE FIRST (otherwise, -* options are already fixed) and make it ONCE -* on the initial skb, so that all the following fragments -* will inherit fixed options. -*/ -if (state->offset ==0 ) -ip_options_fragment (skb); -/* * Added AC : If we are fragmenting a fragment that's not the * last fragment then keep MF on each bit
@@ -851,11 +858,14 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,*/ while (state.left >0 ) { +bool first_frag = (state.offset ==0 ); + skb2 =ip_frag_next (skb, &state);if (IS_ERR (skb2)) { err =PTR_ERR (skb2); goto fail; } +ip_frag_ipcb (skb, skb2, first_frag, &state);/* * Put this fragment into the sending queue.
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/10 netfilter: bridge: add support for conntrack support
In reply to Pablo Neira AyusoThis 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 at bridge prerouting to call nf_conntrack_in() and another at the bridge postrouting hook to confirm the entry.
The conntrack bridge prerouting hook defragments packets and it passes them to nf_conntrack_in() to look up for an existing entry, otherwise a new entry is created in the conntrack table.
The conntrack bridge postrouting hook confirms new entries, ie. this is the first packet seen of this flow, then (if needed) it refragments the skbuff into the original fragments, leaving the geometry as is if possible. Exceptions are linearized skbuffs, eg. passed up to nfqueue and conntrack helpers, cloned skbuff for the local delivery (eg. tcpdump) or in case of bridge port flooding.
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. The maximum fragment length is stored in the control buffer and it is used to refragment the skbuff.
The new fraglist iterator and fragment transformer APIs is used to implement the 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.
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 that were placed there a bit of time ago already, eg. af_packet, that show that skbuff fraglist 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. We should probably explore how to pass all the packets in a list to the conntrack hook to do this handle only once for this case.
This patch is based on original work from Florian Westphal.
--- include/net/netfilter/nf_conntrack_bridge.h | 7 + include/net/netfilter/nf_conntrack_core.h | 3 + net/bridge/br_device.c | 1 + net/bridge/br_private.h | 1 + net/bridge/netfilter/Kconfig | 14 ++ net/bridge/netfilter/Makefile | 3 + net/bridge/netfilter/nf_conntrack_bridge.c | 378 ++++++++++++++++++++++++++++ net/netfilter/nf_conntrack_proto.c | 7 +- 8 files changed, 410 insertions(+), 4 deletions(-) create mode 100644 net/bridge/netfilter/nf_conntrack_bridge.c
include/net/netfilter/nf_conntrack_bridge.h +7 -0
@@ -10,4 +10,11 @@ struct nf_ct_bridge_info {void nf_ct_bridge_register (struct nf_ct_bridge_info *info);void nf_ct_bridge_unregister (struct nf_ct_bridge_info *info); +struct nf_ct_bridge_frag_data { +char mac[ETH_HLEN ]; +bool vlan_present; +u16 vlan_tci; +__be16 vlan_proto; +}; +#endif
include/net/netfilter/nf_conntrack_core.h +3 -0
@@ -64,6 +64,9 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)return ret; } +unsigned int nf_confirm (struct sk_buff *skb,unsigned int protoff, +struct nf_conn *ct,enum ip_conntrack_info ctinfo); +void print_tuple (struct seq_file *s,const struct nf_conntrack_tuple *tuple,const struct nf_conntrack_l4proto *proto);
net/bridge/br_device.c +1 -0
@@ -56,6 +56,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)br_switchdev_frame_unmark (skb);BR_INPUT_SKB_CB (skb)->brdev = dev; +BR_INPUT_SKB_CB (skb)->frag_max_size =0 ;skb_reset_mac_header (skb); eth =eth_hdr (skb);
net/bridge/br_private.h +1 -0
@@ -424,6 +424,7 @@ struct net_bridge {struct br_input_skb_cb {struct net_device *brdev; +u16 frag_max_size;#ifdef CONFIG_BRIDGE_IGMP_SNOOPING u8 igmp;u8 mrouters_only:1 ;
net/bridge/netfilter/Kconfig +14 -0
@@ -18,6 +18,20 @@ config NF_LOG_BRIDGE tristate "Bridge packet logging" select NF_LOG_COMMON +config NF_CONNTRACK_BRIDGE + tristate "IPv4/IPV6 bridge connection tracking support" + depends on NF_CONNTRACK + default n + help + Connection tracking keeps a record of what packets have passed + through your machine, in order to figure out how they are related + into connections. This is used to enhance packet filtering via + stateful policies. Enable this if you want native tracking from + the bridge. This is provides a replacement for the `br_netfilter' + infrastructure. + + To compile it as a module, choose M here. If unsure, say N. + endif # NF_TABLES_BRIDGE menuconfig BRIDGE_NF_EBTABLES
net/bridge/netfilter/Makefile +3 -0
@@ -5,6 +5,9 @@ obj-$(CONFIG_NFT_BRIDGE_REJECT) += nft_reject_bridge.o +# connection tracking +obj-$(CONFIG_NF_CONNTRACK_BRIDGE) += nf_conntrack_bridge.o + # packet logging obj-$(CONFIG_NF_LOG_BRIDGE) += nf_log_bridge.o
net/bridge/netfilter/nf_conntrack_bridge.c new file +378 -0
378 lines not on this page · raw message
net/netfilter/nf_conntrack_proto.c +3 -4
@@ -121,10 +121,8 @@ const struct nf_conntrack_l4proto *nf_ct_l4proto_find(u8 l4proto) };EXPORT_SYMBOL_GPL (nf_ct_l4proto_find); -static unsigned int nf_confirm (struct sk_buff *skb, -unsigned int protoff, -struct nf_conn *ct, -enum ip_conntrack_info ctinfo) +unsigned int nf_confirm (struct sk_buff *skb,unsigned int protoff, +struct nf_conn *ct,enum ip_conntrack_info ctinfo) {const struct nf_conn_help *help;
@@ -155,6 +153,7 @@ static unsigned int nf_confirm(struct sk_buff *skb,/* We've seen it coming out the other side: confirm it */ return nf_conntrack_confirm (skb); } +EXPORT_SYMBOL_GPL (nf_confirm); static unsigned int ipv4_confirm(void *priv, struct sk_buff *skb,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 10/10 netfilter: nf_conntrack_bridge: register inet conntrack for bridge
In reply to Pablo Neira AyusoThis patch enables an IPv4 and IPv6 conntrack dependency from the bridge to deal with local traffic. Hence, packets that are passed up to the local input path are confirmed later on from the {ipv4,ipv6}_confirm() hooks.
For packets leaving the IP stack (ie. output path), fragmentation occurs after the inet postrouting hook. Therefore, the bridge local out and postrouting bridge hooks see fragments with conntrack objects, which is inconsistent. In this case, we could defragment again from the bridge output hook, but this is expensive. The recommended filtering solution to filter outgoing locally generated traffic leaving through the bridge interface is to use the inet output hook, which comes earlier.
--- net/netfilter/nf_conntrack_proto.c | 58 +++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 16 deletions(-)
net/netfilter/nf_conntrack_proto.c +42 -16
@@ -560,38 +560,64 @@ static void nf_ct_netns_do_put(struct net *net, u8 nfproto)mutex_unlock (&nf_ct_proto_mutex); } -int nf_ct_netns_get (struct net *net,u8 nfproto) +static int nf_ct_netns_inet_get (struct net *net) {int err; -if (nfproto ==NFPROTO_INET ) { - err =nf_ct_netns_do_get (net,NFPROTO_IPV4 ); -if (err <0 ) - goto err1; - err =nf_ct_netns_do_get (net,NFPROTO_IPV6 ); -if (err <0 ) - goto err2; - }else { - err =nf_ct_netns_do_get (net, nfproto); -if (err <0 ) - goto err1; - } -return 0 ; + err =nf_ct_netns_do_get (net,NFPROTO_IPV4 ); +if (err <0 ) + goto err1; + err =nf_ct_netns_do_get (net,NFPROTO_IPV6 ); +if (err <0 ) + goto err2; +return err; err2:nf_ct_netns_put (net,NFPROTO_IPV4 ); err1:return err; } + +int nf_ct_netns_get (struct net *net,u8 nfproto) +{ +int err; + +switch (nfproto) { +case NFPROTO_INET : + err =nf_ct_netns_inet_get (net); +break ; +case NFPROTO_BRIDGE : + err =nf_ct_netns_do_get (net,NFPROTO_BRIDGE ); +if (err <0 ) +return err; + + err =nf_ct_netns_inet_get (net); +if (err <0 ) { +nf_ct_netns_put (net,NFPROTO_BRIDGE ); +return err; + } +break ; +default : + err =nf_ct_netns_do_get (net, nfproto); +break ; + } +return err; +}EXPORT_SYMBOL_GPL (nf_ct_netns_get);void nf_ct_netns_put (struct net *net,uint8_t nfproto) { -if (nfproto ==NFPROTO_INET ) { +switch (nfproto) { +case NFPROTO_BRIDGE : +nf_ct_netns_do_put (net,NFPROTO_BRIDGE ); +/* fall through */ +case NFPROTO_INET :nf_ct_netns_do_put (net,NFPROTO_IPV4 );nf_ct_netns_do_put (net,NFPROTO_IPV6 ); - }else { +break ; +default :nf_ct_netns_do_put (net, nfproto); +break ; } }EXPORT_SYMBOL_GPL (nf_ct_netns_put);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/10 netfilter: nf_conntrack_bridge: add support for IPv6
In reply to Pablo Neira Ayusobr_defrag() and br_fragment() indirections are added in case of IPv6 support comes as a module, to avoid pulling innecessary dependencies in.
The new fraglist iterator and fragment transformer APIs is used to implement the refragmentation code.
--- include/linux/netfilter_ipv6.h | 50 ++++++++++++ net/bridge/netfilter/nf_conntrack_bridge.c | 59 +++++++++++++- net/ipv6/netfilter.c | 123 +++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+), 2 deletions(-)
include/linux/netfilter_ipv6.h +50 -0
@@ -19,6 +19,7 @@ struct ip6_rt_info { };struct nf_queue_entry ; +struct nf_ct_bridge_frag_data ;/* * Hook functions for ipv6 to allow xt_* modules to be built-in even
@@ -39,6 +40,15 @@ struct nf_ipv6_ops {int (*fragment)(struct net *net,struct sock *sk,struct sk_buff *skb,int (*output)(struct net *,struct sock *,struct sk_buff *));int (*reroute)(struct sk_buff *skb,const struct nf_queue_entry *entry); +#if IS_MODULE (CONFIG_IPV6 ) +int (*br_defrag)(struct net *net,struct sk_buff *skb,u32 user); +int (*br_fragment)(struct net *net,struct sock *sk, +struct sk_buff *skb, +struct nf_ct_bridge_frag_data *data, +int (*output)(struct net *,struct sock *sk, +const struct nf_ct_bridge_frag_data *data, +struct sk_buff *)); +#endif };#ifdef CONFIG_NETFILTER
@@ -86,6 +96,46 @@ static inline int nf_ip6_route(struct net *net, struct dst_entry **dst,#endif } +static inline int nf_ipv6_br_defrag (struct net *net,struct sk_buff *skb, +u32 user) +{ +#if IS_MODULE (CONFIG_IPV6 ) +const struct nf_ipv6_ops *v6_ops =nf_get_ipv6_ops (); + +if (!v6_ops) +return 1 ; + +return v6_ops->br_defrag (net, skb, user); +#else +return nf_ct_frag6_gather (net, skb, user); +#endif +} + +int br_ip6_fragment (struct net *net,struct sock *sk,struct sk_buff *skb, +struct nf_ct_bridge_frag_data *data, +int (*output)(struct net *,struct sock *sk, +const struct nf_ct_bridge_frag_data *data, +struct sk_buff *)); + +static inline int nf_br_ip6_fragment (struct net *net,struct sock *sk, +struct sk_buff *skb, +struct nf_ct_bridge_frag_data *data, +int (*output)(struct net *,struct sock *sk, +const struct nf_ct_bridge_frag_data *data, +struct sk_buff *)) +{ +#if IS_MODULE (CONFIG_IPV6 ) +const struct nf_ipv6_ops *v6_ops =nf_get_ipv6_ops (); + +if (!v6_ops) +return 1 ; + +return v6_ops->br_fragment (net, sk, skb, data, output); +#else +return br_ip6_fragment (net, sk, skb, data, output); +#endif +} +int ip6_route_me_harder (struct net *net,struct sk_buff *skb);static inline int nf_ip6_route_me_harder (struct net *net,struct sk_buff *skb)
net/bridge/netfilter/nf_conntrack_bridge.c +57 -2
83 lines not on this page · raw message
net/ipv6/netfilter.c +123 -0
141 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/10 net: ipv4: place cb handling away from fraglist iterator
In reply to Pablo Neira AyusoDeal with the IPCB() area away from the fraglist iterator.
The bridge codebase has its own control buffer layout, move specific IP control buffer into function.
--- net/ipv4/ip_output.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
net/ipv4/ip_output.c +15 -6
@@ -523,9 +523,6 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from)skb_copy_hash (to, from); -/* Copy the flags to each fragment. */ -IPCB (to)->flags =IPCB (from)->flags; -#ifdef CONFIG_NET_SCHED to->tc_index = from->tc_index;#endif
@@ -580,6 +577,18 @@ void ip_fraglist_init(struct sk_buff *skb, struct iphdr *iph, }EXPORT_SYMBOL (ip_fraglist_init); +static void ip_fraglist_ipcb_prepare (struct sk_buff *skb, +struct ip_fraglist_iter *iter) +{ +struct sk_buff *to = iter->frag; + +/* Copy the flags to each fragment. */ +IPCB (to)->flags =IPCB (skb)->flags; + +if (iter->offset ==0 ) +ip_options_fragment (to); +} +void ip_fraglist_prepare (struct sk_buff *skb,struct ip_fraglist_iter *iter) {unsigned int hlen = iter->hlen;
@@ -596,8 +605,6 @@ void ip_fraglist_prepare(struct sk_buff *skb, struct ip_fraglist_iter *iter) iph = iter->iph; iph->tot_len =htons (frag->len);ip_copy_metadata (frag, skb); -if (iter->offset ==0 ) -ip_options_fragment (frag); iter->offset += skb->len - hlen; iph->frag_off =htons (iter->offset >>3 );if (frag->next)
@@ -797,8 +804,10 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,for (;;) {/* Prepare header of the next frame, * before previous one went down. */ -if (iter.frag) +if (iter.frag) { +ip_fraglist_ipcb_prepare (skb, &iter);ip_fraglist_prepare (skb, &iter); + } err =output (net, sk, skb);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 7/10 netfilter: nf_conntrack: allow to register bridge support
In reply to Pablo Neira AyusoThis patch adds infrastructure to register and to unregister bridge support for conntrack module via nf_ct_bridge_register() and nf_ct_bridge_unregister().
--- include/net/netfilter/nf_conntrack.h | 1 + include/net/netfilter/nf_conntrack_bridge.h | 13 ++++++ net/netfilter/nf_conntrack_proto.c | 61 +++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 include/net/netfilter/nf_conntrack_bridge.h
include/net/netfilter/nf_conntrack.h +1 -0
@@ -49,6 +49,7 @@ union nf_conntrack_expect_proto {struct nf_conntrack_net {unsigned int users4;unsigned int users6; +unsigned int users_bridge; };#include <linux/types.h>
include/net/netfilter/nf_conntrack_bridge.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef NF_CONNTRACK_BRIDGE_ +#define NF_CONNTRACK_BRIDGE_ + +struct nf_ct_bridge_info { +struct nf_hook_ops *ops; +unsigned int ops_size; +struct module *me; +}; + +void nf_ct_bridge_register (struct nf_ct_bridge_info *info); +void nf_ct_bridge_unregister (struct nf_ct_bridge_info *info); + +#endif
net/netfilter/nf_conntrack_proto.c +58 -3
96 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/10 net: ipv4: split skbuff into fragments transformer
In reply to Pablo Neira AyusoThis patch exposes a new API to refragment a skbuff. The allows you to split either linear skbuff or force the refragmentation of an existing fraglist.
The API consists of:
* ip_frag_init(), that initializes the internal state of the transformer.
* ip_frag_next(), that allows you to fetch the next fragment. This function internally allocates the skbuff that represents the fragment, it pushes the IPv4 header, and it also copies the payload for this fragment.
The ip_frag_state object stores the internal state of the splitter.
This code has been extracted from ip_do_fragment(). Symbols are also exported to allow to reuse this transformer from the bridge codepath for refragmentation.
--- include/net/ip.h | 16 +++++ net/ipv4/ip_output.c | 200 ++++++++++++++++++++++++++++----------------------- 2 files changed, 128 insertions(+), 88 deletions(-)
include/net/ip.h +16 -0
@@ -188,6 +188,22 @@ static inline struct sk_buff *ip_fraglist_next(struct ip_fraglist_iter *iter)return skb; } +struct ip_frag_state { +struct iphdr *iph; +unsigned int hlen; +unsigned int ll_rs; +unsigned int mtu; +unsigned int left; +int offset; +int ptr; +__be16 not_last_frag; +}; + +void ip_frag_init (struct sk_buff *skb,unsigned int hlen,unsigned int ll_rs, +unsigned int mtu,struct ip_frag_state *state); +struct sk_buff *ip_frag_next (struct sk_buff *skb, +struct ip_frag_state *state); +void ip_send_check (struct iphdr *ip);int __ip_local_out (struct net *net,struct sock *sk,struct sk_buff *skb);int ip_local_out (struct net *net,struct sock *sk,struct sk_buff *skb);
net/ipv4/ip_output.c +112 -88
236 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/10 net: ipv6: split skbuff into fragments transformer
In reply to Pablo Neira AyusoThis patch exposes a new API to refragment a skbuff. The allows you to split either linear skbuff or force the refragmentation of an existing fraglist.
The API consists of:
* ip6_frag_init(), that initializes the internal state of the transformer.
* ip6_frag_next(), that allows you to fetch the next fragment. This function internally allocates the skbuff that represents the fragment, it pushes the IPv6, and it also copies the payload for this fragment.
The ip6_frag_state object stores the internal state of the splitter.
This code has been extracted from ip6_fragment(). Symbols are also exported to allow to reuse this transformer from the bridge codepath for refragmentation.
--- include/net/ipv6.h | 19 ++++++ net/ipv6/ip6_output.c | 183 +++++++++++++++++++++++++++++--------------------- 2 files changed, 126 insertions(+), 76 deletions(-)
include/net/ipv6.h +19 -0
@@ -179,6 +179,25 @@ static inline struct sk_buff *ip6_fraglist_next(struct ip6_fraglist_iter *iter)return skb; } +struct ip6_frag_state { +u8 *prevhdr; +unsigned int hlen; +unsigned int mtu; +unsigned int left; +int offset; +int ptr; +int hroom; +int troom; +__be32 frag_id; +u8 nexthdr; +}; + +void ip6_frag_init (struct sk_buff *skb,unsigned int hlen,unsigned int mtu, +unsigned short needed_tailroom,int hdr_room,u8 *prevhdr, +u8 nexthdr,__be32 frag_id,struct ip6_frag_state *state); +struct sk_buff *ip6_frag_next (struct sk_buff *skb, +struct ip6_frag_state *state); +#define IP6_REPLY_MARK (net, mark) \ ((net)->ipv6.sysctl.fwmark_reflect ? (mark) : 0)
net/ipv6/ip6_output.c +107 -76
215 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/10 net: ipv6: add skbuff fraglist split iterator
In reply to Pablo Neira AyusoThis patch adds skbuff fraglist split iterator. The API consists of:
* ip6_fraglist_init(), that initializes the internal state of the fraglist iterator.
* ip6_fraglist_prepare(), that restores the IPv6 header on the fragment.
* ip6_fraglist_next(), that retrieves the fragment from the fraglist and updates the internal state of the iterator to point to the next fragment in the fraglist.
The ip6_fraglist_iter object stores the internal state of the iterator.
This code has been extracted from ip6_fragment(). Symbols are also exported to allow to reuse this iterator from the bridge codepath for refragmentation.
--- include/net/ipv6.h | 25 ++++++++++ net/ipv6/ip6_output.c | 132 +++++++++++++++++++++++++++++--------------------- 2 files changed, 102 insertions(+), 55 deletions(-)
include/net/ipv6.h +25 -0
@@ -154,6 +154,31 @@ struct frag_hdr {#define IP6_MF 0x0001#define IP6_OFFSET 0xFFF8 +struct ip6_fraglist_iter { +struct ipv6hdr *tmp_hdr; +struct sk_buff *frag_list; +struct sk_buff *frag; +int offset; +unsigned int hlen; +__be32 frag_id; +u8 nexthdr; +}; + +int ip6_fraglist_init (struct sk_buff *skb,unsigned int hlen,u8 *prevhdr, +u8 nexthdr,__be32 frag_id, +struct ip6_fraglist_iter *iter); +void ip6_fraglist_prepare (struct sk_buff *skb,struct ip6_fraglist_iter *iter); + +static inline struct sk_buff *ip6_fraglist_next (struct ip6_fraglist_iter *iter) +{ +struct sk_buff *skb = iter->frag; + + iter->frag = skb->next; +skb_mark_not_on_list (skb); + +return skb; +} +#define IP6_REPLY_MARK (net, mark) \ ((net)->ipv6.sysctl.fwmark_reflect ? (mark) : 0)
net/ipv6/ip6_output.c +77 -55
177 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH net-next 08/10] netfilter: bridge: add support for conntrack support
In reply to Pablo Neira AyusoQuoted 59 lines · Pablo Neira Ayuso
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 at bridge prerouting to call
nf_conntrack_in()and another at the bridge postrouting hook to confirm the entry.The conntrack bridge prerouting hook defragments packets and it passes them to
nf_conntrack_in()to look up for an existing entry, otherwise a new entry is created in the conntrack table.The conntrack bridge postrouting hook confirms new entries, ie. this is the first packet seen of this flow, then (if needed) it refragments the skbuff into the original fragments, leaving the geometry as is if possible. Exceptions are linearized skbuffs, eg. passed up to nfqueue and conntrack helpers, cloned skbuff for the local delivery (eg. tcpdump) or in case of bridge port flooding.
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. The maximum fragment length is stored in the control buffer and it is used to refragment the skbuff.The new fraglist iterator and fragment transformer APIs is used to implement the 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.
Like
br_netfilter, there is no refragmentation for packets that are passed up for local delivery, ie. prerouting -> input path. There are calls tonf_reset()already in several spots that were placed there a bit of time ago already, eg.af_packet, that show that skbuff fraglist from thenetif_rxpath 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. We should probably explore how to pass all the packets in a list to the conntrack hook to do this handle only once for this case.
This patch is based on original work from Florian Westphal.
Signed-off-by Pablo Neira Ayuso <[email protected]>--- include/net/netfilter/nf_conntrack_bridge.h | 7 + include/net/netfilter/nf_conntrack_core.h | 3 + net/bridge/br_device.c | 1 + net/bridge/br_private.h | 1 + net/bridge/netfilter/Kconfig | 14 ++ net/bridge/netfilter/Makefile | 3 + net/bridge/netfilter/nf_conntrack_bridge.c | 378 ++++++++++++++++++++++++++++ net/netfilter/nf_conntrack_proto.c | 7 +- 8 files changed, 410 insertions(+), 4 deletions(-) create mode 100644 net/bridge/netfilter/nf_conntrack_bridge.c
[snip]
Quoted 8 lines
net/bridge/netfilter/Kconfig +0
-0@@ -18,6 +18,20 @@ config NF_LOG_BRIDGE tristate "Bridge packet logging" select NF_LOG_COMMON
net/bridge/netfilter/Kconfig config NF_LOG_BRIDGE · line 30
Quoted 10 lines
net/bridge/netfilter/Kconfig +10
-0+config NF_CONNTRACK_BRIDGE + tristate "IPv4/IPV6 bridge connection tracking support" + depends on NF_CONNTRACK + default n + help + Connection tracking keeps a record of what packets have passed + through your machine, in order to figure out how they are related + into connections. This is used to enhance packet filtering via + stateful policies. Enable this if you want native tracking from + the bridge. This is provides a replacement for the `br_netfilter'
nit: typo "This is provides..."
Quoted 4 lines
net/bridge/netfilter/Kconfig +4
-0+ infrastructure. + + To compile it as a module, choose M here. If unsure, say N. +
David Miller
maintainerRe: [PATCH net-next 04/10] net: ipv6: split skbuff into fragments transformer
In reply to Pablo Neira AyusoFrom: Pablo Neira Ayuso <[email protected]>
Date: Mon, 15 Apr 2019 23:36:05 +0200
Quoted 6 lines
The API consists of:
*
ip6_frag_init(), that initializes the internal state of the transformer.
*ip6_frag_next(), that allows you to fetch the next fragment. This function internally allocates the skbuff that represents the fragment, it pushes the IPv6, and it also copies the payload for this fragment.
^^^^^^^^
I think you mean "the IPv6 header" here?