]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/m_xt_old.c
man: tc-taprio.8: fix syntax error
[mirror_iproute2.git] / tc / m_xt_old.c
index 0c7ec6042a224111c44eab346e370f9108aff7f0..313bea61cc7e05bb8ed24168b48dd320c63a31bb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * m_xt.c      xtables based targets
- *             utilities mostly ripped from iptables <duh, its the linux way>
+ *             utilities mostly ripped from iptables <duh, its the linux way>
  *
  *             This program is free software; you can distribute it and/or
  *             modify it under the terms of the GNU General Public License
@@ -13,7 +13,6 @@
 /*XXX: in the future (xtables 1.4.3?) get rid of everything tagged
  * as TC_CONFIG_XT_H */
 
-#include <syslog.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include "xt-internal.h"
 #endif
 
+#ifndef ALIGN
+#define ALIGN(x, a)            __ALIGN_MASK(x, (typeof(x))(a)-1)
+#define __ALIGN_MASK(x, mask)  (((x)+(mask))&~(mask))
+#endif
+
 static const char *pname = "tc-ipt";
 static const char *tname = "mangle";
 static const char *pversion = "0.2";
@@ -58,7 +62,7 @@ static struct option original_opts[] = {
 };
 
 static struct option *opts = original_opts;
-static unsigned int global_option_offset = 0;
+static unsigned int global_option_offset;
 char *lib_dir;
 const char *program_version = XTABLES_VERSION;
 const char *program_name = "tc-ipt";
@@ -91,18 +95,18 @@ merge_options(struct option *oldopts, const struct option *newopts,
        struct option *merge;
        unsigned int num_old, num_new, i;
 
-       for (num_old = 0; oldopts[num_old].name; num_old++) ;
-       for (num_new = 0; newopts[num_new].name; num_new++) ;
+       for (num_old = 0; oldopts[num_old].name; num_old++);
+       for (num_new = 0; newopts[num_new].name; num_new++);
 
        *option_offset = global_option_offset + OPTION_OFFSET;
 
-       merge = malloc(sizeof (struct option) * (num_new + num_old + 1));
-       memcpy(merge, oldopts, num_old * sizeof (struct option));
+       merge = malloc(sizeof(struct option) * (num_new + num_old + 1));
+       memcpy(merge, oldopts, num_old * sizeof(struct option));
        for (i = 0; i < num_new; i++) {
                merge[num_old + i] = newopts[i];
                merge[num_old + i].val += *option_offset;
        }
-       memset(merge + num_old + num_new, 0, sizeof (struct option));
+       memset(merge + num_old + num_new, 0, sizeof(struct option));
 
        return merge;
 }
