From patchwork Wed Sep 1 20:46:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 12470305 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEF8BC4320A for ; Wed, 1 Sep 2021 20:47:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A090B610C7 for ; Wed, 1 Sep 2021 20:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232629AbhIAUsE (ORCPT ); Wed, 1 Sep 2021 16:48:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231398AbhIAUsC (ORCPT ); Wed, 1 Sep 2021 16:48:02 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9F43C061575 for ; Wed, 1 Sep 2021 13:47:05 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id f11-20020a17090aa78b00b0018e98a7cddaso620996pjq.4 for ; Wed, 01 Sep 2021 13:47:05 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=BidK7xPrerg6Gymyud5dTvFiiB0Y7sTgtHAJBav52rA=; b=DDGXFPWHTCNljHa6bWc11tyFLy/JTVpipElLG2XDKcH/qXhJq9mGfDUfbJcIjdGsT8 I5ZPSf+O9lPL64NL6f/G/DGt8Wa1vqCiXSQ6P+6KXb3nPdWvbjILNHZsJHlSf80R8hla vTrx8hbPYkOhigARP7g/W3qzOG82rqLhMJi7b4jDkvf61YEEKPAEYzVLpTJFknEyFnf/ x/sVElQLdwGCpdp83DDcNM/IF9tXrvnTJTCIBQ+O9ZSOcHOqGWZ1GjsKzTm2/Fv/eU38 T+jdUSuQBjg+7oGmgiOJVvuCaIGpXF2atAlnbrGsHLdkdGP/cUBOim/FM9u0JOgVYVK6 tAFA== 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:mime-version:content-transfer-encoding; bh=BidK7xPrerg6Gymyud5dTvFiiB0Y7sTgtHAJBav52rA=; b=chpWsfKCCKXrNpnPVTaKHXcjQUcFkRPPxW3+3D7zkA+jGPQwbGCawdgQsDPxpKxsWO 7WwoS7BuZNqcWAeTp7vUzO7NMKaLr6n0oxIzGU21xW7ijbTc6Qp1BABfe62EZAjfmV8D TirvKJRVbmtrLpqNVjH6135HaLPJLx1SPulckUZLnFbn7tOCedh3oCIw+mMb9YJVE/j9 S9R6H1l3p0Dlyz/WXArsHqhXiM4in+oSJBNAX0VWsiEkYnDo+VdRSeZ4AW+qQxcFZtbF FoIPiF+O+Tm8GhWTZUkWgyYrZEqnHUJERsVNFMBDFhsD7MmVlnVR9q8fPiznJE1MBoe6 eLvw== X-Gm-Message-State: AOAM533hvY1vX0fHSSxEyTgaHmrK53rHV7iVoHJVATd19YKS/VaaXTxI R0ckPtk9nzPRk0HOnt5GCWr5y1tA3Zx2mQ== X-Google-Smtp-Source: ABdhPJyCioJU7aOQ59w45tBmv4xLnYD1LbF7CPK408ZkAiB8LZxYiAieo5S16ZrzO1R+JnPVJ1N+4g== X-Received: by 2002:a17:90b:88e:: with SMTP id bj14mr1256184pjb.115.1630529224705; Wed, 01 Sep 2021 13:47:04 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id g26sm565073pgb.45.2021.09.01.13.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 13:47:04 -0700 (PDT) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger Subject: [PATCH iproute2-next 1/4] ip: remove old rtpr script Date: Wed, 1 Sep 2021 13:46:58 -0700 Message-Id: <20210901204701.19646-2-sthemmin@microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210901204701.19646-1-sthemmin@microsoft.com> References: <20210901204701.19646-1-sthemmin@microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Stephen Hemminger This script was a one off hack for a special case. Now that ip commands have better formatting, there is no real reason for it. Signed-off-by: Stephen Hemminger --- ip/Makefile | 2 +- ip/rtpr | 5 ----- man/man8/rtpr.8 | 25 ------------------------- 3 files changed, 1 insertion(+), 31 deletions(-) delete mode 100755 ip/rtpr delete mode 100644 man/man8/rtpr.8 diff --git a/ip/Makefile b/ip/Makefile index 2ae9df89b5a6..a3b4249e7e06 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -18,7 +18,7 @@ RTMONOBJ=rtmon.o include ../config.mk ALLOBJ=$(IPOBJ) $(RTMONOBJ) -SCRIPTS=ifcfg rtpr routel routef +SCRIPTS=ifcfg routel routef TARGETS=ip rtmon all: $(TARGETS) $(SCRIPTS) diff --git a/ip/rtpr b/ip/rtpr deleted file mode 100755 index 7e48674bcf53..000000000000 --- a/ip/rtpr +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/sh -# SPDX-License-Identifier: GPL-2.0 - -exec tr "[\\\\]" "[ -]" diff --git a/man/man8/rtpr.8 b/man/man8/rtpr.8 deleted file mode 100644 index 87f291ab50ac..000000000000 --- a/man/man8/rtpr.8 +++ /dev/null @@ -1,25 +0,0 @@ -.TH RTPR 8 "18 September, 2015" - -.SH NAME -rtpr \- replace backslashes with newlines. - -.SH DESCRIPTION -.B rtpr -is a trivial shell script which converts backslashes in standard input to newlines. It's sole purpose is to be fed with input from -.B ip -when executed with it's -.B --oneline -flag. - -.SH EXAMPLES -.TP -ip --oneline address show | rtpr -Undo oneline converted -.B ip-address -output. - -.SH SEE ALSO -.BR ip (8) - -.SH AUTHORS -Stephen Hemminger From patchwork Wed Sep 1 20:46:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 12470307 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E31A3C432BE for ; Wed, 1 Sep 2021 20:47:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4F6B61053 for ; Wed, 1 Sep 2021 20:47:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234133AbhIAUsF (ORCPT ); Wed, 1 Sep 2021 16:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231735AbhIAUsE (ORCPT ); Wed, 1 Sep 2021 16:48:04 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02BB8C061575 for ; Wed, 1 Sep 2021 13:47:07 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id u11-20020a17090adb4b00b00181668a56d6so621169pjx.5 for ; Wed, 01 Sep 2021 13:47:06 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=SCHnJfUNurDt0jhBUdRhrGAXCjDumm2atE4LQxnOY1I=; b=hdg6pT0eC8J6wQxw1cuE+MCnMOm2HY1ZbrbY0vtMfR2g9osNvPrqrWzaDgoUX8M37R Ye/7pE9XMxAd/kXBOxvyUqRe3kQANrD24b0WI/h6O1UjmNIVr6v/iy56tozc/5+M84/m 40zgGq4FPb7HseHK2KVALnAA8yNnHMwrbZcgvNBco8pbZ0nLzgK7DPNXvswIegw2fOgx pqn6xuwZe3ZUvNTYkrj7BBYmCk+H71mISVDwJrbED6yGNXruOXpINAheRMje7WO2Sexe Tfr/U+oQD2GdcvrBqKqxMNn/mlN62hiJSSBzv3bVOMabKVbT5wNpHq72HmDayX/sLG/s M1ag== 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:mime-version:content-transfer-encoding; bh=SCHnJfUNurDt0jhBUdRhrGAXCjDumm2atE4LQxnOY1I=; b=ORvnj3zxGmplKFc/fYXxAtrznRKwLHQ053PRa+FZsFQT2mUROVfO+9hTX5b513n+oU 26ElFLYuBL6Y2cbl0ZlMpUCAkyJvr+1VPrb057j08TDQLogAwbXDdOexAzQ8R9rNh9m3 QJzGwEe2DK6Z5zgtBzKsnhPhnPbL7KlC/UrfcxYnUo8C1kl2EvTuyx7simQgCr3HXz5k t0jRLt2oyR1k/c+aqybqB0ucvc+yLKHF5ceLsHZQXDYMzxEqcvbQHGkFUbAlWuFMftuQ kfyZjVa0Z5KS/9KtdOhuL1PfdzC19QO/lzrXZW7iWP63sP/H1rp1AhbDlJ3NLpAzUiKF awDw== X-Gm-Message-State: AOAM533ihbawj8B7sLmxUcTYn6Kh20fi8xQrzDOEmndbee6rjg0vrJVE W72QeQrJdYhFRKc89RtWFrXX8Rw5sD/Lrg== X-Google-Smtp-Source: ABdhPJxj5eISC6B7Ty9DODIYtwh244k5X8epxVd1q3Mo4XP7p6j2esM9nGYyBfhRoPAvBXcfUl2+nw== X-Received: by 2002:a17:90a:448f:: with SMTP id t15mr1212023pjg.21.1630529225935; Wed, 01 Sep 2021 13:47:05 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id g26sm565073pgb.45.2021.09.01.13.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 13:47:05 -0700 (PDT) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger Subject: [PATCH iproute2-next 2/4] ip: remove ifcfg script Date: Wed, 1 Sep 2021 13:46:59 -0700 Message-Id: <20210901204701.19646-3-sthemmin@microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210901204701.19646-1-sthemmin@microsoft.com> References: <20210901204701.19646-1-sthemmin@microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Stephen Hemminger This script was from olden days of ifcfg. I don't see any distribution using it and it is time to put it out to pasture. Signed-off-by: Stephen Hemminger --- ip/Makefile | 2 +- ip/ifcfg | 150 ----------------------------------------------- man/man8/ifcfg.8 | 48 --------------- 3 files changed, 1 insertion(+), 199 deletions(-) delete mode 100755 ip/ifcfg delete mode 100644 man/man8/ifcfg.8 diff --git a/ip/Makefile b/ip/Makefile index a3b4249e7e06..e27dfa097877 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -18,7 +18,7 @@ RTMONOBJ=rtmon.o include ../config.mk ALLOBJ=$(IPOBJ) $(RTMONOBJ) -SCRIPTS=ifcfg routel routef +SCRIPTS=routel routef TARGETS=ip rtmon all: $(TARGETS) $(SCRIPTS) diff --git a/ip/ifcfg b/ip/ifcfg deleted file mode 100755 index 5b34decd4480..000000000000 --- a/ip/ifcfg +++ /dev/null @@ -1,150 +0,0 @@ -#! /bin/sh -# SPDX-License-Identifier: GPL-2.0 - -CheckForwarding () { - local sbase fwd - sbase=/proc/sys/net/ipv4/conf - fwd=0 - if [ -d $sbase ]; then - for dir in $sbase/*/forwarding; do - fwd=$(( fwd + $(cat "$dir") )) - done - else - fwd=2 - fi - return $fwd -} - -RestartRDISC () { - killall -HUP rdisc || rdisc -fs -} - -ABCMaskLen () { - local class; - - class=${1%%.*} - if [ "$1" = "" -o $class -eq 0 -o $class -ge 224 ]; then return 0 - elif [ $class -ge 224 ]; then return 0 - elif [ $class -ge 192 ]; then return 24 - elif [ $class -ge 128 ]; then return 16 - else return 8; fi -} - -label="label $1" -ldev="$1" -dev=${1%:*} -if [ "$dev" = "" -o "$1" = "help" ]; then - echo "Usage: ifcfg DEV [[add|del [ADDR[/LEN]] [PEER] | stop]" 1>&2 - echo " add - add new address" 1>&2 - echo " del - delete address" 1>&2 - echo " stop - completely disable IP" 1>&2 - exit 1 -fi -shift - -CheckForwarding -fwd=$? -if [ $fwd -ne 0 ]; then - echo "Forwarding is ON or its state is unknown ($fwd). OK, No RDISC." 1>&2 -fi - - -deleting=0 -case "$1" in -add) shift ;; -stop) - if [ "$ldev" != "$dev" ]; then - echo "Cannot stop alias $ldev" 1>&2 - exit 1; - fi - ip -4 addr flush dev $dev $label || exit 1 - if [ $fwd -eq 0 ]; then RestartRDISC; fi - exit 0 ;; -del*) - deleting=1; shift ;; -*) -esac - -ipaddr= -pfxlen= -if [ "$1" != "" ]; then - ipaddr=${1%/*} - if [ "$1" != "$ipaddr" ]; then - pfxlen=${1#*/} - fi - if [ "$ipaddr" = "" ]; then - echo "$1 is bad IP address." 1>&2 - exit 1 - fi -fi -shift - -peer=$1 -if [ "$peer" != "" ]; then - if [ "$pfxlen" != "" -a "$pfxlen" != "32" ]; then - echo "Peer address with non-trivial netmask." 1>&2 - exit 1 - fi - pfx="$ipaddr peer $peer" -else - if [ "$ipaddr" = "" ]; then - echo "Missing IP address argument." 1>&2 - exit 1 - fi - if [ "$pfxlen" = "" ]; then - ABCMaskLen $ipaddr - pfxlen=$? - fi - pfx="$ipaddr/$pfxlen" -fi - -if [ "$ldev" = "$dev" -a "$ipaddr" != "" ]; then - label= -fi - -if [ $deleting -ne 0 ]; then - ip addr del $pfx dev $dev $label || exit 1 - if [ $fwd -eq 0 ]; then RestartRDISC; fi - exit 0 -fi - - -if ! ip link set up dev $dev ; then - echo "Error: cannot enable interface $dev." 1>&2 - exit 1 -fi -if [ "$ipaddr" = "" ]; then exit 0; fi - -if ! arping -q -c 2 -w 3 -D -I $dev $ipaddr ; then - echo "Error: some host already uses address $ipaddr on $dev." 1>&2 - exit 1 -fi - -if ! ip address add $pfx brd + dev $dev $label; then - echo "Error: failed to add $pfx on $dev." 1>&2 - exit 1 -fi - -arping -q -A -c 1 -I $dev $ipaddr -noarp=$? -( sleep 2 ; - arping -q -U -c 1 -I $dev $ipaddr ) >/dev/null 2>&1 /dev/null 2>&1 -ip route add unreachable 255.255.255.255 >/dev/null 2>&1 -if [ "`ip link ls $dev | grep -c MULTICAST`" -ge 1 ]; then - ip route add 224.0.0.0/4 dev $dev scope global >/dev/null 2>&1 -fi - -if [ $fwd -eq 0 ]; then - if [ $noarp -eq 0 ]; then - ip ro append default dev $dev metric 30000 scope global - elif [ "$peer" != "" ]; then - if ping -q -c 2 -w 4 $peer ; then - ip ro append default via $peer dev $dev metric 30001 - fi - fi - RestartRDISC -fi - -exit 0 diff --git a/man/man8/ifcfg.8 b/man/man8/ifcfg.8 deleted file mode 100644 index 1a3786c1b0d9..000000000000 --- a/man/man8/ifcfg.8 +++ /dev/null @@ -1,48 +0,0 @@ -.TH IFCFG 8 "September 24 2009" "iproute2" "Linux" -.SH NAME -ifcfg \- simplistic script which replaces ifconfig IP management -.SH SYNOPSIS -.ad l -.in +8 -.ti -8 -.B ifcfg -.RI "[ " DEVICE " ] [ " command " ] " ADDRESS " [ " PEER " ] " -.sp - -.SH DESCRIPTION -This manual page documents briefly the -.B ifcfg -command. -.PP -This is a simplistic script replacing one option of -.B ifconfig -, namely, IP address management. It not only adds -addresses, but also carries out Duplicate Address Detection RFC-DHCP, -sends unsolicited ARP to update the caches of other hosts sharing -the interface, adds some control routes and restarts Router Discovery -when it is necessary. - -.SH IFCONFIG - COMMAND SYNTAX - -.SS -.TP -.B DEVICE -- it may have alias, suffix, separated by colon. - -.TP -.B command -- add, delete or stop. - -.TP -.B ADDRESS -- optionally followed by prefix length. - -.TP -.B peer -- optional peer address for pointpoint interfaces. - -.SH NOTES -This script is not suitable for use with IPv6. - -.SH SEE ALSO -.RB "IP Command reference " ip-cref.ps From patchwork Wed Sep 1 20:47:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 12470309 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 651E1C4320A for ; Wed, 1 Sep 2021 20:47:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4611761053 for ; Wed, 1 Sep 2021 20:47:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238362AbhIAUsL (ORCPT ); Wed, 1 Sep 2021 16:48:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233905AbhIAUsF (ORCPT ); Wed, 1 Sep 2021 16:48:05 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C4C3C061764 for ; Wed, 1 Sep 2021 13:47:08 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id x16so799242pfh.2 for ; Wed, 01 Sep 2021 13:47:08 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=0WJ+KTbtxL5NhEb3PLLI/YCaMbaL5oHeHgo83ZaRNSU=; b=d2Vt+IYj0gjOjykYd/5TUPMQ3QnbWFFhYchD8hBemCfeSsGoO3r67u0QxszNLEEGJ5 L1RbVETlxD9KXUmBhsBLKzDivWCS2wBHEfeH2NPUr4+3MW0gV0UyvdZCGVV5q281qMLx +oYF/noRyJbbsfSCfe+R1VnvGoDqQXtXAZ0DisI7NE20/P1tket5XASyYjTmf0YvYWN1 CdJqmbKiAicU1L1C/pWzp7SMN2zmPXX5f6nmAuh0wgoBZT9ddU+++7ikIBkEr7ih2j2O jHyAXZ3PvMxtY4D6xVHvg3U/wwjMH3A6myPywLoloqI/MuWWV6Fq3v8jmJCn9IAqEAX9 eE2Q== 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:mime-version:content-transfer-encoding; bh=0WJ+KTbtxL5NhEb3PLLI/YCaMbaL5oHeHgo83ZaRNSU=; b=rISnTv8/Yasw0zmzvnw2WjHWwLva1tJIRhgVyd/ShxNU8Gl0ki80g6t1DCIbZxdTZZ 123wPI6BW4Fwbo2cFJjRGx2v/aEtCzw4h1ooiCrKC6k4iXKnPouANU3NHHa14Yn0dfjY VtqQIKDC9hEWPvbTtoClm23rNCOrdyVgEjVsuM/f6KQFcAV/RBSjlS3tHX541BJNCiw2 Uu+5SA6x73mF06Tmy1au5co5tAWI1khGObaRn0b4bokgLQmfdlLk3T2xquFLWXMOzY7A fLaJ9H/RAwgQitIE47um94IwpdRG6e/RoJdovrVsUUz8yJq8oJ4/JeNFFGCkw5KcG4Yb UBKQ== X-Gm-Message-State: AOAM531bsa+7dfxdXz40ZgxsdCoqlPVJtxSESqWwX0IA+fxY2BTj77tv itRt1CNGrtjvtTgnf5x+xrhMhAuPSiv8EA== X-Google-Smtp-Source: ABdhPJz1N8/pTPuuQvqJKdukxWu0WVCTBNRLidVf/xlXR8fkGwdpUNfA+fx3+SFUPkUfdo2a06Amhw== X-Received: by 2002:a63:1247:: with SMTP id 7mr867925pgs.366.1630529227221; Wed, 01 Sep 2021 13:47:07 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id g26sm565073pgb.45.2021.09.01.13.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 13:47:06 -0700 (PDT) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger Subject: [PATCH iproute2-next 3/4] ip: remove routef script Date: Wed, 1 Sep 2021 13:47:00 -0700 Message-Id: <20210901204701.19646-4-sthemmin@microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210901204701.19646-1-sthemmin@microsoft.com> References: <20210901204701.19646-1-sthemmin@microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Stephen Hemminger This script is old and limited to IPv4. Using ip route command directly is better option. Signed-off-by: Stephen Hemminger --- ip/Makefile | 2 +- ip/routef | 10 ---------- man/man8/routef.8 | 1 - man/man8/routel.8 | 12 ++---------- 4 files changed, 3 insertions(+), 22 deletions(-) delete mode 100755 ip/routef delete mode 100644 man/man8/routef.8 diff --git a/ip/Makefile b/ip/Makefile index e27dfa097877..bcc5f816b319 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -18,7 +18,7 @@ RTMONOBJ=rtmon.o include ../config.mk ALLOBJ=$(IPOBJ) $(RTMONOBJ) -SCRIPTS=routel routef +SCRIPTS=routel TARGETS=ip rtmon all: $(TARGETS) $(SCRIPTS) diff --git a/ip/routef b/ip/routef deleted file mode 100755 index c251e7b87efd..000000000000 --- a/ip/routef +++ /dev/null @@ -1,10 +0,0 @@ -#! /bin/sh -# SPDX-License-Identifier: GPL-2.0 - -if [ -z "$*" ] ; then - exec ip -4 ro flush scope global type unicast -else - echo "Usage: routef" - echo - echo "This script will flush the IPv4 routing table" -fi diff --git a/man/man8/routef.8 b/man/man8/routef.8 deleted file mode 100644 index c2a70598923f..000000000000 --- a/man/man8/routef.8 +++ /dev/null @@ -1 +0,0 @@ -.so man8/routel.8 diff --git a/man/man8/routel.8 b/man/man8/routel.8 index 2270eacb51fb..b32eeafcf69d 100644 --- a/man/man8/routel.8 +++ b/man/man8/routel.8 @@ -2,21 +2,13 @@ .SH "NAME" .LP routel \- list routes with pretty output format -.br -routef \- flush routes .SH "SYNTAX" .LP routel [\fItablenr\fP [\fIraw ip args...\fP]] -.br -routef .SH "DESCRIPTION" .LP -These programs are a set of helper scripts you can use instead of raw iproute2 commands. -.br -The routel script will list routes in a format that some might consider easier to interpret then the ip route list equivalent. -.br -The routef script does not take any arguments and will simply flush the routing table down the drain. Beware! This means deleting all routes which will make your network unusable! - +The routel script will list routes in a format that some might consider easier to interpret +then the ip route list equivalent. .SH "AUTHORS" .LP The routel script was written by Stephen R. van den Berg , 1999/04/18 and donated to the public domain. From patchwork Wed Sep 1 20:47:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 12470311 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E93D3C432BE for ; Wed, 1 Sep 2021 20:47:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB129610A2 for ; Wed, 1 Sep 2021 20:47:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239018AbhIAUsN (ORCPT ); Wed, 1 Sep 2021 16:48:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233327AbhIAUsI (ORCPT ); Wed, 1 Sep 2021 16:48:08 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4473DC061575 for ; Wed, 1 Sep 2021 13:47:09 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 8so724705pga.7 for ; Wed, 01 Sep 2021 13:47:09 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=FubUooDS2WKMSYk2DOHk3EgWqp53DYzfL986g15sWe4=; b=G25M0gwUD74aqihsxJCooO/Id/T+ZQ79GNmWjRK2WZjTFAEmoYVEt81Ubv+GATYUnl pZB0nlmY6NEP7tzQANsVcERDn4o2dBnXzAdM1NUL0EEJLi7udT11hJ/nwks+IdT5LoK7 sqmgyvJQPSTUO9lbMzX2j4l8nOV1HQKKC7U3m1yN3Tx3upcZokMJklZxWEtSt9nnLgNL aaqCwyIF3k1owPVrWW+q5/uYC5A9qryezAom+uYAQhZsYxdcaPT2IMzWqX73OOHKXdm8 tAKf9NyZ3rzyPMkHfnfgYX4Y7ok74jtPip8Gqm3pVCWO8Fg4VtcUr7zKyTSnp/3IT7n1 DfOA== 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:mime-version:content-transfer-encoding; bh=FubUooDS2WKMSYk2DOHk3EgWqp53DYzfL986g15sWe4=; b=EjLx6DS2UA9oSvNhrxTQq2bbv0gB0nAjPm4CanlrnVYSWaBMAwgCpqKXscBc+8msq8 F+MuuPTDOi/u2nx74G+0a3XyFky42G5dlWX8ipnuYNCb+U+U56E6zgdo5Ry6ydFzEQuD N/YU59u/x7BhLJeoLkn5JyrgfeRIXdXvb+L6X6q7WO8Q8WysGruCJlub+kOfv/eqlQzo uFrLRy+xcm7TbsXCHlNVDUwnNoeEE/Orjw1x1sJluKSRIKucHpayh5DeB1rRk4+tNLiZ qHnDbQvjsdLX1Ue0hsMVKYMh4c+4+hJzn07OUY0bZ9cfyP6Qkxni/cNwPHCAOqqqSPn1 OFTw== X-Gm-Message-State: AOAM532JHoPFJBgAXiZPl+HQ4ja2sFS3nmWaRC7VrdOE/9is2ZiybbTc BD+SSdF5IUEW8hE7ABMIH9gF+A/+2XtVbw== X-Google-Smtp-Source: ABdhPJxm5XH/JYseoOdaSfSKFZeana8XTW5b4KHzfwIMjPtf0arhEAeDTLupj+fL2azoAAXllYaD0A== X-Received: by 2002:a65:47c6:: with SMTP id f6mr876471pgs.450.1630529228306; Wed, 01 Sep 2021 13:47:08 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id g26sm565073pgb.45.2021.09.01.13.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 13:47:07 -0700 (PDT) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger Subject: [PATCH iproute2-next 4/4] ip: rewrite routel in python Date: Wed, 1 Sep 2021 13:47:01 -0700 Message-Id: <20210901204701.19646-5-sthemmin@microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210901204701.19646-1-sthemmin@microsoft.com> References: <20210901204701.19646-1-sthemmin@microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Stephen Hemminger Not sure if anyone uses the routel script. The script was a combination of ip route, shell and awk doing command scraping. It is now possible to do this much better using the JSON output formats and python. Rewriting also fixes the bug where the old script could not parse the current output format. At the end was getting: /usr/bin/routel: 48: shift: can't shift that many The new script also has IPv6 as option. Signed-off-by: Stephen Hemminger --- ip/routel | 124 +++++++++++++++++++++------------------------- man/man8/routel.8 | 30 ++++++++--- 2 files changed, 79 insertions(+), 75 deletions(-) diff --git a/ip/routel b/ip/routel index 7056886d0f94..09a901267fb3 100755 --- a/ip/routel +++ b/ip/routel @@ -1,72 +1,62 @@ -#!/bin/sh +#! /usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 - -# -# Script created by: Stephen R. van den Berg , 1999/04/18 -# Donated to the public domain. -# -# This script transforms the output of "ip" into more readable text. -# "ip" is the Linux-advanced-routing configuration tool part of the -# iproute package. # +# This is simple script to process JSON output from ip route +# command and format it. Based on earlier shell script version. +"""Script to parse ip route output into more readable text.""" + +import sys +import json +import getopt +import subprocess + + +def usage(): + '''Print usage and exit''' + print("Usage: {} [tablenr [raw ip args...]]".format(sys.argv[0])) + sys.exit(64) + + +def main(): + '''Process the arguments''' + family = 'inet' + try: + opts, args = getopt.getopt(sys.argv[1:], "h46f:", ["help", "family="]) + except getopt.GetoptError as err: + print(err) + usage() + + for opt, arg in opts: + if opt in ["-h", "--help"]: + usage() + elif opt == '-6': + family = 'inet6' + elif opt == "-4": + family = 'inet' + elif opt in ["-f", "--family"]: + family = arg + else: + assert False, "unhandled option" + + if not args: + args = ['0'] + + cmd = ['ip', '-f', family, '-j', 'route', 'list', 'table'] + args + process = subprocess.Popen(cmd, stdout=subprocess.PIPE) + tbl = json.load(process.stdout) + if family == 'inet': + fmt = '{:15} {:15} {:15} {:8} {:8}{:<16} {}' + else: + fmt = '{:32} {:32} {:32} {:8} {:8}{:<16} {}' + + # ip route json keys + keys = ['dst', 'gateway', 'prefsrc', 'protocol', 'scope', 'dev', 'table'] + print(fmt.format(*map(lambda x: x.capitalize(), keys))) -test "X-h" = "X$1" && echo "Usage: $0 [tablenr [raw ip args...]]" && exit 64 + for record in tbl: + fields = [record[k] if k in record else '' for k in keys] + print(fmt.format(*fields)) -test -z "$*" && set 0 -ip route list table "$@" | - while read network rest - do set xx $rest - shift - proto="" - via="" - dev="" - scope="" - src="" - table="" - case $network in - broadcast|local|unreachable) via=$network - network=$1 - shift - ;; - esac - while test $# != 0 - do - case "$1" in - proto|via|dev|scope|src|table) - key=$1 - val=$2 - eval "$key='$val'" - shift 2 - ;; - dead|onlink|pervasive|offload|notify|linkdown|unresolved) - shift - ;; - *) - # avoid infinite loop on unknown keyword without value at line end - shift - shift - ;; - esac - done - echo "$network $via $src $proto $scope $dev $table" - done | awk -F ' ' ' -BEGIN { - format="%15s%-3s %15s %15s %8s %8s%7s %s\n"; - printf(format,"target","","gateway","source","proto","scope","dev","tbl"); - } - { network=$1; - mask=""; - if(match(network,"/")) - { mask=" "substr(network,RSTART+1); - network=substr(network,0,RSTART); - } - via=$2; - src=$3; - proto=$4; - scope=$5; - dev=$6; - table=$7; - printf(format,network,mask,via,src,proto,scope,dev,table); - } -' +if __name__ == "__main__": + main() diff --git a/man/man8/routel.8 b/man/man8/routel.8 index b32eeafcf69d..b1668e73615a 100644 --- a/man/man8/routel.8 +++ b/man/man8/routel.8 @@ -1,17 +1,31 @@ -.TH "ROUTEL" "8" "3 Jan, 2008" "iproute2" "Linux" +.TH ROUTEL 8 "1 Sept, 2021" "iproute2" "Linux" .SH "NAME" -.LP routel \- list routes with pretty output format -.SH "SYNTAX" -.LP -routel [\fItablenr\fP [\fIraw ip args...\fP]] +.SH SYNOPSIS +.B routel +.RI "[ " OPTIONS " ]" +.RI "[ " tablenr +[ \fIip route options...\fR ] ] +.P +.ti 8 +.IR OPTIONS " := {" +\fB-h\fR | \fB--help\fR | +[{\fB-f\fR | \fB--family\fR } +{\fBinet\fR | \fBinet6\fR } | +\fB-4\fR | \fB-6\fR } + .SH "DESCRIPTION" .LP -The routel script will list routes in a format that some might consider easier to interpret -then the ip route list equivalent. +The routel script will list routes in a format that some might consider +easier to interpret then the +.B ip +route list equivalent. + .SH "AUTHORS" .LP -The routel script was written by Stephen R. van den Berg , 1999/04/18 and donated to the public domain. +Rewritten by Stephen Hemminger . +.br +Original script by Stephen R. van den Berg . .br This manual page was written by Andreas Henriksson , for the Debian GNU/Linux system. .SH "SEE ALSO"