misc cleanups
Subsystems (3)
cover misc cleanups
Code cleanup including:
* make local functions static
* drop dead code
* whitespace code style cleanup
Stephen Hemminger (22):
lib/ll_addr: whitespace and indent cleanup
lib/utils: make local functions static
lib/color: make local functions static
lib/ll_map: make local function static
libnetlnk: unused and local functions cleanup
genl: remove dead code
bridge: make local variables static
ip: make flag names const/static
ipmonitor: make local variable static
ipxfrm: make local functions static
tc: drop unused name_to_id function
tipc: make cmd_find static
tc/class: make filter variables static
tc/police: make print_police static
ss: make local variables static
tc/pedit: make functions static
tc/ematch: make local functions static
tc/util: make local functions static
tc/meta: make meta_table static and const
tc/action: make variables static
tc/pedit: use structure initialization
rdma: make local functions static
bridge/bridge.c | 5 ++-- bridge/monitor.c | 2 +- genl/ctrl.c | 71 -------------------------------------------- genl/genl_utils.h | 2 -- include/color.h | 2 -- include/libnetlink.h | 7 ----- include/ll_map.h | 1 - include/names.h | 1 - include/utils.h | 5 ---- ip/ipaddress.c | 2 +- ip/ipmonitor.c | 2 +- ip/ipxfrm.c | 11 +++---- ip/xfrm.h | 9 ------ ip/xfrm_monitor.c | 2 +- lib/color.c | 6 ++-- lib/libnetlink.c | 28 ++--------------- lib/ll_addr.c | 24 ++++++++------- lib/ll_map.c | 2 +- lib/names.c | 28 ----------------- lib/utils.c | 48 +++++------------------------- misc/ss.c | 28 ++++++++--------- rdma/rdma.h | 11 ------- rdma/utils.c | 12 ++++---- tc/em_meta.c | 12 ++++---- tc/m_action.c | 4 +-- tc/m_ematch.c | 30 ++----------------- tc/m_ematch.h | 1 - tc/m_pedit.c | 33 +++++++++----------- tc/m_pedit.h | 15 ---------- tc/m_police.c | 10 +++++-- tc/p_eth.c | 5 ++-- tc/p_icmp.c | 5 ++-- tc/p_ip.c | 5 ++-- tc/p_ip6.c | 5 ++-- tc/p_tcp.c | 5 ++-- tc/p_udp.c | 5 ++-- tc/tc_class.c | 6 ++-- tc/tc_util.c | 17 ++--------- tc/tc_util.h | 8 ----- tipc/cmdl.c | 2 +- tipc/cmdl.h | 2 -- 41 files changed, 110 insertions(+), 369 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/22 lib/ll_addr: whitespace and indent cleanup
Run old ll_addr through kernel Lindent.
--- lib/ll_addr.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
lib/ll_addr.c +13 -11
@@ -26,20 +26,20 @@#include "rt_names.h" #include "utils.h" - -const char *ll_addr_n2a (const unsigned char *addr,int alen,int type,char *buf,int blen) +const char *ll_addr_n2a (const unsigned char *addr,int alen,int type, +char *buf,int blen) {int i;int l;if (alen ==4 && - (type ==ARPHRD_TUNNEL || type ==ARPHRD_SIT || type ==ARPHRD_IPGRE )) { + (type ==ARPHRD_TUNNEL || type ==ARPHRD_SIT + || type ==ARPHRD_IPGRE ))return inet_ntop (AF_INET , addr, buf, blen); - } -if (alen ==16 && - (type ==ARPHRD_TUNNEL6 || type ==ARPHRD_IP6GRE )) { + +if (alen ==16 && (type ==ARPHRD_TUNNEL6 || type ==ARPHRD_IP6GRE ))return inet_ntop (AF_INET6 , addr, buf, blen); - } +snprintf (buf, blen,"%02x" , addr[0 ]);for (i =1 , l =2 ; i < alen && l < blen; i++, l +=3 )snprintf (buf + l, blen - l,":%02x" , addr[i]);
@@ -62,7 +62,7 @@ int ll_addr_a2n(char *lladdr, int len, const char *arg) }else {int i; -for (i=0 ; i<len; i++) { +for (i =0 ; i < len; i++) {int temp;char *cp =strchr (arg,':' );if (cp) {
@@ -70,11 +70,13 @@ int ll_addr_a2n(char *lladdr, int len, const char *arg) cp++; }if (sscanf (arg,"%x" , &temp) !=1 ) { -fprintf (stderr,"\"%s\" is invalid lladdr.\n" , arg); +fprintf (stderr,"\"%s\" is invalid lladdr.\n" , + arg);return -1 ; }if (temp <0 || temp >255 ) { -fprintf (stderr,"\"%s\" is invalid lladdr.\n" , arg); +fprintf (stderr,"\"%s\" is invalid lladdr.\n" , + arg);return -1 ; } lladdr[i] = temp;
@@ -82,6 +84,6 @@ int ll_addr_a2n(char *lladdr, int len, const char *arg)break ; arg = cp; } -return i+1 ; +return i +1 ; } }
Signature · 1 line
2.17.1
PATCH 2/22 lib/utils: make local functions static
In reply to Stephen HemmingerSome of the print/parsing is only used internally. Drop unused get_s8/get_s16.
--- include/utils.h | 5 ----- lib/utils.c | 48 +++++++----------------------------------------- 2 files changed, 7 insertions(+), 46 deletions(-)
include/utils.h +0 -5
@@ -157,9 +157,7 @@ int get_u64(__u64 *val, const char *arg, int base);int get_u32 (__u32 *val,const char *arg,int base);int get_s32 (__s32 *val,const char *arg,int base);int get_u16 (__u16 *val,const char *arg,int base); -int get_s16 (__s16 *val,const char *arg,int base);int get_u8 (__u8 *val,const char *arg,int base); -int get_s8 (__s8 *val,const char *arg,int base);int get_be64 (__be64 *val,const char *arg,int base);int get_be32 (__be32 *val,const char *arg,int base);int get_be16 (__be16 *val,const char *arg,int base);
@@ -172,7 +170,6 @@ __u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len);int addr64_n2a (__u64 addr,char *buff,size_t len);int af_bit_len (int af); -int af_byte_len (int af);const char *format_host_r (int af,int len,const void *addr,char *buf,int buflen);
@@ -326,8 +323,6 @@ void drop_cap(void);int get_time (unsigned int *time,const char *str);int get_time64 (__s64 *time,const char *str); -void print_time (char *buf,int len,__u32 time); -void print_time64 (char *buf,int len,__s64 time);char *sprint_time (__u32 time,char *buf);char *sprint_time64 (__s64 time,char *buf);
lib/utils.c +7 -41
78 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 3/22 lib/color: make local functions static
In reply to Stephen Hemmingercolor_enable etc, only used here.
--- include/color.h | 2 -- lib/color.c | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-)
include/color.h +0 -2
@@ -20,10 +20,8 @@ enum color_opt { COLOR_OPT_ALWAYS = 2 }; -void enable_color (void );bool check_enable_color (int color,int json);bool matches_color (const char *arg,int *val); -void set_color_palette (void );int color_fprintf (FILE *fp,enum color_attr attr,const char *fmt, ...);enum color_attr ifa_family_color (__u8 ifa_family);enum color_attr oper_state_color (__u8 state);
lib/color.c +4 -2
@@ -11,6 +11,8 @@#include "color.h" #include "utils.h" +static void set_color_palette (void ); +enum color {C_RED ,C_GREEN ,
@@ -73,7 +75,7 @@ static enum color attr_colors_dark[] = {static int is_dark_bg;static int color_is_enabled; -void enable_color (void ) +static void enable_color (void ) { color_is_enabled =1 ;set_color_palette ();
@@ -117,7 +119,7 @@ bool matches_color(const char *arg, int *val)return true; } -void set_color_palette (void ) +static void set_color_palette (void ) {char *p =getenv ("COLORFGBG" );
Signature · 1 line
2.17.1
PATCH 4/22 lib/ll_map: make local function static
In reply to Stephen Hemmingerll_idx_a2n is only used in ll_map.
--- include/ll_map.h | 1 - lib/ll_map.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
include/ll_map.h +0 -1
@@ -12,6 +12,5 @@ int ll_index_to_flags(unsigned idx);unsigned namehash (const char *str);const char *ll_idx_n2a (unsigned int idx); -unsigned int ll_idx_a2n (const char *name);#endif /* __LL_MAP_H__ */
lib/ll_map.c +1 -1
@@ -143,7 +143,7 @@ const char *ll_idx_n2a(unsigned int idx)return buf; } -unsigned int ll_idx_a2n (const char *name) +static unsigned int ll_idx_a2n (const char *name) {unsigned int idx;
Signature · 1 line
2.17.1
PATCH 5/22 libnetlnk: unused and local functions cleanup
In reply to Stephen Hemmingerrntl_talk_extack and parse_rtattr_index not used in current code. rtnl_dump_filter_l is only used in this file.
--- include/libnetlink.h | 7 ------- lib/libnetlink.c | 28 ++-------------------------- 2 files changed, 2 insertions(+), 33 deletions(-)
include/libnetlink.h +0 -7
@@ -102,8 +102,6 @@ struct rtnl_dump_filter_arg {__u16 nc_flags; }; -int rtnl_dump_filter_l (struct rtnl_handle *rth, -const struct rtnl_dump_filter_arg *arg);int rtnl_dump_filter_nc (struct rtnl_handle *rth,rtnl_filter_t filter,void *arg,__u16 nc_flags);
@@ -115,9 +113,6 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,int rtnl_talk_iov (struct rtnl_handle *rtnl,struct iovec *iovec,size_t iovlen,struct nlmsghdr **answer) __attribute__((warn_unused_result)); -int rtnl_talk_extack (struct rtnl_handle *rtnl,struct nlmsghdr *n, -struct nlmsghdr **answer,nl_ext_ack_fn_t errfn) - __attribute__((warn_unused_result));int rtnl_talk_suppress_rtnl_errmsg (struct rtnl_handle *rtnl,struct nlmsghdr *n,struct nlmsghdr **answer) __attribute__((warn_unused_result));
@@ -152,8 +147,6 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type,int parse_rtattr (struct rtattr *tb[],int max,struct rtattr *rta,int len);int parse_rtattr_flags (struct rtattr *tb[],int max,struct rtattr *rta,int len,unsigned short flags); -int parse_rtattr_byindex (struct rtattr *tb[],int max, -struct rtattr *rta,int len);struct rtattr *parse_rtattr_one (int type,struct rtattr *rta,int len);int __parse_rtattr_nested_compat (struct rtattr *tb[],int max,struct rtattr *rta,int len);
lib/libnetlink.c +2 -26
@@ -611,8 +611,8 @@ static int rtnl_recvmsg(int fd, struct msghdr *msg, char **answer)return len; } -int rtnl_dump_filter_l (struct rtnl_handle *rth, -const struct rtnl_dump_filter_arg *arg) +static int rtnl_dump_filter_l (struct rtnl_handle *rth, +const struct rtnl_dump_filter_arg *arg) {struct sockaddr_nl nladdr;struct iovec iov;
@@ -877,13 +877,6 @@ int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen,return __rtnl_talk_iov (rtnl, iovec, iovlen, answer, true,NULL ); } -int rtnl_talk_extack (struct rtnl_handle *rtnl,struct nlmsghdr *n, -struct nlmsghdr **answer, -nl_ext_ack_fn_t errfn) -{ -return __rtnl_talk (rtnl, n, answer, true, errfn); -} -int rtnl_talk_suppress_rtnl_errmsg (struct rtnl_handle *rtnl,struct nlmsghdr *n,struct nlmsghdr **answer) {
@@ -1242,23 +1235,6 @@ int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta,return 0 ; } -int parse_rtattr_byindex (struct rtattr *tb[],int max, -struct rtattr *rta,int len) -{ -int i =0 ; - -memset (tb,0 ,sizeof (struct rtattr *) * max); -while (RTA_OK (rta, len)) { -if (rta->rta_type <= max && i < max) - tb[i++] = rta; - rta =RTA_NEXT (rta, len); - } -if (len) -fprintf (stderr,"!!!Deficit %d, rta_len=%d\n" , - len, rta->rta_len); -return i; -} -struct rtattr *parse_rtattr_one (int type,struct rtattr *rta,int len) {while (RTA_OK (rta, len)) {
Signature · 1 line
2.17.1
PATCH 6/22 genl: remove dead code
In reply to Stephen HemmingerThe function genl_ctrl_resolve_family is defined but never used in current code.
--- genl/ctrl.c | 71 ----------------------------------------------- genl/genl_utils.h | 2 -- 2 files changed, 73 deletions(-)
genl/ctrl.c +0 -71
@@ -38,77 +38,6 @@ static int usage(void)return -1 ; } -int genl_ctrl_resolve_family (const char *family) -{ -struct rtnl_handle rth; -int ret =0 ; -struct { -struct nlmsghdr n; -struct genlmsghdr g; -char buf[4096 ]; - } req = { - .n.nlmsg_len =NLMSG_LENGTH (GENL_HDRLEN ), - .n.nlmsg_flags =NLM_F_REQUEST |NLM_F_ACK , - .n.nlmsg_type =GENL_ID_CTRL , - .g.cmd =CTRL_CMD_GETFAMILY , - }; -struct nlmsghdr *nlh = &req.n; -struct genlmsghdr *ghdr = &req.g; -struct nlmsghdr *answer =NULL ; - -if (rtnl_open_byproto (&rth,0 ,NETLINK_GENERIC ) <0 ) { -fprintf (stderr,"Cannot open generic netlink socket\n" ); -exit (1 ); - } - -addattr_l (nlh,128 ,CTRL_ATTR_FAMILY_NAME , family,strlen (family) +1 ); - -if (rtnl_talk (&rth, nlh, &answer) <0 ) { -fprintf (stderr,"Error talking to the kernel\n" ); - goto errout; - } - - { -struct rtattr *tb[CTRL_ATTR_MAX +1 ]; -int len = answer->nlmsg_len; -struct rtattr *attrs; - -if (answer->nlmsg_type !=GENL_ID_CTRL ) { -fprintf (stderr,"Not a controller message, nlmsg_len=%d " -"nlmsg_type=0x%x\n" , answer->nlmsg_len, answer->nlmsg_type); - goto errout; - } - -if (ghdr->cmd !=CTRL_CMD_NEWFAMILY ) { -fprintf (stderr,"Unknown controller command %d\n" , ghdr->cmd); - goto errout; - } - - len -=NLMSG_LENGTH (GENL_HDRLEN ); - -if (len <0 ) { -fprintf (stderr,"wrong controller message len %d\n" , len); -free (answer); -return -1 ; - } - - attrs = (struct rtattr *) ((char *) answer +NLMSG_LENGTH (GENL_HDRLEN )); -parse_rtattr (tb,CTRL_ATTR_MAX , attrs, len); - -if (tb[CTRL_ATTR_FAMILY_ID ] ==NULL ) { -fprintf (stderr,"Missing family id TLV\n" ); - goto errout; - } - - ret =rta_getattr_u16 (tb[CTRL_ATTR_FAMILY_ID ]); - } - -errout: -free (answer); -rtnl_close (&rth); -return ret; -} -static void print_ctrl_cmd_flags (FILE *fp,__u32 fl) {fprintf (fp,"\n\t\tCapabilities (0x%x):\n " , fl);
genl/genl_utils.h +0 -2
@@ -13,6 +13,4 @@ struct genl_util int (*print_genlopt)(struct nlmsghdr *n, void *arg); }; -int genl_ctrl_resolve_family (const char *family); -#endif
Signature · 1 line
2.17.1
PATCH 7/22 bridge: make local variables static
In reply to Stephen Hemmingerenable_color and set_color_palette only used here.
--- bridge/bridge.c | 5 ++--- bridge/monitor.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-)
bridge/bridge.c +2 -3
@@ -23,12 +23,11 @@ int preferred_family = AF_UNSPEC;int oneline;int show_stats;int show_details; -int show_pretty; -int color; +static int color;int compress_vlans;int json;int timestamp; -char *batch_file; +static const char *batch_file;int force;static void usage (void ) __attribute__((noreturn));
bridge/monitor.c +1 -1
@@ -27,7 +27,7 @@static void usage (void ) __attribute__((noreturn)); -int prefix_banner; +static int prefix_banner;static void usage (void ) {
Signature · 1 line
2.17.1
PATCH 8/22 ip: make flag names const/static
In reply to Stephen HemmingerThe table of filter flags is only used in ipaddress
--- ip/ipaddress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipaddress.c +1 -1
@@ -1149,7 +1149,7 @@ static unsigned int get_ifa_flags(struct ifaddrmsg *ifa, }/* Mapping from argument to address flag mask */ -struct { +static const struct {const char *name;unsigned long value; } ifa_flag_names[] = {
Signature · 1 line
2.17.1
PATCH 9/22 ipmonitor: make local variable static
In reply to Stephen Hemmingerprefix_banner only used in one file.
--- ip/ipmonitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipmonitor.c +1 -1
@@ -24,7 +24,7 @@#include "ip_common.h" static void usage (void ) __attribute__((noreturn)); -int prefix_banner; +static int prefix_banner;int listen_all_nsid;static void usage (void )
Signature · 1 line
2.17.1
PATCH 10/22 ipxfrm: make local functions static
In reply to Stephen HemmingerMake functions only used in ipxfrm.c static.
--- ip/ipxfrm.c | 11 ++++++----- ip/xfrm.h | 9 --------- ip/xfrm_monitor.c | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-)
ip/ipxfrm.c +6 -5
@@ -186,7 +186,7 @@ const char *strxf_algotype(int type)return str; } -const char *strxf_mask8 (__u8 mask) +static const char *strxf_mask8 (__u8 mask) {static char str[16 ];const int sn =sizeof (mask) *8 -1 ;
@@ -209,7 +209,7 @@ const char *strxf_mask32(__u32 mask)return str; } -const char *strxf_share (__u8 share) +static const char *strxf_share (__u8 share) {static char str[32 ];
@@ -270,7 +270,7 @@ const char *strxf_ptype(__u8 ptype)return str; } -void xfrm_id_info_print (xfrm_address_t *saddr,struct xfrm_id *id, +static void xfrm_id_info_print (xfrm_address_t *saddr,struct xfrm_id *id,__u8 mode,__u32 reqid,__u16 family,int force_spi,FILE *fp,const char *prefix,const char *title) {
@@ -337,7 +337,8 @@ static const char *strxf_limit(__u64 limit)return str; } -void xfrm_stats_print (struct xfrm_stats *s,FILE *fp,const char *prefix) +static void xfrm_stats_print (struct xfrm_stats *s,FILE *fp, +const char *prefix) {if (prefix)fputs (prefix, fp);
@@ -371,7 +372,7 @@ static const char *strxf_time(__u64 time)return str; } -void xfrm_lifetime_print (struct xfrm_lifetime_cfg *cfg, +static void xfrm_lifetime_print (struct xfrm_lifetime_cfg *cfg,struct xfrm_lifetime_cur *cur,FILE *fp,const char *prefix) {
ip/xfrm.h +0 -9
@@ -118,18 +118,9 @@ int xfrm_algotype_getbyname(char *name);int xfrm_parse_mark (struct xfrm_mark *mark,int *argcp,char ***argvp);const char *strxf_xfrmproto (__u8 proto);const char *strxf_algotype (int type); -const char *strxf_mask8 (__u8 mask);const char *strxf_mask32 (__u32 mask); -const char *strxf_share (__u8 share);const char *strxf_proto (__u8 proto);const char *strxf_ptype (__u8 ptype); -void xfrm_id_info_print (xfrm_address_t *saddr,struct xfrm_id *id, -__u8 mode,__u32 reqid,__u16 family,int force_spi, -FILE *fp,const char *prefix,const char *title); -void xfrm_stats_print (struct xfrm_stats *s,FILE *fp,const char *prefix); -void xfrm_lifetime_print (struct xfrm_lifetime_cfg *cfg, -struct xfrm_lifetime_cur *cur, -FILE *fp,const char *prefix);void xfrm_selector_print (struct xfrm_selector *sel,__u16 family,FILE *fp,const char *prefix); void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
ip/xfrm_monitor.c +1 -1
@@ -34,7 +34,7 @@#include "ip_common.h" static void usage (void ) __attribute__((noreturn)); -int listen_all_nsid; +static int listen_all_nsid;static void usage (void ) {
Signature · 1 line
2.17.1
PATCH 11/22 tc: drop unused name_to_id function
In reply to Stephen HemmingerNot used in current code.
--- include/names.h | 1 - lib/names.c | 28 ---------------------------- 2 files changed, 29 deletions(-)
include/names.h +0 -1
@@ -22,6 +22,5 @@ int db_names_load(struct db_names *db, const char *path);void db_names_free (struct db_names *db);char *id_to_name (struct db_names *db,int id,char *name); -int name_to_id (struct db_names *db,int *id,const char *name);#endif
lib/names.c +0 -28
@@ -150,31 +150,3 @@ char *id_to_name(struct db_names *db, int id, char *name)snprintf (name,IDNAME_MAX ,"%d" , id);return NULL ; } - -int name_to_id (struct db_names *db,int *id,const char *name) -{ -struct db_entry *entry; -int i; - -if (!db) -return -1 ; - -if (db->cached &&strcmp (db->cached->name, name) ==0 ) { - *id = db->cached->id; -return 0 ; - } - -for (i =0 ; i < db->size; i++) { - entry = db->hash[i]; -while (entry &&strcmp (entry->name, name)) - entry = entry->next; - -if (entry) { - db->cached = entry; - *id = entry->id; -return 0 ; - } - } - -return -1 ; -}
Signature · 1 line
2.17.1
PATCH 12/22 tipc: make cmd_find static
In reply to Stephen HemmingerFunction only used in one file.
--- tipc/cmdl.c | 2 +- tipc/cmdl.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
tipc/cmdl.c +1 -1
@@ -17,7 +17,7 @@#include "cmdl.h" -const struct cmd *find_cmd (const struct cmd *cmds,char *str) +static const struct cmd *find_cmd (const struct cmd *cmds,char *str) {const struct cmd *c;const struct cmd *match =NULL ;
tipc/cmdl.h +0 -2
@@ -54,6 +54,4 @@ char *shift_cmdl(struct cmdl *cmdl);int run_cmd (struct nlmsghdr *nlh,const struct cmd *caller,const struct cmd *cmds,struct cmdl *cmdl,void *data); -const struct cmd *find_cmd (const struct cmd *cmds,char *str); -#endif
Signature · 1 line
2.17.1
PATCH 13/22 tc/class: make filter variables static
In reply to Stephen HemmingerOnly used in this file.
--- tc/tc_class.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tc/tc_class.c +3 -3
@@ -153,9 +153,9 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)return 0 ; } -int filter_ifindex; -__u32 filter_qdisc; -__u32 filter_classid; +static int filter_ifindex; +static __u32 filter_qdisc; +static __u32 filter_classid;static void graph_node_add (__u32 parent_id,__u32 id,void *data,int len)
Signature · 1 line
2.17.1
PATCH 14/22 tc/police: make print_police static
In reply to Stephen Hemmingerprint_police function only used by m_police.
--- tc/m_police.c | 10 +++++++--- tc/tc_util.h | 3 --- 2 files changed, 7 insertions(+), 6 deletions(-)
tc/m_police.c +7 -3
@@ -25,6 +25,10 @@#include "utils.h" #include "tc_util.h" +static int act_parse_police (struct action_util *a,int *argc_p, +char ***argv_p,int tca_id,struct nlmsghdr *n); +static int print_police (struct action_util *a,FILE *f,struct rtattr *tb); +struct action_util police_action_util = { .id ="police" , .parse_aopt = act_parse_police,
@@ -50,8 +54,8 @@ static void explain1(char *arg)fprintf (stderr,"Illegal \"%s\"\n" , arg); } -int act_parse_police (struct action_util *a,int *argc_p,char ***argv_p, -int tca_id,struct nlmsghdr *n) +static int act_parse_police (struct action_util *a,int *argc_p,char ***argv_p, +int tca_id,struct nlmsghdr *n) {int argc = *argc_p;char **argv = *argv_p;
@@ -256,7 +260,7 @@ int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)return act_parse_police (NULL , argc_p, argv_p, tca_id, n); } -int print_police (struct action_util *a,FILE *f,struct rtattr *arg) +static int print_police (struct action_util *a,FILE *f,struct rtattr *arg) {SPRINT_BUF (b1);SPRINT_BUF (b2);
tc/tc_util.h +0 -3
@@ -117,9 +117,6 @@ int parse_action_control_slash(int *argc_p, char ***argv_p, int *result1_p, int *result2_p, bool allow_num);void print_action_control (FILE *f,const char *prefix,int action,const char *suffix); -int act_parse_police (struct action_util *a,int *argc_p, -char ***argv_p,int tca_id,struct nlmsghdr *n); -int print_police (struct action_util *a,FILE *f,struct rtattr *tb);int police_print_xstats (struct action_util *a,FILE *f,struct rtattr *tb);int tc_print_action (FILE *f,const struct rtattr *tb,unsigned short tot_acts);int tc_print_ipt (FILE *f,const struct rtattr *tb);
Signature · 1 line
2.17.1
PATCH 15/22 ss: make local variables static
In reply to Stephen HemmingerSeveral variables only used in this code.
--- misc/ss.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
misc/ss.c +14 -14
@@ -96,20 +96,20 @@ static int security_get_initial_context(char *name, char **context) }#endif -int resolve_services =1 ; +static int resolve_services =1 ;int preferred_family =AF_UNSPEC ; -int show_options; +static int show_options;int show_details; -int show_users; -int show_mem; -int show_tcpinfo; -int show_bpf; -int show_proc_ctx; -int show_sock_ctx; -int show_header =1 ; -int follow_events; -int sctp_ino; -int show_tipcinfo; +static int show_users; +static int show_mem; +static int show_tcpinfo; +static int show_bpf; +static int show_proc_ctx; +static int show_sock_ctx; +static int show_header =1 ; +static int follow_events; +static int sctp_ino; +static int show_tipcinfo;enum col_id {COL_NETID ,
@@ -494,7 +494,7 @@ struct user_ent { };#define USER_ENT_HASH_SIZE 256 -struct user_ent *user_ent_hash[USER_ENT_HASH_SIZE ]; +static struct user_ent *user_ent_hash[USER_ENT_HASH_SIZE ];static int user_ent_hashfn (unsigned int ino) {
@@ -1404,7 +1404,7 @@ struct scache {const char *proto; }; -struct scache *rlist; +static struct scache *rlist;static void init_service_resolver (void ) {
Signature · 1 line
2.17.1
PATCH 16/22 tc/pedit: make functions static
In reply to Stephen HemmingerThe parse and pack functions are only used by the pedit routines.
--- tc/m_pedit.c | 33 ++++++++++++++------------------- tc/m_pedit.h | 15 --------------- 2 files changed, 14 insertions(+), 34 deletions(-)
tc/m_pedit.c +14 -19
@@ -118,7 +118,7 @@ noexist:return p; } -int pack_key (struct m_pedit_sel *_sel,struct m_pedit_key *tkey) +static int pack_key (struct m_pedit_sel *_sel,struct m_pedit_key *tkey) {struct tc_pedit_sel *sel = &_sel->sel;struct m_pedit_key_ex *keys_ex = _sel->keys_ex;
@@ -155,8 +155,8 @@ int pack_key(struct m_pedit_sel *_sel, struct m_pedit_key *tkey)return 0 ; } -int pack_key32 (__u32 retain,struct m_pedit_sel *sel, -struct m_pedit_key *tkey) +static int pack_key32 (__u32 retain,struct m_pedit_sel *sel, +struct m_pedit_key *tkey) {if (tkey->off > (tkey->off & ~3 )) { fprintf(stderr,
@@ -169,8 +169,8 @@ int pack_key32(__u32 retain, struct m_pedit_sel *sel,return pack_key (sel, tkey); } -int pack_key16 (__u32 retain,struct m_pedit_sel *sel, -struct m_pedit_key *tkey) +static int pack_key16 (__u32 retain,struct m_pedit_sel *sel, +struct m_pedit_key *tkey) {int ind, stride;__u32 m[4 ] = {0x0000FFFF ,0xFF0000FF ,0xFFFF0000 };
@@ -197,10 +197,10 @@ int pack_key16(__u32 retain, struct m_pedit_sel *sel,printf ("pack_key16: Final val %08x mask %08x\n" , tkey->val, tkey->mask);return pack_key (sel, tkey); - } -int pack_key8 (__u32 retain,struct m_pedit_sel *sel,struct m_pedit_key *tkey) +static int pack_key8 (__u32 retain,struct m_pedit_sel *sel, +struct m_pedit_key *tkey) {int ind, stride;__u32 m[4 ] = {0x00FFFFFF ,0xFF00FFFF ,0xFFFF00FF ,0xFFFFFF00 };
@@ -283,7 +283,7 @@ static int pack_ipv6(struct m_pedit_sel *sel, struct m_pedit_key *tkey,return 0 ; } -int parse_val (int *argc_p,char ***argv_p,__u32 *val,int type) +static int parse_val (int *argc_p,char ***argv_p,__u32 *val,int type) {int argc = *argc_p;char **argv = *argv_p;
@@ -433,8 +433,8 @@ done: } -int parse_offset (int *argc_p,char ***argv_p,struct m_pedit_sel *sel, -struct m_pedit_key *tkey) +static int parse_offset (int *argc_p,char ***argv_p,struct m_pedit_sel *sel, +struct m_pedit_key *tkey) {int off;__u32 len, retain;
@@ -612,8 +612,8 @@ static int pedit_keys_ex_addattr(struct m_pedit_sel *sel, struct nlmsghdr *n)return 0 ; } -int parse_pedit (struct action_util *a,int *argc_p,char ***argv_p,int tca_id, -struct nlmsghdr *n) +static int parse_pedit (struct action_util *a,int *argc_p,char ***argv_p, +int tca_id,struct nlmsghdr *n) {struct m_pedit_sel sel = {};
@@ -705,7 +705,7 @@ int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,return 0 ; } -const char *pedit_htype_str[] = { +static const char *const pedit_htype_str[] = { [TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK ] ="" , [TCA_PEDIT_KEY_EX_HDR_TYPE_ETH ] ="eth" , [TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 ] ="ipv4" ,
@@ -730,7 +730,7 @@ static void print_pedit_location(FILE *f,fprintf (f,"%c%d" , (int )off >=0 ?'+' :'-' ,abs ((int )off)); } -int print_pedit (struct action_util *au,FILE *f,struct rtattr *arg) +static int print_pedit (struct action_util *au,FILE *f,struct rtattr *arg) {struct tc_pedit_sel *sel;struct rtattr *tb[TCA_PEDIT_MAX +1 ];
@@ -826,11 +826,6 @@ int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)return 0 ; } -int pedit_print_xstats (struct action_util *au,FILE *f,struct rtattr *xstats) -{ -return 0 ; -} -struct action_util pedit_action_util = { .id ="pedit" , .parse_aopt = parse_pedit,
tc/m_pedit.h +0 -15
@@ -71,22 +71,7 @@ struct m_pedit_util { struct m_pedit_key *tkey); }; -int pack_key (struct m_pedit_sel *sel,struct m_pedit_key *tkey); -int pack_key32 (__u32 retain,struct m_pedit_sel *sel, -struct m_pedit_key *tkey); -int pack_key16 (__u32 retain,struct m_pedit_sel *sel, -struct m_pedit_key *tkey); -int pack_key8 (__u32 retain,struct m_pedit_sel *sel, -struct m_pedit_key *tkey); -int parse_val (int *argc_p,char ***argv_p,__u32 *val,int type);int parse_cmd (int *argc_p,char ***argv_p,__u32 len,int type,__u32 retain,struct m_pedit_sel *sel,struct m_pedit_key *tkey); -int parse_offset (int *argc_p,char ***argv_p, -struct m_pedit_sel *sel,struct m_pedit_key *tkey); -int parse_pedit (struct action_util *a,int *argc_p,char ***argv_p, -int tca_id,struct nlmsghdr *n); -int print_pedit (struct action_util *au,FILE *f,struct rtattr *arg); -int pedit_print_xstats (struct action_util *au,FILE *f, -struct rtattr *xstats);#endif
Signature · 1 line
2.17.1
PATCH 17/22 tc/ematch: make local functions static
In reply to Stephen HemmingerThe print handling is only used in tc/m_ematch.c
Remove unused function to print_ematch_tree.
--- tc/m_ematch.c | 30 +++--------------------------- tc/m_ematch.h | 1 - 2 files changed, 3 insertions(+), 28 deletions(-)
tc/m_ematch.c +3 -27
@@ -38,6 +38,8 @@ struct ematch *ematch_root;static int begin_argc;static char **begin_argv; +static void bstr_print (FILE *fd,const struct bstr *b,int ascii); +static inline void map_warning (int num,char *kind) { fprintf(stderr,
@@ -548,7 +550,7 @@ unsigned long bstrtoul(const struct bstr *b)return l; } -void bstr_print (FILE *fd,const struct bstr *b,int ascii) +static void bstr_print (FILE *fd,const struct bstr *b,int ascii) {int i;char *s = b->data;
@@ -565,29 +567,3 @@ void bstr_print(FILE *fd, const struct bstr *b, int ascii)fprintf (fd,"\"" ); } } - -void print_ematch_tree (const struct ematch *tree) -{ -const struct ematch *t; - -for (t = tree; t; t = t->next) { -if (t->inverted) -printf ("NOT " ); - -if (t->child) { -printf ("(" ); -print_ematch_tree (t->child); -printf (")" ); - }else { -struct bstr *b; - -for (b = t->args; b; b = b->next) -printf ("%s%s" , b->data, b->next ?" " :"" ); - } - -if (t->relation ==TCF_EM_REL_AND ) -printf (" AND " ); -else if (t->relation ==TCF_EM_REL_OR ) -printf (" OR " ); - } -}
tc/m_ematch.h +0 -1
@@ -51,7 +51,6 @@ static inline struct bstr *bstr_next(struct bstr *b) }unsigned long bstrtoul (const struct bstr *b); -void bstr_print (FILE *fd,const struct bstr *b,int ascii);struct ematch {struct bstr *args;
Signature · 1 line
2.17.1
PATCH 18/22 tc/util: make local functions static
In reply to Stephen HemmingerThe tc util library parse/print has functions only used locally (and some dead code removed).
--- tc/tc_util.c | 17 +++-------------- tc/tc_util.h | 5 ----- 2 files changed, 3 insertions(+), 19 deletions(-)
tc/tc_util.c +3 -14
@@ -190,7 +190,7 @@ static const struct rate_suffix { { NULL } }; -int parse_percent_rate (char *rate,const char *str,const char *dev) +static int parse_percent_rate (char *rate,const char *str,const char *dev) {long dev_mbit;int ret;
@@ -409,7 +409,7 @@ void print_devname(enum output_type type, int ifindex) "dev", "%s ", ifname); } -void print_size (char *buf,int len,__u32 sz) +static void print_size (char *buf,int len,__u32 sz) {double tmp = sz;
@@ -427,17 +427,6 @@ char *sprint_size(__u32 size, char *buf)return buf; } -void print_qdisc_handle (char *buf,int len,__u32 h) -{ -snprintf (buf, len,"%x:" ,TC_H_MAJ (h)>>16 ); -} - -char *sprint_qdisc_handle (__u32 h,char *buf) -{ -print_qdisc_handle (buf,SPRINT_BSIZE -1 , h); -return buf; -} -static const char *action_n2a (int action) {static char buf[64 ];
@@ -709,7 +698,7 @@ int get_linklayer(unsigned int *val, const char *arg)return 0 ; } -void print_linklayer (char *buf,int len,unsigned int linklayer) +static void print_linklayer (char *buf,int len,unsigned int linklayer) {switch (linklayer) {case LINKLAYER_UNSPEC :
tc/tc_util.h +0 -5
@@ -73,7 +73,6 @@ const char *get_tc_lib(void);struct qdisc_util *get_qdisc_kind (const char *str);struct filter_util *get_filter_kind (const char *str); -int parse_percent_rate (char *rate,const char *str,const char *dev);int get_qdisc_handle (__u32 *h,const char *str);int get_rate (unsigned int *rate,const char *str);int get_percent_rate (unsigned int *rate,const char *str,const char *dev);
@@ -84,14 +83,10 @@ int get_size_and_cell(unsigned int *size, int *cell_log, char *str);int get_linklayer (unsigned int *val,const char *arg);void print_rate (char *buf,int len,__u64 rate); -void print_size (char *buf,int len,__u32 size); -void print_qdisc_handle (char *buf,int len,__u32 h); -void print_linklayer (char *buf,int len,unsigned int linklayer);void print_devname (enum output_type type,int ifindex);char *sprint_rate (__u64 rate,char *buf);char *sprint_size (__u32 size,char *buf); -char *sprint_qdisc_handle (__u32 h,char *buf);char *sprint_tc_classid (__u32 h,char *buf);char *sprint_ticks (__u32 ticks,char *buf);char *sprint_linklayer (unsigned int linklayer,char *buf);
Signature · 1 line
2.17.1
PATCH 19/22 tc/meta: make meta_table static and const
In reply to Stephen HemmingerThe mapping table is only used by em_meta.
--- tc/em_meta.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tc/em_meta.c +6 -6
@@ -38,7 +38,7 @@ static void meta_print_usage(FILE *fd) "For a list of meta identifiers, use meta(list).\n"); } -struct meta_entry { +static const struct meta_entry { int id; char *kind; char *mask;
@@ -121,7 +121,7 @@ static inline int map_type(char k)return INT_MAX ; } -static struct meta_entry *lookup_meta_entry (struct bstr *kind) +static const struct meta_entry *lookup_meta_entry (struct bstr *kind) {int i;
@@ -133,7 +133,7 @@ static struct meta_entry *lookup_meta_entry(struct bstr *kind)return NULL ; } -static struct meta_entry *lookup_meta_entry_byid (int id) +static const struct meta_entry *lookup_meta_entry_byid (int id) {int i;
@@ -168,8 +168,8 @@ static inline void dump_value(struct nlmsghdr *n, int tlv, unsigned long val,static inline int is_compatible (struct tcf_meta_val *what,struct tcf_meta_val *needed) { +const struct meta_entry *entry;char *p; -struct meta_entry *entry; entry =lookup_meta_entry_byid (TCF_META_ID (what->kind));
@@ -249,7 +249,7 @@ static inline struct bstr * parse_object(struct bstr *args, struct bstr *arg, struct tcf_meta_val *obj, unsigned long *dst, struct tcf_meta_val *left) { - struct meta_entry *entry; + const struct meta_entry *entry;unsigned long num;struct bstr *a;
@@ -461,7 +461,7 @@ static int print_object(FILE *fd, struct tcf_meta_val *obj, struct rtattr *rta) {int id =TCF_META_ID (obj->kind);int type =TCF_META_TYPE (obj->kind); -struct meta_entry *entry; +const struct meta_entry *entry;if (id ==TCF_META_ID_VALUE )return print_value (fd, type, rta);
Signature · 1 line
2.17.1
PATCH 20/22 tc/action: make variables static
In reply to Stephen Hemminger--- tc/m_action.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tc/m_action.c +2 -2
@@ -30,9 +30,9 @@static struct action_util *action_list;#ifdef CONFIG_GACT -int gact_ld;/* f*ckin backward compatibility */ +static int gact_ld;/* f*ckin backward compatibility */ #endif -int tab_flush; +static int tab_flush;static void act_usage (void ) {
Signature · 1 line
2.17.1
PATCH 21/22 tc/pedit: use structure initialization
In reply to Stephen HemmingerThe pedit callback structure table should be iniatialized using structure initialization to avoid structure changes problems.
--- tc/p_eth.c | 5 ++--- tc/p_icmp.c | 5 ++--- tc/p_ip.c | 5 ++--- tc/p_ip6.c | 5 ++--- tc/p_tcp.c | 5 ++--- tc/p_udp.c | 5 ++--- 6 files changed, 12 insertions(+), 18 deletions(-)
tc/p_eth.c +2 -3
@@ -68,7 +68,6 @@ done: }struct m_pedit_util p_pedit_eth = { -NULL , -"eth" , - parse_eth, + .id ="eth" , + .parse_peopt = parse_eth, };
tc/p_icmp.c +2 -3
@@ -55,7 +55,6 @@ done: }struct m_pedit_util p_pedit_icmp = { -NULL , -"icmp" , - parse_icmp, + .id ="icmp" , + .parse_peopt = parse_icmp, };
tc/p_ip.c +2 -3
@@ -156,7 +156,6 @@ done: }struct m_pedit_util p_pedit_ip = { -NULL , -"ip" , - parse_ip, + .id ="ip" , + .parse_peopt = parse_ip, };
tc/p_ip6.c +2 -3
@@ -84,7 +84,6 @@ done: }struct m_pedit_util p_pedit_ip6 = { -NULL , -"ipv6" , - parse_ip6, + .id ="ipv6" , + .parse_peopt = parse_ip6, };
tc/p_tcp.c +2 -3
@@ -67,7 +67,6 @@ done:return res; }struct m_pedit_util p_pedit_tcp = { -NULL , -"tcp" , - parse_tcp, + .id ="tcp" , + .parse_peopt = parse_tcp, };
tc/p_udp.c +2 -3
@@ -61,7 +61,6 @@ done: }struct m_pedit_util p_pedit_udp = { -NULL , -"udp" , - parse_udp, + .id ="udp" , + .parse_peopt = parse_udp, };
Signature · 1 line
2.17.1
PATCH 22/22 rdma: make local functions static
In reply to Stephen HemmingerSeveral functions only used inside utils.c
--- rdma/rdma.h | 11 ----------- rdma/utils.c | 12 ++++++------ 2 files changed, 6 insertions(+), 17 deletions(-)
rdma/rdma.h +0 -11
@@ -74,13 +74,6 @@ struct rd_cmd {int (*func)(struct rd *rd); }; -/* -* Parser interface -*/ -bool rd_no_arg (struct rd *rd); -void rd_arg_inc (struct rd *rd); - -char *rd_argv (struct rd *rd);/* * Commands interface
@@ -95,8 +88,6 @@ void rd_free(struct rd *rd);int rd_set_arg_to_devname (struct rd *rd);int rd_argc (struct rd *rd); -int strcmpx (const char *str1,const char *str2); -/* * Device manipulation */
@@ -117,14 +108,12 @@ int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq);void rd_prepare_msg (struct rd *rd,uint32_t cmd,uint32_t *seq,uint16_t flags);int rd_dev_init_cb (const struct nlmsghdr *nlh,void *data);int rd_attr_cb (const struct nlattr *attr,void *data); -int rd_attr_check (const struct nlattr *attr,int *typep);/* * Print helpers */ void print_driver_table (struct rd *rd,struct nlattr *tb);void newline (struct rd *rd); -void newline_indent (struct rd *rd);#define MAX_LINE_LENGTH 80#endif /* _RDMA_TOOL_H_ */
rdma/utils.c +6 -6
@@ -18,14 +18,14 @@ int rd_argc(struct rd *rd)return rd->argc; } -char *rd_argv (struct rd *rd) +static char *rd_argv (struct rd *rd) {if (!rd_argc (rd))return NULL ;return *rd->argv; } -int strcmpx (const char *str1,const char *str2) +static int strcmpx (const char *str1,const char *str2) {if (strlen (str1) >strlen (str2))return -1 ;
@@ -39,7 +39,7 @@ static bool rd_argv_match(struct rd *rd, const char *pattern)return strcmpx (rd_argv (rd), pattern) ==0 ; } -void rd_arg_inc (struct rd *rd) +static void rd_arg_inc (struct rd *rd) {if (!rd_argc (rd))return ;
@@ -47,7 +47,7 @@ void rd_arg_inc(struct rd *rd) rd->argv++; } -bool rd_no_arg (struct rd *rd) +static bool rd_no_arg (struct rd *rd) {return rd_argc (rd) ==0 ; }
@@ -404,7 +404,7 @@ static const enum mnl_attr_data_type nldev_policy[RDMA_NLDEV_ATTR_MAX] = { [RDMA_NLDEV_ATTR_DRIVER_U64] = MNL_TYPE_U64, }; -int rd_attr_check (const struct nlattr *attr,int *typep) +static int rd_attr_check (const struct nlattr *attr,int *typep) {int type;
@@ -696,7 +696,7 @@ void newline(struct rd *rd)pr_out ("\n" ); } -void newline_indent (struct rd *rd) +static void newline_indent (struct rd *rd) {newline (rd);if (!rd->json_output)
Signature · 1 line
2.17.1
Re: [PATCH iproute2 22/22] rdma: make local functions static
Quoted 8 lines · Stephen Hemminger
Several functions only used inside
utils.cSigned-off-by Stephen Hemminger <[email protected]>--- rdma/rdma.h | 11 ----------- rdma/utils.c | 12 ++++++------ 2 files changed, 6 insertions(+), 17 deletions(-)
this patch breaks builds for me on Debian stretch:
rdma
CC rdma.o
CC utils.o
CC dev.o
CC link.o
dev.c: In function 'dev_set_name':
dev.c:248:6: warning: implicit declaration of function 'rd_no_arg'
[-Wimplicit-function-declaration]
if (rd_no_arg(rd)) {
^~~~~~~~~
dev.c:256:55: warning: implicit declaration of function 'rd_argv'
[-Wimplicit-function-declaration]
mnl_attr_put_strz(rd->nlh, RDMA_NLDEV_ATTR_DEV_NAME, rd_argv(rd));
^~~~~~~
dev.c:256:55: warning: passing argument 3 of 'mnl_attr_put_strz' makes
pointer from integer without a cast [-Wint-conversion]
In file included from rdma.h:19:0,
from dev.c:12:/usr/include/libmnl/libmnl.h:103:13: note: expected 'const char *' but argument is of type 'int'
extern void mnl_attr_put_strz(struct nlmsghdr *nlh, uint16_t type,
const char *data);
Reverting the patch fixes it.
Quoted 5 lines · Stephen Hemminger
Code cleanup including:
* make local functions static
* drop dead code
* whitespace code style cleanup
Hi Stephen:
You did not mark these for -next but that is typically where cleanups go. What is your intention?