core: kill stage4 (IP Config Get)

It was somewhat pointless since the IP config is always known when
stage4 gets scheduled, so why not just pass the config to stage5
immediately?  Also helps consolidate the v4/v6 failure handling
logic and makes the operational flow clearer where both v4 and
v6 are active and proceeding in parallel.
This commit is contained in:
Dan Williams 2011-10-09 22:50:04 -05:00
parent 22d72483f6
commit bdd556fe4d
8 changed files with 514 additions and 891 deletions

View file

@ -55,7 +55,6 @@ typedef struct {
char *path;
NMPPPManager *ppp_manager;
NMIP4Config *pending_ip4_config;
guint32 ip_method;
char *device;
char *iface;
@ -129,21 +128,6 @@ nm_modem_get_proxy (NMModem *self,
return priv->proxy;
}
static void
merge_ip4_config (NMActRequest *req, NMIP4Config *config)
{
NMConnection *connection;
NMSettingIP4Config *s_ip4;
/* Merge user-defined overrides into the IP4Config to be applied */
connection = nm_act_request_get_connection (req);
g_assert (connection);
s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
if (s_ip4)
nm_utils_merge_ip4_config (config, s_ip4);
}
/*****************************************************************************/
/* IP method PPP */
@ -169,7 +153,6 @@ ppp_ip4_config (NMPPPManager *ppp_manager,
gpointer user_data)
{
NMModem *self = NM_MODEM (user_data);
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
guint32 i, num;
guint32 bad_dns1 = htonl (0x0A0B0C0D);
guint32 good_dns1 = htonl (0x04020201); /* GTE nameserver */
@ -213,7 +196,6 @@ ppp_ip4_config (NMPPPManager *ppp_manager,
nm_ip4_config_add_nameserver (config, good_dns2);
}
priv->pending_ip4_config = g_object_ref (config);
g_signal_emit (self, signals[IP4_CONFIG_RESULT], 0, iface, config, NULL);
}
@ -287,22 +269,6 @@ ppp_stage3_ip4_config_start (NMModem *self,
return ret;
}
static NMActStageReturn
ppp_stage4 (NMModem *self,
NMActRequest *req,
NMIP4Config **config,
NMDeviceStateReason *reason)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
*config = priv->pending_ip4_config;
priv->pending_ip4_config = NULL;
merge_ip4_config (req, *config);
return NM_ACT_STAGE_RETURN_SUCCESS;
}
/*****************************************************************************/
/* IP method static */
@ -336,9 +302,6 @@ static_stage3_done (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
nm_ip4_config_add_nameserver (config, g_value_get_uint (value));
}
g_value_array_free (ret_array);
priv->pending_ip4_config = g_object_ref (config);
g_signal_emit (self, signals[IP4_CONFIG_RESULT], 0, NULL, config, NULL);
}
g_signal_emit (self, signals[IP4_CONFIG_RESULT], 0, NULL, config, error);
@ -368,32 +331,6 @@ static_stage3_ip4_config_start (NMModem *self,
return NM_ACT_STAGE_RETURN_POSTPONE;
}
static NMActStageReturn
static_stage4 (NMModem *self,
NMActRequest *req,
NMDevice *device,
NMIP4Config **config,
NMDeviceStateReason *reason)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
gboolean no_firmware = FALSE;
if (!nm_device_hw_bring_up (device, TRUE, &no_firmware)) {
if (no_firmware)
*reason = NM_DEVICE_STATE_REASON_FIRMWARE_MISSING;
else
*reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
return NM_ACT_STAGE_RETURN_FAILURE;
}
*config = priv->pending_ip4_config;
priv->pending_ip4_config = NULL;
merge_ip4_config (req, *config);
return NM_ACT_STAGE_RETURN_SUCCESS;
}
/*****************************************************************************/
NMActStageReturn
@ -426,49 +363,7 @@ nm_modem_stage3_ip4_config_start (NMModem *self,
ret = static_stage3_ip4_config_start (self, req, reason);
break;
case MM_MODEM_IP_METHOD_DHCP:
ret = device_class->act_stage3_ip4_config_start (device, reason);
break;
default:
nm_log_err (LOGD_MB, "unknown IP method %d", priv->ip_method);
ret = NM_ACT_STAGE_RETURN_FAILURE;
break;
}
return ret;
}
NMActStageReturn
nm_modem_stage4_get_ip4_config (NMModem *self,
NMDevice *device,
NMDeviceClass *device_class,
NMIP4Config **config,
NMDeviceStateReason *reason)
{
NMModemPrivate *priv;
NMActRequest *req;
NMActStageReturn ret;
g_return_val_if_fail (self != NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (NM_IS_MODEM (self), NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (device != NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (NM_IS_DEVICE (device), NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (device_class != NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (NM_IS_DEVICE_CLASS (device_class), NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
req = nm_device_get_act_request (device);
g_assert (req);
priv = NM_MODEM_GET_PRIVATE (self);
switch (priv->ip_method) {
case MM_MODEM_IP_METHOD_PPP:
ret = ppp_stage4 (self, req, config, reason);
break;
case MM_MODEM_IP_METHOD_STATIC:
ret = static_stage4 (self, req, device, config, reason);
break;
case MM_MODEM_IP_METHOD_DHCP:
ret = device_class->act_stage4_get_ip4_config (device, config, reason);
ret = device_class->act_stage3_ip4_config_start (device, NULL, reason);
break;
default:
nm_log_err (LOGD_MB, "unknown IP method %d", priv->ip_method);
@ -662,11 +557,6 @@ real_deactivate (NMModem *self, NMDevice *device)
priv->call = NULL;
}
if (priv->pending_ip4_config) {
g_object_unref (priv->pending_ip4_config);
priv->pending_ip4_config = NULL;
}
priv->in_bytes = priv->out_bytes = 0;
if (priv->ppp_manager) {
@ -758,44 +648,20 @@ nm_modem_device_state_changed (NMModem *self,
}
}
static gboolean
_state_is_active (NMDeviceState state)
{
return (state >= NM_DEVICE_STATE_IP_CONFIG && state <= NM_DEVICE_STATE_DEACTIVATING);
}
gboolean
nm_modem_hw_is_up (NMModem *self, NMDevice *device)
{
guint32 ip_method = NM_MODEM_GET_PRIVATE (self)->ip_method;
int ifindex = nm_device_get_ip_ifindex (device);
if (ip_method == MM_MODEM_IP_METHOD_STATIC || ip_method == MM_MODEM_IP_METHOD_DHCP) {
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
NMDeviceState state;
state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (device));
if (priv->pending_ip4_config || _state_is_active (state))
return nm_system_iface_is_up (nm_device_get_ip_ifindex (device));
}
return TRUE;
return ifindex > 0 ? nm_system_iface_is_up (ifindex) : TRUE;
}
gboolean
nm_modem_hw_bring_up (NMModem *self, NMDevice *device, gboolean *no_firmware)
{
guint32 ip_method = NM_MODEM_GET_PRIVATE (self)->ip_method;
int ifindex = nm_device_get_ip_ifindex (device);
if (ip_method == MM_MODEM_IP_METHOD_STATIC || ip_method == MM_MODEM_IP_METHOD_DHCP) {
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
NMDeviceState state;
state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (device));
if (priv->pending_ip4_config || _state_is_active (state))
return nm_system_iface_set_up (nm_device_get_ip_ifindex (device), TRUE, no_firmware);
}
return TRUE;
return ifindex > 0 ? nm_system_iface_set_up (ifindex, TRUE, no_firmware) : TRUE;
}
const char *

View file

@ -129,12 +129,6 @@ NMActStageReturn nm_modem_stage3_ip4_config_start (NMModem *modem,
NMDeviceClass *device_class,
NMDeviceStateReason *reason);
NMActStageReturn nm_modem_stage4_get_ip4_config (NMModem *modem,
NMDevice *device,
NMDeviceClass *device_class,
NMIP4Config **config,
NMDeviceStateReason *reason);
gboolean nm_modem_get_secrets (NMModem *modem,
const char *setting_name,
gboolean request_new,

View file

@ -543,7 +543,7 @@ modem_ip4_config_result (NMModem *self,
if (iface)
nm_device_set_ip_iface (device, iface);
nm_device_activate_schedule_stage4_ip4_config_get (device);
nm_device_activate_schedule_ip4_config_result (device, config);
}
}
@ -920,7 +920,9 @@ real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
}
static NMActStageReturn
real_act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason)
real_act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *reason)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
NMActStageReturn ret;
@ -931,27 +933,7 @@ real_act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason)
NM_DEVICE_CLASS (nm_device_bt_parent_class),
reason);
} else
ret = NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip4_config_start (device, reason);
return ret;
}
static NMActStageReturn
real_act_stage4_get_ip4_config (NMDevice *device,
NMIP4Config **config,
NMDeviceStateReason *reason)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
NMActStageReturn ret;
if (priv->bt_type == NM_BT_CAPABILITY_DUN) {
ret = nm_modem_stage4_get_ip4_config (NM_DEVICE_BT_GET_PRIVATE (device)->modem,
device,
NM_DEVICE_CLASS (nm_device_bt_parent_class),
config,
reason);
} else
ret = NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage4_get_ip4_config (device, config, reason);
ret = NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip4_config_start (device, out_config, reason);
return ret;
}
@ -1148,7 +1130,6 @@ nm_device_bt_class_init (NMDeviceBtClass *klass)
device_class->deactivate = real_deactivate;
device_class->act_stage2_config = real_act_stage2_config;
device_class->act_stage3_ip4_config_start = real_act_stage3_ip4_config_start;
device_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
device_class->check_connection_compatible = real_check_connection_compatible;
device_class->complete_connection = real_complete_connection;

