diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-05 09:21:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-05 09:21:57 +0000 |
commit | 76140a77c9c47c41f244d90d4250d77b9504f7d4 (patch) | |
tree | 67c43b25beb904f111e8a96548bee1592f5010e2 | |
parent | 021de3f0297af87bfc098bd364dffb332d6ace20 (diff) | |
download | busybox-w32-76140a77c9c47c41f244d90d4250d77b9504f7d4.tar.gz busybox-w32-76140a77c9c47c41f244d90d4250d77b9504f7d4.tar.bz2 busybox-w32-76140a77c9c47c41f244d90d4250d77b9504f7d4.zip |
networking/libiproute/*: code shrink by optimizing numeric conversions
and other misc stuff
function old new delta
print_tunnel 660 656 -4
format_host 5 - -5
get_unsigned 70 54 -16
get_u32 70 54 -16
do_iplink 1173 1151 -22
get_prefix 417 393 -24
print_rule 800 771 -29
print_addrinfo 1374 1342 -32
print_route 1745 1709 -36
iprule_modify 905 866 -39
iproute_modify 1105 1048 -57
get_integer 70 - -70
parse_args 1684 1440 -244
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/11 up/down: 0/-594) Total: -594 bytes
text data bss dec hex filename
817378 476 7892 825746 c9992 busybox_old
816784 476 7892 825152 c9740 busybox_unstripped
-rw-r--r-- | networking/libiproute/ipaddress.c | 9 | ||||
-rw-r--r-- | networking/libiproute/iplink.c | 3 | ||||
-rw-r--r-- | networking/libiproute/iproute.c | 9 | ||||
-rw-r--r-- | networking/libiproute/iprule.c | 8 | ||||
-rw-r--r-- | networking/libiproute/iptunnel.c | 15 | ||||
-rw-r--r-- | networking/libiproute/ll_proto.c | 10 | ||||
-rw-r--r-- | networking/libiproute/utils.c | 121 | ||||
-rw-r--r-- | networking/libiproute/utils.h | 20 | ||||
-rw-r--r-- | networking/tc.c | 8 |
9 files changed, 63 insertions, 140 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index fadab6f39..644874f46 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c | |||
@@ -280,17 +280,16 @@ static int print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, | |||
280 | 280 | ||
281 | if (rta_tb[IFA_LOCAL]) { | 281 | if (rta_tb[IFA_LOCAL]) { |
282 | fputs(rt_addr_n2a(ifa->ifa_family, | 282 | fputs(rt_addr_n2a(ifa->ifa_family, |
283 | RTA_PAYLOAD(rta_tb[IFA_LOCAL]), | ||
284 | RTA_DATA(rta_tb[IFA_LOCAL]), | 283 | RTA_DATA(rta_tb[IFA_LOCAL]), |
285 | abuf, sizeof(abuf)), stdout); | 284 | abuf, sizeof(abuf)), stdout); |
286 | 285 | ||
287 | if (rta_tb[IFA_ADDRESS] == NULL || | 286 | if (rta_tb[IFA_ADDRESS] == NULL |
288 | memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0) { | 287 | || memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0 |
288 | ) { | ||
289 | printf("/%d ", ifa->ifa_prefixlen); | 289 | printf("/%d ", ifa->ifa_prefixlen); |
290 | } else { | 290 | } else { |
291 | printf(" peer %s/%d ", | 291 | printf(" peer %s/%d ", |
292 | rt_addr_n2a(ifa->ifa_family, | 292 | rt_addr_n2a(ifa->ifa_family, |
293 | RTA_PAYLOAD(rta_tb[IFA_ADDRESS]), | ||
294 | RTA_DATA(rta_tb[IFA_ADDRESS]), | 293 | RTA_DATA(rta_tb[IFA_ADDRESS]), |
295 | abuf, sizeof(abuf)), | 294 | abuf, sizeof(abuf)), |
296 | ifa->ifa_prefixlen); | 295 | ifa->ifa_prefixlen); |
@@ -300,14 +299,12 @@ static int print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, | |||
300 | if (rta_tb[IFA_BROADCAST]) { | 299 | if (rta_tb[IFA_BROADCAST]) { |
301 | printf("brd %s ", | 300 | printf("brd %s ", |
302 | rt_addr_n2a(ifa->ifa_family, | 301 | rt_addr_n2a(ifa->ifa_family, |
303 | RTA_PAYLOAD(rta_tb[IFA_BROADCAST]), | ||
304 | RTA_DATA(rta_tb[IFA_BROADCAST]), | 302 | RTA_DATA(rta_tb[IFA_BROADCAST]), |
305 | abuf, sizeof(abuf))); | 303 | abuf, sizeof(abuf))); |
306 | } | 304 | } |
307 | if (rta_tb[IFA_ANYCAST]) { | 305 | if (rta_tb[IFA_ANYCAST]) { |
308 | printf("any %s ", | 306 | printf("any %s ", |
309 | rt_addr_n2a(ifa->ifa_family, | 307 | rt_addr_n2a(ifa->ifa_family, |
310 | RTA_PAYLOAD(rta_tb[IFA_ANYCAST]), | ||
311 | RTA_DATA(rta_tb[IFA_ANYCAST]), | 308 | RTA_DATA(rta_tb[IFA_ANYCAST]), |
312 | abuf, sizeof(abuf))); | 309 | abuf, sizeof(abuf))); |
313 | } | 310 | } |
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index d3d0338b0..1e7ee07d2 100644 --- a/networking/libiproute/iplink.c +++ b/networking/libiproute/iplink.c | |||
@@ -202,8 +202,7 @@ static int do_set(char **argv) | |||
202 | NEXT_ARG(); | 202 | NEXT_ARG(); |
203 | if (mtu != -1) | 203 | if (mtu != -1) |
204 | duparg("mtu", *argv); | 204 | duparg("mtu", *argv); |
205 | if (get_integer(&mtu, *argv, 0)) | 205 | mtu = get_unsigned(*argv, "mtu"); |
206 | invarg(*argv, "mtu"); | ||
207 | } | 206 | } |
208 | if (key == ARG_multicast) { | 207 | if (key == ARG_multicast) { |
209 | int param; | 208 | int param; |
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index a7ec66c7f..66557d8fd 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c | |||
@@ -202,7 +202,6 @@ static int print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
202 | if (tb[RTA_DST]) { | 202 | if (tb[RTA_DST]) { |
203 | if (r->rtm_dst_len != host_len) { | 203 | if (r->rtm_dst_len != host_len) { |
204 | printf("%s/%u ", rt_addr_n2a(r->rtm_family, | 204 | printf("%s/%u ", rt_addr_n2a(r->rtm_family, |
205 | RTA_PAYLOAD(tb[RTA_DST]), | ||
206 | RTA_DATA(tb[RTA_DST]), | 205 | RTA_DATA(tb[RTA_DST]), |
207 | abuf, sizeof(abuf)), | 206 | abuf, sizeof(abuf)), |
208 | r->rtm_dst_len | 207 | r->rtm_dst_len |
@@ -222,7 +221,6 @@ static int print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
222 | if (tb[RTA_SRC]) { | 221 | if (tb[RTA_SRC]) { |
223 | if (r->rtm_src_len != host_len) { | 222 | if (r->rtm_src_len != host_len) { |
224 | printf("from %s/%u ", rt_addr_n2a(r->rtm_family, | 223 | printf("from %s/%u ", rt_addr_n2a(r->rtm_family, |
225 | RTA_PAYLOAD(tb[RTA_SRC]), | ||
226 | RTA_DATA(tb[RTA_SRC]), | 224 | RTA_DATA(tb[RTA_SRC]), |
227 | abuf, sizeof(abuf)), | 225 | abuf, sizeof(abuf)), |
228 | r->rtm_src_len | 226 | r->rtm_src_len |
@@ -252,7 +250,6 @@ static int print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
252 | and symbolic name will not be useful. | 250 | and symbolic name will not be useful. |
253 | */ | 251 | */ |
254 | printf(" src %s ", rt_addr_n2a(r->rtm_family, | 252 | printf(" src %s ", rt_addr_n2a(r->rtm_family, |
255 | RTA_PAYLOAD(tb[RTA_PREFSRC]), | ||
256 | RTA_DATA(tb[RTA_PREFSRC]), | 253 | RTA_DATA(tb[RTA_PREFSRC]), |
257 | abuf, sizeof(abuf))); | 254 | abuf, sizeof(abuf))); |
258 | } | 255 | } |
@@ -367,8 +364,7 @@ USE_FEATURE_IP_RULE(ARG_table,) | |||
367 | mxlock |= (1 << RTAX_MTU); | 364 | mxlock |= (1 << RTAX_MTU); |
368 | NEXT_ARG(); | 365 | NEXT_ARG(); |
369 | } | 366 | } |
370 | if (get_unsigned(&mtu, *argv, 0)) | 367 | mtu = get_unsigned(*argv, "mtu"); |
371 | invarg(*argv, "mtu"); | ||
372 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu); | 368 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu); |
373 | } else if (arg == ARG_protocol) { | 369 | } else if (arg == ARG_protocol) { |
374 | uint32_t prot; | 370 | uint32_t prot; |
@@ -391,8 +387,7 @@ USE_FEATURE_IP_RULE(ARG_table,) | |||
391 | } else if (arg == ARG_metric) { | 387 | } else if (arg == ARG_metric) { |
392 | uint32_t metric; | 388 | uint32_t metric; |
393 | NEXT_ARG(); | 389 | NEXT_ARG(); |
394 | if (get_u32(&metric, *argv, 0)) | 390 | metric = get_u32(*argv, "metric"); |
395 | invarg(*argv, "metric"); | ||
396 | addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric); | 391 | addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric); |
397 | } else { | 392 | } else { |
398 | int type; | 393 | int type; |
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c index ca2254667..6c90c6d21 100644 --- a/networking/libiproute/iprule.c +++ b/networking/libiproute/iprule.c | |||
@@ -78,7 +78,6 @@ static int print_rule(const struct sockaddr_nl *who UNUSED_PARAM, | |||
78 | if (tb[RTA_SRC]) { | 78 | if (tb[RTA_SRC]) { |
79 | if (r->rtm_src_len != host_len) { | 79 | if (r->rtm_src_len != host_len) { |
80 | printf("%s/%u", rt_addr_n2a(r->rtm_family, | 80 | printf("%s/%u", rt_addr_n2a(r->rtm_family, |
81 | RTA_PAYLOAD(tb[RTA_SRC]), | ||
82 | RTA_DATA(tb[RTA_SRC]), | 81 | RTA_DATA(tb[RTA_SRC]), |
83 | abuf, sizeof(abuf)), | 82 | abuf, sizeof(abuf)), |
84 | r->rtm_src_len | 83 | r->rtm_src_len |
@@ -99,7 +98,6 @@ static int print_rule(const struct sockaddr_nl *who UNUSED_PARAM, | |||
99 | if (tb[RTA_DST]) { | 98 | if (tb[RTA_DST]) { |
100 | if (r->rtm_dst_len != host_len) { | 99 | if (r->rtm_dst_len != host_len) { |
101 | printf("to %s/%u ", rt_addr_n2a(r->rtm_family, | 100 | printf("to %s/%u ", rt_addr_n2a(r->rtm_family, |
102 | RTA_PAYLOAD(tb[RTA_DST]), | ||
103 | RTA_DATA(tb[RTA_DST]), | 101 | RTA_DATA(tb[RTA_DST]), |
104 | abuf, sizeof(abuf)), | 102 | abuf, sizeof(abuf)), |
105 | r->rtm_dst_len | 103 | r->rtm_dst_len |
@@ -238,8 +236,7 @@ static int iprule_modify(int cmd, char **argv) | |||
238 | key == ARG_priority) { | 236 | key == ARG_priority) { |
239 | uint32_t pref; | 237 | uint32_t pref; |
240 | NEXT_ARG(); | 238 | NEXT_ARG(); |
241 | if (get_u32(&pref, *argv, 0)) | 239 | pref = get_u32(*argv, "preference"); |
242 | invarg(*argv, "preference"); | ||
243 | addattr32(&req.n, sizeof(req), RTA_PRIORITY, pref); | 240 | addattr32(&req.n, sizeof(req), RTA_PRIORITY, pref); |
244 | } else if (key == ARG_tos) { | 241 | } else if (key == ARG_tos) { |
245 | uint32_t tos; | 242 | uint32_t tos; |
@@ -250,8 +247,7 @@ static int iprule_modify(int cmd, char **argv) | |||
250 | } else if (key == ARG_fwmark) { | 247 | } else if (key == ARG_fwmark) { |
251 | uint32_t fwmark; | 248 | uint32_t fwmark; |
252 | NEXT_ARG(); | 249 | NEXT_ARG(); |
253 | if (get_u32(&fwmark, *argv, 0)) | 250 | fwmark = get_u32(*argv, "fwmark"); |
254 | invarg(*argv, "fwmark"); | ||
255 | addattr32(&req.n, sizeof(req), RTA_PROTOINFO, fwmark); | 251 | addattr32(&req.n, sizeof(req), RTA_PROTOINFO, fwmark); |
256 | } else if (key == ARG_realms) { | 252 | } else if (key == ARG_realms) { |
257 | uint32_t realm; | 253 | uint32_t realm; |
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index 5349587ae..6a841aadb 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c | |||
@@ -232,9 +232,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) | |||
232 | if (strchr(*argv, '.')) | 232 | if (strchr(*argv, '.')) |
233 | p->i_key = p->o_key = get_addr32(*argv); | 233 | p->i_key = p->o_key = get_addr32(*argv); |
234 | else { | 234 | else { |
235 | if (get_unsigned(&uval, *argv, 0) < 0) { | 235 | uval = get_unsigned(*argv, "key"); |
236 | invarg(*argv, "key"); | ||
237 | } | ||
238 | p->i_key = p->o_key = htonl(uval); | 236 | p->i_key = p->o_key = htonl(uval); |
239 | } | 237 | } |
240 | } else if (key == ARG_ikey) { | 238 | } else if (key == ARG_ikey) { |
@@ -244,9 +242,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) | |||
244 | if (strchr(*argv, '.')) | 242 | if (strchr(*argv, '.')) |
245 | p->o_key = get_addr32(*argv); | 243 | p->o_key = get_addr32(*argv); |
246 | else { | 244 | else { |
247 | if (get_unsigned(&uval, *argv, 0) < 0) { | 245 | uval = get_unsigned(*argv, "ikey"); |
248 | invarg(*argv, "ikey"); | ||
249 | } | ||
250 | p->i_key = htonl(uval); | 246 | p->i_key = htonl(uval); |
251 | } | 247 | } |
252 | } else if (key == ARG_okey) { | 248 | } else if (key == ARG_okey) { |
@@ -256,9 +252,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) | |||
256 | if (strchr(*argv, '.')) | 252 | if (strchr(*argv, '.')) |
257 | p->o_key = get_addr32(*argv); | 253 | p->o_key = get_addr32(*argv); |
258 | else { | 254 | else { |
259 | if (get_unsigned(&uval, *argv, 0) < 0) { | 255 | uval = get_unsigned(*argv, "okey"); |
260 | invarg(*argv, "okey"); | ||
261 | } | ||
262 | p->o_key = htonl(uval); | 256 | p->o_key = htonl(uval); |
263 | } | 257 | } |
264 | } else if (key == ARG_seq) { | 258 | } else if (key == ARG_seq) { |
@@ -297,8 +291,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) | |||
297 | NEXT_ARG(); | 291 | NEXT_ARG(); |
298 | key = index_in_strings(keywords, *argv); | 292 | key = index_in_strings(keywords, *argv); |
299 | if (key != ARG_inherit) { | 293 | if (key != ARG_inherit) { |
300 | if (get_unsigned(&uval, *argv, 0)) | 294 | uval = get_unsigned(*argv, "TTL"); |
301 | invarg(*argv, "TTL"); | ||
302 | if (uval > 255) | 295 | if (uval > 255) |
303 | invarg(*argv, "TTL must be <=255"); | 296 | invarg(*argv, "TTL must be <=255"); |
304 | p->iph.ttl = uval; | 297 | p->iph.ttl = uval; |
diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c index b8268732e..a93493538 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c | |||
@@ -115,13 +115,15 @@ int ll_proto_a2n(unsigned short *id, char *buf) | |||
115 | unsigned i; | 115 | unsigned i; |
116 | for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { | 116 | for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { |
117 | if (strcasecmp(llproto_names[i].name, buf) == 0) { | 117 | if (strcasecmp(llproto_names[i].name, buf) == 0) { |
118 | *id = htons(llproto_names[i].id); | 118 | i = llproto_names[i].id; |
119 | return 0; | 119 | goto good; |
120 | } | 120 | } |
121 | } | 121 | } |
122 | if (get_u16(id, buf, 0)) | 122 | i = bb_strtou(buf, NULL, 0); |
123 | if (errno || i > 0xffff) | ||
123 | return -1; | 124 | return -1; |
124 | *id = htons(*id); | 125 | good: |
126 | *id = htons(i); | ||
125 | return 0; | 127 | return 0; |
126 | } | 128 | } |
127 | 129 | ||
diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c index 6b9f6a7f5..c84d018eb 100644 --- a/networking/libiproute/utils.c +++ b/networking/libiproute/utils.c | |||
@@ -15,102 +15,46 @@ | |||
15 | #include "utils.h" | 15 | #include "utils.h" |
16 | #include "inet_common.h" | 16 | #include "inet_common.h" |
17 | 17 | ||
18 | int get_integer(int *val, char *arg, int base) | 18 | unsigned get_unsigned(char *arg, const char *errmsg) |
19 | { | ||
20 | long res; | ||
21 | char *ptr; | ||
22 | |||
23 | if (!arg || !*arg) | ||
24 | return -1; | ||
25 | res = strtol(arg, &ptr, base); | ||
26 | if (!ptr || ptr == arg || *ptr || res > INT_MAX || res < INT_MIN) | ||
27 | return -1; | ||
28 | *val = res; | ||
29 | return 0; | ||
30 | } | ||
31 | //XXX: FIXME: use some libbb function instead | ||
32 | int get_unsigned(unsigned *val, char *arg, int base) | ||
33 | { | ||
34 | unsigned long res; | ||
35 | char *ptr; | ||
36 | |||
37 | if (!arg || !*arg) | ||
38 | return -1; | ||
39 | res = strtoul(arg, &ptr, base); | ||
40 | if (!ptr || ptr == arg || *ptr || res > UINT_MAX) | ||
41 | return -1; | ||
42 | *val = res; | ||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | int get_u32(uint32_t *val, char *arg, int base) | ||
47 | { | 19 | { |
48 | unsigned long res; | 20 | unsigned long res; |
49 | char *ptr; | 21 | char *ptr; |
50 | 22 | ||
51 | if (!arg || !*arg) | 23 | if (*arg) { |
52 | return -1; | 24 | res = strtoul(arg, &ptr, 0); |
53 | res = strtoul(arg, &ptr, base); | 25 | if (!*ptr && res <= UINT_MAX) { |
54 | if (!ptr || ptr == arg || *ptr || res > 0xFFFFFFFFUL) | 26 | return res; |
55 | return -1; | 27 | } |
56 | *val = res; | 28 | } |
57 | return 0; | 29 | invarg(arg, errmsg); /* does not return */ |
58 | } | 30 | } |
59 | 31 | ||
60 | int get_u16(uint16_t *val, char *arg, int base) | 32 | uint32_t get_u32(char *arg, const char *errmsg) |
61 | { | 33 | { |
62 | unsigned long res; | 34 | unsigned long res; |
63 | char *ptr; | 35 | char *ptr; |
64 | 36 | ||
65 | if (!arg || !*arg) | 37 | if (*arg) { |
66 | return -1; | 38 | res = strtoul(arg, &ptr, 0); |
67 | res = strtoul(arg, &ptr, base); | 39 | if (!*ptr && res <= 0xFFFFFFFFUL) { |
68 | if (!ptr || ptr == arg || *ptr || res > 0xFFFF) | 40 | return res; |
69 | return -1; | 41 | } |
70 | *val = res; | 42 | } |
71 | return 0; | 43 | invarg(arg, errmsg); /* does not return */ |
72 | } | 44 | } |
73 | 45 | ||
74 | int get_u8(uint8_t *val, char *arg, int base) | 46 | uint16_t get_u16(char *arg, const char *errmsg) |
75 | { | 47 | { |
76 | unsigned long res; | 48 | unsigned long res; |
77 | char *ptr; | 49 | char *ptr; |
78 | 50 | ||
79 | if (!arg || !*arg) | 51 | if (*arg) { |
80 | return -1; | 52 | res = strtoul(arg, &ptr, 0); |
81 | res = strtoul(arg, &ptr, base); | 53 | if (!*ptr && res <= 0xFFFF) { |
82 | if (!ptr || ptr == arg || *ptr || res > 0xFF) | 54 | return res; |
83 | return -1; | 55 | } |
84 | *val = res; | 56 | } |
85 | return 0; | 57 | invarg(arg, errmsg); /* does not return */ |
86 | } | ||
87 | |||
88 | int get_s16(int16_t *val, char *arg, int base) | ||
89 | { | ||
90 | long res; | ||
91 | char *ptr; | ||
92 | |||
93 | if (!arg || !*arg) | ||
94 | return -1; | ||
95 | res = strtol(arg, &ptr, base); | ||
96 | if (!ptr || ptr == arg || *ptr || res > 0x7FFF || res < -0x8000) | ||
97 | return -1; | ||
98 | *val = res; | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | int get_s8(int8_t *val, char *arg, int base) | ||
103 | { | ||
104 | long res; | ||
105 | char *ptr; | ||
106 | |||
107 | if (!arg || !*arg) | ||
108 | return -1; | ||
109 | res = strtol(arg, &ptr, base); | ||
110 | if (!ptr || ptr == arg || *ptr || res > 0x7F || res < -0x80) | ||
111 | return -1; | ||
112 | *val = res; | ||
113 | return 0; | ||
114 | } | 58 | } |
115 | 59 | ||
116 | int get_addr_1(inet_prefix *addr, char *name, int family) | 60 | int get_addr_1(inet_prefix *addr, char *name, int family) |
@@ -161,8 +105,8 @@ static int get_prefix_1(inet_prefix *dst, char *arg, int family) | |||
161 | || strcmp(arg, "any") == 0 | 105 | || strcmp(arg, "any") == 0 |
162 | ) { | 106 | ) { |
163 | dst->family = family; | 107 | dst->family = family; |
164 | dst->bytelen = 0; | 108 | /*dst->bytelen = 0; - done by memset */ |
165 | dst->bitlen = 0; | 109 | /*dst->bitlen = 0;*/ |
166 | return 0; | 110 | return 0; |
167 | } | 111 | } |
168 | 112 | ||
@@ -176,7 +120,8 @@ static int get_prefix_1(inet_prefix *dst, char *arg, int family) | |||
176 | inet_prefix netmask_pfx; | 120 | inet_prefix netmask_pfx; |
177 | 121 | ||
178 | netmask_pfx.family = AF_UNSPEC; | 122 | netmask_pfx.family = AF_UNSPEC; |
179 | if ((get_unsigned(&plen, slash + 1, 0) || plen > dst->bitlen) | 123 | plen = bb_strtou(slash + 1, NULL, 0); |
124 | if ((errno || plen > dst->bitlen) | ||
180 | && (get_addr_1(&netmask_pfx, slash + 1, family))) | 125 | && (get_addr_1(&netmask_pfx, slash + 1, family))) |
181 | err = -1; | 126 | err = -1; |
182 | else if (netmask_pfx.family == AF_INET) { | 127 | else if (netmask_pfx.family == AF_INET) { |
@@ -262,7 +207,7 @@ int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits) | |||
262 | { | 207 | { |
263 | uint32_t *a1 = a->data; | 208 | uint32_t *a1 = a->data; |
264 | uint32_t *a2 = b->data; | 209 | uint32_t *a2 = b->data; |
265 | int words = bits >> 0x05; | 210 | int words = bits >> 5; |
266 | 211 | ||
267 | bits &= 0x1f; | 212 | bits &= 0x1f; |
268 | 213 | ||
@@ -286,7 +231,7 @@ int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits) | |||
286 | return 0; | 231 | return 0; |
287 | } | 232 | } |
288 | 233 | ||
289 | const char *rt_addr_n2a(int af, int UNUSED_PARAM len, | 234 | const char *rt_addr_n2a(int af, |
290 | void *addr, char *buf, int buflen) | 235 | void *addr, char *buf, int buflen) |
291 | { | 236 | { |
292 | switch (af) { | 237 | switch (af) { |
@@ -298,9 +243,9 @@ const char *rt_addr_n2a(int af, int UNUSED_PARAM len, | |||
298 | } | 243 | } |
299 | } | 244 | } |
300 | 245 | ||
246 | #ifdef RESOLVE_HOSTNAMES | ||
301 | const char *format_host(int af, int len, void *addr, char *buf, int buflen) | 247 | const char *format_host(int af, int len, void *addr, char *buf, int buflen) |
302 | { | 248 | { |
303 | #ifdef RESOLVE_HOSTNAMES | ||
304 | if (resolve_hosts) { | 249 | if (resolve_hosts) { |
305 | struct hostent *h_ent; | 250 | struct hostent *h_ent; |
306 | 251 | ||
@@ -323,6 +268,6 @@ const char *format_host(int af, int len, void *addr, char *buf, int buflen) | |||
323 | } | 268 | } |
324 | } | 269 | } |
325 | } | 270 | } |
326 | #endif | 271 | return rt_addr_n2a(af, addr, buf, buflen); |
327 | return rt_addr_n2a(af, len, addr, buf, buflen); | ||
328 | } | 272 | } |
273 | #endif | ||
diff --git a/networking/libiproute/utils.h b/networking/libiproute/utils.h index c1dbc6e8b..3603c75a7 100644 --- a/networking/libiproute/utils.h +++ b/networking/libiproute/utils.h | |||
@@ -64,19 +64,17 @@ extern int get_addr_1(inet_prefix *dst, char *arg, int family); | |||
64 | extern int get_addr(inet_prefix *dst, char *arg, int family); | 64 | extern int get_addr(inet_prefix *dst, char *arg, int family); |
65 | extern int get_prefix(inet_prefix *dst, char *arg, int family); | 65 | extern int get_prefix(inet_prefix *dst, char *arg, int family); |
66 | 66 | ||
67 | extern int get_integer(int *val, char *arg, int base); | 67 | extern unsigned get_unsigned(char *arg, const char *errmsg); |
68 | extern int get_unsigned(unsigned *val, char *arg, int base); | 68 | extern uint32_t get_u32(char *arg, const char *errmsg); |
69 | #define get_byte get_u8 | 69 | extern uint16_t get_u16(char *arg, const char *errmsg); |
70 | #define get_ushort get_u16 | ||
71 | #define get_short get_s16 | ||
72 | extern int get_u32(uint32_t *val, char *arg, int base); | ||
73 | extern int get_u16(uint16_t *val, char *arg, int base); | ||
74 | extern int get_s16(int16_t *val, char *arg, int base); | ||
75 | extern int get_u8(uint8_t *val, char *arg, int base); | ||
76 | extern int get_s8(int8_t *val, char *arg, int base); | ||
77 | 70 | ||
71 | extern const char *rt_addr_n2a(int af, void *addr, char *buf, int buflen); | ||
72 | #ifdef RESOLVE_HOSTNAMES | ||
78 | extern const char *format_host(int af, int len, void *addr, char *buf, int buflen); | 73 | extern const char *format_host(int af, int len, void *addr, char *buf, int buflen); |
79 | extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int buflen); | 74 | #else |
75 | #define format_host(af, len, addr, buf, buflen) \ | ||
76 | rt_addr_n2a(af, addr, buf, buflen) | ||
77 | #endif | ||
80 | 78 | ||
81 | void invarg(const char *, const char *) NORETURN; | 79 | void invarg(const char *, const char *) NORETURN; |
82 | void duparg(const char *, const char *) NORETURN; | 80 | void duparg(const char *, const char *) NORETURN; |
diff --git a/networking/tc.c b/networking/tc.c index 6e31074f4..03f57f637 100644 --- a/networking/tc.c +++ b/networking/tc.c | |||
@@ -508,15 +508,13 @@ int tc_main(int argc UNUSED_PARAM, char **argv) | |||
508 | if ((slash = strchr(handle, '/')) != NULL) | 508 | if ((slash = strchr(handle, '/')) != NULL) |
509 | *slash = '\0'; | 509 | *slash = '\0'; |
510 | */ | 510 | */ |
511 | if (get_u32(&msg.tcm_handle, *argv, 0)) | 511 | msg.tcm_handle = get_u32(*argv, "handle"); |
512 | invarg(*argv, "handle"); | 512 | /* if (slash) {if (get_u32(__u32 &mask, slash+1, NULL)) inv mask; addattr32(n, MAX_MSG, TCA_FW_MASK, mask); */ |
513 | /* if (slash) {if (get_u32(__u32 &mask, slash+1,0)) inv mask;addattr32(n, MAX_MSG, TCA_FW_MASK, mask); */ | ||
514 | } else if (arg == ARG_classid && obj == OBJ_class && cmd == CMD_change){ | 513 | } else if (arg == ARG_classid && obj == OBJ_class && cmd == CMD_change){ |
515 | } else if (arg == ARG_pref || arg == ARG_prio) { /* filter::list */ | 514 | } else if (arg == ARG_pref || arg == ARG_prio) { /* filter::list */ |
516 | if (filter_prio) | 515 | if (filter_prio) |
517 | duparg(*argv, "priority"); | 516 | duparg(*argv, "priority"); |
518 | if (get_u32(&filter_prio, *argv, 0)) | 517 | filter_prio = get_u32(*argv, "priority"); |
519 | invarg(*argv, "priority"); | ||
520 | } else if (arg == ARG_proto) { /* filter::list */ | 518 | } else if (arg == ARG_proto) { /* filter::list */ |
521 | __u16 tmp; | 519 | __u16 tmp; |
522 | if (filter_proto) | 520 | if (filter_proto) |