Beniamino Galvani 2019-11-22 10:21:17 +01:00
commit d99c91a05a
20 changed files with 1678 additions and 417 deletions

View file

@ -551,6 +551,44 @@ const NmcMetaGenericInfo *const metagen_device_detail_wifi_properties[_NMC_GENER
_METAGEN_DEVICE_DETAIL_WIFI_PROPERTIES (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_IBSS_RSN, "IBSS-RSN"),
};
/*****************************************************************************/
static gconstpointer
_metagen_device_detail_interface_flags_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
{
NMDevice *d = target;
NMDeviceInterfaceFlags flags;
NMC_HANDLE_COLOR (NM_META_COLOR_NONE);
flags = nm_device_get_interface_flags (d);
switch (info->info_type) {
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_UP:
return nmc_meta_generic_get_bool (NM_FLAGS_HAS (flags, NM_DEVICE_INTERFACE_FLAG_UP),
get_type);
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_LOWER_UP:
return nmc_meta_generic_get_bool (NM_FLAGS_HAS (flags, NM_DEVICE_INTERFACE_FLAG_LOWER_UP),
get_type);
case NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_CARRIER:
return nmc_meta_generic_get_bool (NM_FLAGS_HAS (flags, NM_DEVICE_INTERFACE_FLAG_CARRIER),
get_type);
default:
break;
}
g_return_val_if_reached (NULL);
}
const NmcMetaGenericInfo *const metagen_device_detail_interface_flags[_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_NUM + 1] = {
#define _METAGEN_DEVICE_DETAIL_INTERFACE_FLAGS(type, name) \
[type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_device_detail_interface_flags_get_fcn)
_METAGEN_DEVICE_DETAIL_INTERFACE_FLAGS (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_UP, "UP"),
_METAGEN_DEVICE_DETAIL_INTERFACE_FLAGS (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_LOWER_UP, "LOWER-UP"),
_METAGEN_DEVICE_DETAIL_INTERFACE_FLAGS (NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_CARRIER, "CARRIER"),
};
/*****************************************************************************/
const NmcMetaGenericInfo *const metagen_device_detail_wimax_properties[] = {
@ -631,23 +669,24 @@ const NmcMetaGenericInfo *const nmc_fields_dev_show_bluetooth[] = {
/* Available sections for 'device show' */
const NmcMetaGenericInfo *const nmc_fields_dev_show_sections[] = {
NMC_META_GENERIC_WITH_NESTED ("GENERAL", metagen_device_detail_general), /* 0 */
NMC_META_GENERIC_WITH_NESTED ("CAPABILITIES", metagen_device_detail_capabilities), /* 1 */
NMC_META_GENERIC_WITH_NESTED ("WIFI-PROPERTIES", metagen_device_detail_wifi_properties), /* 2 */
NMC_META_GENERIC_WITH_NESTED ("AP", nmc_fields_dev_wifi_list + 1), /* 3 */
NMC_META_GENERIC_WITH_NESTED ("WIRED-PROPERTIES", metagen_device_detail_wired_properties), /* 4 */
NMC_META_GENERIC_WITH_NESTED ("WIMAX-PROPERTIES", metagen_device_detail_wimax_properties), /* 5 */
NMC_META_GENERIC_WITH_NESTED ("NSP", nmc_fields_dev_wimax_list + 1), /* 6 */
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 7 */
NMC_META_GENERIC_WITH_NESTED ("DHCP4", metagen_dhcp_config), /* 8 */
NMC_META_GENERIC_WITH_NESTED ("IP6", metagen_ip6_config), /* 9 */
NMC_META_GENERIC_WITH_NESTED ("DHCP6", metagen_dhcp_config), /* 10 */
NMC_META_GENERIC_WITH_NESTED ("BOND", nmc_fields_dev_show_master_prop + 1), /* 11 */
NMC_META_GENERIC_WITH_NESTED ("TEAM", nmc_fields_dev_show_team_prop + 1), /* 12 */
NMC_META_GENERIC_WITH_NESTED ("BRIDGE", nmc_fields_dev_show_master_prop + 1), /* 13 */
NMC_META_GENERIC_WITH_NESTED ("VLAN", nmc_fields_dev_show_vlan_prop + 1), /* 14 */
NMC_META_GENERIC_WITH_NESTED ("BLUETOOTH", nmc_fields_dev_show_bluetooth + 1), /* 15 */
NMC_META_GENERIC_WITH_NESTED ("CONNECTIONS", metagen_device_detail_connections), /* 16 */
NMC_META_GENERIC_WITH_NESTED ("GENERAL", metagen_device_detail_general), /* 0 */
NMC_META_GENERIC_WITH_NESTED ("CAPABILITIES", metagen_device_detail_capabilities), /* 1 */
NMC_META_GENERIC_WITH_NESTED ("INTERFACE-FLAGS", metagen_device_detail_interface_flags), /* 2 */
NMC_META_GENERIC_WITH_NESTED ("WIFI-PROPERTIES", metagen_device_detail_wifi_properties), /* 3 */
NMC_META_GENERIC_WITH_NESTED ("AP", nmc_fields_dev_wifi_list + 1), /* 4 */
NMC_META_GENERIC_WITH_NESTED ("WIRED-PROPERTIES", metagen_device_detail_wired_properties), /* 5 */
NMC_META_GENERIC_WITH_NESTED ("WIMAX-PROPERTIES", metagen_device_detail_wimax_properties), /* 6 */
NMC_META_GENERIC_WITH_NESTED ("NSP", nmc_fields_dev_wimax_list + 1), /* 7 */
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 8 */
NMC_META_GENERIC_WITH_NESTED ("DHCP4", metagen_dhcp_config), /* 9 */
NMC_META_GENERIC_WITH_NESTED ("IP6", metagen_ip6_config), /* 10 */
NMC_META_GENERIC_WITH_NESTED ("DHCP6", metagen_dhcp_config), /* 11 */
NMC_META_GENERIC_WITH_NESTED ("BOND", nmc_fields_dev_show_master_prop + 1), /* 12 */
NMC_META_GENERIC_WITH_NESTED ("TEAM", nmc_fields_dev_show_team_prop + 1), /* 13 */
NMC_META_GENERIC_WITH_NESTED ("BRIDGE", nmc_fields_dev_show_master_prop + 1), /* 14 */
NMC_META_GENERIC_WITH_NESTED ("VLAN", nmc_fields_dev_show_vlan_prop + 1), /* 15 */
NMC_META_GENERIC_WITH_NESTED ("BLUETOOTH", nmc_fields_dev_show_bluetooth + 1), /* 16 */
NMC_META_GENERIC_WITH_NESTED ("CONNECTIONS", metagen_device_detail_connections), /* 17 */
NULL,
};
#define NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON "GENERAL.DEVICE,GENERAL.TYPE,GENERAL.HWADDR,GENERAL.MTU,GENERAL.STATE,"\
@ -1461,6 +1500,20 @@ show_device_info (NMDevice *device, NmCli *nmc)
continue;
}
if (nmc_fields_dev_show_sections[section_idx]->nested == metagen_device_detail_interface_flags) {
gs_free char *f = section_fld ? g_strdup_printf ("INTERFACE-FLAGS.%s", section_fld) : NULL;
nmc_print (&nmc->nmc_config,
(gpointer[]) { device, NULL },
NULL,
NULL,
NMC_META_GENERIC_GROUP ("INTERFACE-FLAGS", metagen_device_detail_interface_flags, N_("NAME")),
f,
NULL);
was_output = TRUE;
continue;
}
if (nmc_fields_dev_show_sections[section_idx]->nested == metagen_device_detail_wifi_properties) {
if (NM_IS_DEVICE_WIFI (device)) {
gs_free char *f = section_fld ? g_strdup_printf ("WIFI-PROPERTIES.%s", section_fld) : NULL;
@ -1484,7 +1537,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
GPtrArray *aps;
/* section AP */
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[3]->name)) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[4]->name)) {
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
if (state == NM_DEVICE_STATE_ACTIVATED) {
@ -1542,42 +1595,42 @@ show_device_info (NMDevice *device, NmCli *nmc)
dhcp6 = nm_device_get_dhcp6_config (device);
/* IP4 */
if (cfg4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[7]->name))
if (cfg4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[8]->name))
was_output = print_ip_config (cfg4, AF_INET, &nmc->nmc_config, section_fld);
/* DHCP4 */
if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[8]->name))
if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[9]->name))
was_output = print_dhcp_config (dhcp4, AF_INET, &nmc->nmc_config, section_fld);
/* IP6 */
if (cfg6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[9]->name))
if (cfg6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[10]->name))
was_output = print_ip_config (cfg6, AF_INET6, &nmc->nmc_config, section_fld);
/* DHCP6 */
if (dhcp6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[10]->name))
if (dhcp6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[11]->name))
was_output = print_dhcp_config (dhcp6, AF_INET6, &nmc->nmc_config, section_fld);
/* Bond specific information */
if (NM_IS_DEVICE_BOND (device)) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[11]->name))
was_output = print_bond_bridge_info (device, nmc, nmc_fields_dev_show_sections[11]->name, section_fld);
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[12]->name))
was_output = print_bond_bridge_info (device, nmc, nmc_fields_dev_show_sections[12]->name, section_fld);
}
/* Team specific information */
if (NM_IS_DEVICE_TEAM (device)) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[12]->name))
was_output = print_team_info (device, nmc, nmc_fields_dev_show_sections[12]->name, section_fld);
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[13]->name))
was_output = print_team_info (device, nmc, nmc_fields_dev_show_sections[13]->name, section_fld);
}
/* Bridge specific information */
if (NM_IS_DEVICE_BRIDGE (device)) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[13]->name))
was_output = print_bond_bridge_info (device, nmc, nmc_fields_dev_show_sections[13]->name, section_fld);
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[14]->name))
was_output = print_bond_bridge_info (device, nmc, nmc_fields_dev_show_sections[14]->name, section_fld);
}
/* VLAN-specific information */
if ((NM_IS_DEVICE_VLAN (device))) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[14]->name)) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[15]->name)) {
char * vlan_id_str = g_strdup_printf ("%u", nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device)));
NMDevice *parent = nm_device_vlan_get_parent (NM_DEVICE_VLAN (device));
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
@ -1589,7 +1642,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
g_ptr_array_add (out.output_data, arr);
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, nmc_fields_dev_show_sections[14]->name); /* "VLAN" */
set_val_strc (arr, 0, nmc_fields_dev_show_sections[15]->name); /* "VLAN" */
set_val_strc (arr, 1, parent ? nm_device_get_iface (parent) : NULL);
set_val_str (arr, 2, vlan_id_str);
g_ptr_array_add (out.output_data, arr);
@ -1602,7 +1655,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
}
if (NM_IS_DEVICE_BT (device)) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[15]->name)) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[16]->name)) {
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_dev_show_bluetooth;
@ -1612,7 +1665,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
g_ptr_array_add (out.output_data, arr);
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, nmc_fields_dev_show_sections[15]->name); /* "BLUETOOTH" */
set_val_strc (arr, 0, nmc_fields_dev_show_sections[16]->name); /* "BLUETOOTH" */
set_val_str (arr, 1, bluetooth_caps_to_string (nm_device_bt_get_capabilities (NM_DEVICE_BT (device))));
g_ptr_array_add (out.output_data, arr);

