summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-07-27 10:48:09 +0200
committerThomas Haller <thaller@redhat.com>2022-07-28 13:08:31 +0200
commit5806db7f4ec32606e0ff64a9b5fe18fa88cd63f2 (patch)
tree4bae76e282bc57710c3712afe2a3aeb6af92bc64
parentfdebcfa0a0e32a15bce03e379a734ca5bac9dd89 (diff)
downloadNetworkManager-th/misc-aux.tar.gz
glib-aux: replace nm_ip4_addr_is_localhost() by nm_utils_ip4_address_is_loopback()th/misc-aux
This was duplicated.
-rw-r--r--src/core/dhcp/nm-dhcp-nettools.c2
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h6
-rw-r--r--src/libnm-glib-aux/tests/test-shared-general.c17
3 files changed, 10 insertions, 15 deletions
diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c
index 469d65fc59..05b7b52e95 100644
--- a/src/core/dhcp/nm-dhcp-nettools.c
+++ b/src/core/dhcp/nm-dhcp-nettools.c
@@ -343,7 +343,7 @@ lease_parse_address_list(NDhcp4ClientLease *lease,
switch (option) {
case NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER:
- if (addr == 0 || nm_ip4_addr_is_localhost(addr)) {
+ if (addr == 0 || nm_utils_ip4_address_is_loopback(addr)) {
/* Skip localhost addresses, like also networkd does.
* See https://github.com/systemd/systemd/issues/4524. */
nm_dhcp_lease_log_invalid_option(iface,
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index c59a40e47b..1584042ac5 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -326,12 +326,6 @@ gboolean nm_ip_addr_set_from_untrusted(int addr_family,
gboolean
nm_ip_addr_set_from_variant(int addr_family, gpointer dst, GVariant *variant, int *out_addr_family);
-static inline gboolean
-nm_ip4_addr_is_localhost(in_addr_t addr4)
-{
- return (addr4 & htonl(0xFF000000u)) == htonl(0x7F000000u);
-}
-
static inline gconstpointer
nm_ip_addr_from_packed_array(int addr_family, gconstpointer ipaddr_arr, gsize idx)
{
diff --git a/src/libnm-glib-aux/tests/test-shared-general.c b/src/libnm-glib-aux/tests/test-shared-general.c
index 12d412c9b4..a4817e1973 100644
--- a/src/libnm-glib-aux/tests/test-shared-general.c
+++ b/src/libnm-glib-aux/tests/test-shared-general.c
@@ -251,14 +251,14 @@ test_nm_strndup_a(void)
/*****************************************************************************/
static void
-test_nm_ip4_addr_is_localhost(void)
+test_nm_utils_ip4_address_is_loopback(void)
{
- g_assert(nm_ip4_addr_is_localhost(nmtst_inet4_from_string("127.0.0.0")));
- g_assert(nm_ip4_addr_is_localhost(nmtst_inet4_from_string("127.0.0.1")));
- g_assert(nm_ip4_addr_is_localhost(nmtst_inet4_from_string("127.5.0.1")));
- g_assert(!nm_ip4_addr_is_localhost(nmtst_inet4_from_string("126.5.0.1")));
- g_assert(!nm_ip4_addr_is_localhost(nmtst_inet4_from_string("128.5.0.1")));
- g_assert(!nm_ip4_addr_is_localhost(nmtst_inet4_from_string("129.5.0.1")));
+ g_assert(nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("127.0.0.0")));
+ g_assert(nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("127.0.0.1")));
+ g_assert(nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("127.5.0.1")));
+ g_assert(!nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("126.5.0.1")));
+ g_assert(!nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("128.5.0.1")));
+ g_assert(!nm_utils_ip4_address_is_loopback(nmtst_inet4_from_string("129.5.0.1")));
}
/*****************************************************************************/
@@ -2215,7 +2215,8 @@ main(int argc, char **argv)
g_test_add_func("/general/test_nm_make_strv", test_make_strv);
g_test_add_func("/general/test_nm_strdup_int", test_nm_strdup_int);
g_test_add_func("/general/test_nm_strndup_a", test_nm_strndup_a);
- g_test_add_func("/general/test_nm_ip4_addr_is_localhost", test_nm_ip4_addr_is_localhost);
+ g_test_add_func("/general/test_nm_utils_ip4_address_is_loopback",
+ test_nm_utils_ip4_address_is_loopback);
g_test_add_func("/general/test_nm_utils_ip4_prefix_to_netmask",
test_nm_utils_ip4_prefix_to_netmask);
g_test_add_func("/general/test_unaligned", test_unaligned);