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, 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 typedef struct { /* tmp struct for parsing routes */
41 cfs_list_t ltb_list; /* stash on lists */
42 int ltb_size; /* allocated size */
43 char ltb_text[0]; /* text buffer */
46 static int lnet_tbnob = 0; /* track text buf allocation */
47 #define LNET_MAX_TEXTBUF_NOB (64<<10) /* bound allocation */
48 #define LNET_SINGLE_TEXTBUF_NOB (4<<10)
51 lnet_syntax(char *name, char *str, int offset, int width)
53 static char dots[LNET_SINGLE_TEXTBUF_NOB];
54 static char dashes[LNET_SINGLE_TEXTBUF_NOB];
56 memset(dots, '.', sizeof(dots));
57 dots[sizeof(dots)-1] = 0;
58 memset(dashes, '-', sizeof(dashes));
59 dashes[sizeof(dashes)-1] = 0;
61 LCONSOLE_ERROR_MSG(0x10f, "Error parsing '%s=\"%s\"'\n", name, str);
62 LCONSOLE_ERROR_MSG(0x110, "here...........%.*s..%.*s|%.*s|\n",
63 (int)strlen(name), dots, offset, dots,
64 (width < 1) ? 0 : width - 1, dashes);
81 lnet_net_unique(__u32 net, cfs_list_t *nilist)
86 cfs_list_for_each (tmp, nilist) {
87 ni = cfs_list_entry(tmp, lnet_ni_t, ni_list);
89 if (LNET_NIDNET(ni->ni_nid) == net)
97 lnet_ni_free(struct lnet_ni *ni)
99 if (ni->ni_refs != NULL)
100 cfs_percpt_free(ni->ni_refs);
102 if (ni->ni_tx_queues != NULL)
103 cfs_percpt_free(ni->ni_tx_queues);
105 if (ni->ni_cpts != NULL)
106 cfs_expr_list_values_free(ni->ni_cpts, 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 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);
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]));
178 /* LND will fill in the address part of the NID */
179 ni->ni_nid = LNET_MKNID(net, 0);
180 ni->ni_last_alive = cfs_time_current_sec();
181 cfs_list_add_tail(&ni->ni_list, nilist);
189 lnet_parse_networks(cfs_list_t *nilist, char *networks)
191 struct cfs_expr_list *el = NULL;
192 int tokensize = strlen(networks) + 1;
200 if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
201 /* _WAY_ conservative */
202 LCONSOLE_ERROR_MSG(0x112, "Can't parse networks: string too "
207 LIBCFS_ALLOC(tokens, tokensize);
208 if (tokens == NULL) {
209 CERROR("Can't allocate net tokens\n");
213 the_lnet.ln_network_tokens = tokens;
214 the_lnet.ln_network_tokens_nob = tokensize;
215 memcpy (tokens, networks, tokensize);
218 /* Add in the loopback network */
219 ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist);
223 while (str != NULL && *str != 0) {
224 char *comma = strchr(str, ',');
225 char *bracket = strchr(str, '(');
226 char *square = strchr(str, '[');
231 /* NB we don't check interface conflicts here; it's the LNDs
232 * responsibility (if it cares at all) */
234 if (square != NULL && (comma == NULL || square < comma)) {
235 /* i.e: o2ib0(ib0)[1,2], number between square
236 * brackets are CPTs this NI needs to be bond */
237 if (bracket != NULL && bracket > square) {
242 tmp = strchr(square, ']');
248 rc = cfs_expr_list_parse(square, tmp - square + 1,
249 0, LNET_CPT_NUMBER - 1, &el);
255 while (square <= tmp)
259 if (bracket == NULL ||
260 (comma != NULL && comma < bracket)) {
262 /* no interface list specified */
266 net = libcfs_str2net(cfs_trimwhite(str));
268 if (net == LNET_NIDNET(LNET_NID_ANY)) {
269 LCONSOLE_ERROR_MSG(0x113, "Unrecognised network"
275 if (LNET_NETTYP(net) != LOLND && /* LO is implicit */
276 lnet_ni_alloc(net, el, nilist) == NULL)
280 cfs_expr_list_free(el);
289 net = libcfs_str2net(cfs_trimwhite(str));
290 if (net == LNET_NIDNET(LNET_NID_ANY)) {
296 ni = lnet_ni_alloc(net, el, nilist);
301 cfs_expr_list_free(el);
308 bracket = strchr(iface, ')');
309 if (bracket == NULL) {
316 comma = strchr(iface, ',');
320 iface = cfs_trimwhite(iface);
326 if (niface == LNET_MAX_INTERFACES) {
327 LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
329 libcfs_net2str(net));
333 ni->ni_interfaces[niface++] = iface;
335 } while (iface != NULL);
338 comma = strchr(bracket + 1, ',');
341 str = cfs_trimwhite(str);
350 str = cfs_trimwhite(str);
357 LASSERT(!cfs_list_empty(nilist));
361 lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
363 while (!cfs_list_empty(nilist)) {
364 ni = cfs_list_entry(nilist->next, lnet_ni_t, ni_list);
366 cfs_list_del(&ni->ni_list);
371 cfs_expr_list_free(el);
373 LIBCFS_FREE(tokens, tokensize);
374 the_lnet.ln_network_tokens = NULL;
380 lnet_new_text_buf (int str_len)
382 lnet_text_buf_t *ltb;
385 /* NB allocate space for the terminating 0 */
386 nob = offsetof(lnet_text_buf_t, ltb_text[str_len + 1]);
387 if (nob > LNET_SINGLE_TEXTBUF_NOB) {
388 /* _way_ conservative for "route net gateway..." */
389 CERROR("text buffer too big\n");
393 if (lnet_tbnob + nob > LNET_MAX_TEXTBUF_NOB) {
394 CERROR("Too many text buffers\n");
398 LIBCFS_ALLOC(ltb, nob);
403 ltb->ltb_text[0] = 0;
409 lnet_free_text_buf (lnet_text_buf_t *ltb)
411 lnet_tbnob -= ltb->ltb_size;
412 LIBCFS_FREE(ltb, ltb->ltb_size);
416 lnet_free_text_bufs(cfs_list_t *tbs)
418 lnet_text_buf_t *ltb;
420 while (!cfs_list_empty(tbs)) {
421 ltb = cfs_list_entry(tbs->next, lnet_text_buf_t, ltb_list);
423 cfs_list_del(<b->ltb_list);
424 lnet_free_text_buf(ltb);
429 lnet_print_text_bufs(cfs_list_t *tbs)
432 lnet_text_buf_t *ltb;
434 cfs_list_for_each (tmp, tbs) {
435 ltb = cfs_list_entry(tmp, lnet_text_buf_t, ltb_list);
437 CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
440 CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
444 lnet_str2tbs_sep (cfs_list_t *tbs, char *str)
450 lnet_text_buf_t *ltb;
452 CFS_INIT_LIST_HEAD(&pending);
454 /* Split 'str' into separate commands */
456 /* skip leading whitespace */
457 while (cfs_iswhite(*str))
460 /* scan for separator or comment */
461 for (sep = str; *sep != 0; sep++)
462 if (lnet_issep(*sep) || *sep == '#')
465 nob = (int)(sep - str);
467 ltb = lnet_new_text_buf(nob);
469 lnet_free_text_bufs(&pending);
473 for (i = 0; i < nob; i++)
474 if (cfs_iswhite(str[i]))
475 ltb->ltb_text[i] = ' ';
477 ltb->ltb_text[i] = str[i];
479 ltb->ltb_text[nob] = 0;
481 cfs_list_add_tail(<b->ltb_list, &pending);
485 /* scan for separator */
488 } while (*sep != 0 && !lnet_issep(*sep));
497 cfs_list_splice(&pending, tbs->prev);
502 lnet_expand1tb (cfs_list_t *list,
503 char *str, char *sep1, char *sep2,
504 char *item, int itemlen)
506 int len1 = (int)(sep1 - str);
507 int len2 = strlen(sep2 + 1);
508 lnet_text_buf_t *ltb;
510 LASSERT (*sep1 == '[');
511 LASSERT (*sep2 == ']');
513 ltb = lnet_new_text_buf(len1 + itemlen + len2);
517 memcpy(ltb->ltb_text, str, len1);
518 memcpy(<b->ltb_text[len1], item, itemlen);
519 memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2);
520 ltb->ltb_text[len1 + itemlen + len2] = 0;
522 cfs_list_add_tail(<b->ltb_list, list);
527 lnet_str2tbs_expand (cfs_list_t *tbs, char *str)
542 CFS_INIT_LIST_HEAD(&pending);
544 sep = strchr(str, '[');
545 if (sep == NULL) /* nothing to expand */
548 sep2 = strchr(sep, ']');
552 for (parsed = sep; parsed < sep2; parsed = enditem) {
555 while (enditem < sep2 && *enditem != ',')
558 if (enditem == parsed) /* no empty items */
561 if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
563 if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
565 /* simple string enumeration */
566 if (lnet_expand1tb(&pending, str, sep, sep2,
567 parsed, (int)(enditem - parsed)) != 0)
576 /* range expansion */
578 if (enditem != parsed + scanned) /* no trailing junk */
581 if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
582 (hi - lo) % stride != 0)
585 for (i = lo; i <= hi; i += stride) {
587 snprintf(num, sizeof(num), "%d", i);
589 if (nob + 1 == sizeof(num))
592 if (lnet_expand1tb(&pending, str, sep, sep2,
598 cfs_list_splice(&pending, tbs->prev);
602 lnet_free_text_bufs(&pending);
607 lnet_parse_hops (char *str, unsigned int *hops)
609 int len = strlen(str);
612 return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
614 *hops > 0 && *hops < 256);
617 #define LNET_PRIORITY_SEPARATOR (':')
620 lnet_parse_priority(char *str, unsigned int *priority, char **token)
626 sep = strchr(str, LNET_PRIORITY_SEPARATOR);
631 len = strlen(sep + 1);
633 if ((sscanf((sep+1), "%u%n", priority, &nob) < 1) || (len != nob)) {
634 /* Update the caller's token pointer so it treats the found
635 priority as the token to report in the error message. */
636 *token += sep - str + 1;
640 CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
643 * Change priority separator to \0 to be able to parse NID
650 lnet_parse_route (char *str, int *im_a_router)
652 /* static scratch buffer OK (single threaded) */
653 static char cmd[LNET_SINGLE_TEXTBUF_NOB];
661 lnet_text_buf_t *ltb;
669 unsigned int priority = 0;
671 CFS_INIT_LIST_HEAD(&gateways);
672 CFS_INIT_LIST_HEAD(&nets);
674 /* save a copy of the string for error messages */
675 strncpy(cmd, str, sizeof(cmd) - 1);
676 cmd[sizeof(cmd) - 1] = 0;
680 /* scan for token start */
681 while (cfs_iswhite(*sep))
684 if (ntokens < (got_hops ? 3 : 2))
692 /* scan for token end */
693 while (*sep != 0 && !cfs_iswhite(*sep))
699 tmp2 = &nets; /* expanding nets */
700 } else if (ntokens == 2 &&
701 lnet_parse_hops(token, &hops)) {
702 got_hops = 1; /* got a hop count */
705 tmp2 = &gateways; /* expanding gateways */
708 ltb = lnet_new_text_buf(strlen(token));
712 strcpy(ltb->ltb_text, token);
713 tmp1 = <b->ltb_list;
714 cfs_list_add_tail(tmp1, tmp2);
716 while (tmp1 != tmp2) {
717 ltb = cfs_list_entry(tmp1, lnet_text_buf_t, ltb_list);
719 rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
725 if (rc > 0) { /* expanded! */
726 cfs_list_del(<b->ltb_list);
727 lnet_free_text_buf(ltb);
732 net = libcfs_str2net(ltb->ltb_text);
733 if (net == LNET_NIDNET(LNET_NID_ANY) ||
734 LNET_NETTYP(net) == LOLND)
737 rc = lnet_parse_priority(ltb->ltb_text,
742 nid = libcfs_str2nid(ltb->ltb_text);
743 if (nid == LNET_NID_ANY ||
744 LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
753 LASSERT (!cfs_list_empty(&nets));
754 LASSERT (!cfs_list_empty(&gateways));
756 cfs_list_for_each (tmp1, &nets) {
757 ltb = cfs_list_entry(tmp1, lnet_text_buf_t, ltb_list);
758 net = libcfs_str2net(ltb->ltb_text);
759 LASSERT (net != LNET_NIDNET(LNET_NID_ANY));
761 cfs_list_for_each (tmp2, &gateways) {
762 ltb = cfs_list_entry(tmp2, lnet_text_buf_t, ltb_list);
763 nid = libcfs_str2nid(ltb->ltb_text);
764 LASSERT(nid != LNET_NID_ANY);
766 if (lnet_islocalnid(nid)) {
771 rc = lnet_add_route(net, hops, nid, priority);
773 CERROR("Can't create route "
776 libcfs_nid2str(nid));
786 lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
788 lnet_free_text_bufs(&nets);
789 lnet_free_text_bufs(&gateways);
794 lnet_parse_route_tbs(cfs_list_t *tbs, int *im_a_router)
796 lnet_text_buf_t *ltb;
798 while (!cfs_list_empty(tbs)) {
799 ltb = cfs_list_entry(tbs->next, lnet_text_buf_t, ltb_list);
801 if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
802 lnet_free_text_bufs(tbs);
806 cfs_list_del(<b->ltb_list);
807 lnet_free_text_buf(ltb);
814 lnet_parse_routes (char *routes, int *im_a_router)
821 CFS_INIT_LIST_HEAD(&tbs);
823 if (lnet_str2tbs_sep(&tbs, routes) < 0) {
824 CERROR("Error parsing routes\n");
827 rc = lnet_parse_route_tbs(&tbs, im_a_router);
830 LASSERT (lnet_tbnob == 0);
835 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
837 CFS_LIST_HEAD (list);
841 rc = cfs_ip_addr_parse(token, len, &list);
845 for (rc = i = 0; !rc && i < nip; i++)
846 rc = cfs_ip_addr_match(ipaddrs[i], &list);
848 cfs_ip_addr_free(&list);
854 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
856 static char tokens[LNET_SINGLE_TEXTBUF_NOB];
866 LASSERT (strlen(net_entry) < sizeof(tokens));
868 /* work on a copy of the string */
869 strcpy(tokens, net_entry);
872 /* scan for token start */
873 while (cfs_iswhite(*sep))
880 /* scan for token end */
881 while (*sep != 0 && !cfs_iswhite(*sep))
886 if (ntokens++ == 0) {
893 rc = lnet_match_network_token(token, len, ipaddrs, nip);
895 lnet_syntax("ip2nets", net_entry,
896 (int)(token - tokens), len);
900 matched |= (rc != 0);
906 strcpy(net_entry, net); /* replace with matched net */
911 lnet_netspec2net(char *netspec)
913 char *bracket = strchr(netspec, '(');
919 net = libcfs_str2net(netspec);
928 lnet_splitnets(char *source, cfs_list_t *nets)
934 lnet_text_buf_t *tb2;
940 LASSERT (!cfs_list_empty(nets));
941 LASSERT (nets->next == nets->prev); /* single entry */
943 tb = cfs_list_entry(nets->next, lnet_text_buf_t, ltb_list);
946 sep = strchr(tb->ltb_text, ',');
947 bracket = strchr(tb->ltb_text, '(');
952 /* netspec lists interfaces... */
954 offset2 = offset + (int)(bracket - tb->ltb_text);
955 len = strlen(bracket);
957 bracket = strchr(bracket + 1, ')');
959 if (bracket == NULL ||
960 !(bracket[1] == ',' || bracket[1] == 0)) {
961 lnet_syntax("ip2nets", source, offset2, len);
965 sep = (bracket[1] == 0) ? NULL : bracket + 1;
971 net = lnet_netspec2net(tb->ltb_text);
972 if (net == LNET_NIDNET(LNET_NID_ANY)) {
973 lnet_syntax("ip2nets", source, offset,
974 strlen(tb->ltb_text));
978 cfs_list_for_each(t, nets) {
979 tb2 = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
984 if (net == lnet_netspec2net(tb2->ltb_text)) {
985 /* duplicate network */
986 lnet_syntax("ip2nets", source, offset,
987 strlen(tb->ltb_text));
995 offset += (int)(sep - tb->ltb_text);
996 tb2 = lnet_new_text_buf(strlen(sep));
1000 strcpy(tb2->ltb_text, sep);
1001 cfs_list_add_tail(&tb2->ltb_list, nets);
1008 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
1010 static char networks[LNET_SINGLE_TEXTBUF_NOB];
1011 static char source[LNET_SINGLE_TEXTBUF_NOB];
1013 cfs_list_t raw_entries;
1014 cfs_list_t matched_nets;
1015 cfs_list_t current_nets;
1018 lnet_text_buf_t *tb;
1019 lnet_text_buf_t *tb2;
1027 CFS_INIT_LIST_HEAD(&raw_entries);
1028 if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
1029 CERROR("Error parsing ip2nets\n");
1030 LASSERT (lnet_tbnob == 0);
1034 CFS_INIT_LIST_HEAD(&matched_nets);
1035 CFS_INIT_LIST_HEAD(¤t_nets);
1041 while (!cfs_list_empty(&raw_entries)) {
1042 tb = cfs_list_entry(raw_entries.next, lnet_text_buf_t,
1045 strncpy(source, tb->ltb_text, sizeof(source)-1);
1046 source[sizeof(source)-1] = 0;
1048 /* replace ltb_text with the network(s) add on match */
1049 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
1053 cfs_list_del(&tb->ltb_list);
1055 if (rc == 0) { /* no match */
1056 lnet_free_text_buf(tb);
1060 /* split into separate networks */
1061 CFS_INIT_LIST_HEAD(¤t_nets);
1062 cfs_list_add(&tb->ltb_list, ¤t_nets);
1063 rc = lnet_splitnets(source, ¤t_nets);
1068 cfs_list_for_each (t, ¤t_nets) {
1069 tb = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
1070 net1 = lnet_netspec2net(tb->ltb_text);
1071 LASSERT (net1 != LNET_NIDNET(LNET_NID_ANY));
1073 cfs_list_for_each(t2, &matched_nets) {
1074 tb2 = cfs_list_entry(t2, lnet_text_buf_t,
1076 net2 = lnet_netspec2net(tb2->ltb_text);
1077 LASSERT (net2 != LNET_NIDNET(LNET_NID_ANY));
1090 lnet_free_text_bufs(¤t_nets);
1094 cfs_list_for_each_safe(t, t2, ¤t_nets) {
1095 tb = cfs_list_entry(t, lnet_text_buf_t, ltb_list);
1097 cfs_list_del(&tb->ltb_list);
1098 cfs_list_add_tail(&tb->ltb_list, &matched_nets);
1100 len += snprintf(networks + len, sizeof(networks) - len,
1101 "%s%s", (len == 0) ? "" : ",",
1104 if (len >= sizeof(networks)) {
1105 CERROR("Too many matched networks\n");
1115 lnet_free_text_bufs(&raw_entries);
1116 lnet_free_text_bufs(&matched_nets);
1117 lnet_free_text_bufs(¤t_nets);
1118 LASSERT (lnet_tbnob == 0);
1123 *networksp = networks;
1129 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
1131 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
1135 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
1143 int nif = libcfs_ipif_enumerate(&ifnames);
1150 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
1151 if (ipaddrs == NULL) {
1152 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1153 libcfs_ipif_free_enumeration(ifnames, nif);
1157 for (i = nip = 0; i < nif; i++) {
1158 if (!strcmp(ifnames[i], "lo"))
1161 rc = libcfs_ipif_query(ifnames[i], &up,
1162 &ipaddrs[nip], &netmask);
1164 CWARN("Can't query interface %s: %d\n",
1170 CWARN("Ignoring interface %s: it's down\n",
1178 libcfs_ipif_free_enumeration(ifnames, nif);
1181 *ipaddrsp = ipaddrs;
1184 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
1185 if (ipaddrs2 == NULL) {
1186 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1189 memcpy(ipaddrs2, ipaddrs,
1190 nip * sizeof(*ipaddrs));
1191 *ipaddrsp = ipaddrs2;
1195 lnet_ipaddr_free_enumeration(ipaddrs, nif);
1201 lnet_parse_ip2nets (char **networksp, char *ip2nets)
1204 int nip = lnet_ipaddr_enumerate(&ipaddrs);
1208 LCONSOLE_ERROR_MSG(0x117, "Error %d enumerating local IP "
1209 "interfaces for ip2nets to match\n", nip);
1214 LCONSOLE_ERROR_MSG(0x118, "No local IP interfaces "
1215 "for ip2nets to match\n");
1219 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1220 lnet_ipaddr_free_enumeration(ipaddrs, nip);
1223 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
1228 LCONSOLE_ERROR_MSG(0x11a, "ip2nets does not match "
1229 "any local IP interfaces\n");
1237 lnet_set_ip_niaddr (lnet_ni_t *ni)
1239 __u32 net = LNET_NIDNET(ni->ni_nid);
1248 /* Convenience for LNDs that use the IP address of a local interface as
1249 * the local address part of their NID */
1251 if (ni->ni_interfaces[0] != NULL) {
1253 CLASSERT (LNET_MAX_INTERFACES > 1);
1255 if (ni->ni_interfaces[1] != NULL) {
1256 CERROR("Net %s doesn't support multiple interfaces\n",
1257 libcfs_net2str(net));
1261 rc = libcfs_ipif_query(ni->ni_interfaces[0],
1262 &up, &ip, &netmask);
1264 CERROR("Net %s can't query interface %s: %d\n",
1265 libcfs_net2str(net), ni->ni_interfaces[0], rc);
1270 CERROR("Net %s can't use interface %s: it's down\n",
1271 libcfs_net2str(net), ni->ni_interfaces[0]);
1275 ni->ni_nid = LNET_MKNID(net, ip);
1279 n = libcfs_ipif_enumerate(&names);
1281 CERROR("Net %s can't enumerate interfaces: %d\n",
1282 libcfs_net2str(net), n);
1286 for (i = 0; i < n; i++) {
1287 if (!strcmp(names[i], "lo")) /* skip the loopback IF */
1290 rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
1293 CWARN("Net %s can't query interface %s: %d\n",
1294 libcfs_net2str(net), names[i], rc);
1299 CWARN("Net %s ignoring interface %s (down)\n",
1300 libcfs_net2str(net), names[i]);
1304 libcfs_ipif_free_enumeration(names, n);
1305 ni->ni_nid = LNET_MKNID(net, ip);
1309 CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
1310 libcfs_ipif_free_enumeration(names, n);
1313 EXPORT_SYMBOL(lnet_set_ip_niaddr);