lib utils: Use helpers to get AF bit/byte len
Subsystems (3)
PATCH 1/1 lib utils: Use helpers to get AF bit/byte len
From: Vadim Kochan <[email protected]>
Added funcs to get AF_XXX len in bit/bytes and replace places where switch(AF_XXX) is used for this.
Signed-off-by Vadim Kochan <[email protected]>
--- include/utils.h | 3 +++ ip/iproute.c | 22 ++++------------------ ip/iprule.c | 9 +-------- lib/utils.c | 58 +++++++++++++++++++++++++-------------------------------- 4 files changed, 33 insertions(+), 59 deletions(-)
include/utils.h +3 -0
@@ -101,6 +101,9 @@ extern int get_s8(__s8 *val, const char *arg, int base);extern char *hexstring_n2a (const __u8 *str,int len,char *buf,int blen);extern __u8 *hexstring_a2n (const char *str,__u8 *buf,int blen); +extern int af_bit_len (int af); +extern int af_byte_len (int af); +extern const char *format_host (int af,int len,const void *addr,char *buf,int buflen); extern const char *rt_addr_n2a(int af, const void *addr,
ip/iproute.c +4 -18
@@ -268,20 +268,6 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)return 1 ; } -static int calc_host_len (const struct rtmsg *r) -{ -if (r->rtm_family ==AF_INET6 ) -return 128 ; -else if (r->rtm_family ==AF_INET ) -return 32 ; -else if (r->rtm_family == AF_DECnet) -return 16 ; -else if (r->rtm_family ==AF_IPX ) -return 80 ; -else -return -1 ; -} -static void print_rtax_features (FILE *fp,unsigned int features) {unsigned int of = features;
@@ -302,7 +288,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)int len = n->nlmsg_len;struct rtattr * tb[RTA_MAX +1 ];char abuf[256 ]; -int host_len =-1 ; +int host_len;__u32 table;SPRINT_BUF (b1);static int hz;
@@ -320,7 +306,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)return -1 ; } - host_len =calc_host_len (r); + host_len =af_bit_len (r->rtm_family);parse_rtattr (tb,RTA_MAX ,RTM_RTA (r), len); table =rtm_get_table (r, tb);
@@ -1134,9 +1120,9 @@ static int save_route(const struct sockaddr_nl *who, struct nlmsghdr *n,int len = n->nlmsg_len;struct rtmsg *r =NLMSG_DATA (n);struct rtattr *tb[RTA_MAX +1 ]; -int host_len =-1 ; +int host_len; - host_len =calc_host_len (r); + host_len =af_bit_len (r->rtm_family); len -=NLMSG_LENGTH (sizeof (*r));parse_rtattr (tb,RTA_MAX ,RTM_RTA (r), len);
ip/iprule.c +1 -8
@@ -66,14 +66,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)parse_rtattr (tb,FRA_MAX ,RTM_RTA (r), len); -if (r->rtm_family ==AF_INET ) - host_len =32 ; -else if (r->rtm_family ==AF_INET6 ) - host_len =128 ; -else if (r->rtm_family == AF_DECnet) - host_len =16 ; -else if (r->rtm_family ==AF_IPX ) - host_len =80 ; + host_len =af_bit_len (r->rtm_family);if (n->nlmsg_type ==RTM_DELRULE )fprintf (fp,"Deleted " );
lib/utils.c +25 -33
82 lines not on this page · raw message
Signature · 1 line
2.2.2
Stephen Hemminger
AppliedQuoted 6 lines · On Sat, 28 Feb 2015 02:50:24 +0200 Vadim Kochan <[email protected]> wrote:
From: Vadim Kochan <[email protected]>
Added funcs to get
AF_XXXlen in bit/bytes and replace places whereswitch(AF_XXX)is used for this.Signed-off-by Vadim Kochan <[email protected]>
Applied, thanks