Whamcloud - gitweb
LU-4423 lnet: Avoid forward declarations in nidstring.c
[fs/lustre-release.git] / lnet / lnet / nidstrings.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lnet/lnet/nidstrings.c
37  *
38  * Author: Phil Schwan <phil@clusterfs.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_LNET
42
43 #include <libcfs/libcfs.h>
44 #include <lnet/nidstr.h>
45
46 /* max value for numeric network address */
47 #define MAX_NUMERIC_VALUE 0xffffffff
48
49 #define IPSTRING_LENGTH 16
50
51 /* CAVEAT VENDITOR! Keep the canonical string representation of nets/nids
52  * consistent in all conversion functions.  Some code fragments are copied
53  * around for the sake of clarity...
54  */
55
56 /* CAVEAT EMPTOR! Racey temporary buffer allocation!
57  * Choose the number of nidstrings to support the MAXIMUM expected number of
58  * concurrent users.  If there are more, the returned string will be volatile.
59  * NB this number must allow for a process to be descheduled for a timeslice
60  * between getting its string and using it.
61  */
62
63 static char      libcfs_nidstrings[LNET_NIDSTR_COUNT][LNET_NIDSTR_SIZE];
64 static int       libcfs_nidstring_idx;
65
66 static DEFINE_SPINLOCK(libcfs_nidstring_lock);
67
68 char *
69 libcfs_next_nidstring(void)
70 {
71         char          *str;
72         unsigned long  flags;
73
74         spin_lock_irqsave(&libcfs_nidstring_lock, flags);
75
76         str = libcfs_nidstrings[libcfs_nidstring_idx++];
77         if (libcfs_nidstring_idx == ARRAY_SIZE(libcfs_nidstrings))
78                 libcfs_nidstring_idx = 0;
79
80         spin_unlock_irqrestore(&libcfs_nidstring_lock, flags);
81         return str;
82 }
83 EXPORT_SYMBOL(libcfs_next_nidstring);
84
85 static int
86 libcfs_lo_str2addr(const char *str, int nob, __u32 *addr)
87 {
88         *addr = 0;
89         return 1;
90 }
91
92 static void
93 libcfs_ip_addr2str(__u32 addr, char *str, size_t size)
94 {
95         snprintf(str, size, "%u.%u.%u.%u",
96                  (addr >> 24) & 0xff, (addr >> 16) & 0xff,
97                  (addr >> 8) & 0xff, addr & 0xff);
98 }
99
100 /* CAVEAT EMPTOR XscanfX
101  * I use "%n" at the end of a sscanf format to detect trailing junk.  However
102  * sscanf may return immediately if it sees the terminating '0' in a string, so
103  * I initialise the %n variable to the expected length.  If sscanf sets it;
104  * fine, if it doesn't, then the scan ended at the end of the string, which is
105  * fine too :) */
106 static int
107 libcfs_ip_str2addr(const char *str, int nob, __u32 *addr)
108 {
109         unsigned int    a;
110         unsigned int    b;
111         unsigned int    c;
112         unsigned int    d;
113         int             n = nob; /* XscanfX */
114
115         /* numeric IP? */
116         if (sscanf(str, "%u.%u.%u.%u%n", &a, &b, &c, &d, &n) >= 4 &&
117             n == nob &&
118             (a & ~0xff) == 0 && (b & ~0xff) == 0 &&
119             (c & ~0xff) == 0 && (d & ~0xff) == 0) {
120                 *addr = ((a<<24)|(b<<16)|(c<<8)|d);
121                 return 1;
122         }
123         return 0;
124 }
125
126 static int
127 libcfs_ip_addr_range_print(char *buffer, int count, struct list_head *list)
128 {
129         int i = 0, j = 0;
130         struct cfs_expr_list *el;
131
132         list_for_each_entry(el, list, el_link) {
133                 LASSERT(j++ < 4);
134                 if (i != 0)
135                         i += scnprintf(buffer + i, count - i, ".");
136                 i += cfs_expr_list_print(buffer + i, count - i, el);
137         }
138         return i;
139 }
140
141 /**
142  * Print the network part of the nidrange \a nr into the specified \a buffer.
143  *
144  * \retval number of characters written
145  */
146 static void
147 libcfs_decnum_addr2str(__u32 addr, char *str, size_t size)
148 {
149         snprintf(str, size, "%u", addr);
150 }
151
152 static void
153 libcfs_hexnum_addr2str(__u32 addr, char *str, size_t size)
154 {
155         snprintf(str, size, "0x%x", addr);
156 }
157
158 static int
159 libcfs_num_str2addr(const char *str, int nob, __u32 *addr)
160 {
161         int     n;
162
163         n = nob;
164         if (sscanf(str, "0x%x%n", addr, &n) >= 1 && n == nob)
165                 return 1;
166
167         n = nob;
168         if (sscanf(str, "0X%x%n", addr, &n) >= 1 && n == nob)
169                 return 1;
170
171         n = nob;
172         if (sscanf(str, "%u%n", addr, &n) >= 1 && n == nob)
173                 return 1;
174
175         return 0;
176 }
177
178 /**
179  * Nf_parse_addrlist method for networks using numeric addresses.
180  *
181  * Examples of such networks are gm and elan.
182  *
183  * \retval 0 if \a str parsed to numeric address
184  * \retval errno otherwise
185  */
186 static int
187 libcfs_num_parse(char *str, int len, struct list_head *list)
188 {
189         struct cfs_expr_list *el;
190         int     rc;
191
192         rc = cfs_expr_list_parse(str, len, 0, MAX_NUMERIC_VALUE, &el);
193         if (rc == 0)
194                 list_add_tail(&el->el_link, list);
195
196         return rc;
197 }
198
199 static int
200 libcfs_num_addr_range_print(char *buffer, int count, struct list_head *list)
201 {
202         int i = 0, j = 0;
203         struct cfs_expr_list *el;
204
205         list_for_each_entry(el, list, el_link) {
206                 LASSERT(j++ < 1);
207                 i += cfs_expr_list_print(buffer + i, count - i, el);
208         }
209         return i;
210 }
211
212 /*
213  * Nf_match_addr method for networks using numeric addresses
214  *
215  * \retval 1 on match
216  * \retval 0 otherwise
217  */
218 static int
219 libcfs_num_match(__u32 addr, struct list_head *numaddr)
220 {
221         struct cfs_expr_list *el;
222
223         LASSERT(!list_empty(numaddr));
224         el = list_entry(numaddr->next, struct cfs_expr_list, el_link);
225
226         return cfs_expr_list_match(addr, el);
227 }
228
229 static bool cfs_ip_is_contiguous(struct list_head *nidlist);
230 static void cfs_ip_min_max(struct list_head *nidlist, __u32 *min, __u32 *max);
231 static bool cfs_num_is_contiguous(struct list_head *nidlist);
232 static void cfs_num_min_max(struct list_head *nidlist, __u32 *min, __u32 *max);
233
234 static struct netstrfns  libcfs_netstrfns[] = {
235         {/* .nf_type      */  LOLND,
236          /* .nf_name      */  "lo",
237          /* .nf_modname   */  "klolnd",
238          /* .nf_addr2str  */  libcfs_decnum_addr2str,
239          /* .nf_str2addr  */  libcfs_lo_str2addr,
240          /* .nf_parse_addr*/  libcfs_num_parse,
241          /* .nf_print_addrlist*/  libcfs_num_addr_range_print,
242          /* .nf_match_addr*/      libcfs_num_match,
243          /* .nf_is_contiguous */  cfs_num_is_contiguous,
244          /* .nf_min_max   */      cfs_num_min_max},
245         {/* .nf_type      */  SOCKLND,
246          /* .nf_name      */  "tcp",
247          /* .nf_modname   */  "ksocklnd",
248          /* .nf_addr2str  */  libcfs_ip_addr2str,
249          /* .nf_str2addr  */  libcfs_ip_str2addr,
250          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
251          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
252          /* .nf_match_addr*/      cfs_ip_addr_match,
253          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
254          /* .nf_min_max   */      cfs_ip_min_max},
255         {/* .nf_type      */  O2IBLND,
256          /* .nf_name      */  "o2ib",
257          /* .nf_modname   */  "ko2iblnd",
258          /* .nf_addr2str  */  libcfs_ip_addr2str,
259          /* .nf_str2addr  */  libcfs_ip_str2addr,
260          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
261          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
262          /* .nf_match_addr*/      cfs_ip_addr_match,
263          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
264          /* .nf_min_max   */      cfs_ip_min_max},
265         {/* .nf_type      */  CIBLND,
266          /* .nf_name      */  "cib",
267          /* .nf_modname   */  "kciblnd",
268          /* .nf_addr2str  */  libcfs_ip_addr2str,
269          /* .nf_str2addr  */  libcfs_ip_str2addr,
270          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
271          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
272          /* .nf_match_addr*/      cfs_ip_addr_match,
273          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
274          /* .nf_min_max   */      cfs_ip_min_max},
275         {/* .nf_type      */  OPENIBLND,
276          /* .nf_name      */  "openib",
277          /* .nf_modname   */  "kopeniblnd",
278          /* .nf_addr2str  */  libcfs_ip_addr2str,
279          /* .nf_str2addr  */  libcfs_ip_str2addr,
280          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
281          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
282          /* .nf_match_addr*/      cfs_ip_addr_match,
283          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
284          /* .nf_min_max   */      cfs_ip_min_max},
285         {/* .nf_type      */  IIBLND,
286          /* .nf_name      */  "iib",
287          /* .nf_modname   */  "kiiblnd",
288          /* .nf_addr2str  */  libcfs_ip_addr2str,
289          /* .nf_str2addr  */  libcfs_ip_str2addr,
290          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
291          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
292          /* .nf_match_addr*/      cfs_ip_addr_match,
293          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
294          /* .nf_min_max   */      cfs_ip_min_max},
295         {/* .nf_type      */  VIBLND,
296          /* .nf_name      */  "vib",
297          /* .nf_modname   */  "kviblnd",
298          /* .nf_addr2str  */  libcfs_ip_addr2str,
299          /* .nf_str2addr  */  libcfs_ip_str2addr,
300          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
301          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
302          /* .nf_match_addr*/      cfs_ip_addr_match,
303          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
304          /* .nf_min_max   */      cfs_ip_min_max},
305         {/* .nf_type      */  RALND,
306          /* .nf_name      */  "ra",
307          /* .nf_modname   */  "kralnd",
308          /* .nf_addr2str  */  libcfs_ip_addr2str,
309          /* .nf_str2addr  */  libcfs_ip_str2addr,
310          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
311          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
312          /* .nf_match_addr*/      cfs_ip_addr_match,
313          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
314          /* .nf_min_max   */      cfs_ip_min_max},
315         {/* .nf_type      */      QSWLND,
316          /* .nf_name      */      "elan",
317          /* .nf_modname   */      "kqswlnd",
318          /* .nf_addr2str  */      libcfs_decnum_addr2str,
319          /* .nf_str2addr  */      libcfs_num_str2addr,
320          /* .nf_parse_addrlist*/  libcfs_num_parse,
321          /* .nf_print_addrlist*/  libcfs_num_addr_range_print,
322          /* .nf_match_addr*/      libcfs_num_match,
323          /* .nf_is_contiguous */  cfs_num_is_contiguous,
324          /* .nf_min_max   */      cfs_num_min_max},
325         {/* .nf_type      */      GMLND,
326          /* .nf_name      */      "gm",
327          /* .nf_modname   */      "kgmlnd",
328          /* .nf_addr2str  */      libcfs_hexnum_addr2str,
329          /* .nf_str2addr  */      libcfs_num_str2addr,
330          /* .nf_parse_addrlist*/  libcfs_num_parse,
331          /* .nf_print_addrlist*/  libcfs_num_addr_range_print,
332          /* .nf_match_addr*/      libcfs_num_match,
333          /* .nf_is_contiguous */  cfs_num_is_contiguous,
334          /* .nf_min_max   */      cfs_num_min_max},
335         {/* .nf_type      */      MXLND,
336          /* .nf_name      */      "mx",
337          /* .nf_modname   */      "kmxlnd",
338          /* .nf_addr2str  */      libcfs_ip_addr2str,
339          /* .nf_str2addr  */      libcfs_ip_str2addr,
340          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
341          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
342          /* .nf_match_addr*/      cfs_ip_addr_match,
343          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
344          /* .nf_min_max   */      cfs_ip_min_max},
345         {/* .nf_type      */      PTLLND,
346          /* .nf_name      */      "ptl",
347          /* .nf_modname   */      "kptllnd",
348          /* .nf_addr2str  */      libcfs_decnum_addr2str,
349          /* .nf_str2addr  */      libcfs_num_str2addr,
350          /* .nf_parse_addrlist*/  libcfs_num_parse,
351          /* .nf_print_addrlist*/  libcfs_num_addr_range_print,
352          /* .nf_match_addr*/      libcfs_num_match,
353          /* .nf_is_contiguous */  cfs_num_is_contiguous,
354          /* .nf_min_max   */      cfs_num_min_max},
355         {/* .nf_type      */      GNILND,
356          /* .nf_name      */      "gni",
357          /* .nf_modname   */      "kgnilnd",
358          /* .nf_addr2str  */      libcfs_decnum_addr2str,
359          /* .nf_str2addr  */      libcfs_num_str2addr,
360          /* .nf_parse_addrlist*/  libcfs_num_parse,
361          /* .nf_print_addrlist*/  libcfs_num_addr_range_print,
362          /* .nf_match_addr*/      libcfs_num_match,
363          /* .nf_is_contiguous */  cfs_num_is_contiguous,
364          /* .nf_min_max   */      cfs_num_min_max},
365         {/* .nf_type      */      GNIIPLND,
366          /* .nf_name      */      "gip",
367          /* .nf_modname   */      "kgnilnd",
368          /* .nf_addr2str  */      libcfs_ip_addr2str,
369          /* .nf_str2addr  */      libcfs_ip_str2addr,
370          /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
371          /* .nf_print_addrlist*/  libcfs_ip_addr_range_print,
372          /* .nf_match_addr*/      cfs_ip_addr_match,
373          /* .nf_is_contiguous */  cfs_ip_is_contiguous,
374          /* .nf_min_max   */      cfs_ip_min_max},
375          /* placeholder for net0 alias.  It MUST BE THE LAST ENTRY */
376         {/* .nf_type      */  -1},
377 };
378
379 static const size_t libcfs_nnetstrfns = ARRAY_SIZE(libcfs_netstrfns);
380
381 static struct netstrfns *
382 libcfs_lnd2netstrfns(__u32 lnd)
383 {
384         int     i;
385
386         for (i = 0; i < libcfs_nnetstrfns; i++)
387                 if (lnd == libcfs_netstrfns[i].nf_type)
388                         return &libcfs_netstrfns[i];
389
390         return NULL;
391 }
392
393 static struct netstrfns *
394 libcfs_namenum2netstrfns(const char *name)
395 {
396         struct netstrfns *nf;
397         int               i;
398
399         for (i = 0; i < libcfs_nnetstrfns; i++) {
400                 nf = &libcfs_netstrfns[i];
401                 if (nf->nf_type >= 0 &&
402                     !strncmp(name, nf->nf_name, strlen(nf->nf_name)))
403                         return nf;
404         }
405         return NULL;
406 }
407
408 static struct netstrfns *
409 libcfs_name2netstrfns(const char *name)
410 {
411         int    i;
412
413         for (i = 0; i < libcfs_nnetstrfns; i++)
414                 if (libcfs_netstrfns[i].nf_type >= 0 &&
415                     !strcmp(libcfs_netstrfns[i].nf_name, name))
416                         return &libcfs_netstrfns[i];
417
418         return NULL;
419 }
420
421 int
422 libcfs_isknown_lnd(__u32 lnd)
423 {
424         return libcfs_lnd2netstrfns(lnd) != NULL;
425 }
426 EXPORT_SYMBOL(libcfs_isknown_lnd);
427
428 char *
429 libcfs_lnd2modname(__u32 lnd)
430 {
431         struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);
432
433         return (nf == NULL) ? NULL : nf->nf_modname;
434 }
435 EXPORT_SYMBOL(libcfs_lnd2modname);
436
437 int
438 libcfs_str2lnd(const char *str)
439 {
440         struct netstrfns *nf = libcfs_name2netstrfns(str);
441
442         if (nf != NULL)
443                 return nf->nf_type;
444
445         return -1;
446 }
447 EXPORT_SYMBOL(libcfs_str2lnd);
448
449 char *
450 libcfs_lnd2str_r(__u32 lnd, char *buf, size_t buf_size)
451 {
452         struct netstrfns *nf;
453
454         nf = libcfs_lnd2netstrfns(lnd);
455         if (nf == NULL)
456                 snprintf(buf, buf_size, "?%u?", lnd);
457         else
458                 snprintf(buf, buf_size, "%s", nf->nf_name);
459
460         return buf;
461 }
462 EXPORT_SYMBOL(libcfs_lnd2str_r);
463
464 char *
465 libcfs_net2str_r(__u32 net, char *buf, size_t buf_size)
466 {
467         __u32             nnum = LNET_NETNUM(net);
468         __u32             lnd  = LNET_NETTYP(net);
469         struct netstrfns *nf;
470
471         nf = libcfs_lnd2netstrfns(lnd);
472         if (nf == NULL)
473                 snprintf(buf, buf_size, "<%u:%u>", lnd, nnum);
474         else if (nnum == 0)
475                 snprintf(buf, buf_size, "%s", nf->nf_name);
476         else
477                 snprintf(buf, buf_size, "%s%u", nf->nf_name, nnum);
478
479         return buf;
480 }
481 EXPORT_SYMBOL(libcfs_net2str_r);
482
483 char *
484 libcfs_nid2str_r(lnet_nid_t nid, char *buf, size_t buf_size)
485 {
486         __u32             addr = LNET_NIDADDR(nid);
487         __u32             net  = LNET_NIDNET(nid);
488         __u32             nnum = LNET_NETNUM(net);
489         __u32             lnd  = LNET_NETTYP(net);
490         struct netstrfns *nf;
491
492         if (nid == LNET_NID_ANY) {
493                 strncpy(buf, "<?>", buf_size);
494                 buf[buf_size - 1] = '\0';
495                 return buf;
496         }
497
498         nf = libcfs_lnd2netstrfns(lnd);
499         if (nf == NULL) {
500                 snprintf(buf, buf_size, "%x@<%u:%u>", addr, lnd, nnum);
501         } else {
502                 size_t addr_len;
503
504                 nf->nf_addr2str(addr, buf, buf_size);
505                 addr_len = strlen(buf);
506                 if (nnum == 0)
507                         snprintf(buf + addr_len, buf_size - addr_len, "@%s",
508                                  nf->nf_name);
509                 else
510                         snprintf(buf + addr_len, buf_size - addr_len, "@%s%u",
511                                  nf->nf_name, nnum);
512         }
513
514         return buf;
515 }
516 EXPORT_SYMBOL(libcfs_nid2str_r);
517
518 static struct netstrfns *
519 libcfs_str2net_internal(const char *str, __u32 *net)
520 {
521         struct netstrfns *nf = NULL;
522         int               nob;
523         unsigned int      netnum;
524         int               i;
525
526         for (i = 0; i < libcfs_nnetstrfns; i++) {
527                 nf = &libcfs_netstrfns[i];
528                 if (nf->nf_type >= 0 &&
529                     !strncmp(str, nf->nf_name, strlen(nf->nf_name)))
530                         break;
531         }
532
533         if (i == libcfs_nnetstrfns)
534                 return NULL;
535
536         nob = strlen(nf->nf_name);
537
538         if (strlen(str) == (unsigned int)nob) {
539                 netnum = 0;
540         } else {
541                 if (nf->nf_type == LOLND) /* net number not allowed */
542                         return NULL;
543
544                 str += nob;
545                 i = strlen(str);
546                 if (sscanf(str, "%u%n", &netnum, &i) < 1 ||
547                     i != (int)strlen(str))
548                         return NULL;
549         }
550
551         *net = LNET_MKNET(nf->nf_type, netnum);
552         return nf;
553 }
554
555 __u32
556 libcfs_str2net(const char *str)
557 {
558         __u32  net;
559
560         if (libcfs_str2net_internal(str, &net) != NULL)
561                 return net;
562
563         return LNET_NIDNET(LNET_NID_ANY);
564 }
565 EXPORT_SYMBOL(libcfs_str2net);
566
567 lnet_nid_t
568 libcfs_str2nid(const char *str)
569 {
570         const char       *sep = strchr(str, '@');
571         struct netstrfns *nf;
572         __u32             net;
573         __u32             addr;
574
575         if (sep != NULL) {
576                 nf = libcfs_str2net_internal(sep + 1, &net);
577                 if (nf == NULL)
578                         return LNET_NID_ANY;
579         } else {
580                 sep = str + strlen(str);
581                 net = LNET_MKNET(SOCKLND, 0);
582                 nf = libcfs_lnd2netstrfns(SOCKLND);
583                 LASSERT(nf != NULL);
584         }
585
586         if (!nf->nf_str2addr(str, (int)(sep - str), &addr))
587                 return LNET_NID_ANY;
588
589         return LNET_MKNID(net, addr);
590 }
591 EXPORT_SYMBOL(libcfs_str2nid);
592
593 char *
594 libcfs_id2str(lnet_process_id_t id)
595 {
596         char *str = libcfs_next_nidstring();
597
598         if (id.pid == LNET_PID_ANY) {
599                 snprintf(str, LNET_NIDSTR_SIZE,
600                          "LNET_PID_ANY-%s", libcfs_nid2str(id.nid));
601                 return str;
602         }
603
604         snprintf(str, LNET_NIDSTR_SIZE, "%s%u-%s",
605                  ((id.pid & LNET_PID_USERFLAG) != 0) ? "U" : "",
606                  (id.pid & ~LNET_PID_USERFLAG), libcfs_nid2str(id.nid));
607         return str;
608 }
609 EXPORT_SYMBOL(libcfs_id2str);
610
611 int
612 libcfs_str2anynid(lnet_nid_t *nidp, const char *str)
613 {
614         if (!strcmp(str, "*")) {
615                 *nidp = LNET_NID_ANY;
616                 return 1;
617         }
618
619         *nidp = libcfs_str2nid(str);
620         return *nidp != LNET_NID_ANY;
621 }
622 EXPORT_SYMBOL(libcfs_str2anynid);
623
624 /**
625  * Nid range list syntax.
626  * \verbatim
627  *
628  * <nidlist>         :== <nidrange> [ ' ' <nidrange> ]
629  * <nidrange>        :== <addrrange> '@' <net>
630  * <addrrange>       :== '*' |
631  *                       <ipaddr_range> |
632  *                       <cfs_expr_list>
633  * <ipaddr_range>    :== <cfs_expr_list>.<cfs_expr_list>.<cfs_expr_list>.
634  *                       <cfs_expr_list>
635  * <cfs_expr_list>   :== <number> |
636  *                       <expr_list>
637  * <expr_list>       :== '[' <range_expr> [ ',' <range_expr>] ']'
638  * <range_expr>      :== <number> |
639  *                       <number> '-' <number> |
640  *                       <number> '-' <number> '/' <number>
641  * <net>             :== <netname> | <netname><number>
642  * <netname>         :== "lo" | "tcp" | "o2ib" | "cib" | "openib" | "iib" |
643  *                       "vib" | "ra" | "elan" | "mx" | "ptl"
644  * \endverbatim
645  */
646
647 /**
648  * Structure to represent \<nidrange\> token of the syntax.
649  *
650  * One of this is created for each \<net\> parsed.
651  */
652 struct nidrange {
653         /**
654          * Link to list of this structures which is built on nid range
655          * list parsing.
656          */
657         struct list_head nr_link;
658         /**
659          * List head for addrrange::ar_link.
660          */
661         struct list_head nr_addrranges;
662         /**
663          * Flag indicating that *@<net> is found.
664          */
665         int nr_all;
666         /**
667          * Pointer to corresponding element of libcfs_netstrfns.
668          */
669         struct netstrfns *nr_netstrfns;
670         /**
671          * Number of network. E.g. 5 if \<net\> is "elan5".
672          */
673         int nr_netnum;
674 };
675
676 /**
677  * Structure to represent \<addrrange\> token of the syntax.
678  */
679 struct addrrange {
680         /**
681          * Link to nidrange::nr_addrranges.
682          */
683         struct list_head ar_link;
684         /**
685          * List head for cfs_expr_list::el_list.
686          */
687         struct list_head ar_numaddr_ranges;
688 };
689
690 /**
691  * Parses \<addrrange\> token on the syntax.
692  *
693  * Allocates struct addrrange and links to \a nidrange via
694  * (nidrange::nr_addrranges)
695  *
696  * \retval 0 if \a src parses to '*' | \<ipaddr_range\> | \<cfs_expr_list\>
697  * \retval -errno otherwise
698  */
699 static int
700 parse_addrange(const struct cfs_lstr *src, struct nidrange *nidrange)
701 {
702         struct addrrange *addrrange;
703
704         if (src->ls_len == 1 && src->ls_str[0] == '*') {
705                 nidrange->nr_all = 1;
706                 return 0;
707         }
708
709         LIBCFS_ALLOC(addrrange, sizeof(struct addrrange));
710         if (addrrange == NULL)
711                 return -ENOMEM;
712         list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges);
713         INIT_LIST_HEAD(&addrrange->ar_numaddr_ranges);
714
715         return nidrange->nr_netstrfns->nf_parse_addrlist(src->ls_str,
716                                                 src->ls_len,
717                                                 &addrrange->ar_numaddr_ranges);
718 }
719
720 /**
721  * Finds or creates struct nidrange.
722  *
723  * Checks if \a src is a valid network name, looks for corresponding
724  * nidrange on the ist of nidranges (\a nidlist), creates new struct
725  * nidrange if it is not found.
726  *
727  * \retval pointer to struct nidrange matching network specified via \a src
728  * \retval NULL if \a src does not match any network
729  */
730 static struct nidrange *
731 add_nidrange(const struct cfs_lstr *src,
732              struct list_head *nidlist)
733 {
734         struct netstrfns *nf;
735         struct nidrange *nr;
736         int endlen;
737         unsigned netnum;
738
739         if (src->ls_len >= LNET_NIDSTR_SIZE)
740                 return NULL;
741
742         nf = libcfs_namenum2netstrfns(src->ls_str);
743         if (nf == NULL)
744                 return NULL;
745         endlen = src->ls_len - strlen(nf->nf_name);
746         if (endlen == 0)
747                 /* network name only, e.g. "elan" or "tcp" */
748                 netnum = 0;
749         else {
750                 /* e.g. "elan25" or "tcp23", refuse to parse if
751                  * network name is not appended with decimal or
752                  * hexadecimal number */
753                 if (!cfs_str2num_check(src->ls_str + strlen(nf->nf_name),
754                                        endlen, &netnum, 0, MAX_NUMERIC_VALUE))
755                         return NULL;
756         }
757
758         list_for_each_entry(nr, nidlist, nr_link) {
759                 if (nr->nr_netstrfns != nf)
760                         continue;
761                 if (nr->nr_netnum != netnum)
762                         continue;
763                 return nr;
764         }
765
766         LIBCFS_ALLOC(nr, sizeof(struct nidrange));
767         if (nr == NULL)
768                 return NULL;
769         list_add_tail(&nr->nr_link, nidlist);
770         INIT_LIST_HEAD(&nr->nr_addrranges);
771         nr->nr_netstrfns = nf;
772         nr->nr_all = 0;
773         nr->nr_netnum = netnum;
774
775         return nr;
776 }
777
778 /**
779  * Parses \<nidrange\> token of the syntax.
780  *
781  * \retval 1 if \a src parses to \<addrrange\> '@' \<net\>
782  * \retval 0 otherwise
783  */
784 static int
785 parse_nidrange(struct cfs_lstr *src, struct list_head *nidlist)
786 {
787         struct cfs_lstr addrrange;
788         struct cfs_lstr net;
789         struct cfs_lstr tmp;
790         struct nidrange *nr;
791
792         tmp = *src;
793         if (cfs_gettok(src, '@', &addrrange) == 0)
794                 goto failed;
795
796         if (cfs_gettok(src, '@', &net) == 0 || src->ls_str != NULL)
797                 goto failed;
798
799         nr = add_nidrange(&net, nidlist);
800         if (nr == NULL)
801                 goto failed;
802
803         if (parse_addrange(&addrrange, nr) != 0)
804                 goto failed;
805
806         return 1;
807  failed:
808         CWARN("can't parse nidrange: \"%.*s\"\n", tmp.ls_len, tmp.ls_str);
809         return 0;
810 }
811
812 /**
813  * Frees addrrange structures of \a list.
814  *
815  * For each struct addrrange structure found on \a list it frees
816  * cfs_expr_list list attached to it and frees the addrrange itself.
817  *
818  * \retval none
819  */
820 static void
821 free_addrranges(struct list_head *list)
822 {
823         while (!list_empty(list)) {
824                 struct addrrange *ar;
825
826                 ar = list_entry(list->next, struct addrrange, ar_link);
827
828                 cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
829                 list_del(&ar->ar_link);
830                 LIBCFS_FREE(ar, sizeof(struct addrrange));
831         }
832 }
833
834 /**
835  * Frees nidrange strutures of \a list.
836  *
837  * For each struct nidrange structure found on \a list it frees
838  * addrrange list attached to it and frees the nidrange itself.
839  *
840  * \retval none
841  */
842 void
843 cfs_free_nidlist(struct list_head *list)
844 {
845         struct list_head *pos, *next;
846         struct nidrange *nr;
847
848         list_for_each_safe(pos, next, list) {
849                 nr = list_entry(pos, struct nidrange, nr_link);
850                 free_addrranges(&nr->nr_addrranges);
851                 list_del(pos);
852                 LIBCFS_FREE(nr, sizeof(struct nidrange));
853         }
854 }
855 EXPORT_SYMBOL(cfs_free_nidlist);
856
857 /**
858  * Parses nid range list.
859  *
860  * Parses with rigorous syntax and overflow checking \a str into
861  * \<nidrange\> [ ' ' \<nidrange\> ], compiles \a str into set of
862  * structures and links that structure to \a nidlist. The resulting
863  * list can be used to match a NID againts set of NIDS defined by \a
864  * str.
865  * \see cfs_match_nid
866  *
867  * \retval 1 on success
868  * \retval 0 otherwise
869  */
870 int
871 cfs_parse_nidlist(char *str, int len, struct list_head *nidlist)
872 {
873         struct cfs_lstr src;
874         struct cfs_lstr res;
875         int rc;
876
877         src.ls_str = str;
878         src.ls_len = len;
879         INIT_LIST_HEAD(nidlist);
880         while (src.ls_str) {
881                 rc = cfs_gettok(&src, ' ', &res);
882                 if (rc == 0) {
883                         cfs_free_nidlist(nidlist);
884                         return 0;
885                 }
886                 rc = parse_nidrange(&res, nidlist);
887                 if (rc == 0) {
888                         cfs_free_nidlist(nidlist);
889                         return 0;
890                 }
891         }
892         return 1;
893 }
894 EXPORT_SYMBOL(cfs_parse_nidlist);
895
896 /**
897  * Matches a nid (\a nid) against the compiled list of nidranges (\a nidlist).
898  *
899  * \see cfs_parse_nidlist()
900  *
901  * \retval 1 on match
902  * \retval 0  otherwises
903  */
904 int cfs_match_nid(lnet_nid_t nid, struct list_head *nidlist)
905 {
906         struct nidrange *nr;
907         struct addrrange *ar;
908
909         list_for_each_entry(nr, nidlist, nr_link) {
910                 if (nr->nr_netstrfns->nf_type != LNET_NETTYP(LNET_NIDNET(nid)))
911                         continue;
912                 if (nr->nr_netnum != LNET_NETNUM(LNET_NIDNET(nid)))
913                         continue;
914                 if (nr->nr_all)
915                         return 1;
916                 list_for_each_entry(ar, &nr->nr_addrranges, ar_link)
917                         if (nr->nr_netstrfns->nf_match_addr(LNET_NIDADDR(nid),
918                                                         &ar->ar_numaddr_ranges))
919                                 return 1;
920         }
921         return 0;
922 }
923 EXPORT_SYMBOL(cfs_match_nid);
924
925 /**
926  * Print the network part of the nidrange \a nr into the specified \a buffer.
927  *
928  * \retval number of characters written
929  */
930 static int
931 cfs_print_network(char *buffer, int count, struct nidrange *nr)
932 {
933         struct netstrfns *nf = nr->nr_netstrfns;
934
935         if (nr->nr_netnum == 0)
936                 return scnprintf(buffer, count, "@%s", nf->nf_name);
937         else
938                 return scnprintf(buffer, count, "@%s%u",
939                                     nf->nf_name, nr->nr_netnum);
940 }
941
942
943 /**
944  * Print a list of addrrange (\a addrranges) into the specified \a buffer.
945  * At max \a count characters can be printed into \a buffer.
946  *
947  * \retval number of characters written
948  */
949 static int
950 cfs_print_addrranges(char *buffer, int count, struct list_head *addrranges,
951                      struct nidrange *nr)
952 {
953         int i = 0;
954         struct addrrange *ar;
955         struct netstrfns *nf = nr->nr_netstrfns;
956
957         list_for_each_entry(ar, addrranges, ar_link) {
958                 if (i != 0)
959                         i += scnprintf(buffer + i, count - i, " ");
960                 i += nf->nf_print_addrlist(buffer + i, count - i,
961                                            &ar->ar_numaddr_ranges);
962                 i += cfs_print_network(buffer + i, count - i, nr);
963         }
964         return i;
965 }
966
967 /**
968  * Print a list of nidranges (\a nidlist) into the specified \a buffer.
969  * At max \a count characters can be printed into \a buffer.
970  * Nidranges are separated by a space character.
971  *
972  * \retval number of characters written
973  */
974 int cfs_print_nidlist(char *buffer, int count, struct list_head *nidlist)
975 {
976         int i = 0;
977         struct nidrange *nr;
978
979         if (count <= 0)
980                 return 0;
981
982         list_for_each_entry(nr, nidlist, nr_link) {
983                 if (i != 0)
984                         i += scnprintf(buffer + i, count - i, " ");
985
986                 if (nr->nr_all != 0) {
987                         LASSERT(list_empty(&nr->nr_addrranges));
988                         i += scnprintf(buffer + i, count - i, "*");
989                         i += cfs_print_network(buffer + i, count - i, nr);
990                 } else {
991                         i += cfs_print_addrranges(buffer + i, count - i,
992                                                   &nr->nr_addrranges, nr);
993                 }
994         }
995         return i;
996 }
997 EXPORT_SYMBOL(cfs_print_nidlist);
998
999 /**
1000  * Determines minimum and maximum addresses for a single
1001  * numeric address range
1002  *
1003  * \param       ar
1004  * \param       min_nid
1005  * \param       max_nid
1006  */
1007 static void cfs_ip_ar_min_max(struct addrrange *ar, __u32 *min_nid,
1008                               __u32 *max_nid)
1009 {
1010         struct cfs_expr_list    *el;
1011         struct cfs_range_expr   *re;
1012         __u32                   tmp_ip_addr = 0;
1013         unsigned int            min_ip[4] = {0};
1014         unsigned int            max_ip[4] = {0};
1015         int                     re_count = 0;
1016
1017         list_for_each_entry(el, &ar->ar_numaddr_ranges, el_link) {
1018                 list_for_each_entry(re, &el->el_exprs, re_link) {
1019                         min_ip[re_count] = re->re_lo;
1020                         max_ip[re_count] = re->re_hi;
1021                         re_count++;
1022                 }
1023         }
1024
1025         tmp_ip_addr = ((min_ip[0] << 24) | (min_ip[1] << 16) |
1026                        (min_ip[2] << 8) | min_ip[3]);
1027
1028         if (min_nid != NULL)
1029                 *min_nid = tmp_ip_addr;
1030
1031         tmp_ip_addr = ((max_ip[0] << 24) | (max_ip[1] << 16) |
1032                        (max_ip[2] << 8) | max_ip[3]);
1033
1034         if (max_nid != NULL)
1035                 *max_nid = tmp_ip_addr;
1036 }
1037
1038 /**
1039  * Determines minimum and maximum addresses for a single
1040  * numeric address range
1041  *
1042  * \param       ar
1043  * \param       min_nid
1044  * \param       max_nid
1045  */
1046 static void cfs_num_ar_min_max(struct addrrange *ar, __u32 *min_nid,
1047                                __u32 *max_nid)
1048 {
1049         struct cfs_expr_list    *el;
1050         struct cfs_range_expr   *re;
1051         unsigned int            min_addr = 0;
1052         unsigned int            max_addr = 0;
1053
1054         list_for_each_entry(el, &ar->ar_numaddr_ranges, el_link) {
1055                 list_for_each_entry(re, &el->el_exprs, re_link) {
1056                         if (re->re_lo < min_addr || min_addr == 0)
1057                                 min_addr = re->re_lo;
1058                         if (re->re_hi > max_addr)
1059                                 max_addr = re->re_hi;
1060                 }
1061         }
1062
1063         if (min_nid != NULL)
1064                 *min_nid = min_addr;
1065         if (max_nid != NULL)
1066                 *max_nid = max_addr;
1067 }
1068
1069 /**
1070  * Determines whether an expression list in an nidrange contains exactly
1071  * one contiguous address range. Calls the correct netstrfns for the LND
1072  *
1073  * \param       *nidlist
1074  *
1075  * \retval      true if contiguous
1076  * \retval      false if not contiguous
1077  */
1078 bool cfs_nidrange_is_contiguous(struct list_head *nidlist)
1079 {
1080         struct nidrange         *nr;
1081         struct netstrfns        *nf = NULL;
1082         char                    *lndname = NULL;
1083         int                     netnum = -1;
1084
1085         list_for_each_entry(nr, nidlist, nr_link) {
1086                 nf = nr->nr_netstrfns;
1087                 if (lndname == NULL)
1088                         lndname = nf->nf_name;
1089                 if (netnum == -1)
1090                         netnum = nr->nr_netnum;
1091
1092                 if (strcmp(lndname, nf->nf_name) != 0 ||
1093                     netnum != nr->nr_netnum)
1094                         return false;
1095         }
1096
1097         if (nf == NULL)
1098                 return false;
1099
1100         if (!nf->nf_is_contiguous(nidlist))
1101                 return false;
1102
1103         return true;
1104 }
1105 EXPORT_SYMBOL(cfs_nidrange_is_contiguous);
1106
1107 /**
1108  * Determines whether an expression list in an num nidrange contains exactly
1109  * one contiguous address range.
1110  *
1111  * \param       *nidlist
1112  *
1113  * \retval      true if contiguous
1114  * \retval      false if not contiguous
1115  */
1116 static bool cfs_num_is_contiguous(struct list_head *nidlist)
1117 {
1118         struct nidrange         *nr;
1119         struct addrrange        *ar;
1120         struct cfs_expr_list    *el;
1121         struct cfs_range_expr   *re;
1122         int                     last_hi = 0;
1123         __u32                   last_end_nid = 0;
1124         __u32                   current_start_nid = 0;
1125         __u32                   current_end_nid = 0;
1126
1127         list_for_each_entry(nr, nidlist, nr_link) {
1128                 list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
1129                         cfs_num_ar_min_max(ar, &current_start_nid,
1130                                            &current_end_nid);
1131                         if (last_end_nid != 0 &&
1132                             (current_start_nid - last_end_nid != 1))
1133                                         return false;
1134                         last_end_nid = current_end_nid;
1135                         list_for_each_entry(el, &ar->ar_numaddr_ranges,
1136                                             el_link) {
1137                                 list_for_each_entry(re, &el->el_exprs,
1138                                                     re_link) {
1139                                         if (re->re_stride > 1)
1140                                                 return false;
1141                                         else if (last_hi != 0 &&
1142                                                  re->re_hi - last_hi != 1)
1143                                                 return false;
1144                                         last_hi = re->re_hi;
1145                                 }
1146                         }
1147                 }
1148         }
1149
1150         return true;
1151 }
1152
1153 /**
1154  * Determines whether an expression list in an ip nidrange contains exactly
1155  * one contiguous address range.
1156  *
1157  * \param       *nidlist
1158  *
1159  * \retval      true if contiguous
1160  * \retval      false if not contiguous
1161  */
1162 static bool cfs_ip_is_contiguous(struct list_head *nidlist)
1163 {
1164         struct nidrange         *nr;
1165         struct addrrange        *ar;
1166         struct cfs_expr_list    *el;
1167         struct cfs_range_expr   *re;
1168         int                     expr_count;
1169         int                     last_hi = 255;
1170         int                     last_diff = 0;
1171         __u32                   last_end_nid = 0;
1172         __u32                   current_start_nid = 0;
1173         __u32                   current_end_nid = 0;
1174
1175         list_for_each_entry(nr, nidlist, nr_link) {
1176                 list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
1177                         last_hi = 255;
1178                         last_diff = 0;
1179                         cfs_ip_ar_min_max(ar, &current_start_nid,
1180                                           &current_end_nid);
1181                         if (last_end_nid != 0 &&
1182                             (current_start_nid - last_end_nid != 1))
1183                                         return false;
1184                         last_end_nid = current_end_nid;
1185                         list_for_each_entry(el,
1186                                             &ar->ar_numaddr_ranges,
1187                                             el_link) {
1188                                 expr_count = 0;
1189                                 list_for_each_entry(re, &el->el_exprs,
1190                                                     re_link) {
1191                                         expr_count++;
1192                                         if (re->re_stride > 1 ||
1193                                             (last_diff > 0 && last_hi != 255) ||
1194                                             (last_diff > 0 && last_hi == 255 &&
1195                                              re->re_lo > 0))
1196                                                 return false;
1197                                         last_hi = re->re_hi;
1198                                         last_diff = re->re_hi - re->re_lo;
1199                                 }
1200                         }
1201                 }
1202         }
1203
1204         return true;
1205 }
1206
1207 /**
1208  * Takes a linked list of nidrange expressions, determines the minimum
1209  * and maximum nid and creates appropriate nid structures
1210  *
1211  * \param       *nidlist
1212  * \param       *min_nid
1213  * \param       *max_nid
1214  */
1215 void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
1216                                char *max_nid, size_t nidstr_length)
1217 {
1218         struct nidrange         *nr;
1219         struct netstrfns        *nf = NULL;
1220         int                     netnum = -1;
1221         __u32                   min_addr;
1222         __u32                   max_addr;
1223         char                    *lndname = NULL;
1224         char                    min_addr_str[IPSTRING_LENGTH];
1225         char                    max_addr_str[IPSTRING_LENGTH];
1226
1227         list_for_each_entry(nr, nidlist, nr_link) {
1228                 nf = nr->nr_netstrfns;
1229                 lndname = nf->nf_name;
1230                 if (netnum == -1)
1231                         netnum = nr->nr_netnum;
1232
1233                 nf->nf_min_max(nidlist, &min_addr, &max_addr);
1234         }
1235         nf->nf_addr2str(min_addr, min_addr_str, sizeof(min_addr_str));
1236         nf->nf_addr2str(max_addr, max_addr_str, sizeof(max_addr_str));
1237
1238         snprintf(min_nid, nidstr_length, "%s@%s%d", min_addr_str, lndname,
1239                  netnum);
1240         snprintf(max_nid, nidstr_length, "%s@%s%d", max_addr_str, lndname,
1241                  netnum);
1242 }
1243 EXPORT_SYMBOL(cfs_nidrange_find_min_max);
1244
1245 /**
1246  * Determines the min and max NID values for num LNDs
1247  *
1248  * \param       *nidlist
1249  * \param       *min_nid
1250  * \param       *max_nid
1251  */
1252 static void cfs_num_min_max(struct list_head *nidlist, __u32 *min_nid,
1253                             __u32 *max_nid)
1254 {
1255         struct nidrange         *nr;
1256         struct addrrange        *ar;
1257         unsigned int            tmp_min_addr = 0;
1258         unsigned int            tmp_max_addr = 0;
1259         unsigned int            min_addr = 0;
1260         unsigned int            max_addr = 0;
1261
1262         list_for_each_entry(nr, nidlist, nr_link) {
1263                 list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
1264                         cfs_num_ar_min_max(ar, &tmp_min_addr,
1265                                            &tmp_max_addr);
1266                         if (tmp_min_addr < min_addr || min_addr == 0)
1267                                 min_addr = tmp_min_addr;
1268                         if (tmp_max_addr > max_addr)
1269                                 max_addr = tmp_min_addr;
1270                 }
1271         }
1272         *max_nid = max_addr;
1273         *min_nid = min_addr;
1274 }
1275
1276 /**
1277  * Takes an nidlist and determines the minimum and maximum
1278  * ip addresses.
1279  *
1280  * \param       *nidlist
1281  * \param       *min_nid
1282  * \param       *max_nid
1283  */
1284 static void cfs_ip_min_max(struct list_head *nidlist, __u32 *min_nid,
1285                            __u32 *max_nid)
1286 {
1287         struct nidrange         *nr;
1288         struct addrrange        *ar;
1289         __u32                   tmp_min_ip_addr = 0;
1290         __u32                   tmp_max_ip_addr = 0;
1291         __u32                   min_ip_addr = 0;
1292         __u32                   max_ip_addr = 0;
1293
1294         list_for_each_entry(nr, nidlist, nr_link) {
1295                 list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
1296                         cfs_ip_ar_min_max(ar, &tmp_min_ip_addr,
1297                                           &tmp_max_ip_addr);
1298                         if (tmp_min_ip_addr < min_ip_addr || min_ip_addr == 0)
1299                                 min_ip_addr = tmp_min_ip_addr;
1300                         if (tmp_max_ip_addr > max_ip_addr)
1301                                 max_ip_addr = tmp_max_ip_addr;
1302                 }
1303         }
1304
1305         if (min_nid != NULL)
1306                 *min_nid = min_ip_addr;
1307         if (max_nid != NULL)
1308                 *max_nid = max_ip_addr;
1309 }