4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LNET
38 #include <lnet/lib-lnet.h>
40 /* tmp struct for parsing routes */
41 struct lnet_text_buf {
42 struct list_head ltb_list; /* stash on lists */
43 int ltb_size; /* allocated size */
44 char ltb_text[0]; /* text buffer */
47 static int lnet_tbnob = 0; /* track text buf allocation */
48 #define LNET_MAX_TEXTBUF_NOB (64<<10) /* bound allocation */
49 #define LNET_SINGLE_TEXTBUF_NOB (4<<10)
52 lnet_syntax(char *name, char *str, int offset, int width)
54 static char dots[LNET_SINGLE_TEXTBUF_NOB];
55 static char dashes[LNET_SINGLE_TEXTBUF_NOB];
57 memset(dots, '.', sizeof(dots));
58 dots[sizeof(dots)-1] = 0;
59 memset(dashes, '-', sizeof(dashes));
60 dashes[sizeof(dashes)-1] = 0;
62 LCONSOLE_ERROR_MSG(0x10f, "Error parsing '%s=\"%s\"'\n", name, str);
63 LCONSOLE_ERROR_MSG(0x110, "here...........%.*s..%.*s|%.*s|\n",
64 (int)strlen(name), dots, offset, dots,
65 (width < 1) ? 0 : width - 1, dashes);
82 lnet_net_unique(__u32 net, struct list_head *nilist)
84 struct list_head *tmp;
87 list_for_each(tmp, nilist) {
88 ni = list_entry(tmp, lnet_ni_t, ni_list);
90 if (LNET_NIDNET(ni->ni_nid) == net)
98 lnet_ni_free(struct lnet_ni *ni)
102 if (ni->ni_refs != NULL)
103 cfs_percpt_free(ni->ni_refs);
105 if (ni->ni_tx_queues != NULL)
106 cfs_percpt_free(ni->ni_tx_queues);
108 if (ni->ni_cpts != NULL)
109 cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
111 for (i = 0; i < LNET_MAX_INTERFACES &&
112 ni->ni_interfaces[i] != NULL; i++) {
113 LIBCFS_FREE(ni->ni_interfaces[i],
114 strlen(ni->ni_interfaces[i]) + 1);
116 LIBCFS_FREE(ni, sizeof(*ni));
120 lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
122 struct lnet_tx_queue *tq;
127 if (!lnet_net_unique(net, nilist)) {
128 LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n",
129 libcfs_net2str(net));
133 LIBCFS_ALLOC(ni, sizeof(*ni));
135 CERROR("Out of memory creating network %s\n",
136 libcfs_net2str(net));
140 spin_lock_init(&ni->ni_lock);
141 INIT_LIST_HEAD(&ni->ni_cptlist);
142 ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
143 sizeof(*ni->ni_refs[0]));
144 if (ni->ni_refs == NULL)
147 ni->ni_tx_queues = cfs_percpt_alloc(lnet_cpt_table(),
148 sizeof(*ni->ni_tx_queues[0]));
149 if (ni->ni_tx_queues == NULL)
152 cfs_percpt_for_each(tq, i, ni->ni_tx_queues)
153 INIT_LIST_HEAD(&tq->tq_delayed);
157 ni->ni_ncpts = LNET_CPT_NUMBER;
159 rc = cfs_expr_list_values(el, LNET_CPT_NUMBER, &ni->ni_cpts);
161 CERROR("Failed to set CPTs for NI %s: %d\n",
162 libcfs_net2str(net), rc);
166 LASSERT(rc <= LNET_CPT_NUMBER);
167 if (rc == LNET_CPT_NUMBER) {
168 LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0]));
175 /* LND will fill in the address part of the NID */
176 ni->ni_nid = LNET_MKNID(net, 0);
177 ni->ni_last_alive = cfs_time_current_sec();
178 list_add_tail(&ni->ni_list, nilist);
186 lnet_parse_networks(struct list_head *nilist, char *networks)
188 struct cfs_expr_list *el = NULL;
196 struct list_head *temp_node;
198 if (networks == NULL) {
199 CERROR("networks string is undefined\n");
203 if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
204 /* _WAY_ conservative */
205 LCONSOLE_ERROR_MSG(0x112, "Can't parse networks: string too "
210 tokensize = strlen(networks) + 1;
212 LIBCFS_ALLOC(tokens, tokensize);
213 if (tokens == NULL) {
214 CERROR("Can't allocate net tokens\n");
218 memcpy(tokens, networks, tokensize);
221 while (str != NULL && *str != 0) {
222 char *comma = strchr(str, ',');
223 char *bracket = strchr(str, '(');
224 char *square = strchr(str, '[');
229 /* NB we don't check interface conflicts here; it's the LNDs
230 * responsibility (if it cares at all) */
232 if (square != NULL && (comma == NULL || square < comma)) {
233 /* i.e: o2ib0(ib0)[1,2], number between square
234 * brackets are CPTs this NI needs to be bond */
235 if (bracket != NULL && bracket > square) {
240 tmp = strchr(square, ']');
246 rc = cfs_expr_list_parse(square, tmp - square + 1,
247 0, LNET_CPT_NUMBER - 1, &el);
253 while (square <= tmp)
257 if (bracket == NULL ||
258 (comma != NULL && comma < bracket)) {
260 /* no interface list specified */
264 net = libcfs_str2net(cfs_trimwhite(str));
266 if (net == LNET_NIDNET(LNET_NID_ANY)) {
267 LCONSOLE_ERROR_MSG(0x113, "Unrecognised network"
273 if (LNET_NETTYP(net) != LOLND && /* LO is implicit */
274 lnet_ni_alloc(net, el, nilist) == NULL)
278 cfs_expr_list_free(el);
287 net = libcfs_str2net(cfs_trimwhite(str));
288 if (net == LNET_NIDNET(LNET_NID_ANY)) {
293 ni = lnet_ni_alloc(net, el, nilist);
298 cfs_expr_list_free(el);
305 bracket = strchr(iface, ')');
306 if (bracket == NULL) {
313 comma = strchr(iface, ',');
317 iface = cfs_trimwhite(iface);
323 if (niface == LNET_MAX_INTERFACES) {
324 LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
326 libcfs_net2str(net));
330 /* Allocate a separate piece of memory and copy
331 * into it the string, so we don't have
332 * a depencency on the tokens string. This way we
333 * can free the tokens at the end of the function.
334 * The newly allocated ni_interfaces[] can be
335 * freed when freeing the NI */
336 LIBCFS_ALLOC(ni->ni_interfaces[niface],
338 if (ni->ni_interfaces[niface] == NULL) {
339 CERROR("Can't allocate net interface name\n");
342 strncpy(ni->ni_interfaces[niface], iface,
346 } while (iface != NULL);
349 comma = strchr(bracket + 1, ',');
352 str = cfs_trimwhite(str);
361 str = cfs_trimwhite(str);
368 list_for_each(temp_node, nilist)
371 LIBCFS_FREE(tokens, tokensize);
375 lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
377 while (!list_empty(nilist)) {
378 ni = list_entry(nilist->next, lnet_ni_t, ni_list);
380 list_del(&ni->ni_list);
385 cfs_expr_list_free(el);
387 LIBCFS_FREE(tokens, tokensize);
392 static struct lnet_text_buf *lnet_new_text_buf(int str_len)
394 struct lnet_text_buf *ltb;
397 /* NB allocate space for the terminating 0 */
398 nob = offsetof(struct lnet_text_buf, ltb_text[str_len + 1]);
399 if (nob > LNET_SINGLE_TEXTBUF_NOB) {
400 /* _way_ conservative for "route net gateway..." */
401 CERROR("text buffer too big\n");
405 if (lnet_tbnob + nob > LNET_MAX_TEXTBUF_NOB) {
406 CERROR("Too many text buffers\n");
410 LIBCFS_ALLOC(ltb, nob);
415 ltb->ltb_text[0] = 0;
421 lnet_free_text_buf(struct lnet_text_buf *ltb)
423 lnet_tbnob -= ltb->ltb_size;
424 LIBCFS_FREE(ltb, ltb->ltb_size);
428 lnet_free_text_bufs(struct list_head *tbs)
430 struct lnet_text_buf *ltb;
432 while (!list_empty(tbs)) {
433 ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
435 list_del(<b->ltb_list);
436 lnet_free_text_buf(ltb);
441 lnet_print_text_bufs(struct list_head *tbs)
443 struct list_head *tmp;
444 struct lnet_text_buf *ltb;
446 list_for_each(tmp, tbs) {
447 ltb = list_entry(tmp, struct lnet_text_buf, ltb_list);
449 CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
452 CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
456 lnet_str2tbs_sep(struct list_head *tbs, char *str)
458 struct list_head pending;
462 struct lnet_text_buf *ltb;
464 INIT_LIST_HEAD(&pending);
466 /* Split 'str' into separate commands */
468 /* skip leading whitespace */
469 while (isspace(*str))
472 /* scan for separator or comment */
473 for (sep = str; *sep != 0; sep++)
474 if (lnet_issep(*sep) || *sep == '#')
477 nob = (int)(sep - str);
479 ltb = lnet_new_text_buf(nob);
481 lnet_free_text_bufs(&pending);
485 for (i = 0; i < nob; i++)
487 ltb->ltb_text[i] = ' ';
489 ltb->ltb_text[i] = str[i];
491 ltb->ltb_text[nob] = 0;
493 list_add_tail(<b->ltb_list, &pending);
497 /* scan for separator */
500 } while (*sep != 0 && !lnet_issep(*sep));
509 list_splice(&pending, tbs->prev);
514 lnet_expand1tb(struct list_head *list,
515 char *str, char *sep1, char *sep2,
516 char *item, int itemlen)
518 int len1 = (int)(sep1 - str);
519 int len2 = strlen(sep2 + 1);
520 struct lnet_text_buf *ltb;
522 LASSERT (*sep1 == '[');
523 LASSERT (*sep2 == ']');
525 ltb = lnet_new_text_buf(len1 + itemlen + len2);
529 memcpy(ltb->ltb_text, str, len1);
530 memcpy(<b->ltb_text[len1], item, itemlen);
531 memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2);
532 ltb->ltb_text[len1 + itemlen + len2] = 0;
534 list_add_tail(<b->ltb_list, list);
539 lnet_str2tbs_expand(struct list_head *tbs, char *str)
542 struct list_head pending;
554 INIT_LIST_HEAD(&pending);
556 sep = strchr(str, '[');
557 if (sep == NULL) /* nothing to expand */
560 sep2 = strchr(sep, ']');
564 for (parsed = sep; parsed < sep2; parsed = enditem) {
567 while (enditem < sep2 && *enditem != ',')
570 if (enditem == parsed) /* no empty items */
573 if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
575 if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
577 /* simple string enumeration */
578 if (lnet_expand1tb(&pending, str, sep, sep2,
579 parsed, (int)(enditem - parsed)) != 0)
588 /* range expansion */
590 if (enditem != parsed + scanned) /* no trailing junk */
593 if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
594 (hi - lo) % stride != 0)
597 for (i = lo; i <= hi; i += stride) {
599 snprintf(num, sizeof(num), "%d", i);
601 if (nob + 1 == sizeof(num))
604 if (lnet_expand1tb(&pending, str, sep, sep2,
610 list_splice(&pending, tbs->prev);
614 lnet_free_text_bufs(&pending);
619 lnet_parse_hops (char *str, unsigned int *hops)
621 int len = strlen(str);
624 return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
626 *hops > 0 && *hops < 256);
629 #define LNET_PRIORITY_SEPARATOR (':')
632 lnet_parse_priority(char *str, unsigned int *priority, char **token)
638 sep = strchr(str, LNET_PRIORITY_SEPARATOR);
643 len = strlen(sep + 1);
645 if ((sscanf((sep+1), "%u%n", priority, &nob) < 1) || (len != nob)) {
646 /* Update the caller's token pointer so it treats the found
647 priority as the token to report in the error message. */
648 *token += sep - str + 1;
652 CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
655 * Change priority separator to \0 to be able to parse NID
662 lnet_parse_route (char *str, int *im_a_router)
664 /* static scratch buffer OK (single threaded) */
665 static char cmd[LNET_SINGLE_TEXTBUF_NOB];
667 struct list_head nets;
668 struct list_head gateways;
669 struct list_head *tmp1;
670 struct list_head *tmp2;
673 struct lnet_text_buf *ltb;
681 unsigned int priority = 0;
683 INIT_LIST_HEAD(&gateways);
684 INIT_LIST_HEAD(&nets);
686 /* save a copy of the string for error messages */
687 strncpy(cmd, str, sizeof(cmd));
688 cmd[sizeof(cmd) - 1] = '\0';
692 /* scan for token start */
693 while (isspace(*sep))
696 if (ntokens < (got_hops ? 3 : 2))
704 /* scan for token end */
705 while (*sep != 0 && !isspace(*sep))
711 tmp2 = &nets; /* expanding nets */
712 } else if (ntokens == 2 &&
713 lnet_parse_hops(token, &hops)) {
714 got_hops = 1; /* got a hop count */
717 tmp2 = &gateways; /* expanding gateways */
720 ltb = lnet_new_text_buf(strlen(token));
724 strcpy(ltb->ltb_text, token);
725 tmp1 = <b->ltb_list;
726 list_add_tail(tmp1, tmp2);
728 while (tmp1 != tmp2) {
729 ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
731 rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
737 if (rc > 0) { /* expanded! */
738 list_del(<b->ltb_list);
739 lnet_free_text_buf(ltb);
744 net = libcfs_str2net(ltb->ltb_text);
745 if (net == LNET_NIDNET(LNET_NID_ANY) ||
746 LNET_NETTYP(net) == LOLND)
749 rc = lnet_parse_priority(ltb->ltb_text,
754 nid = libcfs_str2nid(ltb->ltb_text);
755 if (nid == LNET_NID_ANY ||
756 LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
762 /* if there are no hops set then we want to flag this value as
763 * unset since hops is an optional parameter */
765 hops = LNET_UNDEFINED_HOPS;
767 LASSERT(!list_empty(&nets));
768 LASSERT(!list_empty(&gateways));
770 list_for_each(tmp1, &nets) {
771 ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
772 net = libcfs_str2net(ltb->ltb_text);
773 LASSERT (net != LNET_NIDNET(LNET_NID_ANY));
775 list_for_each(tmp2, &gateways) {
776 ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
777 nid = libcfs_str2nid(ltb->ltb_text);
778 LASSERT(nid != LNET_NID_ANY);
780 if (lnet_islocalnid(nid)) {
785 rc = lnet_add_route(net, hops, nid, priority);
786 if (rc != 0 && rc != -EEXIST && rc != -EHOSTUNREACH) {
787 CERROR("Can't create route "
790 libcfs_nid2str(nid));
800 lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
802 lnet_free_text_bufs(&nets);
803 lnet_free_text_bufs(&gateways);
808 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
810 struct lnet_text_buf *ltb;
812 while (!list_empty(tbs)) {
813 ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
815 if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
816 lnet_free_text_bufs(tbs);
820 list_del(<b->ltb_list);
821 lnet_free_text_buf(ltb);
828 lnet_parse_routes (char *routes, int *im_a_router)
830 struct list_head tbs;
835 INIT_LIST_HEAD(&tbs);
837 if (lnet_str2tbs_sep(&tbs, routes) < 0) {
838 CERROR("Error parsing routes\n");
841 rc = lnet_parse_route_tbs(&tbs, im_a_router);
844 LASSERT (lnet_tbnob == 0);
849 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
851 struct list_head list = LIST_HEAD_INIT(list);
855 rc = cfs_ip_addr_parse(token, len, &list);
859 for (rc = i = 0; !rc && i < nip; i++)
860 rc = cfs_ip_addr_match(ipaddrs[i], &list);
862 cfs_expr_list_free_list(&list);
868 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
870 static char tokens[LNET_SINGLE_TEXTBUF_NOB];
880 LASSERT (strlen(net_entry) < sizeof(tokens));
882 /* work on a copy of the string */
883 strcpy(tokens, net_entry);
886 /* scan for token start */
887 while (isspace(*sep))
894 /* scan for token end */
895 while (*sep != 0 && !isspace(*sep))
900 if (ntokens++ == 0) {
907 rc = lnet_match_network_token(token, len, ipaddrs, nip);
909 lnet_syntax("ip2nets", net_entry,
910 (int)(token - tokens), len);
914 matched |= (rc != 0);
920 strcpy(net_entry, net); /* replace with matched net */
925 lnet_netspec2net(char *netspec)
927 char *bracket = strchr(netspec, '(');
933 net = libcfs_str2net(netspec);
942 lnet_splitnets(char *source, struct list_head *nets)
947 struct lnet_text_buf *tb;
948 struct lnet_text_buf *tb2;
954 LASSERT(!list_empty(nets));
955 LASSERT(nets->next == nets->prev); /* single entry */
957 tb = list_entry(nets->next, struct lnet_text_buf, ltb_list);
960 sep = strchr(tb->ltb_text, ',');
961 bracket = strchr(tb->ltb_text, '(');
966 /* netspec lists interfaces... */
968 offset2 = offset + (int)(bracket - tb->ltb_text);
969 len = strlen(bracket);
971 bracket = strchr(bracket + 1, ')');
973 if (bracket == NULL ||
974 !(bracket[1] == ',' || bracket[1] == 0)) {
975 lnet_syntax("ip2nets", source, offset2, len);
979 sep = (bracket[1] == 0) ? NULL : bracket + 1;
985 net = lnet_netspec2net(tb->ltb_text);
986 if (net == LNET_NIDNET(LNET_NID_ANY)) {
987 lnet_syntax("ip2nets", source, offset,
988 strlen(tb->ltb_text));
992 list_for_each(t, nets) {
993 tb2 = list_entry(t, struct lnet_text_buf, ltb_list);
998 if (net == lnet_netspec2net(tb2->ltb_text)) {
999 /* duplicate network */
1000 lnet_syntax("ip2nets", source, offset,
1001 strlen(tb->ltb_text));
1009 offset += (int)(sep - tb->ltb_text);
1011 tb2 = lnet_new_text_buf(len);
1015 strncpy(tb2->ltb_text, sep, len);
1016 tb2->ltb_text[len] = '\0';
1017 list_add_tail(&tb2->ltb_list, nets);
1024 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
1026 static char networks[LNET_SINGLE_TEXTBUF_NOB];
1027 static char source[LNET_SINGLE_TEXTBUF_NOB];
1029 struct list_head raw_entries;
1030 struct list_head matched_nets;
1031 struct list_head current_nets;
1032 struct list_head *t;
1033 struct list_head *t2;
1034 struct lnet_text_buf *tb;
1035 struct lnet_text_buf *tb2;
1043 INIT_LIST_HEAD(&raw_entries);
1044 if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
1045 CERROR("Error parsing ip2nets\n");
1046 LASSERT (lnet_tbnob == 0);
1050 INIT_LIST_HEAD(&matched_nets);
1051 INIT_LIST_HEAD(¤t_nets);
1057 while (!list_empty(&raw_entries)) {
1058 tb = list_entry(raw_entries.next, struct lnet_text_buf,
1061 strncpy(source, tb->ltb_text, sizeof(source));
1062 source[sizeof(source) - 1] = '\0';
1064 /* replace ltb_text with the network(s) add on match */
1065 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
1069 list_del(&tb->ltb_list);
1071 if (rc == 0) { /* no match */
1072 lnet_free_text_buf(tb);
1076 /* split into separate networks */
1077 INIT_LIST_HEAD(¤t_nets);
1078 list_add(&tb->ltb_list, ¤t_nets);
1079 rc = lnet_splitnets(source, ¤t_nets);
1084 list_for_each(t, ¤t_nets) {
1085 tb = list_entry(t, struct lnet_text_buf, ltb_list);
1086 net1 = lnet_netspec2net(tb->ltb_text);
1087 LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
1089 list_for_each(t2, &matched_nets) {
1090 tb2 = list_entry(t2, struct lnet_text_buf,
1092 net2 = lnet_netspec2net(tb2->ltb_text);
1093 LASSERT(net2 != LNET_NIDNET(LNET_NID_ANY));
1106 lnet_free_text_bufs(¤t_nets);
1110 list_for_each_safe(t, t2, ¤t_nets) {
1111 tb = list_entry(t, struct lnet_text_buf, ltb_list);
1113 list_del(&tb->ltb_list);
1114 list_add_tail(&tb->ltb_list, &matched_nets);
1116 len += snprintf(networks + len, sizeof(networks) - len,
1117 "%s%s", (len == 0) ? "" : ",",
1120 if (len >= sizeof(networks)) {
1121 CERROR("Too many matched networks\n");
1131 lnet_free_text_bufs(&raw_entries);
1132 lnet_free_text_bufs(&matched_nets);
1133 lnet_free_text_bufs(¤t_nets);
1134 LASSERT (lnet_tbnob == 0);
1139 *networksp = networks;
1144 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
1146 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
1150 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
1158 int nif = lnet_ipif_enumerate(&ifnames);
1165 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
1166 if (ipaddrs == NULL) {
1167 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1168 lnet_ipif_free_enumeration(ifnames, nif);
1172 for (i = nip = 0; i < nif; i++) {
1173 if (!strcmp(ifnames[i], "lo"))
1176 rc = lnet_ipif_query(ifnames[i], &up,
1177 &ipaddrs[nip], &netmask);
1179 CWARN("Can't query interface %s: %d\n",
1185 CWARN("Ignoring interface %s: it's down\n",
1193 lnet_ipif_free_enumeration(ifnames, nif);
1196 *ipaddrsp = ipaddrs;
1199 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
1200 if (ipaddrs2 == NULL) {
1201 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1204 memcpy(ipaddrs2, ipaddrs,
1205 nip * sizeof(*ipaddrs));
1206 *ipaddrsp = ipaddrs2;
1210 lnet_ipaddr_free_enumeration(ipaddrs, nif);
1216 lnet_parse_ip2nets (char **networksp, char *ip2nets)
1218 __u32 *ipaddrs = NULL;
1219 int nip = lnet_ipaddr_enumerate(&ipaddrs);
1223 LCONSOLE_ERROR_MSG(0x117, "Error %d enumerating local IP "
1224 "interfaces for ip2nets to match\n", nip);
1229 LCONSOLE_ERROR_MSG(0x118, "No local IP interfaces "
1230 "for ip2nets to match\n");
1234 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1235 lnet_ipaddr_free_enumeration(ipaddrs, nip);
1238 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
1243 LCONSOLE_ERROR_MSG(0x11a, "ip2nets does not match "
1244 "any local IP interfaces\n");