core,wireguard: merge branch 'th/wireguard-routes'

https://github.com/NetworkManager/NetworkManager/pull/305
This commit is contained in:
Thomas Haller 2019-03-05 09:54:56 +01:00
commit 9b56d760af
26 changed files with 1069 additions and 922 deletions

View file

@ -7536,6 +7536,12 @@ static const NMMetaPropertyInfo *const property_infos_WIREGUARD[] = {
.base = 16,
),
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_PEER_ROUTES,
.property_type = &_pt_gobject_bool,
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_WIREGUARD_MTU,
.property_type = &_pt_gobject_mtu,
),
NULL
};

View file

@ -364,6 +364,8 @@
#define DESCRIBE_DOC_NM_SETTING_WIMAX_NETWORK_NAME N_("Network Service Provider (NSP) name of the WiMAX network this connection should use. Deprecated: 1")
#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_FWMARK N_("The use of fwmark is optional and is by default off. Setting it to 0 disables it. Otherwise it is a 32-bit fwmark for outgoing packets.")
#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_LISTEN_PORT N_("The listen-port. If listen-port is not specified, the port will be chosen randomly when the interface comes up.")
#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_MTU N_("If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple fragments. If zero a default MTU is used. Note that contrary to wg-quick's MTU setting, this does not take into account the current routes at the time of activation.")
#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_PEER_ROUTES N_("Whether to automatically add routes for the AllowedIPs ranges of the peers. If TRUE (the default), NetworkManager will automatically add routes in the routing tables according to ipv4.route-table and ipv6.route-table. If FALSE, no such routes are added automatically. In this case, the user may want to configure static routes in ipv4.routes and ipv6.routes, respectively.")
#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_PRIVATE_KEY N_("The 256 bit private-key in base64 encoding.")
#define DESCRIBE_DOC_NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS N_("Flags indicating how to handle the \"private-key\" property.")
#define DESCRIBE_DOC_NM_SETTING_WPAN_CHANNEL N_("IEEE 802.15.4 channel. A positive integer or -1, meaning \"do not set, use whatever the device is already set to\".")

View file

