From: Stephen Hemminger Subject: [PATCH iproute2-next 2/9] iproute: make printing icmpv6 a function Date: Wed, 7 Feb 2018 09:10:10 -0800 Message-ID: <20180207171017.20558-3-sthemmin@microsoft.com> References: <20180207171017.20558-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]:42141 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754731AbeBGRKY (ORCPT ); Wed, 7 Feb 2018 12:10:24 -0500 Received: by mail-pf0-f196.google.com with SMTP id b25so578071pfd.9 for ; Wed, 07 Feb 2018 09:10:23 -0800 (PST) In-Reply-To: <20180207171017.20558-1-sthemmin@microsoft.com> Sender: netdev-owner@vger.kernel.org List-ID: Refactor to reduce size of print_route and improve readability. Signed-off-by: Stephen Hemminger --- ip/iproute.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/ip/iproute.c b/ip/iproute.c index 024f1cd87cbb..da6a4faed836 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -363,6 +363,25 @@ static void print_rt_flags(FILE *fp, unsigned int flags) fprintf(fp, "unresolved "); } +static void print_rt_pref(FILE *fp, unsigned int pref) +{ + fprintf(fp, "pref "); + + switch (pref) { + case ICMPV6_ROUTER_PREF_LOW: + fprintf(fp, "low"); + break; + case ICMPV6_ROUTER_PREF_MEDIUM: + fprintf(fp, "medium"); + break; + case ICMPV6_ROUTER_PREF_HIGH: + fprintf(fp, "high"); + break; + default: + fprintf(fp, "%u", pref); + } +} + int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE *)arg; @@ -740,25 +759,10 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) nh = RTNH_NEXT(nh); } } - if (tb[RTA_PREF]) { - unsigned int pref = rta_getattr_u8(tb[RTA_PREF]); - fprintf(fp, "pref "); + if (tb[RTA_PREF]) + print_rt_pref(fp, rta_getattr_u8(tb[RTA_PREF])); - switch (pref) { - case ICMPV6_ROUTER_PREF_LOW: - fprintf(fp, "low"); - break; - case ICMPV6_ROUTER_PREF_MEDIUM: - fprintf(fp, "medium"); - break; - case ICMPV6_ROUTER_PREF_HIGH: - fprintf(fp, "high"); - break; - default: - fprintf(fp, "%u", pref); - } - } if (tb[RTA_TTL_PROPAGATE]) { fprintf(fp, "ttl-propagate "); if (rta_getattr_u8(tb[RTA_TTL_PROPAGATE])) -- 2.15.1