Whamcloud - gitweb
LU-6245 libcfs: create userland and kernel string operations
[fs/lustre-release.git] / lnet / lnet / config.c
index 7e9c3b6..1b8fc3c 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -48,24 +48,24 @@ static int lnet_tbnob = 0;                  /* track text buf allocation */
 #define LNET_MAX_TEXTBUF_NOB     (64<<10)      /* bound allocation */
 #define LNET_SINGLE_TEXTBUF_NOB  (4<<10)
 
-void
+static void
 lnet_syntax(char *name, char *str, int offset, int width)
 {
         static char dots[LNET_SINGLE_TEXTBUF_NOB];
         static char dashes[LNET_SINGLE_TEXTBUF_NOB];
-        
+
         memset(dots, '.', sizeof(dots));
         dots[sizeof(dots)-1] = 0;
         memset(dashes, '-', sizeof(dashes));
         dashes[sizeof(dashes)-1] = 0;
-        
+
        LCONSOLE_ERROR_MSG(0x10f, "Error parsing '%s=\"%s\"'\n", name, str);
-       LCONSOLE_ERROR_MSG(0x110, "here...........%.*s..%.*s|%.*s|\n", 
+       LCONSOLE_ERROR_MSG(0x110, "here...........%.*s..%.*s|%.*s|\n",
                            (int)strlen(name), dots, offset, dots,
                             (width < 1) ? 0 : width - 1, dashes);
 }
 
-int 
+static int
 lnet_issep (char c)
 {
        switch (c) {
@@ -97,6 +97,8 @@ lnet_net_unique(__u32 net, struct list_head *nilist)
 void
 lnet_ni_free(struct lnet_ni *ni)
 {
+       int i;
+
        if (ni->ni_refs != NULL)
                cfs_percpt_free(ni->ni_refs);
 
@@ -106,11 +108,11 @@ lnet_ni_free(struct lnet_ni *ni)
        if (ni->ni_cpts != NULL)
                cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
 
-#ifndef __KERNEL__
-# ifdef HAVE_LIBPTHREAD
-       pthread_mutex_destroy(&ni->ni_lock);
-# endif
-#endif
+       for (i = 0; i < LNET_MAX_INTERFACES &&
+                   ni->ni_interfaces[i] != NULL; i++) {
+               LIBCFS_FREE(ni->ni_interfaces[i],
+                           strlen(ni->ni_interfaces[i]) + 1);
+       }
        LIBCFS_FREE(ni, sizeof(*ni));
 }
 
@@ -135,13 +137,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
                 return NULL;
         }
 
-#ifdef __KERNEL__
        spin_lock_init(&ni->ni_lock);
-#else
-# ifdef HAVE_LIBPTHREAD
-       pthread_mutex_init(&ni->ni_lock, NULL);
-# endif
-#endif
        INIT_LIST_HEAD(&ni->ni_cptlist);
        ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
                                       sizeof(*ni->ni_refs[0]));
@@ -190,13 +186,19 @@ int
 lnet_parse_networks(struct list_head *nilist, char *networks)
 {
        struct cfs_expr_list *el = NULL;
-       int             tokensize = strlen(networks) + 1;
+       int             tokensize;
        char            *tokens;
        char            *str;
        char            *tmp;
        struct lnet_ni  *ni;
        __u32           net;
        int             nnets = 0;
+       struct list_head *temp_node;
+
+       if (networks == NULL) {
+               CERROR("networks string is undefined\n");
+               return -EINVAL;
+       }
 
        if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
                /* _WAY_ conservative */
@@ -205,22 +207,17 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                return -EINVAL;
        }
 
-        LIBCFS_ALLOC(tokens, tokensize);
-        if (tokens == NULL) {
-                CERROR("Can't allocate net tokens\n");
+       tokensize = strlen(networks) + 1;
+
+       LIBCFS_ALLOC(tokens, tokensize);
+       if (tokens == NULL) {
+               CERROR("Can't allocate net tokens\n");
                return -ENOMEM;
-        }
+       }
 
-        the_lnet.ln_network_tokens = tokens;
-        the_lnet.ln_network_tokens_nob = tokensize;
-        memcpy (tokens, networks, tokensize);
+       memcpy(tokens, networks, tokensize);
        str = tmp = tokens;
 
-       /* Add in the loopback network */
-       ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist);
-       if (ni == NULL)
-               goto failed;
-
        while (str != NULL && *str != 0) {
                char    *comma = strchr(str, ',');
                char    *bracket = strchr(str, '(');
@@ -293,7 +290,6 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                        goto failed_syntax;
                }
 
