]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - devlink/devlink.c
devlink: fix encap mode manupulation
[mirror_iproute2.git] / devlink / devlink.c
index a641c4dc1e7926f6aedc13c1e0f72047a8881ca4..6a24f28fac8764f6e6787ddd152210bb9059af68 100644 (file)
@@ -41,6 +41,9 @@
 #define ESWITCH_INLINE_MODE_NETWORK "network"
 #define ESWITCH_INLINE_MODE_TRANSPORT "transport"
 
+#define ESWITCH_ENCAP_MODE_NONE "none"
+#define ESWITCH_ENCAP_MODE_BASIC "basic"
+
 #define PARAM_CMODE_RUNTIME_STR "runtime"
 #define PARAM_CMODE_DRIVERINIT_STR "driverinit"
 #define PARAM_CMODE_PERMANENT_STR "permanent"
@@ -262,6 +265,9 @@ static void ifname_map_free(struct ifname_map *ifname_map)
 #define DL_OPT_TRAP_ACTION             BIT(31)
 #define DL_OPT_TRAP_GROUP_NAME         BIT(32)
 #define DL_OPT_NETNS   BIT(33)
+#define DL_OPT_TRAP_POLICER_ID         BIT(34)
+#define DL_OPT_TRAP_POLICER_RATE       BIT(35)
+#define DL_OPT_TRAP_POLICER_BURST      BIT(36)
 
 struct dl_opts {
        uint64_t present; /* flags of present items */
@@ -281,7 +287,7 @@ struct dl_opts {
        enum devlink_eswitch_inline_mode eswitch_inline_mode;
        const char *dpipe_table_name;
        bool dpipe_counters_enable;
-       bool eswitch_encap_mode;
+       enum devlink_eswitch_encap_mode eswitch_encap_mode;
        const char *resource_path;
        uint64_t resource_size;
        uint32_t resource_id;
@@ -303,6 +309,9 @@ struct dl_opts {
        enum devlink_trap_action trap_action;
        bool netns_is_pid;
        uint32_t netns;
+       uint32_t trap_policer_id;
+       uint64_t trap_policer_rate;
+       uint64_t trap_policer_burst;
 };
 
 struct dl {
@@ -395,6 +404,17 @@ static void __pr_out_indent_newline(struct dl *dl)
                pr_out(" ");
 }
 
+static void check_indent_newline(struct dl *dl)
+{
+       __pr_out_indent_newline(dl);
+
+       if (g_indent_newline && !is_json_context()) {
+               printf("%s", g_indent_str);
+               g_indent_newline = false;
+       }
+       g_new_line_count = 0;
+}
+
 static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_BUS_NAME] = MNL_TYPE_NUL_STRING,
        [DEVLINK_ATTR_DEV_NAME] = MNL_TYPE_NUL_STRING,
@@ -495,12 +515,16 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_TRAP_METADATA] = MNL_TYPE_NESTED,
        [DEVLINK_ATTR_TRAP_GROUP_NAME] = MNL_TYPE_STRING,
        [DEVLINK_ATTR_RELOAD_FAILED] = MNL_TYPE_U8,
+       [DEVLINK_ATTR_TRAP_POLICER_ID] = MNL_TYPE_U32,
+       [DEVLINK_ATTR_TRAP_POLICER_RATE] = MNL_TYPE_U64,
+       [DEVLINK_ATTR_TRAP_POLICER_BURST] = MNL_TYPE_U64,
 };
 
 static const enum mnl_attr_data_type
 devlink_stats_policy[DEVLINK_ATTR_STATS_MAX + 1] = {
        [DEVLINK_ATTR_STATS_RX_PACKETS] = MNL_TYPE_U64,
        [DEVLINK_ATTR_STATS_RX_BYTES] = MNL_TYPE_U64,
+       [DEVLINK_ATTR_STATS_RX_DROPPED] = MNL_TYPE_U64,
 };
 
 static int attr_cb(const struct nlattr *attr, void *data)
