diff mbox

[nf,v2] netfilter: bridge: honor frag_max_size when refragmenting

Message ID 20170309222230.2190-1-fw@strlen.de
State Accepted
Delegated to: Pablo Neira
Headers show

Commit Message

Florian Westphal March 9, 2017, 10:22 p.m. UTC
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.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 changes since v1:
  only use nonzero frag_max_size, else non-fragmented packets won't
  be forwarded anymore.

 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.

 I tested ping & ping6 with sizes of 64, 8000, 32000.
 Without patch, 8000-sized packets are dropped on the bridge.

Comments

Pablo Neira Ayuso March 13, 2017, 12:32 p.m. UTC | #1
On Thu, Mar 09, 2017 at 11:22:30PM +0100, Florian Westphal wrote:
> 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.

Applied, thanks Florian.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c
index 95087e6e8258..3c5185021c1c 100644
--- a/net/bridge/br_netfilter_hooks.c
+++ b/net/bridge/br_netfilter_hooks.c
@@ -721,18 +721,20 @@  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 = skb->dev->mtu;
+
+	if (nf_bridge->frag_max_size && nf_bridge->frag_max_size < mtu)
+		mtu = nf_bridge->frag_max_size;
 
-	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.
 	 */