settings: add ipv4.link-local flag

Allows the ip4 local-link address configuration to be started
independently of the ipv4.method configuration.

This is done by adding a new link-local parameter to the ipv4 settings.
The link-local parameter partially overlaps with the existing method
parameter. The first step is to reject inconsistent settings for method
and link-local settings.
This commit is contained in:
Adrian Freihofer 2022-04-08 13:11:56 +02:00
parent 3a69aa50b8
commit 06c741b00f
10 changed files with 822 additions and 546 deletions

View file

@ -1510,6 +1510,20 @@ _prop_get_connection_lldp(NMDevice *self)
return lldp == NM_SETTING_CONNECTION_LLDP_ENABLE_RX;
}
static NMSettingIP4LinkLocal
_prop_get_ipv4_link_local(NMDevice *self)
{
NMSettingIP4Config *s_ip4;
NMSettingIP4LinkLocal link_local;
s_ip4 = nm_device_get_applied_setting(self, NM_TYPE_SETTING_IP4_CONFIG);
if (!s_ip4)
return NM_SETTING_IP4_LL_DISABLED;
link_local = nm_setting_ip4_config_get_link_local(s_ip4);
return link_local;
}
static guint32
_prop_get_ipv4_dad_timeout(NMDevice *self)
{
@ -11706,11 +11720,14 @@ activate_stage3_ip_config_for_addr_family(NMDevice *self, int addr_family, const
goto out_devip;
if (IS_IPv4) {
if (_prop_get_ipv4_link_local(self) == NM_SETTING_IP4_LL_ENABLED)
_dev_ipll4_start(self);
if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
_dev_ipdhcpx_start(self, AF_INET);
else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
_dev_ipll4_start(self);
else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) {
/* pass */
} else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
_dev_ipshared4_start(self);
else if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED))
priv->ip_data_x[IS_IPv4].is_disabled = TRUE;

View file

@ -1826,4 +1826,9 @@ libnm_1_38_0 {
global:
nm_client_get_radio_flags;
nm_radio_flags_get_type;
} libnm_1_36_0;
} libnm_1_36_0;
libnm_1_40_0 {
global:
nm_setting_ip4_link_local_get_type;
} libnm_1_38_0;

View file

