tc: util: No need for action_n2a() to be reentrant
This allows to remove some buffers here and there. While at it, make it return a const value. Signed-off-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
parent
69f5aff63c
commit
7093200611
|
|
@ -136,8 +136,6 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
struct rtattr *tb[TCA_ACT_BPF_MAX + 1];
|
||||
struct tc_act_bpf *parm;
|
||||
|
||||
SPRINT_BUF(action_buf);
|
||||
|
||||
if (arg == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
@ -162,8 +160,7 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
fprintf(f, " ");
|
||||
}
|
||||
|
||||
fprintf(f, "default-action %s\n", action_n2a(parm->action, action_buf,
|
||||
sizeof(action_buf)));
|
||||
fprintf(f, "default-action %s\n", action_n2a(parm->action));
|
||||
fprintf(f, "\tindex %d ref %d bind %d", parm->index, parm->refcnt,
|
||||
parm->bindcnt);
|
||||
|
||||
|
|
|
|||
|
|
@ -161,8 +161,6 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
char *uflag_5 = "";
|
||||
char *uflag_6 = "";
|
||||
|
||||
SPRINT_BUF(action_buf);
|
||||
|
||||
int uflag_count = 0;
|
||||
|
||||
if (arg == NULL)
|
||||
|
|
@ -200,7 +198,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
fprintf(f, "csum (%s%s%s%s%s%s) action %s\n",
|
||||
uflag_1, uflag_2, uflag_3,
|
||||
uflag_4, uflag_5, uflag_6,
|
||||
action_n2a(sel->action, action_buf, sizeof(action_buf)));
|
||||
action_n2a(sel->action));
|
||||
fprintf(f, "\tindex %d ref %d bind %d", sel->index, sel->refcnt, sel->bindcnt);
|
||||
|
||||
if (show_stats) {
|
||||
|
|
|
|||
|
|
@ -194,9 +194,7 @@ parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
|
|||
static int
|
||||
print_gact(struct action_util *au, FILE * f, struct rtattr *arg)
|
||||
{
|
||||
SPRINT_BUF(b1);
|
||||
#ifdef CONFIG_GACT_PROB
|
||||
SPRINT_BUF(b2);
|
||||
struct tc_gact_p *pp = NULL;
|
||||
struct tc_gact_p pp_dummy;
|
||||
#endif
|
||||
|
|
@ -214,7 +212,7 @@ print_gact(struct action_util *au, FILE * f, struct rtattr *arg)
|
|||
}
|
||||
p = RTA_DATA(tb[TCA_GACT_PARMS]);
|
||||
|
||||
fprintf(f, "gact action %s", action_n2a(p->action, b1, sizeof(b1)));
|
||||
fprintf(f, "gact action %s", action_n2a(p->action));
|
||||
#ifdef CONFIG_GACT_PROB
|
||||
if (tb[TCA_GACT_PROB] != NULL) {
|
||||
pp = RTA_DATA(tb[TCA_GACT_PROB]);
|
||||
|
|
@ -223,7 +221,8 @@ print_gact(struct action_util *au, FILE * f, struct rtattr *arg)
|
|||
memset(&pp_dummy, 0, sizeof(pp_dummy));
|
||||
pp = &pp_dummy;
|
||||
}
|
||||
fprintf(f, "\n\t random type %s %s val %d", prob_n2a(pp->ptype), action_n2a(pp->paction, b2, sizeof (b2)), pp->pval);
|
||||
fprintf(f, "\n\t random type %s %s val %d",
|
||||
prob_n2a(pp->ptype), action_n2a(pp->paction), pp->pval);
|
||||
#endif
|
||||
fprintf(f, "\n\t index %d ref %d bind %d", p->index, p->refcnt, p->bindcnt);
|
||||
if (show_stats) {
|
||||
|
|
|
|||
|
|
@ -215,7 +215,6 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
__u32 mhash = 0;
|
||||
__u32 mprio = 0;
|
||||
int has_optional = 0;
|
||||
SPRINT_BUF(b1);
|
||||
SPRINT_BUF(b2);
|
||||
|
||||
if (arg == NULL)
|
||||
|
|
@ -231,7 +230,7 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
|
||||
fprintf(f, "ife %s action %s ",
|
||||
(p->flags & IFE_ENCODE) ? "encode" : "decode",
|
||||
action_n2a(p->action, b1, sizeof(b1)));
|
||||
action_n2a(p->action));
|
||||
|
||||
if (tb[TCA_IFE_TYPE]) {
|
||||
ife_type = rta_getattr_u16(tb[TCA_IFE_TYPE]);
|
||||
|
|
|
|||
|
|
@ -235,8 +235,6 @@ print_mirred(struct action_util *au, FILE * f, struct rtattr *arg)
|
|||
struct rtattr *tb[TCA_MIRRED_MAX + 1];
|
||||
const char *dev;
|
||||
|
||||
SPRINT_BUF(b1);
|
||||
|
||||
if (arg == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
@ -258,7 +256,8 @@ print_mirred(struct action_util *au, FILE * f, struct rtattr *arg)
|
|||
return -1;
|
||||
}
|
||||
|
||||
fprintf(f, "mirred (%s to device %s) %s", mirred_n2a(p->eaction), dev, action_n2a(p->action, b1, sizeof (b1)));
|
||||
fprintf(f, "mirred (%s to device %s) %s",
|
||||
mirred_n2a(p->eaction), dev, action_n2a(p->action));
|
||||
|
||||
fprintf(f, "\n ");
|
||||
fprintf(f, "\tindex %d ref %d bind %d", p->index, p->refcnt, p->bindcnt);
|
||||
|
|
|
|||
|
|
@ -148,7 +148,6 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
|
|||
char buf1[256];
|
||||
char buf2[256];
|
||||
|
||||
SPRINT_BUF(buf3);
|
||||
int len;
|
||||
|
||||
if (arg == NULL)
|
||||
|
|
@ -170,7 +169,7 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
|
|||
format_host_r(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
|
||||
len,
|
||||
format_host_r(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)),
|
||||
action_n2a(sel->action, buf3, sizeof(buf3)));
|
||||
action_n2a(sel->action));
|
||||
|
||||
if (show_stats) {
|
||||
if (tb[TCA_NAT_TM]) {
|
||||
|
|
|
|||
|
|
@ -514,8 +514,6 @@ int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
struct tc_pedit_sel *sel;
|
||||
struct rtattr *tb[TCA_PEDIT_MAX + 1];
|
||||
|
||||
SPRINT_BUF(b1);
|
||||
|
||||
if (arg == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
@ -528,7 +526,7 @@ int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
sel = RTA_DATA(tb[TCA_PEDIT_PARMS]);
|
||||
|
||||
fprintf(f, " pedit action %s keys %d\n ",
|
||||
action_n2a(sel->action, b1, sizeof(b1)), sel->nkeys);
|
||||
action_n2a(sel->action), sel->nkeys);
|
||||
fprintf(f, "\t index %d ref %d bind %d", sel->index, sel->refcnt,
|
||||
sel->bindcnt);
|
||||
|
||||
|
|
|
|||
|
|
@ -49,28 +49,6 @@ static void explain1(char *arg)
|
|||
fprintf(stderr, "Illegal \"%s\"\n", arg);
|
||||
}
|
||||
|
||||
static const char *police_action_n2a(int action, char *buf, int len)
|
||||
{
|
||||
switch (action) {
|
||||
case -1:
|
||||
return "continue";
|
||||
break;
|
||||
case TC_POLICE_OK:
|
||||
return "pass";
|
||||
break;
|
||||
case TC_POLICE_SHOT:
|
||||
return "drop";
|
||||
break;
|
||||
case TC_POLICE_RECLASSIFY:
|
||||
return "reclassify";
|
||||
case TC_POLICE_PIPE:
|
||||
return "pipe";
|
||||
default:
|
||||
snprintf(buf, len, "%d", action);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
static int get_police_result(int *action, int *result, char *arg)
|
||||
{
|
||||
char *p = strchr(arg, '/');
|
||||
|
|
@ -339,14 +317,12 @@ int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
|
|||
fprintf(f, "avrate %s ",
|
||||
sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]),
|
||||
b1));
|
||||
fprintf(f, "action %s",
|
||||
police_action_n2a(p->action, b1, sizeof(b1)));
|
||||
fprintf(f, "action %s", action_n2a(p->action));
|
||||
|
||||
if (tb[TCA_POLICE_RESULT]) {
|
||||
__u32 action = rta_getattr_u32(tb[TCA_POLICE_RESULT]);
|
||||
|
||||
fprintf(f, "/%s",
|
||||
police_action_n2a(action, b1, sizeof(b1)));
|
||||
fprintf(f, "/%s", action_n2a(action));
|
||||
} else
|
||||
fprintf(f, " ");
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
|
|||
}
|
||||
break;
|
||||
}
|
||||
fprintf(f, " %s", action_n2a(parm->action, b1, sizeof(b1)));
|
||||
fprintf(f, " %s", action_n2a(parm->action));
|
||||
|
||||
fprintf(f, "\n\t index %d ref %d bind %d", parm->index, parm->refcnt,
|
||||
parm->bindcnt);
|
||||
|
|
|
|||
12
tc/tc_util.c
12
tc/tc_util.c
|
|
@ -411,18 +411,17 @@ char *sprint_qdisc_handle(__u32 h, char *buf)
|
|||
return buf;
|
||||
}
|
||||
|
||||
char *action_n2a(int action, char *buf, int len)
|
||||
const char *action_n2a(int action)
|
||||
{
|
||||
static char buf[64];
|
||||
|
||||
switch (action) {
|
||||
case -1:
|
||||
case TC_ACT_UNSPEC:
|
||||
return "continue";
|
||||
break;
|
||||
case TC_ACT_OK:
|
||||
return "pass";
|
||||
break;
|
||||
case TC_ACT_SHOT:
|
||||
return "drop";
|
||||
break;
|
||||
case TC_ACT_RECLASSIFY:
|
||||
return "reclassify";
|
||||
case TC_ACT_PIPE:
|
||||
|
|
@ -430,7 +429,8 @@ char *action_n2a(int action, char *buf, int len)
|
|||
case TC_ACT_STOLEN:
|
||||
return "stolen";
|
||||
default:
|
||||
snprintf(buf, len, "%d", action);
|
||||
snprintf(buf, 64, "%d", action);
|
||||
buf[63] = '\0';
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ char *sprint_tc_classid(__u32 h, char *buf);
|
|||
int tc_print_police(FILE *f, struct rtattr *tb);
|
||||
int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
|
||||
|
||||
char *action_n2a(int action, char *buf, int len);
|
||||
const char *action_n2a(int action);
|
||||
int action_a2n(char *arg, int *result, bool allow_num);
|
||||
int act_parse_police(struct action_util *a, int *argc_p,
|
||||
char ***argv_p, int tca_id, struct nlmsghdr *n);
|
||||
|
|
|
|||
Loading…
Reference in New Issue