diff options
Diffstat (limited to 'networking/libiproute/rt_names.c')
-rw-r--r-- | networking/libiproute/rt_names.c | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/networking/libiproute/rt_names.c b/networking/libiproute/rt_names.c index c0f790754..ed21fbe26 100644 --- a/networking/libiproute/rt_names.c +++ b/networking/libiproute/rt_names.c | |||
@@ -240,7 +240,23 @@ int rtnl_rtrealm_a2n(uint32_t *id, char *arg) | |||
240 | return 0; | 240 | return 0; |
241 | } | 241 | } |
242 | 242 | ||
243 | 243 | #if ENABLE_FEATURE_IP_RULE | |
244 | const char * rtnl_rtrealm_n2a(int id, char *buf, int len) | ||
245 | { | ||
246 | if (id<0 || id>=256) { | ||
247 | snprintf(buf, len, "%d", id); | ||
248 | return buf; | ||
249 | } | ||
250 | if (!rtnl_rtrealm_tab[id]) { | ||
251 | if (!rtnl_rtrealm_init) | ||
252 | rtnl_rtrealm_initialize(); | ||
253 | } | ||
254 | if (rtnl_rtrealm_tab[id]) | ||
255 | return rtnl_rtrealm_tab[id]; | ||
256 | snprintf(buf, len, "%d", id); | ||
257 | return buf; | ||
258 | } | ||
259 | #endif | ||
244 | 260 | ||
245 | static const char * rtnl_rtdsfield_tab[256] = { | 261 | static const char * rtnl_rtdsfield_tab[256] = { |
246 | "0", | 262 | "0", |
@@ -303,3 +319,66 @@ int rtnl_dsfield_a2n(uint32_t *id, char *arg) | |||
303 | *id = res; | 319 | *id = res; |
304 | return 0; | 320 | return 0; |
305 | } | 321 | } |
322 | |||
323 | #if ENABLE_FEATURE_IP_RULE | ||
324 | static int rtnl_rttable_init; | ||
325 | static const char * rtnl_rttable_tab[256] = { | ||
326 | "unspec", | ||
327 | }; | ||
328 | static void rtnl_rttable_initialize(void) | ||
329 | { | ||
330 | rtnl_rttable_init = 1; | ||
331 | rtnl_rttable_tab[255] = "local"; | ||
332 | rtnl_rttable_tab[254] = "main"; | ||
333 | rtnl_rttable_tab[253] = "default"; | ||
334 | rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab, 256); | ||
335 | } | ||
336 | |||
337 | const char *rtnl_rttable_n2a(int id, char *buf, int len) | ||
338 | { | ||
339 | if (id < 0 || id >= 256) { | ||
340 | snprintf(buf, len, "%d", id); | ||
341 | return buf; | ||
342 | } | ||
343 | if (!rtnl_rttable_tab[id]) { | ||
344 | if (!rtnl_rttable_init) | ||
345 | rtnl_rttable_initialize(); | ||
346 | } | ||
347 | if (rtnl_rttable_tab[id]) | ||
348 | return rtnl_rttable_tab[id]; | ||
349 | snprintf(buf, len, "%d", id); | ||
350 | return buf; | ||
351 | } | ||
352 | |||
353 | int rtnl_rttable_a2n(uint32_t * id, char *arg) | ||
354 | { | ||
355 | static char *cache = NULL; | ||
356 | static unsigned long res; | ||
357 | char *end; | ||
358 | int i; | ||
359 | |||
360 | if (cache && strcmp(cache, arg) == 0) { | ||
361 | *id = res; | ||
362 | return 0; | ||
363 | } | ||
364 | |||
365 | if (!rtnl_rttable_init) | ||
366 | rtnl_rttable_initialize(); | ||
367 | |||
368 | for (i = 0; i < 256; i++) { | ||
369 | if (rtnl_rttable_tab[i] && strcmp(rtnl_rttable_tab[i], arg) == 0) { | ||
370 | cache = (char*)rtnl_rttable_tab[i]; | ||
371 | res = i; | ||
372 | *id = res; | ||
373 | return 0; | ||
374 | } | ||
375 | } | ||
376 | |||
377 | i = strtoul(arg, &end, 0); | ||
378 | if (!end || end == arg || *end || i > 255) | ||
379 | return -1; | ||
380 | *id = i; | ||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | #endif | ||