View file

@ -1434,19 +1434,17 @@ ppp_state_changed (NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_
static void
ppp_ip4_config (NMPPPManager *ppp_manager,
const char *iface,
NMIP4Config *config,
gpointer user_data)
const char *iface,
NMIP4Config *config,
gpointer user_data)
{
NMDevice *device = NM_DEVICE (user_data);
/* Ignore PPP IP4 events that come in after initial configuration */
if (nm_device_get_state (device) != NM_DEVICE_STATE_IP_CONFIG)
return;
nm_device_set_ip_iface (device, iface);
NM_DEVICE_ETHERNET_GET_PRIVATE (device)->pending_ip4_config = g_object_ref (config);
nm_device_activate_schedule_stage4_ip4_config_get (device);
if (nm_device_get_state (device) == NM_DEVICE_STATE_IP_CONFIG) {
nm_device_set_ip_iface (device, iface);
nm_device_activate_schedule_ip4_config_result (device, config);
}
}
static NMActStageReturn
@ -1519,7 +1517,9 @@ real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
}
static NMActStageReturn
real_act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason)
real_act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *reason)
{
NMSettingConnection *s_con;
const char *connection_type;
@ -1533,61 +1533,29 @@ real_act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason)
if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME))
return pppoe_stage3_ip4_config_start (NM_DEVICE_ETHERNET (device), reason);
return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage3_ip4_config_start (device, reason);
return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage3_ip4_config_start (device, out_config, reason);
}
static NMActStageReturn
real_act_stage4_get_ip4_config (NMDevice *device,
NMIP4Config **config,
NMDeviceStateReason *reason)
static void
real_ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
NMActStageReturn ret;
NMConnection *connection;
NMSettingWired *s_wired;
guint32 mtu;
g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
/* MTU only set for plain ethernet */
if (NM_DEVICE_ETHERNET_GET_PRIVATE (device)->ppp_manager)
return;
if (!priv->ppp_manager) {
/* Regular ethernet connection. */
connection = nm_act_request_get_connection (nm_device_get_act_request (device));
g_assert (connection);
s_wired = nm_connection_get_setting_wired (connection);
g_assert (s_wired);
/* Chain up to parent */
ret = NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage4_get_ip4_config (device, config, reason);
if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
NMConnection *connection;
NMSettingWired *s_wired;
guint32 mtu;
connection = nm_act_request_get_connection (nm_device_get_act_request (device));
g_assert (connection);
s_wired = NM_SETTING_WIRED (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED));
g_assert (s_wired);
/* MTU override */
mtu = nm_setting_wired_get_mtu (s_wired);
if (mtu)
nm_ip4_config_set_mtu (*config, mtu);
}
} else {
NMConnection *connection;
NMSettingIP4Config *s_ip4;
/* PPPoE */
*config = priv->pending_ip4_config;
priv->pending_ip4_config = NULL;
/* Merge user-defined overrides into the IP4Config to be applied */
connection = nm_act_request_get_connection (nm_device_get_act_request (device));
g_assert (connection);
s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
nm_utils_merge_ip4_config (*config, s_ip4);
ret = NM_ACT_STAGE_RETURN_SUCCESS;
}
return ret;
/* MTU override */
mtu = nm_setting_wired_get_mtu (s_wired);
if (mtu)
nm_ip4_config_set_mtu (config, mtu);
}
static void
@ -2011,7 +1979,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
parent_class->act_stage1_prepare = real_act_stage1_prepare;
parent_class->act_stage2_config = real_act_stage2_config;
parent_class->act_stage3_ip4_config_start = real_act_stage3_ip4_config_start;
parent_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
parent_class->ip4_config_pre_commit = real_ip4_config_pre_commit;
parent_class->deactivate = real_deactivate;
parent_class->spec_match_list = spec_match_list;
parent_class->connection_match_config = connection_match_config;

