summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-31 20:40:20 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-31 20:40:20 +0000
commitd1a302b52f11563240db5313344a1331613e1538 (patch)
tree8c432cbb270e68bc2ea9d638fc183949ee5f0f8d /networking
parent50ddabc8592a528c84f236467f4febe9795e2d6b (diff)
downloadbusybox-w32-d1a302b52f11563240db5313344a1331613e1538.tar.gz
busybox-w32-d1a302b52f11563240db5313344a1331613e1538.tar.bz2
busybox-w32-d1a302b52f11563240db5313344a1331613e1538.zip
rt_names: stop allocating 5k in rwdata
objsizes: don't show build machinery's object modules
Diffstat (limited to 'networking')
-rw-r--r--networking/libiproute/rt_names.c190
1 files changed, 85 insertions, 105 deletions
diff --git a/networking/libiproute/rt_names.c b/networking/libiproute/rt_names.c
index ed21fbe26..69eb55e79 100644
--- a/networking/libiproute/rt_names.c
+++ b/networking/libiproute/rt_names.c
@@ -9,11 +9,8 @@
9 * 9 *
10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11 */ 11 */
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15 12
16#include <stdint.h> 13#include "libbb.h"
17#include "rt_names.h" 14#include "rt_names.h"
18 15
19static void rtnl_tab_initialize(char *file, const char **tab, int size) 16static void rtnl_tab_initialize(char *file, const char **tab, int size)
@@ -37,57 +34,56 @@ static void rtnl_tab_initialize(char *file, const char **tab, int size)
37 sscanf(p, "0x%x %s #", &id, namebuf) != 2 && 34 sscanf(p, "0x%x %s #", &id, namebuf) != 2 &&
38 sscanf(p, "%d %s\n", &id, namebuf) != 2 && 35 sscanf(p, "%d %s\n", &id, namebuf) != 2 &&
39 sscanf(p, "%d %s #", &id, namebuf) != 2) { 36 sscanf(p, "%d %s #", &id, namebuf) != 2) {
40 fprintf(stderr, "Database %s is corrupted at %s\n", 37 bb_error_msg("database %s is corrupted at %s",
41 file, p); 38 file, p);
42 return; 39 return;
43 } 40 }
44 41
45 if (id<0 || id>size) 42 if (id < 0 || id > size)
46 continue; 43 continue;
47 44
48 tab[id] = strdup(namebuf); 45 tab[id] = xstrdup(namebuf);
49 } 46 }
50 fclose(fp); 47 fclose(fp);
51} 48}
52 49
53 50
54static const char * rtnl_rtprot_tab[256] = { 51static const char **rtnl_rtprot_tab; /* [256] */
55 "none",
56 "redirect",
57 "kernel",
58 "boot",
59 "static",
60 NULL,
61 NULL,
62 NULL,
63 "gated",
64 "ra",
65 "mrt",
66 "zebra",
67 "bird",
68};
69
70
71
72static int rtnl_rtprot_init;
73 52
74static void rtnl_rtprot_initialize(void) 53static void rtnl_rtprot_initialize(void)
75{ 54{
76 rtnl_rtprot_init = 1; 55 static const char *const init_tab[] = {
56 "none",
57 "redirect",
58 "kernel",
59 "boot",
60 "static",
61 NULL,
62 NULL,
63 NULL,
64 "gated",
65 "ra",
66 "mrt",
67 "zebra",
68 "bird",
69 };
70 if (rtnl_rtprot_tab) return;
71 rtnl_rtprot_tab = xzalloc(256 * sizeof(rtnl_rtprot_tab[0]));
72 memcpy(rtnl_rtprot_tab, init_tab, sizeof(init_tab));
77 rtnl_tab_initialize("/etc/iproute2/rt_protos", 73 rtnl_tab_initialize("/etc/iproute2/rt_protos",
78 rtnl_rtprot_tab, 256); 74 rtnl_rtprot_tab, 256);
79} 75}
80 76
81const char * rtnl_rtprot_n2a(int id, char *buf, int len) 77
78const char* rtnl_rtprot_n2a(int id, char *buf, int len)
82{ 79{
83 if (id<0 || id>=256) { 80 if (id < 0 || id >= 256) {
84 snprintf(buf, len, "%d", id); 81 snprintf(buf, len, "%d", id);
85 return buf; 82 return buf;
86 } 83 }
87 if (!rtnl_rtprot_tab[id]) { 84
88 if (!rtnl_rtprot_init) 85 rtnl_rtprot_initialize();
89 rtnl_rtprot_initialize(); 86
90 }
91 if (rtnl_rtprot_tab[id]) 87 if (rtnl_rtprot_tab[id])
92 return rtnl_rtprot_tab[id]; 88 return rtnl_rtprot_tab[id];
93 snprintf(buf, len, "%d", id); 89 snprintf(buf, len, "%d", id);
@@ -98,7 +94,6 @@ int rtnl_rtprot_a2n(uint32_t *id, char *arg)
98{ 94{
99 static const char *cache = NULL; 95 static const char *cache = NULL;
100 static unsigned long res; 96 static unsigned long res;
101 char *end;
102 int i; 97 int i;
103 98
104 if (cache && strcmp(cache, arg) == 0) { 99 if (cache && strcmp(cache, arg) == 0) {
@@ -106,10 +101,9 @@ int rtnl_rtprot_a2n(uint32_t *id, char *arg)
106 return 0; 101 return 0;
107 } 102 }
108 103
109 if (!rtnl_rtprot_init) 104 rtnl_rtprot_initialize();
110 rtnl_rtprot_initialize();
111 105
112 for (i=0; i<256; i++) { 106 for (i = 0; i < 256; i++) {
113 if (rtnl_rtprot_tab[i] && 107 if (rtnl_rtprot_tab[i] &&
114 strcmp(rtnl_rtprot_tab[i], arg) == 0) { 108 strcmp(rtnl_rtprot_tab[i], arg) == 0) {
115 cache = rtnl_rtprot_tab[i]; 109 cache = rtnl_rtprot_tab[i];
@@ -119,24 +113,21 @@ int rtnl_rtprot_a2n(uint32_t *id, char *arg)
119 } 113 }
120 } 114 }
121 115
122 res = strtoul(arg, &end, 0); 116 res = bb_strtoul(arg, NULL, 0);
123 if (!end || end == arg || *end || res > 255) 117 if (errno || res > 255)
124 return -1; 118 return -1;
125 *id = res; 119 *id = res;
126 return 0; 120 return 0;
127} 121}
128 122
129 123
130 124static const char **rtnl_rtscope_tab; /* [256] */
131static const char * rtnl_rtscope_tab[256] = {
132 "global",
133};
134
135static int rtnl_rtscope_init;
136 125
137static void rtnl_rtscope_initialize(void) 126static void rtnl_rtscope_initialize(void)
138{ 127{
139 rtnl_rtscope_init = 1; 128 if (rtnl_rtscope_tab) return;
129 rtnl_rtscope_tab = xzalloc(256 * sizeof(rtnl_rtscope_tab[0]));
130 rtnl_rtscope_tab[0] = "global";
140 rtnl_rtscope_tab[255] = "nowhere"; 131 rtnl_rtscope_tab[255] = "nowhere";
141 rtnl_rtscope_tab[254] = "host"; 132 rtnl_rtscope_tab[254] = "host";
142 rtnl_rtscope_tab[253] = "link"; 133 rtnl_rtscope_tab[253] = "link";
@@ -145,16 +136,16 @@ static void rtnl_rtscope_initialize(void)
145 rtnl_rtscope_tab, 256); 136 rtnl_rtscope_tab, 256);
146} 137}
147 138
148const char * rtnl_rtscope_n2a(int id, char *buf, int len) 139
140const char* rtnl_rtscope_n2a(int id, char *buf, int len)
149{ 141{
150 if (id<0 || id>=256) { 142 if (id < 0 || id >= 256) {
151 snprintf(buf, len, "%d", id); 143 snprintf(buf, len, "%d", id);
152 return buf; 144 return buf;
153 } 145 }
154 if (!rtnl_rtscope_tab[id]) { 146
155 if (!rtnl_rtscope_init) 147 rtnl_rtscope_initialize();
156 rtnl_rtscope_initialize(); 148
157 }
158 if (rtnl_rtscope_tab[id]) 149 if (rtnl_rtscope_tab[id])
159 return rtnl_rtscope_tab[id]; 150 return rtnl_rtscope_tab[id];
160 snprintf(buf, len, "%d", id); 151 snprintf(buf, len, "%d", id);
@@ -165,7 +156,6 @@ int rtnl_rtscope_a2n(uint32_t *id, char *arg)
165{ 156{
166 static const char *cache = NULL; 157 static const char *cache = NULL;
167 static unsigned long res; 158 static unsigned long res;
168 char *end;
169 int i; 159 int i;
170 160
171 if (cache && strcmp(cache, arg) == 0) { 161 if (cache && strcmp(cache, arg) == 0) {
@@ -173,10 +163,9 @@ int rtnl_rtscope_a2n(uint32_t *id, char *arg)
173 return 0; 163 return 0;
174 } 164 }
175 165
176 if (!rtnl_rtscope_init) 166 rtnl_rtscope_initialize();
177 rtnl_rtscope_initialize();
178 167
179 for (i=0; i<256; i++) { 168 for (i = 0; i < 256; i++) {
180 if (rtnl_rtscope_tab[i] && 169 if (rtnl_rtscope_tab[i] &&
181 strcmp(rtnl_rtscope_tab[i], arg) == 0) { 170 strcmp(rtnl_rtscope_tab[i], arg) == 0) {
182 cache = rtnl_rtscope_tab[i]; 171 cache = rtnl_rtscope_tab[i];
@@ -186,33 +175,30 @@ int rtnl_rtscope_a2n(uint32_t *id, char *arg)
186 } 175 }
187 } 176 }
188 177
189 res = strtoul(arg, &end, 0); 178 res = bb_strtoul(arg, NULL, 0);
190 if (!end || end == arg || *end || res > 255) 179 if (errno || res > 255)
191 return -1; 180 return -1;
192 *id = res; 181 *id = res;
193 return 0; 182 return 0;
194} 183}
195 184
196 185
197 186static const char **rtnl_rtrealm_tab; /* [256] */
198static const char * rtnl_rtrealm_tab[256] = {
199 "unknown",
200};
201
202static int rtnl_rtrealm_init;
203 187
204static void rtnl_rtrealm_initialize(void) 188static void rtnl_rtrealm_initialize(void)
205{ 189{
206 rtnl_rtrealm_init = 1; 190 if (rtnl_rtrealm_tab) return;
191 rtnl_rtrealm_tab = xzalloc(256 * sizeof(rtnl_rtrealm_tab[0]));
192 rtnl_rtrealm_tab[0] = "unknown";
207 rtnl_tab_initialize("/etc/iproute2/rt_realms", 193 rtnl_tab_initialize("/etc/iproute2/rt_realms",
208 rtnl_rtrealm_tab, 256); 194 rtnl_rtrealm_tab, 256);
209} 195}
210 196
197
211int rtnl_rtrealm_a2n(uint32_t *id, char *arg) 198int rtnl_rtrealm_a2n(uint32_t *id, char *arg)
212{ 199{
213 static const char *cache = NULL; 200 static const char *cache = NULL;
214 static unsigned long res; 201 static unsigned long res;
215 char *end;
216 int i; 202 int i;
217 203
218 if (cache && strcmp(cache, arg) == 0) { 204 if (cache && strcmp(cache, arg) == 0) {
@@ -220,10 +206,9 @@ int rtnl_rtrealm_a2n(uint32_t *id, char *arg)
220 return 0; 206 return 0;
221 } 207 }
222 208
223 if (!rtnl_rtrealm_init) 209 rtnl_rtrealm_initialize();
224 rtnl_rtrealm_initialize();
225 210
226 for (i=0; i<256; i++) { 211 for (i = 0; i < 256; i++) {
227 if (rtnl_rtrealm_tab[i] && 212 if (rtnl_rtrealm_tab[i] &&
228 strcmp(rtnl_rtrealm_tab[i], arg) == 0) { 213 strcmp(rtnl_rtrealm_tab[i], arg) == 0) {
229 cache = rtnl_rtrealm_tab[i]; 214 cache = rtnl_rtrealm_tab[i];
@@ -233,24 +218,23 @@ int rtnl_rtrealm_a2n(uint32_t *id, char *arg)
233 } 218 }
234 } 219 }
235 220
236 res = strtoul(arg, &end, 0); 221 res = bb_strtoul(arg, NULL, 0);
237 if (!end || end == arg || *end || res > 255) 222 if (errno || res > 255)
238 return -1; 223 return -1;
239 *id = res; 224 *id = res;
240 return 0; 225 return 0;
241} 226}
242 227
243#if ENABLE_FEATURE_IP_RULE 228#if ENABLE_FEATURE_IP_RULE
244const char * rtnl_rtrealm_n2a(int id, char *buf, int len) 229const char* rtnl_rtrealm_n2a(int id, char *buf, int len)
245{ 230{
246 if (id<0 || id>=256) { 231 if (id<0 || id>=256) {
247 snprintf(buf, len, "%d", id); 232 snprintf(buf, len, "%d", id);
248 return buf; 233 return buf;
249 } 234 }
250 if (!rtnl_rtrealm_tab[id]) { 235
251 if (!rtnl_rtrealm_init) 236 rtnl_rtrealm_initialize();
252 rtnl_rtrealm_initialize(); 237
253 }
254 if (rtnl_rtrealm_tab[id]) 238 if (rtnl_rtrealm_tab[id])
255 return rtnl_rtrealm_tab[id]; 239 return rtnl_rtrealm_tab[id];
256 snprintf(buf, len, "%d", id); 240 snprintf(buf, len, "%d", id);
@@ -258,29 +242,28 @@ const char * rtnl_rtrealm_n2a(int id, char *buf, int len)
258} 242}
259#endif 243#endif
260 244
261static const char * rtnl_rtdsfield_tab[256] = {
262 "0",
263};
264 245
265static int rtnl_rtdsfield_init; 246static const char **rtnl_rtdsfield_tab; /* [256] */
266 247
267static void rtnl_rtdsfield_initialize(void) 248static void rtnl_rtdsfield_initialize(void)
268{ 249{
269 rtnl_rtdsfield_init = 1; 250 if (rtnl_rtdsfield_tab) return;
251 rtnl_rtdsfield_tab = xzalloc(256 * sizeof(rtnl_rtdsfield_tab[0]));
252 rtnl_rtdsfield_tab[0] = "0";
270 rtnl_tab_initialize("/etc/iproute2/rt_dsfield", 253 rtnl_tab_initialize("/etc/iproute2/rt_dsfield",
271 rtnl_rtdsfield_tab, 256); 254 rtnl_rtdsfield_tab, 256);
272} 255}
273 256
257
274const char * rtnl_dsfield_n2a(int id, char *buf, int len) 258const char * rtnl_dsfield_n2a(int id, char *buf, int len)
275{ 259{
276 if (id<0 || id>=256) { 260 if (id<0 || id>=256) {
277 snprintf(buf, len, "%d", id); 261 snprintf(buf, len, "%d", id);
278 return buf; 262 return buf;
279 } 263 }
280 if (!rtnl_rtdsfield_tab[id]) { 264
281 if (!rtnl_rtdsfield_init) 265 rtnl_rtdsfield_initialize();
282 rtnl_rtdsfield_initialize(); 266
283 }
284 if (rtnl_rtdsfield_tab[id]) 267 if (rtnl_rtdsfield_tab[id])
285 return rtnl_rtdsfield_tab[id]; 268 return rtnl_rtdsfield_tab[id];
286 snprintf(buf, len, "0x%02x", id); 269 snprintf(buf, len, "0x%02x", id);
@@ -292,7 +275,6 @@ int rtnl_dsfield_a2n(uint32_t *id, char *arg)
292{ 275{
293 static const char *cache = NULL; 276 static const char *cache = NULL;
294 static unsigned long res; 277 static unsigned long res;
295 char *end;
296 int i; 278 int i;
297 279
298 if (cache && strcmp(cache, arg) == 0) { 280 if (cache && strcmp(cache, arg) == 0) {
@@ -300,10 +282,9 @@ int rtnl_dsfield_a2n(uint32_t *id, char *arg)
300 return 0; 282 return 0;
301 } 283 }
302 284
303 if (!rtnl_rtdsfield_init) 285 rtnl_rtdsfield_initialize();
304 rtnl_rtdsfield_initialize();
305 286
306 for (i=0; i<256; i++) { 287 for (i = 0; i < 256; i++) {
307 if (rtnl_rtdsfield_tab[i] && 288 if (rtnl_rtdsfield_tab[i] &&
308 strcmp(rtnl_rtdsfield_tab[i], arg) == 0) { 289 strcmp(rtnl_rtdsfield_tab[i], arg) == 0) {
309 cache = rtnl_rtdsfield_tab[i]; 290 cache = rtnl_rtdsfield_tab[i];
@@ -313,37 +294,38 @@ int rtnl_dsfield_a2n(uint32_t *id, char *arg)
313 } 294 }
314 } 295 }
315 296
316 res = strtoul(arg, &end, 16); 297 res = bb_strtoul(arg, NULL, 16);
317 if (!end || end == arg || *end || res > 255) 298 if (errno || res > 255)
318 return -1; 299 return -1;
319 *id = res; 300 *id = res;
320 return 0; 301 return 0;
321} 302}
322 303
304
323#if ENABLE_FEATURE_IP_RULE 305#if ENABLE_FEATURE_IP_RULE
324static int rtnl_rttable_init; 306static const char **rtnl_rttable_tab; /* [256] */
325static const char * rtnl_rttable_tab[256] = { 307
326 "unspec",
327};
328static void rtnl_rttable_initialize(void) 308static void rtnl_rttable_initialize(void)
329{ 309{
330 rtnl_rttable_init = 1; 310 if (rtnl_rtdsfield_tab) return;
311 rtnl_rttable_tab = xzalloc(256 * sizeof(rtnl_rttable_tab[0]));
312 rtnl_rttable_tab[0] = "unspec";
331 rtnl_rttable_tab[255] = "local"; 313 rtnl_rttable_tab[255] = "local";
332 rtnl_rttable_tab[254] = "main"; 314 rtnl_rttable_tab[254] = "main";
333 rtnl_rttable_tab[253] = "default"; 315 rtnl_rttable_tab[253] = "default";
334 rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab, 256); 316 rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab, 256);
335} 317}
336 318
319
337const char *rtnl_rttable_n2a(int id, char *buf, int len) 320const char *rtnl_rttable_n2a(int id, char *buf, int len)
338{ 321{
339 if (id < 0 || id >= 256) { 322 if (id < 0 || id >= 256) {
340 snprintf(buf, len, "%d", id); 323 snprintf(buf, len, "%d", id);
341 return buf; 324 return buf;
342 } 325 }
343 if (!rtnl_rttable_tab[id]) { 326
344 if (!rtnl_rttable_init) 327 rtnl_rttable_initialize();
345 rtnl_rttable_initialize(); 328
346 }
347 if (rtnl_rttable_tab[id]) 329 if (rtnl_rttable_tab[id])
348 return rtnl_rttable_tab[id]; 330 return rtnl_rttable_tab[id];
349 snprintf(buf, len, "%d", id); 331 snprintf(buf, len, "%d", id);
@@ -354,7 +336,6 @@ int rtnl_rttable_a2n(uint32_t * id, char *arg)
354{ 336{
355 static char *cache = NULL; 337 static char *cache = NULL;
356 static unsigned long res; 338 static unsigned long res;
357 char *end;
358 int i; 339 int i;
359 340
360 if (cache && strcmp(cache, arg) == 0) { 341 if (cache && strcmp(cache, arg) == 0) {
@@ -362,8 +343,7 @@ int rtnl_rttable_a2n(uint32_t * id, char *arg)
362 return 0; 343 return 0;
363 } 344 }
364 345
365 if (!rtnl_rttable_init) 346 rtnl_rttable_initialize();
366 rtnl_rttable_initialize();
367 347
368 for (i = 0; i < 256; i++) { 348 for (i = 0; i < 256; i++) {
369 if (rtnl_rttable_tab[i] && strcmp(rtnl_rttable_tab[i], arg) == 0) { 349 if (rtnl_rttable_tab[i] && strcmp(rtnl_rttable_tab[i], arg) == 0) {
@@ -374,8 +354,8 @@ int rtnl_rttable_a2n(uint32_t * id, char *arg)
374 } 354 }
375 } 355 }
376 356
377 i = strtoul(arg, &end, 0); 357 i = bb_strtoul(arg, NULL, 0);
378 if (!end || end == arg || *end || i > 255) 358 if (errno || i > 255)
379 return -1; 359 return -1;
380 *id = i; 360 *id = i;
381 return 0; 361 return 0;