core: export interface flags of devices

Add a new read-only "InterfaceFlags" property to the Device interface
to export via D-Bus kernel flags and possibly other NM specific
flags. At the moment IFF_UP and IFF_LOWERUP are implemented.
This commit is contained in:
Beniamino Galvani 2019-10-10 09:23:22 +02:00
parent 6c86f68ac4
commit 1b90ad41bb
5 changed files with 66 additions and 0 deletions

View file

@ -278,6 +278,17 @@
-->
<property name="Ip6Connectivity" type="u" access="read"/>
<!--
InterfaceFlags:
The flags of the network interface. See
<link linkend="NMDeviceInterfaceFlags">NMDeviceInterfaceFlags</link> for
the currently defined flags.
Since: 1.22
-->
<property name="InterfaceFlags" type="u" access="read"/>
<!--
Reapply:
@connection: The optional connection settings that will be reapplied on the device. If empty, the currently active settings-connection will be used. The connection cannot arbitrarly differ from the current applied-connection otherwise the call will fail. Only certain changes are supported, like adding or removing IP addresses.

View file

@ -1150,4 +1150,23 @@ typedef enum { /*< flags >*/
NM_MANAGER_RELOAD_FLAG_ALL = 0x7, /*< skip >*/
} NMManagerReloadFlags;
/**
* NMDeviceInterfaceFlags:
* @NM_DEVICE_INTERFACE_FLAG_NONE: an alias for numeric zero, no flags set.
* @NM_DEVICE_INTERFACE_FLAG_UP: the interface is enabled from the
* administrative point of view. Corresponds to kernel IFF_UP.
* @NM_DEVICE_INTERFACE_FLAG_LOWER_UP: the physical link is up. Corresponds
* to kernel IFF_LOWER_UP.
*
* Flags for a network interface.
*
* Since: 1.22
*/
typedef enum { /*< flags >*/
/* kernel flags */
NM_DEVICE_INTERFACE_FLAG_NONE = 0, /*< skip >*/
NM_DEVICE_INTERFACE_FLAG_UP = 0x1,
NM_DEVICE_INTERFACE_FLAG_LOWER_UP = 0x2,
} NMDeviceInterfaceFlags;
#endif /* __NM_DBUS_INTERFACE_H__ */

View file

@ -1640,6 +1640,7 @@ global:
nm_client_get_dbus_name_owner;
nm_client_reload;
nm_client_reload_finish;
nm_device_interface_flags_get_type;
nm_manager_reload_flags_get_type;
nm_setting_gsm_get_auto_config;
} libnm_1_20_0;

View file

@ -225,6 +225,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDevice,
PROP_RX_BYTES,
PROP_IP4_CONNECTIVITY,
PROP_IP6_CONNECTIVITY,
PROP_INTERFACE_FLAGS,
);
typedef struct _NMDevicePrivate {
@ -583,6 +584,7 @@ typedef struct _NMDevicePrivate {
} concheck_x[2];
guint check_delete_unrealized_id;
guint32 interface_flags;
struct {
SriovOp *pending; /* SR-IOV operation currently running */
@ -3804,6 +3806,23 @@ ndisc_set_router_config (NMNDisc *ndisc, NMDevice *self)
g_array_unref (dns_domains);
}
static void
device_update_interface_flags (NMDevice *self, const NMPlatformLink *plink)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMDeviceInterfaceFlags flags = NM_DEVICE_INTERFACE_FLAG_NONE;
if (plink && NM_FLAGS_HAS (plink->n_ifi_flags, IFF_UP))
flags |= NM_DEVICE_INTERFACE_FLAG_UP;
if (plink && NM_FLAGS_HAS (plink->n_ifi_flags, IFF_LOWER_UP))
flags |= NM_DEVICE_INTERFACE_FLAG_LOWER_UP;
if (flags != priv->interface_flags) {
priv->interface_flags = flags;
_notify (self, PROP_INTERFACE_FLAGS);
}
}
static gboolean
device_link_changed (NMDevice *self)
{
@ -3891,6 +3910,8 @@ device_link_changed (NMDevice *self)
&& !nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER))
nm_device_set_carrier (self, pllink->connected);
device_update_interface_flags (self, pllink);
klass->link_changed (self, pllink);
/* Update DHCP, etc, if needed */
@ -4243,6 +4264,8 @@ nm_device_update_from_platform_link (NMDevice *self, const NMPlatformLink *plink
_notify (self, PROP_IFINDEX);
NM_DEVICE_GET_CLASS (self)->link_changed (self, plink);
}
device_update_interface_flags (self, plink);
}
/*****************************************************************************/
@ -17265,6 +17288,9 @@ get_property (GObject *object, guint prop_id,
case PROP_IP6_CONNECTIVITY:
g_value_set_uint (value, priv->concheck_x[0].state);
break;
case PROP_INTERFACE_FLAGS:
g_value_set_uint (value, priv->interface_flags);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -17353,6 +17379,7 @@ static const NMDBusInterfaceInfoExtended interface_info_device = {
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Real", "b", NM_DEVICE_REAL),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("Ip4Connectivity", "u", NM_DEVICE_IP4_CONNECTIVITY),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("Ip6Connectivity", "u", NM_DEVICE_IP6_CONNECTIVITY),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("InterfaceFlags", "u", NM_DEVICE_INTERFACE_FLAGS),
),
),
};
@ -17628,6 +17655,13 @@ nm_device_class_init (NMDeviceClass *klass)
NM_CONNECTIVITY_UNKNOWN, NM_CONNECTIVITY_FULL, NM_CONNECTIVITY_UNKNOWN,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_INTERFACE_FLAGS] =
g_param_spec_uint (NM_DEVICE_INTERFACE_FLAGS, "", "",
0,
G_MAXUINT32,
0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);

View file

@ -132,6 +132,7 @@ nm_device_state_reason_check (NMDeviceStateReason reason)
#define NM_DEVICE_IP4_CONNECTIVITY "ip4-connectivity"
#define NM_DEVICE_IP6_CONNECTIVITY "ip6-connectivity"
#define NM_DEVICE_INTERFACE_FLAGS "interface-flags"
#define NM_TYPE_DEVICE (nm_device_get_type ())
#define NM_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE, NMDevice))