View file

@ -155,7 +155,7 @@ modem_ip4_config_result (NMModem *self,
if (iface)
nm_device_set_ip_iface (device, iface);
nm_device_activate_schedule_stage4_ip4_config_get (device);
nm_device_activate_schedule_ip4_config_result (device, config);
}
}
@ -275,7 +275,9 @@ real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
}
static NMActStageReturn
real_act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason)
real_act_stage3_ip4_config_start (NMDevice *device,
NMIP4Config **out_config,
NMDeviceStateReason *reason)
{
return nm_modem_stage3_ip4_config_start (NM_DEVICE_MODEM_GET_PRIVATE (device)->modem,
device,
@ -283,18 +285,6 @@ real_act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason)
reason);
}
static NMActStageReturn
real_act_stage4_get_ip4_config (NMDevice *device,
NMIP4Config **config,
NMDeviceStateReason *reason)
{
return nm_modem_stage4_get_ip4_config (NM_DEVICE_MODEM_GET_PRIVATE (device)->modem,
device,
NM_DEVICE_CLASS (nm_device_modem_parent_class),
config,
reason);
}
/*****************************************************************************/
static gboolean
@ -469,7 +459,6 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass)
device_class->act_stage1_prepare = real_act_stage1_prepare;
device_class->act_stage2_config = real_act_stage2_config;
device_class->act_stage3_ip4_config_start = real_act_stage3_ip4_config_start;
device_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
/* Properties */
g_object_class_install_property

