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 /* 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)
100 if (ni->ni_refs != NULL)
101 cfs_percpt_free(ni->ni_refs);
103 if (ni->ni_tx_queues != NULL)
104 cfs_percpt_free(ni->ni_tx_queues);
106 if (ni->ni_cpts != NULL)
107 cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
110 # ifdef HAVE_LIBPTHREAD
111 pthread_mutex_destroy(&ni->ni_lock);
114 LIBCFS_FREE(ni, sizeof(*ni));
118 lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
120 struct lnet_tx_queue *tq;
125 if (!lnet_net_unique(net, nilist)) {
126 LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n",
127 libcfs_net2str(net));
131 LIBCFS_ALLOC(ni, sizeof(*ni));
133 CERROR("Out of memory creating network %s\n",
134 libcfs_net2str(net));
139 spin_lock_init(&ni->ni_lock);
141 # ifdef HAVE_LIBPTHREAD
142 pthread_mutex_init(&ni->ni_lock, NULL);
145 INIT_LIST_HEAD(&ni->ni_cptlist);
146 ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
147 sizeof(*ni->ni_refs[0]));
148 if (ni->ni_refs == NULL)
151 ni->ni_tx_queues = cfs_percpt_alloc(lnet_cpt_table(),
152 sizeof(*ni->ni_tx_queues[0]));
153 if (ni->ni_tx_queues == NULL)
156 cfs_percpt_for_each(tq, i, ni->ni_tx_queues)
157 INIT_LIST_HEAD(&tq->tq_delayed);
161 ni->ni_ncpts = LNET_CPT_NUMBER;
163 rc = cfs_expr_list_values(el, LNET_CPT_NUMBER, &ni->ni_cpts);
165 CERROR("Failed to set CPTs for NI %s: %d\n",
166 libcfs_net2str(net), rc);
170 LASSERT(rc <= LNET_CPT_NUMBER);
171 if (rc == LNET_CPT_NUMBER) {
172 LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0]));
179 /* LND will fill in the address part of the NID */
180 ni->ni_nid = LNET_MKNID(net, 0);
181 ni->ni_last_alive = cfs_time_current_sec();
182 list_add_tail(&ni->ni_list, nilist);
190 lnet_parse_networks(struct list_head *nilist, char *networks)
192 struct cfs_expr_list *el = NULL;
193 int tokensize = strlen(networks) + 1;
201 if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
202 /* _WAY_ conservative */
203 LCONSOLE_ERROR_MSG(0x112, "Can't parse networks: string too "
208 LIBCFS_ALLOC(tokens, tokensize);
209 if (tokens == NULL) {
210 CERROR("Can't allocate net tokens\n");
214 the_lnet.ln_network_tokens = tokens;
215 the_lnet.ln_network_tokens_nob = tokensize;
216 memcpy (tokens, networks, tokensize);
219 /* Add in the loopback network */
220 ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist);
224 while (str != NULL && *str != 0) {
225 char *comma = strchr(str, ',');
226 char *bracket = strchr(str, '(');
227 char *square = strchr(str, '[');
232 /* NB we don't check interface conflicts here; it's the LNDs
233 * responsibility (if it cares at all) */
235 if (square != NULL && (comma == NULL || square < comma)) {
236 /* i.e: o2ib0(ib0)[1,2], number between square
237 * brackets are CPTs this NI needs to be bond */
238 if (bracket != NULL && bracket > square) {
243 tmp = strchr(square, ']');
249 rc = cfs_expr_list_parse(square, tmp - square + 1,
250 0, LNET_CPT_NUMBER - 1, &el);
256 while (square <= tmp)
260 if (bracket == NULL ||
261 (comma != NULL && comma < bracket)) {
263 /* no interface list specified */
267 net = libcfs_str2net(cfs_trimwhite(str));
269 if (net == LNET_NIDNET(LNET_NID_ANY)) {
270 LCONSOLE_ERROR_MSG(0x113, "Unrecognised network"
276 if (LNET_NETTYP(net) != LOLND && /* LO is implicit */
277 lnet_ni_alloc(net, el, nilist) == NULL)
281 cfs_expr_list_free(el);
290 net = libcfs_str2net(cfs_trimwhite(str));
291 if (net == LNET_NIDNET(LNET_NID_ANY)) {
297 ni = lnet_ni_alloc(net, el, nilist);
302 cfs_expr_list_free(el);
309 bracket = strchr(iface, ')');
310 if (bracket == NULL) {
317 comma = strchr(iface, ',');
321 iface = cfs_trimwhite(iface);
327 if (niface == LNET_MAX_INTERFACES) {
328 LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
330 libcfs_net2str(net));
334 ni->ni_interfaces[niface++] = iface;
336 } while (iface != NULL);
339 comma = strchr(bracket + 1, ',');
342 str = cfs_trimwhite(str);
351 str = cfs_trimwhite(str);
358 LASSERT(!list_empty(nilist));
362 lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
364 while (!list_empty(nilist)) {
365 ni = list_entry(nilist->next, lnet_ni_t, ni_list);
367 list_del(&ni->ni_list);
372 cfs_expr_list_free(el);
374 LIBCFS_FREE(tokens, tokensize);
375 the_lnet.ln_network_tokens = NULL;
380 struct lnet_text_buf *
381 lnet_new_text_buf (int str_len)
383 struct lnet_text_buf *ltb;
386 /* NB allocate space for the terminating 0 */
387 nob = offsetof(struct lnet_text_buf, ltb_text[str_len + 1]);
388 if (nob > LNET_SINGLE_TEXTBUF_NOB) {
389 /* _way_ conservative for "route net gateway..." */
390 CERROR("text buffer too big\n");
394 if (lnet_tbnob + nob > LNET_MAX_TEXTBUF_NOB) {
395 CERROR("Too many text buffers\n");
399 LIBCFS_ALLOC(ltb, nob);
404 ltb->ltb_text[0] = 0;
410 lnet_free_text_buf(struct lnet_text_buf *ltb)
412 lnet_tbnob -= ltb->ltb_size;
413 LIBCFS_FREE(ltb, ltb->ltb_size);
417 lnet_free_text_bufs(struct list_head *tbs)
419 struct lnet_text_buf *ltb;
421 while (!list_empty(tbs)) {
422 ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
424 list_del(<b->ltb_list);
425 lnet_free_text_buf(ltb);
430 lnet_print_text_bufs(struct list_head *tbs)
432 struct list_head *tmp;
433 struct lnet_text_buf *ltb;
435 list_for_each(tmp, tbs) {
436 ltb = list_entry(tmp, struct lnet_text_buf, ltb_list);
438 CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
441 CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
445 lnet_str2tbs_sep(struct list_head *tbs, char *str)
447 struct list_head pending;
451 struct lnet_text_buf *ltb;
453 INIT_LIST_HEAD(&pending);
455 /* Split 'str' into separate commands */
457 /* skip leading whitespace */
458 while (cfs_iswhite(*str))
461 /* scan for separator or comment */
462 for (sep = str; *sep != 0; sep++)
463 if (lnet_issep(*sep) || *sep == '#')
466 nob = (int)(sep - str);
468 ltb = lnet_new_text_buf(nob);
470 lnet_free_text_bufs(&pending);
474 for (i = 0; i < nob; i++)
475 if (cfs_iswhite(str[i]))
476 ltb->ltb_text[i] = ' ';
478 ltb->ltb_text[i] = str[i];
480 ltb->ltb_text[nob] = 0;
482 list_add_tail(<b->ltb_list, &pending);
486 /* scan for separator */
489 } while (*sep != 0 && !lnet_issep(*sep));
498 list_splice(&pending, tbs->prev);
503 lnet_expand1tb(struct list_head *list,
504 char *str, char *sep1, char *sep2,
505 char *item, int itemlen)
507 int len1 = (int)(sep1 - str);
508 int len2 = strlen(sep2 + 1);
509 struct lnet_text_buf *ltb;
511 LASSERT (*sep1 == '[');
512 LASSERT (*sep2 == ']');
514 ltb = lnet_new_text_buf(len1 + itemlen + len2);
518 memcpy(ltb->ltb_text, str, len1);
519 memcpy(<b->ltb_text[len1], item, itemlen);
520 memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2);
521 ltb->ltb_text[len1 + itemlen + len2] = 0;
523 list_add_tail(<b->ltb_list, list);
528 lnet_str2tbs_expand(struct list_head *tbs, char *str)
531 struct list_head pending;
543 INIT_LIST_HEAD(&pending);
545 sep = strchr(str, '[');
546 if (sep == NULL) /* nothing to expand */
549 sep2 = strchr(sep, ']');
553 for (parsed = sep; parsed < sep2; parsed = enditem) {
556 while (enditem < sep2 && *enditem != ',')
559 if (enditem == parsed) /* no empty items */
562 if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
564 if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
566 /* simple string enumeration */
567 if (lnet_expand1tb(&pending, str, sep, sep2,
568 parsed, (int)(enditem - parsed)) != 0)
577 /* range expansion */
579 if (enditem != parsed + scanned) /* no trailing junk */
582 if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
583 (hi - lo) % stride != 0)
586 for (i = lo; i <= hi; i += stride) {
588 snprintf(num, sizeof(num), "%d", i);
590 if (nob + 1 == sizeof(num))
593 if (lnet_expand1tb(&pending, str, sep, sep2,
599 list_splice(&pending, tbs->prev);
603 lnet_free_text_bufs(&pending);
608 lnet_parse_hops (char *str, unsigned int *hops)
610 int len = strlen(str);
613 return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
615 *hops > 0 && *hops < 256);
618 #define LNET_PRIORITY_SEPARATOR (':')
621 lnet_parse_priority(char *str, unsigned int *priority, char **token)
627 sep = strchr(str, LNET_PRIORITY_SEPARATOR);
632 len = strlen(sep + 1);
634 if ((sscanf((sep+1), "%u%n", priority, &nob) < 1) || (len != nob)) {
635 /* Update the caller's token pointer so it treats the found
636 priority as the token to report in the error message. */
637 *token += sep - str + 1;
641 CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
644 * Change priority separator to \0 to be able to parse NID
651 lnet_parse_route (char *str, int *im_a_router)
653 /* static scratch buffer OK (single threaded) */
654 static char cmd[LNET_SINGLE_TEXTBUF_NOB];
656 struct list_head nets;
657 struct list_head gateways;
658 struct list_head *tmp1;
659 struct list_head *tmp2;
662 struct lnet_text_buf *ltb;
670 unsigned int priority = 0;
672 INIT_LIST_HEAD(&gateways);
673 INIT_LIST_HEAD(&nets);
675 /* save a copy of the string for error messages */
676 strncpy(cmd, str, sizeof(cmd) - 1);
677 cmd[sizeof(cmd) - 1] = 0;
681 /* scan for token start */
682 while (cfs_iswhite(*sep))
685 if (ntokens < (got_hops ? 3 : 2))
693 /* scan for token end */
694 while (*sep != 0 && !cfs_iswhite(*sep))
700 tmp2 = &nets; /* expanding nets */
701 } else if (ntokens == 2 &&
702 lnet_parse_hops(token, &hops)) {
703 got_hops = 1; /* got a hop count */
706 tmp2 = &gateways; /* expanding gateways */
709 ltb = lnet_new_text_buf(strlen(token));
713 strcpy(ltb->ltb_text, token);
714 tmp1 = <b->ltb_list;
715 list_add_tail(tmp1, tmp2);
717 while (tmp1 != tmp2) {
718 ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
720 rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
726 if (rc > 0) { /* expanded! */
727 list_del(<b->ltb_list);
728 lnet_free_text_buf(ltb);
733 net = libcfs_str2net(ltb->ltb_text);
734 if (net == LNET_NIDNET(LNET_NID_ANY) ||
735 LNET_NETTYP(net) == LOLND)
738 rc = lnet_parse_priority(ltb->ltb_text,
743 nid = libcfs_str2nid(ltb->ltb_text);
744 if (nid == LNET_NID_ANY ||
745 LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
754 LASSERT(!list_empty(&nets));
755 LASSERT(!list_empty(&gateways));
757 list_for_each(tmp1, &nets) {
758 ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
759 net = libcfs_str2net(ltb->ltb_text);
760 LASSERT (net != LNET_NIDNET(LNET_NID_ANY));
762 list_for_each(tmp2, &gateways) {
763 ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
764 nid = libcfs_str2nid(ltb->ltb_text);
765 LASSERT(nid != LNET_NID_ANY);
767 if (lnet_islocalnid(nid)) {
772 rc = lnet_add_route(net, hops, nid, priority);
774 CERROR("Can't create route "
777 libcfs_nid2str(nid));
787 lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
789 lnet_free_text_bufs(&nets);
790 lnet_free_text_bufs(&gateways);
795 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
797 struct lnet_text_buf *ltb;
799 while (!list_empty(tbs)) {
800 ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
802 if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
803 lnet_free_text_bufs(tbs);
807 list_del(<b->ltb_list);
808 lnet_free_text_buf(ltb);
815 lnet_parse_routes (char *routes, int *im_a_router)
817 struct list_head tbs;
822 INIT_LIST_HEAD(&tbs);
824 if (lnet_str2tbs_sep(&tbs, routes) < 0) {
825 CERROR("Error parsing routes\n");
828 rc = lnet_parse_route_tbs(&tbs, im_a_router);
831 LASSERT (lnet_tbnob == 0);
836 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
838 struct list_head list = LIST_HEAD_INIT(list);
842 rc = cfs_ip_addr_parse(token, len, &list);
846 for (rc = i = 0; !rc && i < nip; i++)
847 rc = cfs_ip_addr_match(ipaddrs[i], &list);
849 cfs_ip_addr_free(&list);
855 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
857 static char tokens[LNET_SINGLE_TEXTBUF_NOB];
867 LASSERT (strlen(net_entry) < sizeof(tokens));
869 /* work on a copy of the string */
870 strcpy(tokens, net_entry);
873 /* scan for token start */
874 while (cfs_iswhite(*sep))
881 /* scan for token end */
882 while (*sep != 0 && !cfs_iswhite(*sep))
887 if (ntokens++ == 0) {
894 rc = lnet_match_network_token(token, len, ipaddrs, nip);
896 lnet_syntax("ip2nets", net_entry,
897 (int)(token - tokens), len);
901 matched |= (rc != 0);
907 strcpy(net_entry, net); /* replace with matched net */
912 lnet_netspec2net(char *netspec)
914 char *bracket = strchr(netspec, '(');
920 net = libcfs_str2net(netspec);
929 lnet_splitnets(char *source, struct list_head *nets)
934 struct lnet_text_buf *tb;
935 struct lnet_text_buf *tb2;
941 LASSERT(!list_empty(nets));
942 LASSERT(nets->next == nets->prev); /* single entry */
944 tb = list_entry(nets->next, struct lnet_text_buf, ltb_list);
947 sep = strchr(tb->ltb_text, ',');
948 bracket = strchr(tb->ltb_text, '(');
953 /* netspec lists interfaces... */
955 offset2 = offset + (int)(bracket - tb->ltb_text);
956 len = strlen(bracket);
958 bracket = strchr(bracket + 1, ')');
960 if (bracket == NULL ||
961 !(bracket[1] == ',' || bracket[1] == 0)) {
962 lnet_syntax("ip2nets", source, offset2, len);
966 sep = (bracket[1] == 0) ? NULL : bracket + 1;
972 net = lnet_netspec2net(tb->ltb_text);
973 if (net == LNET_NIDNET(LNET_NID_ANY)) {
974 lnet_syntax("ip2nets", source, offset,
975 strlen(tb->ltb_text));
979 list_for_each(t, nets) {
980 tb2 = list_entry(t, struct lnet_text_buf, ltb_list);
985 if (net == lnet_netspec2net(tb2->ltb_text)) {
986 /* duplicate network */
987 lnet_syntax("ip2nets", source, offset,
988 strlen(tb->ltb_text));
996 offset += (int)(sep - tb->ltb_text);
997 tb2 = lnet_new_text_buf(strlen(sep));
1001 strncpy(tb2->ltb_text, sep, strlen(sep));
1002 list_add_tail(&tb2->ltb_list, nets);
1009 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
1011 static char networks[LNET_SINGLE_TEXTBUF_NOB];
1012 static char source[LNET_SINGLE_TEXTBUF_NOB];
1014 struct list_head raw_entries;
1015 struct list_head matched_nets;
1016 struct list_head current_nets;
1017 struct list_head *t;
1018 struct list_head *t2;
1019 struct lnet_text_buf *tb;
1020 struct lnet_text_buf *tb2;
1028 INIT_LIST_HEAD(&raw_entries);
1029 if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
1030 CERROR("Error parsing ip2nets\n");
1031 LASSERT (lnet_tbnob == 0);
1035 INIT_LIST_HEAD(&matched_nets);
1036 INIT_LIST_HEAD(¤t_nets);
1042 while (!list_empty(&raw_entries)) {
1043 tb = list_entry(raw_entries.next, struct lnet_text_buf,
1046 strncpy(source, tb->ltb_text, sizeof(source)-1);
1047 source[sizeof(source)-1] = 0;
1049 /* replace ltb_text with the network(s) add on match */
1050 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
1054 list_del(&tb->ltb_list);
1056 if (rc == 0) { /* no match */
1057 lnet_free_text_buf(tb);
1061 /* split into separate networks */
1062 INIT_LIST_HEAD(¤t_nets);
1063 list_add(&tb->ltb_list, ¤t_nets);
1064 rc = lnet_splitnets(source, ¤t_nets);
1069 list_for_each(t, ¤t_nets) {
1070 tb = list_entry(t, struct lnet_text_buf, ltb_list);
1071 net1 = lnet_netspec2net(tb->ltb_text);
1072 LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
1074 list_for_each(t2, &matched_nets) {
1075 tb2 = list_entry(t2, struct lnet_text_buf,
1077 net2 = lnet_netspec2net(tb2->ltb_text);
1078 LASSERT(net2 != LNET_NIDNET(LNET_NID_ANY));
1091 lnet_free_text_bufs(¤t_nets);
1095 list_for_each_safe(t, t2, ¤t_nets) {
1096 tb = list_entry(t, struct lnet_text_buf, ltb_list);
1098 list_del(&tb->ltb_list);
1099 list_add_tail(&tb->ltb_list, &matched_nets);
1101 len += snprintf(networks + len, sizeof(networks) - len,
1102 "%s%s", (len == 0) ? "" : ",",
1105 if (len >= sizeof(networks)) {
1106 CERROR("Too many matched networks\n");
1116 lnet_free_text_bufs(&raw_entries);
1117 lnet_free_text_bufs(&matched_nets);
1118 lnet_free_text_bufs(¤t_nets);
1119 LASSERT (lnet_tbnob == 0);
1124 *networksp = networks;
1130 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
1132 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
1136 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
1144 int nif = libcfs_ipif_enumerate(&ifnames);
1151 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
1152 if (ipaddrs == NULL) {
1153 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1154 libcfs_ipif_free_enumeration(ifnames, nif);
1158 for (i = nip = 0; i < nif; i++) {
1159 if (!strcmp(ifnames[i], "lo"))
1162 rc = libcfs_ipif_query(ifnames[i], &up,
1163 &ipaddrs[nip], &netmask);
1165 CWARN("Can't query interface %s: %d\n",
1171 CWARN("Ignoring interface %s: it's down\n",
1179 libcfs_ipif_free_enumeration(ifnames, nif);
1182 *ipaddrsp = ipaddrs;
1185 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
1186 if (ipaddrs2 == NULL) {
1187 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1190 memcpy(ipaddrs2, ipaddrs,
1191 nip * sizeof(*ipaddrs));
1192 *ipaddrsp = ipaddrs2;
1196 lnet_ipaddr_free_enumeration(ipaddrs, nif);
1202 lnet_parse_ip2nets (char **networksp, char *ip2nets)
1205 int nip = lnet_ipaddr_enumerate(&ipaddrs);
1209 LCONSOLE_ERROR_MSG(0x117, "Error %d enumerating local IP "
1210 "interfaces for ip2nets to match\n", nip);
1215 LCONSOLE_ERROR_MSG(0x118, "No local IP interfaces "
1216 "for ip2nets to match\n");
1220 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1221 lnet_ipaddr_free_enumeration(ipaddrs, nip);
1224 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
1229 LCONSOLE_ERROR_MSG(0x11a, "ip2nets does not match "
1230 "any local IP interfaces\n");
1238 lnet_set_ip_niaddr (lnet_ni_t *ni)
1240 __u32 net = LNET_NIDNET(ni->ni_nid);
1249 /* Convenience for LNDs that use the IP address of a local interface as
1250 * the local address part of their NID */
1252 if (ni->ni_interfaces[0] != NULL) {
1254 CLASSERT (LNET_MAX_INTERFACES > 1);
1256 if (ni->ni_interfaces[1] != NULL) {
1257 CERROR("Net %s doesn't support multiple interfaces\n",
1258 libcfs_net2str(net));
1262 rc = libcfs_ipif_query(ni->ni_interfaces[0],
1263 &up, &ip, &netmask);
1265 CERROR("Net %s can't query interface %s: %d\n",
1266 libcfs_net2str(net), ni->ni_interfaces[0], rc);
1271 CERROR("Net %s can't use interface %s: it's down\n",
1272 libcfs_net2str(net), ni->ni_interfaces[0]);
1276 ni->ni_nid = LNET_MKNID(net, ip);
1280 n = libcfs_ipif_enumerate(&names);
1282 CERROR("Net %s can't enumerate interfaces: %d\n",
1283 libcfs_net2str(net), n);
1287 for (i = 0; i < n; i++) {
1288 if (!strcmp(names[i], "lo")) /* skip the loopback IF */
1291 rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
1294 CWARN("Net %s can't query interface %s: %d\n",
1295 libcfs_net2str(net), names[i], rc);
1300 CWARN("Net %s ignoring interface %s (down)\n",
1301 libcfs_net2str(net), names[i]);
1305 libcfs_ipif_free_enumeration(names, n);
1306 ni->ni_nid = LNET_MKNID(net, ip);
1310 CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
1311 libcfs_ipif_free_enumeration(names, n);
1314 EXPORT_SYMBOL(lnet_set_ip_niaddr);