* [PATCH RESEND net-next] netlink: add IPv6 anycast join/leave notifications
@ 2025-01-05 2:00 Yuyang Huang
2025-01-06 17:53 ` David Ahern
0 siblings, 1 reply; 3+ messages in thread
From: Yuyang Huang @ 2025-01-05 2:00 UTC (permalink / raw)
To: Yuyang Huang
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, David Ahern, roopa, jiri, stephen, jimictw, prohr,
liuhangbin, nicolas.dichtel, andrew, netdev,
Maciej Żenczykowski, Lorenzo Colitti
This change introduces a mechanism for notifying userspace
applications about changes to IPv6 anycast addresses via netlink. It
includes:
* Addition and deletion of IPv6 anycast addresses are reported using
RTM_NEWANYCAST and RTM_DELANYCAST.
* A new netlink group (RTNLGRP_IPV6_ACADDR) for subscribing to these
notifications.
This enables user space applications(e.g. ip monitor) to efficiently
track anycast addresses through netlink messages, improving metrics
collection and system monitoring. It also unlocks the potential for
advanced anycast management in user space, such as hardware offload
control and fine grained network control.
Cc: Maciej Żenczykowski <maze@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
---
include/net/addrconf.h | 3 +++
include/uapi/linux/rtnetlink.h | 8 ++++++-
net/ipv6/addrconf.c | 6 +++---
net/ipv6/anycast.c | 38 ++++++++++++++++++++++++++++++++++
4 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index 58337898fa21..f8f91b2038ea 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -546,4 +546,7 @@ int inet6_fill_ifmcaddr(struct sk_buff *skb,
const struct ifmcaddr6 *ifmca,
struct inet6_fill_args *args);
+int inet6_fill_ifacaddr(struct sk_buff *skb,
+ const struct ifacaddr6 *ifaca,
+ struct inet6_fill_args *args);
#endif
diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index eccc0e7dcb7d..6b74864ef6fb 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -100,7 +100,11 @@ enum {
RTM_GETMULTICAST,
#define RTM_GETMULTICAST RTM_GETMULTICAST
- RTM_GETANYCAST = 62,
+ RTM_NEWANYCAST = 60,
+#define RTM_NEWANYCAST RTM_NEWANYCAST
+ RTM_DELANYCAST,
+#define RTM_DELANYCAST RTM_DELANYCAST
+ RTM_GETANYCAST,
#define RTM_GETANYCAST RTM_GETANYCAST
RTM_NEWNEIGHTBL = 64,
@@ -782,6 +786,8 @@ enum rtnetlink_groups {
#define RTNLGRP_IPV4_MCADDR RTNLGRP_IPV4_MCADDR
RTNLGRP_IPV6_MCADDR,
#define RTNLGRP_IPV6_MCADDR RTNLGRP_IPV6_MCADDR
+ RTNLGRP_IPV6_ACADDR,
+#define RTNLGRP_IPV6_ACADDR RTNLGRP_IPV6_ACADDR
__RTNLGRP_MAX
};
#define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 2e2684886953..66032cadd81f 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -5241,9 +5241,9 @@ int inet6_fill_ifmcaddr(struct sk_buff *skb,
}
EXPORT_SYMBOL(inet6_fill_ifmcaddr);
-static int inet6_fill_ifacaddr(struct sk_buff *skb,
- const struct ifacaddr6 *ifaca,
- struct inet6_fill_args *args)
+int inet6_fill_ifacaddr(struct sk_buff *skb,
+ const struct ifacaddr6 *ifaca,
+ struct inet6_fill_args *args)
{
struct net_device *dev = fib6_info_nh_dev(ifaca->aca_rt);
int ifindex = dev ? dev->ifindex : 1;
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 562cace50ca9..6793ff436986 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -278,6 +278,40 @@ static struct ifacaddr6 *aca_alloc(struct fib6_info *f6i,
return aca;
}
+static void inet6_ifacaddr_notify(struct net_device *dev,
+ const struct ifacaddr6 *ifaca, int event)
+{
+ struct inet6_fill_args fillargs = {
+ .portid = 0,
+ .seq = 0,
+ .event = event,
+ .flags = 0,
+ .netnsid = -1,
+ };
+ struct net *net = dev_net(dev);
+ struct sk_buff *skb;
+ int err = -ENOMEM;
+
+ skb = nlmsg_new(NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
+ nla_total_size(sizeof(struct in6_addr)) +
+ nla_total_size(sizeof(struct ifa_cacheinfo)),
+ GFP_KERNEL);
+ if (!skb)
+ goto error;
+
+ err = inet6_fill_ifacaddr(skb, ifaca, &fillargs);
+ if (err < 0) {
+ WARN_ON_ONCE(err == -EMSGSIZE);
+ nlmsg_free(skb);
+ goto error;
+ }
+
+ rtnl_notify(skb, net, 0, RTNLGRP_IPV6_ACADDR, NULL, GFP_KERNEL);
+ return;
+error:
+ rtnl_set_sk_err(net, RTNLGRP_IPV6_ACADDR, err);
+}
+
/*
* device anycast group inc (add if not found)
*/
@@ -333,6 +367,8 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr)
addrconf_join_solict(idev->dev, &aca->aca_addr);
+ inet6_ifacaddr_notify(idev->dev, aca, RTM_NEWANYCAST);
+
aca_put(aca);
return 0;
out:
@@ -375,6 +411,8 @@ int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr)
ip6_del_rt(dev_net(idev->dev), aca->aca_rt, false);
+ inet6_ifacaddr_notify(idev->dev, aca, RTM_DELANYCAST);
+
aca_put(aca);
return 0;
}
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND net-next] netlink: add IPv6 anycast join/leave notifications
2025-01-05 2:00 [PATCH RESEND net-next] netlink: add IPv6 anycast join/leave notifications Yuyang Huang
@ 2025-01-06 17:53 ` David Ahern
2025-01-07 1:31 ` Yuyang Huang
0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2025-01-06 17:53 UTC (permalink / raw)
To: Yuyang Huang
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, roopa, jiri, stephen, jimictw, prohr, liuhangbin,
nicolas.dichtel, andrew, netdev, Maciej Żenczykowski,
Lorenzo Colitti
On 1/4/25 7:00 PM, Yuyang Huang wrote:
> diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
> index 562cace50ca9..6793ff436986 100644
> --- a/net/ipv6/anycast.c
> +++ b/net/ipv6/anycast.c
> @@ -278,6 +278,40 @@ static struct ifacaddr6 *aca_alloc(struct fib6_info *f6i,
> return aca;
> }
>
> +static void inet6_ifacaddr_notify(struct net_device *dev,
> + const struct ifacaddr6 *ifaca, int event)
> +{
> + struct inet6_fill_args fillargs = {
> + .portid = 0,
> + .seq = 0,
> + .event = event,
> + .flags = 0,
0 initializations are not needed.
> + .netnsid = -1,
> + };
> + struct net *net = dev_net(dev);
> + struct sk_buff *skb;
> + int err = -ENOMEM;
> +
> + skb = nlmsg_new(NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
> + nla_total_size(sizeof(struct in6_addr)) +
> + nla_total_size(sizeof(struct ifa_cacheinfo)),
> + GFP_KERNEL);
> + if (!skb)
> + goto error;
> +
> + err = inet6_fill_ifacaddr(skb, ifaca, &fillargs);
> + if (err < 0) {
> + WARN_ON_ONCE(err == -EMSGSIZE);
simple error message should suffice; stack trace does not provide
additional value.
> + nlmsg_free(skb);
> + goto error;
> + }
> +
> + rtnl_notify(skb, net, 0, RTNLGRP_IPV6_ACADDR, NULL, GFP_KERNEL);
> + return;
> +error:
> + rtnl_set_sk_err(net, RTNLGRP_IPV6_ACADDR, err);
> +}
> +
> /*
> * device anycast group inc (add if not found)
> */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND net-next] netlink: add IPv6 anycast join/leave notifications
2025-01-06 17:53 ` David Ahern
@ 2025-01-07 1:31 ` Yuyang Huang
0 siblings, 0 replies; 3+ messages in thread
From: Yuyang Huang @ 2025-01-07 1:31 UTC (permalink / raw)
To: David Ahern
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, roopa, jiri, stephen, jimictw, prohr, liuhangbin,
nicolas.dichtel, andrew, netdev, Maciej Żenczykowski,
Lorenzo Colitti
>0 initializations are not needed.
>simple error message should suffice; stack trace does not provide
>additional value.
Thanks for helping with the review. This patch is superseded by the v2
patch. I will adjust the comment in the v3 patch.
Thanks,
Yuyang
Thanks,
Yuyang
On Tue, Jan 7, 2025 at 2:53 AM David Ahern <dsahern@kernel.org> wrote:
>
> On 1/4/25 7:00 PM, Yuyang Huang wrote:
> > diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
> > index 562cace50ca9..6793ff436986 100644
> > --- a/net/ipv6/anycast.c
> > +++ b/net/ipv6/anycast.c
> > @@ -278,6 +278,40 @@ static struct ifacaddr6 *aca_alloc(struct fib6_info *f6i,
> > return aca;
> > }
> >
> > +static void inet6_ifacaddr_notify(struct net_device *dev,
> > + const struct ifacaddr6 *ifaca, int event)
> > +{
> > + struct inet6_fill_args fillargs = {
> > + .portid = 0,
> > + .seq = 0,
> > + .event = event,
> > + .flags = 0,
>
> 0 initializations are not needed.
>
> > + .netnsid = -1,
> > + };
> > + struct net *net = dev_net(dev);
> > + struct sk_buff *skb;
> > + int err = -ENOMEM;
> > +
> > + skb = nlmsg_new(NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
> > + nla_total_size(sizeof(struct in6_addr)) +
> > + nla_total_size(sizeof(struct ifa_cacheinfo)),
> > + GFP_KERNEL);
> > + if (!skb)
> > + goto error;
> > +
> > + err = inet6_fill_ifacaddr(skb, ifaca, &fillargs);
> > + if (err < 0) {
> > + WARN_ON_ONCE(err == -EMSGSIZE);
>
> simple error message should suffice; stack trace does not provide
> additional value.
>
> > + nlmsg_free(skb);
> > + goto error;
> > + }
> > +
> > + rtnl_notify(skb, net, 0, RTNLGRP_IPV6_ACADDR, NULL, GFP_KERNEL);
> > + return;
> > +error:
> > + rtnl_set_sk_err(net, RTNLGRP_IPV6_ACADDR, err);
> > +}
> > +
> > /*
> > * device anycast group inc (add if not found)
> > */
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-07 1:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-05 2:00 [PATCH RESEND net-next] netlink: add IPv6 anycast join/leave notifications Yuyang Huang
2025-01-06 17:53 ` David Ahern
2025-01-07 1:31 ` Yuyang Huang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).