From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 798531382C5 for ; Thu, 11 Mar 2021 16:54:25 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A1709E086A; Thu, 11 Mar 2021 16:54:24 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 879EFE086A for ; Thu, 11 Mar 2021 16:54:24 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 14E7F335C9F for ; Thu, 11 Mar 2021 16:54:23 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B8F71591 for ; Thu, 11 Mar 2021 16:54:21 +0000 (UTC) From: "Lars Wendler" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Lars Wendler" Message-ID: <1615481613.b581c3f76b95bd2173a13d08054120f284ac06e7.polynomial-c@OpenRC> Subject: [gentoo-commits] proj/netifrc:master commit in: net/ X-VCS-Repository: proj/netifrc X-VCS-Files: net/bridge.sh X-VCS-Directories: net/ X-VCS-Committer: polynomial-c X-VCS-Committer-Name: Lars Wendler X-VCS-Revision: b581c3f76b95bd2173a13d08054120f284ac06e7 X-VCS-Branch: master Date: Thu, 11 Mar 2021 16:54:21 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 3c824267-4641-4ac0-b2fc-9a944c9ab92c X-Archives-Hash: 7624a5ff860850bd116f9c945564d6ab commit: b581c3f76b95bd2173a13d08054120f284ac06e7 Author: Patrick McLean gentoo org> AuthorDate: Sat Nov 21 06:53:31 2020 +0000 Commit: Lars Wendler gentoo org> CommitDate: Thu Mar 11 16:53:33 2021 +0000 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 ${brport_dir}/bridge) iface=${iface##*/} [ -z "${iface}" ] && return 0 extra=" from ${iface}" @@ -218,7 +218,7 @@ bridge_post_stop() local IFACE="${port}" _set_flag -promisc if type ip > /dev/null 2>&1; then - ip link set "${port}" nomaster + _netns ip link set "${port}" nomaster else brctl delif "${iface}" "${port}" fi @@ -228,7 +228,7 @@ bridge_post_stop() if ${delete}; then eoutdent if type ip > /dev/null 2>&1; then - ip link del "${iface}" + _netns ip link del "${iface}" else brctl delbr "${iface}" fi