aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/libiproute/ipaddress.c22
-rw-r--r--networking/libiproute/ipneigh.c5
-rw-r--r--networking/libiproute/iproute.c36
-rw-r--r--networking/libiproute/iprule.c19
-rw-r--r--networking/libiproute/iptunnel.c28
-rw-r--r--networking/libiproute/utils.c14
-rw-r--r--networking/libiproute/utils.h8
7 files changed, 57 insertions, 75 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index c0f27c70d..5c975d8c5 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -214,8 +214,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
214{ 214{
215 struct ifaddrmsg *ifa = NLMSG_DATA(n); 215 struct ifaddrmsg *ifa = NLMSG_DATA(n);
216 int len = n->nlmsg_len; 216 int len = n->nlmsg_len;
217 struct rtattr * rta_tb[IFA_MAX+1]; 217 struct rtattr *rta_tb[IFA_MAX+1];
218 char abuf[256];
219 218
220 if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR) 219 if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
221 return 0; 220 return 0;
@@ -291,9 +290,9 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
291 printf(" family %d ", ifa->ifa_family); 290 printf(" family %d ", ifa->ifa_family);
292 291
293 if (rta_tb[IFA_LOCAL]) { 292 if (rta_tb[IFA_LOCAL]) {
294 fputs(rt_addr_n2a(ifa->ifa_family, 293 fputs(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])),
295 RTA_DATA(rta_tb[IFA_LOCAL]), 294 stdout
296 abuf, sizeof(abuf)), stdout); 295 );
297 296
298 if (rta_tb[IFA_ADDRESS] == NULL 297 if (rta_tb[IFA_ADDRESS] == NULL
299 || memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0 298 || memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0
@@ -301,25 +300,22 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
301 printf("/%d ", ifa->ifa_prefixlen); 300 printf("/%d ", ifa->ifa_prefixlen);
302 } else { 301 } else {
303 printf(" peer %s/%d ", 302 printf(" peer %s/%d ",
304 rt_addr_n2a(ifa->ifa_family, 303 rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_ADDRESS])),
305 RTA_DATA(rta_tb[IFA_ADDRESS]), 304 ifa->ifa_prefixlen
306 abuf, sizeof(abuf)), 305 );
307 ifa->ifa_prefixlen);
308 } 306 }
309 } 307 }
310 308
311 if (rta_tb[IFA_BROADCAST]) { 309 if (rta_tb[IFA_BROADCAST]) {
312 printf("brd %s ", 310 printf("brd %s ",
313 rt_addr_n2a(ifa->ifa_family, 311 rt_addr_n2a(ifa->ifa_family,
314 RTA_DATA(rta_tb[IFA_BROADCAST]), 312 RTA_DATA(rta_tb[IFA_BROADCAST]))
315 abuf, sizeof(abuf))
316 ); 313 );
317 } 314 }
318 if (rta_tb[IFA_ANYCAST]) { 315 if (rta_tb[IFA_ANYCAST]) {
319 printf("any %s ", 316 printf("any %s ",
320 rt_addr_n2a(ifa->ifa_family, 317 rt_addr_n2a(ifa->ifa_family,
321 RTA_DATA(rta_tb[IFA_ANYCAST]), 318 RTA_DATA(rta_tb[IFA_ANYCAST]))
322 abuf, sizeof(abuf))
323 ); 319 );
324 } 320 }
325 printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope)); 321 printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope));
diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c
index 6588c12f1..179505c2d 100644
--- a/networking/libiproute/ipneigh.c
+++ b/networking/libiproute/ipneigh.c
@@ -91,7 +91,6 @@ static int FAST_FUNC print_neigh(const struct sockaddr_nl *who UNUSED_PARAM,
91 struct ndmsg *r = NLMSG_DATA(n); 91 struct ndmsg *r = NLMSG_DATA(n);
92 int len = n->nlmsg_len; 92 int len = n->nlmsg_len;
93 struct rtattr *tb[NDA_MAX+1]; 93 struct rtattr *tb[NDA_MAX+1];
94 char abuf[256];
95 94
96 if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) { 95 if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) {
97 bb_error_msg_and_die("not RTM_NEWNEIGH: %08x %08x %08x", 96 bb_error_msg_and_die("not RTM_NEWNEIGH: %08x %08x %08x",
@@ -155,8 +154,8 @@ static int FAST_FUNC print_neigh(const struct sockaddr_nl *who UNUSED_PARAM,
155 printf("%s ", 154 printf("%s ",
156 format_host(r->ndm_family, 155 format_host(r->ndm_family,
157 RTA_PAYLOAD(tb[NDA_DST]), 156 RTA_PAYLOAD(tb[NDA_DST]),
158 RTA_DATA(tb[NDA_DST]), 157 RTA_DATA(tb[NDA_DST]))
159 abuf, sizeof(abuf))); 158 );
160 } 159 }
161 if (!G_filter.index && r->ndm_ifindex) 160 if (!G_filter.index && r->ndm_ifindex)
162 printf("dev %s ", ll_index_to_name(r->ndm_ifindex)); 161 printf("dev %s ", ll_index_to_name(r->ndm_ifindex));
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 0d2914405..d232ee6fd 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -61,7 +61,6 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
61 struct rtmsg *r = NLMSG_DATA(n); 61 struct rtmsg *r = NLMSG_DATA(n);
62 int len = n->nlmsg_len; 62 int len = n->nlmsg_len;
63 struct rtattr *tb[RTA_MAX+1]; 63 struct rtattr *tb[RTA_MAX+1];
64 char abuf[256];
65 inet_prefix dst; 64 inet_prefix dst;
66 inet_prefix src; 65 inet_prefix src;
67 int host_len = -1; 66 int host_len = -1;
@@ -218,17 +217,15 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
218 217
219 if (tb[RTA_DST]) { 218 if (tb[RTA_DST]) {
220 if (r->rtm_dst_len != host_len) { 219 if (r->rtm_dst_len != host_len) {
221 printf("%s/%u ", rt_addr_n2a(r->rtm_family, 220 printf("%s/%u ",
222 RTA_DATA(tb[RTA_DST]), 221 rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_DST])),
223 abuf, sizeof(abuf)), 222 r->rtm_dst_len
224 r->rtm_dst_len 223 );
225 );
226 } else { 224 } else {
227 printf("%s ", format_host(r->rtm_family, 225 printf("%s ", format_host(r->rtm_family,
228 RTA_PAYLOAD(tb[RTA_DST]), 226 RTA_PAYLOAD(tb[RTA_DST]),
229 RTA_DATA(tb[RTA_DST]), 227 RTA_DATA(tb[RTA_DST]))
230 abuf, sizeof(abuf)) 228 );
231 );
232 } 229 }
233 } else if (r->rtm_dst_len) { 230 } else if (r->rtm_dst_len) {
234 printf("0/%d ", r->rtm_dst_len); 231 printf("0/%d ", r->rtm_dst_len);
@@ -237,17 +234,15 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
237 } 234 }
238 if (tb[RTA_SRC]) { 235 if (tb[RTA_SRC]) {
239 if (r->rtm_src_len != host_len) { 236 if (r->rtm_src_len != host_len) {
240 printf("from %s/%u ", rt_addr_n2a(r->rtm_family, 237 printf("from %s/%u ",
241 RTA_DATA(tb[RTA_SRC]), 238 rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])),
242 abuf, sizeof(abuf)), 239 r->rtm_src_len
243 r->rtm_src_len 240 );
244 );
245 } else { 241 } else {
246 printf("from %s ", format_host(r->rtm_family, 242 printf("from %s ", format_host(r->rtm_family,
247 RTA_PAYLOAD(tb[RTA_SRC]), 243 RTA_PAYLOAD(tb[RTA_SRC]),
248 RTA_DATA(tb[RTA_SRC]), 244 RTA_DATA(tb[RTA_SRC]))
249 abuf, sizeof(abuf)) 245 );
250 );
251 } 246 }
252 } else if (r->rtm_src_len) { 247 } else if (r->rtm_src_len) {
253 printf("from 0/%u ", r->rtm_src_len); 248 printf("from 0/%u ", r->rtm_src_len);
@@ -255,8 +250,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
255 if (tb[RTA_GATEWAY] && G_filter.rvia.bitlen != host_len) { 250 if (tb[RTA_GATEWAY] && G_filter.rvia.bitlen != host_len) {
256 printf("via %s ", format_host(r->rtm_family, 251 printf("via %s ", format_host(r->rtm_family,
257 RTA_PAYLOAD(tb[RTA_GATEWAY]), 252 RTA_PAYLOAD(tb[RTA_GATEWAY]),
258 RTA_DATA(tb[RTA_GATEWAY]), 253 RTA_DATA(tb[RTA_GATEWAY]))
259 abuf, sizeof(abuf))); 254 );
260 } 255 }
261 if (tb[RTA_OIF]) { 256 if (tb[RTA_OIF]) {
262 printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); 257 printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
@@ -269,8 +264,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
269 and symbolic name will not be useful. 264 and symbolic name will not be useful.
270 */ 265 */
271 printf(" src %s ", rt_addr_n2a(r->rtm_family, 266 printf(" src %s ", rt_addr_n2a(r->rtm_family,
272 RTA_DATA(tb[RTA_PREFSRC]), 267 RTA_DATA(tb[RTA_PREFSRC])));
273 abuf, sizeof(abuf)));
274 } 268 }
275 if (tb[RTA_PRIORITY]) { 269 if (tb[RTA_PRIORITY]) {
276 printf(" metric %d ", *(uint32_t*)RTA_DATA(tb[RTA_PRIORITY])); 270 printf(" metric %d ", *(uint32_t*)RTA_DATA(tb[RTA_PRIORITY]));
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index c3b210982..dba64346f 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -44,7 +44,6 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
44 int len = n->nlmsg_len; 44 int len = n->nlmsg_len;
45 int host_len = -1; 45 int host_len = -1;
46 struct rtattr * tb[RTA_MAX+1]; 46 struct rtattr * tb[RTA_MAX+1];
47 char abuf[256];
48 47
49 if (n->nlmsg_type != RTM_NEWRULE) 48 if (n->nlmsg_type != RTM_NEWRULE)
50 return 0; 49 return 0;
@@ -71,16 +70,14 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
71 printf("from "); 70 printf("from ");
72 if (tb[RTA_SRC]) { 71 if (tb[RTA_SRC]) {
73 if (r->rtm_src_len != host_len) { 72 if (r->rtm_src_len != host_len) {
74 printf("%s/%u", rt_addr_n2a(r->rtm_family, 73 printf("%s/%u",
75 RTA_DATA(tb[RTA_SRC]), 74 rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])),
76 abuf, sizeof(abuf)),
77 r->rtm_src_len 75 r->rtm_src_len
78 ); 76 );
79 } else { 77 } else {
80 fputs(format_host(r->rtm_family, 78 fputs(format_host(r->rtm_family,
81 RTA_PAYLOAD(tb[RTA_SRC]), 79 RTA_PAYLOAD(tb[RTA_SRC]),
82 RTA_DATA(tb[RTA_SRC]), 80 RTA_DATA(tb[RTA_SRC])),
83 abuf, sizeof(abuf)),
84 stdout 81 stdout
85 ); 82 );
86 } 83 }
@@ -94,15 +91,13 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
94 if (tb[RTA_DST]) { 91 if (tb[RTA_DST]) {
95 if (r->rtm_dst_len != host_len) { 92 if (r->rtm_dst_len != host_len) {
96 printf("to %s/%u ", rt_addr_n2a(r->rtm_family, 93 printf("to %s/%u ", rt_addr_n2a(r->rtm_family,
97 RTA_DATA(tb[RTA_DST]), 94 RTA_DATA(tb[RTA_DST])),
98 abuf, sizeof(abuf)),
99 r->rtm_dst_len 95 r->rtm_dst_len
100 ); 96 );
101 } else { 97 } else {
102 printf("to %s ", format_host(r->rtm_family, 98 printf("to %s ", format_host(r->rtm_family,
103 RTA_PAYLOAD(tb[RTA_DST]), 99 RTA_PAYLOAD(tb[RTA_DST]),
104 RTA_DATA(tb[RTA_DST]), 100 RTA_DATA(tb[RTA_DST])));
105 abuf, sizeof(abuf)));
106 } 101 }
107 } else if (r->rtm_dst_len) { 102 } else if (r->rtm_dst_len) {
108 printf("to 0/%d ", r->rtm_dst_len); 103 printf("to 0/%d ", r->rtm_dst_len);
@@ -139,8 +134,8 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
139 printf("map-to %s ", 134 printf("map-to %s ",
140 format_host(r->rtm_family, 135 format_host(r->rtm_family,
141 RTA_PAYLOAD(tb[RTA_GATEWAY]), 136 RTA_PAYLOAD(tb[RTA_GATEWAY]),
142 RTA_DATA(tb[RTA_GATEWAY]), 137 RTA_DATA(tb[RTA_GATEWAY]))
143 abuf, sizeof(abuf))); 138 );
144 } else 139 } else
145 printf("masquerade"); 140 printf("masquerade");
146 } else if (r->rtm_type != RTN_UNICAST) 141 } else if (r->rtm_type != RTN_UNICAST)
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c
index b88c3a401..eb136e435 100644
--- a/networking/libiproute/iptunnel.c
+++ b/networking/libiproute/iptunnel.c
@@ -404,22 +404,18 @@ static int do_del(char **argv)
404 404
405static void print_tunnel(struct ip_tunnel_parm *p) 405static void print_tunnel(struct ip_tunnel_parm *p)
406{ 406{
407 char s1[256]; 407 char s3[INET_ADDRSTRLEN];
408 char s2[256]; 408 char s4[INET_ADDRSTRLEN];
409 char s3[64];
410 char s4[64];
411
412 format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1));
413 format_host(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2));
414 inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
415 inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
416 409
417 printf("%s: %s/ip remote %s local %s ", 410 printf("%s: %s/ip remote %s local %s ",
418 p->name, 411 p->name,
419 p->iph.protocol == IPPROTO_IPIP ? "ip" : 412 p->iph.protocol == IPPROTO_IPIP ? "ip" :
420 (p->iph.protocol == IPPROTO_GRE ? "gre" : 413 p->iph.protocol == IPPROTO_GRE ? "gre" :
421 (p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : "unknown")), 414 p->iph.protocol == IPPROTO_IPV6 ? "ipv6" :
422 p->iph.daddr ? s1 : "any", p->iph.saddr ? s2 : "any"); 415 "unknown",
416 p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr) : "any",
417 p->iph.saddr ? format_host(AF_INET, 4, &p->iph.saddr) : "any"
418 );
423 if (p->link) { 419 if (p->link) {
424 char *n = do_ioctl_get_ifname(p->link); 420 char *n = do_ioctl_get_ifname(p->link);
425 if (n) { 421 if (n) {
@@ -442,9 +438,11 @@ static void print_tunnel(struct ip_tunnel_parm *p)
442 if (!(p->iph.frag_off & htons(IP_DF))) 438 if (!(p->iph.frag_off & htons(IP_DF)))
443 printf(" nopmtudisc"); 439 printf(" nopmtudisc");
444 440
441 inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
442 inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
445 if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key) 443 if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
446 printf(" key %s", s3); 444 printf(" key %s", s3);
447 else if ((p->i_flags | p->o_flags) & GRE_KEY) { 445 else {
448 if (p->i_flags & GRE_KEY) 446 if (p->i_flags & GRE_KEY)
449 printf(" ikey %s ", s3); 447 printf(" ikey %s ", s3);
450 if (p->o_flags & GRE_KEY) 448 if (p->o_flags & GRE_KEY)
diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c
index 7f7cb4203..42025bc66 100644
--- a/networking/libiproute/utils.c
+++ b/networking/libiproute/utils.c
@@ -276,20 +276,21 @@ int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits)
276 return 0; 276 return 0;
277} 277}
278 278
279const char *rt_addr_n2a(int af, 279const char *rt_addr_n2a(int af, void *addr)
280 void *addr, char *buf, int buflen)
281{ 280{
282 switch (af) { 281 switch (af) {
283 case AF_INET: 282 case AF_INET:
284 case AF_INET6: 283 case AF_INET6:
285 return inet_ntop(af, addr, buf, buflen); 284 return inet_ntop(af, addr,
285 auto_string(xzalloc(INET6_ADDRSTRLEN)), INET6_ADDRSTRLEN
286 );
286 default: 287 default:
287 return "???"; 288 return "???";
288 } 289 }
289} 290}
290 291
291#ifdef RESOLVE_HOSTNAMES 292#ifdef RESOLVE_HOSTNAMES
292const char *format_host(int af, int len, void *addr, char *buf, int buflen) 293const char *format_host(int af, int len, void *addr)
293{ 294{
294 if (resolve_hosts) { 295 if (resolve_hosts) {
295 struct hostent *h_ent; 296 struct hostent *h_ent;
@@ -308,11 +309,10 @@ const char *format_host(int af, int len, void *addr, char *buf, int buflen)
308 if (len > 0) { 309 if (len > 0) {
309 h_ent = gethostbyaddr(addr, len, af); 310 h_ent = gethostbyaddr(addr, len, af);
310 if (h_ent != NULL) { 311 if (h_ent != NULL) {
311 safe_strncpy(buf, h_ent->h_name, buflen); 312 return auto_string(xstrdup(h_ent->h_name));
312 return buf;
313 } 313 }
314 } 314 }
315 } 315 }
316 return rt_addr_n2a(af, addr, buf, buflen); 316 return rt_addr_n2a(af, addr);
317} 317}
318#endif 318#endif
diff --git a/networking/libiproute/utils.h b/networking/libiproute/utils.h
index 9bbed6481..408d5f65f 100644
--- a/networking/libiproute/utils.h
+++ b/networking/libiproute/utils.h
@@ -66,12 +66,12 @@ extern unsigned get_unsigned(char *arg, const char *errmsg);
66extern uint32_t get_u32(char *arg, const char *errmsg); 66extern uint32_t get_u32(char *arg, const char *errmsg);
67extern uint16_t get_u16(char *arg, const char *errmsg); 67extern uint16_t get_u16(char *arg, const char *errmsg);
68 68
69extern const char *rt_addr_n2a(int af, void *addr, char *buf, int buflen); 69extern const char *rt_addr_n2a(int af, void *addr);
70#ifdef RESOLVE_HOSTNAMES 70#ifdef RESOLVE_HOSTNAMES
71extern const char *format_host(int af, int len, void *addr, char *buf, int buflen); 71extern const char *format_host(int af, int len, void *addr);
72#else 72#else
73#define format_host(af, len, addr, buf, buflen) \ 73#define format_host(af, len, addr) \
74 rt_addr_n2a(af, addr, buf, buflen) 74 rt_addr_n2a(af, addr)
75#endif 75#endif
76 76
77void invarg_1_to_2(const char *, const char *) NORETURN; 77void invarg_1_to_2(const char *, const char *) NORETURN;