git: f45132db215b - main - genl: subscribe to all if no group is provided

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Mon, 07 Oct 2024 10:12:10 UTC
The branch main has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=f45132db215be4d811e0efa0d01bcab72e4d0a59

commit f45132db215be4d811e0efa0d01bcab72e4d0a59
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2024-10-07 10:07:07 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2024-10-07 10:07:07 +0000

    genl: subscribe to all if no group is provided
    
    the monitor command now subscribes too all groups if no "multicast
    group" is provided, this avoid potential collision with a group that
    could be named "all"
---
 usr.bin/genl/genl.1 | 13 +++++++++----
 usr.bin/genl/genl.c |  6 +++---
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/usr.bin/genl/genl.1 b/usr.bin/genl/genl.1
index b3d66298eb00..8aafd24dd6f3 100644
--- a/usr.bin/genl/genl.1
+++ b/usr.bin/genl/genl.1
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd Oct 5, 2023
+.Dd Oct 5, 2024
 .Dt GENL 1
 .Os
 .Sh NAME
@@ -35,7 +35,8 @@
 .Pp
 .Nm Cm list
 .Pp
-.Nm Cm monitor Ao family Ac Ao multicast group Ac
+.Nm Cm monitor Ao family Ac
+.Op multicast group
 .Sh DESCRIPTION
 The
 .Nm
@@ -52,7 +53,7 @@ Id of the operation if any and associated capabilities
 .It multicast groups
 If of the available multicast group if any and it associated name
 .El
-.It Cm monitor Ao family Ac Ao multicast group Ac
+.It Cm monitor Ao family Ac Oo multicast group Oc
 Connect to the
 .Ar family
 protocol and subscribe to the
@@ -60,7 +61,11 @@ protocol and subscribe to the
 then print the received messages in a readable format if the protocol is known.
 So far only
 .Qq nlctrl
-is known.
+and
+.Qq nlsysevent
+are known. If no
+.Ar multicast group
+are provided then all the groups are subsribed to.
 .El
 .Sh SEE ALSO
 .Xr genetlink 4 ,
diff --git a/usr.bin/genl/genl.c b/usr.bin/genl/genl.c
index eaf20d20e890..88880c4bacbd 100644
--- a/usr.bin/genl/genl.c
+++ b/usr.bin/genl/genl.c
@@ -51,7 +51,7 @@ static struct commands {
 	const char *usage;
 	int (*cmd)(int argc, char **argv);
 } cmds[] = {
-	{ "monitor", "monitor <family> <multicast group>", monitor_mcast },
+	{ "monitor", "monitor <family> [multicast group]", monitor_mcast },
 	{ "list", "list", list_families },
 };
 
@@ -205,13 +205,13 @@ monitor_mcast(int argc __unused, char **argv)
 	if (!snl_init(&ss, NETLINK_GENERIC))
 		err(EXIT_FAILURE, "snl_init()");
 
-	if (argc != 2) {
+	if (argc < 1 || argc > 2) {
 		usage();
 		return (EXIT_FAILURE);
 	}
 	if (!snl_get_genl_family_info(&ss, argv[0], &attrs))
 		errx(EXIT_FAILURE, "Unknown family '%s'", argv[0]);
-	if (strcmp(argv[1], "all") == 0)
+	if (argc == 1)
 		all = true;
 	for (uint32_t i = 0; i < attrs.mcast_groups.num_groups; i++) {
 		if (all || strcmp(attrs.mcast_groups.groups[i]->mcast_grp_name,