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
5029void netif_inherit_tso_max(struct net_device *to,5029void netif_inherit_tso_max(struct net_device *to,
5030 const struct net_device *from);5030 const struct net_device *from);
5031 5031
5032static inline unsigned int
5033netif_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
5032static inline bool netif_is_macsec(const struct net_device *dev)5041static inline bool netif_is_macsec(const struct net_device *dev)
5033{5042{
5034 return dev->priv_flags & IFF_MACSEC;5043 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
98 unsigned int headlen = skb_headlen(skb);98 unsigned int headlen = skb_headlen(skb);
99 unsigned int len = skb_gro_len(skb);99 unsigned int len = skb_gro_len(skb);
100 unsigned int delta_truesize;100 unsigned int delta_truesize;
101 unsigned int gro_max_size;
102 unsigned int new_truesize;101 unsigned int new_truesize;
103 struct sk_buff *lp;102 struct sk_buff *lp;
104 int segs;103 int segs;
@@ -112,12 +111,8 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) · 7 unmodified lines
112 if (p->pp_recycle != skb->pp_recycle)111 if (p->pp_recycle != skb->pp_recycle)
113 return -ETOOMANYREFS;112 return -ETOOMANYREFS;
114 113
115 /* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */114 if (unlikely(p->len + len >= netif_get_gro_max_size(p->dev, p) ||
116 gro_max_size = p->protocol == htons(ETH_P_IPV6) ?115 NAPI_GRO_CB(skb)->flush))
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))
121 return -E2BIG;116 return -E2BIG;
122 117
123 if (unlikely(p->len + len >= GRO_LEGACY_MAX_SIZE)) {118 if (unlikely(p->len + len >= GRO_LEGACY_MAX_SIZE)) {