From: Hangbin Liu <liuhangbin@gmail.com>
To: Yuyang Huang <yuyanghuang@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"David Ahern" <dsahern@kernel.org>,
roopa@cumulusnetworks.com, jiri@resnulli.us,
stephen@networkplumber.org, jimictw@google.com, prohr@google.com,
nicolas.dichtel@6wind.com, andrew@lunn.ch,
netdev@vger.kernel.org, "Maciej Żenczykowski" <maze@google.com>,
"Lorenzo Colitti" <lorenzo@google.com>
Subject: Re: [PATCH iproute2-next] iproute2: add 'ip monitor mcaddr' support
Date: Mon, 18 Nov 2024 12:36:20 +0000 [thread overview]
Message-ID: <Zzs0xDi-3jdQSuk0@fedora> (raw)
In-Reply-To: <20241117141655.2078777-1-yuyanghuang@google.com>
On Sun, Nov 17, 2024 at 11:16:55PM +0900, Yuyang Huang wrote:
> Enhanced the 'ip monitor' command to track changes in IPv4 and IPv6
> multicast addresses. This update allows the command to listen for
> events related to multicast address additions and deletions by
> registering to the newly introduced RTNLGRP_IPV4_MCADDR and
> RTNLGRP_IPV6_MCADDR netlink groups.
>
> This patch depends on the kernel patch that adds RTNLGRP_IPV4_MCADDR
> and RTNLGRP_IPV6_MCADDR being merged first.
>
> Here is an example usage:
>
> root@uml-x86-64:/# ip monitor mcaddr
> 8: nettest123 inet6 mcast ff01::1 scope global
> 8: nettest123 inet6 mcast ff02::1 scope global
> 8: nettest123 inet mcast 224.0.0.1 scope link
> 8: nettest123 inet6 mcast ff02::1:ff00:7b01 scope global
> Deleted 8: nettest123 inet mcast 224.0.0.1 scope link
> Deleted 8: nettest123 inet6 mcast ff02::1:ff00:7b01 scope global
> Deleted 8: nettest123 inet6 mcast ff02::1 scope global
>
> Cc: Maciej Żenczykowski <maze@google.com>
> Cc: Lorenzo Colitti <lorenzo@google.com>
> Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
> ---
> include/uapi/linux/rtnetlink.h | 8 ++++++++
> ip/ipaddress.c | 17 +++++++++++++++--
> ip/ipmonitor.c | 25 ++++++++++++++++++++++++-
> 3 files changed, 47 insertions(+), 3 deletions(-)
>
> diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> index 4e6c8e14..ccf26bf1 100644
> --- a/include/uapi/linux/rtnetlink.h
> +++ b/include/uapi/linux/rtnetlink.h
> @@ -93,6 +93,10 @@ enum {
> RTM_NEWPREFIX = 52,
> #define RTM_NEWPREFIX RTM_NEWPREFIX
>
> + RTM_NEWMULTICAST,
> +#define RTM_NEWMULTICAST RTM_NEWMULTICAST
> + RTM_DELMULTICAST,
> +#define RTM_DELMULTICAST RTM_DELMULTICAST
> RTM_GETMULTICAST = 58,
> #define RTM_GETMULTICAST RTM_GETMULTICAST
>
> @@ -772,6 +776,10 @@ enum rtnetlink_groups {
> #define RTNLGRP_TUNNEL RTNLGRP_TUNNEL
> RTNLGRP_STATS,
> #define RTNLGRP_STATS RTNLGRP_STATS
> + RTNLGRP_IPV4_MCADDR,
> +#define RTNLGRP_IPV4_MCADDR RTNLGRP_IPV4_MCADDR
> + RTNLGRP_IPV6_MCADDR,
> +#define RTNLGRP_IPV6_MCADDR RTNLGRP_IPV6_MCADDR
> __RTNLGRP_MAX
> };
> #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
No need changes for headers. Stephen will sync the headers.
> @@ -220,6 +226,8 @@ int do_ipmonitor(int argc, char **argv)
> lmask |= IPMON_LNEXTHOP;
> } else if (strcmp(*argv, "stats") == 0) {
> lmask |= IPMON_LSTATS;
> + } else if (strcmp(*argv, "mcaddr") == 0) {
> + lmask |= IPMON_LMCADDR;
> } else if (strcmp(*argv, "all") == 0) {
> prefix_banner = 1;
> } else if (matches(*argv, "all-nsid") == 0) {
> @@ -326,6 +334,21 @@ int do_ipmonitor(int argc, char **argv)
> exit(1);
> }
>
> + if (lmask & IPMON_LMCADDR) {
> + if ((!preferred_family || preferred_family == AF_INET) &&
> + rtnl_add_nl_group(&rth, RTNLGRP_IPV4_MCADDR) < 0) {
The rtnl_add_nl_group() should be aligned with the upper bracket. e.g.
if ((!preferred_family || preferred_family == AF_INET) &&
rtnl_add_nl_group(&rth, RTNLGRP_IPV4_MCADDR) < 0) {
> + fprintf(stderr,
> + "Failed to add ipv4 mcaddr group to list\n");
> + exit(1);
> + }
> + if ((!preferred_family || preferred_family == AF_INET6) &&
> + rtnl_add_nl_group(&rth, RTNLGRP_IPV6_MCADDR) < 0) {
Same with this one.
Thanks
Hangbin
next prev parent reply other threads:[~2024-11-18 12:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-17 14:16 [PATCH iproute2-next] iproute2: add 'ip monitor mcaddr' support Yuyang Huang
2024-11-18 12:36 ` Hangbin Liu [this message]
2024-11-18 13:19 ` Yuyang Huang
2024-11-18 18:45 ` David Ahern
2024-11-19 1:06 ` Andrew Lunn
2024-11-19 4:25 ` Yuyang Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zzs0xDi-3jdQSuk0@fedora \
--to=liuhangbin@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jimictw@google.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=lorenzo@google.com \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=prohr@google.com \
--cc=roopa@cumulusnetworks.com \
--cc=stephen@networkplumber.org \
--cc=yuyanghuang@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).