@ -230,6 +230,18 @@ nm_connection_get_setting (NMConnection *connection, GType setting_type)
return _connection_get_setting_check (connection, setting_type);
}
NMSettingIPConfig *
nm_connection_get_setting_ip_config (NMConnection *connection,
int addr_family)
{
nm_assert_addr_family (addr_family);
return NM_SETTING_IP_CONFIG (_connection_get_setting (connection,
(addr_family == AF_INET)
? NM_TYPE_SETTING_IP4_CONFIG
: NM_TYPE_SETTING_IP6_CONFIG));
}
/**
* nm_connection_get_setting_by_name:
* @connection: a #NMConnection

View file

@ -449,6 +449,11 @@ gboolean _nm_utils_generate_mac_address_mask_parse (const char *value,
/*****************************************************************************/
NMSettingIPConfig *nm_connection_get_setting_ip_config (NMConnection *connection,
int addr_family);
/*****************************************************************************/
typedef enum {
NM_BOND_OPTION_TYPE_INT,
NM_BOND_OPTION_TYPE_STRING,

View file

@ -850,10 +850,12 @@ typedef struct {
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_FWMARK,
PROP_LISTEN_PORT,
PROP_MTU,
PROP_PEER_ROUTES,
PROP_PRIVATE_KEY,
PROP_PRIVATE_KEY_FLAGS,
PROP_LISTEN_PORT,
PROP_FWMARK,
);
typedef struct {
@ -862,8 +864,10 @@ typedef struct {
GHashTable *peers_hash;
NMSettingSecretFlags private_key_flags;
guint32 fwmark;
guint32 mtu;
guint16 listen_port;
bool private_key_valid:1;
bool peer_routes:1;
} NMSettingWireGuardPrivate;
/**
@ -978,6 +982,38 @@ nm_setting_wireguard_get_listen_port (NMSettingWireGuard *self)
return NM_SETTING_WIREGUARD_GET_PRIVATE (self)->listen_port;
}
/**
* nm_setting_wireguard_get_peer_routes:
* @self: the #NMSettingWireGuard instance
*
* Returns: whether automatically add peer routes.
*
* Since: 1.16
*/
gboolean
nm_setting_wireguard_get_peer_routes (NMSettingWireGuard *self)
{
g_return_val_if_fail (NM_IS_SETTING_WIREGUARD (self), TRUE);
return NM_SETTING_WIREGUARD_GET_PRIVATE (self)->peer_routes;
}
/**
* nm_setting_wireguard_get_mtu:
* @self: the #NMSettingWireGuard instance
*
* Returns: the MTU of the setting.
*
* Since: 1.16
*/
guint32
nm_setting_wireguard_get_mtu (NMSettingWireGuard *self)
{
g_return_val_if_fail (NM_IS_SETTING_WIREGUARD (self), 0);
return NM_SETTING_WIREGUARD_GET_PRIVATE (self)->mtu;
}
/*****************************************************************************/
static void
@ -2160,18 +2196,24 @@ get_property (GObject *object, guint prop_id,
NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE (setting);
switch (prop_id) {
case PROP_FWMARK:
g_value_set_uint (value, priv->fwmark);
break;
case PROP_LISTEN_PORT:
g_value_set_uint (value, priv->listen_port);
break;
case PROP_MTU:
g_value_set_uint (value, priv->mtu);
break;
case PROP_PEER_ROUTES:
g_value_set_boolean (value, priv->peer_routes);
break;
case PROP_PRIVATE_KEY:
g_value_set_string (value, priv->private_key);
break;
case PROP_PRIVATE_KEY_FLAGS:
g_value_set_flags (value, priv->private_key_flags);
break;
case PROP_LISTEN_PORT:
g_value_set_uint (value, priv->listen_port);
break;
case PROP_FWMARK:
g_value_set_uint (value, priv->fwmark);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -2186,6 +2228,18 @@ set_property (GObject *object, guint prop_id,
const char *str;
switch (prop_id) {
case PROP_FWMARK:
priv->fwmark = g_value_get_uint (value);
break;
case PROP_LISTEN_PORT:
priv->listen_port = g_value_get_uint (value);
break;
case PROP_MTU:
priv->mtu = g_value_get_uint (value);
break;
case PROP_PEER_ROUTES:
priv->peer_routes = g_value_get_boolean (value);
break;
case PROP_PRIVATE_KEY:
nm_clear_pointer (&priv->private_key, nm_free_secret);
str = g_value_get_string (value);
@ -2203,12 +2257,6 @@ set_property (GObject *object, guint prop_id,
case PROP_PRIVATE_KEY_FLAGS:
priv->private_key_flags = g_value_get_flags (value);
break;
case PROP_LISTEN_PORT:
priv->listen_port = g_value_get_uint (value);
break;
case PROP_FWMARK:
priv->fwmark = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -2224,6 +2272,7 @@ nm_setting_wireguard_init (NMSettingWireGuard *setting)
priv->peers_arr = g_ptr_array_new ();
priv->peers_hash = g_hash_table_new (nm_pstr_hash, nm_pstr_equal);
priv->peer_routes = TRUE;
}
/**
@ -2338,6 +2387,45 @@ nm_setting_wireguard_class_init (NMSettingWireGuardClass *klass)
| NM_SETTING_PARAM_INFERRABLE
| G_PARAM_STATIC_STRINGS);
/**
* NMSettingWireGuard:peer-routes:
*
* Whether to automatically add routes for the AllowedIPs ranges
* of the peers. If %TRUE (the default), NetworkManager will automatically
* add routes in the routing tables according to ipv4.route-table and
* ipv6.route-table.
* If %FALSE, no such routes are added automatically. In this case, the
* user may want to configure static routes in ipv4.routes and ipv6.routes,
* respectively.
*
* Since: 1.16
**/
obj_properties[PROP_PEER_ROUTES] =
g_param_spec_boolean (NM_SETTING_WIREGUARD_PEER_ROUTES, "", "",
TRUE,
G_PARAM_READWRITE
| NM_SETTING_PARAM_INFERRABLE
| G_PARAM_STATIC_STRINGS);
/**
* NMSettingWireGuard:mtu:
*
* If non-zero, only transmit packets of the specified size or smaller,
* breaking larger packets up into multiple fragments.
*
* If zero a default MTU is used. Note that contrary to wg-quick's MTU
* setting, this does not take into account the current routes at the
* time of activation.
*
* Since: 1.16
**/
obj_properties[PROP_MTU] =
g_param_spec_uint (NM_SETTING_WIREGUARD_MTU, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE
| NM_SETTING_PARAM_INFERRABLE
| G_PARAM_STATIC_STRINGS);
/* ---dbus---
* property: peers
* format: array of 'a{sv}'

View file

@ -126,19 +126,22 @@ int nm_wireguard_peer_cmp (const NMWireGuardPeer *a,
#define NM_SETTING_WIREGUARD_SETTING_NAME "wireguard"
#define NM_SETTING_WIREGUARD_FWMARK "fwmark"
#define NM_SETTING_WIREGUARD_LISTEN_PORT "listen-port"
#define NM_SETTING_WIREGUARD_PRIVATE_KEY "private-key"
#define NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS "private-key-flags"
#define NM_SETTING_WIREGUARD_LISTEN_PORT "listen-port"
#define NM_SETTING_WIREGUARD_FWMARK "fwmark"
#define NM_SETTING_WIREGUARD_PEERS "peers"
#define NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY "public-key"
#define NM_SETTING_WIREGUARD_MTU "mtu"
#define NM_SETTING_WIREGUARD_PEER_ROUTES "peer-routes"
#define NM_WIREGUARD_PEER_ATTR_ALLOWED_IPS "allowed-ips"
#define NM_WIREGUARD_PEER_ATTR_ENDPOINT "endpoint"
#define NM_WIREGUARD_PEER_ATTR_PERSISTENT_KEEPALIVE "persistent-keepalive"
#define NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY "preshared-key"
#define NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY_FLAGS "preshared-key-flags"
#define NM_WIREGUARD_PEER_ATTR_ALLOWED_IPS "allowed-ips"
#define NM_WIREGUARD_PEER_ATTR_PERSISTENT_KEEPALIVE "persistent-keepalive"
#define NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY "public-key"
/*****************************************************************************/
@ -194,6 +197,12 @@ gboolean nm_setting_wireguard_remove_peer (NMSettingWireGuard *self,
NM_AVAILABLE_IN_1_16
guint nm_setting_wireguard_clear_peers (NMSettingWireGuard *self);
NM_AVAILABLE_IN_1_16
gboolean nm_setting_wireguard_get_peer_routes (NMSettingWireGuard *self);
NM_AVAILABLE_IN_1_16
guint32 nm_setting_wireguard_get_mtu (NMSettingWireGuard *self);
/*****************************************************************************/
G_END_DECLS

View file

@ -1466,8 +1466,10 @@ global:
nm_setting_wireguard_clear_peers;
nm_setting_wireguard_get_fwmark;
nm_setting_wireguard_get_listen_port;
nm_setting_wireguard_get_mtu;
nm_setting_wireguard_get_peer;
nm_setting_wireguard_get_peer_by_public_key;
nm_setting_wireguard_get_peer_routes;
nm_setting_wireguard_get_peers_len;
nm_setting_wireguard_get_private_key;
nm_setting_wireguard_get_private_key_flags;

View file

@ -827,6 +827,9 @@ ipv6.ip6-privacy=0
<varlistentry>
<term><varname>wifi.wake-on-wlan</varname></term>
</varlistentry>
<varlistentry>
<term><varname>wireguard.mtu</varname></term>
</varlistentry>
</variablelist>
<!-- The following comment is used by check-config-options.sh, don't remove it. -->
<!-- end connection defaults -->

View file

@ -212,10 +212,7 @@ nm_utils_connection_has_default_route (NMConnection *connection,
if (!connection)
goto out;
if (addr_family == AF_INET)
s_ip = nm_connection_get_setting_ip4_config (connection);
else
s_ip = nm_connection_get_setting_ip6_config (connection);
s_ip = nm_connection_get_setting_ip_config (connection, addr_family);
if (!s_ip)
goto out;
if (nm_setting_ip_config_get_never_default (s_ip)) {
@ -404,8 +401,8 @@ route_compare (NMIPRoute *route1, NMIPRoute *route2, gint64 default_metric)
nm_assert_not_reached ();
if (!inet_pton (family, nm_ip_route_get_dest (route2), &a2))
nm_assert_not_reached ();
nm_utils_ipx_address_clear_host_address (family, &a1, &a1, plen);
nm_utils_ipx_address_clear_host_address (family, &a2, &a2, plen);
nm_utils_ipx_address_clear_host_address (family, &a1, NULL, plen);
nm_utils_ipx_address_clear_host_address (family, &a2, NULL, plen);
NM_CMP_DIRECT_MEMCMP (&a1, &a2, nm_utils_addr_family_to_size (family));
return 0;

View file

@ -30,6 +30,7 @@
#include <unistd.h>
#include <stdlib.h>
#include "nm-ip4-config.h"
#include "devices/nm-device-private.h"
#include "platform/nm-platform.h"
#include "ppp/nm-ppp-manager-call.h"
@ -447,9 +448,8 @@ ppp_ip4_config (NMPPPManager *ppp_manager,
NMDevice *device = NM_DEVICE (user_data);
/* Ignore PPP IP4 events that come in after initial configuration */
if (nm_device_activate_ip4_state_in_conf (device)) {
nm_device_activate_schedule_ip4_config_result (device, config);
}
if (nm_device_activate_ip4_state_in_conf (device))
nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config));
}
static NMActStageReturn
@ -518,6 +518,18 @@ act_stage3_ip4_config_start (NMDevice *device,
return NM_ACT_STAGE_RETURN_POSTPONE;
}
static NMActStageReturn
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
if (addr_family == AF_INET)
return act_stage3_ip4_config_start (device, (NMIP4Config **) out_config, out_failure_reason);
return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason);
}
static void
adsl_cleanup (NMDeviceAdsl *self)
{
@ -687,7 +699,7 @@ nm_device_adsl_class_init (NMDeviceAdslClass *klass)
device_class->complete_connection = complete_connection;
device_class->act_stage2_config = act_stage2_config;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->deactivate = deactivate;
obj_properties[PROP_ATM_INDEX] =

View file

@ -38,6 +38,7 @@
#include "settings/nm-settings-connection.h"
#include "nm-utils.h"
#include "nm-bt-error.h"
#include "nm-ip4-config.h"
#include "platform/nm-platform.h"
#include "devices/wwan/nm-modem-manager.h"
@ -397,9 +398,9 @@ ppp_failed (NMModem *modem,
case NM_DEVICE_STATE_SECONDARIES:
case NM_DEVICE_STATE_ACTIVATED:
if (nm_device_activate_ip4_state_in_conf (device))
nm_device_activate_schedule_ip4_config_timeout (device);
nm_device_activate_schedule_ip_config_timeout (device, AF_INET);
else if (nm_device_activate_ip6_state_in_conf (device))
nm_device_activate_schedule_ip6_config_timeout (device);
nm_device_activate_schedule_ip_config_timeout (device, AF_INET6);
else if (nm_device_activate_ip4_state_done (device)) {
nm_device_ip_method_failed (device,
AF_INET,
@ -541,7 +542,7 @@ modem_ip4_config_result (NMModem *modem,
AF_INET,
NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
} else
nm_device_activate_schedule_ip4_config_result (device, config);
nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config));
}
static void
@ -898,33 +899,29 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
}
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) device);
nm_assert_addr_family (addr_family);
if (priv->bt_type == NM_BT_CAPABILITY_DUN) {
return nm_modem_stage3_ip4_config_start (priv->modem,
device,
NM_DEVICE_CLASS (nm_device_bt_parent_class),
out_failure_reason);
if (addr_family == AF_INET) {
return nm_modem_stage3_ip4_config_start (priv->modem,
device,
NM_DEVICE_CLASS (nm_device_bt_parent_class),
out_failure_reason);
} else {
return nm_modem_stage3_ip6_config_start (priv->modem,
device,
out_failure_reason);
}
}
return NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason);
}
static NMActStageReturn
act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) device);
if (priv->bt_type == NM_BT_CAPABILITY_DUN)
return nm_modem_stage3_ip6_config_start (priv->modem, device, out_failure_reason);
return NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason);
return NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason);
}
static void
@ -1203,8 +1200,7 @@ nm_device_bt_class_init (NMDeviceBtClass *klass)
device_class->can_auto_connect = can_auto_connect;
device_class->deactivate = deactivate;
device_class->act_stage2_config = act_stage2_config;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->check_connection_compatible = check_connection_compatible;
device_class->check_connection_available = check_connection_available;
device_class->complete_connection = complete_connection;

