From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [RFC iproute2-next 01/16] iproute: refactor printing flags Date: Thu, 1 Feb 2018 17:19:31 -0800 Message-ID: <20180202011946.21929-2-sthemmin@microsoft.com> References: <20180202011946.21929-1-sthemmin@microsoft.com> Cc: netdev@vger.kernel.org, Stephen Hemminger , Stephen Hemminger To: dsahern@gmail.com Return-path: Received: from mail-pf0-f196.google.com ([209.85.192.196]:41825 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751594AbeBBBUG (ORCPT ); Thu, 1 Feb 2018 20:20:06 -0500 Received: by mail-pf0-f196.google.com with SMTP id c6so16420593pfi.8 for ; Thu, 01 Feb 2018 17:20:06 -0800 (PST) In-Reply-To: <20180202011946.21929-1-sthemmin@microsoft.com> Sender: netdev-owner@vger.kernel.org List-ID: Both next hop and route need to decode flags. Signed-off-by: Stephen Hemminger --- ip/iproute.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/ip/iproute.c b/ip/iproute.c index bf886fda9d76..a343187ff90e 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -348,6 +348,22 @@ static void print_rtax_features(FILE *fp, unsigned int features) fprintf(fp, "0x%x ", of); } +static void print_rt_flags(FILE *fp, unsigned int flags) +{ + if (flags & RTNH_F_DEAD) + fprintf(fp, "dead "); + if (flags & RTNH_F_ONLINK) + fprintf(fp, "onlink "); + if (flags & RTNH_F_PERVASIVE) + fprintf(fp, "pervasive "); + if (flags & RTNH_F_OFFLOAD) + fprintf(fp, "offload "); + if (flags & RTNH_F_LINKDOWN) + fprintf(fp, "linkdown "); + if (flags & RTNH_F_UNRESOLVED) + fprintf(fp, "unresolved "); +} + int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE *)arg; @@ -479,20 +495,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) } if (tb[RTA_PRIORITY] && filter.metricmask != -1) fprintf(fp, "metric %u ", rta_getattr_u32(tb[RTA_PRIORITY])); - if (r->rtm_flags & RTNH_F_DEAD) - fprintf(fp, "dead "); - if (r->rtm_flags & RTNH_F_ONLINK) - fprintf(fp, "onlink "); - if (r->rtm_flags & RTNH_F_PERVASIVE) - fprintf(fp, "pervasive "); - if (r->rtm_flags & RTNH_F_OFFLOAD) - fprintf(fp, "offload "); - if (r->rtm_flags & RTM_F_NOTIFY) - fprintf(fp, "notify "); - if (r->rtm_flags & RTNH_F_LINKDOWN) - fprintf(fp, "linkdown "); - if (r->rtm_flags & RTNH_F_UNRESOLVED) - fprintf(fp, "unresolved "); + + print_rt_flags(fp, r->rtm_flags); + if (tb[RTA_MARK]) { unsigned int mark = rta_getattr_u32(tb[RTA_MARK]); @@ -729,16 +734,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) fprintf(fp, "weight %d ", nh->rtnh_hops+1); } - if (nh->rtnh_flags & RTNH_F_DEAD) - fprintf(fp, "dead "); - if (nh->rtnh_flags & RTNH_F_ONLINK) - fprintf(fp, "onlink "); - if (nh->rtnh_flags & RTNH_F_PERVASIVE) - fprintf(fp, "pervasive "); - if (nh->rtnh_flags & RTNH_F_OFFLOAD) - fprintf(fp, "offload "); - if (nh->rtnh_flags & RTNH_F_LINKDOWN) - fprintf(fp, "linkdown "); + + print_rt_flags(fp, nh->rtnh_flags); + len -= NLMSG_ALIGN(nh->rtnh_len); nh = RTNH_NEXT(nh); } -- 2.15.1