[gentoo-commits] proj/netifrc:master commit in: net/

2024-06-10 Thread Patrick McLean
commit: 7f323cf374035ac1c871f13d6a6ad29bb97bc930
Author: Andrey Volkov  ekb-info  ru>
AuthorDate: Tue Sep 28 13:40:27 2021 +
Commit: Patrick McLean  gentoo  org>
CommitDate: Fri May 24 05:51:45 2024 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=7f323cf3

Add missing wireguard_depend program

Signed-off-by: Andrey Volkov  ekb-info.ru>

 net/wireguard.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/wireguard.sh b/net/wireguard.sh
index f6ca69e..301836d 100644
--- a/net/wireguard.sh
+++ b/net/wireguard.sh
@@ -5,7 +5,7 @@
 
 wireguard_depend()
 {
-   program wg
+   program ip wg
before interface
 }
 



[gentoo-commits] proj/netifrc:master commit in: net/

2024-06-10 Thread Patrick McLean
commit: 9ef4fb84a7c1848c067f89f5510f448fb04c5c7a
Author: Andrey Volkov  ekb-info  ru>
AuthorDate: Tue Sep 28 13:43:52 2021 +
Commit: Patrick McLean  gentoo  org>
CommitDate: Fri May 24 05:51:59 2024 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=9ef4fb84

Add type_${IFVAR}=wireguard for arbitrary wireguard interface names

Signed-off-by: Andrey Volkov  ekb-info.ru>

 net/wireguard.sh | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/net/wireguard.sh b/net/wireguard.sh
index 301836d..269c8f0 100644
--- a/net/wireguard.sh
+++ b/net/wireguard.sh
@@ -9,9 +9,15 @@ wireguard_depend()
before interface
 }
 
+_is_wireguard() {
+   is_interface_type wireguard
+}
+
 wireguard_pre_start()
 {
-   [ "${IFACE#wg}" != "$IFACE" ] || return 0
+   local wireguard=
+   eval wireguard=\$type_${IFVAR}
+   [ "${wireguard}" = "wireguard" -o "${IFACE#wg}" != "$IFACE" ] || return 0
 
ip link delete dev "$IFACE" type wireguard 2>/dev/null
ebegin "Creating WireGuard interface $IFACE"
@@ -35,6 +41,7 @@ wireguard_pre_start()
e=$?
if [ $e -eq 0 ]; then
eend $e
+   set_interface_type wireguard
return $e
fi
fi
@@ -45,7 +52,7 @@ wireguard_pre_start()
 
 wireguard_post_stop()
 {
-   [ "${IFACE#wg}" != "$IFACE" ] || return 0
+   _is_wireguard || [ "${IFACE#wg}" != "$IFACE" ] || return 0
 
ebegin "Removing WireGuard interface $IFACE"
ip link delete dev "$IFACE" type wireguard



[gentoo-commits] proj/netifrc:master commit in: net/

2024-05-23 Thread Patrick McLean
commit: 8bb61b90c1d791bafd5cd0b6c54093cccee425f4
Author: Alexander Zubkov  qrator  net>
AuthorDate: Thu May 23 14:56:42 2024 +
Commit: Patrick McLean  gentoo  org>
CommitDate: Thu May 23 18:12:13 2024 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=8bb61b90

net/wireguard.sh: make wireguard module to run before interface

Wireguard module was configured to run after interface module, that
caused interface-related settings like mtu not to apply, because
wireguard interfaces was not present by that time. It seems logical
that wireguard module should be run before interface module.

Credits to lmk  gmail.com> who proposed the solution and
to Louis Sautier (sbraz)  gentoo.org> who proposed the patch.

Closes: https://bugs.gentoo.org/678184
Closes: https://github.com/gentoo/netifrc/pull/54
Signed-off-by: Louis Sautier (sbraz)  gentoo.org>
Signed-off-by: Alexander Zubkov  qrator.net>
Signed-off-by: Patrick McLean  gentoo.org>

 net/wireguard.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/wireguard.sh b/net/wireguard.sh
index bb71d6f..f6ca69e 100644
--- a/net/wireguard.sh
+++ b/net/wireguard.sh
@@ -6,7 +6,7 @@
 wireguard_depend()
 {
program wg
-   after interface
+   before interface
 }
 
 wireguard_pre_start()



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2024-01-07 Thread Sam James
commit: 7b1c09f80b94f01f670c8d487df361b3ddfebe0c
Author: Matoro Mahri  matoro  tk>
AuthorDate: Sun Jan  7 07:16:30 2024 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Jan  7 09:42:35 2024 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=7b1c09f8

Remove support for treecleaned net-misc/pump

Bug: https://bugs.gentoo.org/694314
Closes: https://bugs.gentoo.org/921538
Signed-off-by: Matoro Mahri  matoro.tk>
Closes: https://github.com/gentoo/netifrc/pull/51
Signed-off-by: Sam James  gentoo.org>

 doc/net.example.Linux.in |  7 ++
 net/Makefile |  2 +-
 net/dhclient.sh  |  2 +-
 net/dhcpcd.sh|  2 +-
 net/pump.sh  | 63 
 5 files changed, 5 insertions(+), 71 deletions(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index cbd81e7..84e4b1c 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -493,11 +493,10 @@
 
 #-
 # DHCP
-# DHCP can be provided by dhclient, dhcpcd, pump or udhcpc.
+# DHCP can be provided by dhclient, dhcpcd, or udhcpc.
 #
 # dhclient: emerge net-misc/dhcp
 # dhcpcd:   emerge net-misc/dhcpcd
-# pump: emerge net-misc/pump
 # udhcpc:   emerge sys-apps/busybox
 
 # If you have more than one DHCP client installed, you need to specify which
@@ -508,7 +507,6 @@
 # - All clients send the current hostname to the DHCP server by default
 # - dhcpcd does not daemonize when the lease time is infinite
 # - udhcp-0.9.3-r3 and earlier do not support getting NTP servers
-# - pump does not support getting NIS servers
 # - DHCP tends to erase any existing device information - so add
 #   static addresses after dhcp if you need them
 # - dhclient and udhcpc can set other resolv.conf options such as "option"
@@ -524,11 +522,10 @@
 # default) to 10 seconds.
 #dhcpcd_eth0="-t 10"
 
-# dhclient, udhcpc and pump don't have many runtime options
+# dhclient and udhcpc don't have many runtime options
 # You can pass options to them in a similar manner to dhcpcd though
 #dhclient_eth0="..."
 #udhcpc_eth0="..."
-#pump_eth0="..."
 
 # GENERIC DHCP OPTIONS
 # Set generic DHCP options like so

diff --git a/net/Makefile b/net/Makefile
index f562d15..22bd8d1 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -12,7 +12,7 @@ INC-FreeBSD=  iwconfig.sh
 SRCS-Linux=iwconfig.sh.in udhcpc.sh.in
 INC-Linux= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh 
\
-   ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh 
udhcpc.sh \
+   ipppd.sh iwconfig.sh netplugd.sh pppd.sh tuntap.sh udhcpc.sh \
vlan.sh macvlan.sh ip6rd.sh firewalld.sh dummy.sh hsr.sh 
l2tp.sh \
iw.sh iwd.sh wireguard.sh veth.sh dhclientv6.sh qmi.sh
 

diff --git a/net/dhclient.sh b/net/dhclient.sh
index 6fa4a92..ce964b0 100644
--- a/net/dhclient.sh
+++ b/net/dhclient.sh
@@ -9,7 +9,7 @@ dhclient_depend()
provide dhcp
 
# We prefer dhclient over these
-   after udhcpc pump
+   after udhcpc
 }
 
 _config_vars="$_config_vars dhcp dhcpcd"

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index 2493f27..e159f0a 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -10,7 +10,7 @@ dhcpcd_depend()
provide dhcp
 
# We prefer dhcpcd over these
-   after udhcpc pump dhclient
+   after udhcpc dhclient
 }
 
 _config_vars="$_config_vars dhcp dhcpcd"

diff --git a/net/pump.sh b/net/pump.sh
deleted file mode 100644
index 144316f..000
--- a/net/pump.sh
+++ /dev/null
@@ -1,63 +0,0 @@
-# Copyright (c) 2007-2008 Roy Marples 
-# Released under the 2-clause BSD license.
-# shellcheck shell=sh disable=SC1008
-
-pump_depend()
-{
-   program pump
-   after interface
-   provide dhcp
-
-   # We prefer pump over udhcpc
-   after udhcpc
-}
-
-_config_vars="$_config_vars dhcp pump"
-
-pump_start()
-{
-   local args= opt= opts=
-
-   # Get our options
-   eval opts=\$dhcp_${IFVAR}
-   [ -z "${opts}" ] && opts=${dhcp}
-
-   # Map some generic options to dhcpcd
-   for opt in ${opts}; do
-   case "${opt}" in
-   nodns) args="${args} --no-dns";;
-   nontp) args="${args} --no-ntp";;
-   nogateway) args="${args} --no-gateway";;
-   esac
-   done
-
-   # Add our route metric
-   [ "${metric:-0}" != "0" ] && args="${args} --route-metric ${metric}"
-
-   args="${args} --win-client-ident"
-   args="${args} --keep-up --interface ${IFACE}"
-
-   ebegin "Running pump"
-   eval pump "${args}"
-   eend $? || return 1
-
-   _show_address
-   return 0
-}
-
-pump_stop()
-{
-   # We check for a pump process first as querying for status
-   # causes pump to spawn a process
-   

[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2023-11-24 Thread Robin H. Johnson
commit: a0b69349707b4aaaefc01fd37f1b386935d75c90
Author: Alon Bar-Lev  gmail  com>
AuthorDate: Sun May 14 21:38:28 2023 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sat Nov 25 04:54:01 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=a0b69349

net: add qmi interface support

qmi is useful for cellular modem connection, the management interface is
implemented using libqmi's qmicli utility.

Signed-off-by: Alon Bar-Lev  gmail.com>
Signed-off-by: Robin H. Johnson  gentoo.org>
Closes: https://github.com/gentoo/netifrc/pull/44

 doc/net.example.Linux.in |  13 +
 net/Makefile |   2 +-
 net/qmi.sh   | 133 +++
 3 files changed, 147 insertions(+), 1 deletion(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index 42b8071..cbd81e7 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -1132,6 +1132,19 @@
 #l2tpsession_l2tpeth2="tunnel_id 2 session_id 1 peer_session_id 1"
 #config_l2tpeth2="10.100.2.1/24"
 
+#-
+# QMI
+# For QMI support, emerge net-libs/libqmi
+# QMI is used for some cellular modems.
+#
+# Each QMI interface may have the following configuration:
+#qmi_apn_wwan0=# The name of the APN
+#qmi_auth_wwan0=   # none, pop, chap, both, Default: none
+#qmi_username_wwan0=   # Default: dummy
+#qmi_password_wwan0=   # Default dummy
+#qmi_cdc_wwan0=# Default: /dev/cdc-wmiX where 
X is taken from IFACE
+#-
+
 #-
 # Advanced Routing
 # WARNING: For advanced routing you MUST be using sys-apps/iproute2

diff --git a/net/Makefile b/net/Makefile
index 58483cd..f562d15 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -14,7 +14,7 @@ INC-Linux=adsl.sh apipa.sh arping.sh bonding.sh 
br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh 
\
ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh 
udhcpc.sh \
vlan.sh macvlan.sh ip6rd.sh firewalld.sh dummy.sh hsr.sh 
l2tp.sh \
-   iw.sh iwd.sh wireguard.sh veth.sh dhclientv6.sh
+   iw.sh iwd.sh wireguard.sh veth.sh dhclientv6.sh qmi.sh
 
 SRCS-NetBSD= ifwatchd.sh.in
 INC-NetBSD=ifwatchd.sh

diff --git a/net/qmi.sh b/net/qmi.sh
new file mode 100644
index 000..ac1b2dd
--- /dev/null
+++ b/net/qmi.sh
@@ -0,0 +1,133 @@
+# Copyright (c) 2011 by Gentoo Foundation
+# Released under the 2-clause BSD license.
+# shellcheck shell=sh disable=SC1008
+
+_is_qmi() {
+   [ -d "/sys/class/net/${IFACE}/qmi" ]
+}
+
+_get_state() {
+   echo "/run/net.${IFACE}.qmi.state"
+}
+
+_get_device() {
+   echo "/dev/cdc-$(echo "${IFACE}" | sed 's/wwan/wdm/')"
+}
+
+qmi_depend()
+{
+   program qmicli
+   program ip
+   before interface
+}
+
+qmi_pre_start() {
+
+   _is_qmi || return 0
+
+   local device
+   local apn
+   local auth
+   local username
+   local password
+   local out
+   local rc
+
+   eval device=\$qmi_cdc_${IFVAR}
+   eval apn=\$qmi_apn_${IFVAR}
+   eval auth=\$qmi_auth_${IFVAR}
+   eval username=\$qmi_username_${IFVAR}
+   eval password=\$qmi_password_${IFVAR}
+
+   [ -n "${apn}" ] || return 0
+
+   [ -n "${device}" ] || device="$(_get_device)"
+   [ -n "${auth}" ] || auth="none"
+   [ -n "${username}" ] || username="dummy"
+   [ -n "${password}" ] || password="dummy"
+
+   if ! [ -c "${device}" ]; then
+   ewarn "Cannot open device ${device} for ${IFACE}, aborting 
configuration"
+   return 1
+   fi
+
+   if ! cat "/sys/class/net/${IFACE}/qmi/raw_ip" | grep -q Y; then
+   ebegin "Configuring QMI raw IP"
+
+   ip link set "${IFACE}" down
+   if ! echo Y > "/sys/class/net/${IFACE}/qmi/raw_ip"; then
+   eend 1 "Cannot set raw IP mode for ${IFACE}, aborting 
configuration"
+   return 1
+   else
+   eend 0
+   fi
+   fi
+
+   local 
wwan_connection="apn='${apn}',auth='${auth}',username='${username}',password='${password}',autoconnect=yes,ip-type=4"
+   local n
+   for n in 1 2 3; do
+   ebegin "Connecting QMI APN '${apn}' using '${username}'"
+
+   if out="$( \
+   qmicli \
+   --device="${device}" \
+   --wds-start-network="${wwan_connection}" \
+   --device-open-proxy \
+   --client-no-release-cid \
+   )"; then
+   eend 0
+  

[gentoo-commits] proj/netifrc:master commit in: net/

2023-11-24 Thread Robin H. Johnson
commit: acf5e9c1d505e14524dcc78a1433872ae273c491
Author: Violet Purcell  inventati  org>
AuthorDate: Wed Nov 22 23:35:01 2023 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sat Nov 25 04:52:47 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=acf5e9c1

iwd: depend on "program /usr/libexec/iwd" instead of "program iwd"

In iwd.sh, the iwd executable used is /usr/libexec/iwd, however in the
dependency block it depends on just "program iwd." Since iwd is not in
PATH, this will fail and cause iwd to not be started when it should be.
Correct this to /usr/libexec/iwd.

Signed-off-by: Violet Purcell  inventati.org>
Signed-off-by: Robin H. Johnson  gentoo.org>
Closes: https://github.com/gentoo/netifrc/pull/49

 net/iwd.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/iwd.sh b/net/iwd.sh
index d8be2d5..75edb8c 100644
--- a/net/iwd.sh
+++ b/net/iwd.sh
@@ -7,7 +7,7 @@ iwd_depend()
before interface
provide wireless
after iwconfig
-   program iwd
+   program /usr/libexec/iwd
 }
 
 _config_vars="$_config_vars iwd"



[gentoo-commits] proj/netifrc:master commit in: net/

2023-10-19 Thread Sam James
commit: bf02831a7a59f5552c916dde7dd47296a7bce0b1
Author: kmartin36  gtri  gatech  edu>
AuthorDate: Fri Sep 15 01:29:27 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Thu Oct 19 22:57:19 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=bf02831a

dhcpcd: Fixing the handling of dhcpcd arguments with spaces

Bug: https://bugs.gentoo.org/881039
Signed-off-by: Kevin Martin  gmail.com>
Fixes: bd8ff4aa89e1d56e9886dad32bb2406c8f43c747
Closes: https://github.com/gentoo/netifrc/pull/48
Signed-off-by: Sam James  gentoo.org>

 net/dhcpcd.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index 6bd44ba..2493f27 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -90,8 +90,8 @@ dhcpcd_stop()
eval opts=\$dhcp_${IFVAR}
[ -z "${opts}" ] && opts=${dhcp}
case " ${opts} " in
-   *" release "*) dhcpcd -k "${args}" "${IFACE}" ;;
-   *) dhcpcd -x "${args}" "${IFACE}" ;;
+   *" release "*) dhcpcd -k ${args} "${IFACE}" ;;
+   *) dhcpcd -x ${args} "${IFACE}" ;;
esac
[ -f "${argsfile}" ] && rm -f "${argsfile}"
eend $?



[gentoo-commits] proj/netifrc:master commit in: net/

2023-09-10 Thread Sam James
commit: a509a86bbfe77db20d676caa5f3c421d5a781780
Author: Mike Gilbert  gentoo  org>
AuthorDate: Thu Jun  1 19:21:23 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Sep 10 15:15:45 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=a509a86b

net/bonding.sh: fix spelling of "lose"

Signed-off-by: Mike Gilbert  gentoo.org>
Closes: https://github.com/gentoo/netifrc/pull/47
Signed-off-by: Sam James  gentoo.org>

 net/bonding.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bonding.sh b/net/bonding.sh
index d8f48d8..e3fcaa7 100644
--- a/net/bonding.sh
+++ b/net/bonding.sh
@@ -8,7 +8,7 @@ bonding_depend()
before interface macchanger
program ip ifconfig
# If you do not have sysfs, you MUST have this binary instead for ioctl
-   # Also you will loose some functionality that cannot be done via sysfs:
+   # Also you will lose some functionality that cannot be done via sysfs:
if [ ! -d /sys/class/net ]; then
program ifenslave
fi



[gentoo-commits] proj/netifrc:master commit in: net/

2023-05-28 Thread Mike Gilbert
commit: 0ac293faa15b49f08830120e7b5fa1e4523f19e5
Author: Mike Gilbert  gentoo  org>
AuthorDate: Sun May 28 20:07:47 2023 +
Commit: Mike Gilbert  gentoo  org>
CommitDate: Sun May 28 22:49:02 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=0ac293fa

Update pidfile path for ppp-2.5.0

Bug: https://bugs.gentoo.org/907311
Signed-off-by: Mike Gilbert  gentoo.org>

 net/pppd.sh | 38 ++
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/net/pppd.sh b/net/pppd.sh
index 22644f2..1b14fed 100644
--- a/net/pppd.sh
+++ b/net/pppd.sh
@@ -1,4 +1,4 @@
-# Copyright (c) 2005-2007 Gentoo Foundation
+# Copyright (c) 2005-2023 Gentoo Authors
 # Copyright (c) 2007-2008 Roy Marples 
 # Released under the 2-clause BSD license.
 # shellcheck shell=sh disable=SC1008
@@ -21,12 +21,28 @@ requote()
printf "'%s' " "$@"
 }
 
+pppd_version_int() {
+   # 002004008 is v2.4.8
+   printf '%03d' $(/usr/sbin/pppd --version | awk '/pppd version/ {print 
$3}' | tr '.' ' ')
+}
+
 pppd_is_ge_248()
 {
-   local ver_str="$(/usr/sbin/pppd --version 2>&1 | awk '/pppd version/ 
{print $3}' | tr '.' ' ')"
+   [ $(pppd_version_int) -ge 002004008 ]
+}
 
-   # 002004008 is v2.4.8
-   [ "$(printf '%03d' ${ver_str})" -ge 002004008 ]
+pppd_is_ge_250()
+{
+   [ $(pppd_version_int) -ge 002005000 ]
+}
+
+pppd_pidfile()
+{
+   if pppd_is_ge_250; then
+   echo "/run/pppd/ppp-${IFACE}.pid"
+   else
+   echo "/run/ppp-${IFACE}.pid"
+   fi
 }
 
 pppd_pre_start()
@@ -207,16 +223,18 @@ pppd_pre_start()
fi
[ "${insert_link_in_opts}" = "0" ] || opts="${link} ${opts}"
 
+   local pidfile="$(pppd_pidfile)"
+
ebegin "Starting pppd in ${IFACE}"
mark_service_inactive
if [ -n "${username}" ] \
&& [ -n "${password}" -o -z "${passwordset}" ]; then
printf "%s" "${password}" | \
eval start-stop-daemon --start --exec /usr/sbin/pppd \
-   --pidfile "/run/ppp-${IFACE}.pid" -- "${opts}" 
>/dev/null
+   --pidfile "${pidfile}" -- "${opts}" >/dev/null
else
eval start-stop-daemon --start --exec /usr/sbin/pppd \
-   --pidfile "/run/ppp-${IFACE}.pid" -- "${opts}" 
>/dev/null
+   --pidfile "${pidfile}" -- "${opts}" >/dev/null
fi
 
if ! eend $? "Failed to start PPP"; then
@@ -243,9 +261,13 @@ pppd_start()
 pppd_stop()
 {
yesno ${IN_BACKGROUND} && return 0
-   local pidfile="/run/ppp-${IFACE}.pid"
 
-   [ ! -s "${pidfile}" ] && return 0
+   local pidfile="$(pppd_pidfile)"
+   if [ ! -s "${pidfile}" ]; then
+   # Try the old path.
+   pidfile="/run/ppp-${IFACE}.pid"
+   [ -s "${pidfile}" ] || return 0
+   fi
 
# Give pppd at least 30 seconds do die, #147490
einfo "Stopping pppd on ${IFACE}"



[gentoo-commits] proj/netifrc:master commit in: net/

2023-04-19 Thread Robin H. Johnson
commit: baff1e37615921b37cfa166215d3d1c6531a81af
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Wed Apr 19 17:11:32 2023 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Wed Apr 19 17:14:32 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=baff1e37

net/Makefile: include iwd

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/Makefile b/net/Makefile
index ee48294..58483cd 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -14,7 +14,7 @@ INC-Linux=adsl.sh apipa.sh arping.sh bonding.sh 
br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh 
\
ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh 
udhcpc.sh \
vlan.sh macvlan.sh ip6rd.sh firewalld.sh dummy.sh hsr.sh 
l2tp.sh \
-   iw.sh wireguard.sh veth.sh dhclientv6.sh
+   iw.sh iwd.sh wireguard.sh veth.sh dhclientv6.sh
 
 SRCS-NetBSD= ifwatchd.sh.in
 INC-NetBSD=ifwatchd.sh



[gentoo-commits] proj/netifrc:master commit in: net/

2023-04-16 Thread Sam James
commit: a43884bca4b34b8649574fb3ea85a2a658fd0a6f
Author: Greg Kubaryk  vt  edu>
AuthorDate: Mon Apr 17 04:34:36 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Mon Apr 17 04:35:08 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=a43884bc

net/dhcpcd.sh: adapt to dhcpcd-10 versioning

Closes: https://bugs.gentoo.org/904422
Signed-off-by: Greg Kubaryk  vt.edu>
Signed-off-by: Sam James  gentoo.org>

 net/dhcpcd.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index 1380944..6bd44ba 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -32,7 +32,7 @@ dhcpcd_start()
[ -z "${opts}" ] && opts=${dhcp}
 
case "$(dhcpcd --version | head -n 1)" in
-   "dhcpcd "[123]*)
+   "dhcpcd "[123]\.*)
eerror 'The dhcpcd version is too old. Please upgrade.'
return 1
;;



[gentoo-commits] proj/netifrc:master commit in: net/

2023-02-11 Thread Sam James
commit: 8390af35cb89002b33acea91d2b2b641f0728398
Author: Sam James  gentoo  org>
AuthorDate: Sun Feb 12 06:54:09 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Feb 12 06:54:15 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=8390af35

net/arping.sh: adapt to new arping path in /usr/bin

Bug: https://bugs.gentoo.org/893290
Signed-off-by: Sam James  gentoo.org>

 net/arping.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/arping.sh b/net/arping.sh
index 7e178b7..bdd8284 100644
--- a/net/arping.sh
+++ b/net/arping.sh
@@ -4,7 +4,7 @@
 
 arping_depend()
 {
-   program /sbin/arping /bin/arping /usr/sbin/arping /usr/sbin/arping2
+   program /sbin/arping /bin/arping /usr/bin/arping /usr/sbin/arping 
/usr/sbin/arping2
before interface
 }
 



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-19 Thread Sam James
commit: e6db37173cb70183ee983aa1aaa5224a2f8c49c3
Author: Kerin Millar  plushkava  net>
AuthorDate: Thu Jan 19 04:47:54 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Thu Jan 19 18:49:22 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=e6db3717

net/l2tp.sh: Don't try to evaluate l2tptunnel_${IFVAR} if unset

The "restructuring" commit went one step too far by combining the test for
whether l2tptunnel_${IFVAR} is defined with the test for whether the tunnel
exists, in a way that adversely affects the outer control flow. Fix it by
nesting the latter test.