View file

@ -982,9 +982,8 @@ ppp_ip4_config (NMPPPManager *ppp_manager,
NMDevice *device = NM_DEVICE (user_data);
/* Ignore PPP IP4 events that come in after initial configuration */
if (nm_device_activate_ip4_state_in_conf (device)) {
nm_device_activate_schedule_ip4_config_result (device, config);
}
if (nm_device_activate_ip4_state_in_conf (device))
nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config));
}
static NMActStageReturn
@ -1315,22 +1314,25 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
}
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
NMSettingConnection *s_con;
const char *connection_type;
s_con = nm_device_get_applied_setting (device, NM_TYPE_SETTING_CONNECTION);
if (addr_family == AF_INET) {
s_con = nm_device_get_applied_setting (device, NM_TYPE_SETTING_CONNECTION);
g_return_val_if_fail (s_con, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (s_con, NM_ACT_STAGE_RETURN_FAILURE);
connection_type = nm_setting_connection_get_connection_type (s_con);
if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME))
return pppoe_stage3_ip4_config_start (NM_DEVICE_ETHERNET (device), out_failure_reason);
connection_type = nm_setting_connection_get_connection_type (s_con);
if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME))
return pppoe_stage3_ip4_config_start (NM_DEVICE_ETHERNET (device), out_failure_reason);
}
return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason);
return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason);
}
static guint32
@ -1792,7 +1794,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
device_class->act_stage1_prepare = act_stage1_prepare;
device_class->act_stage2_config = act_stage2_config;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->get_configured_mtu = get_configured_mtu;
device_class->deactivate = deactivate;
device_class->get_s390_subchannels = get_s390_subchannels;

View file

