From b317557f5854bb8e4ed0ff47a2327f652c6e3433 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 24 Nov 2017 11:18:31 -0800 Subject: [PATCH] tc: replace magic constant 16 with #define For places where tc is expecting device name use IFNAMSIZ. For others where it is a filter name, introduce a new constant. Signed-off-by: Stephen Hemminger --- tc/m_action.c | 6 +++--- tc/m_ipt.c | 2 +- tc/m_mirred.c | 2 +- tc/m_pedit.c | 2 +- tc/m_xt.c | 2 +- tc/m_xt_old.c | 2 +- tc/tc_class.c | 6 +++--- tc/tc_exec.c | 2 +- tc/tc_filter.c | 10 +++++----- tc/tc_qdisc.c | 6 +++--- tc/tc_util.h | 11 ++++++++--- 11 files changed, 28 insertions(+), 23 deletions(-) diff --git a/tc/m_action.c b/tc/m_action.c index 0dce97f08..85f9e27bf 100644 --- a/tc/m_action.c +++ b/tc/m_action.c @@ -154,7 +154,7 @@ int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) int argc = *argc_p; char **argv = *argv_p; struct rtattr *tail, *tail2; - char k[16]; + char k[FILTER_NAMESZ]; int act_ck_len = 0; int ok = 0; int eap = 0; /* expect action parameters */ @@ -431,7 +431,7 @@ int print_action(const struct sockaddr_nl *who, static int tc_action_gd(int cmd, unsigned int flags, int *argc_p, char ***argv_p) { - char k[16]; + char k[FILTER_NAMESZ]; struct action_util *a = NULL; int argc = *argc_p; char **argv = *argv_p; @@ -581,7 +581,7 @@ static int tc_act_list_or_flush(int *argc_p, char ***argv_p, int event) char **argv = *argv_p; __u32 msec_since = 0; int argc = *argc_p; - char k[16]; + char k[FILTER_NAMESZ]; struct { struct nlmsghdr n; struct tcamsg t; diff --git a/tc/m_ipt.c b/tc/m_ipt.c index 942b4f23b..1c3c240f6 100644 --- a/tc/m_ipt.c +++ b/tc/m_ipt.c @@ -286,7 +286,7 @@ static int parse_ipt(struct action_util *a, int *argc_p, int rargc = *argc_p; char **argv = *argv_p; int argc = 0, iargc = 0; - char k[16]; + char k[FILTER_NAMESZ]; int size = 0; int iok = 0, ok = 0; __u32 hook = 0, index = 0; diff --git a/tc/m_mirred.c b/tc/m_mirred.c index d0b7a46ab..33c915d68 100644 --- a/tc/m_mirred.c +++ b/tc/m_mirred.c @@ -70,7 +70,7 @@ parse_direction(struct action_util *a, int *argc_p, char ***argv_p, int ok = 0, iok = 0, mirror = 0, redir = 0, ingress = 0, egress = 0; struct tc_mirred p = {}; struct rtattr *tail; - char d[16] = {}; + char d[IFNAMSIZ] = {}; while (argc > 0) { diff --git a/tc/m_pedit.c b/tc/m_pedit.c index a6da95365..26549eeea 100644 --- a/tc/m_pedit.c +++ b/tc/m_pedit.c @@ -524,7 +524,7 @@ static int parse_munge(int *argc_p, char ***argv_p, struct m_pedit_sel *sel) res = parse_offset(&argc, &argv, sel, &tkey); goto done; } else { - char k[16]; + char k[FILTER_NAMESZ]; struct m_pedit_util *p = NULL; strncpy(k, *argv, sizeof(k) - 1); diff --git a/tc/m_xt.c b/tc/m_xt.c index 0baea33c9..a1137be96 100644 --- a/tc/m_xt.c +++ b/tc/m_xt.c @@ -154,7 +154,7 @@ static int parse_ipt(struct action_util *a, int *argc_p, int c; char **argv = *argv_p; int argc; - char k[16]; + char k[FILTER_NAMESZ]; int size = 0; int iok = 0, ok = 0; __u32 hook = 0, index = 0; diff --git a/tc/m_xt_old.c b/tc/m_xt_old.c index 4e56e2673..21d908773 100644 --- a/tc/m_xt_old.c +++ b/tc/m_xt_old.c @@ -213,7 +213,7 @@ static int parse_ipt(struct action_util *a, int *argc_p, int rargc = *argc_p; char **argv = *argv_p; int argc = 0, iargc = 0; - char k[16]; + char k[FILTER_NAMESZ]; int size = 0; int iok = 0, ok = 0; __u32 hook = 0, index = 0; diff --git a/tc/tc_class.c b/tc/tc_class.c index c4a6a2505..507864ad8 100644 --- a/tc/tc_class.c +++ b/tc/tc_class.c @@ -67,8 +67,8 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv) }; struct qdisc_util *q = NULL; struct tc_estimator est = {}; - char d[16] = {}; - char k[16] = {}; + char d[IFNAMSIZ] = {}; + char k[FILTER_NAMESZ] = {}; while (argc > 0) { if (strcmp(*argv, "dev") == 0) { @@ -388,7 +388,7 @@ int print_class(const struct sockaddr_nl *who, static int tc_class_list(int argc, char **argv) { struct tcmsg t = { .tcm_family = AF_UNSPEC }; - char d[16] = {}; + char d[IFNAMSIZ] = {}; char buf[1024] = {0}; filter_qdisc = 0; diff --git a/tc/tc_exec.c b/tc/tc_exec.c index d23a825db..0151af7be 100644 --- a/tc/tc_exec.c +++ b/tc/tc_exec.c @@ -84,7 +84,7 @@ noexist: int do_exec(int argc, char **argv) { struct exec_util *eu; - char kind[16] = {}; + char kind[FILTER_NAMESZ] = {}; if (argc < 1) { fprintf(stderr, "No command given, try \"tc exec help\".\n"); diff --git a/tc/tc_filter.c b/tc/tc_filter.c index d0c967a96..276a66cb0 100644 --- a/tc/tc_filter.c +++ b/tc/tc_filter.c @@ -61,8 +61,8 @@ static int tc_filter_modify(int cmd, unsigned int flags, int argc, char **argv) __u32 chain_index; int chain_index_set = 0; char *fhandle = NULL; - char d[16] = {}; - char k[16] = {}; + char d[IFNAMSIZ] = {}; + char k[FILTER_NAMESZ] = {}; struct tc_estimator est = {}; if (cmd == RTM_NEWTFILTER && flags & NLM_F_CREATE) @@ -339,8 +339,8 @@ static int tc_filter_get(int cmd, unsigned int flags, int argc, char **argv) int chain_index_set = 0; __u32 parent_handle = 0; char *fhandle = NULL; - char d[16] = {}; - char k[16] = {}; + char d[IFNAMSIZ] = {}; + char k[FILTER_NAMESZ] = {}; while (argc > 0) { if (strcmp(*argv, "dev") == 0) { @@ -507,7 +507,7 @@ static int tc_filter_list(int argc, char **argv) .t.tcm_parent = TC_H_UNSPEC, .t.tcm_family = AF_UNSPEC, }; - char d[16] = {}; + char d[IFNAMSIZ] = {}; __u32 prio = 0; __u32 protocol = 0; __u32 chain_index; diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c index fcb75f291..56034b599 100644 --- a/tc/tc_qdisc.c +++ b/tc/tc_qdisc.c @@ -49,8 +49,8 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv) struct tc_sizespec szopts; __u16 *data; } stab = {}; - char d[16] = {}; - char k[16] = {}; + char d[IFNAMSIZ] = {}; + char k[FILTER_NAMESZ] = {}; struct { struct nlmsghdr n; struct tcmsg t; @@ -300,7 +300,7 @@ int print_qdisc(const struct sockaddr_nl *who, static int tc_qdisc_list(int argc, char **argv) { struct tcmsg t = { .tcm_family = AF_UNSPEC }; - char d[16] = {}; + char d[IFNAMSIZ] = {}; bool dump_invisible = false; while (argc > 0) { diff --git a/tc/tc_util.h b/tc/tc_util.h index 583a21a82..3d3d4f1d8 100644 --- a/tc/tc_util.h +++ b/tc/tc_util.h @@ -3,9 +3,12 @@ #define MAX_MSG 16384 #include +#include + #include #include #include + #include "tc_core.h" /* This is the deprecated multiqueue interface */ @@ -20,6 +23,8 @@ enum #define TCA_PRIO_MAX (__TCA_PRIO_MAX - 1) #endif +#define FILTER_NAMESZ 16 + struct qdisc_util { struct qdisc_util *next; const char *id; @@ -38,7 +43,7 @@ struct qdisc_util { extern __u16 f_proto; struct filter_util { struct filter_util *next; - char id[16]; + char id[FILTER_NAMESZ]; int (*parse_fopt)(struct filter_util *qu, char *fhandle, int argc, char **argv, struct nlmsghdr *n); int (*print_fopt)(struct filter_util *qu, @@ -47,7 +52,7 @@ struct filter_util { struct action_util { struct action_util *next; - char id[16]; + char id[FILTER_NAMESZ]; int (*parse_aopt)(struct action_util *a, int *argc, char ***argv, int code, struct nlmsghdr *n); int (*print_aopt)(struct action_util *au, FILE *f, struct rtattr *opt); @@ -57,7 +62,7 @@ struct action_util { struct exec_util { struct exec_util *next; - char id[16]; + char id[FILTER_NAMESZ]; int (*parse_eopt)(struct exec_util *eu, int argc, char **argv); }; -- 2.47.2