From nobody Mon Feb 9 08:29:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542411172050303.6918591165039; Fri, 16 Nov 2018 15:32:52 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 702A483F3E; Fri, 16 Nov 2018 23:32:49 +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 3EA0519C7E; Fri, 16 Nov 2018 23:32:49 +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 EA4A11808872; Fri, 16 Nov 2018 23:32:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wAGMQkuQ006489 for ; Fri, 16 Nov 2018 17:26:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id D00305D717; Fri, 16 Nov 2018 22:26:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6D745D6B3 for ; Fri, 16 Nov 2018 22:26:43 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B164A4E916 for ; Fri, 16 Nov 2018 22:26:41 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Fri, 16 Nov 2018 15:26:37 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Fri, 16 Nov 2018 15:26:27 -0700 Message-Id: <20181116222628.8425-3-jfehlig@suse.com> In-Reply-To: <20181116222628.8425-1-jfehlig@suse.com> References: <20181116222628.8425-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 16 Nov 2018 22:26:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 16 Nov 2018 22:26:42 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] xenconfig: add support for openvswitch configuration 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 16 Nov 2018 23:32:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add support for converting openvswitch interface configuration to/from libvirt domXML and xl.cfg(5). The xl config syntax for virtual interfaces is described in detail in the xl-network-configuration(5) man page. The Xen Networking wiki also contains information and examples for using openvswitch in xl.cfg config format https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch Tests are added to check conversions of openvswitch tagged and trunked VLAN configuration. Signed-off-by: Jim Fehlig --- src/xenconfig/xen_common.c | 113 +++++++++++++++++- .../test-fullvirt-ovswitch-tagged.cfg | 25 ++++ .../test-fullvirt-ovswitch-tagged.xml | 50 ++++++++ .../test-fullvirt-ovswitch-trunked.cfg | 25 ++++ .../test-fullvirt-ovswitch-trunked.xml | 51 ++++++++ tests/xlconfigtest.c | 2 + 6 files changed, 262 insertions(+), 4 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 0a9958711f..5390b933e0 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -856,6 +856,84 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, = const char *nativeFormat) } =20 =20 +static int +xenParseVifBridge(virDomainNetDefPtr net, char *bridge) +{ + char *vlanstr; + unsigned int tag; + + /* 'bridge' string contains a bridge name and single vlan tag */ + vlanstr =3D strchr(bridge, '.'); + if (vlanstr) { + if (VIR_STRNDUP(net->data.bridge.brname, bridge, vlanstr - bridge)= < 0) + return -1; + + vlanstr++; + if (virStrToLong_ui(vlanstr, NULL, 10, &tag) < 0) + return -1; + + if (VIR_ALLOC_N(net->vlan.tag, 1) < 0) + return -1; + + net->vlan.tag[0] =3D tag; + net->vlan.nTags =3D 1; + + if (VIR_ALLOC(net->virtPortProfile) < 0) + return -1; + + net->virtPortProfile->virtPortType =3D VIR_NETDEV_VPORT_PROFILE_OP= ENVSWITCH; + return 0; + } + + /* 'bridge' string contains a bridge name and one or more vlan trunks = */ + vlanstr =3D strchr(bridge, ':'); + if (vlanstr) { + size_t i; + size_t nvlans =3D 0; + char **vlanstr_list =3D virStringSplit(bridge, ":", 0); + + if (!vlanstr_list) + return -1; + + if (VIR_STRDUP(net->data.bridge.brname, vlanstr_list[0]) < 0) { + virStringListFree(vlanstr_list); + return -1; + } + + for (i =3D 1; vlanstr_list[i]; i++) + nvlans++; + + if (VIR_ALLOC_N(net->vlan.tag, nvlans) < 0) { + virStringListFree(vlanstr_list); + return -1; + } + + for (i =3D 1; i <=3D nvlans; i++) { + if (virStrToLong_ui(vlanstr_list[i], NULL, 10, &tag) < 0) { + virStringListFree(vlanstr_list); + return -1; + } + net->vlan.tag[i - 1] =3D tag; + } + net->vlan.nTags =3D nvlans; + net->vlan.trunk =3D true; + virStringListFree(vlanstr_list); + + if (VIR_ALLOC(net->virtPortProfile) < 0) + return -1; + + net->virtPortProfile->virtPortType =3D VIR_NETDEV_VPORT_PROFILE_OP= ENVSWITCH; + return 0; + } + + /* 'bridge' string only contains the bridge name */ + if (VIR_STRDUP(net->data.bridge.brname, bridge) < 0) + return -1; + + return 0; +} + + static virDomainNetDefPtr xenParseVif(char *entry, const char *vif_typename) { @@ -974,8 +1052,8 @@ xenParseVif(char *entry, const char *vif_typename) net->type =3D VIR_DOMAIN_NET_TYPE_ETHERNET; } =20 - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) { - if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && bridge[0]) { + if (xenParseVifBridge(net, bridge) < 0) goto cleanup; } if (ip[0]) { @@ -1249,14 +1327,41 @@ xenFormatNet(virConnectPtr conn, =20 switch (net->type) { case VIR_DOMAIN_NET_TYPE_BRIDGE: + { + virNetDevVPortProfilePtr port_profile =3D virDomainNetGetActualVir= tPortProfile(net); + virNetDevVlanPtr virt_vlan =3D virDomainNetGetActualVlan(net); + const char *script =3D net->script; + size_t i; + virBufferAsprintf(&buf, ",bridge=3D%s", net->data.bridge.brname); + if (port_profile && + port_profile->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFILE_OPE= NVSWITCH) { + if (!script) + script =3D "vif-openvswitch"; + /* + * libxl_device_nic->bridge supports an extended format for + * specifying VLAN tags and trunks + * + * BRIDGE_NAME[.VLAN][:TRUNK:TRUNK] + */ + if (virt_vlan && virt_vlan->nTags > 0) { + if (virt_vlan->trunk) { + for (i =3D 0; i < virt_vlan->nTags; i++) + virBufferAsprintf(&buf, ":%d", virt_vlan->tag[i]); + } else { + virBufferAsprintf(&buf, ".%d", virt_vlan->tag[0]); + } + } + } + if (net->guestIP.nips > 0) { char *ipStr =3D xenMakeIPList(&net->guestIP); virBufferAsprintf(&buf, ",ip=3D%s", ipStr); VIR_FREE(ipStr); } - virBufferAsprintf(&buf, ",script=3D%s", DEFAULT_VIF_SCRIPT); - break; + virBufferAsprintf(&buf, ",script=3D%s", script ? script : DEFAULT_= VIF_SCRIPT); + } + break; =20 case VIR_DOMAIN_NET_TYPE_ETHERNET: if (net->script) diff --git a/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg b/tests/x= lconfigdata/test-fullvirt-ovswitch-tagged.cfg new file mode 100644 index 0000000000..6a3dc3cfeb --- /dev/null +++ b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.cfg @@ -0,0 +1,25 @@ +name =3D "XenGuest2" +uuid =3D "c7a5fdb2-cdaf-9455-926a-d65c16db1809" +maxmem =3D 8192 +memory =3D 8192 +vcpus =3D 8 +pae =3D 1 +acpi =3D 1 +apic =3D 1 +viridian =3D 0 +rtc_timeoffset =3D 0 +localtime =3D 0 +on_poweroff =3D "destroy" +on_reboot =3D "restart" +on_crash =3D "restart" +device_model =3D "/usr/lib/xen/bin/qemu-system-i386" +sdl =3D 0 +vnc =3D 1 +vncunused =3D 1 +vnclisten =3D "127.0.0.1" +vif =3D [ "mac=3D00:16:3e:66:92:9c,bridge=3Dovsbr0.42,script=3Dvif-openvsw= itch,model=3De1000" ] +parallel =3D "none" +serial =3D "none" +builder =3D "hvm" +boot =3D "c" +disk =3D [ "format=3Draw,vdev=3Dhda,access=3Drw,backendtype=3Dphy,target= =3D/dev/HostVG/XenGuest2" ] diff --git a/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml b/tests/x= lconfigdata/test-fullvirt-ovswitch-tagged.xml new file mode 100644 index 0000000000..63f3258b84 --- /dev/null +++ b/tests/xlconfigdata/test-fullvirt-ovswitch-tagged.xml @@ -0,0 +1,50 @@ + + XenGuest2 + c7a5fdb2-cdaf-9455-926a-d65c16db1809 + 8388608 + 8388608 + 8 + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + destroy + restart + restart + + /usr/lib/xen/bin/qemu-system-i386 + + + + +
+ + + + + + + + + +