Cleanup of ip scripts
Subsystems (2)
cover Cleanup of ip scripts
Remove several old useless scripts and fix the routel script by rewriting it.
Stephen Hemminger (4):
ip: remove old rtpr script
ip: remove ifcfg script
ip: remove routef script
ip: rewrite routel in python
ip/Makefile | 2 +- ip/ifcfg | 150 ---------------------------------------------- ip/routef | 10 ---- ip/routel | 124 ++++++++++++++++++-------------------- ip/rtpr | 5 -- man/man8/ifcfg.8 | 48 --------------- man/man8/routef.8 | 1 - man/man8/routel.8 | 17 ++---- man/man8/rtpr.8 | 25 -------- 9 files changed, 64 insertions(+), 318 deletions(-) delete mode 100755 ip/ifcfg delete mode 100755 ip/routef delete mode 100755 ip/rtpr delete mode 100644 man/man8/ifcfg.8 delete mode 100644 man/man8/routef.8 delete mode 100644 man/man8/rtpr.8
Signature · 28 lines
2.30.2 Stephen Hemminger (4): ip: remove old rtpr script ip: remove ifcfg script ip: remove routef script ip: rewrite routel in python ip/Makefile | 2 +- ip/ifcfg | 150 ---------------------------------------------- ip/routef | 10 ---- ip/routel | 124 ++++++++++++++++++-------------------- ip/rtpr | 5 -- man/man8/ifcfg.8 | 48 --------------- man/man8/routef.8 | 1 - man/man8/routel.8 | 36 ++++++----- man/man8/rtpr.8 | 25 -------- 9 files changed, 79 insertions(+), 322 deletions(-) delete mode 100755 ip/ifcfg delete mode 100755 ip/routef delete mode 100755 ip/rtpr delete mode 100644 man/man8/ifcfg.8 delete mode 100644 man/man8/routef.8 delete mode 100644 man/man8/rtpr.8 -- 2.30.2
PATCH 1/4 ip: remove old rtpr script
From: Stephen Hemminger <[email protected]>
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.
--- 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
ip/Makefile +1 -1
@@ -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)
ip/rtpr deleted +0 -5
@@ -1,5 +0,0 @@ -#! /bin/sh -# SPDX-License-Identifier: GPL-2.0 - -exec tr "[\\\\]" "[ -]"
man/man8/rtpr.8 deleted +0 -25
@@ -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 <[email protected]>
Signature · 1 line
2.30.2
PATCH 2/4 ip: remove ifcfg script
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
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.
--- 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
ip/Makefile +1 -1
@@ -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)
ip/ifcfg deleted +0 -150
150 lines not on this page · raw message
man/man8/ifcfg.8 deleted +0 -48
48 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH 3/4 ip: remove routef script
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
This script is old and limited to IPv4. Using ip route command directly is better option.
--- 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
ip/Makefile +1 -1
@@ -18,7 +18,7 @@ RTMONOBJ=rtmon.o include ../config.mk ALLOBJ=$(IPOBJ) $(RTMONOBJ) -SCRIPTS=routel routef +SCRIPTS=routel TARGETS=ip rtmon all: $(TARGETS) $(SCRIPTS)
ip/routef deleted +0 -10
@@ -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
man/man8/routef.8 deleted +0 -1
@@ -1 +0,0 @@ -.so man8/routel.8
man/man8/routel.8 +2 -10
@@ -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 <[email protected]>, 1999/04/18 and donated to the public domain.
Signature · 1 line
2.30.2
PATCH 4/4 ip: rewrite routel in python
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
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.
--- ip/routel | 124 +++++++++++++++++++++------------------------- man/man8/routel.8 | 30 ++++++++--- 2 files changed, 79 insertions(+), 75 deletions(-)
ip/routel +57 -67
@@ -1,72 +1,62 @@ -#!/bin/sh +#! /usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 - -# -# Script created by: Stephen R. van den Berg <[email protected]>, 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()
man/man8/routel.8 +22 -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 <[email protected]>, 1999/04/18 and donated to the public domain. +Rewritten by Stephen Hemminger <[email protected]>. +.br +Original script by Stephen R. van den Berg <[email protected]>. .br This manual page was written by Andreas Henriksson <[email protected]>, for the Debian GNU/Linux system. .SH "SEE ALSO"
Signature · 1 line
2.30.2
David Ahern
AppliedQuoted 3 lines · Stephen Hemminger
Remove several old useless scripts and fix the routel script by rewriting it.
applied to iproute2-next