@ -38,14 +38,16 @@
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_DHCP_CLIENT_ID,
PROP_DHCP_FQDN,
PROP_DHCP_VENDOR_CLASS_IDENTIFIER, );
PROP_DHCP_VENDOR_CLASS_IDENTIFIER,
PROP_LINK_LOCAL, );
typedef struct {
NMSettingIPConfigPrivate parent;
char *dhcp_client_id;
char *dhcp_fqdn;
char *dhcp_vendor_class_identifier;
char *dhcp_client_id;
char *dhcp_fqdn;
char *dhcp_vendor_class_identifier;
gint32 link_local;
} NMSettingIP4ConfigPrivate;
/**
@ -127,6 +129,25 @@ nm_setting_ip4_config_get_dhcp_vendor_class_identifier(NMSettingIP4Config *setti
return NM_SETTING_IP4_CONFIG_GET_PRIVATE(setting)->dhcp_vendor_class_identifier;
}
/**
* nm_setting_ip4_config_get_link_local:
* @setting: the #NMSettingIP4Config
*
* Returns the value contained in the #NMSettingIP4Config:link_local
* property.
*
* Returns: the link-local configuration
*
* Since: 1.40
**/
NMSettingIP4LinkLocal
nm_setting_ip4_config_get_link_local(NMSettingIP4Config *setting)
{
g_return_val_if_fail(NM_IS_SETTING_IP4_CONFIG(setting), NM_SETTING_IP4_LL_NONE);
return NM_SETTING_IP4_CONFIG_GET_PRIVATE(setting)->link_local;
}
static gboolean
verify(NMSetting *setting, NMConnection *connection, GError **error)
{
@ -218,6 +239,45 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
if (!NM_IN_SET(priv->link_local,
NM_SETTING_IP4_LL_NONE,
NM_SETTING_IP4_LL_DISABLED,
NM_SETTING_IP4_LL_ENABLED)) {
g_set_error(error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error(error,
"%s.%s: ",
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_LINK_LOCAL);
return FALSE;
}
if (priv->link_local == NM_SETTING_IP4_LL_ENABLED
&& nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
g_set_error_literal(error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("cannot enable ipv4.link-local with ipv4.method=disabled"));
g_prefix_error(error,
"%s.%s: ",
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_LINK_LOCAL);
return FALSE;
}
if (priv->link_local == NM_SETTING_IP4_LL_DISABLED
&& nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) {
g_set_error_literal(error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("cannot disable ipv4.link-local with ipv4.method=link-local"));
g_prefix_error(error,
"%s.%s: ",
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_LINK_LOCAL);
return FALSE;
}
if (priv->dhcp_client_id && !priv->dhcp_client_id[0]) {
g_set_error_literal(error,
NM_CONNECTION_ERROR,
@ -854,6 +914,27 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass)
NMSettingIP4ConfigPrivate,
dhcp_vendor_class_identifier);
/**
* NMSettingIP4Config:link-local:
*
* Enable and disable the IPv4 link-local configuration independently of the
* ipv4.method configuration. This allows a link-local address (169.254.x.y/16)
* to be obtained in addition to other addresses, such as those manually
* configured or obtained from a DHCP server.
*
* Since 1.40
*/
_nm_setting_property_define_direct_int32(properties_override,
obj_properties,
NM_SETTING_IP4_CONFIG_LINK_LOCAL,
PROP_LINK_LOCAL,
G_MININT32,
G_MAXINT32,
NM_SETTING_IP4_LL_NONE,
NM_SETTING_PARAM_NONE,
NMSettingIP4ConfigPrivate,
link_local);
/* IP4-specific property overrides */
/* ---dbus---

View file

@ -3872,6 +3872,7 @@ test_connection_diff_a_only(void)
{NM_SETTING_IP_CONFIG_DHCP_IAID, NM_SETTING_DIFF_RESULT_IN_A},
{NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER, NM_SETTING_DIFF_RESULT_IN_A},
{NM_SETTING_IP_CONFIG_DHCP_REJECT_SERVERS, NM_SETTING_DIFF_RESULT_IN_A},
{NM_SETTING_IP4_CONFIG_LINK_LOCAL, NM_SETTING_DIFF_RESULT_IN_A},
{NULL, NM_SETTING_DIFF_RESULT_UNKNOWN},
}},
};

View file

@ -32,6 +32,7 @@ G_BEGIN_DECLS
#define NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID "dhcp-client-id"
#define NM_SETTING_IP4_CONFIG_DHCP_FQDN "dhcp-fqdn"
#define NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER "dhcp-vendor-class-identifier"
#define NM_SETTING_IP4_CONFIG_LINK_LOCAL "link-local"
/**
* NM_SETTING_IP4_CONFIG_METHOD_AUTO:
@ -77,6 +78,23 @@ G_BEGIN_DECLS
*/
#define NM_SETTING_IP4_CONFIG_METHOD_DISABLED "disabled"
/**
* NMSettingIP4LinkLocal:
* @NM_SETTING_IP4_LL_NONE: default value
* @NM_SETTING_IP4_LL_DISABLED: disable link-local protocol
* @NM_SETTING_IP4_LL_ENABLED: enable the link-local protocol regardless what other protocols
* such as DHCP or manually assigned IP addresses might be active.
*
* #NMSettingIP4LinkLocal values indicate whether link-local address protocol should be enabled.
*
* Since: 1.40
*/
typedef enum {
NM_SETTING_IP4_LL_NONE = 0,
NM_SETTING_IP4_LL_DISABLED = 2,
NM_SETTING_IP4_LL_ENABLED = 3,
} NMSettingIP4LinkLocal;
typedef struct _NMSettingIP4ConfigClass NMSettingIP4ConfigClass;
GType nm_setting_ip4_config_get_type(void);
@ -90,6 +108,9 @@ const char *nm_setting_ip4_config_get_dhcp_fqdn(NMSettingIP4Config *setting);
NM_AVAILABLE_IN_1_28
const char *nm_setting_ip4_config_get_dhcp_vendor_class_identifier(NMSettingIP4Config *setting);
NM_AVAILABLE_IN_1_40
NMSettingIP4LinkLocal nm_setting_ip4_config_get_link_local(NMSettingIP4Config *setting);
G_END_DECLS
#endif /* __NM_SETTING_IP4_CONFIG_H__ */

View file

@ -6133,6 +6133,14 @@ static const NMMetaPropertyInfo *const property_infos_IP4_CONFIG[] = {
PROPERTY_INFO_WITH_DESC (NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER,
.property_type = &_pt_gobject_string,
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_IP4_CONFIG_LINK_LOCAL,
.property_type = &_pt_gobject_enum,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA (
PROPERTY_TYP_DATA_SUBTYPE (gobject_enum,
.get_gtype = nm_setting_ip4_link_local_get_type,
),
),
),
PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_REJECT_SERVERS, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_REJECT_SERVERS,
.property_type = &_pt_multilist,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA (

View file

@ -246,6 +246,7 @@
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_GATEWAY N_("The gateway associated with this configuration. This is only meaningful if \"addresses\" is also set. The gateway's main purpose is to control the next hop of the standard default route on the device. Hence, the gateway property conflicts with \"never-default\" and will be automatically dropped if the IP configuration is set to never-default. As an alternative to set the gateway, configure a static default route with /0 as prefix length.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured name servers and search domains are ignored and only name servers and search domains specified in the \"dns\" and \"dns-search\" properties, if any, are used.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES N_("When \"method\" is set to \"auto\" and this property to TRUE, automatically configured routes are ignored and only routes specified in the \"routes\" property, if any, are used.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_LINK_LOCAL N_("Enable and disable the IPv4 link-local configuration independently of the ipv4.method configuration. This allows a link-local address (169.254.x.y/16) to be obtained in addition to other addresses, such as those manually configured or obtained from a DHCP server. Since 1.40")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_MAY_FAIL N_("If TRUE, allow overall network configuration to proceed even if the configuration specified by this property times out. Note that at least one IP configuration must succeed or overall network configuration will still fail. For example, in IPv6-only networks, setting this property to TRUE on the NMSettingIP4Config allows the overall network configuration to succeed if IPv4 configuration fails but IPv6 configuration completes successfully.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_METHOD N_("IP configuration method. NMSettingIP4Config and NMSettingIP6Config both support \"disabled\", \"auto\", \"manual\", and \"link-local\". See the subclass-specific documentation for other values. In general, for the \"auto\" method, properties such as \"dns\" and \"routes\" specify information that is added on to the information returned from automatic configuration. The \"ignore-auto-routes\" and \"ignore-auto-dns\" properties modify this behavior. For methods that imply no upstream network, such as \"shared\" or \"link-local\", these properties must be empty. For IPv4 method \"shared\", the IP subnet can be configured by adding one manual IPv4 address or otherwise 10.42.x.0/24 is chosen. Note that the shared method must be configured on the interface which shares the internet to a subnet, not on the uplink which is shared.")
#define DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_NEVER_DEFAULT N_("If TRUE, this connection will never be the default connection for this IP type, meaning it will never be assigned the default route by NetworkManager.")

View file

@ -696,6 +696,8 @@
description="Timeout in milliseconds used to check for the presence of duplicate IP addresses on the network. If an address conflict is detected, the activation will fail. A zero value means that no duplicate address detection is performed, -1 means the default value (either configuration ipvx.dad-timeout override or zero). A value greater than zero is a timeout in milliseconds. The property is currently implemented only for IPv4." />
<property name="dhcp-vendor-class-identifier"
description="The Vendor Class Identifier DHCP option (60). Special characters in the data string may be escaped using C-style escapes, nevertheless this property cannot contain nul bytes. If the per-profile value is unspecified (the default), a global connection default gets consulted. If still unspecified, the DHCP option is not sent to the server. Since 1.28" />
<property name="link-local"
description="Enable and disable the IPv4 link-local configuration independently of the ipv4.method configuration. This allows a link-local address (169.254.x.y/16) to be obtained in addition to other addresses, such as those manually configured or obtained from a DHCP server. Since 1.40" />
<property name="dhcp-reject-servers"
description="Array of servers from which DHCP offers must be rejected. This property is useful to avoid getting a lease from misconfigured or rogue servers. For DHCPv4, each element must be an IPv4 address, optionally followed by a slash and a prefix length (e.g. &quot;192.168.122.0/24&quot;). This property is currently not implemented for DHCPv6." />
</setting>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff