Skip to contentSkip to conversation

genl: print caps for all families

PATCH Applied Jakub Kicinski 3 participants 3 messages Feb 25, 2023 – Mar 4, 2023

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 genl: print caps for all families

Back in 2006 kernel commit 334c29a64507 ("[GENETLINK]: Move command capabilities to flags.") removed some attributes and moved the capabilities to flags. Corresponding iproute2 commit 26328fc3933f ("Add controller support for new features exposed") added the ability to print those caps.

Printing is gated on version of the family, but we're checking the version of each individual family rather than the control family. The format of attributes in the control family is dictated by the version of the control family alone.

In fact the entire version check is not strictly necessary. The code is not using the old attributes, so on older kernels it will simply print nothing either way.

Families can't use flags for random things, because kernel core has a fixed interpretation.

Thanks to this change caps will be shown for all families (assuming kernel newer than 2.6.19), not just those which by coincidence have their local version >= 2.

For instance devlink, before:

  $ genl ctrl get name devlink
  Name: devlink
	ID: 0x15  Version: 0x1  header size: 0  max attribs: 179
	commands supported:
		#1:  ID-0x1
		#2:  ID-0x5
		#3:  ID-0x6
		...

after:

  $ genl ctrl get name devlink
  Name: devlink
	ID: 0x15  Version: 0x1  header size: 0  max attribs: 179
	commands supported:
		#1:  ID-0x1
		Capabilities (0xe):
 		  can doit; can dumpit; has policy
		#2:  ID-0x5
		Capabilities (0xe):

can doit; can dumpit; has policy

		#3:  ID-0x6
		Capabilities (0xb):

requires admin permission; can doit; has policy

Fixes 26328fc3933f ("Add controller support for new features exposed")
---
 genl/ctrl.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
genl/ctrl.c +5 -7
index a2d87af0ad07..8d2e944802ba 100644
@@ -57,7 +57,7 @@ static void print_ctrl_cmd_flags(FILE *fp, __u32 fl)
 	fprintf(fp, "\n");
 }
 
-static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
+static int print_ctrl_cmds(FILE *fp, struct rtattr *arg)
 {
 	struct rtattr *tb[CTRL_ATTR_OP_MAX + 1];
 
@@ -70,7 +70,7 @@ static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
 		fprintf(fp, " ID-0x%x ",*id);
 	}
 	/* we are only gonna do this for newer version of the controller */
-	if (tb[CTRL_ATTR_OP_FLAGS] && ctrl_ver >= 0x2) {
+	if (tb[CTRL_ATTR_OP_FLAGS]) {
 		__u32 *fl = RTA_DATA(tb[CTRL_ATTR_OP_FLAGS]);
 		print_ctrl_cmd_flags(fp, *fl);
 	}
@@ -78,7 +78,7 @@ static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
 
 }
 
