]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/m_pedit.c
tc: Remove pointless assignments in batch()
[mirror_iproute2.git] / tc / m_pedit.c
index 9b74c965932e0ef545ddcde016f18cb852dcdbc7..2aeb56d9615f1e9ee4029aa5280c7170fe95e730 100644 (file)
@@ -18,7 +18,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -45,7 +44,8 @@ static void explain(void)
                "\t\tCMD:= clear | invert | set <setval>| add <addval> | retain\n"
                "\t<LAYERED>:= ip <ipdata> | ip6 <ip6data>\n"
                " \t\t| udp <udpdata> | tcp <tcpdata> | icmp <icmpdata>\n"
-               "\tCONTROL:= reclassify | pipe | drop | continue | pass\n"
+               "\tCONTROL:= reclassify | pipe | drop | continue | pass |\n"
+               "\t          goto chain <CHAIN_INDEX>\n"
                "\tNOTE: if 'ex' is set, extended functionality will be supported (kernel >= 4.11)\n"
                "For Example usage look at the examples directory\n");
 
@@ -111,7 +111,7 @@ reg:
 noexist:
        p = calloc(1, sizeof(*p));
        if (p) {
-               strncpy(p->id, str, sizeof(p->id) - 1);
+               strlcpy(p->id, str, sizeof(p->id));
                p->parse_peopt = pedit_parse_nopopt;
                goto reg;
        }
@@ -257,6 +257,32 @@ static int pack_mac(struct m_pedit_sel *sel, struct m_pedit_key *tkey,
        return ret;
 }
 
+static int pack_ipv6(struct m_pedit_sel *sel, struct m_pedit_key *tkey,
+                    __u32 *ipv6)
+{
+       int ret = 0;
+       int i;
+
+       if (tkey->off & 0x3) {
+               fprintf(stderr,
+                       "pack_ipv6: IPv6 offsets must begin in 32bit boundaries\n");
+               return -1;
+       }
+
+       for (i = 0; i < 4; i++) {
+               tkey->mask = 0;
+               tkey->val = ntohl(ipv6[i]);
+
+               ret = pack_key32(~0, sel, tkey);
+               if (ret)
+                       return ret;
+
+               tkey->off += 4;
+       }
+
+       return 0;
+}
+
 int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
 {
        int argc = *argc_p;
@@ -281,8 +307,16 @@ int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
                return 0;
        }
 
-       if (type == TIPV6)
-               return -1; /* not implemented yet */
+       if (type == TIPV6) {
+               inet_prefix addr;
+
+               if (get_prefix_1(&addr, *argv, AF_INET6))
+                       return -1;
+
+               memcpy(val, addr.data, addr.bytelen);
+
+               return 0;
+       }
 
        if (type == TMAC) {
 #define MAC_ALEN 6
@@ -364,6 +398,11 @@ int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type, __u32 retain,
                goto done;
        }
 
+       if (type == TIPV6) {
+               res = pack_ipv6(sel, tkey, val);
+               goto done;
+       }
+
        tkey->val = *v;
        tkey->mask = *m;
 
@@ -485,7 +524,7 @@ static int parse_munge(int *argc_p, char ***argv_p, struct m_pedit_sel *sel)
                res = parse_offset(&argc, &argv, sel, &tkey);
                goto done;
        } else {
-               char k[16];
+               char k[FILTER_NAMESZ];
                struct m_pedit_util *p = NULL;
 
                strncpy(k, *argv, sizeof(k) - 1);
@@ -631,8 +670,7 @@ int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
                return -1;
        }
 
-       if (argc && !action_a2n(*argv, &sel.sel.action, false))
-               NEXT_ARG();
+       parse_action_control_dflt(&argc, &argv, &sel.sel.action, false, TC_ACT_OK);
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
@@ -647,8 +685,7 @@ int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
                }
        }
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, MAX_MSG, tca_id, NULL, 0);
+       tail = addattr_nest(n, MAX_MSG, tca_id);
        if (!sel.extended) {
                addattr_l(n, MAX_MSG, TCA_PEDIT_PARMS, &sel,
                          sizeof(sel.sel) +
@@ -661,7 +698,7 @@ int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
                pedit_keys_ex_addattr(&sel, n);
        }
 
-       tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail;
+       addattr_nest_end(n, tail);
 
        *argc_p = argc;
        *argv_p = argv;
@@ -737,8 +774,9 @@ int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
                }
        }
 
-       fprintf(f, " pedit action %s keys %d\n ",
-               action_n2a(sel->action), sel->nkeys);
+       fprintf(f, " pedit ");
+       print_action_control(f, "action ", sel->action, " ");
+       fprintf(f,"keys %d\n ", sel->nkeys);
        fprintf(f, "\t index %u ref %d bind %d", sel->index, sel->refcnt,
                sel->bindcnt);