@@ -718,9 +742,11 @@ static int strtobool(const char *str, bool *p_val)
 {
        bool val;
 
-       if (!strcmp(str, "true") || !strcmp(str, "1"))
+       if (!strcmp(str, "true") || !strcmp(str, "1") ||
+           !strcmp(str, "enable"))
                val = true;
-       else if (!strcmp(str, "false") || !strcmp(str, "0"))
+       else if (!strcmp(str, "false") || !strcmp(str, "0") ||
+                !strcmp(str, "disable"))
                val = false;
        else
                return -EINVAL;
@@ -1055,26 +1081,19 @@ static int eswitch_inline_mode_get(const char *typestr,
        return 0;
 }
 
-static int dpipe_counters_enable_get(const char *typestr,
-                                    bool *counters_enable)
-{
-       if (strcmp(typestr, "enable") == 0) {
-               *counters_enable = 1;
-       } else if (strcmp(typestr, "disable") == 0) {
-               *counters_enable = 0;
-       } else {
-               pr_err("Unknown counter_state \"%s\"\n", typestr);
-               return -EINVAL;
-       }
-       return 0;
-}
-
-static int eswitch_encap_mode_get(const char *typestr, bool *p_mode)
+static int
+eswitch_encap_mode_get(const char *typestr,
+                      enum devlink_eswitch_encap_mode *p_encap_mode)
 {
-       if (strcmp(typestr, "enable") == 0) {
-               *p_mode = true;
-       } else if (strcmp(typestr, "disable") == 0) {
-               *p_mode = false;
+       /* The initial implementation incorrectly accepted "enable"/"disable".
+        * Carry it to maintain backward compatibility.
+        */
+       if (strcmp(typestr, "disable") == 0 ||
+                  strcmp(typestr, ESWITCH_ENCAP_MODE_NONE) == 0) {
+               *p_encap_mode = DEVLINK_ESWITCH_ENCAP_MODE_NONE;
+       } else if (strcmp(typestr, "enable") == 0 ||
+                  strcmp(typestr, ESWITCH_ENCAP_MODE_BASIC) == 0) {
+               *p_encap_mode = DEVLINK_ESWITCH_ENCAP_MODE_BASIC;
        } else {
                pr_err("Unknown eswitch encap mode \"%s\"\n", typestr);
                return -EINVAL;
@@ -1315,18 +1334,13 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                        o_found |= DL_OPT_DPIPE_TABLE_NAME;
                } else if (dl_argv_match(dl, "counters") &&
                           (o_all & DL_OPT_DPIPE_TABLE_COUNTERS)) {
-                       const char *typestr;
-
                        dl_arg_inc(dl);
-                       err = dl_argv_str(dl, &typestr);
-                       if (err)
-                               return err;
-                       err = dpipe_counters_enable_get(typestr,
-                                                       &opts->dpipe_counters_enable);
+                       err = dl_argv_bool(dl, &opts->dpipe_counters_enable);
                        if (err)
                                return err;
                        o_found |= DL_OPT_DPIPE_TABLE_COUNTERS;
-               } else if (dl_argv_match(dl, "encap") &&
+               } else if ((dl_argv_match(dl, "encap") || /* Original incorrect implementation */
+                           dl_argv_match(dl, "encap-mode")) &&
                           (o_all & DL_OPT_ESWITCH_ENCAP_MODE)) {
                        const char *typestr;
 
@@ -1479,6 +1493,32 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                                opts->netns_is_pid = true;
                        }
                        o_found |= DL_OPT_NETNS;
+               } else if (dl_argv_match(dl, "policer") &&
+                          (o_all & DL_OPT_TRAP_POLICER_ID)) {
+                       dl_arg_inc(dl);
+                       err = dl_argv_uint32_t(dl, &opts->trap_policer_id);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_TRAP_POLICER_ID;
+               } else if (dl_argv_match(dl, "nopolicer") &&
+                          (o_all & DL_OPT_TRAP_POLICER_ID)) {
+                       dl_arg_inc(dl);
+                       opts->trap_policer_id = 0;
+                       o_found |= DL_OPT_TRAP_POLICER_ID;
+               } else if (dl_argv_match(dl, "rate") &&
+                          (o_all & DL_OPT_TRAP_POLICER_RATE)) {
+                       dl_arg_inc(dl);
+                       err = dl_argv_uint64_t(dl, &opts->trap_policer_rate);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_TRAP_POLICER_RATE;
+               } else if (dl_argv_match(dl, "burst") &&
+                          (o_all & DL_OPT_TRAP_POLICER_BURST)) {
+                       dl_arg_inc(dl);
+                       err = dl_argv_uint64_t(dl, &opts->trap_policer_burst);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_TRAP_POLICER_BURST;
                } else {
                        pr_err("Unknown option \"%s\"\n", dl_argv(dl));
                        return -EINVAL;
@@ -1606,6 +1646,15 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
                                 opts->netns_is_pid ? DEVLINK_ATTR_NETNS_PID :
                                                      DEVLINK_ATTR_NETNS_FD,
                                 opts->netns);
+       if (opts->present & DL_OPT_TRAP_POLICER_ID)
+               mnl_attr_put_u32(nlh, DEVLINK_ATTR_TRAP_POLICER_ID,
+                                opts->trap_policer_id);
+       if (opts->present & DL_OPT_TRAP_POLICER_RATE)
+               mnl_attr_put_u64(nlh, DEVLINK_ATTR_TRAP_POLICER_RATE,
+                                opts->trap_policer_rate);
+       if (opts->present & DL_OPT_TRAP_POLICER_BURST)
+               mnl_attr_put_u64(nlh, DEVLINK_ATTR_TRAP_POLICER_BURST,
+                                opts->trap_policer_burst);
 }
 
 static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
@@ -1662,7 +1711,7 @@ static void cmd_dev_help(void)
        pr_err("Usage: devlink dev show [ DEV ]\n");
        pr_err("       devlink dev eswitch set DEV [ mode { legacy | switchdev } ]\n");
        pr_err("                               [ inline-mode { none | link | network | transport } ]\n");
-       pr_err("                               [ encap { disable | enable } ]\n");
+       pr_err("                               [ encap-mode { none | basic } ]\n");
        pr_err("       devlink dev eswitch show DEV\n");
        pr_err("       devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
        pr_err("       devlink dev param show [DEV name PARAMETER]\n");
@@ -1865,38 +1914,11 @@ static void pr_out_port_handle_end(struct dl *dl)
                pr_out("\n");
 }
 
-
-static void pr_out_str(struct dl *dl, const char *name, const char *val)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               print_string(PRINT_JSON, name, NULL, val);
-       else
-               pr_out("%s %s", name, val);
-}
-
-static void pr_out_bool(struct dl *dl, const char *name, bool val)
-{
-       if (dl->json_output)
-               print_bool(PRINT_JSON, name, NULL, val);
-       else
-               pr_out_str(dl, name, val ? "true" : "false");
-}
-
-static void pr_out_uint(struct dl *dl, const char *name, unsigned int val)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               print_uint(PRINT_JSON, name, NULL, val);
-       else
-               pr_out("%s %u", name, val);
-}
-
 static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
 {
        __pr_out_indent_newline(dl);
        if (val == (uint64_t) -1)
-               return pr_out_str(dl, name, "unlimited");
+               return print_string_name_value(name, "unlimited");
 
        if (dl->json_output)
                print_u64(PRINT_JSON, name, NULL, val);
@@ -1904,33 +1926,6 @@ static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
                pr_out("%s %"PRIu64, name, val);
 }
 
-static void pr_out_bool_value(struct dl *dl, bool value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               print_bool(PRINT_JSON, NULL, NULL, value);
-       else
-               pr_out("%s", value ? "true" : "false");
-}
-
-static void pr_out_uint_value(struct dl *dl, unsigned int value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               print_uint(PRINT_JSON, NULL, NULL, value);
-       else
-               pr_out("%u", value);
-}
-
-static void pr_out_uint64_value(struct dl *dl, uint64_t value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               print_u64(PRINT_JSON, NULL, NULL, value);
-       else
-               pr_out("%"PRIu64, value);
-}
-
 static bool is_binary_eol(int i)
 {
        return !(i%16);
@@ -1953,15 +1948,6 @@ static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len)
                __pr_out_newline();
 }
 
-static void pr_out_str_value(struct dl *dl, const char *value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               print_string(PRINT_JSON, NULL, NULL, value);
-       else
-               pr_out("%s", value);
-}
-
 static void pr_out_name(struct dl *dl, const char *name)
 {
        __pr_out_indent_newline(dl);
@@ -2110,6 +2096,9 @@ static void pr_out_stats(struct dl *dl, struct nlattr *nla_stats)
        if (tb[DEVLINK_ATTR_STATS_RX_PACKETS])
                pr_out_u64(dl, "packets",
                           mnl_attr_get_u64(tb[DEVLINK_ATTR_STATS_RX_PACKETS]));
+       if (tb[DEVLINK_ATTR_STATS_RX_DROPPED])
+               pr_out_u64(dl, "dropped",
+                          mnl_attr_get_u64(tb[DEVLINK_ATTR_STATS_RX_DROPPED]));
        pr_out_object_end(dl);
        pr_out_object_end(dl);
 }
@@ -2152,23 +2141,39 @@ static const char *eswitch_inline_mode_name(uint32_t mode)
        }
 }
 