Fixes: 0b8b9b13146c1eba04f2bd8d0b2b049c03891010
Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Sam James  gentoo.org>

 net/l2tp.sh | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index aa8e3fd..dde86af 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -28,12 +28,14 @@ l2tp_pre_start() {
eend 1 "${key} defines a \"name\" parameter, which is forbidden 
by netifrc"
elif ! modprobe l2tp_eth; then
eend 1 "Couldn't load the l2tp_eth module (perhaps the 
CONFIG_L2TP_ETH kernel option is disabled)"
-   elif key="l2tptunnel_${IFVAR}"; ! eval "[ \${${key}+set} ]" && ! 
_l2tp_has_tunnel "${tunnel_id}"; then
+   elif key="l2tptunnel_${IFVAR}"; ! eval "[ \${${key}+set} ]"; then
# A tunnel may incorporate more than one session (link). This
# module allows for the user not to define a tunnel for a given
# session. In that case, it will be expected that the required
# tunnel has already been created to satisfy some other session.
-   eend 1 "Tunnel #${tunnel_id} not found (defining ${key} may be 
required)"
+   if ! _l2tp_has_tunnel "${tunnel_id}"; then
+   eend 1 "Tunnel #${tunnel_id} not found (defining ${key} 
may be required)"
+   fi
elif eval "l2tptunnel=\$${key}"; _is_blank "${l2tptunnel}"; then
eend 1 "${key} is defined but its value is blank"
elif ! declared_tunnel=$(_l2tp_parse_opts "${l2tptunnel}" "local 
peer_tunnel_id remote tunnel_id" "encap"); then



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-19 Thread Sam James
commit: 46f8a90fef9d9bff21760dab52124bfbbb62e064
Author: Kerin Millar  plushkava  net>
AuthorDate: Sat Jul 17 09:53:36 2021 +
Commit: Sam James  gentoo  org>
CommitDate: Thu Jan 19 18:49:25 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=46f8a90f

net/iproute2.sh: Fix two regressions in _get_mac_address

Commit 4143e26 re-introduced the ip(8) parser in the course of adding
network namespace support. In doing so, it also introduced two
regressions. Firstly, in the case that no MAC address is successfully
discerned, the function will return 0. Secondly, FF:FF:FF:FF:FF:FF is
no longer handled as a special case.

This patch, once again, does away with the ip(8) parser and, instead,
collects the address from sysfs. The _netns function is used to ensure
that the procedure is carried out within the applicable network
namespace, if necessary. In the event that the address file cannot be
read, or that it contains nothing, the function will now return 1,
which addresses the first issue. The second issue is addressed by
uppercasing the applicable case pattern.

As an aside, this patch also addresses an issue whereby sed(1) was used
to match against a pattern containing \< and \>, which are GNU-specific
extensions.

Fixes: 4143e26dd4a56c08fbb99e18913eaafaf2a04f32
Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Sam James  gentoo.org>

 net/iproute2.sh | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index bd7333e..ea0a6f7 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -91,17 +91,15 @@ _set_flag()
 _get_mac_address()
 {
local mac=
-   mac=$(LC_ALL=C _ip link show "${IFACE}" | sed -n \
-   -e 'y/abcdef/ABCDEF/' \
-   -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p' | head -n1)
+   mac=$(_netns sed -e 'y/abcdef/ABCDEF/;q' 
/sys/class/net/"${IFACE}"/address) || return
 
case "${mac}" in
-   00:00:00:00:00:00) return 1 ;;
-   44:44:44:44:44:44) return 1 ;;
-   ff:ff:ff:ff:ff:ff) return 1 ;;
-   esac
-
-   printf '%s\n' "${mac}" | LC_ALL=C tr '[:lower:]' '[:upper:]'
+   '')false ;;
+   00:00:00:00:00:00) false ;;
+   44:44:44:44:44:44) false ;;
+   FF:FF:FF:FF:FF:FF) false ;;
+   esac &&
+   printf '%s\n' "${mac}"
 }
 
 _set_mac_address()



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-17 Thread Sam James
commit: e5a46f30deedabef5c18a587db2984a314f61071
Author: Kerin Millar  plushkava  net>
AuthorDate: Tue Jan 17 09:11:22 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Tue Jan 17 15:05:51 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=e5a46f30

net/bonding.sh: Eliminate the bashism that is pattern substitution

Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Sam James  gentoo.org>

 net/bonding.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bonding.sh b/net/bonding.sh
index 1757a89..6db90fa 100644
--- a/net/bonding.sh
+++ b/net/bonding.sh
@@ -92,7 +92,7 @@ bonding_pre_start()
if [ -n "${s}" ]; then
for i in $s; do
einfo "Adding ${n}: ${i}"
-   _netns echo "+${i/+/}" \>"${x}" || \
+   _netns echo "+${i#+}" \>"${x}" || \
eerror "Failed to add $i (${n}_${IFVAR})"
done
fi



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-17 Thread Sam James
commit: 9f752fd223ce8a2539874631008d9eda83aa5ba0
Author: Kerin Millar  plushkava  net>
AuthorDate: Tue Jan 17 09:25:58 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Tue Jan 17 15:06:28 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=9f752fd2

net/wpa_supplicant.sh: Properly expand the number of positional parameters

${#*} is undefined behaviour. Just write it as $#.

Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Sam James  gentoo.org>

 net/wpa_supplicant.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/wpa_supplicant.sh b/net/wpa_supplicant.sh
index 3f8e1b1..9f024c0 100644
--- a/net/wpa_supplicant.sh
+++ b/net/wpa_supplicant.sh
@@ -57,7 +57,7 @@ wpa_supplicant_pre_start()
[ -z "${cliopts}" ] && cliopts=${wpa_cli}
set -- $opts
local opt_D
-   while [ ${#*} -gt 0 ]; do
+   while [ "$#" -gt 0 ]; do
local opt=$1 ; shift
case "$opt" in
-D) opt_D=${1} ; shift ;;



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-17 Thread Sam James
commit: f9c4602fec8b4a5bb6561dbf8bbeeff8447165bc
Author: Kerin Millar  plushkava  net>
AuthorDate: Tue Jan 17 09:14:37 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Tue Jan 17 15:06:12 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=f9c4602f

net/veth.sh: Eliminate the bashism that is the == test operator

Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Sam James  gentoo.org>

 net/veth.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/veth.sh b/net/veth.sh
index 80f9a8e..e18906c 100644
--- a/net/veth.sh
+++ b/net/veth.sh
@@ -132,7 +132,7 @@ veth_pre_start()
 
local createveth
eval createveth=\$veth_${IFVAR}_create
-   if [ "$createveth" == "no" ]; then
+   if [ "$createveth" = "no" ]; then
return 0
fi
 



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-15 Thread Sam James
commit: 315341e5af9dad09ca4e5c1ff8b16e3c0fc72898
Author: Kerin Millar  plushkava  net>
AuthorDate: Sun Jan 15 19:30:35 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Jan 15 20:36:57 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=315341e5

net/l2tp.sh: Really favour IFACE over IFVAR in an informational message

The previous commit intended to replace an instance of IFVAR with IFACE.
Instead, it replaced with IFNAME, which means nothing to netifrc.
Frustratingly, I had realised my error at the time of submitting the patch,
yet still managed to attach a bad one. Make it right.

Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Sam James  gentoo.org>

 net/l2tp.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index 2221d26..aa8e3fd 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -39,7 +39,7 @@ l2tp_pre_start() {
elif ! declared_tunnel=$(_l2tp_parse_opts "${l2tptunnel}" "local 
peer_tunnel_id remote tunnel_id" "encap"); then
eend 1 "${key} is missing at least one required parameter"
elif set -- "${tunnel_id}"; eval "${declared_tunnel}"; [ "$1" != 
"${tunnel_id}" ]; then
-   eend 1 "${key} defines a \"tunnel_id\" parameter that 
contradicts l2tpsession_${IFNAME}"
+   eend 1 "${key} defines a \"tunnel_id\" parameter that 
contradicts l2tpsession_${IFACE:?}"
elif _l2tp_should_add_tunnel "${tunnel_id}" "${declared_tunnel}"; set 
-- $?; [ "$1" -eq 2 ]; then
eend 1 "Tunnel #${tunnel_id} exists but its properties mismatch 
those defined by ${key}"
elif [ "$1" -eq 1 ]; then



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-15 Thread Sam James
commit: 735b7e1b920874fe2f588f5b9385ff40d33c48c2
Author: Kerin Millar  plushkava  net>
AuthorDate: Sun Jan 15 06:09:40 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Jan 15 14:03:29 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=735b7e1b

net/l2tp.sh: Favour IFACE over IFVAR in an informational message

IFVAR is (supposed to be) requoted for injection, so it doesn't make any sense
to expand it within the second argument given to eend.

Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Sam James  gentoo.org>

 net/l2tp.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index ad459df..2221d26 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -39,7 +39,7 @@ l2tp_pre_start() {
elif ! declared_tunnel=$(_l2tp_parse_opts "${l2tptunnel}" "local 
peer_tunnel_id remote tunnel_id" "encap"); then
eend 1 "${key} is missing at least one required parameter"
elif set -- "${tunnel_id}"; eval "${declared_tunnel}"; [ "$1" != 
"${tunnel_id}" ]; then
-   eend 1 "${key} defines a \"tunnel_id\" parameter that 
contradicts l2tpsession_${IFVAR}"
+   eend 1 "${key} defines a \"tunnel_id\" parameter that 
contradicts l2tpsession_${IFNAME}"
elif _l2tp_should_add_tunnel "${tunnel_id}" "${declared_tunnel}"; set 
-- $?; [ "$1" -eq 2 ]; then
eend 1 "Tunnel #${tunnel_id} exists but its properties mismatch 
those defined by ${key}"
elif [ "$1" -eq 1 ]; then



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-15 Thread Sam James
commit: 0b8b9b13146c1eba04f2bd8d0b2b049c03891010
Author: Kerin Millar  plushkava  net>
AuthorDate: Sun Jan 15 05:41:10 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Jan 15 14:03:10 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=0b8b9b13

net/l2tp.sh: Slightly improve the structure of l2tp_pre_start()

Restructure so as to avoid an unnecessary level of indentation. The behaviour
of the function remains the same.

Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Sam James  gentoo.org>

 net/l2tp.sh | 40 +++-
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index 52b5733..ad459df 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -28,32 +28,30 @@ l2tp_pre_start() {
eend 1 "${key} defines a \"name\" parameter, which is forbidden 
by netifrc"
elif ! modprobe l2tp_eth; then
eend 1 "Couldn't load the l2tp_eth module (perhaps the 
CONFIG_L2TP_ETH kernel option is disabled)"
-   elif key="l2tptunnel_${IFVAR}"; eval "[ \${${key}+set} ]"; then
-   if eval "l2tptunnel=\$${key}"; _is_blank "${l2tptunnel}"; then
-   eend 1 "${key} is defined but its value is blank"
-   elif ! declared_tunnel=$(_l2tp_parse_opts "${l2tptunnel}" 
"local peer_tunnel_id remote tunnel_id" "encap"); then
-   eend 1 "${key} is missing at least one required 
parameter"
-   elif set -- "${tunnel_id}"; eval "${declared_tunnel}"; [ "$1" 
!= "${tunnel_id}" ]; then
-   eend 1 "${key} defines a \"tunnel_id\" parameter that 
contradicts l2tpsession_${IFVAR}"
-   elif _l2tp_should_add_tunnel "${tunnel_id}" 
"${declared_tunnel}"; set -- $?; [ "$1" -eq 2 ]; then
-   eend 1 "Tunnel #${tunnel_id} exists but its properties 
mismatch those defined by ${key}"
-   elif [ "$1" -eq 1 ]; then
-   # The config matches an existing tunnel.
-   true
-   elif [ "${encap}" = ip ] && ! modprobe l2tp_ip; then
-   eend 1 "Couldn't load the l2tp_ip module (perhaps the 
CONFIG_L2TP_IP kernel option is disabled)"
-   else
-   ebegin "Creating L2TPv3 tunnel (tunnel_id ${tunnel_id})"
-   printf %s "l2tp add tunnel ${l2tptunnel}" \
-   | xargs -E '' ip
-   eend $?
-   fi
-   elif ! _l2tp_has_tunnel "${tunnel_id}"; then
+   elif key="l2tptunnel_${IFVAR}"; ! eval "[ \${${key}+set} ]" && ! 
_l2tp_has_tunnel "${tunnel_id}"; then
# A tunnel may incorporate more than one session (link). This
# module allows for the user not to define a tunnel for a given
# session. In that case, it will be expected that the required
# tunnel has already been created to satisfy some other session.
eend 1 "Tunnel #${tunnel_id} not found (defining ${key} may be 
required)"
+   elif eval "l2tptunnel=\$${key}"; _is_blank "${l2tptunnel}"; then
+   eend 1 "${key} is defined but its value is blank"
+   elif ! declared_tunnel=$(_l2tp_parse_opts "${l2tptunnel}" "local 
peer_tunnel_id remote tunnel_id" "encap"); then
+   eend 1 "${key} is missing at least one required parameter"
+   elif set -- "${tunnel_id}"; eval "${declared_tunnel}"; [ "$1" != 
"${tunnel_id}" ]; then
+   eend 1 "${key} defines a \"tunnel_id\" parameter that 
contradicts l2tpsession_${IFVAR}"
+   elif _l2tp_should_add_tunnel "${tunnel_id}" "${declared_tunnel}"; set 
-- $?; [ "$1" -eq 2 ]; then
+   eend 1 "Tunnel #${tunnel_id} exists but its properties mismatch 
those defined by ${key}"
+   elif [ "$1" -eq 1 ]; then
+   # The config matches an existing tunnel.
+   true
+   elif [ "${encap}" = ip ] && ! modprobe l2tp_ip; then
+   eend 1 "Couldn't load the l2tp_ip module (perhaps the 
CONFIG_L2TP_IP kernel option is disabled)"
+   else
+   ebegin "Creating L2TPv3 tunnel (tunnel_id ${tunnel_id})"
+   printf %s "l2tp add tunnel ${l2tptunnel}" \
+   | xargs -E '' ip
+   eend $?
fi || return
 
ebegin "Creating L2TPv3 session (session_id ${session_id} tunnel_id 
${tunnel_id})"



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-14 Thread Sam James
commit: bd50c2ce076f2a6a5b0f884287a7940cd29cc6db
Author: 7e3f <122086774+7e3f  users  noreply  github  
com>
AuthorDate: Fri Jan  6 10:20:09 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Jan 15 01:52:46 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=bd50c2ce

net/macchanger.sh: Update path to macchanger to /usr

Proposing changes in diff from bug #889922, net-analyzer/macchanger-1.7.0_p5_p4
to net-analyzer/macchanger-1.7.0_p5_p4-r1 changed softlink and binary location 
due
to #886121.

There was a temporary tidy up in net-analyzer/macchanger-1.7.0_p5_p4-r2, but
proposing macchanger.sh change to allow netifrc to work with macchanger
binary location.

Bug: https://bugs.gentoo.org/886121
Bug: https://bugs.gentoo.org/889922
Closes: https://github.com/gentoo/netifrc/pull/42
Signed-off-by: Sam James  gentoo.org>

 net/macchanger.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/macchanger.sh b/net/macchanger.sh
index d87d96e..5b32b80 100644
--- a/net/macchanger.sh
+++ b/net/macchanger.sh
@@ -64,7 +64,7 @@ macchanger_pre_start()
*) opts="${opts} -m ${mac}";;
esac
 
-   if [ ! -x /sbin/macchanger ]; then
+   if [ ! -x /usr/bin/macchanger ]; then
eerror "For changing MAC addresses, emerge 
net-analyzer/macchanger"
return 1
fi
@@ -72,7 +72,7 @@ macchanger_pre_start()
for try in 1 2; do
# Sometimes the interface needs to be up
[ "${try}" -eq 2 ] && _up
-   output=$(/sbin/macchanger ${opts} "${IFACE}")
+   output=$(/usr/bin/macchanger ${opts} "${IFACE}")
rc=$?
[ "${rc}" -eq 0 ] && break
done



[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-14 Thread Sam James
commit: 1601d0dbed5d0373f0e19f90f07612bf60c59184
Author: Kerin Millar  plushkava  net>
AuthorDate: Sat Jan 14 22:58:41 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Jan 15 01:51:20 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=1601d0db

net/l2tp.sh: Rewrite to address issues of POSIX conformance (and more besides)

Ensure that awk(1) is used portably throughout.

Eliminate the use of ${parameter^^} expansion syntax, which is a bashism.

Delegate netfirc parameter parsing to xargs(1) and awk(1). The potential for
code injection is thus eliminated, to the extent that is currently possible in
netifrc. It also eliminates potential issues pertaining to word splitting and
unintentional pathname expansion.

Add additional sanity checks and increase the rigour of those that exist. For
instance, blank values are no longer permitted and the tunnel_id parameter must
match that of l2tpsession_*, in the case that l2tptunnel_* is defined.

Add additional diagnostic messages while improving the clarity of those that
already existed. This is achieved in some instances by being more precise and,
in others, through the use of English that exhibits greater formality and
consistency. At least one grammatical error was rectified.

Simplify and refine the code in terms of both structure and syntax, and greatly
reduce the number of (local) variables. As a byproduct, all complaints 
previously
raised by shellcheck have been eliminated, save for the use of local, whose
behaviour is not defined by POSIX. I have not attempted to eliminate the use of
local because, for now, it continues to be used extensively throughout the
netifrc codebase.

Honour the exit status value of ip(8) for the "add" and "del" verbs, rather
than parse STDERR.

Optimise l2tp_post_stop() by refraining from executing ip(8) and awk(8) in the
case that the interface cannot be identifed as a virtual one. Further, do not
attempt to destroy the tunnels associated with an identified session in the
case that the attempt to destroy the session has failed.

Signed-off-by: Kerin Millar  plushkava.net>
Bug: https://bugs.gentoo.org/890238
Signed-off-by: Sam James  gentoo.org>

 net/l2tp.sh | 349 +++-
 1 file changed, 206 insertions(+), 143 deletions(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index 82649b9..51a2331 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -1,6 +1,11 @@
 # Copyright (c) 2016 Emeric Verschuur 
+# Copyright (c) 2023 Kerin Millar 
 # All rights reserved. Released under the 2-clause BSD license.
-# shellcheck shell=sh disable=SC1008
+
+# Don't complain about local, even though POSIX does not define its behaviour.
+# This is unwise but, as things stand, it is being used extensively by netifrc.
+# Also, SC2034 and SC2316 are muted because they produce false-positives.
+# shellcheck shell=sh disable=SC3043,SC2034,SC2316
 
 l2tp_depend()
 {
@@ -8,166 +13,224 @@ l2tp_depend()
before bridge interface macchanger
 }
 
-# Extract parameter list to shell vars
-#   1. variable prefix
-#   2. string to parse
-_l2tp_eval_props() {
-   local prop_pref=$1
-   local prop_list=$2
-   eval set -- "$3"
-   while [ -n "$1" ]; do
-   eval "case $1 in
-   $prop_list)
-   $prop_pref$1=\"$2\"
-   shift
-   shift
-   ;;
-   *)
-   l2tp_err=\"invalid property $1\"
-   return 1
-   ;;
-   
-   esac" || return 1
-   done
-   return 0
+_l2tp_parse_opts()
+{
+   # Parses lt2psession or l2tptunnel options using xargs(1), conveying
+   # them as arguments to awk(1). The awk program interprets the arguments
+   # as a series of key/value pairs and safely prints those specified as
+   # being required as variable declarations for evaluation by sh(1).
+   # Other keys are handled similarly, only in a way that renders them a
+   # no-op. For the program to exit successfully, all key names must be
+   # well-formed, all required keys must be seen, and all values must be
+   # non-blank. Note that assigning 1 to ARGC prevents awk from treating
+   # its arguments as the names of files to be opened.
+   printf %s "$1" \
+   | LC_CTYPE=C xargs -E '' awk -v q="'" -v required_keys="$2" -v 
other_keys="$3" '
+   function shquote(str) {
+   gsub(q, q "\\" q q, str)
+   return q str q
+   }
+   BEGIN {
+   argc = ARGC
+   ARGC = 1
+   gsub(" ", "|", required_keys)
+   gsub(" ", "|", other_keys)
+   re = "^(" required_keys "|" other_keys ")$"
+   

[gentoo-commits] proj/netifrc:master commit in: net/

2023-01-14 Thread Sam James
commit: b6c67a56b566b0a178fc8eb7cac761e0f6521356
Author: Kerin Millar  plushkava  net>
AuthorDate: Sat Jan 14 23:04:46 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Jan 15 01:51:26 2023 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=b6c67a56

net/l2tp.sh: Re-order function declarations and use a consistent brace style

This is how I would initially have submitted it, only I wanted for the initial
set of changes to be legible as a unified diff.

Signed-off-by: Kerin Millar  plushkava.net>
Bug: https://bugs.gentoo.org/890238
Signed-off-by: Sam James  gentoo.org>

 net/l2tp.sh | 168 +---
 1 file changed, 82 insertions(+), 86 deletions(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index 51a2331..52b5733 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -7,14 +7,92 @@
 # Also, SC2034 and SC2316 are muted because they produce false-positives.
 # shellcheck shell=sh disable=SC3043,SC2034,SC2316
 
-l2tp_depend()
-{
+l2tp_depend() {
program ip
before bridge interface macchanger
 }
 
-_l2tp_parse_opts()
-{
+l2tp_pre_start() {
+   local declared_session declared_tunnel l2tpsession l2tptunnel
+   local name peer_session_id session_id tunnel_id
+   local encap local peer_tunnel_id remote
+   local key
+
+   if key="l2tpsession_${IFVAR:?}"; ! eval "[ \${${key}+set} ]"; then
+   return
+   elif eval "l2tpsession=\$${key}"; _is_blank "${l2tpsession}"; then
+   eend 1 "${key} is defined but its value is blank"
+   elif ! declared_session=$(_l2tp_parse_opts "${l2tpsession}" 
"peer_session_id session_id tunnel_id" "name"); then
+   eend 1 "${key} is missing at least one required parameter"
+   elif eval "${declared_session}"; [ "${name+set}" ]; then
+   eend 1 "${key} defines a \"name\" parameter, which is forbidden 
by netifrc"
+   elif ! modprobe l2tp_eth; then
+   eend 1 "Couldn't load the l2tp_eth module (perhaps the 
CONFIG_L2TP_ETH kernel option is disabled)"
+   elif key="l2tptunnel_${IFVAR}"; eval "[ \${${key}+set} ]"; then
+   if eval "l2tptunnel=\$${key}"; _is_blank "${l2tptunnel}"; then
+   eend 1 "${key} is defined but its value is blank"
+   elif ! declared_tunnel=$(_l2tp_parse_opts "${l2tptunnel}" 
"local peer_tunnel_id remote tunnel_id" "encap"); then
+   eend 1 "${key} is missing at least one required 
parameter"
+   elif set -- "${tunnel_id}"; eval "${declared_tunnel}"; [ "$1" 
!= "${tunnel_id}" ]; then
+   eend 1 "${key} defines a \"tunnel_id\" parameter that 
contradicts l2tpsession_${IFVAR}"
+   elif _l2tp_should_add_tunnel "${tunnel_id}" 
"${declared_tunnel}"; set -- $?; [ "$1" -eq 2 ]; then
+   eend 1 "Tunnel #${tunnel_id} exists but its properties 
mismatch those defined by ${key}"
+   elif [ "$1" -eq 1 ]; then
+   # The config matches an existing tunnel.
+   true
+   elif [ "${encap}" = ip ] && ! modprobe l2tp_ip; then
+   eend 1 "Couldn't load the l2tp_ip module (perhaps the 
CONFIG_L2TP_IP kernel option is disabled)"
+   else
+   ebegin "Creating L2TPv3 tunnel (tunnel_id ${tunnel_id})"
+   printf %s "l2tp add tunnel ${l2tptunnel}" \
+   | xargs -E '' ip
+   eend $?
+   fi
+   elif ! _l2tp_has_tunnel "${tunnel_id}"; then
+   # A tunnel may incorporate more than one session (link). This
+   # module allows for the user not to define a tunnel for a given
+   # session. In that case, it will be expected that the required
+   # tunnel has already been created to satisfy some other session.
+   eend 1 "Tunnel #${tunnel_id} not found (defining ${key} may be 
required)"
+   fi || return
+
+   ebegin "Creating L2TPv3 session (session_id ${session_id} tunnel_id 
${tunnel_id})"
+   printf %s "l2tp add session ${l2tpsession} name ${IFACE:?}" \
+   | xargs -E '' ip && _up
+   eend $?
+}
+
+l2tp_post_stop() {
+   local existing_session session_id tunnel_id
+
+   # This function may be invoked for every interface. If not a virtual
+   # interface, it can't possibly be one that's managed by this module, in
+   # which case running ip(8) and awk(1) would be a needless expense.
+   [ -e /sys/devices/virtual/net/"${IFACE:?}" ] \
+   && existing_session=$(_l2tp_parse_existing_session 2>/dev/null) \
+   || return 0
+
+   eval "${existing_session}"
+   set -- session_id "${session_id}" tunnel_id "${tunnel_id}"
+   ebegin "Destroying L2TPv3 session ($*)"
+   ip l2tp del session "$@"
+   eend $? &&
+   if ! _l2tp_in_session "${tunnel_id}"; then
+   shift 2

[gentoo-commits] proj/netifrc:master commit in: net/

2022-12-25 Thread Robin H. Johnson
commit: d877a5aa5b105b17ced7be467fb4412a9ddd05aa
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Dec 25 19:14:04 2022 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Dec 25 19:14:04 2022 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=d877a5aa

net/hsr: add Parallel Redundancy Protocol (PRP) support

Signed-off-by: Robin H. Johnson  gentoo.org>
Reference: https://github.com/gentoo/netifrc/pull/38

 net/hsr.sh | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/hsr.sh b/net/hsr.sh
index f5a427f..cbe35e9 100644
--- a/net/hsr.sh
+++ b/net/hsr.sh
@@ -21,6 +21,8 @@ hsr_pre_start()
eval hsr_slave1=\$hsr_slave1_${IFVAR}
eval hsr_slave2=\$hsr_slave2_${IFVAR}
eval hsr_supervision=\$hsr_supervision_${IFVAR}
+   eval hsr_version=\$hsr_version_${IFVAR}
+   eval hsr_proto=\$hsr_proto_${IFVAR}
if [ -z "${hsr_slave1}" ] || [ -z "${hsr_slave2}" ]; then
eerror "HSR interfaces require two slave interfaces to be set"
return 1
@@ -35,7 +37,10 @@ hsr_pre_start()
fi
 
ebegin "Creating HSR interface ${IFACE}"
-   cmd="ip link add name "${IFACE}" type hsr slave1 ${hsr_slave1} slave2 
${hsr_slave2} ${hsr_supervision:+supervision }${hsr_supervision}"
+   cmd="ip link add name "${IFACE}" type hsr slave1 ${hsr_slave1} slave2 
${hsr_slave2}"
+   test -n "${hsr_supervision}" && cmd="${cmd} supervision 
${hsr_supervision}"
+   test -n "${hsr_version}" && cmd="${cmd} version ${hsr_version}"
+   test -n "${hsr_proto}" && cmd="${cmd} proto ${hsr_proto}"
veinfo $cmd
if $cmd ; then
eend 0 && _up && set_interface_type hsr



[gentoo-commits] proj/netifrc:master commit in: net/

2022-12-25 Thread Robin H. Johnson
commit: bd8ff4aa89e1d56e9886dad32bb2406c8f43c747
Author: kmartin36  gtri  gatech  edu>
AuthorDate: Sat Dec 17 08:26:21 2022 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Dec 25 19:06:36 2022 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=bd8ff4aa

Adding the saved args to the stop command

Closes: https://bugs.gentoo.org/881039
Signed-off-by: Kevin Martin  gmail.com>
(cherry picked from commit 0e1c19959a6d82accdb57fa7a1f5b0036037a001)
Signed-off-by: Robin H. Johnson  gentoo.org>
Closes: https://github.com/gentoo/netifrc/pull/41

 net/dhcpcd.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index 1e1bbe0..1380944 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -90,8 +90,8 @@ dhcpcd_stop()
eval opts=\$dhcp_${IFVAR}
[ -z "${opts}" ] && opts=${dhcp}
case " ${opts} " in
-   *" release "*) dhcpcd -k "${IFACE}" ;;
-   *) dhcpcd -x "${IFACE}" ;;
+   *" release "*) dhcpcd -k "${args}" "${IFACE}" ;;
+   *) dhcpcd -x "${args}" "${IFACE}" ;;
esac
[ -f "${argsfile}" ] && rm -f "${argsfile}"
eend $?



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2021-04-05 Thread Robin H. Johnson
commit: 4bd8be5f43d07a9e92b73174c7fbef8b989aaa55
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Apr  5 19:54:47 2021 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Apr  5 20:00:28 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=4bd8be5f

net/ethtool: support more ethtool config knobs

Additional options now supported:
--set-channels
--set-dump
--set-fec
--set-phy-tunable
--set-priv-flags
--set-rxfh-indir
--per-queue
--features

Signed-off-by: Robin H. Johnson  gentoo.org>

 doc/net.example.Linux.in |  6 +++---
 net/ethtool.sh   | 15 +--
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index b2c0f82..e59ce52 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -1318,10 +1318,10 @@
 # flash change-eeprom change pause eee coalesce ring offload tunable identify 
nfc rxfh-indir ntuple
 
 # Set global order to default
-#ethtool_order="flash change-eeprom change pause eee coalesce ring offload 
tunable identify nfc rxfh-indir ntuple"
+#ethtool_order="flash change-eeprom change priv-flags channels dump pause eee 
fec coalesce per-queue ring offload features phy-tunable tunable identify nfc 
rxfh-indir ntuple"
 
-# Hypothetical network card that requires a change-eeprom toggle to enable 
flashing
-#ethtool_order_eth0="change-eeprom flash change pause eee coalesce ring 
offload tunable nfc rxfh-indir ntuple"
+# Hypothetical network card that requires a change-eeprom or priv-flags toggle 
to enable flashing
+#ethtool_order_eth0="priv-flags change-eeprom flash channels dump pause eee 
fec coalesce per-queue ring offload features phy-tunable tunable identify nfc 
rxfh-indir ntuple"
 
 #-
 # Firewalld support

diff --git a/net/ethtool.sh b/net/ethtool.sh
index 0bcceff..ee595a2 100644
--- a/net/ethtool.sh
+++ b/net/ethtool.sh
@@ -17,7 +17,7 @@ ethtool_pre_start() {
local order opt OFS="${OIFS}"
eval order=\$ethtool_order_${IFVAR}
[ -z "${order}" ] && eval order=\$ethtool_order
-   [ -z "${order}" ] && order="flash change-eeprom change pause eee 
coalesce ring offload tunable identify nfc rxfh-indir ntuple"
+   [ -z "${order}" ] && order="flash change-eeprom change priv-flags 
channels dump pause eee fec coalesce per-queue ring offload features 
phy-tunable tunable identify nfc rxfh-indir ntuple"
# ethtool options not used: --driver, --register-dump, --eeprom-dump, 
--negotiate, --test, --statistics
eindent
for opt in ${order} ; do
@@ -36,7 +36,18 @@ ethtool_pre_start() {
local args_pretty="$(_trim "${p}")"
# Do nothing if empty
[ -z "${args_pretty}" ] && continue
-   [ "${opt}" = "eee" -o "${opt}" = "ring" -o "${opt}" = 
"tunable" ] && opt="set-${opt}"
+   case "$opt" in
+   # Cleaner to patch in future for new options
+   channels) opt="set-${opt}" ;;
+   dump) opt="set-${opt}" ;;
+   eee) opt="set-${opt}" ;;
+   fec) opt="set-${opt}" ;;
+   phy-tunable) opt="set-${opt}" ;;
+   priv-flags) opt="set-${opt}" ;;
+   ring) opt="set-${opt}" ;;
+   rxfh-indir) opt="set-${opt}" ;;
+   tunable) opt="set-${opt}" ;;
+   esac
args_pretty="--${opt} $IFACE ${args_pretty}"
args="--${opt} $IFACE ${args}"
ebegin "ethtool ${args_pretty}"



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2021-04-05 Thread Robin H. Johnson
commit: b8373edc844297fb54333ffab69d0cd0a7b5e0b8
Author: Maciej S. Szmigiero  maciej  szmigiero  name>
AuthorDate: Sat Mar 27 22:32:35 2021 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sat Mar 27 22:34:02 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=b8373edc

