diff options
Diffstat (limited to 'tc/m_simple.c')
-rw-r--r-- | tc/m_simple.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/tc/m_simple.c b/tc/m_simple.c index 1ad55268..f8937bca 100644 --- a/tc/m_simple.c +++ b/tc/m_simple.c @@ -81,9 +81,10 @@ #endif static void explain(void) { - fprintf(stderr, "Usage: ... simple STRING\n" - "STRING being an arbitrary string\n" - "example: \"simple blah\"\n"); + fprintf(stderr, "Usage:... simple [sdata STRING] [index INDEX] [CONTROL]\n"); + fprintf(stderr, "\tSTRING being an arbitrary string\n" + "\tINDEX := optional index value used\n" + "\tCONTROL := reclassify|pipe|drop|continue|ok\n"); } static void usage(void) @@ -103,42 +104,43 @@ parse_simple(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct rtattr *tail; char *simpdata = NULL; - while (argc > 0) { if (matches(*argv, "simple") == 0) { NEXT_ARG(); + } else if (matches(*argv, "sdata") == 0) { + NEXT_ARG(); + ok += 1; simpdata = *argv; - ok = 1; argc--; argv++; - break; } else if (matches(*argv, "help") == 0) { usage(); } else { break; } - - } - - if (!ok) { - explain(); - return -1; } if (argc) { if (matches(*argv, "index") == 0) { NEXT_ARG(); if (get_u32(&sel.index, *argv, 10)) { - fprintf(stderr, "simple: Illegal \"index\"\n"); + fprintf(stderr, "simple: Illegal \"index\" (%s)\n", + *argv); return -1; } + ok += 1; argc--; argv++; } } - if (strlen(simpdata) > (SIMP_MAX_DATA - 1)) { - fprintf(stderr, "simple: Illegal string len %zu <%s> \n", + if (!ok) { + explain(); + return -1; + } + + if (simpdata && (strlen(simpdata) > (SIMP_MAX_DATA - 1))) { + fprintf(stderr, "simple: Illegal string len %zu <%s>\n", strlen(simpdata), simpdata); return -1; } @@ -148,7 +150,8 @@ parse_simple(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); addattr_l(n, MAX_MSG, TCA_DEF_PARMS, &sel, sizeof(sel)); - addattr_l(n, MAX_MSG, TCA_DEF_DATA, simpdata, SIMP_MAX_DATA); + if (simpdata) + addattr_l(n, MAX_MSG, TCA_DEF_DATA, simpdata, SIMP_MAX_DATA); tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail; *argc_p = argc; @@ -156,7 +159,7 @@ parse_simple(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, return 0; } -static int print_simple(struct action_util *au, FILE * f, struct rtattr *arg) +static int print_simple(struct action_util *au, FILE *f, struct rtattr *arg) { struct tc_defact *sel; struct rtattr *tb[TCA_DEF_MAX + 1]; @@ -181,12 +184,13 @@ static int print_simple(struct action_util *au, FILE * f, struct rtattr *arg) simpdata = RTA_DATA(tb[TCA_DEF_DATA]); fprintf(f, "Simple <%s>\n", simpdata); - fprintf(f, "\t index %d ref %d bind %d", sel->index, + fprintf(f, "\t index %u ref %d bind %d", sel->index, sel->refcnt, sel->bindcnt); if (show_stats) { if (tb[TCA_DEF_TM]) { struct tcf_t *tm = RTA_DATA(tb[TCA_DEF_TM]); + print_tm(f, tm); } } |