View file

@ -216,6 +216,11 @@ typedef enum {
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_IBSS_RSN,
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_NUM,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_UP = 0,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_LOWER_UP,
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_CARRIER,
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_NUM,
} NmcGenericInfoType;
#define NMC_HANDLE_COLOR(color) \

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (C) 2019 Red Hat, Inc.
#
import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM
if __name__ == "__main__":
client = NM.Client.new(None)
devices = client.get_devices()
for d in devices:
print("{:<16} {:<16} {}".format(d.get_iface(),
"(" + d.get_type_description() + ")",
NM.utils_enum_to_str(NM.DeviceInterfaceFlags,
d.get_interface_flags())))

View file

@ -21,6 +21,9 @@
Carrier:
Indicates whether the physical carrier is found.
DEPRECATED: check for the "carrier" flag in the "InterfaceFlags"
property on the "org.freedesktop.NetworkManager.Device" interface.
-->
<property name="Carrier" type="b" access="read"/>
</interface>

View file

@ -19,6 +19,9 @@
Indicates whether the physical carrier is found (e.g. whether a cable is
plugged in or not).
DEPRECATED: check for the "lower-up" flag in the "InterfaceFlags"
property on the "org.freedesktop.NetworkManager.Device" interface.
-->
<property name="Carrier" type="b" access="read"/>

