Whamcloud - gitweb
LU-16307 util: fix lnetctl bugs that break sanity-sec 29/49129/5
authorJames Simmons <jsimmons@infradead.org>
Fri, 11 Nov 2022 02:40:04 +0000 (21:40 -0500)
committerOleg Drokin <green@whamcloud.com>
Tue, 15 Nov 2022 08:10:52 +0000 (08:10 +0000)
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 <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49129
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Cyril Bordage <cbordage@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/utils/lnetctl.c

index 2338230..2ee019f 100644 (file)
@@ -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,