From patchwork Thu Nov 21 05:56:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yuyang Huang X-Patchwork-Id: 13881674 X-Patchwork-Delegate: dsahern@gmail.com Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88B7E2309B6 for ; Thu, 21 Nov 2024 05:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732168583; cv=none; b=XyZ1BbvnOTdgr2keZqgoKFFGegpiFH7uAqU62pVw+bUz6z0U0jRo31TU5aIr/mqZYQSR9HuheqlS3J4HR3JPyCzpmBvr9sKy8Jbyef7pMxn5U14E+g1LqSSxy4qBdH3Xc7XiKoTPsCL6maY84omEkgDKUIGfWq+vnK2yx0cQvyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732168583; c=relaxed/simple; bh=ztknavxuIVBDUI45LRspwNFcluis/bcqOBEq7fbbVHg=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=q80s1qxnmXDGCCGfk0gzNdU8gPWVgsiyDxK4gire3vlgzHQOTHaXAKydQseo5/2EZWpv1E0TwKsKb+6Xtrae0GgwbO9UQtDz+W/vRSjlR6K/gXntAZrgHMjMLofBny7gqdqRaai+rRJ58fjwLkc1+A+F9thVVKFtRWkgWmzFOOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuyanghuang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WQyLEew6; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuyanghuang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WQyLEew6" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea8901dff1so8011537b3.1 for ; Wed, 20 Nov 2024 21:56:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732168580; x=1732773380; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=D5VNkpWoVPxuHBX2Pcnf13AY6LQMDvUHfwQtvBvrrKg=; b=WQyLEew6Fhr0LXrw0ts4vNNfW35mlkzLDzuwso2ZJKqk07Np7NhMcXo8LycmGtZp8G qnPmL6UXPGutfxb+Fv/D3Z+VrbUf9TAXgScBpg0hhZmkKjHknoHjOYkZyytGjMMdopBf 7ZagTZmrALkOC6UKS7LiFJIS9EgjHkmglQwESkdxPow2yjf9TovFc3xAn3s4yw9GfMeC /g3WmtkcFc1Z+BKNzD2nquhaNpnmtaEIiTzBrpRwWuV7/MNd4EKp4ELxCU0eV661B4No J6HAt7c7XiC+FHUi/sAZcYrr34jNjMKSZzrLXGkQWhwZe3m5zGIQWJfdDKE+iEiLTpzU eFDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732168580; x=1732773380; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=D5VNkpWoVPxuHBX2Pcnf13AY6LQMDvUHfwQtvBvrrKg=; b=UJYrys/d32Vi5E6f90if44Y9RTHRJad4WciujnvrG/Mum17Q3WfEQTFq2I1ZWlGA2f lsn2I/qiyxmi0J9Qlb/I3MDfS57aB8/3/RGBY5B9u67XOUCQ4wQzVS8r6KcKQAr2RTtT 3WDaIJHpJrJeXoutJ3GDVzu2NWXt1E11nvg8c0R4rmc4KhvenKceUMdcnscfzeL/rCUi ZBTZo3PY3cDQX7GjebABSJIVZYO4AlO/KEZgkhU4E5x9Zyk4YkAOjPTiJPs0TSebOpbG 0bGNoE1135OlXXA7T88Zqb4/guTkn1MkA2SxPuvW5CXCoIFttAsp+ifQATB5LSduHGau 5+Ww== X-Forwarded-Encrypted: i=1; AJvYcCUhbVBOpEq51cTNvxoMpyBRRjhhQdEN/ymbYsTAUIMs8vmxLr/bErzxoXDiqlvdCBIqQo6yic0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4vChyXAb8xKdddDpn++dQfDwZV3qX4BWY1m+gIPgNqF+m1G+T FbN0ZmzxtXsLxks9BYa9QSHyKcLzDL/mQM2B4KjBsqAiZpiX4roYqWvv/ODHZO3qDr6COKUCw+5 rtHAxvvOmsldmwqcBPfnQhg== X-Google-Smtp-Source: AGHT+IH53CQR5B+ZXp6BN2nQgHDSPFZeHTLSsYHJCpctFuJ+JRzp5TZZGJKVH+pDsEId0GV4vTZCHQ4PV/865ttQQA== X-Received: from yuyanghuang.tok.corp.google.com ([2401:fa00:8f:203:b514:d526:a415:3fd7]) (user=yuyanghuang job=sendgmr) by 2002:a05:690c:ec9:b0:6ee:7ea4:4925 with SMTP id 00721157ae682-6eebd2f0fafmr1194457b3.5.1732168580253; Wed, 20 Nov 2024 21:56:20 -0800 (PST) Date: Thu, 21 Nov 2024 14:56:14 +0900 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.371.ga323438b13-goog Message-ID: <20241121055615.826882-1-yuyanghuang@google.com> Subject: [PATCH iproute2-next, v2 1/2] iproute2: expose netlink constants in UAPI From: Yuyang Huang To: Yuyang Huang Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , David Ahern , roopa@cumulusnetworks.com, jiri@resnulli.us, stephen@networkplumber.org, jimictw@google.com, prohr@google.com, liuhangbin@gmail.com, nicolas.dichtel@6wind.com, andrew@lunn.ch, netdev@vger.kernel.org, " =?utf-8?q?Maciej_=C5=BBenczykow?= =?utf-8?q?ski?= " , Lorenzo Colitti X-Patchwork-Delegate: dsahern@gmail.com This change adds the following multicast related netlink constants to the UAPI: * RTNLGRP_IPV4_MCADDR and RTNLGRP_IPV6_MCADDR: Netlink multicast groups for IPv4 and IPv6 multicast address changes. * RTM_NEWMULTICAST and RTM_DELMULTICAST: Netlink message types for multicast address additions and deletions. Exposing these constants in the UAPI enables ip monitor to effectively monitor and manage multicast group memberships. Cc: Maciej Żenczykowski Cc: Lorenzo Colitti Signed-off-by: Yuyang Huang --- include/uapi/linux/rtnetlink.h | 8 ++++++++ 1 file changed, 8 insertions(+) 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) From patchwork Thu Nov 21 05:56:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yuyang Huang X-Patchwork-Id: 13881675 X-Patchwork-Delegate: dsahern@gmail.com Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D4FE2309B6 for ; Thu, 21 Nov 2024 05:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732168587; cv=none; b=S8gvTk5YpWNekSPrAsO9ey4pxrSXiBVChJt5WuUFxHukTY5Q7xIJemMGc11o9gAI6z0SNhWxQ/5fBWtadV/DLUHsXNWm3O28uunjDxXrNtTzqcz7cS29+tq2vj2bwRYTmnRS4m6g4xKKmud+L2feNK1TtOdnrozW9W1MaQcBIs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732168587; c=relaxed/simple; bh=VNx8I/juCIHP0kztyYJX441I+5TTY8l1myOYu29viAQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RMp24fv1jhwoigqydbQtCSetMjv6l4iCkS9E8Utu3iOQH7BXIBY3QG3cXQS0N4oAxmKBQaMhri3RBTl2P6j4DvnG/GBSPCiMPlmv45ExigcYrsS/hkAUPssqylktfg9V7BX0NclCMs9rXIGWX4HWMXJOiQOZPjVj3kkYeThfD+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuyanghuang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LvboM6Dr; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuyanghuang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LvboM6Dr" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2971589916so873292276.3 for ; Wed, 20 Nov 2024 21:56:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732168585; x=1732773385; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=6gpQHyvdz3/cQZhC+wn7EctdgPhoza9EHtNYdRv78gg=; b=LvboM6Drrcy4KZz1qnYqKN3c3C7pWv6orZlhZ4gz1/ueBkR9/tRNq+GTeP14zZnxyf 4hTBw8Bv/SbAm1btZbbhU28RPpJu9yghK5UF6w7xPzyipDLS1nc8BQRkdwx0ozkQooAj wuoanBPlc+qrLKyIqN1dbtn93e5LLGYua9P13XfeJ2AWXMXxsv9DmMGIf+UB/P0CfQBZ npqFhzBFwFtzbgBjzEfHZsaY6hd+wV4J4rTypvHbO8zx+elZGoiEGY+rLpndWE06WLPu KqCdrO5JBSNxYa1xfX0lrv0AqbTPDJ0aDdyhMFa6R7eDzmwrglXuE9HjdzAKJw8M8ho9 Inqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732168585; x=1732773385; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=6gpQHyvdz3/cQZhC+wn7EctdgPhoza9EHtNYdRv78gg=; b=p1lWyXg1SGjT4f6wavMP1bdGyt3wLHLiSETcAcwCz+d6oGoq/Rg9/b/yMu74Faml9o KEjknQgTij6vbfliOjK5WZI+rcPgYF17I+QlZI394wMxpm/bP9UXvFhkbSMI0QCkN/Qu NX3mUc22nX1/jMSwSPUImDKoacM85YtzYu9SNdlmnIk8gqs0E+Xnj4kHSwwusdJEVIQL XazYXnOxH6jMjFwl8jk3CO6MhbRkq8kG0u6AAIMYLQ3fZJTZt6/UbIorGnq3RKOa59Fp W7l483S8q1ncgHZelTiplIAIvTytb2iwLkyPCnLvT6qSTXAvdp6s5Kb8bVn0lGwVdyMe MyQw== X-Forwarded-Encrypted: i=1; AJvYcCWKw65//4NMLU1rKktzT+Ng7/51ZIRU9GkIu0dHKxwjWTyF+Wv4jTUErVpvYT+oSVTvMFgZC6I=@vger.kernel.org X-Gm-Message-State: AOJu0YyVTqGLI3ryCgRtDGR/5/u4gJY63JAQXnsm1kdS8GcgLF3r00a7 EHN+mYmwH4Y4VF0jAIS8go7DdDzLPyhQrofasq4d/5GyO+uqx438uUtlbYLxee3XouDWPQ+jZZv 2ygLwxFdxV8u1OyQ5vMs+qA== X-Google-Smtp-Source: AGHT+IHLlWE5euc6o4hH0upicx6wBJNeZKmVtgPxJBJDrlJ8T0GuAJjERbIWp3nedsgnJdu4L+ACCyIbsWiocXI62g== X-Received: from yuyanghuang.tok.corp.google.com ([2401:fa00:8f:203:b514:d526:a415:3fd7]) (user=yuyanghuang job=sendgmr) by 2002:a25:d60f:0:b0:e38:bd8b:df20 with SMTP id 3f1490d57ef6-e38cb797158mr2205276.9.1732168585198; Wed, 20 Nov 2024 21:56:25 -0800 (PST) Date: Thu, 21 Nov 2024 14:56:15 +0900 In-Reply-To: <20241121055615.826882-1-yuyanghuang@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241121055615.826882-1-yuyanghuang@google.com> X-Mailer: git-send-email 2.47.0.371.ga323438b13-goog Message-ID: <20241121055615.826882-2-yuyanghuang@google.com> Subject: [PATCH iproute2-next, v2 2/2] iproute2: add 'ip monitor mcaddr' support From: Yuyang Huang To: Yuyang Huang Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , David Ahern , roopa@cumulusnetworks.com, jiri@resnulli.us, stephen@networkplumber.org, jimictw@google.com, prohr@google.com, liuhangbin@gmail.com, nicolas.dichtel@6wind.com, andrew@lunn.ch, netdev@vger.kernel.org, " =?utf-8?q?Maciej_=C5=BBenczykow?= =?utf-8?q?ski?= " , Lorenzo Colitti X-Patchwork-Delegate: dsahern@gmail.com 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 global 8: nettest123 inet6 mcast ff02::1:ff00:7b01 scope global Deleted 8: nettest123 inet mcast 224.0.0.1 scope global Deleted 8: nettest123 inet6 mcast ff02::1:ff00:7b01 scope global Deleted 8: nettest123 inet6 mcast ff02::1 scope global Cc: Maciej Żenczykowski Cc: Lorenzo Colitti Signed-off-by: Yuyang Huang --- Changelog since v1: - Move the UAPI constants to a separate patch. - Update the commit message. - Fix the indentation format. ip/ipaddress.c | 17 +++++++++++++++-- ip/ipmonitor.c | 25 ++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index d90ba94d..373f613f 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1504,7 +1504,10 @@ int print_addrinfo(struct nlmsghdr *n, void *arg) SPRINT_BUF(b1); - if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR) + if (n->nlmsg_type != RTM_NEWADDR + && n->nlmsg_type != RTM_DELADDR + && n->nlmsg_type != RTM_NEWMULTICAST + && n->nlmsg_type != RTM_DELMULTICAST) return 0; len -= NLMSG_LENGTH(sizeof(*ifa)); if (len < 0) { @@ -1564,7 +1567,7 @@ int print_addrinfo(struct nlmsghdr *n, void *arg) print_headers(fp, "[ADDR]"); - if (n->nlmsg_type == RTM_DELADDR) + if (n->nlmsg_type == RTM_DELADDR || n->nlmsg_type == RTM_DELMULTICAST) print_bool(PRINT_ANY, "deleted", "Deleted ", true); if (!brief) { @@ -1639,6 +1642,16 @@ int print_addrinfo(struct nlmsghdr *n, void *arg) rta_tb[IFA_ANYCAST])); } + if (rta_tb[IFA_MULTICAST]) { + print_string(PRINT_FP, NULL, "%s ", "mcast"); + print_color_string(PRINT_ANY, + ifa_family_color(ifa->ifa_family), + "multicast", + "%s ", + format_host_rta(ifa->ifa_family, + rta_tb[IFA_MULTICAST])); + } + print_string(PRINT_ANY, "scope", "scope %s ", diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c index de67f2c9..4743b3e1 100644 --- a/ip/ipmonitor.c +++ b/ip/ipmonitor.c @@ -30,7 +30,7 @@ static void usage(void) fprintf(stderr, "Usage: ip monitor [ all | OBJECTS ] [ FILE ] [ label ] [ all-nsid ]\n" " [ dev DEVICE ]\n" - "OBJECTS := address | link | mroute | neigh | netconf |\n" + "OBJECTS := address | link | mroute | mcaddr | neigh | netconf |\n" " nexthop | nsid | prefix | route | rule | stats\n" "FILE := file FILENAME\n"); exit(-1); @@ -152,6 +152,11 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl, ipstats_print(n, arg); return 0; + case RTM_DELMULTICAST: + case RTM_NEWMULTICAST: + print_addrinfo(n, arg); + return 0; + case NLMSG_ERROR: case NLMSG_NOOP: case NLMSG_DONE: @@ -178,6 +183,7 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl, #define IPMON_LRULE BIT(8) #define IPMON_LNSID BIT(9) #define IPMON_LNEXTHOP BIT(10) +#define IPMON_LMCADDR BIT(11) #define IPMON_L_ALL (~0) @@ -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) { + 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) { + fprintf(stderr, + "Failed to add ipv6 mcaddr group to list\n"); + exit(1); + } + } + if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0) exit(1);