1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2005 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.sf.net/projects/lustre/
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_LNET
23 #include <lnet/lib-lnet.h>
25 typedef struct { /* tmp struct for parsing routes */
26 struct list_head ltb_list; /* stash on lists */
27 int ltb_size; /* allocated size */
28 char ltb_text[0]; /* text buffer */
31 static int lnet_tbnob = 0; /* track text buf allocation */
32 #define LNET_MAX_TEXTBUF_NOB (64<<10) /* bound allocation */
33 #define LNET_SINGLE_TEXTBUF_NOB (4<<10)
36 struct list_head lre_list; /* stash in a list */
37 int lre_min; /* min value */
38 int lre_max; /* max value */
39 int lre_stride; /* stride */
42 static int lnet_re_alloc = 0; /* track expr allocation */
45 lnet_syntax(char *name, char *str, int offset, int width)
47 static char dots[LNET_SINGLE_TEXTBUF_NOB];
48 static char dashes[LNET_SINGLE_TEXTBUF_NOB];
50 memset(dots, '.', sizeof(dots));
51 dots[sizeof(dots)-1] = 0;
52 memset(dashes, '-', sizeof(dashes));
53 dashes[sizeof(dashes)-1] = 0;
55 LCONSOLE_ERROR(0x10f, "Error parsing '%s=\"%s\"'\n", name, str);
56 LCONSOLE_ERROR(0x110, "here...........%.*s..%.*s|%.*s|\n",
57 (int)strlen(name), dots, offset, dots,
58 (width < 1) ? 0 : width - 1, dashes);
89 lnet_trimwhite(char *str)
93 while (lnet_iswhite(*str))
96 end = str + strlen(str);
98 if (!lnet_iswhite(end[-1]))
108 lnet_net_unique(__u32 net, struct list_head *nilist)
110 struct list_head *tmp;
113 list_for_each (tmp, nilist) {
114 ni = list_entry(tmp, lnet_ni_t, ni_list);
116 if (LNET_NIDNET(ni->ni_nid) == net)
124 lnet_new_ni(__u32 net, struct list_head *nilist)
128 if (!lnet_net_unique(net, nilist)) {
129 LCONSOLE_ERROR(0x111, "Duplicate network specified: %s\n",
130 libcfs_net2str(net));
134 LIBCFS_ALLOC(ni, sizeof(*ni));
136 CERROR("Out of memory creating network %s\n",
137 libcfs_net2str(net));
141 /* zero counters/flags, NULL pointers... */
142 memset(ni, 0, sizeof(*ni));
144 /* LND will fill in the address part of the NID */
145 ni->ni_nid = LNET_MKNID(net, 0);
146 CFS_INIT_LIST_HEAD(&ni->ni_txq);
148 list_add_tail(&ni->ni_list, nilist);
153 lnet_parse_networks(struct list_head *nilist, char *networks)
155 int tokensize = strlen(networks) + 1;
162 if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
163 /* _WAY_ conservative */
164 LCONSOLE_ERROR(0x112, "Can't parse networks: string too long\n");
168 LIBCFS_ALLOC(tokens, tokensize);
169 if (tokens == NULL) {
170 CERROR("Can't allocate net tokens\n");
174 the_lnet.ln_network_tokens = tokens;
175 the_lnet.ln_network_tokens_nob = tokensize;
176 memcpy (tokens, networks, tokensize);
179 /* Add in the loopback network */
180 ni = lnet_new_ni(LNET_MKNET(LOLND, 0), nilist);
184 while (str != NULL && *str != 0) {
185 char *comma = strchr(str, ',');
186 char *bracket = strchr(str, '(');
190 /* NB we don't check interface conflicts here; it's the LNDs
191 * responsibility (if it cares at all) */
193 if (bracket == NULL ||
194 (comma != NULL && comma < bracket)) {
196 /* no interface list specified */
200 net = libcfs_str2net(lnet_trimwhite(str));
202 if (net == LNET_NIDNET(LNET_NID_ANY)) {
203 lnet_syntax("networks", networks,
204 str - tokens, strlen(str));
205 LCONSOLE_ERROR(0x113, "Unrecognised network type\n");
209 if (LNET_NETTYP(net) != LOLND && /* loopback is implicit */
210 lnet_new_ni(net, nilist) == NULL)
218 net = libcfs_str2net(lnet_trimwhite(str));
219 if (net == LNET_NIDNET(LNET_NID_ANY)) {
220 lnet_syntax("networks", networks,
221 str - tokens, strlen(str));
226 the_lnet.ln_ptlcompat > 0) {
227 LCONSOLE_ERROR(0x114, "Only 1 network supported when "
228 "'portals_compatible' is set\n");
233 ni = lnet_new_ni(net, nilist);
240 bracket = strchr(iface, ')');
241 if (bracket == NULL) {
242 lnet_syntax("networks", networks,
243 iface - tokens, strlen(iface));
249 comma = strchr(iface, ',');
253 iface = lnet_trimwhite(iface);
255 lnet_syntax("networks", networks,
256 iface - tokens, strlen(iface));
260 if (niface == LNET_MAX_INTERFACES) {
261 LCONSOLE_ERROR(0x115, "Too many interfaces for net %s\n",
262 libcfs_net2str(net));
266 ni->ni_interfaces[niface++] = iface;
268 } while (iface != NULL);
271 comma = strchr(bracket + 1, ',');
274 str = lnet_trimwhite(str);
276 lnet_syntax("networks", networks,
277 str - tokens, strlen(str));
284 str = lnet_trimwhite(str);
286 lnet_syntax("networks", networks,
287 str - tokens, strlen(str));
292 LASSERT (!list_empty(nilist));
296 while (!list_empty(nilist)) {
297 ni = list_entry(nilist->next, lnet_ni_t, ni_list);
299 list_del(&ni->ni_list);
300 LIBCFS_FREE(ni, sizeof(*ni));
302 LIBCFS_FREE(tokens, tokensize);
303 the_lnet.ln_network_tokens = NULL;
309 lnet_new_text_buf (int str_len)
311 lnet_text_buf_t *ltb;
314 /* NB allocate space for the terminating 0 */
315 nob = offsetof(lnet_text_buf_t, ltb_text[str_len + 1]);
316 if (nob > LNET_SINGLE_TEXTBUF_NOB) {
317 /* _way_ conservative for "route net gateway..." */
318 CERROR("text buffer too big\n");
322 if (lnet_tbnob + nob > LNET_MAX_TEXTBUF_NOB) {
323 CERROR("Too many text buffers\n");
327 LIBCFS_ALLOC(ltb, nob);
332 ltb->ltb_text[0] = 0;
338 lnet_free_text_buf (lnet_text_buf_t *ltb)
340 lnet_tbnob -= ltb->ltb_size;
341 LIBCFS_FREE(ltb, ltb->ltb_size);
345 lnet_free_text_bufs(struct list_head *tbs)
347 lnet_text_buf_t *ltb;
349 while (!list_empty(tbs)) {
350 ltb = list_entry(tbs->next, lnet_text_buf_t, ltb_list);
352 list_del(<b->ltb_list);
353 lnet_free_text_buf(ltb);
358 lnet_print_text_bufs(struct list_head *tbs)
360 struct list_head *tmp;
361 lnet_text_buf_t *ltb;
363 list_for_each (tmp, tbs) {
364 ltb = list_entry(tmp, lnet_text_buf_t, ltb_list);
366 CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
369 CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
373 lnet_str2tbs_sep (struct list_head *tbs, char *str)
375 struct list_head pending;
379 lnet_text_buf_t *ltb;
381 INIT_LIST_HEAD(&pending);
383 /* Split 'str' into separate commands */
385 /* skip leading whitespace */
386 while (lnet_iswhite(*str))
389 /* scan for separator or comment */
390 for (sep = str; *sep != 0; sep++)
391 if (lnet_issep(*sep) || *sep == '#')
396 ltb = lnet_new_text_buf(nob);
398 lnet_free_text_bufs(&pending);
402 for (i = 0; i < nob; i++)
403 if (lnet_iswhite(str[i]))
404 ltb->ltb_text[i] = ' ';
406 ltb->ltb_text[i] = str[i];
408 ltb->ltb_text[nob] = 0;
410 list_add_tail(<b->ltb_list, &pending);
414 /* scan for separator */
417 } while (*sep != 0 && !lnet_issep(*sep));
426 list_splice(&pending, tbs->prev);
431 lnet_expand1tb (struct list_head *list,
432 char *str, char *sep1, char *sep2,
433 char *item, int itemlen)
435 int len1 = sep1 - str;
436 int len2 = strlen(sep2 + 1);
437 lnet_text_buf_t *ltb;
439 LASSERT (*sep1 == '[');
440 LASSERT (*sep2 == ']');
442 ltb = lnet_new_text_buf(len1 + itemlen + len2);
446 memcpy(ltb->ltb_text, str, len1);
447 memcpy(<b->ltb_text[len1], item, itemlen);
448 memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2);
449 ltb->ltb_text[len1 + itemlen + len2] = 0;
451 list_add_tail(<b->ltb_list, list);
456 lnet_str2tbs_expand (struct list_head *tbs, char *str)
459 struct list_head pending;
471 INIT_LIST_HEAD(&pending);
473 sep = strchr(str, '[');
474 if (sep == NULL) /* nothing to expand */
477 sep2 = strchr(sep, ']');
481 for (parsed = sep; parsed < sep2; parsed = enditem) {
484 while (enditem < sep2 && *enditem != ',')
487 if (enditem == parsed) /* no empty items */
490 if (sscanf(parsed, "%d-%d/%d%n", &lo, &hi, &stride, &scanned) < 3) {
492 if (sscanf(parsed, "%d-%d%n", &lo, &hi, &scanned) < 2) {
494 /* simple string enumeration */
495 if (lnet_expand1tb(&pending, str, sep, sep2,
496 parsed, enditem - parsed) != 0)
505 /* range expansion */
507 if (enditem != parsed + scanned) /* no trailing junk */
510 if (hi < 0 || lo < 0 || stride < 0 || hi < lo ||
511 (hi - lo) % stride != 0)
514 for (i = lo; i <= hi; i += stride) {
516 snprintf(num, sizeof(num), "%d", i);
518 if (nob + 1 == sizeof(num))
521 if (lnet_expand1tb(&pending, str, sep, sep2,
527 list_splice(&pending, tbs->prev);
531 lnet_free_text_bufs(&pending);
536 lnet_parse_hops (char *str, unsigned int *hops)
538 int len = strlen(str);
541 return (sscanf(str, "%u%n", hops, &nob) >= 1 &&
543 *hops > 0 && *hops < 256);
548 lnet_parse_route (char *str, int *im_a_router)
550 /* static scratch buffer OK (single threaded) */
551 static char cmd[LNET_SINGLE_TEXTBUF_NOB];
553 struct list_head nets;
554 struct list_head gateways;
555 struct list_head *tmp1;
556 struct list_head *tmp2;
559 lnet_text_buf_t *ltb;
568 CFS_INIT_LIST_HEAD(&gateways);
569 CFS_INIT_LIST_HEAD(&nets);
571 /* save a copy of the string for error messages */
572 strncpy(cmd, str, sizeof(cmd) - 1);
573 cmd[sizeof(cmd) - 1] = 0;
577 /* scan for token start */
578 while (lnet_iswhite(*sep))
581 if (ntokens < (got_hops ? 3 : 2))
589 /* scan for token end */
590 while (*sep != 0 && !lnet_iswhite(*sep))
596 tmp2 = &nets; /* expanding nets */
597 } else if (ntokens == 2 &&
598 lnet_parse_hops(token, &hops)) {
599 got_hops = 1; /* got a hop count */
602 tmp2 = &gateways; /* expanding gateways */
605 ltb = lnet_new_text_buf(strlen(token));
609 strcpy(ltb->ltb_text, token);
610 tmp1 = <b->ltb_list;
611 list_add_tail(tmp1, tmp2);
613 while (tmp1 != tmp2) {
614 ltb = list_entry(tmp1, lnet_text_buf_t, ltb_list);
616 rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
622 if (rc > 0) { /* expanded! */
623 list_del(<b->ltb_list);
624 lnet_free_text_buf(ltb);
629 net = libcfs_str2net(ltb->ltb_text);
630 if (net == LNET_NIDNET(LNET_NID_ANY) ||
631 LNET_NETTYP(net) == LOLND)
634 nid = libcfs_str2nid(ltb->ltb_text);
635 if (nid == LNET_NID_ANY ||
636 LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
645 LASSERT (!list_empty(&nets));
646 LASSERT (!list_empty(&gateways));
648 list_for_each (tmp1, &nets) {
649 ltb = list_entry(tmp1, lnet_text_buf_t, ltb_list);
650 net = libcfs_str2net(ltb->ltb_text);
651 LASSERT (net != LNET_NIDNET(LNET_NID_ANY));
653 list_for_each (tmp2, &gateways) {
654 ltb = list_entry(tmp2, lnet_text_buf_t, ltb_list);
655 nid = libcfs_str2nid(ltb->ltb_text);
656 LASSERT (nid != LNET_NID_ANY);
658 if (lnet_islocalnid(nid)) {
663 rc = lnet_add_route (net, hops, nid);
665 CERROR("Can't create route "
668 libcfs_nid2str(nid));
678 lnet_syntax("routes", cmd, token - str, strlen(token));
680 lnet_free_text_bufs(&nets);
681 lnet_free_text_bufs(&gateways);
686 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
688 lnet_text_buf_t *ltb;
690 while (!list_empty(tbs)) {
691 ltb = list_entry(tbs->next, lnet_text_buf_t, ltb_list);
693 if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
694 lnet_free_text_bufs(tbs);
698 list_del(<b->ltb_list);
699 lnet_free_text_buf(ltb);
706 lnet_parse_routes (char *routes, int *im_a_router)
708 struct list_head tbs;
713 if (the_lnet.ln_ptlcompat > 0 &&
715 /* Can't route when running in compatibility mode */
716 LCONSOLE_ERROR(0x116, "Route tables are not supported when "
717 "'portals_compatible' is set\n");
721 CFS_INIT_LIST_HEAD(&tbs);
723 if (lnet_str2tbs_sep(&tbs, routes) < 0) {
724 CERROR("Error parsing routes\n");
727 rc = lnet_parse_route_tbs(&tbs, im_a_router);
730 LASSERT (lnet_tbnob == 0);
735 lnet_print_range_exprs(struct list_head *exprs)
738 lnet_range_expr_t *lre;
740 list_for_each(e, exprs) {
741 lre = list_entry(exprs->next, lnet_range_expr_t, lre_list);
743 CDEBUG(D_WARNING, "%d-%d/%d\n",
744 lre->lre_min, lre->lre_max, lre->lre_stride);
747 CDEBUG(D_WARNING, "%d allocated\n", lnet_re_alloc);
751 lnet_new_range_expr(struct list_head *exprs, int min, int max, int stride)
753 lnet_range_expr_t *lre;
755 CDEBUG(D_NET, "%d-%d/%d\n", min, max, stride);
757 if (min < 0 || min > 255 || min > max || stride < 0)
760 LIBCFS_ALLOC(lre, sizeof(*lre));
768 lre->lre_stride = stride;
770 list_add(&lre->lre_list, exprs);
775 lnet_destroy_range_exprs(struct list_head *exprs)
777 lnet_range_expr_t *lre;
779 while (!list_empty(exprs)) {
780 lre = list_entry(exprs->next, lnet_range_expr_t, lre_list);
782 list_del(&lre->lre_list);
783 LIBCFS_FREE(lre, sizeof(*lre));
789 lnet_parse_range_expr(struct list_head *exprs, char *str)
791 int nob = strlen(str);
802 if (!strcmp(str, "*")) /* match all */
803 return lnet_new_range_expr(exprs, 0, 255, 1);
806 if (sscanf(str, "%u%n", &x, &n) >= 1 && n == nob) {
808 return lnet_new_range_expr(exprs, x, x, 1);
811 /* Has to be an expansion */
812 if (!(str[0] == '[' && nob > 2 && str[nob-1] == ']'))
820 /* Comma separated list of expressions... */
821 sep = strchr(str, ',');
827 if (sscanf(str, "%u%n", &x, &n) >= 1 && n == nob) {
829 rc = lnet_new_range_expr(exprs, x, x, 1);
837 if (sscanf(str, "%u-%u%n", &x, &y, &n) >= 2 && n == nob) {
839 rc = lnet_new_range_expr(exprs, x, y, 1);
846 if (sscanf(str, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob) {
848 rc = lnet_new_range_expr(exprs, x, y, z);
856 } while ((str = sep) != NULL);
862 lnet_match_network_token(char *token, __u32 *ipaddrs, int nip)
864 struct list_head exprs[4];
866 lnet_range_expr_t *re;
875 for (i = 0; i < 4; i++)
876 CFS_INIT_LIST_HEAD(&exprs[i]);
878 for (i = 0; i < 4; i++) {
881 token = strchr(token, '.');
889 rc = lnet_parse_range_expr(&exprs[i], str);
896 for (match = i = 0; !match && i < nip; i++) {
899 for (match = 1, j = 0; match && j < 4; j++) {
900 n = (ip >> (8 * (3 - j))) & 0xff;
903 list_for_each(e, &exprs[j]) {
904 re = list_entry(e, lnet_range_expr_t, lre_list);
906 if (re->lre_min <= n &&
908 (n - re->lre_min) % re->lre_stride == 0) {
919 for (i = 0; i < 4; i++)
920 lnet_destroy_range_exprs(&exprs[i]);
921 LASSERT (lnet_re_alloc == 0);
927 lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
929 static char tokens[LNET_SINGLE_TEXTBUF_NOB];
939 LASSERT (strlen(net_entry) < sizeof(tokens));
941 /* work on a copy of the string */
942 strcpy(tokens, net_entry);
945 /* scan for token start */
946 while (lnet_iswhite(*sep))
953 /* scan for token end */
954 while (*sep != 0 && !lnet_iswhite(*sep))
959 if (ntokens++ == 0) {
966 rc = lnet_match_network_token(token, ipaddrs, nip);
968 lnet_syntax("ip2nets", net_entry,
969 token - tokens, len);
973 matched |= (rc != 0);
979 strcpy(net_entry, net); /* replace with matched net */
984 lnet_netspec2net(char *netspec)
986 char *bracket = strchr(netspec, '(');
992 net = libcfs_str2net(netspec);
1001 lnet_splitnets(char *source, struct list_head *nets)
1006 lnet_text_buf_t *tb;
1007 lnet_text_buf_t *tb2;
1008 struct list_head *t;
1013 LASSERT (!list_empty(nets));
1014 LASSERT (nets->next == nets->prev); /* single entry */
1016 tb = list_entry(nets->next, lnet_text_buf_t, ltb_list);
1019 sep = strchr(tb->ltb_text, ',');
1020 bracket = strchr(tb->ltb_text, '(');
1025 /* netspec lists interfaces... */
1027 offset2 = offset + (bracket - tb->ltb_text);
1028 len = strlen(bracket);
1030 bracket = strchr(bracket + 1, ')');
1032 if (bracket == NULL ||
1033 !(bracket[1] == ',' || bracket[1] == 0)) {
1034 lnet_syntax("ip2nets", source, offset2, len);
1038 sep = (bracket[1] == 0) ? NULL : bracket + 1;
1044 net = lnet_netspec2net(tb->ltb_text);
1045 if (net == LNET_NIDNET(LNET_NID_ANY)) {
1046 lnet_syntax("ip2nets", source, offset,
1047 strlen(tb->ltb_text));
1051 list_for_each(t, nets) {
1052 tb2 = list_entry(t, lnet_text_buf_t, ltb_list);
1057 if (net == lnet_netspec2net(tb2->ltb_text)) {
1058 /* duplicate network */
1059 lnet_syntax("ip2nets", source, offset,
1060 strlen(tb->ltb_text));
1068 offset += sep - tb->ltb_text;
1069 tb2 = lnet_new_text_buf(strlen(sep));
1073 strcpy(tb2->ltb_text, sep);
1074 list_add_tail(&tb2->ltb_list, nets);
1081 lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
1083 static char networks[LNET_SINGLE_TEXTBUF_NOB];
1084 static char source[LNET_SINGLE_TEXTBUF_NOB];
1086 struct list_head raw_entries;
1087 struct list_head matched_nets;
1088 struct list_head current_nets;
1089 struct list_head *t;
1090 struct list_head *t2;
1091 lnet_text_buf_t *tb;
1092 lnet_text_buf_t *tb2;
1100 CFS_INIT_LIST_HEAD(&raw_entries);
1101 if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
1102 CERROR("Error parsing ip2nets\n");
1103 LASSERT (lnet_tbnob == 0);
1107 CFS_INIT_LIST_HEAD(&matched_nets);
1108 CFS_INIT_LIST_HEAD(¤t_nets);
1114 while (!list_empty(&raw_entries)) {
1115 tb = list_entry(raw_entries.next, lnet_text_buf_t, ltb_list);
1117 strncpy(source, tb->ltb_text, sizeof(source)-1);
1118 source[sizeof(source)-1] = 0;
1120 /* replace ltb_text with the network(s) add on match */
1121 rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);
1125 list_del(&tb->ltb_list);
1127 if (rc == 0) { /* no match */
1128 lnet_free_text_buf(tb);
1132 /* split into separate networks */
1133 CFS_INIT_LIST_HEAD(¤t_nets);
1134 list_add(&tb->ltb_list, ¤t_nets);
1135 rc = lnet_splitnets(source, ¤t_nets);
1140 list_for_each (t, ¤t_nets) {
1141 tb = list_entry(t, lnet_text_buf_t, ltb_list);
1142 net1 = lnet_netspec2net(tb->ltb_text);
1143 LASSERT (net1 != LNET_NIDNET(LNET_NID_ANY));
1145 list_for_each(t2, &matched_nets) {
1146 tb2 = list_entry(t2, lnet_text_buf_t, ltb_list);
1147 net2 = lnet_netspec2net(tb2->ltb_text);
1148 LASSERT (net2 != LNET_NIDNET(LNET_NID_ANY));
1161 lnet_free_text_bufs(¤t_nets);
1165 list_for_each_safe(t, t2, ¤t_nets) {
1166 tb = list_entry(t, lnet_text_buf_t, ltb_list);
1168 list_del(&tb->ltb_list);
1169 list_add_tail(&tb->ltb_list, &matched_nets);
1171 len += snprintf(networks + len, sizeof(networks) - len,
1172 "%s%s", (len == 0) ? "" : ",",
1175 if (len >= sizeof(networks)) {
1176 CERROR("Too many matched networks\n");
1186 lnet_free_text_bufs(&raw_entries);
1187 lnet_free_text_bufs(&matched_nets);
1188 lnet_free_text_bufs(¤t_nets);
1189 LASSERT (lnet_tbnob == 0);
1194 *networksp = networks;
1200 lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
1202 LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
1206 lnet_ipaddr_enumerate (__u32 **ipaddrsp)
1214 int nif = libcfs_ipif_enumerate(&ifnames);
1221 LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
1222 if (ipaddrs == NULL) {
1223 CERROR("Can't allocate ipaddrs[%d]\n", nif);
1224 libcfs_ipif_free_enumeration(ifnames, nif);
1228 for (i = nip = 0; i < nif; i++) {
1229 if (!strcmp(ifnames[i], "lo"))
1232 rc = libcfs_ipif_query(ifnames[i], &up,
1233 &ipaddrs[nip], &netmask);
1235 CWARN("Can't query interface %s: %d\n",
1241 CWARN("Ignoring interface %s: it's down\n",
1249 libcfs_ipif_free_enumeration(ifnames, nif);
1252 *ipaddrsp = ipaddrs;
1255 LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2));
1256 if (ipaddrs2 == NULL) {
1257 CERROR("Can't allocate ipaddrs[%d]\n", nip);
1260 memcpy(ipaddrs2, ipaddrs,
1261 nip * sizeof(*ipaddrs));
1262 *ipaddrsp = ipaddrs2;
1266 lnet_ipaddr_free_enumeration(ipaddrs, nif);
1272 lnet_parse_ip2nets (char **networksp, char *ip2nets)
1275 int nip = lnet_ipaddr_enumerate(&ipaddrs);
1279 LCONSOLE_ERROR(0x117, "Error %d enumerating local IP interfaces "
1280 "for ip2nets to match\n", nip);
1285 LCONSOLE_ERROR(0x118, "No local IP interfaces "
1286 "for ip2nets to match\n");
1290 rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
1291 lnet_ipaddr_free_enumeration(ipaddrs, nip);
1294 LCONSOLE_ERROR(0x119, "Error %d parsing ip2nets\n", rc);
1299 LCONSOLE_ERROR(0x11a, "ip2nets does not match "
1300 "any local IP interfaces\n");
1308 lnet_set_ip_niaddr (lnet_ni_t *ni)
1310 __u32 net = LNET_NIDNET(ni->ni_nid);
1319 /* Convenience for LNDs that use the IP address of a local interface as
1320 * the local address part of their NID */
1322 if (ni->ni_interfaces[0] != NULL) {
1324 CLASSERT (LNET_MAX_INTERFACES > 1);
1326 if (ni->ni_interfaces[1] != NULL) {
1327 CERROR("Net %s doesn't support multiple interfaces\n",
1328 libcfs_net2str(net));
1332 rc = libcfs_ipif_query(ni->ni_interfaces[0],
1333 &up, &ip, &netmask);
1335 CERROR("Net %s can't query interface %s: %d\n",
1336 libcfs_net2str(net), ni->ni_interfaces[0], rc);
1341 CERROR("Net %s can't use interface %s: it's down\n",
1342 libcfs_net2str(net), ni->ni_interfaces[0]);
1346 ni->ni_nid = LNET_MKNID(net, ip);
1350 n = libcfs_ipif_enumerate(&names);
1352 CERROR("Net %s can't enumerate interfaces: %d\n",
1353 libcfs_net2str(net), n);
1357 for (i = 0; i < n; i++) {
1358 if (!strcmp(names[i], "lo")) /* skip the loopback IF */
1361 rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
1364 CWARN("Net %s can't query interface %s: %d\n",
1365 libcfs_net2str(net), names[i], rc);
1370 CWARN("Net %s ignoring interface %s (down)\n",
1371 libcfs_net2str(net), names[i]);
1375 libcfs_ipif_free_enumeration(names, n);
1376 ni->ni_nid = LNET_MKNID(net, ip);
1380 CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
1381 libcfs_ipif_free_enumeration(names, n);
1384 EXPORT_SYMBOL(lnet_set_ip_niaddr);