1 // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
2 /* Do not edit directly, auto-generated from: */
3 /* Documentation/netlink/specs/devlink.yaml */
4 /* YNL-GEN user source */
8 #include "devlink-user.h"
10 #include <linux/devlink.h>
12 #include <libmnl/libmnl.h>
13 #include <linux/genetlink.h>
16 static const char * const devlink_op_strmap[] = {
19 [DEVLINK_CMD_SB_GET] = "sb-get",
20 [DEVLINK_CMD_SB_POOL_GET] = "sb-pool-get",
21 [DEVLINK_CMD_SB_PORT_POOL_GET] = "sb-port-pool-get",
22 [DEVLINK_CMD_SB_TC_POOL_BIND_GET] = "sb-tc-pool-bind-get",
23 [DEVLINK_CMD_PARAM_GET] = "param-get",
24 [DEVLINK_CMD_REGION_GET] = "region-get",
25 [DEVLINK_CMD_INFO_GET] = "info-get",
26 [DEVLINK_CMD_HEALTH_REPORTER_GET] = "health-reporter-get",
27 [DEVLINK_CMD_TRAP_GET] = "trap-get",
28 [DEVLINK_CMD_TRAP_GROUP_GET] = "trap-group-get",
29 [DEVLINK_CMD_TRAP_POLICER_GET] = "trap-policer-get",
30 [DEVLINK_CMD_RATE_GET] = "rate-get",
31 [DEVLINK_CMD_LINECARD_GET] = "linecard-get",
32 [DEVLINK_CMD_SELFTESTS_GET] = "selftests-get",
35 const char *devlink_op_str(int op)
37 if (op < 0 || op >= (int)MNL_ARRAY_SIZE(devlink_op_strmap))
39 return devlink_op_strmap[op];
42 static const char * const devlink_sb_pool_type_strmap[] = {
47 const char *devlink_sb_pool_type_str(enum devlink_sb_pool_type value)
49 if (value < 0 || value >= (int)MNL_ARRAY_SIZE(devlink_sb_pool_type_strmap))
51 return devlink_sb_pool_type_strmap[value];
55 struct ynl_policy_attr devlink_dl_info_version_policy[DEVLINK_ATTR_MAX + 1] = {
56 [DEVLINK_ATTR_INFO_VERSION_NAME] = { .name = "info-version-name", .type = YNL_PT_NUL_STR, },
57 [DEVLINK_ATTR_INFO_VERSION_VALUE] = { .name = "info-version-value", .type = YNL_PT_NUL_STR, },
60 struct ynl_policy_nest devlink_dl_info_version_nest = {
61 .max_attr = DEVLINK_ATTR_MAX,
62 .table = devlink_dl_info_version_policy,
65 struct ynl_policy_attr devlink_dl_reload_stats_entry_policy[DEVLINK_ATTR_MAX + 1] = {
66 [DEVLINK_ATTR_RELOAD_STATS_LIMIT] = { .name = "reload-stats-limit", .type = YNL_PT_U8, },
67 [DEVLINK_ATTR_RELOAD_STATS_VALUE] = { .name = "reload-stats-value", .type = YNL_PT_U32, },
70 struct ynl_policy_nest devlink_dl_reload_stats_entry_nest = {
71 .max_attr = DEVLINK_ATTR_MAX,
72 .table = devlink_dl_reload_stats_entry_policy,
75 struct ynl_policy_attr devlink_dl_reload_act_stats_policy[DEVLINK_ATTR_MAX + 1] = {
76 [DEVLINK_ATTR_RELOAD_STATS_ENTRY] = { .name = "reload-stats-entry", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_entry_nest, },
79 struct ynl_policy_nest devlink_dl_reload_act_stats_nest = {
80 .max_attr = DEVLINK_ATTR_MAX,
81 .table = devlink_dl_reload_act_stats_policy,
84 struct ynl_policy_attr devlink_dl_reload_act_info_policy[DEVLINK_ATTR_MAX + 1] = {
85 [DEVLINK_ATTR_RELOAD_ACTION] = { .name = "reload-action", .type = YNL_PT_U8, },
86 [DEVLINK_ATTR_RELOAD_ACTION_STATS] = { .name = "reload-action-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_stats_nest, },
89 struct ynl_policy_nest devlink_dl_reload_act_info_nest = {
90 .max_attr = DEVLINK_ATTR_MAX,
91 .table = devlink_dl_reload_act_info_policy,
94 struct ynl_policy_attr devlink_dl_reload_stats_policy[DEVLINK_ATTR_MAX + 1] = {
95 [DEVLINK_ATTR_RELOAD_ACTION_INFO] = { .name = "reload-action-info", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_info_nest, },
98 struct ynl_policy_nest devlink_dl_reload_stats_nest = {
99 .max_attr = DEVLINK_ATTR_MAX,
100 .table = devlink_dl_reload_stats_policy,
103 struct ynl_policy_attr devlink_dl_dev_stats_policy[DEVLINK_ATTR_MAX + 1] = {
104 [DEVLINK_ATTR_RELOAD_STATS] = { .name = "reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
105 [DEVLINK_ATTR_REMOTE_RELOAD_STATS] = { .name = "remote-reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
108 struct ynl_policy_nest devlink_dl_dev_stats_nest = {
109 .max_attr = DEVLINK_ATTR_MAX,
110 .table = devlink_dl_dev_stats_policy,
113 struct ynl_policy_attr devlink_policy[DEVLINK_ATTR_MAX + 1] = {
114 [DEVLINK_ATTR_BUS_NAME] = { .name = "bus-name", .type = YNL_PT_NUL_STR, },
115 [DEVLINK_ATTR_DEV_NAME] = { .name = "dev-name", .type = YNL_PT_NUL_STR, },
116 [DEVLINK_ATTR_PORT_INDEX] = { .name = "port-index", .type = YNL_PT_U32, },
117 [DEVLINK_ATTR_SB_INDEX] = { .name = "sb-index", .type = YNL_PT_U32, },
118 [DEVLINK_ATTR_SB_POOL_INDEX] = { .name = "sb-pool-index", .type = YNL_PT_U16, },
119 [DEVLINK_ATTR_SB_POOL_TYPE] = { .name = "sb-pool-type", .type = YNL_PT_U8, },
120 [DEVLINK_ATTR_SB_TC_INDEX] = { .name = "sb-tc-index", .type = YNL_PT_U16, },
121 [DEVLINK_ATTR_PARAM_NAME] = { .name = "param-name", .type = YNL_PT_NUL_STR, },
122 [DEVLINK_ATTR_REGION_NAME] = { .name = "region-name", .type = YNL_PT_NUL_STR, },
123 [DEVLINK_ATTR_INFO_DRIVER_NAME] = { .name = "info-driver-name", .type = YNL_PT_NUL_STR, },
124 [DEVLINK_ATTR_INFO_SERIAL_NUMBER] = { .name = "info-serial-number", .type = YNL_PT_NUL_STR, },
125 [DEVLINK_ATTR_INFO_VERSION_FIXED] = { .name = "info-version-fixed", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
126 [DEVLINK_ATTR_INFO_VERSION_RUNNING] = { .name = "info-version-running", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
127 [DEVLINK_ATTR_INFO_VERSION_STORED] = { .name = "info-version-stored", .type = YNL_PT_NEST, .nest = &devlink_dl_info_version_nest, },
128 [DEVLINK_ATTR_INFO_VERSION_NAME] = { .name = "info-version-name", .type = YNL_PT_NUL_STR, },
129 [DEVLINK_ATTR_INFO_VERSION_VALUE] = { .name = "info-version-value", .type = YNL_PT_NUL_STR, },
130 [DEVLINK_ATTR_HEALTH_REPORTER_NAME] = { .name = "health-reporter-name", .type = YNL_PT_NUL_STR, },
131 [DEVLINK_ATTR_TRAP_NAME] = { .name = "trap-name", .type = YNL_PT_NUL_STR, },
132 [DEVLINK_ATTR_TRAP_GROUP_NAME] = { .name = "trap-group-name", .type = YNL_PT_NUL_STR, },
133 [DEVLINK_ATTR_RELOAD_FAILED] = { .name = "reload-failed", .type = YNL_PT_U8, },
134 [DEVLINK_ATTR_TRAP_POLICER_ID] = { .name = "trap-policer-id", .type = YNL_PT_U32, },
135 [DEVLINK_ATTR_RELOAD_ACTION] = { .name = "reload-action", .type = YNL_PT_U8, },
136 [DEVLINK_ATTR_DEV_STATS] = { .name = "dev-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_dev_stats_nest, },
137 [DEVLINK_ATTR_RELOAD_STATS] = { .name = "reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
138 [DEVLINK_ATTR_RELOAD_STATS_ENTRY] = { .name = "reload-stats-entry", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_entry_nest, },
139 [DEVLINK_ATTR_RELOAD_STATS_LIMIT] = { .name = "reload-stats-limit", .type = YNL_PT_U8, },
140 [DEVLINK_ATTR_RELOAD_STATS_VALUE] = { .name = "reload-stats-value", .type = YNL_PT_U32, },
141 [DEVLINK_ATTR_REMOTE_RELOAD_STATS] = { .name = "remote-reload-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_stats_nest, },
142 [DEVLINK_ATTR_RELOAD_ACTION_INFO] = { .name = "reload-action-info", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_info_nest, },
143 [DEVLINK_ATTR_RELOAD_ACTION_STATS] = { .name = "reload-action-stats", .type = YNL_PT_NEST, .nest = &devlink_dl_reload_act_stats_nest, },
144 [DEVLINK_ATTR_RATE_NODE_NAME] = { .name = "rate-node-name", .type = YNL_PT_NUL_STR, },
145 [DEVLINK_ATTR_LINECARD_INDEX] = { .name = "linecard-index", .type = YNL_PT_U32, },
148 struct ynl_policy_nest devlink_nest = {
149 .max_attr = DEVLINK_ATTR_MAX,
150 .table = devlink_policy,
153 /* Common nested types */
154 void devlink_dl_info_version_free(struct devlink_dl_info_version *obj)
156 free(obj->info_version_name);
157 free(obj->info_version_value);
160 int devlink_dl_info_version_parse(struct ynl_parse_arg *yarg,
161 const struct nlattr *nested)
163 struct devlink_dl_info_version *dst = yarg->data;
164 const struct nlattr *attr;
166 mnl_attr_for_each_nested(attr, nested) {
167 unsigned int type = mnl_attr_get_type(attr);
169 if (type == DEVLINK_ATTR_INFO_VERSION_NAME) {
172 if (ynl_attr_validate(yarg, attr))
175 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
176 dst->_present.info_version_name_len = len;
177 dst->info_version_name = malloc(len + 1);
178 memcpy(dst->info_version_name, mnl_attr_get_str(attr), len);
179 dst->info_version_name[len] = 0;
180 } else if (type == DEVLINK_ATTR_INFO_VERSION_VALUE) {
183 if (ynl_attr_validate(yarg, attr))
186 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
187 dst->_present.info_version_value_len = len;
188 dst->info_version_value = malloc(len + 1);
189 memcpy(dst->info_version_value, mnl_attr_get_str(attr), len);
190 dst->info_version_value[len] = 0;
198 devlink_dl_reload_stats_entry_free(struct devlink_dl_reload_stats_entry *obj)
202 int devlink_dl_reload_stats_entry_parse(struct ynl_parse_arg *yarg,
203 const struct nlattr *nested)
205 struct devlink_dl_reload_stats_entry *dst = yarg->data;
206 const struct nlattr *attr;
208 mnl_attr_for_each_nested(attr, nested) {
209 unsigned int type = mnl_attr_get_type(attr);
211 if (type == DEVLINK_ATTR_RELOAD_STATS_LIMIT) {
212 if (ynl_attr_validate(yarg, attr))
214 dst->_present.reload_stats_limit = 1;
215 dst->reload_stats_limit = mnl_attr_get_u8(attr);
216 } else if (type == DEVLINK_ATTR_RELOAD_STATS_VALUE) {
217 if (ynl_attr_validate(yarg, attr))
219 dst->_present.reload_stats_value = 1;
220 dst->reload_stats_value = mnl_attr_get_u32(attr);
227 void devlink_dl_reload_act_stats_free(struct devlink_dl_reload_act_stats *obj)
231 for (i = 0; i < obj->n_reload_stats_entry; i++)
232 devlink_dl_reload_stats_entry_free(&obj->reload_stats_entry[i]);
233 free(obj->reload_stats_entry);
236 int devlink_dl_reload_act_stats_parse(struct ynl_parse_arg *yarg,
237 const struct nlattr *nested)
239 struct devlink_dl_reload_act_stats *dst = yarg->data;
240 unsigned int n_reload_stats_entry = 0;
241 const struct nlattr *attr;
242 struct ynl_parse_arg parg;
247 if (dst->reload_stats_entry)
248 return ynl_error_parse(yarg, "attribute already present (dl-reload-act-stats.reload-stats-entry)");
250 mnl_attr_for_each_nested(attr, nested) {
251 unsigned int type = mnl_attr_get_type(attr);
253 if (type == DEVLINK_ATTR_RELOAD_STATS_ENTRY) {
254 n_reload_stats_entry++;
258 if (n_reload_stats_entry) {
259 dst->reload_stats_entry = calloc(n_reload_stats_entry, sizeof(*dst->reload_stats_entry));
260 dst->n_reload_stats_entry = n_reload_stats_entry;
262 parg.rsp_policy = &devlink_dl_reload_stats_entry_nest;
263 mnl_attr_for_each_nested(attr, nested) {
264 if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_STATS_ENTRY) {
265 parg.data = &dst->reload_stats_entry[i];
266 if (devlink_dl_reload_stats_entry_parse(&parg, attr))
276 void devlink_dl_reload_act_info_free(struct devlink_dl_reload_act_info *obj)
280 for (i = 0; i < obj->n_reload_action_stats; i++)
281 devlink_dl_reload_act_stats_free(&obj->reload_action_stats[i]);
282 free(obj->reload_action_stats);
285 int devlink_dl_reload_act_info_parse(struct ynl_parse_arg *yarg,
286 const struct nlattr *nested)
288 struct devlink_dl_reload_act_info *dst = yarg->data;
289 unsigned int n_reload_action_stats = 0;
290 const struct nlattr *attr;
291 struct ynl_parse_arg parg;
296 if (dst->reload_action_stats)
297 return ynl_error_parse(yarg, "attribute already present (dl-reload-act-info.reload-action-stats)");
299 mnl_attr_for_each_nested(attr, nested) {
300 unsigned int type = mnl_attr_get_type(attr);
302 if (type == DEVLINK_ATTR_RELOAD_ACTION) {
303 if (ynl_attr_validate(yarg, attr))
305 dst->_present.reload_action = 1;
306 dst->reload_action = mnl_attr_get_u8(attr);
307 } else if (type == DEVLINK_ATTR_RELOAD_ACTION_STATS) {
308 n_reload_action_stats++;
312 if (n_reload_action_stats) {
313 dst->reload_action_stats = calloc(n_reload_action_stats, sizeof(*dst->reload_action_stats));
314 dst->n_reload_action_stats = n_reload_action_stats;
316 parg.rsp_policy = &devlink_dl_reload_act_stats_nest;
317 mnl_attr_for_each_nested(attr, nested) {
318 if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION_STATS) {
319 parg.data = &dst->reload_action_stats[i];
320 if (devlink_dl_reload_act_stats_parse(&parg, attr))
330 void devlink_dl_reload_stats_free(struct devlink_dl_reload_stats *obj)
334 for (i = 0; i < obj->n_reload_action_info; i++)
335 devlink_dl_reload_act_info_free(&obj->reload_action_info[i]);
336 free(obj->reload_action_info);
339 int devlink_dl_reload_stats_parse(struct ynl_parse_arg *yarg,
340 const struct nlattr *nested)
342 struct devlink_dl_reload_stats *dst = yarg->data;
343 unsigned int n_reload_action_info = 0;
344 const struct nlattr *attr;
345 struct ynl_parse_arg parg;
350 if (dst->reload_action_info)
351 return ynl_error_parse(yarg, "attribute already present (dl-reload-stats.reload-action-info)");
353 mnl_attr_for_each_nested(attr, nested) {
354 unsigned int type = mnl_attr_get_type(attr);
356 if (type == DEVLINK_ATTR_RELOAD_ACTION_INFO) {
357 n_reload_action_info++;
361 if (n_reload_action_info) {
362 dst->reload_action_info = calloc(n_reload_action_info, sizeof(*dst->reload_action_info));
363 dst->n_reload_action_info = n_reload_action_info;
365 parg.rsp_policy = &devlink_dl_reload_act_info_nest;
366 mnl_attr_for_each_nested(attr, nested) {
367 if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION_INFO) {
368 parg.data = &dst->reload_action_info[i];
369 if (devlink_dl_reload_act_info_parse(&parg, attr))
379 void devlink_dl_dev_stats_free(struct devlink_dl_dev_stats *obj)
381 devlink_dl_reload_stats_free(&obj->reload_stats);
382 devlink_dl_reload_stats_free(&obj->remote_reload_stats);
385 int devlink_dl_dev_stats_parse(struct ynl_parse_arg *yarg,
386 const struct nlattr *nested)
388 struct devlink_dl_dev_stats *dst = yarg->data;
389 const struct nlattr *attr;
390 struct ynl_parse_arg parg;
394 mnl_attr_for_each_nested(attr, nested) {
395 unsigned int type = mnl_attr_get_type(attr);
397 if (type == DEVLINK_ATTR_RELOAD_STATS) {
398 if (ynl_attr_validate(yarg, attr))
400 dst->_present.reload_stats = 1;
402 parg.rsp_policy = &devlink_dl_reload_stats_nest;
403 parg.data = &dst->reload_stats;
404 if (devlink_dl_reload_stats_parse(&parg, attr))
406 } else if (type == DEVLINK_ATTR_REMOTE_RELOAD_STATS) {
407 if (ynl_attr_validate(yarg, attr))
409 dst->_present.remote_reload_stats = 1;
411 parg.rsp_policy = &devlink_dl_reload_stats_nest;
412 parg.data = &dst->remote_reload_stats;
413 if (devlink_dl_reload_stats_parse(&parg, attr))
421 /* ============== DEVLINK_CMD_GET ============== */
422 /* DEVLINK_CMD_GET - do */
423 void devlink_get_req_free(struct devlink_get_req *req)
430 void devlink_get_rsp_free(struct devlink_get_rsp *rsp)
434 devlink_dl_dev_stats_free(&rsp->dev_stats);
438 int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
440 struct ynl_parse_arg *yarg = data;
441 struct devlink_get_rsp *dst;
442 const struct nlattr *attr;
443 struct ynl_parse_arg parg;
448 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
449 unsigned int type = mnl_attr_get_type(attr);
451 if (type == DEVLINK_ATTR_BUS_NAME) {
454 if (ynl_attr_validate(yarg, attr))
457 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
458 dst->_present.bus_name_len = len;
459 dst->bus_name = malloc(len + 1);
460 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
461 dst->bus_name[len] = 0;
462 } else if (type == DEVLINK_ATTR_DEV_NAME) {
465 if (ynl_attr_validate(yarg, attr))
468 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
469 dst->_present.dev_name_len = len;
470 dst->dev_name = malloc(len + 1);
471 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
472 dst->dev_name[len] = 0;
473 } else if (type == DEVLINK_ATTR_RELOAD_FAILED) {
474 if (ynl_attr_validate(yarg, attr))
476 dst->_present.reload_failed = 1;
477 dst->reload_failed = mnl_attr_get_u8(attr);
478 } else if (type == DEVLINK_ATTR_RELOAD_ACTION) {
479 if (ynl_attr_validate(yarg, attr))
481 dst->_present.reload_action = 1;
482 dst->reload_action = mnl_attr_get_u8(attr);
483 } else if (type == DEVLINK_ATTR_DEV_STATS) {
484 if (ynl_attr_validate(yarg, attr))
486 dst->_present.dev_stats = 1;
488 parg.rsp_policy = &devlink_dl_dev_stats_nest;
489 parg.data = &dst->dev_stats;
490 if (devlink_dl_dev_stats_parse(&parg, attr))
498 struct devlink_get_rsp *
499 devlink_get(struct ynl_sock *ys, struct devlink_get_req *req)
501 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
502 struct devlink_get_rsp *rsp;
503 struct nlmsghdr *nlh;
506 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_GET, 1);
507 ys->req_policy = &devlink_nest;
508 yrs.yarg.rsp_policy = &devlink_nest;
510 if (req->_present.bus_name_len)
511 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
512 if (req->_present.dev_name_len)
513 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
515 rsp = calloc(1, sizeof(*rsp));
517 yrs.cb = devlink_get_rsp_parse;
520 err = ynl_exec(ys, nlh, &yrs);
527 devlink_get_rsp_free(rsp);
531 /* DEVLINK_CMD_GET - dump */
532 void devlink_get_list_free(struct devlink_get_list *rsp)
534 struct devlink_get_list *next = rsp;
536 while ((void *)next != YNL_LIST_END) {
540 free(rsp->obj.bus_name);
541 free(rsp->obj.dev_name);
542 devlink_dl_dev_stats_free(&rsp->obj.dev_stats);
547 struct devlink_get_list *devlink_get_dump(struct ynl_sock *ys)
549 struct ynl_dump_state yds = {};
550 struct nlmsghdr *nlh;
554 yds.alloc_sz = sizeof(struct devlink_get_list);
555 yds.cb = devlink_get_rsp_parse;
557 yds.rsp_policy = &devlink_nest;
559 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_GET, 1);
561 err = ynl_exec_dump(ys, nlh, &yds);
568 devlink_get_list_free(yds.first);
572 /* ============== DEVLINK_CMD_PORT_GET ============== */
573 /* DEVLINK_CMD_PORT_GET - do */
574 void devlink_port_get_req_free(struct devlink_port_get_req *req)
581 void devlink_port_get_rsp_free(struct devlink_port_get_rsp *rsp)
588 int devlink_port_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
590 struct ynl_parse_arg *yarg = data;
591 struct devlink_port_get_rsp *dst;
592 const struct nlattr *attr;
596 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
597 unsigned int type = mnl_attr_get_type(attr);
599 if (type == DEVLINK_ATTR_BUS_NAME) {
602 if (ynl_attr_validate(yarg, attr))
605 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
606 dst->_present.bus_name_len = len;
607 dst->bus_name = malloc(len + 1);
608 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
609 dst->bus_name[len] = 0;
610 } else if (type == DEVLINK_ATTR_DEV_NAME) {
613 if (ynl_attr_validate(yarg, attr))
616 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
617 dst->_present.dev_name_len = len;
618 dst->dev_name = malloc(len + 1);
619 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
620 dst->dev_name[len] = 0;
621 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
622 if (ynl_attr_validate(yarg, attr))
624 dst->_present.port_index = 1;
625 dst->port_index = mnl_attr_get_u32(attr);
632 struct devlink_port_get_rsp *
633 devlink_port_get(struct ynl_sock *ys, struct devlink_port_get_req *req)
635 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
636 struct devlink_port_get_rsp *rsp;
637 struct nlmsghdr *nlh;
640 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PORT_GET, 1);
641 ys->req_policy = &devlink_nest;
642 yrs.yarg.rsp_policy = &devlink_nest;
644 if (req->_present.bus_name_len)
645 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
646 if (req->_present.dev_name_len)
647 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
648 if (req->_present.port_index)
649 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
651 rsp = calloc(1, sizeof(*rsp));
653 yrs.cb = devlink_port_get_rsp_parse;
656 err = ynl_exec(ys, nlh, &yrs);
663 devlink_port_get_rsp_free(rsp);
667 /* DEVLINK_CMD_PORT_GET - dump */
668 int devlink_port_get_rsp_dump_parse(const struct nlmsghdr *nlh, void *data)
670 struct devlink_port_get_rsp_dump *dst;
671 struct ynl_parse_arg *yarg = data;
672 const struct nlattr *attr;
676 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
677 unsigned int type = mnl_attr_get_type(attr);
679 if (type == DEVLINK_ATTR_BUS_NAME) {
682 if (ynl_attr_validate(yarg, attr))
685 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
686 dst->_present.bus_name_len = len;
687 dst->bus_name = malloc(len + 1);
688 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
689 dst->bus_name[len] = 0;
690 } else if (type == DEVLINK_ATTR_DEV_NAME) {
693 if (ynl_attr_validate(yarg, attr))
696 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
697 dst->_present.dev_name_len = len;
698 dst->dev_name = malloc(len + 1);
699 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
700 dst->dev_name[len] = 0;
701 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
702 if (ynl_attr_validate(yarg, attr))
704 dst->_present.port_index = 1;
705 dst->port_index = mnl_attr_get_u32(attr);
712 void devlink_port_get_rsp_list_free(struct devlink_port_get_rsp_list *rsp)
714 struct devlink_port_get_rsp_list *next = rsp;
716 while ((void *)next != YNL_LIST_END) {
720 free(rsp->obj.bus_name);
721 free(rsp->obj.dev_name);
726 struct devlink_port_get_rsp_list *
727 devlink_port_get_dump(struct ynl_sock *ys,
728 struct devlink_port_get_req_dump *req)
730 struct ynl_dump_state yds = {};
731 struct nlmsghdr *nlh;
735 yds.alloc_sz = sizeof(struct devlink_port_get_rsp_list);
736 yds.cb = devlink_port_get_rsp_dump_parse;
738 yds.rsp_policy = &devlink_nest;
740 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_PORT_GET, 1);
741 ys->req_policy = &devlink_nest;
743 if (req->_present.bus_name_len)
744 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
745 if (req->_present.dev_name_len)
746 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
748 err = ynl_exec_dump(ys, nlh, &yds);
755 devlink_port_get_rsp_list_free(yds.first);
759 /* ============== DEVLINK_CMD_SB_GET ============== */
760 /* DEVLINK_CMD_SB_GET - do */
761 void devlink_sb_get_req_free(struct devlink_sb_get_req *req)
768 void devlink_sb_get_rsp_free(struct devlink_sb_get_rsp *rsp)
775 int devlink_sb_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
777 struct ynl_parse_arg *yarg = data;
778 struct devlink_sb_get_rsp *dst;
779 const struct nlattr *attr;
783 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
784 unsigned int type = mnl_attr_get_type(attr);
786 if (type == DEVLINK_ATTR_BUS_NAME) {
789 if (ynl_attr_validate(yarg, attr))
792 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
793 dst->_present.bus_name_len = len;
794 dst->bus_name = malloc(len + 1);
795 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
796 dst->bus_name[len] = 0;
797 } else if (type == DEVLINK_ATTR_DEV_NAME) {
800 if (ynl_attr_validate(yarg, attr))
803 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
804 dst->_present.dev_name_len = len;
805 dst->dev_name = malloc(len + 1);
806 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
807 dst->dev_name[len] = 0;
808 } else if (type == DEVLINK_ATTR_SB_INDEX) {
809 if (ynl_attr_validate(yarg, attr))
811 dst->_present.sb_index = 1;
812 dst->sb_index = mnl_attr_get_u32(attr);
819 struct devlink_sb_get_rsp *
820 devlink_sb_get(struct ynl_sock *ys, struct devlink_sb_get_req *req)
822 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
823 struct devlink_sb_get_rsp *rsp;
824 struct nlmsghdr *nlh;
827 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_GET, 1);
828 ys->req_policy = &devlink_nest;
829 yrs.yarg.rsp_policy = &devlink_nest;
831 if (req->_present.bus_name_len)
832 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
833 if (req->_present.dev_name_len)
834 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
835 if (req->_present.sb_index)
836 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
838 rsp = calloc(1, sizeof(*rsp));
840 yrs.cb = devlink_sb_get_rsp_parse;
841 yrs.rsp_cmd = DEVLINK_CMD_SB_GET;
843 err = ynl_exec(ys, nlh, &yrs);
850 devlink_sb_get_rsp_free(rsp);
854 /* DEVLINK_CMD_SB_GET - dump */
855 void devlink_sb_get_list_free(struct devlink_sb_get_list *rsp)
857 struct devlink_sb_get_list *next = rsp;
859 while ((void *)next != YNL_LIST_END) {
863 free(rsp->obj.bus_name);
864 free(rsp->obj.dev_name);
869 struct devlink_sb_get_list *
870 devlink_sb_get_dump(struct ynl_sock *ys, struct devlink_sb_get_req_dump *req)
872 struct ynl_dump_state yds = {};
873 struct nlmsghdr *nlh;
877 yds.alloc_sz = sizeof(struct devlink_sb_get_list);
878 yds.cb = devlink_sb_get_rsp_parse;
879 yds.rsp_cmd = DEVLINK_CMD_SB_GET;
880 yds.rsp_policy = &devlink_nest;
882 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_GET, 1);
883 ys->req_policy = &devlink_nest;
885 if (req->_present.bus_name_len)
886 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
887 if (req->_present.dev_name_len)
888 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
890 err = ynl_exec_dump(ys, nlh, &yds);
897 devlink_sb_get_list_free(yds.first);
901 /* ============== DEVLINK_CMD_SB_POOL_GET ============== */
902 /* DEVLINK_CMD_SB_POOL_GET - do */
903 void devlink_sb_pool_get_req_free(struct devlink_sb_pool_get_req *req)
910 void devlink_sb_pool_get_rsp_free(struct devlink_sb_pool_get_rsp *rsp)
917 int devlink_sb_pool_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
919 struct devlink_sb_pool_get_rsp *dst;
920 struct ynl_parse_arg *yarg = data;
921 const struct nlattr *attr;
925 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
926 unsigned int type = mnl_attr_get_type(attr);
928 if (type == DEVLINK_ATTR_BUS_NAME) {
931 if (ynl_attr_validate(yarg, attr))
934 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
935 dst->_present.bus_name_len = len;
936 dst->bus_name = malloc(len + 1);
937 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
938 dst->bus_name[len] = 0;
939 } else if (type == DEVLINK_ATTR_DEV_NAME) {
942 if (ynl_attr_validate(yarg, attr))
945 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
946 dst->_present.dev_name_len = len;
947 dst->dev_name = malloc(len + 1);
948 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
949 dst->dev_name[len] = 0;
950 } else if (type == DEVLINK_ATTR_SB_INDEX) {
951 if (ynl_attr_validate(yarg, attr))
953 dst->_present.sb_index = 1;
954 dst->sb_index = mnl_attr_get_u32(attr);
955 } else if (type == DEVLINK_ATTR_SB_POOL_INDEX) {
956 if (ynl_attr_validate(yarg, attr))
958 dst->_present.sb_pool_index = 1;
959 dst->sb_pool_index = mnl_attr_get_u16(attr);
966 struct devlink_sb_pool_get_rsp *
967 devlink_sb_pool_get(struct ynl_sock *ys, struct devlink_sb_pool_get_req *req)
969 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
970 struct devlink_sb_pool_get_rsp *rsp;
971 struct nlmsghdr *nlh;
974 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_POOL_GET, 1);
975 ys->req_policy = &devlink_nest;
976 yrs.yarg.rsp_policy = &devlink_nest;
978 if (req->_present.bus_name_len)
979 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
980 if (req->_present.dev_name_len)
981 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
982 if (req->_present.sb_index)
983 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
984 if (req->_present.sb_pool_index)
985 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
987 rsp = calloc(1, sizeof(*rsp));
989 yrs.cb = devlink_sb_pool_get_rsp_parse;
990 yrs.rsp_cmd = DEVLINK_CMD_SB_POOL_GET;
992 err = ynl_exec(ys, nlh, &yrs);
999 devlink_sb_pool_get_rsp_free(rsp);
1003 /* DEVLINK_CMD_SB_POOL_GET - dump */
1004 void devlink_sb_pool_get_list_free(struct devlink_sb_pool_get_list *rsp)
1006 struct devlink_sb_pool_get_list *next = rsp;
1008 while ((void *)next != YNL_LIST_END) {
1012 free(rsp->obj.bus_name);
1013 free(rsp->obj.dev_name);
1018 struct devlink_sb_pool_get_list *
1019 devlink_sb_pool_get_dump(struct ynl_sock *ys,
1020 struct devlink_sb_pool_get_req_dump *req)
1022 struct ynl_dump_state yds = {};
1023 struct nlmsghdr *nlh;
1027 yds.alloc_sz = sizeof(struct devlink_sb_pool_get_list);
1028 yds.cb = devlink_sb_pool_get_rsp_parse;
1029 yds.rsp_cmd = DEVLINK_CMD_SB_POOL_GET;
1030 yds.rsp_policy = &devlink_nest;
1032 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_POOL_GET, 1);
1033 ys->req_policy = &devlink_nest;
1035 if (req->_present.bus_name_len)
1036 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1037 if (req->_present.dev_name_len)
1038 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1040 err = ynl_exec_dump(ys, nlh, &yds);
1047 devlink_sb_pool_get_list_free(yds.first);
1051 /* ============== DEVLINK_CMD_SB_PORT_POOL_GET ============== */
1052 /* DEVLINK_CMD_SB_PORT_POOL_GET - do */
1054 devlink_sb_port_pool_get_req_free(struct devlink_sb_port_pool_get_req *req)
1056 free(req->bus_name);
1057 free(req->dev_name);
1062 devlink_sb_port_pool_get_rsp_free(struct devlink_sb_port_pool_get_rsp *rsp)
1064 free(rsp->bus_name);
1065 free(rsp->dev_name);
1069 int devlink_sb_port_pool_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
1071 struct devlink_sb_port_pool_get_rsp *dst;
1072 struct ynl_parse_arg *yarg = data;
1073 const struct nlattr *attr;
1077 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1078 unsigned int type = mnl_attr_get_type(attr);
1080 if (type == DEVLINK_ATTR_BUS_NAME) {
1083 if (ynl_attr_validate(yarg, attr))
1084 return MNL_CB_ERROR;
1086 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1087 dst->_present.bus_name_len = len;
1088 dst->bus_name = malloc(len + 1);
1089 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
1090 dst->bus_name[len] = 0;
1091 } else if (type == DEVLINK_ATTR_DEV_NAME) {
1094 if (ynl_attr_validate(yarg, attr))
1095 return MNL_CB_ERROR;
1097 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1098 dst->_present.dev_name_len = len;
1099 dst->dev_name = malloc(len + 1);
1100 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
1101 dst->dev_name[len] = 0;
1102 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
1103 if (ynl_attr_validate(yarg, attr))
1104 return MNL_CB_ERROR;
1105 dst->_present.port_index = 1;
1106 dst->port_index = mnl_attr_get_u32(attr);
1107 } else if (type == DEVLINK_ATTR_SB_INDEX) {
1108 if (ynl_attr_validate(yarg, attr))
1109 return MNL_CB_ERROR;
1110 dst->_present.sb_index = 1;
1111 dst->sb_index = mnl_attr_get_u32(attr);
1112 } else if (type == DEVLINK_ATTR_SB_POOL_INDEX) {
1113 if (ynl_attr_validate(yarg, attr))
1114 return MNL_CB_ERROR;
1115 dst->_present.sb_pool_index = 1;
1116 dst->sb_pool_index = mnl_attr_get_u16(attr);
1123 struct devlink_sb_port_pool_get_rsp *
1124 devlink_sb_port_pool_get(struct ynl_sock *ys,
1125 struct devlink_sb_port_pool_get_req *req)
1127 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
1128 struct devlink_sb_port_pool_get_rsp *rsp;
1129 struct nlmsghdr *nlh;
1132 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_PORT_POOL_GET, 1);
1133 ys->req_policy = &devlink_nest;
1134 yrs.yarg.rsp_policy = &devlink_nest;
1136 if (req->_present.bus_name_len)
1137 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1138 if (req->_present.dev_name_len)
1139 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1140 if (req->_present.port_index)
1141 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
1142 if (req->_present.sb_index)
1143 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
1144 if (req->_present.sb_pool_index)
1145 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_POOL_INDEX, req->sb_pool_index);
1147 rsp = calloc(1, sizeof(*rsp));
1148 yrs.yarg.data = rsp;
1149 yrs.cb = devlink_sb_port_pool_get_rsp_parse;
1150 yrs.rsp_cmd = DEVLINK_CMD_SB_PORT_POOL_GET;
1152 err = ynl_exec(ys, nlh, &yrs);
1159 devlink_sb_port_pool_get_rsp_free(rsp);
1163 /* DEVLINK_CMD_SB_PORT_POOL_GET - dump */
1165 devlink_sb_port_pool_get_list_free(struct devlink_sb_port_pool_get_list *rsp)
1167 struct devlink_sb_port_pool_get_list *next = rsp;
1169 while ((void *)next != YNL_LIST_END) {
1173 free(rsp->obj.bus_name);
1174 free(rsp->obj.dev_name);
1179 struct devlink_sb_port_pool_get_list *
1180 devlink_sb_port_pool_get_dump(struct ynl_sock *ys,
1181 struct devlink_sb_port_pool_get_req_dump *req)
1183 struct ynl_dump_state yds = {};
1184 struct nlmsghdr *nlh;
1188 yds.alloc_sz = sizeof(struct devlink_sb_port_pool_get_list);
1189 yds.cb = devlink_sb_port_pool_get_rsp_parse;
1190 yds.rsp_cmd = DEVLINK_CMD_SB_PORT_POOL_GET;
1191 yds.rsp_policy = &devlink_nest;
1193 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_PORT_POOL_GET, 1);
1194 ys->req_policy = &devlink_nest;
1196 if (req->_present.bus_name_len)
1197 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1198 if (req->_present.dev_name_len)
1199 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1201 err = ynl_exec_dump(ys, nlh, &yds);
1208 devlink_sb_port_pool_get_list_free(yds.first);
1212 /* ============== DEVLINK_CMD_SB_TC_POOL_BIND_GET ============== */
1213 /* DEVLINK_CMD_SB_TC_POOL_BIND_GET - do */
1215 devlink_sb_tc_pool_bind_get_req_free(struct devlink_sb_tc_pool_bind_get_req *req)
1217 free(req->bus_name);
1218 free(req->dev_name);
1223 devlink_sb_tc_pool_bind_get_rsp_free(struct devlink_sb_tc_pool_bind_get_rsp *rsp)
1225 free(rsp->bus_name);
1226 free(rsp->dev_name);
1230 int devlink_sb_tc_pool_bind_get_rsp_parse(const struct nlmsghdr *nlh,
1233 struct devlink_sb_tc_pool_bind_get_rsp *dst;
1234 struct ynl_parse_arg *yarg = data;
1235 const struct nlattr *attr;
1239 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1240 unsigned int type = mnl_attr_get_type(attr);
1242 if (type == DEVLINK_ATTR_BUS_NAME) {
1245 if (ynl_attr_validate(yarg, attr))
1246 return MNL_CB_ERROR;
1248 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1249 dst->_present.bus_name_len = len;
1250 dst->bus_name = malloc(len + 1);
1251 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
1252 dst->bus_name[len] = 0;
1253 } else if (type == DEVLINK_ATTR_DEV_NAME) {
1256 if (ynl_attr_validate(yarg, attr))
1257 return MNL_CB_ERROR;
1259 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1260 dst->_present.dev_name_len = len;
1261 dst->dev_name = malloc(len + 1);
1262 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
1263 dst->dev_name[len] = 0;
1264 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
1265 if (ynl_attr_validate(yarg, attr))
1266 return MNL_CB_ERROR;
1267 dst->_present.port_index = 1;
1268 dst->port_index = mnl_attr_get_u32(attr);
1269 } else if (type == DEVLINK_ATTR_SB_INDEX) {
1270 if (ynl_attr_validate(yarg, attr))
1271 return MNL_CB_ERROR;
1272 dst->_present.sb_index = 1;
1273 dst->sb_index = mnl_attr_get_u32(attr);
1274 } else if (type == DEVLINK_ATTR_SB_POOL_TYPE) {
1275 if (ynl_attr_validate(yarg, attr))
1276 return MNL_CB_ERROR;
1277 dst->_present.sb_pool_type = 1;
1278 dst->sb_pool_type = mnl_attr_get_u8(attr);
1279 } else if (type == DEVLINK_ATTR_SB_TC_INDEX) {
1280 if (ynl_attr_validate(yarg, attr))
1281 return MNL_CB_ERROR;
1282 dst->_present.sb_tc_index = 1;
1283 dst->sb_tc_index = mnl_attr_get_u16(attr);
1290 struct devlink_sb_tc_pool_bind_get_rsp *
1291 devlink_sb_tc_pool_bind_get(struct ynl_sock *ys,
1292 struct devlink_sb_tc_pool_bind_get_req *req)
1294 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
1295 struct devlink_sb_tc_pool_bind_get_rsp *rsp;
1296 struct nlmsghdr *nlh;
1299 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SB_TC_POOL_BIND_GET, 1);
1300 ys->req_policy = &devlink_nest;
1301 yrs.yarg.rsp_policy = &devlink_nest;
1303 if (req->_present.bus_name_len)
1304 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1305 if (req->_present.dev_name_len)
1306 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1307 if (req->_present.port_index)
1308 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
1309 if (req->_present.sb_index)
1310 mnl_attr_put_u32(nlh, DEVLINK_ATTR_SB_INDEX, req->sb_index);
1311 if (req->_present.sb_pool_type)
1312 mnl_attr_put_u8(nlh, DEVLINK_ATTR_SB_POOL_TYPE, req->sb_pool_type);
1313 if (req->_present.sb_tc_index)
1314 mnl_attr_put_u16(nlh, DEVLINK_ATTR_SB_TC_INDEX, req->sb_tc_index);
1316 rsp = calloc(1, sizeof(*rsp));
1317 yrs.yarg.data = rsp;
1318 yrs.cb = devlink_sb_tc_pool_bind_get_rsp_parse;
1319 yrs.rsp_cmd = DEVLINK_CMD_SB_TC_POOL_BIND_GET;
1321 err = ynl_exec(ys, nlh, &yrs);
1328 devlink_sb_tc_pool_bind_get_rsp_free(rsp);
1332 /* DEVLINK_CMD_SB_TC_POOL_BIND_GET - dump */
1334 devlink_sb_tc_pool_bind_get_list_free(struct devlink_sb_tc_pool_bind_get_list *rsp)
1336 struct devlink_sb_tc_pool_bind_get_list *next = rsp;
1338 while ((void *)next != YNL_LIST_END) {
1342 free(rsp->obj.bus_name);
1343 free(rsp->obj.dev_name);
1348 struct devlink_sb_tc_pool_bind_get_list *
1349 devlink_sb_tc_pool_bind_get_dump(struct ynl_sock *ys,
1350 struct devlink_sb_tc_pool_bind_get_req_dump *req)
1352 struct ynl_dump_state yds = {};
1353 struct nlmsghdr *nlh;
1357 yds.alloc_sz = sizeof(struct devlink_sb_tc_pool_bind_get_list);
1358 yds.cb = devlink_sb_tc_pool_bind_get_rsp_parse;
1359 yds.rsp_cmd = DEVLINK_CMD_SB_TC_POOL_BIND_GET;
1360 yds.rsp_policy = &devlink_nest;
1362 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SB_TC_POOL_BIND_GET, 1);
1363 ys->req_policy = &devlink_nest;
1365 if (req->_present.bus_name_len)
1366 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1367 if (req->_present.dev_name_len)
1368 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1370 err = ynl_exec_dump(ys, nlh, &yds);
1377 devlink_sb_tc_pool_bind_get_list_free(yds.first);
1381 /* ============== DEVLINK_CMD_PARAM_GET ============== */
1382 /* DEVLINK_CMD_PARAM_GET - do */
1383 void devlink_param_get_req_free(struct devlink_param_get_req *req)
1385 free(req->bus_name);
1386 free(req->dev_name);
1387 free(req->param_name);
1391 void devlink_param_get_rsp_free(struct devlink_param_get_rsp *rsp)
1393 free(rsp->bus_name);
1394 free(rsp->dev_name);
1395 free(rsp->param_name);
1399 int devlink_param_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
1401 struct devlink_param_get_rsp *dst;
1402 struct ynl_parse_arg *yarg = data;
1403 const struct nlattr *attr;
1407 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1408 unsigned int type = mnl_attr_get_type(attr);
1410 if (type == DEVLINK_ATTR_BUS_NAME) {
1413 if (ynl_attr_validate(yarg, attr))
1414 return MNL_CB_ERROR;
1416 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1417 dst->_present.bus_name_len = len;
1418 dst->bus_name = malloc(len + 1);
1419 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
1420 dst->bus_name[len] = 0;
1421 } else if (type == DEVLINK_ATTR_DEV_NAME) {
1424 if (ynl_attr_validate(yarg, attr))
1425 return MNL_CB_ERROR;
1427 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1428 dst->_present.dev_name_len = len;
1429 dst->dev_name = malloc(len + 1);
1430 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
1431 dst->dev_name[len] = 0;
1432 } else if (type == DEVLINK_ATTR_PARAM_NAME) {
1435 if (ynl_attr_validate(yarg, attr))
1436 return MNL_CB_ERROR;
1438 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1439 dst->_present.param_name_len = len;
1440 dst->param_name = malloc(len + 1);
1441 memcpy(dst->param_name, mnl_attr_get_str(attr), len);
1442 dst->param_name[len] = 0;
1449 struct devlink_param_get_rsp *
1450 devlink_param_get(struct ynl_sock *ys, struct devlink_param_get_req *req)
1452 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
1453 struct devlink_param_get_rsp *rsp;
1454 struct nlmsghdr *nlh;
1457 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_PARAM_GET, 1);
1458 ys->req_policy = &devlink_nest;
1459 yrs.yarg.rsp_policy = &devlink_nest;
1461 if (req->_present.bus_name_len)
1462 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1463 if (req->_present.dev_name_len)
1464 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1465 if (req->_present.param_name_len)
1466 mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_NAME, req->param_name);
1468 rsp = calloc(1, sizeof(*rsp));
1469 yrs.yarg.data = rsp;
1470 yrs.cb = devlink_param_get_rsp_parse;
1471 yrs.rsp_cmd = DEVLINK_CMD_PARAM_GET;
1473 err = ynl_exec(ys, nlh, &yrs);
1480 devlink_param_get_rsp_free(rsp);
1484 /* DEVLINK_CMD_PARAM_GET - dump */
1485 void devlink_param_get_list_free(struct devlink_param_get_list *rsp)
1487 struct devlink_param_get_list *next = rsp;
1489 while ((void *)next != YNL_LIST_END) {
1493 free(rsp->obj.bus_name);
1494 free(rsp->obj.dev_name);
1495 free(rsp->obj.param_name);
1500 struct devlink_param_get_list *
1501 devlink_param_get_dump(struct ynl_sock *ys,
1502 struct devlink_param_get_req_dump *req)
1504 struct ynl_dump_state yds = {};
1505 struct nlmsghdr *nlh;
1509 yds.alloc_sz = sizeof(struct devlink_param_get_list);
1510 yds.cb = devlink_param_get_rsp_parse;
1511 yds.rsp_cmd = DEVLINK_CMD_PARAM_GET;
1512 yds.rsp_policy = &devlink_nest;
1514 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_PARAM_GET, 1);
1515 ys->req_policy = &devlink_nest;
1517 if (req->_present.bus_name_len)
1518 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1519 if (req->_present.dev_name_len)
1520 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1522 err = ynl_exec_dump(ys, nlh, &yds);
1529 devlink_param_get_list_free(yds.first);
1533 /* ============== DEVLINK_CMD_REGION_GET ============== */
1534 /* DEVLINK_CMD_REGION_GET - do */
1535 void devlink_region_get_req_free(struct devlink_region_get_req *req)
1537 free(req->bus_name);
1538 free(req->dev_name);
1539 free(req->region_name);
1543 void devlink_region_get_rsp_free(struct devlink_region_get_rsp *rsp)
1545 free(rsp->bus_name);
1546 free(rsp->dev_name);
1547 free(rsp->region_name);
1551 int devlink_region_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
1553 struct devlink_region_get_rsp *dst;
1554 struct ynl_parse_arg *yarg = data;
1555 const struct nlattr *attr;
1559 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1560 unsigned int type = mnl_attr_get_type(attr);
1562 if (type == DEVLINK_ATTR_BUS_NAME) {
1565 if (ynl_attr_validate(yarg, attr))
1566 return MNL_CB_ERROR;
1568 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1569 dst->_present.bus_name_len = len;
1570 dst->bus_name = malloc(len + 1);
1571 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
1572 dst->bus_name[len] = 0;
1573 } else if (type == DEVLINK_ATTR_DEV_NAME) {
1576 if (ynl_attr_validate(yarg, attr))
1577 return MNL_CB_ERROR;
1579 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1580 dst->_present.dev_name_len = len;
1581 dst->dev_name = malloc(len + 1);
1582 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
1583 dst->dev_name[len] = 0;
1584 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
1585 if (ynl_attr_validate(yarg, attr))
1586 return MNL_CB_ERROR;
1587 dst->_present.port_index = 1;
1588 dst->port_index = mnl_attr_get_u32(attr);
1589 } else if (type == DEVLINK_ATTR_REGION_NAME) {
1592 if (ynl_attr_validate(yarg, attr))
1593 return MNL_CB_ERROR;
1595 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1596 dst->_present.region_name_len = len;
1597 dst->region_name = malloc(len + 1);
1598 memcpy(dst->region_name, mnl_attr_get_str(attr), len);
1599 dst->region_name[len] = 0;
1606 struct devlink_region_get_rsp *
1607 devlink_region_get(struct ynl_sock *ys, struct devlink_region_get_req *req)
1609 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
1610 struct devlink_region_get_rsp *rsp;
1611 struct nlmsghdr *nlh;
1614 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_REGION_GET, 1);
1615 ys->req_policy = &devlink_nest;
1616 yrs.yarg.rsp_policy = &devlink_nest;
1618 if (req->_present.bus_name_len)
1619 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1620 if (req->_present.dev_name_len)
1621 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1622 if (req->_present.port_index)
1623 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
1624 if (req->_present.region_name_len)
1625 mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, req->region_name);
1627 rsp = calloc(1, sizeof(*rsp));
1628 yrs.yarg.data = rsp;
1629 yrs.cb = devlink_region_get_rsp_parse;
1630 yrs.rsp_cmd = DEVLINK_CMD_REGION_GET;
1632 err = ynl_exec(ys, nlh, &yrs);
1639 devlink_region_get_rsp_free(rsp);
1643 /* DEVLINK_CMD_REGION_GET - dump */
1644 void devlink_region_get_list_free(struct devlink_region_get_list *rsp)
1646 struct devlink_region_get_list *next = rsp;
1648 while ((void *)next != YNL_LIST_END) {
1652 free(rsp->obj.bus_name);
1653 free(rsp->obj.dev_name);
1654 free(rsp->obj.region_name);
1659 struct devlink_region_get_list *
1660 devlink_region_get_dump(struct ynl_sock *ys,
1661 struct devlink_region_get_req_dump *req)
1663 struct ynl_dump_state yds = {};
1664 struct nlmsghdr *nlh;
1668 yds.alloc_sz = sizeof(struct devlink_region_get_list);
1669 yds.cb = devlink_region_get_rsp_parse;
1670 yds.rsp_cmd = DEVLINK_CMD_REGION_GET;
1671 yds.rsp_policy = &devlink_nest;
1673 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_REGION_GET, 1);
1674 ys->req_policy = &devlink_nest;
1676 if (req->_present.bus_name_len)
1677 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1678 if (req->_present.dev_name_len)
1679 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1681 err = ynl_exec_dump(ys, nlh, &yds);
1688 devlink_region_get_list_free(yds.first);
1692 /* ============== DEVLINK_CMD_INFO_GET ============== */
1693 /* DEVLINK_CMD_INFO_GET - do */
1694 void devlink_info_get_req_free(struct devlink_info_get_req *req)
1696 free(req->bus_name);
1697 free(req->dev_name);
1701 void devlink_info_get_rsp_free(struct devlink_info_get_rsp *rsp)
1705 free(rsp->bus_name);
1706 free(rsp->dev_name);
1707 free(rsp->info_driver_name);
1708 free(rsp->info_serial_number);
1709 for (i = 0; i < rsp->n_info_version_fixed; i++)
1710 devlink_dl_info_version_free(&rsp->info_version_fixed[i]);
1711 free(rsp->info_version_fixed);
1712 for (i = 0; i < rsp->n_info_version_running; i++)
1713 devlink_dl_info_version_free(&rsp->info_version_running[i]);
1714 free(rsp->info_version_running);
1715 for (i = 0; i < rsp->n_info_version_stored; i++)
1716 devlink_dl_info_version_free(&rsp->info_version_stored[i]);
1717 free(rsp->info_version_stored);
1721 int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
1723 unsigned int n_info_version_running = 0;
1724 unsigned int n_info_version_stored = 0;
1725 unsigned int n_info_version_fixed = 0;
1726 struct ynl_parse_arg *yarg = data;
1727 struct devlink_info_get_rsp *dst;
1728 const struct nlattr *attr;
1729 struct ynl_parse_arg parg;
1735 if (dst->info_version_fixed)
1736 return ynl_error_parse(yarg, "attribute already present (devlink.info-version-fixed)");
1737 if (dst->info_version_running)
1738 return ynl_error_parse(yarg, "attribute already present (devlink.info-version-running)");
1739 if (dst->info_version_stored)
1740 return ynl_error_parse(yarg, "attribute already present (devlink.info-version-stored)");
1742 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1743 unsigned int type = mnl_attr_get_type(attr);
1745 if (type == DEVLINK_ATTR_BUS_NAME) {
1748 if (ynl_attr_validate(yarg, attr))
1749 return MNL_CB_ERROR;
1751 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1752 dst->_present.bus_name_len = len;
1753 dst->bus_name = malloc(len + 1);
1754 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
1755 dst->bus_name[len] = 0;
1756 } else if (type == DEVLINK_ATTR_DEV_NAME) {
1759 if (ynl_attr_validate(yarg, attr))
1760 return MNL_CB_ERROR;
1762 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1763 dst->_present.dev_name_len = len;
1764 dst->dev_name = malloc(len + 1);
1765 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
1766 dst->dev_name[len] = 0;
1767 } else if (type == DEVLINK_ATTR_INFO_DRIVER_NAME) {
1770 if (ynl_attr_validate(yarg, attr))
1771 return MNL_CB_ERROR;
1773 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1774 dst->_present.info_driver_name_len = len;
1775 dst->info_driver_name = malloc(len + 1);
1776 memcpy(dst->info_driver_name, mnl_attr_get_str(attr), len);
1777 dst->info_driver_name[len] = 0;
1778 } else if (type == DEVLINK_ATTR_INFO_SERIAL_NUMBER) {
1781 if (ynl_attr_validate(yarg, attr))
1782 return MNL_CB_ERROR;
1784 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1785 dst->_present.info_serial_number_len = len;
1786 dst->info_serial_number = malloc(len + 1);
1787 memcpy(dst->info_serial_number, mnl_attr_get_str(attr), len);
1788 dst->info_serial_number[len] = 0;
1789 } else if (type == DEVLINK_ATTR_INFO_VERSION_FIXED) {
1790 n_info_version_fixed++;
1791 } else if (type == DEVLINK_ATTR_INFO_VERSION_RUNNING) {
1792 n_info_version_running++;
1793 } else if (type == DEVLINK_ATTR_INFO_VERSION_STORED) {
1794 n_info_version_stored++;
1798 if (n_info_version_fixed) {
1799 dst->info_version_fixed = calloc(n_info_version_fixed, sizeof(*dst->info_version_fixed));
1800 dst->n_info_version_fixed = n_info_version_fixed;
1802 parg.rsp_policy = &devlink_dl_info_version_nest;
1803 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1804 if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_FIXED) {
1805 parg.data = &dst->info_version_fixed[i];
1806 if (devlink_dl_info_version_parse(&parg, attr))
1807 return MNL_CB_ERROR;
1812 if (n_info_version_running) {
1813 dst->info_version_running = calloc(n_info_version_running, sizeof(*dst->info_version_running));
1814 dst->n_info_version_running = n_info_version_running;
1816 parg.rsp_policy = &devlink_dl_info_version_nest;
1817 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1818 if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_RUNNING) {
1819 parg.data = &dst->info_version_running[i];
1820 if (devlink_dl_info_version_parse(&parg, attr))
1821 return MNL_CB_ERROR;
1826 if (n_info_version_stored) {
1827 dst->info_version_stored = calloc(n_info_version_stored, sizeof(*dst->info_version_stored));
1828 dst->n_info_version_stored = n_info_version_stored;
1830 parg.rsp_policy = &devlink_dl_info_version_nest;
1831 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1832 if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_STORED) {
1833 parg.data = &dst->info_version_stored[i];
1834 if (devlink_dl_info_version_parse(&parg, attr))
1835 return MNL_CB_ERROR;
1844 struct devlink_info_get_rsp *
1845 devlink_info_get(struct ynl_sock *ys, struct devlink_info_get_req *req)
1847 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
1848 struct devlink_info_get_rsp *rsp;
1849 struct nlmsghdr *nlh;
1852 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_INFO_GET, 1);
1853 ys->req_policy = &devlink_nest;
1854 yrs.yarg.rsp_policy = &devlink_nest;
1856 if (req->_present.bus_name_len)
1857 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
1858 if (req->_present.dev_name_len)
1859 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
1861 rsp = calloc(1, sizeof(*rsp));
1862 yrs.yarg.data = rsp;
1863 yrs.cb = devlink_info_get_rsp_parse;
1864 yrs.rsp_cmd = DEVLINK_CMD_INFO_GET;
1866 err = ynl_exec(ys, nlh, &yrs);
1873 devlink_info_get_rsp_free(rsp);
1877 /* DEVLINK_CMD_INFO_GET - dump */
1878 void devlink_info_get_list_free(struct devlink_info_get_list *rsp)
1880 struct devlink_info_get_list *next = rsp;
1882 while ((void *)next != YNL_LIST_END) {
1888 free(rsp->obj.bus_name);
1889 free(rsp->obj.dev_name);
1890 free(rsp->obj.info_driver_name);
1891 free(rsp->obj.info_serial_number);
1892 for (i = 0; i < rsp->obj.n_info_version_fixed; i++)
1893 devlink_dl_info_version_free(&rsp->obj.info_version_fixed[i]);
1894 free(rsp->obj.info_version_fixed);
1895 for (i = 0; i < rsp->obj.n_info_version_running; i++)
1896 devlink_dl_info_version_free(&rsp->obj.info_version_running[i]);
1897 free(rsp->obj.info_version_running);
1898 for (i = 0; i < rsp->obj.n_info_version_stored; i++)
1899 devlink_dl_info_version_free(&rsp->obj.info_version_stored[i]);
1900 free(rsp->obj.info_version_stored);
1905 struct devlink_info_get_list *devlink_info_get_dump(struct ynl_sock *ys)
1907 struct ynl_dump_state yds = {};
1908 struct nlmsghdr *nlh;
1912 yds.alloc_sz = sizeof(struct devlink_info_get_list);
1913 yds.cb = devlink_info_get_rsp_parse;
1914 yds.rsp_cmd = DEVLINK_CMD_INFO_GET;
1915 yds.rsp_policy = &devlink_nest;
1917 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_INFO_GET, 1);
1919 err = ynl_exec_dump(ys, nlh, &yds);
1926 devlink_info_get_list_free(yds.first);
1930 /* ============== DEVLINK_CMD_HEALTH_REPORTER_GET ============== */
1931 /* DEVLINK_CMD_HEALTH_REPORTER_GET - do */
1933 devlink_health_reporter_get_req_free(struct devlink_health_reporter_get_req *req)
1935 free(req->bus_name);
1936 free(req->dev_name);
1937 free(req->health_reporter_name);
1942 devlink_health_reporter_get_rsp_free(struct devlink_health_reporter_get_rsp *rsp)
1944 free(rsp->bus_name);
1945 free(rsp->dev_name);
1946 free(rsp->health_reporter_name);
1950 int devlink_health_reporter_get_rsp_parse(const struct nlmsghdr *nlh,
1953 struct devlink_health_reporter_get_rsp *dst;
1954 struct ynl_parse_arg *yarg = data;
1955 const struct nlattr *attr;
1959 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
1960 unsigned int type = mnl_attr_get_type(attr);
1962 if (type == DEVLINK_ATTR_BUS_NAME) {
1965 if (ynl_attr_validate(yarg, attr))
1966 return MNL_CB_ERROR;
1968 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1969 dst->_present.bus_name_len = len;
1970 dst->bus_name = malloc(len + 1);
1971 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
1972 dst->bus_name[len] = 0;
1973 } else if (type == DEVLINK_ATTR_DEV_NAME) {
1976 if (ynl_attr_validate(yarg, attr))
1977 return MNL_CB_ERROR;
1979 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1980 dst->_present.dev_name_len = len;
1981 dst->dev_name = malloc(len + 1);
1982 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
1983 dst->dev_name[len] = 0;
1984 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
1985 if (ynl_attr_validate(yarg, attr))
1986 return MNL_CB_ERROR;
1987 dst->_present.port_index = 1;
1988 dst->port_index = mnl_attr_get_u32(attr);
1989 } else if (type == DEVLINK_ATTR_HEALTH_REPORTER_NAME) {
1992 if (ynl_attr_validate(yarg, attr))
1993 return MNL_CB_ERROR;
1995 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
1996 dst->_present.health_reporter_name_len = len;
1997 dst->health_reporter_name = malloc(len + 1);
1998 memcpy(dst->health_reporter_name, mnl_attr_get_str(attr), len);
1999 dst->health_reporter_name[len] = 0;
2006 struct devlink_health_reporter_get_rsp *
2007 devlink_health_reporter_get(struct ynl_sock *ys,
2008 struct devlink_health_reporter_get_req *req)
2010 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2011 struct devlink_health_reporter_get_rsp *rsp;
2012 struct nlmsghdr *nlh;
2015 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_GET, 1);
2016 ys->req_policy = &devlink_nest;
2017 yrs.yarg.rsp_policy = &devlink_nest;
2019 if (req->_present.bus_name_len)
2020 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2021 if (req->_present.dev_name_len)
2022 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2023 if (req->_present.port_index)
2024 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2025 if (req->_present.health_reporter_name_len)
2026 mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME, req->health_reporter_name);
2028 rsp = calloc(1, sizeof(*rsp));
2029 yrs.yarg.data = rsp;
2030 yrs.cb = devlink_health_reporter_get_rsp_parse;
2031 yrs.rsp_cmd = DEVLINK_CMD_HEALTH_REPORTER_GET;
2033 err = ynl_exec(ys, nlh, &yrs);
2040 devlink_health_reporter_get_rsp_free(rsp);
2044 /* DEVLINK_CMD_HEALTH_REPORTER_GET - dump */
2046 devlink_health_reporter_get_list_free(struct devlink_health_reporter_get_list *rsp)
2048 struct devlink_health_reporter_get_list *next = rsp;
2050 while ((void *)next != YNL_LIST_END) {
2054 free(rsp->obj.bus_name);
2055 free(rsp->obj.dev_name);
2056 free(rsp->obj.health_reporter_name);
2061 struct devlink_health_reporter_get_list *
2062 devlink_health_reporter_get_dump(struct ynl_sock *ys,
2063 struct devlink_health_reporter_get_req_dump *req)
2065 struct ynl_dump_state yds = {};
2066 struct nlmsghdr *nlh;
2070 yds.alloc_sz = sizeof(struct devlink_health_reporter_get_list);
2071 yds.cb = devlink_health_reporter_get_rsp_parse;
2072 yds.rsp_cmd = DEVLINK_CMD_HEALTH_REPORTER_GET;
2073 yds.rsp_policy = &devlink_nest;
2075 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_HEALTH_REPORTER_GET, 1);
2076 ys->req_policy = &devlink_nest;
2078 if (req->_present.bus_name_len)
2079 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2080 if (req->_present.dev_name_len)
2081 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2082 if (req->_present.port_index)
2083 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2085 err = ynl_exec_dump(ys, nlh, &yds);
2092 devlink_health_reporter_get_list_free(yds.first);
2096 /* ============== DEVLINK_CMD_TRAP_GET ============== */
2097 /* DEVLINK_CMD_TRAP_GET - do */
2098 void devlink_trap_get_req_free(struct devlink_trap_get_req *req)
2100 free(req->bus_name);
2101 free(req->dev_name);
2102 free(req->trap_name);
2106 void devlink_trap_get_rsp_free(struct devlink_trap_get_rsp *rsp)
2108 free(rsp->bus_name);
2109 free(rsp->dev_name);
2110 free(rsp->trap_name);
2114 int devlink_trap_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2116 struct ynl_parse_arg *yarg = data;
2117 struct devlink_trap_get_rsp *dst;
2118 const struct nlattr *attr;
2122 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2123 unsigned int type = mnl_attr_get_type(attr);
2125 if (type == DEVLINK_ATTR_BUS_NAME) {
2128 if (ynl_attr_validate(yarg, attr))
2129 return MNL_CB_ERROR;
2131 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2132 dst->_present.bus_name_len = len;
2133 dst->bus_name = malloc(len + 1);
2134 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2135 dst->bus_name[len] = 0;
2136 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2139 if (ynl_attr_validate(yarg, attr))
2140 return MNL_CB_ERROR;
2142 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2143 dst->_present.dev_name_len = len;
2144 dst->dev_name = malloc(len + 1);
2145 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2146 dst->dev_name[len] = 0;
2147 } else if (type == DEVLINK_ATTR_TRAP_NAME) {
2150 if (ynl_attr_validate(yarg, attr))
2151 return MNL_CB_ERROR;
2153 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2154 dst->_present.trap_name_len = len;
2155 dst->trap_name = malloc(len + 1);
2156 memcpy(dst->trap_name, mnl_attr_get_str(attr), len);
2157 dst->trap_name[len] = 0;
2164 struct devlink_trap_get_rsp *
2165 devlink_trap_get(struct ynl_sock *ys, struct devlink_trap_get_req *req)
2167 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2168 struct devlink_trap_get_rsp *rsp;
2169 struct nlmsghdr *nlh;
2172 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_GET, 1);
2173 ys->req_policy = &devlink_nest;
2174 yrs.yarg.rsp_policy = &devlink_nest;
2176 if (req->_present.bus_name_len)
2177 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2178 if (req->_present.dev_name_len)
2179 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2180 if (req->_present.trap_name_len)
2181 mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME, req->trap_name);
2183 rsp = calloc(1, sizeof(*rsp));
2184 yrs.yarg.data = rsp;
2185 yrs.cb = devlink_trap_get_rsp_parse;
2186 yrs.rsp_cmd = DEVLINK_CMD_TRAP_GET;
2188 err = ynl_exec(ys, nlh, &yrs);
2195 devlink_trap_get_rsp_free(rsp);
2199 /* DEVLINK_CMD_TRAP_GET - dump */
2200 void devlink_trap_get_list_free(struct devlink_trap_get_list *rsp)
2202 struct devlink_trap_get_list *next = rsp;
2204 while ((void *)next != YNL_LIST_END) {
2208 free(rsp->obj.bus_name);
2209 free(rsp->obj.dev_name);
2210 free(rsp->obj.trap_name);
2215 struct devlink_trap_get_list *
2216 devlink_trap_get_dump(struct ynl_sock *ys,
2217 struct devlink_trap_get_req_dump *req)
2219 struct ynl_dump_state yds = {};
2220 struct nlmsghdr *nlh;
2224 yds.alloc_sz = sizeof(struct devlink_trap_get_list);
2225 yds.cb = devlink_trap_get_rsp_parse;
2226 yds.rsp_cmd = DEVLINK_CMD_TRAP_GET;
2227 yds.rsp_policy = &devlink_nest;
2229 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_GET, 1);
2230 ys->req_policy = &devlink_nest;
2232 if (req->_present.bus_name_len)
2233 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2234 if (req->_present.dev_name_len)
2235 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2237 err = ynl_exec_dump(ys, nlh, &yds);
2244 devlink_trap_get_list_free(yds.first);
2248 /* ============== DEVLINK_CMD_TRAP_GROUP_GET ============== */
2249 /* DEVLINK_CMD_TRAP_GROUP_GET - do */
2250 void devlink_trap_group_get_req_free(struct devlink_trap_group_get_req *req)
2252 free(req->bus_name);
2253 free(req->dev_name);
2254 free(req->trap_group_name);
2258 void devlink_trap_group_get_rsp_free(struct devlink_trap_group_get_rsp *rsp)
2260 free(rsp->bus_name);
2261 free(rsp->dev_name);
2262 free(rsp->trap_group_name);
2266 int devlink_trap_group_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2268 struct devlink_trap_group_get_rsp *dst;
2269 struct ynl_parse_arg *yarg = data;
2270 const struct nlattr *attr;
2274 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2275 unsigned int type = mnl_attr_get_type(attr);
2277 if (type == DEVLINK_ATTR_BUS_NAME) {
2280 if (ynl_attr_validate(yarg, attr))
2281 return MNL_CB_ERROR;
2283 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2284 dst->_present.bus_name_len = len;
2285 dst->bus_name = malloc(len + 1);
2286 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2287 dst->bus_name[len] = 0;
2288 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2291 if (ynl_attr_validate(yarg, attr))
2292 return MNL_CB_ERROR;
2294 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2295 dst->_present.dev_name_len = len;
2296 dst->dev_name = malloc(len + 1);
2297 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2298 dst->dev_name[len] = 0;
2299 } else if (type == DEVLINK_ATTR_TRAP_GROUP_NAME) {
2302 if (ynl_attr_validate(yarg, attr))
2303 return MNL_CB_ERROR;
2305 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2306 dst->_present.trap_group_name_len = len;
2307 dst->trap_group_name = malloc(len + 1);
2308 memcpy(dst->trap_group_name, mnl_attr_get_str(attr), len);
2309 dst->trap_group_name[len] = 0;
2316 struct devlink_trap_group_get_rsp *
2317 devlink_trap_group_get(struct ynl_sock *ys,
2318 struct devlink_trap_group_get_req *req)
2320 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2321 struct devlink_trap_group_get_rsp *rsp;
2322 struct nlmsghdr *nlh;
2325 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_GROUP_GET, 1);
2326 ys->req_policy = &devlink_nest;
2327 yrs.yarg.rsp_policy = &devlink_nest;
2329 if (req->_present.bus_name_len)
2330 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2331 if (req->_present.dev_name_len)
2332 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2333 if (req->_present.trap_group_name_len)
2334 mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_GROUP_NAME, req->trap_group_name);
2336 rsp = calloc(1, sizeof(*rsp));
2337 yrs.yarg.data = rsp;
2338 yrs.cb = devlink_trap_group_get_rsp_parse;
2339 yrs.rsp_cmd = DEVLINK_CMD_TRAP_GROUP_GET;
2341 err = ynl_exec(ys, nlh, &yrs);
2348 devlink_trap_group_get_rsp_free(rsp);
2352 /* DEVLINK_CMD_TRAP_GROUP_GET - dump */
2353 void devlink_trap_group_get_list_free(struct devlink_trap_group_get_list *rsp)
2355 struct devlink_trap_group_get_list *next = rsp;
2357 while ((void *)next != YNL_LIST_END) {
2361 free(rsp->obj.bus_name);
2362 free(rsp->obj.dev_name);
2363 free(rsp->obj.trap_group_name);
2368 struct devlink_trap_group_get_list *
2369 devlink_trap_group_get_dump(struct ynl_sock *ys,
2370 struct devlink_trap_group_get_req_dump *req)
2372 struct ynl_dump_state yds = {};
2373 struct nlmsghdr *nlh;
2377 yds.alloc_sz = sizeof(struct devlink_trap_group_get_list);
2378 yds.cb = devlink_trap_group_get_rsp_parse;
2379 yds.rsp_cmd = DEVLINK_CMD_TRAP_GROUP_GET;
2380 yds.rsp_policy = &devlink_nest;
2382 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_GROUP_GET, 1);
2383 ys->req_policy = &devlink_nest;
2385 if (req->_present.bus_name_len)
2386 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2387 if (req->_present.dev_name_len)
2388 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2390 err = ynl_exec_dump(ys, nlh, &yds);
2397 devlink_trap_group_get_list_free(yds.first);
2401 /* ============== DEVLINK_CMD_TRAP_POLICER_GET ============== */
2402 /* DEVLINK_CMD_TRAP_POLICER_GET - do */
2404 devlink_trap_policer_get_req_free(struct devlink_trap_policer_get_req *req)
2406 free(req->bus_name);
2407 free(req->dev_name);
2412 devlink_trap_policer_get_rsp_free(struct devlink_trap_policer_get_rsp *rsp)
2414 free(rsp->bus_name);
2415 free(rsp->dev_name);
2419 int devlink_trap_policer_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2421 struct devlink_trap_policer_get_rsp *dst;
2422 struct ynl_parse_arg *yarg = data;
2423 const struct nlattr *attr;
2427 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2428 unsigned int type = mnl_attr_get_type(attr);
2430 if (type == DEVLINK_ATTR_BUS_NAME) {
2433 if (ynl_attr_validate(yarg, attr))
2434 return MNL_CB_ERROR;
2436 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2437 dst->_present.bus_name_len = len;
2438 dst->bus_name = malloc(len + 1);
2439 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2440 dst->bus_name[len] = 0;
2441 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2444 if (ynl_attr_validate(yarg, attr))
2445 return MNL_CB_ERROR;
2447 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2448 dst->_present.dev_name_len = len;
2449 dst->dev_name = malloc(len + 1);
2450 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2451 dst->dev_name[len] = 0;
2452 } else if (type == DEVLINK_ATTR_TRAP_POLICER_ID) {
2453 if (ynl_attr_validate(yarg, attr))
2454 return MNL_CB_ERROR;
2455 dst->_present.trap_policer_id = 1;
2456 dst->trap_policer_id = mnl_attr_get_u32(attr);
2463 struct devlink_trap_policer_get_rsp *
2464 devlink_trap_policer_get(struct ynl_sock *ys,
2465 struct devlink_trap_policer_get_req *req)
2467 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2468 struct devlink_trap_policer_get_rsp *rsp;
2469 struct nlmsghdr *nlh;
2472 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_TRAP_POLICER_GET, 1);
2473 ys->req_policy = &devlink_nest;
2474 yrs.yarg.rsp_policy = &devlink_nest;
2476 if (req->_present.bus_name_len)
2477 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2478 if (req->_present.dev_name_len)
2479 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2480 if (req->_present.trap_policer_id)
2481 mnl_attr_put_u32(nlh, DEVLINK_ATTR_TRAP_POLICER_ID, req->trap_policer_id);
2483 rsp = calloc(1, sizeof(*rsp));
2484 yrs.yarg.data = rsp;
2485 yrs.cb = devlink_trap_policer_get_rsp_parse;
2486 yrs.rsp_cmd = DEVLINK_CMD_TRAP_POLICER_GET;
2488 err = ynl_exec(ys, nlh, &yrs);
2495 devlink_trap_policer_get_rsp_free(rsp);
2499 /* DEVLINK_CMD_TRAP_POLICER_GET - dump */
2501 devlink_trap_policer_get_list_free(struct devlink_trap_policer_get_list *rsp)
2503 struct devlink_trap_policer_get_list *next = rsp;
2505 while ((void *)next != YNL_LIST_END) {
2509 free(rsp->obj.bus_name);
2510 free(rsp->obj.dev_name);
2515 struct devlink_trap_policer_get_list *
2516 devlink_trap_policer_get_dump(struct ynl_sock *ys,
2517 struct devlink_trap_policer_get_req_dump *req)
2519 struct ynl_dump_state yds = {};
2520 struct nlmsghdr *nlh;
2524 yds.alloc_sz = sizeof(struct devlink_trap_policer_get_list);
2525 yds.cb = devlink_trap_policer_get_rsp_parse;
2526 yds.rsp_cmd = DEVLINK_CMD_TRAP_POLICER_GET;
2527 yds.rsp_policy = &devlink_nest;
2529 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_TRAP_POLICER_GET, 1);
2530 ys->req_policy = &devlink_nest;
2532 if (req->_present.bus_name_len)
2533 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2534 if (req->_present.dev_name_len)
2535 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2537 err = ynl_exec_dump(ys, nlh, &yds);
2544 devlink_trap_policer_get_list_free(yds.first);
2548 /* ============== DEVLINK_CMD_RATE_GET ============== */
2549 /* DEVLINK_CMD_RATE_GET - do */
2550 void devlink_rate_get_req_free(struct devlink_rate_get_req *req)
2552 free(req->bus_name);
2553 free(req->dev_name);
2554 free(req->rate_node_name);
2558 void devlink_rate_get_rsp_free(struct devlink_rate_get_rsp *rsp)
2560 free(rsp->bus_name);
2561 free(rsp->dev_name);
2562 free(rsp->rate_node_name);
2566 int devlink_rate_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2568 struct ynl_parse_arg *yarg = data;
2569 struct devlink_rate_get_rsp *dst;
2570 const struct nlattr *attr;
2574 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2575 unsigned int type = mnl_attr_get_type(attr);
2577 if (type == DEVLINK_ATTR_BUS_NAME) {
2580 if (ynl_attr_validate(yarg, attr))
2581 return MNL_CB_ERROR;
2583 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2584 dst->_present.bus_name_len = len;
2585 dst->bus_name = malloc(len + 1);
2586 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2587 dst->bus_name[len] = 0;
2588 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2591 if (ynl_attr_validate(yarg, attr))
2592 return MNL_CB_ERROR;
2594 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2595 dst->_present.dev_name_len = len;
2596 dst->dev_name = malloc(len + 1);
2597 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2598 dst->dev_name[len] = 0;
2599 } else if (type == DEVLINK_ATTR_PORT_INDEX) {
2600 if (ynl_attr_validate(yarg, attr))
2601 return MNL_CB_ERROR;
2602 dst->_present.port_index = 1;
2603 dst->port_index = mnl_attr_get_u32(attr);
2604 } else if (type == DEVLINK_ATTR_RATE_NODE_NAME) {
2607 if (ynl_attr_validate(yarg, attr))
2608 return MNL_CB_ERROR;
2610 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2611 dst->_present.rate_node_name_len = len;
2612 dst->rate_node_name = malloc(len + 1);
2613 memcpy(dst->rate_node_name, mnl_attr_get_str(attr), len);
2614 dst->rate_node_name[len] = 0;
2621 struct devlink_rate_get_rsp *
2622 devlink_rate_get(struct ynl_sock *ys, struct devlink_rate_get_req *req)
2624 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2625 struct devlink_rate_get_rsp *rsp;
2626 struct nlmsghdr *nlh;
2629 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_RATE_GET, 1);
2630 ys->req_policy = &devlink_nest;
2631 yrs.yarg.rsp_policy = &devlink_nest;
2633 if (req->_present.bus_name_len)
2634 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2635 if (req->_present.dev_name_len)
2636 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2637 if (req->_present.port_index)
2638 mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
2639 if (req->_present.rate_node_name_len)
2640 mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_NODE_NAME, req->rate_node_name);
2642 rsp = calloc(1, sizeof(*rsp));
2643 yrs.yarg.data = rsp;
2644 yrs.cb = devlink_rate_get_rsp_parse;
2645 yrs.rsp_cmd = DEVLINK_CMD_RATE_GET;
2647 err = ynl_exec(ys, nlh, &yrs);
2654 devlink_rate_get_rsp_free(rsp);
2658 /* DEVLINK_CMD_RATE_GET - dump */
2659 void devlink_rate_get_list_free(struct devlink_rate_get_list *rsp)
2661 struct devlink_rate_get_list *next = rsp;
2663 while ((void *)next != YNL_LIST_END) {
2667 free(rsp->obj.bus_name);
2668 free(rsp->obj.dev_name);
2669 free(rsp->obj.rate_node_name);
2674 struct devlink_rate_get_list *
2675 devlink_rate_get_dump(struct ynl_sock *ys,
2676 struct devlink_rate_get_req_dump *req)
2678 struct ynl_dump_state yds = {};
2679 struct nlmsghdr *nlh;
2683 yds.alloc_sz = sizeof(struct devlink_rate_get_list);
2684 yds.cb = devlink_rate_get_rsp_parse;
2685 yds.rsp_cmd = DEVLINK_CMD_RATE_GET;
2686 yds.rsp_policy = &devlink_nest;
2688 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_RATE_GET, 1);
2689 ys->req_policy = &devlink_nest;
2691 if (req->_present.bus_name_len)
2692 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2693 if (req->_present.dev_name_len)
2694 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2696 err = ynl_exec_dump(ys, nlh, &yds);
2703 devlink_rate_get_list_free(yds.first);
2707 /* ============== DEVLINK_CMD_LINECARD_GET ============== */
2708 /* DEVLINK_CMD_LINECARD_GET - do */
2709 void devlink_linecard_get_req_free(struct devlink_linecard_get_req *req)
2711 free(req->bus_name);
2712 free(req->dev_name);
2716 void devlink_linecard_get_rsp_free(struct devlink_linecard_get_rsp *rsp)
2718 free(rsp->bus_name);
2719 free(rsp->dev_name);
2723 int devlink_linecard_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2725 struct devlink_linecard_get_rsp *dst;
2726 struct ynl_parse_arg *yarg = data;
2727 const struct nlattr *attr;
2731 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2732 unsigned int type = mnl_attr_get_type(attr);
2734 if (type == DEVLINK_ATTR_BUS_NAME) {
2737 if (ynl_attr_validate(yarg, attr))
2738 return MNL_CB_ERROR;
2740 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2741 dst->_present.bus_name_len = len;
2742 dst->bus_name = malloc(len + 1);
2743 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2744 dst->bus_name[len] = 0;
2745 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2748 if (ynl_attr_validate(yarg, attr))
2749 return MNL_CB_ERROR;
2751 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2752 dst->_present.dev_name_len = len;
2753 dst->dev_name = malloc(len + 1);
2754 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2755 dst->dev_name[len] = 0;
2756 } else if (type == DEVLINK_ATTR_LINECARD_INDEX) {
2757 if (ynl_attr_validate(yarg, attr))
2758 return MNL_CB_ERROR;
2759 dst->_present.linecard_index = 1;
2760 dst->linecard_index = mnl_attr_get_u32(attr);
2767 struct devlink_linecard_get_rsp *
2768 devlink_linecard_get(struct ynl_sock *ys, struct devlink_linecard_get_req *req)
2770 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2771 struct devlink_linecard_get_rsp *rsp;
2772 struct nlmsghdr *nlh;
2775 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_LINECARD_GET, 1);
2776 ys->req_policy = &devlink_nest;
2777 yrs.yarg.rsp_policy = &devlink_nest;
2779 if (req->_present.bus_name_len)
2780 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2781 if (req->_present.dev_name_len)
2782 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2783 if (req->_present.linecard_index)
2784 mnl_attr_put_u32(nlh, DEVLINK_ATTR_LINECARD_INDEX, req->linecard_index);
2786 rsp = calloc(1, sizeof(*rsp));
2787 yrs.yarg.data = rsp;
2788 yrs.cb = devlink_linecard_get_rsp_parse;
2789 yrs.rsp_cmd = DEVLINK_CMD_LINECARD_GET;
2791 err = ynl_exec(ys, nlh, &yrs);
2798 devlink_linecard_get_rsp_free(rsp);
2802 /* DEVLINK_CMD_LINECARD_GET - dump */
2803 void devlink_linecard_get_list_free(struct devlink_linecard_get_list *rsp)
2805 struct devlink_linecard_get_list *next = rsp;
2807 while ((void *)next != YNL_LIST_END) {
2811 free(rsp->obj.bus_name);
2812 free(rsp->obj.dev_name);
2817 struct devlink_linecard_get_list *
2818 devlink_linecard_get_dump(struct ynl_sock *ys,
2819 struct devlink_linecard_get_req_dump *req)
2821 struct ynl_dump_state yds = {};
2822 struct nlmsghdr *nlh;
2826 yds.alloc_sz = sizeof(struct devlink_linecard_get_list);
2827 yds.cb = devlink_linecard_get_rsp_parse;
2828 yds.rsp_cmd = DEVLINK_CMD_LINECARD_GET;
2829 yds.rsp_policy = &devlink_nest;
2831 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_LINECARD_GET, 1);
2832 ys->req_policy = &devlink_nest;
2834 if (req->_present.bus_name_len)
2835 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2836 if (req->_present.dev_name_len)
2837 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2839 err = ynl_exec_dump(ys, nlh, &yds);
2846 devlink_linecard_get_list_free(yds.first);
2850 /* ============== DEVLINK_CMD_SELFTESTS_GET ============== */
2851 /* DEVLINK_CMD_SELFTESTS_GET - do */
2852 void devlink_selftests_get_req_free(struct devlink_selftests_get_req *req)
2854 free(req->bus_name);
2855 free(req->dev_name);
2859 void devlink_selftests_get_rsp_free(struct devlink_selftests_get_rsp *rsp)
2861 free(rsp->bus_name);
2862 free(rsp->dev_name);
2866 int devlink_selftests_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
2868 struct devlink_selftests_get_rsp *dst;
2869 struct ynl_parse_arg *yarg = data;
2870 const struct nlattr *attr;
2874 mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
2875 unsigned int type = mnl_attr_get_type(attr);
2877 if (type == DEVLINK_ATTR_BUS_NAME) {
2880 if (ynl_attr_validate(yarg, attr))
2881 return MNL_CB_ERROR;
2883 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2884 dst->_present.bus_name_len = len;
2885 dst->bus_name = malloc(len + 1);
2886 memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
2887 dst->bus_name[len] = 0;
2888 } else if (type == DEVLINK_ATTR_DEV_NAME) {
2891 if (ynl_attr_validate(yarg, attr))
2892 return MNL_CB_ERROR;
2894 len = strnlen(mnl_attr_get_str(attr), mnl_attr_get_payload_len(attr));
2895 dst->_present.dev_name_len = len;
2896 dst->dev_name = malloc(len + 1);
2897 memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
2898 dst->dev_name[len] = 0;
2905 struct devlink_selftests_get_rsp *
2906 devlink_selftests_get(struct ynl_sock *ys,
2907 struct devlink_selftests_get_req *req)
2909 struct ynl_req_state yrs = { .yarg = { .ys = ys, }, };
2910 struct devlink_selftests_get_rsp *rsp;
2911 struct nlmsghdr *nlh;
2914 nlh = ynl_gemsg_start_req(ys, ys->family_id, DEVLINK_CMD_SELFTESTS_GET, 1);
2915 ys->req_policy = &devlink_nest;
2916 yrs.yarg.rsp_policy = &devlink_nest;
2918 if (req->_present.bus_name_len)
2919 mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
2920 if (req->_present.dev_name_len)
2921 mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
2923 rsp = calloc(1, sizeof(*rsp));
2924 yrs.yarg.data = rsp;
2925 yrs.cb = devlink_selftests_get_rsp_parse;
2926 yrs.rsp_cmd = DEVLINK_CMD_SELFTESTS_GET;
2928 err = ynl_exec(ys, nlh, &yrs);
2935 devlink_selftests_get_rsp_free(rsp);
2939 /* DEVLINK_CMD_SELFTESTS_GET - dump */
2940 void devlink_selftests_get_list_free(struct devlink_selftests_get_list *rsp)
2942 struct devlink_selftests_get_list *next = rsp;
2944 while ((void *)next != YNL_LIST_END) {
2948 free(rsp->obj.bus_name);
2949 free(rsp->obj.dev_name);
2954 struct devlink_selftests_get_list *
2955 devlink_selftests_get_dump(struct ynl_sock *ys)
2957 struct ynl_dump_state yds = {};
2958 struct nlmsghdr *nlh;
2962 yds.alloc_sz = sizeof(struct devlink_selftests_get_list);
2963 yds.cb = devlink_selftests_get_rsp_parse;
2964 yds.rsp_cmd = DEVLINK_CMD_SELFTESTS_GET;
2965 yds.rsp_policy = &devlink_nest;
2967 nlh = ynl_gemsg_start_dump(ys, ys->family_id, DEVLINK_CMD_SELFTESTS_GET, 1);
2969 err = ynl_exec_dump(ys, nlh, &yds);
2976 devlink_selftests_get_list_free(yds.first);
2980 const struct ynl_family ynl_devlink_family = {