]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/m_nat.c
Merge branch 'iproute2-master' into iproute2-next
[mirror_iproute2.git] / tc / m_nat.c
index 6e7fd0556034429bedb471df19eedbc85e1aa5c8..653792da91c093768c37ce6b7d93941446405ad6 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
-#include <dlfcn.h>
 #include "utils.h"
 #include "tc_util.h"
 #include <linux/tc_act/tc_nat.h>
@@ -42,7 +40,7 @@ usage(void)
 }
 
 static int
-parse_nat_args(int *argc_p, char ***argv_p,struct tc_nat *sel)
+parse_nat_args(int *argc_p, char ***argv_p, struct tc_nat *sel)
 {
        int argc = *argc_p;
        char **argv = *argv_p;
@@ -85,20 +83,18 @@ bad_val:
 static int
 parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
-       struct tc_nat sel;
+       struct tc_nat sel = {};
 
        int argc = *argc_p;
        char **argv = *argv_p;
        int ok = 0;
        struct rtattr *tail;
 
-       memset(&sel, 0, sizeof(sel));
-
        while (argc > 0) {
                if (matches(*argv, "nat") == 0) {
                        NEXT_ARG();
                        if (parse_nat_args(&argc, &argv, &sel)) {
-                               fprintf(stderr, "Illegal nat construct (%s) \n",
+                               fprintf(stderr, "Illegal nat construct (%s)\n",
                                        *argv);
                                explain();
                                return -1;
@@ -118,36 +114,13 @@ parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct
                return -1;
        }
 
-       if (argc) {
-               if (matches(*argv, "reclassify") == 0) {
-                       sel.action = TC_ACT_RECLASSIFY;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "pipe") == 0) {
-                       sel.action = TC_ACT_PIPE;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "drop") == 0 ||
-                       matches(*argv, "shot") == 0) {
-                       sel.action = TC_ACT_SHOT;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "continue") == 0) {
-                       sel.action = TC_ACT_UNSPEC;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "pass") == 0) {
-                       sel.action = TC_ACT_OK;
-                       argc--;
-                       argv++;
-               }
-       }
+       parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_OK);
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
                        NEXT_ARG();
                        if (get_u32(&sel.index, *argv, 10)) {
-                               fprintf(stderr, "Pedit: Illegal \"index\"\n");
+                               fprintf(stderr, "Nat: Illegal \"index\"\n");
                                return -1;
                        }
                        argc--;
@@ -155,10 +128,9 @@ parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct
                }
        }
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, MAX_MSG, tca_id, NULL, 0);
+       tail = addattr_nest(n, MAX_MSG, tca_id);
        addattr_l(n, MAX_MSG, TCA_NAT_PARMS, &sel, sizeof(sel));
-       tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
+       addattr_nest_end(n, tail);
 
        *argc_p = argc;
        *argv_p = argv;
@@ -166,13 +138,13 @@ parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct
 }
 
 static int
-print_nat(struct action_util *au,FILE * f, struct rtattr *arg)
+print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
 {
        struct tc_nat *sel;
        struct rtattr *tb[TCA_NAT_MAX + 1];
        char buf1[256];
        char buf2[256];
-       SPRINT_BUF(buf3);
+
        int len;
 
        if (arg == NULL)
@@ -189,20 +161,26 @@ print_nat(struct action_util *au,FILE * f, struct rtattr *arg)
        len = ffs(sel->mask);
        len = len ? 33 - len : 0;
 
-       fprintf(f, " nat %s %s/%d %s %s", sel->flags & TCA_NAT_FLAG_EGRESS ?
-                                         "egress" : "ingress",
-               format_host(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
+       fprintf(f, " nat %s %s/%d %s", sel->flags & TCA_NAT_FLAG_EGRESS ?
+                                      "egress" : "ingress",
+               format_host_r(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
                len,
-               format_host(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)),
-               action_n2a(sel->action, buf3, sizeof (buf3)));
+               format_host_r(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)));
+       print_action_control(f, " ", sel->action, "");
+
+       fprintf(f, "\n\t index %u ref %d bind %d",
+               sel->index, sel->refcnt, sel->bindcnt);
 
        if (show_stats) {
                if (tb[TCA_NAT_TM]) {
                        struct tcf_t *tm = RTA_DATA(tb[TCA_NAT_TM]);
-                       print_tm(f,tm);
+
+                       print_tm(f, tm);
                }
        }
 
+       fprintf(f, "\n");
+
        return 0;
 }