device: refactor dhcp-anycast-address handling for OLPC mesh device

dhcp-anycast-address is only set by OLPC mesh device. It's ugly to have
this in form of a nm_device_set_dhcp_anycast_address() method, because
that means to cache the address in NMDevice. Meaning, we have more state
in NMDevice, where it's not clear where it comes from.

Instead, whenever we need to DHCP anycast address, as the subclass to
provide it (if any). This way, it gets extracted from the currently
applied connection at the moment when it is needed. Beyond that, the
setting is not duplicated/cached in NMDevice anymore.
This commit is contained in:
Thomas Haller 2021-05-12 12:47:33 +02:00
parent ca6d30cb24
commit bb1a495213
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
4 changed files with 31 additions and 26 deletions

View file

@ -109,8 +109,6 @@ 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);
gboolean nm_device_dhcp4_renew(NMDevice *device, gboolean release);
gboolean nm_device_dhcp6_renew(NMDevice *device, gboolean release);

View file

@ -499,9 +499,6 @@ typedef struct _NMDevicePrivate {
NMDeviceStageState stage1_sriov_state : 3;
/* Generic DHCP stuff */
char *dhcp_anycast_address;
char *current_stable_id;
/* Proxy Configuration */
@ -8901,6 +8898,21 @@ ensure_con_ip_config(NMDevice *self, int addr_family)
/*****************************************************************************/
static const char *
_device_get_dhcp_anycast_address(NMDevice *self)
{
NMDeviceClass *klass;
nm_assert(NM_IS_DEVICE(self));
klass = NM_DEVICE_GET_CLASS(self);
if (klass->get_dhcp_anycast_address)
return klass->get_dhcp_anycast_address(self);
return NULL;
}
static void
dhcp4_cleanup(NMDevice *self, CleanupType cleanup_type, gboolean release)
{
@ -9469,7 +9481,7 @@ dhcp4_start(NMDevice *self)
_prop_get_connection_mud_url(self, s_con, &mud_url_free),
client_id,
_prop_get_ipvx_dhcp_timeout(self, AF_INET),
priv->dhcp_anycast_address,
_device_get_dhcp_anycast_address(self),
NULL,
vendor_class_identifier,
reject_servers,
@ -9922,7 +9934,7 @@ dhcp6_start_with_link_ready(NMDevice *self, NMConnection *connection)
iaid,
iaid_explicit,
_prop_get_ipvx_dhcp_timeout(self, AF_INET6),
priv->dhcp_anycast_address,
_device_get_dhcp_anycast_address(self),
nm_setting_ip6_config_get_ip6_privacy(NM_SETTING_IP6_CONFIG(s_ip6)),
priv->dhcp6.needed_prefixes,
&error);
@ -15075,20 +15087,6 @@ nm_device_set_unmanaged_by_quitting(NMDevice *self)
/*****************************************************************************/
void
nm_device_set_dhcp_anycast_address(NMDevice *self, const char *addr)
{
NMDevicePrivate *priv;
g_return_if_fail(NM_IS_DEVICE(self));
g_return_if_fail(!addr || nm_utils_hwaddr_valid(addr, ETH_ALEN));
priv = NM_DEVICE_GET_PRIVATE(self);
g_free(priv->dhcp_anycast_address);
priv->dhcp_anycast_address = g_strdup(addr);
}
void
nm_device_reapply_settings_immediately(NMDevice *self)
{
@ -18448,7 +18446,6 @@ finalize(GObject *object)
g_free(priv->driver_version);
g_free(priv->firmware_version);
g_free(priv->type_desc);
g_free(priv->dhcp_anycast_address);
g_free(priv->current_stable_id);
g_hash_table_unref(priv->ip6_saved_properties);

View file

@ -412,6 +412,8 @@ typedef struct _NMDeviceClass {
gboolean (*set_platform_mtu)(NMDevice *self, guint32 mtu);
const char *(*get_dhcp_anycast_address)(NMDevice *self);
} NMDeviceClass;
GType nm_device_get_type(void);

View file

@ -122,6 +122,17 @@ complete_connection(NMDevice * device,
/*****************************************************************************/
static const char *
get_dhcp_anycast_address(NMDevice *device)
{
NMSettingOlpcMesh *s_mesh;
s_mesh = nm_device_get_applied_setting(device, NM_TYPE_SETTING_OLPC_MESH);
return s_mesh ? nm_setting_olpc_mesh_get_dhcp_anycast_address(s_mesh) : NULL;
}
/*****************************************************************************/
static NMActStageReturn
act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason)
{
@ -178,7 +189,6 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason)
NMDeviceOlpcMesh * self = NM_DEVICE_OLPC_MESH(device);
NMSettingOlpcMesh *s_mesh;
GBytes * ssid;
const char * anycast_addr;
gboolean success;
s_mesh = nm_device_get_applied_setting(device, NM_TYPE_SETTING_OLPC_MESH);
@ -197,9 +207,6 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason)
return NM_ACT_STAGE_RETURN_FAILURE;
}
anycast_addr = nm_setting_olpc_mesh_get_dhcp_anycast_address(s_mesh);
nm_device_set_dhcp_anycast_address(device, anycast_addr);
if (!_mesh_set_channel(self, nm_setting_olpc_mesh_get_channel(s_mesh))) {
_LOGW(LOGD_WIFI, "Unable to set the mesh channel");
return NM_ACT_STAGE_RETURN_FAILURE;
@ -527,6 +534,7 @@ nm_device_olpc_mesh_class_init(NMDeviceOlpcMeshClass *klass)
device_class->act_stage2_config = act_stage2_config;
device_class->state_changed = state_changed;
device_class->get_dhcp_timeout_for_device = get_dhcp_timeout_for_device;
device_class->get_dhcp_anycast_address = get_dhcp_anycast_address;
obj_properties[PROP_COMPANION] = g_param_spec_string(NM_DEVICE_OLPC_MESH_COMPANION,
"",