mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
conf: Add getter for network routes
Add virNetworkDefGetRouteByIndex() similarly to virNetworkDefGetIpByIndex(), but for routes. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
f8b784a8ef
commit
0f10eb6a28
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -597,6 +597,7 @@ virNetworkDefFormat;
|
||||
virNetworkDefFormatBuf;
|
||||
virNetworkDefFree;
|
||||
virNetworkDefGetIpByIndex;
|
||||
virNetworkDefGetRouteByIndex;
|
||||
virNetworkDefParseFile;
|
||||
virNetworkDefParseNode;
|
||||
virNetworkDefParseString;
|
||||
|
Loading…
Reference in New Issue
Block a user