libnm-core: cleanup handling IP address in NMIPRoute
The change to canonicalize_ip() has actually no effect because all callers that pass null_any==TRUE, ensure already that they don't pass NULL.
This commit is contained in:
@@ -83,8 +83,15 @@ canonicalize_ip (int family, const char *ip, gboolean null_any)
|
|||||||
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
|
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!ip)
|
if (!ip) {
|
||||||
return NULL;
|
if (null_any)
|
||||||
|
return NULL;
|
||||||
|
if (family == AF_INET)
|
||||||
|
return g_strdup ("0.0.0.0");
|
||||||
|
if (family == AF_INET6)
|
||||||
|
return g_strdup ("::");
|
||||||
|
g_return_val_if_reached (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
ret = inet_pton (family, ip, addr_bytes);
|
ret = inet_pton (family, ip, addr_bytes);
|
||||||
g_return_val_if_fail (ret == 1, NULL);
|
g_return_val_if_fail (ret == 1, NULL);
|
||||||
@@ -599,6 +606,7 @@ nm_ip_route_new (int family,
|
|||||||
NMIPRoute *route;
|
NMIPRoute *route;
|
||||||
|
|
||||||
g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
|
g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
|
||||||
|
g_return_val_if_fail (dest, NULL);
|
||||||
|
|
||||||
if (!valid_ip (family, dest, error))
|
if (!valid_ip (family, dest, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -645,7 +653,6 @@ nm_ip_route_new_binary (int family,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
NMIPRoute *route;
|
NMIPRoute *route;
|
||||||
char string[NM_UTILS_INET_ADDRSTRLEN];
|
|
||||||
|
|
||||||
g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
|
g_return_val_if_fail (family == AF_INET || family == AF_INET6, NULL);
|
||||||
g_return_val_if_fail (dest, NULL);
|
g_return_val_if_fail (dest, NULL);
|
||||||
@@ -659,7 +666,7 @@ nm_ip_route_new_binary (int family,
|
|||||||
route->refcount = 1;
|
route->refcount = 1;
|
||||||
|
|
||||||
route->family = family;
|
route->family = family;
|
||||||
route->dest = g_strdup (inet_ntop (family, dest, string, sizeof (string)));
|
route->dest = canonicalize_ip_binary (family, dest, FALSE);
|
||||||
route->prefix = prefix;
|
route->prefix = prefix;
|
||||||
route->next_hop = canonicalize_ip_binary (family, next_hop, TRUE);
|
route->next_hop = canonicalize_ip_binary (family, next_hop, TRUE);
|
||||||
route->metric = metric;
|
route->metric = metric;
|
||||||
@@ -814,17 +821,11 @@ void
|
|||||||
nm_ip_route_set_dest (NMIPRoute *route,
|
nm_ip_route_set_dest (NMIPRoute *route,
|
||||||
const char *dest)
|
const char *dest)
|
||||||
{
|
{
|
||||||
char *new_dest;
|
|
||||||
|
|
||||||
g_return_if_fail (route != NULL);
|
g_return_if_fail (route != NULL);
|
||||||
g_return_if_fail (dest != NULL);
|
|
||||||
g_return_if_fail (nm_utils_ipaddr_valid (route->family, dest));
|
g_return_if_fail (nm_utils_ipaddr_valid (route->family, dest));
|
||||||
|
|
||||||
new_dest = canonicalize_ip (route->family, dest, FALSE);
|
|
||||||
g_return_if_fail (new_dest);
|
|
||||||
|
|
||||||
g_free (route->dest);
|
g_free (route->dest);
|
||||||
route->dest = new_dest;
|
route->dest = canonicalize_ip (route->family, dest, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2334,7 +2335,7 @@ set_property (GObject *object, guint prop_id,
|
|||||||
gateway = g_value_get_string (value);
|
gateway = g_value_get_string (value);
|
||||||
g_return_if_fail (!gateway || nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway));
|
g_return_if_fail (!gateway || nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway));
|
||||||
g_free (priv->gateway);
|
g_free (priv->gateway);
|
||||||
priv->gateway = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway, FALSE);
|
priv->gateway = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway, TRUE);
|
||||||
break;
|
break;
|
||||||
case PROP_ROUTES:
|
case PROP_ROUTES:
|
||||||
g_ptr_array_unref (priv->routes);
|
g_ptr_array_unref (priv->routes);
|
||||||
|
Reference in New Issue
Block a user