+static const char *eswitch_encap_mode_name(uint32_t mode)
+{
+       switch (mode) {
+       case DEVLINK_ESWITCH_ENCAP_MODE_NONE:
+               return ESWITCH_ENCAP_MODE_NONE;
+       case DEVLINK_ESWITCH_ENCAP_MODE_BASIC:
+               return ESWITCH_ENCAP_MODE_BASIC;
+       default:
+               return "<unknown mode>";
+       }
+}
+
 static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
 {
        __pr_out_handle_start(dl, tb, true, false);
 
-       if (tb[DEVLINK_ATTR_ESWITCH_MODE])
-               pr_out_str(dl, "mode",
-                          eswitch_mode_name(mnl_attr_get_u16(tb[DEVLINK_ATTR_ESWITCH_MODE])));
-
-       if (tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])
-               pr_out_str(dl, "inline-mode",
-                          eswitch_inline_mode_name(mnl_attr_get_u8(
-                                  tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
-
+       if (tb[DEVLINK_ATTR_ESWITCH_MODE]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "mode", "mode %s",
+                            eswitch_mode_name(mnl_attr_get_u16(
+                                    tb[DEVLINK_ATTR_ESWITCH_MODE])));
+       }
+       if (tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "inline-mode", "inline-mode %s",
+                            eswitch_inline_mode_name(mnl_attr_get_u8(
+                                    tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
+       }
        if (tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]) {
-               bool encap_mode = !!mnl_attr_get_u8(tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]);
-
-               pr_out_str(dl, "encap", encap_mode ? "enable" : "disable");
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "encap-mode", "encap-mode %s",
+                            eswitch_encap_mode_name(mnl_attr_get_u8(
+                                   tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE])));
        }
 
        pr_out_handle_end(dl);
@@ -2355,8 +2360,10 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
             !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
                return;
 
-       pr_out_str(dl, "cmode",
-                  param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "cmode", "cmode %s",
+                    param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
+
        val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
 
        conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
@@ -2372,9 +2379,10 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
-                       pr_out_uint(dl, "value", mnl_attr_get_u8(val_attr));
+                       print_uint(PRINT_ANY, "value", " value %u",
+                                  mnl_attr_get_u8(val_attr));
                }
                break;
        case MNL_TYPE_U16:
@@ -2386,9 +2394,10 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
-                       pr_out_uint(dl, "value", mnl_attr_get_u16(val_attr));
+                       print_uint(PRINT_ANY, "value", " value %u",
+                                  mnl_attr_get_u16(val_attr));
                }
                break;
        case MNL_TYPE_U32:
@@ -2400,16 +2409,18 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
-                       pr_out_uint(dl, "value", mnl_attr_get_u32(val_attr));
+                       print_uint(PRINT_ANY, "value", " value %u",
+                                  mnl_attr_get_u32(val_attr));
                }
                break;
        case MNL_TYPE_STRING:
-               pr_out_str(dl, "value", mnl_attr_get_str(val_attr));
+               print_string(PRINT_ANY, "value", " value %s",
+                            mnl_attr_get_str(val_attr));
                break;
        case MNL_TYPE_FLAG:
-               pr_out_bool(dl, "value", val_attr ? true : false);
+               print_bool(PRINT_ANY, "value", " value %s", val_attr);
                break;
        }
 }
@@ -2438,12 +2449,12 @@ static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array)
        nla_type = mnl_attr_get_u8(nla_param[DEVLINK_ATTR_PARAM_TYPE]);
 
        nla_name = mnl_attr_get_str(nla_param[DEVLINK_ATTR_PARAM_NAME]);
-       pr_out_str(dl, "name", nla_name);
-
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s ", nla_name);
        if (!nla_param[DEVLINK_ATTR_PARAM_GENERIC])
-               pr_out_str(dl, "type", "driver-specific");
+               print_string(PRINT_ANY, "type", "type %s", "driver-specific");
        else
-               pr_out_str(dl, "type", "generic");
+               print_string(PRINT_ANY, "type", "type %s", "generic");
 
        pr_out_array_start(dl, "values");
        mnl_attr_for_each_nested(param_value_attr,
@@ -2720,7 +2731,8 @@ static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
 
        if (reload_failed) {
                __pr_out_handle_start(dl, tb, true, false);
-               pr_out_bool(dl, "reload_failed", true);
+               check_indent_newline(dl);
+               print_bool(PRINT_ANY, "reload_failed", "reload_failed %s", true);
                pr_out_handle_end(dl);
        } else {
                pr_out_handle(dl, tb);
@@ -2807,7 +2819,8 @@ static void pr_out_versions_single(struct dl *dl, const struct nlmsghdr *nlh,
                ver_name = mnl_attr_get_str(tb[DEVLINK_ATTR_INFO_VERSION_NAME]);
                ver_value = mnl_attr_get_str(tb[DEVLINK_ATTR_INFO_VERSION_VALUE]);
 
-               pr_out_str(dl, ver_name, ver_value);
+               check_indent_newline(dl);
+               print_string_name_value(ver_name, ver_value);
                if (!dl->json_output)
                        __pr_out_newline();
        }
@@ -2827,7 +2840,9 @@ static void pr_out_info(struct dl *dl, const struct nlmsghdr *nlh,
 
                if (!dl->json_output)
                        __pr_out_newline();
-               pr_out_str(dl, "driver", mnl_attr_get_str(nla_drv));
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "driver", "driver %s",
+                            mnl_attr_get_str(nla_drv));
        }
 
        if (tb[DEVLINK_ATTR_INFO_SERIAL_NUMBER]) {
@@ -2835,7 +2850,9 @@ static void pr_out_info(struct dl *dl, const struct nlmsghdr *nlh,
 
                if (!dl->json_output)
                        __pr_out_newline();
-               pr_out_str(dl, "serial_number", mnl_attr_get_str(nla_sn));
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "serial_number", "serial_number %s",
+                            mnl_attr_get_str(nla_sn));
        }
        __pr_out_indent_dec();
 
@@ -3101,11 +3118,13 @@ static int cmd_dev_flash(struct dl *dl)
                /* In child, just execute the flash and pass returned
                 * value through pipe once it is done.
                 */
+               int cc;
+
                close(pipe_r);
                err = _mnlg_socket_send(dl->nlg, nlh);
-               write(pipe_w, &err, sizeof(err));
+               cc = write(pipe_w, &err, sizeof(err));
                close(pipe_w);
-               exit(0);
+               exit(cc != sizeof(err));
        }
        close(pipe_w);
 
@@ -3183,6 +3202,8 @@ static const char *port_flavour_name(uint16_t flavour)
                return "pcipf";
        case DEVLINK_PORT_FLAVOUR_PCI_VF:
                return "pcivf";
+       case DEVLINK_PORT_FLAVOUR_VIRTUAL:
+               return "virtual";
        default:
                return "<unknown flavour>";
        }
@@ -3194,11 +3215,11 @@ static void pr_out_port_pfvf_num(struct dl *dl, struct nlattr **tb)
 
        if (tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]) {
                fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]);
-               pr_out_uint(dl, "pfnum", fn_num);
+               print_uint(PRINT_ANY, "pfnum", " pfnum %u", fn_num);
        }
        if (tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]) {
                fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]);
-               pr_out_uint(dl, "vfnum", fn_num);
+               print_uint(PRINT_ANY, "vfnum", " vfnum %u", fn_num);
        }
 }
 
@@ -3208,29 +3229,34 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
        struct nlattr *dpt_attr = tb[DEVLINK_ATTR_PORT_DESIRED_TYPE];
 
        pr_out_port_handle_start(dl, tb, false);
