diff options
author | Thomas Haller <thaller@redhat.com> | 2016-01-28 21:09:36 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-01-28 21:15:59 +0100 |
commit | 0ba4322eec6f78559eb6ade85c67c7426e75285b (patch) | |
tree | b205c4d6a0eb8df15bdc0bf9f5c850d45768a428 | |
parent | 91f06323c7f5bf027cca3b554ba0a1b88195839a (diff) | |
download | NetworkManager-0ba4322eec6f78559eb6ade85c67c7426e75285b.tar.gz |
libnm-core: ensure any next_hop in NMIPRoute is NULL
NMIPRoute has the convention that a next-hop 0.0.0.0/:: is stored
as NULL. However, the binary setters could violate that.
-rw-r--r-- | libnm-core/nm-setting-ip-config.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index 4911be9a24..43a2dc3fdd 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -86,6 +86,29 @@ canonicalize_ip (int family, const char *ip, gboolean null_any) return g_strdup (inet_ntop (family, addr_bytes, addr_str, sizeof (addr_str))); } +static char * +canonicalize_ip_binary (int family, gconstpointer ip, gboolean null_any) +{ + char string[NM_UTILS_INET_ADDRSTRLEN]; + + 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); + } + if (null_any) { + int addrlen = (family == AF_INET ? sizeof (struct in_addr) : sizeof (struct in6_addr)); + + if (!memcmp (ip, &in6addr_any, addrlen)) + return NULL; + } + return g_strdup (inet_ntop (family, ip, string, sizeof (string))); +} + static gboolean valid_ip (int family, const char *ip, GError **error) { @@ -629,8 +652,7 @@ nm_ip_route_new_binary (int family, route->family = family; route->dest = g_strdup (inet_ntop (family, dest, string, sizeof (string))); route->prefix = prefix; - if (next_hop) - route->next_hop = g_strdup (inet_ntop (family, next_hop, string, sizeof (string))); + route->next_hop = canonicalize_ip_binary (family, next_hop, TRUE); route->metric = metric; return route; @@ -954,15 +976,10 @@ void nm_ip_route_set_next_hop_binary (NMIPRoute *route, gconstpointer next_hop) { - char string[NM_UTILS_INET_ADDRSTRLEN]; - g_return_if_fail (route != NULL); g_free (route->next_hop); - if (next_hop) - route->next_hop = g_strdup (inet_ntop (route->family, next_hop, string, sizeof (string))); - else - route->next_hop = NULL; + route->next_hop = canonicalize_ip_binary (route->family, next_hop, TRUE); } /** |