tc: use action_a2n() everywhere

Signed-off-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
Phil Sutter 2016-07-23 13:28:09 +02:00 committed by Stephen Hemminger
parent 53aadc5286
commit 69f5aff63c
12 changed files with 27 additions and 275 deletions

View 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) {

View 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) {

View 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) {

View 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

View 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) {

View 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) {

View 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) {

View 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) {

View 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;

View 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) {

View 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) {

View 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) {