device: add nm_device_get_applied_setting()

This commit is contained in:
Beniamino Galvani 2016-02-11 21:33:15 +01:00
parent ac97715688
commit b3401bf921
10 changed files with 44 additions and 97 deletions

View file

@ -449,7 +449,6 @@ act_stage3_ip4_config_start (NMDevice *device,
{
NMDeviceAdsl *self = NM_DEVICE_ADSL (device);
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self);
NMConnection *connection;
NMSettingAdsl *s_adsl;
NMActRequest *req;
GError *err = NULL;
@ -458,11 +457,7 @@ act_stage3_ip4_config_start (NMDevice *device,
req = nm_device_get_act_request (device);
g_assert (req);
connection = nm_act_request_get_applied_connection (req);
g_assert (req);
s_adsl = nm_connection_get_setting_adsl (connection);
s_adsl = (NMSettingAdsl *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_ADSL);
g_assert (s_adsl);
/* PPPoE uses the NAS interface, not the ATM interface */

View file

@ -64,8 +64,6 @@ G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE)
#define PPPOE_RECONNECT_DELAY 7
#define PPPOE_ENCAP_OVERHEAD 8 /* 2 bytes for PPP, 6 for PPPoE */
static NMSetting *device_get_setting (NMDevice *device, GType setting_type);
typedef struct Supplicant {
NMSupplicantManager *mgr;
NMSupplicantInterface *iface;
@ -429,26 +427,6 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return TRUE;
}
/* FIXME: Move it to nm-device.c and then get rid of all foo_device_get_setting() all around.
It's here now to keep the patch short. */
static NMSetting *
device_get_setting (NMDevice *device, GType setting_type)
{
NMActRequest *req;
NMSetting *setting = NULL;
req = nm_device_get_act_request (device);
if (req) {
NMConnection *connection;
connection = nm_act_request_get_applied_connection (req);
if (connection)
setting = nm_connection_get_setting (connection, setting_type);
}
return setting;
}
/*****************************************************************************/
/* 802.1X */
@ -830,7 +808,6 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
NMActRequest *req;
NMSettingWired *s_wired;
const char *cloned_mac;
NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS;
@ -839,10 +816,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
ret = NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->act_stage1_prepare (dev, reason);
if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
req = nm_device_get_act_request (NM_DEVICE (self));
g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
s_wired = (NMSettingWired *) device_get_setting (dev, NM_TYPE_SETTING_WIRED);
s_wired = (NMSettingWired *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_WIRED);
if (s_wired) {
/* Set device MAC address if the connection wants to change it */
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
@ -858,7 +832,8 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
if (priv->last_pppoe_time) {
gint32 delay = nm_utils_get_monotonic_timestamp_s () - priv->last_pppoe_time;
if (delay < PPPOE_RECONNECT_DELAY && device_get_setting (dev, NM_TYPE_SETTING_PPPOE)) {
if ( delay < PPPOE_RECONNECT_DELAY
&& nm_device_get_applied_setting (dev, NM_TYPE_SETTING_PPPOE)) {
_LOGI (LOGD_DEVICE, "delaying PPPoE reconnect for %d seconds to ensure peer is ready...",
delay);
g_assert (!priv->pppoe_wait_id);
@ -960,7 +935,6 @@ static NMActStageReturn
pppoe_stage3_ip4_config_start (NMDeviceEthernet *self, NMDeviceStateReason *reason)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
NMConnection *connection;
NMSettingPppoe *s_pppoe;
NMActRequest *req;
GError *err = NULL;
@ -969,10 +943,7 @@ pppoe_stage3_ip4_config_start (NMDeviceEthernet *self, NMDeviceStateReason *reas
req = nm_device_get_act_request (NM_DEVICE (self));
g_assert (req);
connection = nm_act_request_get_applied_connection (req);
g_assert (req);
s_pppoe = nm_connection_get_setting_pppoe (connection);
s_pppoe = (NMSettingPppoe *) nm_device_get_applied_setting (self, NM_TYPE_SETTING_PPPOE);
g_assert (s_pppoe);
priv->ppp_manager = nm_ppp_manager_new (nm_device_get_iface (NM_DEVICE (self)));
@ -1044,7 +1015,7 @@ dcb_configure (NMDevice *device)
dcb_timeout_cleanup (device);
s_dcb = (NMSettingDcb *) device_get_setting (device, NM_TYPE_SETTING_DCB);
s_dcb = (NMSettingDcb *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_DCB);
g_assert (s_dcb);
if (!nm_dcb_setup (nm_device_get_iface (device), s_dcb, &error)) {
_LOGW (LOGD_DCB, "Activation: (ethernet) failed to enable DCB/FCoE: %s",
@ -1190,7 +1161,7 @@ wake_on_lan_enable (NMDevice *device)
const char *password = NULL;
gs_free char *value = NULL;
s_wired = (NMSettingWired *) device_get_setting (device, NM_TYPE_SETTING_WIRED);
s_wired = (NMSettingWired *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRED);
if (s_wired) {
wol = nm_setting_wired_get_wake_on_lan (s_wired);
password = nm_setting_wired_get_wake_on_lan_password (s_wired);
@ -1235,7 +1206,8 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
s_con = NM_SETTING_CONNECTION (device_get_setting (device, NM_TYPE_SETTING_CONNECTION));
s_con = NM_SETTING_CONNECTION (nm_device_get_applied_setting (device,
NM_TYPE_SETTING_CONNECTION));
g_assert (s_con);
dcb_timeout_cleanup (device);
@ -1248,7 +1220,8 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
if (!strcmp (connection_type, NM_SETTING_WIRED_SETTING_NAME)) {
NMSetting8021x *security;
security = (NMSetting8021x *) device_get_setting (device, NM_TYPE_SETTING_802_1X);
security = (NMSetting8021x *) nm_device_get_applied_setting (device,
NM_TYPE_SETTING_802_1X);
if (security) {
/* FIXME: for now 802.1x is mutually exclusive with DCB */
return nm_8021x_stage2_config (self, reason);
@ -1258,7 +1231,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
wake_on_lan_enable (device);
/* DCB and FCoE setup */
s_dcb = (NMSettingDcb *) device_get_setting (device, NM_TYPE_SETTING_DCB);
s_dcb = (NMSettingDcb *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_DCB);
if (s_dcb) {
/* lldpad really really wants the carrier to be up */
if (nm_platform_link_is_connected (NM_PLATFORM_GET, nm_device_get_ifindex (device))) {
@ -1287,7 +1260,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
NM_SETTING_PPPOE_SETTING_NAME)) {
NMSettingPpp *s_ppp;
s_ppp = (NMSettingPpp *) device_get_setting (device, NM_TYPE_SETTING_PPP);
s_ppp = (NMSettingPpp *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_PPP);
if (s_ppp) {
guint32 mtu = 0, mru = 0, mxu;
@ -1317,7 +1290,7 @@ act_stage3_ip4_config_start (NMDevice *device,
g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
s_con = NM_SETTING_CONNECTION (device_get_setting (device, NM_TYPE_SETTING_CONNECTION));
s_con = NM_SETTING_CONNECTION (nm_device_get_applied_setting (device, NM_TYPE_SETTING_CONNECTION));
g_assert (s_con);
connection_type = nm_setting_connection_get_connection_type (s_con);
@ -1376,7 +1349,7 @@ deactivate (NMDevice *device)
dcb_carrier_cleanup (device);
/* Tear down DCB/FCoE if it was enabled */
s_dcb = (NMSettingDcb *) device_get_setting (device, NM_TYPE_SETTING_DCB);
s_dcb = (NMSettingDcb *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_DCB);
if (s_dcb) {
if (!nm_dcb_cleanup (nm_device_get_iface (device), &error)) {
_LOGW (LOGD_DEVICE | LOGD_HW, "failed to disable DCB/FCoE: %s",
@ -1386,7 +1359,7 @@ deactivate (NMDevice *device)
}
/* Set last PPPoE connection time */
if (device_get_setting (device, NM_TYPE_SETTING_PPPOE))
if (nm_device_get_applied_setting (device, NM_TYPE_SETTING_PPPOE))
NM_DEVICE_ETHERNET_GET_PRIVATE (device)->last_pppoe_time = nm_utils_get_monotonic_timestamp_s ();
/* Reset MAC address back to initial address */

View file

@ -69,8 +69,6 @@ static NMActStageReturn
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
{
NMActStageReturn ret;
NMActRequest *req;
NMConnection *connection;
NMSettingInfiniband *s_infiniband;
const char *transport_mode;
char *mode_path;
@ -82,12 +80,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
return ret;
req = nm_device_get_act_request (dev);
g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
connection = nm_act_request_get_applied_connection (req);
g_assert (connection);
s_infiniband = nm_connection_get_setting_infiniband (connection);
s_infiniband = (NMSettingInfiniband *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_INFINIBAND);
g_assert (s_infiniband);
transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband);

View file

@ -502,8 +502,6 @@ update_connection (NMDevice *device, NMConnection *connection)
static NMActStageReturn
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
{
NMActRequest *req;
NMConnection *connection;
NMSettingWired *s_wired;
const char *cloned_mac;
NMActStageReturn ret;
@ -514,13 +512,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
return ret;
req = nm_device_get_act_request (dev);
g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
connection = nm_act_request_get_applied_connection (req);
g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE);
s_wired = nm_connection_get_setting_wired (connection);
s_wired = (NMSettingWired *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_WIRED);
if (s_wired) {
/* Set device MAC address if the connection wants to change it */
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);

View file

@ -285,8 +285,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
{
NMDeviceTun *self = NM_DEVICE_TUN (device);
NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (self);
NMActRequest *req;
NMConnection *connection;
NMSettingWired *s_wired;
const char *cloned_mac;
NMActStageReturn ret;
@ -301,13 +299,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
if (g_strcmp0 (priv->mode, "tap"))
return NM_ACT_STAGE_RETURN_SUCCESS;
req = nm_device_get_act_request (device);
g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
connection = nm_act_request_get_applied_connection (req);
g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE);
s_wired = nm_connection_get_setting_wired (connection);
s_wired = (NMSettingWired *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRED);
if (s_wired) {
/* Set device MAC address if the connection wants to change it */
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);

View file

@ -546,8 +546,6 @@ update_connection (NMDevice *device, NMConnection *connection)
static NMActStageReturn
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
{
NMActRequest *req;
NMConnection *connection;
NMSettingVlan *s_vlan;
NMSettingWired *s_wired;
const char *cloned_mac;
@ -559,13 +557,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
return ret;
req = nm_device_get_act_request (dev);
g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
connection = nm_act_request_get_applied_connection (req);
g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE);
s_wired = nm_connection_get_setting_wired (connection);
s_wired = (NMSettingWired *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_WIRED);
if (s_wired) {
/* Set device MAC address if the connection wants to change it */
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
@ -573,7 +565,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_VLAN);
}
s_vlan = nm_connection_get_setting_vlan (connection);
s_vlan = (NMSettingVlan *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_VLAN);
if (s_vlan) {
gs_free NMVlanQosMapping *ingress_map = NULL;
gs_free NMVlanQosMapping *egress_map = NULL;

View file

@ -510,8 +510,6 @@ update_connection (NMDevice *device, NMConnection *connection)
static NMActStageReturn
act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
{
NMActRequest *req;
NMConnection *connection;
NMSettingWired *s_wired;
const char *cloned_mac;
NMActStageReturn ret;
@ -522,13 +520,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
return ret;
req = nm_device_get_act_request (device);
g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
connection = nm_act_request_get_applied_connection (req);
g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE);
s_wired = nm_connection_get_setting_wired (connection);
s_wired = (NMSettingWired *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRED);
if (s_wired) {
/* Set device MAC address if the connection wants to change it */
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);

View file

@ -996,6 +996,26 @@ nm_device_has_unmodified_applied_connection (NMDevice *self, NMSettingCompareFla
return nm_active_connection_has_unmodified_applied_connection ((NMActiveConnection *) priv->act_request, compare_flags);
}
NMSetting *
nm_device_get_applied_setting (NMDevice *device, GType setting_type)
{
NMActRequest *req;
NMSetting *setting = NULL;
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
req = nm_device_get_act_request (device);
if (req) {
NMConnection *connection;
connection = nm_act_request_get_applied_connection (req);
if (connection)
setting = nm_connection_get_setting (connection, setting_type);
}
return setting;
}
RfKillType
nm_device_get_rfkill_type (NMDevice *self)
{

View file

@ -377,6 +377,7 @@ NMSettingsConnection * nm_device_get_settings_connection (NMDevice *dev);
NMConnection * nm_device_get_applied_connection (NMDevice *dev);
gboolean nm_device_has_unmodified_applied_connection (NMDevice *self,
NMSettingCompareFlags compare_flags);
NMSetting * nm_device_get_applied_setting (NMDevice *dev, GType setting_type);
void nm_device_removed (NMDevice *dev);

View file

@ -502,7 +502,6 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (self);
NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS;
gs_free_error GError *error = NULL;
NMConnection *connection;
NMSettingTeam *s_team;
const char *cfg;
@ -512,9 +511,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
return ret;
connection = nm_device_get_applied_connection (device);
g_assert (connection);
s_team = nm_connection_get_setting_team (connection);
s_team = (NMSettingTeam *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_TEAM);
g_assert (s_team);
if (priv->tdc) {