ip: code shrink
[oweals/busybox.git] / networking / libiproute / iproute.c
index 14fc16c4d930d54fc539c65506381923d7d9aa38..f8a67d9eedc43f3ede19c506773ce20933b39f61 100644 (file)
@@ -82,7 +82,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
 {
        struct rtmsg *r = NLMSG_DATA(n);
        int len = n->nlmsg_len;
-       struct rtattr * tb[RTA_MAX+1];
+       struct rtattr *tb[RTA_MAX+1];
        char abuf[256];
        inet_prefix dst;
        inet_prefix src;
@@ -159,8 +159,21 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
        }
 
        memset(tb, 0, sizeof(tb));
+       memset(&src, 0, sizeof(src));
+       memset(&dst, 0, sizeof(dst));
        parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
 
+       if (tb[RTA_SRC]) {
+               src.bitlen = r->rtm_src_len;
+               src.bytelen = (r->rtm_family == AF_INET6 ? 16 : 4);
+               memcpy(src.data, RTA_DATA(tb[RTA_SRC]), src.bytelen);
+       }
+       if (tb[RTA_DST]) {
+               dst.bitlen = r->rtm_dst_len;
+               dst.bytelen = (r->rtm_family == AF_INET6 ? 16 : 4);
+               memcpy(dst.data, RTA_DATA(tb[RTA_DST]), dst.bytelen);
+       }
+
        if (G_filter.rdst.family
         && inet_addr_match(&dst, &G_filter.rdst, G_filter.rdst.bitlen)
        ) {
@@ -190,6 +203,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
        }
 
        if (G_filter.flushb) {
+               struct nlmsghdr *fn;
+
                /* We are creating route flush commands */
 
                if (r->rtm_family == AF_INET6
@@ -201,12 +216,11 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
                        return 0;
                }
 
-               struct nlmsghdr *fn;
                if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) {
                        if (flush_update())
                                bb_error_msg_and_die("flush");
                }
-               fn = (struct nlmsghdr*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp));
+               fn = (void*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp));
                memcpy(fn, n, n->nlmsg_len);
                fn->nlmsg_type = RTM_DELROUTE;
                fn->nlmsg_flags = NLM_F_REQUEST;
@@ -425,7 +439,8 @@ IF_FEATURE_IP_RULE(ARG_table,)
                                NEXT_ARG();
                        }
                        if ((**argv < '0' || **argv > '9')
-                        && rtnl_rtntype_a2n(&type, *argv) == 0) {
+                        && rtnl_rtntype_a2n(&type, *argv) == 0
+                       ) {
                                NEXT_ARG();
                                req.r.rtm_type = type;
                                ok |= type_ok;