diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-22 10:51:39 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-07-23 15:29:24 +0200 |
commit | 5c273efb36b506d5fab326d0d45491a09222d232 (patch) | |
tree | 6dd4f9e316b093de599a7fa6022abad0cb755377 | |
parent | 4127c88ad2120ce9ad7cac78d972d90aaee0d3d0 (diff) | |
download | NetworkManager-5c273efb36b506d5fab326d0d45491a09222d232.tar.gz |
core: use nm_utils_parse_inaddr_prefix_bin() in nm_utils_ip_route_attribute_to_platform()
We already have an implementation for parsing an address/plen string.
Use it.
-rw-r--r-- | src/NetworkManagerUtils.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index aadafb5898..230ffcda53 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -1349,20 +1349,17 @@ nm_utils_ip_route_attribute_to_platform (int addr_family, if ( addr_family == AF_INET6 && (variant = nm_ip_route_get_attribute (s_route, NM_IP_ROUTE_ATTRIBUTE_FROM)) && g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING)) { - gs_free char *string = NULL; - guint8 plen = 128; - char *sep; - - string = g_variant_dup_string (variant, NULL); - sep = strchr (string, '/'); - if (sep) { - *sep = 0; - plen = _nm_utils_ascii_str_to_int64 (sep + 1, 10, 1, 128, 255); - } - if ( plen <= 128 - && inet_pton (AF_INET6, string, &addr) == 1) { + int prefix; + + if (nm_utils_parse_inaddr_prefix_bin (addr_family, + g_variant_get_string (variant, NULL), + NULL, + &addr, + &prefix)) { + if (prefix < 0) + prefix = 128; r6->src = addr.addr6; - r6->src_plen = plen; + r6->src_plen = prefix; } } #undef GET_ATTR |