summary refs log tree commit diff
path: root/libnm/nm-device.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm/nm-device.c')
-rw-r--r--libnm/nm-device.c88
1 files changed, 82 insertions, 6 deletions
diff --git a/libnm/nm-device.c b/libnm/nm-device.c
index 3f1cc636..5965cb3b 100644
--- a/libnm/nm-device.c
+++ b/libnm/nm-device.c
@@ -23,7 +23,6 @@
 
 #include "nm-device.h"
 
-#include <string.h>
 #include <libudev.h>
 
 #include "nm-libnm-utils.h"
@@ -74,6 +73,8 @@ typedef struct {
 	NMDhcpConfig *dhcp4_config;
 	NMIPConfig *ip6_config;
 	NMDhcpConfig *dhcp6_config;
+	NMConnectivityState ip4_connectivity;
+	NMConnectivityState ip6_connectivity;
 	NMDeviceState state;
 	NMDeviceState last_seen_state;
 	NMDeviceStateReason reason;
@@ -120,6 +121,8 @@ enum {
 	PROP_MTU,
 	PROP_METERED,
 	PROP_LLDP_NEIGHBORS,
+	PROP_IP4_CONNECTIVITY,
+	PROP_IP6_CONNECTIVITY,
 
 	LAST_PROP
 };
@@ -144,6 +147,8 @@ nm_device_init (NMDevice *device)
 {
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
 
+	priv->ip4_connectivity = NM_CONNECTIVITY_UNKNOWN;
+	priv->ip6_connectivity = NM_CONNECTIVITY_UNKNOWN;
 	priv->state = NM_DEVICE_STATE_UNKNOWN;
 	priv->reason = NM_DEVICE_STATE_REASON_NONE;
 	priv->lldp_neighbors = g_ptr_array_new ();
@@ -216,6 +221,8 @@ init_dbus (NMObject *object)
 		{ NM_DEVICE_DHCP4_CONFIG,      &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG },
 		{ NM_DEVICE_IP6_CONFIG,        &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG },
 		{ NM_DEVICE_DHCP6_CONFIG,      &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG },
+		{ NM_DEVICE_IP4_CONNECTIVITY,  &priv->ip4_connectivity },
+		{ NM_DEVICE_IP6_CONNECTIVITY,  &priv->ip6_connectivity },
 		{ NM_DEVICE_STATE,             &priv->state },
 		{ NM_DEVICE_STATE_REASON,      &priv->reason, demarshal_state_reason },
 		{ NM_DEVICE_ACTIVE_CONNECTION, &priv->active_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
@@ -287,6 +294,7 @@ coerce_type (NMDeviceType type)
 	case NM_DEVICE_TYPE_WPAN:
 	case NM_DEVICE_TYPE_6LOWPAN:
 	case NM_DEVICE_TYPE_WIREGUARD:
+	case NM_DEVICE_TYPE_WIFI_P2P:
 		return type;
 	}
 	return NM_DEVICE_TYPE_UNKNOWN;
@@ -348,7 +356,7 @@ get_property (GObject *object,
 
 	switch (prop_id) {
 	case PROP_DEVICE_TYPE:
-		g_value_set_enum (value, coerce_type (nm_device_get_device_type (device)));
+		g_value_set_enum (value, nm_device_get_device_type (device));
 		break;
 	case PROP_UDI:
 		g_value_set_string (value, nm_device_get_udi (device));
@@ -428,6 +436,12 @@ get_property (GObject *object,
 	case PROP_LLDP_NEIGHBORS:
 		g_value_set_boxed (value, nm_device_get_lldp_neighbors (device));
 		break;
+	case PROP_IP4_CONNECTIVITY:
+		g_value_set_enum (value, nm_device_get_connectivity (device, AF_INET));
+		break;
+	case PROP_IP6_CONNECTIVITY:
+		g_value_set_enum (value, nm_device_get_connectivity (device, AF_INET6));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -701,6 +715,36 @@ nm_device_class_init (NMDeviceClass *device_class)
 		                      G_PARAM_STATIC_STRINGS));
 
 	/**
+	 * NMDevice:ip4-connectivity:
+	 *
+	 * The IPv4 connectivity state of the device.
+	 *
+	 * Since: 1.16
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_IP4_CONNECTIVITY,
+		 g_param_spec_enum (NM_DEVICE_IP4_CONNECTIVITY, "", "",
+		                    NM_TYPE_CONNECTIVITY_STATE,
+		                    NM_CONNECTIVITY_UNKNOWN,
+		                    G_PARAM_READABLE |
+		                    G_PARAM_STATIC_STRINGS));
+
+	/**
+	 * NMDevice:ip6-connectivity:
+	 *
+	 * The IPv6 connectivity state of the device.
+	 *
+	 * Since: 1.16
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_IP6_CONNECTIVITY,
+		 g_param_spec_enum (NM_DEVICE_IP6_CONNECTIVITY, "", "",
+		                    NM_TYPE_CONNECTIVITY_STATE,
+		                    NM_CONNECTIVITY_UNKNOWN,
+		                    G_PARAM_READABLE |
+		                    G_PARAM_STATIC_STRINGS));
+
+	/**
 	 * NMDevice:state:
 	 *
 	 * The state of the device.
@@ -893,7 +937,7 @@ nm_device_get_device_type (NMDevice *self)
 {
 	g_return_val_if_fail (NM_IS_DEVICE (self), NM_DEVICE_TYPE_UNKNOWN);
 
-	return NM_DEVICE_GET_PRIVATE (self)->device_type;
+	return coerce_type (NM_DEVICE_GET_PRIVATE (self)->device_type);
 }
 
 /**
@@ -1231,6 +1275,36 @@ nm_device_get_dhcp6_config (NMDevice *device)
 }
 
 /**
+ * nm_device_get_connectivity:
+ * @device: a #NMDevice
+ * @addr_family: network address family
+ *
+ * The connectivity state of the device for given address family.
+ * Supported address families are %AF_INET for IPv4, %AF_INET6
+ * for IPv6 or %AF_UNSPEC for any.
+ *
+ * Returns: the current connectivity state
+ *
+ * Since: 1.16
+ **/
+NMConnectivityState
+nm_device_get_connectivity (NMDevice *device, int addr_family)
+{
+	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
+
+	switch (addr_family) {
+	case AF_INET:
+		return priv->ip4_connectivity;
+	case AF_INET6:
+		return priv->ip6_connectivity;
+	case AF_UNSPEC:
+		return NM_MAX (priv->ip4_connectivity, priv->ip6_connectivity);
+	default:
+		g_return_val_if_reached (NM_CONNECTIVITY_UNKNOWN);
+	}
+}
+
+/**
  * nm_device_get_state:
  * @device: a #NMDevice
  *
@@ -1354,6 +1428,8 @@ get_type_name (NMDevice *device)
 		return _("6LoWPAN");
 	case NM_DEVICE_TYPE_WIREGUARD:
 		return _("WireGuard");
+	case NM_DEVICE_TYPE_WIFI_P2P:
+		return _("Wi-Fi P2P");
 	case NM_DEVICE_TYPE_GENERIC:
 	case NM_DEVICE_TYPE_UNUSED1:
 	case NM_DEVICE_TYPE_UNUSED2:
@@ -2059,7 +2135,7 @@ nm_device_reapply_finish (NMDevice *device,
  * nm_device_get_applied_connection:
  * @device: a #NMDevice
  * @flags: the flags argument. Currently this value must always be zero.
- * @version_id: (out): (allow-none): returns the current version id of
+ * @version_id: (out) (allow-none): returns the current version id of
  *   the applied connection
  * @cancellable: a #GCancellable, or %NULL
  * @error: location for a #GError, or %NULL
@@ -2193,7 +2269,7 @@ nm_device_get_applied_connection_async  (NMDevice *device,
  * nm_device_get_applied_connection_finish:
  * @device: a #NMDevice
  * @result: the result passed to the #GAsyncReadyCallback
- * @version_id: (out): (allow-none): the current version id of the applied
+ * @version_id: (out) (allow-none): the current version id of the applied
  *   connection.
  * @error: location for a #GError, or %NULL
  *
@@ -2392,7 +2468,7 @@ device_delete_cb (GObject *proxy,
  * @callback: callback to be called when delete operation completes
  * @user_data: caller-specific data passed to @callback
  *
- * Asynchronously begins deleteing the software device. Hardware devices can't
+ * Asynchronously begins deleting the software device. Hardware devices can't
  * be deleted.
  **/
 void