Skip to contentSkip to conversation

netfilter: flowtable: initial bridge support

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Jul 12

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v3 1/1 netfilter: flowtable: initial bridge support

This patch adds bridge flowtable support, this allows to define a shortcut between two bridge ports. This is complementary to the existing inet family flowtable support.

Set up does not require userspace updates, an example ruleset to enable the flowtable in the bridge family is provided here below:

 table bridge x {
        flowtable y {
                hook ingress priority 0
                devices = { veth0, veth1 }
        }
        chain forward {
                type filter hook forward priority 0
                ip protocol tcp flow add @y counter
                counter
        }

}

I decided to add an explicit nft_flow_offload_bridge_eval() instead of recycling the existing inet function by adding branches to skip the routing part which is obviously not needed in the bridge path. I consider this mostly boiler plate for feature extensibility and better maintability is better to keep it separated. Similarly, the bridge hook that represents the flowtable bridge datapath is implemented in a separated function.

Although connection tracking in the bridge does not support the tracking of IP flows encapsulated in PPPoE and VLAN tracking yet, there are scenarios that involved PPPoE and VLAN that can be supported already, such as those where packets flows through the bridge with no tagging, eg. a VLAN device is used as a bridge port which decapsulates the packets at the ingress path.

Tested with:
- Plain forwarding between bridge ports with no VLAN tagging.
- VLAN device used in bridged ports, as long as packets that are untagged when circulating within the bridge.

This initial bridge flowtable support does support VLAN tagged packets circulating within the bridge yet, because nf_conntrack_bridge still does not support PPPoE/VLAN natively.

Source and destination mac addresses are statically cached in the flow tuple Roaming between devices is not supported either.

No hardware offload at this stage, but patches has been proposed to enable it and will follow up.

---
v3: Address feedback by sashiko:
- Use is_skb_forwardable() to check if mtu is correct, otherwise drop packet.
- Recover hw offload is unsupported check, which was already in v1, but that I dropped it so sashiko does not report that "patch does not apply" and it can kicks in for review.
- Missing .needs_gso_segment flag unset.
- Missing default case for unsupported layer 4 protocol.
- Set on IP_CT_TCP_FLAG_BE_LIBERAL and NF_FLOW_HW_BIDIRECTIONAL flags
- Missing unregistration of flow_offload bridge expression on module removal.
- Add comment on roam between bridge ports (it is unsupported).
- Ignore comment on NF_CT_EXT_HELPER, IPS_NAT_MASK, and IPS_SEQ_ADJUST, they are not support by nf_conntrack_bridge in the forwarding path.

Using correct tree, which is nf-next.

 include/net/netfilter/nf_flow_table.h |   7 ++
 net/netfilter/nf_flow_table_inet.c    |  12 +++
 net/netfilter/nf_flow_table_ip.c      | 137 ++++++++++++++++++++++++++
 net/netfilter/nf_flow_table_offload.c |   8 +-
 net/netfilter/nf_flow_table_path.c    |  63 ++++++++++++
 net/netfilter/nft_flow_offload.c      |  95 +++++++++++++++++-
 6 files changed, 318 insertions(+), 4 deletions(-)
include/net/netfilter/nf_flow_table.h +7 -0
index ce414118962f..6e76a6879ff3 100644
@@ -248,6 +248,8 @@ struct nft_pktinfo;
 int nft_flow_route(const struct nft_pktinfo *pkt, const struct nf_conn *ct,
 		   struct nf_flow_route *route, enum ip_conntrack_dir dir,
 		   struct nft_flowtable *ft);
+int nft_flow_bridge(struct flow_offload *flow, const struct nft_pktinfo *pkt,
+		    enum ip_conntrack_dir dir, struct nft_flowtable *ft);
 
 static inline int
 nf_flow_table_offload_add_cb(struct nf_flowtable *flow_table,
@@ -342,6 +344,8 @@ unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
 				     const struct nf_hook_state *state);
 unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
 				       const struct nf_hook_state *state);
