]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/m_xt.c
tc flower: fix parsing vlan_id and vlan_prio
[mirror_iproute2.git] / tc / m_xt.c
index 028bad649c982f1f0c3414507e4a61dfdb2d9ffe..deaf96a26f7517665973ff110a2b7354127437ce 100644 (file)
--- a/tc/m_xt.c
+++ b/tc/m_xt.c
@@ -10,7 +10,6 @@
  * Authors:  J Hadi Salim (hadi@cyberus.ca)
  */
 
-#include <syslog.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -77,6 +76,9 @@ static struct xtables_globals tcipt_globals = {
        .orig_opts = original_opts,
        .opts = original_opts,
        .exit_err = NULL,
+#if XTABLES_VERSION_CODE >= 11
+       .compat_rev = xtables_compatible_revision,
+#endif
 };
 
 /*
@@ -92,7 +94,8 @@ build_st(struct xtables_target *target, struct xt_entry_target *t)
        if (t == NULL) {
                target->t = xtables_calloc(1, size);
                target->t->u.target_size = size;
-               strcpy(target->t->u.user.name, target->name);
+               strncpy(target->t->u.user.name, target->name,
+                       sizeof(target->t->u.user.name) - 1);
                target->t->u.user.revision = target->revision;
 
                if (target->init != NULL)
@@ -123,7 +126,7 @@ static int get_xtables_target_opts(struct xtables_globals *globals,
 {
        struct option *opts;
 
-#if (XTABLES_VERSION_CODE >= 6)
+#if XTABLES_VERSION_CODE >= 6
        opts = xtables_options_xfrm(globals->orig_opts,
                                    globals->opts,
                                    m->x6_options,
@@ -143,12 +146,15 @@ static int parse_ipt(struct action_util *a, int *argc_p,
                     char ***argv_p, int tca_id, struct nlmsghdr *n)
 {
        struct xtables_target *m = NULL;
+#if XTABLES_VERSION_CODE >= 6
+       struct ipt_entry fw = {};
+#endif
        struct rtattr *tail;
 
        int c;
        char **argv = *argv_p;
        int argc;
-       char k[16];
+       char k[FILTER_NAMESZ];
        int size = 0;
        int iok = 0, ok = 0;
        __u32 hook = 0, index = 0;
@@ -201,9 +207,9 @@ static int parse_ipt(struct action_util *a, int *argc_p,
                        break;
 
                default:
-#if (XTABLES_VERSION_CODE >= 6)
+#if XTABLES_VERSION_CODE >= 6
                        if (m != NULL && m->x6_parse != NULL) {
-                               xtables_option_tpcall(c, argv, 0, m, NULL);
+                               xtables_option_tpcall(c, argv, 0, m, &fw);
 #else
                        if (m != NULL && m->parse != NULL) {
                                m->parse(c - m->option_offset, argv, 0,
@@ -239,7 +245,7 @@ static int parse_ipt(struct action_util *a, int *argc_p,
        }
 
        /* check that we passed the correct parameters to the target */
-#if (XTABLES_VERSION_CODE >= 6)
+#if XTABLES_VERSION_CODE >= 6
        if (m)
                xtables_option_tfcall(m);
 #else
@@ -258,8 +264,7 @@ static int parse_ipt(struct action_util *a, int *argc_p,
                }
        }
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, MAX_MSG, tca_id, NULL, 0);
+       tail = addattr_nest(n, MAX_MSG, tca_id);
        fprintf(stdout, "tablename: %s hook: %s\n ", tname, ipthooks[hook]);
        fprintf(stdout, "\ttarget: ");
 
@@ -271,8 +276,8 @@ static int parse_ipt(struct action_util *a, int *argc_p,
        }
        fprintf(stdout, " index %d\n", index);
 
-       if (strlen(tname) > 16) {
-               size = 16;
+       if (strlen(tname) >= 16) {
+               size = 15;
                k[15] = 0;
        } else {
                size = 1 + strlen(tname);
@@ -284,7 +289,7 @@ static int parse_ipt(struct action_util *a, int *argc_p,
        addattr_l(n, MAX_MSG, TCA_IPT_INDEX, &index, 4);
        if (m)
                addattr_l(n, MAX_MSG, TCA_IPT_TARG, m->t, m->t->u.target_size);
-       tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
+       addattr_nest_end(n, tail);
 
        argv += optind;
        *argc_p -= argc;
@@ -312,9 +317,10 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
        struct xtables_target *m;
        struct rtattr *tb[TCA_IPT_MAX + 1];
        struct xt_entry_target *t = NULL;
+       __u32 hook;
 
        if (arg == NULL)
-               return -1;
+               return 0;
 
        /* copy tcipt_globals because .opts will be modified by iptables */
        struct xtables_globals tmp_tcipt_globals = tcipt_globals;
@@ -325,27 +331,25 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
        parse_rtattr_nested(tb, TCA_IPT_MAX, arg);
 
        if (tb[TCA_IPT_TABLE] == NULL) {
-               fprintf(f, "[NULL ipt table name ] assuming mangle ");
+               fprintf(stderr, "Missing ipt table name, assuming mangle\n");
        } else {
                fprintf(f, "tablename: %s ",
                        rta_getattr_str(tb[TCA_IPT_TABLE]));
        }
 
        if (tb[TCA_IPT_HOOK] == NULL) {
-               fprintf(f, "[NULL ipt hook name ]\n ");
+               fprintf(stderr, "Missing ipt hook name\n ");
                return -1;
-       } else {
-               __u32 hook;
-
-               hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
-               fprintf(f, " hook: %s\n", ipthooks[hook]);
        }
 
        if (tb[TCA_IPT_TARG] == NULL) {
-               fprintf(f, "\t[NULL ipt target parameters ]\n");
+               fprintf(stderr, "Missing ipt target parameters\n");
                return -1;
        }
 
+       hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
+       fprintf(f, " hook: %s\n", ipthooks[hook]);
+
        t = RTA_DATA(tb[TCA_IPT_TARG]);
        m = xtables_find_target(t->u.user.name, XTF_TRY_LOAD);
        if (!m) {
@@ -372,7 +376,7 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
                __u32 index;
 
                index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
-               fprintf(f, "\n\tindex %d", index);
+               fprintf(f, "\n\tindex %u", index);
        }
 
        if (tb[TCA_IPT_CNT]) {
@@ -387,7 +391,7 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       fprintf(f, "\n");
+       print_nl();
 
        xtables_free_opts(1);