+       check_indent_newline(dl);
        if (pt_attr) {
                uint16_t port_type = mnl_attr_get_u16(pt_attr);
 
-               pr_out_str(dl, "type", port_type_name(port_type));
+               print_string(PRINT_ANY, "type", "type %s",
+                            port_type_name(port_type));
                if (dpt_attr) {
                        uint16_t des_port_type = mnl_attr_get_u16(dpt_attr);
 
                        if (port_type != des_port_type)
-                               pr_out_str(dl, "des_type",
-                                          port_type_name(des_port_type));
+                               print_string(PRINT_ANY, "des_type", " des_type %s",
+                                            port_type_name(des_port_type));
                }
        }
-       if (tb[DEVLINK_ATTR_PORT_NETDEV_NAME])
-               pr_out_str(dl, "netdev",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]));
-       if (tb[DEVLINK_ATTR_PORT_IBDEV_NAME])
-               pr_out_str(dl, "ibdev",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_IBDEV_NAME]));
+       if (tb[DEVLINK_ATTR_PORT_NETDEV_NAME]) {
+               print_string(PRINT_ANY, "netdev", " netdev %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]));
+       }
+       if (tb[DEVLINK_ATTR_PORT_IBDEV_NAME]) {
+               print_string(PRINT_ANY, "ibdev", " ibdev %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_IBDEV_NAME]));
+               }
        if (tb[DEVLINK_ATTR_PORT_FLAVOUR]) {
                uint16_t port_flavour =
                                mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_FLAVOUR]);
 
-               pr_out_str(dl, "flavour", port_flavour_name(port_flavour));
+               print_string(PRINT_ANY, "flavour", " flavour %s",
+                            port_flavour_name(port_flavour));
 
                switch (port_flavour) {
                case DEVLINK_PORT_FLAVOUR_PCI_PF:
@@ -3245,11 +3271,11 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
                uint32_t port_number;
 
                port_number = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_NUMBER]);
-               pr_out_uint(dl, "port", port_number);
+               print_uint(PRINT_ANY, "port", " port %u", port_number);
        }
        if (tb[DEVLINK_ATTR_PORT_SPLIT_GROUP])
-               pr_out_uint(dl, "split_group",
-                           mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_SPLIT_GROUP]));
+               print_uint(PRINT_ANY, "split_group", " split_group %u",
+                          mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_SPLIT_GROUP]));
        pr_out_port_handle_end(dl);
 }
 
@@ -3381,18 +3407,19 @@ static void cmd_sb_help(void)
 static void pr_out_sb(struct dl *dl, struct nlattr **tb)
 {
        pr_out_handle_start_arr(dl, tb);
-       pr_out_uint(dl, "sb",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-       pr_out_uint(dl, "size",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_SIZE]));
-       pr_out_uint(dl, "ing_pools",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_POOL_COUNT]));
-       pr_out_uint(dl, "eg_pools",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_POOL_COUNT]));
-       pr_out_uint(dl, "ing_tcs",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_TC_COUNT]));
-       pr_out_uint(dl, "eg_tcs",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_TC_COUNT]));
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "sb", "sb %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
+       print_uint(PRINT_ANY, "size", " size %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_SIZE]));
+       print_uint(PRINT_ANY, "ing_pools", " ing_pools %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_POOL_COUNT]));
+       print_uint(PRINT_ANY, "eg_pools", " eg_pools %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_POOL_COUNT]));
+       print_uint(PRINT_ANY, "ing_tcs", " ing_tcs %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_TC_COUNT]));
+       print_uint(PRINT_ANY, "eg_tcs", " eg_tcs %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_TC_COUNT]));
        pr_out_handle_end(dl);
 }
 
@@ -3458,19 +3485,20 @@ static const char *threshold_type_name(uint8_t type)
 static void pr_out_sb_pool(struct dl *dl, struct nlattr **tb)
 {
        pr_out_handle_start_arr(dl, tb);
-       pr_out_uint(dl, "sb",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-       pr_out_uint(dl, "pool",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-       pr_out_str(dl, "type",
-                  pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
-       pr_out_uint(dl, "size",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_SIZE]));
-       pr_out_str(dl, "thtype",
-                  threshold_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE])));
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "sb", "sb %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
+       print_uint(PRINT_ANY, "pool", " pool %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
+       print_string(PRINT_ANY, "type", " type %s",
+                    pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
+       print_uint(PRINT_ANY, "size", " size %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_SIZE]));
+       print_string(PRINT_ANY, "thtype", " thtype %s",
+                    threshold_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE])));
        if (tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE])
-               pr_out_uint(dl, "cell_size",
-                           mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE]));
+               print_uint(PRINT_ANY, "cell_size", " cell size %u",
+                          mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE]));
        pr_out_handle_end(dl);
 }
 
@@ -3550,12 +3578,13 @@ static int cmd_sb_pool(struct dl *dl)
 static void pr_out_sb_port_pool(struct dl *dl, struct nlattr **tb)
 {
        pr_out_port_handle_start_arr(dl, tb, true);
-       pr_out_uint(dl, "sb",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-       pr_out_uint(dl, "pool",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-       pr_out_uint(dl, "threshold",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "sb", "sb %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
+       print_uint(PRINT_ANY, "pool", " pool %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
+       print_uint(PRINT_ANY, "threshold", " threshold %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
        pr_out_port_handle_end(dl);
 }
 
@@ -3648,16 +3677,17 @@ static int cmd_sb_port(struct dl *dl)
 static void pr_out_sb_tc_bind(struct dl *dl, struct nlattr **tb)
 {
        pr_out_port_handle_start_arr(dl, tb, true);
-       pr_out_uint(dl, "sb",
-              mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-       pr_out_uint(dl, "tc",
-              mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_TC_INDEX]));
-       pr_out_str(dl, "type",
-              pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
-       pr_out_uint(dl, "pool",
-              mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-       pr_out_uint(dl, "threshold",
-              mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "sb", "sb %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
+       print_uint(PRINT_ANY, "tc", " tc %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_TC_INDEX]));
+       print_string(PRINT_ANY, "type", " type %s",
+                    pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
+       print_uint(PRINT_ANY, "pool", " pool %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
+       print_uint(PRINT_ANY, "threshold", " threshold %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
        pr_out_port_handle_end(dl);
 }
 
@@ -4154,6 +4184,7 @@ static const char *cmd_name(uint8_t cmd)
        case DEVLINK_CMD_FLASH_UPDATE: return "begin";
        case DEVLINK_CMD_FLASH_UPDATE_END: return "end";
        case DEVLINK_CMD_FLASH_UPDATE_STATUS: return "status";
+       case DEVLINK_CMD_HEALTH_REPORTER_RECOVER: return "status";
        case DEVLINK_CMD_TRAP_GET: return "get";
        case DEVLINK_CMD_TRAP_SET: return "set";
        case DEVLINK_CMD_TRAP_NEW: return "new";
@@ -4162,6 +4193,10 @@ static const char *cmd_name(uint8_t cmd)
        case DEVLINK_CMD_TRAP_GROUP_SET: return "set";
        case DEVLINK_CMD_TRAP_GROUP_NEW: return "new";
        case DEVLINK_CMD_TRAP_GROUP_DEL: return "del";
+       case DEVLINK_CMD_TRAP_POLICER_GET: return "get";
+       case DEVLINK_CMD_TRAP_POLICER_SET: return "set";
+       case DEVLINK_CMD_TRAP_POLICER_NEW: return "new";
+       case DEVLINK_CMD_TRAP_POLICER_DEL: return "del";
        default: return "<unknown cmd>";
        }
 }
@@ -4194,6 +4229,8 @@ static const char *cmd_obj(uint8_t cmd)
        case DEVLINK_CMD_FLASH_UPDATE_END:
        case DEVLINK_CMD_FLASH_UPDATE_STATUS:
                return "flash";
+       case DEVLINK_CMD_HEALTH_REPORTER_RECOVER:
+               return "health";
        case DEVLINK_CMD_TRAP_GET:
        case DEVLINK_CMD_TRAP_SET:
        case DEVLINK_CMD_TRAP_NEW:
@@ -4204,6 +4241,11 @@ static const char *cmd_obj(uint8_t cmd)
        case DEVLINK_CMD_TRAP_GROUP_NEW:
        case DEVLINK_CMD_TRAP_GROUP_DEL:
                return "trap-group";
+       case DEVLINK_CMD_TRAP_POLICER_GET:
+       case DEVLINK_CMD_TRAP_POLICER_SET:
+       case DEVLINK_CMD_TRAP_POLICER_NEW:
+       case DEVLINK_CMD_TRAP_POLICER_DEL:
+               return "trap-policer";
        default: return "<unknown obj>";
        }
 }
@@ -4232,13 +4274,16 @@ static void pr_out_flash_update(struct dl *dl, struct nlattr **tb)
 {
        __pr_out_handle_start(dl, tb, true, false);
 
-       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG])
-               pr_out_str(dl, "msg",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]));
-
-       if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT])
-               pr_out_str(dl, "component",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]));
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "msg", "msg %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]));
+       }
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "component", "component %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]));
+       }
 
        if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE])
                pr_out_u64(dl, "done",
@@ -4252,8 +4297,10 @@ static void pr_out_flash_update(struct dl *dl, struct nlattr **tb)
 }
 
 static void pr_out_region(struct dl *dl, struct nlattr **tb);
