]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/iprule.c
libnetlink: add size argument to rtnl_talk
[mirror_iproute2.git] / ip / iprule.c
index d934f67da2e6c255c4a47f282dfc5566ff53ad80..714278a2be58af0b2c6a80373110e69f9824f486 100644 (file)
@@ -66,14 +66,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 
        parse_rtattr(tb, FRA_MAX, RTM_RTA(r), len);
 
-       if (r->rtm_family == AF_INET)
-               host_len = 32;
-       else if (r->rtm_family == AF_INET6)
-               host_len = 128;
-       else if (r->rtm_family == AF_DECnet)
-               host_len = 16;
-       else if (r->rtm_family == AF_IPX)
-               host_len = 80;
+       host_len = af_bit_len(r->rtm_family);
 
        if (n->nlmsg_type == RTM_DELRULE)
                fprintf(fp, "Deleted ");
@@ -89,9 +82,9 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if (tb[FRA_SRC]) {
                if (r->rtm_src_len != host_len) {
                        fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
-                                                        RTA_PAYLOAD(tb[FRA_SRC]),
-                                                        RTA_DATA(tb[FRA_SRC]),
-                                                        abuf, sizeof(abuf)),
+                                                      RTA_PAYLOAD(tb[FRA_SRC]),
+                                                      RTA_DATA(tb[FRA_SRC]),
+                                                      abuf, sizeof(abuf)),
                                r->rtm_src_len
                                );
                } else {
@@ -110,9 +103,9 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if (tb[FRA_DST]) {
                if (r->rtm_dst_len != host_len) {
                        fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
-                                                        RTA_PAYLOAD(tb[FRA_DST]),
-                                                        RTA_DATA(tb[FRA_DST]),
-                                                        abuf, sizeof(abuf)),
+                                                      RTA_PAYLOAD(tb[FRA_DST]),
+                                                      RTA_DATA(tb[FRA_DST]),
+                                                      abuf, sizeof(abuf)),
                                r->rtm_dst_len
                                );
                } else {
@@ -130,7 +123,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
        }
 
-       if (tb[FRA_FWMARK] || tb[FRA_FWMASK]) {
+       if (tb[FRA_FWMARK] || tb[FRA_FWMASK]) {
                __u32 mark = 0, mask = 0;
 
                if (tb[FRA_FWMARK])
@@ -243,9 +236,9 @@ static int iprule_modify(int cmd, int argc, char **argv)
 {
        int table_ok = 0;
        struct {
-               struct nlmsghdr         n;
-               struct rtmsg            r;
-               char                    buf[1024];
+               struct nlmsghdr n;
+               struct rtmsg            r;
+               char                    buf[1024];
        } req;
 
        memset(&req, 0, sizeof(req));
@@ -387,8 +380,8 @@ static int iprule_modify(int cmd, int argc, char **argv)
        if (!table_ok && cmd == RTM_NEWRULE)
                req.r.rtm_table = RT_TABLE_MAIN;
 
-       if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
-               return 2;
+       if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
+               return -2;
 
        return 0;
 }
@@ -414,7 +407,7 @@ static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *a
                if (rtnl_open(&rth2, 0) < 0)
                        return -1;
 
-               if (rtnl_talk(&rth2, n, 0, 0, NULL) < 0)
+               if (rtnl_talk(&rth2, n, NULL, 0) < 0)
                        return -2;
 
                rtnl_close(&rth2);