diff --git a/home/nipa/nipa_out/866290/ynl/new-code/shaper-user.c b/home/nipa/nipa_out/866290/ynl/new-code/shaper-user.c new file mode 100644 index 000000000000..3a6c32466eb8 --- /dev/null +++ b/home/nipa/nipa_out/866290/ynl/new-code/shaper-user.c @@ -0,0 +1,659 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/shaper.yaml */ +/* YNL-GEN user source */ + +#include +#include +#include "net_shaper-user.h" +#include "ynl.h" +#include + +#include + +/* Enums */ +static const char * const net_shaper_op_strmap[] = { + [NET_SHAPER_CMD_GET] = "get", + [NET_SHAPER_CMD_SET] = "set", + [NET_SHAPER_CMD_DELETE] = "delete", + [NET_SHAPER_CMD_CAP_GET] = "cap-get", +}; + +const char *net_shaper_op_str(int op) +{ + if (op < 0 || op >= (int)YNL_ARRAY_SIZE(net_shaper_op_strmap)) + return NULL; + return net_shaper_op_strmap[op]; +} + +static const char * const net_shaper_scope_strmap[] = { + [0] = "unspec", + [1] = "port", + [2] = "netdev", + [3] = "queue", + [4] = "detached", +}; + +const char *net_shaper_scope_str(enum net_shaper_scope value) +{ + if (value < 0 || value >= (int)YNL_ARRAY_SIZE(net_shaper_scope_strmap)) + return NULL; + return net_shaper_scope_strmap[value]; +} + +static const char * const net_shaper_metric_strmap[] = { + [0] = "bps", + [1] = "pps", +}; + +const char *net_shaper_metric_str(enum net_shaper_metric value) +{ + if (value < 0 || value >= (int)YNL_ARRAY_SIZE(net_shaper_metric_strmap)) + return NULL; + return net_shaper_metric_strmap[value]; +} + +/* Policies */ +const struct ynl_policy_attr net_shaper_handle_policy[NET_SHAPER_A_MAX + 1] = { + [NET_SHAPER_A_SCOPE] = { .name = "scope", .type = YNL_PT_U32, }, + [NET_SHAPER_A_ID] = { .name = "id", .type = YNL_PT_U32, }, +}; + +const struct ynl_policy_nest net_shaper_handle_nest = { + .max_attr = NET_SHAPER_A_MAX, + .table = net_shaper_handle_policy, +}; + +const struct ynl_policy_attr net_shaper_ns_info_policy[NET_SHAPER_A_MAX + 1] = { + [NET_SHAPER_A_PARENT] = { .name = "parent", .type = YNL_PT_NEST, .nest = &net_shaper_handle_nest, }, + [NET_SHAPER_A_HANDLE] = { .name = "handle", .type = YNL_PT_NEST, .nest = &net_shaper_handle_nest, }, + [NET_SHAPER_A_METRIC] = { .name = "metric", .type = YNL_PT_U32, }, + [NET_SHAPER_A_BW_MIN] = { .name = "bw-min", .type = YNL_PT_U64, }, + [NET_SHAPER_A_BW_MAX] = { .name = "bw-max", .type = YNL_PT_U64, }, + [NET_SHAPER_A_BURST] = { .name = "burst", .type = YNL_PT_U64, }, + [NET_SHAPER_A_PRIORITY] = { .name = "priority", .type = YNL_PT_U32, }, + [NET_SHAPER_A_WEIGHT] = { .name = "weight", .type = YNL_PT_U32, }, +}; + +const struct ynl_policy_nest net_shaper_ns_info_nest = { + .max_attr = NET_SHAPER_A_MAX, + .table = net_shaper_ns_info_policy, +}; + +const struct ynl_policy_attr net_shaper_policy[NET_SHAPER_A_MAX + 1] = { + [NET_SHAPER_A_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [NET_SHAPER_A_PARENT] = { .name = "parent", .type = YNL_PT_NEST, .nest = &net_shaper_handle_nest, }, + [NET_SHAPER_A_HANDLE] = { .name = "handle", .type = YNL_PT_NEST, .nest = &net_shaper_handle_nest, }, + [NET_SHAPER_A_METRIC] = { .name = "metric", .type = YNL_PT_U32, }, + [NET_SHAPER_A_BW_MIN] = { .name = "bw-min", .type = YNL_PT_U64, }, + [NET_SHAPER_A_BW_MAX] = { .name = "bw-max", .type = YNL_PT_U64, }, + [NET_SHAPER_A_BURST] = { .name = "burst", .type = YNL_PT_U64, }, + [NET_SHAPER_A_PRIORITY] = { .name = "priority", .type = YNL_PT_U32, }, + [NET_SHAPER_A_WEIGHT] = { .name = "weight", .type = YNL_PT_U32, }, + [NET_SHAPER_A_SCOPE] = { .name = "scope", .type = YNL_PT_U32, }, + [NET_SHAPER_A_ID] = { .name = "id", .type = YNL_PT_U32, }, + [NET_SHAPER_A_HANDLES] = { .name = "handles", .type = YNL_PT_NEST, .nest = &net_shaper_handle_nest, }, + [NET_SHAPER_A_SHAPERS] = { .name = "shapers", .type = YNL_PT_NEST, .nest = &net_shaper_ns_info_nest, }, + [NET_SHAPER_A_MODIFIED] = { .name = "modified", .type = YNL_PT_U32, }, + [NET_SHAPER_A_PAD] = { .name = "pad", .type = YNL_PT_IGNORE, }, +}; + +const struct ynl_policy_nest net_shaper_nest = { + .max_attr = NET_SHAPER_A_MAX, + .table = net_shaper_policy, +}; + +const struct ynl_policy_attr net_shaper_capabilities_policy[NET_SHAPER_A_CAPABILITIES_MAX + 1] = { + [NET_SHAPER_A_CAPABILITIES_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [NET_SHAPER_A_CAPABILITIES_SCOPE] = { .name = "scope", .type = YNL_PT_U32, }, + [NET_SHAPER_A_CAPABILITIES_SUPPORT_METRIC_BPS] = { .name = "support-metric-bps", .type = YNL_PT_FLAG, }, + [NET_SHAPER_A_CAPABILITIES_SUPPORT_METRIC_PPS] = { .name = "support-metric-pps", .type = YNL_PT_FLAG, }, + [NET_SHAPER_A_CAPABILITIES_SUPPORT_NESTING] = { .name = "support-nesting", .type = YNL_PT_FLAG, }, + [NET_SHAPER_A_CAPABILITIES_SUPPORT_BW_MIN] = { .name = "support-bw-min", .type = YNL_PT_FLAG, }, + [NET_SHAPER_A_CAPABILITIES_SUPPORT_BW_MAX] = { .name = "support-bw-max", .type = YNL_PT_FLAG, }, + [NET_SHAPER_A_CAPABILITIES_SUPPORT_BURST] = { .name = "support-burst", .type = YNL_PT_FLAG, }, + [NET_SHAPER_A_CAPABILITIES_SUPPORT_PRIORITY] = { .name = "support-priority", .type = YNL_PT_FLAG, }, + [NET_SHAPER_A_CAPABILITIES_SUPPORT_WEIGHT] = { .name = "support-weight", .type = YNL_PT_FLAG, }, +}; + +const struct ynl_policy_nest net_shaper_capabilities_nest = { + .max_attr = NET_SHAPER_A_CAPABILITIES_MAX, + .table = net_shaper_capabilities_policy, +}; + +/* Common nested types */ +void net_shaper_handle_free(struct net_shaper_handle *obj) +{ +} + +int net_shaper_handle_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct net_shaper_handle *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_present.scope) + ynl_attr_put_u32(nlh, NET_SHAPER_A_SCOPE, obj->scope); + if (obj->_present.id) + ynl_attr_put_u32(nlh, NET_SHAPER_A_ID, obj->id); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +int net_shaper_handle_parse(struct ynl_parse_arg *yarg, + const struct nlattr *nested) +{ + struct net_shaper_handle *dst = yarg->data; + const struct nlattr *attr; + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == NET_SHAPER_A_SCOPE) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.scope = 1; + dst->scope = ynl_attr_get_u32(attr); + } else if (type == NET_SHAPER_A_ID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.id = 1; + dst->id = ynl_attr_get_u32(attr); + } + } + + return 0; +} + +void net_shaper_ns_info_free(struct net_shaper_ns_info *obj) +{ + net_shaper_handle_free(&obj->parent); + net_shaper_handle_free(&obj->handle); +} + +int net_shaper_ns_info_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct net_shaper_ns_info *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_present.parent) + net_shaper_handle_put(nlh, NET_SHAPER_A_PARENT, &obj->parent); + if (obj->_present.handle) + net_shaper_handle_put(nlh, NET_SHAPER_A_HANDLE, &obj->handle); + if (obj->_present.metric) + ynl_attr_put_u32(nlh, NET_SHAPER_A_METRIC, obj->metric); + if (obj->_present.bw_min) + ynl_attr_put_u64(nlh, NET_SHAPER_A_BW_MIN, obj->bw_min); + if (obj->_present.bw_max) + ynl_attr_put_u64(nlh, NET_SHAPER_A_BW_MAX, obj->bw_max); + if (obj->_present.burst) + ynl_attr_put_u64(nlh, NET_SHAPER_A_BURST, obj->burst); + if (obj->_present.priority) + ynl_attr_put_u32(nlh, NET_SHAPER_A_PRIORITY, obj->priority); + if (obj->_present.weight) + ynl_attr_put_u32(nlh, NET_SHAPER_A_WEIGHT, obj->weight); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +/* ============== NET_SHAPER_CMD_GET ============== */ +/* NET_SHAPER_CMD_GET - do */ +void net_shaper_get_req_free(struct net_shaper_get_req *req) +{ + net_shaper_handle_free(&req->handle); + free(req); +} + +void net_shaper_get_rsp_free(struct net_shaper_get_rsp *rsp) +{ + net_shaper_handle_free(&rsp->parent); + net_shaper_handle_free(&rsp->handle); + free(rsp); +} + +int net_shaper_get_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct net_shaper_get_rsp *dst; + const struct nlattr *attr; + struct ynl_parse_arg parg; + + dst = yarg->data; + parg.ys = yarg->ys; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == NET_SHAPER_A_PARENT) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.parent = 1; + + parg.rsp_policy = &net_shaper_handle_nest; + parg.data = &dst->parent; + if (net_shaper_handle_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == NET_SHAPER_A_HANDLE) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.handle = 1; + + parg.rsp_policy = &net_shaper_handle_nest; + parg.data = &dst->handle; + if (net_shaper_handle_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == NET_SHAPER_A_METRIC) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.metric = 1; + dst->metric = ynl_attr_get_u32(attr); + } else if (type == NET_SHAPER_A_BW_MIN) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.bw_min = 1; + dst->bw_min = ynl_attr_get_u64(attr); + } else if (type == NET_SHAPER_A_BW_MAX) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.bw_max = 1; + dst->bw_max = ynl_attr_get_u64(attr); + } else if (type == NET_SHAPER_A_BURST) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.burst = 1; + dst->burst = ynl_attr_get_u64(attr); + } else if (type == NET_SHAPER_A_PRIORITY) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.priority = 1; + dst->priority = ynl_attr_get_u32(attr); + } else if (type == NET_SHAPER_A_WEIGHT) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.weight = 1; + dst->weight = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct net_shaper_get_rsp * +net_shaper_get(struct ynl_sock *ys, struct net_shaper_get_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct net_shaper_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NET_SHAPER_CMD_GET, 1); + ys->req_policy = &net_shaper_nest; + yrs.yarg.rsp_policy = &net_shaper_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, NET_SHAPER_A_IFINDEX, req->ifindex); + if (req->_present.handle) + net_shaper_handle_put(nlh, NET_SHAPER_A_HANDLE, &req->handle); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = net_shaper_get_rsp_parse; + yrs.rsp_cmd = NET_SHAPER_CMD_GET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + net_shaper_get_rsp_free(rsp); + return NULL; +} + +/* NET_SHAPER_CMD_GET - dump */ +void net_shaper_get_req_dump_free(struct net_shaper_get_req_dump *req) +{ + free(req); +} + +void net_shaper_get_list_free(struct net_shaper_get_list *rsp) +{ + struct net_shaper_get_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + net_shaper_handle_free(&rsp->obj.parent); + net_shaper_handle_free(&rsp->obj.handle); + free(rsp); + } +} + +struct net_shaper_get_list * +net_shaper_get_dump(struct ynl_sock *ys, struct net_shaper_get_req_dump *req) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.yarg.ys = ys; + yds.yarg.rsp_policy = &net_shaper_nest; + yds.yarg.data = NULL; + yds.alloc_sz = sizeof(struct net_shaper_get_list); + yds.cb = net_shaper_get_rsp_parse; + yds.rsp_cmd = NET_SHAPER_CMD_GET; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, NET_SHAPER_CMD_GET, 1); + ys->req_policy = &net_shaper_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, NET_SHAPER_A_IFINDEX, req->ifindex); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + net_shaper_get_list_free(yds.first); + return NULL; +} + +/* ============== NET_SHAPER_CMD_SET ============== */ +/* NET_SHAPER_CMD_SET - do */ +void net_shaper_set_req_free(struct net_shaper_set_req *req) +{ + unsigned int i; + + for (i = 0; i < req->n_shapers; i++) + net_shaper_ns_info_free(&req->shapers[i]); + free(req->shapers); + free(req); +} + +void net_shaper_set_rsp_free(struct net_shaper_set_rsp *rsp) +{ + free(rsp); +} + +int net_shaper_set_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct net_shaper_set_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == NET_SHAPER_A_MODIFIED) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.modified = 1; + dst->modified = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct net_shaper_set_rsp * +net_shaper_set(struct ynl_sock *ys, struct net_shaper_set_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct net_shaper_set_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NET_SHAPER_CMD_SET, 1); + ys->req_policy = &net_shaper_nest; + yrs.yarg.rsp_policy = &net_shaper_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, NET_SHAPER_A_IFINDEX, req->ifindex); + for (unsigned int i = 0; i < req->n_shapers; i++) + net_shaper_ns_info_put(nlh, NET_SHAPER_A_SHAPERS, &req->shapers[i]); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = net_shaper_set_rsp_parse; + yrs.rsp_cmd = NET_SHAPER_CMD_SET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + net_shaper_set_rsp_free(rsp); + return NULL; +} + +/* ============== NET_SHAPER_CMD_DELETE ============== */ +/* NET_SHAPER_CMD_DELETE - do */ +void net_shaper_delete_req_free(struct net_shaper_delete_req *req) +{ + unsigned int i; + + for (i = 0; i < req->n_handles; i++) + net_shaper_handle_free(&req->handles[i]); + free(req->handles); + free(req); +} + +void net_shaper_delete_rsp_free(struct net_shaper_delete_rsp *rsp) +{ + free(rsp); +} + +int net_shaper_delete_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct net_shaper_delete_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == NET_SHAPER_A_MODIFIED) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.modified = 1; + dst->modified = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct net_shaper_delete_rsp * +net_shaper_delete(struct ynl_sock *ys, struct net_shaper_delete_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct net_shaper_delete_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NET_SHAPER_CMD_DELETE, 1); + ys->req_policy = &net_shaper_nest; + yrs.yarg.rsp_policy = &net_shaper_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, NET_SHAPER_A_IFINDEX, req->ifindex); + for (unsigned int i = 0; i < req->n_handles; i++) + net_shaper_handle_put(nlh, NET_SHAPER_A_HANDLES, &req->handles[i]); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = net_shaper_delete_rsp_parse; + yrs.rsp_cmd = NET_SHAPER_CMD_DELETE; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + net_shaper_delete_rsp_free(rsp); + return NULL; +} + +/* ============== NET_SHAPER_CMD_CAP_GET ============== */ +/* NET_SHAPER_CMD_CAP_GET - do */ +void net_shaper_cap_get_req_free(struct net_shaper_cap_get_req *req) +{ + free(req); +} + +void net_shaper_cap_get_rsp_free(struct net_shaper_cap_get_rsp *rsp) +{ + free(rsp); +} + +int net_shaper_cap_get_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct net_shaper_cap_get_rsp *dst; + const struct nlattr *attr; + + dst = yarg->data; + + ynl_attr_for_each(attr, nlh, yarg->ys->family->hdr_len) { + unsigned int type = ynl_attr_type(attr); + + if (type == NET_SHAPER_A_CAPABILITIES_SUPPORT_METRIC_BPS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.support_metric_bps = 1; + } else if (type == NET_SHAPER_A_CAPABILITIES_SUPPORT_METRIC_PPS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.support_metric_pps = 1; + } else if (type == NET_SHAPER_A_CAPABILITIES_SUPPORT_NESTING) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.support_nesting = 1; + } else if (type == NET_SHAPER_A_CAPABILITIES_SUPPORT_BW_MIN) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.support_bw_min = 1; + } else if (type == NET_SHAPER_A_CAPABILITIES_SUPPORT_BW_MAX) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.support_bw_max = 1; + } else if (type == NET_SHAPER_A_CAPABILITIES_SUPPORT_BURST) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.support_burst = 1; + } else if (type == NET_SHAPER_A_CAPABILITIES_SUPPORT_PRIORITY) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.support_priority = 1; + } else if (type == NET_SHAPER_A_CAPABILITIES_SUPPORT_WEIGHT) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.support_weight = 1; + } + } + + return YNL_PARSE_CB_OK; +} + +struct net_shaper_cap_get_rsp * +net_shaper_cap_get(struct ynl_sock *ys, struct net_shaper_cap_get_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct net_shaper_cap_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NET_SHAPER_CMD_CAP_GET, 1); + ys->req_policy = &net_shaper_capabilities_nest; + yrs.yarg.rsp_policy = &net_shaper_capabilities_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, NET_SHAPER_A_CAPABILITIES_IFINDEX, req->ifindex); + if (req->_present.scope) + ynl_attr_put_u32(nlh, NET_SHAPER_A_CAPABILITIES_SCOPE, req->scope); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = net_shaper_cap_get_rsp_parse; + yrs.rsp_cmd = NET_SHAPER_CMD_CAP_GET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + net_shaper_cap_get_rsp_free(rsp); + return NULL; +} + +/* NET_SHAPER_CMD_CAP_GET - dump */ +void net_shaper_cap_get_req_dump_free(struct net_shaper_cap_get_req_dump *req) +{ + free(req); +} + +void net_shaper_cap_get_list_free(struct net_shaper_cap_get_list *rsp) +{ + struct net_shaper_cap_get_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + free(rsp); + } +} + +struct net_shaper_cap_get_list * +net_shaper_cap_get_dump(struct ynl_sock *ys, + struct net_shaper_cap_get_req_dump *req) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.yarg.ys = ys; + yds.yarg.rsp_policy = &net_shaper_capabilities_nest; + yds.yarg.data = NULL; + yds.alloc_sz = sizeof(struct net_shaper_cap_get_list); + yds.cb = net_shaper_cap_get_rsp_parse; + yds.rsp_cmd = NET_SHAPER_CMD_CAP_GET; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, NET_SHAPER_CMD_CAP_GET, 1); + ys->req_policy = &net_shaper_capabilities_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, NET_SHAPER_A_CAPABILITIES_IFINDEX, req->ifindex); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + net_shaper_cap_get_list_free(yds.first); + return NULL; +} + +const struct ynl_family ynl_net_shaper_family = { + .name = "net_shaper", + .hdr_len = sizeof(struct genlmsghdr), +}; diff --git a/home/nipa/nipa_out/866290/ynl/new-code/shaper-user.h b/home/nipa/nipa_out/866290/ynl/new-code/shaper-user.h new file mode 100644 index 000000000000..326ef31ad38c --- /dev/null +++ b/home/nipa/nipa_out/866290/ynl/new-code/shaper-user.h @@ -0,0 +1,366 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/shaper.yaml */ +/* YNL-GEN user header */ + +#ifndef _LINUX_NET_SHAPER_GEN_H +#define _LINUX_NET_SHAPER_GEN_H + +#include +#include +#include +#include + +struct ynl_sock; + +extern const struct ynl_family ynl_net_shaper_family; + +/* Enums */ +const char *net_shaper_op_str(int op); +const char *net_shaper_scope_str(enum net_shaper_scope value); +const char *net_shaper_metric_str(enum net_shaper_metric value); + +/* Common nested types */ +struct net_shaper_handle { + struct { + __u32 scope:1; + __u32 id:1; + } _present; + + enum net_shaper_scope scope; + __u32 id; +}; + +struct net_shaper_ns_info { + struct { + __u32 parent:1; + __u32 handle:1; + __u32 metric:1; + __u32 bw_min:1; + __u32 bw_max:1; + __u32 burst:1; + __u32 priority:1; + __u32 weight:1; + } _present; + + struct net_shaper_handle parent; + struct net_shaper_handle handle; + enum net_shaper_metric metric; + __u64 bw_min; + __u64 bw_max; + __u64 burst; + __u32 priority; + __u32 weight; +}; + +/* ============== NET_SHAPER_CMD_GET ============== */ +/* NET_SHAPER_CMD_GET - do */ +struct net_shaper_get_req { + struct { + __u32 ifindex:1; + __u32 handle:1; + } _present; + + __u32 ifindex; + struct net_shaper_handle handle; +}; + +static inline struct net_shaper_get_req *net_shaper_get_req_alloc(void) +{ + return calloc(1, sizeof(struct net_shaper_get_req)); +} +void net_shaper_get_req_free(struct net_shaper_get_req *req); + +static inline void +net_shaper_get_req_set_ifindex(struct net_shaper_get_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +net_shaper_get_req_set_handle_scope(struct net_shaper_get_req *req, + enum net_shaper_scope scope) +{ + req->_present.handle = 1; + req->handle._present.scope = 1; + req->handle.scope = scope; +} +static inline void +net_shaper_get_req_set_handle_id(struct net_shaper_get_req *req, __u32 id) +{ + req->_present.handle = 1; + req->handle._present.id = 1; + req->handle.id = id; +} + +struct net_shaper_get_rsp { + struct { + __u32 parent:1; + __u32 handle:1; + __u32 metric:1; + __u32 bw_min:1; + __u32 bw_max:1; + __u32 burst:1; + __u32 priority:1; + __u32 weight:1; + } _present; + + struct net_shaper_handle parent; + struct net_shaper_handle handle; + enum net_shaper_metric metric; + __u64 bw_min; + __u64 bw_max; + __u64 burst; + __u32 priority; + __u32 weight; +}; + +void net_shaper_get_rsp_free(struct net_shaper_get_rsp *rsp); + +/* + * Get / Dump information about a/all the shaper for a given device + + */ +struct net_shaper_get_rsp * +net_shaper_get(struct ynl_sock *ys, struct net_shaper_get_req *req); + +/* NET_SHAPER_CMD_GET - dump */ +struct net_shaper_get_req_dump { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct net_shaper_get_req_dump * +net_shaper_get_req_dump_alloc(void) +{ + return calloc(1, sizeof(struct net_shaper_get_req_dump)); +} +void net_shaper_get_req_dump_free(struct net_shaper_get_req_dump *req); + +static inline void +net_shaper_get_req_dump_set_ifindex(struct net_shaper_get_req_dump *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +struct net_shaper_get_list { + struct net_shaper_get_list *next; + struct net_shaper_get_rsp obj __attribute__((aligned(8))); +}; + +void net_shaper_get_list_free(struct net_shaper_get_list *rsp); + +struct net_shaper_get_list * +net_shaper_get_dump(struct ynl_sock *ys, struct net_shaper_get_req_dump *req); + +/* ============== NET_SHAPER_CMD_SET ============== */ +/* NET_SHAPER_CMD_SET - do */ +struct net_shaper_set_req { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; + unsigned int n_shapers; + struct net_shaper_ns_info *shapers; +}; + +static inline struct net_shaper_set_req *net_shaper_set_req_alloc(void) +{ + return calloc(1, sizeof(struct net_shaper_set_req)); +} +void net_shaper_set_req_free(struct net_shaper_set_req *req); + +static inline void +net_shaper_set_req_set_ifindex(struct net_shaper_set_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +__net_shaper_set_req_set_shapers(struct net_shaper_set_req *req, + struct net_shaper_ns_info *shapers, + unsigned int n_shapers) +{ + free(req->shapers); + req->shapers = shapers; + req->n_shapers = n_shapers; +} + +struct net_shaper_set_rsp { + struct { + __u32 modified:1; + } _present; + + __u32 modified; +}; + +void net_shaper_set_rsp_free(struct net_shaper_set_rsp *rsp); + +/* + * Create or configures the specified shapers. +The update is atomic with respect to all shaper +affected by a single command, and is allowed to +affect a subset of the specified shapers, e.g. +due to H/W resources exhaustion. In such case +the update stops at the first failure, the extack +is set accordingly. + + */ +struct net_shaper_set_rsp * +net_shaper_set(struct ynl_sock *ys, struct net_shaper_set_req *req); + +/* ============== NET_SHAPER_CMD_DELETE ============== */ +/* NET_SHAPER_CMD_DELETE - do */ +struct net_shaper_delete_req { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; + unsigned int n_handles; + struct net_shaper_handle *handles; +}; + +static inline struct net_shaper_delete_req *net_shaper_delete_req_alloc(void) +{ + return calloc(1, sizeof(struct net_shaper_delete_req)); +} +void net_shaper_delete_req_free(struct net_shaper_delete_req *req); + +static inline void +net_shaper_delete_req_set_ifindex(struct net_shaper_delete_req *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +__net_shaper_delete_req_set_handles(struct net_shaper_delete_req *req, + struct net_shaper_handle *handles, + unsigned int n_handles) +{ + free(req->handles); + req->handles = handles; + req->n_handles = n_handles; +} + +struct net_shaper_delete_rsp { + struct { + __u32 modified:1; + } _present; + + __u32 modified; +}; + +void net_shaper_delete_rsp_free(struct net_shaper_delete_rsp *rsp); + +/* + * Clear (remove) the specified shaper. +The update is atomic with respect to all shaper +affected by a single command, and is allowed to +affect a subset of the specified shapers, e.g. +due to H/W resources exhaustion. In such case +the update stops at the first failure, the extack +is set accordingly. + + */ +struct net_shaper_delete_rsp * +net_shaper_delete(struct ynl_sock *ys, struct net_shaper_delete_req *req); + +/* ============== NET_SHAPER_CMD_CAP_GET ============== */ +/* NET_SHAPER_CMD_CAP_GET - do */ +struct net_shaper_cap_get_req { + struct { + __u32 ifindex:1; + __u32 scope:1; + } _present; + + __u32 ifindex; + enum net_shaper_scope scope; +}; + +static inline struct net_shaper_cap_get_req *net_shaper_cap_get_req_alloc(void) +{ + return calloc(1, sizeof(struct net_shaper_cap_get_req)); +} +void net_shaper_cap_get_req_free(struct net_shaper_cap_get_req *req); + +static inline void +net_shaper_cap_get_req_set_ifindex(struct net_shaper_cap_get_req *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +net_shaper_cap_get_req_set_scope(struct net_shaper_cap_get_req *req, + enum net_shaper_scope scope) +{ + req->_present.scope = 1; + req->scope = scope; +} + +struct net_shaper_cap_get_rsp { + struct { + __u32 support_metric_bps:1; + __u32 support_metric_pps:1; + __u32 support_nesting:1; + __u32 support_bw_min:1; + __u32 support_bw_max:1; + __u32 support_burst:1; + __u32 support_priority:1; + __u32 support_weight:1; + } _present; +}; + +void net_shaper_cap_get_rsp_free(struct net_shaper_cap_get_rsp *rsp); + +/* + * Get / Dump the shaper capabilities supported by the given device + + */ +struct net_shaper_cap_get_rsp * +net_shaper_cap_get(struct ynl_sock *ys, struct net_shaper_cap_get_req *req); + +/* NET_SHAPER_CMD_CAP_GET - dump */ +struct net_shaper_cap_get_req_dump { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct net_shaper_cap_get_req_dump * +net_shaper_cap_get_req_dump_alloc(void) +{ + return calloc(1, sizeof(struct net_shaper_cap_get_req_dump)); +} +void net_shaper_cap_get_req_dump_free(struct net_shaper_cap_get_req_dump *req); + +static inline void +net_shaper_cap_get_req_dump_set_ifindex(struct net_shaper_cap_get_req_dump *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +struct net_shaper_cap_get_list { + struct net_shaper_cap_get_list *next; + struct net_shaper_cap_get_rsp obj __attribute__((aligned(8))); +}; + +void net_shaper_cap_get_list_free(struct net_shaper_cap_get_list *rsp); + +struct net_shaper_cap_get_list * +net_shaper_cap_get_dump(struct ynl_sock *ys, + struct net_shaper_cap_get_req_dump *req); + +#endif /* _LINUX_NET_SHAPER_GEN_H */