From patchwork Fri Nov 8 09:42:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11234457 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 5E39D14E5 for ; Fri, 8 Nov 2019 09:44:16 +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 42FB7214DA for ; Fri, 8 Nov 2019 09:44:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42FB7214DA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org 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 1iT0mu-0008PM-P5; Fri, 08 Nov 2019 09:42:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iT0mu-0008PD-4S for xen-devel@lists.xenproject.org; Fri, 08 Nov 2019 09:42:40 +0000 X-Inumbo-ID: 19a45626-020c-11ea-a1d4-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 19a45626-020c-11ea-a1d4-12813bfff9fa; Fri, 08 Nov 2019 09:42:39 +0000 (UTC) IronPort-SDR: c2+iSJP095cRiIFGgpcEtwz2UYD462FrtmXZzGTQAU8QTxUpJpxDMk10uKq7pRicSyzwzkMNsZ aQzuZf+LQVSw== X-IronPort-AV: E=Sophos;i="5.68,281,1569283200"; d="scan'208";a="5159278" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-859fe132.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 08 Nov 2019 09:42:39 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-859fe132.us-west-2.amazon.com (Postfix) with ESMTPS id 4982C222A05; Fri, 8 Nov 2019 09:42:38 +0000 (UTC) Received: from EX13D32EUC002.ant.amazon.com (10.43.164.94) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 8 Nov 2019 09:42:37 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D32EUC002.ant.amazon.com (10.43.164.94) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 8 Nov 2019 09:42:36 +0000 Received: from u55d8f79c258451.ant.amazon.com (10.125.106.130) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 8 Nov 2019 09:42:35 +0000 From: To: Date: Fri, 8 Nov 2019 09:42:33 +0000 Message-ID: <1573206153-22090-1-git-send-email-paul@xen.org> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v3] tools/hotpug: only attempt to call 'ip route' if there is valid command X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Paul Durrant , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Durrant The vif-route script should only call 'ip route' when 'ipcmd' has been set, otherwise it will fail due to an incorrect command string. This patch also adds routes for 'tap' (i.e. emulated) devices as well as 'vif' (i.e. PV) devices. Empirically offline/online commands relate to 'vif' devices, and add/remove commands relate to 'tap' devices. However, this patch treats them equally and uses ${type_if} to distinguish. By adding cases for add/remove the command list becomes exhaustive and hence 'ipcmd' is guaranteed to be set. Routes for 'tap' and 'vif' devices are distinguished by a route metric. Emulated devices are used by HVM guests until they are unplugged, at which point the PV device becomes active. Thus 'tap' devices should get a higher priority (i.e. lower numbered) metric than 'vif' devices. There is also one small whitespace fix. Signed-off-by: Paul Durrant Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu v3: - Fix Wei's email address - Removed test of ${ipcmd} v2: - Added routes for 'tap' devices - Whitespace fix --- tools/hotplug/Linux/vif-route | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) mode change 100644 => 100755 tools/hotplug/Linux/vif-route diff --git a/tools/hotplug/Linux/vif-route b/tools/hotplug/Linux/vif-route old mode 100644 new mode 100755 index c149ffc..05199bf --- a/tools/hotplug/Linux/vif-route +++ b/tools/hotplug/Linux/vif-route @@ -22,12 +22,16 @@ dir=$(dirname "$0") main_ip=$(dom0_ip) case "${command}" in + add) + ;& online) ifconfig ${dev} ${main_ip} netmask 255.255.255.255 up echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp ipcmd='add' cmdprefix='' ;; + remove) + ;& offline) do_without_error ifdown ${dev} ipcmd='del' @@ -35,13 +39,23 @@ case "${command}" in ;; esac -if [ "${ip}" ] ; then - # If we've been given a list of IP addresses, then add routes from dom0 to - # the guest using those addresses. - for addr in ${ip} ; do - ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} - done -fi +case "${type_if}" in + tap) + metric=1 + ;; + vif) + metric=2 + ;; + *) + fatal "Unrecognised interface type ${type_if}" + ;; +esac + +# If we've been given a list of IP addresses, then add routes from dom0 to +# the guest using those addresses. +for addr in ${ip} ; do + ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} metric ${metric} +done handle_iptable @@ -50,5 +64,5 @@ call_hooks vif post log debug "Successful vif-route ${command} for ${dev}." if [ "${command}" = "online" ] then - success + success fi