-               nnets++;
                ni = lnet_ni_alloc(net, el, nilist);
                if (ni == NULL)
                        goto failed;
@@ -324,14 +320,28 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                                goto failed_syntax;
                         }
 
-                        if (niface == LNET_MAX_INTERFACES) {
-                                LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
-                                                   "for net %s\n",
-                                                   libcfs_net2str(net));
-                                goto failed;
-                        }
+                       if (niface == LNET_MAX_INTERFACES) {
+                               LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
+                                                  "for net %s\n",
+                                                  libcfs_net2str(net));
+                               goto failed;
+                       }
 
-                        ni->ni_interfaces[niface++] = iface;
+                       /* Allocate a seperate piece of memory and copy
+                        * into it the string, so we don't have
+                        * a depencency on the tokens string.  This way we
+                        * can free the tokens at the end of the function.
+                        * The newly allocated ni_interfaces[] can be
+                        * freed when freeing the NI */
+                       LIBCFS_ALLOC(ni->ni_interfaces[niface],
+                                    strlen(iface) + 1);
+                       if (ni->ni_interfaces[niface] == NULL) {
+                               CERROR("Can't allocate net interface name\n");
+                               goto failed;
+                       }
+                       strncpy(ni->ni_interfaces[niface], iface,
+                               strlen(iface));
+                       niface++;
                        iface = comma;
                } while (iface != NULL);
 
@@ -355,8 +365,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                }
        }
 
-       LASSERT(!list_empty(nilist));
-       return 0;
+       list_for_each(temp_node, nilist)
+               nnets++;
+
+       LIBCFS_FREE(tokens, tokensize);
+       return nnets;
 
  failed_syntax:
        lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
@@ -372,18 +385,16 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
                cfs_expr_list_free(el);
 
        LIBCFS_FREE(tokens, tokensize);
-       the_lnet.ln_network_tokens = NULL;
 
        return -EINVAL;
 }
 
-struct lnet_text_buf *
-lnet_new_text_buf (int str_len) 
+static struct lnet_text_buf *lnet_new_text_buf(int str_len)
 {
        struct lnet_text_buf *ltb;
-       int              nob;
+       int nob;
 
-        /* NB allocate space for the terminating 0 */
+       /* NB allocate space for the terminating 0 */
        nob = offsetof(struct lnet_text_buf, ltb_text[str_len + 1]);
        if (nob > LNET_SINGLE_TEXTBUF_NOB) {
                /* _way_ conservative for "route net gateway..." */
@@ -395,25 +406,25 @@ lnet_new_text_buf (int str_len)
                CERROR("Too many text buffers\n");
                return NULL;
        }
-       
+
        LIBCFS_ALLOC(ltb, nob);
        if (ltb == NULL)
                return NULL;
 
        ltb->ltb_size = nob;
-        ltb->ltb_text[0] = 0;
+       ltb->ltb_text[0] = 0;
        lnet_tbnob += nob;
        return ltb;
 }
 
-void
+static void
 lnet_free_text_buf(struct lnet_text_buf *ltb)
 {
        lnet_tbnob -= ltb->ltb_size;
        LIBCFS_FREE(ltb, ltb->ltb_size);
 }
 
-void
+static void
 lnet_free_text_bufs(struct list_head *tbs)
 {
        struct lnet_text_buf  *ltb;
@@ -441,7 +452,7 @@ lnet_print_text_bufs(struct list_head *tbs)
        CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
 }
 
-int
+static int
 lnet_str2tbs_sep(struct list_head *tbs, char *str)
 {
        struct list_head  pending;
@@ -455,9 +466,9 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
        /* Split 'str' into separate commands */
        for (;;) {
                 /* skip leading whitespace */
-                while (cfs_iswhite(*str))
+               while (isspace(*str))
                         str++;
-                
+
                /* scan for separator or comment */
                for (sep = str; *sep != 0; sep++)
                        if (lnet_issep(*sep) || *sep == '#')
@@ -470,9 +481,9 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
                                lnet_free_text_bufs(&pending);
                                return -1;
                        }
-                       
+
                         for (i = 0; i < nob; i++)
-                                if (cfs_iswhite(str[i]))
+                               if (isspace(str[i]))
                                         ltb->ltb_text[i] = ' ';
                                 else
                                         ltb->ltb_text[i] = str[i];
@@ -488,7 +499,7 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
                                sep++;
                        } while (*sep != 0 && !lnet_issep(*sep));
                }
