mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-30 09:40:11 +01:00
core: add nm_ip4_config_get_subnet_for_host() function
And nm_ip6_config_get_subnet_for_host(). Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
3c17254823
commit
644eadcf80
4 changed files with 55 additions and 4 deletions
|
|
@ -1210,12 +1210,12 @@ const NMPlatformIP4Route *
|
|||
nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host)
|
||||
{
|
||||
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
int i;
|
||||
guint i;
|
||||
NMPlatformIP4Route *best_route = NULL;
|
||||
|
||||
g_return_val_if_fail (host, NULL);
|
||||
|
||||
for (i = 0; i < priv->routes->len; i++ ) {
|
||||
for (i = 0; i < priv->routes->len; i++) {
|
||||
NMPlatformIP4Route *item = &g_array_index (priv->routes, NMPlatformIP4Route, i);
|
||||
|
||||
if (item->gateway != 0)
|
||||
|
|
@ -1236,6 +1236,28 @@ nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host
|
|||
return best_route;
|
||||
}
|
||||
|
||||
const NMPlatformIP4Address *
|
||||
nm_ip4_config_get_subnet_for_host (const NMIP4Config *config, guint32 host)
|
||||
{
|
||||
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
guint i;
|
||||
NMPlatformIP4Address *subnet = NULL;
|
||||
|
||||
g_return_val_if_fail (host, NULL);
|
||||
|
||||
for (i = 0; i < priv->addresses->len; i++) {
|
||||
NMPlatformIP4Address *item = &g_array_index (priv->addresses, NMPlatformIP4Address, i);
|
||||
|
||||
if (subnet && subnet->plen >= item->plen)
|
||||
continue;
|
||||
if (nm_utils_ip4_address_clear_host_address (host, item->plen) != nm_utils_ip4_address_clear_host_address (item->address, item->plen))
|
||||
continue;
|
||||
subnet = item;
|
||||
}
|
||||
|
||||
return subnet;
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ guint32 nm_ip4_config_get_num_routes (const NMIP4Config *config);
|
|||
const NMPlatformIP4Route *nm_ip4_config_get_route (const NMIP4Config *config, guint32 i);
|
||||
|
||||
const NMPlatformIP4Route *nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host);
|
||||
const NMPlatformIP4Address *nm_ip4_config_get_subnet_for_host (const NMIP4Config *config, guint32 host);
|
||||
|
||||
/* Nameservers */
|
||||
void nm_ip4_config_reset_nameservers (NMIP4Config *config);
|
||||
|
|
|
|||
|
|
@ -1217,13 +1217,13 @@ const NMPlatformIP6Route *
|
|||
nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct in6_addr *host)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
int i;
|
||||
guint i;
|
||||
struct in6_addr network2, host2;
|
||||
NMPlatformIP6Route *best_route = NULL;
|
||||
|
||||
g_return_val_if_fail (host && !IN6_IS_ADDR_UNSPECIFIED (host), NULL);
|
||||
|
||||
for (i = 0; i < priv->routes->len; i++ ) {
|
||||
for (i = 0; i < priv->routes->len; i++) {
|
||||
NMPlatformIP6Route *item = &g_array_index (priv->routes, NMPlatformIP6Route, i);
|
||||
|
||||
if (!IN6_IS_ADDR_UNSPECIFIED (&item->gateway))
|
||||
|
|
@ -1248,6 +1248,33 @@ nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct
|
|||
return best_route;
|
||||
}
|
||||
|
||||
const NMPlatformIP6Address *
|
||||
nm_ip6_config_get_subnet_for_host (const NMIP6Config *config, const struct in6_addr *host)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
guint i;
|
||||
NMPlatformIP6Address *subnet = NULL;
|
||||
struct in6_addr subnet2, host2;
|
||||
|
||||
g_return_val_if_fail (host && !IN6_IS_ADDR_UNSPECIFIED (host), NULL);
|
||||
|
||||
for (i = 0; i < priv->addresses->len; i++) {
|
||||
NMPlatformIP6Address *item = &g_array_index (priv->addresses, NMPlatformIP6Address, i);
|
||||
|
||||
if (subnet && subnet->plen >= item->plen)
|
||||
continue;
|
||||
|
||||
nm_utils_ip6_address_clear_host_address (&host2, host, item->plen);
|
||||
nm_utils_ip6_address_clear_host_address (&subnet2, &item->address, item->plen);
|
||||
|
||||
if (IN6_ARE_ADDR_EQUAL (&subnet2, &host2))
|
||||
subnet = item;
|
||||
}
|
||||
|
||||
return subnet;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ guint32 nm_ip6_config_get_num_routes (const NMIP6Config *config);
|
|||
const NMPlatformIP6Route *nm_ip6_config_get_route (const NMIP6Config *config, guint32 i);
|
||||
|
||||
const NMPlatformIP6Route *nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct in6_addr *host);
|
||||
const NMPlatformIP6Address *nm_ip6_config_get_subnet_for_host (const NMIP6Config *config, const struct in6_addr *host);
|
||||
|
||||
/* Nameservers */
|
||||
void nm_ip6_config_reset_nameservers (NMIP6Config *config);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue