diff --git a/tmp/ynl_build-tmp.pH6hSc/old-code/netdev-user.c b/tmp/ynl_build-tmp.pH6hSc/new-code/netdev-user.c index 15961fa84a39..f94c5546a16c 100644 --- a/tmp/ynl_build-tmp.pH6hSc/old-code/netdev-user.c +++ b/tmp/ynl_build-tmp.pH6hSc/new-code/netdev-user.c @@ -29,6 +29,7 @@ static const char * const netdev_op_strmap[] = { [NETDEV_CMD_BIND_RX] = "bind-rx", [NETDEV_CMD_NAPI_SET] = "napi-set", [NETDEV_CMD_BIND_TX] = "bind-tx", + [NETDEV_CMD_QUEUE_CREATE] = "queue-create", }; const char *netdev_op_str(int op) @@ -158,6 +159,17 @@ const struct ynl_policy_nest netdev_queue_id_nest = { .table = netdev_queue_id_policy, }; +const struct ynl_policy_attr netdev_lease_policy[NETDEV_A_LEASE_MAX + 1] = { + [NETDEV_A_LEASE_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [NETDEV_A_LEASE_QUEUE] = { .name = "queue", .type = YNL_PT_NEST, .nest = &netdev_queue_id_nest, }, + [NETDEV_A_LEASE_NETNS_ID] = { .name = "netns-id", .type = YNL_PT_U32, }, +}; + +const struct ynl_policy_nest netdev_lease_nest = { + .max_attr = NETDEV_A_LEASE_MAX, + .table = netdev_lease_policy, +}; + const struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX + 1] = { [NETDEV_A_DEV_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, [NETDEV_A_DEV_PAD] = { .name = "pad", .type = YNL_PT_IGNORE, }, @@ -216,6 +228,7 @@ const struct ynl_policy_attr netdev_queue_policy[NETDEV_A_QUEUE_MAX + 1] = { [NETDEV_A_QUEUE_DMABUF] = { .name = "dmabuf", .type = YNL_PT_U32, }, [NETDEV_A_QUEUE_IO_URING] = { .name = "io-uring", .type = YNL_PT_NEST, .nest = &netdev_io_uring_provider_info_nest, }, [NETDEV_A_QUEUE_XSK] = { .name = "xsk", .type = YNL_PT_NEST, .nest = &netdev_xsk_info_nest, }, + [NETDEV_A_QUEUE_LEASE] = { .name = "lease", .type = YNL_PT_NEST, .nest = &netdev_lease_nest, }, }; const struct ynl_policy_nest netdev_queue_nest = { @@ -375,6 +388,89 @@ int netdev_queue_id_put(struct nlmsghdr *nlh, unsigned int attr_type, return 0; } +int netdev_queue_id_parse(struct ynl_parse_arg *yarg, + const struct nlattr *nested) +{ + struct netdev_queue_id *dst = yarg->data; + const struct nlattr *attr; + + ynl_attr_for_each_nested(attr, nested) { + unsigned int type = ynl_attr_type(attr); + + if (type == NETDEV_A_QUEUE_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 == NETDEV_A_QUEUE_TYPE) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.type = 1; + dst->type = ynl_attr_get_u32(attr); + } + } + + return 0; +} + +void netdev_lease_free(struct netdev_lease *obj) +{ + netdev_queue_id_free(&obj->queue); +} + +int netdev_lease_put(struct nlmsghdr *nlh, unsigned int attr_type, + struct netdev_lease *obj) +{ + struct nlattr *nest; + + nest = ynl_attr_nest_start(nlh, attr_type); + if (obj->_present.ifindex) + ynl_attr_put_u32(nlh, NETDEV_A_LEASE_IFINDEX, obj->ifindex); + if (obj->_present.queue) + netdev_queue_id_put(nlh, NETDEV_A_LEASE_QUEUE, &obj->queue); + if (obj->_present.netns_id) + ynl_attr_put_s32(nlh, NETDEV_A_LEASE_NETNS_ID, obj->netns_id); + ynl_attr_nest_end(nlh, nest); + + return 0; +} + +int netdev_lease_parse(struct ynl_parse_arg *yarg, const struct nlattr *nested) +{ + struct netdev_lease *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 == NETDEV_A_LEASE_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 == NETDEV_A_LEASE_QUEUE) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.queue = 1; + + parg.rsp_policy = &netdev_queue_id_nest; + parg.data = &dst->queue; + if (netdev_queue_id_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; + } else if (type == NETDEV_A_LEASE_NETNS_ID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.netns_id = 1; + dst->netns_id = ynl_attr_get_s32(attr); + } + } + + return 0; +} + /* ============== NETDEV_CMD_DEV_GET ============== */ /* NETDEV_CMD_DEV_GET - do */ void netdev_dev_get_req_free(struct netdev_dev_get_req *req) @@ -847,6 +943,7 @@ void netdev_queue_get_rsp_free(struct netdev_queue_get_rsp *rsp) { netdev_io_uring_provider_info_free(&rsp->io_uring); netdev_xsk_info_free(&rsp->xsk); + netdev_lease_free(&rsp->lease); free(rsp); } @@ -906,6 +1003,15 @@ int netdev_queue_get_rsp_parse(const struct nlmsghdr *nlh, parg.data = &dst->xsk; if (netdev_xsk_info_parse(&parg, attr)) return YNL_PARSE_CB_ERROR; + } else if (type == NETDEV_A_QUEUE_LEASE) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.lease = 1; + + parg.rsp_policy = &netdev_lease_nest; + parg.data = &dst->lease; + if (netdev_lease_parse(&parg, attr)) + return YNL_PARSE_CB_ERROR; } } @@ -964,6 +1070,7 @@ void netdev_queue_get_list_free(struct netdev_queue_get_list *rsp) netdev_io_uring_provider_info_free(&rsp->obj.io_uring); netdev_xsk_info_free(&rsp->obj.xsk); + netdev_lease_free(&rsp->obj.lease); free(rsp); } } @@ -1551,6 +1658,77 @@ netdev_bind_tx(struct ynl_sock *ys, struct netdev_bind_tx_req *req) return NULL; } +/* ============== NETDEV_CMD_QUEUE_CREATE ============== */ +/* NETDEV_CMD_QUEUE_CREATE - do */ +void netdev_queue_create_req_free(struct netdev_queue_create_req *req) +{ + netdev_lease_free(&req->lease); + free(req); +} + +void netdev_queue_create_rsp_free(struct netdev_queue_create_rsp *rsp) +{ + free(rsp); +} + +int netdev_queue_create_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct netdev_queue_create_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 == NETDEV_A_QUEUE_ID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.id = 1; + dst->id = ynl_attr_get_u32(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct netdev_queue_create_rsp * +netdev_queue_create(struct ynl_sock *ys, struct netdev_queue_create_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct netdev_queue_create_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NETDEV_CMD_QUEUE_CREATE, 1); + ys->req_policy = &netdev_queue_nest; + ys->req_hdr_len = ys->family->hdr_len; + yrs.yarg.rsp_policy = &netdev_queue_nest; + + if (req->_present.ifindex) + ynl_attr_put_u32(nlh, NETDEV_A_QUEUE_IFINDEX, req->ifindex); + if (req->_present.type) + ynl_attr_put_u32(nlh, NETDEV_A_QUEUE_TYPE, req->type); + if (req->_present.lease) + netdev_lease_put(nlh, NETDEV_A_QUEUE_LEASE, &req->lease); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = netdev_queue_create_rsp_parse; + yrs.rsp_cmd = NETDEV_CMD_QUEUE_CREATE; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + netdev_queue_create_rsp_free(rsp); + return NULL; +} + static const struct ynl_ntf_info netdev_ntf_info[] = { [NETDEV_CMD_DEV_ADD_NTF] = { .alloc_sz = sizeof(struct netdev_dev_get_ntf), diff --git a/tmp/ynl_build-tmp.pH6hSc/old-code/netdev-user.h b/tmp/ynl_build-tmp.pH6hSc/new-code/netdev-user.h index 71b96e7dbc0b..d2721d74a019 100644 --- a/tmp/ynl_build-tmp.pH6hSc/old-code/netdev-user.h +++ b/tmp/ynl_build-tmp.pH6hSc/new-code/netdev-user.h @@ -73,6 +73,18 @@ netdev_queue_id_set_type(struct netdev_queue_id *obj, obj->type = type; } +struct netdev_lease { + struct { + __u32 ifindex:1; + __u32 queue:1; + __u32 netns_id:1; + } _present; + + __u32 ifindex; + struct netdev_queue_id queue; + __s32 netns_id; +}; + /* ============== NETDEV_CMD_DEV_GET ============== */ /* NETDEV_CMD_DEV_GET - do */ struct netdev_dev_get_req { @@ -358,6 +370,7 @@ struct netdev_queue_get_rsp { __u32 dmabuf:1; __u32 io_uring:1; __u32 xsk:1; + __u32 lease:1; } _present; __u32 id; @@ -367,6 +380,7 @@ struct netdev_queue_get_rsp { __u32 dmabuf; struct netdev_io_uring_provider_info io_uring; struct netdev_xsk_info xsk; + struct netdev_lease lease; }; void netdev_queue_get_rsp_free(struct netdev_queue_get_rsp *rsp); @@ -782,4 +796,92 @@ void netdev_bind_tx_rsp_free(struct netdev_bind_tx_rsp *rsp); struct netdev_bind_tx_rsp * netdev_bind_tx(struct ynl_sock *ys, struct netdev_bind_tx_req *req); +/* ============== NETDEV_CMD_QUEUE_CREATE ============== */ +/* NETDEV_CMD_QUEUE_CREATE - do */ +struct netdev_queue_create_req { + struct { + __u32 ifindex:1; + __u32 type:1; + __u32 lease:1; + } _present; + + __u32 ifindex; + enum netdev_queue_type type; + struct netdev_lease lease; +}; + +static inline struct netdev_queue_create_req * +netdev_queue_create_req_alloc(void) +{ + return calloc(1, sizeof(struct netdev_queue_create_req)); +} +void netdev_queue_create_req_free(struct netdev_queue_create_req *req); + +static inline void +netdev_queue_create_req_set_ifindex(struct netdev_queue_create_req *req, + __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} +static inline void +netdev_queue_create_req_set_type(struct netdev_queue_create_req *req, + enum netdev_queue_type type) +{ + req->_present.type = 1; + req->type = type; +} +static inline void +netdev_queue_create_req_set_lease_ifindex(struct netdev_queue_create_req *req, + __u32 ifindex) +{ + req->_present.lease = 1; + req->lease._present.ifindex = 1; + req->lease.ifindex = ifindex; +} +static inline void +netdev_queue_create_req_set_lease_queue_id(struct netdev_queue_create_req *req, + __u32 id) +{ + req->_present.lease = 1; + req->lease._present.queue = 1; + req->lease.queue._present.id = 1; + req->lease.queue.id = id; +} +static inline void +netdev_queue_create_req_set_lease_queue_type(struct netdev_queue_create_req *req, + enum netdev_queue_type type) +{ + req->_present.lease = 1; + req->lease._present.queue = 1; + req->lease.queue._present.type = 1; + req->lease.queue.type = type; +} +static inline void +netdev_queue_create_req_set_lease_netns_id(struct netdev_queue_create_req *req, + __s32 netns_id) +{ + req->_present.lease = 1; + req->lease._present.netns_id = 1; + req->lease.netns_id = netns_id; +} + +struct netdev_queue_create_rsp { + struct { + __u32 id:1; + } _present; + + __u32 id; +}; + +void netdev_queue_create_rsp_free(struct netdev_queue_create_rsp *rsp); + +/* + * Create a new queue for the given netdevice. Whether this operation +is supported depends on the device and the driver. + + */ +struct netdev_queue_create_rsp * +netdev_queue_create(struct ynl_sock *ys, struct netdev_queue_create_req *req); + #endif /* _LINUX_NETDEV_GEN_H */