-               
+
                if (*sep == 0)
                        break;
 
@@ -499,9 +510,9 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
        return 0;
 }
 
-int
+static int
 lnet_expand1tb(struct list_head *list,
-              char *str, char *sep1, char *sep2, 
+              char *str, char *sep1, char *sep2,
               char *item, int itemlen)
 {
        int              len1 = (int)(sep1 - str);
@@ -524,7 +535,7 @@ lnet_expand1tb(struct list_head *list,
        return 0;
 }
 
-int
+static int
 lnet_str2tbs_expand(struct list_head *tbs, char *str)
 {
        char              num[16];
@@ -567,10 +578,10 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
                                if (lnet_expand1tb(&pending, str, sep, sep2,
                                                    parsed, (int)(enditem - parsed)) != 0)
                                        goto failed;
-                               
+
                                continue;
                        }
-                       
+
                        stride = 1;
                }
 
@@ -578,38 +589,38 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
 
                if (enditem != parsed + scanned) /* no trailing junk */
                        goto failed;
-                        
-               if (hi < 0 || lo < 0 || stride < 0 || hi < lo || 
+
+               if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
                    (hi - lo) % stride != 0)
                        goto failed;
-                        
+
                for (i = lo; i <= hi; i += stride) {
 
                        snprintf(num, sizeof(num), "%d", i);
                        nob = strlen(num);
                        if (nob + 1 == sizeof(num))
                                goto failed;
-                       
-                       if (lnet_expand1tb(&pending, str, sep, sep2, 
+
+                       if (lnet_expand1tb(&pending, str, sep, sep2,
                                            num, nob) != 0)
                                goto failed;
                }
        }
-               
+
        list_splice(&pending, tbs->prev);
        return 1;
-       
+
  failed:
        lnet_free_text_bufs(&pending);
        return -1;
 }
 
-int
+static int
 lnet_parse_hops (char *str, unsigned int *hops)
 {
         int     len = strlen(str);
         int     nob = len;
-       
+
         return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
                 nob == len &&
                 *hops > 0 && *hops < 256);
@@ -617,7 +628,7 @@ lnet_parse_hops (char *str, unsigned int *hops)
 
 #define LNET_PRIORITY_SEPARATOR (':')
 
-int
+static int
 lnet_parse_priority(char *str, unsigned int *priority, char **token)
 {
        int   nob;
@@ -647,7 +658,7 @@ lnet_parse_priority(char *str, unsigned int *priority, char **token)
        return 0;
 }
 
