public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: netdev <netdev@vger.kernel.org>
Subject: iproute2: make genl ctrl ls print multicast groups
Date: Fri, 24 Oct 2008 17:25:52 +0200	[thread overview]
Message-ID: <1224861953.3919.1.camel@johannes.berg> (raw)

This patch makes the genl tool print multicast groups, useful for
discovering which multicast groups are supported.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
 genl/ctrl.c               |   39 ++++++++++++++++++++++++++++++++++++---
 include/linux/genetlink.h |   13 +++++++++++++
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/genl/ctrl.c b/genl/ctrl.c
index ee5acb8..5c02ee1 100644
--- a/genl/ctrl.c
+++ b/genl/ctrl.c
@@ -23,6 +23,7 @@
 #include "genl_utils.h"
 
 #define GENL_MAX_FAM_OPS	256
+#define GENL_MAX_FAM_MCAST	256
 static int usage(void)
 {
 	fprintf(stderr,"Usage: ctrl <CMD>\n" \
@@ -151,6 +152,24 @@ static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
 
 }
 
+static int print_mcast_grp(FILE *fp, struct rtattr *arg)
+{
+	struct rtattr *tb[CTRL_ATTR_MCAST_GRP_MAX + 1];
+
+	if (!arg)
+		return -1;
+
+	parse_rtattr_nested(tb, CTRL_ATTR_MCAST_GRP_MAX, arg);
+	if (tb[CTRL_ATTR_MCAST_GRP_NAME])
+		fprintf(fp, "%s", (char *)RTA_DATA(tb[CTRL_ATTR_MCAST_GRP_NAME]));
+
+	if (tb[CTRL_ATTR_MCAST_GRP_ID]) {
+		__u32 *id = RTA_DATA(tb[CTRL_ATTR_MCAST_GRP_ID]);
+		fprintf(fp, " (%d)", *id);
+	}
+	return 0;
+}
+
 /*
  * The controller sends one nlmsg per family
 */
@@ -225,10 +244,24 @@ static int print_ctrl(const struct sockaddr_nl *who, struct nlmsghdr *n,
 				fprintf(fp,"\n");
 			}
 		}
-
-		/* end of family::cmds definitions .. */
-		fprintf(fp,"\n");
 	}
+	if (tb[CTRL_ATTR_MCAST_GROUPS]) {
+		struct rtattr *tb2[GENL_MAX_FAM_MCAST];
+		int i=0;
+		parse_rtattr_nested(tb2, GENL_MAX_FAM_MCAST, tb[CTRL_ATTR_MCAST_GROUPS]);
+		fprintf(fp, "\tmulticast groups: \n");
+		for (i = 0; i < GENL_MAX_FAM_MCAST; i++) {
+			if (tb2[i]) {
+				fprintf(fp, "\t\t- ", i);
+				if (0 > print_mcast_grp(fp, tb2[i]))
+					fprintf(fp, "Error printing command\n");
+				/* for next command */
+				fprintf(fp,"\n");
+			}
+		}
+	}
+	fprintf(fp,"\n");
+
 	fflush(fp);
 	return 0;
 }
diff --git a/include/linux/genetlink.h b/include/linux/genetlink.h
index f7a9377..7da02c9 100644
--- a/include/linux/genetlink.h
+++ b/include/linux/genetlink.h
@@ -39,6 +39,9 @@ enum {
 	CTRL_CMD_NEWOPS,
 	CTRL_CMD_DELOPS,
 	CTRL_CMD_GETOPS,
+	CTRL_CMD_NEWMCAST_GRP,
+	CTRL_CMD_DELMCAST_GRP,
+	CTRL_CMD_GETMCAST_GRP, /* unused */
 	__CTRL_CMD_MAX,
 };
 
@@ -52,6 +55,7 @@ enum {
 	CTRL_ATTR_HDRSIZE,
 	CTRL_ATTR_MAXATTR,
 	CTRL_ATTR_OPS,
+	CTRL_ATTR_MCAST_GROUPS,
 	__CTRL_ATTR_MAX,
 };
 
@@ -66,4 +70,13 @@ enum {
 
 #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
 
+enum {
+	CTRL_ATTR_MCAST_GRP_UNSPEC,
+	CTRL_ATTR_MCAST_GRP_NAME,
+	CTRL_ATTR_MCAST_GRP_ID,
+	__CTRL_ATTR_MCAST_GRP_MAX,
+};
+
+#define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
+
 #endif	/* __LINUX_GENERIC_NETLINK_H */



                 reply	other threads:[~2008-10-24 17:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1224861953.3919.1.camel@johannes.berg \
    --to=johannes@sipsolutions.net \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.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