diff options
author | 2012-08-17 00:04:54 -0400 | |
---|---|---|
committer | 2012-08-17 11:12:29 -0400 | |
commit | 7d2b91b86a814d8469fd3aed10cff264ccab70cf (patch) | |
tree | 517b6d0210767226070cb69dcbf77459d9d913d0 /src/util | |
parent | Fix the indentions of libvirt.h.in (diff) | |
download | libvirt-7d2b91b86a814d8469fd3aed10cff264ccab70cf.tar.gz libvirt-7d2b91b86a814d8469fd3aed10cff264ccab70cf.tar.bz2 libvirt-7d2b91b86a814d8469fd3aed10cff264ccab70cf.zip |
network: add support for setting VLANs on Open vSwitch ports
Add the ability to support VLAN tags for Open vSwitch virtual port
types. To accomplish this, modify virNetDevOpenvswitchAddPort and
virNetDevTapCreateInBridgePort to take a virNetDevVlanPtr
argument. When adding the port to the OVS bridge, setup either a
single VLAN or a trunk port based on the configuration from the
virNetDevVlanPtr.
Signed-off-by: Kyle Mestery <kmestery@cisco.com>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/virnetdevopenvswitch.c | 34 | ||||
-rw-r--r-- | src/util/virnetdevopenvswitch.h | 4 | ||||
-rw-r--r-- | src/util/virnetdevtap.c | 3 | ||||
-rw-r--r-- | src/util/virnetdevtap.h | 2 |
4 files changed, 38 insertions, 5 deletions
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index b57532b32..601d79e62 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -46,9 +46,11 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, const virMacAddrPtr macaddr, const unsigned char *vmuuid, - virNetDevVPortProfilePtr ovsport) + virNetDevVPortProfilePtr ovsport, + virNetDevVlanPtr virtVlan) { int ret = -1; + int i = 0; virCommandPtr cmd = NULL; char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; @@ -57,6 +59,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, char *ifaceid_ex_id = NULL; char *profile_ex_id = NULL; char *vmid_ex_id = NULL; + virBufferPtr buf; virMacAddrFormat(macaddr, macaddrstr); virUUIDFormat(ovsport->interfaceID, ifuuidstr); @@ -76,11 +79,35 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, ovsport->profileID) < 0) goto out_of_memory; } + if (virtVlan) { + if (VIR_ALLOC(buf) < 0) + goto out_of_memory; + + /* Trunk port first */ + if (virtVlan->trunk) { + virBufferAddLit(buf, "trunk="); + + /* + * Trunk ports have at least one VLAN. Do the first one + * outside the "for" loop so we can put a "," at the + * start of the for loop if there are more than one VLANs + * on this trunk port. + */ + virBufferAsprintf(buf, "%d", virtVlan->tag[i]); + + for (i = 1; i < virtVlan->nTags; i++) { + virBufferAddLit(buf, ","); + virBufferAsprintf(buf, "%d", virtVlan->tag[i]); + } + } else { + virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]); + } + } cmd = virCommandNew(OVSVSCTL); if (ovsport->profileID[0] == '\0') { virCommandAddArgList(cmd, "--", "--may-exist", "add-port", - brname, ifname, + brname, ifname, virBufferContentAndReset(buf), "--", "set", "Interface", ifname, attachedmac_ex_id, "--", "set", "Interface", ifname, ifaceid_ex_id, "--", "set", "Interface", ifname, vmid_ex_id, @@ -89,7 +116,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, NULL); } else { virCommandAddArgList(cmd, "--", "--may-exist", "add-port", - brname, ifname, + brname, ifname, virBufferContentAndReset(buf), "--", "set", "Interface", ifname, attachedmac_ex_id, "--", "set", "Interface", ifname, ifaceid_ex_id, "--", "set", "Interface", ifname, vmid_ex_id, @@ -108,6 +135,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, ret = 0; cleanup: + VIR_FREE(buf); VIR_FREE(attachedmac_ex_id); VIR_FREE(ifaceid_ex_id); VIR_FREE(vmid_ex_id); diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitch.h index fbf91687a..58b4ddadd 100644 --- a/src/util/virnetdevopenvswitch.h +++ b/src/util/virnetdevopenvswitch.h @@ -27,13 +27,15 @@ # include "internal.h" # include "util.h" # include "virnetdevvportprofile.h" +# include "virnetdevvlan.h" int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, const virMacAddrPtr macaddr, const unsigned char *vmuuid, - virNetDevVPortProfilePtr ovsport) + virNetDevVPortProfilePtr ovsport, + virNetDevVlanPtr virtVlan) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 192d180ec..24f30b506 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -280,6 +280,7 @@ int virNetDevTapCreateInBridgePort(const char *brname, const unsigned char *vmuuid, int *tapfd, virNetDevVPortProfilePtr virtPortProfile, + virNetDevVlanPtr virtVlan, unsigned int flags) { virMacAddr tapmac; @@ -324,7 +325,7 @@ int virNetDevTapCreateInBridgePort(const char *brname, if (virtPortProfile) { if (virNetDevOpenvswitchAddPort(brname, *ifname, macaddr, vmuuid, - virtPortProfile) < 0) { + virtPortProfile, virtVlan) < 0) { goto error; } } else { diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h index ce3365eb3..45d0c0817 100644 --- a/src/util/virnetdevtap.h +++ b/src/util/virnetdevtap.h @@ -25,6 +25,7 @@ # include "internal.h" # include "virnetdevvportprofile.h" +# include "virnetdevvlan.h" int virNetDevTapCreate(char **ifname, int *tapfd, @@ -50,6 +51,7 @@ int virNetDevTapCreateInBridgePort(const char *brname, const unsigned char *vmuuid, int *tapfd, virNetDevVPortProfilePtr virtPortProfile, + virNetDevVlanPtr virtVlan, unsigned int flags) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; |