View file

@ -2684,38 +2684,22 @@ out:
return ret;
}
static NMActStageReturn
real_act_stage4_get_ip4_config (NMDevice *dev,
NMIP4Config **config,
NMDeviceStateReason *reason)
static void
real_ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
{
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
NMDeviceClass *parent_class;
NMConnection *connection;
NMSettingWireless *s_wifi;
guint32 mtu;
g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE);
g_return_val_if_fail (*config == NULL, NM_ACT_STAGE_RETURN_FAILURE);
connection = nm_act_request_get_connection (nm_device_get_act_request (device));
g_assert (connection);
s_wifi = nm_connection_get_setting_wireless (connection);
g_assert (s_wifi);
/* Chain up to parent */
parent_class = NM_DEVICE_CLASS (nm_device_wifi_parent_class);
ret = parent_class->act_stage4_get_ip4_config (dev, config, reason);
if ((ret == NM_ACT_STAGE_RETURN_SUCCESS) && *config) {
NMConnection *connection;
NMSettingWireless *s_wireless;
guint32 mtu;
connection = nm_act_request_get_connection (nm_device_get_act_request (dev));
g_assert (connection);
s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
g_assert (s_wireless);
/* MTU override */
mtu = nm_setting_wireless_get_mtu (s_wireless);
if (mtu)
nm_ip4_config_set_mtu (*config, mtu);
}
return ret;
/* MTU override */
mtu = nm_setting_wireless_get_mtu (s_wifi);
if (mtu)
nm_ip4_config_set_mtu (config, mtu);
}
static gboolean
@ -3290,7 +3274,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
parent_class->act_stage1_prepare = real_act_stage1_prepare;
parent_class->act_stage2_config = real_act_stage2_config;
parent_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
parent_class->ip4_config_pre_commit = real_ip4_config_pre_commit;
parent_class->act_stage4_ip4_config_timeout = real_act_stage4_ip4_config_timeout;
parent_class->act_stage4_ip6_config_timeout = real_act_stage4_ip6_config_timeout;
parent_class->deactivate = real_deactivate;

