"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 2 | /* |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 3 | * This program is free software; you can redistribute it and/or |
| 4 | * modify it under the terms of the GNU General Public License |
| 5 | * as published by the Free Software Foundation; either version |
| 6 | * 2 of the License, or (at your option) any later version. |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 8 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 9 | */ |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 10 | #include "libbb.h" |
Bernhard Reutner-Fischer | 1d62d3b | 2005-10-08 20:47:15 +0000 | [diff] [blame] | 11 | #include "rt_names.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 12 | |
Christoph J. Thompson | d1eea8d | 2015-10-08 17:06:06 +0200 | [diff] [blame] | 13 | #define CONFDIR CONFIG_FEATURE_IP_ROUTE_DIR |
| 14 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 15 | typedef struct rtnl_tab_t { |
| 16 | const char *cached_str; |
| 17 | unsigned cached_result; |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 18 | /* upstream version switched to a hash table and removed |
| 19 | * id < 256 limit. For now bbox bumps this array size from 256 |
| 20 | * to 1024. If you plan to change this to a hash table, |
| 21 | * consider merging several hash tables we have (for example, |
| 22 | * awk has resizable one! |
| 23 | */ |
| 24 | #define RT_TABLE_MAX 1023 |
| 25 | const char *tab[RT_TABLE_MAX+1]; |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 26 | } rtnl_tab_t; |
| 27 | |
| 28 | static void rtnl_tab_initialize(const char *file, const char **tab) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 29 | { |
Denis Vlasenko | 0f99d49 | 2008-07-24 23:38:04 +0000 | [diff] [blame] | 30 | char *token[2]; |
Denys Vlasenko | 8403b01 | 2015-10-08 17:15:08 +0200 | [diff] [blame] | 31 | char fullname[sizeof(CONFDIR"/rt_dsfield") + 8]; |
| 32 | parser_t *parser; |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 33 | |
Denys Vlasenko | 8403b01 | 2015-10-08 17:15:08 +0200 | [diff] [blame] | 34 | sprintf(fullname, CONFDIR"/rt_%s", file); |
| 35 | parser = config_open2(fullname, fopen_for_read); |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 36 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 37 | unsigned id = bb_strtou(token[0], NULL, 0); |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 38 | if (id > RT_TABLE_MAX) { |
Denis Vlasenko | 0f99d49 | 2008-07-24 23:38:04 +0000 | [diff] [blame] | 39 | bb_error_msg("database %s is corrupted at line %d", |
| 40 | file, parser->lineno); |
| 41 | break; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 42 | } |
Denis Vlasenko | 0f99d49 | 2008-07-24 23:38:04 +0000 | [diff] [blame] | 43 | tab[id] = xstrdup(token[1]); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 44 | } |
Denis Vlasenko | 0f99d49 | 2008-07-24 23:38:04 +0000 | [diff] [blame] | 45 | config_close(parser); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 46 | } |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 47 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 48 | static int rtnl_a2n(rtnl_tab_t *tab, uint32_t *id, const char *arg, int base) |
| 49 | { |
| 50 | unsigned i; |
| 51 | |
| 52 | if (tab->cached_str && strcmp(tab->cached_str, arg) == 0) { |
| 53 | *id = tab->cached_result; |
| 54 | return 0; |
| 55 | } |
| 56 | |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 57 | for (i = 0; i <= RT_TABLE_MAX; i++) { |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 58 | if (tab->tab[i] |
| 59 | && strcmp(tab->tab[i], arg) == 0 |
| 60 | ) { |
| 61 | tab->cached_str = tab->tab[i]; |
| 62 | tab->cached_result = i; |
| 63 | *id = i; |
| 64 | return 0; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | i = bb_strtou(arg, NULL, base); |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 69 | if (i > RT_TABLE_MAX) |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 70 | return -1; |
| 71 | *id = i; |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | static rtnl_tab_t *rtnl_rtprot_tab; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 77 | |
| 78 | static void rtnl_rtprot_initialize(void) |
| 79 | { |
Denys Vlasenko | 965b795 | 2020-11-30 13:03:03 +0100 | [diff] [blame^] | 80 | static const char *const init_tab[] ALIGN_PTR = { |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 81 | "none", |
| 82 | "redirect", |
| 83 | "kernel", |
| 84 | "boot", |
| 85 | "static", |
| 86 | NULL, |
| 87 | NULL, |
| 88 | NULL, |
| 89 | "gated", |
| 90 | "ra", |
| 91 | "mrt", |
| 92 | "zebra", |
| 93 | "bird", |
| 94 | }; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 95 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 96 | if (rtnl_rtprot_tab) |
| 97 | return; |
| 98 | rtnl_rtprot_tab = xzalloc(sizeof(*rtnl_rtprot_tab)); |
| 99 | memcpy(rtnl_rtprot_tab->tab, init_tab, sizeof(init_tab)); |
Denys Vlasenko | 8403b01 | 2015-10-08 17:15:08 +0200 | [diff] [blame] | 100 | rtnl_tab_initialize("protos", rtnl_rtprot_tab->tab); |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 101 | } |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 102 | |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 103 | #if 0 /* UNUSED */ |
| 104 | const char* FAST_FUNC rtnl_rtprot_n2a(int id) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 105 | { |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 106 | if (id < 0 || id > RT_TABLE_MAX) { |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 107 | return itoa(id); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 108 | } |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 109 | |
| 110 | rtnl_rtprot_initialize(); |
| 111 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 112 | if (rtnl_rtprot_tab->tab[id]) |
| 113 | return rtnl_rtprot_tab->tab[id]; |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 114 | return itoa(id); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 115 | } |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 116 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 117 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 118 | int FAST_FUNC rtnl_rtprot_a2n(uint32_t *id, char *arg) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 119 | { |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 120 | rtnl_rtprot_initialize(); |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 121 | return rtnl_a2n(rtnl_rtprot_tab, id, arg, 0); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 125 | static rtnl_tab_t *rtnl_rtscope_tab; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 126 | |
| 127 | static void rtnl_rtscope_initialize(void) |
| 128 | { |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 129 | if (rtnl_rtscope_tab) |
| 130 | return; |
| 131 | rtnl_rtscope_tab = xzalloc(sizeof(*rtnl_rtscope_tab)); |
| 132 | rtnl_rtscope_tab->tab[0] = "global"; |
| 133 | rtnl_rtscope_tab->tab[255] = "nowhere"; |
| 134 | rtnl_rtscope_tab->tab[254] = "host"; |
| 135 | rtnl_rtscope_tab->tab[253] = "link"; |
| 136 | rtnl_rtscope_tab->tab[200] = "site"; |
Denys Vlasenko | 8403b01 | 2015-10-08 17:15:08 +0200 | [diff] [blame] | 137 | rtnl_tab_initialize("scopes", rtnl_rtscope_tab->tab); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 140 | const char* FAST_FUNC rtnl_rtscope_n2a(int id) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 141 | { |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 142 | if (id < 0 || id > RT_TABLE_MAX) { |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 143 | return itoa(id); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 144 | } |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 145 | |
| 146 | rtnl_rtscope_initialize(); |
| 147 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 148 | if (rtnl_rtscope_tab->tab[id]) |
| 149 | return rtnl_rtscope_tab->tab[id]; |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 150 | return itoa(id); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 153 | int FAST_FUNC rtnl_rtscope_a2n(uint32_t *id, char *arg) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 154 | { |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 155 | rtnl_rtscope_initialize(); |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 156 | return rtnl_a2n(rtnl_rtscope_tab, id, arg, 0); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 160 | static rtnl_tab_t *rtnl_rtrealm_tab; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 161 | |
| 162 | static void rtnl_rtrealm_initialize(void) |
| 163 | { |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 164 | if (rtnl_rtrealm_tab) return; |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 165 | rtnl_rtrealm_tab = xzalloc(sizeof(*rtnl_rtrealm_tab)); |
| 166 | rtnl_rtrealm_tab->tab[0] = "unknown"; |
Denys Vlasenko | 8403b01 | 2015-10-08 17:15:08 +0200 | [diff] [blame] | 167 | rtnl_tab_initialize("realms", rtnl_rtrealm_tab->tab); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 170 | int FAST_FUNC rtnl_rtrealm_a2n(uint32_t *id, char *arg) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 171 | { |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 172 | rtnl_rtrealm_initialize(); |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 173 | return rtnl_a2n(rtnl_rtrealm_tab, id, arg, 0); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 176 | #if ENABLE_FEATURE_IP_RULE |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 177 | const char* FAST_FUNC rtnl_rtrealm_n2a(int id) |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 178 | { |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 179 | if (id < 0 || id > RT_TABLE_MAX) { |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 180 | return itoa(id); |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 181 | } |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 182 | |
| 183 | rtnl_rtrealm_initialize(); |
| 184 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 185 | if (rtnl_rtrealm_tab->tab[id]) |
| 186 | return rtnl_rtrealm_tab->tab[id]; |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 187 | return itoa(id); |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 188 | } |
| 189 | #endif |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 190 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 191 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 192 | static rtnl_tab_t *rtnl_rtdsfield_tab; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 193 | |
| 194 | static void rtnl_rtdsfield_initialize(void) |
| 195 | { |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 196 | if (rtnl_rtdsfield_tab) return; |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 197 | rtnl_rtdsfield_tab = xzalloc(sizeof(*rtnl_rtdsfield_tab)); |
| 198 | rtnl_rtdsfield_tab->tab[0] = "0"; |
Denys Vlasenko | 8403b01 | 2015-10-08 17:15:08 +0200 | [diff] [blame] | 199 | rtnl_tab_initialize("dsfield", rtnl_rtdsfield_tab->tab); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 202 | const char* FAST_FUNC rtnl_dsfield_n2a(int id) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 203 | { |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 204 | if (id < 0 || id > RT_TABLE_MAX) { |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 205 | return itoa(id); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 206 | } |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 207 | |
| 208 | rtnl_rtdsfield_initialize(); |
| 209 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 210 | if (rtnl_rtdsfield_tab->tab[id]) |
| 211 | return rtnl_rtdsfield_tab->tab[id]; |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 212 | return itoa(id); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 215 | int FAST_FUNC rtnl_dsfield_a2n(uint32_t *id, char *arg) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 216 | { |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 217 | rtnl_rtdsfield_initialize(); |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 218 | return rtnl_a2n(rtnl_rtdsfield_tab, id, arg, 16); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 219 | } |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 220 | |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 221 | |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 222 | #if ENABLE_FEATURE_IP_RULE |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 223 | static rtnl_tab_t *rtnl_rttable_tab; |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 224 | |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 225 | static void rtnl_rttable_initialize(void) |
| 226 | { |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 227 | if (rtnl_rttable_tab) |
| 228 | return; |
| 229 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 230 | rtnl_rttable_tab = xzalloc(sizeof(*rtnl_rttable_tab)); |
| 231 | rtnl_rttable_tab->tab[0] = "unspec"; |
| 232 | rtnl_rttable_tab->tab[255] = "local"; |
| 233 | rtnl_rttable_tab->tab[254] = "main"; |
| 234 | rtnl_rttable_tab->tab[253] = "default"; |
Denys Vlasenko | 8403b01 | 2015-10-08 17:15:08 +0200 | [diff] [blame] | 235 | rtnl_tab_initialize("tables", rtnl_rttable_tab->tab); |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 238 | const char* FAST_FUNC rtnl_rttable_n2a(int id) |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 239 | { |
Denys Vlasenko | 413feca | 2015-10-08 15:10:10 +0200 | [diff] [blame] | 240 | if (id < 0 || id > RT_TABLE_MAX) { |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 241 | return itoa(id); |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 242 | } |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 243 | |
| 244 | rtnl_rttable_initialize(); |
| 245 | |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 246 | if (rtnl_rttable_tab->tab[id]) |
| 247 | return rtnl_rttable_tab->tab[id]; |
Denys Vlasenko | 3d8d5e8 | 2015-10-08 13:02:28 +0200 | [diff] [blame] | 248 | return itoa(id); |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Denys Vlasenko | d31575a | 2009-10-13 17:58:24 +0200 | [diff] [blame] | 251 | int FAST_FUNC rtnl_rttable_a2n(uint32_t *id, char *arg) |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 252 | { |
Denis Vlasenko | d1a302b | 2006-12-31 20:40:20 +0000 | [diff] [blame] | 253 | rtnl_rttable_initialize(); |
Denys Vlasenko | 94466b8 | 2009-10-13 16:27:11 +0200 | [diff] [blame] | 254 | return rtnl_a2n(rtnl_rttable_tab, id, arg, 0); |
Bernhard Reutner-Fischer | 921f5df | 2006-11-21 15:36:08 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | #endif |