From nobody Fri Apr 26 03:37:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605595751; cv=none; d=zohomail.com; s=zohoarc; b=hs9la4CexBiMjWdqfdxME3OYX7daSAscU2jY9A/d9A6acXyW8c88YoXwuzcivJa3hIZtvkWAdVhi3kWNGwHRQr3+salEFtc3/OqP7TG+umRLTuGIUNloMI1iMZAlIdURMxWX+BkgmLargecY2u1hycMlaMPv7YHt8UCdAAQT5ws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605595751; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YIsUgQBOxY1j94iG7u4wFvocUyO57PBgyeXmh2wT1rU=; b=IrwbOsajX/Wp2wLq2mqiVTplJP5kfyyv80Lo7jMeO5Yf8E3xALMts1TSlx7e1+75RmDESVaSfw29/phLE9g9+fIXXc3emjI25nVObFyqGiNKmIrHE8Si3dxFfU4UTnqukMd0IH0mb51uxZHU4FnqpUNUnHamuf4EUSHcgSQ9AKQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605595751456189.51575587056573; Mon, 16 Nov 2020 22:49:11 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-lf7WCgB3MrqyWHCKZH9YHQ-1; Tue, 17 Nov 2020 01:49:08 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD2C9100747C; Tue, 17 Nov 2020 06:49:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B413A10013D7; Tue, 17 Nov 2020 06:49:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 63C8318005A3; Tue, 17 Nov 2020 06:49:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AH6n16q022829 for ; Tue, 17 Nov 2020 01:49:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB4EF86D84; Tue, 17 Nov 2020 06:49:01 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A2673906D6 for ; Tue, 17 Nov 2020 06:48:57 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 762521021E15 for ; Tue, 17 Nov 2020 06:48:57 +0000 (UTC) Received: from m97136.mail.qiye.163.com (m97136.mail.qiye.163.com [220.181.97.136]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-pNje-JE2MeSrftnXoKRRAA-1; Tue, 17 Nov 2020 01:48:53 -0500 Received: from localhost.localdomain (unknown [113.128.197.238]) by smtp2 (Coremail) with SMTP id iOCowADnFfBEcrNfsLvPCQ--.4067S3; Tue, 17 Nov 2020 14:48:45 +0800 (CST) X-MC-Unique: lf7WCgB3MrqyWHCKZH9YHQ-1 X-MC-Unique: pNje-JE2MeSrftnXoKRRAA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [PATCH 1/2] util:netlink: Enable virNetlinkNewLink to support veth Date: Tue, 17 Nov 2020 14:48:26 +0800 Message-Id: <20201117064827.53286-2-shi_lei@massclouds.com> In-Reply-To: <20201117064827.53286-1-shi_lei@massclouds.com> References: <20201117064827.53286-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: iOCowADnFfBEcrNfsLvPCQ--.4067S3 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjfUJnIDDUUUU X-Originating-IP: [113.128.197.238] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiQg3fT1bdHTSBqwAAsX X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Shi Lei X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Shi Lei --- src/util/virnetlink.c | 25 +++++++++++++++++++++++++ src/util/virnetlink.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index fdd3a6a4..e191f63b 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -41,6 +41,18 @@ VIR_LOG_INIT("util.netlink"); #define NETLINK_ACK_TIMEOUT_S (2*1000) =20 #if defined(WITH_LIBNL) + +/* + * VETH_INFO_PEER is defined in libnl, but it isn't exposed. + * We include it just like what iproute2 has done. + */ +enum { + VETH_INFO_UNSPEC, + VETH_INFO_PEER, + + __VETH_INFO_MAX +}; + /* State for a single netlink event handle */ struct virNetlinkEventHandle { int watch; @@ -535,6 +547,19 @@ virNetlinkNewLink(const char *ifname, NETLINK_MSG_NEST_END(nl_msg, infodata); } =20 + if (STREQ(type, "veth") && extra_args && extra_args->veth_peer) { + struct nlattr *infoveth =3D NULL; + + NETLINK_MSG_NEST_START(nl_msg, infodata, IFLA_INFO_DATA); + NETLINK_MSG_NEST_START(nl_msg, infoveth, VETH_INFO_PEER); + nlmsg_reserve(nl_msg, sizeof(struct ifinfomsg), 0); + NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, + (strlen(extra_args->veth_peer) + 1), + extra_args->veth_peer); + NETLINK_MSG_NEST_END(nl_msg, infoveth); + NETLINK_MSG_NEST_END(nl_msg, infodata); + } + NETLINK_MSG_NEST_END(nl_msg, linkinfo); =20 if (extra_args) { diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index 7121eac4..7c4ed202 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -84,6 +84,7 @@ struct _virNetlinkNewLinkData { const int *ifindex; /* The index for the 'link' device */ const virMacAddr *mac; /* The MAC address of the device */ const uint32_t *macvlan_mode; /* The mode of macvlan */ + const char *veth_peer; /* The peer name for veth */ }; =20 int virNetlinkNewLink(const char *ifname, --=20 2.25.1 From nobody Fri Apr 26 03:37:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605595804; cv=none; d=zohomail.com; s=zohoarc; b=f9+oYYD80hLC4w56egKn9c0cpRddi5Z6eVfXWbelXNE2NnO+4fXHGZ+JQIoYSNJubVCGOVZt965DmDGtwtaCDZrkEerZzSunVW5aJwZdgu/UMGqq6MgDCRNTiMol9yOgNOGcvmBnOa2HrmC9+grDSloRYVvZf3Xe8+UOZwM8kMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605595804; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0SYkGjFwbJ5WB89I/1KjJq07vuSUdFZGqBusJgdU9AI=; b=JGClh4SwUWFJ7iikhP456E7Hrg4908oabImQXRCyKKesdHZnGMSVUgG6hbi//AFuiTRrwB15KMmI0GWamgdQ8MnUxtr03ElZuT47VV23n82VVV2v7Als9nLF0VWXru4+yclo78XaFoDfoX9NebL+omJ6XWgK9VTYX0Wi05pobK4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605595804130823.4814045024399; Mon, 16 Nov 2020 22:50:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-eqcJIUMcPi6843Dknrp0XA-1; Tue, 17 Nov 2020 01:49:30 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B46480EFBF; Tue, 17 Nov 2020 06:49:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1901651512; Tue, 17 Nov 2020 06:49:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D1F93180B791; Tue, 17 Nov 2020 06:49:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AH6muOo022815 for ; Tue, 17 Nov 2020 01:48:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id B4DCB2166BA0; Tue, 17 Nov 2020 06:48:56 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFD9F2166B44 for ; Tue, 17 Nov 2020 06:48:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9706C800183 for ; Tue, 17 Nov 2020 06:48:56 +0000 (UTC) Received: from m97136.mail.qiye.163.com (m97136.mail.qiye.163.com [220.181.97.136]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-F-ppj70FPBaq4IXRPepBFw-1; Tue, 17 Nov 2020 01:48:52 -0500 Received: from localhost.localdomain (unknown [113.128.197.238]) by smtp2 (Coremail) with SMTP id iOCowADnFfBEcrNfsLvPCQ--.4067S4; Tue, 17 Nov 2020 14:48:47 +0800 (CST) X-MC-Unique: eqcJIUMcPi6843Dknrp0XA-1 X-MC-Unique: F-ppj70FPBaq4IXRPepBFw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [PATCH 2/2] util:veth: Create veth device pair by netlink Date: Tue, 17 Nov 2020 14:48:27 +0800 Message-Id: <20201117064827.53286-3-shi_lei@massclouds.com> In-Reply-To: <20201117064827.53286-1-shi_lei@massclouds.com> References: <20201117064827.53286-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: iOCowADnFfBEcrNfsLvPCQ--.4067S4 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjfUJov3UUUUU X-Originating-IP: [113.128.197.238] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiHw-fT1uyHgm3PgAAs3 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Shi Lei X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When netlink is supported, use netlink to create veth device pair rather than 'ip link' command. Signed-off-by: Shi Lei --- src/util/virnetdevveth.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index b3eee1af..996bf5dd 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -27,6 +27,7 @@ #include "virfile.h" #include "virstring.h" #include "virnetdev.h" +#include "virnetlink.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -116,7 +117,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) for (i =3D 0; i < MAX_VETH_RETRIES; i++) { g_autofree char *veth1auto =3D NULL; g_autofree char *veth2auto =3D NULL; - g_autoptr(virCommand) cmd =3D NULL; =20 int status; if (!*veth1) { @@ -136,15 +136,32 @@ int virNetDevVethCreate(char** veth1, char** veth2) vethNum =3D veth2num + 1; } =20 - cmd =3D virCommandNew("ip"); - virCommandAddArgList(cmd, "link", "add", - *veth1 ? *veth1 : veth1auto, - "type", "veth", "peer", "name", - *veth2 ? *veth2 : veth2auto, - NULL); +#if defined(WITH_LIBNL) + { + int error =3D 0; + virNetlinkNewLinkData data =3D { + .veth_peer =3D *veth2 ? *veth2 : veth2auto, + }; =20 - if (virCommandRun(cmd, &status) < 0) - goto cleanup; + status =3D virNetlinkNewLink(*veth1 ? *veth1 : veth1auto, + "veth", &data, &error); + if (status < 0) + goto cleanup; + } +#else + { + g_autoptr(virCommand) cmd =3D NULL; + cmd =3D virCommandNew("ip"); + virCommandAddArgList(cmd, "link", "add", + *veth1 ? *veth1 : veth1auto, + "type", "veth", "peer", "name", + *veth2 ? *veth2 : veth2auto, + NULL); + + if (virCommandRun(cmd, &status) < 0) + goto cleanup; + } +#endif /* WITH_LIBNL */ =20 if (status =3D=3D 0) { if (veth1auto) { @@ -188,6 +205,9 @@ int virNetDevVethCreate(char** veth1, char** veth2) */ int virNetDevVethDelete(const char *veth) { +#if defined(WITH_LIBNL) + return virNetlinkDelLink(veth, NULL); +#else int status; g_autoptr(virCommand) cmd =3D virCommandNewArgList("ip", "link", "del", veth, NULL); @@ -206,4 +226,5 @@ int virNetDevVethDelete(const char *veth) } =20 return 0; +#endif /* WITH_LIBNL */ } --=20 2.25.1