-int
+static int
 lnet_parse_route (char *str, int *im_a_router)
 {
        /* static scratch buffer OK (single threaded) */
@@ -664,22 +675,22 @@ lnet_parse_route (char *str, int *im_a_router)
        char             *sep;
        char             *token = str;
        int               ntokens = 0;
-        int               myrc = -1;
-        unsigned int      hops;
-        int               got_hops = 0;
+       int               myrc = -1;
+       unsigned int      hops;
+       int               got_hops = 0;
        unsigned int      priority = 0;
 
        INIT_LIST_HEAD(&gateways);
        INIT_LIST_HEAD(&nets);
 
        /* save a copy of the string for error messages */
-       strncpy(cmd, str, sizeof(cmd) - 1);
-       cmd[sizeof(cmd) - 1] = 0;
+       strncpy(cmd, str, sizeof(cmd));
+       cmd[sizeof(cmd) - 1] = '\0';
 
        sep = str;
        for (;;) {
                /* scan for token start */
-                while (cfs_iswhite(*sep))
+               while (isspace(*sep))
                        sep++;
                if (*sep == 0) {
                        if (ntokens < (got_hops ? 3 : 2))
@@ -691,11 +702,11 @@ lnet_parse_route (char *str, int *im_a_router)
                token = sep++;
 
                /* scan for token end */
-                while (*sep != 0 && !cfs_iswhite(*sep))
+               while (*sep != 0 && !isspace(*sep))
                        sep++;
                if (*sep != 0)
                        *sep++ = 0;
-               
+
                if (ntokens == 1) {
                        tmp2 = &nets;           /* expanding nets */
                 } else if (ntokens == 2 &&
@@ -705,7 +716,7 @@ lnet_parse_route (char *str, int *im_a_router)
                 } else {
                        tmp2 = &gateways;       /* expanding gateways */
                 }
-                
+
                ltb = lnet_new_text_buf(strlen(token));
                if (ltb == NULL)
                        goto out;
@@ -713,7 +724,7 @@ lnet_parse_route (char *str, int *im_a_router)
                strcpy(ltb->ltb_text, token);
                tmp1 = &ltb->ltb_list;
                list_add_tail(tmp1, tmp2);
-               
+
                while (tmp1 != tmp2) {
                        ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
 
@@ -722,7 +733,7 @@ lnet_parse_route (char *str, int *im_a_router)
                                goto token_error;
 
                        tmp1 = tmp1->next;
-                       
+
                        if (rc > 0) {           /* expanded! */
                                list_del(&ltb->ltb_list);
                                lnet_free_text_buf(ltb);
@@ -748,8 +759,8 @@ lnet_parse_route (char *str, int *im_a_router)
                }
        }
 
-        if (!got_hops)
-                hops = 1;
+       if (!got_hops)
+               hops = 1;
 
        LASSERT(!list_empty(&nets));
        LASSERT(!list_empty(&gateways));
@@ -764,34 +775,34 @@ lnet_parse_route (char *str, int *im_a_router)
                        nid = libcfs_str2nid(ltb->ltb_text);
                        LASSERT(nid != LNET_NID_ANY);
 
-                        if (lnet_islocalnid(nid)) {
-                                *im_a_router = 1;
-                                continue;
-                        }
+                       if (lnet_islocalnid(nid)) {
+                               *im_a_router = 1;
+                               continue;
+                       }
 
                        rc = lnet_add_route(net, hops, nid, priority);
-                        if (rc != 0) {
-                                CERROR("Can't create route "
-                                       "to %s via %s\n",
-                                       libcfs_net2str(net),
-                                       libcfs_nid2str(nid));
-                                goto out;
-                        }
+                       if (rc != 0 && rc != -EEXIST && rc != -EHOSTUNREACH) {
+                               CERROR("Can't create route "
+                                      "to %s via %s\n",
+                                      libcfs_net2str(net),
+                                      libcfs_nid2str(nid));
+                               goto out;
+                       }
                }
        }
 
-        myrc = 0;
-        goto out;
-        
- token_error:
+       myrc = 0;
+       goto out;
+
+token_error:
        lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
- out:
+out:
        lnet_free_text_bufs(&nets);
        lnet_free_text_bufs(&gateways);
        return myrc;
 }
 
-int
+static int
 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
 {
        struct lnet_text_buf   *ltb;
@@ -832,7 +843,7 @@ lnet_parse_routes (char *routes, int *im_a_router)
        return rc;
 }
 
-int
+static int
 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
 {
        struct list_head list = LIST_HEAD_INIT(list);
@@ -846,12 +857,12 @@ lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
        for (rc = i = 0; !rc && i < nip; i++)
                rc = cfs_ip_addr_match(ipaddrs[i], &list);
 
-       cfs_ip_addr_free(&list);
+       cfs_expr_list_free_list(&list);
 
         return rc;
 }
 
