platform: add nm_platform_route_type_is_nodev() helper

(cherry picked from commit 7ad14b86f8)
This commit is contained in:
Thomas Haller 2022-02-07 18:50:54 +01:00
parent 2394a93944
commit bd08f8e81c
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 32 additions and 0 deletions

View file

@ -748,6 +748,31 @@ test_platform_ip_address_pretty_sort_cmp(gconstpointer test_data)
/*****************************************************************************/
static void
test_route_type_is_nodev(void)
{
int i;
for (i = -1; i <= 257; i++) {
gboolean is_nodev;
switch ((guint8) i) {
case RTN_BLACKHOLE:
case RTN_UNREACHABLE:
case RTN_PROHIBIT:
is_nodev = TRUE;
break;
default:
is_nodev = FALSE;
break;
}
g_assert_cmpint(is_nodev, ==, nm_platform_route_type_is_nodev(i));
}
}
/*****************************************************************************/
NMTST_DEFINE();
int
@ -767,6 +792,7 @@ main(int argc, char **argv)
g_test_add_data_func("/general/platform_ip_address_pretty_sort_cmp/6/2",
GINT_TO_POINTER(2),
test_platform_ip_address_pretty_sort_cmp);
g_test_add_func("/general/test_route_type_is_nodev", test_route_type_is_nodev);
return g_test_run();
}

View file

@ -1408,6 +1408,12 @@ _nm_platform_link_get_inet6_addr_gen_mode(const NMPlatformLink *pllink)
return _nm_platform_uint8_inv(pllink->inet6_addr_gen_mode_inv);
}
static inline gboolean
nm_platform_route_type_is_nodev(guint8 type)
{
return NM_IN_SET(type, 6 /* RTN_BLACKHOLE */, 7 /* RTN_UNREACHABLE */, 8 /* RTN_PROHIBIT */);
}
/**
* nm_platform_route_type_coerce:
* @table: the route type, in its original value.