diff --git a/home/nipa/nipa_out/1014679/ynl/old-code/psp-user.c b/home/nipa/nipa_out/1014679/ynl/new-code/psp-user.c index f17bf7b75816..4b488bc0e83d 100644 --- a/home/nipa/nipa_out/1014679/ynl/old-code/psp-user.c +++ b/home/nipa/nipa_out/1014679/ynl/new-code/psp-user.c @@ -22,6 +22,7 @@ static const char * const psp_op_strmap[] = { [PSP_CMD_KEY_ROTATE_NTF] = "key-rotate-ntf", [PSP_CMD_RX_ASSOC] = "rx-assoc", [PSP_CMD_TX_ASSOC] = "tx-assoc", + [PSP_CMD_GET_STATS] = "get-stats", }; const char *psp_op_str(int op) @@ -81,6 +82,25 @@ const struct ynl_policy_nest psp_assoc_nest = { .table = psp_assoc_policy, }; +const struct ynl_policy_attr psp_stats_policy[PSP_A_STATS_MAX + 1] = { + [PSP_A_STATS_DEV_ID] = { .name = "dev-id", .type = YNL_PT_U32, }, + [PSP_A_STATS_KEY_ROTATIONS] = { .name = "key-rotations", .type = YNL_PT_UINT, }, + [PSP_A_STATS_STALE_EVENTS] = { .name = "stale-events", .type = YNL_PT_UINT, }, + [PSP_A_STATS_RX_PACKETS] = { .name = "rx-packets", .type = YNL_PT_UINT, }, + [PSP_A_STATS_RX_BYTES] = { .name = "rx-bytes", .type = YNL_PT_UINT, }, + [PSP_A_STATS_RX_AUTH_FAIL] = { .name = "rx-auth-fail", .type = YNL_PT_UINT, }, + [PSP_A_STATS_RX_ERROR] = { .name = "rx-error", .type = YNL_PT_UINT, }, + [PSP_A_STATS_RX_BAD] = { .name = "rx-bad", .type = YNL_PT_UINT, }, + [PSP_A_STATS_TX_PACKETS] = { .name = "tx-packets", .type = YNL_PT_UINT, }, + [PSP_A_STATS_TX_BYTES] = { .name = "tx-bytes", .type = YNL_PT_UINT, }, + [PSP_A_STATS_TX_ERROR] = { .name = "tx-error", .type = YNL_PT_UINT, }, +}; + +const struct ynl_policy_nest psp_stats_nest = { + .max_attr = PSP_A_STATS_MAX, + .table = psp_stats_policy, +}; + /* Common nested types */ void psp_keys_free(struct psp_keys *obj) { @@ -519,6 +539,121 @@ psp_tx_assoc(struct ynl_sock *ys, struct psp_tx_assoc_req *req) return NULL; } +/* ============== PSP_CMD_GET_STATS ============== */ +/* PSP_CMD_GET_STATS - do */ +void psp_get_stats_req_free(struct psp_get_stats_req *req) +{ + free(req); +} + +void psp_get_stats_rsp_free(struct psp_get_stats_rsp *rsp) +{ + free(rsp); +} + +int psp_get_stats_rsp_parse(const struct nlmsghdr *nlh, + struct ynl_parse_arg *yarg) +{ + struct psp_get_stats_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 == PSP_A_STATS_DEV_ID) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.dev_id = 1; + dst->dev_id = ynl_attr_get_u32(attr); + } else if (type == PSP_A_STATS_KEY_ROTATIONS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.key_rotations = 1; + dst->key_rotations = ynl_attr_get_uint(attr); + } else if (type == PSP_A_STATS_STALE_EVENTS) { + if (ynl_attr_validate(yarg, attr)) + return YNL_PARSE_CB_ERROR; + dst->_present.stale_events = 1; + dst->stale_events = ynl_attr_get_uint(attr); + } + } + + return YNL_PARSE_CB_OK; +} + +struct psp_get_stats_rsp * +psp_get_stats(struct ynl_sock *ys, struct psp_get_stats_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct psp_get_stats_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, PSP_CMD_GET_STATS, 1); + ys->req_policy = &psp_stats_nest; + ys->req_hdr_len = ys->family->hdr_len; + yrs.yarg.rsp_policy = &psp_stats_nest; + + if (req->_present.dev_id) + ynl_attr_put_u32(nlh, PSP_A_STATS_DEV_ID, req->dev_id); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = psp_get_stats_rsp_parse; + yrs.rsp_cmd = PSP_CMD_GET_STATS; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + psp_get_stats_rsp_free(rsp); + return NULL; +} + +/* PSP_CMD_GET_STATS - dump */ +void psp_get_stats_list_free(struct psp_get_stats_list *rsp) +{ + struct psp_get_stats_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + rsp = next; + next = rsp->next; + + free(rsp); + } +} + +struct psp_get_stats_list *psp_get_stats_dump(struct ynl_sock *ys) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.yarg.ys = ys; + yds.yarg.rsp_policy = &psp_stats_nest; + yds.yarg.data = NULL; + yds.alloc_sz = sizeof(struct psp_get_stats_list); + yds.cb = psp_get_stats_rsp_parse; + yds.rsp_cmd = PSP_CMD_GET_STATS; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, PSP_CMD_GET_STATS, 1); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + psp_get_stats_list_free(yds.first); + return NULL; +} + static const struct ynl_ntf_info psp_ntf_info[] = { [PSP_CMD_DEV_ADD_NTF] = { .alloc_sz = sizeof(struct psp_dev_get_ntf), diff --git a/home/nipa/nipa_out/1014679/ynl/old-code/psp-user.h b/home/nipa/nipa_out/1014679/ynl/new-code/psp-user.h index f5914db2da96..cfad820cb615 100644 --- a/home/nipa/nipa_out/1014679/ynl/old-code/psp-user.h +++ b/home/nipa/nipa_out/1014679/ynl/new-code/psp-user.h @@ -319,4 +319,57 @@ void psp_tx_assoc_rsp_free(struct psp_tx_assoc_rsp *rsp); struct psp_tx_assoc_rsp * psp_tx_assoc(struct ynl_sock *ys, struct psp_tx_assoc_req *req); +/* ============== PSP_CMD_GET_STATS ============== */ +/* PSP_CMD_GET_STATS - do */ +struct psp_get_stats_req { + struct { + __u32 dev_id:1; + } _present; + + __u32 dev_id; +}; + +static inline struct psp_get_stats_req *psp_get_stats_req_alloc(void) +{ + return calloc(1, sizeof(struct psp_get_stats_req)); +} +void psp_get_stats_req_free(struct psp_get_stats_req *req); + +static inline void +psp_get_stats_req_set_dev_id(struct psp_get_stats_req *req, __u32 dev_id) +{ + req->_present.dev_id = 1; + req->dev_id = dev_id; +} + +struct psp_get_stats_rsp { + struct { + __u32 dev_id:1; + __u32 key_rotations:1; + __u32 stale_events:1; + } _present; + + __u32 dev_id; + __u64 key_rotations; + __u64 stale_events; +}; + +void psp_get_stats_rsp_free(struct psp_get_stats_rsp *rsp); + +/* + * Get device statistics. + */ +struct psp_get_stats_rsp * +psp_get_stats(struct ynl_sock *ys, struct psp_get_stats_req *req); + +/* PSP_CMD_GET_STATS - dump */ +struct psp_get_stats_list { + struct psp_get_stats_list *next; + struct psp_get_stats_rsp obj __attribute__((aligned(8))); +}; + +void psp_get_stats_list_free(struct psp_get_stats_list *rsp); + +struct psp_get_stats_list *psp_get_stats_dump(struct ynl_sock *ys); + #endif /* _LINUX_PSP_GEN_H */