]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: use action_a2n() everywhere
authorPhil Sutter <phil@nwl.cc>
Sat, 23 Jul 2016 11:28:09 +0000 (13:28 +0200)
committerStephen Hemminger <shemming@brocade.com>
Mon, 25 Jul 2016 15:10:43 +0000 (08:10 -0700)
Signed-off-by: Phil Sutter <phil@nwl.cc>
12 files changed:
tc/m_bpf.c
tc/m_connmark.c
tc/m_csum.c
tc/m_gact.c
tc/m_ife.c
tc/m_mirred.c
tc/m_nat.c
tc/m_pedit.c
tc/m_police.c
tc/m_simple.c
tc/m_skbedit.c
tc/m_vlan.c

index 20da11d07adae7565badea0d4bb44e4134b34f5e..275634e78b093e81df19f4934beabd64581a9d69 100644 (file)
@@ -104,26 +104,8 @@ opt_bpf:
                NEXT_ARG_FWD();
        }
 
-       if (argc) {
-               if (matches(*argv, "reclassify") == 0) {
-                       parm.action = TC_ACT_RECLASSIFY;
-                       NEXT_ARG_FWD();
-               } else if (matches(*argv, "pipe") == 0) {
-                       parm.action = TC_ACT_PIPE;
-                       NEXT_ARG_FWD();
-               } else if (matches(*argv, "drop") == 0 ||
-                          matches(*argv, "shot") == 0) {
-                       parm.action = TC_ACT_SHOT;
-                       NEXT_ARG_FWD();
-               } else if (matches(*argv, "continue") == 0) {
-                       parm.action = TC_ACT_UNSPEC;
-                       NEXT_ARG_FWD();
-               } else if (matches(*argv, "pass") == 0 ||
-                          matches(*argv, "ok") == 0) {
-                       parm.action = TC_ACT_OK;
-                       NEXT_ARG_FWD();
-               }
-       }
+       if (argc && !action_a2n(*argv, &parm.action, false))
+               NEXT_ARG_FWD();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
index 143d75de66b8b01b02cd0cf68787dcec7054a566..20f98e4fd63a8a9b1d0c1b20db67a8893c834553 100644 (file)
@@ -81,31 +81,8 @@ parse_connmark(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
        }
 
        sel.action = TC_ACT_PIPE;
-       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 ||
-                          matches(*argv, "ok") == 0) {
-                       sel.action = TC_ACT_OK;
-                       argc--;
-                       argv++;
-               }
-       }
+       if (argc && !action_a2n(*argv, &sel.action, false))
+               NEXT_ARG_FWD();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
index 047986efd90c573f0fdd7d016df066c0d8808a6f..db7eed3adfeaf7af7f13da814a7daf6eba93db71 100644 (file)
@@ -120,31 +120,8 @@ parse_csum(struct action_util *a, int *argc_p,
                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 ||
-                          matches(*argv, "ok") == 0) {
-                       sel.action = TC_ACT_OK;
-                       argc--;
-                       argv++;
-               }
-       }
+       if (argc && !action_a2n(*argv, &sel.action, false))
+               NEXT_ARG_FWD();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
index ea2c9ec8251463b58d44cfd8075f50be32c47dd7..9f31fdd324fdcd8bafc6ccb63192bbde4c994cb2 100644 (file)
@@ -71,22 +71,13 @@ usage(void)
 static int
 get_act(char ***argv_p)
 {
-       char **argv = *argv_p;
+       int n;
 
-       if (matches(*argv, "reclassify") == 0) {
-               return TC_ACT_RECLASSIFY;
-       } else if (matches(*argv, "drop") == 0 || matches(*argv, "shot") == 0) {
-               return TC_ACT_SHOT;
-       } else if (matches(*argv, "continue") == 0) {
-               return TC_ACT_UNSPEC;
-       } else if (matches(*argv, "pipe") == 0) {
-               return TC_ACT_PIPE;
-       } else if (matches(*argv, "pass") == 0 || matches(*argv, "ok") == 0)  {
-               return TC_ACT_OK;
-       } else {
-               fprintf(stderr, "bad action type %s\n", *argv);
+       if (!action_a2n(**argv_p, &n, false)) {
+               fprintf(stderr, "bad action type %s\n", **argv_p);
                return -10;
        }
+       return n;
 }
 
 static int
index eaab1cc85513d9b372a6917bae1af05affe9825c..5eee544b71b82ebf797eae7abc70d5514e1d96a4 100644 (file)
@@ -146,31 +146,8 @@ static int parse_ife(struct action_util *a, int *argc_p, char ***argv_p,
                argv++;
        }
 
-       if (argc) {
-               if (matches(*argv, "reclassify") == 0) {
-                       p.action = TC_ACT_RECLASSIFY;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "pipe") == 0) {
-                       p.action = TC_ACT_PIPE;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "drop") == 0 ||
-                          matches(*argv, "shot") == 0) {
-                       p.action = TC_ACT_SHOT;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "continue") == 0) {
-                       p.action = TC_ACT_UNSPEC;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "pass") == 0 ||
-                          matches(*argv, "ok") == 0) {
-                       p.action = TC_ACT_OK;
-                       argc--;
-                       argv++;
-               }
-       }
+       if (argc && !action_a2n(*argv, &p.action, false))
+               NEXT_ARG_FWD();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
index 0066905ace553704ff6ac7ba83a914ec2531a4f8..61a84f575cf1217dc03dbcd5e6a02ad49ad17f3a 100644 (file)
@@ -154,28 +154,9 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p,
        }
 
 