net/ethtool.sh: add "eee" and "tunable" setting operations

This adds an ability to set "eee" and "tunable" ethtool parameters of a
network interface.

Signed-off-by: Maciej S. Szmigiero  maciej.szmigiero.name>

 doc/net.example.Linux.in | 12 +---
 net/ethtool.sh   |  4 ++--
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index 3bd2ee1..b2c0f82 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -1275,12 +1275,18 @@
 #ethtool_pause_eth0="autoneg off
 #rx on tx on"
 
+# Enable Energy-Efficient Ethernet
+#ethtool_eee_eth0="eee on"
+
 # Enable adaptive RX and TX coalescing
 #ethtool_coalesce_eth0="adaptive-rx on adaptive-tx on"
 
 # Change ring buffer settings
 #ethtool_ring_eth0=""
 
+# Set RX copy-break at 1500 bytes
+#ethtool_tunable_eth0="rx-copybreak 1500"
+
 # Enable all offload settings
 #ethtool_offload_eth0="rx on tx on sg on tso on ufo on gso on gro on lro on"
 
@@ -1309,13 +1315,13 @@
 
 # Additionally, there is a special control variable, if you need to change the
 # order of option processing. The default order is:
-# flash change-eeprom change pause coalesce ring offload identify nfc 
rxfh-indir ntuple
+# flash change-eeprom change pause eee coalesce ring offload tunable identify 
nfc rxfh-indir ntuple
 
 # Set global order to default
-#ethtool_order="flash change-eeprom change pause coalesce ring offload 
identify nfc rxfh-indir ntuple"
+#ethtool_order="flash change-eeprom change pause eee coalesce ring offload 
tunable identify nfc rxfh-indir ntuple"
 
 # Hypothetical network card that requires a change-eeprom toggle to enable 
flashing
-#ethtool_order_eth0="change-eeprom flash change pause coalesce ring offload 
nfc rxfh-indir ntuple"
+#ethtool_order_eth0="change-eeprom flash change pause eee coalesce ring 
offload tunable nfc rxfh-indir ntuple"
 
 #-
 # Firewalld support

diff --git a/net/ethtool.sh b/net/ethtool.sh
index 57c98f7..0bcceff 100644
--- a/net/ethtool.sh
+++ b/net/ethtool.sh
@@ -17,7 +17,7 @@ ethtool_pre_start() {
local order opt OFS="${OIFS}"
eval order=\$ethtool_order_${IFVAR}
[ -z "${order}" ] && eval order=\$ethtool_order
-   [ -z "${order}" ] && order="flash change-eeprom change pause coalesce 
ring offload identify nfc rxfh-indir ntuple"
+   [ -z "${order}" ] && order="flash change-eeprom change pause eee 
coalesce ring offload tunable identify nfc rxfh-indir ntuple"
# ethtool options not used: --driver, --register-dump, --eeprom-dump, 
--negotiate, --test, --statistics
eindent
for opt in ${order} ; do
@@ -36,7 +36,7 @@ ethtool_pre_start() {
local args_pretty="$(_trim "${p}")"
# Do nothing if empty
[ -z "${args_pretty}" ] && continue
-   [ "${opt}" = "ring" ] && opt="set-ring"
+   [ "${opt}" = "eee" -o "${opt}" = "ring" -o "${opt}" = 
"tunable" ] && opt="set-${opt}"
args_pretty="--${opt} $IFACE ${args_pretty}"
args="--${opt} $IFACE ${args}"
ebegin "ethtool ${args_pretty}"



[gentoo-commits] proj/netifrc:master commit in: net/

2021-03-30 Thread Patrick McLean
commit: 4143e26dd4a56c08fbb99e18913eaafaf2a04f32
Author: Patrick McLean  gentoo  org>
AuthorDate: Wed Mar 31 01:07:57 2021 +
Commit: Patrick McLean  gentoo  org>
CommitDate: Wed Mar 31 01:11:03 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=4143e26d

net/iproute2.sh: in _get_mac_address, don't return multiple addresses

Currently if a device has virtual functions configured, ip will list the mac
addresses for the virtual functions on a device as well as the device itself.
This makes _get_mac_address return these addresses as well, causing functions
that consume this output to fail in "interesting" ways. This makes sure it only
returns 1 address.

Also don't set the mac variable to the address of the interface from sysfs, then
proceed to overwrite it with a call to "ip".

Signed-off-by: Patrick McLean  gentoo.org>

 net/iproute2.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 46f0e48..bd7333e 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -91,10 +91,9 @@ _set_flag()
 _get_mac_address()
 {
local mac=
-   read -r mac < /sys/class/net/"${IFACE}"/address || return 1
-   local mac=$(LC_ALL=C _ip link show "${IFACE}" | sed -n \
+   mac=$(LC_ALL=C _ip link show "${IFACE}" | sed -n \
-e 'y/abcdef/ABCDEF/' \
-   -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p')
+   -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p' | head -n1)
 
case "${mac}" in
00:00:00:00:00:00) return 1 ;;



[gentoo-commits] proj/netifrc:master commit in: net/

2021-03-11 Thread Lars Wendler
commit: 2eca000593194ef3bcf099b8bb1003bb5ea4292f
Author: Patrick McLean  gentoo  org>
AuthorDate: Sat Nov 21 06:52:48 2020 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Thu Mar 11 16:53:33 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=2eca0005

net/bonding.sh: Add support for network namespaces

Signed-off-by: Lars Wendler  gentoo.org>

 net/bonding.sh | 57 +++--
 1 file changed, 31 insertions(+), 26 deletions(-)

diff --git a/net/bonding.sh b/net/bonding.sh
index 880f69b..1757a89 100644
--- a/net/bonding.sh
+++ b/net/bonding.sh
@@ -12,13 +12,18 @@ bonding_depend()
if [ ! -d /sys/class/net ]; then
program /sbin/ifenslave
fi
+
+   local netns
+   eval netns="\$netns_${IFVAR}"
+   [ -n "${netns}" ] && program ip
+   return 0
 }
 
 _config_vars="$_config_vars slaves"
 
 _is_bond()
 {
-   [ -f "/proc/net/bonding/${IFACE}" ]
+   _netns [ -f "/proc/net/bonding/${IFACE}" ]
 }
 
 bonding_pre_start()
@@ -52,7 +57,7 @@ bonding_pre_start()
# We can create the interface name we like now, but this
# requires sysfs
if ! _exists && [ -d /sys/class/net ]; then
-   echo "+${IFACE}" > /sys/class/net/bonding_masters
+   _netns echo "+${IFACE}" \> /sys/class/net/bonding_masters
fi
_exists true || return 1
 
@@ -68,13 +73,13 @@ bonding_pre_start()
# we configure all other options
# mode needs to be done before all other options.
# miimon needs to be done BEFORE downdelay
-   [ -d /sys/class/net ] && for n in mode miimon; do
+   _netns [ -d /sys/class/net ] && for n in mode miimon; do
x=/sys/class/net/"${IFACE}"/bonding/$n
-   [ -f "${x}" ] || continue
+   _netns [ -f "${x}" ] || continue
eval s=\$${n}_${IFVAR}
if [ -n "${s}" ]; then
einfo "Setting ${n}: ${s}"
-   echo "${s}" >"${x}" || \
+   _netns echo "${s}" \>"${x}" || \
eerror "Failed to configure $n (${n}_${IFVAR})"
fi
done
@@ -82,19 +87,19 @@ bonding_pre_start()
# With a leading '+' as a prefix.
n=arp_ip_target
x=/sys/class/net/"${IFACE}"/bonding/$n
-   [ -d /sys/class/net ] && if [ -f "$x" ]; then
+   _netns [ -d /sys/class/net ] && if _netns [ -f "$x" ]; then
eval s=\$${n}_${IFVAR}
if [ -n "${s}" ]; then
for i in $s; do
einfo "Adding ${n}: ${i}"
-   echo "+${i/+/}" >"${x}" || \
+   _netns echo "+${i/+/}" \>"${x}" || \
eerror "Failed to add $i (${n}_${IFVAR})"
done
fi
fi
# Nice and dynamic for remaining options:)
-   [ -d /sys/class/net ] && for x in /sys/class/net/"${IFACE}"/bonding/*; 
do
-   [ -f "${x}" ] || continue
+   _netns [ -d /sys/class/net ] && for x in $(_netns glob 
/sys/class/net/"${IFACE}"/bonding/\*); do
+   _netns [ -f "${x}" ] || continue
n=${x##*/}
# These entries are already handled above.
case "$n" in
@@ -106,7 +111,7 @@ bonding_pre_start()
eval s=\$${n}_${IFVAR}
if [ -n "${s}" ]; then
einfo "Setting ${n}: ${s}"
-   echo "${s}" >"${x}" || \
+   _netns echo "${s}" \>"${x}" || \
eerror "Failed to configure $n (${n}_${IFVAR})"
fi
done
@@ -145,9 +150,9 @@ bonding_pre_start()
unset oiface
eoutdent
# subsume (presumably kernel auto-)configured IP
-   if [ -x "$(command -v ip)" ]; then
-   ip link set ${IFACE} up
-   ip address add ${addr} dev ${IFACE}
+   if [ -x "$(command -v ip 2>/dev/null)" ]; then
+   _netns ip link set ${IFACE} up
+   _netns ip address add ${addr} dev ${IFACE}
else
ifconfig ${IFACE} ${addr} up
fi
@@ -171,7 +176,7 @@ bonding_pre_start()
# set mtu: ifenslave, kernel
# set slave MAC: ifenslave, kernel
eoutdent
-   if [ -d /sys/class/net ]; then
+   if _netns [ -d /sys/class/net ]; then
sys_bonding_path=/sys/class/net/"${IFACE}"/bonding
local oiface
oiface=$IFACE
@@ -179,20 +184,20 @@ bonding_pre_start()
IFACE=$primary
_down
IFACE=$oiface
-   echo "+${primary}" >$sys_bonding_path/slaves
-   echo "${primary}" >$sys_bonding_path/primary
+ 

[gentoo-commits] proj/netifrc:master commit in: net/

2021-03-11 Thread Lars Wendler
commit: b581c3f76b95bd2173a13d08054120f284ac06e7
Author: Patrick McLean  gentoo  org>
AuthorDate: Sat Nov 21 06:53:31 2020 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Thu Mar 11 16:53:33 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=b581c3f7

net/bridge.sh: Add support for network namespaces when using iproute2

Signed-off-by: Lars Wendler  gentoo.org>

 net/bridge.sh | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/net/bridge.sh b/net/bridge.sh
index 4166215..a380f6a 100644
--- a/net/bridge.sh
+++ b/net/bridge.sh
@@ -12,19 +12,19 @@ _config_vars="$_config_vars bridge bridge_add brctl"
 
 _is_bridge()
 {
-   [ -d /sys/class/net/"${1:-${IFACE}}"/bridge ]
+   _netns [ -d /sys/class/net/"${1:-${IFACE}}"/bridge ]
return $?
 }
 
 _is_bridge_port()
 {
-   [ -d /sys/class/net/"${1:-${IFACE}}"/brport ]
+   _netns [ -d /sys/class/net/"${1:-${IFACE}}"/brport ]
return $?
 }
 
 _bridge_ports()
 {
-   for x in /sys/class/net/"${1:-${IFACE}}"/brif/*; do
+   for x in $(_netns glob /sys/class/net/"${1:-${IFACE}}"/brif/\*); do
n=${x##*/}
echo $n
done
@@ -82,7 +82,7 @@ bridge_pre_start()
if ! _is_bridge ; then
ebegin "Creating bridge ${IFACE}"
if ${do_iproute2}; then
-   ip link add "${IFACE}" type bridge
+   _netns ip link add "${IFACE}" type bridge
rc=$?
elif ${do_brctl}; then
brctl addbr "${IFACE}"
@@ -123,7 +123,7 @@ bridge_pre_start()
fi
 
# New configuration set mechanism, matches bonding
-   for x in /sys/class/net/"${IFACE}"/bridge/*; do
+   for x in $(_netns glob /sys/class/net/"${IFACE}"/bridge/\*); do
[ -f "${x}" ] || continue
n=${x##*/}
# keep no prefix for backward compatibility
@@ -132,7 +132,7 @@ bridge_pre_start()
if [ -n "${s}" ]; then
[ -z "${prefix}" ] && ewarn "sysfs key 
'${n}_${IFVAR}' should be prefixed, please add bridge_ prefix."
einfo "Setting ${n}: ${s}"
-   echo "${s}" >"${x}" || \
+   _netns echo "${s}" \>"${x}" || \
eerror "Failed to configure $n (${n}_${IFVAR})"
fi
done
@@ -154,7 +154,7 @@ bridge_pre_start()
# The interface is known to exist now
_up
if ${do_iproute2}; then
-   ip link set "${x}" master "${BR_IFACE}"
+   _netns ip link set "${x}" master "${BR_IFACE}"
elif ${do_brctl}; then
brctl addif "${BR_IFACE}" "${x}"
fi
@@ -163,7 +163,7 @@ bridge_pre_start()
return 1
fi
# Per-interface bridge settings
-   for x in /sys/class/net/"${IFACE}"/brport/*; do
+   for x in $(_netns glob 
/sys/class/net/"${IFACE}"/brport/\*); do
[ -f "${x}" ] || continue
n=${x##*/}
for prefix in "" brport_; do
@@ -171,7 +171,7 @@ bridge_pre_start()
if [ -n "${s}" ]; then
[ -z "${prefix}" ] && ewarn 
"sysfs key '${n}_${IFVAR}' should be prefixed, please add brport_ prefix."
einfo "Setting ${n}@${IFACE}: 
${s}"
-   echo "${s}" >"${x}" || \
+   _netns echo "${s}" \>"${x}" || \
eerror "Failed to configure $n 
(${n}_${IFVAR})"
fi
done
@@ -194,7 +194,7 @@ bridge_post_stop()
if _is_bridge "${IFACE}"; then
ebegin "Destroying bridge ${IFACE}"
_down
-   for x in /sys/class/net/"${IFACE}"/brif/*; do
+   for x in $(_netns glob /sys/class/net/"${IFACE}"/brif/\*); do
[ -s $x ] || continue
n=${x##*/}
ports="${ports} ${n}"
@@ -206,8 +206,8 @@ bridge_post_stop()
# We are taking down an interface that is part of a bridge maybe
ports="${IFACE}"
local brport_dir="/sys/class/net/${IFACE}/brport"
-   [ -d ${brport_dir} ] || return 0
-   iface=$(readlink ${brport_dir}/bridge)
+   _netns [ -d ${brport_dir} ] || return 0
+   iface=$(_netns readlink 

[gentoo-commits] proj/netifrc:master commit in: net/

2021-03-11 Thread Lars Wendler
commit: f56e5753063e4d461b3e140e50bcbd6a60b0c1eb
Author: Patrick McLean  gentoo  org>
AuthorDate: Sat Nov 21 06:53:54 2020 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Thu Mar 11 16:53:33 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=f56e5753

net/dummy.sh: Add support for network namespaces

Closes: https://github.com/gentoo/netifrc/pull/35
Signed-off-by: Lars Wendler  gentoo.org>

 net/dummy.sh | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/net/dummy.sh b/net/dummy.sh
index 421d951..091e08c 100644
--- a/net/dummy.sh
+++ b/net/dummy.sh
@@ -13,16 +13,20 @@ _is_dummy() {
is_interface_type dummy
 }
 
+_ip()
+{
+   veinfo ip "${@}"
+   _netns ip "${@}"
+}
+
 dummy_pre_start()
 {
local dummy=
-   eval dummy=\$type_${IFVAR}
+   eval dummy="\$type_${IFVAR}"
[ "${dummy}" = "dummy" ] || return 0
 
ebegin "Creating dummy interface ${IFACE}"
-   cmd="ip link add name "${IFACE}" type dummy"
-   veinfo $cmd
-   if $cmd ; then
+   if _ip link add name "${IFACE}" type dummy ; then
eend 0 && _up && set_interface_type dummy
else
eend 1
@@ -35,8 +39,6 @@ dummy_post_stop()
_is_dummy || return 0
 
ebegin "Removing dummy ${IFACE}"
-   cmd="ip link delete "${IFACE}" type dummy"
-   veinfo "$cmd"
-   $cmd
+   _ip link delete "${IFACE}" type dummy
eend $?
 }



[gentoo-commits] proj/netifrc:master commit in: net/

2021-02-02 Thread Lars Wendler
commit: b60fd3319a254dfacf0051dc0e5343a8fe6e87f1
Author: Kerin Millar  plushkava  net>
AuthorDate: Tue Feb  2 03:47:13 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Tue Feb  2 08:27:02 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=b60fd331

net/apipa.sh: Simplify and address the remaining portability issues

Re-factor the over-generalised seeding function into a _random_uint16
function. Have it use a simpler, faster method to collect entropy, with
the aid of od(1). Shorten the previously rambling comment.

Simplify the _random_apipa_octets function. Clamp the seed to the range
0-32767 for maximal portability. Convey the seed as a formal parameter,
rather then inject it. Use a simpler method to produce the octets, running
awk(1) only once. Format the random float, so that awk(1) is prevented
from using scientific notation to represent certain numbers.

Change a variable name in the subshell responsible for reading the list of
octet pairs, so as to be less confusing to future readers.

Note that the portability issue mentioned by commit 31a05f1 is addressed.
The code should now be fully POSIX-compliant, save for the continued use
of the local keyword, upon which it does not rely.

Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Lars Wendler  gentoo.org>

 net/apipa.sh | 63 
 1 file changed, 29 insertions(+), 34 deletions(-)

diff --git a/net/apipa.sh b/net/apipa.sh
index 41274fa..a124b84 100644
--- a/net/apipa.sh
+++ b/net/apipa.sh
@@ -6,47 +6,42 @@ apipa_depend()
program /sbin/arping /bin/arping
 }
 
-_random_bytes_as_int()
+_random_uint16()
 {
-   local hex num_bytes="$1"
-
-   # While POSIX does not require that /dev/urandom exist, it is a
-   # de-facto standard. Therefore, the following approach should be
-   # highly portable in practice. In the case of Linux, and unlike BSD
-   # this interface does not block in the event that the CSRNG has not
-   # yet been seeded. Still, this is acceptable because we do not
-   # require a guarantee that the entropy be cryptographically secure.
-   # It's also worth noting that Linux >=5.4 is faster at seeding in
-   # the absence of RDRAND/RDSEED than previous versions were.
+   # While POSIX does not require that /dev/urandom exist, it is a de-facto
+   # standard. In the case of Linux, and unlike BSD, this interface does
+   # not block in the event that the CSRNG has not yet been seeded.
+   # Still, this is acceptable because we do not require a guarantee that
+   # the entropy be cryptographically secure.
test -e /dev/urandom &&
-   hex=$(
-   LC_ALL=C tr -dc '[:xdigit:]' < /dev/urandom |
-   dd bs="$(( num_bytes * 2 ))" count=1 2>/dev/null) &&
-   test "${#hex}" = "$(( num_bytes * 2 ))" &&
-   printf '%d\n' "0x${hex}"
+   printf %d 0x"$(LC_ALL=C od -vAn -N2 -tx1 /dev/urandom | tr -d 
'[:space:]')"
 }
 
 _random_apipa_octets()
 {
local seed
 
-   # Obtain a highly random 16-bit seed for use by awk's RNG. In the
-   # unlikely event that the seed ends up being empty, awk will seed
-   # based on the time of day, with a granularity of one second.
-   seed=$(_random_bytes_as_int 2)
+   # Attempt to generate a random uint16 to seed awk's RNG. The maximum
+   # value of RAND_MAX known to be portable is 32767. Clamp accordingly by
+   # discarding one bit's worth of data. Should the seed turn out to be
+   # empty, we instruct awk to seed based on the time of day, in seconds.
+   seed=$(_random_uint16) && : $(( seed >>= 1 ))
 
# For APIPA (RFC 3927), the 169.254.0.0/16 address block is
# reserved. This provides 65024 addresses, having accounted for the
# fact that the first and last /24 are reserved for future use.
-   awk "BEGIN {
-   srand($seed)
-   for (i=256; i<65280; i++) print rand() \" \" i
-   }" |
-   sort -k 1,1 -n |
-   POSIXLY_CORRECT=1 awk '{
-   hex = sprintf("%04x",$2)
-   printf("%d %d\n", "0x" substr(hex,1,2), "0x" substr(hex,3,2))
-   }'
+   awk -v seed="$seed" 'BEGIN {
+   if (seed != "") {
+   srand(seed)
+   } else {
+   srand()
+   }
+   for (i = 1; i < 255; i++) {
+   for (j = 0; j < 256; j++) {
+   printf("%f %d %d\n", rand(), i, j)
+   }
+   }
+   }' | sort -k 1,1 -n
 }
 
 apipa_start()