View file

@ -19,6 +19,9 @@
Indicates whether the physical carrier is found (e.g. whether a cable is
plugged in or not).
DEPRECATED: check for the "carrier" flag in the "InterfaceFlags"
property on the "org.freedesktop.NetworkManager.Device" interface.
-->
<property name="Carrier" type="b" access="read"/>

View file

@ -19,6 +19,9 @@
Indicates whether the physical carrier is found (e.g. whether a cable is
plugged in or not).
DEPRECATED: check for the "lower-up" flag in the "InterfaceFlags"
property on the "org.freedesktop.NetworkManager.Device" interface.
-->
<property name="Carrier" type="b" access="read"/>

View file

@ -19,6 +19,9 @@
Indicates whether the physical carrier is found (e.g. whether a cable is
plugged in or not).
DEPRECATED: check for the "lower-up" flag in the "InterfaceFlags"
property on the "org.freedesktop.NetworkManager.Device" interface.
-->
<property name="Carrier" type="b" access="read"/>

View file

@ -19,6 +19,9 @@
Indicates whether the physical carrier is found (e.g. whether a cable is
plugged in or not).
DEPRECATED: check for the "carrier" flag in the "InterfaceFlags"
property on the "org.freedesktop.NetworkManager.Device" interface.
-->
<property name="Carrier" type="b" access="read"/>

