From patchwork Wed Feb 7 17:10:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 870523 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="0CdMitTi"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zc7BJ2LrTz9s71 for ; Thu, 8 Feb 2018 04:10:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754761AbeBGRK3 (ORCPT ); Wed, 7 Feb 2018 12:10:29 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:40749 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754731AbeBGRK1 (ORCPT ); Wed, 7 Feb 2018 12:10:27 -0500 Received: by mail-pg0-f66.google.com with SMTP id g2so526362pgn.7 for ; Wed, 07 Feb 2018 09:10:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=60X2Zhf1XCMOMleJyFAc9R9LLUCyNQ3NHcWPiJcWAnU=; b=0CdMitTi7nmEQVfa9j4CMSPYabIt9kNrVI2UXuX/UaqUf57OPyC5s2Er2KSjGLpAcv Udf6nT07h6x7eRJqe/WgNCxVjVOOrEsGHnAXM/ifmXOiB/jL9se87xkTVtWFiwyQDPzT TaUNooxdHiFhUQ8w3hkErpPmyQ9IbNhXdhPy6dPsg9gEXhZFKILA6gjGP0bdDY2nQeJk NYwQ0zTe8Hg3vCDrdsGWuRyu8u+l1blIeMfDGme8XHZLtI6tsDUmT0OK+P0TvDrLD2Rn zqQC/WJLUexeoxv9vL4T+ZlhKtcZmWJYq2uyccy51VGu/TcVdkVZK6Gs/QyTGw+H1Rwr FvLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=60X2Zhf1XCMOMleJyFAc9R9LLUCyNQ3NHcWPiJcWAnU=; b=p1c/C47gq2wGLWwcmtYUStwd6BXf80xb8vh7wKYWn5vaBCuM3om2bgRjAT/x4oeOhz q10w5WV110t7xObdAqB6K0dCbwPH+x7evu41261CwSenK9TFEUqoHfe85b1t8LzaTXB5 rfA5WjarsziSxMej+nWaBWOx/OXPUCuAAt2YueyueFvbn1O1sz5nqnQ0YhqBlftwkc6l 4uI0/JNWhYAyMinwUP1AQklrxnWDgtg48TxEUb/+VyI7Ma5RDUnZM48YyuqH6GWH0288 WnKAq1AWZdchKPbDlCUu/YYJecNxVIjEesw7q3tuCzup7Us39LP4p/VHpatZj6IJ68yJ 4OMQ== X-Gm-Message-State: APf1xPCOaSNOiswEWWSpMCnE7g3vLq3TaIVPXNoLQ1xaIx/hbUmsvZtJ vhcxUvQ8rrEFe24ugYHQEJ/lmA== X-Google-Smtp-Source: AH8x227Sfs24mFPA55jB8eAzhCiQ/b2gGH+qQehdDE2g+V9dKC/YInPp6FD3Dhx5H2GgC93IP30W7Q== X-Received: by 10.99.165.86 with SMTP id r22mr5447121pgu.1.1518023426249; Wed, 07 Feb 2018 09:10:26 -0800 (PST) Received: from xeon-e3.lan (204-195-71-95.wavecable.com. [204.195.71.95]) by smtp.gmail.com with ESMTPSA id f80sm2684344pff.81.2018.02.07.09.10.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Feb 2018 09:10:24 -0800 (PST) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: dsahern@gmail.com Cc: netdev@vger.kernel.org, Stephen Hemminger , Stephen Hemminger Subject: [PATCH iproute2-next 4/9] iproute: refactor cacheinfo printing Date: Wed, 7 Feb 2018 09:10:12 -0800 Message-Id: <20180207171017.20558-5-sthemmin@microsoft.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180207171017.20558-1-sthemmin@microsoft.com> References: <20180207171017.20558-1-sthemmin@microsoft.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Make common function for decoding cacheinfo. This code may print more info than old version in some cases. Signed-off-by: Stephen Hemminger --- ip/iproute.c | 78 +++++++++++++++++++++++++----------------------------------- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/ip/iproute.c b/ip/iproute.c index 7317bf116e2c..a5e4c926e617 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -419,6 +419,31 @@ static void print_cache_flags(FILE *fp, __u32 flags) fprintf(fp, "%#x> ", flags); } +static void print_rta_cacheinfo(FILE *fp, const struct rta_cacheinfo *ci) +{ + static int hz; + + if (!hz) + hz = get_user_hz(); + if (ci->rta_expires != 0) + fprintf(fp, "expires %dsec ", ci->rta_expires/hz); + if (ci->rta_error != 0) + fprintf(fp, "error %d ", ci->rta_error); + if (show_stats) { + if (ci->rta_clntref) + fprintf(fp, "users %d ", ci->rta_clntref); + if (ci->rta_used != 0) + fprintf(fp, "used %d ", ci->rta_used); + if (ci->rta_lastuse != 0) + fprintf(fp, "age %dsec ", ci->rta_lastuse/hz); + } + if (ci->rta_id) + fprintf(fp, "ipid 0x%04x ", ci->rta_id); + if (ci->rta_ts || ci->rta_tsage) + fprintf(fp, "ts 0x%x tsage %dsec ", + ci->rta_ts, ci->rta_tsage); +} + int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE *)arg; @@ -430,7 +455,6 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) int ret; SPRINT_BUF(b1); - static int hz; if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) { fprintf(stderr, "Not a route: %08x %08x %08x\n", @@ -584,56 +608,18 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if ((r->rtm_flags & RTM_F_CLONED) && r->rtm_family == AF_INET) { print_cache_flags(fp, r->rtm_flags); - if (tb[RTA_CACHEINFO]) { - struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]); + if (tb[RTA_CACHEINFO]) + print_rta_cacheinfo(fp, RTA_DATA(tb[RTA_CACHEINFO])); - if (!hz) - hz = get_user_hz(); - if (ci->rta_expires != 0) - fprintf(fp, "expires %dsec ", ci->rta_expires/hz); - if (ci->rta_error != 0) - fprintf(fp, "error %d ", ci->rta_error); - if (show_stats) { - if (ci->rta_clntref) - fprintf(fp, "users %d ", ci->rta_clntref); - if (ci->rta_used != 0) - fprintf(fp, "used %d ", ci->rta_used); - if (ci->rta_lastuse != 0) - fprintf(fp, "age %dsec ", ci->rta_lastuse/hz); - } - if (ci->rta_id) - fprintf(fp, "ipid 0x%04x ", ci->rta_id); - if (ci->rta_ts || ci->rta_tsage) - fprintf(fp, "ts 0x%x tsage %dsec ", - ci->rta_ts, ci->rta_tsage); - } } else if (r->rtm_family == AF_INET6) { - struct rta_cacheinfo *ci = NULL; + + if (r->rtm_flags & RTM_F_CLONED) + fprintf(fp, "%s cache ", _SL_); if (tb[RTA_CACHEINFO]) - ci = RTA_DATA(tb[RTA_CACHEINFO]); - if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) { - if (!hz) - hz = get_user_hz(); - if (r->rtm_flags & RTM_F_CLONED) - fprintf(fp, "%s cache ", _SL_); - if (ci->rta_expires) - fprintf(fp, "expires %dsec ", ci->rta_expires/hz); - if (ci->rta_error != 0) - fprintf(fp, "error %d ", ci->rta_error); - if (show_stats) { - if (ci->rta_clntref) - fprintf(fp, "users %d ", ci->rta_clntref); - if (ci->rta_used != 0) - fprintf(fp, "used %d ", ci->rta_used); - if (ci->rta_lastuse != 0) - fprintf(fp, "age %dsec ", ci->rta_lastuse/hz); - } - } else if (ci) { - if (ci->rta_error != 0) - fprintf(fp, "error %d ", ci->rta_error); - } + print_rta_cacheinfo(fp, RTA_DATA(tb[RTA_CACHEINFO])); } + if (tb[RTA_METRICS]) { int i; unsigned int mxlock = 0;