diff options
author | Thomas Haller <thaller@redhat.com> | 2017-09-05 19:11:17 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-09-05 19:11:17 +0200 |
commit | 08d7bf5988173f8569b17c646eb1a5c5d9d9340c (patch) | |
tree | 1d56c9698bb913241cc1fd789fff4d1556091152 | |
parent | a47153f5b8a114ce1f0d226b33d0ad6d6ec7f150 (diff) | |
parent | 416a9616dea36a616eef3aceb70cf15660b0ee6c (diff) | |
download | NetworkManager-08d7bf5988173f8569b17c646eb1a5c5d9d9340c.tar.gz |
tui: merge branch 'th/tui-route-input-rh1474295'
https://bugzilla.redhat.com/show_bug.cgi?id=1474295
24 files changed, 271 insertions, 124 deletions
diff --git a/Makefile.am b/Makefile.am index e8a6a8aeea..60b1adf175 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3423,6 +3423,8 @@ clients_tui_newt_libnmt_newt_a_CPPFLAGS = \ bin_PROGRAMS += clients/tui/nmtui clients_tui_nmtui_SOURCES = \ + shared/nm-utils/nm-shared-utils.c \ + shared/nm-utils/nm-shared-utils.h \ clients/tui/nmtui.c \ clients/tui/nmtui.h \ clients/tui/nmtui-connect.c \ diff --git a/clients/tui/newt/nmt-newt-entry-numeric.c b/clients/tui/newt/nmt-newt-entry-numeric.c index b79f056a61..f0eceb5ffe 100644 --- a/clients/tui/newt/nmt-newt-entry-numeric.c +++ b/clients/tui/newt/nmt-newt-entry-numeric.c @@ -38,12 +38,14 @@ G_DEFINE_TYPE (NmtNewtEntryNumeric, nmt_newt_entry_numeric, NMT_TYPE_NEWT_ENTRY) typedef struct { int min, max; + bool optional; } NmtNewtEntryNumericPrivate; enum { PROP_0, PROP_MINIMUM, PROP_MAXIMUM, + PROP_OPTIONAL, LAST_PROP }; @@ -64,10 +66,35 @@ nmt_newt_entry_numeric_new (int width, int min, int max) { + return nmt_newt_entry_numeric_new_full (width, + min, + max, + FALSE); +} + +/** + * nmt_newt_entry_numeric_new_full: + * @width: the entry's width in characters + * @min: the minimum valid value + * @max: the maximum valid value + * @optional: whether an empty entry is valid + * + * Creates a new #NmtNewtEntryNumeric, accepting values in the + * indicated range. + * + * Returns: a new #NmtNewtEntryNumeric + */ +NmtNewtWidget * +nmt_newt_entry_numeric_new_full (int width, + int min, + int max, + gboolean optional) +{ return g_object_new (NMT_TYPE_NEWT_ENTRY_NUMERIC, "width", width, "minimum", min, "maximum", max, + "optional", optional, NULL); } @@ -96,18 +123,12 @@ newt_entry_numeric_validate (NmtNewtEntry *entry, { NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE (entry); int val; - char *end; if (!*text) - return FALSE; + return priv->optional ? TRUE : FALSE; - val = strtoul (text, &end, 10); - if (*end) - return FALSE; - if (val < priv->min || val > priv->max) - return FALSE; - - return TRUE; + val = _nm_utils_ascii_str_to_int64 (text, 10, priv->min, priv->max, 0); + return val != 0 || errno == 0; } static void @@ -147,6 +168,9 @@ nmt_newt_entry_numeric_set_property (GObject *object, case PROP_MAXIMUM: priv->max = g_value_get_int (value); break; + case PROP_OPTIONAL: + priv->optional = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -168,6 +192,9 @@ nmt_newt_entry_numeric_get_property (GObject *object, case PROP_MAXIMUM: g_value_set_int (value, priv->max); break; + case PROP_OPTIONAL: + g_value_set_boolean (value, priv->optional); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -212,4 +239,17 @@ nmt_newt_entry_numeric_class_init (NmtNewtEntryNumericClass *entry_class) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + /** + * NmtNewtEntryNumeric:optional: + * + * If %TRUE, allow empty string to indicate some default value. + * It means the property is optional and can be left at the default + */ + g_object_class_install_property + (object_class, PROP_OPTIONAL, + g_param_spec_boolean ("optional", "", "", + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); } diff --git a/clients/tui/newt/nmt-newt-entry-numeric.h b/clients/tui/newt/nmt-newt-entry-numeric.h index 00e1973963..c158631635 100644 --- a/clients/tui/newt/nmt-newt-entry-numeric.h +++ b/clients/tui/newt/nmt-newt-entry-numeric.h @@ -44,4 +44,9 @@ NmtNewtWidget *nmt_newt_entry_numeric_new (int width, int min, int max); +NmtNewtWidget *nmt_newt_entry_numeric_new_full (int width, + int min, + int max, + gboolean optional); + #endif /* NMT_NEWT_ENTRY_NUMERIC_H */ diff --git a/clients/tui/nm-editor-bindings.c b/clients/tui/nm-editor-bindings.c index 3753aaa9ac..7ac7f0c7e2 100644 --- a/clients/tui/nm-editor-bindings.c +++ b/clients/tui/nm-editor-bindings.c @@ -71,45 +71,6 @@ nm_editor_bindings_init (void) } static gboolean -parse_addr_prefix (const char *text, - int family, - char **addr, - guint32 *prefix) -{ - const char *slash; - char *addrstr, *end; - gboolean valid; - - slash = strchr (text, '/'); - - if (slash) - addrstr = g_strndup (text, slash - text); - else - addrstr = g_strdup (text); - valid = nm_utils_ipaddr_valid (family, addrstr); - - if (slash) { - *prefix = strtoul (slash + 1, &end, 10); - if ( *end - || *prefix == 0 - || (family == AF_INET && *prefix > 32) - || (family == AF_INET6 && *prefix > 128)) - valid = FALSE; - } else if (prefix) { - if (family == AF_INET) - *prefix = 32; - else - *prefix = 128; - } - - if (addr && valid) - *addr = addrstr; - else - g_free (addrstr); - return valid; -} - -static gboolean ip_addresses_with_prefix_to_strv (GBinding *binding, const GValue *source_value, GValue *target_value, @@ -151,7 +112,7 @@ ip_addresses_with_prefix_from_strv (GBinding *binding, GPtrArray *addrs; NMIPAddress *addr; char *addrstr; - guint32 prefix; + int prefix; int i; strings = g_value_get_boxed (source_value); @@ -170,11 +131,24 @@ ip_addresses_with_prefix_from_strv (GBinding *binding, } else addr = addrs->pdata[i]; - if (!parse_addr_prefix (strings[i], family, &addrstr, &prefix)) { + if (!nm_utils_parse_inaddr_prefix (strings[i], family, &addrstr, &prefix)) { g_ptr_array_unref (addrs); return FALSE; } + if (prefix == -1) { + if (family == AF_INET) { + in_addr_t v4; + + inet_pton (family, addrstr, &v4); + if (nm_utils_ip_is_site_local (AF_INET, &v4)) + prefix = nm_utils_ip4_get_default_prefix (v4); + else + prefix = 32; + } else + prefix = 64; + } + nm_ip_address_set_address (addr, addrstr); nm_ip_address_set_prefix (addr, prefix); g_free (addrstr); @@ -451,10 +425,10 @@ ip_route_transform_from_dest_string (GBinding *binding, NMIPRoute *route; const char *text; char *addrstr; - guint32 prefix; + int prefix; text = g_value_get_string (source_value); - if (!parse_addr_prefix (text, family, &addrstr, &prefix)) + if (!nm_utils_parse_inaddr_prefix (text, family, &addrstr, &prefix)) return FALSE; /* Fetch the original property value */ @@ -462,6 +436,21 @@ ip_route_transform_from_dest_string (GBinding *binding, g_binding_get_source_property (binding), &route, NULL); + if (prefix == -1) { + if (family == AF_INET) { + in_addr_t v4; + + inet_pton (family, addrstr, &v4); + if (nm_utils_ip_is_site_local (AF_INET, &v4)) { + prefix = nm_utils_ip4_get_default_prefix (v4); + if (v4 & (~nm_utils_ip4_prefix_to_netmask (prefix))) + prefix = 32; + } else + prefix = 32; + } else + prefix = 64; + } + nm_ip_route_set_dest (route, addrstr); nm_ip_route_set_prefix (route, prefix); g_free (addrstr); diff --git a/clients/tui/nmt-ip-entry.c b/clients/tui/nmt-ip-entry.c index 8d8f888f0d..1556c8d7fe 100644 --- a/clients/tui/nmt-ip-entry.c +++ b/clients/tui/nmt-ip-entry.c @@ -123,39 +123,12 @@ ip_entry_validate (NmtNewtEntry *entry, gpointer user_data) { NmtIPEntryPrivate *priv = NMT_IP_ENTRY_GET_PRIVATE (entry); - guchar buf[16]; - guint32 prefix; - const char *slash; - char *addrstr, *end; - gboolean valid; if (!*text) return priv->optional; - - slash = strchr (text, '/'); - - if (slash) { - if (!priv->prefix) - return FALSE; - addrstr = g_strndup (text, slash - text); - } else - addrstr = g_strdup (text); - valid = (inet_pton (priv->family, addrstr, buf) == 1); - g_free (addrstr); - - if (!valid) - return FALSE; - - if (slash) { - prefix = strtoul (slash + 1, &end, 10); - if ( *end - || prefix == 0 - || (priv->family == AF_INET && prefix > 32) - || (priv->family == AF_INET6 && prefix > 128)) - valid = FALSE; - } - - return valid; + if (priv->prefix) + return nm_utils_parse_inaddr_prefix (text, priv->family, NULL, NULL); + return nm_utils_parse_inaddr (text, priv->family, NULL); } static void diff --git a/clients/tui/nmt-route-entry.c b/clients/tui/nmt-route-entry.c index f7c75e0aaa..1f58fc0000 100644 --- a/clients/tui/nmt-route-entry.c +++ b/clients/tui/nmt-route-entry.c @@ -126,7 +126,7 @@ nmt_route_entry_constructed (GObject *object) priv->dest = nmt_ip_entry_new (priv->ip_entry_width, priv->family, TRUE, FALSE); priv->next_hop = nmt_ip_entry_new (priv->ip_entry_width, priv->family, FALSE, TRUE); - priv->metric = nmt_newt_entry_numeric_new (priv->metric_entry_width, 0, 65535); + priv->metric = nmt_newt_entry_numeric_new_full (priv->metric_entry_width, 0, 65535, TRUE); nmt_newt_grid_add (grid, priv->dest, 0, 0); warning_label = create_warning_label (priv->dest); diff --git a/clients/tui/nmt-route-table.c b/clients/tui/nmt-route-table.c index 7005e8ad0d..a63f52053e 100644 --- a/clients/tui/nmt-route-table.c +++ b/clients/tui/nmt-route-table.c @@ -149,9 +149,9 @@ add_route (NmtWidgetList *list, NMIPRoute *route; if (priv->family == AF_INET) - route = nm_ip_route_new (AF_INET, "0.0.0.0", 32, NULL, 0, NULL); + route = nm_ip_route_new (AF_INET, "0.0.0.0", 32, NULL, -1, NULL); else - route = nm_ip_route_new (AF_INET6, "::", 128, NULL, 0, NULL); + route = nm_ip_route_new (AF_INET6, "::", 128, NULL, -1, NULL); g_ptr_array_add (priv->routes, route); nmt_widget_list_set_length (list, priv->routes->len); g_object_notify (table, "routes"); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 9966b7c68f..36169e2b70 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -1490,10 +1490,9 @@ nm_utils_ip4_netmask_to_prefix (guint32 netmask) guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix) { - return prefix < 32 ? ~htonl(0xFFFFFFFF >> prefix) : 0xFFFFFFFF; + return _nm_utils_ip4_prefix_to_netmask (prefix); } - /** * nm_utils_ip4_get_default_prefix: * @ip: an IPv4 address (in network byte order) @@ -1509,12 +1508,7 @@ nm_utils_ip4_prefix_to_netmask (guint32 prefix) guint32 nm_utils_ip4_get_default_prefix (guint32 ip) { - if (((ntohl (ip) & 0xFF000000) >> 24) <= 127) - return 8; /* Class A - 255.0.0.0 */ - else if (((ntohl (ip) & 0xFF000000) >> 24) <= 191) - return 16; /* Class B - 255.255.0.0 */ - - return 24; /* Class C - 255.255.255.0 */ + return _nm_utils_ip4_get_default_prefix (ip); } /** diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 00ac2cebe5..d33a6e87d2 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -3249,7 +3249,7 @@ test_ip4_prefix_to_netmask (void) int i; for (i = 0; i<=32; i++) { - guint32 netmask = nm_utils_ip4_prefix_to_netmask (i); + guint32 netmask = _nm_utils_ip4_prefix_to_netmask (i); int plen = nm_utils_ip4_netmask_to_prefix (netmask); g_assert_cmpint (i, ==, plen); @@ -3277,8 +3277,8 @@ test_ip4_netmask_to_prefix (void) g_rand_set_seed (rand, 1); for (i = 2; i<=32; i++) { - guint32 netmask = nm_utils_ip4_prefix_to_netmask (i); - guint32 netmask_lowest_bit = netmask & ~nm_utils_ip4_prefix_to_netmask (i-1); + guint32 netmask = _nm_utils_ip4_prefix_to_netmask (i); + guint32 netmask_lowest_bit = netmask & ~_nm_utils_ip4_prefix_to_netmask (i-1); g_assert_cmpint (i, ==, nm_utils_ip4_netmask_to_prefix (netmask)); diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index 04deecf986..fba87c5a79 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -1102,7 +1102,7 @@ nm_utils_ip4_netmask_to_prefix (guint32 netmask) guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix) { - return prefix < 32 ? ~htonl(0xFFFFFFFF >> prefix) : 0xFFFFFFFF; + return _nm_utils_ip4_prefix_to_netmask (prefix); } @@ -1121,12 +1121,7 @@ nm_utils_ip4_prefix_to_netmask (guint32 prefix) guint32 nm_utils_ip4_get_default_prefix (guint32 ip) { - if (((ntohl (ip) & 0xFF000000) >> 24) <= 127) - return 8; /* Class A - 255.0.0.0 */ - else if (((ntohl (ip) & 0xFF000000) >> 24) <= 191) - return 16; /* Class B - 255.255.0.0 */ - - return 24; /* Class C - 255.255.255.0 */ + return _nm_utils_ip4_get_default_prefix (ip); } /** diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index 9a87536e53..b512e52a57 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -24,6 +24,7 @@ #include "nm-shared-utils.h" #include <errno.h> +#include <arpa/inet.h> /*****************************************************************************/ @@ -110,6 +111,137 @@ nm_utils_strbuf_append (char **buf, gsize *len, const char *format, ...) /*****************************************************************************/ +/** + * _nm_utils_ip4_prefix_to_netmask: + * @prefix: a CIDR prefix + * + * Returns: the netmask represented by the prefix, in network byte order + **/ +guint32 +_nm_utils_ip4_prefix_to_netmask (guint32 prefix) +{ + return prefix < 32 ? ~htonl(0xFFFFFFFF >> prefix) : 0xFFFFFFFF; +} + +/** + * _nm_utils_ip4_get_default_prefix: + * @ip: an IPv4 address (in network byte order) + * + * When the Internet was originally set up, various ranges of IP addresses were + * segmented into three network classes: A, B, and C. This function will return + * a prefix that is associated with the IP address specified defining where it + * falls in the predefined classes. + * + * Returns: the default class prefix for the given IP + **/ +/* The function is originally from ipcalc.c of Red Hat's initscripts. */ +guint32 +_nm_utils_ip4_get_default_prefix (guint32 ip) +{ + if (((ntohl (ip) & 0xFF000000) >> 24) <= 127) + return 8; /* Class A - 255.0.0.0 */ + else if (((ntohl (ip) & 0xFF000000) >> 24) <= 191) + return 16; /* Class B - 255.255.0.0 */ + + return 24; /* Class C - 255.255.255.0 */ +} + +gboolean +nm_utils_ip_is_site_local (int addr_family, + const void *address) +{ + in_addr_t addr4; + + switch (addr_family) { + case AF_INET: + /* RFC1918 private addresses + * 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 */ + addr4 = ntohl (*((const in_addr_t *) address)); + return (addr4 & 0xff000000) == 0x0a000000 + || (addr4 & 0xfff00000) == 0xac100000 + || (addr4 & 0xffff0000) == 0xc0a80000; + case AF_INET6: + return IN6_IS_ADDR_SITELOCAL (address); + default: + g_return_val_if_reached (FALSE); + } +} + +/*****************************************************************************/ + +gboolean +nm_utils_parse_inaddr (const char *text, + int family, + char **out_addr) +{ + union { + in_addr_t v4; + struct in6_addr v6; + } addrbin; + char addrstr_buf[MAX (INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; + + g_return_val_if_fail (text, FALSE); + + if (family == AF_UNSPEC) + family = strchr (text, ':') ? AF_INET6 : AF_INET; + else + g_return_val_if_fail (NM_IN_SET (family, AF_INET, AF_INET6), FALSE); + + if (inet_pton (family, text, &addrbin) != 1) + return FALSE; + + NM_SET_OUT (out_addr, g_strdup (inet_ntop (family, &addrbin, addrstr_buf, sizeof (addrstr_buf)))); + return TRUE; +} + +gboolean +nm_utils_parse_inaddr_prefix (const char *text, + int family, + char **out_addr, + int *out_prefix) +{ + gs_free char *addrstr_free = NULL; + int prefix = -1; + const char *slash; + const char *addrstr; + union { + in_addr_t v4; + struct in6_addr v6; + } addrbin; + char addrstr_buf[MAX (INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; + + g_return_val_if_fail (text, FALSE); + + if (family == AF_UNSPEC) + family = strchr (text, ':') ? AF_INET6 : AF_INET; + else + g_return_val_if_fail (NM_IN_SET (family, AF_INET, AF_INET6), FALSE); + + slash = strchr (text, '/'); + if (slash) + addrstr = addrstr_free = g_strndup (text, slash - text); + else + addrstr = text; + + if (inet_pton (family, addrstr, &addrbin) != 1) + return FALSE; + + if (slash) { + prefix = _nm_utils_ascii_str_to_int64 (slash + 1, 10, + 0, + family == AF_INET ? 32 : 128, + -1); + if (prefix == -1) + return FALSE; + } + + NM_SET_OUT (out_addr, g_strdup (inet_ntop (family, &addrbin, addrstr_buf, sizeof (addrstr_buf)))); + NM_SET_OUT (out_prefix, prefix); + return TRUE; +} + +/*****************************************************************************/ + /* _nm_utils_ascii_str_to_int64: * * A wrapper for g_ascii_strtoll, that checks whether the whole string diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index 6c8eb4dac2..dc17fb269f 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -143,6 +143,23 @@ char **_nm_utils_strv_cleanup (char **strv, /*****************************************************************************/ +guint32 _nm_utils_ip4_prefix_to_netmask (guint32 prefix); +guint32 _nm_utils_ip4_get_default_prefix (guint32 ip); + +gboolean nm_utils_ip_is_site_local (int addr_family, + const void *address); + +/*****************************************************************************/ + +gboolean nm_utils_parse_inaddr (const char *text, + int family, + char **out_addr); + +gboolean nm_utils_parse_inaddr_prefix (const char *text, + int family, + char **out_addr, + int *out_prefix); + gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback); gint _nm_utils_ascii_str_to_bool (const char *str, diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 95c95479d8..8001e74b08 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -8385,7 +8385,7 @@ start_sharing (NMDevice *self, NMIP4Config *config) if (!ip4_addr || !ip4_addr->address) return FALSE; - netmask = nm_utils_ip4_prefix_to_netmask (ip4_addr->plen); + netmask = _nm_utils_ip4_prefix_to_netmask (ip4_addr->plen); if (!inet_ntop (AF_INET, &netmask, str_mask, sizeof (str_mask))) return FALSE; diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c index 168c13192e..f66c5880e4 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/dhcp/nm-dhcp-dhclient-utils.c @@ -782,7 +782,7 @@ nm_dhcp_dhclient_read_lease_ip_configs (NMDedupMultiIndex *multi_idx, /* Get default netmask for the IP according to appropriate class. */ if (!address.plen) - address.plen = nm_utils_ip4_get_default_prefix (address.address); + address.plen = _nm_utils_ip4_get_default_prefix (address.address); address.timestamp = now_monotonic_ts; address.lifetime = address.preferred = expiry; diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c index 520046395a..f544a644bc 100644 --- a/src/dhcp/nm-dhcp-utils.c +++ b/src/dhcp/nm-dhcp-utils.c @@ -317,8 +317,8 @@ process_classful_routes (const char *iface, The Static Routes option (option 33) does not provide a subnet mask for each route - it is assumed that the subnet mask is implicit in whatever network number is specified in each route entry */ - route.plen = nm_utils_ip4_get_default_prefix (rt_addr); - if (rt_addr & ~nm_utils_ip4_prefix_to_netmask (route.plen)) { + route.plen = _nm_utils_ip4_get_default_prefix (rt_addr); + if (rt_addr & ~_nm_utils_ip4_prefix_to_netmask (route.plen)) { /* RFC 943: target not "this network"; using host routing */ route.plen = 32; } @@ -418,7 +418,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx, _LOG2I (LOGD_DHCP4, iface, " plen %d (%s)", plen, str); } else { /* Get default netmask for the IP according to appropriate class. */ - plen = nm_utils_ip4_get_default_prefix (addr); + plen = _nm_utils_ip4_get_default_prefix (addr); _LOG2I (LOGD_DHCP4, iface, " plen %d (default)", plen); } nm_platform_ip4_address_set_addr (&address, addr, plen); diff --git a/src/dnsmasq/nm-dnsmasq-utils.c b/src/dnsmasq/nm-dnsmasq-utils.c index cee52c3def..382b3aeb49 100644 --- a/src/dnsmasq/nm-dnsmasq-utils.c +++ b/src/dnsmasq/nm-dnsmasq-utils.c @@ -65,7 +65,7 @@ nm_dnsmasq_utils_get_range (const NMPlatformIP4Address *addr, prefix = 24; } - netmask = nm_utils_ip4_prefix_to_netmask (prefix); + netmask = _nm_utils_ip4_prefix_to_netmask (prefix); /* treat addresses in host-order from here on. */ netmask = ntohl (netmask); diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 9a3efd5dce..5cb53982e0 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -278,7 +278,7 @@ nm_utils_ipx_address_clear_host_address (int family, gpointer dst, gconstpointer in_addr_t nm_utils_ip4_address_clear_host_address (in_addr_t addr, guint8 plen) { - return addr & nm_utils_ip4_prefix_to_netmask (plen); + return addr & _nm_utils_ip4_prefix_to_netmask (plen); } /* nm_utils_ip6_address_clear_host_address: diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 8740261f3a..ad939d0008 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -61,7 +61,7 @@ nm_ip_config_obj_id_equal_ip4_address (const NMPlatformIP4Address *a, { return a->address == b->address && a->plen == b->plen - && ((a->peer_address ^ b->peer_address) & nm_utils_ip4_prefix_to_netmask (a->plen)) == 0; + && ((a->peer_address ^ b->peer_address) & _nm_utils_ip4_prefix_to_netmask (a->plen)) == 0; } gboolean @@ -589,8 +589,8 @@ _addresses_sort_cmp (gconstpointer a, gconstpointer b, gpointer user_data) * subnet (and thus also the primary/secondary role) is * preserved. */ - n1 = a1->address & nm_utils_ip4_prefix_to_netmask (a1->plen); - n2 = a2->address & nm_utils_ip4_prefix_to_netmask (a2->plen); + n1 = a1->address & _nm_utils_ip4_prefix_to_netmask (a1->plen); + n2 = a2->address & _nm_utils_ip4_prefix_to_netmask (a2->plen); return memcmp (&n1, &n2, sizeof (guint32)); } @@ -2698,7 +2698,7 @@ nm_ip4_config_hash (const NMIP4Config *self, GChecksum *sum, gboolean dns_only) nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, self, &address) { hash_u32 (sum, address->address); hash_u32 (sum, address->plen); - hash_u32 (sum, address->peer_address & nm_utils_ip4_prefix_to_netmask (address->plen)); + hash_u32 (sum, address->peer_address & _nm_utils_ip4_prefix_to_netmask (address->plen)); } nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, self, &route) { diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 1512b4f090..9ecfaaa704 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -1071,7 +1071,7 @@ ipx_address_delete (NMPlatform *platform, || (addr && address->address != *((guint32 *) addr)) || (plen && address->plen != *plen) || ( peer_addr - && (((peer_addr_i ^ address->peer_address) & nm_utils_ip4_prefix_to_netmask (address->plen)) != 0))) + && (((peer_addr_i ^ address->peer_address) & _nm_utils_ip4_prefix_to_netmask (address->plen)) != 0))) continue; } else { const NMPlatformIP6Address *address = NMP_OBJECT_CAST_IP6_ADDRESS (o); diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index ff7fc71b6e..96cd99d658 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2543,7 +2543,7 @@ _nl_msg_new_address (int nlmsg_type, && *((in_addr_t *) address) != 0) { in_addr_t broadcast; - broadcast = *((in_addr_t *) address) | ~nm_utils_ip4_prefix_to_netmask (plen); + broadcast = *((in_addr_t *) address) | ~_nm_utils_ip4_prefix_to_netmask (plen); NLA_PUT (msg, IFA_BROADCAST, addr_len, &broadcast); } diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 9a350861a6..8542c945bd 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -3190,7 +3190,7 @@ ip4_addr_subnets_build_index (const GPtrArray *addresses, p_address = &addresses->pdata[i]; address = NMP_OBJECT_CAST_IP4_ADDRESS (addresses->pdata[i]); - net = address->address & nm_utils_ip4_prefix_to_netmask (address->plen); + net = address->address & _nm_utils_ip4_prefix_to_netmask (address->plen); if (!g_hash_table_lookup_extended (subnets, GUINT_TO_POINTER (net), NULL, &p)) { g_hash_table_insert (subnets, GUINT_TO_POINTER (net), p_address); continue; @@ -3251,7 +3251,7 @@ ip4_addr_subnets_is_secondary (const NMPObject *address, a = NMP_OBJECT_CAST_IP4_ADDRESS (address); - net = a->address & nm_utils_ip4_prefix_to_netmask (a->plen); + net = a->address & _nm_utils_ip4_prefix_to_netmask (a->plen); p = g_hash_table_lookup (subnets, GUINT_TO_POINTER (net)); nm_assert (p); if (!ip4_addr_subnets_is_plain_address (addresses, p)) { diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index 9d2a2bad5b..9c8845a4d5 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -740,7 +740,7 @@ _vt_cmd_plobj_to_string_id_##type (const NMPlatformObject *_obj, char *buf, gsiz _vt_cmd_plobj_to_string_id (link, NMPlatformLink, "%d", obj->ifindex); _vt_cmd_plobj_to_string_id (ip4_address, NMPlatformIP4Address, "%d: %s/%d%s%s", obj->ifindex, nm_utils_inet4_ntop ( obj->address, buf1), obj->plen, obj->peer_address != obj->address ? "," : "", - obj->peer_address != obj->address ? nm_utils_inet4_ntop (obj->peer_address & nm_utils_ip4_prefix_to_netmask (obj->plen), buf2) : ""); + obj->peer_address != obj->address ? nm_utils_inet4_ntop (obj->peer_address & _nm_utils_ip4_prefix_to_netmask (obj->plen), buf2) : ""); _vt_cmd_plobj_to_string_id (ip6_address, NMPlatformIP6Address, "%d: %s", obj->ifindex, nm_utils_inet6_ntop (&obj->address, buf1)); guint @@ -1102,7 +1102,7 @@ _vt_cmd_plobj_id_hash (ip4_address, NMPlatformIP4Address, { hash = NM_HASH_COMBINE (hash, obj->plen); hash = NM_HASH_COMBINE (hash, obj->address); /* for IPv4 we must also consider the net-part of the peer-address (IFA_ADDRESS) */ - hash = NM_HASH_COMBINE (hash, (obj->peer_address & nm_utils_ip4_prefix_to_netmask (obj->plen))); + hash = NM_HASH_COMBINE (hash, (obj->peer_address & _nm_utils_ip4_prefix_to_netmask (obj->plen))); }) _vt_cmd_plobj_id_hash (ip6_address, NMPlatformIP6Address, { hash = (guint) 2907861637u; diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index d605acf81e..ae720b9803 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -399,7 +399,7 @@ read_full_ip4_address (shvarFile *ifcfg, prefix = nm_ip_address_get_prefix (base_addr); else { /* Try to autodetermine the prefix for the address' class */ - prefix = nm_utils_ip4_get_default_prefix (ipaddr); + prefix = _nm_utils_ip4_get_default_prefix (ipaddr); PARSE_WARNING ("missing %s, assuming %s/%d", prefix_tag, nm_utils_inet4_ntop (ipaddr, inet_buf), prefix); } } @@ -588,7 +588,7 @@ read_one_ip4_route (shvarFile *ifcfg, return FALSE; if (has_key) { prefix = nm_utils_ip4_netmask_to_prefix (netmask); - if (prefix == 0 || netmask != nm_utils_ip4_prefix_to_netmask (prefix)) { + if (prefix == 0 || netmask != _nm_utils_ip4_prefix_to_netmask (prefix)) { g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "Invalid IP4 netmask '%s' \"%s\"", netmask_tag, nm_utils_inet4_ntop (netmask, inet_buf)); return FALSE; diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index c2c3786330..c1b927aadf 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -2151,7 +2151,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) char buf[INET_ADDRSTRLEN]; svSetValueStr (ifcfg, tag, - nm_utils_inet4_ntop (nm_utils_ip4_prefix_to_netmask (prefix), buf)); + nm_utils_inet4_ntop (_nm_utils_ip4_prefix_to_netmask (prefix), buf)); } else svUnsetValue (ifcfg, tag); @@ -2293,7 +2293,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) svSetValueStr (routefile, addr_key, nm_ip_route_get_dest (route)); memset (buf, 0, sizeof (buf)); - netmask = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); + netmask = _nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); inet_ntop (AF_INET, (const void *) &netmask, &buf[0], sizeof (buf)); svSetValueStr (routefile, netmask_key, &buf[0]); |