mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-26 19:00:28 +01:00
core: honor the ipv4.clat property
This commit is contained in:
parent
f11fb6dafc
commit
75c423f4c8
5 changed files with 122 additions and 8 deletions
|
|
@ -954,6 +954,10 @@ ipv6.ip6-privacy=0
|
|||
<term><varname>ipv4.forwarding</varname></term>
|
||||
<listitem><para>Whether to configure IPv4 sysctl interface-specific forwarding. When enabled, the interface will act as a router to forward the IPv4 packet from one interface to another. If left unspecified, "auto" is used, so NetworkManager sets the IPv4 forwarding if any shared connection is active, or it will use the kernel default value otherwise. The "ipv4.forwarding" property is ignored when "ipv4.method" is set to "shared", because forwarding is always enabled in this case. The accepted values are: 0: disabled, 1: enabled, 2: auto, 3: ignored (leave the forwarding unchanged).</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>ipv4.clat</varname></term>
|
||||
<listitem><para>If left unspecified, defaults to "no".</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>ipv4.routed-dns</varname></term>
|
||||
</varlistentry>
|
||||
|
|
|
|||
|
|
@ -906,10 +906,11 @@ static void concheck_update_state(NMDevice *self,
|
|||
static void sriov_op_cb(GError *error, gpointer user_data);
|
||||
|
||||
static void device_ifindex_changed_cb(NMManager *manager, NMDevice *device_changed, NMDevice *self);
|
||||
static gboolean device_link_changed(gpointer user_data);
|
||||
static gboolean _get_maybe_ipv6_disabled(NMDevice *self);
|
||||
static void deactivate_ready(NMDevice *self, NMDeviceStateReason reason);
|
||||
static void carrier_disconnected_action_cancel(NMDevice *self);
|
||||
static gboolean device_link_changed(gpointer user_data);
|
||||
static gboolean _get_maybe_ipv6_disabled(NMDevice *self);
|
||||
static void deactivate_ready(NMDevice *self, NMDeviceStateReason reason);
|
||||
static void carrier_disconnected_action_cancel(NMDevice *self);
|
||||
static const char *nm_device_get_effective_ip_config_method(NMDevice *self, int addr_family);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -1523,6 +1524,40 @@ _prop_get_connection_dnssec(NMDevice *self, NMConnection *connection)
|
|||
NM_SETTING_CONNECTION_DNSSEC_DEFAULT);
|
||||
}
|
||||
|
||||
static NMSettingIp4ConfigClat
|
||||
_prop_get_ipv4_clat(NMDevice *self)
|
||||
{
|
||||
NMSettingIP4Config *s_ip4 = NULL;
|
||||
NMSettingIp4ConfigClat clat;
|
||||
const char *method;
|
||||
|
||||
s_ip4 = nm_device_get_applied_setting(self, NM_TYPE_SETTING_IP4_CONFIG);
|
||||
if (!s_ip4)
|
||||
return NM_SETTING_IP4_CONFIG_CLAT_NO;
|
||||
|
||||
method = nm_device_get_effective_ip_config_method(self, AF_INET);
|
||||
if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED))
|
||||
return NM_SETTING_IP4_CONFIG_CLAT_NO;
|
||||
|
||||
clat = nm_setting_ip4_config_get_clat(s_ip4);
|
||||
if (clat == NM_SETTING_IP4_CONFIG_CLAT_DEFAULT) {
|
||||
clat = nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA,
|
||||
NM_CON_DEFAULT("ipv4.clat"),
|
||||
self,
|
||||
NM_SETTING_IP4_CONFIG_CLAT_NO,
|
||||
NM_SETTING_IP4_CONFIG_CLAT_FORCE,
|
||||
NM_SETTING_IP4_CONFIG_CLAT_NO);
|
||||
}
|
||||
|
||||
if (clat == NM_SETTING_IP4_CONFIG_CLAT_AUTO
|
||||
&& !nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
|
||||
/* clat=auto enables CLAT only with method=auto */
|
||||
clat = NM_SETTING_IP4_CONFIG_CLAT_NO;
|
||||
}
|
||||
|
||||
return clat;
|
||||
}
|
||||
|
||||
static NMMptcpFlags
|
||||
_prop_get_connection_mptcp_flags(NMDevice *self, NMConnection *connection)
|
||||
{
|
||||
|
|
@ -3641,6 +3676,7 @@ nm_device_create_l3_config_data_from_connection(NMDevice *self, NMConnection *co
|
|||
nm_l3_config_data_set_dnssec(l3cd, _prop_get_connection_dnssec(self, connection));
|
||||
nm_l3_config_data_set_ip6_privacy(l3cd, _prop_get_ipv6_ip6_privacy(self, connection));
|
||||
nm_l3_config_data_set_mptcp_flags(l3cd, _prop_get_connection_mptcp_flags(self, connection));
|
||||
|
||||
return l3cd;
|
||||
}
|
||||
|
||||
|
|
@ -11467,6 +11503,8 @@ _dev_ipmanual_start(NMDevice *self)
|
|||
if (_prop_get_ipvx_routed_dns(self, AF_INET6) == NM_SETTING_IP_CONFIG_ROUTED_DNS_YES) {
|
||||
nm_l3_config_data_set_routed_dns(l3cd, AF_INET6, TRUE);
|
||||
}
|
||||
|
||||
nm_l3_config_data_set_clat(l3cd, _prop_get_ipv4_clat(self));
|
||||
}
|
||||
|
||||
if (!l3cd) {
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ struct _NML3ConfigData {
|
|||
NMSettingConnectionDnsOverTls dns_over_tls;
|
||||
NMSettingConnectionDnssec dnssec;
|
||||
NMUtilsIPv6IfaceId ip6_token;
|
||||
NMSettingIp4ConfigClat clat;
|
||||
NMRefString *network_id;
|
||||
|
||||
NML3ConfigDatFlags flags;
|
||||
|
|
@ -525,6 +526,13 @@ nm_l3_config_data_log(const NML3ConfigData *self,
|
|||
_L("nis-domain: %s", self->nis_domain->str);
|
||||
}
|
||||
|
||||
if (!IS_IPv4) {
|
||||
if (self->clat == NM_SETTING_IP4_CONFIG_CLAT_AUTO)
|
||||
_L("clat: auto");
|
||||
else if (self->clat == NM_SETTING_IP4_CONFIG_CLAT_FORCE)
|
||||
_L("clat: force");
|
||||
}
|
||||
|
||||
if (!IS_IPv4 && self->pref64_valid) {
|
||||
_L("pref64_prefix: %s/%d",
|
||||
nm_utils_inet6_ntop(&self->pref64_prefix, sbuf_addr),
|
||||
|
|
@ -725,6 +733,7 @@ nm_l3_config_data_new(NMDedupMultiIndex *multi_idx, int ifindex, NMIPConfigSourc
|
|||
.flags = NM_L3_CONFIG_DAT_FLAGS_NONE,
|
||||
.metered = NM_TERNARY_DEFAULT,
|
||||
.proxy_browser_only = NM_TERNARY_DEFAULT,
|
||||
.clat = NM_SETTING_IP4_CONFIG_CLAT_NO,
|
||||
.proxy_method = NM_PROXY_CONFIG_METHOD_UNKNOWN,
|
||||
.route_table_sync_4 = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE,
|
||||
.route_table_sync_6 = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE,
|
||||
|
|
@ -1991,6 +2000,29 @@ nm_l3_config_data_set_network_id(NML3ConfigData *self, const char *value)
|
|||
return nm_ref_string_reset_str(&self->network_id, value);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_set_clat(NML3ConfigData *self, NMSettingIp4ConfigClat val)
|
||||
{
|
||||
nm_assert(_NM_IS_L3_CONFIG_DATA(self, FALSE));
|
||||
nm_assert(NM_IN_SET(val,
|
||||
NM_SETTING_IP4_CONFIG_CLAT_NO,
|
||||
NM_SETTING_IP4_CONFIG_CLAT_FORCE,
|
||||
NM_SETTING_IP4_CONFIG_CLAT_AUTO));
|
||||
|
||||
if (self->clat == val)
|
||||
return FALSE;
|
||||
self->clat = val;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NMSettingIp4ConfigClat
|
||||
nm_l3_config_data_get_clat(const NML3ConfigData *self)
|
||||
{
|
||||
nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE));
|
||||
|
||||
return self->clat;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_set_pref64_valid(NML3ConfigData *self, gboolean val)
|
||||
{
|
||||
|
|
@ -2591,6 +2623,8 @@ nm_l3_config_data_cmp_full(const NML3ConfigData *a,
|
|||
NM_CMP_DIRECT_UNSAFE(a->routed_dns_4, b->routed_dns_4);
|
||||
NM_CMP_DIRECT_UNSAFE(a->routed_dns_6, b->routed_dns_6);
|
||||
|
||||
NM_CMP_DIRECT_UNSAFE(a->clat, b->clat);
|
||||
|
||||
NM_CMP_DIRECT(!!a->pref64_valid, !!b->pref64_valid);
|
||||
if (a->pref64_valid) {
|
||||
NM_CMP_DIRECT(a->pref64_plen, b->pref64_plen);
|
||||
|
|
@ -3662,6 +3696,14 @@ nm_l3_config_data_merge(NML3ConfigData *self,
|
|||
if (src->routed_dns_6)
|
||||
self->routed_dns_6 = TRUE;
|
||||
|
||||
if (self->clat == NM_SETTING_IP4_CONFIG_CLAT_NO) {
|
||||
/* 'no' always loses to 'force' and 'auto' */
|
||||
self->clat = src->clat;
|
||||
} else if (src->clat == NM_SETTING_IP4_CONFIG_CLAT_FORCE) {
|
||||
/* 'force' always takes precedence */
|
||||
self->clat = src->clat;
|
||||
}
|
||||
|
||||
if (src->pref64_valid) {
|
||||
self->pref64_prefix = src->pref64_prefix;
|
||||
self->pref64_plen = src->pref64_plen;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "libnm-glib-aux/nm-dedup-multi.h"
|
||||
#include "nm-setting-connection.h"
|
||||
#include "nm-setting-ip4-config.h"
|
||||
#include "nm-setting-ip6-config.h"
|
||||
#include "libnm-platform/nm-platform.h"
|
||||
#include "libnm-platform/nmp-object.h"
|
||||
|
|
@ -498,6 +499,10 @@ gboolean nm_l3_config_data_set_network_id(NML3ConfigData *self, const char *netw
|
|||
|
||||
const char *nm_l3_config_data_get_network_id(const NML3ConfigData *self);
|
||||
|
||||
gboolean nm_l3_config_data_set_clat(NML3ConfigData *self, NMSettingIp4ConfigClat val);
|
||||
|
||||
NMSettingIp4ConfigClat nm_l3_config_data_get_clat(const NML3ConfigData *self);
|
||||
|
||||
gboolean nm_l3_config_data_set_pref64_valid(NML3ConfigData *self, gboolean val);
|
||||
|
||||
gboolean nm_l3_config_data_get_pref64_valid(const NML3ConfigData *self);
|
||||
|
|
|
|||
|
|
@ -4159,8 +4159,11 @@ _l3cfg_update_combined_config(NML3Cfg *self,
|
|||
gboolean merged_changed = FALSE;
|
||||
gboolean commited_changed = FALSE;
|
||||
#if HAVE_CLAT
|
||||
struct in6_addr pref64;
|
||||
guint32 pref64_plen;
|
||||
struct in6_addr pref64;
|
||||
guint32 pref64_plen;
|
||||
gboolean clat_enabled = FALSE;
|
||||
const NMPlatformIP4Route *ip4_route;
|
||||
NMDedupMultiIter iter;
|
||||
#endif
|
||||
|
||||
nm_assert(NM_IS_L3CFG(self));
|
||||
|
|
@ -4260,10 +4263,32 @@ _l3cfg_update_combined_config(NML3Cfg *self,
|
|||
}
|
||||
|
||||
#if HAVE_CLAT
|
||||
if (nm_l3_config_data_get_pref64_valid(l3cd)) {
|
||||
switch (nm_l3_config_data_get_clat(l3cd)) {
|
||||
case NM_SETTING_IP4_CONFIG_CLAT_FORCE:
|
||||
clat_enabled = TRUE;
|
||||
break;
|
||||
case NM_SETTING_IP4_CONFIG_CLAT_NO:
|
||||
clat_enabled = FALSE;
|
||||
break;
|
||||
case NM_SETTING_IP4_CONFIG_CLAT_AUTO:
|
||||
clat_enabled = TRUE;
|
||||
/* disable if there is a native IPv4 gateway */
|
||||
nm_l3_config_data_iter_ip4_route_for_each (&iter, l3cd, &ip4_route) {
|
||||
if (ip4_route->network == INADDR_ANY && ip4_route->plen == 0
|
||||
&& ip4_route->gateway != INADDR_ANY)
|
||||
clat_enabled = FALSE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NM_SETTING_IP4_CONFIG_CLAT_DEFAULT:
|
||||
nm_assert_not_reached();
|
||||
clat_enabled = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (clat_enabled && nm_l3_config_data_get_pref64_valid(l3cd)) {
|
||||
NMPlatformIPXRoute rx;
|
||||
NMIPAddrTyped best_v6_gateway;
|
||||
NMDedupMultiIter iter;
|
||||
const NMPlatformIP6Route *best_v6_route;
|
||||
const NMPlatformIP6Address *ip6_entry;
|
||||
struct in6_addr ip6;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue