Skip to contentSkip to conversation

netfilter: bridge: honor frag_max_size when refragmenting

PATCH Superseded Florian Westphal 1 participant 2 messages Mar 9, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: bridge: honor frag_max_size when refragmenting

consider a bridge with mtu 9000, but end host sending smaller packets to another host with mtu < 9000.

In this case, after reassembly, bridge+defrag would refragment, and then attempt to send the reassembled packet as long as it was below 9k.

Instead we have to cap by the largest fragment size seen.

---
No Fixes tag, seems this problem has always existed. tested in kvm with both ipv4 and ipv6 and following setup:

client (mtu 1500) --- bridge(mtu 9k) --- client (mtu 1500)

bridge (incl. all ports) have 9k mtu.

without this patch, ping/ping6 only works for sizes <= 1500 and > 9000.

 net/bridge/br_netfilter_hooks.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
net/bridge/br_netfilter_hooks.c +6 -5
index 95087e6e8258..81889afee212 100644
@@ -721,18 +721,19 @@ static unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb)
 
 static int br_nf_dev_queue_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)
 {
-	struct nf_bridge_info *nf_bridge;
-	unsigned int mtu_reserved;
+	struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
+	unsigned int mtu, mtu_reserved;
 
 	mtu_reserved = nf_bridge_mtu_reduction(skb);
+	mtu = nf_bridge->frag_max_size;
+	if (mtu > skb->dev->mtu)
+		mtu = skb->dev->mtu;
 
-	if (skb_is_gso(skb) || skb->len + mtu_reserved <= skb->dev->mtu) {
+	if (skb_is_gso(skb) || skb->len + mtu_reserved <= mtu) {
 		nf_bridge_info_free(skb);
 		return br_dev_queue_push_xmit(net, sk, skb);
 	}
 
-	nf_bridge = nf_bridge_info_get(skb);
-
 	/* This is wrong! We should preserve the original fragment
 	 * boundaries by preserving frag_list rather than refragmenting.
 	 */
Signature · 1 line
2.10.2
author maintainer
#1 lore raw
Quoted 14 lines · Florian Westphal

consider a bridge with mtu 9000, but end host sending smaller packets to another host with mtu < 9000.

In this case, after reassembly, bridge+defrag would refragment, and then attempt to send the reassembled packet as long as it was below 9k.

Instead we have to cap by the largest fragment size seen.

---
No Fixes tag, seems this problem has always existed. tested in kvm with both ipv4 and ipv6 and following setup:

Quoted 6 lines

client (mtu 1500) --- bridge(mtu 9k) --- client (mtu 1500)

bridge (incl. all ports) have 9k mtu.

without this patch, ping/ping6 only works for sizes <= 1500 and > 9000.

grrr. it breaks the normal path...

Quoted 5 lines
net/bridge/br_netfilter_hooks.c +0 -0
index 95087e6e8258..81889afee212 100644

net/bridge/br_netfilter_hooks.c static unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb) · line 728

Quoted 10 lines
net/bridge/br_netfilter_hooks.c +3 -2
@@ -721,18 +721,19 @@ static unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb)
 
 static int br_nf_dev_queue_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)
 {
-	struct nf_bridge_info *nf_bridge;
-	unsigned int mtu_reserved;
+	struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
+	unsigned int mtu, mtu_reserved;
 
 	mtu_reserved = nf_bridge_mtu_reduction(skb);
+	mtu = nf_bridge->frag_max_size;

This can be 0, I'll send a v2.