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];
|
||||
int ret;
|
||||
|
||||
if (!ip)
|
||||
return NULL;
|
||||
if (!ip) {
|
||||
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);
|
||||
g_return_val_if_fail (ret == 1, NULL);
|
||||
@@ -599,6 +606,7 @@ nm_ip_route_new (int family,
|
||||
NMIPRoute *route;
|
||||
|
||||
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))
|
||||
return NULL;
|
||||
@@ -645,7 +653,6 @@ nm_ip_route_new_binary (int family,
|
||||
GError **error)
|
||||
{
|
||||
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 (dest, NULL);
|
||||
@@ -659,7 +666,7 @@ nm_ip_route_new_binary (int family,
|
||||
route->refcount = 1;
|
||||
|
||||
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->next_hop = canonicalize_ip_binary (family, next_hop, TRUE);
|
||||
route->metric = metric;
|
||||
@@ -814,17 +821,11 @@ void
|
||||
nm_ip_route_set_dest (NMIPRoute *route,
|
||||
const char *dest)
|
||||
{
|
||||
char *new_dest;
|
||||
|
||||
g_return_if_fail (route != NULL);
|
||||
g_return_if_fail (dest != NULL);
|
||||
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);
|
||||
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);
|
||||
g_return_if_fail (!gateway || nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), 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;
|
||||
case PROP_ROUTES:
|
||||
g_ptr_array_unref (priv->routes);
|
||||
|
Reference in New Issue
Block a user