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 "../../include/linux/lnet/lib-lnet.h"
40 typedef struct { /* tmp struct for parsing routes */
41 struct list_head ltb_list; /* stash on lists */
42 int ltb_size; /* allocated size */
43 char ltb_text[0]; /* text buffer */
46 static int lnet_tbnob; /* 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, struct list_head *nilist)
83 struct list_head *tmp;
86 list_for_each(tmp, nilist) {
87 ni = 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);
108 LIBCFS_FREE(ni, sizeof(*ni));
112 lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
114 struct lnet_tx_queue *tq;
119 if (!lnet_net_unique(net, nilist)) {
120 LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n",
121 libcfs_net2str(net));
125 LIBCFS_ALLOC(ni, sizeof(*ni));
127 CERROR("Out of memory creating network %s\n",
128 libcfs_net2str(net));
132 spin_lock_init(&ni->ni_lock);
133 INIT_LIST_HEAD(&ni->ni_cptlist);
134 ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
135 sizeof(*ni->ni_refs[0]));
136 if (ni->ni_refs == NULL)
139 ni->ni_tx_queues = cfs_percpt_alloc(lnet_cpt_table(),
140 sizeof(*ni->ni_tx_queues[0]));
141 if (ni->ni_tx_queues == NULL)
144 cfs_percpt_for_each(tq, i, ni->ni_tx_queues)
145 INIT_LIST_HEAD(&tq->tq_delayed);
149 ni->ni_ncpts = LNET_CPT_NUMBER;
151 rc = cfs_expr_list_values(el, LNET_CPT_NUMBER, &ni->ni_cpts);
153 CERROR("Failed to set CPTs for NI %s: %d\n",
154 libcfs_net2str(net), rc);
158 LASSERT(rc <= LNET_CPT_NUMBER);
159 if (rc == LNET_CPT_NUMBER) {
160 LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0]));
167 /* LND will fill in the address part of the NID */
168 ni->ni_nid = LNET_MKNID(net, 0);
169 ni->ni_last_alive = get_seconds();
170 list_add_tail(&ni->ni_list, nilist);
178 lnet_parse_networks(struct list_head *nilist, char *networks)
180 struct cfs_expr_list *el = NULL;
181 int tokensize = strlen(networks) + 1;
189 if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
190 /* _WAY_ conservative */
191 LCONSOLE_ERROR_MSG(0x112,
192 "Can't parse networks: string too long\n");
196 LIBCFS_ALLOC(tokens, tokensize);
197 if (tokens == NULL) {
198 CERROR("Can't allocate net tokens\n");
202 the_lnet.ln_network_tokens = tokens;
203 the_lnet.ln_network_tokens_nob = tokensize;
204 memcpy(tokens, networks, tokensize);
207 /* Add in the loopback network */
208 ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist);
212 while (str != NULL && *str != 0) {
213 char *comma = strchr(str, ',');
214 char *bracket = strchr(str, '(');
215 char *square = strchr(str, '[');
220 /* NB we don't check interface conflicts here; it's the LNDs
221 * responsibility (if it cares at all) */
223 if (square != NULL && (comma == NULL || square < comma)) {
224 /* i.e: o2ib0(ib0)[1,2], number between square
225 * brackets are CPTs this NI needs to be bond */
226 if (bracket != NULL && bracket > square) {
231 tmp = strchr(square, ']');
237 rc = cfs_expr_list_parse(square, tmp - square + 1,
238 0, LNET_CPT_NUMBER - 1, &el);
244 while (square <= tmp)
248 if (bracket == NULL ||
249 (comma != NULL && comma < bracket)) {
251 /* no interface list specified */
255 net = libcfs_str2net(cfs_trimwhite(str));
257 if (net == LNET_NIDNET(LNET_NID_ANY)) {
258 LCONSOLE_ERROR_MSG(0x113,
259 "Unrecognised network type\n");
264 if (LNET_NETTYP(net) != LOLND && /* LO is implicit */
265 lnet_ni_alloc(net, el, nilist) == NULL)
269 cfs_expr_list_free(el);
278 net = libcfs_str2net(cfs_trimwhite(str));
279 if (net == LNET_NIDNET(LNET_NID_ANY)) {
285 ni = lnet_ni_alloc(net, el, nilist);
290 cfs_expr_list_free(el);
297 bracket = strchr(iface, ')');
298 if (bracket == NULL) {
305 comma = strchr(iface, ',');
309 iface = cfs_trimwhite(iface);
315 if (niface == LNET_MAX_INTERFACES) {
316 LCONSOLE_ERROR_MSG(0x115,
317 "Too many interfaces for net %s\n",
318 libcfs_net2str(net));
322 ni->ni_interfaces[niface++] = iface;
324 } while (iface != NULL);
327 comma = strchr(bracket + 1, ',');
330 str = cfs_trimwhite(str);
339 str = cfs_trimwhite(str);
346 LASSERT(!list_empty(nilist));
350 lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
352 while (!list_empty(nilist)) {
353 ni = list_entry(nilist->next, lnet_ni_t, ni_list);
355 list_del(&ni->ni_list);
360 cfs_expr_list_free(el);
362 LIBCFS_FREE(tokens, tokensize);
363 the_lnet.ln_network_tokens = NULL;
369 lnet_new_text_buf(int str_len)
371 lnet_text_buf_t *ltb;
374 /* NB allocate space for the terminating 0 */
375 nob = offsetof(lnet_text_buf_t, ltb_text[str_len + 1]);
376 if (nob > LNET_SINGLE_TEXTBUF_NOB) {
377 /* _way_ conservative for "route net gateway..." */
378 CERROR("text buffer too big\n");
382 if (lnet_tbnob + nob > LNET_MAX_TEXTBUF_NOB) {
383 CERROR("Too many text buffers\n");
387 LIBCFS_ALLOC(ltb, nob);
392 ltb->ltb_text[0] = 0;
398 lnet_free_text_buf(lnet_text_buf_t *ltb)
400 lnet_tbnob -= ltb->ltb_size;
401 LIBCFS_FREE(ltb, ltb->ltb_size);
405 lnet_free_text_bufs(struct list_head *tbs)
407 lnet_text_buf_t *ltb;
409 while (!list_empty(tbs)) {
410 ltb = list_entry(tbs->next, lnet_text_buf_t, ltb_list);
412 list_del(<b->ltb_list);
413 lnet_free_text_buf(ltb);
418 lnet_print_text_bufs(struct list_head *tbs)
420 struct list_head *tmp;
421 lnet_text_buf_t *ltb;
423 list_for_each(tmp, tbs) {
424 ltb = list_entry(tmp, lnet_text_buf_t, ltb_list);
426 CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
429 CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
433 lnet_str2tbs_sep(struct list_head *tbs, char *str)
435 struct list_head pending;
439 lnet_text_buf_t *ltb;
441 INIT_LIST_HEAD(&pending);
443 /* Split 'str' into separate commands */
445 /* skip leading whitespace */
446 while (isspace(*str))
449 /* scan for separator or comment */
450 for (sep = str; *sep != 0; sep++)
451 if (lnet_issep(*sep) || *sep == '#')
454 nob = (int)(sep - str);
456 ltb = lnet_new_text_buf(nob);
458 lnet_free_text_bufs(&pending);
462 for (i = 0; i < nob; i++)
464 ltb->ltb_text[i] = ' ';
466 ltb->ltb_text[i] = str[i];
468 ltb->ltb_text[nob] = 0;
470 list_add_tail(<b->ltb_list, &pending);
474 /* scan for separator */
477 } while (*sep != 0 && !lnet_issep(*sep));
486 list_splice(&pending, tbs->prev);
491 lnet_expand1tb(struct list_head *list,
492 char *str, char *sep1, char *sep2,
493 char *item, int itemlen)
495 int len1 = (int)(sep1 - str);
496 int len2 = strlen(sep2 + 1);
497 lnet_text_buf_t *ltb;
499 LASSERT(*sep1 == '[');
500 LASSERT(*sep2 == ']');
502 ltb = lnet_new_text_buf(len1 + itemlen + len2);
506 memcpy(ltb->ltb_text, str, len1);
507 memcpy(<b->ltb_text[len1], item, itemlen);
508 memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2);
509 ltb->ltb_text[len1 + itemlen + len2] = 0;
511 list_add_tail(<b->ltb_list, list);
516 lnet_str2tbs_expand(struct list_head *tbs, char *str)
519 struct list_head pending;
531 INIT_LIST_HEAD(&pending);
533 sep = strchr(str, '[');
534 if (sep == NULL) /* nothing to expand */
537 sep2 = strchr(sep, ']');
541 for (parsed = sep; parsed < sep2; parsed = enditem) {
544 while (enditem < sep2 && *enditem != ',')
547 if (enditem == parsed) /* no empty items */
550 if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
552 if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
554 /* simple string enumeration */
555 if (lnet_expand1tb(&pending, str, sep, sep2,
556 parsed, (int)(enditem - parsed)) != 0)
565 /* range expansion */
567 if (enditem != parsed + scanned) /* no trailing junk */
570 if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
571 (hi - lo) % stride != 0)
574 for (i = lo; i <= hi; i += stride) {
576 snprintf(num, sizeof(num), "%d", i);
578 if (nob + 1 == sizeof(num))
581 if (lnet_expand1tb(&pending, str, sep, sep2,
587 list_splice(&pending, tbs->prev);
591 lnet_free_text_bufs(&pending);
596 lnet_parse_hops(char *str, unsigned int *hops)
598 int len = strlen(str);
601 return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
603 *hops > 0 && *hops < 256);
606 #define LNET_PRIORITY_SEPARATOR (':')
609 lnet_parse_priority(char *str, unsigned int *priority, char **token)
615 sep = strchr(str, LNET_PRIORITY_SEPARATOR);
620 len = strlen(sep + 1);
622 if ((sscanf((sep+1), "%u%n", priority, &nob) < 1) || (len != nob)) {
623 /* Update the caller's token pointer so it treats the found
624 priority as the token to report in the error message. */
625 *token += sep - str + 1;
629 CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
632 * Change priority separator to \0 to be able to parse NID
639 lnet_parse_route(char *str, int *im_a_router)
641 /* static scratch buffer OK (single threaded) */
642 static char cmd[LNET_SINGLE_TEXTBUF_NOB];
644 struct list_head nets;
645 struct list_head gateways;
646 struct list_head *tmp1;
647 struct list_head *tmp2;
650 lnet_text_buf_t *ltb;
658 unsigned int priority = 0;
660 INIT_LIST_HEAD(&gateways);
661 INIT_LIST_HEAD(&nets);
663 /* save a copy of the string for error messages */
664 strncpy(cmd, str, sizeof(cmd) - 1);
665 cmd[sizeof(cmd) - 1] = 0;
669 /* scan for token start */
670 while (isspace(*sep))
673 if (ntokens < (got_hops ? 3 : 2))
681 /* scan for token end */
682 while (*sep != 0 && !isspace(*sep))
688 tmp2 = &nets; /* expanding nets */
689 } else if (ntokens == 2 &&
690 lnet_parse_hops(token, &hops)) {
691 got_hops = 1; /* got a hop count */
694 tmp2 = &gateways; /* expanding gateways */
697 ltb = lnet_new_text_buf(strlen(token));
701 strcpy(ltb->ltb_text, token);
702 tmp1 = <b->ltb_list;
703 list_add_tail(tmp1, tmp2);
705 while (tmp1 != tmp2) {
706 ltb = list_entry(tmp1, lnet_text_buf_t, ltb_list);
708 rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
714 if (rc > 0) { /* expanded! */
715 list_del(<b->ltb_list);
716 lnet_free_text_buf(ltb);
721 net = libcfs_str2net(ltb->ltb_text);
722 if (net == LNET_NIDNET(LNET_NID_ANY) ||
723 LNET_NETTYP(net) == LOLND)
726 rc = lnet_parse_priority(ltb->ltb_text,
731 nid = libcfs_str2nid(ltb->ltb_text);
732 if (nid == LNET_NID_ANY ||
733 LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
742 LASSERT(!list_empty(&nets));
743 LASSERT(!list_empty(&gateways));
745 list_for_each(tmp1, &nets) {
746 ltb = list_entry(tmp1, lnet_text_buf_t, ltb_list);
747 net = libcfs_str2net(ltb->ltb_text);
748 LASSERT(net != LNET_NIDNET(LNET_NID_ANY));
750 list_for_each(tmp2, &gateways) {
751 ltb = list_entry(tmp2, lnet_text_buf_t, ltb_list);
752 nid = libcfs_str2nid(ltb->ltb_text);
753 LASSERT(nid != LNET_NID_ANY);
755 if (lnet_islocalnid(nid)) {
760 rc = lnet_add_route(net, hops, nid, priority);
762 CERROR("Can't create route to %s via %s\n",
764 libcfs_nid2str(nid));
774 lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
776 lnet_free_text_bufs(&nets);
777 lnet_free_text_bufs(&gateways);
782 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
784 lnet_text_buf_t *ltb;
786 while (!list_empty(tbs)) {
787 ltb = list_entry(tbs->next, lnet_text_buf_t, ltb_list);
789 if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
790 lnet_free_text_bufs(tbs);
794 list_del(<b->ltb_list);
795 lnet_free_text_buf(ltb);
802 lnet_parse_routes(char *routes, int *im_a_router)
804 struct list_head tbs;
809 INIT_LIST_HEAD(&tbs);
811 if (lnet_str2tbs_sep(&tbs, routes) < 0) {
812 CERROR("Error parsing routes\n");
815 rc = lnet_parse_route_tbs(&tbs, im_a_router);
818 LASSERT(lnet_tbnob == 0);
823 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
829 rc = cfs_ip_addr_parse(token, len, &list);
833 for (rc = i = 0; !rc && i < nip; i++)
834 rc = cfs_ip_addr_match(ipaddrs[i], &list);
836 cfs_ip_addr_free(&list);
842 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
844 static char tokens[LNET_SINGLE_TEXTBUF_NOB];
854 LASSERT(strlen(net_entry) < sizeof(tokens));
856 /* work on a copy of the string */
857 strcpy(tokens, net_entry);
860 /* scan for token start */
861 while (isspace(*sep))
868 /* scan for token end */
869 while (*sep != 0 && !isspace(*sep))
874 if (ntokens++ == 0) {
881 rc = lnet_match_network_token(token, len, ipaddrs, nip);
883 lnet_syntax("ip2nets", net_entry,
884 (int)(token - tokens), len);
888 matched |= (rc != 0);
894 strcpy(net_entry, net); /* replace with matched net */
899 lnet_netspec2net(char *netspec)
901 char *bracket = strchr(netspec, '(');
907 net = libcfs_str2net(netspec);
916 lnet_splitnets(char *source, struct list_head *nets)
922 lnet_text_buf_t *tb2;
928 LASSERT(!list_empty(nets));
929 LASSERT(nets->next == nets->prev); /* single entry */
931 tb = list_entry(nets->next, lnet_text_buf_t, ltb_list);
934 sep = strchr(tb->ltb_text, ',');
935 bracket = strchr(tb->ltb_text, '(');
940 /* netspec lists interfaces... */
942 offset2 = offset + (int)(bracket - tb->ltb_text);
943 len = strlen(bracket);
945 bracket = strchr(bracket + 1, ')');
947 if (bracket == NULL ||
948 !(bracket[1] == ',' || bracket[1] == 0)) {
949 lnet_syntax("ip2nets", source, offset2, len);
953 sep = (bracket[1] == 0) ? NULL : bracket + 1;
959 net = lnet_netspec2net(tb->ltb_text);
960 if (net == LNET_NIDNET(LNET_NID_ANY)) {
961 lnet_syntax("ip2nets", source, offset,
962 strlen(tb->ltb_text));
966 list_for_each(t, nets) {
967 tb2 = list_entry(t, lnet_text_buf_t, ltb_list);
972 if (net == lnet_netspec2net(tb2->ltb_text)) {
973 /* duplicate network */
974 lnet_syntax("ip2nets", source, offset,
975 strlen(tb->ltb_text));
983 offset += (int)(sep - tb->ltb_text);
984 tb2 = lnet_new_text_buf(strlen(sep));
988 strcpy(tb2->ltb_text, sep);
989 list_add_tail(&tb2->ltb_list, nets);
996 lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
998 static char networks[LNET_SINGLE_TEXTBUF_NOB];
999 static char source[LNET_SINGLE_TEXTBUF_NOB];
1001 struct list_head raw_entries;
1002 struct list_head matched_nets;
1003 struct list_head current_nets;
1004 struct list_head *t;
1005 struct list_head *t2;
1006 lnet_text_buf_t *tb;
1007 lnet_text_buf_t *tb2;
1015 INIT_LIST_HEAD(&raw_entries);
1016 if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
1017 CERROR("Error parsing ip2nets\n");
1018 LASSERT(lnet_tbnob == 0);
1022 INIT_LIST_HEAD(&matched_nets);
1023 INIT_LIST_HEAD(¤t_nets);
1029 while (!list_empty(&raw_entries)) {
1030 tb = list_entry(raw_entries.next, lnet_text_buf_t,
1033 strncpy(source, tb->ltb_text, sizeof(source)-1);
1034 source[sizeof(source)-1] = 0;
1036 /* replace ltb_text with the network(s) add on match */
1037 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
1041 list_del(&tb->ltb_list);
1043 if (rc == 0) { /* no match */
1044 lnet_free_text_buf(tb);
1048 /* split into separate networks */
1049 INIT_LIST_HEAD(¤t_nets);
1050 list_add(&tb->ltb_list, ¤t_nets);
1051 rc = lnet_splitnets(source, ¤t_nets);
1056 list_for_each(t, ¤t_nets) {
1057 tb = list_entry(t, lnet_text_buf_t, ltb_list);
1058 net1 = lnet_netspec2net(tb->ltb_text);
1059 LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
1061 list_for_each(t2, &matched_nets) {
1062 tb2 = list_entry(t2, lnet_text_buf_t,
1064 net2 = lnet_netspec2net(tb2->ltb_text);
1065 LASSERT(net2 != LNET_NIDNET(LNET_NID_ANY));
1078 lnet_free_text_bufs(¤t_nets);
1082 list_for_each_safe(t, t2, ¤t_nets) {
1083 tb = list_entry(t, lnet_text_buf_t, ltb_list);
1085 list_del(&tb->ltb_list);
1086 list_add_tail(&tb->ltb_list, &matched_nets);
1088 len += snprintf(networks + len, sizeof(networks) - len,
1089 "%s%s", (len == 0) ? "" : ",",
1092 if (len >= sizeof(networks)) {
1093 CERROR("Too many matched networks\n");
1103 lnet_free_text_bufs(&raw_entries);
1104 lnet_free_text_bufs(&matched_nets);
1105 lnet_free_text_bufs(¤t_nets);
1106 LASSERT(lnet_tbnob == 0);
1111 *networksp = networks;
1116 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
1118 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
1122 lnet_ipaddr_enumerate(__u32 **ipaddrsp)
1130 int nif = libcfs_ipif_enumerate(&ifnames);
1137 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
1138 if (ipaddrs == NULL) {
1139 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1140 libcfs_ipif_free_enumeration(ifnames, nif);
1144 for (i = nip = 0; i < nif; i++) {
1145 if (!strcmp(ifnames[i], "lo"))
1148 rc = libcfs_ipif_query(ifnames[i], &up,
1149 &ipaddrs[nip], &netmask);
1151 CWARN("Can't query interface %s: %d\n",
1157 CWARN("Ignoring interface %s: it's down\n",
1165 libcfs_ipif_free_enumeration(ifnames, nif);
1168 *ipaddrsp = ipaddrs;
1171 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
1172 if (ipaddrs2 == NULL) {
1173 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1176 memcpy(ipaddrs2, ipaddrs,
1177 nip * sizeof(*ipaddrs));
1178 *ipaddrsp = ipaddrs2;
1182 lnet_ipaddr_free_enumeration(ipaddrs, nif);
1188 lnet_parse_ip2nets(char **networksp, char *ip2nets)
1191 int nip = lnet_ipaddr_enumerate(&ipaddrs);
1195 LCONSOLE_ERROR_MSG(0x117,
1196 "Error %d enumerating local IP interfaces for ip2nets to match\n",
1202 LCONSOLE_ERROR_MSG(0x118,
1203 "No local IP interfaces for ip2nets to match\n");
1207 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1208 lnet_ipaddr_free_enumeration(ipaddrs, nip);
1211 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
1216 LCONSOLE_ERROR_MSG(0x11a,
1217 "ip2nets does not match any local IP interfaces\n");
1225 lnet_set_ip_niaddr(lnet_ni_t *ni)
1227 __u32 net = LNET_NIDNET(ni->ni_nid);
1236 /* Convenience for LNDs that use the IP address of a local interface as
1237 * the local address part of their NID */
1239 if (ni->ni_interfaces[0] != NULL) {
1241 CLASSERT(LNET_MAX_INTERFACES > 1);
1243 if (ni->ni_interfaces[1] != NULL) {
1244 CERROR("Net %s doesn't support multiple interfaces\n",
1245 libcfs_net2str(net));
1249 rc = libcfs_ipif_query(ni->ni_interfaces[0],
1250 &up, &ip, &netmask);
1252 CERROR("Net %s can't query interface %s: %d\n",
1253 libcfs_net2str(net), ni->ni_interfaces[0], rc);
1258 CERROR("Net %s can't use interface %s: it's down\n",
1259 libcfs_net2str(net), ni->ni_interfaces[0]);
1263 ni->ni_nid = LNET_MKNID(net, ip);
1267 n = libcfs_ipif_enumerate(&names);
1269 CERROR("Net %s can't enumerate interfaces: %d\n",
1270 libcfs_net2str(net), n);
1274 for (i = 0; i < n; i++) {
1275 if (!strcmp(names[i], "lo")) /* skip the loopback IF */
1278 rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
1281 CWARN("Net %s can't query interface %s: %d\n",
1282 libcfs_net2str(net), names[i], rc);
1287 CWARN("Net %s ignoring interface %s (down)\n",
1288 libcfs_net2str(net), names[i]);
1292 libcfs_ipif_free_enumeration(names, n);
1293 ni->ni_nid = LNET_MKNID(net, ip);
1297 CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
1298 libcfs_ipif_free_enumeration(names, n);
1301 EXPORT_SYMBOL(lnet_set_ip_niaddr);