@ -16,6 +16,7 @@
#include "nm-device-ppp.h"
#include "nm-ip4-config.h"
#include "nm-act-request.h"
#include "nm-device-factory.h"
#include "nm-device-private.h"
@ -106,7 +107,7 @@ ppp_ip4_config (NMPPPManager *ppp_manager,
if (nm_device_get_state (device) == NM_DEVICE_STATE_IP_CONFIG) {
if (nm_device_activate_ip4_state_in_conf (device)) {
nm_device_activate_schedule_ip4_config_result (device, config);
nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config));
return;
}
} else {
@ -172,23 +173,31 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
}
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
NMDevicePpp *self = NM_DEVICE_PPP (device);
NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self);
if (addr_family == AF_INET) {
NMDevicePpp *self = NM_DEVICE_PPP (device);
NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self);
if (priv->ip4_config) {
if (out_config)
*out_config = g_steal_pointer (&priv->ip4_config);
else
g_clear_object (&priv->ip4_config);
return NM_ACT_STAGE_RETURN_SUCCESS;
if (priv->ip4_config) {
if (out_config)
*out_config = g_steal_pointer (&priv->ip4_config);
else
g_clear_object (&priv->ip4_config);
return NM_ACT_STAGE_RETURN_SUCCESS;
}
/* Wait IPCP termination */
return NM_ACT_STAGE_RETURN_POSTPONE;
}
/* Wait IPCP termination */
return NM_ACT_STAGE_RETURN_POSTPONE;
return NM_DEVICE_CLASS (nm_device_ppp_parent_class)->act_stage3_ip_config_start (device,
addr_family,
out_config,
out_failure_reason);
}
static gboolean
@ -270,7 +279,7 @@ nm_device_ppp_class_init (NMDevicePppClass *klass)
device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES (NM_LINK_TYPE_PPP);
device_class->act_stage2_config = act_stage2_config;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->create_and_realize = create_and_realize;
device_class->deactivate = deactivate;
device_class->get_generic_capabilities = get_generic_capabilities;

View file

