Skip to contentSkip to conversation

bridge: send correct MTU value in PMTU

PATCH New Simon Wunderlich 1 participant 1 message Jul 12, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bridge: send correct MTU value in PMTU

When bridging interfaces with different MTUs, the bridge correctly chooses the minimum of the MTUs of the physical devices as the bridges MTU. But when a frame is passed which fits through the incoming, but not through the outgoing interface, a "Fragmentation Needed" packet is generated.

However, the propagated MTU is hardcoded to 1500, which is wrong in this situation. The sender will repeat the packet again with the same frame size, and the same problem will occur again.

Instead of sending 1500, the (correct) MTU value of the bridge is now sent via PMTU. To achieve this, the corresponding rtable structure is stored in its net_bridge structure.

---
 net/bridge/br_device.c    |    9 ++++++-
 net/bridge/br_if.c        |   27 +++++++++++++++++++++++
 net/bridge/br_netfilter.c |   53 +++++++++++++++++----------------------------
 net/bridge/br_private.h   |    5 ++++
 4 files changed, 60 insertions(+), 34 deletions(-)
net/bridge/br_device.c +8 -1
index bf77873..1617e30 100644
@@ -76,10 +76,17 @@ static int br_dev_stop(struct net_device *dev)
 
 static int br_change_mtu(struct net_device *dev, int new_mtu)
 {
-	if (new_mtu < 68 || new_mtu > br_min_mtu(netdev_priv(dev)))
+	struct net_bridge *br = netdev_priv(dev);
+	if (new_mtu < 68 || new_mtu > br_min_mtu(br))
 		return -EINVAL;
 
 	dev->mtu = new_mtu;
+
+#ifdef CONFIG_BRIDGE_NETFILTER
+	/* remember the MTU in the rtable for PMTU */
+	br->fake_rtable.u.dst.metrics[RTAX_MTU - 1] = new_mtu;
+#endif
+
 	return 0;
 }
 
net/bridge/br_if.c +27 -0
index f38cc53..370b0ea 100644
@@ -170,6 +170,23 @@ static void del_br(struct net_bridge *br)
 	unregister_netdevice(br->dev);
 }
 
+#ifdef CONFIG_BRIDGE_NETFILTER
+/* We need these fake structures to make netfilter happy --
+ * lots of places assume that skb->dst != NULL, which isn't
+ * all that unreasonable.
+ *
+ * Currently, we fill in the PMTU entry because netfilter
+ * refragmentation needs it, and the rt_flags entry because
+ * ipt_REJECT needs it.  Future netfilter modules might
+ * require us to fill additional fields. */
+struct net_device __fake_net_device = {
+	.hard_header_len	= ETH_HLEN,
+#ifdef CONFIG_NET_NS
+	.nd_net			= &init_net,
+#endif
+};
+#endif
+
 static struct net_device *new_bridge_dev(const char *name)
 {
 	struct net_bridge *br;
@@ -204,6 +221,16 @@ static struct net_device *new_bridge_dev(const char *name)
 	br->topology_change = 0;
 	br->topology_change_detected = 0;
 	br->ageing_time = 300 * HZ;
+
+#ifdef CONFIG_BRIDGE_NETFILTER
+	atomic_set(&br->fake_rtable.u.dst.__refcnt, 1);
+	br->fake_rtable.u.dst.dev = &__fake_net_device;
+	br->fake_rtable.u.dst.path = &br->fake_rtable.u.dst;
+	br->fake_rtable.u.dst.metrics[RTAX_MTU - 1] = 1500;
+	br->fake_rtable.u.dst.flags	= DST_NOXFRM;
+	br->fake_rtable.rt_flags = 0;
+#endif
+
 	INIT_LIST_HEAD(&br->age_list);
 
 	br_stp_timer_init(br);
net/bridge/br_netfilter.c +19 -32

76 lines not on this page · raw message

net/bridge/br_private.h +5 -0
index c11b554..4f0f030 100644
@@ -17,6 +17,7 @@
 
 #include <linux/netdevice.h>
 #include <linux/if_bridge.h>
+#include <net/route.h>	/* struct rtable, RTAX_MTU */
 
 #define BR_HASH_BITS 8
 #define BR_HASH_SIZE (1 << BR_HASH_BITS)
@@ -95,6 +96,9 @@ struct net_bridge
 	struct hlist_head		hash[BR_HASH_SIZE];
 	struct list_head		age_list;
 	unsigned long			feature_mask;
+#ifdef CONFIG_BRIDGE_NETFILTER
+	struct rtable 			fake_rtable;
+#endif
 
 	/* STP */
 	bridge_id			designated_root;
@@ -201,6 +205,7 @@ extern void br_netfilter_fini(void);
 #else
 #define br_netfilter_init()	(0)
 #define br_netfilter_fini()	do { } while(0)
+extern struct net_device __fake_net_device;
 #endif
 
 /* br_stp.c */
Signature · 1 line
1.5.6.2