-       if (argc && p.eaction == TCA_EGRESS_MIRROR) {
-
-               if (matches(*argv, "reclassify") == 0) {
-                       p.action = TC_POLICE_RECLASSIFY;
-                       NEXT_ARG();
-               } else if (matches(*argv, "pipe") == 0) {
-                       p.action = TC_POLICE_PIPE;
-                       NEXT_ARG();
-               } else if (matches(*argv, "drop") == 0 ||
-                          matches(*argv, "shot") == 0) {
-                       p.action = TC_POLICE_SHOT;
-                       NEXT_ARG();
-               } else if (matches(*argv, "continue") == 0) {
-                       p.action = TC_POLICE_UNSPEC;
-                       NEXT_ARG();
-               } else if (matches(*argv, "pass") == 0 ||
-                          matches(*argv, "ok") == 0) {
-                       p.action = TC_POLICE_OK;
-                       NEXT_ARG();
-               }
-
-       }
+       if (argc && p.eaction == TCA_EGRESS_MIRROR
+           && !action_a2n(*argv, &p.action, false))
+               NEXT_ARG();
 
        if (argc) {
                if (iok && matches(*argv, "index") == 0) {
index 839fb8a056a4017e4bbc571563014ab52ccb41ca..52bafa79e1b73972561662904b8e9d85c4fdfceb 100644 (file)
@@ -115,31 +115,8 @@ 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 ||
-                          matches(*argv, "ok") == 0) {
-                       sel.action = TC_ACT_OK;
-                       argc--;
-                       argv++;
-               }
-       }
+       if (argc && !action_a2n(*argv, &sel.action, false))
+               NEXT_ARG_FWD();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
index 35879b7fb72e2458fc48c8174a001508db2c5061..c28f2610aa011eff80fa577e03b0902c6222fb34 100644 (file)
@@ -481,26 +481,8 @@ int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
                return -1;
        }
 
-       if (argc) {
-               if (matches(*argv, "reclassify") == 0) {
-                       sel.sel.action = TC_ACT_RECLASSIFY;
-                       NEXT_ARG();
-               } else if (matches(*argv, "pipe") == 0) {
-                       sel.sel.action = TC_ACT_PIPE;
-                       NEXT_ARG();
-               } else if (matches(*argv, "drop") == 0 ||
-                          matches(*argv, "shot") == 0) {
-                       sel.sel.action = TC_ACT_SHOT;
-                       NEXT_ARG();
-               } else if (matches(*argv, "continue") == 0) {
-                       sel.sel.action = TC_ACT_UNSPEC;
-                       NEXT_ARG();
-               } else if (matches(*argv, "pass") == 0 ||
-                          matches(*argv, "ok") == 0) {
-                       sel.sel.action = TC_ACT_OK;
-                       NEXT_ARG();
-               }
-       }
+       if (argc && !action_a2n(*argv, &sel.sel.action, false))
+               NEXT_ARG();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
index 9ae25f28882021330fb011ca094a089b785e1d60..3ba580e4fc225cdd6aba8ee4789735c22fd4ea9d 100644 (file)
@@ -71,34 +71,6 @@ static const char *police_action_n2a(int action, char *buf, int len)
        }
 }
 