+static void pr_out_health(struct dl *dl, struct nlattr **tb_health);
 static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array);
 static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array);
+static void pr_out_trap_policer(struct dl *dl, struct nlattr **tb, bool array);
 
 static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
 {
@@ -4318,6 +4365,14 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                pr_out_mon_header(genl->cmd);
                pr_out_flash_update(dl, tb);
                break;
+       case DEVLINK_CMD_HEALTH_REPORTER_RECOVER:
+               mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+               if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+                   !tb[DEVLINK_ATTR_HEALTH_REPORTER])
+                       return MNL_CB_ERROR;
+               pr_out_mon_header(genl->cmd);
+               pr_out_health(dl, tb);
+               break;
        case DEVLINK_CMD_TRAP_GET: /* fall through */
        case DEVLINK_CMD_TRAP_SET: /* fall through */
        case DEVLINK_CMD_TRAP_NEW: /* fall through */
@@ -4346,6 +4401,19 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                pr_out_mon_header(genl->cmd);
                pr_out_trap_group(dl, tb, false);
                break;
+       case DEVLINK_CMD_TRAP_POLICER_GET: /* fall through */
+       case DEVLINK_CMD_TRAP_POLICER_SET: /* fall through */
+       case DEVLINK_CMD_TRAP_POLICER_NEW: /* fall through */
+       case DEVLINK_CMD_TRAP_POLICER_DEL: /* fall through */
+               mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+               if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+                   !tb[DEVLINK_ATTR_TRAP_POLICER_ID] ||
+                   !tb[DEVLINK_ATTR_TRAP_POLICER_RATE] ||
+                   !tb[DEVLINK_ATTR_TRAP_POLICER_BURST])
+                       return MNL_CB_ERROR;
+               pr_out_mon_header(genl->cmd);
+               pr_out_trap_policer(dl, tb, false);
+               break;
        }
        return MNL_CB_OK;
 }
@@ -4360,8 +4428,10 @@ static int cmd_mon_show(struct dl *dl)
                if (strcmp(cur_obj, "all") != 0 &&
                    strcmp(cur_obj, "dev") != 0 &&
                    strcmp(cur_obj, "port") != 0 &&
+                   strcmp(cur_obj, "health") != 0 &&
                    strcmp(cur_obj, "trap") != 0 &&
-                   strcmp(cur_obj, "trap-group") != 0) {
+                   strcmp(cur_obj, "trap-group") != 0 &&
+                   strcmp(cur_obj, "trap-policer") != 0) {
                        pr_err("Unknown object \"%s\"\n", cur_obj);
                        return -EINVAL;
                }
@@ -4378,7 +4448,7 @@ static int cmd_mon_show(struct dl *dl)
 static void cmd_mon_help(void)
 {
        pr_err("Usage: devlink monitor [ all | OBJECT-LIST ]\n"
-              "where  OBJECT-LIST := { dev | port | trap | trap-group }\n");
+              "where  OBJECT-LIST := { dev | port | health | trap | trap-group | trap-policer }\n");
 }
 
 static int cmd_mon(struct dl *dl)
@@ -4705,13 +4775,15 @@ static void pr_out_dpipe_fields(struct dpipe_ctx *ctx,
        for (i = 0; i < field_count; i++) {
                field = &fields[i];
                pr_out_entry_start(ctx->dl);
-               pr_out_str(ctx->dl, "name", field->name);
+               check_indent_newline(ctx->dl);
+               print_string(PRINT_ANY, "name", "name %s", field->name);
                if (ctx->dl->verbose)
-                       pr_out_uint(ctx->dl, "id", field->id);
-               pr_out_uint(ctx->dl, "bitwidth", field->bitwidth);
-               if (field->mapping_type)
-                       pr_out_str(ctx->dl, "mapping_type",
-                                  dpipe_field_mapping_e2s(field->mapping_type));
+                       print_uint(PRINT_ANY, "id", " id %u", field->id);
+               print_uint(PRINT_ANY, "bitwidth", " bitwidth %u", field->bitwidth);
+               if (field->mapping_type) {
+                       print_string(PRINT_ANY, "mapping_type", " mapping_type %s",
+                                    dpipe_field_mapping_e2s(field->mapping_type));
+               }
                pr_out_entry_end(ctx->dl);
        }
 }
