]> xenbits.xensource.com Git - libvirt.git/commitdiff
Set broadcast address for IPv4 addresses on virtual network bridges
authorLaine Stump <laine@laine.org>
Fri, 31 Dec 2010 08:57:37 +0000 (03:57 -0500)
committerLaine Stump <laine@laine.org>
Fri, 31 Dec 2010 16:34:24 +0000 (11:34 -0500)
Previously we used ioctl() to set the IP address and netmask of the
bridges used for virtual networks, and apparently the SIOCSIFNETMASK
ioctl implicitly set the broadcast address for the interface. The new
method of using the "ip" command requires broadcast address to be
explicitly specified though.

src/util/bridge.c

index 81a043cf548e82a0e2c560914e71610d667ffbdd..e53fce5f7359681dcf2727366f1b1f9a986b64e7 100644 (file)
@@ -677,14 +677,23 @@ brAddInetAddress(brControl *ctl ATTRIBUTE_UNUSED,
                  unsigned int prefix)
 {
     virCommandPtr cmd = NULL;
-    char *addrstr;
+    char *addrstr = NULL, *bcaststr = NULL;
+    virSocketAddr broadcast;
     int ret = -1;
 
     if (!(addrstr = virSocketFormatAddr(addr)))
         goto cleanup;
+    /* format up a broadcast address if this is IPv4 */
+    if ((VIR_SOCKET_IS_FAMILY(addr, AF_INET)) &&
+        ((virSocketAddrBroadcastByPrefix(addr, prefix, &broadcast) < 0) ||
+         !(bcaststr = virSocketFormatAddr(&broadcast)))) {
+        goto cleanup;
+    }
     cmd = virCommandNew(IP_PATH);
     virCommandAddArgList(cmd, "addr", "add", NULL);
     virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
+    if (bcaststr)
+        virCommandAddArgList(cmd, "broadcast", bcaststr, NULL);
     virCommandAddArgList(cmd, "dev", ifname, NULL);
 
     if (virCommandRun(cmd, NULL) < 0)
@@ -693,6 +702,7 @@ brAddInetAddress(brControl *ctl ATTRIBUTE_UNUSED,
     ret = 0;
 cleanup:
     VIR_FREE(addrstr);
+    VIR_FREE(bcaststr);
     virCommandFree(cmd);
     return ret;
 }