View file

@ -41,6 +41,9 @@
Indicates whether the physical carrier is found (e.g. whether a cable is
plugged in or not).
DEPRECATED: check for the "carrier" flag in the "InterfaceFlags"
property on the "org.freedesktop.NetworkManager.Device" interface.
-->
<property name="Carrier" type="b" access="read"/>

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,28 @@ 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.
* @NM_DEVICE_INTERFACE_FLAG_CARRIER: the interface has carrier. In most
* cases this is equal to the value of @NM_DEVICE_INTERFACE_FLAG_LOWER_UP.
* However some devices have a non-standard carrier detection mechanism.
*
* 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,
/* NM-specific flags */
NM_DEVICE_INTERFACE_FLAG_CARRIER = 0x10000,
} NMDeviceInterfaceFlags;
#endif /* __NM_DBUS_INTERFACE_H__ */

View file

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

View file

@ -61,6 +61,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_LLDP_NEIGHBORS,
PROP_IP4_CONNECTIVITY,
PROP_IP6_CONNECTIVITY,
PROP_INTERFACE_FLAGS,
);
enum {
@ -110,6 +111,7 @@ typedef struct _NMDevicePrivate {
char *physical_port_id;
guint32 mtu;
GPtrArray *lldp_neighbors;
guint32 interface_flags;
} NMDevicePrivate;
G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_OBJECT);
@ -223,6 +225,7 @@ init_dbus (NMObject *object)
{ NM_DEVICE_MTU, &priv->mtu },
{ NM_DEVICE_METERED, &priv->metered },
{ NM_DEVICE_LLDP_NEIGHBORS, &priv->lldp_neighbors, demarshal_lldp_neighbors },
{ NM_DEVICE_INTERFACE_FLAGS, &priv->interface_flags },
/* Properties that exist in D-Bus but that we don't track */
{ "ip4-address", NULL },
@ -434,6 +437,9 @@ get_property (GObject *object,
case PROP_IP6_CONNECTIVITY:
g_value_set_enum (value, nm_device_get_connectivity (device, AF_INET6));
break;
case PROP_INTERFACE_FLAGS:
g_value_set_uint (value, nm_device_get_interface_flags (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -825,6 +831,19 @@ nm_device_class_init (NMDeviceClass *device_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
/**
* NMDevice:interface-flags:
*
* The interface flags.
*
* Since: 1.22
**/
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);
/**
@ -1276,6 +1295,24 @@ nm_device_get_connectivity (NMDevice *device, int addr_family)
}
}
/**
* nm_device_get_interface_flags:
* @device: a #NMDevice
*
* Gets the interface flags of the device.
*
* Returns: the flags
*
* Since: 1.22
**/
NMDeviceInterfaceFlags
nm_device_get_interface_flags (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_INTERFACE_FLAG_NONE);
return NM_DEVICE_GET_PRIVATE (device)->interface_flags;
}
/**
* nm_device_get_state:
* @device: a #NMDevice

View file

@ -54,6 +54,7 @@ _NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
#define NM_DEVICE_LLDP_NEIGHBORS "lldp-neighbors"
#define NM_DEVICE_IP4_CONNECTIVITY "ip4-connectivity"
#define NM_DEVICE_IP6_CONNECTIVITY "ip6-connectivity"
#define NM_DEVICE_INTERFACE_FLAGS "interface-flags"
/**
* NMDevice:
@ -113,6 +114,9 @@ NM_AVAILABLE_IN_1_2
NMMetered nm_device_get_metered (NMDevice *device);
NM_AVAILABLE_IN_1_2
GPtrArray * nm_device_get_lldp_neighbors (NMDevice *device);
NM_AVAILABLE_IN_1_22
NMDeviceInterfaceFlags nm_device_get_interface_flags (NMDevice *device);
char ** nm_device_disambiguate_names (NMDevice **devices,
int num_devices);
NM_AVAILABLE_IN_1_2

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 */
@ -3602,12 +3604,26 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMDeviceState state = nm_device_get_state (self);
gboolean notify_flags = FALSE;
if (priv->carrier == carrier)
return;
if (NM_FLAGS_ALL (priv->capabilities,
NM_DEVICE_CAP_CARRIER_DETECT
| NM_DEVICE_CAP_NONSTANDARD_CARRIER)) {
if (carrier)
priv->interface_flags |= NM_DEVICE_INTERFACE_FLAG_CARRIER;
else
priv->interface_flags &= ~NM_DEVICE_INTERFACE_FLAG_CARRIER;
notify_flags = TRUE;
}
priv->carrier = carrier;
_notify (self, PROP_CARRIER);
if (notify_flags)
nm_gobject_notify_together (self, PROP_CARRIER, PROP_INTERFACE_FLAGS);
else
_notify (self, PROP_CARRIER);
if (priv->carrier) {
_LOGI (LOGD_DEVICE, "carrier: link connected");
@ -3804,6 +3820,33 @@ 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 (NM_FLAGS_ALL (priv->capabilities,
NM_DEVICE_CAP_CARRIER_DETECT
| NM_DEVICE_CAP_NONSTANDARD_CARRIER)) {
if (priv->carrier)
flags |= NM_DEVICE_INTERFACE_FLAG_CARRIER;
} else {
if (plink && NM_FLAGS_HAS (plink->n_ifi_flags, IFF_LOWER_UP))
flags |= NM_DEVICE_INTERFACE_FLAG_CARRIER;
}
if (flags != priv->interface_flags) {
priv->interface_flags = flags;
_notify (self, PROP_INTERFACE_FLAGS);
}
}
static gboolean
device_link_changed (NMDevice *self)
{
@ -3891,6 +3934,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 +4288,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 +17312,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 +17403,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),
),
),
};
@ -17580,14 +17631,6 @@ nm_device_class_init (NMDeviceClass *klass)
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
/**
* NMDevice:metered:
*
* Whether the connection is metered.
*
* Since: 1.2
**/
obj_properties[PROP_METERED] =
g_param_spec_uint (NM_DEVICE_METERED, "", "",
0, G_MAXUINT32, NM_METERED_UNKNOWN,
@ -17636,6 +17679,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))

View file

@ -683,6 +683,7 @@ PRP_DEVICE_AUTOCONNECT = "Autoconnect"
PRP_DEVICE_DEVICE_TYPE = "DeviceType"
PRP_DEVICE_AVAILABLE_CONNECTIONS = "AvailableConnections"
PRP_DEVICE_LLDP_NEIGHBORS = "LldpNeighbors"
PRP_DEVICE_INTERFACE_FLAGS = "InterfaceFlags"
class Device(ExportedObj):
@ -718,6 +719,7 @@ class Device(ExportedObj):
PRP_DEVICE_AUTOCONNECT: True,
PRP_DEVICE_DEVICE_TYPE: dbus.UInt32(devtype),
PRP_DEVICE_AVAILABLE_CONNECTIONS: ExportedObj.to_path_array([]),
PRP_DEVICE_INTERFACE_FLAGS: dbus.UInt32(3), # up,lower-up
PRP_DEVICE_LLDP_NEIGHBORS: dbus.Array([
dbus.Dictionary({
'chassis-id-type': dbus.UInt32(6),