@@ -116,7 +116,12 @@ static int lustre_device_list_start(struct netlink_callback *cb)
struct nlattr *dev;
int rem;
- nla_for_each_attr(dev, params, msg_len, rem) {
+ if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
+ NL_SET_ERR_MSG(extack, "no configuration");
+ goto report_err;
+ }
+
+ nla_for_each_nested(dev, params, rem) {
struct nlattr *prop;
int rem2;
@@ -4695,7 +4695,12 @@ static int lnet_net_show_start(struct netlink_callback *cb)
return 0;
params = genlmsg_data(gnlh);
- nla_for_each_attr(top, params, msg_len, rem) {
+ if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
+ NL_SET_ERR_MSG(extack, "invalid configuration");
+ return -EINVAL;
+ }
+
+ nla_for_each_nested(top, params, rem) {
struct nlattr *net;
int rem2;
@@ -4703,7 +4708,7 @@ static int lnet_net_show_start(struct netlink_callback *cb)
char filter[LNET_NIDSTR_SIZE];
if (nla_type(net) != LN_SCALAR_ATTR_VALUE ||
- nla_strcmp(net, "name") != 0)
+ nla_strcmp(net, "net type") != 0)
continue;
net = nla_next(net, &rem2);
@@ -4931,12 +4936,21 @@ static int lnet_genl_parse_lnd_tunables(struct nlattr *settings,
static int
lnet_genl_parse_local_ni(struct nlattr *entry, struct genl_info *info,
int net_id, struct lnet_ioctl_config_ni *conf,
- struct lnet_ioctl_config_lnd_tunables *tun,
bool *ni_list)
{
+ bool create = info->nlhdr->nlmsg_flags & NLM_F_CREATE;
+ struct lnet_ioctl_config_lnd_tunables tun;
struct nlattr *settings;
int rem3, rc = 0;
+ memset(&tun, 0, sizeof(tun));
+ /* Use LND defaults */
+ tun.lt_cmn.lct_peer_timeout = -1;
+ tun.lt_cmn.lct_peer_tx_credits = -1;
+ tun.lt_cmn.lct_peer_rtr_credits = -1;
+ tun.lt_cmn.lct_max_tx_credits = -1;
+ conf->lic_ncpts = 0;
+
nla_for_each_nested(settings, entry, rem3) {
if (nla_type(settings) != LN_SCALAR_ATTR_VALUE)
continue;
@@ -4983,7 +4997,7 @@ static int lnet_genl_parse_lnd_tunables(struct nlattr *settings,
goto out;
}
- rc = lnet_genl_parse_tunables(settings, tun);
+ rc = lnet_genl_parse_tunables(settings, &tun);
if (rc < 0) {
GENL_SET_ERR_MSG(info,
"failed to parse tunables");
@@ -5010,7 +5024,7 @@ static int lnet_genl_parse_lnd_tunables(struct nlattr *settings,
}
rc = lnet_genl_parse_lnd_tunables(settings,
- &tun->lt_tun, lnd);
+ &tun.lt_tun, lnd);
if (rc < 0) {
GENL_SET_ERR_MSG(info,
"failed to parse lnd tunables");
@@ -5052,6 +5066,73 @@ static int lnet_genl_parse_lnd_tunables(struct nlattr *settings,
}
}
}
+
+ if (!create) {
+ struct lnet_net *net;
+ struct lnet_ni *ni;
+
+ rc = -ENODEV;
+ if (!strlen(conf->lic_ni_intf)) {
+ GENL_SET_ERR_MSG(info,
+ "interface is missing");
+ goto out;
+ }
+
+ lnet_net_lock(LNET_LOCK_EX);
+ net = lnet_get_net_locked(net_id);
+ if (!net) {
+ GENL_SET_ERR_MSG(info,
+ "LNet net doesn't exist");
+ lnet_net_unlock(LNET_LOCK_EX);
+ goto out;
+ }
+
+ list_for_each_entry(ni, &net->net_ni_list,
+ ni_netlist) {
+ if (!ni->ni_interface ||
+ strcmp(ni->ni_interface,
+ conf->lic_ni_intf) != 0)
+ continue;
+
+ lnet_net_unlock(LNET_LOCK_EX);
+ rc = lnet_dyn_del_ni(&ni->ni_nid);
+ if (rc < 0) {
+ GENL_SET_ERR_MSG(info,
+ "cannot del LNet NI");
+ goto out;
+ }
+ break;
+ }
+
+ if (rc < 0) { /* will be -ENODEV */
+ GENL_SET_ERR_MSG(info,
+ "interface invalid for deleting LNet NI");
+ lnet_net_unlock(LNET_LOCK_EX);
+ }
+ } else {
+ if (!strlen(conf->lic_ni_intf)) {
+ GENL_SET_ERR_MSG(info,
+ "interface is missing");
+ goto out;
+ }
+
+ rc = lnet_dyn_add_ni(conf, net_id, &tun);
+ switch (rc) {
+ case -ENOENT:
+ GENL_SET_ERR_MSG(info,
+ "cannot parse net");
+ break;
+ case -ERANGE:
+ GENL_SET_ERR_MSG(info,
+ "invalid CPT set");
+ break;
+ default:
+ GENL_SET_ERR_MSG(info,
+ "cannot add LNet NI");
+ case 0:
+ break;
+ }
+ }
out:
return rc;
}
@@ -5070,7 +5151,12 @@ static int lnet_net_cmd(struct sk_buff *skb, struct genl_info *info)
return -ENOMSG;
}
- nla_for_each_attr(attr, params, msg_len, rem) {
+ if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
+ GENL_SET_ERR_MSG(info, "invalid configuration");
+ return -EINVAL;
+ }
+
+ nla_for_each_nested(attr, params, rem) {
struct lnet_ioctl_config_ni conf;
u32 net_id = LNET_NET_ANY;
struct nlattr *entry;
@@ -5149,85 +5235,13 @@ static int lnet_net_cmd(struct sk_buff *skb, struct genl_info *info)
break;
}
case LN_SCALAR_ATTR_LIST: {
- bool create = info->nlhdr->nlmsg_flags &
- NLM_F_CREATE;
- struct lnet_ioctl_config_lnd_tunables tun;
-
- memset(&tun, 0, sizeof(tun));
- /* Use LND defaults */
- tun.lt_cmn.lct_peer_timeout = -1;
- tun.lt_cmn.lct_peer_tx_credits = -1;
- tun.lt_cmn.lct_peer_rtr_credits = -1;
- tun.lt_cmn.lct_max_tx_credits = -1;
- conf.lic_ncpts = 0;
-
- rc = lnet_genl_parse_local_ni(entry, info,
- net_id, &conf,
- &tun, &ni_list);
- if (rc < 0)
- goto out;
+ struct nlattr *interface;
+ int rem3;
- if (!create) {
- struct lnet_net *net;
- struct lnet_ni *ni;
-
- rc = -ENODEV;
- if (!strlen(conf.lic_ni_intf)) {
- GENL_SET_ERR_MSG(info,
- "interface is missing");
- goto out;
- }
-
- lnet_net_lock(LNET_LOCK_EX);
- net = lnet_get_net_locked(net_id);
- if (!net) {
- GENL_SET_ERR_MSG(info,
- "LNet net doesn't exist");
- lnet_net_unlock(LNET_LOCK_EX);
- goto out;
- }
- list_for_each_entry(ni, &net->net_ni_list,
- ni_netlist) {
- if (!ni->ni_interface ||
- strncmp(ni->ni_interface,
- conf.lic_ni_intf,
- strlen(conf.lic_ni_intf)) != 0) {
- ni = NULL;
- continue;
- }
-
- lnet_net_unlock(LNET_LOCK_EX);
- rc = lnet_dyn_del_ni(&ni->ni_nid);
- if (rc < 0) {
- GENL_SET_ERR_MSG(info,
- "cannot del LNet NI");
- goto out;
- }
- break;
- }
-
- if (rc < 0) { /* will be -ENODEV */
- GENL_SET_ERR_MSG(info,
- "interface invalid for deleting LNet NI");
- lnet_net_unlock(LNET_LOCK_EX);
- }
- } else {
- rc = lnet_dyn_add_ni(&conf, net_id, &tun);
- switch (rc) {
- case -ENOENT:
- GENL_SET_ERR_MSG(info,
- "cannot parse net");
- break;
- case -ERANGE:
- GENL_SET_ERR_MSG(info,
- "invalid CPT set");
- fallthrough;
- default:
- GENL_SET_ERR_MSG(info,
- "cannot add LNet NI");
- case 0:
- break;
- }
+ nla_for_each_nested(interface, entry, rem3) {
+ rc = lnet_genl_parse_local_ni(interface, info,
+ net_id, &conf,
+ &ni_list);
if (rc < 0)
goto out;
}
@@ -5593,6 +5607,7 @@ static int lnet_ping_show_dump(struct sk_buff *msg,
static const struct genl_ops lnet_genl_ops[] = {
{
.cmd = LNET_CMD_NETS,
+ .flags = GENL_ADMIN_PERM,
.start = lnet_net_show_start,
.dumpit = lnet_net_show_dump,
.done = lnet_net_show_done,
@@ -1024,7 +1024,12 @@ static int lst_groups_show_start(struct netlink_callback *cb)
}
glist->lggl_verbose = true;
- nla_for_each_attr(groups, params, msg_len, rem) {
+ if (!(nla_type(params) & LN_SCALAR_ATTR_LIST)) {
+ NL_SET_ERR_MSG(extack, "no configuration");
+ goto report_err;
+ }
+
+ nla_for_each_nested(groups, params, rem) {
struct lst_genl_group_prop *prop = NULL;
struct nlattr *group;
int rem2;