diff --git a/tmp/ynl_build-tmp.C60lPS/new-code/ipxlat-user.c b/tmp/ynl_build-tmp.C60lPS/new-code/ipxlat-user.c new file mode 100644 index 000000000000..e98c5ba45754 --- /dev/null +++ b/tmp/ynl_build-tmp.C60lPS/new-code/ipxlat-user.c @@ -0,0 +1,339 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/ipxlat.yaml */ +/* YNL-GEN user source */ +/* To regenerate run: tools/net/ynl/ynl-regen.sh */ + +#include +#include +#include "ipxlat-user.h" +#include "ynl.h" +#include + +#include + +/* Enums */ +static const char * const ipxlat_op_strmap[] = { + [IPXLAT_CMD_DEV_GET] = "dev-get", + [IPXLAT_CMD_DEV_SET] = "dev-set", +}; + +const char *ipxlat_op_str(int op) +{ + if (op < 0 || op >= (int)YNL_ARRAY_SIZE(ipxlat_op_strmap)) + return NULL; + return ipxlat_op_strmap[op]; +} + +/* Policies */ +const struct ynl_policy_attr ipxlat_pool_policy[IPXLAT_A_POOL_MAX + 1] = { + [IPXLAT_A_POOL_PREFIX] = { .name = "prefix", .type = YNL_PT_BINARY,}, + [IPXLAT_A_POOL_PREFIX_LEN] = { .name = "prefix-len", .type = YNL_PT_U8, }, +}; + +const struct ynl_policy_nest ipxlat_pool_nest = { + .max_attr = IPXLAT_A_POOL_MAX, + .table = ipxlat_pool_policy, +}; + +const struct ynl_policy_attr ipxlat_cfg_policy[IPXLAT_A_CFG_MAX + 1] = { + [IPXLAT_A_CFG_XLAT_PREFIX6] = { .name = "xlat-prefix6", .type = YNL_PT_NEST, .nest = &ipxlat_pool_nest, }, + [IPXLAT_A_CFG_LOWEST_IPV6_MTU] = { .name = "lowest-ipv6-mtu", .type = YNL_PT_U32, }, +}; + +const struct ynl_policy_nest ipxlat_cfg_nest = { + .max_attr = IPXLAT_A_CFG_MAX, + .table = ipxlat_cfg_policy, +}; + +const struct ynl_policy_attr ipxlat_dev_policy[IPXLAT_A_DEV_MAX + 1] = { + [IPXLAT_A_DEV_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [IPXLAT_A_DEV_NETNSID] = { .name = "netnsid", .type = YNL_PT_U32, }, + [IPXLAT_A_DEV_CONFIG] = { .name = "config", .type = YNL_PT_NEST, .nest = &ipxlat_cfg_nest, }, +}; + +const struct ynl_policy_nest ipxlat_dev_nest = { + .max_attr = IPXLAT_A_DEV_MAX, + .table = ipxlat_dev_policy, +}; + +/* Common nested types */ +void ipxlat_pool_free(struct ipxlat_pool *obj) +{ + free(obj->prefix); +} + +int ipxlat_pool_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct ipxlat_pool *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_len.prefix) + ynl_attr_put(nlh, IPXLAT_A_POOL_PREFIX, obj->prefix, obj->_len.prefix); + if (obj->_present.prefix_len) + ynl_attr_put_u8(nlh, IPXLAT_A_POOL_PREFIX_LEN, obj->prefix_len); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +int ipxlat_pool_parse(struct ynl_parse_arg *yarg, const struct nlattr *nested) +{ + struct ipxlat_pool *dst = yarg->data; + const struct nlattr *attr; + unsigned int len; + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == IPXLAT_A_POOL_PREFIX) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + + len = ynl_attr_data_len(attr); + dst->_len.prefix = len; + dst->prefix = malloc(len); + memcpy(dst->prefix, ynl_attr_data(attr), len); + } else if (type == IPXLAT_A_POOL_PREFIX_LEN) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.prefix_len = 1; + dst->prefix_len = ynl_attr_get_u8(attr); + } + } + + return 0; +} + +void ipxlat_cfg_free(struct ipxlat_cfg *obj) +{ + ipxlat_pool_free(&obj->xlat_prefix6); +} + +int ipxlat_cfg_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct ipxlat_cfg *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_present.xlat_prefix6) + ipxlat_pool_put(nlh, IPXLAT_A_CFG_XLAT_PREFIX6, &obj->xlat_prefix6); + if (obj->_present.lowest_ipv6_mtu) + ynl_attr_put_u32(nlh, IPXLAT_A_CFG_LOWEST_IPV6_MTU, obj->lowest_ipv6_mtu); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +int ipxlat_cfg_parse(struct ynl_parse_arg *yarg, const struct nlattr *nested) +{ + struct ipxlat_cfg *dst = yarg->data; + const struct nlattr *attr; + struct ynl_parse_arg parg; + + parg.ys = yarg->ys; + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == IPXLAT_A_CFG_XLAT_PREFIX6) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.xlat_prefix6 = 1; + + parg.rsp_policy = &ipxlat_pool_nest; + parg.data = &dst->xlat_prefix6; + if (ipxlat_pool_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == IPXLAT_A_CFG_LOWEST_IPV6_MTU) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.lowest_ipv6_mtu = 1; + dst->lowest_ipv6_mtu = ynl_attr_get_u32(attr); + } + } + + return 0; +} + +/* ============== IPXLAT_CMD_DEV_GET ============== */ +/* IPXLAT_CMD_DEV_GET - do */ +void ipxlat_dev_get_req_free(struct ipxlat_dev_get_req *req) +{ + free(req); +} + +void ipxlat_dev_get_rsp_free(struct ipxlat_dev_get_rsp *rsp) +{ + ipxlat_cfg_free(&rsp->config); + free(rsp); +} + +int ipxlat_dev_get_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct ipxlat_dev_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 == IPXLAT_A_DEV_IFINDEX) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.ifindex = 1; + dst->ifindex = ynl_attr_get_u32(attr); + } else if (type == IPXLAT_A_DEV_NETNSID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.netnsid = 1; + dst->netnsid = ynl_attr_get_s32(attr); + } else if (type == IPXLAT_A_DEV_CONFIG) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.config = 1; + + parg.rsp_policy = &ipxlat_cfg_nest; + parg.data = &dst->config; + if (ipxlat_cfg_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } + } + + return YNL_PARSE_CB_OK; +} + +struct ipxlat_dev_get_rsp * +ipxlat_dev_get(struct ynl_sock *ys, struct ipxlat_dev_get_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct ipxlat_dev_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, IPXLAT_CMD_DEV_GET, 1); + ys->req_policy = &ipxlat_dev_nest; + ys->req_hdr_len = ys->family->hdr_len; + yrs.yarg.rsp_policy = &ipxlat_dev_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, IPXLAT_A_DEV_IFINDEX, req->ifindex); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = ipxlat_dev_get_rsp_parse; + yrs.rsp_cmd = IPXLAT_CMD_DEV_GET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + ipxlat_dev_get_rsp_free(rsp); + return NULL; +} + +/* IPXLAT_CMD_DEV_GET - dump */ +void ipxlat_dev_get_list_free(struct ipxlat_dev_get_list *rsp) +{ + struct ipxlat_dev_get_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + ipxlat_cfg_free(&rsp->obj.config); + free(rsp); + } +} + +struct ipxlat_dev_get_list *ipxlat_dev_get_dump(struct ynl_sock *ys) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.yarg.ys = ys; + yds.yarg.rsp_policy = &ipxlat_dev_nest; + yds.yarg.data = NULL; + yds.alloc_sz = sizeof(struct ipxlat_dev_get_list); + yds.cb = ipxlat_dev_get_rsp_parse; + yds.rsp_cmd = IPXLAT_CMD_DEV_GET; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, IPXLAT_CMD_DEV_GET, 1); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + ipxlat_dev_get_list_free(yds.first); + return NULL; +} + +/* ============== IPXLAT_CMD_DEV_SET ============== */ +/* IPXLAT_CMD_DEV_SET - do */ +void ipxlat_dev_set_req_free(struct ipxlat_dev_set_req *req) +{ + ipxlat_cfg_free(&req->config); + free(req); +} + +void ipxlat_dev_set_rsp_free(struct ipxlat_dev_set_rsp *rsp) +{ + free(rsp); +} + +int ipxlat_dev_set_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + return YNL_PARSE_CB_OK; +} + +struct ipxlat_dev_set_rsp * +ipxlat_dev_set(struct ynl_sock *ys, struct ipxlat_dev_set_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct ipxlat_dev_set_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, IPXLAT_CMD_DEV_SET, 1); + ys->req_policy = &ipxlat_dev_nest; + ys->req_hdr_len = ys->family->hdr_len; + yrs.yarg.rsp_policy = &ipxlat_dev_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, IPXLAT_A_DEV_IFINDEX, req->ifindex); + if (req->_present.config) + ipxlat_cfg_put(nlh, IPXLAT_A_DEV_CONFIG, &req->config); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = ipxlat_dev_set_rsp_parse; + yrs.rsp_cmd = IPXLAT_CMD_DEV_SET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + ipxlat_dev_set_rsp_free(rsp); + return NULL; +} + +const struct ynl_family ynl_ipxlat_family = { + .name = "ipxlat", + .hdr_len = sizeof(struct genlmsghdr), +}; diff --git a/tmp/ynl_build-tmp.C60lPS/new-code/ipxlat-user.h b/tmp/ynl_build-tmp.C60lPS/new-code/ipxlat-user.h new file mode 100644 index 000000000000..0b4bce7792a4 --- /dev/null +++ b/tmp/ynl_build-tmp.C60lPS/new-code/ipxlat-user.h @@ -0,0 +1,163 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/ipxlat.yaml */ +/* YNL-GEN user header */ +/* To regenerate run: tools/net/ynl/ynl-regen.sh */ + +#ifndef _LINUX_IPXLAT_GEN_H +#define _LINUX_IPXLAT_GEN_H + +#include +#include +#include +#include + +struct ynl_sock; + +extern const struct ynl_family ynl_ipxlat_family; + +/* Enums */ +const char *ipxlat_op_str(int op); + +/* Common nested types */ +struct ipxlat_pool { + struct { + __u32 prefix_len:1; + } _present; + struct { + __u32 prefix; + } _len; + + void *prefix; + __u8 prefix_len; +}; + +struct ipxlat_cfg { + struct { + __u32 xlat_prefix6:1; + __u32 lowest_ipv6_mtu:1; + } _present; + + struct ipxlat_pool xlat_prefix6; + __u32 lowest_ipv6_mtu; +}; + +/* ============== IPXLAT_CMD_DEV_GET ============== */ +/* IPXLAT_CMD_DEV_GET - do */ +struct ipxlat_dev_get_req { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct ipxlat_dev_get_req *ipxlat_dev_get_req_alloc(void) +{ + return calloc(1, sizeof(struct ipxlat_dev_get_req)); +} +void ipxlat_dev_get_req_free(struct ipxlat_dev_get_req *req); + +static inline void +ipxlat_dev_get_req_set_ifindex(struct ipxlat_dev_get_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +struct ipxlat_dev_get_rsp { + struct { + __u32 ifindex:1; + __u32 netnsid:1; + __u32 config:1; + } _present; + + __u32 ifindex; + __s32 netnsid; + struct ipxlat_cfg config; +}; + +void ipxlat_dev_get_rsp_free(struct ipxlat_dev_get_rsp *rsp); + +/* + * Get / dump configuration of ipxlat devices. + */ +struct ipxlat_dev_get_rsp * +ipxlat_dev_get(struct ynl_sock *ys, struct ipxlat_dev_get_req *req); + +/* IPXLAT_CMD_DEV_GET - dump */ +struct ipxlat_dev_get_list { + struct ipxlat_dev_get_list *next; + struct ipxlat_dev_get_rsp obj __attribute__((aligned(8))); +}; + +void ipxlat_dev_get_list_free(struct ipxlat_dev_get_list *rsp); + +struct ipxlat_dev_get_list *ipxlat_dev_get_dump(struct ynl_sock *ys); + +/* ============== IPXLAT_CMD_DEV_SET ============== */ +/* IPXLAT_CMD_DEV_SET - do */ +struct ipxlat_dev_set_req { + struct { + __u32 ifindex:1; + __u32 config:1; + } _present; + + __u32 ifindex; + struct ipxlat_cfg config; +}; + +static inline struct ipxlat_dev_set_req *ipxlat_dev_set_req_alloc(void) +{ + return calloc(1, sizeof(struct ipxlat_dev_set_req)); +} +void ipxlat_dev_set_req_free(struct ipxlat_dev_set_req *req); + +static inline void +ipxlat_dev_set_req_set_ifindex(struct ipxlat_dev_set_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +ipxlat_dev_set_req_set_config_xlat_prefix6_prefix(struct ipxlat_dev_set_req *req, + const void *prefix, + size_t len) +{ + req->_present.config = 1; + req->config._present.xlat_prefix6 = 1; + free(req->config.xlat_prefix6.prefix); + req->config.xlat_prefix6._len.prefix = len; + req->config.xlat_prefix6.prefix = malloc(req->config.xlat_prefix6._len.prefix); + memcpy(req->config.xlat_prefix6.prefix, prefix, req->config.xlat_prefix6._len.prefix); +} +static inline void +ipxlat_dev_set_req_set_config_xlat_prefix6_prefix_len(struct ipxlat_dev_set_req *req, + __u8 prefix_len) +{ + req->_present.config = 1; + req->config._present.xlat_prefix6 = 1; + req->config.xlat_prefix6._present.prefix_len = 1; + req->config.xlat_prefix6.prefix_len = prefix_len; +} +static inline void +ipxlat_dev_set_req_set_config_lowest_ipv6_mtu(struct ipxlat_dev_set_req *req, + __u32 lowest_ipv6_mtu) +{ + req->_present.config = 1; + req->config._present.lowest_ipv6_mtu = 1; + req->config.lowest_ipv6_mtu = lowest_ipv6_mtu; +} + +struct ipxlat_dev_set_rsp { +}; + +void ipxlat_dev_set_rsp_free(struct ipxlat_dev_set_rsp *rsp); + +/* + * Set configuration of an ipxlat device. + */ +struct ipxlat_dev_set_rsp * +ipxlat_dev_set(struct ynl_sock *ys, struct ipxlat_dev_set_req *req); + +#endif /* _LINUX_IPXLAT_GEN_H */