From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [RFC iproute2-next 02/16] iproute: make printing icmpv6 a function Date: Thu, 1 Feb 2018 17:19:32 -0800 Message-ID: <20180202011946.21929-3-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-f193.google.com ([209.85.192.193]:43646 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751707AbeBBBUH (ORCPT ); Thu, 1 Feb 2018 20:20:07 -0500 Received: by mail-pf0-f193.google.com with SMTP id y26so16417934pfi.10 for ; Thu, 01 Feb 2018 17:20:07 -0800 (PST) In-Reply-To: <20180202011946.21929-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 a343187ff90e..472e4135c5d9 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -364,6 +364,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; @@ -741,25 +760,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