-static int print_ctrl_grp(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
+static int print_ctrl_grp(FILE *fp, struct rtattr *arg)
 {
 	struct rtattr *tb[CTRL_ATTR_MCAST_GRP_MAX + 1];
 
@@ -109,7 +109,6 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
 	int len = n->nlmsg_len;
 	struct rtattr *attrs;
 	FILE *fp = (FILE *) arg;
-	__u32 ctrl_v = 0x1;
 
 	if (n->nlmsg_type !=  GENL_ID_CTRL) {
 		fprintf(stderr, "Not a controller message, nlmsg_len=%d "
@@ -148,7 +147,6 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
 	if (tb[CTRL_ATTR_VERSION]) {
 		__u32 *v = RTA_DATA(tb[CTRL_ATTR_VERSION]);
 		fprintf(fp, " Version: 0x%x ",*v);
-		ctrl_v = *v;
 	}
 	if (tb[CTRL_ATTR_HDRSIZE]) {
 		__u32 *h = RTA_DATA(tb[CTRL_ATTR_HDRSIZE]);
@@ -198,7 +196,7 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
 		for (i = 0; i < GENL_MAX_FAM_OPS; i++) {
 			if (tb2[i]) {
 				fprintf(fp, "\t\t#%d: ", i);
-				if (0 > print_ctrl_cmds(fp, tb2[i], ctrl_v)) {
+				if (0 > print_ctrl_cmds(fp, tb2[i])) {
 					fprintf(fp, "Error printing command\n");
 				}
 				/* for next command */
@@ -221,7 +219,7 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
 		for (i = 0; i < GENL_MAX_FAM_GRPS; i++) {
 			if (tb2[i]) {
 				fprintf(fp, "\t\t#%d: ", i);
-				if (0 > print_ctrl_grp(fp, tb2[i], ctrl_v))
+				if (0 > print_ctrl_grp(fp, tb2[i]))
 					fprintf(fp, "Error printing group\n");
 				/* for next group */
 				fprintf(fp,"\n");
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 124 lines · Jakub Kicinski

Back in 2006 kernel commit 334c29a64507 ("[GENETLINK]: Move command capabilities to flags.") removed some attributes and moved the capabilities to flags. Corresponding iproute2 commit 26328fc3933f ("Add controller support for new features exposed") added the ability to print those caps.

Printing is gated on version of the family, but we're checking the version of each individual family rather than the control family. The format of attributes in the control family is dictated by the version of the control family alone.

In fact the entire version check is not strictly necessary. The code is not using the old attributes, so on older kernels it will simply print nothing either way.

Families can't use flags for random things, because kernel core has a fixed interpretation.

Thanks to this change caps will be shown for all families (assuming kernel newer than 2.6.19), not just those which by coincidence have their local version >= 2.

For instance devlink, before:

  $ genl ctrl get name devlink
  Name: devlink
        ID: 0x15  Version: 0x1  header size: 0  max attribs: 179
        commands supported:
                #1:  ID-0x1
                #2:  ID-0x5
                #3:  ID-0x6
                ...

after:

  $ genl ctrl get name devlink
  Name: devlink
        ID: 0x15  Version: 0x1  header size: 0  max attribs: 179
        commands supported:
                #1:  ID-0x1
                Capabilities (0xe):
                  can doit; can dumpit; has policy
                #2:  ID-0x5
                Capabilities (0xe):
                  can doit; can dumpit; has policy

                #3:  ID-0x6
                Capabilities (0xb):
                  requires admin permission; can doit; has policy
Fixes 26328fc3933f ("Add controller support for new features exposed")
---
 genl/ctrl.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
genl/ctrl.c +5 -8
index a2d87af0ad07..8d2e944802ba 100644
@@ -57,7 +57,7 @@ static void print_ctrl_cmd_flags(FILE *fp, __u32 fl)
        fprintf(fp, "\n");
 }
 
-static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
+static int print_ctrl_cmds(FILE *fp, struct rtattr *arg)
 {
        struct rtattr *tb[CTRL_ATTR_OP_MAX + 1];
 
@@ -70,7 +70,7 @@ static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
                fprintf(fp, " ID-0x%x ",*id);
        }
        /* we are only gonna do this for newer version of the controller */
-       if (tb[CTRL_ATTR_OP_FLAGS] && ctrl_ver >= 0x2) {
+       if (tb[CTRL_ATTR_OP_FLAGS]) {
                __u32 *fl = RTA_DATA(tb[CTRL_ATTR_OP_FLAGS]);
                print_ctrl_cmd_flags(fp, *fl);
        }
@@ -78,7 +78,7 @@ static int print_ctrl_cmds(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
 
 }
 
-static int print_ctrl_grp(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)
+static int print_ctrl_grp(FILE *fp, struct rtattr *arg)
 {
        struct rtattr *tb[CTRL_ATTR_MCAST_GRP_MAX + 1];
 
@@ -109,7 +109,6 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
        int len = n->nlmsg_len;
        struct rtattr *attrs;
        FILE *fp = (FILE *) arg;
-       __u32 ctrl_v = 0x1;
 
        if (n->nlmsg_type !=  GENL_ID_CTRL) {
                fprintf(stderr, "Not a controller message, nlmsg_len=%d "
@@ -148,7 +147,6 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
        if (tb[CTRL_ATTR_VERSION]) {
                __u32 *v = RTA_DATA(tb[CTRL_ATTR_VERSION]);
                fprintf(fp, " Version: 0x%x ",*v);
-               ctrl_v = *v;
        }
        if (tb[CTRL_ATTR_HDRSIZE]) {
                __u32 *h = RTA_DATA(tb[CTRL_ATTR_HDRSIZE]);
@@ -198,7 +196,7 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
                for (i = 0; i < GENL_MAX_FAM_OPS; i++) {
                        if (tb2[i]) {
                                fprintf(fp, "\t\t#%d: ", i);
-                               if (0 > print_ctrl_cmds(fp, tb2[i], ctrl_v)) {
+                               if (0 > print_ctrl_cmds(fp, tb2[i])) {
                                        fprintf(fp, "Error printing command\n");
                                }
                                /* for next command */
@@ -221,7 +219,7 @@ static int print_ctrl(struct rtnl_ctrl_data *ctrl,
                for (i = 0; i < GENL_MAX_FAM_GRPS; i++) {
                        if (tb2[i]) {
                                fprintf(fp, "\t\t#%d: ", i);
-                               if (0 > print_ctrl_grp(fp, tb2[i], ctrl_v))
+                               if (0 > print_ctrl_grp(fp, tb2[i]))
                                        fprintf(fp, "Error printing group\n");
                                /* for next group */
                                fprintf(fp,"\n");
--
Quoted 2 lines

2.39.2

cheers,
jamal

#2 lore raw
In reply to Jakub Kicinski
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 6 lines · On Fri, 24 Feb 2023 16:37:54 -0800 you wrote:

Back in 2006 kernel commit 334c29a64507 ("[GENETLINK]: Move command capabilities to flags.") removed some attributes and moved the capabilities to flags. Corresponding iproute2 commit 26328fc3933f ("Add controller support for new features exposed") added the ability to print those caps.

Quoted 6 lines

Printing is gated on version of the family, but we're checking the version of each individual family rather than the control family. The format of attributes in the control family is dictated by the version of the control family alone.

[...]

Here is the summary with links:
- [iproute2] genl: print caps for all families

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=2a98bc13169b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html