blob: 369e0f4e4950c80298a522347d2d3a85134e8cdf [file] [log] [blame]
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00001/*
2 * rt_names.c rtnetlink names DB.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <unistd.h>
15#include <syslog.h>
16#include <fcntl.h>
17#include <string.h>
18#include <sys/time.h>
osdl.org!shemmingerb88fd9f2004-06-08 23:50:43 +000019#include <sys/socket.h>
20
21#include <asm/types.h>
22#include <linux/rtnetlink.h>
23
24#include "rt_names.h"
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000025
Christoph J. Thompsonfb721292012-03-01 06:44:43 +000026#ifndef CONFDIR
27#define CONFDIR "/etc/iproute2"
28#endif
29
Patrick McHardy9c47d872006-08-11 00:14:50 +020030struct rtnl_hash_entry {
31 struct rtnl_hash_entry *next;
Stephen Hemminger46ac8a52013-02-12 11:39:07 -080032 const char * name;
Patrick McHardy9c47d872006-08-11 00:14:50 +020033 unsigned int id;
34};
35
36static void
Stephen Hemminger46ac8a52013-02-12 11:39:07 -080037rtnl_hash_initialize(const char *file, struct rtnl_hash_entry **hash, int size)
Patrick McHardy9c47d872006-08-11 00:14:50 +020038{
39 struct rtnl_hash_entry *entry;
40 char buf[512];
41 FILE *fp;
42
43 fp = fopen(file, "r");
44 if (!fp)
45 return;
46 while (fgets(buf, sizeof(buf), fp)) {
47 char *p = buf;
48 int id;
49 char namebuf[512];
50
51 while (*p == ' ' || *p == '\t')
52 p++;
53 if (*p == '#' || *p == '\n' || *p == 0)
54 continue;
55 if (sscanf(p, "0x%x %s\n", &id, namebuf) != 2 &&
56 sscanf(p, "0x%x %s #", &id, namebuf) != 2 &&
57 sscanf(p, "%d %s\n", &id, namebuf) != 2 &&
58 sscanf(p, "%d %s #", &id, namebuf) != 2) {
59 fprintf(stderr, "Database %s is corrupted at %s\n",
60 file, p);
Thomas Jarosch97c13582011-10-03 05:22:42 +000061 fclose(fp);
Patrick McHardy9c47d872006-08-11 00:14:50 +020062 return;
63 }
64
65 if (id<0)
66 continue;
67 entry = malloc(sizeof(*entry));
68 entry->id = id;
69 entry->name = strdup(namebuf);
70 entry->next = hash[id & (size - 1)];
71 hash[id & (size - 1)] = entry;
72 }
73 fclose(fp);
74}
75
Stephen Hemminger46ac8a52013-02-12 11:39:07 -080076static void rtnl_tab_initialize(const char *file, char **tab, int size)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000077{
78 char buf[512];
79 FILE *fp;
80
81 fp = fopen(file, "r");
82 if (!fp)
83 return;
84 while (fgets(buf, sizeof(buf), fp)) {
85 char *p = buf;
86 int id;
87 char namebuf[512];
88
89 while (*p == ' ' || *p == '\t')
90 p++;
91 if (*p == '#' || *p == '\n' || *p == 0)
92 continue;
93 if (sscanf(p, "0x%x %s\n", &id, namebuf) != 2 &&
94 sscanf(p, "0x%x %s #", &id, namebuf) != 2 &&
95 sscanf(p, "%d %s\n", &id, namebuf) != 2 &&
96 sscanf(p, "%d %s #", &id, namebuf) != 2) {
97 fprintf(stderr, "Database %s is corrupted at %s\n",
98 file, p);
Thomas Jarosch97c13582011-10-03 05:22:42 +000099 fclose(fp);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000100 return;
101 }
102
103 if (id<0 || id>size)
104 continue;
105
106 tab[id] = strdup(namebuf);
107 }
108 fclose(fp);
109}
110
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000111static char * rtnl_rtprot_tab[256] = {
osdl.org!shemmingerb88fd9f2004-06-08 23:50:43 +0000112 [RTPROT_UNSPEC] = "none",
113 [RTPROT_REDIRECT] ="redirect",
114 [RTPROT_KERNEL] = "kernel",
115 [RTPROT_BOOT] = "boot",
116 [RTPROT_STATIC] = "static",
117
118 [RTPROT_GATED] = "gated",
119 [RTPROT_RA] = "ra",
120 [RTPROT_MRT] = "mrt",
121 [RTPROT_ZEBRA] ="zebra",
122 [RTPROT_BIRD] = "bird",
Dave Taht1fa804e2014-11-04 14:23:47 -0800123 [RTPROT_BABEL] = "babel",
osdl.org!shemmingerb88fd9f2004-06-08 23:50:43 +0000124 [RTPROT_DNROUTED] = "dnrouted",
125 [RTPROT_XORP] = "xorp",
shemminger40b6c622006-03-10 23:44:04 +0000126 [RTPROT_NTK] = "ntk",
Stephen Hemminger1e659af2009-03-18 13:33:12 -0700127 [RTPROT_DHCP] = "dhcp",
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000128};
129
130
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000131static int rtnl_rtprot_init;
132
133static void rtnl_rtprot_initialize(void)
134{
135 rtnl_rtprot_init = 1;
Christoph J. Thompsonfb721292012-03-01 06:44:43 +0000136 rtnl_tab_initialize(CONFDIR "/rt_protos",
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000137 rtnl_rtprot_tab, 256);
138}
139
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800140const char * rtnl_rtprot_n2a(int id, char *buf, int len)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000141{
142 if (id<0 || id>=256) {
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800143 snprintf(buf, len, "%u", id);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000144 return buf;
145 }
146 if (!rtnl_rtprot_tab[id]) {
147 if (!rtnl_rtprot_init)
148 rtnl_rtprot_initialize();
149 }
150 if (rtnl_rtprot_tab[id])
151 return rtnl_rtprot_tab[id];
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800152 snprintf(buf, len, "%u", id);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000153 return buf;
154}
155
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800156int rtnl_rtprot_a2n(__u32 *id, const char *arg)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000157{
158 static char *cache = NULL;
159 static unsigned long res;
160 char *end;
161 int i;
162
163 if (cache && strcmp(cache, arg) == 0) {
164 *id = res;
165 return 0;
166 }
167
168 if (!rtnl_rtprot_init)
169 rtnl_rtprot_initialize();
170
171 for (i=0; i<256; i++) {
172 if (rtnl_rtprot_tab[i] &&
173 strcmp(rtnl_rtprot_tab[i], arg) == 0) {
174 cache = rtnl_rtprot_tab[i];
175 res = i;
176 *id = res;
177 return 0;
178 }
179 }
180
181 res = strtoul(arg, &end, 0);
182 if (!end || end == arg || *end || res > 255)
183 return -1;
184 *id = res;
185 return 0;
186}
187
188
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000189static char * rtnl_rtscope_tab[256] = {
190 "global",
191};
192
193static int rtnl_rtscope_init;
194
195static void rtnl_rtscope_initialize(void)
196{
197 rtnl_rtscope_init = 1;
Masatake YAMATO58ed50e2014-03-07 19:21:36 +0900198 rtnl_rtscope_tab[RT_SCOPE_NOWHERE] = "nowhere";
199 rtnl_rtscope_tab[RT_SCOPE_HOST] = "host";
200 rtnl_rtscope_tab[RT_SCOPE_LINK] = "link";
201 rtnl_rtscope_tab[RT_SCOPE_SITE] = "site";
Christoph J. Thompsonfb721292012-03-01 06:44:43 +0000202 rtnl_tab_initialize(CONFDIR "/rt_scopes",
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000203 rtnl_rtscope_tab, 256);
204}
205
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800206const char *rtnl_rtscope_n2a(int id, char *buf, int len)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000207{
208 if (id<0 || id>=256) {
209 snprintf(buf, len, "%d", id);
210 return buf;
211 }
212 if (!rtnl_rtscope_tab[id]) {
213 if (!rtnl_rtscope_init)
214 rtnl_rtscope_initialize();
215 }
216 if (rtnl_rtscope_tab[id])
217 return rtnl_rtscope_tab[id];
218 snprintf(buf, len, "%d", id);
219 return buf;
220}
221
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800222int rtnl_rtscope_a2n(__u32 *id, const char *arg)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000223{
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800224 static const char *cache = NULL;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000225 static unsigned long res;
226 char *end;
227 int i;
228
229 if (cache && strcmp(cache, arg) == 0) {
230 *id = res;
231 return 0;
232 }
233
234 if (!rtnl_rtscope_init)
235 rtnl_rtscope_initialize();
236
237 for (i=0; i<256; i++) {
238 if (rtnl_rtscope_tab[i] &&
239 strcmp(rtnl_rtscope_tab[i], arg) == 0) {
240 cache = rtnl_rtscope_tab[i];
241 res = i;
242 *id = res;
243 return 0;
244 }
245 }
246
247 res = strtoul(arg, &end, 0);
248 if (!end || end == arg || *end || res > 255)
249 return -1;
250 *id = res;
251 return 0;
252}
253
254
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000255static char * rtnl_rtrealm_tab[256] = {
256 "unknown",
257};
258
259static int rtnl_rtrealm_init;
260
261static void rtnl_rtrealm_initialize(void)
262{
263 rtnl_rtrealm_init = 1;
Christoph J. Thompsonfb721292012-03-01 06:44:43 +0000264 rtnl_tab_initialize(CONFDIR "/rt_realms",
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000265 rtnl_rtrealm_tab, 256);
266}
267
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800268const char *rtnl_rtrealm_n2a(int id, char *buf, int len)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000269{
270 if (id<0 || id>=256) {
271 snprintf(buf, len, "%d", id);
272 return buf;
273 }
274 if (!rtnl_rtrealm_tab[id]) {
275 if (!rtnl_rtrealm_init)
276 rtnl_rtrealm_initialize();
277 }
278 if (rtnl_rtrealm_tab[id])
279 return rtnl_rtrealm_tab[id];
280 snprintf(buf, len, "%d", id);
281 return buf;
282}
283
284
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800285int rtnl_rtrealm_a2n(__u32 *id, const char *arg)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000286{
287 static char *cache = NULL;
288 static unsigned long res;
289 char *end;
290 int i;
291
292 if (cache && strcmp(cache, arg) == 0) {
293 *id = res;
294 return 0;
295 }
296
297 if (!rtnl_rtrealm_init)
298 rtnl_rtrealm_initialize();
299
300 for (i=0; i<256; i++) {
301 if (rtnl_rtrealm_tab[i] &&
302 strcmp(rtnl_rtrealm_tab[i], arg) == 0) {
303 cache = rtnl_rtrealm_tab[i];
304 res = i;
305 *id = res;
306 return 0;
307 }
308 }
309
310 res = strtoul(arg, &end, 0);
311 if (!end || end == arg || *end || res > 255)
312 return -1;
313 *id = res;
314 return 0;
315}
316
317
Masatake YAMATO81ebcb22014-03-07 19:21:37 +0900318static struct rtnl_hash_entry dflt_table_entry = { .name = "default" };
319static struct rtnl_hash_entry main_table_entry = { .name = "main" };
320static struct rtnl_hash_entry local_table_entry = { .name = "local" };
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000321
Patrick McHardy9c47d872006-08-11 00:14:50 +0200322static struct rtnl_hash_entry * rtnl_rttable_hash[256] = {
Masatake YAMATO81ebcb22014-03-07 19:21:37 +0900323 [RT_TABLE_DEFAULT] = &dflt_table_entry,
324 [RT_TABLE_MAIN] = &main_table_entry,
325 [RT_TABLE_LOCAL] = &local_table_entry,
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000326};
327
328static int rtnl_rttable_init;
329
330static void rtnl_rttable_initialize(void)
331{
Masatake YAMATO81ebcb22014-03-07 19:21:37 +0900332 int i;
333
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000334 rtnl_rttable_init = 1;
Masatake YAMATO81ebcb22014-03-07 19:21:37 +0900335 for (i = 0; i < 256; i++) {
336 if (rtnl_rttable_hash[i])
337 rtnl_rttable_hash[i]->id = i;
338 }
Christoph J. Thompsonfb721292012-03-01 06:44:43 +0000339 rtnl_hash_initialize(CONFDIR "/rt_tables",
Patrick McHardy9c47d872006-08-11 00:14:50 +0200340 rtnl_rttable_hash, 256);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000341}
342
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800343const char * rtnl_rttable_n2a(__u32 id, char *buf, int len)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000344{
Patrick McHardy9c47d872006-08-11 00:14:50 +0200345 struct rtnl_hash_entry *entry;
346
Boian Bonev887a5d02006-11-27 14:12:31 -0800347 if (id > RT_TABLE_MAX) {
Patrick McHardy9c47d872006-08-11 00:14:50 +0200348 snprintf(buf, len, "%u", id);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000349 return buf;
350 }
Patrick McHardy9c47d872006-08-11 00:14:50 +0200351 if (!rtnl_rttable_init)
352 rtnl_rttable_initialize();
353 entry = rtnl_rttable_hash[id & 255];
354 while (entry && entry->id != id)
355 entry = entry->next;
356 if (entry)
357 return entry->name;
358 snprintf(buf, len, "%u", id);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000359 return buf;
360}
361
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800362int rtnl_rttable_a2n(__u32 *id, const char *arg)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000363{
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800364 static const char *cache = NULL;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000365 static unsigned long res;
Patrick McHardy9c47d872006-08-11 00:14:50 +0200366 struct rtnl_hash_entry *entry;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000367 char *end;
Patrick McHardy34e95642006-08-11 00:14:51 +0200368 __u32 i;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000369
370 if (cache && strcmp(cache, arg) == 0) {
371 *id = res;
372 return 0;
373 }
374
375 if (!rtnl_rttable_init)
376 rtnl_rttable_initialize();
377
378 for (i=0; i<256; i++) {
Patrick McHardy9c47d872006-08-11 00:14:50 +0200379 entry = rtnl_rttable_hash[i];
380 while (entry && strcmp(entry->name, arg))
381 entry = entry->next;
382 if (entry) {
383 cache = entry->name;
384 res = entry->id;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000385 *id = res;
386 return 0;
387 }
388 }
389
390 i = strtoul(arg, &end, 0);
Patrick McHardy9c47d872006-08-11 00:14:50 +0200391 if (!end || end == arg || *end || i > RT_TABLE_MAX)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000392 return -1;
393 *id = i;
394 return 0;
395}
396
397
398static char * rtnl_rtdsfield_tab[256] = {
399 "0",
400};
401
402static int rtnl_rtdsfield_init;
403
404static void rtnl_rtdsfield_initialize(void)
405{
406 rtnl_rtdsfield_init = 1;
Christoph J. Thompsonfb721292012-03-01 06:44:43 +0000407 rtnl_tab_initialize(CONFDIR "/rt_dsfield",
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000408 rtnl_rtdsfield_tab, 256);
409}
410
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800411const char *rtnl_dsfield_n2a(int id, char *buf, int len)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000412{
413 if (id<0 || id>=256) {
414 snprintf(buf, len, "%d", id);
415 return buf;
416 }
417 if (!rtnl_rtdsfield_tab[id]) {
418 if (!rtnl_rtdsfield_init)
419 rtnl_rtdsfield_initialize();
420 }
421 if (rtnl_rtdsfield_tab[id])
422 return rtnl_rtdsfield_tab[id];
423 snprintf(buf, len, "0x%02x", id);
424 return buf;
425}
426
427
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800428int rtnl_dsfield_a2n(__u32 *id, const char *arg)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000429{
430 static char *cache = NULL;
431 static unsigned long res;
432 char *end;
433 int i;
434
435 if (cache && strcmp(cache, arg) == 0) {
436 *id = res;
437 return 0;
438 }
439
440 if (!rtnl_rtdsfield_init)
441 rtnl_rtdsfield_initialize();
442
443 for (i=0; i<256; i++) {
444 if (rtnl_rtdsfield_tab[i] &&
445 strcmp(rtnl_rtdsfield_tab[i], arg) == 0) {
446 cache = rtnl_rtdsfield_tab[i];
447 res = i;
448 *id = res;
449 return 0;
450 }
451 }
452
453 res = strtoul(arg, &end, 16);
454 if (!end || end == arg || *end || res > 255)
455 return -1;
456 *id = res;
457 return 0;
458}
459
Vlad Dogaruac694c32011-02-02 20:23:40 +0200460
461static struct rtnl_hash_entry dflt_group_entry = { .id = 0, .name = "default" };
462
463static struct rtnl_hash_entry * rtnl_group_hash[256] = {
464 [0] = &dflt_group_entry,
465};
466
467static int rtnl_group_init;
468
469static void rtnl_group_initialize(void)
470{
471 rtnl_group_init = 1;
472 rtnl_hash_initialize("/etc/iproute2/group",
473 rtnl_group_hash, 256);
474}
475
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800476int rtnl_group_a2n(int *id, const char *arg)
Vlad Dogaruac694c32011-02-02 20:23:40 +0200477{
Stephen Hemminger46ac8a52013-02-12 11:39:07 -0800478 static const char *cache = NULL;
Vlad Dogaruac694c32011-02-02 20:23:40 +0200479 static unsigned long res;
480 struct rtnl_hash_entry *entry;
481 char *end;
482 int i;
483
484 if (cache && strcmp(cache, arg) == 0) {
485 *id = res;
486 return 0;
487 }
488
489 if (!rtnl_group_init)
490 rtnl_group_initialize();
491
492 for (i=0; i<256; i++) {
493 entry = rtnl_group_hash[i];
494 while (entry && strcmp(entry->name, arg))
495 entry = entry->next;
496 if (entry) {
497 cache = entry->name;
498 res = entry->id;
499 *id = res;
500 return 0;
501 }
502 }
503
504 i = strtol(arg, &end, 0);
505 if (!end || end == arg || *end || i < 0)
506 return -1;
507 *id = i;
508 return 0;
509}
Stefan Tomanekc4fdf752013-08-03 14:20:53 +0200510
511const char *rtnl_group_n2a(int id, char *buf, int len)
512{
513 struct rtnl_hash_entry *entry;
514 int i;
515
516 if (!rtnl_group_init)
517 rtnl_group_initialize();
518
519 for (i=0; i<256; i++) {
520 entry = rtnl_group_hash[i];
521 if (entry && entry->id == id) {
522 return entry->name;
523 }
524 }
525
526 snprintf(buf, len, "%d", id);
527 return buf;
528}
vadimkeef43b52014-10-30 17:33:36 +0200529
530static char *nl_proto_tab[256] = {
531 [NETLINK_ROUTE] = "rtnl",
532 [NETLINK_UNUSED] = "unused",
533 [NETLINK_USERSOCK] = "usersock",
534 [NETLINK_FIREWALL] = "fw",
535 [NETLINK_SOCK_DIAG] = "tcpdiag",
536 [NETLINK_NFLOG] = "nflog",
537 [NETLINK_XFRM] = "xfrm",
538 [NETLINK_SELINUX] = "selinux",
539 [NETLINK_ISCSI] = "iscsi",
540 [NETLINK_AUDIT] = "audit",
541 [NETLINK_FIB_LOOKUP] = "fiblookup",
542 [NETLINK_CONNECTOR] = "connector",
543 [NETLINK_NETFILTER] = "nft",
544 [NETLINK_IP6_FW] = "ip6fw",
545 [NETLINK_DNRTMSG] = "dec-rt",
546 [NETLINK_KOBJECT_UEVENT] = "uevent",
547 [NETLINK_GENERIC] = "genl",
548 [NETLINK_SCSITRANSPORT] = "scsi-trans",
549 [NETLINK_ECRYPTFS] = "ecryptfs",
550 [NETLINK_RDMA] = "rdma",
551 [NETLINK_CRYPTO] = "crypto",
552};
553
554static int nl_proto_init;
555
556static void nl_proto_initialize(void)
557{
558 nl_proto_init = 1;
559 rtnl_tab_initialize(CONFDIR "/nl_protos",
560 nl_proto_tab, 256);
561}
562
563const char *nl_proto_n2a(int id, char *buf, int len)
564{
565 if (id < 0 || id >= 256) {
566 snprintf(buf, len, "%u", id);
567 return buf;
568 }
569
570 if (!nl_proto_init)
571 nl_proto_initialize();
572
573 if (nl_proto_tab[id])
574 return nl_proto_tab[id];
575
576 snprintf(buf, len, "%u", id);
577 return buf;
578}
579
580int nl_proto_a2n(__u32 *id, const char *arg)
581{
582 static char *cache = NULL;
583 static unsigned long res;
584 char *end;
585 int i;
586
587 if (cache && strcmp(cache, arg) == 0) {
588 *id = res;
589 return 0;
590 }
591
592 if (!nl_proto_init)
593 nl_proto_initialize();
594
595 for (i = 0; i < 256; i++) {
596 if (nl_proto_tab[i] &&
597 strcmp(nl_proto_tab[i], arg) == 0) {
598 cache = nl_proto_tab[i];
599 res = i;
600 *id = res;
601 return 0;
602 }
603 }
604
605 res = strtoul(arg, &end, 0);
606 if (!end || end == arg || *end || res > 255)
607 return -1;
608 *id = res;
609 return 0;
610}