Re: [PATCHv5 net-next 1/4] rtnetlink: add new helper rtnl_configure_link_notify()

Nicolas Dichtel
2022-09-30T14:23:54Z

Le 30/09/2022 à 11:45, Hangbin Liu a écrit :
> This patch update rtnl_configure_link() to rtnl_configure_link_nlh() by
> adding parameter netlink message header and port id so we can notify the
> userspace about the new link info if NLM_F_ECHO flag is set.
>
> The rtnl_configure_link() will be a wrapper of the new function. The new
> call chain looks like:
>
> - rtnl_configure_link_notify()
> - __dev_notify_flags()
> - rtmsg_ifinfo_nlh()
> - rtmsg_ifinfo_event()
> - rtmsg_ifinfo_build_skb()
> - rtmsg_ifinfo_send()
>
> All the functions in this call chain will add parameter nlh and pid, so
> we can use them in the last call rtnl_notify().
>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
> include/linux/netdevice.h | 2 +-
> include/linux/rtnetlink.h | 6 ++++--
> net/core/dev.c | 14 ++++++-------
> net/core/rtnetlink.c | 41 ++++++++++++++++++++++++++-------------
> 4 files changed, 40 insertions(+), 23 deletions(-)
>
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index eddf8ee270e7..a71d378945e3 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -3856,7 +3856,7 @@ int __dev_change_flags(struct net_device *dev, unsigned int flags,
> int dev_change_flags(struct net_device *dev, unsigned int flags,
> struct netlink_ext_ack *extack);
> void __dev_notify_flags(struct net_device *, unsigned int old_flags,
> - unsigned int gchanges);
> + unsigned int gchanges, u32 pid, struct nlmsghdr *nlh);
Order is pid/nlh.

[snip]

> +void rtmsg_ifinfo_nlh(int type, struct net_device *dev, unsigned int change,
> + gfp_t flags, u32 pid, struct nlmsghdr *nlh);
Same here.

> struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
> unsigned change, u32 event,
> gfp_t flags, int *new_nsid,
> - int new_ifindex);
> + int new_ifindex, u32 pid, u32 seq);
Same here.

> void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev,
> - gfp_t flags);
> + gfp_t flags, u32 pid, struct nlmsghdr *nlh);
Same here.

[snip]

> -int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm)
> +static int rtnl_configure_link_notify(struct net_device *dev, const struct ifinfomsg *ifm,
> + struct nlmsghdr *nlh, u32 pid)
But not here. Following patches also use this order instead of the previous one.
For consistency, it could be good to keep the same order everywhere.

Regards,
Nicolas