@@ -120,35 +124,35 @@ merge_options(struct option *oldopts, const struct option *newopts,
 int
 check_inverse(const char option[], int *invert, int *my_optind, int argc)
 {
-        if (option && strcmp(option, "!") == 0) {
-                if (*invert)
-                        exit_error(PARAMETER_PROBLEM,
-                                   "Multiple `!' flags not allowed");
-                *invert = TRUE;
-                if (my_optind != NULL) {
-                        ++*my_optind;
-                        if (argc && *my_optind > argc)
-                                exit_error(PARAMETER_PROBLEM,
-                                           "no argument following `!'");
-                }
-
-                return TRUE;
-        }
-        return FALSE;
+       if (option && strcmp(option, "!") == 0) {
+               if (*invert)
+                       exit_error(PARAMETER_PROBLEM,
+                                  "Multiple `!' flags not allowed");
+               *invert = TRUE;
+               if (my_optind != NULL) {
+                       ++*my_optind;
+                       if (argc && *my_optind > argc)
+                               exit_error(PARAMETER_PROBLEM,
+                                          "no argument following `!'");
+               }
+
+               return TRUE;
+       }
+       return FALSE;
 }
 
 /*XXX: TC_CONFIG_XT_H */
 void exit_error(enum exittype status, const char *msg, ...)
 {
-        va_list args;
-
-        va_start(args, msg);
-        fprintf(stderr, "%s v%s: ", pname, pversion);
-        vfprintf(stderr, msg, args);
-        va_end(args);
-        fprintf(stderr, "\n");
-        /* On error paths, make sure that we don't leak memory */
-        exit(status);
+       va_list args;
+
+       va_start(args, msg);
+       fprintf(stderr, "%s v%s: ", pname, pversion);
+       vfprintf(stderr, msg, args);
+       va_end(args);
+       fprintf(stderr, "\n");
+       /* On error paths, make sure that we don't leak memory */
+       exit(status);
 }
 
 /*XXX: TC_CONFIG_XT_H */
@@ -168,9 +172,9 @@ build_st(struct xtables_target *target, struct xt_entry_target *t)
 {
 
        size_t size =
-                   XT_ALIGN(sizeof (struct xt_entry_target)) + target->size;
+                   XT_ALIGN(sizeof(struct xt_entry_target)) + target->size;
 
-       if (NULL == t) {
+       if (t == NULL) {
                target->t = fw_calloc(1, size);
                target->t->u.target_size = size;
                strcpy(target->t->u.user.name, target->name);
@@ -192,14 +196,14 @@ inline void set_lib_dir(void)
        if (!lib_dir) {
                lib_dir = getenv("IPTABLES_LIB_DIR");
                if (lib_dir)
-                       fprintf(stderr, "using deprecated IPTABLES_LIB_DIR \n");
+                       fprintf(stderr, "using deprecated IPTABLES_LIB_DIR\n");
        }
        if (lib_dir == NULL)
                lib_dir = XT_LIB_DIR;
 
 }
 
-static int parse_ipt(struct action_util *a,int *argc_p,
+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;
@@ -209,17 +213,16 @@ static int parse_ipt(struct action_util *a,int *argc_p,
        int rargc = *argc_p;
        char **argv = *argv_p;
        int argc = 0, iargc = 0;
-       char k[16];
-       int res = -1;
+       char k[FILTER_NAMESZ];
        int size = 0;
        int iok = 0, ok = 0;
        __u32 hook = 0, index = 0;
-       res = 0;
 
        set_lib_dir();
 
        {
                int i;
+
                for (i = 0; i < rargc; i++) {
                        if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) {
                                break;
@@ -229,7 +232,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
        }
 
        if (argc <= 2) {
-               fprintf(stderr,"bad arguements to ipt %d vs %d \n", argc, rargc);
+               fprintf(stderr, "bad arguments to ipt %d vs %d\n", argc, rargc);
                return -1;
        }
 
@@ -240,29 +243,29 @@ static int parse_ipt(struct action_util *a,int *argc_p,
                switch (c) {
                case 'j':
                        m = find_target(optarg, TRY_LOAD);
-                       if (NULL != m) {
+                       if (m != NULL) {
 
-                               if (0 > build_st(m, NULL)) {
-                                       printf(" %s error \n", m->name);
+                               if (build_st(m, NULL) < 0) {
+                                       printf(" %s error\n", m->name);
                                        return -1;
                                }
                                opts =
                                    merge_options(opts, m->extra_opts,
                                                  &m->option_offset);
                        } else {
-                               fprintf(stderr," failed to find target %s\n\n", optarg);
+                               fprintf(stderr, " failed to find target %s\n\n", optarg);
                                return -1;
                        }
                        ok++;
                        break;
 
                default:
-                       memset(&fw, 0, sizeof (fw));
+                       memset(&fw, 0, sizeof(fw));
                        if (m) {
                                m->parse(c - m->option_offset, argv, 0,
                                         &m->tflags, NULL, &m->t);
                        } else {
-                               fprintf(stderr," failed to find target %s\n\n", optarg);
+                               fprintf(stderr, " failed to find target %s\n\n", optarg);
                                return -1;
 
                        }
@@ -286,7 +289,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
        }
 
        if (!ok && !iok) {
-               fprintf(stderr," ipt Parser BAD!! (%s)\n", *argv);
+               fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv);
                return -1;
        }
 
@@ -296,6 +299,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
 
        {
                struct tcmsg *t = NLMSG_DATA(n);
+
                if (t->tcm_parent != TC_H_ROOT
                    && t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) {
                        hook = NF_IP_PRE_ROUTING;
@@ -304,8 +308,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: ");
 
@@ -326,7 +329,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);
 
        argc -= optind;
        argv += optind;
@@ -336,11 +339,11 @@ static int parse_ipt(struct action_util *a,int *argc_p,
        optind = 0;
        free_opts(opts);
        /* Clear flags if target will be used again */
-        m->tflags=0;
-        m->used=0;
+        m->tflags = 0;
+        m->used = 0;
        /* Free allocated memory */
-        if (m->t)
-            free(m->t);
+       if (m->t)
+           free(m->t);
 
 
        return 0;
@@ -348,7 +351,7 @@ static int parse_ipt(struct action_util *a,int *argc_p,
 }
 
 static int
-print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
+print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
 {
        struct rtattr *tb[TCA_IPT_MAX + 1];
        struct xt_entry_target *t = NULL;
@@ -364,7 +367,7 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
                fprintf(f, "[NULL ipt table name ] assuming mangle ");
        } else {
                fprintf(f, "tablename: %s ",
-                       (char *) RTA_DATA(tb[TCA_IPT_TABLE]));
+                       rta_getattr_str(tb[TCA_IPT_TABLE]));
        }
 
        if (tb[TCA_IPT_HOOK] == NULL) {
@@ -372,20 +375,22 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
                return -1;
        } else {
                __u32 hook;
-               hook = *(__u32 *) RTA_DATA(tb[TCA_IPT_HOOK]);
-               fprintf(f, " hook: %s \n", ipthooks[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(f, "\t[NULL ipt target parameters ]\n");
                return -1;
        } else {
                struct xtables_target *m = NULL;
+
                t = RTA_DATA(tb[TCA_IPT_TARG]);
                m = find_target(t->u.user.name, TRY_LOAD);
-               if (NULL != m) {
-                       if (0 > build_st(m, t)) {
-                               fprintf(stderr, " %s error \n", m->name);
+               if (m != NULL) {
+                       if (build_st(m, t) < 0) {
+                               fprintf(stderr, " %s error\n", m->name);
                                return -1;
                        }
 
@@ -403,21 +408,24 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
                        fprintf(f, " [NULL ipt target index ]\n");
                } else {
                        __u32 index;
-                       index = *(__u32 *) RTA_DATA(tb[TCA_IPT_INDEX]);
-                       fprintf(f, " \n\tindex %d", index);
+
+                       index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
+                       fprintf(f, "\n\tindex %u", index);
                }
 
                if (tb[TCA_IPT_CNT]) {
-                       struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);;
+                       struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);
+
                        fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
                }
                if (show_stats) {
                        if (tb[TCA_IPT_TM]) {
                                struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
-                               print_tm(f,tm);
+
+                               print_tm(f, tm);
                        }
                }
-               fprintf(f, " \n");
+               fprintf(f, "\n");
 
        }
        free_opts(opts);
@@ -426,8 +434,7 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
 }
 
 struct action_util ipt_action_util = {
-        .id = "ipt",
-        .parse_aopt = parse_ipt,
-        .print_aopt = print_ipt,
+       .id = "ipt",
+       .parse_aopt = parse_ipt,
+       .print_aopt = print_ipt,
 };
-