+unsigned int nf_flow_offload_bridge_hook(void *priv, struct sk_buff *skb,
+					 const struct nf_hook_state *state);
 
 #if (IS_BUILTIN(CONFIG_NF_FLOW_TABLE) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) || \
     (IS_MODULE(CONFIG_NF_FLOW_TABLE) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
@@ -377,6 +381,9 @@ int nf_flow_rule_route_ipv4(struct net *net, struct flow_offload *flow,
 int nf_flow_rule_route_ipv6(struct net *net, struct flow_offload *flow,
 			    enum flow_offload_tuple_dir dir,
 			    struct nf_flow_rule *flow_rule);
+int nf_flow_rule_bridge(struct net *net, struct flow_offload *flow,
+			enum flow_offload_tuple_dir dir,
+			struct nf_flow_rule *flow_rule);
 
 int nf_flow_table_offload_init(void);
 void nf_flow_table_offload_exit(void);
net/netfilter/nf_flow_table_inet.c +12 -0
index b0f199171932..44790a0d3012 100644
@@ -65,6 +65,15 @@ static int nf_flow_rule_route_inet(struct net *net,
 	return err;
 }
 
+static struct nf_flowtable_type flowtable_bridge = {
+	.family		= NFPROTO_BRIDGE,
+	.init		= nf_flow_table_init,
+	.setup		= nf_flow_table_offload_setup,
+	.free		= nf_flow_table_free,
+	.hook		= nf_flow_offload_bridge_hook,
+	.owner		= THIS_MODULE,
+};
+
 static struct nf_flowtable_type flowtable_inet = {
 	.family		= NFPROTO_INET,
 	.init		= nf_flow_table_init,
@@ -97,6 +106,7 @@ static struct nf_flowtable_type flowtable_ipv6 = {
 
 static int __init nf_flow_inet_module_init(void)
 {
+	nft_register_flowtable_type(&flowtable_bridge);
 	nft_register_flowtable_type(&flowtable_ipv4);
 	nft_register_flowtable_type(&flowtable_ipv6);
 	nft_register_flowtable_type(&flowtable_inet);
@@ -109,6 +119,7 @@ static void __exit nf_flow_inet_module_exit(void)
 	nft_unregister_flowtable_type(&flowtable_inet);
 	nft_unregister_flowtable_type(&flowtable_ipv6);
 	nft_unregister_flowtable_type(&flowtable_ipv4);
+	nft_unregister_flowtable_type(&flowtable_bridge);
 }
 
 module_init(nf_flow_inet_module_init);
@@ -118,5 +129,6 @@ MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Pablo Neira Ayuso <[email protected]>");
 MODULE_ALIAS_NF_FLOWTABLE(AF_INET);
 MODULE_ALIAS_NF_FLOWTABLE(AF_INET6);
+MODULE_ALIAS_NF_FLOWTABLE(AF_BRIDGE);
 MODULE_ALIAS_NF_FLOWTABLE(1); /* NFPROTO_INET */
 MODULE_DESCRIPTION("Netfilter flow table mixed IPv4/IPv6 module");
net/netfilter/nf_flow_table_ip.c +137 -0

140 lines not on this page · raw message

net/netfilter/nf_flow_table_offload.c +5 -3
index 801a3dd9ceea..cd8d468fe0c9 100644
@@ -1101,9 +1101,11 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
 	return offload;
 }
 
-static bool nf_flow_offload_unsupported(struct flow_offload *flow)
+static bool nf_flow_offload_unsupported(struct nf_flowtable *flowtable,
+					struct flow_offload *flow)
 {
-	if (flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.tun_num ||
+	if (flowtable->type->family == NFPROTO_BRIDGE ||
+	    flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple.tun_num ||
 	    flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.tun_num)
 		return true;
 
@@ -1125,7 +1127,7 @@ void nf_flow_offload_refresh(struct nf_flowtable *flowtable,
 void nf_flow_offload_add(struct nf_flowtable *flowtable,
 			 struct flow_offload *flow)
 {
-	if (nf_flow_offload_unsupported(flow))
+	if (nf_flow_offload_unsupported(flowtable, flow))
 		return;
 
 	set_bit(NF_FLOW_HW, &flow->flags);
net/netfilter/nf_flow_table_path.c +63 -0

72 lines not on this page · raw message

net/netfilter/nft_flow_offload.c +94 -1

127 lines not on this page · raw message

Signature · 1 line
2.47.3