summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-06-17 18:53:45 +0200
committerThomas Haller <thaller@redhat.com>2016-06-30 08:29:55 +0200
commit6db3c80aba13e401d0f4ed87f65849b985feb2ed (patch)
treea8e8e78f4fe573e763c8fb5e983f0d0532012fd8
parent2a94587232f5ac401cd8d2f13729836f731566f2 (diff)
downloadNetworkManager-6db3c80aba13e401d0f4ed87f65849b985feb2ed.tar.gz
device: implememnt "perm-hw-address" property in NMDevice
Both NMDeviceEthernet and NMDeviceWifi have a property "perm-hw-address". As the hw_addr_perm property is tracked in the parent NMDevice class, let it also implement the GObject property. Then it knows better when to emit a notification about property changes.
-rw-r--r--src/devices/nm-device-ethernet.c20
-rw-r--r--src/devices/nm-device-ethernet.h1
-rw-r--r--src/devices/nm-device.c23
-rw-r--r--src/devices/nm-device.h5
-rw-r--r--src/devices/wifi/nm-device-wifi.c20
-rw-r--r--src/devices/wifi/nm-device-wifi.h1
6 files changed, 22 insertions, 48 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index f38798234a..ad498004d4 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -120,7 +120,6 @@ typedef struct {
enum {
PROP_0,
- PROP_PERM_HW_ADDRESS,
PROP_SPEED,
PROP_S390_SUBCHANNELS,
@@ -307,14 +306,6 @@ nm_device_ethernet_init (NMDeviceEthernet *self)
priv->s390_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
-static void
-realize_start_notify (NMDevice *device, const NMPlatformLink *plink)
-{
- NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->realize_start_notify (device, plink);
-
- g_object_notify (G_OBJECT (device), NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
-}
-
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *device)
{
@@ -1635,9 +1626,6 @@ get_property (GObject *object, guint prop_id,
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
switch (prop_id) {
- case PROP_PERM_HW_ADDRESS:
- g_value_set_string (value, nm_device_get_permanent_hw_address ((NMDevice *) object, FALSE));
- break;
case PROP_SPEED:
g_value_set_uint (value, priv->speed);
break;
@@ -1679,7 +1667,6 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
object_class->set_property = set_property;
parent_class->get_generic_capabilities = get_generic_capabilities;
- parent_class->realize_start_notify = realize_start_notify;
parent_class->check_connection_compatible = check_connection_compatible;
parent_class->complete_connection = complete_connection;
parent_class->new_default_connection = new_default_connection;
@@ -1699,13 +1686,6 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
/* properties */
g_object_class_install_property
- (object_class, PROP_PERM_HW_ADDRESS,
- g_param_spec_string (NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property
(object_class, PROP_SPEED,
g_param_spec_uint (NM_DEVICE_ETHERNET_SPEED, "", "",
0, G_MAXUINT32, 0,
diff --git a/src/devices/nm-device-ethernet.h b/src/devices/nm-device-ethernet.h
index 2d284822d2..e39d689666 100644
--- a/src/devices/nm-device-ethernet.h
+++ b/src/devices/nm-device-ethernet.h
@@ -33,7 +33,6 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_ETHERNET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_ETHERNET))
#define NM_DEVICE_ETHERNET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetClass))
-#define NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS "perm-hw-address"
#define NM_DEVICE_ETHERNET_SPEED "speed"
#define NM_DEVICE_ETHERNET_S390_SUBCHANNELS "s390-subchannels"
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 6e5660be5c..d857288290 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -132,6 +132,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDevice,
PROP_IS_MASTER,
PROP_MASTER,
PROP_HW_ADDRESS,
+ PROP_PERM_HW_ADDRESS,
PROP_HAS_PENDING_ACTION,
PROP_METERED,
PROP_LLDP_NEIGHBORS,
@@ -2357,6 +2358,7 @@ nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error)
}
g_clear_pointer (&priv->hw_addr_perm, g_free);
+ _notify (self, PROP_PERM_HW_ADDRESS);
g_clear_pointer (&priv->hw_addr_initial, g_free);
priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED;
@@ -11467,13 +11469,13 @@ nm_device_update_permanent_hw_address (NMDevice *self)
priv->hw_addr);
priv->hw_addr_perm_fake = TRUE;
priv->hw_addr_perm = g_strdup (priv->hw_addr);
- return;
+ } else {
+ priv->hw_addr_perm_fake = FALSE;
+ priv->hw_addr_perm = nm_utils_hwaddr_ntoa (buf, len);
+ _LOGD (LOGD_DEVICE, "hw-addr: read permanent MAC address '%s'",
+ priv->hw_addr_perm);
}
-
- priv->hw_addr_perm_fake = FALSE;
- priv->hw_addr_perm = nm_utils_hwaddr_ntoa (buf, len);
- _LOGD (LOGD_DEVICE, "hw-addr: read permanent MAC address '%s'",
- priv->hw_addr_perm);
+ _notify (self, PROP_PERM_HW_ADDRESS);
}
static gboolean
@@ -12104,6 +12106,10 @@ get_property (GObject *object, guint prop_id,
case PROP_HW_ADDRESS:
g_value_set_string (value, priv->hw_addr);
break;
+ case PROP_PERM_HW_ADDRESS:
+ /* this property is exposed on D-Bus for NMDeviceEthernet and NMDeviceWifi. */
+ g_value_set_string (value, nm_device_get_permanent_hw_address (self, FALSE));
+ break;
case PROP_HAS_PENDING_ACTION:
g_value_set_boolean (value, nm_device_has_pending_action (self));
break;
@@ -12349,6 +12355,11 @@ nm_device_class_init (NMDeviceClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_PERM_HW_ADDRESS] =
+ g_param_spec_string (NM_DEVICE_PERM_HW_ADDRESS, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
obj_properties[PROP_HAS_PENDING_ACTION] =
g_param_spec_boolean (NM_DEVICE_HAS_PENDING_ACTION, "", "",
FALSE,
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index bd8e64a9ab..181ad8e1c5 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -57,6 +57,11 @@
#define NM_DEVICE_PHYSICAL_PORT_ID "physical-port-id"
#define NM_DEVICE_MTU "mtu"
#define NM_DEVICE_HW_ADDRESS "hw-address"
+
+/* "perm-hw-address" is exposed on D-Bus both for NMDeviceEthernet
+ * and NMDeviceWifi. */
+#define NM_DEVICE_PERM_HW_ADDRESS "perm-hw-address"
+
#define NM_DEVICE_METERED "metered"
#define NM_DEVICE_LLDP_NEIGHBORS "lldp-neighbors"
#define NM_DEVICE_REAL "real"
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index e126a98e82..bb5fd30aba 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -71,7 +71,6 @@ G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE)
enum {
PROP_0,
- PROP_PERM_HW_ADDRESS,
PROP_MODE,
PROP_BITRATE,
PROP_ACCESS_POINTS,
@@ -403,14 +402,6 @@ periodic_update_cb (gpointer user_data)
return TRUE;
}
-static void
-realize_start_notify (NMDevice *device, const NMPlatformLink *plink)
-{
- NM_DEVICE_CLASS (nm_device_wifi_parent_class)->realize_start_notify (device, plink);
-
- g_object_notify (G_OBJECT (device), NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS);
-}
-
static gboolean
bring_up (NMDevice *device, gboolean *no_firmware)
{
@@ -2980,9 +2971,6 @@ get_property (GObject *object, guint prop_id,
GPtrArray *array;
switch (prop_id) {
- case PROP_PERM_HW_ADDRESS:
- g_value_set_string (value, nm_device_get_permanent_hw_address ((NMDevice *) device, FALSE));
- break;
case PROP_MODE:
g_value_set_uint (value, priv->mode);
break;
@@ -3047,7 +3035,6 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
object_class->dispose = dispose;
object_class->finalize = finalize;
- parent_class->realize_start_notify = realize_start_notify;
parent_class->bring_up = bring_up;
parent_class->can_auto_connect = can_auto_connect;
parent_class->is_available = is_available;
@@ -3071,13 +3058,6 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
/* Properties */
g_object_class_install_property
- (object_class, PROP_PERM_HW_ADDRESS,
- g_param_spec_string (NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, "", "",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property
(object_class, PROP_MODE,
g_param_spec_uint (NM_DEVICE_WIFI_MODE, "", "",
NM_802_11_MODE_UNKNOWN,
diff --git a/src/devices/wifi/nm-device-wifi.h b/src/devices/wifi/nm-device-wifi.h
index 7e0d06f5a1..2b7e8217a6 100644
--- a/src/devices/wifi/nm-device-wifi.h
+++ b/src/devices/wifi/nm-device-wifi.h
@@ -36,7 +36,6 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_WIFI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_WIFI))
#define NM_DEVICE_WIFI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_WIFI, NMDeviceWifiClass))
-#define NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS "perm-hw-address"
#define NM_DEVICE_WIFI_MODE "mode"
#define NM_DEVICE_WIFI_BITRATE "bitrate"
#define NM_DEVICE_WIFI_ACCESS_POINTS "access-points"