diff --git a/tmp/ynl_build-tmp.ciVlDj/old-code/ethtool-user.c b/tmp/ynl_build-tmp.ciVlDj/new-code/ethtool-user.c index 161544ca083f..097629131bc4 100644 --- a/tmp/ynl_build-tmp.ciVlDj/old-code/ethtool-user.c +++ b/tmp/ynl_build-tmp.ciVlDj/new-code/ethtool-user.c @@ -71,6 +71,7 @@ static const char * const ethtool_op_strmap[] = { [52] = "rss-create-ntf", [53] = "rss-delete-ntf", [54] = "mse-get", + [55] = "port-get", }; const char *ethtool_op_str(int op) @@ -240,6 +241,18 @@ const char *ethtool_rxfh_fields_str(int value) return ethtool_rxfh_fields_strmap[value]; } +static const char * const ethtool_port_type_strmap[] = { + [0] = "mdi", + [1] = "sfp", +}; + +const char *ethtool_port_type_str(enum ethtool_port_type value) +{ + if (value < 0 || value >= (int)YNL_ARRAY_SIZE(ethtool_port_type_strmap)) + return NULL; + return ethtool_port_type_strmap[value]; +} + /* Policies */ const struct ynl_policy_attr ethtool_header_policy[ETHTOOL_A_HEADER_MAX + 1] = { [ETHTOOL_A_HEADER_UNSPEC] = { .name = "unspec", .type = YNL_PT_REJECT, }, @@ -1090,6 +1103,20 @@ const struct ynl_policy_nest ethtool_mse_nest = { .table = ethtool_mse_policy, }; +const struct ynl_policy_attr ethtool_port_policy[ETHTOOL_A_PORT_MAX + 1] = { + [ETHTOOL_A_PORT_HEADER] = { .name = "header", .type = YNL_PT_NEST, .nest = ðtool_header_nest, }, + [ETHTOOL_A_PORT_ID] = { .name = "id", .type = YNL_PT_U32, }, + [ETHTOOL_A_PORT_SUPPORTED_MODES] = { .name = "supported-modes", .type = YNL_PT_NEST, .nest = ðtool_bitset_nest, }, + [ETHTOOL_A_PORT_SUPPORTED_INTERFACES] = { .name = "supported-interfaces", .type = YNL_PT_NEST, .nest = ðtool_bitset_nest, }, + [ETHTOOL_A_PORT_TYPE] = { .name = "type", .type = YNL_PT_U8, }, + [ETHTOOL_A_PORT_OCCUPIED] = { .name = "occupied", .type = YNL_PT_U8, }, +}; + +const struct ynl_policy_nest ethtool_port_nest = { + .max_attr = ETHTOOL_A_PORT_MAX, + .table = ethtool_port_policy, +}; + /* Common nested types */ void ethtool_header_free(struct ethtool_header *obj) { @@ -8638,6 +8665,174 @@ ethtool_mse_get_dump(struct ynl_sock *ys, struct ethtool_mse_get_req_dump *req) return NULL; } +/* ============== ETHTOOL_MSG_PORT_GET ============== */ +/* ETHTOOL_MSG_PORT_GET - do */ +void ethtool_port_get_req_free(struct ethtool_port_get_req *req) +{ + ethtool_header_free(&req->header); + free(req); +} + +void ethtool_port_get_rsp_free(struct ethtool_port_get_rsp *rsp) +{ + ethtool_header_free(&rsp->header); + ethtool_bitset_free(&rsp->supported_modes); + ethtool_bitset_free(&rsp->supported_interfaces); + free(rsp); +} + +int ethtool_port_get_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct ethtool_port_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 == ETHTOOL_A_PORT_HEADER) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.header = 1; + + parg.rsp_policy = ðtool_header_nest; + parg.data = &dst->header; + if (ethtool_header_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == ETHTOOL_A_PORT_ID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.id = 1; + dst->id = ynl_attr_get_u32(attr); + } else if (type == ETHTOOL_A_PORT_SUPPORTED_MODES) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.supported_modes = 1; + + parg.rsp_policy = ðtool_bitset_nest; + parg.data = &dst->supported_modes; + if (ethtool_bitset_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == ETHTOOL_A_PORT_SUPPORTED_INTERFACES) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.supported_interfaces = 1; + + parg.rsp_policy = ðtool_bitset_nest; + parg.data = &dst->supported_interfaces; + if (ethtool_bitset_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == ETHTOOL_A_PORT_TYPE) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.type = 1; + dst->type = ynl_attr_get_u8(attr); + } else if (type == ETHTOOL_A_PORT_OCCUPIED) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.occupied = 1; + dst->occupied = ynl_attr_get_u8(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct ethtool_port_get_rsp * +ethtool_port_get(struct ynl_sock *ys, struct ethtool_port_get_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct ethtool_port_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, ETHTOOL_MSG_PORT_GET, 1); + ys->req_policy = ðtool_port_nest; + ys->req_hdr_len = ys->family->hdr_len; + yrs.yarg.rsp_policy = ðtool_port_nest; + + if (req->_present.header) + ethtool_header_put(nlh, ETHTOOL_A_PORT_HEADER, &req->header); + if (req->_present.id) + ynl_attr_put_u32(nlh, ETHTOOL_A_PORT_ID, req->id); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = ethtool_port_get_rsp_parse; + yrs.rsp_cmd = 55; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + ethtool_port_get_rsp_free(rsp); + return NULL; +} + +/* ETHTOOL_MSG_PORT_GET - dump */ +void ethtool_port_get_req_dump_free(struct ethtool_port_get_req_dump *req) +{ + ethtool_header_free(&req->header); + free(req); +} + +void ethtool_port_get_list_free(struct ethtool_port_get_list *rsp) +{ + struct ethtool_port_get_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + ethtool_header_free(&rsp->obj.header); + ethtool_bitset_free(&rsp->obj.supported_modes); + ethtool_bitset_free(&rsp->obj.supported_interfaces); + free(rsp); + } +} + +struct ethtool_port_get_list * +ethtool_port_get_dump(struct ynl_sock *ys, + struct ethtool_port_get_req_dump *req) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.yarg.ys = ys; + yds.yarg.rsp_policy = ðtool_port_nest; + yds.yarg.data = NULL; + yds.alloc_sz = sizeof(struct ethtool_port_get_list); + yds.cb = ethtool_port_get_rsp_parse; + yds.rsp_cmd = 55; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, ETHTOOL_MSG_PORT_GET, 1); + ys->req_policy = ðtool_port_nest; + ys->req_hdr_len = ys->family->hdr_len; + + if (req->_present.header) + ethtool_header_put(nlh, ETHTOOL_A_PORT_HEADER, &req->header); + if (req->_present.id) + ynl_attr_put_u32(nlh, ETHTOOL_A_PORT_ID, req->id); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + ethtool_port_get_list_free(yds.first); + return NULL; +} + /* ETHTOOL_MSG_CABLE_TEST_NTF - event */ int ethtool_cable_test_ntf_rsp_parse(const struct nlmsghdr *nlh, struct ynl_parse_arg *yarg) diff --git a/tmp/ynl_build-tmp.ciVlDj/old-code/ethtool-user.h b/tmp/ynl_build-tmp.ciVlDj/new-code/ethtool-user.h index 43e10c5f442b..62622b7e08e0 100644 --- a/tmp/ynl_build-tmp.ciVlDj/old-code/ethtool-user.h +++ b/tmp/ynl_build-tmp.ciVlDj/new-code/ethtool-user.h @@ -33,6 +33,7 @@ const char *ethtool_hwtstamp_source_str(enum hwtstamp_source value); const char *ethtool_pse_event_str(enum ethtool_pse_event value); const char *ethtool_input_xfrm_str(int value); const char *ethtool_rxfh_fields_str(int value); +const char *ethtool_port_type_str(enum ethtool_port_type value); /* Common nested types */ struct ethtool_header { @@ -8347,6 +8348,164 @@ void ethtool_mse_get_list_free(struct ethtool_mse_get_list *rsp); struct ethtool_mse_get_list * ethtool_mse_get_dump(struct ynl_sock *ys, struct ethtool_mse_get_req_dump *req); +/* ============== ETHTOOL_MSG_PORT_GET ============== */ +/* ETHTOOL_MSG_PORT_GET - do */ +struct ethtool_port_get_req { + struct { + __u32 header:1; + __u32 id:1; + } _present; + + struct ethtool_header header; + __u32 id; +}; + +static inline struct ethtool_port_get_req *ethtool_port_get_req_alloc(void) +{ + return calloc(1, sizeof(struct ethtool_port_get_req)); +} +void ethtool_port_get_req_free(struct ethtool_port_get_req *req); + +static inline void +ethtool_port_get_req_set_header_dev_index(struct ethtool_port_get_req *req, + __u32 dev_index) +{ + req->_present.header = 1; + req->header._present.dev_index = 1; + req->header.dev_index = dev_index; +} +static inline void +ethtool_port_get_req_set_header_dev_name(struct ethtool_port_get_req *req, + const char *dev_name) +{ + req->_present.header = 1; + free(req->header.dev_name); + req->header._len.dev_name = strlen(dev_name); + req->header.dev_name = malloc(req->header._len.dev_name + 1); + memcpy(req->header.dev_name, dev_name, req->header._len.dev_name); + req->header.dev_name[req->header._len.dev_name] = 0; +} +static inline void +ethtool_port_get_req_set_header_flags(struct ethtool_port_get_req *req, + __u32 flags) +{ + req->_present.header = 1; + req->header._present.flags = 1; + req->header.flags = flags; +} +static inline void +ethtool_port_get_req_set_header_phy_index(struct ethtool_port_get_req *req, + __u32 phy_index) +{ + req->_present.header = 1; + req->header._present.phy_index = 1; + req->header.phy_index = phy_index; +} +static inline void +ethtool_port_get_req_set_id(struct ethtool_port_get_req *req, __u32 id) +{ + req->_present.id = 1; + req->id = id; +} + +struct ethtool_port_get_rsp { + struct { + __u32 header:1; + __u32 id:1; + __u32 supported_modes:1; + __u32 supported_interfaces:1; + __u32 type:1; + __u32 occupied:1; + } _present; + + struct ethtool_header header; + __u32 id; + struct ethtool_bitset supported_modes; + struct ethtool_bitset supported_interfaces; + enum ethtool_port_type type; + __u8 occupied; +}; + +void ethtool_port_get_rsp_free(struct ethtool_port_get_rsp *rsp); + +/* + * Get ports attached to an interface + */ +struct ethtool_port_get_rsp * +ethtool_port_get(struct ynl_sock *ys, struct ethtool_port_get_req *req); + +/* ETHTOOL_MSG_PORT_GET - dump */ +struct ethtool_port_get_req_dump { + struct { + __u32 header:1; + __u32 id:1; + } _present; + + struct ethtool_header header; + __u32 id; +}; + +static inline struct ethtool_port_get_req_dump * +ethtool_port_get_req_dump_alloc(void) +{ + return calloc(1, sizeof(struct ethtool_port_get_req_dump)); +} +void ethtool_port_get_req_dump_free(struct ethtool_port_get_req_dump *req); + +static inline void +ethtool_port_get_req_dump_set_header_dev_index(struct ethtool_port_get_req_dump *req, + __u32 dev_index) +{ + req->_present.header = 1; + req->header._present.dev_index = 1; + req->header.dev_index = dev_index; +} +static inline void +ethtool_port_get_req_dump_set_header_dev_name(struct ethtool_port_get_req_dump *req, + const char *dev_name) +{ + req->_present.header = 1; + free(req->header.dev_name); + req->header._len.dev_name = strlen(dev_name); + req->header.dev_name = malloc(req->header._len.dev_name + 1); + memcpy(req->header.dev_name, dev_name, req->header._len.dev_name); + req->header.dev_name[req->header._len.dev_name] = 0; +} +static inline void +ethtool_port_get_req_dump_set_header_flags(struct ethtool_port_get_req_dump *req, + __u32 flags) +{ + req->_present.header = 1; + req->header._present.flags = 1; + req->header.flags = flags; +} +static inline void +ethtool_port_get_req_dump_set_header_phy_index(struct ethtool_port_get_req_dump *req, + __u32 phy_index) +{ + req->_present.header = 1; + req->header._present.phy_index = 1; + req->header.phy_index = phy_index; +} +static inline void +ethtool_port_get_req_dump_set_id(struct ethtool_port_get_req_dump *req, + __u32 id) +{ + req->_present.id = 1; + req->id = id; +} + +struct ethtool_port_get_list { + struct ethtool_port_get_list *next; + struct ethtool_port_get_rsp obj __attribute__((aligned(8))); +}; + +void ethtool_port_get_list_free(struct ethtool_port_get_list *rsp); + +struct ethtool_port_get_list * +ethtool_port_get_dump(struct ynl_sock *ys, + struct ethtool_port_get_req_dump *req); + /* ETHTOOL_MSG_CABLE_TEST_NTF - event */ struct ethtool_cable_test_ntf_rsp { struct {