Messages in this thread | ![/](/images/icornerl.gif) | | From | David Laight <> | Subject | RE: [PATCH v2 1/1] net: gro: fix misuse of CB in udp socket lookup | Date | Fri, 21 Jul 2023 09:52:05 +0000 |
| |
From: Richard Gobert > Sent: 20 July 2023 17:26 > > This patch fixes a misuse of IP{6}CB(skb) in GRO, while calling to > `udp6_lib_lookup2` when handling udp tunnels. `udp6_lib_lookup2` fetch the > device from CB. The fix changes it to fetch the device from `skb->dev`. > l3mdev case requires special attention since it has a master and a slave > device. > ... > +/* This function is the alternative to 'inet_iif' and 'inet_sdif' > + * functions in case we can not rely on fields of IPCB. > + * > + * The caller must verify skb_valid_dst(skb) is false and skb->dev is initialized. > + * The caller must hold the RCU read lock. > + */ > +inline void udp4_get_iif_sdif(const struct sk_buff *skb, int *iif, int *sdif) > +{ > + *iif = inet_iif(skb) ?: skb->dev->ifindex; > + *sdif = 0; > + > +#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) > + if (netif_is_l3_slave(skb->dev)) { > + struct net_device *master = netdev_master_upper_dev_get_rcu(skb->dev); > + > + *sdif = *iif; > + *iif = master ? master->ifindex : 0; > + } > +#endif > +}
You need to make that a 'static inline' in the .h file. Otherwise the code generated will be horrid.
It would be much better to use the return value - say for 'iif' then have: { iif = inet_iif(skb) ?: skb->dev->ifindex;
if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) if (netif_is_l3_slave(skb->dev)) { struct net_device *master = netdev_master_upper_dev_get_rcu(skb->dev);
*sdif = iif; return master ? master->ifindex : 0; } #endif *sdif = 0; return iif; }
The compiler might generate that is inlined, not inlined it is definitely better.
David
- Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
| ![\](/images/icornerr.gif) |