File diff suppressed because it is too large Load diff

View file

@ -99,19 +99,20 @@ typedef struct {
NMActStageReturn (* act_stage2_config) (NMDevice *self,
NMDeviceStateReason *reason);
NMActStageReturn (* act_stage3_ip4_config_start) (NMDevice *self,
NMIP4Config **out_config,
NMDeviceStateReason *reason);
NMActStageReturn (* act_stage3_ip6_config_start) (NMDevice *self,
NMIP6Config **out_config,
NMDeviceStateReason *reason);
NMActStageReturn (* act_stage4_get_ip4_config) (NMDevice *self,
NMIP4Config **config,
NMDeviceStateReason *reason);
NMActStageReturn (* act_stage4_get_ip6_config) (NMDevice *self,
NMIP6Config **config,
NMDeviceStateReason *reason);
NMActStageReturn (* act_stage4_ip4_config_timeout) (NMDevice *self,
NMDeviceStateReason *reason);
NMActStageReturn (* act_stage4_ip6_config_timeout) (NMDevice *self,
NMDeviceStateReason *reason);
/* Called right before IP config is set; use for setting MTU etc */
void (* ip4_config_pre_commit) (NMDevice *self, NMIP4Config *config);
void (* ip6_config_pre_commit) (NMDevice *self, NMIP6Config *config);
void (* deactivate) (NMDevice *self);
gboolean (* can_interrupt_activation) (NMDevice *self);
@ -150,8 +151,6 @@ NMDHCP6Config * nm_device_get_dhcp6_config (NMDevice *dev);
NMIP4Config * nm_device_get_ip4_config (NMDevice *dev);
NMIP6Config * nm_device_get_ip6_config (NMDevice *dev);
void * nm_device_get_system_config_data (NMDevice *dev);
NMActRequest * nm_device_get_act_request (NMDevice *dev);
gboolean nm_device_is_available (NMDevice *dev);
@ -168,10 +167,13 @@ gboolean nm_device_complete_connection (NMDevice *device,
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_stage4_ip4_config_get (NMDevice *device);
void nm_device_activate_schedule_stage4_ip4_config_timeout (NMDevice *device);
void nm_device_activate_schedule_stage4_ip6_config_get (NMDevice *device);
void nm_device_activate_schedule_stage4_ip6_config_timeout (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_ip6_config_result (NMDevice *device, NMIP6Config *config);
void nm_device_activate_schedule_ip6_config_timeout (NMDevice *device);
gboolean nm_device_is_activating (NMDevice *dev);
gboolean nm_device_can_interrupt_activation (NMDevice *self);
gboolean nm_device_autoconnect_allowed (NMDevice *self);