]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blobdiff - ip/ipneigh.c
Convert to use rta_getattr_ functions
[lisovros/iproute2_canprio.git] / ip / ipneigh.c
index 9e12befc3ba43201b01b9239a83889a5ed734649..93cfba257211e0b497fadc8dfc6cbe30e09cbf67 100644 (file)
@@ -8,10 +8,6 @@
  *
  * Authors:    Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  *
- *
- * Changes:
- *
- * Rani Assaf <rani@magic.metawire.com> 980929:        resolve addresses
  */
 
 #include <stdio.h>
@@ -21,7 +17,6 @@
 #include <fcntl.h>
 #include <string.h>
 #include <sys/time.h>
-#include <net/if.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
@@ -88,8 +83,8 @@ int nud_state_a2n(unsigned *state, char *arg)
 
 static int flush_update(void)
 {
-       if (rtnl_send(&rth, filter.flushb, filter.flushp) < 0) {
-               perror("Failed to send flush request\n");
+       if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) {
+               perror("Failed to send flush request");
                return -1;
        }
        filter.flushp = 0;
@@ -165,7 +160,7 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
        addattr_l(&req.n, sizeof(req), NDA_DST, &dst.data, dst.bytelen);
 
        if (lla && strcmp(lla, "null")) {
-               char llabuf[16];
+               char llabuf[20];
                int l;
 
                l = ll_addr_a2n(llabuf, sizeof(llabuf), lla);
@@ -179,7 +174,7 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
                return -1;
        }
 
-       if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
+       if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
                exit(2);
 
        return 0;
@@ -197,7 +192,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) {
                fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n",
                        n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
-               
+
                return 0;
        }
        len -= NLMSG_LENGTH(sizeof(*r));
@@ -214,6 +209,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if (filter.index && filter.index != r->ndm_ifindex)
                return 0;
        if (!(filter.state&r->ndm_state) &&
+           !(r->ndm_flags & NTF_PROXY) &&
            (r->ndm_state || !(filter.state&0x100)) &&
              (r->ndm_family != AF_DECnet))
                return 0;
@@ -254,7 +250,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        }
 
        if (tb[NDA_DST]) {
-               fprintf(fp, "%s ", 
+               fprintf(fp, "%s ",
                        format_host(r->ndm_family,
                                    RTA_PAYLOAD(tb[NDA_DST]),
                                    RTA_DATA(tb[NDA_DST]),
@@ -272,23 +268,23 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if (r->ndm_flags & NTF_ROUTER) {
                fprintf(fp, " router");
        }
+       if (r->ndm_flags & NTF_PROXY) {
+               fprintf(fp, " proxy");
+       }
        if (tb[NDA_CACHEINFO] && show_stats) {
-               static int hz;
                struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);
-               if (!hz)
-                       hz = get_hz();
+               int hz = get_user_hz();
+
                if (ci->ndm_refcnt)
                        printf(" ref %d", ci->ndm_refcnt);
                fprintf(fp, " used %d/%d/%d", ci->ndm_used/hz,
                       ci->ndm_confirmed/hz, ci->ndm_updated/hz);
        }
 
-#ifdef NDA_PROBES
        if (tb[NDA_PROBES] && show_stats) {
-               __u32 p = *(__u32 *) RTA_DATA(tb[NDA_PROBES]);
+               __u32 p = rta_getattr_u32(tb[NDA_PROBES]);
                fprintf(fp, " probes %u", p);
        }
-#endif
 
        if (r->ndm_state) {
                int nud = r->ndm_state;
@@ -322,6 +318,7 @@ int do_show_or_flush(int argc, char **argv, int flush)
 {
        char *filter_dev = NULL;
        int state_given = 0;
+       struct ndmsg ndm = { 0 };
 
        ipneigh_reset_filter();
 
@@ -362,7 +359,9 @@ int do_show_or_flush(int argc, char **argv, int flush)
                        if (state == 0)
                                state = 0x100;
                        filter.state |= state;
-               } else {
+               } else if (strcmp(*argv, "proxy") == 0)
+                       ndm.ndm_flags = NTF_PROXY;
+               else {
                        if (strcmp(*argv, "to") == 0) {
                                NEXT_ARG();
                        }
@@ -399,15 +398,17 @@ int do_show_or_flush(int argc, char **argv, int flush)
                                exit(1);
                        }
                        filter.flushed = 0;
-                       if (rtnl_dump_filter(&rth, print_neigh, stdout, NULL, NULL) < 0) {
+                       if (rtnl_dump_filter(&rth, print_neigh, stdout) < 0) {
                                fprintf(stderr, "Flush terminated\n");
                                exit(1);
                        }
                        if (filter.flushed == 0) {
-                               if (round == 0) {
-                                       fprintf(stderr, "Nothing to flush.\n");
-                               } else if (show_stats)
-                                       printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":"");
+                               if (show_stats) {
+                                       if (round == 0)
+                                               printf("Nothing to flush.\n");
+                                       else
+                                               printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":"");
+                               }
                                fflush(stdout);
                                return 0;
                        }
@@ -424,12 +425,14 @@ int do_show_or_flush(int argc, char **argv, int flush)
                return 1;
        }
 
-       if (rtnl_wilddump_request(&rth, filter.family, RTM_GETNEIGH) < 0) {
+       ndm.ndm_family = filter.family;
+
+       if (rtnl_dump_request(&rth, RTM_GETNEIGH, &ndm, sizeof(struct ndmsg)) < 0) {
                perror("Cannot send dump request");
                exit(1);
        }
 
-       if (rtnl_dump_filter(&rth, print_neigh, stdout, NULL, NULL) < 0) {
+       if (rtnl_dump_filter(&rth, print_neigh, stdout) < 0) {
                fprintf(stderr, "Dump terminated\n");
                exit(1);
        }