net: core: introduce netif_skb_dev_features
Subsystems (3)
PATCH 1/2 net: core: introduce netif_skb_dev_features
Will be used by upcoming ipv4 forward path change that needs to determine feature mask using skb->dst->dev instead of skb->dev.
--- include/linux/netdevice.h | 7 ++++++- net/core/dev.c | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-)
include/linux/netdevice.h +6 -1
@@ -3068,7 +3068,12 @@ void netdev_change_features(struct net_device *dev);void netif_stacked_transfer_operstate (const struct net_device *rootdev,struct net_device *dev); -netdev_features_t netif_skb_features (struct sk_buff *skb); +netdev_features_t netif_skb_dev_features (struct sk_buff *skb, +const struct net_device *dev); +static inline netdev_features_t netif_skb_features (struct sk_buff *skb) +{ +return netif_skb_dev_features (skb, skb->dev); +}static inline bool net_gso_ok (netdev_features_t features,int gso_type) {
net/core/dev.c +11 -9
@@ -2495,34 +2495,36 @@ static int dev_gso_segment(struct sk_buff *skb, netdev_features_t features) }static netdev_features_t harmonize_features (struct sk_buff *skb, -netdev_features_t features) +const struct net_device *dev, +netdev_features_t features) {if (skb->ip_summed !=CHECKSUM_NONE && !can_checksum_protocol (features,skb_network_protocol (skb))) { features &= ~NETIF_F_ALL_CSUM ; - }else if (illegal_highdma (skb->dev, skb)) { + }else if (illegal_highdma (dev, skb)) { features &= ~NETIF_F_SG ; }return features; } -netdev_features_t netif_skb_features (struct sk_buff *skb) +netdev_features_t netif_skb_dev_features (struct sk_buff *skb, +const struct net_device *dev) {__be16 protocol = skb->protocol; -netdev_features_t features = skb->dev->features; +netdev_features_t features = dev->features; -if (skb_shinfo (skb)->gso_segs > skb->dev->gso_max_segs) +if (skb_shinfo (skb)->gso_segs > dev->gso_max_segs) features &= ~NETIF_F_GSO_MASK ;if (protocol ==htons (ETH_P_8021Q ) || protocol ==htons (ETH_P_8021AD )) {struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; protocol = veh->h_vlan_encapsulated_proto; }else if (!vlan_tx_tag_present (skb)) { -return harmonize_features (skb, features); +return harmonize_features (skb, dev, features); } - features &= (skb->dev->vlan_features |NETIF_F_HW_VLAN_CTAG_TX | + features &= (dev->vlan_features |NETIF_F_HW_VLAN_CTAG_TX |NETIF_F_HW_VLAN_STAG_TX );if (protocol ==htons (ETH_P_8021Q ) || protocol ==htons (ETH_P_8021AD ))
@@ -2530,9 +2532,9 @@ netdev_features_t netif_skb_features(struct sk_buff *skb)NETIF_F_GEN_CSUM |NETIF_F_HW_VLAN_CTAG_TX |NETIF_F_HW_VLAN_STAG_TX ; -return harmonize_features (skb, features); +return harmonize_features (skb, dev, features); } -EXPORT_SYMBOL (netif_skb_features); +EXPORT_SYMBOL (netif_skb_dev_features);int dev_hard_start_xmit (struct sk_buff *skb,struct net_device *dev,struct netdev_queue *txq)
Signature · 1 line
1.8.1.5
PATCH v5 2/2 net: ip, ipv6: handle gso skbs in forwarding path
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.
---
Changes since V4:
- use new netif_skb_dev_features instead of netif_skb_features as we need dst->dev and not skb->dev (spotted by Hannes Frederic Sowa)
Changes since V3:
- use ip_dst_mtu_maybe_forward instead of dst_mtu
- add comment wrt. DF bit not being set
Changes since V2:
- make this thing apply to current -net tree
- kill unused variables in ip_forward/ip6_output
Changes since V1:
suggestions from Eric Dumazet:
- skip more expensive computation for small packets in fwd path
- use netif_skb_features() feature mask and remove GSO flags instead of using 0 feature set.
include/linux/skbuff.h | 17 ++++++++++++ net/ipv4/ip_forward.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-- net/ipv6/ip6_output.c | 17 ++++++++++-- 3 files changed, 101 insertions(+), 4 deletions(-)
include/linux/skbuff.h +17 -0
@@ -2916,5 +2916,22 @@ static inline bool skb_head_is_locked(const struct sk_buff *skb) {return !skb->head_frag ||skb_cloned (skb); } + +/** +* 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 +69 -2
89 lines not on this page · raw message
net/ipv6/ip6_output.c +15 -2
@@ -342,6 +342,20 @@ static unsigned int ip6_dst_mtu_forward(const struct dst_entry *dst)return mtu; } +static bool ip6_pkt_too_big (const struct sk_buff *skb,unsigned int mtu) +{ +if (skb->len <= mtu || skb->local_df) +return false; + +if (IP6CB (skb)->frag_max_size &&IP6CB (skb)->frag_max_size > mtu) +return true; + +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);
@@ -466,8 +480,7 @@ int ip6_forward(struct sk_buff *skb)if (mtu <IPV6_MIN_MTU ) mtu =IPV6_MIN_MTU ; -if ((!skb->local_df && skb->len > mtu && !skb_is_gso (skb)) || - (IP6CB (skb)->frag_max_size &&IP6CB (skb)->frag_max_size > mtu)) { +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
Re: [PATCH v5 2/2] net: ip, ipv6: handle gso skbs in forwarding path
Quoted 47 lines · Florian Westphal
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> R2Host 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 skbnr_fragsis 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_sizeskb_segmentwould then also need to deal with the case whereSKB_MAX_FRAGSwould 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.
Quoted 4 lines
Cc Herbert Xu <[email protected]>Cc Eric Dumazet <[email protected]>Reported-by Marcelo Ricardo Leitner <[email protected]>Signed-off-by Florian Westphal <[email protected]>
Although I think we're adding too much complexity for ~DF packets, I don't see anything wrong with this patch per se since we're already aggregating ~DF packets.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
David Miller
maintainerFrom: Florian Westphal <[email protected]>
Date: Mon, 10 Feb 2014 21:35:36 +0100
Quoted 7 lines
net/core/dev.c +2
-1@@ -2495,34 +2495,36 @@ static int dev_gso_segment(struct sk_buff *skb, netdev_features_t features) }static netdev_features_t harmonize_features (struct sk_buff *skb, -netdev_features_t features) +const struct net_device *dev, +netdev_features_t features)
...
net/core/dev.c static int dev_gso_segment(struct sk_buff *skb, netdev_features_t features) · line 2504
Quoted 2 lines
net/core/dev.c +1
-1- }else if (illegal_highdma (skb->dev, skb)) { + }else if (illegal_highdma (dev, skb)) {
illegal_highdma() is not prepared to take a "const struct net_device *", you must have seen the warning in your build. At least I did.
Please fix this and resubmit this series, thanks.