15d1a30ebSJakub Kicinski // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
25d1a30ebSJakub Kicinski /* Do not edit directly, auto-generated from: */
35d1a30ebSJakub Kicinski /* Documentation/netlink/specs/devlink.yaml */
45d1a30ebSJakub Kicinski /* YNL-GEN user source */
55d1a30ebSJakub Kicinski
65d1a30ebSJakub Kicinski #include <stdlib.h>
79b52fd4bSJakub Kicinski #include <string.h>
85d1a30ebSJakub Kicinski #include "devlink-user.h"
95d1a30ebSJakub Kicinski #include "ynl.h"
105d1a30ebSJakub Kicinski #include <linux/devlink.h>
115d1a30ebSJakub Kicinski
125d1a30ebSJakub Kicinski #include <libmnl/libmnl.h>
135d1a30ebSJakub Kicinski #include <linux/genetlink.h>
145d1a30ebSJakub Kicinski
155d1a30ebSJakub Kicinski /* Enums */
165d1a30ebSJakub Kicinski static const char * const devlink_op_strmap[] = {
175d1a30ebSJakub Kicinski [3] = "get",
187199c862SJiri Pirko [7] = "port-get",
19*0f4d44f6SJiri Pirko [13] = "sb-get",
20*0f4d44f6SJiri Pirko [17] = "sb-pool-get",
21*0f4d44f6SJiri Pirko [21] = "sb-port-pool-get",
22*0f4d44f6SJiri Pirko [25] = "sb-tc-pool-bind-get",
237199c862SJiri Pirko [DEVLINK_CMD_PARAM_GET] = "param-get",
247199c862SJiri Pirko [DEVLINK_CMD_REGION_GET] = "region-get",
255d1a30ebSJakub Kicinski [DEVLINK_CMD_INFO_GET] = "info-get",
267199c862SJiri Pirko [DEVLINK_CMD_HEALTH_REPORTER_GET] = "health-reporter-get",
27*0f4d44f6SJiri Pirko [63] = "trap-get",
28*0f4d44f6SJiri Pirko [67] = "trap-group-get",
29*0f4d44f6SJiri Pirko [71] = "trap-policer-get",
30*0f4d44f6SJiri Pirko [76] = "rate-get",
31*0f4d44f6SJiri Pirko [80] = "linecard-get",
327199c862SJiri Pirko [DEVLINK_CMD_SELFTESTS_GET] = "selftests-get",
335d1a30ebSJakub Kicinski };
345d1a30ebSJakub Kicinski
devlink_op_str(int op)355d1a30ebSJakub Kicinski const char *devlink_op_str(int op)
365d1a30ebSJakub Kicinski {
375d1a30ebSJakub Kicinski if (op < 0 || op >= (int)MNL_ARRAY_SIZE(devlink_op_strmap))
385d1a30ebSJakub Kicinski return NULL;
395d1a30ebSJakub Kicinski return devlink_op_strmap[op];
405d1a30ebSJakub Kicinski }
415d1a30ebSJakub Kicinski
427199c862SJiri Pirko static const char * const devlink_sb_pool_type_strmap[] = {
437199c862SJiri Pirko [0] = "ingress",
447199c862SJiri Pirko [1] = "egress",
457199c862SJiri Pirko };
467199c862SJiri Pirko
devlink_sb_pool_type_str(enum devlink_sb_pool_type value)477199c862SJiri Pirko const char *devlink_sb_pool_type_str(enum devlink_sb_pool_type value)
487199c862SJiri Pirko {
497199c862SJiri Pirko if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_sb_pool_type_strmap))
507199c862SJiri Pirko return NULL;
517199c862SJiri Pirko return devlink_sb_pool_type_strmap[value];
527199c862SJiri Pirko }
537199c862SJiri Pirko
545d1a30ebSJakub Kicinski /* Policies */
555d1a30ebSJakub Kicinski struct ynl_policy_attr devlink_dl_info_version_policy[DEVLINK_ATTR_MAX + 1] = {
565d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_VERSION_NAME] = { .name = "info-version-name", .type = YNL_PT_NUL_STR, },
575d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_VERSION_VALUE] = { .name = "info-version-value", .type = YNL_PT_NUL_STR, },
585d1a30ebSJakub Kicinski };
595d1a30ebSJakub Kicinski
605d1a30ebSJakub Kicinski struct ynl_policy_nest devlink_dl_info_version_nest = {
615d1a30ebSJakub Kicinski .max_attr = DEVLINK_ATTR_MAX,
625d1a30ebSJakub Kicinski .table = devlink_dl_info_version_policy,
635d1a30ebSJakub Kicinski };
645d1a30ebSJakub Kicinski
655d1a30ebSJakub Kicinski struct ynl_policy_attr devlink_dl_reload_stats_entry_policy[DEVLINK_ATTR_MAX + 1] = {
665d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_STATS_LIMIT] = { .name = "reload-stats-limit", .type = YNL_PT_U8, },
675d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_STATS_VALUE] = { .name = "reload-stats-value", .type = YNL_PT_U32, },
685d1a30ebSJakub Kicinski };
695d1a30ebSJakub Kicinski
705d1a30ebSJakub Kicinski struct ynl_policy_nest devlink_dl_reload_stats_entry_nest = {
715d1a30ebSJakub Kicinski .max_attr = DEVLINK_ATTR_MAX,
725d1a30ebSJakub Kicinski .table = devlink_dl_reload_stats_entry_policy,
735d1a30ebSJakub Kicinski };
745d1a30ebSJakub Kicinski
755d1a30ebSJakub Kicinski struct ynl_policy_attr devlink_dl_reload_act_stats_policy[DEVLINK_ATTR_MAX + 1] = {
765d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_STATS_ENTRY] = { .name = "reload-stats-entry", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_entry_nest, },
775d1a30ebSJakub Kicinski };
785d1a30ebSJakub Kicinski
795d1a30ebSJakub Kicinski struct ynl_policy_nest devlink_dl_reload_act_stats_nest = {
805d1a30ebSJakub Kicinski .max_attr = DEVLINK_ATTR_MAX,
815d1a30ebSJakub Kicinski .table = devlink_dl_reload_act_stats_policy,
825d1a30ebSJakub Kicinski };
835d1a30ebSJakub Kicinski
845d1a30ebSJakub Kicinski struct ynl_policy_attr devlink_dl_reload_act_info_policy[DEVLINK_ATTR_MAX + 1] = {
855d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_ACTION] = { .name = "reload-action", .type = YNL_PT_U8, },
865d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_ACTION_STATS] = { .name = "reload-action-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_stats_nest, },
875d1a30ebSJakub Kicinski };
885d1a30ebSJakub Kicinski
895d1a30ebSJakub Kicinski struct ynl_policy_nest devlink_dl_reload_act_info_nest = {
905d1a30ebSJakub Kicinski .max_attr = DEVLINK_ATTR_MAX,
915d1a30ebSJakub Kicinski .table = devlink_dl_reload_act_info_policy,
925d1a30ebSJakub Kicinski };
935d1a30ebSJakub Kicinski
945d1a30ebSJakub Kicinski struct ynl_policy_attr devlink_dl_reload_stats_policy[DEVLINK_ATTR_MAX + 1] = {
955d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_ACTION_INFO] = { .name = "reload-action-info", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_info_nest, },
965d1a30ebSJakub Kicinski };
975d1a30ebSJakub Kicinski
985d1a30ebSJakub Kicinski struct ynl_policy_nest devlink_dl_reload_stats_nest = {
995d1a30ebSJakub Kicinski .max_attr = DEVLINK_ATTR_MAX,
1005d1a30ebSJakub Kicinski .table = devlink_dl_reload_stats_policy,
1015d1a30ebSJakub Kicinski };
1025d1a30ebSJakub Kicinski
1035d1a30ebSJakub Kicinski struct ynl_policy_attr devlink_dl_dev_stats_policy[DEVLINK_ATTR_MAX + 1] = {
1045d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_STATS] = { .name = "reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
1055d1a30ebSJakub Kicinski [DEVLINK_ATTR_REMOTE_RELOAD_STATS] = { .name = "remote-reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
1065d1a30ebSJakub Kicinski };
1075d1a30ebSJakub Kicinski
1085d1a30ebSJakub Kicinski struct ynl_policy_nest devlink_dl_dev_stats_nest = {
1095d1a30ebSJakub Kicinski .max_attr = DEVLINK_ATTR_MAX,
1105d1a30ebSJakub Kicinski .table = devlink_dl_dev_stats_policy,
1115d1a30ebSJakub Kicinski };
1125d1a30ebSJakub Kicinski
1135d1a30ebSJakub Kicinski struct ynl_policy_attr devlink_policy[DEVLINK_ATTR_MAX + 1] = {
1145d1a30ebSJakub Kicinski [DEVLINK_ATTR_BUS_NAME] = { .name = "bus-name", .type = YNL_PT_NUL_STR, },
1155d1a30ebSJakub Kicinski [DEVLINK_ATTR_DEV_NAME] = { .name = "dev-name", .type = YNL_PT_NUL_STR, },
1165d1a30ebSJakub Kicinski [DEVLINK_ATTR_PORT_INDEX] = { .name = "port-index", .type = YNL_PT_U32, },
1177199c862SJiri Pirko [DEVLINK_ATTR_SB_INDEX] = { .name = "sb-index", .type = YNL_PT_U32, },
1187199c862SJiri Pirko [DEVLINK_ATTR_SB_POOL_INDEX] = { .name = "sb-pool-index", .type = YNL_PT_U16, },
1197199c862SJiri Pirko [DEVLINK_ATTR_SB_POOL_TYPE] = { .name = "sb-pool-type", .type = YNL_PT_U8, },
1207199c862SJiri Pirko [DEVLINK_ATTR_SB_TC_INDEX] = { .name = "sb-tc-index", .type = YNL_PT_U16, },
1217199c862SJiri Pirko [DEVLINK_ATTR_PARAM_NAME] = { .name = "param-name", .type = YNL_PT_NUL_STR, },
1227199c862SJiri Pirko [DEVLINK_ATTR_REGION_NAME] = { .name = "region-name", .type = YNL_PT_NUL_STR, },
1235d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_DRIVER_NAME] = { .name = "info-driver-name", .type = YNL_PT_NUL_STR, },
1245d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_SERIAL_NUMBER] = { .name = "info-serial-number", .type = YNL_PT_NUL_STR, },
1255d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_VERSION_FIXED] = { .name = "info-version-fixed", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
1265d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_VERSION_RUNNING] = { .name = "info-version-running", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
1275d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_VERSION_STORED] = { .name = "info-version-stored", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
1285d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_VERSION_NAME] = { .name = "info-version-name", .type = YNL_PT_NUL_STR, },
1295d1a30ebSJakub Kicinski [DEVLINK_ATTR_INFO_VERSION_VALUE] = { .name = "info-version-value", .type = YNL_PT_NUL_STR, },
1307199c862SJiri Pirko [DEVLINK_ATTR_HEALTH_REPORTER_NAME] = { .name = "health-reporter-name", .type = YNL_PT_NUL_STR, },
1317199c862SJiri Pirko [DEVLINK_ATTR_TRAP_NAME] = { .name = "trap-name", .type = YNL_PT_NUL_STR, },
1327199c862SJiri Pirko [DEVLINK_ATTR_TRAP_GROUP_NAME] = { .name = "trap-group-name", .type = YNL_PT_NUL_STR, },
1335d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_FAILED] = { .name = "reload-failed", .type = YNL_PT_U8, },
1347199c862SJiri Pirko [DEVLINK_ATTR_TRAP_POLICER_ID] = { .name = "trap-policer-id", .type = YNL_PT_U32, },
1355d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_ACTION] = { .name = "reload-action", .type = YNL_PT_U8, },
1365d1a30ebSJakub Kicinski [DEVLINK_ATTR_DEV_STATS] = { .name = "dev-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_dev_stats_nest, },
1375d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_STATS] = { .name = "reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
1385d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_STATS_ENTRY] = { .name = "reload-stats-entry", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_entry_nest, },
1395d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_STATS_LIMIT] = { .name = "reload-stats-limit", .type = YNL_PT_U8, },
1405d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_STATS_VALUE] = { .name = "reload-stats-value", .type = YNL_PT_U32, },
1415d1a30ebSJakub Kicinski [DEVLINK_ATTR_REMOTE_RELOAD_STATS] = { .name = "remote-reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
1425d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_ACTION_INFO] = { .name = "reload-action-info", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_info_nest, },
1435d1a30ebSJakub Kicinski [DEVLINK_ATTR_RELOAD_ACTION_STATS] = { .name = "reload-action-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_stats_nest, },
1447199c862SJiri Pirko [DEVLINK_ATTR_RATE_NODE_NAME] = { .name = "rate-node-name", .type = YNL_PT_NUL_STR, },
1457199c862SJiri Pirko [DEVLINK_ATTR_LINECARD_INDEX] = { .name = "linecard-index", .type = YNL_PT_U32, },
1465d1a30ebSJakub Kicinski };
1475d1a30ebSJakub Kicinski
1485d1a30ebSJakub Kicinski struct ynl_policy_nest devlink_nest = {
1495d1a30ebSJakub Kicinski .max_attr = DEVLINK_ATTR_MAX,
1505d1a30ebSJakub Kicinski .table = devlink_policy,
1515d1a30ebSJakub Kicinski };
1525d1a30ebSJakub Kicinski
1535d1a30ebSJakub Kicinski /* Common nested types */
devlink_dl_info_version_free(struct devlink_dl_info_version * obj)1545d1a30ebSJakub Kicinski void devlink_dl_info_version_free(struct devlink_dl_info_version *obj)
1555d1a30ebSJakub Kicinski {
1565d1a30ebSJakub Kicinski free(obj->info_version_name);
1575d1a30ebSJakub Kicinski free(obj->info_version_value);
1585d1a30ebSJakub Kicinski }
1595d1a30ebSJakub Kicinski
devlink_dl_info_version_parse(struct ynl_parse_arg * yarg,const struct nlattr * nested)1605d1a30ebSJakub Kicinski int devlink_dl_info_version_parse(struct ynl_parse_arg *yarg,
1615d1a30ebSJakub Kicinski const struct nlattr *nested)
1625d1a30ebSJakub Kicinski {
1635d1a30ebSJakub Kicinski struct devlink_dl_info_version *dst = yarg->data;
1645d1a30ebSJakub Kicinski const struct nlattr *attr;
1655d1a30ebSJakub Kicinski
1665d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
1677234415bSJakub Kicinski unsigned int type = mnl_attr_get_type(attr);
1687234415bSJakub Kicinski
1697234415bSJakub Kicinski if (type == DEVLINK_ATTR_INFO_VERSION_NAME) {
1705d1a30ebSJakub Kicinski unsigned int len;
1715d1a30ebSJakub Kicinski
1725d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
1735d1a30ebSJakub Kicinski return MNL_CB_ERROR;
1745d1a30ebSJakub Kicinski
1755d1a30ebSJakub Kicinski len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1765d1a30ebSJakub Kicinski dst->_present.info_version_name_len = len;
1775d1a30ebSJakub Kicinski dst->info_version_name = malloc(len + 1);
1785d1a30ebSJakub Kicinski memcpy(dst->info_version_name, mnl_attr_get_str(attr), len);
1795d1a30ebSJakub Kicinski dst->info_version_name[len] = 0;
1807234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_INFO_VERSION_VALUE) {
1815d1a30ebSJakub Kicinski unsigned int len;
1825d1a30ebSJakub Kicinski
1835d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
1845d1a30ebSJakub Kicinski return MNL_CB_ERROR;
1855d1a30ebSJakub Kicinski
1865d1a30ebSJakub Kicinski len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1875d1a30ebSJakub Kicinski dst->_present.info_version_value_len = len;
1885d1a30ebSJakub Kicinski dst->info_version_value = malloc(len + 1);
1895d1a30ebSJakub Kicinski memcpy(dst->info_version_value, mnl_attr_get_str(attr), len);
1905d1a30ebSJakub Kicinski dst->info_version_value[len] = 0;
1915d1a30ebSJakub Kicinski }
1925d1a30ebSJakub Kicinski }
1935d1a30ebSJakub Kicinski
1945d1a30ebSJakub Kicinski return 0;
1955d1a30ebSJakub Kicinski }
1965d1a30ebSJakub Kicinski
1975d1a30ebSJakub Kicinski void
devlink_dl_reload_stats_entry_free(struct devlink_dl_reload_stats_entry * obj)1985d1a30ebSJakub Kicinski devlink_dl_reload_stats_entry_free(struct devlink_dl_reload_stats_entry *obj)
1995d1a30ebSJakub Kicinski {
2005d1a30ebSJakub Kicinski }
2015d1a30ebSJakub Kicinski
devlink_dl_reload_stats_entry_parse(struct ynl_parse_arg * yarg,const struct nlattr * nested)2025d1a30ebSJakub Kicinski int devlink_dl_reload_stats_entry_parse(struct ynl_parse_arg *yarg,
2035d1a30ebSJakub Kicinski const struct nlattr *nested)
2045d1a30ebSJakub Kicinski {
2055d1a30ebSJakub Kicinski struct devlink_dl_reload_stats_entry *dst = yarg->data;
2065d1a30ebSJakub Kicinski const struct nlattr *attr;
2075d1a30ebSJakub Kicinski
2085d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
2097234415bSJakub Kicinski unsigned int type = mnl_attr_get_type(attr);
2107234415bSJakub Kicinski
2117234415bSJakub Kicinski if (type == DEVLINK_ATTR_RELOAD_STATS_LIMIT) {
2125d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
2135d1a30ebSJakub Kicinski return MNL_CB_ERROR;
2145d1a30ebSJakub Kicinski dst->_present.reload_stats_limit = 1;
2155d1a30ebSJakub Kicinski dst->reload_stats_limit = mnl_attr_get_u8(attr);
2167234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_RELOAD_STATS_VALUE) {
2175d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
2185d1a30ebSJakub Kicinski return MNL_CB_ERROR;
2195d1a30ebSJakub Kicinski dst->_present.reload_stats_value = 1;
2205d1a30ebSJakub Kicinski dst->reload_stats_value = mnl_attr_get_u32(attr);
2215d1a30ebSJakub Kicinski }
2225d1a30ebSJakub Kicinski }
2235d1a30ebSJakub Kicinski
2245d1a30ebSJakub Kicinski return 0;
2255d1a30ebSJakub Kicinski }
2265d1a30ebSJakub Kicinski
devlink_dl_reload_act_stats_free(struct devlink_dl_reload_act_stats * obj)2275d1a30ebSJakub Kicinski void devlink_dl_reload_act_stats_free(struct devlink_dl_reload_act_stats *obj)
2285d1a30ebSJakub Kicinski {
2295d1a30ebSJakub Kicinski unsigned int i;
2305d1a30ebSJakub Kicinski
2315d1a30ebSJakub Kicinski for (i = 0; i < obj->n_reload_stats_entry; i++)
2325d1a30ebSJakub Kicinski devlink_dl_reload_stats_entry_free(&obj->reload_stats_entry[i]);
2335d1a30ebSJakub Kicinski free(obj->reload_stats_entry);
2345d1a30ebSJakub Kicinski }
2355d1a30ebSJakub Kicinski
devlink_dl_reload_act_stats_parse(struct ynl_parse_arg * yarg,const struct nlattr * nested)2365d1a30ebSJakub Kicinski int devlink_dl_reload_act_stats_parse(struct ynl_parse_arg *yarg,
2375d1a30ebSJakub Kicinski const struct nlattr *nested)
2385d1a30ebSJakub Kicinski {
2395d1a30ebSJakub Kicinski struct devlink_dl_reload_act_stats *dst = yarg->data;
2405d1a30ebSJakub Kicinski unsigned int n_reload_stats_entry = 0;
2415d1a30ebSJakub Kicinski const struct nlattr *attr;
2425d1a30ebSJakub Kicinski struct ynl_parse_arg parg;
2435d1a30ebSJakub Kicinski int i;
2445d1a30ebSJakub Kicinski
2455d1a30ebSJakub Kicinski parg.ys = yarg->ys;
2465d1a30ebSJakub Kicinski
2475d1a30ebSJakub Kicinski if (dst->reload_stats_entry)
2485d1a30ebSJakub Kicinski return ynl_error_parse(yarg, "attribute already present (dl-reload-act-stats.reload-stats-entry)");
2495d1a30ebSJakub Kicinski
2505d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
2517234415bSJakub Kicinski unsigned int type = mnl_attr_get_type(attr);
2527234415bSJakub Kicinski
2537234415bSJakub Kicinski if (type == DEVLINK_ATTR_RELOAD_STATS_ENTRY) {
2545d1a30ebSJakub Kicinski n_reload_stats_entry++;
2555d1a30ebSJakub Kicinski }
2565d1a30ebSJakub Kicinski }
2575d1a30ebSJakub Kicinski
2585d1a30ebSJakub Kicinski if (n_reload_stats_entry) {
2595d1a30ebSJakub Kicinski dst->reload_stats_entry = calloc(n_reload_stats_entry, sizeof(*dst->reload_stats_entry));
2605d1a30ebSJakub Kicinski dst->n_reload_stats_entry = n_reload_stats_entry;
2615d1a30ebSJakub Kicinski i = 0;
2625d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_reload_stats_entry_nest;
2635d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
2645d1a30ebSJakub Kicinski if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_STATS_ENTRY) {
2655d1a30ebSJakub Kicinski parg.data = &dst->reload_stats_entry[i];
2665d1a30ebSJakub Kicinski if (devlink_dl_reload_stats_entry_parse(&parg, attr))
2675d1a30ebSJakub Kicinski return MNL_CB_ERROR;
2685d1a30ebSJakub Kicinski i++;
2695d1a30ebSJakub Kicinski }
2705d1a30ebSJakub Kicinski }
2715d1a30ebSJakub Kicinski }
2725d1a30ebSJakub Kicinski
2735d1a30ebSJakub Kicinski return 0;
2745d1a30ebSJakub Kicinski }
2755d1a30ebSJakub Kicinski
devlink_dl_reload_act_info_free(struct devlink_dl_reload_act_info * obj)2765d1a30ebSJakub Kicinski void devlink_dl_reload_act_info_free(struct devlink_dl_reload_act_info *obj)
2775d1a30ebSJakub Kicinski {
2785d1a30ebSJakub Kicinski unsigned int i;
2795d1a30ebSJakub Kicinski
2805d1a30ebSJakub Kicinski for (i = 0; i < obj->n_reload_action_stats; i++)
2815d1a30ebSJakub Kicinski devlink_dl_reload_act_stats_free(&obj->reload_action_stats[i]);
2825d1a30ebSJakub Kicinski free(obj->reload_action_stats);
2835d1a30ebSJakub Kicinski }
2845d1a30ebSJakub Kicinski
devlink_dl_reload_act_info_parse(struct ynl_parse_arg * yarg,const struct nlattr * nested)2855d1a30ebSJakub Kicinski int devlink_dl_reload_act_info_parse(struct ynl_parse_arg *yarg,
2865d1a30ebSJakub Kicinski const struct nlattr *nested)
2875d1a30ebSJakub Kicinski {
2885d1a30ebSJakub Kicinski struct devlink_dl_reload_act_info *dst = yarg->data;
2895d1a30ebSJakub Kicinski unsigned int n_reload_action_stats = 0;
2905d1a30ebSJakub Kicinski const struct nlattr *attr;
2915d1a30ebSJakub Kicinski struct ynl_parse_arg parg;
2925d1a30ebSJakub Kicinski int i;
2935d1a30ebSJakub Kicinski
2945d1a30ebSJakub Kicinski parg.ys = yarg->ys;
2955d1a30ebSJakub Kicinski
2965d1a30ebSJakub Kicinski if (dst->reload_action_stats)
2975d1a30ebSJakub Kicinski return ynl_error_parse(yarg, "attribute already present (dl-reload-act-info.reload-action-stats)");
2985d1a30ebSJakub Kicinski
2995d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
3007234415bSJakub Kicinski unsigned int type = mnl_attr_get_type(attr);
3017234415bSJakub Kicinski
3027234415bSJakub Kicinski if (type == DEVLINK_ATTR_RELOAD_ACTION) {
3035d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
3045d1a30ebSJakub Kicinski return MNL_CB_ERROR;
3055d1a30ebSJakub Kicinski dst->_present.reload_action = 1;
3065d1a30ebSJakub Kicinski dst->reload_action = mnl_attr_get_u8(attr);
3077234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_RELOAD_ACTION_STATS) {
3085d1a30ebSJakub Kicinski n_reload_action_stats++;
3095d1a30ebSJakub Kicinski }
3105d1a30ebSJakub Kicinski }
3115d1a30ebSJakub Kicinski
3125d1a30ebSJakub Kicinski if (n_reload_action_stats) {
3135d1a30ebSJakub Kicinski dst->reload_action_stats = calloc(n_reload_action_stats, sizeof(*dst->reload_action_stats));
3145d1a30ebSJakub Kicinski dst->n_reload_action_stats = n_reload_action_stats;
3155d1a30ebSJakub Kicinski i = 0;
3165d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_reload_act_stats_nest;
3175d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
3185d1a30ebSJakub Kicinski if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION_STATS) {
3195d1a30ebSJakub Kicinski parg.data = &dst->reload_action_stats[i];
3205d1a30ebSJakub Kicinski if (devlink_dl_reload_act_stats_parse(&parg, attr))
3215d1a30ebSJakub Kicinski return MNL_CB_ERROR;
3225d1a30ebSJakub Kicinski i++;
3235d1a30ebSJakub Kicinski }
3245d1a30ebSJakub Kicinski }
3255d1a30ebSJakub Kicinski }
3265d1a30ebSJakub Kicinski
3275d1a30ebSJakub Kicinski return 0;
3285d1a30ebSJakub Kicinski }
3295d1a30ebSJakub Kicinski
devlink_dl_reload_stats_free(struct devlink_dl_reload_stats * obj)3305d1a30ebSJakub Kicinski void devlink_dl_reload_stats_free(struct devlink_dl_reload_stats *obj)
3315d1a30ebSJakub Kicinski {
3325d1a30ebSJakub Kicinski unsigned int i;
3335d1a30ebSJakub Kicinski
3345d1a30ebSJakub Kicinski for (i = 0; i < obj->n_reload_action_info; i++)
3355d1a30ebSJakub Kicinski devlink_dl_reload_act_info_free(&obj->reload_action_info[i]);
3365d1a30ebSJakub Kicinski free(obj->reload_action_info);
3375d1a30ebSJakub Kicinski }
3385d1a30ebSJakub Kicinski
devlink_dl_reload_stats_parse(struct ynl_parse_arg * yarg,const struct nlattr * nested)3395d1a30ebSJakub Kicinski int devlink_dl_reload_stats_parse(struct ynl_parse_arg *yarg,
3405d1a30ebSJakub Kicinski const struct nlattr *nested)
3415d1a30ebSJakub Kicinski {
3425d1a30ebSJakub Kicinski struct devlink_dl_reload_stats *dst = yarg->data;
3435d1a30ebSJakub Kicinski unsigned int n_reload_action_info = 0;
3445d1a30ebSJakub Kicinski const struct nlattr *attr;
3455d1a30ebSJakub Kicinski struct ynl_parse_arg parg;
3465d1a30ebSJakub Kicinski int i;
3475d1a30ebSJakub Kicinski
3485d1a30ebSJakub Kicinski parg.ys = yarg->ys;
3495d1a30ebSJakub Kicinski
3505d1a30ebSJakub Kicinski if (dst->reload_action_info)
3515d1a30ebSJakub Kicinski return ynl_error_parse(yarg, "attribute already present (dl-reload-stats.reload-action-info)");
3525d1a30ebSJakub Kicinski
3535d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
3547234415bSJakub Kicinski unsigned int type = mnl_attr_get_type(attr);
3557234415bSJakub Kicinski
3567234415bSJakub Kicinski if (type == DEVLINK_ATTR_RELOAD_ACTION_INFO) {
3575d1a30ebSJakub Kicinski n_reload_action_info++;
3585d1a30ebSJakub Kicinski }
3595d1a30ebSJakub Kicinski }
3605d1a30ebSJakub Kicinski
3615d1a30ebSJakub Kicinski if (n_reload_action_info) {
3625d1a30ebSJakub Kicinski dst->reload_action_info = calloc(n_reload_action_info, sizeof(*dst->reload_action_info));
3635d1a30ebSJakub Kicinski dst->n_reload_action_info = n_reload_action_info;
3645d1a30ebSJakub Kicinski i = 0;
3655d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_reload_act_info_nest;
3665d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
3675d1a30ebSJakub Kicinski if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION_INFO) {
3685d1a30ebSJakub Kicinski parg.data = &dst->reload_action_info[i];
3695d1a30ebSJakub Kicinski if (devlink_dl_reload_act_info_parse(&parg, attr))
3705d1a30ebSJakub Kicinski return MNL_CB_ERROR;
3715d1a30ebSJakub Kicinski i++;
3725d1a30ebSJakub Kicinski }
3735d1a30ebSJakub Kicinski }
3745d1a30ebSJakub Kicinski }
3755d1a30ebSJakub Kicinski
3765d1a30ebSJakub Kicinski return 0;
3775d1a30ebSJakub Kicinski }
3785d1a30ebSJakub Kicinski
devlink_dl_dev_stats_free(struct devlink_dl_dev_stats * obj)3795d1a30ebSJakub Kicinski void devlink_dl_dev_stats_free(struct devlink_dl_dev_stats *obj)
3805d1a30ebSJakub Kicinski {
3815d1a30ebSJakub Kicinski devlink_dl_reload_stats_free(&obj->reload_stats);
3825d1a30ebSJakub Kicinski devlink_dl_reload_stats_free(&obj->remote_reload_stats);
3835d1a30ebSJakub Kicinski }
3845d1a30ebSJakub Kicinski
devlink_dl_dev_stats_parse(struct ynl_parse_arg * yarg,const struct nlattr * nested)3855d1a30ebSJakub Kicinski int devlink_dl_dev_stats_parse(struct ynl_parse_arg *yarg,
3865d1a30ebSJakub Kicinski const struct nlattr *nested)
3875d1a30ebSJakub Kicinski {
3885d1a30ebSJakub Kicinski struct devlink_dl_dev_stats *dst = yarg->data;
3895d1a30ebSJakub Kicinski const struct nlattr *attr;
3905d1a30ebSJakub Kicinski struct ynl_parse_arg parg;
3915d1a30ebSJakub Kicinski
3925d1a30ebSJakub Kicinski parg.ys = yarg->ys;
3935d1a30ebSJakub Kicinski
3945d1a30ebSJakub Kicinski mnl_attr_for_each_nested(attr, nested) {
3957234415bSJakub Kicinski unsigned int type = mnl_attr_get_type(attr);
3967234415bSJakub Kicinski
3977234415bSJakub Kicinski if (type == DEVLINK_ATTR_RELOAD_STATS) {
3985d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
3995d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4005d1a30ebSJakub Kicinski dst->_present.reload_stats = 1;
4015d1a30ebSJakub Kicinski
4025d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_reload_stats_nest;
4035d1a30ebSJakub Kicinski parg.data = &dst->reload_stats;
4045d1a30ebSJakub Kicinski if (devlink_dl_reload_stats_parse(&parg, attr))
4055d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4067234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_REMOTE_RELOAD_STATS) {
4075d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
4085d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4095d1a30ebSJakub Kicinski dst->_present.remote_reload_stats = 1;
4105d1a30ebSJakub Kicinski
4115d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_reload_stats_nest;
4125d1a30ebSJakub Kicinski parg.data = &dst->remote_reload_stats;
4135d1a30ebSJakub Kicinski if (devlink_dl_reload_stats_parse(&parg, attr))
4145d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4155d1a30ebSJakub Kicinski }
4165d1a30ebSJakub Kicinski }
4175d1a30ebSJakub Kicinski
4185d1a30ebSJakub Kicinski return 0;
4195d1a30ebSJakub Kicinski }
4205d1a30ebSJakub Kicinski
4215d1a30ebSJakub Kicinski /* ============== DEVLINK_CMD_GET ============== */
4225d1a30ebSJakub Kicinski /* DEVLINK_CMD_GET - do */
devlink_get_req_free(struct devlink_get_req * req)4235d1a30ebSJakub Kicinski void devlink_get_req_free(struct devlink_get_req *req)
4245d1a30ebSJakub Kicinski {
4255d1a30ebSJakub Kicinski free(req->bus_name);
4265d1a30ebSJakub Kicinski free(req->dev_name);
4275d1a30ebSJakub Kicinski free(req);
4285d1a30ebSJakub Kicinski }
4295d1a30ebSJakub Kicinski
devlink_get_rsp_free(struct devlink_get_rsp * rsp)4305d1a30ebSJakub Kicinski void devlink_get_rsp_free(struct devlink_get_rsp *rsp)
4315d1a30ebSJakub Kicinski {
4325d1a30ebSJakub Kicinski free(rsp->bus_name);
4335d1a30ebSJakub Kicinski free(rsp->dev_name);
4345d1a30ebSJakub Kicinski devlink_dl_dev_stats_free(&rsp->dev_stats);
4355d1a30ebSJakub Kicinski free(rsp);
4365d1a30ebSJakub Kicinski }
4375d1a30ebSJakub Kicinski
devlink_get_rsp_parse(const struct nlmsghdr * nlh,void * data)4385d1a30ebSJakub Kicinski int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
4395d1a30ebSJakub Kicinski {
4405d1a30ebSJakub Kicinski struct ynl_parse_arg *yarg = data;
4415d1a30ebSJakub Kicinski struct devlink_get_rsp *dst;
4425d1a30ebSJakub Kicinski const struct nlattr *attr;
4435d1a30ebSJakub Kicinski struct ynl_parse_arg parg;
4445d1a30ebSJakub Kicinski
4455d1a30ebSJakub Kicinski dst = yarg->data;
4465d1a30ebSJakub Kicinski parg.ys = yarg->ys;
4475d1a30ebSJakub Kicinski
4485d1a30ebSJakub Kicinski mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
4497234415bSJakub Kicinski unsigned int type = mnl_attr_get_type(attr);
4507234415bSJakub Kicinski
4517234415bSJakub Kicinski if (type == DEVLINK_ATTR_BUS_NAME) {
4525d1a30ebSJakub Kicinski unsigned int len;
4535d1a30ebSJakub Kicinski
4545d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
4555d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4565d1a30ebSJakub Kicinski
4575d1a30ebSJakub Kicinski len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4585d1a30ebSJakub Kicinski dst->_present.bus_name_len = len;
4595d1a30ebSJakub Kicinski dst->bus_name = malloc(len + 1);
4605d1a30ebSJakub Kicinski memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
4615d1a30ebSJakub Kicinski dst->bus_name[len] = 0;
4627234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_DEV_NAME) {
4635d1a30ebSJakub Kicinski unsigned int len;
4645d1a30ebSJakub Kicinski
4655d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
4665d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4675d1a30ebSJakub Kicinski
4685d1a30ebSJakub Kicinski len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
4695d1a30ebSJakub Kicinski dst->_present.dev_name_len = len;
4705d1a30ebSJakub Kicinski dst->dev_name = malloc(len + 1);
4715d1a30ebSJakub Kicinski memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
4725d1a30ebSJakub Kicinski dst->dev_name[len] = 0;
4737234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_RELOAD_FAILED) {
4745d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
4755d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4765d1a30ebSJakub Kicinski dst->_present.reload_failed = 1;
4775d1a30ebSJakub Kicinski dst->reload_failed = mnl_attr_get_u8(attr);
4787234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_RELOAD_ACTION) {
4795d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
4805d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4815d1a30ebSJakub Kicinski dst->_present.reload_action = 1;
4825d1a30ebSJakub Kicinski dst->reload_action = mnl_attr_get_u8(attr);
4837234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_DEV_STATS) {
4845d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
4855d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4865d1a30ebSJakub Kicinski dst->_present.dev_stats = 1;
4875d1a30ebSJakub Kicinski
4885d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_dev_stats_nest;
4895d1a30ebSJakub Kicinski parg.data = &dst->dev_stats;
4905d1a30ebSJakub Kicinski if (devlink_dl_dev_stats_parse(&parg, attr))
4915d1a30ebSJakub Kicinski return MNL_CB_ERROR;
4925d1a30ebSJakub Kicinski }
4935d1a30ebSJakub Kicinski }
4945d1a30ebSJakub Kicinski
4955d1a30ebSJakub Kicinski return MNL_CB_OK;
4965d1a30ebSJakub Kicinski }
4975d1a30ebSJakub Kicinski
4985d1a30ebSJakub Kicinski struct devlink_get_rsp *
devlink_get(struct ynl_sock * ys,struct devlink_get_req * req)4995d1a30ebSJakub Kicinski devlink_get(struct ynl_sock *ys, struct devlink_get_req *req)
5005d1a30ebSJakub Kicinski {
5015d1a30ebSJakub Kicinski struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
5025d1a30ebSJakub Kicinski struct devlink_get_rsp *rsp;
5035d1a30ebSJakub Kicinski struct nlmsghdr *nlh;
5045d1a30ebSJakub Kicinski int err;
5055d1a30ebSJakub Kicinski
5065d1a30ebSJakub Kicinski nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_GET, 1);
5075d1a30ebSJakub Kicinski ys->req_policy = &devlink_nest;
5085d1a30ebSJakub Kicinski yrs.yarg.rsp_policy = &devlink_nest;
5095d1a30ebSJakub Kicinski
5105d1a30ebSJakub Kicinski if (req->_present.bus_name_len)
5115d1a30ebSJakub Kicinski mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
5125d1a30ebSJakub Kicinski if (req->_present.dev_name_len)
5135d1a30ebSJakub Kicinski mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
5145d1a30ebSJakub Kicinski
5155d1a30ebSJakub Kicinski rsp = calloc(1, sizeof(*rsp));
5165d1a30ebSJakub Kicinski yrs.yarg.data = rsp;
5175d1a30ebSJakub Kicinski yrs.cb = devlink_get_rsp_parse;
5185d1a30ebSJakub Kicinski yrs.rsp_cmd = 3;
5195d1a30ebSJakub Kicinski
5205d1a30ebSJakub Kicinski err = ynl_exec(ys, nlh, &yrs);
5215d1a30ebSJakub Kicinski if (err < 0)
5225d1a30ebSJakub Kicinski goto err_free;
5235d1a30ebSJakub Kicinski
5245d1a30ebSJakub Kicinski return rsp;
5255d1a30ebSJakub Kicinski
5265d1a30ebSJakub Kicinski err_free:
5275d1a30ebSJakub Kicinski devlink_get_rsp_free(rsp);
5285d1a30ebSJakub Kicinski return NULL;
5295d1a30ebSJakub Kicinski }
5305d1a30ebSJakub Kicinski
5315d1a30ebSJakub Kicinski /* DEVLINK_CMD_GET - dump */
devlink_get_list_free(struct devlink_get_list * rsp)5325d1a30ebSJakub Kicinski void devlink_get_list_free(struct devlink_get_list *rsp)
5335d1a30ebSJakub Kicinski {
5345d1a30ebSJakub Kicinski struct devlink_get_list *next = rsp;
5355d1a30ebSJakub Kicinski
5365d1a30ebSJakub Kicinski while ((void *)next != YNL_LIST_END) {
5375d1a30ebSJakub Kicinski rsp = next;
5385d1a30ebSJakub Kicinski next = rsp->next;
5395d1a30ebSJakub Kicinski
5405d1a30ebSJakub Kicinski free(rsp->obj.bus_name);
5415d1a30ebSJakub Kicinski free(rsp->obj.dev_name);
5425d1a30ebSJakub Kicinski devlink_dl_dev_stats_free(&rsp->obj.dev_stats);
5435d1a30ebSJakub Kicinski free(rsp);
5445d1a30ebSJakub Kicinski }
5455d1a30ebSJakub Kicinski }
5465d1a30ebSJakub Kicinski
devlink_get_dump(struct ynl_sock * ys)5475d1a30ebSJakub Kicinski struct devlink_get_list *devlink_get_dump(struct ynl_sock *ys)
5485d1a30ebSJakub Kicinski {
5495d1a30ebSJakub Kicinski struct ynl_dump_state yds = {};
5505d1a30ebSJakub Kicinski struct nlmsghdr *nlh;
5515d1a30ebSJakub Kicinski int err;
5525d1a30ebSJakub Kicinski
5535d1a30ebSJakub Kicinski yds.ys = ys;
5545d1a30ebSJakub Kicinski yds.alloc_sz = sizeof(struct devlink_get_list);
5555d1a30ebSJakub Kicinski yds.cb = devlink_get_rsp_parse;
5565d1a30ebSJakub Kicinski yds.rsp_cmd = 3;
5575d1a30ebSJakub Kicinski yds.rsp_policy = &devlink_nest;
5585d1a30ebSJakub Kicinski
5595d1a30ebSJakub Kicinski nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_GET, 1);
5605d1a30ebSJakub Kicinski
5615d1a30ebSJakub Kicinski err = ynl_exec_dump(ys, nlh, &yds);
5625d1a30ebSJakub Kicinski if (err < 0)
5635d1a30ebSJakub Kicinski goto free_list;
5645d1a30ebSJakub Kicinski
5655d1a30ebSJakub Kicinski return yds.first;
5665d1a30ebSJakub Kicinski
5675d1a30ebSJakub Kicinski free_list:
5685d1a30ebSJakub Kicinski devlink_get_list_free(yds.first);
5695d1a30ebSJakub Kicinski return NULL;
5705d1a30ebSJakub Kicinski }
5715d1a30ebSJakub Kicinski
5727199c862SJiri Pirko /* ============== DEVLINK_CMD_PORT_GET ============== */
5737199c862SJiri Pirko /* DEVLINK_CMD_PORT_GET - do */
devlink_port_get_req_free(struct devlink_port_get_req * req)5747199c862SJiri Pirko void devlink_port_get_req_free(struct devlink_port_get_req *req)
5757199c862SJiri Pirko {
5767199c862SJiri Pirko free(req->bus_name);
5777199c862SJiri Pirko free(req->dev_name);
5787199c862SJiri Pirko free(req);
5797199c862SJiri Pirko }
5807199c862SJiri Pirko
devlink_port_get_rsp_free(struct devlink_port_get_rsp * rsp)5817199c862SJiri Pirko void devlink_port_get_rsp_free(struct devlink_port_get_rsp *rsp)
5827199c862SJiri Pirko {
5837199c862SJiri Pirko free(rsp->bus_name);
5847199c862SJiri Pirko free(rsp->dev_name);
5857199c862SJiri Pirko free(rsp);
5867199c862SJiri Pirko }
5877199c862SJiri Pirko
devlink_port_get_rsp_parse(const struct nlmsghdr * nlh,void * data)5887199c862SJiri Pirko int devlink_port_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
5897199c862SJiri Pirko {
5907199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
5917199c862SJiri Pirko struct devlink_port_get_rsp *dst;
5927199c862SJiri Pirko const struct nlattr *attr;
5937199c862SJiri Pirko
5947199c862SJiri Pirko dst = yarg->data;
5957199c862SJiri Pirko
5967199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
5977199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
5987199c862SJiri Pirko
5997199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
6007199c862SJiri Pirko unsigned int len;
6017199c862SJiri Pirko
6027199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
6037199c862SJiri Pirko return MNL_CB_ERROR;
6047199c862SJiri Pirko
6057199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6067199c862SJiri Pirko dst->_present.bus_name_len = len;
6077199c862SJiri Pirko dst->bus_name = malloc(len + 1);
6087199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
6097199c862SJiri Pirko dst->bus_name[len] = 0;
6107199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
6117199c862SJiri Pirko unsigned int len;
6127199c862SJiri Pirko
6137199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
6147199c862SJiri Pirko return MNL_CB_ERROR;
6157199c862SJiri Pirko
6167199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6177199c862SJiri Pirko dst->_present.dev_name_len = len;
6187199c862SJiri Pirko dst->dev_name = malloc(len + 1);
6197199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
6207199c862SJiri Pirko dst->dev_name[len] = 0;
6217199c862SJiri Pirko } else if (type == DEVLINK_ATTR_PORT_INDEX) {
6227199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
6237199c862SJiri Pirko return MNL_CB_ERROR;
6247199c862SJiri Pirko dst->_present.port_index = 1;
6257199c862SJiri Pirko dst->port_index = mnl_attr_get_u32(attr);
6267199c862SJiri Pirko }
6277199c862SJiri Pirko }
6287199c862SJiri Pirko
6297199c862SJiri Pirko return MNL_CB_OK;
6307199c862SJiri Pirko }
6317199c862SJiri Pirko
6327199c862SJiri Pirko struct devlink_port_get_rsp *
devlink_port_get(struct ynl_sock * ys,struct devlink_port_get_req * req)6337199c862SJiri Pirko devlink_port_get(struct ynl_sock *ys, struct devlink_port_get_req *req)
6347199c862SJiri Pirko {
6357199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
6367199c862SJiri Pirko struct devlink_port_get_rsp *rsp;
6377199c862SJiri Pirko struct nlmsghdr *nlh;
6387199c862SJiri Pirko int err;
6397199c862SJiri Pirko
6407199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_GET, 1);
6417199c862SJiri Pirko ys->req_policy = &devlink_nest;
6427199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
6437199c862SJiri Pirko
6447199c862SJiri Pirko if (req->_present.bus_name_len)
6457199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
6467199c862SJiri Pirko if (req->_present.dev_name_len)
6477199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
6487199c862SJiri Pirko if (req->_present.port_index)
6497199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
6507199c862SJiri Pirko
6517199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
6527199c862SJiri Pirko yrs.yarg.data = rsp;
6537199c862SJiri Pirko yrs.cb = devlink_port_get_rsp_parse;
6547199c862SJiri Pirko yrs.rsp_cmd = 7;
6557199c862SJiri Pirko
6567199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
6577199c862SJiri Pirko if (err < 0)
6587199c862SJiri Pirko goto err_free;
6597199c862SJiri Pirko
6607199c862SJiri Pirko return rsp;
6617199c862SJiri Pirko
6627199c862SJiri Pirko err_free:
6637199c862SJiri Pirko devlink_port_get_rsp_free(rsp);
6647199c862SJiri Pirko return NULL;
6657199c862SJiri Pirko }
6667199c862SJiri Pirko
6677199c862SJiri Pirko /* DEVLINK_CMD_PORT_GET - dump */
devlink_port_get_rsp_dump_parse(const struct nlmsghdr * nlh,void * data)6687199c862SJiri Pirko int devlink_port_get_rsp_dump_parse(const struct nlmsghdr *nlh, void *data)
6697199c862SJiri Pirko {
6707199c862SJiri Pirko struct devlink_port_get_rsp_dump *dst;
6717199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
6727199c862SJiri Pirko const struct nlattr *attr;
6737199c862SJiri Pirko
6747199c862SJiri Pirko dst = yarg->data;
6757199c862SJiri Pirko
6767199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
6777199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
6787199c862SJiri Pirko
6797199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
6807199c862SJiri Pirko unsigned int len;
6817199c862SJiri Pirko
6827199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
6837199c862SJiri Pirko return MNL_CB_ERROR;
6847199c862SJiri Pirko
6857199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6867199c862SJiri Pirko dst->_present.bus_name_len = len;
6877199c862SJiri Pirko dst->bus_name = malloc(len + 1);
6887199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
6897199c862SJiri Pirko dst->bus_name[len] = 0;
6907199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
6917199c862SJiri Pirko unsigned int len;
6927199c862SJiri Pirko
6937199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
6947199c862SJiri Pirko return MNL_CB_ERROR;
6957199c862SJiri Pirko
6967199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
6977199c862SJiri Pirko dst->_present.dev_name_len = len;
6987199c862SJiri Pirko dst->dev_name = malloc(len + 1);
6997199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
7007199c862SJiri Pirko dst->dev_name[len] = 0;
7017199c862SJiri Pirko } else if (type == DEVLINK_ATTR_PORT_INDEX) {
7027199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
7037199c862SJiri Pirko return MNL_CB_ERROR;
7047199c862SJiri Pirko dst->_present.port_index = 1;
7057199c862SJiri Pirko dst->port_index = mnl_attr_get_u32(attr);
7067199c862SJiri Pirko }
7077199c862SJiri Pirko }
7087199c862SJiri Pirko
7097199c862SJiri Pirko return MNL_CB_OK;
7107199c862SJiri Pirko }
7117199c862SJiri Pirko
devlink_port_get_rsp_list_free(struct devlink_port_get_rsp_list * rsp)7127199c862SJiri Pirko void devlink_port_get_rsp_list_free(struct devlink_port_get_rsp_list *rsp)
7137199c862SJiri Pirko {
7147199c862SJiri Pirko struct devlink_port_get_rsp_list *next = rsp;
7157199c862SJiri Pirko
7167199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
7177199c862SJiri Pirko rsp = next;
7187199c862SJiri Pirko next = rsp->next;
7197199c862SJiri Pirko
7207199c862SJiri Pirko free(rsp->obj.bus_name);
7217199c862SJiri Pirko free(rsp->obj.dev_name);
7227199c862SJiri Pirko free(rsp);
7237199c862SJiri Pirko }
7247199c862SJiri Pirko }
7257199c862SJiri Pirko
72634493336SJiri Pirko struct devlink_port_get_rsp_list *
devlink_port_get_dump(struct ynl_sock * ys,struct devlink_port_get_req_dump * req)72734493336SJiri Pirko devlink_port_get_dump(struct ynl_sock *ys,
72834493336SJiri Pirko struct devlink_port_get_req_dump *req)
7297199c862SJiri Pirko {
7307199c862SJiri Pirko struct ynl_dump_state yds = {};
7317199c862SJiri Pirko struct nlmsghdr *nlh;
7327199c862SJiri Pirko int err;
7337199c862SJiri Pirko
7347199c862SJiri Pirko yds.ys = ys;
7357199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_port_get_rsp_list);
7367199c862SJiri Pirko yds.cb = devlink_port_get_rsp_dump_parse;
7377199c862SJiri Pirko yds.rsp_cmd = 7;
7387199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
7397199c862SJiri Pirko
7407199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_PORT_GET, 1);
74134493336SJiri Pirko ys->req_policy = &devlink_nest;
74234493336SJiri Pirko
74334493336SJiri Pirko if (req->_present.bus_name_len)
74434493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
74534493336SJiri Pirko if (req->_present.dev_name_len)
74634493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
7477199c862SJiri Pirko
7487199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
7497199c862SJiri Pirko if (err < 0)
7507199c862SJiri Pirko goto free_list;
7517199c862SJiri Pirko
7527199c862SJiri Pirko return yds.first;
7537199c862SJiri Pirko
7547199c862SJiri Pirko free_list:
7557199c862SJiri Pirko devlink_port_get_rsp_list_free(yds.first);
7567199c862SJiri Pirko return NULL;
7577199c862SJiri Pirko }
7587199c862SJiri Pirko
7597199c862SJiri Pirko /* ============== DEVLINK_CMD_SB_GET ============== */
7607199c862SJiri Pirko /* DEVLINK_CMD_SB_GET - do */
devlink_sb_get_req_free(struct devlink_sb_get_req * req)7617199c862SJiri Pirko void devlink_sb_get_req_free(struct devlink_sb_get_req *req)
7627199c862SJiri Pirko {
7637199c862SJiri Pirko free(req->bus_name);
7647199c862SJiri Pirko free(req->dev_name);
7657199c862SJiri Pirko free(req);
7667199c862SJiri Pirko }
7677199c862SJiri Pirko
devlink_sb_get_rsp_free(struct devlink_sb_get_rsp * rsp)7687199c862SJiri Pirko void devlink_sb_get_rsp_free(struct devlink_sb_get_rsp *rsp)
7697199c862SJiri Pirko {
7707199c862SJiri Pirko free(rsp->bus_name);
7717199c862SJiri Pirko free(rsp->dev_name);
7727199c862SJiri Pirko free(rsp);
7737199c862SJiri Pirko }
7747199c862SJiri Pirko
devlink_sb_get_rsp_parse(const struct nlmsghdr * nlh,void * data)7757199c862SJiri Pirko int devlink_sb_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
7767199c862SJiri Pirko {
7777199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
7787199c862SJiri Pirko struct devlink_sb_get_rsp *dst;
7797199c862SJiri Pirko const struct nlattr *attr;
7807199c862SJiri Pirko
7817199c862SJiri Pirko dst = yarg->data;
7827199c862SJiri Pirko
7837199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
7847199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
7857199c862SJiri Pirko
7867199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
7877199c862SJiri Pirko unsigned int len;
7887199c862SJiri Pirko
7897199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
7907199c862SJiri Pirko return MNL_CB_ERROR;
7917199c862SJiri Pirko
7927199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
7937199c862SJiri Pirko dst->_present.bus_name_len = len;
7947199c862SJiri Pirko dst->bus_name = malloc(len + 1);
7957199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
7967199c862SJiri Pirko dst->bus_name[len] = 0;
7977199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
7987199c862SJiri Pirko unsigned int len;
7997199c862SJiri Pirko
8007199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
8017199c862SJiri Pirko return MNL_CB_ERROR;
8027199c862SJiri Pirko
8037199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
8047199c862SJiri Pirko dst->_present.dev_name_len = len;
8057199c862SJiri Pirko dst->dev_name = malloc(len + 1);
8067199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
8077199c862SJiri Pirko dst->dev_name[len] = 0;
8087199c862SJiri Pirko } else if (type == DEVLINK_ATTR_SB_INDEX) {
8097199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
8107199c862SJiri Pirko return MNL_CB_ERROR;
8117199c862SJiri Pirko dst->_present.sb_index = 1;
8127199c862SJiri Pirko dst->sb_index = mnl_attr_get_u32(attr);
8137199c862SJiri Pirko }
8147199c862SJiri Pirko }
8157199c862SJiri Pirko
8167199c862SJiri Pirko return MNL_CB_OK;
8177199c862SJiri Pirko }
8187199c862SJiri Pirko
8197199c862SJiri Pirko struct devlink_sb_get_rsp *
devlink_sb_get(struct ynl_sock * ys,struct devlink_sb_get_req * req)8207199c862SJiri Pirko devlink_sb_get(struct ynl_sock *ys, struct devlink_sb_get_req *req)
8217199c862SJiri Pirko {
8227199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
8237199c862SJiri Pirko struct devlink_sb_get_rsp *rsp;
8247199c862SJiri Pirko struct nlmsghdr *nlh;
8257199c862SJiri Pirko int err;
8267199c862SJiri Pirko
8277199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_GET, 1);
8287199c862SJiri Pirko ys->req_policy = &devlink_nest;
8297199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
8307199c862SJiri Pirko
8317199c862SJiri Pirko if (req->_present.bus_name_len)
8327199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
8337199c862SJiri Pirko if (req->_present.dev_name_len)
8347199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
8357199c862SJiri Pirko if (req->_present.sb_index)
8367199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
8377199c862SJiri Pirko
8387199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
8397199c862SJiri Pirko yrs.yarg.data = rsp;
8407199c862SJiri Pirko yrs.cb = devlink_sb_get_rsp_parse;
841*0f4d44f6SJiri Pirko yrs.rsp_cmd = 13;
8427199c862SJiri Pirko
8437199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
8447199c862SJiri Pirko if (err < 0)
8457199c862SJiri Pirko goto err_free;
8467199c862SJiri Pirko
8477199c862SJiri Pirko return rsp;
8487199c862SJiri Pirko
8497199c862SJiri Pirko err_free:
8507199c862SJiri Pirko devlink_sb_get_rsp_free(rsp);
8517199c862SJiri Pirko return NULL;
8527199c862SJiri Pirko }
8537199c862SJiri Pirko
8547199c862SJiri Pirko /* DEVLINK_CMD_SB_GET - dump */
devlink_sb_get_list_free(struct devlink_sb_get_list * rsp)8557199c862SJiri Pirko void devlink_sb_get_list_free(struct devlink_sb_get_list *rsp)
8567199c862SJiri Pirko {
8577199c862SJiri Pirko struct devlink_sb_get_list *next = rsp;
8587199c862SJiri Pirko
8597199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
8607199c862SJiri Pirko rsp = next;
8617199c862SJiri Pirko next = rsp->next;
8627199c862SJiri Pirko
8637199c862SJiri Pirko free(rsp->obj.bus_name);
8647199c862SJiri Pirko free(rsp->obj.dev_name);
8657199c862SJiri Pirko free(rsp);
8667199c862SJiri Pirko }
8677199c862SJiri Pirko }
8687199c862SJiri Pirko
86934493336SJiri Pirko struct devlink_sb_get_list *
devlink_sb_get_dump(struct ynl_sock * ys,struct devlink_sb_get_req_dump * req)87034493336SJiri Pirko devlink_sb_get_dump(struct ynl_sock *ys, struct devlink_sb_get_req_dump *req)
8717199c862SJiri Pirko {
8727199c862SJiri Pirko struct ynl_dump_state yds = {};
8737199c862SJiri Pirko struct nlmsghdr *nlh;
8747199c862SJiri Pirko int err;
8757199c862SJiri Pirko
8767199c862SJiri Pirko yds.ys = ys;
8777199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_sb_get_list);
8787199c862SJiri Pirko yds.cb = devlink_sb_get_rsp_parse;
879*0f4d44f6SJiri Pirko yds.rsp_cmd = 13;
8807199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
8817199c862SJiri Pirko
8827199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_GET, 1);
88334493336SJiri Pirko ys->req_policy = &devlink_nest;
88434493336SJiri Pirko
88534493336SJiri Pirko if (req->_present.bus_name_len)
88634493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
88734493336SJiri Pirko if (req->_present.dev_name_len)
88834493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
8897199c862SJiri Pirko
8907199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
8917199c862SJiri Pirko if (err < 0)
8927199c862SJiri Pirko goto free_list;
8937199c862SJiri Pirko
8947199c862SJiri Pirko return yds.first;
8957199c862SJiri Pirko
8967199c862SJiri Pirko free_list:
8977199c862SJiri Pirko devlink_sb_get_list_free(yds.first);
8987199c862SJiri Pirko return NULL;
8997199c862SJiri Pirko }
9007199c862SJiri Pirko
9017199c862SJiri Pirko /* ============== DEVLINK_CMD_SB_POOL_GET ============== */
9027199c862SJiri Pirko /* DEVLINK_CMD_SB_POOL_GET - do */
devlink_sb_pool_get_req_free(struct devlink_sb_pool_get_req * req)9037199c862SJiri Pirko void devlink_sb_pool_get_req_free(struct devlink_sb_pool_get_req *req)
9047199c862SJiri Pirko {
9057199c862SJiri Pirko free(req->bus_name);
9067199c862SJiri Pirko free(req->dev_name);
9077199c862SJiri Pirko free(req);
9087199c862SJiri Pirko }
9097199c862SJiri Pirko
devlink_sb_pool_get_rsp_free(struct devlink_sb_pool_get_rsp * rsp)9107199c862SJiri Pirko void devlink_sb_pool_get_rsp_free(struct devlink_sb_pool_get_rsp *rsp)
9117199c862SJiri Pirko {
9127199c862SJiri Pirko free(rsp->bus_name);
9137199c862SJiri Pirko free(rsp->dev_name);
9147199c862SJiri Pirko free(rsp);
9157199c862SJiri Pirko }
9167199c862SJiri Pirko
devlink_sb_pool_get_rsp_parse(const struct nlmsghdr * nlh,void * data)9177199c862SJiri Pirko int devlink_sb_pool_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
9187199c862SJiri Pirko {
9197199c862SJiri Pirko struct devlink_sb_pool_get_rsp *dst;
9207199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
9217199c862SJiri Pirko const struct nlattr *attr;
9227199c862SJiri Pirko
9237199c862SJiri Pirko dst = yarg->data;
9247199c862SJiri Pirko
9257199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
9267199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
9277199c862SJiri Pirko
9287199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
9297199c862SJiri Pirko unsigned int len;
9307199c862SJiri Pirko
9317199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
9327199c862SJiri Pirko return MNL_CB_ERROR;
9337199c862SJiri Pirko
9347199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
9357199c862SJiri Pirko dst->_present.bus_name_len = len;
9367199c862SJiri Pirko dst->bus_name = malloc(len + 1);
9377199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
9387199c862SJiri Pirko dst->bus_name[len] = 0;
9397199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
9407199c862SJiri Pirko unsigned int len;
9417199c862SJiri Pirko
9427199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
9437199c862SJiri Pirko return MNL_CB_ERROR;
9447199c862SJiri Pirko
9457199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
9467199c862SJiri Pirko dst->_present.dev_name_len = len;
9477199c862SJiri Pirko dst->dev_name = malloc(len + 1);
9487199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
9497199c862SJiri Pirko dst->dev_name[len] = 0;
9507199c862SJiri Pirko } else if (type == DEVLINK_ATTR_SB_INDEX) {
9517199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
9527199c862SJiri Pirko return MNL_CB_ERROR;
9537199c862SJiri Pirko dst->_present.sb_index = 1;
9547199c862SJiri Pirko dst->sb_index = mnl_attr_get_u32(attr);
9557199c862SJiri Pirko } else if (type == DEVLINK_ATTR_SB_POOL_INDEX) {
9567199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
9577199c862SJiri Pirko return MNL_CB_ERROR;
9587199c862SJiri Pirko dst->_present.sb_pool_index = 1;
9597199c862SJiri Pirko dst->sb_pool_index = mnl_attr_get_u16(attr);
9607199c862SJiri Pirko }
9617199c862SJiri Pirko }
9627199c862SJiri Pirko
9637199c862SJiri Pirko return MNL_CB_OK;
9647199c862SJiri Pirko }
9657199c862SJiri Pirko
9667199c862SJiri Pirko struct devlink_sb_pool_get_rsp *
devlink_sb_pool_get(struct ynl_sock * ys,struct devlink_sb_pool_get_req * req)9677199c862SJiri Pirko devlink_sb_pool_get(struct ynl_sock *ys, struct devlink_sb_pool_get_req *req)
9687199c862SJiri Pirko {
9697199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
9707199c862SJiri Pirko struct devlink_sb_pool_get_rsp *rsp;
9717199c862SJiri Pirko struct nlmsghdr *nlh;
9727199c862SJiri Pirko int err;
9737199c862SJiri Pirko
9747199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_POOL_GET, 1);
9757199c862SJiri Pirko ys->req_policy = &devlink_nest;
9767199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
9777199c862SJiri Pirko
9787199c862SJiri Pirko if (req->_present.bus_name_len)
9797199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
9807199c862SJiri Pirko if (req->_present.dev_name_len)
9817199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
9827199c862SJiri Pirko if (req->_present.sb_index)
9837199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
9847199c862SJiri Pirko if (req->_present.sb_pool_index)
9857199c862SJiri Pirko mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
9867199c862SJiri Pirko
9877199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
9887199c862SJiri Pirko yrs.yarg.data = rsp;
9897199c862SJiri Pirko yrs.cb = devlink_sb_pool_get_rsp_parse;
990*0f4d44f6SJiri Pirko yrs.rsp_cmd = 17;
9917199c862SJiri Pirko
9927199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
9937199c862SJiri Pirko if (err < 0)
9947199c862SJiri Pirko goto err_free;
9957199c862SJiri Pirko
9967199c862SJiri Pirko return rsp;
9977199c862SJiri Pirko
9987199c862SJiri Pirko err_free:
9997199c862SJiri Pirko devlink_sb_pool_get_rsp_free(rsp);
10007199c862SJiri Pirko return NULL;
10017199c862SJiri Pirko }
10027199c862SJiri Pirko
10037199c862SJiri Pirko /* DEVLINK_CMD_SB_POOL_GET - dump */
devlink_sb_pool_get_list_free(struct devlink_sb_pool_get_list * rsp)10047199c862SJiri Pirko void devlink_sb_pool_get_list_free(struct devlink_sb_pool_get_list *rsp)
10057199c862SJiri Pirko {
10067199c862SJiri Pirko struct devlink_sb_pool_get_list *next = rsp;
10077199c862SJiri Pirko
10087199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
10097199c862SJiri Pirko rsp = next;
10107199c862SJiri Pirko next = rsp->next;
10117199c862SJiri Pirko
10127199c862SJiri Pirko free(rsp->obj.bus_name);
10137199c862SJiri Pirko free(rsp->obj.dev_name);
10147199c862SJiri Pirko free(rsp);
10157199c862SJiri Pirko }
10167199c862SJiri Pirko }
10177199c862SJiri Pirko
101834493336SJiri Pirko struct devlink_sb_pool_get_list *
devlink_sb_pool_get_dump(struct ynl_sock * ys,struct devlink_sb_pool_get_req_dump * req)101934493336SJiri Pirko devlink_sb_pool_get_dump(struct ynl_sock *ys,
102034493336SJiri Pirko struct devlink_sb_pool_get_req_dump *req)
10217199c862SJiri Pirko {
10227199c862SJiri Pirko struct ynl_dump_state yds = {};
10237199c862SJiri Pirko struct nlmsghdr *nlh;
10247199c862SJiri Pirko int err;
10257199c862SJiri Pirko
10267199c862SJiri Pirko yds.ys = ys;
10277199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_sb_pool_get_list);
10287199c862SJiri Pirko yds.cb = devlink_sb_pool_get_rsp_parse;
1029*0f4d44f6SJiri Pirko yds.rsp_cmd = 17;
10307199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
10317199c862SJiri Pirko
10327199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_POOL_GET, 1);
103334493336SJiri Pirko ys->req_policy = &devlink_nest;
103434493336SJiri Pirko
103534493336SJiri Pirko if (req->_present.bus_name_len)
103634493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
103734493336SJiri Pirko if (req->_present.dev_name_len)
103834493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
10397199c862SJiri Pirko
10407199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
10417199c862SJiri Pirko if (err < 0)
10427199c862SJiri Pirko goto free_list;
10437199c862SJiri Pirko
10447199c862SJiri Pirko return yds.first;
10457199c862SJiri Pirko
10467199c862SJiri Pirko free_list:
10477199c862SJiri Pirko devlink_sb_pool_get_list_free(yds.first);
10487199c862SJiri Pirko return NULL;
10497199c862SJiri Pirko }
10507199c862SJiri Pirko
10517199c862SJiri Pirko /* ============== DEVLINK_CMD_SB_PORT_POOL_GET ============== */
10527199c862SJiri Pirko /* DEVLINK_CMD_SB_PORT_POOL_GET - do */
10537199c862SJiri Pirko void
devlink_sb_port_pool_get_req_free(struct devlink_sb_port_pool_get_req * req)10547199c862SJiri Pirko devlink_sb_port_pool_get_req_free(struct devlink_sb_port_pool_get_req *req)
10557199c862SJiri Pirko {
10567199c862SJiri Pirko free(req->bus_name);
10577199c862SJiri Pirko free(req->dev_name);
10587199c862SJiri Pirko free(req);
10597199c862SJiri Pirko }
10607199c862SJiri Pirko
10617199c862SJiri Pirko void
devlink_sb_port_pool_get_rsp_free(struct devlink_sb_port_pool_get_rsp * rsp)10627199c862SJiri Pirko devlink_sb_port_pool_get_rsp_free(struct devlink_sb_port_pool_get_rsp *rsp)
10637199c862SJiri Pirko {
10647199c862SJiri Pirko free(rsp->bus_name);
10657199c862SJiri Pirko free(rsp->dev_name);
10667199c862SJiri Pirko free(rsp);
10677199c862SJiri Pirko }
10687199c862SJiri Pirko
devlink_sb_port_pool_get_rsp_parse(const struct nlmsghdr * nlh,void * data)10697199c862SJiri Pirko int devlink_sb_port_pool_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
10707199c862SJiri Pirko {
10717199c862SJiri Pirko struct devlink_sb_port_pool_get_rsp *dst;
10727199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
10737199c862SJiri Pirko const struct nlattr *attr;
10747199c862SJiri Pirko
10757199c862SJiri Pirko dst = yarg->data;
10767199c862SJiri Pirko
10777199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
10787199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
10797199c862SJiri Pirko
10807199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
10817199c862SJiri Pirko unsigned int len;
10827199c862SJiri Pirko
10837199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
10847199c862SJiri Pirko return MNL_CB_ERROR;
10857199c862SJiri Pirko
10867199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
10877199c862SJiri Pirko dst->_present.bus_name_len = len;
10887199c862SJiri Pirko dst->bus_name = malloc(len + 1);
10897199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
10907199c862SJiri Pirko dst->bus_name[len] = 0;
10917199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
10927199c862SJiri Pirko unsigned int len;
10937199c862SJiri Pirko
10947199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
10957199c862SJiri Pirko return MNL_CB_ERROR;
10967199c862SJiri Pirko
10977199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
10987199c862SJiri Pirko dst->_present.dev_name_len = len;
10997199c862SJiri Pirko dst->dev_name = malloc(len + 1);
11007199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
11017199c862SJiri Pirko dst->dev_name[len] = 0;
11027199c862SJiri Pirko } else if (type == DEVLINK_ATTR_PORT_INDEX) {
11037199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
11047199c862SJiri Pirko return MNL_CB_ERROR;
11057199c862SJiri Pirko dst->_present.port_index = 1;
11067199c862SJiri Pirko dst->port_index = mnl_attr_get_u32(attr);
11077199c862SJiri Pirko } else if (type == DEVLINK_ATTR_SB_INDEX) {
11087199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
11097199c862SJiri Pirko return MNL_CB_ERROR;
11107199c862SJiri Pirko dst->_present.sb_index = 1;
11117199c862SJiri Pirko dst->sb_index = mnl_attr_get_u32(attr);
11127199c862SJiri Pirko } else if (type == DEVLINK_ATTR_SB_POOL_INDEX) {
11137199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
11147199c862SJiri Pirko return MNL_CB_ERROR;
11157199c862SJiri Pirko dst->_present.sb_pool_index = 1;
11167199c862SJiri Pirko dst->sb_pool_index = mnl_attr_get_u16(attr);
11177199c862SJiri Pirko }
11187199c862SJiri Pirko }
11197199c862SJiri Pirko
11207199c862SJiri Pirko return MNL_CB_OK;
11217199c862SJiri Pirko }
11227199c862SJiri Pirko
11237199c862SJiri Pirko struct devlink_sb_port_pool_get_rsp *
devlink_sb_port_pool_get(struct ynl_sock * ys,struct devlink_sb_port_pool_get_req * req)11247199c862SJiri Pirko devlink_sb_port_pool_get(struct ynl_sock *ys,
11257199c862SJiri Pirko struct devlink_sb_port_pool_get_req *req)
11267199c862SJiri Pirko {
11277199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
11287199c862SJiri Pirko struct devlink_sb_port_pool_get_rsp *rsp;
11297199c862SJiri Pirko struct nlmsghdr *nlh;
11307199c862SJiri Pirko int err;
11317199c862SJiri Pirko
11327199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_PORT_POOL_GET, 1);
11337199c862SJiri Pirko ys->req_policy = &devlink_nest;
11347199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
11357199c862SJiri Pirko
11367199c862SJiri Pirko if (req->_present.bus_name_len)
11377199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
11387199c862SJiri Pirko if (req->_present.dev_name_len)
11397199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
11407199c862SJiri Pirko if (req->_present.port_index)
11417199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
11427199c862SJiri Pirko if (req->_present.sb_index)
11437199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
11447199c862SJiri Pirko if (req->_present.sb_pool_index)
11457199c862SJiri Pirko mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
11467199c862SJiri Pirko
11477199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
11487199c862SJiri Pirko yrs.yarg.data = rsp;
11497199c862SJiri Pirko yrs.cb = devlink_sb_port_pool_get_rsp_parse;
1150*0f4d44f6SJiri Pirko yrs.rsp_cmd = 21;
11517199c862SJiri Pirko
11527199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
11537199c862SJiri Pirko if (err < 0)
11547199c862SJiri Pirko goto err_free;
11557199c862SJiri Pirko
11567199c862SJiri Pirko return rsp;
11577199c862SJiri Pirko
11587199c862SJiri Pirko err_free:
11597199c862SJiri Pirko devlink_sb_port_pool_get_rsp_free(rsp);
11607199c862SJiri Pirko return NULL;
11617199c862SJiri Pirko }
11627199c862SJiri Pirko
11637199c862SJiri Pirko /* DEVLINK_CMD_SB_PORT_POOL_GET - dump */
11647199c862SJiri Pirko void
devlink_sb_port_pool_get_list_free(struct devlink_sb_port_pool_get_list * rsp)11657199c862SJiri Pirko devlink_sb_port_pool_get_list_free(struct devlink_sb_port_pool_get_list *rsp)
11667199c862SJiri Pirko {
11677199c862SJiri Pirko struct devlink_sb_port_pool_get_list *next = rsp;
11687199c862SJiri Pirko
11697199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
11707199c862SJiri Pirko rsp = next;
11717199c862SJiri Pirko next = rsp->next;
11727199c862SJiri Pirko
11737199c862SJiri Pirko free(rsp->obj.bus_name);
11747199c862SJiri Pirko free(rsp->obj.dev_name);
11757199c862SJiri Pirko free(rsp);
11767199c862SJiri Pirko }
11777199c862SJiri Pirko }
11787199c862SJiri Pirko
11797199c862SJiri Pirko struct devlink_sb_port_pool_get_list *
devlink_sb_port_pool_get_dump(struct ynl_sock * ys,struct devlink_sb_port_pool_get_req_dump * req)118034493336SJiri Pirko devlink_sb_port_pool_get_dump(struct ynl_sock *ys,
118134493336SJiri Pirko struct devlink_sb_port_pool_get_req_dump *req)
11827199c862SJiri Pirko {
11837199c862SJiri Pirko struct ynl_dump_state yds = {};
11847199c862SJiri Pirko struct nlmsghdr *nlh;
11857199c862SJiri Pirko int err;
11867199c862SJiri Pirko
11877199c862SJiri Pirko yds.ys = ys;
11887199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_sb_port_pool_get_list);
11897199c862SJiri Pirko yds.cb = devlink_sb_port_pool_get_rsp_parse;
1190*0f4d44f6SJiri Pirko yds.rsp_cmd = 21;
11917199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
11927199c862SJiri Pirko
11937199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_PORT_POOL_GET, 1);
119434493336SJiri Pirko ys->req_policy = &devlink_nest;
119534493336SJiri Pirko
119634493336SJiri Pirko if (req->_present.bus_name_len)
119734493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
119834493336SJiri Pirko if (req->_present.dev_name_len)
119934493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
12007199c862SJiri Pirko
12017199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
12027199c862SJiri Pirko if (err < 0)
12037199c862SJiri Pirko goto free_list;
12047199c862SJiri Pirko
12057199c862SJiri Pirko return yds.first;
12067199c862SJiri Pirko
12077199c862SJiri Pirko free_list:
12087199c862SJiri Pirko devlink_sb_port_pool_get_list_free(yds.first);
12097199c862SJiri Pirko return NULL;
12107199c862SJiri Pirko }
12117199c862SJiri Pirko
12127199c862SJiri Pirko /* ============== DEVLINK_CMD_SB_TC_POOL_BIND_GET ============== */
12137199c862SJiri Pirko /* DEVLINK_CMD_SB_TC_POOL_BIND_GET - do */
12147199c862SJiri Pirko void
devlink_sb_tc_pool_bind_get_req_free(struct devlink_sb_tc_pool_bind_get_req * req)12157199c862SJiri Pirko devlink_sb_tc_pool_bind_get_req_free(struct devlink_sb_tc_pool_bind_get_req *req)
12167199c862SJiri Pirko {
12177199c862SJiri Pirko free(req->bus_name);
12187199c862SJiri Pirko free(req->dev_name);
12197199c862SJiri Pirko free(req);
12207199c862SJiri Pirko }
12217199c862SJiri Pirko
12227199c862SJiri Pirko void
devlink_sb_tc_pool_bind_get_rsp_free(struct devlink_sb_tc_pool_bind_get_rsp * rsp)12237199c862SJiri Pirko devlink_sb_tc_pool_bind_get_rsp_free(struct devlink_sb_tc_pool_bind_get_rsp *rsp)
12247199c862SJiri Pirko {
12257199c862SJiri Pirko free(rsp->bus_name);
12267199c862SJiri Pirko free(rsp->dev_name);
12277199c862SJiri Pirko free(rsp);
12287199c862SJiri Pirko }
12297199c862SJiri Pirko
devlink_sb_tc_pool_bind_get_rsp_parse(const struct nlmsghdr * nlh,void * data)12307199c862SJiri Pirko int devlink_sb_tc_pool_bind_get_rsp_parse(const struct nlmsghdr *nlh,
12317199c862SJiri Pirko void *data)
12327199c862SJiri Pirko {
12337199c862SJiri Pirko struct devlink_sb_tc_pool_bind_get_rsp *dst;
12347199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
12357199c862SJiri Pirko const struct nlattr *attr;
12367199c862SJiri Pirko
12377199c862SJiri Pirko dst = yarg->data;
12387199c862SJiri Pirko
12397199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
12407199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
12417199c862SJiri Pirko
12427199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
12437199c862SJiri Pirko unsigned int len;
12447199c862SJiri Pirko
12457199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
12467199c862SJiri Pirko return MNL_CB_ERROR;
12477199c862SJiri Pirko
12487199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
12497199c862SJiri Pirko dst->_present.bus_name_len = len;
12507199c862SJiri Pirko dst->bus_name = malloc(len + 1);
12517199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
12527199c862SJiri Pirko dst->bus_name[len] = 0;
12537199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
12547199c862SJiri Pirko unsigned int len;
12557199c862SJiri Pirko
12567199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
12577199c862SJiri Pirko return MNL_CB_ERROR;
12587199c862SJiri Pirko
12597199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
12607199c862SJiri Pirko dst->_present.dev_name_len = len;
12617199c862SJiri Pirko dst->dev_name = malloc(len + 1);
12627199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
12637199c862SJiri Pirko dst->dev_name[len] = 0;
12647199c862SJiri Pirko } else if (type == DEVLINK_ATTR_PORT_INDEX) {
12657199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
12667199c862SJiri Pirko return MNL_CB_ERROR;
12677199c862SJiri Pirko dst->_present.port_index = 1;
12687199c862SJiri Pirko dst->port_index = mnl_attr_get_u32(attr);
12697199c862SJiri Pirko } else if (type == DEVLINK_ATTR_SB_INDEX) {
12707199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
12717199c862SJiri Pirko return MNL_CB_ERROR;
12727199c862SJiri Pirko dst->_present.sb_index = 1;
12737199c862SJiri Pirko dst->sb_index = mnl_attr_get_u32(attr);
12747199c862SJiri Pirko } else if (type == DEVLINK_ATTR_SB_POOL_TYPE) {
12757199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
12767199c862SJiri Pirko return MNL_CB_ERROR;
12777199c862SJiri Pirko dst->_present.sb_pool_type = 1;
12787199c862SJiri Pirko dst->sb_pool_type = mnl_attr_get_u8(attr);
12797199c862SJiri Pirko } else if (type == DEVLINK_ATTR_SB_TC_INDEX) {
12807199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
12817199c862SJiri Pirko return MNL_CB_ERROR;
12827199c862SJiri Pirko dst->_present.sb_tc_index = 1;
12837199c862SJiri Pirko dst->sb_tc_index = mnl_attr_get_u16(attr);
12847199c862SJiri Pirko }
12857199c862SJiri Pirko }
12867199c862SJiri Pirko
12877199c862SJiri Pirko return MNL_CB_OK;
12887199c862SJiri Pirko }
12897199c862SJiri Pirko
12907199c862SJiri Pirko struct devlink_sb_tc_pool_bind_get_rsp *
devlink_sb_tc_pool_bind_get(struct ynl_sock * ys,struct devlink_sb_tc_pool_bind_get_req * req)12917199c862SJiri Pirko devlink_sb_tc_pool_bind_get(struct ynl_sock *ys,
12927199c862SJiri Pirko struct devlink_sb_tc_pool_bind_get_req *req)
12937199c862SJiri Pirko {
12947199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
12957199c862SJiri Pirko struct devlink_sb_tc_pool_bind_get_rsp *rsp;
12967199c862SJiri Pirko struct nlmsghdr *nlh;
12977199c862SJiri Pirko int err;
12987199c862SJiri Pirko
12997199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_TC_POOL_BIND_GET, 1);
13007199c862SJiri Pirko ys->req_policy = &devlink_nest;
13017199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
13027199c862SJiri Pirko
13037199c862SJiri Pirko if (req->_present.bus_name_len)
13047199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
13057199c862SJiri Pirko if (req->_present.dev_name_len)
13067199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
13077199c862SJiri Pirko if (req->_present.port_index)
13087199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
13097199c862SJiri Pirko if (req->_present.sb_index)
13107199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
13117199c862SJiri Pirko if (req->_present.sb_pool_type)
13127199c862SJiri Pirko mnl_attr_put_u8(nlh, DEVLINK_ATTR_SB_POOL_TYPE, req->sb_pool_type);
13137199c862SJiri Pirko if (req->_present.sb_tc_index)
13147199c862SJiri Pirko mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_TC_INDEX, req->sb_tc_index);
13157199c862SJiri Pirko
13167199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
13177199c862SJiri Pirko yrs.yarg.data = rsp;
13187199c862SJiri Pirko yrs.cb = devlink_sb_tc_pool_bind_get_rsp_parse;
1319*0f4d44f6SJiri Pirko yrs.rsp_cmd = 25;
13207199c862SJiri Pirko
13217199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
13227199c862SJiri Pirko if (err < 0)
13237199c862SJiri Pirko goto err_free;
13247199c862SJiri Pirko
13257199c862SJiri Pirko return rsp;
13267199c862SJiri Pirko
13277199c862SJiri Pirko err_free:
13287199c862SJiri Pirko devlink_sb_tc_pool_bind_get_rsp_free(rsp);
13297199c862SJiri Pirko return NULL;
13307199c862SJiri Pirko }
13317199c862SJiri Pirko
13327199c862SJiri Pirko /* DEVLINK_CMD_SB_TC_POOL_BIND_GET - dump */
13337199c862SJiri Pirko void
devlink_sb_tc_pool_bind_get_list_free(struct devlink_sb_tc_pool_bind_get_list * rsp)13347199c862SJiri Pirko devlink_sb_tc_pool_bind_get_list_free(struct devlink_sb_tc_pool_bind_get_list *rsp)
13357199c862SJiri Pirko {
13367199c862SJiri Pirko struct devlink_sb_tc_pool_bind_get_list *next = rsp;
13377199c862SJiri Pirko
13387199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
13397199c862SJiri Pirko rsp = next;
13407199c862SJiri Pirko next = rsp->next;
13417199c862SJiri Pirko
13427199c862SJiri Pirko free(rsp->obj.bus_name);
13437199c862SJiri Pirko free(rsp->obj.dev_name);
13447199c862SJiri Pirko free(rsp);
13457199c862SJiri Pirko }
13467199c862SJiri Pirko }
13477199c862SJiri Pirko
13487199c862SJiri Pirko struct devlink_sb_tc_pool_bind_get_list *
devlink_sb_tc_pool_bind_get_dump(struct ynl_sock * ys,struct devlink_sb_tc_pool_bind_get_req_dump * req)134934493336SJiri Pirko devlink_sb_tc_pool_bind_get_dump(struct ynl_sock *ys,
135034493336SJiri Pirko struct devlink_sb_tc_pool_bind_get_req_dump *req)
13517199c862SJiri Pirko {
13527199c862SJiri Pirko struct ynl_dump_state yds = {};
13537199c862SJiri Pirko struct nlmsghdr *nlh;
13547199c862SJiri Pirko int err;
13557199c862SJiri Pirko
13567199c862SJiri Pirko yds.ys = ys;
13577199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_sb_tc_pool_bind_get_list);
13587199c862SJiri Pirko yds.cb = devlink_sb_tc_pool_bind_get_rsp_parse;
1359*0f4d44f6SJiri Pirko yds.rsp_cmd = 25;
13607199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
13617199c862SJiri Pirko
13627199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_TC_POOL_BIND_GET, 1);
136334493336SJiri Pirko ys->req_policy = &devlink_nest;
136434493336SJiri Pirko
136534493336SJiri Pirko if (req->_present.bus_name_len)
136634493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
136734493336SJiri Pirko if (req->_present.dev_name_len)
136834493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
13697199c862SJiri Pirko
13707199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
13717199c862SJiri Pirko if (err < 0)
13727199c862SJiri Pirko goto free_list;
13737199c862SJiri Pirko
13747199c862SJiri Pirko return yds.first;
13757199c862SJiri Pirko
13767199c862SJiri Pirko free_list:
13777199c862SJiri Pirko devlink_sb_tc_pool_bind_get_list_free(yds.first);
13787199c862SJiri Pirko return NULL;
13797199c862SJiri Pirko }
13807199c862SJiri Pirko
13817199c862SJiri Pirko /* ============== DEVLINK_CMD_PARAM_GET ============== */
13827199c862SJiri Pirko /* DEVLINK_CMD_PARAM_GET - do */
devlink_param_get_req_free(struct devlink_param_get_req * req)13837199c862SJiri Pirko void devlink_param_get_req_free(struct devlink_param_get_req *req)
13847199c862SJiri Pirko {
13857199c862SJiri Pirko free(req->bus_name);
13867199c862SJiri Pirko free(req->dev_name);
13877199c862SJiri Pirko free(req->param_name);
13887199c862SJiri Pirko free(req);
13897199c862SJiri Pirko }
13907199c862SJiri Pirko
devlink_param_get_rsp_free(struct devlink_param_get_rsp * rsp)13917199c862SJiri Pirko void devlink_param_get_rsp_free(struct devlink_param_get_rsp *rsp)
13927199c862SJiri Pirko {
13937199c862SJiri Pirko free(rsp->bus_name);
13947199c862SJiri Pirko free(rsp->dev_name);
13957199c862SJiri Pirko free(rsp->param_name);
13967199c862SJiri Pirko free(rsp);
13977199c862SJiri Pirko }
13987199c862SJiri Pirko
devlink_param_get_rsp_parse(const struct nlmsghdr * nlh,void * data)13997199c862SJiri Pirko int devlink_param_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
14007199c862SJiri Pirko {
14017199c862SJiri Pirko struct devlink_param_get_rsp *dst;
14027199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
14037199c862SJiri Pirko const struct nlattr *attr;
14047199c862SJiri Pirko
14057199c862SJiri Pirko dst = yarg->data;
14067199c862SJiri Pirko
14077199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
14087199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
14097199c862SJiri Pirko
14107199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
14117199c862SJiri Pirko unsigned int len;
14127199c862SJiri Pirko
14137199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
14147199c862SJiri Pirko return MNL_CB_ERROR;
14157199c862SJiri Pirko
14167199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
14177199c862SJiri Pirko dst->_present.bus_name_len = len;
14187199c862SJiri Pirko dst->bus_name = malloc(len + 1);
14197199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
14207199c862SJiri Pirko dst->bus_name[len] = 0;
14217199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
14227199c862SJiri Pirko unsigned int len;
14237199c862SJiri Pirko
14247199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
14257199c862SJiri Pirko return MNL_CB_ERROR;
14267199c862SJiri Pirko
14277199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
14287199c862SJiri Pirko dst->_present.dev_name_len = len;
14297199c862SJiri Pirko dst->dev_name = malloc(len + 1);
14307199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
14317199c862SJiri Pirko dst->dev_name[len] = 0;
14327199c862SJiri Pirko } else if (type == DEVLINK_ATTR_PARAM_NAME) {
14337199c862SJiri Pirko unsigned int len;
14347199c862SJiri Pirko
14357199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
14367199c862SJiri Pirko return MNL_CB_ERROR;
14377199c862SJiri Pirko
14387199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
14397199c862SJiri Pirko dst->_present.param_name_len = len;
14407199c862SJiri Pirko dst->param_name = malloc(len + 1);
14417199c862SJiri Pirko memcpy(dst->param_name, mnl_attr_get_str(attr), len);
14427199c862SJiri Pirko dst->param_name[len] = 0;
14437199c862SJiri Pirko }
14447199c862SJiri Pirko }
14457199c862SJiri Pirko
14467199c862SJiri Pirko return MNL_CB_OK;
14477199c862SJiri Pirko }
14487199c862SJiri Pirko
14497199c862SJiri Pirko struct devlink_param_get_rsp *
devlink_param_get(struct ynl_sock * ys,struct devlink_param_get_req * req)14507199c862SJiri Pirko devlink_param_get(struct ynl_sock *ys, struct devlink_param_get_req *req)
14517199c862SJiri Pirko {
14527199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
14537199c862SJiri Pirko struct devlink_param_get_rsp *rsp;
14547199c862SJiri Pirko struct nlmsghdr *nlh;
14557199c862SJiri Pirko int err;
14567199c862SJiri Pirko
14577199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PARAM_GET, 1);
14587199c862SJiri Pirko ys->req_policy = &devlink_nest;
14597199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
14607199c862SJiri Pirko
14617199c862SJiri Pirko if (req->_present.bus_name_len)
14627199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
14637199c862SJiri Pirko if (req->_present.dev_name_len)
14647199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
14657199c862SJiri Pirko if (req->_present.param_name_len)
14667199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_NAME, req->param_name);
14677199c862SJiri Pirko
14687199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
14697199c862SJiri Pirko yrs.yarg.data = rsp;
14707199c862SJiri Pirko yrs.cb = devlink_param_get_rsp_parse;
14717199c862SJiri Pirko yrs.rsp_cmd = DEVLINK_CMD_PARAM_GET;
14727199c862SJiri Pirko
14737199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
14747199c862SJiri Pirko if (err < 0)
14757199c862SJiri Pirko goto err_free;
14767199c862SJiri Pirko
14777199c862SJiri Pirko return rsp;
14787199c862SJiri Pirko
14797199c862SJiri Pirko err_free:
14807199c862SJiri Pirko devlink_param_get_rsp_free(rsp);
14817199c862SJiri Pirko return NULL;
14827199c862SJiri Pirko }
14837199c862SJiri Pirko
14847199c862SJiri Pirko /* DEVLINK_CMD_PARAM_GET - dump */
devlink_param_get_list_free(struct devlink_param_get_list * rsp)14857199c862SJiri Pirko void devlink_param_get_list_free(struct devlink_param_get_list *rsp)
14867199c862SJiri Pirko {
14877199c862SJiri Pirko struct devlink_param_get_list *next = rsp;
14887199c862SJiri Pirko
14897199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
14907199c862SJiri Pirko rsp = next;
14917199c862SJiri Pirko next = rsp->next;
14927199c862SJiri Pirko
14937199c862SJiri Pirko free(rsp->obj.bus_name);
14947199c862SJiri Pirko free(rsp->obj.dev_name);
14957199c862SJiri Pirko free(rsp->obj.param_name);
14967199c862SJiri Pirko free(rsp);
14977199c862SJiri Pirko }
14987199c862SJiri Pirko }
14997199c862SJiri Pirko
150034493336SJiri Pirko struct devlink_param_get_list *
devlink_param_get_dump(struct ynl_sock * ys,struct devlink_param_get_req_dump * req)150134493336SJiri Pirko devlink_param_get_dump(struct ynl_sock *ys,
150234493336SJiri Pirko struct devlink_param_get_req_dump *req)
15037199c862SJiri Pirko {
15047199c862SJiri Pirko struct ynl_dump_state yds = {};
15057199c862SJiri Pirko struct nlmsghdr *nlh;
15067199c862SJiri Pirko int err;
15077199c862SJiri Pirko
15087199c862SJiri Pirko yds.ys = ys;
15097199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_param_get_list);
15107199c862SJiri Pirko yds.cb = devlink_param_get_rsp_parse;
15117199c862SJiri Pirko yds.rsp_cmd = DEVLINK_CMD_PARAM_GET;
15127199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
15137199c862SJiri Pirko
15147199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_PARAM_GET, 1);
151534493336SJiri Pirko ys->req_policy = &devlink_nest;
151634493336SJiri Pirko
151734493336SJiri Pirko if (req->_present.bus_name_len)
151834493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
151934493336SJiri Pirko if (req->_present.dev_name_len)
152034493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
15217199c862SJiri Pirko
15227199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
15237199c862SJiri Pirko if (err < 0)
15247199c862SJiri Pirko goto free_list;
15257199c862SJiri Pirko
15267199c862SJiri Pirko return yds.first;
15277199c862SJiri Pirko
15287199c862SJiri Pirko free_list:
15297199c862SJiri Pirko devlink_param_get_list_free(yds.first);
15307199c862SJiri Pirko return NULL;
15317199c862SJiri Pirko }
15327199c862SJiri Pirko
15337199c862SJiri Pirko /* ============== DEVLINK_CMD_REGION_GET ============== */
15347199c862SJiri Pirko /* DEVLINK_CMD_REGION_GET - do */
devlink_region_get_req_free(struct devlink_region_get_req * req)15357199c862SJiri Pirko void devlink_region_get_req_free(struct devlink_region_get_req *req)
15367199c862SJiri Pirko {
15377199c862SJiri Pirko free(req->bus_name);
15387199c862SJiri Pirko free(req->dev_name);
15397199c862SJiri Pirko free(req->region_name);
15407199c862SJiri Pirko free(req);
15417199c862SJiri Pirko }
15427199c862SJiri Pirko
devlink_region_get_rsp_free(struct devlink_region_get_rsp * rsp)15437199c862SJiri Pirko void devlink_region_get_rsp_free(struct devlink_region_get_rsp *rsp)
15447199c862SJiri Pirko {
15457199c862SJiri Pirko free(rsp->bus_name);
15467199c862SJiri Pirko free(rsp->dev_name);
15477199c862SJiri Pirko free(rsp->region_name);
15487199c862SJiri Pirko free(rsp);
15497199c862SJiri Pirko }
15507199c862SJiri Pirko
devlink_region_get_rsp_parse(const struct nlmsghdr * nlh,void * data)15517199c862SJiri Pirko int devlink_region_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
15527199c862SJiri Pirko {
15537199c862SJiri Pirko struct devlink_region_get_rsp *dst;
15547199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
15557199c862SJiri Pirko const struct nlattr *attr;
15567199c862SJiri Pirko
15577199c862SJiri Pirko dst = yarg->data;
15587199c862SJiri Pirko
15597199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
15607199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
15617199c862SJiri Pirko
15627199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
15637199c862SJiri Pirko unsigned int len;
15647199c862SJiri Pirko
15657199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
15667199c862SJiri Pirko return MNL_CB_ERROR;
15677199c862SJiri Pirko
15687199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
15697199c862SJiri Pirko dst->_present.bus_name_len = len;
15707199c862SJiri Pirko dst->bus_name = malloc(len + 1);
15717199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
15727199c862SJiri Pirko dst->bus_name[len] = 0;
15737199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
15747199c862SJiri Pirko unsigned int len;
15757199c862SJiri Pirko
15767199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
15777199c862SJiri Pirko return MNL_CB_ERROR;
15787199c862SJiri Pirko
15797199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
15807199c862SJiri Pirko dst->_present.dev_name_len = len;
15817199c862SJiri Pirko dst->dev_name = malloc(len + 1);
15827199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
15837199c862SJiri Pirko dst->dev_name[len] = 0;
15847199c862SJiri Pirko } else if (type == DEVLINK_ATTR_PORT_INDEX) {
15857199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
15867199c862SJiri Pirko return MNL_CB_ERROR;
15877199c862SJiri Pirko dst->_present.port_index = 1;
15887199c862SJiri Pirko dst->port_index = mnl_attr_get_u32(attr);
15897199c862SJiri Pirko } else if (type == DEVLINK_ATTR_REGION_NAME) {
15907199c862SJiri Pirko unsigned int len;
15917199c862SJiri Pirko
15927199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
15937199c862SJiri Pirko return MNL_CB_ERROR;
15947199c862SJiri Pirko
15957199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
15967199c862SJiri Pirko dst->_present.region_name_len = len;
15977199c862SJiri Pirko dst->region_name = malloc(len + 1);
15987199c862SJiri Pirko memcpy(dst->region_name, mnl_attr_get_str(attr), len);
15997199c862SJiri Pirko dst->region_name[len] = 0;
16007199c862SJiri Pirko }
16017199c862SJiri Pirko }
16027199c862SJiri Pirko
16037199c862SJiri Pirko return MNL_CB_OK;
16047199c862SJiri Pirko }
16057199c862SJiri Pirko
16067199c862SJiri Pirko struct devlink_region_get_rsp *
devlink_region_get(struct ynl_sock * ys,struct devlink_region_get_req * req)16077199c862SJiri Pirko devlink_region_get(struct ynl_sock *ys, struct devlink_region_get_req *req)
16087199c862SJiri Pirko {
16097199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
16107199c862SJiri Pirko struct devlink_region_get_rsp *rsp;
16117199c862SJiri Pirko struct nlmsghdr *nlh;
16127199c862SJiri Pirko int err;
16137199c862SJiri Pirko
16147199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_REGION_GET, 1);
16157199c862SJiri Pirko ys->req_policy = &devlink_nest;
16167199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
16177199c862SJiri Pirko
16187199c862SJiri Pirko if (req->_present.bus_name_len)
16197199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
16207199c862SJiri Pirko if (req->_present.dev_name_len)
16217199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
16227199c862SJiri Pirko if (req->_present.port_index)
16237199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
16247199c862SJiri Pirko if (req->_present.region_name_len)
16257199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, req->region_name);
16267199c862SJiri Pirko
16277199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
16287199c862SJiri Pirko yrs.yarg.data = rsp;
16297199c862SJiri Pirko yrs.cb = devlink_region_get_rsp_parse;
16307199c862SJiri Pirko yrs.rsp_cmd = DEVLINK_CMD_REGION_GET;
16317199c862SJiri Pirko
16327199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
16337199c862SJiri Pirko if (err < 0)
16347199c862SJiri Pirko goto err_free;
16357199c862SJiri Pirko
16367199c862SJiri Pirko return rsp;
16377199c862SJiri Pirko
16387199c862SJiri Pirko err_free:
16397199c862SJiri Pirko devlink_region_get_rsp_free(rsp);
16407199c862SJiri Pirko return NULL;
16417199c862SJiri Pirko }
16427199c862SJiri Pirko
16437199c862SJiri Pirko /* DEVLINK_CMD_REGION_GET - dump */
devlink_region_get_list_free(struct devlink_region_get_list * rsp)16447199c862SJiri Pirko void devlink_region_get_list_free(struct devlink_region_get_list *rsp)
16457199c862SJiri Pirko {
16467199c862SJiri Pirko struct devlink_region_get_list *next = rsp;
16477199c862SJiri Pirko
16487199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
16497199c862SJiri Pirko rsp = next;
16507199c862SJiri Pirko next = rsp->next;
16517199c862SJiri Pirko
16527199c862SJiri Pirko free(rsp->obj.bus_name);
16537199c862SJiri Pirko free(rsp->obj.dev_name);
16547199c862SJiri Pirko free(rsp->obj.region_name);
16557199c862SJiri Pirko free(rsp);
16567199c862SJiri Pirko }
16577199c862SJiri Pirko }
16587199c862SJiri Pirko
165934493336SJiri Pirko struct devlink_region_get_list *
devlink_region_get_dump(struct ynl_sock * ys,struct devlink_region_get_req_dump * req)166034493336SJiri Pirko devlink_region_get_dump(struct ynl_sock *ys,
166134493336SJiri Pirko struct devlink_region_get_req_dump *req)
16627199c862SJiri Pirko {
16637199c862SJiri Pirko struct ynl_dump_state yds = {};
16647199c862SJiri Pirko struct nlmsghdr *nlh;
16657199c862SJiri Pirko int err;
16667199c862SJiri Pirko
16677199c862SJiri Pirko yds.ys = ys;
16687199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_region_get_list);
16697199c862SJiri Pirko yds.cb = devlink_region_get_rsp_parse;
16707199c862SJiri Pirko yds.rsp_cmd = DEVLINK_CMD_REGION_GET;
16717199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
16727199c862SJiri Pirko
16737199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_REGION_GET, 1);
167434493336SJiri Pirko ys->req_policy = &devlink_nest;
167534493336SJiri Pirko
167634493336SJiri Pirko if (req->_present.bus_name_len)
167734493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
167834493336SJiri Pirko if (req->_present.dev_name_len)
167934493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
16807199c862SJiri Pirko
16817199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
16827199c862SJiri Pirko if (err < 0)
16837199c862SJiri Pirko goto free_list;
16847199c862SJiri Pirko
16857199c862SJiri Pirko return yds.first;
16867199c862SJiri Pirko
16877199c862SJiri Pirko free_list:
16887199c862SJiri Pirko devlink_region_get_list_free(yds.first);
16897199c862SJiri Pirko return NULL;
16907199c862SJiri Pirko }
16917199c862SJiri Pirko
16925d1a30ebSJakub Kicinski /* ============== DEVLINK_CMD_INFO_GET ============== */
16935d1a30ebSJakub Kicinski /* DEVLINK_CMD_INFO_GET - do */
devlink_info_get_req_free(struct devlink_info_get_req * req)16945d1a30ebSJakub Kicinski void devlink_info_get_req_free(struct devlink_info_get_req *req)
16955d1a30ebSJakub Kicinski {
16965d1a30ebSJakub Kicinski free(req->bus_name);
16975d1a30ebSJakub Kicinski free(req->dev_name);
16985d1a30ebSJakub Kicinski free(req);
16995d1a30ebSJakub Kicinski }
17005d1a30ebSJakub Kicinski
devlink_info_get_rsp_free(struct devlink_info_get_rsp * rsp)17015d1a30ebSJakub Kicinski void devlink_info_get_rsp_free(struct devlink_info_get_rsp *rsp)
17025d1a30ebSJakub Kicinski {
17035d1a30ebSJakub Kicinski unsigned int i;
17045d1a30ebSJakub Kicinski
17055d1a30ebSJakub Kicinski free(rsp->bus_name);
17065d1a30ebSJakub Kicinski free(rsp->dev_name);
17075d1a30ebSJakub Kicinski free(rsp->info_driver_name);
17085d1a30ebSJakub Kicinski free(rsp->info_serial_number);
17095d1a30ebSJakub Kicinski for (i = 0; i < rsp->n_info_version_fixed; i++)
17105d1a30ebSJakub Kicinski devlink_dl_info_version_free(&rsp->info_version_fixed[i]);
17115d1a30ebSJakub Kicinski free(rsp->info_version_fixed);
17125d1a30ebSJakub Kicinski for (i = 0; i < rsp->n_info_version_running; i++)
17135d1a30ebSJakub Kicinski devlink_dl_info_version_free(&rsp->info_version_running[i]);
17145d1a30ebSJakub Kicinski free(rsp->info_version_running);
17155d1a30ebSJakub Kicinski for (i = 0; i < rsp->n_info_version_stored; i++)
17165d1a30ebSJakub Kicinski devlink_dl_info_version_free(&rsp->info_version_stored[i]);
17175d1a30ebSJakub Kicinski free(rsp->info_version_stored);
17185d1a30ebSJakub Kicinski free(rsp);
17195d1a30ebSJakub Kicinski }
17205d1a30ebSJakub Kicinski
devlink_info_get_rsp_parse(const struct nlmsghdr * nlh,void * data)17215d1a30ebSJakub Kicinski int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
17225d1a30ebSJakub Kicinski {
17235d1a30ebSJakub Kicinski unsigned int n_info_version_running = 0;
17245d1a30ebSJakub Kicinski unsigned int n_info_version_stored = 0;
17255d1a30ebSJakub Kicinski unsigned int n_info_version_fixed = 0;
17265d1a30ebSJakub Kicinski struct ynl_parse_arg *yarg = data;
17275d1a30ebSJakub Kicinski struct devlink_info_get_rsp *dst;
17285d1a30ebSJakub Kicinski const struct nlattr *attr;
17295d1a30ebSJakub Kicinski struct ynl_parse_arg parg;
17305d1a30ebSJakub Kicinski int i;
17315d1a30ebSJakub Kicinski
17325d1a30ebSJakub Kicinski dst = yarg->data;
17335d1a30ebSJakub Kicinski parg.ys = yarg->ys;
17345d1a30ebSJakub Kicinski
17355d1a30ebSJakub Kicinski if (dst->info_version_fixed)
17365d1a30ebSJakub Kicinski return ynl_error_parse(yarg, "attribute already present (devlink.info-version-fixed)");
17375d1a30ebSJakub Kicinski if (dst->info_version_running)
17385d1a30ebSJakub Kicinski return ynl_error_parse(yarg, "attribute already present (devlink.info-version-running)");
17395d1a30ebSJakub Kicinski if (dst->info_version_stored)
17405d1a30ebSJakub Kicinski return ynl_error_parse(yarg, "attribute already present (devlink.info-version-stored)");
17415d1a30ebSJakub Kicinski
17425d1a30ebSJakub Kicinski mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
17437234415bSJakub Kicinski unsigned int type = mnl_attr_get_type(attr);
17447234415bSJakub Kicinski
17457234415bSJakub Kicinski if (type == DEVLINK_ATTR_BUS_NAME) {
17465d1a30ebSJakub Kicinski unsigned int len;
17475d1a30ebSJakub Kicinski
17485d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
17495d1a30ebSJakub Kicinski return MNL_CB_ERROR;
17505d1a30ebSJakub Kicinski
17515d1a30ebSJakub Kicinski len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
17525d1a30ebSJakub Kicinski dst->_present.bus_name_len = len;
17535d1a30ebSJakub Kicinski dst->bus_name = malloc(len + 1);
17545d1a30ebSJakub Kicinski memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
17555d1a30ebSJakub Kicinski dst->bus_name[len] = 0;
17567234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_DEV_NAME) {
17575d1a30ebSJakub Kicinski unsigned int len;
17585d1a30ebSJakub Kicinski
17595d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
17605d1a30ebSJakub Kicinski return MNL_CB_ERROR;
17615d1a30ebSJakub Kicinski
17625d1a30ebSJakub Kicinski len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
17635d1a30ebSJakub Kicinski dst->_present.dev_name_len = len;
17645d1a30ebSJakub Kicinski dst->dev_name = malloc(len + 1);
17655d1a30ebSJakub Kicinski memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
17665d1a30ebSJakub Kicinski dst->dev_name[len] = 0;
17677234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_INFO_DRIVER_NAME) {
17685d1a30ebSJakub Kicinski unsigned int len;
17695d1a30ebSJakub Kicinski
17705d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
17715d1a30ebSJakub Kicinski return MNL_CB_ERROR;
17725d1a30ebSJakub Kicinski
17735d1a30ebSJakub Kicinski len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
17745d1a30ebSJakub Kicinski dst->_present.info_driver_name_len = len;
17755d1a30ebSJakub Kicinski dst->info_driver_name = malloc(len + 1);
17765d1a30ebSJakub Kicinski memcpy(dst->info_driver_name, mnl_attr_get_str(attr), len);
17775d1a30ebSJakub Kicinski dst->info_driver_name[len] = 0;
17787234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_INFO_SERIAL_NUMBER) {
17795d1a30ebSJakub Kicinski unsigned int len;
17805d1a30ebSJakub Kicinski
17815d1a30ebSJakub Kicinski if (ynl_attr_validate(yarg, attr))
17825d1a30ebSJakub Kicinski return MNL_CB_ERROR;
17835d1a30ebSJakub Kicinski
17845d1a30ebSJakub Kicinski len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
17855d1a30ebSJakub Kicinski dst->_present.info_serial_number_len = len;
17865d1a30ebSJakub Kicinski dst->info_serial_number = malloc(len + 1);
17875d1a30ebSJakub Kicinski memcpy(dst->info_serial_number, mnl_attr_get_str(attr), len);
17885d1a30ebSJakub Kicinski dst->info_serial_number[len] = 0;
17897234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_INFO_VERSION_FIXED) {
17905d1a30ebSJakub Kicinski n_info_version_fixed++;
17917234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_INFO_VERSION_RUNNING) {
17925d1a30ebSJakub Kicinski n_info_version_running++;
17937234415bSJakub Kicinski } else if (type == DEVLINK_ATTR_INFO_VERSION_STORED) {
17945d1a30ebSJakub Kicinski n_info_version_stored++;
17955d1a30ebSJakub Kicinski }
17965d1a30ebSJakub Kicinski }
17975d1a30ebSJakub Kicinski
17985d1a30ebSJakub Kicinski if (n_info_version_fixed) {
17995d1a30ebSJakub Kicinski dst->info_version_fixed = calloc(n_info_version_fixed, sizeof(*dst->info_version_fixed));
18005d1a30ebSJakub Kicinski dst->n_info_version_fixed = n_info_version_fixed;
18015d1a30ebSJakub Kicinski i = 0;
18025d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_info_version_nest;
18035d1a30ebSJakub Kicinski mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
18045d1a30ebSJakub Kicinski if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_FIXED) {
18055d1a30ebSJakub Kicinski parg.data = &dst->info_version_fixed[i];
18065d1a30ebSJakub Kicinski if (devlink_dl_info_version_parse(&parg, attr))
18075d1a30ebSJakub Kicinski return MNL_CB_ERROR;
18085d1a30ebSJakub Kicinski i++;
18095d1a30ebSJakub Kicinski }
18105d1a30ebSJakub Kicinski }
18115d1a30ebSJakub Kicinski }
18125d1a30ebSJakub Kicinski if (n_info_version_running) {
18135d1a30ebSJakub Kicinski dst->info_version_running = calloc(n_info_version_running, sizeof(*dst->info_version_running));
18145d1a30ebSJakub Kicinski dst->n_info_version_running = n_info_version_running;
18155d1a30ebSJakub Kicinski i = 0;
18165d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_info_version_nest;
18175d1a30ebSJakub Kicinski mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
18185d1a30ebSJakub Kicinski if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_RUNNING) {
18195d1a30ebSJakub Kicinski parg.data = &dst->info_version_running[i];
18205d1a30ebSJakub Kicinski if (devlink_dl_info_version_parse(&parg, attr))
18215d1a30ebSJakub Kicinski return MNL_CB_ERROR;
18225d1a30ebSJakub Kicinski i++;
18235d1a30ebSJakub Kicinski }
18245d1a30ebSJakub Kicinski }
18255d1a30ebSJakub Kicinski }
18265d1a30ebSJakub Kicinski if (n_info_version_stored) {
18275d1a30ebSJakub Kicinski dst->info_version_stored = calloc(n_info_version_stored, sizeof(*dst->info_version_stored));
18285d1a30ebSJakub Kicinski dst->n_info_version_stored = n_info_version_stored;
18295d1a30ebSJakub Kicinski i = 0;
18305d1a30ebSJakub Kicinski parg.rsp_policy = &devlink_dl_info_version_nest;
18315d1a30ebSJakub Kicinski mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
18325d1a30ebSJakub Kicinski if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_STORED) {
18335d1a30ebSJakub Kicinski parg.data = &dst->info_version_stored[i];
18345d1a30ebSJakub Kicinski if (devlink_dl_info_version_parse(&parg, attr))
18355d1a30ebSJakub Kicinski return MNL_CB_ERROR;
18365d1a30ebSJakub Kicinski i++;
18375d1a30ebSJakub Kicinski }
18385d1a30ebSJakub Kicinski }
18395d1a30ebSJakub Kicinski }
18405d1a30ebSJakub Kicinski
18415d1a30ebSJakub Kicinski return MNL_CB_OK;
18425d1a30ebSJakub Kicinski }
18435d1a30ebSJakub Kicinski
18445d1a30ebSJakub Kicinski struct devlink_info_get_rsp *
devlink_info_get(struct ynl_sock * ys,struct devlink_info_get_req * req)18455d1a30ebSJakub Kicinski devlink_info_get(struct ynl_sock *ys, struct devlink_info_get_req *req)
18465d1a30ebSJakub Kicinski {
18475d1a30ebSJakub Kicinski struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
18485d1a30ebSJakub Kicinski struct devlink_info_get_rsp *rsp;
18495d1a30ebSJakub Kicinski struct nlmsghdr *nlh;
18505d1a30ebSJakub Kicinski int err;
18515d1a30ebSJakub Kicinski
18525d1a30ebSJakub Kicinski nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_INFO_GET, 1);
18535d1a30ebSJakub Kicinski ys->req_policy = &devlink_nest;
18545d1a30ebSJakub Kicinski yrs.yarg.rsp_policy = &devlink_nest;
18555d1a30ebSJakub Kicinski
18565d1a30ebSJakub Kicinski if (req->_present.bus_name_len)
18575d1a30ebSJakub Kicinski mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
18585d1a30ebSJakub Kicinski if (req->_present.dev_name_len)
18595d1a30ebSJakub Kicinski mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
18605d1a30ebSJakub Kicinski
18615d1a30ebSJakub Kicinski rsp = calloc(1, sizeof(*rsp));
18625d1a30ebSJakub Kicinski yrs.yarg.data = rsp;
18635d1a30ebSJakub Kicinski yrs.cb = devlink_info_get_rsp_parse;
18645d1a30ebSJakub Kicinski yrs.rsp_cmd = DEVLINK_CMD_INFO_GET;
18655d1a30ebSJakub Kicinski
18665d1a30ebSJakub Kicinski err = ynl_exec(ys, nlh, &yrs);
18675d1a30ebSJakub Kicinski if (err < 0)
18685d1a30ebSJakub Kicinski goto err_free;
18695d1a30ebSJakub Kicinski
18705d1a30ebSJakub Kicinski return rsp;
18715d1a30ebSJakub Kicinski
18725d1a30ebSJakub Kicinski err_free:
18735d1a30ebSJakub Kicinski devlink_info_get_rsp_free(rsp);
18745d1a30ebSJakub Kicinski return NULL;
18755d1a30ebSJakub Kicinski }
18765d1a30ebSJakub Kicinski
1877759f6610SJiri Pirko /* DEVLINK_CMD_INFO_GET - dump */
devlink_info_get_list_free(struct devlink_info_get_list * rsp)1878759f6610SJiri Pirko void devlink_info_get_list_free(struct devlink_info_get_list *rsp)
1879759f6610SJiri Pirko {
1880759f6610SJiri Pirko struct devlink_info_get_list *next = rsp;
1881759f6610SJiri Pirko
1882759f6610SJiri Pirko while ((void *)next != YNL_LIST_END) {
1883759f6610SJiri Pirko unsigned int i;
1884759f6610SJiri Pirko
1885759f6610SJiri Pirko rsp = next;
1886759f6610SJiri Pirko next = rsp->next;
1887759f6610SJiri Pirko
1888759f6610SJiri Pirko free(rsp->obj.bus_name);
1889759f6610SJiri Pirko free(rsp->obj.dev_name);
1890759f6610SJiri Pirko free(rsp->obj.info_driver_name);
1891759f6610SJiri Pirko free(rsp->obj.info_serial_number);
1892759f6610SJiri Pirko for (i = 0; i < rsp->obj.n_info_version_fixed; i++)
1893759f6610SJiri Pirko devlink_dl_info_version_free(&rsp->obj.info_version_fixed[i]);
1894759f6610SJiri Pirko free(rsp->obj.info_version_fixed);
1895759f6610SJiri Pirko for (i = 0; i < rsp->obj.n_info_version_running; i++)
1896759f6610SJiri Pirko devlink_dl_info_version_free(&rsp->obj.info_version_running[i]);
1897759f6610SJiri Pirko free(rsp->obj.info_version_running);
1898759f6610SJiri Pirko for (i = 0; i < rsp->obj.n_info_version_stored; i++)
1899759f6610SJiri Pirko devlink_dl_info_version_free(&rsp->obj.info_version_stored[i]);
1900759f6610SJiri Pirko free(rsp->obj.info_version_stored);
1901759f6610SJiri Pirko free(rsp);
1902759f6610SJiri Pirko }
1903759f6610SJiri Pirko }
1904759f6610SJiri Pirko
devlink_info_get_dump(struct ynl_sock * ys)1905759f6610SJiri Pirko struct devlink_info_get_list *devlink_info_get_dump(struct ynl_sock *ys)
1906759f6610SJiri Pirko {
1907759f6610SJiri Pirko struct ynl_dump_state yds = {};
1908759f6610SJiri Pirko struct nlmsghdr *nlh;
1909759f6610SJiri Pirko int err;
1910759f6610SJiri Pirko
1911759f6610SJiri Pirko yds.ys = ys;
1912759f6610SJiri Pirko yds.alloc_sz = sizeof(struct devlink_info_get_list);
1913759f6610SJiri Pirko yds.cb = devlink_info_get_rsp_parse;
1914759f6610SJiri Pirko yds.rsp_cmd = DEVLINK_CMD_INFO_GET;
1915759f6610SJiri Pirko yds.rsp_policy = &devlink_nest;
1916759f6610SJiri Pirko
1917759f6610SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_INFO_GET, 1);
1918759f6610SJiri Pirko
1919759f6610SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
1920759f6610SJiri Pirko if (err < 0)
1921759f6610SJiri Pirko goto free_list;
1922759f6610SJiri Pirko
1923759f6610SJiri Pirko return yds.first;
1924759f6610SJiri Pirko
1925759f6610SJiri Pirko free_list:
1926759f6610SJiri Pirko devlink_info_get_list_free(yds.first);
1927759f6610SJiri Pirko return NULL;
1928759f6610SJiri Pirko }
1929759f6610SJiri Pirko
19307199c862SJiri Pirko /* ============== DEVLINK_CMD_HEALTH_REPORTER_GET ============== */
19317199c862SJiri Pirko /* DEVLINK_CMD_HEALTH_REPORTER_GET - do */
19327199c862SJiri Pirko void
devlink_health_reporter_get_req_free(struct devlink_health_reporter_get_req * req)19337199c862SJiri Pirko devlink_health_reporter_get_req_free(struct devlink_health_reporter_get_req *req)
19347199c862SJiri Pirko {
19357199c862SJiri Pirko free(req->bus_name);
19367199c862SJiri Pirko free(req->dev_name);
19377199c862SJiri Pirko free(req->health_reporter_name);
19387199c862SJiri Pirko free(req);
19397199c862SJiri Pirko }
19407199c862SJiri Pirko
19417199c862SJiri Pirko void
devlink_health_reporter_get_rsp_free(struct devlink_health_reporter_get_rsp * rsp)19427199c862SJiri Pirko devlink_health_reporter_get_rsp_free(struct devlink_health_reporter_get_rsp *rsp)
19437199c862SJiri Pirko {
19447199c862SJiri Pirko free(rsp->bus_name);
19457199c862SJiri Pirko free(rsp->dev_name);
19467199c862SJiri Pirko free(rsp->health_reporter_name);
19477199c862SJiri Pirko free(rsp);
19487199c862SJiri Pirko }
19497199c862SJiri Pirko
devlink_health_reporter_get_rsp_parse(const struct nlmsghdr * nlh,void * data)19507199c862SJiri Pirko int devlink_health_reporter_get_rsp_parse(const struct nlmsghdr *nlh,
19517199c862SJiri Pirko void *data)
19527199c862SJiri Pirko {
19537199c862SJiri Pirko struct devlink_health_reporter_get_rsp *dst;
19547199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
19557199c862SJiri Pirko const struct nlattr *attr;
19567199c862SJiri Pirko
19577199c862SJiri Pirko dst = yarg->data;
19587199c862SJiri Pirko
19597199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
19607199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
19617199c862SJiri Pirko
19627199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
19637199c862SJiri Pirko unsigned int len;
19647199c862SJiri Pirko
19657199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
19667199c862SJiri Pirko return MNL_CB_ERROR;
19677199c862SJiri Pirko
19687199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
19697199c862SJiri Pirko dst->_present.bus_name_len = len;
19707199c862SJiri Pirko dst->bus_name = malloc(len + 1);
19717199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
19727199c862SJiri Pirko dst->bus_name[len] = 0;
19737199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
19747199c862SJiri Pirko unsigned int len;
19757199c862SJiri Pirko
19767199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
19777199c862SJiri Pirko return MNL_CB_ERROR;
19787199c862SJiri Pirko
19797199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
19807199c862SJiri Pirko dst->_present.dev_name_len = len;
19817199c862SJiri Pirko dst->dev_name = malloc(len + 1);
19827199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
19837199c862SJiri Pirko dst->dev_name[len] = 0;
19847199c862SJiri Pirko } else if (type == DEVLINK_ATTR_PORT_INDEX) {
19857199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
19867199c862SJiri Pirko return MNL_CB_ERROR;
19877199c862SJiri Pirko dst->_present.port_index = 1;
19887199c862SJiri Pirko dst->port_index = mnl_attr_get_u32(attr);
19897199c862SJiri Pirko } else if (type == DEVLINK_ATTR_HEALTH_REPORTER_NAME) {
19907199c862SJiri Pirko unsigned int len;
19917199c862SJiri Pirko
19927199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
19937199c862SJiri Pirko return MNL_CB_ERROR;
19947199c862SJiri Pirko
19957199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
19967199c862SJiri Pirko dst->_present.health_reporter_name_len = len;
19977199c862SJiri Pirko dst->health_reporter_name = malloc(len + 1);
19987199c862SJiri Pirko memcpy(dst->health_reporter_name, mnl_attr_get_str(attr), len);
19997199c862SJiri Pirko dst->health_reporter_name[len] = 0;
20007199c862SJiri Pirko }
20017199c862SJiri Pirko }
20027199c862SJiri Pirko
20037199c862SJiri Pirko return MNL_CB_OK;
20047199c862SJiri Pirko }
20057199c862SJiri Pirko
20067199c862SJiri Pirko struct devlink_health_reporter_get_rsp *
devlink_health_reporter_get(struct ynl_sock * ys,struct devlink_health_reporter_get_req * req)20077199c862SJiri Pirko devlink_health_reporter_get(struct ynl_sock *ys,
20087199c862SJiri Pirko struct devlink_health_reporter_get_req *req)
20097199c862SJiri Pirko {
20107199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
20117199c862SJiri Pirko struct devlink_health_reporter_get_rsp *rsp;
20127199c862SJiri Pirko struct nlmsghdr *nlh;
20137199c862SJiri Pirko int err;
20147199c862SJiri Pirko
20157199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_GET, 1);
20167199c862SJiri Pirko ys->req_policy = &devlink_nest;
20177199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
20187199c862SJiri Pirko
20197199c862SJiri Pirko if (req->_present.bus_name_len)
20207199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
20217199c862SJiri Pirko if (req->_present.dev_name_len)
20227199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
20237199c862SJiri Pirko if (req->_present.port_index)
20247199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
20257199c862SJiri Pirko if (req->_present.health_reporter_name_len)
20267199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
20277199c862SJiri Pirko
20287199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
20297199c862SJiri Pirko yrs.yarg.data = rsp;
20307199c862SJiri Pirko yrs.cb = devlink_health_reporter_get_rsp_parse;
20317199c862SJiri Pirko yrs.rsp_cmd = DEVLINK_CMD_HEALTH_REPORTER_GET;
20327199c862SJiri Pirko
20337199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
20347199c862SJiri Pirko if (err < 0)
20357199c862SJiri Pirko goto err_free;
20367199c862SJiri Pirko
20377199c862SJiri Pirko return rsp;
20387199c862SJiri Pirko
20397199c862SJiri Pirko err_free:
20407199c862SJiri Pirko devlink_health_reporter_get_rsp_free(rsp);
20417199c862SJiri Pirko return NULL;
20427199c862SJiri Pirko }
20437199c862SJiri Pirko
20447199c862SJiri Pirko /* DEVLINK_CMD_HEALTH_REPORTER_GET - dump */
20457199c862SJiri Pirko void
devlink_health_reporter_get_list_free(struct devlink_health_reporter_get_list * rsp)20467199c862SJiri Pirko devlink_health_reporter_get_list_free(struct devlink_health_reporter_get_list *rsp)
20477199c862SJiri Pirko {
20487199c862SJiri Pirko struct devlink_health_reporter_get_list *next = rsp;
20497199c862SJiri Pirko
20507199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
20517199c862SJiri Pirko rsp = next;
20527199c862SJiri Pirko next = rsp->next;
20537199c862SJiri Pirko
20547199c862SJiri Pirko free(rsp->obj.bus_name);
20557199c862SJiri Pirko free(rsp->obj.dev_name);
20567199c862SJiri Pirko free(rsp->obj.health_reporter_name);
20577199c862SJiri Pirko free(rsp);
20587199c862SJiri Pirko }
20597199c862SJiri Pirko }
20607199c862SJiri Pirko
20617199c862SJiri Pirko struct devlink_health_reporter_get_list *
devlink_health_reporter_get_dump(struct ynl_sock * ys,struct devlink_health_reporter_get_req_dump * req)206234493336SJiri Pirko devlink_health_reporter_get_dump(struct ynl_sock *ys,
206334493336SJiri Pirko struct devlink_health_reporter_get_req_dump *req)
20647199c862SJiri Pirko {
20657199c862SJiri Pirko struct ynl_dump_state yds = {};
20667199c862SJiri Pirko struct nlmsghdr *nlh;
20677199c862SJiri Pirko int err;
20687199c862SJiri Pirko
20697199c862SJiri Pirko yds.ys = ys;
20707199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_health_reporter_get_list);
20717199c862SJiri Pirko yds.cb = devlink_health_reporter_get_rsp_parse;
20727199c862SJiri Pirko yds.rsp_cmd = DEVLINK_CMD_HEALTH_REPORTER_GET;
20737199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
20747199c862SJiri Pirko
20757199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_GET, 1);
207634493336SJiri Pirko ys->req_policy = &devlink_nest;
207734493336SJiri Pirko
207834493336SJiri Pirko if (req->_present.bus_name_len)
207934493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
208034493336SJiri Pirko if (req->_present.dev_name_len)
208134493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
20820149bca1SJiri Pirko if (req->_present.port_index)
20830149bca1SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
20847199c862SJiri Pirko
20857199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
20867199c862SJiri Pirko if (err < 0)
20877199c862SJiri Pirko goto free_list;
20887199c862SJiri Pirko
20897199c862SJiri Pirko return yds.first;
20907199c862SJiri Pirko
20917199c862SJiri Pirko free_list:
20927199c862SJiri Pirko devlink_health_reporter_get_list_free(yds.first);
20937199c862SJiri Pirko return NULL;
20947199c862SJiri Pirko }
20957199c862SJiri Pirko
20967199c862SJiri Pirko /* ============== DEVLINK_CMD_TRAP_GET ============== */
20977199c862SJiri Pirko /* DEVLINK_CMD_TRAP_GET - do */
devlink_trap_get_req_free(struct devlink_trap_get_req * req)20987199c862SJiri Pirko void devlink_trap_get_req_free(struct devlink_trap_get_req *req)
20997199c862SJiri Pirko {
21007199c862SJiri Pirko free(req->bus_name);
21017199c862SJiri Pirko free(req->dev_name);
21027199c862SJiri Pirko free(req->trap_name);
21037199c862SJiri Pirko free(req);
21047199c862SJiri Pirko }
21057199c862SJiri Pirko
devlink_trap_get_rsp_free(struct devlink_trap_get_rsp * rsp)21067199c862SJiri Pirko void devlink_trap_get_rsp_free(struct devlink_trap_get_rsp *rsp)
21077199c862SJiri Pirko {
21087199c862SJiri Pirko free(rsp->bus_name);
21097199c862SJiri Pirko free(rsp->dev_name);
21107199c862SJiri Pirko free(rsp->trap_name);
21117199c862SJiri Pirko free(rsp);
21127199c862SJiri Pirko }
21137199c862SJiri Pirko
devlink_trap_get_rsp_parse(const struct nlmsghdr * nlh,void * data)21147199c862SJiri Pirko int devlink_trap_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
21157199c862SJiri Pirko {
21167199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
21177199c862SJiri Pirko struct devlink_trap_get_rsp *dst;
21187199c862SJiri Pirko const struct nlattr *attr;
21197199c862SJiri Pirko
21207199c862SJiri Pirko dst = yarg->data;
21217199c862SJiri Pirko
21227199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
21237199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
21247199c862SJiri Pirko
21257199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
21267199c862SJiri Pirko unsigned int len;
21277199c862SJiri Pirko
21287199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
21297199c862SJiri Pirko return MNL_CB_ERROR;
21307199c862SJiri Pirko
21317199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
21327199c862SJiri Pirko dst->_present.bus_name_len = len;
21337199c862SJiri Pirko dst->bus_name = malloc(len + 1);
21347199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
21357199c862SJiri Pirko dst->bus_name[len] = 0;
21367199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
21377199c862SJiri Pirko unsigned int len;
21387199c862SJiri Pirko
21397199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
21407199c862SJiri Pirko return MNL_CB_ERROR;
21417199c862SJiri Pirko
21427199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
21437199c862SJiri Pirko dst->_present.dev_name_len = len;
21447199c862SJiri Pirko dst->dev_name = malloc(len + 1);
21457199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
21467199c862SJiri Pirko dst->dev_name[len] = 0;
21477199c862SJiri Pirko } else if (type == DEVLINK_ATTR_TRAP_NAME) {
21487199c862SJiri Pirko unsigned int len;
21497199c862SJiri Pirko
21507199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
21517199c862SJiri Pirko return MNL_CB_ERROR;
21527199c862SJiri Pirko
21537199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
21547199c862SJiri Pirko dst->_present.trap_name_len = len;
21557199c862SJiri Pirko dst->trap_name = malloc(len + 1);
21567199c862SJiri Pirko memcpy(dst->trap_name, mnl_attr_get_str(attr), len);
21577199c862SJiri Pirko dst->trap_name[len] = 0;
21587199c862SJiri Pirko }
21597199c862SJiri Pirko }
21607199c862SJiri Pirko
21617199c862SJiri Pirko return MNL_CB_OK;
21627199c862SJiri Pirko }
21637199c862SJiri Pirko
21647199c862SJiri Pirko struct devlink_trap_get_rsp *
devlink_trap_get(struct ynl_sock * ys,struct devlink_trap_get_req * req)21657199c862SJiri Pirko devlink_trap_get(struct ynl_sock *ys, struct devlink_trap_get_req *req)
21667199c862SJiri Pirko {
21677199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
21687199c862SJiri Pirko struct devlink_trap_get_rsp *rsp;
21697199c862SJiri Pirko struct nlmsghdr *nlh;
21707199c862SJiri Pirko int err;
21717199c862SJiri Pirko
21727199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_GET, 1);
21737199c862SJiri Pirko ys->req_policy = &devlink_nest;
21747199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
21757199c862SJiri Pirko
21767199c862SJiri Pirko if (req->_present.bus_name_len)
21777199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
21787199c862SJiri Pirko if (req->_present.dev_name_len)
21797199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
21807199c862SJiri Pirko if (req->_present.trap_name_len)
21817199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME, req->trap_name);
21827199c862SJiri Pirko
21837199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
21847199c862SJiri Pirko yrs.yarg.data = rsp;
21857199c862SJiri Pirko yrs.cb = devlink_trap_get_rsp_parse;
2186*0f4d44f6SJiri Pirko yrs.rsp_cmd = 63;
21877199c862SJiri Pirko
21887199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
21897199c862SJiri Pirko if (err < 0)
21907199c862SJiri Pirko goto err_free;
21917199c862SJiri Pirko
21927199c862SJiri Pirko return rsp;
21937199c862SJiri Pirko
21947199c862SJiri Pirko err_free:
21957199c862SJiri Pirko devlink_trap_get_rsp_free(rsp);
21967199c862SJiri Pirko return NULL;
21977199c862SJiri Pirko }
21987199c862SJiri Pirko
21997199c862SJiri Pirko /* DEVLINK_CMD_TRAP_GET - dump */
devlink_trap_get_list_free(struct devlink_trap_get_list * rsp)22007199c862SJiri Pirko void devlink_trap_get_list_free(struct devlink_trap_get_list *rsp)
22017199c862SJiri Pirko {
22027199c862SJiri Pirko struct devlink_trap_get_list *next = rsp;
22037199c862SJiri Pirko
22047199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
22057199c862SJiri Pirko rsp = next;
22067199c862SJiri Pirko next = rsp->next;
22077199c862SJiri Pirko
22087199c862SJiri Pirko free(rsp->obj.bus_name);
22097199c862SJiri Pirko free(rsp->obj.dev_name);
22107199c862SJiri Pirko free(rsp->obj.trap_name);
22117199c862SJiri Pirko free(rsp);
22127199c862SJiri Pirko }
22137199c862SJiri Pirko }
22147199c862SJiri Pirko
221534493336SJiri Pirko struct devlink_trap_get_list *
devlink_trap_get_dump(struct ynl_sock * ys,struct devlink_trap_get_req_dump * req)221634493336SJiri Pirko devlink_trap_get_dump(struct ynl_sock *ys,
221734493336SJiri Pirko struct devlink_trap_get_req_dump *req)
22187199c862SJiri Pirko {
22197199c862SJiri Pirko struct ynl_dump_state yds = {};
22207199c862SJiri Pirko struct nlmsghdr *nlh;
22217199c862SJiri Pirko int err;
22227199c862SJiri Pirko
22237199c862SJiri Pirko yds.ys = ys;
22247199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_trap_get_list);
22257199c862SJiri Pirko yds.cb = devlink_trap_get_rsp_parse;
2226*0f4d44f6SJiri Pirko yds.rsp_cmd = 63;
22277199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
22287199c862SJiri Pirko
22297199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_GET, 1);
223034493336SJiri Pirko ys->req_policy = &devlink_nest;
223134493336SJiri Pirko
223234493336SJiri Pirko if (req->_present.bus_name_len)
223334493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
223434493336SJiri Pirko if (req->_present.dev_name_len)
223534493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
22367199c862SJiri Pirko
22377199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
22387199c862SJiri Pirko if (err < 0)
22397199c862SJiri Pirko goto free_list;
22407199c862SJiri Pirko
22417199c862SJiri Pirko return yds.first;
22427199c862SJiri Pirko
22437199c862SJiri Pirko free_list:
22447199c862SJiri Pirko devlink_trap_get_list_free(yds.first);
22457199c862SJiri Pirko return NULL;
22467199c862SJiri Pirko }
22477199c862SJiri Pirko
22487199c862SJiri Pirko /* ============== DEVLINK_CMD_TRAP_GROUP_GET ============== */
22497199c862SJiri Pirko /* DEVLINK_CMD_TRAP_GROUP_GET - do */
devlink_trap_group_get_req_free(struct devlink_trap_group_get_req * req)22507199c862SJiri Pirko void devlink_trap_group_get_req_free(struct devlink_trap_group_get_req *req)
22517199c862SJiri Pirko {
22527199c862SJiri Pirko free(req->bus_name);
22537199c862SJiri Pirko free(req->dev_name);
22547199c862SJiri Pirko free(req->trap_group_name);
22557199c862SJiri Pirko free(req);
22567199c862SJiri Pirko }
22577199c862SJiri Pirko
devlink_trap_group_get_rsp_free(struct devlink_trap_group_get_rsp * rsp)22587199c862SJiri Pirko void devlink_trap_group_get_rsp_free(struct devlink_trap_group_get_rsp *rsp)
22597199c862SJiri Pirko {
22607199c862SJiri Pirko free(rsp->bus_name);
22617199c862SJiri Pirko free(rsp->dev_name);
22627199c862SJiri Pirko free(rsp->trap_group_name);
22637199c862SJiri Pirko free(rsp);
22647199c862SJiri Pirko }
22657199c862SJiri Pirko
devlink_trap_group_get_rsp_parse(const struct nlmsghdr * nlh,void * data)22667199c862SJiri Pirko int devlink_trap_group_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
22677199c862SJiri Pirko {
22687199c862SJiri Pirko struct devlink_trap_group_get_rsp *dst;
22697199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
22707199c862SJiri Pirko const struct nlattr *attr;
22717199c862SJiri Pirko
22727199c862SJiri Pirko dst = yarg->data;
22737199c862SJiri Pirko
22747199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
22757199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
22767199c862SJiri Pirko
22777199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
22787199c862SJiri Pirko unsigned int len;
22797199c862SJiri Pirko
22807199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
22817199c862SJiri Pirko return MNL_CB_ERROR;
22827199c862SJiri Pirko
22837199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
22847199c862SJiri Pirko dst->_present.bus_name_len = len;
22857199c862SJiri Pirko dst->bus_name = malloc(len + 1);
22867199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
22877199c862SJiri Pirko dst->bus_name[len] = 0;
22887199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
22897199c862SJiri Pirko unsigned int len;
22907199c862SJiri Pirko
22917199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
22927199c862SJiri Pirko return MNL_CB_ERROR;
22937199c862SJiri Pirko
22947199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
22957199c862SJiri Pirko dst->_present.dev_name_len = len;
22967199c862SJiri Pirko dst->dev_name = malloc(len + 1);
22977199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
22987199c862SJiri Pirko dst->dev_name[len] = 0;
22997199c862SJiri Pirko } else if (type == DEVLINK_ATTR_TRAP_GROUP_NAME) {
23007199c862SJiri Pirko unsigned int len;
23017199c862SJiri Pirko
23027199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
23037199c862SJiri Pirko return MNL_CB_ERROR;
23047199c862SJiri Pirko
23057199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
23067199c862SJiri Pirko dst->_present.trap_group_name_len = len;
23077199c862SJiri Pirko dst->trap_group_name = malloc(len + 1);
23087199c862SJiri Pirko memcpy(dst->trap_group_name, mnl_attr_get_str(attr), len);
23097199c862SJiri Pirko dst->trap_group_name[len] = 0;
23107199c862SJiri Pirko }
23117199c862SJiri Pirko }
23127199c862SJiri Pirko
23137199c862SJiri Pirko return MNL_CB_OK;
23147199c862SJiri Pirko }
23157199c862SJiri Pirko
23167199c862SJiri Pirko struct devlink_trap_group_get_rsp *
devlink_trap_group_get(struct ynl_sock * ys,struct devlink_trap_group_get_req * req)23177199c862SJiri Pirko devlink_trap_group_get(struct ynl_sock *ys,
23187199c862SJiri Pirko struct devlink_trap_group_get_req *req)
23197199c862SJiri Pirko {
23207199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
23217199c862SJiri Pirko struct devlink_trap_group_get_rsp *rsp;
23227199c862SJiri Pirko struct nlmsghdr *nlh;
23237199c862SJiri Pirko int err;
23247199c862SJiri Pirko
23257199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_GROUP_GET, 1);
23267199c862SJiri Pirko ys->req_policy = &devlink_nest;
23277199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
23287199c862SJiri Pirko
23297199c862SJiri Pirko if (req->_present.bus_name_len)
23307199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
23317199c862SJiri Pirko if (req->_present.dev_name_len)
23327199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
23337199c862SJiri Pirko if (req->_present.trap_group_name_len)
23347199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_GROUP_NAME, req->trap_group_name);
23357199c862SJiri Pirko
23367199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
23377199c862SJiri Pirko yrs.yarg.data = rsp;
23387199c862SJiri Pirko yrs.cb = devlink_trap_group_get_rsp_parse;
2339*0f4d44f6SJiri Pirko yrs.rsp_cmd = 67;
23407199c862SJiri Pirko
23417199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
23427199c862SJiri Pirko if (err < 0)
23437199c862SJiri Pirko goto err_free;
23447199c862SJiri Pirko
23457199c862SJiri Pirko return rsp;
23467199c862SJiri Pirko
23477199c862SJiri Pirko err_free:
23487199c862SJiri Pirko devlink_trap_group_get_rsp_free(rsp);
23497199c862SJiri Pirko return NULL;
23507199c862SJiri Pirko }
23517199c862SJiri Pirko
23527199c862SJiri Pirko /* DEVLINK_CMD_TRAP_GROUP_GET - dump */
devlink_trap_group_get_list_free(struct devlink_trap_group_get_list * rsp)23537199c862SJiri Pirko void devlink_trap_group_get_list_free(struct devlink_trap_group_get_list *rsp)
23547199c862SJiri Pirko {
23557199c862SJiri Pirko struct devlink_trap_group_get_list *next = rsp;
23567199c862SJiri Pirko
23577199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
23587199c862SJiri Pirko rsp = next;
23597199c862SJiri Pirko next = rsp->next;
23607199c862SJiri Pirko
23617199c862SJiri Pirko free(rsp->obj.bus_name);
23627199c862SJiri Pirko free(rsp->obj.dev_name);
23637199c862SJiri Pirko free(rsp->obj.trap_group_name);
23647199c862SJiri Pirko free(rsp);
23657199c862SJiri Pirko }
23667199c862SJiri Pirko }
23677199c862SJiri Pirko
23687199c862SJiri Pirko struct devlink_trap_group_get_list *
devlink_trap_group_get_dump(struct ynl_sock * ys,struct devlink_trap_group_get_req_dump * req)236934493336SJiri Pirko devlink_trap_group_get_dump(struct ynl_sock *ys,
237034493336SJiri Pirko struct devlink_trap_group_get_req_dump *req)
23717199c862SJiri Pirko {
23727199c862SJiri Pirko struct ynl_dump_state yds = {};
23737199c862SJiri Pirko struct nlmsghdr *nlh;
23747199c862SJiri Pirko int err;
23757199c862SJiri Pirko
23767199c862SJiri Pirko yds.ys = ys;
23777199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_trap_group_get_list);
23787199c862SJiri Pirko yds.cb = devlink_trap_group_get_rsp_parse;
2379*0f4d44f6SJiri Pirko yds.rsp_cmd = 67;
23807199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
23817199c862SJiri Pirko
23827199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_GROUP_GET, 1);
238334493336SJiri Pirko ys->req_policy = &devlink_nest;
238434493336SJiri Pirko
238534493336SJiri Pirko if (req->_present.bus_name_len)
238634493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
238734493336SJiri Pirko if (req->_present.dev_name_len)
238834493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
23897199c862SJiri Pirko
23907199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
23917199c862SJiri Pirko if (err < 0)
23927199c862SJiri Pirko goto free_list;
23937199c862SJiri Pirko
23947199c862SJiri Pirko return yds.first;
23957199c862SJiri Pirko
23967199c862SJiri Pirko free_list:
23977199c862SJiri Pirko devlink_trap_group_get_list_free(yds.first);
23987199c862SJiri Pirko return NULL;
23997199c862SJiri Pirko }
24007199c862SJiri Pirko
24017199c862SJiri Pirko /* ============== DEVLINK_CMD_TRAP_POLICER_GET ============== */
24027199c862SJiri Pirko /* DEVLINK_CMD_TRAP_POLICER_GET - do */
24037199c862SJiri Pirko void
devlink_trap_policer_get_req_free(struct devlink_trap_policer_get_req * req)24047199c862SJiri Pirko devlink_trap_policer_get_req_free(struct devlink_trap_policer_get_req *req)
24057199c862SJiri Pirko {
24067199c862SJiri Pirko free(req->bus_name);
24077199c862SJiri Pirko free(req->dev_name);
24087199c862SJiri Pirko free(req);
24097199c862SJiri Pirko }
24107199c862SJiri Pirko
24117199c862SJiri Pirko void
devlink_trap_policer_get_rsp_free(struct devlink_trap_policer_get_rsp * rsp)24127199c862SJiri Pirko devlink_trap_policer_get_rsp_free(struct devlink_trap_policer_get_rsp *rsp)
24137199c862SJiri Pirko {
24147199c862SJiri Pirko free(rsp->bus_name);
24157199c862SJiri Pirko free(rsp->dev_name);
24167199c862SJiri Pirko free(rsp);
24177199c862SJiri Pirko }
24187199c862SJiri Pirko
devlink_trap_policer_get_rsp_parse(const struct nlmsghdr * nlh,void * data)24197199c862SJiri Pirko int devlink_trap_policer_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
24207199c862SJiri Pirko {
24217199c862SJiri Pirko struct devlink_trap_policer_get_rsp *dst;
24227199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
24237199c862SJiri Pirko const struct nlattr *attr;
24247199c862SJiri Pirko
24257199c862SJiri Pirko dst = yarg->data;
24267199c862SJiri Pirko
24277199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
24287199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
24297199c862SJiri Pirko
24307199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
24317199c862SJiri Pirko unsigned int len;
24327199c862SJiri Pirko
24337199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
24347199c862SJiri Pirko return MNL_CB_ERROR;
24357199c862SJiri Pirko
24367199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
24377199c862SJiri Pirko dst->_present.bus_name_len = len;
24387199c862SJiri Pirko dst->bus_name = malloc(len + 1);
24397199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
24407199c862SJiri Pirko dst->bus_name[len] = 0;
24417199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
24427199c862SJiri Pirko unsigned int len;
24437199c862SJiri Pirko
24447199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
24457199c862SJiri Pirko return MNL_CB_ERROR;
24467199c862SJiri Pirko
24477199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
24487199c862SJiri Pirko dst->_present.dev_name_len = len;
24497199c862SJiri Pirko dst->dev_name = malloc(len + 1);
24507199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
24517199c862SJiri Pirko dst->dev_name[len] = 0;
24527199c862SJiri Pirko } else if (type == DEVLINK_ATTR_TRAP_POLICER_ID) {
24537199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
24547199c862SJiri Pirko return MNL_CB_ERROR;
24557199c862SJiri Pirko dst->_present.trap_policer_id = 1;
24567199c862SJiri Pirko dst->trap_policer_id = mnl_attr_get_u32(attr);
24577199c862SJiri Pirko }
24587199c862SJiri Pirko }
24597199c862SJiri Pirko
24607199c862SJiri Pirko return MNL_CB_OK;
24617199c862SJiri Pirko }
24627199c862SJiri Pirko
24637199c862SJiri Pirko struct devlink_trap_policer_get_rsp *
devlink_trap_policer_get(struct ynl_sock * ys,struct devlink_trap_policer_get_req * req)24647199c862SJiri Pirko devlink_trap_policer_get(struct ynl_sock *ys,
24657199c862SJiri Pirko struct devlink_trap_policer_get_req *req)
24667199c862SJiri Pirko {
24677199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
24687199c862SJiri Pirko struct devlink_trap_policer_get_rsp *rsp;
24697199c862SJiri Pirko struct nlmsghdr *nlh;
24707199c862SJiri Pirko int err;
24717199c862SJiri Pirko
24727199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_POLICER_GET, 1);
24737199c862SJiri Pirko ys->req_policy = &devlink_nest;
24747199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
24757199c862SJiri Pirko
24767199c862SJiri Pirko if (req->_present.bus_name_len)
24777199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
24787199c862SJiri Pirko if (req->_present.dev_name_len)
24797199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
24807199c862SJiri Pirko if (req->_present.trap_policer_id)
24817199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_TRAP_POLICER_ID, req->trap_policer_id);
24827199c862SJiri Pirko
24837199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
24847199c862SJiri Pirko yrs.yarg.data = rsp;
24857199c862SJiri Pirko yrs.cb = devlink_trap_policer_get_rsp_parse;
2486*0f4d44f6SJiri Pirko yrs.rsp_cmd = 71;
24877199c862SJiri Pirko
24887199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
24897199c862SJiri Pirko if (err < 0)
24907199c862SJiri Pirko goto err_free;
24917199c862SJiri Pirko
24927199c862SJiri Pirko return rsp;
24937199c862SJiri Pirko
24947199c862SJiri Pirko err_free:
24957199c862SJiri Pirko devlink_trap_policer_get_rsp_free(rsp);
24967199c862SJiri Pirko return NULL;
24977199c862SJiri Pirko }
24987199c862SJiri Pirko
24997199c862SJiri Pirko /* DEVLINK_CMD_TRAP_POLICER_GET - dump */
25007199c862SJiri Pirko void
devlink_trap_policer_get_list_free(struct devlink_trap_policer_get_list * rsp)25017199c862SJiri Pirko devlink_trap_policer_get_list_free(struct devlink_trap_policer_get_list *rsp)
25027199c862SJiri Pirko {
25037199c862SJiri Pirko struct devlink_trap_policer_get_list *next = rsp;
25047199c862SJiri Pirko
25057199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
25067199c862SJiri Pirko rsp = next;
25077199c862SJiri Pirko next = rsp->next;
25087199c862SJiri Pirko
25097199c862SJiri Pirko free(rsp->obj.bus_name);
25107199c862SJiri Pirko free(rsp->obj.dev_name);
25117199c862SJiri Pirko free(rsp);
25127199c862SJiri Pirko }
25137199c862SJiri Pirko }
25147199c862SJiri Pirko
25157199c862SJiri Pirko struct devlink_trap_policer_get_list *
devlink_trap_policer_get_dump(struct ynl_sock * ys,struct devlink_trap_policer_get_req_dump * req)251634493336SJiri Pirko devlink_trap_policer_get_dump(struct ynl_sock *ys,
251734493336SJiri Pirko struct devlink_trap_policer_get_req_dump *req)
25187199c862SJiri Pirko {
25197199c862SJiri Pirko struct ynl_dump_state yds = {};
25207199c862SJiri Pirko struct nlmsghdr *nlh;
25217199c862SJiri Pirko int err;
25227199c862SJiri Pirko
25237199c862SJiri Pirko yds.ys = ys;
25247199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_trap_policer_get_list);
25257199c862SJiri Pirko yds.cb = devlink_trap_policer_get_rsp_parse;
2526*0f4d44f6SJiri Pirko yds.rsp_cmd = 71;
25277199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
25287199c862SJiri Pirko
25297199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_POLICER_GET, 1);
253034493336SJiri Pirko ys->req_policy = &devlink_nest;
253134493336SJiri Pirko
253234493336SJiri Pirko if (req->_present.bus_name_len)
253334493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
253434493336SJiri Pirko if (req->_present.dev_name_len)
253534493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
25367199c862SJiri Pirko
25377199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
25387199c862SJiri Pirko if (err < 0)
25397199c862SJiri Pirko goto free_list;
25407199c862SJiri Pirko
25417199c862SJiri Pirko return yds.first;
25427199c862SJiri Pirko
25437199c862SJiri Pirko free_list:
25447199c862SJiri Pirko devlink_trap_policer_get_list_free(yds.first);
25457199c862SJiri Pirko return NULL;
25467199c862SJiri Pirko }
25477199c862SJiri Pirko
25487199c862SJiri Pirko /* ============== DEVLINK_CMD_RATE_GET ============== */
25497199c862SJiri Pirko /* DEVLINK_CMD_RATE_GET - do */
devlink_rate_get_req_free(struct devlink_rate_get_req * req)25507199c862SJiri Pirko void devlink_rate_get_req_free(struct devlink_rate_get_req *req)
25517199c862SJiri Pirko {
25527199c862SJiri Pirko free(req->bus_name);
25537199c862SJiri Pirko free(req->dev_name);
25547199c862SJiri Pirko free(req->rate_node_name);
25557199c862SJiri Pirko free(req);
25567199c862SJiri Pirko }
25577199c862SJiri Pirko
devlink_rate_get_rsp_free(struct devlink_rate_get_rsp * rsp)25587199c862SJiri Pirko void devlink_rate_get_rsp_free(struct devlink_rate_get_rsp *rsp)
25597199c862SJiri Pirko {
25607199c862SJiri Pirko free(rsp->bus_name);
25617199c862SJiri Pirko free(rsp->dev_name);
25627199c862SJiri Pirko free(rsp->rate_node_name);
25637199c862SJiri Pirko free(rsp);
25647199c862SJiri Pirko }
25657199c862SJiri Pirko
devlink_rate_get_rsp_parse(const struct nlmsghdr * nlh,void * data)25667199c862SJiri Pirko int devlink_rate_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
25677199c862SJiri Pirko {
25687199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
25697199c862SJiri Pirko struct devlink_rate_get_rsp *dst;
25707199c862SJiri Pirko const struct nlattr *attr;
25717199c862SJiri Pirko
25727199c862SJiri Pirko dst = yarg->data;
25737199c862SJiri Pirko
25747199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
25757199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
25767199c862SJiri Pirko
25777199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
25787199c862SJiri Pirko unsigned int len;
25797199c862SJiri Pirko
25807199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
25817199c862SJiri Pirko return MNL_CB_ERROR;
25827199c862SJiri Pirko
25837199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
25847199c862SJiri Pirko dst->_present.bus_name_len = len;
25857199c862SJiri Pirko dst->bus_name = malloc(len + 1);
25867199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
25877199c862SJiri Pirko dst->bus_name[len] = 0;
25887199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
25897199c862SJiri Pirko unsigned int len;
25907199c862SJiri Pirko
25917199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
25927199c862SJiri Pirko return MNL_CB_ERROR;
25937199c862SJiri Pirko
25947199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
25957199c862SJiri Pirko dst->_present.dev_name_len = len;
25967199c862SJiri Pirko dst->dev_name = malloc(len + 1);
25977199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
25987199c862SJiri Pirko dst->dev_name[len] = 0;
25997199c862SJiri Pirko } else if (type == DEVLINK_ATTR_PORT_INDEX) {
26007199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
26017199c862SJiri Pirko return MNL_CB_ERROR;
26027199c862SJiri Pirko dst->_present.port_index = 1;
26037199c862SJiri Pirko dst->port_index = mnl_attr_get_u32(attr);
26047199c862SJiri Pirko } else if (type == DEVLINK_ATTR_RATE_NODE_NAME) {
26057199c862SJiri Pirko unsigned int len;
26067199c862SJiri Pirko
26077199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
26087199c862SJiri Pirko return MNL_CB_ERROR;
26097199c862SJiri Pirko
26107199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
26117199c862SJiri Pirko dst->_present.rate_node_name_len = len;
26127199c862SJiri Pirko dst->rate_node_name = malloc(len + 1);
26137199c862SJiri Pirko memcpy(dst->rate_node_name, mnl_attr_get_str(attr), len);
26147199c862SJiri Pirko dst->rate_node_name[len] = 0;
26157199c862SJiri Pirko }
26167199c862SJiri Pirko }
26177199c862SJiri Pirko
26187199c862SJiri Pirko return MNL_CB_OK;
26197199c862SJiri Pirko }
26207199c862SJiri Pirko
26217199c862SJiri Pirko struct devlink_rate_get_rsp *
devlink_rate_get(struct ynl_sock * ys,struct devlink_rate_get_req * req)26227199c862SJiri Pirko devlink_rate_get(struct ynl_sock *ys, struct devlink_rate_get_req *req)
26237199c862SJiri Pirko {
26247199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
26257199c862SJiri Pirko struct devlink_rate_get_rsp *rsp;
26267199c862SJiri Pirko struct nlmsghdr *nlh;
26277199c862SJiri Pirko int err;
26287199c862SJiri Pirko
26297199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RATE_GET, 1);
26307199c862SJiri Pirko ys->req_policy = &devlink_nest;
26317199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
26327199c862SJiri Pirko
26337199c862SJiri Pirko if (req->_present.bus_name_len)
26347199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
26357199c862SJiri Pirko if (req->_present.dev_name_len)
26367199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
26377199c862SJiri Pirko if (req->_present.port_index)
26387199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
26397199c862SJiri Pirko if (req->_present.rate_node_name_len)
26407199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_NODE_NAME, req->rate_node_name);
26417199c862SJiri Pirko
26427199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
26437199c862SJiri Pirko yrs.yarg.data = rsp;
26447199c862SJiri Pirko yrs.cb = devlink_rate_get_rsp_parse;
2645*0f4d44f6SJiri Pirko yrs.rsp_cmd = 76;
26467199c862SJiri Pirko
26477199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
26487199c862SJiri Pirko if (err < 0)
26497199c862SJiri Pirko goto err_free;
26507199c862SJiri Pirko
26517199c862SJiri Pirko return rsp;
26527199c862SJiri Pirko
26537199c862SJiri Pirko err_free:
26547199c862SJiri Pirko devlink_rate_get_rsp_free(rsp);
26557199c862SJiri Pirko return NULL;
26567199c862SJiri Pirko }
26577199c862SJiri Pirko
26587199c862SJiri Pirko /* DEVLINK_CMD_RATE_GET - dump */
devlink_rate_get_list_free(struct devlink_rate_get_list * rsp)26597199c862SJiri Pirko void devlink_rate_get_list_free(struct devlink_rate_get_list *rsp)
26607199c862SJiri Pirko {
26617199c862SJiri Pirko struct devlink_rate_get_list *next = rsp;
26627199c862SJiri Pirko
26637199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
26647199c862SJiri Pirko rsp = next;
26657199c862SJiri Pirko next = rsp->next;
26667199c862SJiri Pirko
26677199c862SJiri Pirko free(rsp->obj.bus_name);
26687199c862SJiri Pirko free(rsp->obj.dev_name);
26697199c862SJiri Pirko free(rsp->obj.rate_node_name);
26707199c862SJiri Pirko free(rsp);
26717199c862SJiri Pirko }
26727199c862SJiri Pirko }
26737199c862SJiri Pirko
267434493336SJiri Pirko struct devlink_rate_get_list *
devlink_rate_get_dump(struct ynl_sock * ys,struct devlink_rate_get_req_dump * req)267534493336SJiri Pirko devlink_rate_get_dump(struct ynl_sock *ys,
267634493336SJiri Pirko struct devlink_rate_get_req_dump *req)
26777199c862SJiri Pirko {
26787199c862SJiri Pirko struct ynl_dump_state yds = {};
26797199c862SJiri Pirko struct nlmsghdr *nlh;
26807199c862SJiri Pirko int err;
26817199c862SJiri Pirko
26827199c862SJiri Pirko yds.ys = ys;
26837199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_rate_get_list);
26847199c862SJiri Pirko yds.cb = devlink_rate_get_rsp_parse;
2685*0f4d44f6SJiri Pirko yds.rsp_cmd = 76;
26867199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
26877199c862SJiri Pirko
26887199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_RATE_GET, 1);
268934493336SJiri Pirko ys->req_policy = &devlink_nest;
269034493336SJiri Pirko
269134493336SJiri Pirko if (req->_present.bus_name_len)
269234493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
269334493336SJiri Pirko if (req->_present.dev_name_len)
269434493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
26957199c862SJiri Pirko
26967199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
26977199c862SJiri Pirko if (err < 0)
26987199c862SJiri Pirko goto free_list;
26997199c862SJiri Pirko
27007199c862SJiri Pirko return yds.first;
27017199c862SJiri Pirko
27027199c862SJiri Pirko free_list:
27037199c862SJiri Pirko devlink_rate_get_list_free(yds.first);
27047199c862SJiri Pirko return NULL;
27057199c862SJiri Pirko }
27067199c862SJiri Pirko
27077199c862SJiri Pirko /* ============== DEVLINK_CMD_LINECARD_GET ============== */
27087199c862SJiri Pirko /* DEVLINK_CMD_LINECARD_GET - do */
devlink_linecard_get_req_free(struct devlink_linecard_get_req * req)27097199c862SJiri Pirko void devlink_linecard_get_req_free(struct devlink_linecard_get_req *req)
27107199c862SJiri Pirko {
27117199c862SJiri Pirko free(req->bus_name);
27127199c862SJiri Pirko free(req->dev_name);
27137199c862SJiri Pirko free(req);
27147199c862SJiri Pirko }
27157199c862SJiri Pirko
devlink_linecard_get_rsp_free(struct devlink_linecard_get_rsp * rsp)27167199c862SJiri Pirko void devlink_linecard_get_rsp_free(struct devlink_linecard_get_rsp *rsp)
27177199c862SJiri Pirko {
27187199c862SJiri Pirko free(rsp->bus_name);
27197199c862SJiri Pirko free(rsp->dev_name);
27207199c862SJiri Pirko free(rsp);
27217199c862SJiri Pirko }
27227199c862SJiri Pirko
devlink_linecard_get_rsp_parse(const struct nlmsghdr * nlh,void * data)27237199c862SJiri Pirko int devlink_linecard_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
27247199c862SJiri Pirko {
27257199c862SJiri Pirko struct devlink_linecard_get_rsp *dst;
27267199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
27277199c862SJiri Pirko const struct nlattr *attr;
27287199c862SJiri Pirko
27297199c862SJiri Pirko dst = yarg->data;
27307199c862SJiri Pirko
27317199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
27327199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
27337199c862SJiri Pirko
27347199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
27357199c862SJiri Pirko unsigned int len;
27367199c862SJiri Pirko
27377199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
27387199c862SJiri Pirko return MNL_CB_ERROR;
27397199c862SJiri Pirko
27407199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
27417199c862SJiri Pirko dst->_present.bus_name_len = len;
27427199c862SJiri Pirko dst->bus_name = malloc(len + 1);
27437199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
27447199c862SJiri Pirko dst->bus_name[len] = 0;
27457199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
27467199c862SJiri Pirko unsigned int len;
27477199c862SJiri Pirko
27487199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
27497199c862SJiri Pirko return MNL_CB_ERROR;
27507199c862SJiri Pirko
27517199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
27527199c862SJiri Pirko dst->_present.dev_name_len = len;
27537199c862SJiri Pirko dst->dev_name = malloc(len + 1);
27547199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
27557199c862SJiri Pirko dst->dev_name[len] = 0;
27567199c862SJiri Pirko } else if (type == DEVLINK_ATTR_LINECARD_INDEX) {
27577199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
27587199c862SJiri Pirko return MNL_CB_ERROR;
27597199c862SJiri Pirko dst->_present.linecard_index = 1;
27607199c862SJiri Pirko dst->linecard_index = mnl_attr_get_u32(attr);
27617199c862SJiri Pirko }
27627199c862SJiri Pirko }
27637199c862SJiri Pirko
27647199c862SJiri Pirko return MNL_CB_OK;
27657199c862SJiri Pirko }
27667199c862SJiri Pirko
27677199c862SJiri Pirko struct devlink_linecard_get_rsp *
devlink_linecard_get(struct ynl_sock * ys,struct devlink_linecard_get_req * req)27687199c862SJiri Pirko devlink_linecard_get(struct ynl_sock *ys, struct devlink_linecard_get_req *req)
27697199c862SJiri Pirko {
27707199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
27717199c862SJiri Pirko struct devlink_linecard_get_rsp *rsp;
27727199c862SJiri Pirko struct nlmsghdr *nlh;
27737199c862SJiri Pirko int err;
27747199c862SJiri Pirko
27757199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_LINECARD_GET, 1);
27767199c862SJiri Pirko ys->req_policy = &devlink_nest;
27777199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
27787199c862SJiri Pirko
27797199c862SJiri Pirko if (req->_present.bus_name_len)
27807199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
27817199c862SJiri Pirko if (req->_present.dev_name_len)
27827199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
27837199c862SJiri Pirko if (req->_present.linecard_index)
27847199c862SJiri Pirko mnl_attr_put_u32(nlh, DEVLINK_ATTR_LINECARD_INDEX, req->linecard_index);
27857199c862SJiri Pirko
27867199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
27877199c862SJiri Pirko yrs.yarg.data = rsp;
27887199c862SJiri Pirko yrs.cb = devlink_linecard_get_rsp_parse;
2789*0f4d44f6SJiri Pirko yrs.rsp_cmd = 80;
27907199c862SJiri Pirko
27917199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
27927199c862SJiri Pirko if (err < 0)
27937199c862SJiri Pirko goto err_free;
27947199c862SJiri Pirko
27957199c862SJiri Pirko return rsp;
27967199c862SJiri Pirko
27977199c862SJiri Pirko err_free:
27987199c862SJiri Pirko devlink_linecard_get_rsp_free(rsp);
27997199c862SJiri Pirko return NULL;
28007199c862SJiri Pirko }
28017199c862SJiri Pirko
28027199c862SJiri Pirko /* DEVLINK_CMD_LINECARD_GET - dump */
devlink_linecard_get_list_free(struct devlink_linecard_get_list * rsp)28037199c862SJiri Pirko void devlink_linecard_get_list_free(struct devlink_linecard_get_list *rsp)
28047199c862SJiri Pirko {
28057199c862SJiri Pirko struct devlink_linecard_get_list *next = rsp;
28067199c862SJiri Pirko
28077199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
28087199c862SJiri Pirko rsp = next;
28097199c862SJiri Pirko next = rsp->next;
28107199c862SJiri Pirko
28117199c862SJiri Pirko free(rsp->obj.bus_name);
28127199c862SJiri Pirko free(rsp->obj.dev_name);
28137199c862SJiri Pirko free(rsp);
28147199c862SJiri Pirko }
28157199c862SJiri Pirko }
28167199c862SJiri Pirko
28177199c862SJiri Pirko struct devlink_linecard_get_list *
devlink_linecard_get_dump(struct ynl_sock * ys,struct devlink_linecard_get_req_dump * req)281834493336SJiri Pirko devlink_linecard_get_dump(struct ynl_sock *ys,
281934493336SJiri Pirko struct devlink_linecard_get_req_dump *req)
28207199c862SJiri Pirko {
28217199c862SJiri Pirko struct ynl_dump_state yds = {};
28227199c862SJiri Pirko struct nlmsghdr *nlh;
28237199c862SJiri Pirko int err;
28247199c862SJiri Pirko
28257199c862SJiri Pirko yds.ys = ys;
28267199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_linecard_get_list);
28277199c862SJiri Pirko yds.cb = devlink_linecard_get_rsp_parse;
2828*0f4d44f6SJiri Pirko yds.rsp_cmd = 80;
28297199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
28307199c862SJiri Pirko
28317199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_LINECARD_GET, 1);
283234493336SJiri Pirko ys->req_policy = &devlink_nest;
283334493336SJiri Pirko
283434493336SJiri Pirko if (req->_present.bus_name_len)
283534493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
283634493336SJiri Pirko if (req->_present.dev_name_len)
283734493336SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
28387199c862SJiri Pirko
28397199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
28407199c862SJiri Pirko if (err < 0)
28417199c862SJiri Pirko goto free_list;
28427199c862SJiri Pirko
28437199c862SJiri Pirko return yds.first;
28447199c862SJiri Pirko
28457199c862SJiri Pirko free_list:
28467199c862SJiri Pirko devlink_linecard_get_list_free(yds.first);
28477199c862SJiri Pirko return NULL;
28487199c862SJiri Pirko }
28497199c862SJiri Pirko
28507199c862SJiri Pirko /* ============== DEVLINK_CMD_SELFTESTS_GET ============== */
28517199c862SJiri Pirko /* DEVLINK_CMD_SELFTESTS_GET - do */
devlink_selftests_get_req_free(struct devlink_selftests_get_req * req)28527199c862SJiri Pirko void devlink_selftests_get_req_free(struct devlink_selftests_get_req *req)
28537199c862SJiri Pirko {
28547199c862SJiri Pirko free(req->bus_name);
28557199c862SJiri Pirko free(req->dev_name);
28567199c862SJiri Pirko free(req);
28577199c862SJiri Pirko }
28587199c862SJiri Pirko
devlink_selftests_get_rsp_free(struct devlink_selftests_get_rsp * rsp)28597199c862SJiri Pirko void devlink_selftests_get_rsp_free(struct devlink_selftests_get_rsp *rsp)
28607199c862SJiri Pirko {
28617199c862SJiri Pirko free(rsp->bus_name);
28627199c862SJiri Pirko free(rsp->dev_name);
28637199c862SJiri Pirko free(rsp);
28647199c862SJiri Pirko }
28657199c862SJiri Pirko
devlink_selftests_get_rsp_parse(const struct nlmsghdr * nlh,void * data)28667199c862SJiri Pirko int devlink_selftests_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
28677199c862SJiri Pirko {
28687199c862SJiri Pirko struct devlink_selftests_get_rsp *dst;
28697199c862SJiri Pirko struct ynl_parse_arg *yarg = data;
28707199c862SJiri Pirko const struct nlattr *attr;
28717199c862SJiri Pirko
28727199c862SJiri Pirko dst = yarg->data;
28737199c862SJiri Pirko
28747199c862SJiri Pirko mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
28757199c862SJiri Pirko unsigned int type = mnl_attr_get_type(attr);
28767199c862SJiri Pirko
28777199c862SJiri Pirko if (type == DEVLINK_ATTR_BUS_NAME) {
28787199c862SJiri Pirko unsigned int len;
28797199c862SJiri Pirko
28807199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
28817199c862SJiri Pirko return MNL_CB_ERROR;
28827199c862SJiri Pirko
28837199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
28847199c862SJiri Pirko dst->_present.bus_name_len = len;
28857199c862SJiri Pirko dst->bus_name = malloc(len + 1);
28867199c862SJiri Pirko memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
28877199c862SJiri Pirko dst->bus_name[len] = 0;
28887199c862SJiri Pirko } else if (type == DEVLINK_ATTR_DEV_NAME) {
28897199c862SJiri Pirko unsigned int len;
28907199c862SJiri Pirko
28917199c862SJiri Pirko if (ynl_attr_validate(yarg, attr))
28927199c862SJiri Pirko return MNL_CB_ERROR;
28937199c862SJiri Pirko
28947199c862SJiri Pirko len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
28957199c862SJiri Pirko dst->_present.dev_name_len = len;
28967199c862SJiri Pirko dst->dev_name = malloc(len + 1);
28977199c862SJiri Pirko memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
28987199c862SJiri Pirko dst->dev_name[len] = 0;
28997199c862SJiri Pirko }
29007199c862SJiri Pirko }
29017199c862SJiri Pirko
29027199c862SJiri Pirko return MNL_CB_OK;
29037199c862SJiri Pirko }
29047199c862SJiri Pirko
29057199c862SJiri Pirko struct devlink_selftests_get_rsp *
devlink_selftests_get(struct ynl_sock * ys,struct devlink_selftests_get_req * req)29067199c862SJiri Pirko devlink_selftests_get(struct ynl_sock *ys,
29077199c862SJiri Pirko struct devlink_selftests_get_req *req)
29087199c862SJiri Pirko {
29097199c862SJiri Pirko struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
29107199c862SJiri Pirko struct devlink_selftests_get_rsp *rsp;
29117199c862SJiri Pirko struct nlmsghdr *nlh;
29127199c862SJiri Pirko int err;
29137199c862SJiri Pirko
29147199c862SJiri Pirko nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SELFTESTS_GET, 1);
29157199c862SJiri Pirko ys->req_policy = &devlink_nest;
29167199c862SJiri Pirko yrs.yarg.rsp_policy = &devlink_nest;
29177199c862SJiri Pirko
29187199c862SJiri Pirko if (req->_present.bus_name_len)
29197199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
29207199c862SJiri Pirko if (req->_present.dev_name_len)
29217199c862SJiri Pirko mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
29227199c862SJiri Pirko
29237199c862SJiri Pirko rsp = calloc(1, sizeof(*rsp));
29247199c862SJiri Pirko yrs.yarg.data = rsp;
29257199c862SJiri Pirko yrs.cb = devlink_selftests_get_rsp_parse;
29267199c862SJiri Pirko yrs.rsp_cmd = DEVLINK_CMD_SELFTESTS_GET;
29277199c862SJiri Pirko
29287199c862SJiri Pirko err = ynl_exec(ys, nlh, &yrs);
29297199c862SJiri Pirko if (err < 0)
29307199c862SJiri Pirko goto err_free;
29317199c862SJiri Pirko
29327199c862SJiri Pirko return rsp;
29337199c862SJiri Pirko
29347199c862SJiri Pirko err_free:
29357199c862SJiri Pirko devlink_selftests_get_rsp_free(rsp);
29367199c862SJiri Pirko return NULL;
29377199c862SJiri Pirko }
29387199c862SJiri Pirko
29397199c862SJiri Pirko /* DEVLINK_CMD_SELFTESTS_GET - dump */
devlink_selftests_get_list_free(struct devlink_selftests_get_list * rsp)29407199c862SJiri Pirko void devlink_selftests_get_list_free(struct devlink_selftests_get_list *rsp)
29417199c862SJiri Pirko {
29427199c862SJiri Pirko struct devlink_selftests_get_list *next = rsp;
29437199c862SJiri Pirko
29447199c862SJiri Pirko while ((void *)next != YNL_LIST_END) {
29457199c862SJiri Pirko rsp = next;
29467199c862SJiri Pirko next = rsp->next;
29477199c862SJiri Pirko
29487199c862SJiri Pirko free(rsp->obj.bus_name);
29497199c862SJiri Pirko free(rsp->obj.dev_name);
29507199c862SJiri Pirko free(rsp);
29517199c862SJiri Pirko }
29527199c862SJiri Pirko }
29537199c862SJiri Pirko
29547199c862SJiri Pirko struct devlink_selftests_get_list *
devlink_selftests_get_dump(struct ynl_sock * ys)29557199c862SJiri Pirko devlink_selftests_get_dump(struct ynl_sock *ys)
29567199c862SJiri Pirko {
29577199c862SJiri Pirko struct ynl_dump_state yds = {};
29587199c862SJiri Pirko struct nlmsghdr *nlh;
29597199c862SJiri Pirko int err;
29607199c862SJiri Pirko
29617199c862SJiri Pirko yds.ys = ys;
29627199c862SJiri Pirko yds.alloc_sz = sizeof(struct devlink_selftests_get_list);
29637199c862SJiri Pirko yds.cb = devlink_selftests_get_rsp_parse;
29647199c862SJiri Pirko yds.rsp_cmd = DEVLINK_CMD_SELFTESTS_GET;
29657199c862SJiri Pirko yds.rsp_policy = &devlink_nest;
29667199c862SJiri Pirko
29677199c862SJiri Pirko nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SELFTESTS_GET, 1);
29687199c862SJiri Pirko
29697199c862SJiri Pirko err = ynl_exec_dump(ys, nlh, &yds);
29707199c862SJiri Pirko if (err < 0)
29717199c862SJiri Pirko goto free_list;
29727199c862SJiri Pirko
29737199c862SJiri Pirko return yds.first;
29747199c862SJiri Pirko
29757199c862SJiri Pirko free_list:
29767199c862SJiri Pirko devlink_selftests_get_list_free(yds.first);
29777199c862SJiri Pirko return NULL;
29787199c862SJiri Pirko }
29797199c862SJiri Pirko
29805d1a30ebSJakub Kicinski const struct ynl_family ynl_devlink_family = {
29815d1a30ebSJakub Kicinski .name = "devlink",
29825d1a30ebSJakub Kicinski };
2983