glib-aux: replace nm_ip4_addr_is_localhost() by nm_utils_ip4_address_is_loopback()
This was duplicated.
This commit is contained in:
@@ -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,
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user