@@ -4721,11 +4793,11 @@ pr_out_dpipe_header(struct dpipe_ctx *ctx, struct nlattr **tb,
                    struct dpipe_header *header, bool global)
 {
        pr_out_handle_start_arr(ctx->dl, tb);
-       pr_out_str(ctx->dl, "name", header->name);
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "name", "name %s", header->name);
        if (ctx->dl->verbose) {
-               pr_out_uint(ctx->dl, "id", header->id);
-               pr_out_str(ctx->dl, "global",
-                          global ? "true" : "false");
+               print_uint(PRINT_ANY, "id", " id %u", header->id);
+               print_bool(PRINT_ANY, "global", " global %s", global);
        }
        pr_out_array_start(ctx->dl, "field");
        pr_out_dpipe_fields(ctx, header->fields,
@@ -4949,20 +5021,21 @@ static void pr_out_dpipe_action(struct dpipe_action *action,
        struct dpipe_op_info *op_info = &action->info;
        const char *mapping;
 
-       pr_out_str(ctx->dl, "type",
-                  dpipe_action_type_e2s(action->type));
-       pr_out_str(ctx->dl, "header",
-                  dpipe_header_id2s(ctx, op_info->header_id,
-                                    op_info->header_global));
-       pr_out_str(ctx->dl, "field",
-                  dpipe_field_id2s(ctx, op_info->header_id,
-                                   op_info->field_id,
-                                   op_info->header_global));
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "type", "type %s",
+                    dpipe_action_type_e2s(action->type));
+       print_string(PRINT_ANY, "header", " header %s",
+                    dpipe_header_id2s(ctx, op_info->header_id,
+                                      op_info->header_global));
+       print_string(PRINT_ANY, "field", " field %s",
+                    dpipe_field_id2s(ctx, op_info->header_id,
+                                     op_info->field_id,
+                                     op_info->header_global));
        mapping = dpipe_mapping_get(ctx, op_info->header_id,
                                    op_info->field_id,
                                    op_info->header_global);
        if (mapping)
-               pr_out_str(ctx->dl, "mapping", mapping);
+               print_string(PRINT_ANY, "mapping", " mapping %s", mapping);
 }
 
 static int dpipe_action_parse(struct dpipe_action *action, struct nlattr *nl)
@@ -5031,20 +5104,21 @@ static void pr_out_dpipe_match(struct dpipe_match *match,
        struct dpipe_op_info *op_info = &match->info;
        const char *mapping;
 
-       pr_out_str(ctx->dl, "type",
-                  dpipe_match_type_e2s(match->type));
-       pr_out_str(ctx->dl, "header",
-                  dpipe_header_id2s(ctx, op_info->header_id,
-                                    op_info->header_global));
-       pr_out_str(ctx->dl, "field",
-                  dpipe_field_id2s(ctx, op_info->header_id,
-                                   op_info->field_id,
-                                   op_info->header_global));
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "type", "type %s",
+                    dpipe_match_type_e2s(match->type));
+       print_string(PRINT_ANY, "header", " header %s",
+                    dpipe_header_id2s(ctx, op_info->header_id,
+                                      op_info->header_global));
+       print_string(PRINT_ANY, "field", " field %s",
+                    dpipe_field_id2s(ctx, op_info->header_id,
+                                     op_info->field_id,
+                                     op_info->header_global));
        mapping = dpipe_mapping_get(ctx, op_info->header_id,
                                    op_info->field_id,
                                    op_info->header_global);
        if (mapping)
-               pr_out_str(ctx->dl, "mapping", mapping);
+               print_string(PRINT_ANY, "mapping", " mapping %s", mapping);
 }
 
 static int dpipe_match_parse(struct dpipe_match *match,
@@ -5149,7 +5223,8 @@ resource_path_print(struct dl *dl, struct resources *resources,
                path -= strlen(del);
                memcpy(path, del, strlen(del));
        }
-       pr_out_str(dl, "resource_path", path);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "resource_path", "resource_path %s", path);
        free(path);
 }
 
@@ -5194,16 +5269,17 @@ static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl)
        if (!ctx->print_tables)
                return 0;
 
-       pr_out_str(ctx->dl, "name", table->name);
-       pr_out_uint(ctx->dl, "size", size);
-       pr_out_str(ctx->dl, "counters_enabled",
-                  counters_enabled ? "true" : "false");
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "name", "name %s", table->name);
+       print_uint(PRINT_ANY, "size", " size %u", size);
+       print_bool(PRINT_ANY, "counters_enabled", " counters_enabled %s", counters_enabled);
 
        if (resource_valid) {
                resource_units = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS]);
                resource_path_print(ctx->dl, ctx->resources,
                                    table->resource_id);
-               pr_out_uint(ctx->dl, "resource_units", resource_units);
+               print_uint(PRINT_ANY, "resource_units", " resource_units %u",
+                          resource_units);
        }
 
        pr_out_array_start(ctx->dl, "match");
@@ -5374,7 +5450,8 @@ static void dpipe_field_printer_ipv4_addr(struct dpipe_ctx *ctx,
        struct in_addr ip_addr;
 
        ip_addr.s_addr = htonl(*(uint32_t *)value);
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type), inet_ntoa(ip_addr));
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type), inet_ntoa(ip_addr));
 }
 
 static void
@@ -5382,8 +5459,9 @@ dpipe_field_printer_ethernet_addr(struct dpipe_ctx *ctx,
                                  enum dpipe_value_type type,
                                  void *value)
 {
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type),
-                  ether_ntoa((struct ether_addr *)value));
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type),
+                               ether_ntoa((struct ether_addr *)value));
 }
 
 static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx,
@@ -5393,7 +5471,8 @@ static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx,
        char str[INET6_ADDRSTRLEN];
 
        inet_ntop(AF_INET6, value, str, INET6_ADDRSTRLEN);
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type), str);
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type), str);
 }
 
 static struct dpipe_field_printer dpipe_field_printers_ipv4[] = {
@@ -5483,7 +5562,8 @@ static void __pr_out_entry_value(struct dpipe_ctx *ctx,
        if (value_len == sizeof(uint32_t)) {
                uint32_t *value_32 = value;
 
-               pr_out_uint(ctx->dl, dpipe_value_type_e2s(type), *value_32);
+               check_indent_newline(ctx->dl);
+               print_uint_name_value(dpipe_value_type_e2s(type), *value_32);
        }
 }
 
@@ -5504,7 +5584,8 @@ static void pr_out_dpipe_entry_value(struct dpipe_ctx *ctx,
 
        if (mapping) {
                value_mapping = mnl_attr_get_u32(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MAPPING]);
-               pr_out_uint(ctx->dl, "mapping_value", value_mapping);
+               check_indent_newline(ctx->dl);
+               print_uint(PRINT_ANY, "mapping_value", "mapping_value %u", value_mapping);
        }
 
        if (mask) {
@@ -5621,12 +5702,13 @@ static int dpipe_entry_show(struct dpipe_ctx *ctx, struct nlattr *nl)
                return -EINVAL;
        }
 
+       check_indent_newline(ctx->dl);
        entry_index = mnl_attr_get_u32(nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_INDEX]);
-       pr_out_uint(ctx->dl, "index", entry_index);
+       print_uint(PRINT_ANY, "index", "index %u", entry_index);
 
        if (nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_COUNTER]) {
                counter = mnl_attr_get_u64(nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_COUNTER]);
-               pr_out_uint(ctx->dl, "counter", counter);
+               print_uint(PRINT_ANY, "counter", " counter %u", counter);
        }
 
        pr_out_array_start(ctx->dl, "match_value");