@ -26,6 +26,14 @@
/* This file should only be used by subclasses of NMDevice */
typedef enum {
NM_DEVICE_IP_STATE_NONE,
NM_DEVICE_IP_STATE_WAIT,
NM_DEVICE_IP_STATE_CONF,
NM_DEVICE_IP_STATE_DONE,
NM_DEVICE_IP_STATE_FAIL,
} NMDeviceIPState;
enum NMActStageReturn {
NM_ACT_STAGE_RETURN_FAILURE = 0, /* Hard failure of activation */
NM_ACT_STAGE_RETURN_SUCCESS, /* Activation stage done */
@ -75,19 +83,51 @@ void nm_device_set_firmware_missing (NMDevice *self, gboolean missing);
void nm_device_activate_schedule_stage1_device_prepare (NMDevice *device);
void nm_device_activate_schedule_stage2_device_config (NMDevice *device);
void nm_device_activate_schedule_ip4_config_result(NMDevice *device, NMIP4Config *config);
void nm_device_activate_schedule_ip4_config_timeout (NMDevice *device);
void nm_device_activate_schedule_ip_config_result (NMDevice *device,
int addr_family,
NMIPConfig *config);
void nm_device_activate_schedule_ip6_config_result (NMDevice *device);
void nm_device_activate_schedule_ip6_config_timeout (NMDevice *device);
void nm_device_activate_schedule_ip_config_timeout (NMDevice *device,
int addr_family);
gboolean nm_device_activate_ip4_state_in_conf (NMDevice *device);
gboolean nm_device_activate_ip4_state_in_wait (NMDevice *device);
gboolean nm_device_activate_ip4_state_done (NMDevice *device);
NMDeviceIPState nm_device_activate_get_ip_state (NMDevice *self,
int addr_family);
gboolean nm_device_activate_ip6_state_in_conf (NMDevice *device);
gboolean nm_device_activate_ip6_state_in_wait (NMDevice *device);
gboolean nm_device_activate_ip6_state_done (NMDevice *device);
static inline gboolean
nm_device_activate_ip4_state_in_conf (NMDevice *self)
{
return nm_device_activate_get_ip_state (self, AF_INET) == NM_DEVICE_IP_STATE_CONF;
}
static inline gboolean
nm_device_activate_ip4_state_in_wait (NMDevice *self)
{
return nm_device_activate_get_ip_state (self, AF_INET) == NM_DEVICE_IP_STATE_WAIT;
}
static inline gboolean
nm_device_activate_ip4_state_done (NMDevice *self)
{
return nm_device_activate_get_ip_state (self, AF_INET) == NM_DEVICE_IP_STATE_DONE;
}
static inline gboolean
nm_device_activate_ip6_state_in_conf (NMDevice *self)
{
return nm_device_activate_get_ip_state (self, AF_INET6) == NM_DEVICE_IP_STATE_CONF;
}
static inline gboolean
nm_device_activate_ip6_state_in_wait (NMDevice *self)
{
return nm_device_activate_get_ip_state (self, AF_INET6) == NM_DEVICE_IP_STATE_WAIT;
}
static inline gboolean
nm_device_activate_ip6_state_done (NMDevice *self)
{
return nm_device_activate_get_ip_state (self, AF_INET6) == NM_DEVICE_IP_STATE_DONE;
}
void nm_device_set_dhcp_anycast_address (NMDevice *device, const char *addr);
@ -106,8 +146,9 @@ void nm_device_queue_recheck_available (NMDevice *device,
NMDeviceStateReason available_reason,
NMDeviceStateReason unavailable_reason);
void nm_device_set_wwan_ip4_config (NMDevice *device, NMIP4Config *config);
void nm_device_set_wwan_ip6_config (NMDevice *device, NMIP6Config *config);
void nm_device_set_dev2_ip_config (NMDevice *device,
int addr_family,
NMIPConfig *config);
gboolean nm_device_hw_addr_is_explict (NMDevice *device);
@ -118,6 +159,12 @@ gboolean nm_device_sysctl_ip_conf_set (NMDevice *self,
const char *property,
const char *value);
NMIP4Config *nm_device_ip4_config_new (NMDevice *self);
NMIP6Config *nm_device_ip6_config_new (NMDevice *self);
NMIPConfig *nm_device_ip_config_new (NMDevice *self, int addr_family);
/*****************************************************************************/
gint64 nm_device_get_configured_mtu_from_connection_default (NMDevice *self,

View file

@ -1247,6 +1247,159 @@ act_stage2_config (NMDevice *device,
return NM_ACT_STAGE_RETURN_FAILURE;
}
static NMIPConfig *
_get_dev2_ip_config (NMDeviceWireGuard *self,
int addr_family)
{
gs_unref_object NMIPConfig *ip_config = NULL;
NMConnection *connection;
NMSettingWireGuard *s_wg;
guint n_peers;
guint i;
int ip_ifindex;
guint32 route_metric;
guint32 route_table_coerced;
connection = nm_device_get_applied_connection (NM_DEVICE (self));
s_wg = NM_SETTING_WIREGUARD (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIREGUARD));
/* Differences to `wg-quick`.
*
* `wg-quick` supports the "Table" setting with 3 modes:
*
* a1) "off": this is what we do with "peer-routes" disabled.
*
* a2) an explicit routing table. This is our behavior with "peer-routes" on. In this case
* we honor the "ipv4.route-table" and "ipv6.route-table" settings. One difference is that
* `wg-quick` would resolve table names from /etc/iproute2/rt_tables. Our connection profiles
* only contain table numbers, so that conversion from name to table must have happend
* before already.
*
* a3) "auto" (the default). In this case, `wg-quick` would only add the route to the
* main table, if the AllowedIP range is not yet reachable on the link. With "peer-routes"
* enabled, we don't check for that and always add the routes to the main-table
* (with 'ipv4.route-table' and 'ipv6.route-table' set to zero or RT_TABLE_MAIN (254)).
*
* Also, in "auto" mode, `wg-quick` would add special handling for /0 routes and pick
* an empty table to configure policy routing to avoid routing loops. This handling
* of routing-loops via policy routing is not yet done, and requires a separate solution
* from constructing the peer-routes here.
*/
if (!nm_setting_wireguard_get_peer_routes (s_wg))
return NULL;
ip_ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self));
if (ip_ifindex <= 0)
return NULL;
route_metric = nm_device_get_route_metric (NM_DEVICE (self), addr_family);
route_table_coerced = nm_platform_route_table_coerce (nm_device_get_route_table (NM_DEVICE (self), addr_family, TRUE));
n_peers = nm_setting_wireguard_get_peers_len (s_wg);
for (i = 0; i < n_peers; i++) {
NMWireGuardPeer *peer = nm_setting_wireguard_get_peer (s_wg, i);
guint n_aips;
guint j;
n_aips = nm_wireguard_peer_get_allowed_ips_len (peer);
for (j = 0; j < n_aips; j++) {
NMPlatformIPXRoute rt;
NMIPAddr addrbin;
const char *aip;
gboolean valid;
int prefix;
aip = nm_wireguard_peer_get_allowed_ip (peer, j, &valid);
if ( !valid
|| !nm_utils_parse_inaddr_prefix_bin (addr_family,
aip,
NULL,
&addrbin,
&prefix))
continue;
if (prefix < 0)
prefix = (addr_family == AF_INET) ? 32 : 128;
if (!ip_config)
ip_config = nm_device_ip_config_new (NM_DEVICE (self), addr_family);
nm_utils_ipx_address_clear_host_address (addr_family, &addrbin, NULL, prefix);
if (addr_family == AF_INET) {
rt.r4 = (NMPlatformIP4Route) {
.network = addrbin.addr4,
.plen = prefix,
.ifindex = ip_ifindex,
.rt_source = NM_IP_CONFIG_SOURCE_USER,
.table_coerced = route_table_coerced,
.metric = route_metric,
};
} else {
rt.r6 = (NMPlatformIP6Route) {
.network = addrbin.addr6,
.plen = prefix,
.ifindex = ip_ifindex,
.rt_source = NM_IP_CONFIG_SOURCE_USER,
.table_coerced = route_table_coerced,
.metric = route_metric,
};
}
nm_ip_config_add_route (ip_config, &rt.rx, NULL);
}
}
return g_steal_pointer (&ip_config);
}
static NMActStageReturn
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
gs_unref_object NMIPConfig *ip_config = NULL;
ip_config = _get_dev2_ip_config (NM_DEVICE_WIREGUARD (device), addr_family);
nm_device_set_dev2_ip_config (device, addr_family, ip_config);
return NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason);
}
static guint32
get_configured_mtu (NMDevice *device, NMDeviceMtuSource *out_source)
{
/* When "MTU" for `wg-quick up` is unset, it calls `ip route get` for
* each configured endpoint, to determine the suitable MTU how to reach
* each endpoint.
* For `wg-quick` this works very well, because whenever the script runs it
* determines the best setting at that point in time. It's simply not concerned
* with what happens later (and it's not around anyway).
*
* NetworkManager sticks around, so the right MTU would need to be re-determined
* whenever anything relevant changes. Which basically means, to re-evaluate whenever
* something related to addresses or routing changes (which happens all the time).
*
* The correct MTU indeed depends on the MTU setting of other interfaces (or routes).
* But it's still odd, that activating/deactivating a seemingly unrelated interface
* would trigger an MTU change. It's odd to explain/document and odd to implemented
* -- despite this being the reality.
*
* For now, only support configuring an explicit MTU, or leave the setting untouched.
* The same limitiation also applies to other "ip-tunnel" types, where we could use
* similar smarts for autodetecting the MTU.
*/
return nm_device_get_configured_mtu_from_connection (device,
NM_TYPE_SETTING_WIREGUARD,
out_source);
}
static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
@ -1275,8 +1428,18 @@ can_reapply_change (NMDevice *device,
GError **error)
{
if (nm_streq (setting_name, NM_SETTING_WIREGUARD_SETTING_NAME)) {
/* we allow reapplying all WireGuard settings. */
return TRUE;
/* Most, but not all WireGuard settings can be reapplied. Whitelist.
*
* MTU cannot be reapplied. */
return nm_device_hash_check_invalid_keys (diffs,
NM_SETTING_WIREGUARD_SETTING_NAME,
error,
NM_SETTING_WIREGUARD_FWMARK,
NM_SETTING_WIREGUARD_LISTEN_PORT,
NM_SETTING_WIREGUARD_PEERS,
NM_SETTING_WIREGUARD_PEER_ROUTES,
NM_SETTING_WIREGUARD_PRIVATE_KEY,
NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS);
}
return NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->can_reapply_change (device,
@ -1292,6 +1455,16 @@ reapply_connection (NMDevice *device,
NMConnection *con_old,
NMConnection *con_new)
{
NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD (device);
gs_unref_object NMIPConfig *ip4_config = NULL;
gs_unref_object NMIPConfig *ip6_config = NULL;
ip4_config = _get_dev2_ip_config (self, AF_INET);
ip6_config = _get_dev2_ip_config (self, AF_INET6);
nm_device_set_dev2_ip_config (device, AF_INET, ip4_config);
nm_device_set_dev2_ip_config (device, AF_INET6, ip6_config);
NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->reapply_connection (device,
con_old,
con_new);
@ -1446,11 +1619,13 @@ nm_device_wireguard_class_init (NMDeviceWireGuardClass *klass)
device_class->create_and_realize = create_and_realize;
device_class->act_stage2_config = act_stage2_config;
device_class->act_stage2_config_also_for_external_or_assume = TRUE;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->get_generic_capabilities = get_generic_capabilities;
device_class->link_changed = link_changed;
device_class->update_connection = update_connection;
device_class->can_reapply_change = can_reapply_change;
device_class->reapply_connection = reapply_connection;
device_class->get_configured_mtu = get_configured_mtu;
obj_properties[PROP_PUBLIC_KEY] =
g_param_spec_variant (NM_DEVICE_WIREGUARD_PUBLIC_KEY,

File diff suppressed because it is too large Load diff

View file

@ -369,16 +369,13 @@ typedef struct _NMDeviceClass {
NMDeviceStateReason *out_failure_reason);
NMActStageReturn (* act_stage2_config) (NMDevice *self,
NMDeviceStateReason *out_failure_reason);
NMActStageReturn (* act_stage3_ip4_config_start) (NMDevice *self,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason);
NMActStageReturn (* act_stage3_ip6_config_start) (NMDevice *self,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason);
NMActStageReturn (* act_stage4_ip4_config_timeout) (NMDevice *self,
NMDeviceStateReason *out_failure_reason);
NMActStageReturn (* act_stage4_ip6_config_timeout) (NMDevice *self,
NMDeviceStateReason *out_failure_reason);
NMActStageReturn (* act_stage3_ip_config_start) (NMDevice *self,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason);
NMActStageReturn (* act_stage4_ip_config_timeout) (NMDevice *self,
int addr_family,
NMDeviceStateReason *out_failure_reason);
void (* ip4_config_pre_commit) (NMDevice *self, NMIP4Config *config);

View file

@ -77,17 +77,10 @@ get_generic_capabilities (NMDevice *device)
}
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
return NM_ACT_STAGE_RETURN_IP_FAIL;
}
static NMActStageReturn
act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
return NM_ACT_STAGE_RETURN_IP_FAIL;
}
@ -146,8 +139,7 @@ nm_device_ovs_bridge_class_init (NMDeviceOvsBridgeClass *klass)
device_class->create_and_realize = create_and_realize;
device_class->unrealize = unrealize;
device_class->get_generic_capabilities = get_generic_capabilities;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->enslave_slave = enslave_slave;
device_class->release_slave = release_slave;
}

