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, 2015, 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)
102 if (ni->ni_refs != NULL)
103 cfs_percpt_free(ni->ni_refs);
105 if (ni->ni_tx_queues != NULL)
106 cfs_percpt_free(ni->ni_tx_queues);
108 if (ni->ni_cpts != NULL)
109 cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
111 if (ni->ni_lnd_tunables != NULL)
112 LIBCFS_FREE(ni->ni_lnd_tunables, sizeof(*ni->ni_lnd_tunables));
114 for (i = 0; i < LNET_MAX_INTERFACES &&
115 ni->ni_interfaces[i] != NULL; i++) {
116 LIBCFS_FREE(ni->ni_interfaces[i],
117 strlen(ni->ni_interfaces[i]) + 1);
119 LIBCFS_FREE(ni, sizeof(*ni));
123 lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
125 struct lnet_tx_queue *tq;
130 if (!lnet_net_unique(net, nilist)) {
131 LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n",
132 libcfs_net2str(net));
136 LIBCFS_ALLOC(ni, sizeof(*ni));
138 CERROR("Out of memory creating network %s\n",
139 libcfs_net2str(net));
143 spin_lock_init(&ni->ni_lock);
144 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 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 list_add_tail(&ni->ni_list, nilist);
189 lnet_parse_networks(struct list_head *nilist, char *networks)
191 struct cfs_expr_list *el = NULL;
199 struct list_head *temp_node;
201 if (networks == NULL) {
202 CERROR("networks string is undefined\n");
206 if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
207 /* _WAY_ conservative */
208 LCONSOLE_ERROR_MSG(0x112, "Can't parse networks: string too "
213 tokensize = strlen(networks) + 1;
215 LIBCFS_ALLOC(tokens, tokensize);
216 if (tokens == NULL) {
217 CERROR("Can't allocate net tokens\n");
221 memcpy(tokens, networks, tokensize);
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)) {
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 /* Allocate a separate piece of memory and copy
334 * into it the string, so we don't have
335 * a depencency on the tokens string. This way we
336 * can free the tokens at the end of the function.
337 * The newly allocated ni_interfaces[] can be
338 * freed when freeing the NI */
339 LIBCFS_ALLOC(ni->ni_interfaces[niface],
341 if (ni->ni_interfaces[niface] == NULL) {
342 CERROR("Can't allocate net interface name\n");
345 strncpy(ni->ni_interfaces[niface], iface,
349 } while (iface != NULL);
352 comma = strchr(bracket + 1, ',');
355 str = cfs_trimwhite(str);
364 str = cfs_trimwhite(str);
371 list_for_each(temp_node, nilist)
374 LIBCFS_FREE(tokens, tokensize);
378 lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
380 while (!list_empty(nilist)) {
381 ni = list_entry(nilist->next, lnet_ni_t, ni_list);
383 list_del(&ni->ni_list);
388 cfs_expr_list_free(el);
390 LIBCFS_FREE(tokens, tokensize);
395 static struct lnet_text_buf *lnet_new_text_buf(int str_len)
397 struct lnet_text_buf *ltb;
400 /* NB allocate space for the terminating 0 */
401 nob = offsetof(struct lnet_text_buf, ltb_text[str_len + 1]);
402 if (nob > LNET_SINGLE_TEXTBUF_NOB) {
403 /* _way_ conservative for "route net gateway..." */
404 CERROR("text buffer too big\n");
408 if (lnet_tbnob + nob > LNET_MAX_TEXTBUF_NOB) {
409 CERROR("Too many text buffers\n");
413 LIBCFS_ALLOC(ltb, nob);
418 ltb->ltb_text[0] = 0;
424 lnet_free_text_buf(struct lnet_text_buf *ltb)
426 lnet_tbnob -= ltb->ltb_size;
427 LIBCFS_FREE(ltb, ltb->ltb_size);
431 lnet_free_text_bufs(struct list_head *tbs)
433 struct lnet_text_buf *ltb;
435 while (!list_empty(tbs)) {
436 ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
438 list_del(<b->ltb_list);
439 lnet_free_text_buf(ltb);
444 lnet_print_text_bufs(struct list_head *tbs)
446 struct list_head *tmp;
447 struct lnet_text_buf *ltb;
449 list_for_each(tmp, tbs) {
450 ltb = list_entry(tmp, struct lnet_text_buf, ltb_list);
452 CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
455 CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
459 lnet_str2tbs_sep(struct list_head *tbs, char *str)
461 struct list_head pending;
465 struct lnet_text_buf *ltb;
467 INIT_LIST_HEAD(&pending);
469 /* Split 'str' into separate commands */
471 /* skip leading whitespace */
472 while (isspace(*str))
475 /* scan for separator or comment */
476 for (sep = str; *sep != 0; sep++)
477 if (lnet_issep(*sep) || *sep == '#')
480 nob = (int)(sep - str);
482 ltb = lnet_new_text_buf(nob);
484 lnet_free_text_bufs(&pending);
488 for (i = 0; i < nob; i++)
490 ltb->ltb_text[i] = ' ';
492 ltb->ltb_text[i] = str[i];
494 ltb->ltb_text[nob] = 0;
496 list_add_tail(<b->ltb_list, &pending);
500 /* scan for separator */
503 } while (*sep != 0 && !lnet_issep(*sep));
512 list_splice(&pending, tbs->prev);
517 lnet_expand1tb(struct list_head *list,
518 char *str, char *sep1, char *sep2,
519 char *item, int itemlen)
521 int len1 = (int)(sep1 - str);
522 int len2 = strlen(sep2 + 1);
523 struct lnet_text_buf *ltb;
525 LASSERT (*sep1 == '[');
526 LASSERT (*sep2 == ']');
528 ltb = lnet_new_text_buf(len1 + itemlen + len2);
532 memcpy(ltb->ltb_text, str, len1);
533 memcpy(<b->ltb_text[len1], item, itemlen);
534 memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2);
535 ltb->ltb_text[len1 + itemlen + len2] = 0;
537 list_add_tail(<b->ltb_list, list);
542 lnet_str2tbs_expand(struct list_head *tbs, char *str)
545 struct list_head pending;
557 INIT_LIST_HEAD(&pending);
559 sep = strchr(str, '[');
560 if (sep == NULL) /* nothing to expand */
563 sep2 = strchr(sep, ']');
567 for (parsed = sep; parsed < sep2; parsed = enditem) {
570 while (enditem < sep2 && *enditem != ',')
573 if (enditem == parsed) /* no empty items */
576 if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
578 if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
580 /* simple string enumeration */
581 if (lnet_expand1tb(&pending, str, sep, sep2,
582 parsed, (int)(enditem - parsed)) != 0)
591 /* range expansion */
593 if (enditem != parsed + scanned) /* no trailing junk */
596 if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
597 (hi - lo) % stride != 0)
600 for (i = lo; i <= hi; i += stride) {
602 snprintf(num, sizeof(num), "%d", i);
604 if (nob + 1 == sizeof(num))
607 if (lnet_expand1tb(&pending, str, sep, sep2,
613 list_splice(&pending, tbs->prev);
617 lnet_free_text_bufs(&pending);
622 lnet_parse_hops (char *str, unsigned int *hops)
624 int len = strlen(str);
627 return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
629 *hops > 0 && *hops < 256);
632 #define LNET_PRIORITY_SEPARATOR (':')
635 lnet_parse_priority(char *str, unsigned int *priority, char **token)
641 sep = strchr(str, LNET_PRIORITY_SEPARATOR);
646 len = strlen(sep + 1);
648 if ((sscanf((sep+1), "%u%n", priority, &nob) < 1) || (len != nob)) {
649 /* Update the caller's token pointer so it treats the found
650 priority as the token to report in the error message. */
651 *token += sep - str + 1;
655 CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
658 * Change priority separator to \0 to be able to parse NID
665 lnet_parse_route (char *str, int *im_a_router)
667 /* static scratch buffer OK (single threaded) */
668 static char cmd[LNET_SINGLE_TEXTBUF_NOB];
670 struct list_head nets;
671 struct list_head gateways;
672 struct list_head *tmp1;
673 struct list_head *tmp2;
676 struct lnet_text_buf *ltb;
684 unsigned int priority = 0;
686 INIT_LIST_HEAD(&gateways);
687 INIT_LIST_HEAD(&nets);
689 /* save a copy of the string for error messages */
690 strncpy(cmd, str, sizeof(cmd));
691 cmd[sizeof(cmd) - 1] = '\0';
695 /* scan for token start */
696 while (isspace(*sep))
699 if (ntokens < (got_hops ? 3 : 2))
707 /* scan for token end */
708 while (*sep != 0 && !isspace(*sep))
714 tmp2 = &nets; /* expanding nets */
715 } else if (ntokens == 2 &&
716 lnet_parse_hops(token, &hops)) {
717 got_hops = 1; /* got a hop count */
720 tmp2 = &gateways; /* expanding gateways */
723 ltb = lnet_new_text_buf(strlen(token));
727 strcpy(ltb->ltb_text, token);
728 tmp1 = <b->ltb_list;
729 list_add_tail(tmp1, tmp2);
731 while (tmp1 != tmp2) {
732 ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
734 rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
740 if (rc > 0) { /* expanded! */
741 list_del(<b->ltb_list);
742 lnet_free_text_buf(ltb);
747 net = libcfs_str2net(ltb->ltb_text);
748 if (net == LNET_NIDNET(LNET_NID_ANY) ||
749 LNET_NETTYP(net) == LOLND)
752 rc = lnet_parse_priority(ltb->ltb_text,
757 nid = libcfs_str2nid(ltb->ltb_text);
758 if (nid == LNET_NID_ANY ||
759 LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
765 /* if there are no hops set then we want to flag this value as
766 * unset since hops is an optional parameter */
768 hops = LNET_UNDEFINED_HOPS;
770 LASSERT(!list_empty(&nets));
771 LASSERT(!list_empty(&gateways));
773 list_for_each(tmp1, &nets) {
774 ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
775 net = libcfs_str2net(ltb->ltb_text);
776 LASSERT (net != LNET_NIDNET(LNET_NID_ANY));
778 list_for_each(tmp2, &gateways) {
779 ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
780 nid = libcfs_str2nid(ltb->ltb_text);
781 LASSERT(nid != LNET_NID_ANY);
783 if (lnet_islocalnid(nid)) {
788 rc = lnet_add_route(net, hops, nid, priority);
789 if (rc != 0 && rc != -EEXIST && rc != -EHOSTUNREACH) {
790 CERROR("Can't create route "
793 libcfs_nid2str(nid));
803 lnet_syntax("routes", cmd, (int)(token - str), strlen(token));
805 lnet_free_text_bufs(&nets);
806 lnet_free_text_bufs(&gateways);
811 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
813 struct lnet_text_buf *ltb;
815 while (!list_empty(tbs)) {
816 ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
818 if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
819 lnet_free_text_bufs(tbs);
823 list_del(<b->ltb_list);
824 lnet_free_text_buf(ltb);
831 lnet_parse_routes (char *routes, int *im_a_router)
833 struct list_head tbs;
838 INIT_LIST_HEAD(&tbs);
840 if (lnet_str2tbs_sep(&tbs, routes) < 0) {
841 CERROR("Error parsing routes\n");
844 rc = lnet_parse_route_tbs(&tbs, im_a_router);
847 LASSERT (lnet_tbnob == 0);
852 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
854 struct list_head list = LIST_HEAD_INIT(list);
858 rc = cfs_ip_addr_parse(token, len, &list);
862 for (rc = i = 0; !rc && i < nip; i++)
863 rc = cfs_ip_addr_match(ipaddrs[i], &list);
865 cfs_expr_list_free_list(&list);
871 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
873 static char tokens[LNET_SINGLE_TEXTBUF_NOB];
883 LASSERT (strlen(net_entry) < sizeof(tokens));
885 /* work on a copy of the string */
886 strcpy(tokens, net_entry);
889 /* scan for token start */
890 while (isspace(*sep))
897 /* scan for token end */
898 while (*sep != 0 && !isspace(*sep))
903 if (ntokens++ == 0) {
910 rc = lnet_match_network_token(token, len, ipaddrs, nip);
912 lnet_syntax("ip2nets", net_entry,
913 (int)(token - tokens), len);
917 matched |= (rc != 0);
923 strcpy(net_entry, net); /* replace with matched net */
928 lnet_netspec2net(char *netspec)
930 char *bracket = strchr(netspec, '(');
936 net = libcfs_str2net(netspec);
945 lnet_splitnets(char *source, struct list_head *nets)
950 struct lnet_text_buf *tb;
951 struct lnet_text_buf *tb2;
957 LASSERT(!list_empty(nets));
958 LASSERT(nets->next == nets->prev); /* single entry */
960 tb = list_entry(nets->next, struct lnet_text_buf, ltb_list);
963 sep = strchr(tb->ltb_text, ',');
964 bracket = strchr(tb->ltb_text, '(');
969 /* netspec lists interfaces... */
971 offset2 = offset + (int)(bracket - tb->ltb_text);
972 len = strlen(bracket);
974 bracket = strchr(bracket + 1, ')');
976 if (bracket == NULL ||
977 !(bracket[1] == ',' || bracket[1] == 0)) {
978 lnet_syntax("ip2nets", source, offset2, len);
982 sep = (bracket[1] == 0) ? NULL : bracket + 1;
988 net = lnet_netspec2net(tb->ltb_text);
989 if (net == LNET_NIDNET(LNET_NID_ANY)) {
990 lnet_syntax("ip2nets", source, offset,
991 strlen(tb->ltb_text));
995 list_for_each(t, nets) {
996 tb2 = list_entry(t, struct lnet_text_buf, ltb_list);
1001 if (net == lnet_netspec2net(tb2->ltb_text)) {
1002 /* duplicate network */
1003 lnet_syntax("ip2nets", source, offset,
1004 strlen(tb->ltb_text));
1012 offset += (int)(sep - tb->ltb_text);
1014 tb2 = lnet_new_text_buf(len);
1018 strncpy(tb2->ltb_text, sep, len);
1019 tb2->ltb_text[len] = '\0';
1020 list_add_tail(&tb2->ltb_list, nets);
1027 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
1029 static char networks[LNET_SINGLE_TEXTBUF_NOB];
1030 static char source[LNET_SINGLE_TEXTBUF_NOB];
1032 struct list_head raw_entries;
1033 struct list_head matched_nets;
1034 struct list_head current_nets;
1035 struct list_head *t;
1036 struct list_head *t2;
1037 struct lnet_text_buf *tb;
1038 struct lnet_text_buf *tb2;
1046 INIT_LIST_HEAD(&raw_entries);
1047 if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
1048 CERROR("Error parsing ip2nets\n");
1049 LASSERT (lnet_tbnob == 0);
1053 INIT_LIST_HEAD(&matched_nets);
1054 INIT_LIST_HEAD(¤t_nets);
1060 while (!list_empty(&raw_entries)) {
1061 tb = list_entry(raw_entries.next, struct lnet_text_buf,
1064 strncpy(source, tb->ltb_text, sizeof(source));
1065 source[sizeof(source) - 1] = '\0';
1067 /* replace ltb_text with the network(s) add on match */
1068 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
1072 list_del(&tb->ltb_list);
1074 if (rc == 0) { /* no match */
1075 lnet_free_text_buf(tb);
1079 /* split into separate networks */
1080 INIT_LIST_HEAD(¤t_nets);
1081 list_add(&tb->ltb_list, ¤t_nets);
1082 rc = lnet_splitnets(source, ¤t_nets);
1087 list_for_each(t, ¤t_nets) {
1088 tb = list_entry(t, struct lnet_text_buf, ltb_list);
1089 net1 = lnet_netspec2net(tb->ltb_text);
1090 LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
1092 list_for_each(t2, &matched_nets) {
1093 tb2 = list_entry(t2, struct lnet_text_buf,
1095 net2 = lnet_netspec2net(tb2->ltb_text);
1096 LASSERT(net2 != LNET_NIDNET(LNET_NID_ANY));
1109 lnet_free_text_bufs(¤t_nets);
1113 list_for_each_safe(t, t2, ¤t_nets) {
1114 tb = list_entry(t, struct lnet_text_buf, ltb_list);
1116 list_del(&tb->ltb_list);
1117 list_add_tail(&tb->ltb_list, &matched_nets);
1119 len += snprintf(networks + len, sizeof(networks) - len,
1120 "%s%s", (len == 0) ? "" : ",",
1123 if (len >= sizeof(networks)) {
1124 CERROR("Too many matched networks\n");
1134 lnet_free_text_bufs(&raw_entries);
1135 lnet_free_text_bufs(&matched_nets);
1136 lnet_free_text_bufs(¤t_nets);
1137 LASSERT (lnet_tbnob == 0);
1142 *networksp = networks;
1147 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
1149 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
1153 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
1161 int nif = lnet_ipif_enumerate(&ifnames);
1168 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
1169 if (ipaddrs == NULL) {
1170 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1171 lnet_ipif_free_enumeration(ifnames, nif);
1175 for (i = nip = 0; i < nif; i++) {
1176 if (!strcmp(ifnames[i], "lo"))
1179 rc = lnet_ipif_query(ifnames[i], &up,
1180 &ipaddrs[nip], &netmask);
1182 CWARN("Can't query interface %s: %d\n",
1188 CWARN("Ignoring interface %s: it's down\n",
1196 lnet_ipif_free_enumeration(ifnames, nif);
1199 *ipaddrsp = ipaddrs;
1202 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
1203 if (ipaddrs2 == NULL) {
1204 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1207 memcpy(ipaddrs2, ipaddrs,
1208 nip * sizeof(*ipaddrs));
1209 *ipaddrsp = ipaddrs2;
1213 lnet_ipaddr_free_enumeration(ipaddrs, nif);
1219 lnet_parse_ip2nets (char **networksp, char *ip2nets)
1221 __u32 *ipaddrs = NULL;
1222 int nip = lnet_ipaddr_enumerate(&ipaddrs);
1226 LCONSOLE_ERROR_MSG(0x117, "Error %d enumerating local IP "
1227 "interfaces for ip2nets to match\n", nip);
1232 LCONSOLE_ERROR_MSG(0x118, "No local IP interfaces "
1233 "for ip2nets to match\n");
1237 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1238 lnet_ipaddr_free_enumeration(ipaddrs, nip);
1241 LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);
1246 LCONSOLE_ERROR_MSG(0x11a, "ip2nets does not match "
1247 "any local IP interfaces\n");