@@ -5872,20 +5954,24 @@ static void resource_show(struct resource *resource,
        struct dl *dl = ctx->dl;
        bool array = false;
 
-       pr_out_str(dl, "name", resource->name);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s", resource->name);
        if (dl->verbose)
                resource_path_print(dl, ctx->resources, resource->id);
        pr_out_u64(dl, "size", resource->size);
        if (resource->size != resource->size_new)
                pr_out_u64(dl, "size_new", resource->size_new);
        if (resource->occ_valid)
-               pr_out_uint(dl, "occ", resource->size_occ);
-       pr_out_str(dl, "unit", resource_unit_str_get(resource->unit));
+               print_uint(PRINT_ANY, "occ", " occ %u",  resource->size_occ);
+       print_string(PRINT_ANY, "unit", " unit %s",
+                    resource_unit_str_get(resource->unit));
 
        if (resource->size_min != resource->size_max) {
-               pr_out_uint(dl, "size_min", resource->size_min);
+               print_uint(PRINT_ANY, "size_min", " size_min %u",
+                          resource->size_min);
                pr_out_u64(dl, "size_max", resource->size_max);
-               pr_out_uint(dl, "size_gran", resource->size_gran);
+               print_uint(PRINT_ANY, "size_gran", " size_gran %u",
+                          resource->size_gran);
        }
 
        list_for_each_entry(table, &ctx->tables->table_list, list)
@@ -5896,14 +5982,17 @@ static void resource_show(struct resource *resource,
        if (array)
                pr_out_array_start(dl, "dpipe_tables");
        else
-               pr_out_str(dl, "dpipe_tables", "none");
+               print_string(PRINT_ANY, "dpipe_tables", " dpipe_tables none",
+                            "none");
 
        list_for_each_entry(table, &ctx->tables->table_list, list) {
                if (table->resource_id != resource->id ||
                    !table->resource_valid)
                        continue;
                pr_out_entry_start(dl);
-               pr_out_str(dl, "table_name", table->name);
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "table_name", "table_name %s",
+                            table->name);
                pr_out_entry_end(dl);
        }
        if (array)
@@ -5912,9 +6001,11 @@ static void resource_show(struct resource *resource,
        if (list_empty(&resource->resource_list))
                return;
 
-       if (ctx->pending_change)
-               pr_out_str(dl, "size_valid", resource->size_valid ?
-                          "true" : "false");
+       if (ctx->pending_change) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "size_valid", "size_valid %s",
+                            resource->size_valid ? "true" : "false");
+       }
        pr_out_array_start(dl, "resources");
        list_for_each_entry(child_resource, &resource->resource_list, list) {
                pr_out_entry_start(dl);
@@ -6418,24 +6509,25 @@ static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
        uint8_t *data;
        uint32_t len;
 
+       check_indent_newline(dl);
        switch (type) {
        case MNL_TYPE_FLAG:
-               pr_out_bool_value(dl, mnl_attr_get_u8(nl_data));
+               print_bool(PRINT_ANY, NULL, "%s", mnl_attr_get_u8(nl_data));
                break;
        case MNL_TYPE_U8:
-               pr_out_uint_value(dl, mnl_attr_get_u8(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u8(nl_data));
                break;
        case MNL_TYPE_U16:
-               pr_out_uint_value(dl, mnl_attr_get_u16(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u16(nl_data));
                break;
        case MNL_TYPE_U32:
-               pr_out_uint_value(dl, mnl_attr_get_u32(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u32(nl_data));
                break;
        case MNL_TYPE_U64:
-               pr_out_uint64_value(dl, mnl_attr_get_u64(nl_data));
+               print_u64(PRINT_ANY, NULL, "%"PRIu64, mnl_attr_get_u64(nl_data));
                break;
        case MNL_TYPE_NUL_STRING:
-               pr_out_str_value(dl, mnl_attr_get_str(nl_data));
+               print_string(PRINT_ANY, NULL, "%s", mnl_attr_get_str(nl_data));
                break;
        case MNL_TYPE_BINARY:
                len = mnl_attr_get_payload_len(nl_data);
@@ -6733,8 +6825,9 @@ static void pr_out_dump_reporter_format_logtime(struct dl *dl, const struct nlat
 out:
        strftime(dump_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", info);
        strftime(dump_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", info);
-       pr_out_str(dl, "last_dump_date", dump_date);
-       pr_out_str(dl, "last_dump_time", dump_time);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "last_dump_date", "last_dump_date %s", dump_date);
+       print_string(PRINT_ANY, "last_dump_time", " last_dump_time %s", dump_time);
 }
 
 static void pr_out_dump_report_timestamp(struct dl *dl, const struct nlattr *attr)
@@ -6752,8 +6845,9 @@ static void pr_out_dump_report_timestamp(struct dl *dl, const struct nlattr *att
        strftime(dump_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", tm);
        strftime(dump_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", tm);
 
-       pr_out_str(dl, "last_dump_date", dump_date);
-       pr_out_str(dl, "last_dump_time", dump_time);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "last_dump_date", "last_dump_date %s", dump_date);
+       print_string(PRINT_ANY, "last_dump_time", " last_dump_time %s", dump_time);
 }
 
 static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
@@ -6775,14 +6869,16 @@ static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
 
        pr_out_handle_start_arr(dl, tb_health);
 
-       pr_out_str(dl, "reporter",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_HEALTH_REPORTER_NAME]));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "reporter", "reporter %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_HEALTH_REPORTER_NAME]));
        if (!dl->json_output) {
                __pr_out_newline();
                __pr_out_indent_inc();
        }
        state = mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_STATE]);
-       pr_out_str(dl, "state", health_state_name(state));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "state", "state %s", health_state_name(state));
        pr_out_u64(dl, "error",
                   mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT]));
        pr_out_u64(dl, "recover",
@@ -6795,8 +6891,8 @@ static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
                pr_out_u64(dl, "grace_period",
                           mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD]));
        if (tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])
-               pr_out_bool(dl, "auto_recover",
-                           mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]));
+               print_bool(PRINT_ANY, "auto_recover", " auto_recover %s",
+                          mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]));
 
        __pr_out_indent_dec();
        pr_out_handle_end(dl);
@@ -6850,7 +6946,9 @@ static void cmd_health_help(void)
        pr_err("       devlink health diagnose DEV reporter REPORTER_NAME\n");
        pr_err("       devlink health dump show DEV reporter REPORTER_NAME\n");
        pr_err("       devlink health dump clear DEV reporter REPORTER_NAME\n");
-       pr_err("       devlink health set DEV reporter REPORTER_NAME { grace_period | auto_recover } { msec | boolean }\n");
+       pr_err("       devlink health set DEV reporter REPORTER_NAME\n");
+       pr_err("                          [ grace_period MSEC ]\n");
+       pr_err("                          [ auto_recover { true | false } ]\n");
 }
 
 static int cmd_health(struct dl *dl)
@@ -6914,6 +7012,8 @@ static const char *trap_metadata_name(const struct nlattr *attr)
        switch (attr->nla_type) {
        case DEVLINK_ATTR_TRAP_METADATA_TYPE_IN_PORT:
                return "input_port";
+       case DEVLINK_ATTR_TRAP_METADATA_TYPE_FA_COOKIE:
+               return "flow_action_cookie";
        default:
                return "<unknown metadata type>";
        }
