Commit ded5c1a1 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'tools-ynl-gen-code-gen-improvements-before-ethtool'

Jakub Kicinski says:

====================
tools: ynl-gen: code gen improvements before ethtool

I was going to post ethtool but I couldn't stand the ugliness
of the if conditions which were previously generated.
So I cleaned that up and improved a number of other things
ethtool will benefit from.
====================

Link: https://lore.kernel.org/r/20230608211200.1247213-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 7ec5d48f 76abff37
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
/* YNL-GEN user source */ /* YNL-GEN user source */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "devlink-user.h" #include "devlink-user.h"
#include "ynl.h" #include "ynl.h"
#include <linux/devlink.h> #include <linux/devlink.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libmnl/libmnl.h> #include <libmnl/libmnl.h>
#include <linux/genetlink.h> #include <linux/genetlink.h>
...@@ -128,7 +126,9 @@ int devlink_dl_info_version_parse(struct ynl_parse_arg *yarg, ...@@ -128,7 +126,9 @@ int devlink_dl_info_version_parse(struct ynl_parse_arg *yarg,
const struct nlattr *attr; const struct nlattr *attr;
mnl_attr_for_each_nested(attr, nested) { mnl_attr_for_each_nested(attr, nested) {
if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_NAME) { unsigned int type = mnl_attr_get_type(attr);
if (type == DEVLINK_ATTR_INFO_VERSION_NAME) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -139,8 +139,7 @@ int devlink_dl_info_version_parse(struct ynl_parse_arg *yarg, ...@@ -139,8 +139,7 @@ int devlink_dl_info_version_parse(struct ynl_parse_arg *yarg,
dst->info_version_name = malloc(len + 1); dst->info_version_name = malloc(len + 1);
memcpy(dst->info_version_name, mnl_attr_get_str(attr), len); memcpy(dst->info_version_name, mnl_attr_get_str(attr), len);
dst->info_version_name[len] = 0; dst->info_version_name[len] = 0;
} } else if (type == DEVLINK_ATTR_INFO_VERSION_VALUE) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_VALUE) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -169,13 +168,14 @@ int devlink_dl_reload_stats_entry_parse(struct ynl_parse_arg *yarg, ...@@ -169,13 +168,14 @@ int devlink_dl_reload_stats_entry_parse(struct ynl_parse_arg *yarg,
const struct nlattr *attr; const struct nlattr *attr;
mnl_attr_for_each_nested(attr, nested) { mnl_attr_for_each_nested(attr, nested) {
if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_STATS_LIMIT) { unsigned int type = mnl_attr_get_type(attr);
if (type == DEVLINK_ATTR_RELOAD_STATS_LIMIT) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.reload_stats_limit = 1; dst->_present.reload_stats_limit = 1;
dst->reload_stats_limit = mnl_attr_get_u8(attr); dst->reload_stats_limit = mnl_attr_get_u8(attr);
} } else if (type == DEVLINK_ATTR_RELOAD_STATS_VALUE) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_STATS_VALUE) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.reload_stats_value = 1; dst->_present.reload_stats_value = 1;
...@@ -210,7 +210,9 @@ int devlink_dl_reload_act_stats_parse(struct ynl_parse_arg *yarg, ...@@ -210,7 +210,9 @@ int devlink_dl_reload_act_stats_parse(struct ynl_parse_arg *yarg,
return ynl_error_parse(yarg, "attribute already present (dl-reload-act-stats.reload-stats-entry)"); return ynl_error_parse(yarg, "attribute already present (dl-reload-act-stats.reload-stats-entry)");
mnl_attr_for_each_nested(attr, nested) { mnl_attr_for_each_nested(attr, nested) {
if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_STATS_ENTRY) { unsigned int type = mnl_attr_get_type(attr);
if (type == DEVLINK_ATTR_RELOAD_STATS_ENTRY) {
n_reload_stats_entry++; n_reload_stats_entry++;
} }
} }
...@@ -257,13 +259,14 @@ int devlink_dl_reload_act_info_parse(struct ynl_parse_arg *yarg, ...@@ -257,13 +259,14 @@ int devlink_dl_reload_act_info_parse(struct ynl_parse_arg *yarg,
return ynl_error_parse(yarg, "attribute already present (dl-reload-act-info.reload-action-stats)"); return ynl_error_parse(yarg, "attribute already present (dl-reload-act-info.reload-action-stats)");
mnl_attr_for_each_nested(attr, nested) { mnl_attr_for_each_nested(attr, nested) {
if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION) { unsigned int type = mnl_attr_get_type(attr);
if (type == DEVLINK_ATTR_RELOAD_ACTION) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.reload_action = 1; dst->_present.reload_action = 1;
dst->reload_action = mnl_attr_get_u8(attr); dst->reload_action = mnl_attr_get_u8(attr);
} } else if (type == DEVLINK_ATTR_RELOAD_ACTION_STATS) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION_STATS) {
n_reload_action_stats++; n_reload_action_stats++;
} }
} }
...@@ -310,7 +313,9 @@ int devlink_dl_reload_stats_parse(struct ynl_parse_arg *yarg, ...@@ -310,7 +313,9 @@ int devlink_dl_reload_stats_parse(struct ynl_parse_arg *yarg,
return ynl_error_parse(yarg, "attribute already present (dl-reload-stats.reload-action-info)"); return ynl_error_parse(yarg, "attribute already present (dl-reload-stats.reload-action-info)");
mnl_attr_for_each_nested(attr, nested) { mnl_attr_for_each_nested(attr, nested) {
if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION_INFO) { unsigned int type = mnl_attr_get_type(attr);
if (type == DEVLINK_ATTR_RELOAD_ACTION_INFO) {
n_reload_action_info++; n_reload_action_info++;
} }
} }
...@@ -349,7 +354,9 @@ int devlink_dl_dev_stats_parse(struct ynl_parse_arg *yarg, ...@@ -349,7 +354,9 @@ int devlink_dl_dev_stats_parse(struct ynl_parse_arg *yarg,
parg.ys = yarg->ys; parg.ys = yarg->ys;
mnl_attr_for_each_nested(attr, nested) { mnl_attr_for_each_nested(attr, nested) {
if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_STATS) { unsigned int type = mnl_attr_get_type(attr);
if (type == DEVLINK_ATTR_RELOAD_STATS) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.reload_stats = 1; dst->_present.reload_stats = 1;
...@@ -358,8 +365,7 @@ int devlink_dl_dev_stats_parse(struct ynl_parse_arg *yarg, ...@@ -358,8 +365,7 @@ int devlink_dl_dev_stats_parse(struct ynl_parse_arg *yarg,
parg.data = &dst->reload_stats; parg.data = &dst->reload_stats;
if (devlink_dl_reload_stats_parse(&parg, attr)) if (devlink_dl_reload_stats_parse(&parg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
} } else if (type == DEVLINK_ATTR_REMOTE_RELOAD_STATS) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_REMOTE_RELOAD_STATS) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.remote_reload_stats = 1; dst->_present.remote_reload_stats = 1;
...@@ -402,7 +408,9 @@ int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -402,7 +408,9 @@ int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
parg.ys = yarg->ys; parg.ys = yarg->ys;
mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
if (mnl_attr_get_type(attr) == DEVLINK_ATTR_BUS_NAME) { unsigned int type = mnl_attr_get_type(attr);
if (type == DEVLINK_ATTR_BUS_NAME) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -413,8 +421,7 @@ int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -413,8 +421,7 @@ int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst->bus_name = malloc(len + 1); dst->bus_name = malloc(len + 1);
memcpy(dst->bus_name, mnl_attr_get_str(attr), len); memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
dst->bus_name[len] = 0; dst->bus_name[len] = 0;
} } else if (type == DEVLINK_ATTR_DEV_NAME) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DEV_NAME) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -425,20 +432,17 @@ int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -425,20 +432,17 @@ int devlink_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst->dev_name = malloc(len + 1); dst->dev_name = malloc(len + 1);
memcpy(dst->dev_name, mnl_attr_get_str(attr), len); memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
dst->dev_name[len] = 0; dst->dev_name[len] = 0;
} } else if (type == DEVLINK_ATTR_RELOAD_FAILED) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_FAILED) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.reload_failed = 1; dst->_present.reload_failed = 1;
dst->reload_failed = mnl_attr_get_u8(attr); dst->reload_failed = mnl_attr_get_u8(attr);
} } else if (type == DEVLINK_ATTR_RELOAD_ACTION) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_RELOAD_ACTION) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.reload_action = 1; dst->_present.reload_action = 1;
dst->reload_action = mnl_attr_get_u8(attr); dst->reload_action = mnl_attr_get_u8(attr);
} } else if (type == DEVLINK_ATTR_DEV_STATS) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DEV_STATS) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.dev_stats = 1; dst->_present.dev_stats = 1;
...@@ -578,7 +582,9 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -578,7 +582,9 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
return ynl_error_parse(yarg, "attribute already present (devlink.info-version-stored)"); return ynl_error_parse(yarg, "attribute already present (devlink.info-version-stored)");
mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
if (mnl_attr_get_type(attr) == DEVLINK_ATTR_BUS_NAME) { unsigned int type = mnl_attr_get_type(attr);
if (type == DEVLINK_ATTR_BUS_NAME) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -589,8 +595,7 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -589,8 +595,7 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst->bus_name = malloc(len + 1); dst->bus_name = malloc(len + 1);
memcpy(dst->bus_name, mnl_attr_get_str(attr), len); memcpy(dst->bus_name, mnl_attr_get_str(attr), len);
dst->bus_name[len] = 0; dst->bus_name[len] = 0;
} } else if (type == DEVLINK_ATTR_DEV_NAME) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_DEV_NAME) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -601,8 +606,7 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -601,8 +606,7 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst->dev_name = malloc(len + 1); dst->dev_name = malloc(len + 1);
memcpy(dst->dev_name, mnl_attr_get_str(attr), len); memcpy(dst->dev_name, mnl_attr_get_str(attr), len);
dst->dev_name[len] = 0; dst->dev_name[len] = 0;
} } else if (type == DEVLINK_ATTR_INFO_DRIVER_NAME) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_DRIVER_NAME) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -613,8 +617,7 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -613,8 +617,7 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst->info_driver_name = malloc(len + 1); dst->info_driver_name = malloc(len + 1);
memcpy(dst->info_driver_name, mnl_attr_get_str(attr), len); memcpy(dst->info_driver_name, mnl_attr_get_str(attr), len);
dst->info_driver_name[len] = 0; dst->info_driver_name[len] = 0;
} } else if (type == DEVLINK_ATTR_INFO_SERIAL_NUMBER) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_SERIAL_NUMBER) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -625,14 +628,11 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -625,14 +628,11 @@ int devlink_info_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst->info_serial_number = malloc(len + 1); dst->info_serial_number = malloc(len + 1);
memcpy(dst->info_serial_number, mnl_attr_get_str(attr), len); memcpy(dst->info_serial_number, mnl_attr_get_str(attr), len);
dst->info_serial_number[len] = 0; dst->info_serial_number[len] = 0;
} } else if (type == DEVLINK_ATTR_INFO_VERSION_FIXED) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_FIXED) {
n_info_version_fixed++; n_info_version_fixed++;
} } else if (type == DEVLINK_ATTR_INFO_VERSION_RUNNING) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_RUNNING) {
n_info_version_running++; n_info_version_running++;
} } else if (type == DEVLINK_ATTR_INFO_VERSION_STORED) {
else if (mnl_attr_get_type(attr) == DEVLINK_ATTR_INFO_VERSION_STORED) {
n_info_version_stored++; n_info_version_stored++;
} }
} }
......
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
/* YNL-GEN user source */ /* YNL-GEN user source */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "fou-user.h" #include "fou-user.h"
#include "ynl.h" #include "ynl.h"
#include <linux/fou.h> #include <linux/fou.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libmnl/libmnl.h> #include <libmnl/libmnl.h>
#include <linux/genetlink.h> #include <linux/genetlink.h>
...@@ -174,42 +172,38 @@ int fou_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -174,42 +172,38 @@ int fou_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst = yarg->data; dst = yarg->data;
mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
if (mnl_attr_get_type(attr) == FOU_ATTR_PORT) { unsigned int type = mnl_attr_get_type(attr);
if (type == FOU_ATTR_PORT) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.port = 1; dst->_present.port = 1;
dst->port = mnl_attr_get_u16(attr); dst->port = mnl_attr_get_u16(attr);
} } else if (type == FOU_ATTR_IPPROTO) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_IPPROTO) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.ipproto = 1; dst->_present.ipproto = 1;
dst->ipproto = mnl_attr_get_u8(attr); dst->ipproto = mnl_attr_get_u8(attr);
} } else if (type == FOU_ATTR_TYPE) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_TYPE) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.type = 1; dst->_present.type = 1;
dst->type = mnl_attr_get_u8(attr); dst->type = mnl_attr_get_u8(attr);
} } else if (type == FOU_ATTR_REMCSUM_NOPARTIAL) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_REMCSUM_NOPARTIAL) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.remcsum_nopartial = 1; dst->_present.remcsum_nopartial = 1;
} } else if (type == FOU_ATTR_LOCAL_V4) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_LOCAL_V4) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.local_v4 = 1; dst->_present.local_v4 = 1;
dst->local_v4 = mnl_attr_get_u32(attr); dst->local_v4 = mnl_attr_get_u32(attr);
} } else if (type == FOU_ATTR_PEER_V4) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_PEER_V4) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.peer_v4 = 1; dst->_present.peer_v4 = 1;
dst->peer_v4 = mnl_attr_get_u32(attr); dst->peer_v4 = mnl_attr_get_u32(attr);
} } else if (type == FOU_ATTR_LOCAL_V6) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_LOCAL_V6) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -219,8 +213,7 @@ int fou_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -219,8 +213,7 @@ int fou_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst->_present.local_v6_len = len; dst->_present.local_v6_len = len;
dst->local_v6 = malloc(len); dst->local_v6 = malloc(len);
memcpy(dst->local_v6, mnl_attr_get_payload(attr), len); memcpy(dst->local_v6, mnl_attr_get_payload(attr), len);
} } else if (type == FOU_ATTR_PEER_V6) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_PEER_V6) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -230,14 +223,12 @@ int fou_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -230,14 +223,12 @@ int fou_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst->_present.peer_v6_len = len; dst->_present.peer_v6_len = len;
dst->peer_v6 = malloc(len); dst->peer_v6 = malloc(len);
memcpy(dst->peer_v6, mnl_attr_get_payload(attr), len); memcpy(dst->peer_v6, mnl_attr_get_payload(attr), len);
} } else if (type == FOU_ATTR_PEER_PORT) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_PEER_PORT) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.peer_port = 1; dst->_present.peer_port = 1;
dst->peer_port = mnl_attr_get_u16(attr); dst->peer_port = mnl_attr_get_u16(attr);
} } else if (type == FOU_ATTR_IFINDEX) {
else if (mnl_attr_get_type(attr) == FOU_ATTR_IFINDEX) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.ifindex = 1; dst->_present.ifindex = 1;
......
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
/* YNL-GEN user source */ /* YNL-GEN user source */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "handshake-user.h" #include "handshake-user.h"
#include "ynl.h" #include "ynl.h"
#include <linux/handshake.h> #include <linux/handshake.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libmnl/libmnl.h> #include <libmnl/libmnl.h>
#include <linux/genetlink.h> #include <linux/genetlink.h>
...@@ -118,13 +116,14 @@ int handshake_x509_parse(struct ynl_parse_arg *yarg, ...@@ -118,13 +116,14 @@ int handshake_x509_parse(struct ynl_parse_arg *yarg,
const struct nlattr *attr; const struct nlattr *attr;
mnl_attr_for_each_nested(attr, nested) { mnl_attr_for_each_nested(attr, nested) {
if (mnl_attr_get_type(attr) == HANDSHAKE_A_X509_CERT) { unsigned int type = mnl_attr_get_type(attr);
if (type == HANDSHAKE_A_X509_CERT) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.cert = 1; dst->_present.cert = 1;
dst->cert = mnl_attr_get_u32(attr); dst->cert = mnl_attr_get_u32(attr);
} } else if (type == HANDSHAKE_A_X509_PRIVKEY) {
else if (mnl_attr_get_type(attr) == HANDSHAKE_A_X509_PRIVKEY) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.privkey = 1; dst->_present.privkey = 1;
...@@ -173,37 +172,33 @@ int handshake_accept_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -173,37 +172,33 @@ int handshake_accept_rsp_parse(const struct nlmsghdr *nlh, void *data)
return ynl_error_parse(yarg, "attribute already present (accept.peer-identity)"); return ynl_error_parse(yarg, "attribute already present (accept.peer-identity)");
mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
if (mnl_attr_get_type(attr) == HANDSHAKE_A_ACCEPT_SOCKFD) { unsigned int type = mnl_attr_get_type(attr);
if (type == HANDSHAKE_A_ACCEPT_SOCKFD) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.sockfd = 1; dst->_present.sockfd = 1;
dst->sockfd = mnl_attr_get_u32(attr); dst->sockfd = mnl_attr_get_u32(attr);
} } else if (type == HANDSHAKE_A_ACCEPT_MESSAGE_TYPE) {
else if (mnl_attr_get_type(attr) == HANDSHAKE_A_ACCEPT_MESSAGE_TYPE) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.message_type = 1; dst->_present.message_type = 1;
dst->message_type = mnl_attr_get_u32(attr); dst->message_type = mnl_attr_get_u32(attr);
} } else if (type == HANDSHAKE_A_ACCEPT_TIMEOUT) {
else if (mnl_attr_get_type(attr) == HANDSHAKE_A_ACCEPT_TIMEOUT) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.timeout = 1; dst->_present.timeout = 1;
dst->timeout = mnl_attr_get_u32(attr); dst->timeout = mnl_attr_get_u32(attr);
} } else if (type == HANDSHAKE_A_ACCEPT_AUTH_MODE) {
else if (mnl_attr_get_type(attr) == HANDSHAKE_A_ACCEPT_AUTH_MODE) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.auth_mode = 1; dst->_present.auth_mode = 1;
dst->auth_mode = mnl_attr_get_u32(attr); dst->auth_mode = mnl_attr_get_u32(attr);
} } else if (type == HANDSHAKE_A_ACCEPT_PEER_IDENTITY) {
else if (mnl_attr_get_type(attr) == HANDSHAKE_A_ACCEPT_PEER_IDENTITY) {
n_peer_identity++; n_peer_identity++;
} } else if (type == HANDSHAKE_A_ACCEPT_CERTIFICATE) {
else if (mnl_attr_get_type(attr) == HANDSHAKE_A_ACCEPT_CERTIFICATE) {
n_certificate++; n_certificate++;
} } else if (type == HANDSHAKE_A_ACCEPT_PEERNAME) {
else if (mnl_attr_get_type(attr) == HANDSHAKE_A_ACCEPT_PEERNAME) {
unsigned int len; unsigned int len;
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
...@@ -320,51 +315,6 @@ int handshake_done(struct ynl_sock *ys, struct handshake_done_req *req) ...@@ -320,51 +315,6 @@ int handshake_done(struct ynl_sock *ys, struct handshake_done_req *req)
return 0; return 0;
} }
/* --------------- Common notification parsing --------------- */
struct ynl_ntf_base_type *handshake_ntf_parse(struct ynl_sock *ys)
{
struct ynl_parse_arg yarg = { .ys = ys, };
struct ynl_ntf_base_type *rsp;
struct genlmsghdr *genlh;
struct nlmsghdr *nlh;
mnl_cb_t parse;
int len, err;
len = mnl_socket_recvfrom(ys->sock, ys->rx_buf, MNL_SOCKET_BUFFER_SIZE);
if (len < (ssize_t)(sizeof(*nlh) + sizeof(*genlh)))
return NULL;
nlh = (struct nlmsghdr *)ys->rx_buf;
genlh = mnl_nlmsg_get_payload(nlh);
switch (genlh->cmd) {
case HANDSHAKE_CMD_READY:
rsp = calloc(1, sizeof(struct handshake_accept_ntf));
parse = handshake_accept_rsp_parse;
yarg.rsp_policy = &handshake_accept_nest;
rsp->free = (void *)handshake_accept_ntf_free;
break;
default:
ynl_error_unknown_notification(ys, genlh->cmd);
return NULL;
}
yarg.data = rsp->data;
err = mnl_cb_run2(ys->rx_buf, len, 0, 0, parse, &yarg,
ynl_cb_array, NLMSG_MIN_TYPE);
if (err < 0)
goto err_free;
rsp->family = nlh->nlmsg_type;
rsp->cmd = genlh->cmd;
return rsp;
err_free:
free(rsp);
return NULL;
}
static const struct ynl_ntf_info handshake_ntf_info[] = { static const struct ynl_ntf_info handshake_ntf_info[] = {
[HANDSHAKE_CMD_READY] = { [HANDSHAKE_CMD_READY] = {
.alloc_sz = sizeof(struct handshake_accept_ntf), .alloc_sz = sizeof(struct handshake_accept_ntf),
......
...@@ -142,7 +142,4 @@ __handshake_done_req_set_remote_auth(struct handshake_done_req *req, ...@@ -142,7 +142,4 @@ __handshake_done_req_set_remote_auth(struct handshake_done_req *req,
*/ */
int handshake_done(struct ynl_sock *ys, struct handshake_done_req *req); int handshake_done(struct ynl_sock *ys, struct handshake_done_req *req);
/* --------------- Common notification parsing --------------- */
struct ynl_ntf_base_type *handshake_ntf_parse(struct ynl_sock *ys);
#endif /* _LINUX_HANDSHAKE_GEN_H */ #endif /* _LINUX_HANDSHAKE_GEN_H */
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
/* YNL-GEN user source */ /* YNL-GEN user source */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "netdev-user.h" #include "netdev-user.h"
#include "ynl.h" #include "ynl.h"
#include <linux/netdev.h> #include <linux/netdev.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libmnl/libmnl.h> #include <libmnl/libmnl.h>
#include <linux/genetlink.h> #include <linux/genetlink.h>
...@@ -81,13 +79,14 @@ int netdev_dev_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -81,13 +79,14 @@ int netdev_dev_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
dst = yarg->data; dst = yarg->data;
mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) {
if (mnl_attr_get_type(attr) == NETDEV_A_DEV_IFINDEX) { unsigned int type = mnl_attr_get_type(attr);
if (type == NETDEV_A_DEV_IFINDEX) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.ifindex = 1; dst->_present.ifindex = 1;
dst->ifindex = mnl_attr_get_u32(attr); dst->ifindex = mnl_attr_get_u32(attr);
} } else if (type == NETDEV_A_DEV_XDP_FEATURES) {
else if (mnl_attr_get_type(attr) == NETDEV_A_DEV_XDP_FEATURES) {
if (ynl_attr_validate(yarg, attr)) if (ynl_attr_validate(yarg, attr))
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.xdp_features = 1; dst->_present.xdp_features = 1;
...@@ -173,53 +172,6 @@ void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp) ...@@ -173,53 +172,6 @@ void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp)
free(rsp); free(rsp);
} }
/* --------------- Common notification parsing --------------- */
struct ynl_ntf_base_type *netdev_ntf_parse(struct ynl_sock *ys)
{
struct ynl_parse_arg yarg = { .ys = ys, };
struct ynl_ntf_base_type *rsp;
struct genlmsghdr *genlh;
struct nlmsghdr *nlh;
mnl_cb_t parse;
int len, err;
len = mnl_socket_recvfrom(ys->sock, ys->rx_buf, MNL_SOCKET_BUFFER_SIZE);
if (len < (ssize_t)(sizeof(*nlh) + sizeof(*genlh)))
return NULL;
nlh = (struct nlmsghdr *)ys->rx_buf;
genlh = mnl_nlmsg_get_payload(nlh);
switch (genlh->cmd) {
case NETDEV_CMD_DEV_ADD_NTF:
case NETDEV_CMD_DEV_DEL_NTF:
case NETDEV_CMD_DEV_CHANGE_NTF:
rsp = calloc(1, sizeof(struct netdev_dev_get_ntf));
parse = netdev_dev_get_rsp_parse;
yarg.rsp_policy = &netdev_dev_nest;
rsp->free = (void *)netdev_dev_get_ntf_free;
break;
default:
ynl_error_unknown_notification(ys, genlh->cmd);
return NULL;
}
yarg.data = rsp->data;
err = mnl_cb_run2(ys->rx_buf, len, 0, 0, parse, &yarg,
ynl_cb_array, NLMSG_MIN_TYPE);
if (err < 0)
goto err_free;
rsp->family = nlh->nlmsg_type;
rsp->cmd = genlh->cmd;
return rsp;
err_free:
free(rsp);
return NULL;
}
static const struct ynl_ntf_info netdev_ntf_info[] = { static const struct ynl_ntf_info netdev_ntf_info[] = {
[NETDEV_CMD_DEV_ADD_NTF] = { [NETDEV_CMD_DEV_ADD_NTF] = {
.alloc_sz = sizeof(struct netdev_dev_get_ntf), .alloc_sz = sizeof(struct netdev_dev_get_ntf),
......
...@@ -82,7 +82,4 @@ struct netdev_dev_get_ntf { ...@@ -82,7 +82,4 @@ struct netdev_dev_get_ntf {
void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp); void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp);
/* --------------- Common notification parsing --------------- */
struct ynl_ntf_base_type *netdev_ntf_parse(struct ynl_sock *ys);
#endif /* _LINUX_NETDEV_GEN_H */ #endif /* _LINUX_NETDEV_GEN_H */
...@@ -329,8 +329,8 @@ class SpecFamily(SpecElement): ...@@ -329,8 +329,8 @@ class SpecFamily(SpecElement):
attr_sets dict of attribute sets attr_sets dict of attribute sets
msgs dict of all messages (index by name) msgs dict of all messages (index by name)
msgs_by_value dict of all messages (indexed by name)
ops dict of all valid requests / responses ops dict of all valid requests / responses
ntfs dict of all async events
consts dict of all constants/enums consts dict of all constants/enums
fixed_header string, optional name of family default fixed header struct fixed_header string, optional name of family default fixed header struct
""" """
...@@ -370,6 +370,7 @@ class SpecFamily(SpecElement): ...@@ -370,6 +370,7 @@ class SpecFamily(SpecElement):
self.req_by_value = collections.OrderedDict() self.req_by_value = collections.OrderedDict()
self.rsp_by_value = collections.OrderedDict() self.rsp_by_value = collections.OrderedDict()
self.ops = collections.OrderedDict() self.ops = collections.OrderedDict()
self.ntfs = collections.OrderedDict()
self.consts = collections.OrderedDict() self.consts = collections.OrderedDict()
last_exception = None last_exception = None
...@@ -422,7 +423,7 @@ class SpecFamily(SpecElement): ...@@ -422,7 +423,7 @@ class SpecFamily(SpecElement):
self.fixed_header = self.yaml['operations'].get('fixed-header') self.fixed_header = self.yaml['operations'].get('fixed-header')
req_val = rsp_val = 1 req_val = rsp_val = 1
for elem in self.yaml['operations']['list']: for elem in self.yaml['operations']['list']:
if 'notify' in elem: if 'notify' in elem or 'event' in elem:
if 'value' in elem: if 'value' in elem:
rsp_val = elem['value'] rsp_val = elem['value']
req_val_next = req_val req_val_next = req_val
...@@ -491,3 +492,5 @@ class SpecFamily(SpecElement): ...@@ -491,3 +492,5 @@ class SpecFamily(SpecElement):
self.rsp_by_value[op.rsp_value] = op self.rsp_by_value[op.rsp_value] = op
if not op.is_async and 'attribute-set' in op: if not op.is_async and 'attribute-set' in op:
self.ops[op.name] = op self.ops[op.name] = op
elif op.is_async:
self.ntfs[op.name] = op
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment