From 5055381d9e766c0353d3881119a300b6fa60c10b Mon Sep 17 00:00:00 2001 From: James Simmons Date: Thu, 10 Nov 2022 21:40:04 -0500 Subject: [PATCH] LU-16307 util: fix lnetctl bugs that break sanity-sec For lnetctl net commands you always need a --net option. For the case of creating a local NI you need a list of interfaces. For yaml_lnet_config_ni() I was always requiring a list of interfaces which is wrong. Only test for missing interfaces for the NLM_F_CREATE case. Second bug is if we fail to detect Netlink we use the old api. We end up freeing some needed parameters instead of passing them to old APIs. Jump to old api code without freeing parameter data. Fixes: 8f8f6e2f3 ("LU-10003 lnet: use Netlink to support old and new NI APIs.") Change-Id: I4b11372b9afa8023bcbaba3297dd04196d22ef05 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49129 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Chris Horn Reviewed-by: Serguei Smirnov Reviewed-by: Frank Sehr Reviewed-by: Cyril Bordage Reviewed-by: Oleg Drokin --- lnet/utils/lnetctl.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index 2338230..2ee019f 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -1376,14 +1376,18 @@ static int yaml_lnet_config_ni(char *net_id, char *ip2net, yaml_event_t event; int rc; - if (!ip2net && (!nw_descr || nw_descr->nw_id == 0 || - (list_empty(&nw_descr->nw_intflist)))) { + if (!ip2net && (!nw_descr || nw_descr->nw_id == 0)) { fprintf(stdout, "missing mandatory parameters in NI config: '%s'", (!nw_descr) ? "network , interface" : (nw_descr->nw_id == 0) ? "network" : "interface"); return -EINVAL; } + if ((flags == NLM_F_CREATE) && list_empty(&nw_descr->nw_intflist)) { + fprintf(stdout, "creating a local NI needs at least one interface"); + return -EINVAL; + } + /* Create Netlink emitter to send request to kernel */ sk = nl_socket_alloc(); if (!sk) @@ -1796,14 +1800,15 @@ static int jt_add_ni(int argc, char **argv) (cpt_rc == 0) ? global_cpts : NULL, NLM_F_CREATE); if (rc <= 0) { + if (rc == -EOPNOTSUPP) + goto old_api; if (global_cpts != NULL) cfs_expr_list_free(global_cpts); if (rc == 0 && !skip_mr_route_setup) rc = lustre_lnet_setup_mrrouting(&err_rc); - if (rc != -EOPNOTSUPP) - return rc; + return rc; } - +old_api: rc = lustre_lnet_config_ni(&nw_descr, (cpt_rc == 0) ? global_cpts: NULL, ip2net, (found) ? &tunables : NULL, -- 1.8.3.1