]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
devlink: introduce -[he]x cmdline option to allow dumping numbers in hex format
authorJiri Pirko <jiri@nvidia.com>
Mon, 25 Apr 2022 10:36:27 +0000 (12:36 +0200)
committerDavid Ahern <dsahern@kernel.org>
Thu, 28 Apr 2022 02:10:28 +0000 (20:10 -0600)
For health reporter dumps it is quite convenient to have the numbers in
hexadecimal format. Introduce a command line option to allow user to
achieve that output.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
devlink/devlink.c
man/man8/devlink.8

index da9f97788bcf33e7d316d76997f0e6176254d310..7ace968ca081045cce3b4d7fe91ba16194109e40 100644 (file)
@@ -367,6 +367,7 @@ struct dl {
        bool pretty_output;
        bool verbose;
        bool stats;
+       bool hex;
        struct {
                bool present;
                char *bus_name;
@@ -8044,6 +8045,8 @@ static int cmd_health_dump_clear(struct dl *dl)
 
 static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
 {
+       const char *num_fmt = dl->hex ? "%#x" : "%u";
+       const char *num64_fmt = dl->hex ? "%#"PRIx64 : "%"PRIu64;
        uint8_t *data;
        uint32_t len;
 
@@ -8053,16 +8056,16 @@ static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
                print_bool(PRINT_ANY, NULL, "%s", mnl_attr_get_u8(nl_data));
                break;
        case MNL_TYPE_U8:
-               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u8(nl_data));
+               print_uint(PRINT_ANY, NULL, num_fmt, mnl_attr_get_u8(nl_data));
                break;
        case MNL_TYPE_U16:
-               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u16(nl_data));
+               print_uint(PRINT_ANY, NULL, num_fmt, mnl_attr_get_u16(nl_data));
                break;
        case MNL_TYPE_U32:
-               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u32(nl_data));
+               print_uint(PRINT_ANY, NULL, num_fmt, mnl_attr_get_u32(nl_data));
                break;
        case MNL_TYPE_U64:
-               print_u64(PRINT_ANY, NULL, "%"PRIu64, mnl_attr_get_u64(nl_data));
+               print_u64(PRINT_ANY, NULL, num64_fmt, mnl_attr_get_u64(nl_data));
                break;
        case MNL_TYPE_NUL_STRING:
                print_string(PRINT_ANY, NULL, "%s", mnl_attr_get_str(nl_data));
@@ -8928,7 +8931,7 @@ static void help(void)
        pr_err("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n"
               "       devlink [ -f[orce] ] -b[atch] filename -N[etns] netnsname\n"
               "where  OBJECT := { dev | port | sb | monitor | dpipe | resource | region | health | trap }\n"
-              "       OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] -s[tatistics] }\n");
+              "       OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] -s[tatistics] -[he]x }\n");
 }
 
 static int dl_cmd(struct dl *dl, int argc, char **argv)
@@ -9042,6 +9045,7 @@ int main(int argc, char **argv)
                { "statistics",         no_argument,            NULL, 's' },
                { "Netns",              required_argument,      NULL, 'N' },
                { "iec",                no_argument,            NULL, 'i' },
+               { "hex",                no_argument,            NULL, 'x' },
                { NULL, 0, NULL, 0 }
        };
        const char *batch_file = NULL;
@@ -9057,7 +9061,7 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
-       while ((opt = getopt_long(argc, argv, "Vfb:njpvsN:i",
+       while ((opt = getopt_long(argc, argv, "Vfb:njpvsN:ix",
                                  long_options, NULL)) >= 0) {
 
                switch (opt) {
@@ -9095,6 +9099,9 @@ int main(int argc, char **argv)
                case 'i':
                        use_iec = true;
                        break;
+               case 'x':
+                       dl->hex = true;
+                       break;
                default:
                        pr_err("Unknown option.\n");
                        help();
index 840cf44cf97b7e44a86bcb3e568d4899d1c54a70..de53061bc88011754088c81982dbd7f0a2f57b3e 100644 (file)
@@ -63,6 +63,10 @@ Switches to the specified network namespace.
 .BR "\-i", " --iec"
 Print human readable rates in IEC units (e.g. 1Ki = 1024).
 
+.TP
+.BR "\-x", " --hex"
+Print dump numbers in hexadecimal format.
+
 .SS
 .I OBJECT