diff options
author | Jakub Jankowski <shasta@toxcorp.com> | 2017-11-21 03:57:16 +0100 |
---|---|---|
committer | Robby Workman <rworkman@slackware.com> | 2017-11-21 00:07:59 -0600 |
commit | d0c9d92192a208a4f76ffd7a9e2a580a48698c50 (patch) | |
tree | cc2219a183a2374da1c5910cde6e31a4e88cef57 /rc.inet1 | |
parent | 96cba49d10f8cd7c50bd20b21203fd6277ea3257 (diff) | |
download | slacknetsetup-d0c9d92192a208a4f76ffd7a9e2a580a48698c50.tar.xz |
rc.inet1: Check for iface in /sys/class/net, not /proc/net/dev
There is a slight problem with things like
grep lo: /proc/net/dev
especially with tun/tap devices with can have arbitrary names.
Consider a scenario where you name your tap iface "trololo":
$ grep -c lo: /proc/net/dev
2
$
To fix this (quite hypothetical, but still) problem, instead
of simple grepping in /proc/net/dev, check of sysfs path
existence (/sys/class/net/<interface>).
Same fix in if_up() and if_down() for non-loopback interfaces.
While there, also strip colon-whatever from interface name
(what I think was the original idea behind a construct like
grep $(echo ${1}: | cut -f 1 -d :): /proc/net/dev) by using
parameter expansion: ${1%%:*} will remove the longest suffix
matching ":*", ie. colon-and-everything-after.
This is supported by POSIX:
http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
Alternative solution would be to change the grep pattern to
grep '^ *lo:' /proc/net/dev
Signed-off-by: Robby Workman <rworkman@slackware.com>
Diffstat (limited to 'rc.inet1')
-rw-r--r-- | rc.inet1 | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -55,7 +55,7 @@ debug_log "List of interfaces: '${IFNAME[*]}'" # Function to bring up the loopback interface. If loopback is # already up, do nothing. lo_up() { - if grep lo: /proc/net/dev 1> /dev/null ; then + if [ -e /sys/class/net/lo ]; then if ! /sbin/ip link show dev lo | grep -wq -e "state UP" -e "state UNKNOWN" ; then echo "/etc/rc.d/rc.inet1: /sbin/ip address add 127.0.0.1/8 dev lo" | $LOGGER /sbin/ip address add 127.0.0.1/8 dev lo @@ -68,7 +68,7 @@ lo_up() { # Function to take down the loopback interface: lo_down() { - if grep lo: /proc/net/dev 1> /dev/null ; then + if [ -e /sys/class/net/lo ]; then echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev lo down" | $LOGGER /sbin/ip link set dev lo down fi @@ -148,13 +148,13 @@ if_up() { debug_log "skipping ${1} early, interface is not configured in /etc/rc.d/rc.inet1.conf" return 0 fi - if ! grep $(echo ${1}: | cut -f 1 -d :): /proc/net/dev 1> /dev/null ; then # no interface yet + if [ ! -e /sys/class/net/${1%%:*} ]; then # no interface yet if /sbin/modprobe -c | grep -v "^#" | grep -w "alias ${1}" | grep -vw "alias ${1} off" > /dev/null ; then echo "/etc/rc.d/rc.inet1: /sbin/modprobe ${1}" | $LOGGER /sbin/modprobe ${1} fi fi - if grep $(echo ${1}: | cut -f 1 -d :): /proc/net/dev 1> /dev/null ; then # interface exists + if [ -e /sys/class/net/${1%%:*} ]; then # interface exists if ! /sbin/ip address show dev ${1} 2>/dev/null | grep -wq inet || \ ! /sbin/ip link show dev ${1} | grep -wq "state UP" ; then # interface not up or not configured if [ -n "${HWADDR[$i]}" ]; then # Set hardware address _before_ the interface goes up: @@ -252,7 +252,7 @@ if_down() { echo "/etc/rc.d/rc.inet1: skipping ${1}, you might need to increase MAXNICS" | $LOGGER return fi - if grep $(echo ${1}: | cut -f 1 -d :): /proc/net/dev 1> /dev/null ; then + if [ -e /sys/class/net/${1%%:*} ]; then if [ "${USE_DHCP[$i]}" = "yes" ]; then echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -k -d ${1}" | $LOGGER /sbin/dhcpcd -k -d ${1} 2> /dev/null || /sbin/ip link set dev ${1} down |