]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: util: No need for action_n2a() to be reentrant
authorPhil Sutter <phil@nwl.cc>
Sat, 23 Jul 2016 11:28:10 +0000 (13:28 +0200)
committerStephen Hemminger <shemming@brocade.com>
Mon, 25 Jul 2016 15:10:43 +0000 (08:10 -0700)
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>
tc/m_bpf.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_vlan.c
tc/tc_util.c
tc/tc_util.h

index 275634e78b093e81df19f4934beabd64581a9d69..9bf2a85ea24b822e2ba6fc64c809e3d528cdac11 100644 (file)
@@ -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);
 
index db7eed3adfeaf7af7f13da814a7daf6eba93db71..a6e4c1eb44e5af296c0348e9fe7383b41feb6d11 100644 (file)
@@ -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) {
index 9f31fdd324fdcd8bafc6ccb63192bbde4c994cb2..c0a938c716b6a38d51b52801ab8fe1f320e73cf4 100644 (file)
@@ -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) {
index 5eee544b71b82ebf797eae7abc70d5514e1d96a4..0219760aa3631585d67b037ed45a34878188b44b 100644 (file)
@@ -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]);
index 61a84f575cf1217dc03dbcd5e6a02ad49ad17f3a..11f4c9b46fea9cf2c38e3d130714c2515894b6d1 100644 (file)
@@ -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);
index 52bafa79e1b73972561662904b8e9d85c4fdfceb..525f185e2c08274540bccae434595471a963ad0e 100644 (file)
@@ -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]) {
index c28f2610aa011eff80fa577e03b0902c6222fb34..891c2ec7b788eb6d25ce9070fed7c3d3ea47d5ea 100644 (file)
@@ -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);
 
index 3ba580e4fc225cdd6aba8ee4789735c22fd4ea9d..f0b179fcc174423a7b1d4335ef866476fbb5b52a 100644 (file)
@@ -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, " ");
 
index 82311dd692bca7d713b89531ffec2753d6379af5..ac63d9ed09aa5596aa6263b4097ed2d02d33a5aa 100644 (file)
@@ -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);
index cd7b40b0afe48189abbf6dedc08d11ec45afc016..15e49b7ba29995f6b1d5b1d40a08b9db3f4f29fe 100644 (file)
@@ -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;
        }
 }
index e7613ab1bd496dcfa053ef8901eb294338748f0e..f198a4ad5554102c6901d4d58731e05efb69426e 100644 (file)
@@ -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);