From patchwork Wed Dec 18 01:15:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Haigh X-Patchwork-Id: 11299249 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46F1C13B6 for ; Wed, 18 Dec 2019 01:16:47 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22E292176D for ; Wed, 18 Dec 2019 01:16:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=crc.id.au header.i=@crc.id.au header.b="GNRqouep" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22E292176D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=crc.id.au Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihNw8-0004Km-Jj; Wed, 18 Dec 2019 01:15:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihNw7-0004Kh-M8 for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 01:15:35 +0000 X-Inumbo-ID: e1fdfe4a-2133-11ea-b6f1-bc764e2007e4 Received: from mail.crc.id.au (unknown [2407:e400:b000:200::25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e1fdfe4a-2133-11ea-b6f1-bc764e2007e4; Wed, 18 Dec 2019 01:15:33 +0000 (UTC) Received: from wopr.lan.crc.id.au (unknown [IPv6:2407:e400:b000:200:687b:c909:9c42:5397]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mail.crc.id.au (Postfix) with ESMTPSA id A0B99200115; Wed, 18 Dec 2019 12:15:29 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crc.id.au; s=default; t=1576631729; bh=rUti8ggZ6lNzDMXYxMQRG4Tftf8gAafYwNgXYNNDf4E=; h=From:To:Cc:Subject:Date; b=GNRqouep6I3KgiVwYa8V1dSu9D+AXmqZOwUR03frdpO6GoFHzUhzheAN6sRe1x/9s mPVx8eG6bXgrzrakDTZNZp0jyBn6qwVE6BR5a3i2udWi2asA05rgsiNiTg96U2dtWs puPj75pYbXd5GN7lm0DzQTObgvxqQ9UPQYJ8aCEw= From: Steven Haigh To: xen-devel@lists.xenproject.org Date: Wed, 18 Dec 2019 12:15:23 +1100 Message-Id: <35b942031521f25b63e60634ee86f1b52f504eb3.1576631444.git.netwiz@crc.id.au> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] [tools/hotplug] Use ip on systems where brctl is not available X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Steven Haigh , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Newer distros like CentOS 8 do not have brctl available. As such, we can't use it to configure networking anymore. This patch will fall back to 'ip' or 'bridge' commands if brctl is not available in the working PATH. This would be a likely backport candidate to any version expected to be built on CentOS 8 etc. Acked-by: Wei Liu --- tools/hotplug/Linux/colo-proxy-setup | 30 +++++++++++++++++------ tools/hotplug/Linux/vif-bridge | 16 ++++++++---- tools/hotplug/Linux/vif2 | 12 +++++++-- tools/hotplug/Linux/xen-network-common.sh | 16 +++++++++--- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/tools/hotplug/Linux/colo-proxy-setup b/tools/hotplug/Linux/colo-proxy-setup index 94e2034452..d709146c47 100755 --- a/tools/hotplug/Linux/colo-proxy-setup +++ b/tools/hotplug/Linux/colo-proxy-setup @@ -76,10 +76,17 @@ function teardown_primary() function setup_secondary() { - do_without_error brctl delif $bridge $vifname - do_without_error brctl addbr $forwardbr - do_without_error brctl addif $forwardbr $vifname - do_without_error brctl addif $forwardbr $forwarddev + if which brctl >&/dev/null; then + do_without_error brctl delif $bridge $vifname + do_without_error brctl addbr $forwardbr + do_without_error brctl addif $forwardbr $vifname + do_without_error brctl addif $forwardbr $forwarddev + else + do_without_error ip link set $vifname nomaster + do_without_error ip link add name $forwardbr type bridge + do_without_error ip link set $vifname master $forwardbr + do_without_error ip link set $forwarddev master $forwardbr + fi do_without_error ip link set dev $forwardbr up do_without_error modprobe xt_SECCOLO @@ -91,10 +98,17 @@ function setup_secondary() function teardown_secondary() { - do_without_error brctl delif $forwardbr $forwarddev - do_without_error brctl delif $forwardbr $vifname - do_without_error brctl delbr $forwardbr - do_without_error brctl addif $bridge $vifname + if which brctl >&/dev/null; then + do_without_error brctl delif $forwardbr $forwarddev + do_without_error brctl delif $forwardbr $vifname + do_without_error brctl delbr $forwardbr + do_without_error brctl addif $bridge $vifname + else + do_without_error ip link set $forwarddev nomaster + do_without_error ip link set $vifname nomaster + do_without_error ip link delete $forwardbr type bridge + do_without_error ip link set $vifname master $bridge + fi do_without_error iptables -t mangle -D PREROUTING -m physdev --physdev-in \ $vifname -j SECCOLO --index $index diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge index 6956dea66a..e722090ca8 100644 --- a/tools/hotplug/Linux/vif-bridge +++ b/tools/hotplug/Linux/vif-bridge @@ -31,10 +31,12 @@ dir=$(dirname "$0") bridge=${bridge:-} bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge") -if [ -z "$bridge" ] -then - bridge=$(brctl show | awk 'NR==2{print$1}') - +if [ -z "$bridge" ]; then + if which brctl >&/dev/null; then + bridge=$(brctl show | awk 'NR==2{print$1}') + else + bridge=$(bridge link | cut -d" " -f7) + fi if [ -z "$bridge" ] then fatal "Could not find bridge, and none was specified" @@ -82,7 +84,11 @@ case "$command" in ;; offline) - do_without_error brctl delif "$bridge" "$dev" + if which brctl >&/dev/null; then + do_without_error brctl delif "$bridge" "$dev" + else + do_without_error ip link set "$dev" nomaster + fi do_without_error ifconfig "$dev" down ;; diff --git a/tools/hotplug/Linux/vif2 b/tools/hotplug/Linux/vif2 index 2c155be68c..5bd555c6f0 100644 --- a/tools/hotplug/Linux/vif2 +++ b/tools/hotplug/Linux/vif2 @@ -7,13 +7,21 @@ dir=$(dirname "$0") bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge") if [ -z "$bridge" ] then - nr_bridges=$(($(brctl show | cut -f 1 | grep -v "^$" | wc -l) - 1)) + if which brctl >&/dev/null; then + nr_bridges=$(($(brctl show | cut -f 1 | grep -v "^$" | wc -l) - 1)) + else + nr_bridges=$(bridge link | wc -l) + fi if [ "$nr_bridges" != 1 ] then fatal "no bridge specified, and don't know which one to use ($nr_bridges found)" fi - bridge=$(brctl show | cut -d " + if which brctl >&/dev/null; then + bridge=$(brctl show | cut -d " " -f 2 | cut -f 1) + else + bridge=$(bridge link | cut -d" " -f6) + fi fi command="$1" diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh index 92ffa603f7..8dd3a62068 100644 --- a/tools/hotplug/Linux/xen-network-common.sh +++ b/tools/hotplug/Linux/xen-network-common.sh @@ -111,9 +111,13 @@ create_bridge () { # Don't create the bridge if it already exists. if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then - brctl addbr ${bridge} - brctl stp ${bridge} off - brctl setfd ${bridge} 0 + if which brctl >&/dev/null; then + brctl addbr ${bridge} + brctl stp ${bridge} off + brctl setfd ${bridge} 0 + else + ip link add name ${bridge} type bridge stp_state 0 forward_delay 0 + fi fi } @@ -127,7 +131,11 @@ add_to_bridge () { ip link set dev ${dev} up || true return fi - brctl addif ${bridge} ${dev} + if which brctl >&/dev/null; then + brctl addif ${bridge} ${dev} + else + ip link set ${dev} master ${bridge} + fi ip link set dev ${dev} up }