View file

@ -131,39 +131,22 @@ _is_internal_interface (NMDevice *device)
}
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE (device);
if (!_is_internal_interface (device))
return NM_ACT_STAGE_RETURN_IP_FAIL;
if (!nm_device_get_ip_ifindex (device)) {
if (nm_device_get_ip_ifindex (device) <= 0) {
priv->waiting_for_interface = TRUE;
return NM_ACT_STAGE_RETURN_POSTPONE;
}
return NM_DEVICE_CLASS (nm_device_ovs_interface_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason);
}
static NMActStageReturn
act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
NMDeviceOvsInterfacePrivate *priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE (device);
if (!_is_internal_interface (device))
return NM_ACT_STAGE_RETURN_IP_FAIL;
if (!nm_device_get_ip_ifindex (device)) {
priv->waiting_for_interface = TRUE;
return NM_ACT_STAGE_RETURN_POSTPONE;
}
return NM_DEVICE_CLASS (nm_device_ovs_interface_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason);
return NM_DEVICE_CLASS (nm_device_ovs_interface_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason);
}
static gboolean
@ -207,7 +190,6 @@ nm_device_ovs_interface_class_init (NMDeviceOvsInterfaceClass *klass)
device_class->is_available = is_available;
device_class->check_connection_compatible = check_connection_compatible;
device_class->link_changed = link_changed;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->can_unmanaged_external_down = can_unmanaged_external_down;
}

View file

@ -71,17 +71,10 @@ get_generic_capabilities (NMDevice *device)
}
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
return NM_ACT_STAGE_RETURN_IP_FAIL;
}
static NMActStageReturn
act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
return NM_ACT_STAGE_RETURN_IP_FAIL;
}
@ -186,8 +179,7 @@ nm_device_ovs_port_class_init (NMDeviceOvsPortClass *klass)
device_class->get_type_description = get_type_description;
device_class->create_and_realize = create_and_realize;
device_class->get_generic_capabilities = get_generic_capabilities;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->enslave_slave = enslave_slave;
device_class->release_slave = release_slave;
}

View file

@ -583,50 +583,30 @@ remove_all_peers (NMDeviceWifiP2P *self)
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
gboolean indicate_addressing_running;
NMConnection *connection;
NMSettingIPConfig *s_ip4;
const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
const char *method;
connection = nm_device_get_applied_connection (device);
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
method = nm_setting_ip_config_get_method (s_ip4);
method = nm_utils_get_ip_config_method (connection, addr_family);
/* Indicate that a critical protocol is about to start */
if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
if (addr_family == AF_INET)
indicate_addressing_running = NM_IN_STRSET (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
else {
indicate_addressing_running = NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NM_SETTING_IP6_CONFIG_METHOD_DHCP);
}
if (indicate_addressing_running)
nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), TRUE);
return NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason);
}
static NMActStageReturn
act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
NMConnection *connection;
NMSettingIPConfig *s_ip6;
const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
connection = nm_device_get_applied_connection (device);
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6)
method = nm_setting_ip_config_get_method (s_ip6);
/* Indicate that a critical protocol is about to start */
if (NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO
NM_SETTING_IP6_CONFIG_METHOD_DHCP))
nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), TRUE);
return NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason);
return NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason);
}
static void
@ -1315,8 +1295,7 @@ nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *klass)
device_class->act_stage2_config = act_stage2_config;
device_class->get_configured_mtu = get_configured_mtu;
device_class->get_auto_ip_config_method = get_auto_ip_config_method;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->deactivate = deactivate;
device_class->unmanaged_on_quit = unmanaged_on_quit;

View file

