gso/gro forwarding changeset
Subsystems (3)
cover gso/gro forwarding changeset
Dropped the 2nd patch of the series (addition of netif_skb_dev_features) for the longterm-backport.
The forward path will use 0 feature mask instead.
I think it is preferable to keep the changeset smaller for these kernels.
Should apply to 3.2.y as well.
Let me know if you disagree and would like to have netif_skb_dev_features backport too.
PATCH 1/2 net: add and use skb_gso_transport_seglen()
commit de960aa9ab4decc3304959f69533eef64d05d8e8 upstream.
[ no skb_gso_seglen helper in 3.4, leave tbf alone ]
This moves part of Eric Dumazets skb_gso_seglen helper from tbf sched to skbuff core so it may be reused by upcoming ip forwarding path patch.
--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/linux/skbuff.h +2 -0
@@ -2159,6 +2159,8 @@ extern int skb_shift(struct sk_buff *tgt, struct sk_buff *skb,extern struct sk_buff *skb_segment (struct sk_buff *skb,netdev_features_t features); +unsigned int skb_gso_transport_seglen (const struct sk_buff *skb); +static inline void *skb_header_pointer (const struct sk_buff *skb,int offset,int len,void *buffer) {
net/core/skbuff.c +25 -0
@@ -45,6 +45,8 @@#include <linux/in.h> #include <linux/inet.h> #include <linux/slab.h> +#include <linux/tcp.h> +#include <linux/udp.h> #include <linux/netdevice.h> #ifdef CONFIG_NET_CLS_ACT #include <net/pkt_sched.h>
@@ -3281,3 +3283,26 @@ void __skb_warn_lro_forwarding(const struct sk_buff *skb) " while LRO is enabled\n", skb->dev->name); }EXPORT_SYMBOL (__skb_warn_lro_forwarding); + +/** +* skb_gso_transport_seglen - Return length of individual segments of a gso packet +* +* @skb: GSO skb +* +* skb_gso_transport_seglen is used to determine the real size of the +* individual segments, including Layer4 headers (TCP/UDP). +* +* The MAC/L2 or network (IP, IPv6) headers are not accounted for. +*/ +unsigned int skb_gso_transport_seglen (const struct sk_buff *skb) +{ +const struct skb_shared_info *shinfo =skb_shinfo (skb); +unsigned int hdr_len; + +if (likely (shinfo->gso_type & (SKB_GSO_TCPV4 |SKB_GSO_TCPV6 ))) + hdr_len =tcp_hdrlen (skb); +else + hdr_len =sizeof (struct udphdr ); +return hdr_len + shinfo->gso_size; +} +EXPORT_SYMBOL_GPL (skb_gso_transport_seglen);
Signature · 1 line
1.8.1.5
PATCH 2/2 net: ip, ipv6: handle gso skbs in forwarding path
In reply to Florian Westphalcommit fe6cc55f3a9a053482a76f5a6b2257cee51b4663 upstream.
[ use zero netdev_feature mask to avoid backport of
netif_skb_dev_features function ]
Marcelo Ricardo Leitner reported problems when the forwarding link path has a lower mtu than the incoming one if the inbound interface supports GRO.
Given:
Host <mtu1500> R1 <mtu1200> R2
Host sends tcp stream which is routed via R1 and R2. R1 performs GRO.
In this case, the kernel will fail to send ICMP fragmentation needed messages (or pkt too big for ipv6), as GSO packets currently bypass dstmtu checks in forward path. Instead, Linux tries to send out packets exceeding the mtu.
When locking route MTU on Host (i.e., no ipv4 DF bit set), R1 does not fragment the packets when forwarding, and again tries to send out packets exceeding R1-R2 link mtu.
This alters the forwarding dstmtu checks to take the individual gso segment lengths into account.
For ipv6, we send out pkt too big error for gso if the individual segments are too big.
For ipv4, we either send icmp fragmentation needed, or, if the DF bit is not set, perform software segmentation and let the output path create fragments when the packet is leaving the machine.
It is not 100% correct as the error message will contain the headers of the GRO skb instead of the original/segmented one, but it seems to work fine in my (limited) tests.
Eric Dumazet suggested to simply shrink mss via ->gso_size to avoid sofware segmentation.
However it turns out that skb_segment() assumes skb nr_frags is related to mss size so we would BUG there. I don't want to mess with it considering Herbert and Eric disagree on what the correct behavior should be.
Hannes Frederic Sowa notes that when we would shrink gso_size skb_segment would then also need to deal with the case where SKB_MAX_FRAGS would be exceeded.
This uses sofware segmentation in the forward path when we hit ipv4 non-DF packets and the outgoing link mtu is too small. Its not perfect, but given the lack of bug reports wrt. GRO fwd being broken this is a rare case anyway. Also its not like this could not be improved later once the dust settles.
--- include/linux/skbuff.h | 17 +++++++++++++ net/ipv4/ip_forward.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++-- net/ipv6/ip6_output.c | 13 +++++++++- 3 files changed, 95 insertions(+), 3 deletions(-)
include/linux/skbuff.h +17 -0
@@ -2582,5 +2582,22 @@ static inline bool skb_is_recycleable(const struct sk_buff *skb, int skb_size)return true; } + +/** +* skb_gso_network_seglen - Return length of individual segments of a gso packet +* +* @skb: GSO skb +* +* skb_gso_network_seglen is used to determine the real size of the +* individual segments, including Layer3 (IP, IPv6) and L4 headers (TCP/UDP). +* +* The MAC/L2 header is not accounted for. +*/ +static inline unsigned int skb_gso_network_seglen (const struct sk_buff *skb) +{ +unsigned int hdr_len =skb_transport_header (skb) - +skb_network_header (skb); +return hdr_len +skb_gso_transport_seglen (skb); +}#endif /* __KERNEL__ */ #endif /* _LINUX_SKBUFF_H */
net/ipv4/ip_forward.c +66 -2
86 lines not on this page · raw message
net/ipv6/ip6_output.c +12 -1
@@ -382,6 +382,17 @@ static inline int ip6_forward_finish(struct sk_buff *skb)return dst_output (skb); } +static bool ip6_pkt_too_big (const struct sk_buff *skb,unsigned int mtu) +{ +if (skb->len <= mtu || skb->local_df) +return false; + +if (skb_is_gso (skb) &&skb_gso_network_seglen (skb) <= mtu) +return false; + +return true; +} +int ip6_forward (struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);
@@ -503,7 +514,7 @@ int ip6_forward(struct sk_buff *skb)if (mtu <IPV6_MIN_MTU ) mtu =IPV6_MIN_MTU ; -if (skb->len > mtu && !skb_is_gso (skb)) { +if (ip6_pkt_too_big (skb, mtu)) {/* Again, force OUTPUT device used as source address */ skb->dev = dst->dev;icmpv6_send (skb,ICMPV6_PKT_TOOBIG ,0 , mtu);
Signature · 1 line
1.8.1.5
Ben Hutchings
AppliedQuoted 10 lines · Florian Westphal
Dropped the 2nd patch of the series (addition of
netif_skb_dev_features) for the longterm-backport.The forward path will use 0 feature mask instead.
I think it is preferable to keep the changeset smaller for these kernels.Should apply to 3.2.y as well.
Let me know if you disagree and would like to have
netif_skb_dev_featuresbackport too.
I've queued these up for 3.2, thanks.
Ben.
Signature · 2 lines
Ben Hutchings I say we take off; nuke the site from orbit. It's the only way to be sure.