-int
+static int
 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
 {
         static char tokens[LNET_SINGLE_TEXTBUF_NOB];
@@ -871,19 +882,19 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
         sep = tokens;
         for (;;) {
                 /* scan for token start */
-                while (cfs_iswhite(*sep))
+               while (isspace(*sep))
                         sep++;
                 if (*sep == 0)
                         break;
-                
+
                 token = sep++;
-                
+
                 /* scan for token end */
-                while (*sep != 0 && !cfs_iswhite(*sep))
+               while (*sep != 0 && !isspace(*sep))
                         sep++;
                 if (*sep != 0)
                         *sep++ = 0;
-                
+
                 if (ntokens++ == 0) {
                         net = token;
                         continue;
@@ -900,15 +911,15 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
 
                 matched |= (rc != 0);
         }
-        
+
         if (!matched)
                 return 0;
-        
+
         strcpy(net_entry, net);                 /* replace with matched net */
         return 1;
 }
 
-__u32
+static __u32
 lnet_netspec2net(char *netspec)
 {
         char   *bracket = strchr(netspec, '(');
@@ -925,7 +936,7 @@ lnet_netspec2net(char *netspec)
         return net;
 }
 
-int
+static int
 lnet_splitnets(char *source, struct list_head *nets)
 {
         int               offset = 0;
@@ -947,9 +958,9 @@ lnet_splitnets(char *source, struct list_head *nets)
                 sep = strchr(tb->ltb_text, ',');
                 bracket = strchr(tb->ltb_text, '(');
 
-                if (sep != NULL && 
-                    bracket != NULL && 
-                    bracket < sep) {
+               if (sep != NULL &&
+                   bracket != NULL &&
+                   bracket < sep) {
                         /* netspec lists interfaces... */
 
                         offset2 = offset + (int)(bracket - tb->ltb_text);
@@ -981,7 +992,7 @@ lnet_splitnets(char *source, struct list_head *nets)
 
                         if (tb2 == tb)
                                 continue;
-                        
+
                         if (net == lnet_netspec2net(tb2->ltb_text)) {
                                 /* duplicate network */
                                 lnet_syntax("ip2nets", source, offset,
@@ -994,18 +1005,20 @@ lnet_splitnets(char *source, struct list_head *nets)
                         return 0;
 
                 offset += (int)(sep - tb->ltb_text);
-                tb2 = lnet_new_text_buf(strlen(sep));
-                if (tb2 == NULL)
-                        return -ENOMEM;
+               len = strlen(sep);
+               tb2 = lnet_new_text_buf(len);
+               if (tb2 == NULL)
+                       return -ENOMEM;
 
-               strncpy(tb2->ltb_text, sep, strlen(sep));
+               strncpy(tb2->ltb_text, sep, len);
+               tb2->ltb_text[len] = '\0';
                list_add_tail(&tb2->ltb_list, nets);
 
                tb = tb2;
        }
 }
 
-int
+static int
 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 {
        static char       networks[LNET_SINGLE_TEXTBUF_NOB];
@@ -1043,8 +1056,8 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
                tb = list_entry(raw_entries.next, struct lnet_text_buf,
                                ltb_list);
 
-                strncpy(source, tb->ltb_text, sizeof(source)-1);
-                source[sizeof(source)-1] = 0;
+               strncpy(source, tb->ltb_text, sizeof(source));
+               source[sizeof(source) - 1] = '\0';
 
                 /* replace ltb_text with the network(s) add on match */
                 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
@@ -1094,21 +1107,21 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 
                list_for_each_safe(t, t2, &current_nets) {
                        tb = list_entry(t, struct lnet_text_buf, ltb_list);
-                        
+
                        list_del(&tb->ltb_list);
                        list_add_tail(&tb->ltb_list, &matched_nets);
 
-                        len += snprintf(networks + len, sizeof(networks) - len,
-                                        "%s%s", (len == 0) ? "" : ",", 
-                                        tb->ltb_text);
-                
+                       len += snprintf(networks + len, sizeof(networks) - len,
+                                       "%s%s", (len == 0) ? "" : ",",
+                                       tb->ltb_text);
+
                         if (len >= sizeof(networks)) {
                                 CERROR("Too many matched networks\n");
                                 rc = -E2BIG;
                                 goto out;
                         }
                 }
-                
+
                 count++;
         }
 
@@ -1125,14 +1138,13 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
         return count;
 }
 
-#ifdef __KERNEL__
-void
+static void
 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
 {
         LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
 }
 
-int
+static int
 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
 {
         int        up;
@@ -1141,7 +1153,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
         __u32     *ipaddrs2;
         int        nip;
         char     **ifnames;
-        int        nif = libcfs_ipif_enumerate(&ifnames);
+       int        nif = lnet_ipif_enumerate(&ifnames);
         int        i;
         int        rc;
 
@@ -1151,7 +1163,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
         LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
         if (ipaddrs == NULL) {
                 CERROR("Can't allocate ipaddrs[%d]\n", nif);
-                libcfs_ipif_free_enumeration(ifnames, nif);
+               lnet_ipif_free_enumeration(ifnames, nif);
                 return -ENOMEM;
         }
 
@@ -1159,7 +1171,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
                 if (!strcmp(ifnames[i], "lo"))
                         continue;
 
-                rc = libcfs_ipif_query(ifnames[i], &up,
+               rc = lnet_ipif_query(ifnames[i], &up,
                                        &ipaddrs[nip], &netmask);
                 if (rc != 0) {
                         CWARN("Can't query interface %s: %d\n",
@@ -1176,7 +1188,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
                 nip++;
         }
 
-        libcfs_ipif_free_enumeration(ifnames, nif);
+       lnet_ipif_free_enumeration(ifnames, nif);
 
         if (nip == nif) {
                 *ipaddrsp = ipaddrs;
@@ -1187,8 +1199,8 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
                                 CERROR("Can't allocate ipaddrs[%d]\n", nip);
                                 nip = -ENOMEM;
                         } else {
-                                memcpy(ipaddrs2, ipaddrs, 
-                                       nip * sizeof(*ipaddrs));
+                               memcpy(ipaddrs2, ipaddrs,
+                                       nip * sizeof(*ipaddrs));
                                 *ipaddrsp = ipaddrs2;
                                 rc = nip;
                         }
@@ -1201,7 +1213,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp)
 int
 lnet_parse_ip2nets (char **networksp, char *ip2nets)
 {
-        __u32     *ipaddrs;
+       __u32     *ipaddrs = NULL;
         int        nip = lnet_ipaddr_enumerate(&ipaddrs);
         int        rc;
 
@@ -1233,84 +1245,3 @@ lnet_parse_ip2nets (char **networksp, char *ip2nets)
 
         return 0;
 }
-
-int
-lnet_set_ip_niaddr (lnet_ni_t *ni)
-{
-        __u32  net = LNET_NIDNET(ni->ni_nid);
-        char **names;
-        int    n;
-        __u32  ip;
-        __u32  netmask;
-        int    up;
-        int    i;
-        int    rc;
-
-        /* Convenience for LNDs that use the IP address of a local interface as
-         * the local address part of their NID */
-
-        if (ni->ni_interfaces[0] != NULL) {
-
-                CLASSERT (LNET_MAX_INTERFACES > 1);
-
-                if (ni->ni_interfaces[1] != NULL) {
-                        CERROR("Net %s doesn't support multiple interfaces\n",
-                               libcfs_net2str(net));
-                        return -EPERM;
-                }
-
-                rc = libcfs_ipif_query(ni->ni_interfaces[0],
-                                       &up, &ip, &netmask);
-                if (rc != 0) {
-                        CERROR("Net %s can't query interface %s: %d\n",
-                               libcfs_net2str(net), ni->ni_interfaces[0], rc);
-                        return -EPERM;
-                }
-
-                if (!up) {
-                        CERROR("Net %s can't use interface %s: it's down\n",
-                               libcfs_net2str(net), ni->ni_interfaces[0]);
-                        return -ENETDOWN;
-                }
-
-                ni->ni_nid = LNET_MKNID(net, ip);
-                return 0;
-        }
-
-        n = libcfs_ipif_enumerate(&names);
-        if (n <= 0) {
-                CERROR("Net %s can't enumerate interfaces: %d\n",
-                       libcfs_net2str(net), n);
-                return 0;
-        }
-
-        for (i = 0; i < n; i++) {
-                if (!strcmp(names[i], "lo")) /* skip the loopback IF */
-                        continue;
-
-                rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
-
-                if (rc != 0) {
-                        CWARN("Net %s can't query interface %s: %d\n",
-                              libcfs_net2str(net), names[i], rc);
-                        continue;
-                }
-
-                if (!up) {
-                        CWARN("Net %s ignoring interface %s (down)\n",
-                              libcfs_net2str(net), names[i]);
-                        continue;
-                }
-
-                libcfs_ipif_free_enumeration(names, n);
-                ni->ni_nid = LNET_MKNID(net, ip);
-                return 0;
-        }
-
-        CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
-        libcfs_ipif_free_enumeration(names, n);
-        return -ENOENT;
-}
-EXPORT_SYMBOL(lnet_set_ip_niaddr);
-
-#endif