Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtnetlink: Restore RTM_NEW/DELLINK notification behavior

The commits referenced below allows userspace to use the NLM_F_ECHO flag
for RTM_NEW/DELLINK operations to receive unicast notifications for the
affected link. Prior to these changes, applications may have relied on
multicast notifications to learn the same information without specifying
the NLM_F_ECHO flag.

For such applications, the mentioned commits changed the behavior for
requests not using NLM_F_ECHO. Multicast notifications are still received,
but now use the portid of the requester and the sequence number of the
request instead of zero values used previously. For the application, this
message may be unexpected and likely handled as a response to the
NLM_F_ACKed request, especially if it uses the same socket to handle
requests and notifications.

To fix existing applications relying on the old notification behavior,
set the portid and sequence number in the notification only if the
request included the NLM_F_ECHO flag. This restores the old behavior
for applications not using it, but allows unicasted notifications for
others.

Fixes: f3a63cce1b4f ("rtnetlink: Honour NLM_F_ECHO flag in rtnl_delete_link")
Fixes: d88e136cab37 ("rtnetlink: Honour NLM_F_ECHO flag in rtnl_newlink_create")
Signed-off-by: Martin Willi <martin@strongswan.org>
Acked-by: Guillaume Nault <gnault@redhat.com>
Acked-by: Hangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20230411074319.24133-1-martin@strongswan.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Martin Willi and committed by
Jakub Kicinski
59d3efd2 136f36c7

+12 -4
+2 -1
include/linux/rtnetlink.h
··· 25 25 struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev, 26 26 unsigned change, u32 event, 27 27 gfp_t flags, int *new_nsid, 28 - int new_ifindex, u32 portid, u32 seq); 28 + int new_ifindex, u32 portid, 29 + const struct nlmsghdr *nlh); 29 30 void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, 30 31 gfp_t flags, u32 portid, const struct nlmsghdr *nlh); 31 32
+1 -1
net/core/dev.c
··· 10847 10847 dev->rtnl_link_state == RTNL_LINK_INITIALIZED) 10848 10848 skb = rtmsg_ifinfo_build_skb(RTM_DELLINK, dev, ~0U, 0, 10849 10849 GFP_KERNEL, NULL, 0, 10850 - portid, nlmsg_seq(nlh)); 10850 + portid, nlh); 10851 10851 10852 10852 /* 10853 10853 * Flush the unicast and multicast chains
+9 -2
net/core/rtnetlink.c
··· 3972 3972 struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev, 3973 3973 unsigned int change, 3974 3974 u32 event, gfp_t flags, int *new_nsid, 3975 - int new_ifindex, u32 portid, u32 seq) 3975 + int new_ifindex, u32 portid, 3976 + const struct nlmsghdr *nlh) 3976 3977 { 3977 3978 struct net *net = dev_net(dev); 3978 3979 struct sk_buff *skb; 3979 3980 int err = -ENOBUFS; 3981 + u32 seq = 0; 3980 3982 3981 3983 skb = nlmsg_new(if_nlmsg_size(dev, 0), flags); 3982 3984 if (skb == NULL) 3983 3985 goto errout; 3986 + 3987 + if (nlmsg_report(nlh)) 3988 + seq = nlmsg_seq(nlh); 3989 + else 3990 + portid = 0; 3984 3991 3985 3992 err = rtnl_fill_ifinfo(skb, dev, dev_net(dev), 3986 3993 type, portid, seq, change, 0, 0, event, ··· 4024 4017 return; 4025 4018 4026 4019 skb = rtmsg_ifinfo_build_skb(type, dev, change, event, flags, new_nsid, 4027 - new_ifindex, portid, nlmsg_seq(nlh)); 4020 + new_ifindex, portid, nlh); 4028 4021 if (skb) 4029 4022 rtmsg_ifinfo_send(skb, dev, flags, portid, nlh); 4030 4023 }