@@ -62,11 +57,11 @@ apipa_start()
addr=$(
_random_apipa_octets |
{
-   while read -r i1 i2; do
-   addr="169.254.${i1}.${i2}"
-   vebegin "${addr}/16" >&3
-   if ! 

[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-27 Thread Lars Wendler
commit: e5c3bb95ed454a270cf1796bc123fb0c8f34ab5a
Author: Kerin Millar  plushkava  net>
AuthorDate: Wed Jan 27 16:25:05 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Wed Jan 27 16:55:21 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=e5c3bb95

net/apipa.sh: Account for the first and last /24 being reserved

While the 169.254/16 prefix is used to define IPv4 link-local addresses,
RFC 3927 states that the first 256 and last 256 addresses are reserved for
future use. Therefore, the number of available addresses amounts to neither
64516 nor 65534, but actually 65024.

Signed-off-by: Kerin Millar  plushkava.net>
Signed-off-by: Lars Wendler  gentoo.org>

 net/apipa.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/apipa.sh b/net/apipa.sh
index f3ec534..41274fa 100644
--- a/net/apipa.sh
+++ b/net/apipa.sh
@@ -36,11 +36,11 @@ _random_apipa_octets()
seed=$(_random_bytes_as_int 2)
 
# For APIPA (RFC 3927), the 169.254.0.0/16 address block is
-   # reserved. This provides 65534 addresses, having accounted for the
-   # network and broadcast address. Note that we must count from 1.
+   # reserved. This provides 65024 addresses, having accounted for the
+   # fact that the first and last /24 are reserved for future use.
awk "BEGIN {
srand($seed)
-   for (i=1; i<65535; i++) print rand() \" \" i
+   for (i=256; i<65280; i++) print rand() \" \" i
}" |
sort -k 1,1 -n |
POSIXLY_CORRECT=1 awk '{



[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-27 Thread Lars Wendler
commit: b89e0687fb4facfc7f36fc137944856cf331271c
Author: Lars Wendler  gentoo  org>
AuthorDate: Wed Jan 27 14:16:39 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Wed Jan 27 14:16:39 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=b89e0687

net/iwd.sh: Removed non-working "need dbus" call

This is a copy-paste remnant from net/wpa_supplicant.sh which never
worked with standalone netifrc.

Signed-off-by: Lars Wendler  gentoo.org>

 net/iwd.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/iwd.sh b/net/iwd.sh
index e3f64b2..d8be2d5 100644
--- a/net/iwd.sh
+++ b/net/iwd.sh
@@ -3,7 +3,6 @@
 
 iwd_depend()
 {
-   need dbus
after macnet plug
before interface
provide wireless



[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-27 Thread Lars Wendler
commit: 31a05f1b3fb90a3b4e9c0e587bdd5a39e8236f6b
Author: Kerin Millar  plushkava  net>
AuthorDate: Mon Jan 25 02:40:29 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Wed Jan 27 14:05:54 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=31a05f1b

net/apipa.sh: fix broken implementation by way of a rewrite

Sadly, the present implementation has never functioned correctly. The
original author employed incorrect syntax for what was intended to be a
command substitution. As a result, the _random() function is never called.
What actually happens is that arping is needlessly executed exactly 64516
times, with no address ever being considered as a valid candidate.

Furthermore, this module has other bugs and is poorly designed. Here are the
reasons as to why:-

  • the 169.254.0.0/16 block offers 65534 addresses, not 64516
  • the main loop is horrendously slow at enumerating the address block
  • it counts to 64516 but doesn't ensure that each address is unique!
  • it prefers bash for generating entropy (fine, but non-standard)
  • it falls back to a non-standard utility for generating entropy

Therefore, I decided to re-write most of it. The fundamental difference is
that all 65534 octet pairs are generated up front before being processed by
the main loop. At most, every possible address will now be tested exactly
once.

In fact, this approach turns out to be faster by an order of magnitude. The
following synthetic tests - which calculate the time taken to enumerate the
entire address space - demonstrate the tremendous difference between the
existing code and mine. Of course, to ensure that the comparison was
meaningful, I rectified the command substitution bug in the existing code.

  # time bash apipa-old-test.sh
  real2m34.367s
  user1m9.959s
  sys 1m37.502s

  # time bash apipa-new-test.sh
  real0m1.119s
  user0m0.965s
  sys 0m0.182s

Note that the new _random_apipa_octets() function is responsible for
generating all 65534 combinations of octet pairs in a random order. It
mainly relies on awk(1) and sort(1). Where possible, a seed is obtained from
/dev/urandom for the benefit of awk's RNG, but this is not required.

I have isolated and tested the new functions on GNU/Linux, macOS, FreeBSD,
NetBSD, OpenBSD and MirBSD. I have individually tested gawk, mawk, nawk,
busybox awk and the awk implementations provided by the previously mentioned
operating systems in the case that they are distinct. The only
incompatiblity that I was personally able to find was with the awk
implementation of MirBSD, which affects the final invocation of awk in the
_random_apipa_octets function.  However, MirBSD was forked from an old
version of OpenBSD and seems sufficiently obscure so as not to be worth
worrying about. If someone should try to integrate netifrc into MirBSD one
day then the matter can be dealt with then.

Finally, I want to thank Steve Arnold for bringing the original bug to my
attention. Congratulations, Steve. You may be the only known user of
net/apipa.sh on the planet.

Signed-off-by: Kerin Millar  plushkava.net>
Reported-by: Steve Arnold  gentoo.org>
Closes: https://bugs.gentoo.org/766890
Signed-off-by: Lars Wendler  gentoo.org>

 net/apipa.sh | 94 +++-
 1 file changed, 67 insertions(+), 27 deletions(-)

diff --git a/net/apipa.sh b/net/apipa.sh
index 849728b..f3ec534 100644
--- a/net/apipa.sh
+++ b/net/apipa.sh
@@ -1,49 +1,89 @@
 # Copyright (c) 2007-2008 Roy Marples 
 # Released under the 2-clause BSD license.
-# shellcheck shell=sh disable=SC1008
 
 apipa_depend()
 {
program /sbin/arping /bin/arping
 }
 
-_random()
+_random_bytes_as_int()
 {
-   local r=${RANDOM} # checkbashisms: false positive, we handle it 
AFTERWARDS
-   if [ -n "${r}" ]; then
-   echo "${r}"
-   else
-   uuidgen | sed -n -e 's/[^[:digit:]]//g' -e 
's/\(^.\{1,7\}\).*/\1/p'
-   fi
+   local hex num_bytes="$1"
+
+   # While POSIX does not require that /dev/urandom exist, it is a
+   # de-facto standard. Therefore, the following approach should be
+   # highly portable in practice. In the case of Linux, and unlike BSD
+   # this interface does not block in the event that the CSRNG has not
+   # yet been seeded. Still, this is acceptable because we do not
+   # require a guarantee that the entropy be cryptographically secure.
+   # It's also worth noting that Linux >=5.4 is faster at seeding in
+   # the absence of RDRAND/RDSEED than previous versions were.
+   test -e /dev/urandom &&
+   hex=$(
+   LC_ALL=C tr -dc '[:xdigit:]' < /dev/urandom |
+   dd bs="$(( num_bytes * 2 ))" count=1 2>/dev/null) &&
+   test "${#hex}" = "$(( num_bytes * 2 ))" &&
+   printf '%d\n' "0x${hex}"
+}
+
+_random_apipa_octets()
+{
+   local seed
+
+   # Obtain a highly random 16-bit seed for use by awk's RNG. 

[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-24 Thread Lars Wendler
commit: 6632c348cce8be19c7a960cabb2f6f41ec4c6d51
Author: Kerin Millar  plushkava  net>
AuthorDate: Sun Jan 24 02:49:43 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Sun Jan 24 10:21:20 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=6632c348

Use sysfs to obtain the MAC address in net/iproute2.sh

Dispense with the hideous ip-link(8) parser. Instead, collect the MAC
address by reading from the relevant sysfs file. While at it, tidy up
the remainder of the function so that the control flow is easier to
ascertain at a glance. Note that the address will be rendered in upper
case, just as it was before.

Signed-off-by: Kerin Millar  plushkava.net>
Closes: https://bugs.gentoo.org/766758
Signed-off-by: Lars Wendler  gentoo.org>

 net/iproute2.sh | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 4c32acc..2289587 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -70,19 +70,16 @@ _set_flag()
 
 _get_mac_address()
 {
-   local mac=$(LC_ALL=C ip link show "${IFACE}" | sed -n \
-   -e 'y/abcdef/ABCDEF/' \
-   -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p')
+   local mac=
+   read -r mac < /sys/class/net/"${IFACE}"/address || return 1
 
case "${mac}" in
-   00:00:00:00:00:00);;
-   44:44:44:44:44:44);;
-   FF:FF:FF:FF:FF:FF);;
-   "");;
-   *) echo "${mac}"; return 0;;
+   00:00:00:00:00:00) return 1 ;;
+   44:44:44:44:44:44) return 1 ;;
+   ff:ff:ff:ff:ff:ff) return 1 ;;
esac
 
-   return 1
+   printf '%s\n' "${mac}" | LC_ALL=C tr '[:lower:]' '[:upper:]'
 }
 
 _set_mac_address()



[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-18 Thread Lars Wendler
commit: 60bd853443f8e01c4309aeb2f3198f959c62cfdf
Author: Lars Wendler  gentoo  org>
AuthorDate: Mon Jan 18 14:21:31 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Mon Jan 18 14:26:11 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=60bd8534

net/wpa_supplicant.sh: Removed non-working "need dbus" call

This is a remnant from when netifrc was part of openrc.
After netifrc became it's own standalone project, the call "need dbus"
got caught by the need() function from openrc's sh/openrc-run.sh script
which does a simple echo on every input it receives.

Bug: https://bugs.gentoo.org/622730
Signed-off-by: Lars Wendler  gentoo.org>

 net/wpa_supplicant.sh | 8 
 1 file changed, 8 deletions(-)

diff --git a/net/wpa_supplicant.sh b/net/wpa_supplicant.sh
index d5e2013..3f8e1b1 100644
--- a/net/wpa_supplicant.sh
+++ b/net/wpa_supplicant.sh
@@ -4,14 +4,6 @@
 
 wpa_supplicant_depend()
 {
-   wpas=/usr/sbin/wpa_supplicant
-   [ -x ${wpas} ] || wpas=/sbin/wpa_supplicant
-   if [ -x ${wpas} ]; then
-   program start ${wpas}
-   # bug 345281: if wpa_supplicant is built w/ USE=dbus, we need 
to start
-   # dbus before we can start wpa_supplicant.
-   ${wpas} -h | grep -Fsq DBus && need dbus
-   fi
after macnet plug
before interface
provide wireless



[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-18 Thread Lars Wendler
commit: 72b3a820214fc50d50b8ac0f031491106d8d8634
Author: Lars Wendler  gentoo  org>
AuthorDate: Mon Jan 18 13:01:54 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Mon Jan 18 13:01:54 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=72b3a820

net/pppd.sh: Completely overhauled pppd version check

Thanks-to: Kerin Millar  plushkava.net>
Bug: https://bugs.gentoo.org/729920

Signed-off-by: Lars Wendler  gentoo.org>

 net/pppd.sh | 24 +++-
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/net/pppd.sh b/net/pppd.sh
index 2182497..22644f2 100644
--- a/net/pppd.sh
+++ b/net/pppd.sh
@@ -23,28 +23,10 @@ requote()
 
 pppd_is_ge_248()
 {
-   local ver_str="$(/usr/sbin/pppd --version 2>&1 | awk '/pppd version/ 
{print $3}')"
-   local maj_ver="$(echo ${ver_str} | cut -d . -f 1)"
-   local min_ver="$(echo ${ver_str} | cut -d . -f 2)"
-   local patch_ver="$(echo ${ver_str} | cut -d . -f 3)"
+   local ver_str="$(/usr/sbin/pppd --version 2>&1 | awk '/pppd version/ 
{print $3}' | tr '.' ' ')"
 
-   if [ "${maj_ver}" -gt 2 ] ; then
-   return 0
-   elif [ "${maj_ver}" -eq 2 ] ; then
-   if [ "${min_ver}" -gt 4 ] ; then
-   return 0
-   elif [ "${min_ver}" -eq 4 ] ; then
-   if [ "${patch_ver}" -ge 8 ] ; then
-   return 0
-   else
-   return 1
-   fi
-   else
-   return 1
-   fi
-   else
-   return 1
-   fi
+   # 002004008 is v2.4.8
+   [ "$(printf '%03d' ${ver_str})" -ge 002004008 ]
 }
 
 pppd_pre_start()



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2021-01-18 Thread Lars Wendler
commit: f9951f7d42f1f5ad57e14a29a0be85a80d9a863a
Author: Lars Wendler  gentoo  org>
AuthorDate: Mon Jan 18 10:45:36 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Mon Jan 18 12:32:31 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=f9951f7d

Convert many "grep" calls to "grep -F"

Signed-off-by: Lars Wendler  gentoo.org>

 doc/net.example.Linux.in | 6 +++---
 net/ifconfig.sh.Linux.in | 2 +-
 net/iproute2.sh  | 6 +++---
 net/iw.sh| 4 ++--
 net/iwconfig.sh.Linux.in | 5 ++---
 net/wpa_supplicant.sh| 3 +--
 6 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index b404329..bafde42 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -1365,7 +1365,7 @@
 #  # Test for link on the interface prior to bringing it up.  This
 #  # only works on some network adapters and requires the
 #  # sys-apps/net-tools package to be installed.
-#  if mii-tool "${IFACE}" 2> /dev/null | grep -q 'no link'; then
+#  if mii-tool "${IFACE}" 2> /dev/null | grep -Fq 'no link'; then
 #  ewarn "No link on ${IFACE}, aborting configuration"
 #  return 1
 #  fi
@@ -1373,14 +1373,14 @@
 #  # Test for link on the interface prior to bringing it up.  This
 #  # only works on some network adapters and requires the ethtool
 #  # package to be installed.
-#  if ethtool "${IFACE}" | grep -q 'Link detected: no'; then
+#  if ethtool "${IFACE}" | grep -Fq 'Link detected: no'; then
 #  ewarn "No link on ${IFACE}, aborting configuration"
 #  return 1
 #  fi
 #
 #  # Test to see if we're docked or not and configure like so
 #  # config_docked="dhcp"
-#  if grep -q "1" /sys/devices/platform/dock.0/docked; then
+#  if grep -Fq "1" /sys/devices/platform/dock.0/docked; then
 #   einfo "${IFACE} is docked - configuring"
 #  _configure_variables "docked"
 #  fi

diff --git a/net/ifconfig.sh.Linux.in b/net/ifconfig.sh.Linux.in
index 960b239..b0a4551 100644
--- a/net/ifconfig.sh.Linux.in
+++ b/net/ifconfig.sh.Linux.in
@@ -47,7 +47,7 @@ _is_wireless()
-d /sys/class/net/"${IFACE}"/phy80211 ] && return 0
 
[ ! -e /proc/net/wireless ] && return 1
-   grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless
+   grep -q "^[[:space:]]*${IFACE}:" /proc/net/wireless
 }
 
 _set_flag()

diff --git a/net/iproute2.sh b/net/iproute2.sh
index d19f79d..4c32acc 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -192,7 +192,7 @@ _add_address()
 
# Check for address already existing:
ip addr show to "${address}/${family_maxnetmask}" dev "${IFACE}" 
2>/dev/null | \
-   fgrep -sq "${address}"
+   grep -Fsq "${address}"
address_already_exists=$?
 
# This must appear on a single line, continuations cannot be used
@@ -265,7 +265,7 @@ _add_route()
 
# Check for route already existing:
ip ${family} route show ${cmd_nometric} dev "${IFACE}" 2>/dev/null | \
-   fgrep -sq "${cmd%% *}"
+   grep -Fsq "${cmd%% *}"
route_already_exists=$?
 
_cmd ip ${family} route append ${cmd} dev "${IFACE}"
@@ -304,7 +304,7 @@ _delete_addresses()
 
 _has_carrier()
 {
-   LC_ALL=C ip link show dev "${IFACE}" | grep -q "LOWER_UP"
+   LC_ALL=C ip link show dev "${IFACE}" | grep -Fq "LOWER_UP"
 }
 
 # Used by iproute2, ip6rd & ip6to4

diff --git a/net/iw.sh b/net/iw.sh
index 029b9d6..1f8b068 100644
--- a/net/iw.sh
+++ b/net/iw.sh
@@ -212,7 +212,7 @@ iw_wait_for_association()
# carrier on or buggy madwifi drivers that
# sometimes have carrier on and ssid set
# without being associated.  :/
-   [ -n "$(iw dev "${IFACE}" info |grep ssid)" ] 
&& [ "${station_mac}" != "00:00:00:00:00:00" ] && return 0
+   [ -n "$(iw dev "${IFACE}" info | grep -F ssid)" 
] && [ "${station_mac}" != "00:00:00:00:00:00" ] && return 0
fi
else
local atest=
@@ -704,7 +704,7 @@ iw_pre_start()
 
# Store the fact that tx-power was off so we default to a longer
# wait if our scan returns nothing
-   LC_ALL=C iw dev "${IFACE}" info | sed -e '1d' | grep -q "txpower 0.00"
+   LC_ALL=C iw dev "${IFACE}" info | sed -e '1d' | grep -Fq "txpower 0.00"
local txpowerwasoff=$?
 
iw_defaults

diff --git a/net/iwconfig.sh.Linux.in b/net/iwconfig.sh.Linux.in
index 02f748d..98044a9 100644
--- a/net/iwconfig.sh.Linux.in
+++ b/net/iwconfig.sh.Linux.in
@@ -17,9 +17,8 @@ iwconfig_get_wep_status()
 {
local mode= status="disabled"
 
-   # No easy way of doing this grep in bash regex :/
if LC_ALL=C iwconfig "${IFACE}" | \
-   grep -qE "^ +Encryption 

[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-18 Thread Lars Wendler
commit: 90482eddc3e792809bb220320672816000f727e3
Author: Lars Wendler  gentoo  org>
AuthorDate: Mon Jan 18 11:23:12 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Mon Jan 18 12:32:31 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=90482edd

net/l2tp.sh: dash doesn't know "&>/dev/null" redirect

Signed-off-by: Lars Wendler  gentoo.org>

 net/l2tp.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index 9644e32..82649b9 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -34,8 +34,7 @@ _l2tp_eval_props() {
 
 _is_l2tp() {
# Check for L2TP support in kernel
-   ip l2tp show session &>/dev/null
-   [ $? -ne 0 ] && return 1
+   ip l2tp show session 2>/dev/null 1>/dev/null || return 1
 
eval "$(ip l2tp show session | \
awk "match(\$0, /^Session ([0-9]+) in tunnel ([0-9]+)\$/, ret) 
{sid=ret[1]; tid=ret[2]} 



[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-18 Thread Lars Wendler
commit: e08ad3fd1aa2fca27ddf0ad7dfeedb82db4a3666
Author: Lars Wendler  gentoo  org>
AuthorDate: Mon Jan 18 11:44:10 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Mon Jan 18 12:32:31 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=e08ad3fd

net/pppd.sh: Improved pppd version check

Ed Wildgoose reported an issue with pppd version check if plugins are
also to be initialized. I this case "pppd --version" also reports the
plugins and that can confuse our original version check.

Bug: https://bugs.gentoo.org/729920
Thanks-to: Ed Wildgoose  wildgooses.com>
Closes: https://github.com/gentoo/netifrc/pull/33
Signed-off-by: Lars Wendler  gentoo.org>

 net/pppd.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/pppd.sh b/net/pppd.sh
index 42495a7..2182497 100644
--- a/net/pppd.sh
+++ b/net/pppd.sh
@@ -23,7 +23,7 @@ requote()
 
 pppd_is_ge_248()
 {
-   local ver_str="$(/usr/sbin/pppd --version 2>&1 | grep -o 
'[[:digit:]\.]\+')"
+   local ver_str="$(/usr/sbin/pppd --version 2>&1 | awk '/pppd version/ 
{print $3}')"
local maj_ver="$(echo ${ver_str} | cut -d . -f 1)"
local min_ver="$(echo ${ver_str} | cut -d . -f 2)"
local patch_ver="$(echo ${ver_str} | cut -d . -f 3)"



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2021-01-05 Thread Lars Wendler
commit: 750d89eaf772551588c460a0c8425579e7d49677
Author: Lars Wendler  gentoo  org>
AuthorDate: Tue Jan  5 12:51:41 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Tue Jan  5 14:26:56 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=750d89ea

net/pppd.sh: ppp-2.4.9 has renamed rp-pppoe.so to pppoe.so

Signed-off-by: Lars Wendler  gentoo.org>

 doc/net.example.Linux.in | 5 +++--
 net/pppd.sh  | 7 +++
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index d88302b..b404329 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -805,9 +805,10 @@
 #link_ppp0="pty 'your_link_command'"   # PPP links over ssh, rsh, etc
 #
 # Here you should specify what pppd plugins you want to use
-# Available plugins are: pppoe, pppoa, capi, dhcpc, minconn, radius,
+# Available plugins are: pppoe, rp-pppoe, pppoa, capi, dhcpc, minconn, radius,
 #   radattr, radrealms and winbind
-#plugins_ppp0="pppoe"  # Required plugin for PPPoE
+#plugins_ppp0="pppoe"  # Required plugin for PPPoE with 
>=ppp-2.4.9
+#plugins_ppp0="rp-pppoe"   # Required plugin for PPPoE with 


[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-05 Thread Lars Wendler
commit: 2658f44bb04e117043d1466fcd8e65c1e321db01
Author: Lars Wendler  gentoo  org>
AuthorDate: Tue Jan  5 12:57:51 2021 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Tue Jan  5 14:26:56 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=2658f44b

net/pppd.sh: prefer defaultroute-metric

Signed-off-by: Lars Wendler  gentoo.org>

 net/pppd.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/pppd.sh b/net/pppd.sh
index c6a6a8a..42495a7 100644
--- a/net/pppd.sh
+++ b/net/pppd.sh
@@ -65,10 +65,10 @@ pppd_pre_start()
return 0
fi
 
-   local link= i= unit="${IFACE#ppp}" opts= routemetric=defaultmetric
+   local link= i= unit="${IFACE#ppp}" opts= routemetric=defaultroute-metric
 
# 
https://github.com/paulusmack/ppp/commit/35e5a569c988b1ff865b02a24d9a727a00db4da9
-   pppd_is_ge_248 && routemetric=defaultroute-metric
+   pppd_is_ge_248 || routemetric=defaultmetric
 
# PPP requires a link to communicate over - normally a serial port
# PPPoE communicates over Ethernet



[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-05 Thread Lars Wendler
commit: 86879b6bfd4f6d8ce26945a5570e579bf28249f5
Author: Lars Wendler  gentoo  org>
AuthorDate: Tue Dec 15 20:47:15 2020 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Tue Jan  5 12:44:05 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=86879b6b

Add code style fixes and missing copyright headers

Signed-off-by: Lars Wendler  gentoo.org>

 net/dhcpcd.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index e3410d8..1e1bbe0 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -1,4 +1,5 @@
 # Copyright (c) 2007-2008 Roy Marples 
+# Copyright (c) 2020 Gentoo Authors
 # Released under the 2-clause BSD license.
 # shellcheck shell=sh disable=SC1008
 
@@ -55,9 +56,9 @@ dhcpcd_start()
done
 
# Add our route metric if not given
-   case " $args " in
+   case " ${args} " in
*" -m "*) ;;
-   *) [ "${metric:-0}" != 0 ] && args="$args -m $metric";;
+   *) [ "${metric:-0}" != 0 ] && args="${args} -m ${metric}";;
esac
 
# Bring up DHCP for this interface



[gentoo-commits] proj/netifrc:master commit in: net/

2021-01-05 Thread Lars Wendler
commit: 04e6565b185fd3066822333e1b1932284ec1f6b7
Author: Lars Wendler  gentoo  org>
AuthorDate: Tue Dec 15 19:53:27 2020 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Tue Jan  5 12:44:05 2021 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=04e6565b

net/dhcpcd.sh: Remove support for ancient dhcpcd versions

Signed-off-by: Lars Wendler  gentoo.org>

 net/dhcpcd.sh | 27 +--
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index 548a503..e3410d8 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -20,7 +20,7 @@ dhcpcd_start()
# alter the pidfile's name (#718114)
# Save the args into a file so dhcpcd_stop can later re-use the very
# same args later.
-   local args= opt= pidfile= opts= new=true 
argsfile=/run/netifrc_dhcpcd_${IFACE}_args
+   local args= opt= pidfile= opts= 
argsfile=/run/netifrc_dhcpcd_${IFACE}_args
eval args=\$dhcpcd_${IFVAR}
[ -z "${args}" ] && args=${dhcpcd}
echo "${args}" > ${argsfile}
@@ -30,33 +30,24 @@ dhcpcd_start()
eval opts=\$dhcp_${IFVAR}
[ -z "${opts}" ] && opts=${dhcp}
 
-   case "$(dhcpcd --version)" in
-   "dhcpcd "[123]*) new=false;;
+   case "$(dhcpcd --version | head -n 1)" in
+   "dhcpcd "[123]*)
+   eerror 'The dhcpcd version is too old. Please upgrade.'
+   return 1
+   ;;
esac
 
# Map some generic options to dhcpcd
for opt in ${opts}; do
case "${opt}" in
nodns)
-   if ${new}; then
-   args="${args} -C resolv.conf"
-   else
-   args="${args} -R"
-   fi
+   args="${args} -C resolv.conf"
;;
nontp)
-   if ${new}; then
-   args="${args} -C ntp.conf"
-   else
-   args="${args} -N"
-   fi
+   args="${args} -C ntp.conf"
;;
nonis)
-   if ${new}; then
-   args="${args} -C yp.conf"
-   else
-   args="${args} -Y"
-   fi
+   args="${args} -C yp.conf"
;;
nogateway) args="${args} -G";;
nosendhost) args="${args} -h ''";



[gentoo-commits] proj/netifrc:master commit in: net/

2020-12-15 Thread Lars Wendler
commit: ee7316e32ecd90384f05f77ddb29abbdf97fa6a2
Author: Brian Evans  gentoo  org>
AuthorDate: Tue Dec 15 19:39:21 2020 +
Commit: Lars Wendler  gentoo  org>
CommitDate: Tue Dec 15 20:10:51 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=ee7316e3

net/dhcpcd.sh: Don't run dhcpcd on stop if it's not installed

Bug: https://bugs.gentoo.org/760093
Signed-off-by: Lars Wendler  gentoo.org>

 net/dhcpcd.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index dcc6817..548a503 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -5,7 +5,7 @@
 dhcpcd_depend()
 {
after interface
-   program start dhcpcd
+   program dhcpcd
provide dhcp
 
# We prefer dhcpcd over these



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2020-06-02 Thread Robin H. Johnson
commit: 589d7374dc5c023304f6226cb458d5346bdd3a0b
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Tue Jun  2 21:51:00 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Tue Jun  2 21:53:50 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=589d7374

net/iw: implement 802.11s mesh

Closes: https://bugs.gentoo.org/469296
Signed-off-by: Robin H. Johnson  gentoo.org>

 doc/net.example.Linux.in |  7 ++-
 net/iw.sh| 25 +
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index 4fc603b..d88302b 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -231,7 +231,7 @@
 # do require the SSID to be set - do this here
 #essid_eth0="any"
 
-# Set the mode of the interface (managed, ad-hoc, master or auto)
+# Set the mode of the interface (managed, ad-hoc, master, mesh or auto)
 # The default is auto
 # If it's ad-hoc or master you also may need to specify the channel below
 #mode_eth0="auto"
@@ -409,6 +409,11 @@
 # NOTE: preferred_aps  list ignores blacklisted_aps - so if you have
 # the same SSID in both, well, you're a bit silly :p
 
+# 802.11s mesh support
+# Requires CONFIG_MAC80211_MESH in kernel and hardware support
+#mode_wlan0="mesh"
+#mesh_wlan0="MyMeshNetworkID"
+
 
 
 # wpa_supplicant

diff --git a/net/iw.sh b/net/iw.sh
index dcdbb79..029b9d6 100644
--- a/net/iw.sh
+++ b/net/iw.sh
@@ -5,6 +5,7 @@
 
 _config_vars="$_config_vars ssid mode associate_timeout sleep_scan"
 _config_vars="$_config_vars preferred_aps blacklist_aps"
+_config_vars="$_config_vars mesh"
 
 iw_depend()
 {
@@ -170,6 +171,26 @@ iw_setup_adhoc()
return 0
 }
 
+iw_setup_mesh()
+{
+   if [ -z "${MESH}" ]; then
+   eerror "${IFACE} requires a MESH to be set to operate in mesh 
mode"
+   eerror "adjust the mesh_${IFVAR} setting in /etc/conf.d/net"
+   return 1
+   fi
+
+   iw_set_mode 'mesh'
+
+   veinfo "Joining mesh '$MESH' with $IFACE"
+   iw ${IFACE} mesh join "${MESH}" || return 1
+
+   # Finally apply the user Config
+   iw_user_config
+
+   iw_report
+   return 0
+}
+
 iw_wait_for_association()
 {
local timeout= i=0
@@ -600,6 +621,10 @@ iw_configure()
managed)
# Fall through
;;
+   mesh)
+   iw_setup_mesh
+   return $?
+   ;;
*)
eerror "Only managed and ad-hoc are supported"
return 1



[gentoo-commits] proj/netifrc:master commit in: net/

