Skip to contentSkip to conversation

netfilter: br_netfilter: Fix for missing refrag of VLAN packets

PATCH New Phil Sutter 1 participant 2 messages Nov 20

Subsystems (4)
lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/2 netfilter: br_netfilter: Fix for missing refrag of VLAN packets

It is possible to create a VLAN-aware bridge via IFLA_BR_VLAN_FILTERING netlink attribute while keeping the global bridge-nf-filter-vlan-tagged sysctl off.

When combining this constellation with conntrack, incoming traffic is defragmented but due to the failing is_vlan_* macros, packet refragmentation does not happen.

In detail, br_nf_forward hook has to set nf_bridge->physoutdev so br_nf_post_routing hook does not return early and ip_do_fragment gets called (via br_nf_dev_queue_xmit and br_nf_ip_fragment).

Extending the is_vlan_* macros to also take into account the bridge's BROPT_VLAN_ENABLED flag fixes for all this.

---
 net/bridge/br_netfilter_hooks.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
net/bridge/br_netfilter_hooks.c +20 -9
index 3b28f81a461a..ae7cae0a82c7 100644
@@ -90,27 +90,38 @@ static inline __be16 vlan_proto(const struct sk_buff *skb)
 		return 0;
 }
 
-static inline bool is_vlan_ip(const struct sk_buff *skb, const struct net *net)
+static inline bool is_vlan_enabled(const struct sk_buff *skb,
+				   const struct net *net)
 {
 	struct brnf_net *brnet = net_generic(net, brnf_net_id);
+	struct net_bridge_port *port = NULL;
+
+	if (brnet->filter_vlan_tagged)
+		return true;
+
+	if (skb->dev)
+		port = br_port_get_rcu(skb->dev);
+
+	if (port && port->br)
+		return br_opt_get(port->br, BROPT_VLAN_ENABLED);
+
+	return false;
+}
 
-	return vlan_proto(skb) == htons(ETH_P_IP) && brnet->filter_vlan_tagged;
+static inline bool is_vlan_ip(const struct sk_buff *skb, const struct net *net)
+{
+	return vlan_proto(skb) == htons(ETH_P_IP) && is_vlan_enabled(skb, net);
 }
 
 static inline bool is_vlan_ipv6(const struct sk_buff *skb,
 				const struct net *net)
 {
-	struct brnf_net *brnet = net_generic(net, brnf_net_id);
-
-	return vlan_proto(skb) == htons(ETH_P_IPV6) &&
-	       brnet->filter_vlan_tagged;
+	return vlan_proto(skb) == htons(ETH_P_IPV6) && is_vlan_enabled(skb, net);
 }
 
 static inline bool is_vlan_arp(const struct sk_buff *skb, const struct net *net)
 {
-	struct brnf_net *brnet = net_generic(net, brnf_net_id);
-
-	return vlan_proto(skb) == htons(ETH_P_ARP) && brnet->filter_vlan_tagged;
+	return vlan_proto(skb) == htons(ETH_P_ARP) && is_vlan_enabled(skb, net);
 }
 
 static inline __be16 pppoe_proto(const struct sk_buff *skb)
Signature · 1 line
2.54.0
author reviewer
#1 lore raw

PATCH 2/2 selftests: netfilter: Add minimal VLAN test case to br_netfilter.sh

Cover at least the bridge's ability to tag/untag packets and assert oversize packets are fragmented again after being defragmented for conntrack.

---
 .../selftests/net/netfilter/br_netfilter.sh   | 23 +++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
tools/testing/selftests/net/netfilter/br_netfilter.sh +21 -2
index 011de8763094..e1c258b23998 100755
@@ -33,9 +33,10 @@ do_ping()
 {
 	fromns="$1"
 	dstip="$2"
+	shift 2
 
-	if ! ip netns exec "$fromns" ping -c 1 -q "$dstip" > /dev/null; then
-		echo "ERROR: ping from $fromns to $dstip"
+	if ! ip netns exec "$fromns" ping -c 1 -q "$@" "$dstip" > /dev/null; then
+		echo "ERROR: ping${@:+ $@} from $fromns to $dstip"
 		ip netns exec "$ns0" nft list ruleset
 		ret=1
 	fi
@@ -163,6 +164,24 @@ bcast_ping "$ns3" 10.23.0.255
 # same, this time via veth4:macvlan4.
 bcast_ping "$ns4" 10.23.0.255
 
+# test vlan filtering
+# veth1 -> trunk
+# veth2 -> pvid 2
+checktool "bridge -Version" "run test without bridge tool"
+ip -net "$ns0" link set br0 type bridge vlan_filtering 1
+ip netns exec "$ns0" bridge vlan add dev veth1 vid 2
+ip netns exec "$ns0" bridge vlan del dev veth2 vid 1
+ip netns exec "$ns0" bridge vlan add dev veth2 vid 2 pvid untagged
+ip -net "$ns1" link add link eth0 name eth0.2 type vlan id 2
+ip -net "$ns1" link set eth0.2 up
+ip -net "$ns1" addr del 10.0.0.11/24 dev eth0
+ip -net "$ns1" addr add 10.0.0.11/24 dev eth0.2
+do_ping "$ns2" 10.0.0.11
+do_ping "$ns1" 10.0.0.12
+# make sure defrag'n'refrag work
+do_ping "$ns2" 10.0.0.11 -s 1477 -M dont
+do_ping "$ns1" 10.0.0.12 -s 1477 -M dont
+
 read t < /proc/sys/kernel/tainted
 if [ "$t" -eq 0 ];then
 	echo PASS: kernel not tainted
Signature · 1 line
2.54.0