mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 14:38:09 +02:00
core: cleanup IPv4/IPv6 checks using NM_IS_IPv4()
- we commonly use "int addr_family" as parameters to functions. But then inside the function, we often need to do something for IPv4 or IPv6 specifically. Instead of having lots of redundant "if (addr_family == AF_INET)" checks, prefer to have a variable IS_IPv4 and/or use NM_IS_IPv4() macro. - don't make the "IS_IPv4" variable a gboolean but an int. gboolean is a typedef for int, so it's in practice exactly the same. However, we use "IS_IPv4" as index to arrays of length 2, where at position "1" we have the value related to IPv4. Using a gboolean to index an array is a bit odd. Maybe a "int" is preferable here. This is more about doing consistently one or the other. There are no strong reasons to prefer gboolean or int.
This commit is contained in:
parent
6767ba1205
commit
6c9a289451
8 changed files with 91 additions and 116 deletions
|
|
@ -152,7 +152,7 @@ nm_utils_get_ip_config_method(NMConnection *connection, int addr_family)
|
|||
|
||||
s_con = nm_connection_get_setting_connection(connection);
|
||||
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
g_return_val_if_fail(s_con != NULL, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
|
||||
|
||||
s_ip = nm_connection_get_setting_ip4_config(connection);
|
||||
|
|
@ -164,19 +164,15 @@ nm_utils_get_ip_config_method(NMConnection *connection, int addr_family)
|
|||
return method;
|
||||
}
|
||||
|
||||
if (addr_family == AF_INET6) {
|
||||
g_return_val_if_fail(s_con != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
|
||||
g_return_val_if_fail(s_con != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
|
||||
|
||||
s_ip = nm_connection_get_setting_ip6_config(connection);
|
||||
if (!s_ip)
|
||||
return NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
|
||||
s_ip = nm_connection_get_setting_ip6_config(connection);
|
||||
if (!s_ip)
|
||||
return NM_SETTING_IP6_CONFIG_METHOD_IGNORE;
|
||||
|
||||
method = nm_setting_ip_config_get_method(s_ip);
|
||||
g_return_val_if_fail(method != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
|
||||
return method;
|
||||
}
|
||||
|
||||
g_return_val_if_reached("" /* bogus */);
|
||||
method = nm_setting_ip_config_get_method(s_ip);
|
||||
g_return_val_if_fail(method != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
|
||||
return method;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
@ -204,7 +200,7 @@ nm_utils_connection_has_default_route(NMConnection *connection,
|
|||
}
|
||||
|
||||
method = nm_utils_get_ip_config_method(connection, addr_family);
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
if (NM_IN_STRSET(method,
|
||||
NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
|
||||
NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
|
||||
|
|
@ -1312,7 +1308,7 @@ nm_utils_ip_route_attribute_to_platform(int addr_family,
|
|||
else
|
||||
r->table_coerced = nm_platform_route_table_coerce(table ?: (route_table ?: RT_TABLE_MAIN));
|
||||
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
guint8 scope;
|
||||
|
||||
GET_ATTR(NM_IP_ROUTE_ATTRIBUTE_TOS, r4->tos, BYTE, byte, 0);
|
||||
|
|
@ -1338,14 +1334,14 @@ nm_utils_ip_route_attribute_to_platform(int addr_family,
|
|||
if ((variant = nm_ip_route_get_attribute(s_route, NM_IP_ROUTE_ATTRIBUTE_SRC))
|
||||
&& g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
|
||||
if (inet_pton(addr_family, g_variant_get_string(variant, NULL), &addr) == 1) {
|
||||
if (addr_family == AF_INET)
|
||||
if (NM_IS_IPv4(addr_family))
|
||||
r4->pref_src = addr.addr4;
|
||||
else
|
||||
r6->pref_src = addr.addr6;
|
||||
}
|
||||
}
|
||||
|
||||
if (addr_family == AF_INET6
|
||||
if (!NM_IS_IPv4(addr_family)
|
||||
&& (variant = nm_ip_route_get_attribute(s_route, NM_IP_ROUTE_ATTRIBUTE_FROM))
|
||||
&& g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
|
||||
int prefix;
|
||||
|
|
@ -1392,7 +1388,7 @@ nm_utils_ip_addresses_to_dbus(int addr_family,
|
|||
GVariant ** out_address_data,
|
||||
GVariant ** out_addresses)
|
||||
{
|
||||
const gboolean IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
GVariantBuilder builder_data;
|
||||
GVariantBuilder builder_legacy;
|
||||
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
|
@ -1516,7 +1512,7 @@ nm_utils_ip_routes_to_dbus(int addr_family,
|
|||
GVariant ** out_route_data,
|
||||
GVariant ** out_routes)
|
||||
{
|
||||
const gboolean IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
NMDedupMultiIter iter;
|
||||
const NMPObject *obj;
|
||||
GVariantBuilder builder_data;
|
||||
|
|
|
|||
|
|
@ -1280,7 +1280,7 @@ _prop_get_ipvx_route_table(NMDevice *self, int addr_family)
|
|||
|
||||
/* the route table setting affects how we sync routes. We shall
|
||||
* not change it while the device is active, hence, cache it. */
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
if (priv->v4_route_table_initialized)
|
||||
return priv->v4_route_table;
|
||||
} else {
|
||||
|
|
@ -1298,7 +1298,7 @@ _prop_get_ipvx_route_table(NMDevice *self, int addr_family)
|
|||
gint64 v;
|
||||
|
||||
v = nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA,
|
||||
addr_family == AF_INET
|
||||
NM_IS_IPv4(addr_family)
|
||||
? NM_CON_DEFAULT("ipv4.route-table")
|
||||
: NM_CON_DEFAULT("ipv6.route-table"),
|
||||
self,
|
||||
|
|
@ -1334,7 +1334,7 @@ _prop_get_ipvx_route_table(NMDevice *self, int addr_family)
|
|||
if (klass->coerce_route_table)
|
||||
route_table = klass->coerce_route_table(self, addr_family, route_table, is_user_config);
|
||||
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
priv->v4_route_table_initialized = TRUE;
|
||||
priv->v4_route_table = route_table;
|
||||
} else {
|
||||
|
|
@ -1344,7 +1344,7 @@ _prop_get_ipvx_route_table(NMDevice *self, int addr_family)
|
|||
|
||||
_LOGT(LOGD_DEVICE,
|
||||
"ipv%c.route-table = %u%s",
|
||||
addr_family == AF_INET ? '4' : '6',
|
||||
nm_utils_addr_family_to_char(addr_family),
|
||||
(guint)(route_table ?: RT_TABLE_MAIN),
|
||||
route_table != 0u ? "" : " (policy routing not enabled)");
|
||||
|
||||
|
|
@ -1423,7 +1423,7 @@ _prop_get_ipvx_dhcp_timeout(NMDevice *self, int addr_family)
|
|||
goto out;
|
||||
|
||||
timeout = nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA,
|
||||
addr_family == AF_INET
|
||||
NM_IS_IPv4(addr_family)
|
||||
? NM_CON_DEFAULT("ipv4.dhcp-timeout")
|
||||
: NM_CON_DEFAULT("ipv6.dhcp-timeout"),
|
||||
self,
|
||||
|
|
@ -1466,6 +1466,7 @@ _prop_get_ipvx_dhcp_iaid(NMDevice * self,
|
|||
NMConnection *connection,
|
||||
gboolean * out_is_explicit)
|
||||
{
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
NMSettingIPConfig *s_ip;
|
||||
const char * iaid_str;
|
||||
gs_free char * iaid_str_free = NULL;
|
||||
|
|
@ -1479,8 +1480,7 @@ _prop_get_ipvx_dhcp_iaid(NMDevice * self,
|
|||
if (!iaid_str) {
|
||||
iaid_str_free = nm_config_data_get_connection_default(
|
||||
NM_CONFIG_GET_DATA,
|
||||
addr_family == AF_INET ? NM_CON_DEFAULT("ipv4.dhcp-iaid")
|
||||
: NM_CON_DEFAULT("ipv6.dhcp-iaid"),
|
||||
IS_IPv4 ? NM_CON_DEFAULT("ipv4.dhcp-iaid") : NM_CON_DEFAULT("ipv6.dhcp-iaid"),
|
||||
self);
|
||||
iaid_str = iaid_str_free;
|
||||
if (!iaid_str) {
|
||||
|
|
@ -1564,8 +1564,7 @@ _prop_get_ipvx_dhcp_iaid(NMDevice * self,
|
|||
|
||||
out_fail:
|
||||
nm_assert(fail_reason);
|
||||
_LOGW(addr_family == AF_INET ? (LOGD_DEVICE | LOGD_DHCP4 | LOGD_IP4)
|
||||
: (LOGD_DEVICE | LOGD_DHCP6 | LOGD_IP6),
|
||||
_LOGW(LOGD_DEVICE | LOGD_DHCPX(IS_IPv4) | LOGD_IPX(IS_IPv4),
|
||||
"ipv%c.dhcp-iaid: failure to generate IAID: %s. Using interface-name based IAID",
|
||||
nm_utils_addr_family_to_char(addr_family),
|
||||
fail_reason);
|
||||
|
|
@ -1573,8 +1572,7 @@ out_fail:
|
|||
iface = nm_device_get_ip_iface(self);
|
||||
iaid = nm_utils_create_dhcp_iaid(TRUE, (const guint8 *) iface, strlen(iface));
|
||||
out_good:
|
||||
_LOGD(addr_family == AF_INET ? (LOGD_DEVICE | LOGD_DHCP4 | LOGD_IP4)
|
||||
: (LOGD_DEVICE | LOGD_DHCP6 | LOGD_IP6),
|
||||
_LOGD(LOGD_DEVICE | LOGD_DHCPX(IS_IPv4) | LOGD_IPX(IS_IPv4),
|
||||
"ipv%c.dhcp-iaid: using %u (0x%08x) IAID (str: '%s', explicit %d)",
|
||||
nm_utils_addr_family_to_char(addr_family),
|
||||
iaid,
|
||||
|
|
@ -1608,8 +1606,8 @@ _prop_get_ipvx_dhcp_hostname_flags(NMDevice *self, int addr_family)
|
|||
|
||||
flags = nm_config_data_get_connection_default_int64(
|
||||
NM_CONFIG_GET_DATA,
|
||||
addr_family == AF_INET ? NM_CON_DEFAULT("ipv4.dhcp-hostname-flags")
|
||||
: NM_CON_DEFAULT("ipv6.dhcp-hostname-flags"),
|
||||
NM_IS_IPv4(addr_family) ? NM_CON_DEFAULT("ipv4.dhcp-hostname-flags")
|
||||
: NM_CON_DEFAULT("ipv6.dhcp-hostname-flags"),
|
||||
self,
|
||||
0,
|
||||
NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS,
|
||||
|
|
@ -1617,9 +1615,9 @@ _prop_get_ipvx_dhcp_hostname_flags(NMDevice *self, int addr_family)
|
|||
|
||||
if (!_nm_utils_validate_dhcp_hostname_flags(flags, addr_family, &error)) {
|
||||
_LOGW(LOGD_DEVICE,
|
||||
"invalid global default value 0x%x for ipv%d.%s: %s",
|
||||
"invalid global default value 0x%x for ipv%c.%s: %s",
|
||||
(guint) flags,
|
||||
addr_family == AF_INET ? 4 : 6,
|
||||
nm_utils_addr_family_to_char(addr_family),
|
||||
NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS,
|
||||
error->message);
|
||||
flags = NM_DHCP_HOSTNAME_FLAG_NONE;
|
||||
|
|
@ -1628,7 +1626,7 @@ _prop_get_ipvx_dhcp_hostname_flags(NMDevice *self, int addr_family)
|
|||
if (flags != NM_DHCP_HOSTNAME_FLAG_NONE)
|
||||
return flags;
|
||||
|
||||
if (addr_family == AF_INET)
|
||||
if (NM_IS_IPv4(addr_family))
|
||||
return NM_DHCP_HOSTNAME_FLAGS_FQDN_DEFAULT_IP4;
|
||||
else
|
||||
return NM_DHCP_HOSTNAME_FLAGS_FQDN_DEFAULT_IP6;
|
||||
|
|
@ -2324,8 +2322,8 @@ nm_device_ip_config_new(NMDevice *self, int addr_family)
|
|||
{
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
return addr_family == AF_INET ? (gpointer) nm_device_ip4_config_new(self)
|
||||
: (gpointer) nm_device_ip6_config_new(self);
|
||||
return NM_IS_IPv4(addr_family) ? (gpointer) nm_device_ip4_config_new(self)
|
||||
: (gpointer) nm_device_ip6_config_new(self);
|
||||
}
|
||||
|
||||
NML3ConfigData *
|
||||
|
|
@ -2740,7 +2738,7 @@ static void
|
|||
_set_ip_state(NMDevice *self, int addr_family, NMDeviceIPState new_state)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
|
|
@ -2761,7 +2759,7 @@ _set_ip_state(NMDevice *self, int addr_family, NMDeviceIPState new_state)
|
|||
*
|
||||
* This is not documented/guaranteed behavior, but seems to make sense for now. */
|
||||
_active_connection_set_state_flags(self,
|
||||
addr_family == AF_INET
|
||||
NM_IS_IPv4(addr_family)
|
||||
? NM_ACTIVATION_STATE_FLAG_IP4_READY
|
||||
: NM_ACTIVATION_STATE_FLAG_IP6_READY);
|
||||
}
|
||||
|
|
@ -3545,7 +3543,7 @@ static gboolean
|
|||
default_route_metric_penalty_detect(NMDevice *self, int addr_family)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
/* currently we don't differentiate between IPv4 and IPv6 when detecting
|
||||
* connectivity. */
|
||||
|
|
@ -3561,10 +3559,8 @@ default_route_metric_penalty_get(NMDevice *self, int addr_family)
|
|||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
if (addr_family == AF_INET ? priv->default_route_metric_penalty_ip4_has
|
||||
: priv->default_route_metric_penalty_ip6_has)
|
||||
if (NM_IS_IPv4(addr_family) ? priv->default_route_metric_penalty_ip4_has
|
||||
: priv->default_route_metric_penalty_ip6_has)
|
||||
return 20000;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -3598,8 +3594,8 @@ nm_device_get_route_metric(NMDevice *self, int addr_family)
|
|||
/* use the current NMConfigData, which makes this configuration reloadable.
|
||||
* Note that that means that the route-metric might change between SIGHUP.
|
||||
* You must cache the returned value if that is a problem. */
|
||||
property = addr_family == AF_INET ? NM_CON_DEFAULT("ipv4.route-metric")
|
||||
: NM_CON_DEFAULT("ipv6.route-metric");
|
||||
property = NM_IS_IPv4(addr_family) ? NM_CON_DEFAULT("ipv4.route-metric")
|
||||
: NM_CON_DEFAULT("ipv6.route-metric");
|
||||
route_metric = nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA,
|
||||
property,
|
||||
self,
|
||||
|
|
@ -3640,7 +3636,7 @@ _get_route_table_sync_mode_stateful(NMDevice *self, int addr_family)
|
|||
if (!all_sync_now) {
|
||||
/* If there's a local route switch to all-sync in order
|
||||
* to properly manage the local table */
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
const NMPlatformIP4Route *route;
|
||||
|
||||
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->con_ip_config_4, &route) {
|
||||
|
|
@ -3671,13 +3667,13 @@ _get_route_table_sync_mode_stateful(NMDevice *self, int addr_family)
|
|||
* The purpose of this is to support reapply of route-table (and thus the
|
||||
* all-sync mode). If reapply toggles from all-sync to no-all-sync, we must
|
||||
* sync one last time. */
|
||||
if (addr_family == AF_INET)
|
||||
if (NM_IS_IPv4(addr_family))
|
||||
all_sync_eff = priv->v4_route_table_all_sync_before;
|
||||
else
|
||||
all_sync_eff = priv->v6_route_table_all_sync_before;
|
||||
}
|
||||
|
||||
if (addr_family == AF_INET)
|
||||
if (NM_IS_IPv4(addr_family))
|
||||
priv->v4_route_table_all_sync_before = all_sync_now;
|
||||
else
|
||||
priv->v6_route_table_all_sync_before = all_sync_now;
|
||||
|
|
@ -3929,7 +3925,7 @@ concheck_periodic_schedule_do(NMDevice *self, int addr_family, gint64 now_ns)
|
|||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
gboolean periodic_check_disabled = FALSE;
|
||||
gint64 expiry, tdiff;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
/* we always cancel whatever was pending. */
|
||||
if (nm_clear_g_source(&priv->concheck_x[IS_IPv4].p_cur_id))
|
||||
|
|
@ -3984,7 +3980,7 @@ concheck_periodic_schedule_set(NMDevice *self, int addr_family, ConcheckSchedule
|
|||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
gint64 new_expiry, exp_expiry, cur_expiry, tdiff;
|
||||
gint64 now_ns = 0;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
if (priv->concheck_x[IS_IPv4].p_max_interval == 0) {
|
||||
/* periodic check is disabled. Nothing to do. */
|
||||
|
|
@ -4144,7 +4140,7 @@ concheck_update_interval(NMDevice *self, int addr_family, gboolean check_now)
|
|||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
guint new_interval;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
new_interval = nm_connectivity_get_interval(concheck_get_mgr(self));
|
||||
|
||||
|
|
@ -4188,7 +4184,7 @@ concheck_update_state(NMDevice * self,
|
|||
gboolean allow_periodic_bump)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
/* @state is a result of the connectivity check. We only expect a precise
|
||||
* number of possible values. */
|
||||
|
|
@ -4269,14 +4265,14 @@ nm_device_get_effective_ip_config_method(NMDevice *self, int addr_family)
|
|||
NMDeviceClass *klass;
|
||||
NMConnection * connection = nm_device_get_applied_connection(self);
|
||||
const char * method;
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
g_return_val_if_fail(NM_IS_CONNECTION(connection), "" /* bogus */);
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
method = nm_utils_get_ip_config_method(connection, addr_family);
|
||||
|
||||
if ((addr_family == AF_INET && nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
|
||||
|| (addr_family == AF_INET6 && nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_AUTO))) {
|
||||
if ((IS_IPv4 && nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
|
||||
|| (!IS_IPv4 && nm_streq(method, NM_SETTING_IP6_CONFIG_METHOD_AUTO))) {
|
||||
klass = NM_DEVICE_GET_CLASS(self);
|
||||
if (klass->get_auto_ip_config_method) {
|
||||
const char *auto_method;
|
||||
|
|
@ -4293,7 +4289,7 @@ nm_device_get_effective_ip_config_method(NMDevice *self, int addr_family)
|
|||
static void
|
||||
concheck_handle_complete(NMDeviceConnectivityHandle *handle, GError *error)
|
||||
{
|
||||
const gboolean IS_IPv4 = (handle->addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(handle->addr_family);
|
||||
|
||||
/* The moment we invoke the callback, we unlink it. It signals
|
||||
* that @handle is handled -- as far as the callee of callback
|
||||
|
|
@ -4481,7 +4477,7 @@ concheck_start(NMDevice * self,
|
|||
(long long unsigned) handle->seq,
|
||||
is_periodic ? ", periodic-check" : "");
|
||||
|
||||
if (addr_family == AF_INET && !priv->concheck_rp_filter_checked) {
|
||||
if (NM_IS_IPv4(addr_family) && !priv->concheck_rp_filter_checked) {
|
||||
if ((ifname = nm_device_get_ip_iface_from_platform(self))) {
|
||||
gboolean due_to_all;
|
||||
int val;
|
||||
|
|
@ -7647,7 +7643,7 @@ static void
|
|||
activation_source_clear(NMDevice *self, int addr_family)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
if (priv->activation_source_id_x[IS_IPv4] != 0) {
|
||||
_LOGD(LOGD_DEVICE,
|
||||
|
|
@ -7664,7 +7660,7 @@ static gboolean
|
|||
activation_source_handle_cb(NMDevice *self, int addr_family)
|
||||
{
|
||||
NMDevicePrivate * priv;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
ActivationHandleFunc activation_source_func;
|
||||
guint activation_source_id;
|
||||
|
||||
|
|
@ -7714,7 +7710,7 @@ static void
|
|||
activation_source_schedule(NMDevice *self, ActivationHandleFunc func, int addr_family)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
guint new_id = 0;
|
||||
|
||||
if (priv->activation_source_id_x[IS_IPv4] != 0
|
||||
|
|
@ -7757,7 +7753,7 @@ static void
|
|||
activation_source_invoke_sync(NMDevice *self, ActivationHandleFunc func, int addr_family)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
if (priv->activation_source_id_x[IS_IPv4] == 0) {
|
||||
_LOGD(LOGD_DEVICE,
|
||||
|
|
@ -8746,7 +8742,7 @@ ensure_con_ip_config(NMDevice *self, int addr_family)
|
|||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
NMConnection * connection;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
NMIPConfig * con_ip_config;
|
||||
|
||||
if (priv->con_ip_config_x[IS_IPv4])
|
||||
|
|
@ -8823,7 +8819,7 @@ ip_config_merge_and_apply(NMDevice *self, int addr_family, gboolean commit)
|
|||
gboolean ignore_default_routes = FALSE;
|
||||
GSList * iter;
|
||||
const char * ip6_addr_gen_token = NULL;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
if (nm_device_sys_iface_state_is_external(self))
|
||||
commit = FALSE;
|
||||
|
|
@ -9067,7 +9063,7 @@ static gboolean
|
|||
dhcp_grace_period_expired(NMDevice *self, int addr_family)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
priv->dhcp_data_x[IS_IPv4].grace_id = 0;
|
||||
priv->dhcp_data_x[IS_IPv4].grace_pending = FALSE;
|
||||
|
|
@ -9098,7 +9094,7 @@ static gboolean
|
|||
dhcp_grace_period_start(NMDevice *self, int addr_family)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
guint32 timeout;
|
||||
|
||||
/* In any other case (expired lease, assumed connection, etc.),
|
||||
|
|
@ -9422,7 +9418,7 @@ connection_ip_method_requires_carrier(NMConnection *connection,
|
|||
|
||||
method = nm_utils_get_ip_config_method(connection, addr_family);
|
||||
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
NM_SET_OUT(out_ip_enabled, !nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED));
|
||||
return NM_IN_STRSET(method,
|
||||
NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||
|
|
@ -10945,7 +10941,7 @@ ip_requires_slaves(NMDevice *self, int addr_family)
|
|||
|
||||
method = nm_device_get_effective_ip_config_method(self, addr_family);
|
||||
|
||||
if (addr_family == AF_INET)
|
||||
if (NM_IS_IPv4(addr_family))
|
||||
return nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
|
||||
|
||||
/* SLAAC, DHCP, and Link-Local depend on connectivity (and thus slaves)
|
||||
|
|
@ -10962,7 +10958,7 @@ act_stage3_ip_config_start(NMDevice * self,
|
|||
gpointer * out_config,
|
||||
NMDeviceStateReason *out_failure_reason)
|
||||
{
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
NMConnection * connection;
|
||||
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
|
||||
|
|
@ -11452,7 +11448,7 @@ void
|
|||
nm_device_activate_schedule_ip_config_timeout(NMDevice *self, int addr_family)
|
||||
{
|
||||
NMDevicePrivate *priv;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
g_return_if_fail(NM_IS_DEVICE(self));
|
||||
g_return_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6));
|
||||
|
|
@ -11856,12 +11852,10 @@ void
|
|||
nm_device_activate_schedule_ip_config_result(NMDevice *self, int addr_family, NMIPConfig *config)
|
||||
{
|
||||
NMDevicePrivate *priv;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
g_return_if_fail(NM_IS_DEVICE(self));
|
||||
g_return_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6));
|
||||
g_return_if_fail(
|
||||
!config || (addr_family == AF_INET && nm_ip_config_get_addr_family(config) == AF_INET));
|
||||
g_return_if_fail(!config || (IS_IPv4 && nm_ip_config_get_addr_family(config) == AF_INET));
|
||||
|
||||
priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
|
||||
|
|
@ -11883,7 +11877,7 @@ nm_device_activate_schedule_ip_config_result(NMDevice *self, int addr_family, NM
|
|||
NMDeviceIPState
|
||||
nm_device_activate_get_ip_state(NMDevice *self, int addr_family)
|
||||
{
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
g_return_val_if_fail(NM_IS_DEVICE(self), NM_DEVICE_IP_STATE_NONE);
|
||||
g_return_val_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6), NM_DEVICE_IP_STATE_NONE);
|
||||
|
|
@ -12111,7 +12105,7 @@ static void
|
|||
_cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
_set_ip_state(self, addr_family, NM_DEVICE_IP_STATE_NONE);
|
||||
|
||||
|
|
@ -13319,7 +13313,7 @@ nm_device_set_proxy_config(NMDevice *self, const char *pac_url)
|
|||
NMDhcpConfig *
|
||||
nm_device_get_dhcp_config(NMDevice *self, int addr_family)
|
||||
{
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
g_return_val_if_fail(NM_IS_DEVICE(self), NULL);
|
||||
|
||||
|
|
@ -13344,7 +13338,7 @@ nm_device_set_ip_config(NMDevice * self,
|
|||
GPtrArray * ip4_dev_route_blacklist)
|
||||
{
|
||||
NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self);
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
NMIPConfig * old_config;
|
||||
gboolean has_changes = FALSE;
|
||||
gboolean success = TRUE;
|
||||
|
|
@ -13533,7 +13527,7 @@ void
|
|||
nm_device_set_dev2_ip_config(NMDevice *self, int addr_family, NMIPConfig *config)
|
||||
{
|
||||
NMDevicePrivate *priv;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
g_return_if_fail(NM_IS_DEVICE(self));
|
||||
g_return_if_fail(NM_IN_SET(addr_family, AF_INET, AF_INET6));
|
||||
|
|
@ -14083,7 +14077,7 @@ update_ext_ip_config(NMDevice *self, int addr_family, gboolean intersect_configs
|
|||
|
||||
is_up = nm_platform_link_is_up(nm_device_get_platform(self), ifindex);
|
||||
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
g_clear_object(&priv->ext_ip_config_4);
|
||||
priv->ext_ip_config_4 = nm_ip4_config_capture(nm_device_get_multi_index(self),
|
||||
nm_device_get_platform(self),
|
||||
|
|
@ -14132,7 +14126,7 @@ update_ext_ip_config(NMDevice *self, int addr_family, gboolean intersect_configs
|
|||
}
|
||||
|
||||
} else {
|
||||
nm_assert(addr_family == AF_INET6);
|
||||
nm_assert(!NM_IS_IPv4(addr_family));
|
||||
|
||||
g_clear_object(&priv->ext_ip_config_6);
|
||||
g_clear_object(&priv->ext_ip6_config_captured);
|
||||
|
|
@ -14207,13 +14201,13 @@ update_ip_config(NMDevice *self, int addr_family)
|
|||
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
if (addr_family == AF_INET)
|
||||
if (NM_IS_IPv4(addr_family))
|
||||
priv->update_ip_config_completed_v4 = TRUE;
|
||||
else
|
||||
priv->update_ip_config_completed_v6 = TRUE;
|
||||
|
||||
if (update_ext_ip_config(self, addr_family, TRUE)) {
|
||||
if (addr_family == AF_INET) {
|
||||
if (NM_IS_IPv4(addr_family)) {
|
||||
if (priv->ext_ip_config_4)
|
||||
ip_config_merge_and_apply(self, AF_INET, FALSE);
|
||||
} else {
|
||||
|
|
@ -14238,7 +14232,7 @@ static gboolean
|
|||
queued_ip_config_change(NMDevice *self, int addr_family)
|
||||
{
|
||||
NMDevicePrivate *priv;
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
|
||||
g_return_val_if_fail(NM_IS_DEVICE(self), G_SOURCE_REMOVE);
|
||||
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ nm_utils_ip6_route_metric_normalize(guint32 metric)
|
|||
static inline guint32
|
||||
nm_utils_ip_route_metric_normalize(int addr_family, guint32 metric)
|
||||
{
|
||||
return addr_family == AF_INET6 ? nm_utils_ip6_route_metric_normalize(metric) : metric;
|
||||
return NM_IS_IPv4(addr_family) ? metric : nm_utils_ip6_route_metric_normalize(metric);
|
||||
}
|
||||
|
||||
static inline guint32
|
||||
|
|
|
|||
|
|
@ -587,9 +587,7 @@ _route_valid_6(const NMPlatformIP6Route *r)
|
|||
static gboolean
|
||||
_route_valid(int addr_family, gconstpointer r)
|
||||
{
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
return addr_family == AF_INET ? _route_valid_4(r) : _route_valid_6(r);
|
||||
return NM_IS_IPv4(addr_family) ? _route_valid_4(r) : _route_valid_6(r);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -1204,8 +1202,7 @@ nm_l3_config_data_add_address_full(NML3ConfigData * self,
|
|||
nm_assert(!obj_new || NMP_OBJECT_GET_ADDR_FAMILY(obj_new) == addr_family);
|
||||
|
||||
changed = _l3_config_data_add_obj(self->multi_idx,
|
||||
addr_family == AF_INET ? &self->idx_addresses_4
|
||||
: &self->idx_addresses_6,
|
||||
&self->idx_addresses_x[NM_IS_IPv4(addr_family)],
|
||||
self->ifindex,
|
||||
obj_new,
|
||||
(const NMPlatformObject *) pl_new,
|
||||
|
|
@ -1252,7 +1249,7 @@ nm_l3_config_data_add_route_full(NML3ConfigData * self,
|
|||
else
|
||||
self->has_routes_with_type_local_6_set = FALSE;
|
||||
if (_l3_config_data_add_obj(self->multi_idx,
|
||||
addr_family == AF_INET ? &self->idx_routes_4 : &self->idx_routes_6,
|
||||
&self->idx_routes_x[NM_IS_IPv4(addr_family)],
|
||||
self->ifindex,
|
||||
obj_new,
|
||||
(const NMPlatformObject *) pl_new,
|
||||
|
|
|
|||
|
|
@ -223,21 +223,13 @@ const NMDedupMultiHeadEntry *nm_l3_config_data_lookup_objs(const NML3ConfigData
|
|||
static inline const NMDedupMultiHeadEntry *
|
||||
nm_l3_config_data_lookup_addresses(const NML3ConfigData *self, int addr_family)
|
||||
{
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
return nm_l3_config_data_lookup_objs(self,
|
||||
addr_family == AF_INET ? NMP_OBJECT_TYPE_IP4_ADDRESS
|
||||
: NMP_OBJECT_TYPE_IP6_ADDRESS);
|
||||
return nm_l3_config_data_lookup_objs(self, NMP_OBJECT_TYPE_IP_ADDRESS(NM_IS_IPv4(addr_family)));
|
||||
}
|
||||
|
||||
static inline const NMDedupMultiHeadEntry *
|
||||
nm_l3_config_data_lookup_routes(const NML3ConfigData *self, int addr_family)
|
||||
{
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
return nm_l3_config_data_lookup_objs(self,
|
||||
addr_family == AF_INET ? NMP_OBJECT_TYPE_IP4_ROUTE
|
||||
: NMP_OBJECT_TYPE_IP6_ROUTE);
|
||||
return nm_l3_config_data_lookup_objs(self, NMP_OBJECT_TYPE_IP_ROUTE(NM_IS_IPv4(addr_family)));
|
||||
}
|
||||
|
||||
#define nm_l3_config_data_iter_obj_for_each(iter, self, obj, type) \
|
||||
|
|
|
|||
|
|
@ -637,7 +637,7 @@ _l3cfg_externally_removed_objs_track(NML3Cfg *self, const NMPObject *obj, gboole
|
|||
static void
|
||||
_l3cfg_externally_removed_objs_pickup(NML3Cfg *self, int addr_family)
|
||||
{
|
||||
const gboolean IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
NMDedupMultiIter iter;
|
||||
const NMPObject *obj;
|
||||
|
||||
|
|
@ -3233,7 +3233,7 @@ _l3_commit_one(NML3Cfg * self,
|
|||
gboolean changed_combined_l3cd,
|
||||
const NML3ConfigData *l3cd_old)
|
||||
{
|
||||
const gboolean IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
gs_unref_ptrarray GPtrArray *addresses = NULL;
|
||||
gs_unref_ptrarray GPtrArray *routes = NULL;
|
||||
gs_unref_ptrarray GPtrArray *addresses_prune = NULL;
|
||||
|
|
|
|||
|
|
@ -3740,7 +3740,7 @@ _addr_array_clean_expired(int addr_family,
|
|||
}
|
||||
#endif
|
||||
|
||||
if (addr_family == AF_INET6 && NM_FLAGS_HAS(a->n_ifa_flags, IFA_F_TEMPORARY)) {
|
||||
if (!NM_IS_IPv4(addr_family) && NM_FLAGS_HAS(a->n_ifa_flags, IFA_F_TEMPORARY)) {
|
||||
/* temporary addresses are never added explicitly by NetworkManager but
|
||||
* kernel adds them via mngtempaddr flag.
|
||||
*
|
||||
|
|
@ -3981,7 +3981,7 @@ nm_platform_ip_address_sync(NMPlatform *self,
|
|||
GPtrArray * addresses_prune)
|
||||
{
|
||||
const gint32 now = nm_utils_get_monotonic_timestamp_sec();
|
||||
const gboolean IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
gs_unref_hashtable GHashTable *known_addresses_idx = NULL;
|
||||
GPtrArray * plat_addresses;
|
||||
GHashTable * known_subnets = NULL;
|
||||
|
|
@ -4330,7 +4330,7 @@ nm_platform_ip_address_get_prune_list(NMPlatform *self,
|
|||
int ifindex,
|
||||
gboolean exclude_ipv6_temporary_addrs)
|
||||
{
|
||||
const gboolean IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const NMDedupMultiHeadEntry *head_entry;
|
||||
NMPLookup lookup;
|
||||
GPtrArray * result;
|
||||
|
|
@ -4382,10 +4382,7 @@ nm_platform_ip_route_get_prune_list(NMPlatform * self,
|
|||
NM_IP_ROUTE_TABLE_SYNC_MODE_FULL,
|
||||
NM_IP_ROUTE_TABLE_SYNC_MODE_ALL));
|
||||
|
||||
nmp_lookup_init_object(&lookup,
|
||||
addr_family == AF_INET ? NMP_OBJECT_TYPE_IP4_ROUTE
|
||||
: NMP_OBJECT_TYPE_IP6_ROUTE,
|
||||
ifindex);
|
||||
nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_IP_ROUTE(NM_IS_IPv4(addr_family)), ifindex);
|
||||
head_entry = nm_platform_lookup(self, &lookup);
|
||||
if (!head_entry)
|
||||
return NULL;
|
||||
|
|
@ -4441,6 +4438,7 @@ nm_platform_ip_route_sync(NMPlatform *self,
|
|||
GPtrArray * routes_prune,
|
||||
GPtrArray **out_temporary_not_available)
|
||||
{
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const NMPlatformVTableRoute *vt;
|
||||
gs_unref_hashtable GHashTable *routes_idx = NULL;
|
||||
const NMPObject * conf_o;
|
||||
|
|
@ -4450,10 +4448,8 @@ nm_platform_ip_route_sync(NMPlatform *self,
|
|||
gboolean success = TRUE;
|
||||
char sbuf1[sizeof(_nm_utils_to_string_buffer)];
|
||||
char sbuf2[sizeof(_nm_utils_to_string_buffer)];
|
||||
const gboolean IS_IPv4 = (addr_family == AF_INET);
|
||||
|
||||
nm_assert(NM_IS_PLATFORM(self));
|
||||
nm_assert(NM_IN_SET(addr_family, AF_INET, AF_INET6));
|
||||
nm_assert(ifindex > 0);
|
||||
|
||||
vt = &nm_platform_vtable_route.vx[IS_IPv4];
|
||||
|
|
@ -4665,9 +4661,9 @@ sync_route_add:
|
|||
|
||||
prune_o = routes_prune->pdata[i];
|
||||
|
||||
nm_assert((addr_family == AF_INET
|
||||
nm_assert((NM_IS_IPv4(addr_family)
|
||||
&& NMP_OBJECT_GET_TYPE(prune_o) == NMP_OBJECT_TYPE_IP4_ROUTE)
|
||||
|| (addr_family == AF_INET6
|
||||
|| (!NM_IS_IPv4(addr_family)
|
||||
&& NMP_OBJECT_GET_TYPE(prune_o) == NMP_OBJECT_TYPE_IP6_ROUTE));
|
||||
|
||||
if (routes_idx && g_hash_table_lookup(routes_idx, prune_o))
|
||||
|
|
@ -4810,8 +4806,8 @@ _ip_route_add(NMPlatform *self, NMPNlmFlags flags, int addr_family, gconstpointe
|
|||
_LOG3D("route: %-10s IPv%c route: %s",
|
||||
_nmp_nlm_flag_to_string(flags & NMP_NLM_FLAG_FMASK),
|
||||
nm_utils_addr_family_to_char(addr_family),
|
||||
addr_family == AF_INET ? nm_platform_ip4_route_to_string(route, sbuf, sizeof(sbuf))
|
||||
: nm_platform_ip6_route_to_string(route, sbuf, sizeof(sbuf)));
|
||||
NM_IS_IPv4(addr_family) ? nm_platform_ip4_route_to_string(route, sbuf, sizeof(sbuf))
|
||||
: nm_platform_ip6_route_to_string(route, sbuf, sizeof(sbuf)));
|
||||
|
||||
return klass->ip_route_add(self, flags, addr_family, route);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ nmtstp_platform_ip6_address_get_all(NMPlatform *self, int ifindex)
|
|||
const NMPlatformIPAddress *
|
||||
nmtstp_platform_ip_address_find(NMPlatform *self, int ifindex, int addr_family, gconstpointer addr)
|
||||
{
|
||||
const gboolean IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const int IS_IPv4 = NM_IS_IPv4(addr_family);
|
||||
const NMPlatformIPAddress *found = NULL;
|
||||
NMDedupMultiIter iter;
|
||||
const NMPObject * obj;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue