]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Add getter for network routes
authorMartin Kletzander <mkletzan@redhat.com>
Thu, 9 Jul 2015 13:50:41 +0000 (15:50 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 14 Jul 2015 06:04:49 +0000 (08:04 +0200)
Add virNetworkDefGetRouteByIndex() similarly to
virNetworkDefGetIpByIndex(), but for routes.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/network_conf.c
src/conf/network_conf.h
src/libvirt_private.syms

index 31d4463a475b842ba80d042c443846ab8529fed7..72006e9822d71f5f4621fea50563daaa9a2271aa 100644 (file)
@@ -803,6 +803,32 @@ virNetworkDefGetIpByIndex(const virNetworkDef *def,
     return NULL;
 }
 
+/* return routes[index], or NULL if there aren't enough routes */
+virNetworkRouteDefPtr
+virNetworkDefGetRouteByIndex(const virNetworkDef *def,
+                             int family, size_t n)
+{
+    size_t i;
+
+    if (!def->routes || n >= def->nroutes)
+        return NULL;
+
+    if (family == AF_UNSPEC)
+        return def->routes[n];
+
+    /* find the nth route of type "family" */
+    for (i = 0; i < def->nroutes; i++) {
+        virSocketAddrPtr addr = virNetworkRouteDefGetAddress(def->routes[i]);
+        if (VIR_SOCKET_ADDR_IS_FAMILY(addr, family)
+            && (n-- <= 0)) {
+            return def->routes[i];
+        }
+    }
+
+    /* failed to find enough of the right family */
+    return NULL;
+}
+
 /* return number of 1 bits in netmask for the network's ipAddress,
  * or -1 on error
  */
index 9411a02e32cb4d9f687943750b231a2a38c5d18e..1cd5100c1278c338331945e4c261186d3ad93039 100644 (file)
@@ -360,6 +360,9 @@ virPortGroupDefPtr virPortGroupFindByName(virNetworkDefPtr net,
 virNetworkIpDefPtr
 virNetworkDefGetIpByIndex(const virNetworkDef *def,
                           int family, size_t n);
+virNetworkRouteDefPtr
+virNetworkDefGetRouteByIndex(const virNetworkDef *def,
+                             int family, size_t n);
 int virNetworkIpDefPrefix(const virNetworkIpDef *def);
 int virNetworkIpDefNetmask(const virNetworkIpDef *def,
                            virSocketAddrPtr netmask);
index 1a0326844d49c9d4d46bfc0e4860cf6a3bb1000b..eb7ec769ca452f99df1c51a6e386b33356288a32 100644 (file)
@@ -597,6 +597,7 @@ virNetworkDefFormat;
 virNetworkDefFormatBuf;
 virNetworkDefFree;
 virNetworkDefGetIpByIndex;
+virNetworkDefGetRouteByIndex;
 virNetworkDefParseFile;
 virNetworkDefParseNode;
 virNetworkDefParseString;