2020-06-02 Thread Robin H. Johnson
commit: 1c846d9d8e23d94046df471c7ccbb88228537188
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Tue Jun  2 21:44:26 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Tue Jun  2 21:44:57 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=1c846d9d

net/iw: refactor iw mode setup

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iw.sh | 37 -
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/net/iw.sh b/net/iw.sh
index 82b9ba9..dcdbb79 100644
--- a/net/iw.sh
+++ b/net/iw.sh
@@ -585,27 +585,30 @@ iw_configure()
[ -z "${SSID}" ] && eval SSID=\$essid_${IFVAR}
 
# Setup ad-hoc mode?
-   eval x=\$mode_${IFVAR}
-   x=${x:-managed}
+   eval _mode=\$mode_${IFVAR}
+   _mode=${_mode:-managed}
 
-   if [ "${x}" = "master" ]; then
-   eerror "Please use hostapd to make this interface an access 
point"
-   return 1
-   fi
-
-   if [ "${x}" = "ad-hoc" ]; then
-   iw_setup_adhoc
-   return $?
-   fi
-
-   if [ "${x}" != "managed" ]; then
-   eerror "Only managed and ad-hoc are supported"
-   return 1
-   fi
+   case "${_mode}" in
+   master)
+   eerror "Please use hostapd to make this interface an 
access point"
+   return 1
+   ;;
+   ad-hoc|adhoc)
+   iw_setup_adhoc
+   return $?
+   ;;
+   managed)
+   # Fall through
+   ;;
+   *)
+   eerror "Only managed and ad-hoc are supported"
+   return 1
+   ;;
+   esac
 
# Has an SSID been forced?
if [ -n "${SSID}" ]; then
-   iw_set_mode "${x}"
+   iw_set_mode "${_mode}"
iw_associate && return 0
[ "${SSID}" = "any" ] && iw_force_preferred && return 0
 



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2020-05-31 Thread Robin H. Johnson
commit: ffa5a9e830c609fec987efac5723781e889ae67c
Author: Arseni Nimera  yandex  by>
AuthorDate: Sat May 30 22:20:25 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May 31 23:15:20 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=ffa5a9e8

Added macvtap support

Bug: https://bugs.gentoo.org/691372
Signed-off-by: Arseni Nimera  yandex.by>
(cherry picked from commit 0dc79645173fad82e0d437a6569b7ea7fa356197)
Signed-off-by: Robin H. Johnson  gentoo.org>

 doc/net.example.Linux.in | 3 +++
 net/macvlan.sh   | 8 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index c211ca7..a2993c0 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -664,6 +664,9 @@
 # MAC-VLAN mode (private, vepa, bridge, passtru)
 #mode_macvlan0="private"
 
+# MAC-VLAN type (macvlan, macvtap)
+#type_macvlan0="macvtap"
+
 # IP address, MAC address, ... are configured as a normal interface
 #config_macvlan0="192.168.20.20/24"
 #mac_macvlan0="00:50:06:20:20:20"

diff --git a/net/macvlan.sh b/net/macvlan.sh
index 8d55717..6243858 100644
--- a/net/macvlan.sh
+++ b/net/macvlan.sh
@@ -34,8 +34,12 @@ macvlan_pre_start()
eval mode=\$mode_${IFVAR}
[ -z "${mode}" ] && mode="private"
 
+   local type=
+   eval type=\$type_${IFVAR}
+   [ -z "${type}" ] && type="macvlan"
+
ebegin "Creating MAC-VLAN ${IFACE} to ${macvlan}"
-   e="$(ip link add link "${macvlan}" name "${IFACE}" type macvlan mode 
"${mode}" 2>&1 1>/dev/null)"
+   e="$(ip link add link "${macvlan}" name "${IFACE}" type "${type}" mode 
"${mode}" 2>&1 1>/dev/null)"
if [ -n "${e}" ]; then
eend 1 "${e}"
else
@@ -49,6 +53,6 @@ macvlan_post_stop()
_is_macvlan || return 0
 
ebegin "Removing MAC-VLAN ${IFACE}"
-   ip link delete "${IFACE}" type macvlan >/dev/null
+   ip link delete "${IFACE}" >/dev/null
eend $?
 }



[gentoo-commits] proj/netifrc:master commit in: net/

2020-05-31 Thread Robin H. Johnson
commit: dea30db8062977dc9b8a2c8611f09cf8c891d36f
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun May 31 05:52:43 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May 31 05:52:47 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=dea30db8

net/ip6to4: partial fix for bug #528314

netifrc has never clearly documented exactly what shell is targeted, and
this bug does not occur on any shell that supports the 'local' keyword.

Reference: https://bugs.gentoo.org/528314
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/ip6to4.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ip6to4.sh b/net/ip6to4.sh
index 21acd71..6b573d1 100644
--- a/net/ip6to4.sh
+++ b/net/ip6to4.sh
@@ -103,8 +103,8 @@ ip6to4_pre_start()
 
 ip6to4_start()
 {
-   local config_ip6to4=$(service_get_value "config_ip6to4_$IFVAR")
-   local routes_ip6to4=$(service_get_value "routes_ip6to4_$IFVAR")
+   local config_ip6to4="$(service_get_value "config_ip6to4_$IFVAR")"
+   local routes_ip6to4="$(service_get_value "routes_ip6to4_$IFVAR")"
 
# Now apply our config
eval config_${config_index}=\'"${config_ip6to4}"\'



[gentoo-commits] proj/netifrc:master commit in: net/

2020-05-30 Thread Robin H. Johnson
commit: 626cfdad15f9740208807bc436cb3915056c87b4
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun May 31 05:42:22 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May 31 05:42:22 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=626cfdad

net/iproute2: support containers without /proc/sys/net/ipv4/route/flush

Bug: https://bugs.gentoo.org/648600
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 5f65f1c..ca6c0f8 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -438,8 +438,18 @@ _iproute2_link_delete() {
eend $?
 }
 
+_iproute2_route_flush_supported() {
+   case $FAMILY in
+   -6) p='/proc/sys/net/ipv6/route/flush' ;;
+   -4|*) p='/proc/sys/net/ipv4/route/flush' ;;
+   esac
+   test -f $p
+}
+
 _iproute2_route_flush() {
-   _cmd ip $FAMILY route flush table cache dev "${IFACE}"
+   if _iproute2_route_flush_supported; then
+   _cmd ip $FAMILY route flush table cache dev "${IFACE}"
+   fi
 }
 
 _iproute2_ipv6_tentative_output() {



[gentoo-commits] proj/netifrc:master commit in: net/

2020-05-30 Thread Robin H. Johnson
commit: c0f36e9995b6e07b6691fa0c2d5c3a13223f9815
Author: Hans Fernhout  fernhout  info>
AuthorDate: Sun May 31 05:27:16 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May 31 05:29:36 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=c0f36e99

net/iwd: add iwd helper

Bug: https://bugs.gentoo.org/690808
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iwd.sh | 53 +
 1 file changed, 53 insertions(+)

diff --git a/net/iwd.sh b/net/iwd.sh
new file mode 100644
index 000..afb5b22
--- /dev/null
+++ b/net/iwd.sh
@@ -0,0 +1,53 @@
+# Original copyright (c) 2007-2009 Roy Marples 
+# Released under the 2-clause BSD license.
+
+iwd_depend()
+{
+   need dbus
+   after macnet plug
+   before interface
+   provide wireless
+   after iwconfig
+}
+
+_config_vars="$_config_vars iwd"
+
+iwd_pre_start()
+{
+   local iwds=/usr/libexec/iwd
+   local args= opt= opts=
+   eval opts=\$iwd_${IFVAR}
+
+   #set a "safe" default in case phy was not defined
+   PHY="phy0"
+
+   for opt in ${opts}; do
+   case "${opt}" in
+   phy* )  PHY="${opt}"
+   einfo "Assigned PHY to be ${PHY}"
+   ;;
+   *)  ;;
+   esac
+   done
+   ebegin "Starting iwd on ${PHY} and ${IFVAR}"
+   pidfile="/run/iwd-${IFVAR}.pid"
+   start-stop-daemon --start --exec "${iwds}" --pidfile "${pidfile}" 
--background --verbose --make-pidfile -- -p ${PHY} -i "${IFVAR}"
+   return $?
+}
+
+
+iwd_post_stop()
+{
+   local iwds=/usr/libexec/iwd
+   pidfile="/run/iwd-${IFVAR}.pid"
+   if [ -f ${pidfile} ]; then
+   ebegin "Stopping iwd on ${IFACE}"
+   start-stop-daemon --stop --exec "${iwds}" --pidfile "${pidfile}"
+   eend $?
+   fi
+
+   # If iwd exits uncleanly, we need to remove the stale dir
+   [ -S "/run/iwd/${IFACE}" ] \
+   && rm -f "/run/iwd/${IFACE}"
+}
+



[gentoo-commits] proj/netifrc:master commit in: net/

2020-05-30 Thread Robin H. Johnson
commit: 8d16b31bfc457f03e0e761df19529749ffa1f0d8
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun May 31 05:29:07 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May 31 05:29:40 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=8d16b31b

net/iwd: ensure program is present

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iwd.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/iwd.sh b/net/iwd.sh
index afb5b22..e3f64b2 100644
--- a/net/iwd.sh
+++ b/net/iwd.sh
@@ -8,6 +8,7 @@ iwd_depend()
before interface
provide wireless
after iwconfig
+   program iwd
 }
 
 _config_vars="$_config_vars iwd"



[gentoo-commits] proj/netifrc:master commit in: net/

2020-05-30 Thread Robin H. Johnson
commit: b3848b828d4f1cabe9bda54a0d9da473e5df3e9a
Author: Lars Wendler  gentoo  org>
AuthorDate: Fri May 22 08:09:22 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May 31 05:13:18 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=b3848b82

net/dhcpcd.sh: Put user args into a temp file

So we still use the correct PID even if the user has changed his
configuration between start and stop.

Signed-off-by: Lars Wendler  gentoo.org>
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/dhcpcd.sh | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index c0639e0..dcc6817 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -16,11 +16,14 @@ _config_vars="$_config_vars dhcp dhcpcd"
 
 dhcpcd_start()
 {
-   # check for pidfile after we gathered the user's opts because they can
+   # check for pidfile after we gathered the user's args because they can
# alter the pidfile's name (#718114)
-   local args= opt= pidfile= opts= new=true
+   # Save the args into a file so dhcpcd_stop can later re-use the very
+   # same args later.
+   local args= opt= pidfile= opts= new=true 
argsfile=/run/netifrc_dhcpcd_${IFACE}_args
eval args=\$dhcpcd_${IFVAR}
[ -z "${args}" ] && args=${dhcpcd}
+   echo "${args}" > ${argsfile}
pidfile="$(dhcpcd -P ${args} ${IFACE})"
 
# Get our options
@@ -78,12 +81,16 @@ dhcpcd_start()
 
 dhcpcd_stop()
 {
-   local args= pidfile= opts= sig=SIGTERM
+   local args= pidfile= opts= sig=SIGTERM 
argsfile=/run/netifrc_dhcpcd_${IFACE}_args
 
-   # check for pidfile after we gathered the user's opts because they can
+   # check for pidfile after we gathered the user's args because they can
# alter the pidfile's name (#718114)
-   eval args=\$dhcpcd_${IFVAR}
-   [ -z "${args}" ] && args=${dhcpcd}
+   if [ -f "${argsfile}" ] ; then
+   args="$(cat ${argsfile})"
+   else
+   eval args=\$dhcpcd_${IFVAR}
+   [ -z "${args}" ] && args=${dhcpcd}
+   fi
pidfile="$(dhcpcd -P ${args} ${IFACE})"
[ ! -f "${pidfile}" ] && return 0
 
@@ -94,5 +101,6 @@ dhcpcd_stop()
*" release "*) dhcpcd -k "${IFACE}" ;;
*) dhcpcd -x "${IFACE}" ;;
esac
+   [ -f "${argsfile}" ] && rm -f "${argsfile}"
eend $?
 }



[gentoo-commits] proj/netifrc:master commit in: net/

2020-05-30 Thread Robin H. Johnson
commit: dd5a41de524cfdebe47425e70513f95f9937e406
Author: Lars Wendler  gentoo  org>
AuthorDate: Thu May 21 16:35:32 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May 31 05:13:17 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=dd5a41de

net/dhcpcd.sh: fetch pidfile location from dhcpcd

There's a -P switch for this but we also need to take into account the
-4 and -6 switches as they both alter the pidfile's name.

Bug: https://bugs.gentoo.org/718114
Signed-off-by: Lars Wendler  gentoo.org>
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/dhcpcd.sh | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index 0a306b8..c0639e0 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -16,9 +16,12 @@ _config_vars="$_config_vars dhcp dhcpcd"
 
 dhcpcd_start()
 {
-   local args= opt= opts= pidfile="/run/dhcpcd-${IFACE}.pid" new=true
+   # check for pidfile after we gathered the user's opts because they can
+   # alter the pidfile's name (#718114)
+   local args= opt= pidfile= opts= new=true
eval args=\$dhcpcd_${IFVAR}
[ -z "${args}" ] && args=${dhcpcd}
+   pidfile="$(dhcpcd -P ${args} ${IFACE})"
 
# Get our options
eval opts=\$dhcp_${IFVAR}
@@ -75,7 +78,13 @@ dhcpcd_start()
 
 dhcpcd_stop()
 {
-   local pidfile="/run/dhcpcd-${IFACE}.pid" opts= sig=SIGTERM
+   local args= pidfile= opts= sig=SIGTERM
+
+   # check for pidfile after we gathered the user's opts because they can
+   # alter the pidfile's name (#718114)
+   eval args=\$dhcpcd_${IFVAR}
+   [ -z "${args}" ] && args=${dhcpcd}
+   pidfile="$(dhcpcd -P ${args} ${IFACE})"
[ ! -f "${pidfile}" ] && return 0
 
ebegin "Stopping dhcpcd on ${IFACE}"



[gentoo-commits] proj/netifrc:master commit in: net/

2020-01-04 Thread Robin H. Johnson
commit: 01704754311ada2c2154f501aebfda50710a185d
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sat Jan  4 08:02:40 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sat Jan  4 08:02:40 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=01704754

shellcheck: fix Double quote array expansions to avoid re-splitting elements. 
[SC2068]

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/l2tp.sh | 2 +-
 net/pppd.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index 7c5b064..9644e32 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -81,7 +81,7 @@ _l2tp_get_tunnel_info() {
 
 _ip_l2tp_add() {
local e
-   e="$(LC_ALL=C ip l2tp add $@ 2>&1 1>/dev/null)"
+   e="$(LC_ALL=C ip l2tp add "$@" 2>&1 1>/dev/null)"
case $e in
"")
return 0

diff --git a/net/pppd.sh b/net/pppd.sh
index 796722e..e3c4d43 100644
--- a/net/pppd.sh
+++ b/net/pppd.sh
@@ -163,7 +163,7 @@ pppd_pre_start()
# We need to flatten the useless array
set -- $(_get_array "chat_${IFVAR}")
if [ $# != 0 ]; then
-   opts="${opts} connect '$(echo ${chatprog} $@ | sed -e 
"s:':''':g")'"
+   opts="${opts} connect '$(echo ${chatprog} "$@" | sed -e 
"s:':''':g")'"
fi
 
# Add plugins



[gentoo-commits] proj/netifrc:master commit in: net/

2020-01-04 Thread Robin H. Johnson
commit: 9472b0e2fd402819963f492fe9ba37c82c0de277
Author: Lars Wendler  gentoo  org>
AuthorDate: Fri Jan  3 20:30:28 2020 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sat Jan  4 07:58:21 2020 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=9472b0e2

pppd.sh: ppp-2.4.8 introduced "defaultroute-metric" option

That option name differs from the one we patched into previous pppd releases
so check if we are on >=2.4.8 version and use the correct option name
accordingly

Signed-off-by: Lars Wendler  gentoo.org>
Closes: https://bugs.gentoo.org/704722
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/pppd.sh | 34 --
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/net/pppd.sh b/net/pppd.sh
index 6ca1396..796722e 100644
--- a/net/pppd.sh
+++ b/net/pppd.sh
@@ -21,6 +21,32 @@ requote()
printf "'%s' " "$@"
 }
 
+pppd_is_ge_248()
+{
+   local ver_str="$(/usr/sbin/pppd --version 2>&1 | grep -o 
'[[:digit:]\.]\+')"
+   local maj_ver="$(echo ${ver_str} | cut -d . -f 1)"
+   local min_ver="$(echo ${ver_str} | cut -d . -f 2)"
+   local patch_ver="$(echo ${ver_str} | cut -d . -f 3)"
+
+   if [ "${maj_ver}" -gt 2 ] ; then
+   return 0
+   elif [ "${maj_ver}" -eq 2 ] ; then
+   if [ "${min_ver}" -gt 4 ] ; then
+   return 0
+   elif [ "${min_ver}" -eq 4 ] ; then
+   if [ "${patch_ver}" -ge 8 ] ; then
+   return 0
+   else
+   return 1
+   fi
+   else
+   return 1
+   fi
+   else
+   return 1
+   fi
+}
+
 pppd_pre_start()
 {
# Interface has to be called ppp
@@ -39,7 +65,10 @@ pppd_pre_start()
return 0
fi
 
-   local link= i= unit="${IFACE#ppp}" opts=
+   local link= i= unit="${IFACE#ppp}" opts= routemetric=defaultmetric
+
+   # 
https://github.com/paulusmack/ppp/commit/35e5a569c988b1ff865b02a24d9a727a00db4da9
+   pppd_is_ge_248 && routemetric=defaultroute-metric
 
# PPP requires a link to communicate over - normally a serial port
# PPPoE communicates over Ethernet
@@ -76,6 +105,7 @@ pppd_pre_start()
return 1
;;
defaultmetric) hasdefaultmetric=true;;
+   defaultroute-metric) hasdefaultmetric=true;;
mtu) hasmtu=true;;
mru) hasmru=true;;
maxfail) hasmaxfail=true;;
@@ -98,7 +128,7 @@ pppd_pre_start()
local m=
eval m=\$metric_${IFVAR}
[ -z "${m}" ] && : $(( m = metric + $(_ifindex) ))
-   opts="${opts} defaultmetric ${m}"
+   opts="${opts} ${routemetric} ${m}"
fi
if [ -n "${mtu}" ]; then
${hasmtu} || opts="${opts} mtu ${mtu}"



[gentoo-commits] proj/netifrc:master commit in: net/

2019-07-09 Thread Ben Kohler
commit: 43f0190924f8c721ebccd75a2d6b99671905bedf
Author: Ben Kohler  gentoo  org>
AuthorDate: Tue Jul  9 19:42:16 2019 +
Commit: Ben Kohler  gentoo  org>
CommitDate: Tue Jul  9 19:42:16 2019 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=43f01909

