Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/libiproute/rt_names.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/libiproute/rt_names.c
r2725 r3621 11 11 #include "rt_names.h" 12 12 13 #define CONFDIR CONFIG_FEATURE_IP_ROUTE_DIR 14 13 15 typedef struct rtnl_tab_t { 14 16 const char *cached_str; 15 17 unsigned cached_result; 16 const char *tab[256]; 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]; 17 26 } rtnl_tab_t; 18 27 … … 20 29 { 21 30 char *token[2]; 22 parser_t *parser = config_open2(file, fopen_for_read); 23 31 char fullname[sizeof(CONFDIR"/rt_dsfield") + 8]; 32 parser_t *parser; 33 34 sprintf(fullname, CONFDIR"/rt_%s", file); 35 parser = config_open2(fullname, fopen_for_read); 24 36 while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { 25 37 unsigned id = bb_strtou(token[0], NULL, 0); 26 if (id > 256) {38 if (id > RT_TABLE_MAX) { 27 39 bb_error_msg("database %s is corrupted at line %d", 28 40 file, parser->lineno); … … 43 55 } 44 56 45 for (i = 0; i < 256; i++) {57 for (i = 0; i <= RT_TABLE_MAX; i++) { 46 58 if (tab->tab[i] 47 59 && strcmp(tab->tab[i], arg) == 0 … … 55 67 56 68 i = bb_strtou(arg, NULL, base); 57 if (i > 255)69 if (i > RT_TABLE_MAX) 58 70 return -1; 59 71 *id = i; … … 86 98 rtnl_rtprot_tab = xzalloc(sizeof(*rtnl_rtprot_tab)); 87 99 memcpy(rtnl_rtprot_tab->tab, init_tab, sizeof(init_tab)); 88 rtnl_tab_initialize(" /etc/iproute2/rt_protos", rtnl_rtprot_tab->tab);89 } 90 91 const char* FAST_FUNC rtnl_rtprot_n2a(int id, char *buf) 92 { 93 if (id < 0 || id >= 256){94 sprintf(buf, "%d", id);95 return buf;100 rtnl_tab_initialize("protos", rtnl_rtprot_tab->tab); 101 } 102 103 #if 0 /* UNUSED */ 104 const char* FAST_FUNC rtnl_rtprot_n2a(int id) 105 { 106 if (id < 0 || id > RT_TABLE_MAX) { 107 return itoa(id); 96 108 } 97 109 … … 100 112 if (rtnl_rtprot_tab->tab[id]) 101 113 return rtnl_rtprot_tab->tab[id]; 102 /* buf is SPRINT_BSIZE big */ 103 sprintf(buf, "%d", id); 104 return buf; 105 } 114 return itoa(id); 115 } 116 #endif 106 117 107 118 int FAST_FUNC rtnl_rtprot_a2n(uint32_t *id, char *arg) … … 124 135 rtnl_rtscope_tab->tab[253] = "link"; 125 136 rtnl_rtscope_tab->tab[200] = "site"; 126 rtnl_tab_initialize("/etc/iproute2/rt_scopes", rtnl_rtscope_tab->tab); 127 } 128 129 const char* FAST_FUNC rtnl_rtscope_n2a(int id, char *buf) 130 { 131 if (id < 0 || id >= 256) { 132 sprintf(buf, "%d", id); 133 return buf; 137 rtnl_tab_initialize("scopes", rtnl_rtscope_tab->tab); 138 } 139 140 const char* FAST_FUNC rtnl_rtscope_n2a(int id) 141 { 142 if (id < 0 || id > RT_TABLE_MAX) { 143 return itoa(id); 134 144 } 135 145 … … 138 148 if (rtnl_rtscope_tab->tab[id]) 139 149 return rtnl_rtscope_tab->tab[id]; 140 /* buf is SPRINT_BSIZE big */ 141 sprintf(buf, "%d", id); 142 return buf; 150 return itoa(id); 143 151 } 144 152 … … 157 165 rtnl_rtrealm_tab = xzalloc(sizeof(*rtnl_rtrealm_tab)); 158 166 rtnl_rtrealm_tab->tab[0] = "unknown"; 159 rtnl_tab_initialize(" /etc/iproute2/rt_realms", rtnl_rtrealm_tab->tab);167 rtnl_tab_initialize("realms", rtnl_rtrealm_tab->tab); 160 168 } 161 169 … … 167 175 168 176 #if ENABLE_FEATURE_IP_RULE 169 const char* FAST_FUNC rtnl_rtrealm_n2a(int id, char *buf) 170 { 171 if (id < 0 || id >= 256) { 172 sprintf(buf, "%d", id); 173 return buf; 177 const char* FAST_FUNC rtnl_rtrealm_n2a(int id) 178 { 179 if (id < 0 || id > RT_TABLE_MAX) { 180 return itoa(id); 174 181 } 175 182 … … 178 185 if (rtnl_rtrealm_tab->tab[id]) 179 186 return rtnl_rtrealm_tab->tab[id]; 180 /* buf is SPRINT_BSIZE big */ 181 sprintf(buf, "%d", id); 182 return buf; 187 return itoa(id); 183 188 } 184 189 #endif … … 192 197 rtnl_rtdsfield_tab = xzalloc(sizeof(*rtnl_rtdsfield_tab)); 193 198 rtnl_rtdsfield_tab->tab[0] = "0"; 194 rtnl_tab_initialize("/etc/iproute2/rt_dsfield", rtnl_rtdsfield_tab->tab); 195 } 196 197 const char* FAST_FUNC rtnl_dsfield_n2a(int id, char *buf) 198 { 199 if (id < 0 || id >= 256) { 200 sprintf(buf, "%d", id); 201 return buf; 199 rtnl_tab_initialize("dsfield", rtnl_rtdsfield_tab->tab); 200 } 201 202 const char* FAST_FUNC rtnl_dsfield_n2a(int id) 203 { 204 if (id < 0 || id > RT_TABLE_MAX) { 205 return itoa(id); 202 206 } 203 207 … … 206 210 if (rtnl_rtdsfield_tab->tab[id]) 207 211 return rtnl_rtdsfield_tab->tab[id]; 208 /* buf is SPRINT_BSIZE big */ 209 sprintf(buf, "0x%02x", id); 210 return buf; 212 return itoa(id); 211 213 } 212 214 … … 223 225 static void rtnl_rttable_initialize(void) 224 226 { 225 if (rtnl_rtdsfield_tab) return; 227 if (rtnl_rttable_tab) 228 return; 229 226 230 rtnl_rttable_tab = xzalloc(sizeof(*rtnl_rttable_tab)); 227 231 rtnl_rttable_tab->tab[0] = "unspec"; … … 229 233 rtnl_rttable_tab->tab[254] = "main"; 230 234 rtnl_rttable_tab->tab[253] = "default"; 231 rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab->tab); 232 } 233 234 const char* FAST_FUNC rtnl_rttable_n2a(int id, char *buf) 235 { 236 if (id < 0 || id >= 256) { 237 sprintf(buf, "%d", id); 238 return buf; 235 rtnl_tab_initialize("tables", rtnl_rttable_tab->tab); 236 } 237 238 const char* FAST_FUNC rtnl_rttable_n2a(int id) 239 { 240 if (id < 0 || id > RT_TABLE_MAX) { 241 return itoa(id); 239 242 } 240 243 … … 243 246 if (rtnl_rttable_tab->tab[id]) 244 247 return rtnl_rttable_tab->tab[id]; 245 /* buf is SPRINT_BSIZE big */ 246 sprintf(buf, "%d", id); 247 return buf; 248 return itoa(id); 248 249 } 249 250
Note:
See TracChangeset
for help on using the changeset viewer.