@ -2874,52 +2874,29 @@ out:
}
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
gboolean indicate_addressing_running;
NMConnection *connection;
NMSettingIPConfig *s_ip4;
const char *method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
const char *method;
connection = nm_device_get_applied_connection (device);
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
method = nm_utils_get_ip_config_method (connection, addr_family);
if (addr_family == AF_INET)
indicate_addressing_running = NM_IN_STRSET (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
else {
indicate_addressing_running = NM_IN_STRSET (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NM_SETTING_IP6_CONFIG_METHOD_DHCP);
}
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (s_ip4)
method = nm_setting_ip_config_get_method (s_ip4);
if (indicate_addressing_running)
nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), TRUE);
/* Indicate that a critical protocol is about to start */
if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0)
nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ifindex (device), TRUE);
return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip4_config_start (device, out_config, out_failure_reason);
}
static NMActStageReturn
act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
NMConnection *connection;
NMSettingIPConfig *s_ip6;
const char *method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
connection = nm_device_get_applied_connection (device);
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (s_ip6)
method = nm_setting_ip_config_get_method (s_ip6);
/* Indicate that a critical protocol is about to start */
if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0 ||
strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0)
nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ifindex (device), TRUE);
return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip6_config_start (device, out_config, out_failure_reason);
return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason);
}
static guint32
@ -2954,19 +2931,27 @@ is_static_wep (NMConnection *connection)
}
static NMActStageReturn
handle_ip_config_timeout (NMDeviceWifi *self,
NMConnection *connection,
gboolean may_fail,
gboolean *chain_up,
NMDeviceStateReason *out_failure_reason)
act_stage4_ip_config_timeout (NMDevice *device,
int addr_family,
NMDeviceStateReason *out_failure_reason)
{
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
NMConnection *connection;
NMSettingIPConfig *s_ip;
gboolean may_fail;
g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE);
connection = nm_device_get_applied_connection (device);
s_ip = nm_connection_get_setting_ip4_config (connection);
may_fail = nm_setting_ip_config_get_may_fail (s_ip);
if (NM_DEVICE_WIFI_GET_PRIVATE (self)->mode == NM_802_11_MODE_AP) {
*chain_up = TRUE;
return NM_ACT_STAGE_RETURN_FAILURE;
if (priv->mode == NM_802_11_MODE_AP)
goto call_parent;
if ( may_fail
&& !is_static_wep (connection)) {
/* Not static WEP or failure allowed; let superclass handle it */
goto call_parent;
}
/* If IP configuration times out and it's a static WEP connection, that
@ -2975,71 +2960,23 @@ handle_ip_config_timeout (NMDeviceWifi *self,
* to wait for DHCP to fail to figure it out. For all other Wi-Fi security
* types (open, WPA, 802.1x, etc) if the secrets/certs were wrong the
* connection would have failed before IP configuration.
*/
if (!may_fail && is_static_wep (connection)) {
/* Activation failed, we must have bad encryption key */
_LOGW (LOGD_DEVICE | LOGD_WIFI,
"Activation: (wifi) could not get IP configuration for connection '%s'.",
nm_connection_get_id (connection));
*
* Activation failed, we must have bad encryption key */
_LOGW (LOGD_DEVICE | LOGD_WIFI,
"Activation: (wifi) could not get IP configuration for connection '%s'.",
nm_connection_get_id (connection));
if (handle_auth_or_fail (self, NULL, TRUE)) {
_LOGI (LOGD_DEVICE | LOGD_WIFI,
"Activation: (wifi) asking for new secrets");
ret = NM_ACT_STAGE_RETURN_POSTPONE;
} else {
NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_NO_SECRETS);
ret = NM_ACT_STAGE_RETURN_FAILURE;
}
} else {
/* Not static WEP or failure allowed; let superclass handle it */
*chain_up = TRUE;
if (!handle_auth_or_fail (self, NULL, TRUE)) {
NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_NO_SECRETS);
return NM_ACT_STAGE_RETURN_FAILURE;
}
return ret;
}
_LOGI (LOGD_DEVICE | LOGD_WIFI,
"Activation: (wifi) asking for new secrets");
return NM_ACT_STAGE_RETURN_POSTPONE;
static NMActStageReturn
act_stage4_ip4_config_timeout (NMDevice *device, NMDeviceStateReason *out_failure_reason)
{
NMConnection *connection;
NMSettingIPConfig *s_ip4;
gboolean may_fail = FALSE, chain_up = FALSE;
NMActStageReturn ret;
connection = nm_device_get_applied_connection (device);
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
may_fail = nm_setting_ip_config_get_may_fail (s_ip4);
ret = handle_ip_config_timeout (NM_DEVICE_WIFI (device), connection, may_fail, &chain_up, out_failure_reason);
if (chain_up)
ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip4_config_timeout (device, out_failure_reason);
return ret;
}
static NMActStageReturn
act_stage4_ip6_config_timeout (NMDevice *device, NMDeviceStateReason *out_failure_reason)
{
NMConnection *connection;
NMSettingIPConfig *s_ip6;
gboolean may_fail = FALSE, chain_up = FALSE;
NMActStageReturn ret;
connection = nm_device_get_applied_connection (device);
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
may_fail = nm_setting_ip_config_get_may_fail (s_ip6);
ret = handle_ip_config_timeout (NM_DEVICE_WIFI (device), connection, may_fail, &chain_up, out_failure_reason);
if (chain_up)
ret = NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip6_config_timeout (device, out_failure_reason);
return ret;
call_parent:
return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage4_ip_config_timeout (device, addr_family, out_failure_reason);
}
static void
@ -3447,10 +3384,8 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
device_class->act_stage1_prepare = act_stage1_prepare;
device_class->act_stage2_config = act_stage2_config;
device_class->get_configured_mtu = get_configured_mtu;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->act_stage4_ip4_config_timeout = act_stage4_ip4_config_timeout;
device_class->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->act_stage4_ip_config_timeout = act_stage4_ip_config_timeout;
device_class->deactivate = deactivate;
device_class->deactivate_reset_hw_addr = deactivate_reset_hw_addr;
device_class->unmanaged_on_quit = unmanaged_on_quit;

View file