-static int police_action_a2n(const char *arg, int *result)
-{
-       int res;
-
-       if (matches(arg, "continue") == 0)
-               res = -1;
-       else if (matches(arg, "drop") == 0)
-               res = TC_POLICE_SHOT;
-       else if (matches(arg, "shot") == 0)
-               res = TC_POLICE_SHOT;
-       else if (matches(arg, "pass") == 0)
-               res = TC_POLICE_OK;
-       else if (strcmp(arg, "ok") == 0)
-               res = TC_POLICE_OK;
-       else if (matches(arg, "reclassify") == 0)
-               res = TC_POLICE_RECLASSIFY;
-       else if (matches(arg, "pipe") == 0)
-               res = TC_POLICE_PIPE;
-       else {
-               char dummy;
-
-               if (sscanf(arg, "%d%c", &res, &dummy) != 1)
-                       return -1;
-       }
-       *result = res;
-       return 0;
-}
-
 static int get_police_result(int *action, int *result, char *arg)
 {
        char *p = strchr(arg, '/');
@@ -106,7 +78,7 @@ static int get_police_result(int *action, int *result, char *arg)
        if (p)
                *p = 0;
 
-       if (police_action_a2n(arg, action)) {
+       if (action_a2n(arg, action, true)) {
                if (p)
                        *p = '/';
                return -1;
@@ -114,7 +86,7 @@ static int get_police_result(int *action, int *result, char *arg)
 
        if (p) {
                *p = '/';
-               if (police_action_a2n(p+1, result))
+               if (action_a2n(p+1, result, true))
                        return -1;
        }
        return 0;
index 27b3e5e406d0587ac06a8be4ca19d347b406c8b7..732eaf1eb6d94315ed847e92a268f683cf74c29f 100644 (file)
@@ -120,31 +120,8 @@ parse_simple(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
                }
        }
 
-       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 ||
-                          matches(*argv, "ok") == 0) {
-                       sel.action = TC_ACT_OK;
-                       argc--;
-                       argv++;
-               }
-       }
+       if (argc && !action_a2n(*argv, &sel.action, false))
+               NEXT_ARG_FWD();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
index 9ba288c075e08a11aa4fd1a2411678bb32cf003e..eca6a8ac7389964da8deb33fc7e19c98759e0888 100644 (file)
@@ -100,26 +100,8 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
        }
 
        sel.action = TC_ACT_PIPE;
-       if (argc) {
-               if (matches(*argv, "reclassify") == 0) {
-                       sel.action = TC_ACT_RECLASSIFY;
-                       NEXT_ARG();
-               } else if (matches(*argv, "pipe") == 0) {
-                       sel.action = TC_ACT_PIPE;
-                       NEXT_ARG();
-               } else if (matches(*argv, "drop") == 0 ||
-                       matches(*argv, "shot") == 0) {
-                       sel.action = TC_ACT_SHOT;
-                       NEXT_ARG();
-               } else if (matches(*argv, "continue") == 0) {
-                       sel.action = TC_ACT_UNSPEC;
-                       NEXT_ARG();
-               } else if (matches(*argv, "pass") == 0 ||
-                          matches(*argv, "ok") == 0) {
-                       sel.action = TC_ACT_OK;
-                       NEXT_ARG();
-               }
-       }
+       if (argc && !action_a2n(*argv, &sel.action, false))
+               NEXT_ARG();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
index c2684461b616aaed07dd4f3b32c49c59e3383de7..82311dd692bca7d713b89531ffec2753d6379af5 100644 (file)
@@ -101,31 +101,8 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p,
        }
 
        parm.action = TC_ACT_PIPE;
-       if (argc) {
-               if (matches(*argv, "reclassify") == 0) {
-                       parm.action = TC_ACT_RECLASSIFY;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "pipe") == 0) {
-                       parm.action = TC_ACT_PIPE;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "drop") == 0 ||
-                          matches(*argv, "shot") == 0) {
-                       parm.action = TC_ACT_SHOT;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "continue") == 0) {
-                       parm.action = TC_ACT_UNSPEC;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "pass") == 0 ||
-                          matches(*argv, "ok") == 0) {
-                       parm.action = TC_ACT_OK;
-                       argc--;
-                       argv++;
-               }
-       }
+       if (argc && !action_a2n(*argv, &parm.action, false))
+               NEXT_ARG_FWD();
 
        if (argc) {
                if (matches(*argv, "index") == 0) {