net/*: fix ordering of dhcp clients

We want to prefer dhclient over busybox udhcpc if it's available.  This
commit also adds deps to the other services which will guarantee the
priority dhcpcd > dhclient > pump > udhcpc.

Signed-off-by: Ben Kohler  gentoo.org>

 net/dhclient.sh | 3 +++
 net/dhcpcd.sh   | 4 ++--
 net/pump.sh | 3 +++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/dhclient.sh b/net/dhclient.sh
index fd27308..24c3512 100644
--- a/net/dhclient.sh
+++ b/net/dhclient.sh
@@ -7,6 +7,9 @@ dhclient_depend()
after interface
program start /sbin/dhclient
provide dhcp
+
+   # We prefer dhclient over these
+   after udhcpc pump
 }
 
 _config_vars="$_config_vars dhcp dhcpcd"

diff --git a/net/dhcpcd.sh b/net/dhcpcd.sh
index 1812b45..0a306b8 100644
--- a/net/dhcpcd.sh
+++ b/net/dhcpcd.sh
@@ -8,8 +8,8 @@ dhcpcd_depend()
program start dhcpcd
provide dhcp
 
-   # We prefer dhcpcd over the others
-   after dhclient pump udhcpc
+   # We prefer dhcpcd over these
+   after udhcpc pump dhclient
 }
 
 _config_vars="$_config_vars dhcp dhcpcd"

diff --git a/net/pump.sh b/net/pump.sh
index 270b37d..864b6cf 100644
--- a/net/pump.sh
+++ b/net/pump.sh
@@ -7,6 +7,9 @@ pump_depend()
program /sbin/pump
after interface
provide dhcp
+
+   # We prefer pump over udhcpc
+   after udhcpc
 }
 
 _config_vars="$_config_vars dhcp pump"



[gentoo-commits] proj/netifrc:master commit in: net/

2019-07-09 Thread Ben Kohler
commit: 3392e908a2e3afceb399a1eb56e05c479aad42da
Author: Ben Kohler  gentoo  org>
AuthorDate: Tue Jul  9 19:59:09 2019 +
Commit: Ben Kohler  gentoo  org>
CommitDate: Tue Jul  9 19:59:09 2019 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=3392e908

net/iw.sh: minor whitespace fix

Signed-off-by: Ben Kohler  gentoo.org>

 net/iw.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/iw.sh b/net/iw.sh
index 5462244..82b9ba9 100644
--- a/net/iw.sh
+++ b/net/iw.sh
@@ -12,8 +12,8 @@ iw_depend()
after plug
before interface
provide wireless
-# Prefer us over iwconfig
-after iwconfig
+   # Prefer us over iwconfig
+   after iwconfig
 }
 
 _get_ssid()



[gentoo-commits] proj/netifrc:master commit in: net/

2019-07-09 Thread Ben Kohler
commit: b8be61112499d3fc1681edb21f240bfeb9eeafe1
Author: Ben Kohler  gentoo  org>
AuthorDate: Tue Jul  9 17:38:37 2019 +
Commit: Ben Kohler  gentoo  org>
CommitDate: Tue Jul  9 17:38:37 2019 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=b8be6111

net/system.sh: change net-scripts to netifrc in output

Signed-off-by: Ben Kohler  gentoo.org>

 net/system.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/system.sh b/net/system.sh
index 1f81493..0b65379 100644
--- a/net/system.sh
+++ b/net/system.sh
@@ -34,7 +34,7 @@ _system_dns()
[ -z "${servers}" -a -z "${domain}" -a -z "${search}" \
-a -z "${sortlist}" -a -z "${options}" ] && return 0
 
-   local buffer="# Generated by net-scripts for interface ${IFACE}\n"
+   local buffer="# Generated by netifrc for interface ${IFACE}\n"
[ -n "${domain}" ] && buffer="${buffer}domain ${domain}\n"
[ -n "${search}" ] && buffer="${buffer}search ${search}\n"
 
@@ -67,7 +67,7 @@ _system_ntp()
[ -z "${servers}" ] && servers=${ntp_servers}
[ -z "${servers}" ] && return 0
 
-   buffer="# Generated by net-scripts for interface ${IFACE}\n"
+   buffer="# Generated by netifrc for interface ${IFACE}\n"
buffer="${buffer}restrict default noquery notrust nomodify\n"
buffer="${buffer}restrict 127.0.0.1\n"
 
@@ -92,7 +92,7 @@ _system_nis()
 
[ -z "${servers}" -a -z "${domain}" ] && return 0
 
-   buffer="# Generated by net-scripts for interface ${iface}\n"
+   buffer="# Generated by netifrc for interface ${iface}\n"
 
if [ -n "${domain}" ]; then
hostname -y "${domain}"



[gentoo-commits] proj/netifrc:master commit in: net/

2019-04-20 Thread Robin H. Johnson
commit: 963d378276193c9ae73b889da03960258773d259
Author: Kirill Semenkov  gmail  com>
AuthorDate: Mon Dec 17 09:07:18 2018 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Apr 21 04:10:41 2019 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=963d3782

Veth support added

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/veth.sh | 193 
 1 file changed, 193 insertions(+)

diff --git a/net/veth.sh b/net/veth.sh
new file mode 100644
index 000..d969a14
--- /dev/null
+++ b/net/veth.sh
@@ -0,0 +1,193 @@
+# Copyright (c) 2018 
+# Released under the 2-clause BSD license.
+
+veth_depend()
+{
+   program ip awk
+}
+
+_config_vars="$_config_vars veth"
+
+
+# We need it because _exists() function seeks in /sys/class/net
+_netns_exists()
+{
+   [ -e "/var/run/netns/$1" ]
+}
+
+
+#Creates the network namespace if it doesn't exist. If called with no 
arguments, does nothing
+#Arguments:
+# $1 - name of the namespace
+_create_ns() {
+
+   vethrc=0
+   for _ns in "$@"; do
+   if [ -z "$_ns" ]; then
+   continue
+   fi
+   if ! _netns_exists "$_ns"; then
+   ip netns add "$_ns" > /dev/null 2>&1
+   vethrc=$(($?+ vethrc)) 
+   fi  
+   done
+   return $vethrc
+}
+
+#Brings a virtual interface up and takes network namespaces into account
+#Arguments: 
+# $1 - name of the interface, required!
+# $2 - namespace
+_bring_peer_up()
+{
+   if [ ! -z "$2" ]; then
+   ip link set "$1" netns "$2" > /dev/null 2>&1
+   vethrc=$?
+   ip netns exec "$2" ip link set dev "$1" up > /dev/null 2>&1
+   vethrc=$(($?+ vethrc)) 
+   return $vethrc
+   fi
+
+   ip link set dev "$1" up > /dev/null 2>&1
+   return $?
+} 
+
+#Brings a virtual interface down and takes network namespaces into account
+#Arguments: 
+# $1 - name of the interface, required!
+# $2 - namespace
+_bring_peer_down()
+{
+
+   if [ ! -z "$2" ]; then
+   ip netns exec "$2" ip link del dev "$1" > /dev/null 2>&1
+   return $? 
+   fi
+
+   ip link del dev "$1" > /dev/null 2>&1
+   return $?
+}
+
+
+#Create and bring the veth pair up
+_create_peers()
+{
+   local peers
+   peers="$(_get_array "veth_${IFVAR}")"
+
+   # veth has exactly two peers.
+   # For POSIX compatibility we evade bash arrays
+   local npeers
+   npeers=$(echo "$peers" | awk '{print NF}')
+   if [ "$npeers" != 2 ]; then
+   eerror "veth interface must have exactly two peers"
+   return 1
+   fi
+
+   for x in ${peers}; do
+   if _exists "$x" ; then
+   eerror "Interface $x already exists. Can't continue"
+   return 1
+   fi  
+   done
+
+   local netns1
+   netns1="$(_get_array "veth_${IFVAR}_ns1")"
+   local netns2
+   netns2="$(_get_array "veth_${IFVAR}_ns2")"
+
+   local vethrc
+
+   if ! _create_ns "$netns1" "$netns2"
+   then
+   eerror "Can't create namespaces: $netns1 $netns2"
+   return 1
+   fi
+
+   local peer1
+   peer1=$(echo "$peers" | awk '{print $1}')
+   local peer2
+   peer2=$(echo "$peers" | awk '{print $2}')
+
+   
+   ip link add "$peer1" type veth peer name "$peer2" > /dev/null 2>&1 || {
+   eerror "Can't create veth peer $peer1 or $peer2"
+   return 1
+   }
+
+
+   if ! _bring_peer_up "$peer1" "$netns1"
+   then
+   eerror "Can't bring the veth peer $peer1 up"
+   return 1
+
+   fi
+   if ! _bring_peer_up "$peer2" "$netns2"
+   then
+   eerror "Can't bring the veth peer $peer2 up"
+   return 1
+
+   fi
+
+   return 0
+}
+
+# Create peers and namespaces
+veth_pre_start()
+{
+   local itype
+   eval itype=\$type_${IFVAR}
+   if [ "$itype" != "veth" ]; then
+   return 0
+   fi
+
+   local createveth
+   eval createveth=\$veth_${IFVAR}_create
+   if [ "$createveth" == "no" ]; then
+   return 0
+   fi
+
+   type ip >/dev/null 2>&1 || {
+   eerror "iproute2 nor found, please install iproute2"
+   return 1
+   }
+
+   if ! _create_peers
+   then
+   return 1
+   fi
+
+
+   return 0
+}
+
+#Delete the veth pair
+#We don't delete namespaces because someone may use them for some purposes
+veth_post_stop()
+{
+   local itype
+   eval itype=\$type_${IFVAR}
+   if [ "$itype" != "veth" ]; then
+   return 0
+   fi
+
+   local createveth
+   eval createveth=\$veth_${IFVAR}_create
+   if [ "$createveth" == "no" ]; then
+   return 0
+   fi
+
+   local peers
+ 

[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2019-04-20 Thread Robin H. Johnson
commit: b5bb3cdf925730a693eed9e2528b92c04975c7d0
Author: Kirill Semenkov  gmail  com>
AuthorDate: Mon Dec 17 09:10:50 2018 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Apr 21 04:10:41 2019 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=b5bb3cdf

Veth support added

Signed-off-by: Robin H. Johnson  gentoo.org>

 doc/net.example.Linux.in | 24 
 net/Makefile |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index 3b414ba..6fc6094 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -914,6 +914,30 @@
 # of the node as well
 #openvpn_tun1="--user foo --group bar"
 
+#-
+# Virtual interface device (veth)
+# For veth support install iproute2 and awk
+#
+# The script uses "standard" ways of IP-address assignement in net.lo script. 
Network namespaces are not implemented here
+# because net.lo currently knows nothing about network namespaces.
+#
+#   You must specify veth interface type to avoid interference with "normal" 
interfaces startup
+#   The interface type must be set for both peers
+#type_veth0="veth"
+#   Here we declare peers for "ip link add" command
+#veth_veth0="veth0 veth1"
+#config_veth0="192.168.0.1/24"
+#
+#   Avoids race
+#rc_net_veth1_need="net.veth0"
+#type_veth1="veth"
+#   Both peers are created when the first one starts, we don't need to create 
the second peer
+#   explicitly, we just configure it
+#veth_veth1_create="no"
+#config_veth1="192.168.2.1/24"
+#
+
+
 #-
 # Bridging (802.1d)
 # Preferred: iproute2, emerge sys-apps/iproute2

diff --git a/net/Makefile b/net/Makefile
index 390f8d8..dab94f9 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -14,7 +14,7 @@ INC-Linux=adsl.sh apipa.sh arping.sh bonding.sh 
br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh 
\
ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh 
udhcpc.sh \
vlan.sh macvlan.sh ip6rd.sh firewalld.sh dummy.sh hsr.sh 
l2tp.sh \
-   iw.sh wireguard.sh
+   iw.sh wireguard.sh veth.sh
 
 SRCS-NetBSD= ifwatchd.sh.in
 INC-NetBSD=ifwatchd.sh



[gentoo-commits] proj/netifrc:master commit in: net/

2018-07-12 Thread Robin H. Johnson
commit: 86911bfd4ee00041273ee8439978e64a2163f3e2
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Thu Jul 12 06:24:36 2018 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Thu Jul 12 06:24:36 2018 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=86911bfd

net/wireguard: import from ebuild

This improves non-maintainer commit
66af4525ff3a4530a165443f459134f1f60283f8 to include correct author
attribution for net/wireguard.sh, as traced & discussed with the
upstream author.

Original-Author: Joakim Sindholt  zhasha.com>
Signed-off-by: Jason A. Donenfeld  gentoo.org>
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/wireguard.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/wireguard.sh b/net/wireguard.sh
index efa45b0..8af76ca 100644
--- a/net/wireguard.sh
+++ b/net/wireguard.sh
@@ -1,4 +1,5 @@
-# Copyright (c) 2016 Gentoo Foundation
+# Copyright (c) 2016 Joakim Sindholt (zhasha)
+# Copyright (c) 2018 Jason A. Donenfeld,
 # Released under the 2-clause BSD license.
 
 wireguard_depend()



[gentoo-commits] proj/netifrc:master commit in: net/

2018-07-10 Thread Jason Donenfeld
commit: 66af4525ff3a4530a165443f459134f1f60283f8
Author: Jason A. Donenfeld  gentoo  org>
AuthorDate: Sun May 27 23:56:51 2018 +
Commit: Jason Donenfeld  gentoo  org>
CommitDate: Tue Jul 10 21:10:22 2018 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=66af4525

net/wireguard: import from ebuild

Signed-off-by: Jason A. Donenfeld  gentoo.org>

 net/Makefile |  2 +-
 net/wireguard.sh | 53 +
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/net/Makefile b/net/Makefile
index 347e89c..390f8d8 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -14,7 +14,7 @@ INC-Linux=adsl.sh apipa.sh arping.sh bonding.sh 
br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh 
\
ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh 
udhcpc.sh \
vlan.sh macvlan.sh ip6rd.sh firewalld.sh dummy.sh hsr.sh 
l2tp.sh \
-   iw.sh
+   iw.sh wireguard.sh
 
 SRCS-NetBSD= ifwatchd.sh.in
 INC-NetBSD=ifwatchd.sh

diff --git a/net/wireguard.sh b/net/wireguard.sh
new file mode 100644
index 000..efa45b0
--- /dev/null
+++ b/net/wireguard.sh
@@ -0,0 +1,53 @@
+# Copyright (c) 2016 Gentoo Foundation
+# Released under the 2-clause BSD license.
+
+wireguard_depend()
+{
+   program /usr/bin/wg
+   after interface
+}
+
+wireguard_pre_start()
+{
+   [ "${IFACE#wg}" != "$IFACE" ] || return 0
+
+   ip link delete dev "$IFACE" type wireguard 2>/dev/null
+   ebegin "Creating WireGuard interface $IFACE"
+   if ! ip link add dev "$IFACE" type wireguard; then
+   e=$?
+   eend $e
+   return $e
+   fi
+   eend 0
+
+   ebegin "Configuring WireGuard interface $IFACE"
+   set -- $(_get_array "wireguard_$IFVAR")
+   if [ $# -eq 1 ]; then
+   /usr/bin/wg setconf "$IFACE" "$1"
+   else
+   eval /usr/bin/wg set "$IFACE" "$@"
+   fi
+   e=$?
+   if [ $e -eq 0 ]; then
+   _up
+   e=$?
+   if [ $e -eq 0 ]; then
+   eend $e
+   return $e
+   fi
+   fi
+   ip link delete dev "$IFACE" type wireguard 2>/dev/null
+   eend $e
+   return $e
+}
+
+wireguard_post_stop()
+{
+   [ "${IFACE#wg}" != "$IFACE" ] || return 0
+
+   ebegin "Removing WireGuard interface $IFACE"
+   ip link delete dev "$IFACE" type wireguard
+   e=$?
+   eend $e
+   return $e
+}



[gentoo-commits] proj/netifrc:master commit in: net/

2018-01-21 Thread Robin H. Johnson
commit: 1b52dd84770eab44b5590ecb5cd386eca36f9b34
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Jan 21 21:50:38 2018 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Jan 21 21:50:42 2018 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=1b52dd84

net/iproute2: improve DAD tentative wait/output.

If an interface had dad_timeout=0 set, then the wait loop output is
confusing. Skip it entirely, printing a useful message:
> Not waiting for DAD timeout on tentative IPv6 addresses (per conf.d/net 
> dad_timeout)

Refactor the DAD tentantive conditionals for ease of debugging.

Bug 636846 suggests that some kernels are still showing tentative
addresses despite sysctls being set.

Bug: https://bugs.gentoo.org/636846
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index d33ee11..2d83534 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -441,9 +441,13 @@ _iproute2_route_flush() {
_cmd ip $FAMILY route flush table cache dev "${IFACE}"
 }
 
+_iproute2_ipv6_tentative_output() {
+   LC_ALL=C ip -family inet6 addr show dev ${IFACE} tentative
+}
+
 _iproute2_ipv6_tentative()
 {
-   [ -n "$(LC_ALL=C ip -family inet6 addr show dev ${IFACE} tentative)" ] 
&& return 0
+   [ -n "$(_iproute2_ipv6_tentative_output)" ] && return 0
 
return 1
 }
@@ -462,11 +466,15 @@ iproute2_post_start()
 
# This block must be non-fatal, otherwise the interface will not be
# recorded as starting, and later services may be blocked.
-   if _iproute2_ipv6_tentative; then
-   if [ "$EINFO_VERBOSE" = "yes" ]; then
-   veinfo "Found tentative addresses:"
-   LC_ALL=C ip -family inet6 addr show dev ${IFACE} 
tentative
-   fi
+   _iproute2_ipv6_tentative ; ret_tentative=$?
+   if [ $ret_tentative -eq 0 -a "$EINFO_VERBOSE" = "yes" ]; then
+   veinfo "Found tentative addresses:"
+   _iproute2_ipv6_tentative_output
+   fi
+   # This could be nested, but the conditionals are very deep at that 
point.
+   if [ $ret_tentative -eq 0 -a $_dad_timeout -le 0 ]; then
+   einfo "Not waiting for DAD timeout on tentative IPv6 addresses 
(per conf.d/net dad_timeout)"
+   elif [ $ret_tentative -eq 0 ]; then
einfon "Waiting for tentative IPv6 addresses to complete DAD 
(${_dad_timeout} seconds) "
while [ $_dad_timeout -gt 0 ]; do
_iproute2_ipv6_tentative || break



[gentoo-commits] proj/netifrc:master commit in: net/

2017-11-27 Thread Robin H. Johnson
commit: 986cf37b69299d2aa9d4eb678a2798b0bc021bc0
Author: Henning Schild  hennsch  de>
AuthorDate: Fri Nov 24 13:02:58 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Nov 27 20:22:06 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=986cf37b

net/wpa_supplicant: change how we match wired connections

Before that patch you needed to write "-Dwired" in /etc/conf.d/net.
Where in fact "-D wired" or even a string with multiple spaces would be
ok for wpa_supplicant.

Signed-off-by: Henning Schild  hennsch.de>
Closes: https://github.com/gentoo/netifrc/pull/27
Signed-off-by: Robin H. Johnson  gentoo.org>
(cherry picked from commit f5b82067ee5ce9badf328c92723e36a86588e74d)

 net/wpa_supplicant.sh | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/wpa_supplicant.sh b/net/wpa_supplicant.sh
index c487238..5df662a 100644
--- a/net/wpa_supplicant.sh
+++ b/net/wpa_supplicant.sh
@@ -63,10 +63,11 @@ wpa_supplicant_pre_start()
eval opts=\$wpa_supplicant_${IFVAR}
eval cliopts=\$wpa_cli_${IFVAR}
[ -z "${cliopts}" ] && cliopts=${wpa_cli}
-   case " ${opts} " in
-   *" -Dwired "*) wireless=false;;
-   *) _is_wireless || return 0;;
-   esac
+   if echo " $opts " | grep -q " \-D[[:space:]]wired "; then
+   wireless=false
+   else
+   _is_wireless || return 0
+   fi
 
# We don't configure wireless if we're being called from
# the background unless we're not currently running



[gentoo-commits] proj/netifrc:master commit in: net/

2017-11-27 Thread Robin H. Johnson
commit: 7f6061ca070918204aad75330ea7c32aff3e2a9c
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Nov 27 20:19:02 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Nov 27 20:22:29 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=7f6061ca

net/wpa_supplicant: rewrite -D detection

Commit 38b9fac9 per Henning Schild's submission PR#27 improved
wpa_supplicant driver detection, but had room for improvements as
discussed in the comment thread. Includes detection of -N for future
multiple interface work.

Bug: https://github.com/gentoo/netifrc/pull/27
CC: Henning Schild  hennsch.de>
Thanks-To: Henning Schild  hennsch.de>
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/wpa_supplicant.sh | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/net/wpa_supplicant.sh b/net/wpa_supplicant.sh
index 5df662a..594a157 100644
--- a/net/wpa_supplicant.sh
+++ b/net/wpa_supplicant.sh
@@ -63,11 +63,21 @@ wpa_supplicant_pre_start()
eval opts=\$wpa_supplicant_${IFVAR}
eval cliopts=\$wpa_cli_${IFVAR}
[ -z "${cliopts}" ] && cliopts=${wpa_cli}
-   if echo " $opts " | grep -q " \-D[[:space:]]wired "; then
-   wireless=false
-   else
-   _is_wireless || return 0
-   fi
+   set -- $opts
+   local opt_D
+   while [ ${#*} -gt 0 ]; do
+   local opt=$1 ; shift
+   case "$opt" in
+   -D) opt_D=${1} ; shift ;;
+   -D*) opt_D=${opt#-D} ;;
+   -N) eerror "Cannot use -N to wpa_supplicant for 
\$wpa_supplicant_${IFVAR}!" && return 1 ;;
+   esac
+   done
+   case "$opt_D" in
+   roboswitch) wireless=false ;;
+   wired) wireless=false ;;
+   *) _is_wireless || return 0;;
+   esac
 
# We don't configure wireless if we're being called from
# the background unless we're not currently running



[gentoo-commits] proj/netifrc:master commit in: net/

2017-11-14 Thread Robin H. Johnson
commit: af56301d75988a12c5347b8e9db6812d36f157b4
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Tue Nov 14 19:16:28 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Tue Nov 14 19:16:28 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=af56301d

net/iproute2: refactor veinfo+CMD to _cmd helper.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 77 +
 1 file changed, 34 insertions(+), 43 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 7dea195..6d7a3b5 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -8,16 +8,21 @@ iproute2_depend()
after ifconfig
 }
 
+# This helper exists for the common pattern of 'veinfo $CMD ; $CMD'
+_cmd()
+{
+   veinfo "${@}"
+   "${@}"
+}
+
 _up()
 {
-   veinfo ip link set dev "${IFACE}" up
-   ip link set dev "${IFACE}" up
+   _cmd ip link set dev "${IFACE}" up
 }
 
 _down()
 {
-   veinfo ip link set dev "${IFACE}" down
-   ip link set dev "${IFACE}" down
+   _cmd ip link set dev "${IFACE}" down
 }
 
 _exists()
@@ -59,8 +64,7 @@ _set_flag()
flag=${flag#-}
opt="off"
fi
-   veinfo ip link set dev "${IFACE}" "${flag}" "${opt}"
-   ip link set dev "${IFACE}" "${flag}" "${opt}"
+   _cmd ip link set dev "${IFACE}" "${flag}" "${opt}"
 }
 
 _get_mac_address()
@@ -82,8 +86,7 @@ _get_mac_address()
 
 _set_mac_address()
 {
-   veinfo ip link set dev "${IFACE}" address "$1"
-   ip link set dev "${IFACE}" address "$1"
+   _cmd ip link set dev "${IFACE}" address "$1"
 }
 
 _get_inet_addresses()
@@ -102,8 +105,7 @@ _get_inet_address()
 _add_address()
 {
if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ]; then
-   veinfo ip addr add "$@" dev "${IFACE}" 2>/dev/null
-   ip addr add "$@" dev "${IFACE}" 2>/dev/null
+   _cmd ip addr add "$@" dev "${IFACE}" 2>/dev/null
return 0
fi
local x
@@ -179,8 +181,7 @@ _add_address()
 
# This must appear on a single line, continuations cannot be used
set -- "${address}${netmask:+/}${netmask}" ${peer:+peer} ${peer} 
${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} 
${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" 
${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} 
$preferred_lft $confflaglist
-   veinfo ip addr add "$@"
-   ip addr add "$@"
+   _cmd ip addr add "$@"
rc=$?
# Check return code in some cases
if [ $rc -ne 0 ]; then
@@ -251,8 +252,7 @@ _add_route()
fgrep -sq "${cmd%% *}"
route_already_exists=$?
 
-   veinfo ip ${family} route append ${cmd} dev "${IFACE}"
-   ip ${family} route append ${cmd} dev "${IFACE}"
+   _cmd ip ${family} route append ${cmd} dev "${IFACE}"
rc=$?
# Check return code in some cases
if [ $rc -ne 0 ]; then
@@ -278,13 +278,10 @@ _add_route()
 
 _delete_addresses()
 {
-   veinfo ip addr flush dev "${IFACE}" scope global 2>/dev/null
-   ip addr flush dev "${IFACE}" scope global 2>/dev/null
-   veinfo ip addr flush dev "${IFACE}" scope site 2>/dev/null
-   ip addr flush dev "${IFACE}" scope site 2>/dev/null
+   _cmd ip addr flush dev "${IFACE}" scope global 2>/dev/null
+   _cmd ip addr flush dev "${IFACE}" scope site 2>/dev/null
if [ "${IFACE}" != "lo" ]; then
-   veinfo ip addr flush dev "${IFACE}" scope host 2>/dev/null
-   ip addr flush dev "${IFACE}" scope host 2>/dev/null
+   _cmd ip addr flush dev "${IFACE}" scope host 2>/dev/null
fi
return 0
 }
@@ -294,10 +291,10 @@ _has_carrier()
LC_ALL=C ip link show dev "${IFACE}" | grep -q "LOWER_UP"
 }
 
+# Used by iproute2, ip6rd & ip6to4
 _tunnel()
 {
-   veinfo ip tunnel "$@"
-   ip tunnel "$@"
+   _cmd ip $FAMILY tunnel "$@"
rc=$?
# TODO: check return code in some cases
return $rc
@@ -349,8 +346,7 @@ _iproute2_policy_routing()
_ip_rule_runner -4 add "${rules}"
fi
fi
-   veinfo ip -4 route flush table cache dev "${IFACE}"
-   ip -4 route flush table cache dev "${IFACE}"
+   FAMILY="-4" IFACE="${IFACE}" _iproute2_route_flush
fi
 
# Kernel may not have IPv6 built in
@@ -365,8 +361,7 @@ _iproute2_policy_routing()
_ip_rule_runner -6 add "${rules}"
fi
fi
-   veinfo ip -6 route flush table cache dev "${IFACE}"
-   ip -6 route flush table cache dev "${IFACE}"
+   FAMILY="-6" IFACE="${IFACE}" _iproute2_route_flush
fi
 }
 
@@ -388,8 +383,7 @@ iproute2_pre_start()
esac
 
ebegin "Creating tunnel ${IFVAR}"
-   veinfo 

[gentoo-commits] proj/netifrc:master commit in: net/

2017-11-14 Thread Robin H. Johnson
commit: 5496033be61f97755627ba1da45421a2a635c09e
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Tue Nov 14 20:41:27 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Tue Nov 14 20:41:27 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=5496033b

net/iproute2: clarify "waiting for IPv6 addresses"

Per bug 636846, a user thought that "waiting for IPv6 addresses" was
SLAAC (Stateless Autoconfiguration). In Linux, SLAAC is entirely
kernel-side, and the waiting is actually for DAD (duplicate address
detection) on link-local IPv6 addresses.

- Improve the message to include both DAD & tentative.
- If --verbose is used, print the tentative addresses.

If either of the accept_dad sysctls are set to zero, then the kernel
should NOT mark any addresses as tentative.
- net.ipv6.conf.all.accept_dad=0
- net.ipv6.conf.$IFACE.accept_dad=0

Bug: https://bugs.gentoo.org/636846
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 6d7a3b5..d33ee11 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -463,7 +463,11 @@ iproute2_post_start()
# This block must be non-fatal, otherwise the interface will not be
# recorded as starting, and later services may be blocked.
if _iproute2_ipv6_tentative; then
-   einfon "Waiting for IPv6 addresses (${_dad_timeout} seconds) "
+   if [ "$EINFO_VERBOSE" = "yes" ]; then
+   veinfo "Found tentative addresses:"
+   LC_ALL=C ip -family inet6 addr show dev ${IFACE} 
tentative
+   fi
+   einfon "Waiting for tentative IPv6 addresses to complete DAD 
(${_dad_timeout} seconds) "
while [ $_dad_timeout -gt 0 ]; do
_iproute2_ipv6_tentative || break
sleep 1



[gentoo-commits] proj/netifrc:master commit in: net/

2017-10-21 Thread Robin H. Johnson
commit: 552884f6eb4308109421cc7f90b6b675b82e48b7
Author: stkchp  tkch  net>
AuthorDate: Tue Oct 17 03:04:31 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Thu Oct 19 13:30:24 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=552884f6

net/iproute2: delete IPv6 tunnel.

 net/iproute2.sh | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index d5612ab..7dea195 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -434,6 +434,13 @@ iproute2_pre_start()
return 0
 }
 
+_iproute2_tunnel_delete() {
+   ebegin "Destroying tunnel $1"
+   veinfo ip $2 tunnel del "$1"
+   ip $2 tunnel del "$1"
+   eend $?
+}
+
 _iproute2_link_delete() {
ebegin "Destroying interface $1"
veinfo ip link del dev "$1"
@@ -518,11 +525,11 @@ iproute2_post_stop()
# Don't delete sit0 as it's a special tunnel
if [ "${IFACE}" != "sit0" ]; then
if [ -n "$(ip tunnel show "${IFACE}" 2>/dev/null)" ]; then
-   ebegin "Destroying tunnel ${IFACE}"
-   veinfo ip tunnel del "${IFACE}"
-   ip tunnel del "${IFACE}"
-   eend $?
+   _iproute2_tunnel_delete "${IFACE}"
+   elif  [ -n "$(ip -6 tunnel show "${IFACE}" 2>/dev/null)" ]; then
+   _iproute2_tunnel_delete "${IFACE}" -6
fi
+
[ -n "$(ip link show "${IFACE}" type gretap 2>/dev/null)" ] && 
_iproute2_link_delete "${IFACE}"
[ -n "$(ip link show "${IFACE}" type vxlan 2>/dev/null)" ] && 
_iproute2_link_delete "${IFACE}"
fi



[gentoo-commits] proj/netifrc:master commit in: net/

2017-06-09 Thread Robin H. Johnson
commit: 90f9fd0cee3284767d42d314683e22eb0613c55f
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Fri Jun  9 23:58:49 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Fri Jun  9 23:58:49 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=90f9fd0c

iproute2: apply ipproto=-6 cleanup.

Case statements for easier reading of ipproto='-6' choice.

Fixes: 
https://github.com/gentoo/netifrc/pull/24/files/60714158b4536d1e5694ec8a45e2cfac56202027#r98297184
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 55c9592..d5612ab 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -381,10 +381,11 @@ iproute2_pre_start()
# be passed to iproute2 during tunnel creation.
# state 'any' does not exist for IPv4
local ipproto=''
-   [ "${tunnel##mode ipip6}" != "${tunnel}" ] && ipproto='-6'
-   [ "${tunnel##mode ip6ip6}" != "${tunnel}" ] && ipproto='-6'
-   [ "${tunnel##mode ip6gre}" != "${tunnel}" ] && ipproto='-6'
-   [ "${tunnel##mode any}" != "${tunnel}" ] && ipproto='-6'
+   case $tunnel in
+   *mode\ ipip6*) ipproto='-6' ;;
+   *mode\ ip6*) ipproto='-6' ;;
+   *mode\ any*) ipproto='-6' ;;
+   esac
 
ebegin "Creating tunnel ${IFVAR}"
veinfo ip ${ipproto} tunnel add ${tunnel} name "${IFACE}"
@@ -396,9 +397,11 @@ iproute2_pre_start()
eval link=\$iplink_${IFVAR}
if [ -n "${link}" ]; then
local ipproto=''
-   [ "${tunnel##mode ip6gre}" != "${tunnel}" ] && ipproto='-6'
-   [ "${tunnel##mode ip6gretap}" != "${tunnel}" ] && ipproto='-6'
-   [ "${tunnel##mode ip6tnl}" != "${tunnel}" ] && ipproto='-6'
+   case $tunnel in
+   *mode\ ipip6*) ipproto='-6' ;;
+   *mode\ ip6*) ipproto='-6' ;;
+   *mode\ any*) ipproto='-6' ;;
+   esac
 
ebegin "Creating interface ${IFVAR}"
veinfo ip ${ipproto} link add "${IFACE}" ${link}



[gentoo-commits] proj/netifrc:master commit in: net/

2017-06-09 Thread Robin H. Johnson
commit: 1f76981467f9bbf1f2e22eb154fbb133ba333773
Author: Sergey Popov  pinkbyte  ru>
AuthorDate: Tue Jan 24 09:18:21 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Tue Jan 24 13:45:52 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=1f769814

Support for creating interfaces through iproute2 link command

Original idea and patch by Joseph Glanville  
orionvm.com.au>
https://gist.github.com/josephglanville/2757336

 net/iproute2.sh | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 32ea5a4..55c9592 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -392,6 +392,20 @@ iproute2_pre_start()
eend $? || return 1
_up
fi
+   local link=
+   eval link=\$iplink_${IFVAR}
+   if [ -n "${link}" ]; then
+   local ipproto=''
+   [ "${tunnel##mode ip6gre}" != "${tunnel}" ] && ipproto='-6'
+   [ "${tunnel##mode ip6gretap}" != "${tunnel}" ] && ipproto='-6'
+   [ "${tunnel##mode ip6tnl}" != "${tunnel}" ] && ipproto='-6'
+
+   ebegin "Creating interface ${IFVAR}"
+   veinfo ip ${ipproto} link add "${IFACE}" ${link}
+   ip ${ipproto} link add "${IFACE}" ${link}
+   eend $? || return 1
+   _up
+   fi
 
# MTU support
local mtu=
@@ -417,6 +431,13 @@ iproute2_pre_start()
return 0
 }
 
+_iproute2_link_delete() {
+   ebegin "Destroying interface $1"
+   veinfo ip link del dev "$1"
+   ip link del dev "$1"
+   eend $?
+}
+
 _iproute2_ipv6_tentative()
 {
[ -n "$(LC_ALL=C ip -family inet6 addr show dev ${IFACE} tentative)" ] 
&& return 0
@@ -499,6 +520,8 @@ iproute2_post_stop()
ip tunnel del "${IFACE}"
eend $?
fi
+   [ -n "$(ip link show "${IFACE}" type gretap 2>/dev/null)" ] && 
_iproute2_link_delete "${IFACE}"
+   [ -n "$(ip link show "${IFACE}" type vxlan 2>/dev/null)" ] && 
_iproute2_link_delete "${IFACE}"
fi
 }
 



[gentoo-commits] proj/netifrc:master commit in: net/

2017-06-09 Thread Robin H. Johnson
commit: 18bceba0c3cd4a40937d158f8b59461d0eebee7f
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Fri Jun  9 23:51:53 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Fri Jun  9 23:51:53 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=18bceba0

bonding: make patching sysfs args easier in future.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/bonding.sh | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/bonding.sh b/net/bonding.sh
index a25bf1f..6e5d810 100644
--- a/net/bonding.sh
+++ b/net/bonding.sh
@@ -78,6 +78,7 @@ bonding_pre_start()
fi
done
# Configure arp ip targets, they need to be added one after another
+   # With a leading '+' as a prefix.
n=arp_ip_target
x=/sys/class/net/"${IFACE}"/bonding/$n
[ -d /sys/class/net ] && if [ -f "$x" ]; then
@@ -94,9 +95,14 @@ bonding_pre_start()
[ -d /sys/class/net ] && for x in /sys/class/net/"${IFACE}"/bonding/*; 
do
[ -f "${x}" ] || continue
n=${x##*/}
+   # These entries are already handled above.
+   case "$n" in
+   mode) continue ;;
+   miimon) continue ;;
+   arp_ip_target) continue ;;
+   esac
+   # Check if anything to do.
eval s=\$${n}_${IFVAR}
-   # skip mode and miimon
-   [ "${n}" = "mode" -o "${n}" = "miimon" -o "${n}" = 
"arp_ip_target" ] && continue
if [ -n "${s}" ]; then
einfo "Setting ${n}: ${s}"
echo "${s}" >"${x}" || \
@@ -156,7 +162,7 @@ bonding_pre_start()
fi
# up the interface
_up
-fi
+   fi
 