@ -23,6 +23,7 @@
#include "nm-device-modem.h"
#include "nm-modem.h"
#include "nm-ip4-config.h"
#include "devices/nm-device-private.h"
#include "nm-rfkill-manager.h"
#include "settings/nm-settings-connection.h"
@ -83,9 +84,9 @@ ppp_failed (NMModem *modem,
case NM_DEVICE_STATE_SECONDARIES:
case NM_DEVICE_STATE_ACTIVATED:
if (nm_device_activate_ip4_state_in_conf (device))
nm_device_activate_schedule_ip4_config_timeout (device);
nm_device_activate_schedule_ip_config_timeout (device, AF_INET);
else if (nm_device_activate_ip6_state_in_conf (device))
nm_device_activate_schedule_ip6_config_timeout (device);
nm_device_activate_schedule_ip_config_timeout (device, AF_INET6);
else if (nm_device_activate_ip4_state_done (device)) {
nm_device_ip_method_failed (device,
AF_INET,
@ -211,8 +212,8 @@ modem_ip4_config_result (NMModem *modem,
AF_INET,
NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
} else {
nm_device_set_wwan_ip4_config (device, config);
nm_device_activate_schedule_ip4_config_result (device, NULL);
nm_device_set_dev2_ip_config (device, AF_INET, NM_IP_CONFIG_CAST (config));
nm_device_activate_schedule_ip_config_result (device, AF_INET, NULL);
}
}
@ -227,7 +228,7 @@ modem_ip6_config_result (NMModem *modem,
NMDevice *device = NM_DEVICE (self);
NMActStageReturn ret;
NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE;
NMIP6Config *ignored = NULL;
gs_unref_object NMIP6Config *ignored = NULL;
gboolean got_config = !!config;
g_return_if_fail (nm_device_activate_ip6_state_in_conf (device) == TRUE);
@ -245,11 +246,11 @@ modem_ip6_config_result (NMModem *modem,
nm_device_sysctl_ip_conf_set (device, AF_INET6, "disable_ipv6", "0");
if (config)
nm_device_set_wwan_ip6_config (device, config);
nm_device_set_dev2_ip_config (device, AF_INET6, NM_IP_CONFIG_CAST (config));
if (do_slaac == FALSE) {
if (got_config)
nm_device_activate_schedule_ip6_config_result (device);
nm_device_activate_schedule_ip_config_result (device, AF_INET6, NULL);
else {
_LOGW (LOGD_MB | LOGD_IP6, "retrieving IPv6 configuration failed: SLAAC not requested and no addresses");
nm_device_ip_method_failed (device,
@ -260,15 +261,17 @@ modem_ip6_config_result (NMModem *modem,
}
/* Start SLAAC now that we have a link-local address from the modem */
ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage3_ip6_config_start (device, &ignored, &failure_reason);
g_assert (ignored == NULL);
ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage3_ip_config_start (device, AF_INET6, (gpointer *) &ignored, &failure_reason);
nm_assert (ignored == NULL);
switch (ret) {
case NM_ACT_STAGE_RETURN_FAILURE:
nm_device_ip_method_failed (device, AF_INET6, failure_reason);
break;
case NM_ACT_STAGE_RETURN_IP_FAIL:
/* all done */
nm_device_activate_schedule_ip6_config_result (device);
nm_device_activate_schedule_ip_config_result (device, AF_INET6, NULL);
break;
case NM_ACT_STAGE_RETURN_POSTPONE:
/* let SLAAC run */
@ -277,7 +280,7 @@ modem_ip6_config_result (NMModem *modem,
/* Should never get here since we've assured that the IPv6 method
* will either be "auto" or "ignored" when starting IPv6 configuration.
*/
g_assert_not_reached ();
nm_assert_not_reached ();
}
}
@ -568,14 +571,25 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
}
static NMActStageReturn
act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *out_failure_reason)
act_stage3_ip_config_start (NMDevice *device,
int addr_family,
gpointer *out_config,
NMDeviceStateReason *out_failure_reason)
{
return nm_modem_stage3_ip4_config_start (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem,
device,
NM_DEVICE_CLASS (nm_device_modem_parent_class),
out_failure_reason);
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device);
nm_assert_addr_family (addr_family);
if (addr_family == AF_INET) {
return nm_modem_stage3_ip4_config_start (priv->modem,
device,
NM_DEVICE_CLASS (nm_device_modem_parent_class),
out_failure_reason);
} else {
return nm_modem_stage3_ip6_config_start (priv->modem,
device,
out_failure_reason);
}
}
static void
@ -584,16 +598,6 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
nm_modem_ip4_pre_commit (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, device, config);
}
static NMActStageReturn
act_stage3_ip6_config_start (NMDevice *device,
NMIP6Config **out_config,
NMDeviceStateReason *out_failure_reason)
{
return nm_modem_stage3_ip6_config_start (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem,
device,
out_failure_reason);
}
static gboolean
get_ip_iface_identifier (NMDevice *device, NMUtilsIPv6IfaceId *out_iid)
{
@ -823,8 +827,7 @@ nm_device_modem_class_init (NMDeviceModemClass *klass)
device_class->deactivate = deactivate;
device_class->act_stage1_prepare = act_stage1_prepare;
device_class->act_stage2_config = act_stage2_config;
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
device_class->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
device_class->act_stage3_ip_config_start = act_stage3_ip_config_start;
device_class->ip4_config_pre_commit = ip4_config_pre_commit;
device_class->get_enabled = get_enabled;
device_class->set_enabled = set_enabled;

View file

@ -728,7 +728,7 @@ nm_modem_stage3_ip4_config_start (NMModem *self,
break;
case NM_MODEM_IP_METHOD_AUTO:
_LOGD ("MODEM_IP_METHOD_AUTO");
ret = device_class->act_stage3_ip4_config_start (device, NULL, out_failure_reason);
ret = device_class->act_stage3_ip_config_start (device, AF_INET, NULL, out_failure_reason);
break;
default:
_LOGI ("IPv4 configuration disabled");

View file

@ -244,16 +244,20 @@ nm_ethernet_address_is_valid (gconstpointer addr, gssize len)
gconstpointer
nm_utils_ipx_address_clear_host_address (int family, gpointer dst, gconstpointer src, guint8 plen)
{
g_return_val_if_fail (src, NULL);
g_return_val_if_fail (dst, NULL);
switch (family) {
case AF_INET:
g_return_val_if_fail (plen <= 32, NULL);
if (!src) {
/* allow "self-assignment", by specifying %NULL as source. */
src = dst;
}
*((guint32 *) dst) = nm_utils_ip4_address_clear_host_address (*((guint32 *) src), plen);
break;
case AF_INET6:
g_return_val_if_fail (plen <= 128, NULL);
nm_utils_ip6_address_clear_host_address (dst, src, plen);
break;
default:
@ -4017,7 +4021,7 @@ nm_utils_get_reverse_dns_domains_ip6 (const struct in6_addr *ip, guint8 plen, GP
return;
memcpy (&addr, ip, sizeof (struct in6_addr));
nm_utils_ip6_address_clear_host_address (&addr, &addr, plen);
nm_utils_ip6_address_clear_host_address (&addr, NULL, plen);
/* Number of nibbles to include in domains */
nibbles = (plen - 1) / 4 + 1;

View file

@ -1456,11 +1456,7 @@ get_route_table (NMVpnConnection *self,
connection = _get_applied_connection (self);
if (connection) {
if (addr_family == AF_INET)
s_ip = nm_connection_get_setting_ip4_config (connection);
else
s_ip = nm_connection_get_setting_ip6_config (connection);
s_ip = nm_connection_get_setting_ip_config (connection, addr_family);
if (s_ip)
route_table = nm_setting_ip_config_get_route_table (s_ip);
}