]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/m_pedit.c
tc: m_action: check cookie hex string len
[mirror_iproute2.git] / tc / m_pedit.c
index 5d89ab1d832ab92266026027d7992f777d3148f7..fccfd17ca2709ef169e765f476b1374bd0d631a6 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>
@@ -35,8 +34,8 @@ static int pedit_debug;
 
 static void explain(void)
 {
-       fprintf(stderr, "Usage: ... pedit munge [ex] <MUNGE> [CONTROL]\n");
        fprintf(stderr,
+               "Usage: ... pedit munge [ex] <MUNGE> [CONTROL]\n"
                "Where: MUNGE := <RAW>|<LAYERED>\n"
                "\t<RAW>:= <OFFSETC>[ATC]<CMD>\n \t\tOFFSETC:= offset <offval> <u8|u16|u32>\n"
                "\t\tATC:= at <atval> offmask <maskval> shift <shiftval>\n"
@@ -112,14 +111,14 @@ 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;
        }
        return p;
 }
 
-int pack_key(struct m_pedit_sel *_sel, struct m_pedit_key *tkey)
+static int pack_key(struct m_pedit_sel *_sel, struct m_pedit_key *tkey)
 {
        struct tc_pedit_sel *sel = &_sel->sel;
        struct m_pedit_key_ex *keys_ex = _sel->keys_ex;
@@ -156,8 +155,8 @@ int pack_key(struct m_pedit_sel *_sel, struct m_pedit_key *tkey)
        return 0;
 }
 
-int pack_key32(__u32 retain, struct m_pedit_sel *sel,
-              struct m_pedit_key *tkey)
+static int pack_key32(__u32 retain, struct m_pedit_sel *sel,
+                     struct m_pedit_key *tkey)
 {
        if (tkey->off > (tkey->off & ~3)) {
                fprintf(stderr,
@@ -170,8 +169,8 @@ int pack_key32(__u32 retain, struct m_pedit_sel *sel,
        return pack_key(sel, tkey);
 }
 
-int pack_key16(__u32 retain, struct m_pedit_sel *sel,
-              struct m_pedit_key *tkey)
+static int pack_key16(__u32 retain, struct m_pedit_sel *sel,
+                     struct m_pedit_key *tkey)
 {
        int ind, stride;
        __u32 m[4] = { 0x0000FFFF, 0xFF0000FF, 0xFFFF0000 };
@@ -198,10 +197,10 @@ int pack_key16(__u32 retain, struct m_pedit_sel *sel,
                printf("pack_key16: Final val %08x mask %08x\n",
                       tkey->val, tkey->mask);
        return pack_key(sel, tkey);
-
 }
 
-int pack_key8(__u32 retain, struct m_pedit_sel *sel, struct m_pedit_key *tkey)
+static int pack_key8(__u32 retain, struct m_pedit_sel *sel,
+                    struct m_pedit_key *tkey)
 {
        int ind, stride;
        __u32 m[4] = { 0x00FFFFFF, 0xFF00FFFF, 0xFFFF00FF, 0xFFFFFF00 };
@@ -284,7 +283,7 @@ static int pack_ipv6(struct m_pedit_sel *sel, struct m_pedit_key *tkey,
        return 0;
 }
 
-int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
+static int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
 {
        int argc = *argc_p;
        char **argv = *argv_p;
@@ -434,8 +433,8 @@ done:
 
 }
 
-int parse_offset(int *argc_p, char ***argv_p, struct m_pedit_sel *sel,
-                struct m_pedit_key *tkey)
+static int parse_offset(int *argc_p, char ***argv_p, struct m_pedit_sel *sel,
+                       struct m_pedit_key *tkey)
 {
        int off;
        __u32 len, retain;
@@ -525,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);
@@ -613,8 +612,8 @@ static int pedit_keys_ex_addattr(struct m_pedit_sel *sel, struct nlmsghdr *n)
        return 0;
 }
 
-int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
-               struct nlmsghdr *n)
+static int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p,
+                      int tca_id, struct nlmsghdr *n)
 {
        struct m_pedit_sel sel = {};
 
@@ -686,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) +
@@ -700,14 +698,14 @@ 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;
        return 0;
 }
 
-const char *pedit_htype_str[] = {
+static const char * const pedit_htype_str[] = {
        [TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK] = "",
        [TCA_PEDIT_KEY_EX_HDR_TYPE_ETH] = "eth",
        [TCA_PEDIT_KEY_EX_HDR_TYPE_IP4] = "ipv4",
@@ -732,7 +730,7 @@ static void print_pedit_location(FILE *f,
        fprintf(f, "%c%d", (int)off  >= 0 ? '+' : '-', abs((int)off));
 }
 
-int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
+static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
 {
        struct tc_pedit_sel *sel;
        struct rtattr *tb[TCA_PEDIT_MAX + 1];
@@ -744,7 +742,7 @@ int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
        parse_rtattr_nested(tb, TCA_PEDIT_MAX, arg);
 
        if (!tb[TCA_PEDIT_PARMS] && !tb[TCA_PEDIT_PARMS_EX]) {
-               fprintf(f, "[NULL pedit parameters]");
+               fprintf(stderr, "Missing pedit parameters\n");
                return -1;
        }
 
@@ -822,17 +820,12 @@ int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
                        sel->nkeys);
        }
 
-       fprintf(f, "\n ");
+       print_nl();
 
        free(keys_ex);
        return 0;
 }
 
-int pedit_print_xstats(struct action_util *au, FILE *f, struct rtattr *xstats)
-{
-       return 0;
-}
-
 struct action_util pedit_action_util = {
        .id = "pedit",
        .parse_aopt = parse_pedit,