@@ -6923,8 +7023,11 @@ static void pr_out_trap_metadata(struct dl *dl, struct nlattr *attr)
        struct nlattr *attr_metadata;
 
        pr_out_array_start(dl, "metadata");
-       mnl_attr_for_each_nested(attr_metadata, attr)
-               pr_out_str_value(dl, trap_metadata_name(attr_metadata));
+       mnl_attr_for_each_nested(attr_metadata, attr) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, NULL, "%s",
+                            trap_metadata_name(attr_metadata));
+       }
        pr_out_array_end(dl);
 }
 
@@ -6938,12 +7041,14 @@ static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array)
        else
                __pr_out_handle_start(dl, tb, true, false);
 
-       pr_out_str(dl, "name", mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME]));
-       pr_out_str(dl, "type", trap_type_name(type));
-       pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
-       pr_out_str(dl, "action", trap_action_name(action));
-       pr_out_str(dl, "group",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME]));
+       print_string(PRINT_ANY, "type", " type %s", trap_type_name(type));
+       print_bool(PRINT_ANY, "generic", " generic %s", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
+       print_string(PRINT_ANY, "action", " action %s", trap_action_name(action));
+       print_string(PRINT_ANY, "group", " group %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
        if (dl->verbose)
                pr_out_trap_metadata(dl, tb[DEVLINK_ATTR_TRAP_METADATA]);
        pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
@@ -6974,7 +7079,10 @@ static void cmd_trap_help(void)
        pr_err("Usage: devlink trap set DEV trap TRAP [ action { trap | drop } ]\n");
        pr_err("       devlink trap show [ DEV trap TRAP ]\n");
        pr_err("       devlink trap group set DEV group GROUP [ action { trap | drop } ]\n");
+       pr_err("                              [ policer POLICER ] [ nopolicer ]\n");
        pr_err("       devlink trap group show [ DEV group GROUP ]\n");
+       pr_err("       devlink trap policer set DEV policer POLICER [ rate RATE ] [ burst BURST ]\n");
+       pr_err("       devlink trap policer show DEV policer POLICER\n");
 }
 
 static int cmd_trap_show(struct dl *dl)
@@ -7025,9 +7133,13 @@ static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array)
        else
                __pr_out_handle_start(dl, tb, true, false);
 
-       pr_out_str(dl, "name",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
-       pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
+       print_bool(PRINT_ANY, "generic", " generic %s", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
+       if (tb[DEVLINK_ATTR_TRAP_POLICER_ID])
+               print_uint(PRINT_ANY, "policer", " policer %u",
+                          mnl_attr_get_u32(tb[DEVLINK_ATTR_TRAP_POLICER_ID]));
        pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
        pr_out_handle_end(dl);
 }
@@ -7084,7 +7196,7 @@ static int cmd_trap_group_set(struct dl *dl)
 
        err = dl_argv_parse_put(nlh, dl,
                                DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME,
-                               DL_OPT_TRAP_ACTION);
+                               DL_OPT_TRAP_ACTION | DL_OPT_TRAP_POLICER_ID);
        if (err)
                return err;
 
@@ -7108,6 +7220,104 @@ static int cmd_trap_group(struct dl *dl)
        return -ENOENT;
 }
 
+static void pr_out_trap_policer(struct dl *dl, struct nlattr **tb, bool array)
+{
+       if (array)
+               pr_out_handle_start_arr(dl, tb);
+       else
+               __pr_out_handle_start(dl, tb, true, false);
+
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "policer", "policer %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_TRAP_POLICER_ID]));
+       print_u64(PRINT_ANY, "rate", " rate %llu",
+                  mnl_attr_get_u64(tb[DEVLINK_ATTR_TRAP_POLICER_RATE]));
+       print_u64(PRINT_ANY, "burst", " burst %llu",
+                  mnl_attr_get_u64(tb[DEVLINK_ATTR_TRAP_POLICER_BURST]));
+       if (tb[DEVLINK_ATTR_STATS])
+               pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
+       pr_out_handle_end(dl);
+}
+
+static int cmd_trap_policer_show_cb(const struct nlmsghdr *nlh, void *data)
+{
+       struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+       struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+       struct dl *dl = data;
+
+       mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+       if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+           !tb[DEVLINK_ATTR_TRAP_POLICER_ID] ||
+           !tb[DEVLINK_ATTR_TRAP_POLICER_RATE] ||
+           !tb[DEVLINK_ATTR_TRAP_POLICER_BURST])
+               return MNL_CB_ERROR;
+
+       pr_out_trap_policer(dl, tb, true);
+
+       return MNL_CB_OK;
+}
+
+static int cmd_trap_policer_show(struct dl *dl)
+{
+       uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
+       struct nlmsghdr *nlh;
+       int err;
+
+       if (dl_argc(dl) == 0)
+               flags |= NLM_F_DUMP;
+
+       nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_POLICER_GET, flags);
+
+       if (dl_argc(dl) > 0) {
+               err = dl_argv_parse_put(nlh, dl,
+                                       DL_OPT_HANDLE | DL_OPT_TRAP_POLICER_ID,
+                                       0);
+               if (err)
+                       return err;
+       }
+
+       pr_out_section_start(dl, "trap_policer");
+       err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_policer_show_cb, dl);
+       pr_out_section_end(dl);
+
+       return err;
+}
+
+static int cmd_trap_policer_set(struct dl *dl)
+{
+       struct nlmsghdr *nlh;
+       int err;
+
+       nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_POLICER_SET,
+                              NLM_F_REQUEST | NLM_F_ACK);
+
+       err = dl_argv_parse_put(nlh, dl,
+                               DL_OPT_HANDLE | DL_OPT_TRAP_POLICER_ID,
+                               DL_OPT_TRAP_POLICER_RATE |
+                               DL_OPT_TRAP_POLICER_BURST);
+       if (err)
+               return err;
+
+       return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+}
+
+static int cmd_trap_policer(struct dl *dl)
+{
+       if (dl_argv_match(dl, "help")) {
+               cmd_trap_help();
+               return 0;
+       } else if (dl_argv_match(dl, "show") ||
+                  dl_argv_match(dl, "list") || dl_no_arg(dl)) {
+               dl_arg_inc(dl);
+               return cmd_trap_policer_show(dl);
+       } else if (dl_argv_match(dl, "set")) {
+               dl_arg_inc(dl);
+               return cmd_trap_policer_set(dl);
+       }
+       pr_err("Command \"%s\" not found\n", dl_argv(dl));
+       return -ENOENT;
+}
+
 static int cmd_trap(struct dl *dl)
 {
        if (dl_argv_match(dl, "help")) {
@@ -7123,6 +7333,9 @@ static int cmd_trap(struct dl *dl)
        } else if (dl_argv_match(dl, "group")) {
                dl_arg_inc(dl);
                return cmd_trap_group(dl);
+       } else if (dl_argv_match(dl, "policer")) {
+               dl_arg_inc(dl);
+               return cmd_trap_policer(dl);
        }
        pr_err("Command \"%s\" not found\n", dl_argv(dl));
        return -ENOENT;