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 cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
107 # ifdef HAVE_LIBPTHREAD
108 pthread_mutex_destroy(&ni->ni_lock);
111 LIBCFS_FREE(ni, sizeof(*ni));
115 lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, cfs_list_t *nilist)
117 struct lnet_tx_queue *tq;
122 if (!lnet_net_unique(net, nilist)) {
123 LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n",
124 libcfs_net2str(net));
128 LIBCFS_ALLOC(ni, sizeof(*ni));
130 CERROR("Out of memory creating network %s\n",
131 libcfs_net2str(net));
136 cfs_spin_lock_init(&ni->ni_lock);
138 # ifdef HAVE_LIBPTHREAD
139 pthread_mutex_init(&ni->ni_lock, NULL);
142 CFS_INIT_LIST_HEAD(&ni->ni_cptlist);
143 ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
144 sizeof(*ni->ni_refs[0]));
145 if (ni->ni_refs == NULL)
148 ni->ni_tx_queues = cfs_percpt_alloc(lnet_cpt_table(),
149 sizeof(*ni->ni_tx_queues[0]));
150 if (ni->ni_tx_queues == NULL)
153 cfs_percpt_for_each(tq, i, ni->ni_tx_queues)
154 CFS_INIT_LIST_HEAD(&tq->tq_delayed);
158 ni->ni_ncpts = LNET_CPT_NUMBER;
160 rc = cfs_expr_list_values(el, LNET_CPT_NUMBER, &ni->ni_cpts);
162 CERROR("Failed to set CPTs for NI %s: %d\n",
163 libcfs_net2str(net), rc);
167 LASSERT(rc <= LNET_CPT_NUMBER);
168 if (rc == LNET_CPT_NUMBER) {
169 LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0]));
176 /* LND will fill in the address part of the NID */
177 ni->ni_nid = LNET_MKNID(net, 0);
178 ni->ni_last_alive = cfs_time_current_sec();
179 cfs_list_add_tail(&ni->ni_list, nilist);
187 lnet_parse_networks(cfs_list_t *nilist, char *networks)
189 struct cfs_expr_list *el = NULL;
190 int tokensize = strlen(networks) + 1;
198 if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
199 /* _WAY_ conservative */
200 LCONSOLE_ERROR_MSG(0x112, "Can't parse networks: string too "
205 LIBCFS_ALLOC(tokens, tokensize);
206 if (tokens == NULL) {
207 CERROR("Can't allocate net tokens\n");
211 the_lnet.ln_network_tokens = tokens;
212 the_lnet.ln_network_tokens_nob = tokensize;
213 memcpy (tokens, networks, tokensize);
216 /* Add in the loopback network */
217 ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist);
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)) {
294 ni = lnet_ni_alloc(net, el, nilist);
299 cfs_expr_list_free(el);
306 bracket = strchr(iface, ')');
307 if (bracket == NULL) {
314 comma = strchr(iface, ',');
318 iface = cfs_trimwhite(iface);
324 if (niface == LNET_MAX_INTERFACES) {
325 LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
327 libcfs_net2str(net));
331 ni->ni_interfaces[niface++] = iface;
333 } while (iface != NULL);
336 comma = strchr(bracket + 1, ',');
339 str = cfs_trimwhite(str);
348 str = cfs_trimwhite(str);
355 LASSERT(!cfs_list_empty(nilist));
359 lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
361 while (!cfs_list_empty(nilist)) {
362 ni = cfs_list_entry(nilist->next, lnet_ni_t, ni_list);
364 cfs_list_del(&ni->ni_list);
369 cfs_expr_list_free(el);
371 LIBCFS_FREE(tokens, tokensize);
372 the_lnet.ln_network_tokens = NULL;
378 lnet_new_text_buf (int str_len)
380 lnet_text_buf_t *ltb;
383 /* NB allocate space for the terminating 0 */
384 nob = offsetof(lnet_text_buf_t, ltb_text[str_len + 1]);
385 if (nob > LNET_SINGLE_TEXTBUF_NOB) {
386 /* _way_ conservative for "route net gateway..." */
387 CERROR("text buffer too big\n");
391 if (lnet_tbnob + nob > LNET_MAX_TEXTBUF_NOB) {
392 CERROR("Too many text buffers\n");
396 LIBCFS_ALLOC(ltb, nob);
401 ltb->ltb_text[0] = 0;
407 lnet_free_text_buf (lnet_text_buf_t *ltb)
409 lnet_tbnob -= ltb->ltb_size;
410 LIBCFS_FREE(ltb, ltb->ltb_size);
414 lnet_free_text_bufs(cfs_list_t *tbs)
416 lnet_text_buf_t *ltb;
418 while (!cfs_list_empty(tbs)) {
419 ltb = cfs_list_entry(tbs->next, lnet_text_buf_t, ltb_list);
421 cfs_list_del(<b->ltb_list);
422 lnet_free_text_buf(ltb);
427 lnet_print_text_bufs(cfs_list_t *tbs)
430 lnet_text_buf_t *ltb;
432 cfs_list_for_each (tmp, tbs) {
433 ltb = cfs_list_entry(tmp, lnet_text_buf_t, ltb_list);
435 CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
438 CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
442 lnet_str2tbs_sep (cfs_list_t *tbs, char *str)
448 lnet_text_buf_t *ltb;
450 CFS_INIT_LIST_HEAD(&pending);
452 /* Split 'str' into separate commands */
454 /* skip leading whitespace */
455 while (cfs_iswhite(*str))
458 /* scan for separator or comment */
459 for (sep = str; *sep != 0; sep++)
460 if (lnet_issep(*sep) || *sep == '#')
463 nob = (int)(sep - str);
465 ltb = lnet_new_text_buf(nob);
467 lnet_free_text_bufs(&pending);
471 for (i = 0; i < nob; i++)
472 if (cfs_iswhite(str[i]))
473 ltb->ltb_text[i] = ' ';
475 ltb->ltb_text[i] = str[i];
477 ltb->ltb_text[nob] = 0;
479 cfs_list_add_tail(<b->ltb_list, &pending);
483 /* scan for separator */
486 } while (*sep != 0 && !lnet_issep(*sep));
495 cfs_list_splice(&pending, tbs->prev);
500 lnet_expand1tb (cfs_list_t *list,
501 char *str, char *sep1, char *sep2,
502 char *item, int itemlen)
504 int len1 = (int)(sep1 - str);
505 int len2 = strlen(sep2 + 1);
506 lnet_text_buf_t *ltb;
508 LASSERT (*sep1 == '[');
509 LASSERT (*sep2 == ']');
511 ltb = lnet_new_text_buf(len1 + itemlen + len2);
515 memcpy(ltb->ltb_text, str, len1);
516 memcpy(<b->ltb_text[len1], item, itemlen);
517 memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2);
518 ltb->ltb_text[len1 + itemlen + len2] = 0;
520 cfs_list_add_tail(<b->ltb_list, list);
525 lnet_str2tbs_expand (cfs_list_t *tbs, char *str)
540 CFS_INIT_LIST_HEAD(&pending);
542 sep = strchr(str, '[');
543 if (sep == NULL) /* nothing to expand */
546 sep2 = strchr(sep, ']');
550 for (parsed = sep; parsed < sep2; parsed = enditem) {
553 while (enditem < sep2 && *enditem != ',')
556 if (enditem == parsed) /* no empty items */
559 if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
561 if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
563 /* simple string enumeration */
564 if (lnet_expand1tb(&pending, str, sep, sep2,
565 parsed, (int)(enditem - parsed)) != 0)
574 /* range expansion */
576 if (enditem != parsed + scanned) /* no trailing junk */
579 if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
580 (hi - lo) % stride != 0)
583 for (i = lo; i <= hi; i += stride) {
585 snprintf(num, sizeof(num), "%d", i);
587 if (nob + 1 == sizeof(num))
590 if (lnet_expand1tb(&pending, str, sep, sep2,
596 cfs_list_splice(&pending, tbs->prev);
600 lnet_free_text_bufs(&pending);
605 lnet_parse_hops (char *str, unsigned int *hops)
607 int len = strlen(str);
610 return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
612 *hops > 0 && *hops < 256);
617 lnet_parse_route (char *str, int *im_a_router)
619 /* static scratch buffer OK (single threaded) */
620 static char cmd[LNET_SINGLE_TEXTBUF_NOB];
628 lnet_text_buf_t *ltb;
637 CFS_INIT_LIST_HEAD(&gateways);
638 CFS_INIT_LIST_HEAD(&nets);
640 /* save a copy of the string for error messages */
641 strncpy(cmd, str, sizeof(cmd) - 1);
642 cmd[sizeof(cmd) - 1] = 0;
646 /* scan for token start */
647 while (cfs_iswhite(*sep))
650 if (ntokens < (got_hops ? 3 : 2))
658 /* scan for token end */
659 while (*sep != 0 && !cfs_iswhite(*sep))
665 tmp2 = &nets; /* expanding nets */
666 } else if (ntokens == 2 &&
667 lnet_parse_hops(token, &hops)) {
668 got_hops = 1; /* got a hop count */
671 tmp2 = &gateways; /* expanding gateways */
674 ltb = lnet_new_text_buf(strlen(token));
678 strcpy(ltb->ltb_text, token);
679 tmp1 = <b->ltb_list;
680 cfs_list_add_tail(tmp1, tmp2);
682 while (tmp1 != tmp2) {
683 ltb = cfs_list_entry(tmp1, lnet_text_buf_t, ltb_list);
685 rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
691 if (rc > 0) { /* expanded! */
692 cfs_list_del(<b->ltb_list);
693 lnet_free_text_buf(ltb);
698 net = libcfs_str2net(ltb->ltb_text);
699 if (net == LNET_NIDNET(LNET_NID_ANY) ||
700 LNET_NETTYP(net) == LOLND)
703 nid = libcfs_str2nid(ltb->ltb_text);
704 if (nid == LNET_NID_ANY ||
705 LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
714 LASSERT (!cfs_list_empty(&nets));
715 LASSERT (!cfs_list_empty(&gateways));
717 cfs_list_for_each (tmp1, &nets) {
718 ltb = cfs_list_entry(tmp1, lnet_text_buf_t, ltb_list);
719 net = libcfs_str2net(ltb->ltb_text);
720 LASSERT (net != LNET_NIDNET(LNET_NID_ANY));
722 cfs_list_for_each (tmp2, &gateways) {
723 ltb = cfs_list_entry(tmp2, lnet_text_buf_t, ltb_list);
724 nid = libcfs_str2nid(ltb->ltb_text);
725 LASSERT (nid != LNET_NID_ANY);
727 if (lnet_islocalnid(nid)) {
732 rc = lnet_add_route (net, hops, nid);
734 CERROR("Can't create route "
737 libcfs_nid2str(nid));
747 lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
749 lnet_free_text_bufs(&nets);
750 lnet_free_text_bufs(&gateways);
755 lnet_parse_route_tbs(cfs_list_t *tbs, int *im_a_router)
757 lnet_text_buf_t *ltb;
759 while (!cfs_list_empty(tbs)) {
760 ltb = cfs_list_entry(tbs->next, lnet_text_buf_t, ltb_list);
762 if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
763 lnet_free_text_bufs(tbs);
767 cfs_list_del(<b->ltb_list);
768 lnet_free_text_buf(ltb);
775 lnet_parse_routes (char *routes, int *im_a_router)
782 CFS_INIT_LIST_HEAD(&tbs);
784 if (lnet_str2tbs_sep(&tbs, routes) < 0) {
785 CERROR("Error parsing routes\n");
788 rc = lnet_parse_route_tbs(&tbs, im_a_router);
791 LASSERT (lnet_tbnob == 0);
796 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
798 CFS_LIST_HEAD (list);
802 rc = cfs_ip_addr_parse(token, len, &list);
806 for (rc = i = 0; !rc && i < nip; i++)
807 rc = cfs_ip_addr_match(ipaddrs[i], &list);
809 cfs_ip_addr_free(&list);
815 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
817 static char tokens[LNET_SINGLE_TEXTBUF_NOB];
827 LASSERT (strlen(net_entry) < sizeof(tokens));
829 /* work on a copy of the string */
830 strcpy(tokens, net_entry);
833 /* scan for token start */
834 while (cfs_iswhite(*sep))
841 /* scan for token end */
842 while (*sep != 0 && !cfs_iswhite(*sep))
847 if (ntokens++ == 0) {
854 rc = lnet_match_network_token(token, len, ipaddrs, nip);
856 lnet_syntax("ip2nets", net_entry,
857 (int)(token - tokens), len);
861 matched |= (rc != 0);
867 strcpy(net_entry, net); /* replace with matched net */
872 lnet_netspec2net(char *netspec)
874 char *bracket = strchr(netspec, '(');
880 net = libcfs_str2net(netspec);
889 lnet_splitnets(char *source, cfs_list_t *nets)
895 lnet_text_buf_t *tb2;
901 LASSERT (!cfs_list_empty(nets));
902 LASSERT (nets->next == nets->prev); /* single entry */
904 tb = cfs_list_entry(nets->next, lnet_text_buf_t, ltb_list);
907 sep = strchr(tb->ltb_text, ',');
908 bracket = strchr(tb->ltb_text, '(');
913 /* netspec lists interfaces... */
915 offset2 = offset + (int)(bracket - tb->ltb_text);
916 len = strlen(bracket);
918 bracket = strchr(bracket + 1, ')');
920 if (bracket == NULL ||
921 !(bracket[1] == ',' || bracket[1] == 0)) {
922 lnet_syntax("ip2nets", source, offset2, len);
926 sep = (bracket[1] == 0) ? NULL : bracket + 1;
932 net = lnet_netspec2net(tb->ltb_text);
933 if (net == LNET_NIDNET(LNET_NID_ANY)) {
934 lnet_syntax("ip2nets", source, offset,
935 strlen(tb->ltb_text));
939 cfs_list_for_each(t, nets) {
940 tb2 = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
945 if (net == lnet_netspec2net(tb2->ltb_text)) {
946 /* duplicate network */
947 lnet_syntax("ip2nets", source, offset,
948 strlen(tb->ltb_text));
956 offset += (int)(sep - tb->ltb_text);
957 tb2 = lnet_new_text_buf(strlen(sep));
961 strcpy(tb2->ltb_text, sep);
962 cfs_list_add_tail(&tb2->ltb_list, nets);
969 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
971 static char networks[LNET_SINGLE_TEXTBUF_NOB];
972 static char source[LNET_SINGLE_TEXTBUF_NOB];
974 cfs_list_t raw_entries;
975 cfs_list_t matched_nets;
976 cfs_list_t current_nets;
980 lnet_text_buf_t *tb2;
988 CFS_INIT_LIST_HEAD(&raw_entries);
989 if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
990 CERROR("Error parsing ip2nets\n");
991 LASSERT (lnet_tbnob == 0);
995 CFS_INIT_LIST_HEAD(&matched_nets);
996 CFS_INIT_LIST_HEAD(¤t_nets);
1002 while (!cfs_list_empty(&raw_entries)) {
1003 tb = cfs_list_entry(raw_entries.next, lnet_text_buf_t,
1006 strncpy(source, tb->ltb_text, sizeof(source)-1);
1007 source[sizeof(source)-1] = 0;
1009 /* replace ltb_text with the network(s) add on match */
1010 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
1014 cfs_list_del(&tb->ltb_list);
1016 if (rc == 0) { /* no match */
1017 lnet_free_text_buf(tb);
1021 /* split into separate networks */
1022 CFS_INIT_LIST_HEAD(¤t_nets);
1023 cfs_list_add(&tb->ltb_list, ¤t_nets);
1024 rc = lnet_splitnets(source, ¤t_nets);
1029 cfs_list_for_each (t, ¤t_nets) {
1030 tb = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
1031 net1 = lnet_netspec2net(tb->ltb_text);
1032 LASSERT (net1 != LNET_NIDNET(LNET_NID_ANY));
1034 cfs_list_for_each(t2, &matched_nets) {
1035 tb2 = cfs_list_entry(t2, lnet_text_buf_t,
1037 net2 = lnet_netspec2net(tb2->ltb_text);
1038 LASSERT (net2 != LNET_NIDNET(LNET_NID_ANY));
1051 lnet_free_text_bufs(¤t_nets);
1055 cfs_list_for_each_safe(t, t2, ¤t_nets) {
1056 tb = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
1058 cfs_list_del(&tb->ltb_list);
1059 cfs_list_add_tail(&tb->ltb_list, &matched_nets);
1061 len += snprintf(networks + len, sizeof(networks) - len,
1062 "%s%s", (len == 0) ? "" : ",",
1065 if (len >= sizeof(networks)) {
1066 CERROR("Too many matched networks\n");
1076 lnet_free_text_bufs(&raw_entries);
1077 lnet_free_text_bufs(&matched_nets);
1078 lnet_free_text_bufs(¤t_nets);
1079 LASSERT (lnet_tbnob == 0);
1084 *networksp = networks;
1090 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
1092 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
1096 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
1104 int nif = libcfs_ipif_enumerate(&ifnames);
1111 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
1112 if (ipaddrs == NULL) {
1113 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1114 libcfs_ipif_free_enumeration(ifnames, nif);
1118 for (i = nip = 0; i < nif; i++) {
1119 if (!strcmp(ifnames[i], "lo"))
1122 rc = libcfs_ipif_query(ifnames[i], &up,
1123 &ipaddrs[nip], &netmask);
1125 CWARN("Can't query interface %s: %d\n",
1131 CWARN("Ignoring interface %s: it's down\n",
1139 libcfs_ipif_free_enumeration(ifnames, nif);
1142 *ipaddrsp = ipaddrs;
1145 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
1146 if (ipaddrs2 == NULL) {
1147 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1150 memcpy(ipaddrs2, ipaddrs,
1151 nip * sizeof(*ipaddrs));
1152 *ipaddrsp = ipaddrs2;
1156 lnet_ipaddr_free_enumeration(ipaddrs, nif);
1162 lnet_parse_ip2nets (char **networksp, char *ip2nets)
1165 int nip = lnet_ipaddr_enumerate(&ipaddrs);
1169 LCONSOLE_ERROR_MSG(0x117, "Error %d enumerating local IP "
1170 "interfaces for ip2nets to match\n", nip);
1175 LCONSOLE_ERROR_MSG(0x118, "No local IP interfaces "
1176 "for ip2nets to match\n");
1180 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1181 lnet_ipaddr_free_enumeration(ipaddrs, nip);
1184 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
1189 LCONSOLE_ERROR_MSG(0x11a, "ip2nets does not match "
1190 "any local IP interfaces\n");
1198 lnet_set_ip_niaddr (lnet_ni_t *ni)
1200 __u32 net = LNET_NIDNET(ni->ni_nid);
1209 /* Convenience for LNDs that use the IP address of a local interface as
1210 * the local address part of their NID */
1212 if (ni->ni_interfaces[0] != NULL) {
1214 CLASSERT (LNET_MAX_INTERFACES > 1);
1216 if (ni->ni_interfaces[1] != NULL) {
1217 CERROR("Net %s doesn't support multiple interfaces\n",
1218 libcfs_net2str(net));
1222 rc = libcfs_ipif_query(ni->ni_interfaces[0],
1223 &up, &ip, &netmask);
1225 CERROR("Net %s can't query interface %s: %d\n",
1226 libcfs_net2str(net), ni->ni_interfaces[0], rc);
1231 CERROR("Net %s can't use interface %s: it's down\n",
1232 libcfs_net2str(net), ni->ni_interfaces[0]);
1236 ni->ni_nid = LNET_MKNID(net, ip);
1240 n = libcfs_ipif_enumerate(&names);
1242 CERROR("Net %s can't enumerate interfaces: %d\n",
1243 libcfs_net2str(net), n);
1247 for (i = 0; i < n; i++) {
1248 if (!strcmp(names[i], "lo")) /* skip the loopback IF */
1251 rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
1254 CWARN("Net %s can't query interface %s: %d\n",
1255 libcfs_net2str(net), names[i], rc);
1260 CWARN("Net %s ignoring interface %s (down)\n",
1261 libcfs_net2str(net), names[i]);
1265 libcfs_ipif_free_enumeration(names, n);
1266 ni->ni_nid = LNET_MKNID(net, ip);
1270 CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
1271 libcfs_ipif_free_enumeration(names, n);
1274 EXPORT_SYMBOL(lnet_set_ip_niaddr);