History

net: Add netif_get_gro_max_size helper for GRO

Add a small netif_get_gro_max_size() helper which returns the maximum IPv4 or IPv6 GRO size of the netdevice. We later add a netif_get_gso_max_size() equivalent as well for GSO, so that these helpers can be used consistently instead of open-coded checks.

Daniel Borkmann committed 2 years ago

Commit e8d4d341 parent 6c24a032 files · +11 −7Browse files

Unified · Split

2 files
  1. include/linux/netdevice.h +9 −0
  2. net/core/gro.c +2 −7
include/linux/netdevice.h+9−0
@@ -5029,6 +5029,15 @@ void netif_set_tso_max_segs(struct net_device *dev, unsigned int segs); · 5028 unmodified lines
50295029 void netif_inherit_tso_max(struct net_device *to,
50305030 const struct net_device *from);
50315031
5032+static inline unsigned int
5033+netif_get_gro_max_size(const struct net_device *dev, const struct sk_buff *skb)
5034+{
5035+ /* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */
5036+ return skb->protocol == htons(ETH_P_IPV6) ?
5037+ READ_ONCE(dev->gro_max_size) :
5038+ READ_ONCE(dev->gro_ipv4_max_size);
5039+}
5040+
50325041 static inline bool netif_is_macsec(const struct net_device *dev)
50335042 {
50345043 return dev->priv_flags & IFF_MACSEC;
net/core/gro.c+2−7
@@ -98,7 +98,6 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) · 97 unmodified lines
9898 unsigned int headlen = skb_headlen(skb);
9999 unsigned int len = skb_gro_len(skb);
100100 unsigned int delta_truesize;
101− unsigned int gro_max_size;
102101 unsigned int new_truesize;
103102 struct sk_buff *lp;
104103 int segs;
@@ -112,12 +111,8 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) · 7 unmodified lines
112111 if (p->pp_recycle != skb->pp_recycle)
113112 return -ETOOMANYREFS;
114113
115− /* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */
116− gro_max_size = p->protocol == htons(ETH_P_IPV6) ?
117− READ_ONCE(p->dev->gro_max_size) :
118− READ_ONCE(p->dev->gro_ipv4_max_size);
119−
120− if (unlikely(p->len + len >= gro_max_size || NAPI_GRO_CB(skb)->flush))
114+ if (unlikely(p->len + len >= netif_get_gro_max_size(p->dev, p) ||
115+ NAPI_GRO_CB(skb)->flush))
121116 return -E2BIG;
122117
123118 if (unlikely(p->len + len >= GRO_LEGACY_MAX_SIZE)) {