Re: [PATCH 2/3] Set broadcast address for IPv4 addresses on virtual network bridges

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/31/2010 06:33 AM, Laine Stump wrote:
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 |   12 +++++++++++-
  1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/src/util/bridge.c b/src/util/bridge.c
index 81a043c..e53fce5 100644
--- a/src/util/bridge.c
+++ b/src/util/bridge.c
@@ -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;
  }

ACK.
    Stefan

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]