[libvirt] [PATCH v2] vepa: parsing for 802.1Qb{g|h} XML

Gerhard Stenzel gstenzel at linux.vnet.ibm.com
Wed May 12 19:54:29 UTC 2010


On Wed, 2010-05-12 at 21:08 +0200, Gerhard Stenzel wrote:
> On Wed, 2010-05-12 at 13:21 -0400, Stefan Berger wrote:
> > I am wondering whether it would not be 'more general' to have lldpad
> > determine 
> > the root interface and handling bonding interfaces on the way
> rather 
> > than libvirt trying to determine that here. So we would just pass
> the 
> > linkdev or the even the macvtap to lldptool. The same would be true 
> > for finding the VLAN ID. For both the code I posted here on libvirt 
> > mailing list could be used in lldpad. For now I won't check it in.
> 
> If that is the preferred way ... fine with me.

Just in case, here is a version taking care of that:

Here is a RFC patch, which demonstrates how libvirt could communicate
with lldpad via the lldptool for the 802.1Qbg case. Please note, that
there is currently no public available version of lldptool which accepts
this command line. This is also work in progress. 

Signed-off-by: Gerhard Stenzel <gerhard.stenzel at de.ibm.com>

Index: libvirt/src/util/macvtap.c
===================================================================
--- libvirt.orig/src/util/macvtap.c
+++ libvirt/src/util/macvtap.c
@@ -750,6 +750,92 @@ configMacvtapTap(int tapfd, int vnet_hdr
     return 0;
 }
 
+# define ASSOCIATE                              0x02
+# define DEASSOCIATE                            0x03
+# define LLDPTOOL_NAME  "lldptool"
+
+static int
+setPortProfileId(const char *linkdev,
+                 const unsigned char *mac,
+                 int mode,
+                 const virVSIProfileDefPtr vsi)
+{
+    char macaddr[VIR_MAC_STRING_BUFLEN];
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+    static char *lldptool;
+    char *modestr = NULL;
+    int rc;
+    int status = 0;
+# define NUM_PARAMS 8
+    const char *argv[NUM_PARAMS] = {NULL, };
+    int argc = 0;
+
+    virFormatMacAddr(mac, macaddr);
+
+    if (lldptool == NULL) {
+        lldptool = virFindFileInPath(LLDPTOOL_NAME);
+        if (lldptool == NULL) {
+            macvtapError(VIR_ERR_INTERNAL_ERROR,
+                         _("unable to find %s"), LLDPTOOL_NAME);
+            return -1;
+        }
+    }
+
+    virFormatMacAddr(mac, macaddr);
+    virUUIDFormat(vsi->u.vsi8021Qbg.instanceID, uuidstr);
+
+    VIR_DEBUG("setting typeid '%d' with mode '%d' on link '%s' mac '%
s'\n",
+              vsi->u.vsi8021Qbg.typeID, mode, linkdev, macaddr);
+
+    /*  example syntax:
+     * lldptool -T -i eth2 -V vdp  \
+     *
mode=<mode>,<mgrid>,<typeid>,<typeidversion>,<uuid>
+     */
+
+    if ((virAsprintf(&modestr, "mode=%d,%d,%d,%d,%s,%s", mode,
+                                     vsi->u.vsi8021Qbg.managerID,
+                                     vsi->u.vsi8021Qbg.typeID,
+                                     vsi->u.vsi8021Qbg.typeIDVersion,
+                                     uuidstr,
+                                     macaddr) < 0 )) {
+        rc = -1;
+        goto err_exit;
+    }
+
+    argv[argc++] = lldptool;
+    argv[argc++] = "-T";
+    argv[argc++] = "-i";
+    argv[argc++] = linkdev;
+    argv[argc++] = "-V";
+    argv[argc++] = "vdp";
+    argv[argc++] = modestr;
+    argv[argc  ] = NULL;
+
+    VIR_DEBUG("argc = %d\n", argc);
+    if (argc >= NUM_PARAMS) {
+        macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
+                     _("too many parameters in array"));
+        rc = 1;
+        goto err_exit;
+    }
+# undef NUM_PARAMS
+
+    rc = virRun(argv, &status);
+    status >>= 8;
+
+    VIR_DEBUG("Result from running %s: rc = %d, status = %d\n",
+              lldptool, rc, status);
+
+err_exit:
+    VIR_FREE(modestr);
+
+    if (rc)
+        return rc;
+
+    return status;
+
+}
+
 
 /**
  * associatePortProfile
@@ -791,7 +877,10 @@ associatePortProfileId(const char *linkd
         break;
 
     case VIR_VSI_8021QBG:
-        rc = -1;
+        rc =  setPortProfileId(linkdev,
+                            mac,
+                            ASSOCIATE,
+                            vsi);
         break;
 
     case VIR_VSI_8021QBH:
@@ -829,7 +918,10 @@ disassociatePortProfileId(const char *li
         break;
 
     case VIR_VSI_8021QBG:
-        rc = -1;
+        rc =  setPortProfileId(linkdev,
+                            mac,
+                            DEASSOCIATE,
+                            vsi);
         break;
 
     case VIR_VSI_8021QBH:


-- 
Best regards, 

Gerhard Stenzel, 
-----------------------------------------------------------------------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294




More information about the libvir-list mailing list