On 03/19, Willem de Bruijn wrote: > On Tue, Mar 19, 2019 at 6:20 PM Stanislav Fomichev <sdf@xxxxxxxxxx> wrote: > > > > skb_net returns network namespace from the associated device or socket. > > > > This will be used in the next commit. > > > > I tried to inline it in skbuff.h, but I don't think it's feasible. > > If so, is this helper necessary? > > All existing cases that use it pass both skb_net(skb) and skb to the > flow dissector, so can continue to call it locally if new argument net > is NULL. > > The new users are in patch 9/9 in the device drivers, but those should > pass the device pointer unconditionally. Good point, I can try to drop it. > > It depends on 'net/sock.h' for sock_net() and 'linux/netdevice.h' for > > dev_net(), both of which we don't include from 'linux/skbuff.h' (but > > both sock.h and netdevice.h include skbuff.h). I though about doing > > it as a macro/putting it somewhere else, but we will have > > skb_flow_dissect{_xyz} use it in the next commits. > > > > Signed-off-by: Stanislav Fomichev <sdf@xxxxxxxxxx> > > --- > > include/linux/skbuff.h | 2 ++ > > net/core/skbuff.c | 16 ++++++++++++++++ > > 2 files changed, 18 insertions(+) > > > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > > index e8c1d5b97f96..75e1d4d73cca 100644 > > --- a/include/linux/skbuff.h > > +++ b/include/linux/skbuff.h > > @@ -1275,6 +1275,8 @@ static inline int skb_flow_dissector_bpf_prog_detach(const union bpf_attr *attr) > > } > > #endif > > > > +struct net *skb_net(const struct sk_buff *skb); > > + > > struct bpf_flow_keys; > > bool __skb_flow_bpf_dissect(struct bpf_prog *prog, > > const struct sk_buff *skb, > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > > index b413354ee709..d81f3a95fb4e 100644 > > --- a/net/core/skbuff.c > > +++ b/net/core/skbuff.c > > @@ -5725,3 +5725,19 @@ void __skb_ext_put(struct skb_ext *ext) > > } > > EXPORT_SYMBOL(__skb_ext_put); > > #endif /* CONFIG_SKB_EXTENSIONS */ > > + > > +/** > > + * skb_net - Return network namespace associated with skb. > > + * @skb: skb > > + * > > + * Returns pointer to struct net or NULL. > > + */ > > +struct net *skb_net(const struct sk_buff *skb) > > +{ > > + if (skb->dev) > > + return dev_net(skb->dev); > > + else if (skb->sk) > > + return sock_net(skb->sk); > > + return NULL; > > +} > > +EXPORT_SYMBOL(skb_net); > > -- > > 2.21.0.225.g810b269d1ac-goog > >