# finally add in slaves
# things needed in the process, and if they are done by ifenslave, 
openrc, and/or the kernel.



[gentoo-commits] proj/netifrc:master commit in: net/

2017-06-09 Thread Robin H. Johnson
commit: 85f486367ab158b605d8817571028c90bccdc130
Author: Marc Schiffbauer  gentoo  org>
AuthorDate: Mon Feb  6 18:23:41 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Fri Jun  9 23:48:18 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=85f48636

bonding: add arp_ip_targets properly

netifrc handles bonding interfaces in /lib/netifrc/net/bonding.sh which
will apply all settings (*_bondX) like 'echo "${s}" >"${x}"' which will
not work for bonding arip ip targets: these have to be added by using
"echo + > arp_ip_target"

Please consider merging the attached patch which will fix that feature
and make netifrc work correctly with bonding interfaces when using
arp_ip_target instead of miimon.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/bonding.sh | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/net/bonding.sh b/net/bonding.sh
index d0ed319..a25bf1f 100644
--- a/net/bonding.sh
+++ b/net/bonding.sh
@@ -1,4 +1,5 @@
 # Copyright (c) 2007-2008 Roy Marples 
+#   2017  Marc Schiffbauer 
 # Released under the 2-clause BSD license.
 
 bonding_depend()
@@ -21,7 +22,7 @@ _is_bond()
 
 bonding_pre_start()
 {
-   local x= s= n= slaves= primary=
+   local x= s= n= i= slaves= primary=
 
slaves="$(_get_array "slaves_${IFVAR}")"
unset slaves_${IFVAR}
@@ -76,13 +77,26 @@ bonding_pre_start()
eerror "Failed to configure $n (${n}_${IFVAR})"
fi
done
+   # Configure arp ip targets, they need to be added one after another
+   n=arp_ip_target
+   x=/sys/class/net/"${IFACE}"/bonding/$n
+   [ -d /sys/class/net ] && if [ -f "$x" ]; then
+   eval s=\$${n}_${IFVAR}
+   if [ -n "${s}" ]; then
+   for i in $s; do
+   einfo "Adding ${n}: ${i}"
+   echo "+${i/+/}" >"${x}" || \
+   eerror "Failed to add $i (${n}_${IFVAR})"
+   done
+   fi
+   fi
# Nice and dynamic for remaining options:)
[ -d /sys/class/net ] && for x in /sys/class/net/"${IFACE}"/bonding/*; 
do
[ -f "${x}" ] || continue
n=${x##*/}
eval s=\$${n}_${IFVAR}
# skip mode and miimon
-   [ "${n}" = "mode" -o "${n}" = "miimon" ] && continue
+   [ "${n}" = "mode" -o "${n}" = "miimon" -o "${n}" = 
"arp_ip_target" ] && continue
if [ -n "${s}" ]; then
einfo "Setting ${n}: ${s}"
echo "${s}" >"${x}" || \



[gentoo-commits] proj/netifrc:master commit in: net/

2017-01-27 Thread Robin H. Johnson
commit: 1e14262524d65918ed6d1d13f2abd87b2f11425b
Author: Sergey Popov  pinkbyte  ru>
AuthorDate: Tue Jan 24 14:10:36 2017 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Tue Jan 24 14:10:36 2017 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=1e142625

Check for L2TP support in kernel

 net/l2tp.sh | 4 
 1 file changed, 4 insertions(+)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index 5efb535..dec1986 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -32,6 +32,10 @@ _l2tp_eval_props() {
 }
 
 _is_l2tp() {
+   # Check for L2TP support in kernel
+   ip l2tp show session &>/dev/null
+   [ $? -ne 0 ] && return 1
+
eval "$(ip l2tp show session | \
awk "match(\$0, /^Session ([0-9]+) in tunnel ([0-9]+)\$/, ret) 
{sid=ret[1]; tid=ret[2]} 
match(\$0, /^[ ]*interface name: ${IFACE}\$/) {print 
\"session_id=\"sid\";tunnel_id=\"tid; exit}")"



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-26 Thread Robin H. Johnson
commit: 964a3a835eaa914422d5de55cd4151b4e56b544a
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Wed Oct 26 20:12:16 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Wed Oct 26 20:12:16 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=964a3a83

net/iproute2: fix netmask specifier.

X-Gentoo-Bug: 598078
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=598078
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 6efa2e7..32ea5a4 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -133,7 +133,7 @@ _add_address()
eerror "Too many netmasks: $raw_address 
netmask $1"
return 1
fi
-   netmask="/$(_netmask2cidr "$1")"
+   netmask="$(_netmask2cidr "$1")"
shift ;;
broadcast|brd|br*)
broadcast="$1" ; shift ;;



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-24 Thread Robin H. Johnson
commit: edd52106d7c868c86c396e0c2f486e58a6132d3c
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Oct 24 23:14:06 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Oct 24 23:14:06 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=edd52106

net/macchanger: support newer macchanger tool.

Newer versions of macchanger require -m to specify the MAC (it used to
be a non-option argument).

Also don't depend on the output format at all anymore, instead reading
the new MAC from sysfs on after macchanger reports success.

X-Gentoo-Bug: 540728
X-Gentoo-Bug: 547906
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=540728
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=547906
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/macchanger.sh | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/net/macchanger.sh b/net/macchanger.sh
index ff13770..ae9ff9b 100644
--- a/net/macchanger.sh
+++ b/net/macchanger.sh
@@ -14,7 +14,7 @@ macchanger_pre_start()
# We don't change MAC addresses from background
yesno ${IN_BACKGROUND} && return 0
 
-   local mac= opts=
+   local mac= opts= try= output= rc=
 
eval mac=\$mac_${IFVAR}
[ -z "${mac}" ] && return 0
@@ -60,7 +60,7 @@ macchanger_pre_start()
random-full|random) opts="${opts} -r";;
 
# default case is just to pass on all the options
-   *) opts="${opts} ${mac}";;
+   *) opts="${opts} -m ${mac}";;
esac
 
if [ ! -x /sbin/macchanger ]; then
@@ -68,24 +68,24 @@ macchanger_pre_start()
return 1
fi
 
-   mac=$(/sbin/macchanger ${opts} "${IFACE}" \
-   | sed -n -e 's/^\(Faked\|New\) 
MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\2/p' )
-   _up
+   for try in 1 2; do
+   # Sometimes the interface needs to be up
+   [ "${try}" -eq 2 ] && _up
+   output=$(/sbin/macchanger ${opts} "${IFACE}")
+   rc=$?
+   [ "${rc}" -eq 0 ] && break
+   done
 
-   # Sometimes the interface needs to be up 
-   if [ -z "${mac}" ]; then
-   mac=$(/sbin/macchanger ${opts} "${IFACE}" \
-   | sed -n -e 's/^\(Faked\|New\) 
MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\2/p' )
-   fi
-
-   if [ -z "${mac}" ]; then
+   if [ "${rc}" -ne 0 ]; then
+   eerror "${output}"
eend 1 "Failed to set MAC address"
return 1
fi
 
eend 0
eindent
-   einfo "changed to" "${mac}"
+   newmac=$(_get_mac_address)
+   einfo "changed to ${newmac}"
eoutdent
 
return 0



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-24 Thread Robin H. Johnson
commit: 699636d47ce69ad2ada2748e4522447dc57aadf9
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Oct 24 20:56:20 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Oct 24 20:56:20 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=699636d4

net/iproute2: no automatic scope=host on loopback.

Busybox 'ip address add' does not support the 'scope' argument.

It DOES support the scope argument for 'ip address show', as well as all
of 'ip route'. The kernel does get automatic scope correct now, so drop
any automatic setting of scope to host when it was not otherwise
specified, and let the kernel make it's own decision.

X-Gentoo-Bug: 487208
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=487208
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 5 -
 1 file changed, 5 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 32d3c88..6efa2e7 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -162,11 +162,6 @@ _add_address()
esac
done
 
-   # Always scope lo addresses as host unless specified otherwise
-   if [ "${IFACE}" = "lo" ]; then
-   [ -z "$scope" ] && scope="host"
-   fi
-
# figure out the broadcast address if it is not specified
# This must NOT be set for IPv6 addresses
case $family in



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-24 Thread Robin H. Johnson
commit: 7e3c6ff7af8c1559301bf1e28f1b9c8188c519ac
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Oct 24 16:44:45 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Oct 24 16:44:50 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=7e3c6ff7

net/iproute2: IPv6 DAD delay must be non-fatal.

Commit 50c9fd7827fa58d27a593c8c480068f85c047cec introduced a subtle
accidental change in the handling of IPv6 tentative addresses.

In an environment where the DAD completion time exceeds the configured
timeout (which was also reduced to 5 seconds, while the docs say 10
seconds), the interface was recorded as failing to start when the
timeout was hit without DAD completion. This means that the interface
was then marked as failed and later services did not start. No rollback
took place either.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 9ef704d..32d3c88 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -441,6 +441,8 @@ iproute2_post_start()
[ -z "$policyroute_order" ] && 
policyroute_order=${policy_rules_before_routes:-no}
yesno "$policyroute_order" || _iproute2_policy_routing
 
+   # This block must be non-fatal, otherwise the interface will not be
+   # recorded as starting, and later services may be blocked.
if _iproute2_ipv6_tentative; then
einfon "Waiting for IPv6 addresses (${_dad_timeout} seconds) "
while [ $_dad_timeout -gt 0 ]; do
@@ -454,7 +456,6 @@ iproute2_post_start()
 
if [ $_dad_timeout -le 0 ]; then
eend 1
-   return 1
else
eend 0
fi



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: bf3ee524b605e6a78f5abeb0e6577ae8a9b16f0c
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Oct 24 00:25:41 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Oct 24 00:25:41 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=bf3ee524

iproute2/_get_route: better output on route check

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 1dff3fe..9ef704d 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -272,8 +272,8 @@ _add_route()
error|fatal) msgfunc=eerror rc=1;;
*) msgfunc=eerror rc=1 ; eerror "Unknown error 
behavior: $eh_behavior" ;;
esac
-   eval $msgfunc "Route '$cmd' already existed."
-   eval $msgfunc \"$(ip $family route show $cmd dev 
"${IFACE}" 2>&1)\"
+   eval $msgfunc "Route '$cmd_nometric' already existed:"
+   eval $msgfunc \"$(ip $family route show ${cmd_nometric} 
dev "${IFACE}" 2>&1)\"
else
: # TODO: Handle other errors
fi



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: 0bd4f26da64fb30e0fba06e5866f0bdac132459b
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Oct 24 00:17:08 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Oct 24 00:17:08 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=0bd4f26d

iproute2/_add_route: ensure metric is set properly.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 408e293..938a5fb 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -235,7 +235,7 @@ _add_route()
local cmd= have_metric=false
while [ -n "$1" ]; do
case "$1" in
-   metric) cmd="${cmd} $1"; have_metric=true;;
+   metric) cmd="${cmd} metric $2"; shift ; 
have_metric=true;;
netmask) cmd="${cmd}/$(_netmask2cidr "$2")"; shift;;
-host|-net);;
*) cmd="${cmd} $1";;



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: 95105e7437c1680d564279f4dd7063d7241370ac
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Oct 24 00:23:06 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Oct 24 00:23:06 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=95105e74

iproute2/_get_route: do not include metric in test for existing route.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 938a5fb..1dff3fe 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -232,13 +232,13 @@ _add_route()
set -- "${one}" "${two}" via "$@"
fi
 
-   local cmd= have_metric=false
+   local cmd= cmd_nometric= have_metric=false
while [ -n "$1" ]; do
case "$1" in
-   metric) cmd="${cmd} metric $2"; shift ; 
have_metric=true;;
-   netmask) cmd="${cmd}/$(_netmask2cidr "$2")"; shift;;
+   metric) metric=$2 ; cmd="${cmd} metric $2" ; shift ; 
have_metric=true ;;
+   netmask) x="/$(_netmask2cidr "$2")" ; cmd="${cmd}${x}" 
; cmd_nometric="${cmd}${x}" ; shift;;
-host|-net);;
-   *) cmd="${cmd} $1";;
+   *) cmd="${cmd} ${1}" ; cmd_nometric="${cmd_nometric} 
${1}" ;;
esac
shift
done
@@ -252,7 +252,7 @@ _add_route()
fi
 
# Check for route already existing:
-   ip ${family} route show ${cmd} dev "${IFACE}" 2>/dev/null | \
+   ip ${family} route show ${cmd_nometric} dev "${IFACE}" 2>/dev/null | \
fgrep -sq "${cmd%% *}"
route_already_exists=$?
 



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: 7a057b6ab2dc644f7b292666f4363a72df47a03d
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Oct 23 23:52:01 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Oct 23 23:52:01 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=7a057b6a

iproute2: handle other error case better.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 779d334..2c9f6bb 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -203,7 +203,7 @@ _add_address()
$msgfunc "Address ${address}${netmask:+/}${netmask} 
already existed: $(ip addr show to "${address}/${family_maxnetmask}" dev 
"${IFACE}" 2>&1)"
[ $abort -eq 1 ] && rc=1
else
-   # TODO: Handle other errors
+   : # TODO: Handle other errors
fi
fi
return $rc
@@ -275,7 +275,7 @@ _add_route()
$msgfunc "Route '$cmd' already existed: $(ip $family 
route show $cmd dev "${IFACE}" 2>&1)"
[ $abort -eq 1 ] && rc=1
else
-   # TODO: Handle other errors
+   : # TODO: Handle other errors
fi
fi
eend $rc



[gentoo-commits] proj/netifrc:master commit in: net/, init.d/

2016-10-23 Thread Robin H. Johnson
commit: 7242a8d22d0a441c54824bef37c09731e4918587
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Oct 24 00:02:32 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Oct 24 00:02:32 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=7242a8d2

iproute2: clean up error output and make sure it works.

Signed-off-by: Robin H. Johnson  gentoo.org>

 init.d/net.lo.in |  4 +++-
 net/iproute2.sh  | 28 +---
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/init.d/net.lo.in b/init.d/net.lo.in
index 3b47f1a..dbade70 100644
--- a/init.d/net.lo.in
+++ b/init.d/net.lo.in
@@ -248,7 +248,7 @@ _get_errorhandler_behavior() {
"errh_DEFAULT_DEFAULT_DEFAULT" \
"errh" \
"fallback" ; do
-   eval value="\${key}"
+   eval value="\${${key}}"
if [ -n "$value" ]; then
echo "$value" && break
fi
@@ -844,3 +844,5 @@ stop()
 
return 0
 }
+
+# vim:filetype=gentoo-init-d:

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 2c9f6bb..b6fd847 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -112,7 +112,7 @@ _add_address()
local confflaglist family raw_address family_maxnetmask
raw_address="$1" ; shift
# Extract the netmask on address if present.
-   if [ "${address%\/*}" != "${address}" ]; then
+   if [ "${raw_address%\/*}" != "${raw_address}" ]; then
address="${raw_address%\/*}"
netmask="${raw_address#*\/}"
else
@@ -193,15 +193,14 @@ _add_address()
# You can completely silence this with: 
errh_IFVAR_address_EEXIST=continue
if [ $address_already_exists -eq 0 ]; then
eh_behavior=$(_get_errorhandler_behavior "$IFVAR" 
"address" "EEXIST" "warn")
-   abort=0
case $eh_behavior in
-   continue) msgfunc=true ;;
-   info) msgfunc=einfo ;;
-   warn) msgfunc=ewarn ;;
-   error|fatal) msgfunc=eerror abort=1;;
+   continue) msgfunc=true rc=0 ;;
+   info) msgfunc=einfo rc=0 ;;
+   warn) msgfunc=ewarn rc=0 ;;
+   error|fatal) msgfunc=eerror rc=1;;
esac
-   $msgfunc "Address ${address}${netmask:+/}${netmask} 
already existed: $(ip addr show to "${address}/${family_maxnetmask}" dev 
"${IFACE}" 2>&1)"
-   [ $abort -eq 1 ] && rc=1
+   eval $msgfunc "Address 
${address}${netmask:+/}${netmask} already existed!"
+   eval $msgfunc \"$(ip addr show to 
"${address}/${family_maxnetmask}" dev "${IFACE}" 2>&1)\"
else
: # TODO: Handle other errors
fi
@@ -265,15 +264,14 @@ _add_route()
# You can completely silence this with: 
errh_IFVAR_route_EEXIST=continue
if [ $route_already_exists -eq 0 ]; then
eh_behavior=$(_get_errorhandler_behavior "$IFVAR" 
"route" "EEXIST" "warn")
-   abort=0
case $eh_behavior in
-   continue) msgfunc=true ;;
-   info) msgfunc=einfo ;;
-   warn) msgfunc=ewarn ;;
-   error|fatal) msgfunc=eerror abort=1;;
+   continue) msgfunc=true rc=0 ;;
+   info) msgfunc=einfo rc=0 ;;
+   warn) msgfunc=ewarn rc=0 ;;
+   error|fatal) msgfunc=eerror rc=1;;
esac
-   $msgfunc "Route '$cmd' already existed: $(ip $family 
route show $cmd dev "${IFACE}" 2>&1)"
-   [ $abort -eq 1 ] && rc=1
+   eval $msgfunc "Route '$cmd' already existed."
+   eval $msgfunc \"$(ip $family route show $cmd dev 
"${IFACE}" 2>&1)\"
else
: # TODO: Handle other errors
fi



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: c9fcba63eba9760cdbd5effc9a63394a3fa9d3ae
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon Oct 24 00:04:16 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon Oct 24 00:04:16 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=c9fcba63

iproute2: error-check the error-behavior input.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index b6fd847..408e293 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -198,6 +198,7 @@ _add_address()
info) msgfunc=einfo rc=0 ;;
warn) msgfunc=ewarn rc=0 ;;
error|fatal) msgfunc=eerror rc=1;;
+   *) msgfunc=eerror rc=1 ; eerror "Unknown error 
behavior: $eh_behavior" ;;
esac
eval $msgfunc "Address 
${address}${netmask:+/}${netmask} already existed!"
eval $msgfunc \"$(ip addr show to 
"${address}/${family_maxnetmask}" dev "${IFACE}" 2>&1)\"
@@ -269,6 +270,7 @@ _add_route()
info) msgfunc=einfo rc=0 ;;
warn) msgfunc=ewarn rc=0 ;;
error|fatal) msgfunc=eerror rc=1;;
+   *) msgfunc=eerror rc=1 ; eerror "Unknown error 
behavior: $eh_behavior" ;;
esac
eval $msgfunc "Route '$cmd' already existed."
eval $msgfunc \"$(ip $family route show $cmd dev 
"${IFACE}" 2>&1)\"



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: c0e9d13165c53ee934b25883b03ff39ef04e2904
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Oct 23 23:35:11 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Oct 23 23:35:11 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=c0e9d131

iproute2: capture the family and always set netmask explicitly.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 39 +++
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 6cf9aef..f15f3af 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -109,17 +109,31 @@ _add_address()
local x
local address netmask broadcast peer anycast label scope
local valid_lft preferred_lft home nodad
-   local confflaglist
-   address="$1" ; shift
+   local confflaglist family raw_address family_maxnetmask
+   raw_address="$1" ; shift
+   # Extract the netmask on address if present.
+   if [ "${address%\/*}" != "${address}" ]; then
+   address="${raw_address%\/*}"
+   netmask="${raw_address#*\/}"
+   else
+   address="$raw_address"
+   fi
+
+   # Some options are not valid for one family or the other.
+   case ${address} in
+   *:*) family=6 family_maxnetmask=128 ;;
+   *) family=4 family_maxnetmask=32 ;;
+   esac
+
while [ -n "$*" ]; do
x=$1 ; shift
case "$x" in
netmask|ne*)
-   netmask="/$(_netmask2cidr "$1")"
-   if [ "${address/\/}" != "${address}" ]; then
-   eerror "Too many netmasks: $address 
netmask $1"
+   if [ -n "${netmask}" ]; then
+   eerror "Too many netmasks: $raw_address 
netmask $1"
return 1
fi
+   netmask="/$(_netmask2cidr "$1")"
shift ;;
broadcast|brd|br*)
broadcast="$1" ; shift ;;
@@ -155,15 +169,16 @@ _add_address()
 
# figure out the broadcast address if it is not specified
# This must NOT be set for IPv6 addresses
-   if [ "${address#*:}" = "${address}" ]; then
-   [ -z "$broadcast" ] && broadcast="+"
-   elif [ -n "$broadcast" ]; then
-   eerror "Broadcast keywords are not valid with IPv6 addresses"
-   return 1
-   fi
+   case $family in
+   4) [ -z "$broadcast" ] && broadcast="+" ;;
+   6) [ -n "$broadcast" ] && eerror "Broadcast keywords are not 
valid with IPv6 addresses" && return 1 ;;
+   esac
+
+   # Always have a netmask
+   [ -z "$netmask" ] && netmask=$family_maxnetmask
 
# This must appear on a single line, continuations cannot be used
-   set -- "${address}${netmask}" ${peer:+peer} ${peer} 
${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} 
${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" 
${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} 
$preferred_lft $confflaglist
+   set -- "${address}${netmask:+/}${netmask}" ${peer:+peer} ${peer} 
${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} 
${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" 
${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} 
$preferred_lft $confflaglist
veinfo ip addr add "$@"
ip addr add "$@"
rc=$?



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: f9793bb67a40dc58c97772a9731a2b6dfcb1422f
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Oct 23 23:50:08 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Oct 23 23:50:08 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=f9793bb6

iproute2: treat EEXIST error on routes as non-fatal.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index d03548e..779d334 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -251,10 +251,33 @@ _add_route()
cmd="${cmd} metric ${metric}"
fi
 
+   # Check for route already existing:
+   ip ${family} route show ${cmd} dev "${IFACE}" 2>/dev/null | \
+   fgrep -sq "${cmd%% *}"
+   route_already_exists=$?
+
veinfo ip ${family} route append ${cmd} dev "${IFACE}"
ip ${family} route append ${cmd} dev "${IFACE}"
rc=$?
-   # TODO: check return code in some cases
+   # Check return code in some cases
+   if [ $rc -ne 0 ]; then
+   # If the route already exists, our default behavior is to WARN 
but continue.
+   # You can completely silence this with: 
errh_IFVAR_route_EEXIST=continue
+   if [ $route_already_exists -eq 0 ]; then
+   eh_behavior=$(_get_errorhandler_behavior "$IFVAR" 
"route" "EEXIST" "warn")
+   abort=0
+   case $eh_behavior in
+   continue) msgfunc=true ;;
+   info) msgfunc=einfo ;;
+   warn) msgfunc=ewarn ;;
+   error|fatal) msgfunc=eerror abort=1;;
+   esac
+   $msgfunc "Route '$cmd' already existed: $(ip $family 
route show $cmd dev "${IFACE}" 2>&1)"
+   [ $abort -eq 1 ] && rc=1
+   else
+   # TODO: Handle other errors
+   fi
+   fi
eend $rc
 }
 



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: 5be82041cf23b0359190c148e9d356d8aa85e18b
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Oct 23 23:43:35 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Oct 23 23:43:35 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=5be82041

iproute2: treat EEXIST error on addresses as non-fatal.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index f15f3af..d03548e 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -177,12 +177,35 @@ _add_address()
# Always have a netmask
[ -z "$netmask" ] && netmask=$family_maxnetmask
 
+   # Check for address already existing:
+   ip addr show to "${address}/${family_maxnetmask}" dev "${IFACE}" 
2>/dev/null | \
+   fgrep -sq "${address}"
+   address_already_exists=$?
+
# This must appear on a single line, continuations cannot be used
set -- "${address}${netmask:+/}${netmask}" ${peer:+peer} ${peer} 
${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} 
${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" 
${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} 
$preferred_lft $confflaglist
veinfo ip addr add "$@"
ip addr add "$@"
rc=$?
-   # TODO: check return code in some cases
+   # Check return code in some cases
+   if [ $rc -ne 0 ]; then
+   # If the address already exists, our default behavior is to 
WARN but continue.
+   # You can completely silence this with: 
errh_IFVAR_address_EEXIST=continue
+   if [ $address_already_exists -eq 0 ]; then
+   eh_behavior=$(_get_errorhandler_behavior "$IFVAR" 
"address" "EEXIST" "warn")
+   abort=0
+   case $eh_behavior in
+   continue) msgfunc=true ;;
+   info) msgfunc=einfo ;;
+   warn) msgfunc=ewarn ;;
+   error|fatal) msgfunc=eerror abort=1;;
+   esac
+   $msgfunc "Address ${address}${netmask:+/}${netmask} 
already existed: $(ip addr show to "${address}/${family_maxnetmask}" dev 
"${IFACE}" 2>&1)"
+   [ $abort -eq 1 ] && rc=1
+   else
+   # TODO: Handle other errors
+   fi
+   fi
return $rc
 }
 



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: 486214bb2d772c9316d7a8e6917a70e4a7405381
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Oct 23 22:39:27 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Oct 23 22:39:27 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=486214bb

