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.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
35 #define DEBUG_SUBSYSTEM S_LNET
36 #include <lnet/lib-lnet.h>
38 typedef struct { /* tmp struct for parsing routes */
39 cfs_list_t ltb_list; /* stash on lists */
40 int ltb_size; /* allocated size */
41 char ltb_text[0]; /* text buffer */
44 static int lnet_tbnob = 0; /* track text buf allocation */
45 #define LNET_MAX_TEXTBUF_NOB (64<<10) /* bound allocation */
46 #define LNET_SINGLE_TEXTBUF_NOB (4<<10)
49 lnet_syntax(char *name, char *str, int offset, int width)
51 static char dots[LNET_SINGLE_TEXTBUF_NOB];
52 static char dashes[LNET_SINGLE_TEXTBUF_NOB];
54 memset(dots, '.', sizeof(dots));
55 dots[sizeof(dots)-1] = 0;
56 memset(dashes, '-', sizeof(dashes));
57 dashes[sizeof(dashes)-1] = 0;
59 LCONSOLE_ERROR_MSG(0x10f, "Error parsing '%s=\"%s\"'\n", name, str);
60 LCONSOLE_ERROR_MSG(0x110, "here...........%.*s..%.*s|%.*s|\n",
61 (int)strlen(name), dots, offset, dots,
62 (width < 1) ? 0 : width - 1, dashes);
79 lnet_net_unique(__u32 net, cfs_list_t *nilist)
84 cfs_list_for_each (tmp, nilist) {
85 ni = cfs_list_entry(tmp, lnet_ni_t, ni_list);
87 if (LNET_NIDNET(ni->ni_nid) == net)
95 lnet_ni_free(struct lnet_ni *ni)
97 if (ni->ni_refs != NULL)
98 cfs_percpt_free(ni->ni_refs);
100 if (ni->ni_tx_queues != NULL)
101 cfs_percpt_free(ni->ni_tx_queues);
103 if (ni->ni_cpts != NULL) {
104 LIBCFS_FREE(ni->ni_cpts,
105 sizeof(ni->ni_cpts[0] * ni->ni_ncpts));
109 # ifdef HAVE_LIBPTHREAD
110 pthread_mutex_destroy(&ni->ni_lock);
113 LIBCFS_FREE(ni, sizeof(*ni));
117 lnet_ni_alloc(__u32 net, struct cfs_expr_list **el, cfs_list_t *nilist)
119 struct lnet_tx_queue *tq;
124 if (!lnet_net_unique(net, nilist)) {
125 LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n",
126 libcfs_net2str(net));
130 LIBCFS_ALLOC(ni, sizeof(*ni));
132 CERROR("Out of memory creating network %s\n",
133 libcfs_net2str(net));
138 cfs_spin_lock_init(&ni->ni_lock);
140 # ifdef HAVE_LIBPTHREAD
141 pthread_mutex_init(&ni->ni_lock, NULL);
144 CFS_INIT_LIST_HEAD(&ni->ni_cptlist);
145 ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
146 sizeof(*ni->ni_refs[0]));
147 if (ni->ni_refs == NULL)
150 ni->ni_tx_queues = cfs_percpt_alloc(lnet_cpt_table(),
151 sizeof(*ni->ni_tx_queues[0]));
152 if (ni->ni_tx_queues == NULL)
155 cfs_percpt_for_each(tq, i, ni->ni_tx_queues)
156 CFS_INIT_LIST_HEAD(&tq->tq_delayed);
158 if (el == NULL || *el == NULL) {
160 ni->ni_ncpts = LNET_CPT_NUMBER;
162 rc = cfs_expr_list_values(*el, LNET_CPT_NUMBER, &ni->ni_cpts);
164 CERROR("Failed to set CPTs for NI %s: %d\n",
165 libcfs_net2str(net), rc);
169 LASSERT(rc <= LNET_CPT_NUMBER);
170 if (rc == LNET_CPT_NUMBER) {
171 LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0]));
176 cfs_expr_list_free(*el); /* consume it */
180 /* LND will fill in the address part of the NID */
181 ni->ni_nid = LNET_MKNID(net, 0);
182 ni->ni_last_alive = cfs_time_current();
183 cfs_list_add_tail(&ni->ni_list, nilist);
191 lnet_parse_networks(cfs_list_t *nilist, char *networks)
193 struct cfs_expr_list *el = NULL;
194 int tokensize = strlen(networks) + 1;
202 if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
203 /* _WAY_ conservative */
204 LCONSOLE_ERROR_MSG(0x112, "Can't parse networks: string too "
209 LIBCFS_ALLOC(tokens, tokensize);
210 if (tokens == NULL) {
211 CERROR("Can't allocate net tokens\n");
215 the_lnet.ln_network_tokens = tokens;
216 the_lnet.ln_network_tokens_nob = tokensize;
217 memcpy (tokens, networks, tokensize);
220 /* Add in the loopback network */
221 ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist);
225 while (str != NULL && *str != 0) {
226 char *comma = strchr(str, ',');
227 char *bracket = strchr(str, '(');
228 char *square = strchr(str, '[');
233 /* NB we don't check interface conflicts here; it's the LNDs
234 * responsibility (if it cares at all) */
236 if (square != NULL && (comma == NULL || square < comma)) {
237 /* i.e: o2ib0(ib0)[1,2], number between square
238 * brackets are CPTs this NI needs to be bond */
239 if (bracket != NULL && bracket > square) {
244 tmp = strchr(square, ']');
250 rc = cfs_expr_list_parse(square, tmp - square + 1,
251 0, LNET_CPT_NUMBER - 1, &el);
257 while (square <= tmp)
261 if (bracket == NULL ||
262 (comma != NULL && comma < bracket)) {
264 /* no interface list specified */
268 net = libcfs_str2net(cfs_trimwhite(str));
270 if (net == LNET_NIDNET(LNET_NID_ANY)) {
271 LCONSOLE_ERROR_MSG(0x113, "Unrecognised network"
277 if (LNET_NETTYP(net) != LOLND && /* LO is implicit */
278 lnet_ni_alloc(net, &el, nilist) == NULL)
286 net = libcfs_str2net(cfs_trimwhite(str));
287 if (net == LNET_NIDNET(LNET_NID_ANY)) {
293 ni = lnet_ni_alloc(net, &el, nilist);
300 bracket = strchr(iface, ')');
301 if (bracket == NULL) {
308 comma = strchr(iface, ',');
312 iface = cfs_trimwhite(iface);
318 if (niface == LNET_MAX_INTERFACES) {
319 LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
321 libcfs_net2str(net));
325 ni->ni_interfaces[niface++] = iface;
327 } while (iface != NULL);
330 comma = strchr(bracket + 1, ',');
333 str = cfs_trimwhite(str);
342 str = cfs_trimwhite(str);
349 LASSERT(!cfs_list_empty(nilist));
353 lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
355 while (!cfs_list_empty(nilist)) {
356 ni = cfs_list_entry(nilist->next, lnet_ni_t, ni_list);
358 cfs_list_del(&ni->ni_list);
363 cfs_expr_list_free(el);
365 LIBCFS_FREE(tokens, tokensize);
366 the_lnet.ln_network_tokens = NULL;
372 lnet_new_text_buf (int str_len)
374 lnet_text_buf_t *ltb;
377 /* NB allocate space for the terminating 0 */
378 nob = offsetof(lnet_text_buf_t, ltb_text[str_len + 1]);
379 if (nob > LNET_SINGLE_TEXTBUF_NOB) {
380 /* _way_ conservative for "route net gateway..." */
381 CERROR("text buffer too big\n");
385 if (lnet_tbnob + nob > LNET_MAX_TEXTBUF_NOB) {
386 CERROR("Too many text buffers\n");
390 LIBCFS_ALLOC(ltb, nob);
395 ltb->ltb_text[0] = 0;
401 lnet_free_text_buf (lnet_text_buf_t *ltb)
403 lnet_tbnob -= ltb->ltb_size;
404 LIBCFS_FREE(ltb, ltb->ltb_size);
408 lnet_free_text_bufs(cfs_list_t *tbs)
410 lnet_text_buf_t *ltb;
412 while (!cfs_list_empty(tbs)) {
413 ltb = cfs_list_entry(tbs->next, lnet_text_buf_t, ltb_list);
415 cfs_list_del(<b->ltb_list);
416 lnet_free_text_buf(ltb);
421 lnet_print_text_bufs(cfs_list_t *tbs)
424 lnet_text_buf_t *ltb;
426 cfs_list_for_each (tmp, tbs) {
427 ltb = cfs_list_entry(tmp, lnet_text_buf_t, ltb_list);
429 CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
432 CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
436 lnet_str2tbs_sep (cfs_list_t *tbs, char *str)
442 lnet_text_buf_t *ltb;
444 CFS_INIT_LIST_HEAD(&pending);
446 /* Split 'str' into separate commands */
448 /* skip leading whitespace */
449 while (cfs_iswhite(*str))
452 /* scan for separator or comment */
453 for (sep = str; *sep != 0; sep++)
454 if (lnet_issep(*sep) || *sep == '#')
457 nob = (int)(sep - str);
459 ltb = lnet_new_text_buf(nob);
461 lnet_free_text_bufs(&pending);
465 for (i = 0; i < nob; i++)
466 if (cfs_iswhite(str[i]))
467 ltb->ltb_text[i] = ' ';
469 ltb->ltb_text[i] = str[i];
471 ltb->ltb_text[nob] = 0;
473 cfs_list_add_tail(<b->ltb_list, &pending);
477 /* scan for separator */
480 } while (*sep != 0 && !lnet_issep(*sep));
489 cfs_list_splice(&pending, tbs->prev);
494 lnet_expand1tb (cfs_list_t *list,
495 char *str, char *sep1, char *sep2,
496 char *item, int itemlen)
498 int len1 = (int)(sep1 - str);
499 int len2 = strlen(sep2 + 1);
500 lnet_text_buf_t *ltb;
502 LASSERT (*sep1 == '[');
503 LASSERT (*sep2 == ']');
505 ltb = lnet_new_text_buf(len1 + itemlen + len2);
509 memcpy(ltb->ltb_text, str, len1);
510 memcpy(<b->ltb_text[len1], item, itemlen);
511 memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2);
512 ltb->ltb_text[len1 + itemlen + len2] = 0;
514 cfs_list_add_tail(<b->ltb_list, list);
519 lnet_str2tbs_expand (cfs_list_t *tbs, char *str)
534 CFS_INIT_LIST_HEAD(&pending);
536 sep = strchr(str, '[');
537 if (sep == NULL) /* nothing to expand */
540 sep2 = strchr(sep, ']');
544 for (parsed = sep; parsed < sep2; parsed = enditem) {
547 while (enditem < sep2 && *enditem != ',')
550 if (enditem == parsed) /* no empty items */
553 if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
555 if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
557 /* simple string enumeration */
558 if (lnet_expand1tb(&pending, str, sep, sep2,
559 parsed, (int)(enditem - parsed)) != 0)
568 /* range expansion */
570 if (enditem != parsed + scanned) /* no trailing junk */
573 if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
574 (hi - lo) % stride != 0)
577 for (i = lo; i <= hi; i += stride) {
579 snprintf(num, sizeof(num), "%d", i);
581 if (nob + 1 == sizeof(num))
584 if (lnet_expand1tb(&pending, str, sep, sep2,
590 cfs_list_splice(&pending, tbs->prev);
594 lnet_free_text_bufs(&pending);
599 lnet_parse_hops (char *str, unsigned int *hops)
601 int len = strlen(str);
604 return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
606 *hops > 0 && *hops < 256);
611 lnet_parse_route (char *str, int *im_a_router)
613 /* static scratch buffer OK (single threaded) */
614 static char cmd[LNET_SINGLE_TEXTBUF_NOB];
622 lnet_text_buf_t *ltb;
631 CFS_INIT_LIST_HEAD(&gateways);
632 CFS_INIT_LIST_HEAD(&nets);
634 /* save a copy of the string for error messages */
635 strncpy(cmd, str, sizeof(cmd) - 1);
636 cmd[sizeof(cmd) - 1] = 0;
640 /* scan for token start */
641 while (cfs_iswhite(*sep))
644 if (ntokens < (got_hops ? 3 : 2))
652 /* scan for token end */
653 while (*sep != 0 && !cfs_iswhite(*sep))
659 tmp2 = &nets; /* expanding nets */
660 } else if (ntokens == 2 &&
661 lnet_parse_hops(token, &hops)) {
662 got_hops = 1; /* got a hop count */
665 tmp2 = &gateways; /* expanding gateways */
668 ltb = lnet_new_text_buf(strlen(token));
672 strcpy(ltb->ltb_text, token);
673 tmp1 = <b->ltb_list;
674 cfs_list_add_tail(tmp1, tmp2);
676 while (tmp1 != tmp2) {
677 ltb = cfs_list_entry(tmp1, lnet_text_buf_t, ltb_list);
679 rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
685 if (rc > 0) { /* expanded! */
686 cfs_list_del(<b->ltb_list);
687 lnet_free_text_buf(ltb);
692 net = libcfs_str2net(ltb->ltb_text);
693 if (net == LNET_NIDNET(LNET_NID_ANY) ||
694 LNET_NETTYP(net) == LOLND)
697 nid = libcfs_str2nid(ltb->ltb_text);
698 if (nid == LNET_NID_ANY ||
699 LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
708 LASSERT (!cfs_list_empty(&nets));
709 LASSERT (!cfs_list_empty(&gateways));
711 cfs_list_for_each (tmp1, &nets) {
712 ltb = cfs_list_entry(tmp1, lnet_text_buf_t, ltb_list);
713 net = libcfs_str2net(ltb->ltb_text);
714 LASSERT (net != LNET_NIDNET(LNET_NID_ANY));
716 cfs_list_for_each (tmp2, &gateways) {
717 ltb = cfs_list_entry(tmp2, lnet_text_buf_t, ltb_list);
718 nid = libcfs_str2nid(ltb->ltb_text);
719 LASSERT (nid != LNET_NID_ANY);
721 if (lnet_islocalnid(nid)) {
726 rc = lnet_add_route (net, hops, nid);
728 CERROR("Can't create route "
731 libcfs_nid2str(nid));
741 lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
743 lnet_free_text_bufs(&nets);
744 lnet_free_text_bufs(&gateways);
749 lnet_parse_route_tbs(cfs_list_t *tbs, int *im_a_router)
751 lnet_text_buf_t *ltb;
753 while (!cfs_list_empty(tbs)) {
754 ltb = cfs_list_entry(tbs->next, lnet_text_buf_t, ltb_list);
756 if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
757 lnet_free_text_bufs(tbs);
761 cfs_list_del(<b->ltb_list);
762 lnet_free_text_buf(ltb);
769 lnet_parse_routes (char *routes, int *im_a_router)
776 CFS_INIT_LIST_HEAD(&tbs);
778 if (lnet_str2tbs_sep(&tbs, routes) < 0) {
779 CERROR("Error parsing routes\n");
782 rc = lnet_parse_route_tbs(&tbs, im_a_router);
785 LASSERT (lnet_tbnob == 0);
790 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
792 CFS_LIST_HEAD (list);
796 rc = cfs_ip_addr_parse(token, len, &list);
800 for (rc = i = 0; !rc && i < nip; i++)
801 rc = cfs_ip_addr_match(ipaddrs[i], &list);
803 cfs_ip_addr_free(&list);
809 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
811 static char tokens[LNET_SINGLE_TEXTBUF_NOB];
821 LASSERT (strlen(net_entry) < sizeof(tokens));
823 /* work on a copy of the string */
824 strcpy(tokens, net_entry);
827 /* scan for token start */
828 while (cfs_iswhite(*sep))
835 /* scan for token end */
836 while (*sep != 0 && !cfs_iswhite(*sep))
841 if (ntokens++ == 0) {
848 rc = lnet_match_network_token(token, len, ipaddrs, nip);
850 lnet_syntax("ip2nets", net_entry,
851 (int)(token - tokens), len);
855 matched |= (rc != 0);
861 strcpy(net_entry, net); /* replace with matched net */
866 lnet_netspec2net(char *netspec)
868 char *bracket = strchr(netspec, '(');
874 net = libcfs_str2net(netspec);
883 lnet_splitnets(char *source, cfs_list_t *nets)
889 lnet_text_buf_t *tb2;
895 LASSERT (!cfs_list_empty(nets));
896 LASSERT (nets->next == nets->prev); /* single entry */
898 tb = cfs_list_entry(nets->next, lnet_text_buf_t, ltb_list);
901 sep = strchr(tb->ltb_text, ',');
902 bracket = strchr(tb->ltb_text, '(');
907 /* netspec lists interfaces... */
909 offset2 = offset + (int)(bracket - tb->ltb_text);
910 len = strlen(bracket);
912 bracket = strchr(bracket + 1, ')');
914 if (bracket == NULL ||
915 !(bracket[1] == ',' || bracket[1] == 0)) {
916 lnet_syntax("ip2nets", source, offset2, len);
920 sep = (bracket[1] == 0) ? NULL : bracket + 1;
926 net = lnet_netspec2net(tb->ltb_text);
927 if (net == LNET_NIDNET(LNET_NID_ANY)) {
928 lnet_syntax("ip2nets", source, offset,
929 strlen(tb->ltb_text));
933 cfs_list_for_each(t, nets) {
934 tb2 = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
939 if (net == lnet_netspec2net(tb2->ltb_text)) {
940 /* duplicate network */
941 lnet_syntax("ip2nets", source, offset,
942 strlen(tb->ltb_text));
950 offset += (int)(sep - tb->ltb_text);
951 tb2 = lnet_new_text_buf(strlen(sep));
955 strcpy(tb2->ltb_text, sep);
956 cfs_list_add_tail(&tb2->ltb_list, nets);
963 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
965 static char networks[LNET_SINGLE_TEXTBUF_NOB];
966 static char source[LNET_SINGLE_TEXTBUF_NOB];
968 cfs_list_t raw_entries;
969 cfs_list_t matched_nets;
970 cfs_list_t current_nets;
974 lnet_text_buf_t *tb2;
982 CFS_INIT_LIST_HEAD(&raw_entries);
983 if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
984 CERROR("Error parsing ip2nets\n");
985 LASSERT (lnet_tbnob == 0);
989 CFS_INIT_LIST_HEAD(&matched_nets);
990 CFS_INIT_LIST_HEAD(¤t_nets);
996 while (!cfs_list_empty(&raw_entries)) {
997 tb = cfs_list_entry(raw_entries.next, lnet_text_buf_t,
1000 strncpy(source, tb->ltb_text, sizeof(source)-1);
1001 source[sizeof(source)-1] = 0;
1003 /* replace ltb_text with the network(s) add on match */
1004 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
1008 cfs_list_del(&tb->ltb_list);
1010 if (rc == 0) { /* no match */
1011 lnet_free_text_buf(tb);
1015 /* split into separate networks */
1016 CFS_INIT_LIST_HEAD(¤t_nets);
1017 cfs_list_add(&tb->ltb_list, ¤t_nets);
1018 rc = lnet_splitnets(source, ¤t_nets);
1023 cfs_list_for_each (t, ¤t_nets) {
1024 tb = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
1025 net1 = lnet_netspec2net(tb->ltb_text);
1026 LASSERT (net1 != LNET_NIDNET(LNET_NID_ANY));
1028 cfs_list_for_each(t2, &matched_nets) {
1029 tb2 = cfs_list_entry(t2, lnet_text_buf_t,
1031 net2 = lnet_netspec2net(tb2->ltb_text);
1032 LASSERT (net2 != LNET_NIDNET(LNET_NID_ANY));
1045 lnet_free_text_bufs(¤t_nets);
1049 cfs_list_for_each_safe(t, t2, ¤t_nets) {
1050 tb = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
1052 cfs_list_del(&tb->ltb_list);
1053 cfs_list_add_tail(&tb->ltb_list, &matched_nets);
1055 len += snprintf(networks + len, sizeof(networks) - len,
1056 "%s%s", (len == 0) ? "" : ",",
1059 if (len >= sizeof(networks)) {
1060 CERROR("Too many matched networks\n");
1070 lnet_free_text_bufs(&raw_entries);
1071 lnet_free_text_bufs(&matched_nets);
1072 lnet_free_text_bufs(¤t_nets);
1073 LASSERT (lnet_tbnob == 0);
1078 *networksp = networks;
1084 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
1086 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
1090 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
1098 int nif = libcfs_ipif_enumerate(&ifnames);
1105 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
1106 if (ipaddrs == NULL) {
1107 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1108 libcfs_ipif_free_enumeration(ifnames, nif);
1112 for (i = nip = 0; i < nif; i++) {
1113 if (!strcmp(ifnames[i], "lo"))
1116 rc = libcfs_ipif_query(ifnames[i], &up,
1117 &ipaddrs[nip], &netmask);
1119 CWARN("Can't query interface %s: %d\n",
1125 CWARN("Ignoring interface %s: it's down\n",
1133 libcfs_ipif_free_enumeration(ifnames, nif);
1136 *ipaddrsp = ipaddrs;
1139 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
1140 if (ipaddrs2 == NULL) {
1141 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1144 memcpy(ipaddrs2, ipaddrs,
1145 nip * sizeof(*ipaddrs));
1146 *ipaddrsp = ipaddrs2;
1150 lnet_ipaddr_free_enumeration(ipaddrs, nif);
1156 lnet_parse_ip2nets (char **networksp, char *ip2nets)
1159 int nip = lnet_ipaddr_enumerate(&ipaddrs);
1163 LCONSOLE_ERROR_MSG(0x117, "Error %d enumerating local IP "
1164 "interfaces for ip2nets to match\n", nip);
1169 LCONSOLE_ERROR_MSG(0x118, "No local IP interfaces "
1170 "for ip2nets to match\n");
1174 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1175 lnet_ipaddr_free_enumeration(ipaddrs, nip);
1178 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
1183 LCONSOLE_ERROR_MSG(0x11a, "ip2nets does not match "
1184 "any local IP interfaces\n");
1192 lnet_set_ip_niaddr (lnet_ni_t *ni)
1194 __u32 net = LNET_NIDNET(ni->ni_nid);
1203 /* Convenience for LNDs that use the IP address of a local interface as
1204 * the local address part of their NID */
1206 if (ni->ni_interfaces[0] != NULL) {
1208 CLASSERT (LNET_MAX_INTERFACES > 1);
1210 if (ni->ni_interfaces[1] != NULL) {
1211 CERROR("Net %s doesn't support multiple interfaces\n",
1212 libcfs_net2str(net));
1216 rc = libcfs_ipif_query(ni->ni_interfaces[0],
1217 &up, &ip, &netmask);
1219 CERROR("Net %s can't query interface %s: %d\n",
1220 libcfs_net2str(net), ni->ni_interfaces[0], rc);
1225 CERROR("Net %s can't use interface %s: it's down\n",
1226 libcfs_net2str(net), ni->ni_interfaces[0]);
1230 ni->ni_nid = LNET_MKNID(net, ip);
1234 n = libcfs_ipif_enumerate(&names);
1236 CERROR("Net %s can't enumerate interfaces: %d\n",
1237 libcfs_net2str(net), n);
1241 for (i = 0; i < n; i++) {
1242 if (!strcmp(names[i], "lo")) /* skip the loopback IF */
1245 rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
1248 CWARN("Net %s can't query interface %s: %d\n",
1249 libcfs_net2str(net), names[i], rc);
1254 CWARN("Net %s ignoring interface %s (down)\n",
1255 libcfs_net2str(net), names[i]);
1259 libcfs_ipif_free_enumeration(names, n);
1260 ni->ni_nid = LNET_MKNID(net, ip);
1264 CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
1265 libcfs_ipif_free_enumeration(names, n);
1268 EXPORT_SYMBOL(lnet_set_ip_niaddr);