From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5221 invoked by alias); 11 Aug 2015 13:27:31 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36100 Received: (qmail 24616 invoked from network); 11 Aug 2015 13:27:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 Subject: Re: [PATCH] _find_net_interfaces: use /sys/class/net/* for interface names in linux To: zsh-workers@zsh.org References: <1439254143-4608-1-git-send-email-llua@gmx.com> <27319.1439286441@thecus.kiddle.eu> From: Eric Cook X-Enigmail-Draft-Status: N1110 Message-ID: <55C9F82F.1020201@gmx.com> Date: Tue, 11 Aug 2015 09:27:11 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <27319.1439286441@thecus.kiddle.eu> Content-Type: multipart/mixed; boundary="------------000905060106030704060102" X-Provags-ID: V03:K0:UegaXT13LQatW8uiKlhMeK015b3eO28bJNOwx8RljCwSrM6+aLR QJv9kohG3M+iycmNFARnfWDlQ/x4I7D2Zg/6J4dJTHO/DU9PWYC17vuxzi81GX4T3PRT6Tk fTaoiFxC4QSiBjT3uONMd5ZU2WUBMBV+pomU9KaGrVHjQ7i9UFBAwg3vGnfo1dmw6DiLDkD uVt5igKUn575u8LM4I6Eg== X-UI-Out-Filterresults: notjunk:1;V01:K0:0UKh4YMNe0U=:dfWJBWE1VNybRLSv8t4g1p IYnaIs/WE2kaCiVARj4cC9GnjJqXAynjv6eCsmMhMi53Ro/gLuzi/gbxh1BMrTI+XRHyHNS81 IOsBGwG1O3TwZz2oucCvZZowNdWYFVjI68+8yR4+0KpChBQQyCIllKRjHDoDgJTaEkgbaNy6l wl/72pAwoSrZo7TIub72uN7qnZucoOGANdsXaI++oBl1VTaC9rBJrX9S3Hk2ZyRFaYhqmM44P eDjR45C42OXxnB1rskq2FH8Cssa9urlTRZsW2GjgTddG7Nnh/VLg4ey/p9tTb81Q4ArM9OBg4 evMGk3Yw/tWdJxzFPRW9IX/HCmiR0hxthsA4GZ/E8CSnOMZ9YG/0rFDmclscUz/0+xQcSVZCr JMzYQdMmM6ZqQoSRpQnxK1RjjCXr6q8W6bXVk9QdjHg+iTiGmyYB0PEfj36o/Newf8wO4refL Yt64eR1T9JhZZCzyZgdb4haaOrLKzD88sGvPYznT+q6MpV+NDrOHKmzeZCmiJtD+Yr0TjkKaD 2SjpYOyjyG2QUcIyRePFhywcU+M/SF55u49EjdHTjUYw0TI91dfhRrdjqndv4hLnXk90xEr3s y4tr80lEITfq85B3cy5Bk9PsPVyUN9Zzc9rxygvnTuB56P44dWbNhB7220aCwWzD0ZSZ2Cm9x lDFoB9SnLEVzTZkn0pn/c4zofgZTT3J9jB10rLlcxed039MFCeo6OCHDzX3WlLsInBoyRKN4k UWJvmsjs24zdL6Y7 --------------000905060106030704060102 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 08/11/2015 05:47 AM, Oliver Kiddle wrote: > Eric Cook wrote: >> I also wasn't able to find the type of tunnels mentioned in >> http://www.zsh.org/mla/workers/2007/msg00111.html that doesn't show up >> in /proc/sys/net/ipv4/conf/. Maybe at some point since then, that was >> fixed. But to avoid some kind of regression /sys/class/net/ seems usable >> for the time being. > > One example, is aliases. So if you do something like > ifconfig eth0:1 192.168.42.37 > then ifconfig will show eth0:1 while /sys/class won't. > > There may be cases where we don't want to complete those, however. Are there programs that actually work with aliases interface names? The ones I have seen, not many(ifdown/ifup), assumes you are attempting to address the actual interface. >> diff --git a/Completion/Unix/Type/_find_net_interfaces b/Completion/Unix/Type/_find_net_interfaces >> index 0c70335..f90f310 100644 >> --- a/Completion/Unix/Type/_find_net_interfaces >> +++ b/Completion/Unix/Type/_find_net_interfaces >> @@ -23,7 +23,7 @@ case $OSTYPE in >> irix*) net_intf_list=( ${${${(f)"$(/usr/etc/netstat -i)"}%% *}[2,-1]} ) ;; >> *linux*) >> if (( $+commands[ip] )); then >> - net_intf_list=( ${${(m)${(f)"$(ip -o link)"}#*: }%%: *} ) >> + net_intf_list=( /sys/class/net/*(N:t) ) >> fi >> ;& > > The (( $+commands[ip] )) isn't really applicable after that change. Whoops. > Also did you notice that we still have the following further down in the > function: > if [[ -d /proc/sys/net/ipv4/conf ]]; then > # On linux we used to use the following as the default. > # However, we now use ip or ifconfig since it finds additional devices such > # as tunnels. So only do this if that didn't work. > net_intf_list=( /proc/sys/net/ipv4/conf/*~*(all|default)(N:t) ) > fi > > I think the /proc path there will work for older Linux installations > than the /sys path you use and it still works with new systems. > > Oliver > I noticed it and found /sys/class/net on the oldest linux installs i have access to, centos 4.x. The linux block in the case statement is a fall through. If /sys/class/net doesn't exist it will fall back to using ifconfig or /proc/sys/net/ipv4/conf/ since the array net_intf_list is still empty. I've fixed my original patch, but if you want to solve it another way, go for it :D --------------000905060106030704060102 Content-Type: text/x-patch; name="0001-_find_net_interfaces-use-sys-class-net-for-interface.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-_find_net_interfaces-use-sys-class-net-for-interface.pa"; filename*1="tch" diff --git a/Completion/Unix/Type/_find_net_interfaces b/Completion/Unix/Type/_find_net_interfaces index 0c70335..32c920f 100644 --- a/Completion/Unix/Type/_find_net_interfaces +++ b/Completion/Unix/Type/_find_net_interfaces @@ -22,9 +22,7 @@ case $OSTYPE in darwin*|freebsd*|dragonfly*) net_intf_list=( $(ifconfig -l) ) ;; irix*) net_intf_list=( ${${${(f)"$(/usr/etc/netstat -i)"}%% *}[2,-1]} ) ;; *linux*) - if (( $+commands[ip] )); then - net_intf_list=( ${${(m)${(f)"$(ip -o link)"}#*: }%%: *} ) - fi + net_intf_list=( /sys/class/net/*(N:t) ) ;& *) --------------000905060106030704060102--