iproute2: errorcheck on netmasks.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index d74bc29..682fdc6 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -115,7 +115,12 @@ _add_address()
x=$1 ; shift
case "$x" in
netmask|ne*)
-   netmask="/$(_netmask2cidr "$1")" ; shift ;;
+   netmask="/$(_netmask2cidr "$1")"
+   if [ "${address/\/}" != "${address}" ]; then
+   eerror "Too many netmasks: $address 
netmask $1"
+   return 1
+   fi
+   shift ;;
broadcast|brd|br*)
broadcast="$1" ; shift ;;
pointopoint|pointtopoint|peer|po*|pe*)



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-23 Thread Robin H. Johnson
commit: cec563da1dd8db44a2b9c9f4a0579c5a441e9528
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Oct 23 22:39:50 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Oct 23 22:39:50 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=cec563da

iproute2: prepare for error-checking on ip addr/route/tunnel.

Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 682fdc6..6cf9aef 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -166,6 +166,9 @@ _add_address()
set -- "${address}${netmask}" ${peer:+peer} ${peer} 
${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} 
${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" 
${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} 
$preferred_lft $confflaglist
veinfo ip addr add "$@"
ip addr add "$@"
+   rc=$?
+   # TODO: check return code in some cases
+   return $rc
 }
 
 _add_route()
@@ -212,7 +215,9 @@ _add_route()
 
veinfo ip ${family} route append ${cmd} dev "${IFACE}"
ip ${family} route append ${cmd} dev "${IFACE}"
-   eend $?
+   rc=$?
+   # TODO: check return code in some cases
+   eend $rc
 }
 
 _delete_addresses()
@@ -237,6 +242,9 @@ _tunnel()
 {
veinfo ip tunnel "$@"
ip tunnel "$@"
+   rc=$?
+   # TODO: check return code in some cases
+   return $rc
 }
 
 # This is just to trim whitespace, do not add any quoting!



[gentoo-commits] proj/netifrc:master commit in: net/

2016-10-05 Thread Robin H. Johnson
commit: 6072cfa443119fc89e997d9ff3a7eee5bb33ac36
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Wed Oct  5 14:40:37 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Wed Oct  5 14:40:37 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=6072cfa4

iproute2: add keywords: noprefixroute mngtmpaddr.

iproute2 gained new keywords noprefixroute & mngtmpaddr.
The prefix-match quick config wrongly expands noprefixroute to nodad, so
fix that.

Thanks-To: opensource  zhasha.com
Gentoo-Bug: https://bugs.gentoo.org/show_bug.cgi?id=596234
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/iproute2.sh | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 0b2a8d6..d74bc29 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -129,8 +129,13 @@ _add_address()
pr*) x=preferred_lft ;;
esac
eval "$x=$1" ; shift ;;
-   home|nodad|h*|no*)
-   case $x in h*) x=home ;; n*) x=nodad ;; esac
+   home|mngtmpaddr|nodad|noprefixroute|h*|mng*|no*)
+   case $x in
+   h*) x=home ;;
+   m*) x=mngtmpaddr ;;
+   nop*) x=noprefixroute ;;
+   n*) x=nodad ;;
+   esac
# FIXME: If we need to reorder these, this will 
take more code
confflaglist="${confflaglist} $x" ; ;;
*)



[gentoo-commits] proj/netifrc:master commit in: net/

2016-07-19 Thread Robin H. Johnson
commit: 18dd0598b29d2158529466f1e7097bf894e584dc
Author: Andrey Volkov  ekb-info  ru>
AuthorDate: Fri Jul 15 08:23:56 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Tue Jul 19 19:59:32 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=18dd0598

Fix missing interface types

(cherry picked from commit c8fe42141c95f5446dabf5c0b1f049151e51c2ad)

 net/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/Makefile b/net/Makefile
index a03c171..ce73c1e 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -13,7 +13,7 @@ SRCS-Linux=   iwconfig.sh.in udhcpc.sh.in
 INC-Linux= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \
ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh 
\
ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh 
udhcpc.sh \
-   vlan.sh macvlan.sh ip6rd.sh firewalld.sh
+   vlan.sh macvlan.sh ip6rd.sh firewalld.sh dummy.sh hsr.sh l2tp.sh
 
 SRCS-NetBSD= ifwatchd.sh.in
 INC-NetBSD=ifwatchd.sh



[gentoo-commits] proj/netifrc:master commit in: net/

2016-07-05 Thread Robin H. Johnson
commit: e7a218ea4f3d85df05a8b2ca6c0fe71c0d15e44d
Author: Mr-TI  gmail  com>
AuthorDate: Sun May  1 09:36:55 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May  1 09:36:55 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=e7a218ea

Revert "Add L2TPv3 tunnel/session support to iproute2 module"
Moving the L2TP part to an separate file

This reverts commit 4a8358aaf9c0048930194e0bbe3d2509d9da4fd0.

 net/iproute2.sh | 45 -
 1 file changed, 45 deletions(-)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 825b9b1..0b2a8d6 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -318,32 +318,6 @@ iproute2_pre_start()
eend $? || return 1
_up
fi
-   
-   # L2TPv3
-   local l2tpsession=
-   eval l2tpsession=\$l2tpsession_${IFVAR}
-   if [ -n "${l2tpsession}" ]; then
-   ebegin "Creating L2TPv3 tunnel ${IFVAR}"
-   local l2tptunnel=
-   eval l2tptunnel=\$l2tptunnel_${IFVAR}
-   if [ -n "${l2tptunnel}" ]; then
-   local retcode
-   veinfo ip l2tp add tunnel ${l2tptunnel}
-   ip l2tp add tunnel ${l2tptunnel}
-   #a L2TPv3 tunnel can host several sessions (1 session 
<=> 1 interface)
-   #if $?=2 the tunnel id already exists, just ignore this 
error
-   #we assume that the existing one have the same property 
that we want to create...
-   if [ $? -ne 0 ] && [ $? -ne 2 ]; then
-   eend $? || return 1
-   fi
-   fi
-   veinfo ip l2tp add session ${l2tpsession} name "${IFACE}"
-   ip l2tp add session ${l2tpsession} name "${IFACE}"
-   if [ $? -ne 0 ] && [ $? -ne 2 ]; then
-   eend $? || return 1
-   fi
-   _up
-   fi
 
# MTU support
local mtu=
@@ -450,25 +424,6 @@ iproute2_post_stop()
ip tunnel del "${IFACE}"
eend $?
fi
-   local l2tptuple
-   # Searching for l2tp session associated to ${IFACE}
-   l2tptuple="$(ip l2tp show session | \
-   awk "match(\$0, /^Session ([0-9]+) in tunnel 
([0-9]+)\$/, ret) {sid=ret[1]; tid=ret[2]} 
-   match(\$0, /^[ ]*interface name: ${IFACE}\$/) 
{print sid\":\"tid; exit}")"
-   if [ -n "$l2tptuple" ]; then
-   local l2tpsession_id l2tptunnel_id
-   l2tpsession_id=${l2tptuple%:*}
-   l2tptunnel_id=${l2tptuple#*:}
-   ebegin "Destroying L2TPv3 tunnel ${IFACE}"
-   veinfo ip l2tp del session tunnel_id $l2tptunnel_id 
session_id $l2tpsession_id
-   ip l2tp del session tunnel_id $l2tptunnel_id session_id 
$l2tpsession_id
-   if [ -z "$(ip l2tp show session | grep -E "^Session 
[0-9]+ in tunnel $l2tptunnel_id\$")" ]; then
-   #tunnel $l2tptunnel_id no longer used, 
destoying it...
-   veinfo ip l2tp del tunnel tunnel_id 
$l2tptunnel_id
-   ip l2tp del tunnel tunnel_id $l2tptunnel_id
-   fi
-   eend $?
-   fi
fi
 }
 



[gentoo-commits] proj/netifrc:master commit in: net/

2016-07-05 Thread Robin H. Johnson
commit: 3bdc8488c51bfb1a84c27855f4dd83e814fa81e3
Author: Emeric Verschuur  mbedsys  org>
AuthorDate: Sun May  1 13:38:41 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun May  1 13:38:41 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=3bdc8488

Start/stop message update

 net/l2tp.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/l2tp.sh b/net/l2tp.sh
index 24f5f8c..5efb535 100644
--- a/net/l2tp.sh
+++ b/net/l2tp.sh
@@ -100,7 +100,7 @@ l2tp_pre_start()
eval l2tpsession=\$l2tpsession_${IFVAR}
test -n "${l2tpsession}" || return 0

-   ebegin "Creating L2TP tunnel ${IFVAR}"
+   ebegin "Creating L2TPv3 link ${IFVAR}"
local l2tp_err s_name s_tunnel_id s_session_id s_peer_session_id 
s_cookie s_peer_cookie s_offset s_peer_offset s_l2spec_type
if ! _l2tp_eval_props s_ 
"name|tunnel_id|session_id|peer_session_id|cookie|peer_cookie|offset|peer_offset|l2spec_type"
 "${l2tpsession}"; then
eend 1 "l2tpsession_${IFVAR} syntax error: $l2tp_err"
@@ -157,7 +157,7 @@ l2tp_post_stop()
local session_id tunnel_id
_is_l2tp || return 0

-   ebegin "Destroying L2TP tunnel ${IFACE}"
+   ebegin "Destroying L2TPv3 link ${IFACE}"
veinfo ip l2tp del session tunnel_id $tunnel_id session_id $session_id
ip l2tp del session tunnel_id $tunnel_id session_id $session_id
if ! ip l2tp show session | grep -Eq "^Session [0-9]+ in tunnel 
$tunnel_id\$"; then



[gentoo-commits] proj/netifrc:master commit in: net/

2016-07-05 Thread Robin H. Johnson
commit: 4a8358aaf9c0048930194e0bbe3d2509d9da4fd0
Author: Emeric Verschuur  mbedsys  org>
AuthorDate: Sat Apr 23 20:17:55 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sat Apr 23 20:17:55 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=4a8358aa

Add L2TPv3 tunnel/session support to iproute2 module

Add L2TPv3 tunnel/session support to iproute2 module:

Example of config to add two L2TPv3 session/two interfaces with a shared tunnel:

l2tptunnel_net1="remote 1.2.3.4 local 1.2.3.5tunnel_id 3 peer_tunnel_id 3 encap 
ip"
l2tpsession_net1="tunnel_id 3 session_id 3 peer_session_id 3"
config_net1="null"

l2tptunnel_net2="remote 1.2.3.4 local 1.2.3.5 tunnel_id 3 peer_tunnel_id 3 
encap ip"
l2tpsession_net2="tunnel_id 3 session_id 4 peer_session_id 4"
config_net2="null"

 net/iproute2.sh | 45 +
 1 file changed, 45 insertions(+)

diff --git a/net/iproute2.sh b/net/iproute2.sh
index 0b2a8d6..825b9b1 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -318,6 +318,32 @@ iproute2_pre_start()
eend $? || return 1
_up
fi
+   
+   # L2TPv3
+   local l2tpsession=
+   eval l2tpsession=\$l2tpsession_${IFVAR}
+   if [ -n "${l2tpsession}" ]; then
+   ebegin "Creating L2TPv3 tunnel ${IFVAR}"
+   local l2tptunnel=
+   eval l2tptunnel=\$l2tptunnel_${IFVAR}
+   if [ -n "${l2tptunnel}" ]; then
+   local retcode
+   veinfo ip l2tp add tunnel ${l2tptunnel}
+   ip l2tp add tunnel ${l2tptunnel}
+   #a L2TPv3 tunnel can host several sessions (1 session 
<=> 1 interface)
+   #if $?=2 the tunnel id already exists, just ignore this 
error
+   #we assume that the existing one have the same property 
that we want to create...
+   if [ $? -ne 0 ] && [ $? -ne 2 ]; then
+   eend $? || return 1
+   fi
+   fi
+   veinfo ip l2tp add session ${l2tpsession} name "${IFACE}"
+   ip l2tp add session ${l2tpsession} name "${IFACE}"
+   if [ $? -ne 0 ] && [ $? -ne 2 ]; then
+   eend $? || return 1
+   fi
+   _up
+   fi
 
# MTU support
local mtu=
@@ -424,6 +450,25 @@ iproute2_post_stop()
ip tunnel del "${IFACE}"
eend $?
fi
+   local l2tptuple
+   # Searching for l2tp session associated to ${IFACE}
+   l2tptuple="$(ip l2tp show session | \
+   awk "match(\$0, /^Session ([0-9]+) in tunnel 
([0-9]+)\$/, ret) {sid=ret[1]; tid=ret[2]} 
+   match(\$0, /^[ ]*interface name: ${IFACE}\$/) 
{print sid\":\"tid; exit}")"
+   if [ -n "$l2tptuple" ]; then
+   local l2tpsession_id l2tptunnel_id
+   l2tpsession_id=${l2tptuple%:*}
+   l2tptunnel_id=${l2tptuple#*:}
+   ebegin "Destroying L2TPv3 tunnel ${IFACE}"
+   veinfo ip l2tp del session tunnel_id $l2tptunnel_id 
session_id $l2tpsession_id
+   ip l2tp del session tunnel_id $l2tptunnel_id session_id 
$l2tpsession_id
+   if [ -z "$(ip l2tp show session | grep -E "^Session 
[0-9]+ in tunnel $l2tptunnel_id\$")" ]; then
+   #tunnel $l2tptunnel_id no longer used, 
destoying it...
+   veinfo ip l2tp del tunnel tunnel_id 
$l2tptunnel_id
+   ip l2tp del tunnel tunnel_id $l2tptunnel_id
+   fi
+   eend $?
+   fi
fi
 }
 



[gentoo-commits] proj/netifrc:master commit in: net/

2016-07-05 Thread Robin H. Johnson
commit: d72fb7cc7fe42a0c54ed37fc6b33c5522661af8a
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Tue Jul  5 18:09:02 2016 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Tue Jul  5 18:09:11 2016 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=d72fb7cc

arping: one more path per bug #566142.

Bug: https://bugs.gentoo.org/566142
Signed-off-by: Robin H. Johnson  gentoo.org>

 net/arping.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/arping.sh b/net/arping.sh
index 65eb617..b03b8a9 100644
--- a/net/arping.sh
+++ b/net/arping.sh
@@ -3,7 +3,7 @@
 
 arping_depend()
 {
-   program /sbin/arping /bin/arping /usr/sbin/arping2
+   program /sbin/arping /bin/arping /usr/sbin/arping /usr/sbin/arping2
before interface
 }
 



[gentoo-commits] proj/netifrc:master commit in: net/

2015-11-08 Thread Robin H. Johnson
commit: a4fcc78c90893103d012ae1dc05a2a8f42d7cdaa
Author: Alon Bar-Lev  gentoo  org>
AuthorDate: Sat Nov  7 20:02:59 2015 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Nov  8 07:13:36 2015 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=a4fcc78c

net: bridge: add warning when using sysfs variables without prefix

Signed-off-by: Alon Bar-Lev  gentoo.org>

 net/bridge.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/bridge.sh b/net/bridge.sh
index 407b578..3dfd8b1 100644
--- a/net/bridge.sh
+++ b/net/bridge.sh
@@ -129,6 +129,7 @@ bridge_pre_start()
for prefix in "" bridge_; do
eval s=\$${prefix}${n}_${IFVAR}
if [ -n "${s}" ]; then
+   [ -z "${prefix}" ] && ewarn "sysfs key 
'${n}_${IFVAR}' should be prefixed, please add bridge_ prefix."
einfo "Setting ${n}: ${s}"
echo "${s}" >"${x}" || \
eerror "Failed to configure $n (${n}_${IFVAR})"
@@ -167,6 +168,7 @@ bridge_pre_start()
for prefix in "" brport_; do
eval s=\$${prefix}${n}_${IFVAR}
if [ -n "${s}" ]; then
+   [ -z "${prefix}" ] && ewarn 
"sysfs key '${n}_${IFVAR}' should be prefixed, please add brport_ prefix."
einfo "Setting ${n}@${IFACE}: 
${s}"
echo "${s}" >"${x}" || \
eerror "Failed to configure $n 
(${n}_${IFVAR})"



[gentoo-commits] proj/netifrc:master commit in: /, net/, doc/

2015-11-08 Thread Robin H. Johnson
commit: 2ce8b833812e5db9de7cf1543dd6499b4077db21
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Sun Nov  8 14:29:50 2015 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sun Nov  8 14:29:50 2015 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=2ce8b833

New interace type: HSR.

Signed-off-by: Robin H. Johnson  gentoo.org>

 TODO |  1 -
 doc/net.example.Linux.in |  6 ++
 net/hsr.sh   | 56 
 3 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/TODO b/TODO
index 64f62e2..023bbb4 100644
--- a/TODO
+++ b/TODO
@@ -12,7 +12,6 @@
- add vlan3 - _ifindex (eth0=0,vlan2=1,vlan3=2)
Now your routing table has entries for both vlan2 and vlan3 with a 
metric of 2.
 - Support many more device types easily:
-  - HSR: ip link add name hsr0 type hsr slave1 dummy3 slave2 dummy4
   - VXLAN: ip link add link dummy2 name vxlan199 type vxlan id 199 dev dummy2 
group 224.2.0.199 dstport 4789
   - IPVLAN: ...
   - IFB: ip link add ifb0 type ifb 

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index 1eaebac..6059301 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -159,6 +159,12 @@
 #
 # Dummy network interface:
 #type_dummy0=dummy
+#
+# HSR: High-availability Seamless Redundancy
+#type_hsr0=hsr
+#hsr_slave1=eth0
+#hsr_slave2=eth1
+#hsr_supervision=99 # Byte value
 
 #-
 # WIRELESS (802.11 support)

diff --git a/net/hsr.sh b/net/hsr.sh
new file mode 100644
index 000..94ecc01
--- /dev/null
+++ b/net/hsr.sh
@@ -0,0 +1,56 @@
+# Copyright (c) 2015 Gentoo Foundation
+# All rights reserved. Released under the 2-clause BSD license.
+
+hsr_depend()
+{
+   program ip
+   after interface
+   before dhcp macchanger
+}
+
+_is_hsr() {
+   is_interface_type hsr
+}
+
+hsr_pre_start()
+{
+   local hsr=
+   eval hsr=\$type_${IFVAR}
+   [ "${hsr}" = "hsr" ] || return 0
+   eval hsr_slave1=\$hsr_slave1_${IFVAR}
+   eval hsr_slave2=\$hsr_slave2_${IFVAR}
+   eval hsr_supervision=\$hsr_supervision_${IFVAR}
+   if [ -z "${hsr_slave1}" ] || [ -z "${hsr_slave2}" ]; then
+   eerror "HSR interfaces require two slave interfaces to be set"
+   return 1
+   fi
+   if ! ( IFACE=${hsr_slave1} _exists ); then
+   eerror "HSR slave1 ${hsr_slave1} does not exist"
+   return 1
+   fi
+   if ! ( IFACE=${hsr_slave2} _exists ); then
+   eerror "HSR slave2 ${hsr_slave2} does not exist"
+   return 1
+   fi
+
+   ebegin "Creating HSR interface ${IFACE}"
+   cmd="ip link add name "${IFACE}" type hsr slave1 ${hsr_slave1} slave2 
${hsr_slave2} ${hsr_supervision:+supervision }${hsr_supervision}"
+   veinfo $cmd
+   if $cmd ; then
+   eend 0 && _up && set_interface_type hsr
+   else
+   eend 1
+   fi
+}
+
+
+hsr_post_stop()
+{
+   _is_hsr || return 0
+
+   ebegin "Removing HSR ${IFACE}"
+   cmd="ip link delete "${IFACE}" type hsr"
+   veinfo "$cmd"
+   $cmd
+   eend $?
+}



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2015-11-08 Thread Robin H. Johnson
commit: 734e527dbe32fc3c0abdd326c485a6e69d8646f2
Author: Alon Bar-Lev  gentoo  org>
AuthorDate: Sat Nov  7 20:02:59 2015 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sat Nov  7 20:18:02 2015 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=734e527d

net: bridge: add bridge_ and brport_ prefixes to sysfs interface

keep the no prefix to be backward compatible.

Signed-off-by: Alon Bar-Lev  gentoo.org>

 doc/net.example.Linux.in |  6 +++---
 net/bridge.sh| 29 +
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index bcf3311..f71385d 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -919,9 +919,9 @@
 # You can also configure the bridge or bridge members via sysfs on 2.6 kernels
 # or newer. See the kernel bridge documentation for a description of these
 # options.
-#stp_state_br0="0"
-#forward_delay_br0="10"
-#hairpin_mode_eth0="1"
+#bridge_stp_state_br0="0"
+#bridge_forward_delay_br0="10"
+#brport_hairpin_mode_eth0="1"
 
 #-
 # RFC 2684 Bridge Support

diff --git a/net/bridge.sh b/net/bridge.sh
index 82abb71..407b578 100644
--- a/net/bridge.sh
+++ b/net/bridge.sh
@@ -125,12 +125,15 @@ bridge_pre_start()
for x in /sys/class/net/"${IFACE}"/bridge/*; do
[ -f "${x}" ] || continue
n=${x##*/}
-   eval s=\$${n}_${IFVAR}
-   if [ -n "${s}" ]; then
-   einfo "Setting ${n}: ${s}"
-   echo "${s}" >"${x}" || \
-   eerror "Failed to configure $n (${n}_${IFVAR})"
-   fi
+   # keep no prefix for backward compatibility
+   for prefix in "" bridge_; do
+   eval s=\$${prefix}${n}_${IFVAR}
+   if [ -n "${s}" ]; then
+   einfo "Setting ${n}: ${s}"
+   echo "${s}" >"${x}" || \
+   eerror "Failed to configure $n (${n}_${IFVAR})"
+   fi
+   done
done
 
if [ -n "${ports}" ]; then
@@ -161,12 +164,14 @@ bridge_pre_start()
for x in /sys/class/net/"${IFACE}"/brport/*; do
[ -f "${x}" ] || continue
n=${x##*/}
-   eval s=\$${n}_${IFVAR}
-   if [ -n "${s}" ]; then
-   einfo "Setting ${n}@${IFACE}: ${s}"
-   echo "${s}" >"${x}" || \
-   eerror "Failed to configure $n 
(${n}_${IFVAR})"
-   fi
+   for prefix in "" brport_; do
+   eval s=\$${prefix}${n}_${IFVAR}
+   if [ -n "${s}" ]; then
+   einfo "Setting ${n}@${IFACE}: 
${s}"
+   echo "${s}" >"${x}" || \
+   eerror "Failed to configure $n 
(${n}_${IFVAR})"
+   fi
+   done
done
eend 0
done



[gentoo-commits] proj/netifrc:master commit in: net/, doc/

2015-11-08 Thread Robin H. Johnson
commit: 193803506202d0d37996ee81388215cfe3fc8cda
Author: Alon Bar-Lev  gentoo  org>
AuthorDate: Sat Nov  7 20:02:43 2015 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Sat Nov  7 20:02:43 2015 +
URL:https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=19380350

net: bridge: support iproute2

add bridge_force_IFVAR to be interface independent.

mark the brctl_IFVAR as deprecated.

enable easy removal of brctl in future in favour of the iproute2 without
leaving legacy.

Signed-off-by: Alon Bar-Lev  gentoo.org>

 doc/net.example.Linux.in |  1 +
 net/bridge.sh| 75 
 2 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index b91bb50..bcf3311 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -893,6 +893,7 @@
 # ports to it you must set at least one of the following variables based on the
 # interface name, so that we can pick it up from your configuration. Even an
 # empty value variable is fine, but at least one of them must be set:
+# bridge_force_IFVAR
 # brctl_IFVAR
 
 # You need to configure the ports to null values so dhcp does not get started

diff --git a/net/bridge.sh b/net/bridge.sh
index 1d01be2..82abb71 100644
--- a/net/bridge.sh
+++ b/net/bridge.sh
@@ -4,7 +4,7 @@
 bridge_depend()
 {
before interface macnet
-   program brctl
+   program brctl ip
 }
 
 _config_vars="$_config_vars bridge bridge_add brctl"
@@ -35,17 +35,27 @@ bridge_pre_start()
# ports is for static add
local ports="$(_get_array "bridge_${IFVAR}")"
# old config options
-   local opts="$(_get_array "brctl_${IFVAR}")"
+   local brctl_opts="$(_get_array "brctl_${IFVAR}")"
# brif is used for dynamic add
eval brif=\$bridge_add_${IFVAR}
 
+   local do_iproute2=false do_brctl=false
+   if [ -n "${brctl_opts}" ] && type brctl >/dev/null 2>&1; then
+   do_brctl=true
+   elif type ip >/dev/null 2>&1; then
+   do_iproute2=true
+   elif type brctl >/dev/null 2>&1; then
+   do_brctl=true
+   fi
+
# we need a way to if the bridge exists in a variable name, not just the
# contents of a variable. Eg if somebody has only bridge_add_eth0='br0',
# with no other lines mentioning br0.
eval bridge_unset=\${bridge_${IFVAR}-y\}
eval brctl_unset=\${brctl_${IFVAR}-y\}
+   eval bridge_force_unset=\${bridge_force_${IFVAR}-y\}
 
-   if [ -z "${brif}" -a "${brctl_unset}" = 'y' ]; then
+   if [ -z "${brif}" -a "${brctl_unset}${bridge_force_unset}" = 'yy' ]; 
then
if [ -z "${ports}" -a "${bridge_unset}" = "y" ]; then
#eerror "Misconfigured static bridge detected (see 
net.example)"
return 0
@@ -70,7 +80,18 @@ bridge_pre_start()
 
if ! _is_bridge ; then
ebegin "Creating bridge ${IFACE}"
-   if ! brctl addbr "${IFACE}"; then
+   if ${do_iproute2}; then
+   ip link add "${IFACE}" type bridge
+   rc=$?
+   elif ${do_brctl}; then
+   brctl addbr "${IFACE}"
+   rc=$?
+   else
+   eerror "Neither iproute2 nor brctl has been found, 
please install"
+   eerror "either \"iproute2\" or \"brctl\"."
+   rc=1
+   fi
+   if [ ${rc} != 0 ]; then
eend 1
return 1
fi
@@ -82,19 +103,22 @@ bridge_pre_start()
# Old configuration set mechanism
# Only a very limited subset of the options are available in the old
# configuration method. The sysfs interface is in the next block 
instead.
-   if [ -n "${opts}" ]; then
-   ewarn "brctl options are deprecated please migrate to sysfs 
options"
-   ewarn "map of important options is available at 
https://wiki.gentoo.org/wiki/Netifrc/Brctl_Migration;
-   local IFS="$__IFS"
-   for x in ${opts}; do
+   if ${do_brctl}; then
+   if [ -n "${brctl_opts}" ]; then
+   ewarn "brctl options are deprecated please migrate to 
sysfs options"
+   ewarn "map of important options is available at 
https://wiki.gentoo.org/wiki/Netifrc/Brctl_Migration;
+
+   local IFS="$__IFS"
+   for x in ${brctl_opts}; do
+   unset IFS
+   set -- ${x}
+   x=$1
+   shift
+   set -- "${x}" "${IFACE}" "$@"
+   brctl "$@"
+   done
unset IFS
-   set -- ${x}
-   x=$1

  1   2   >