libnm: export interface flags

Add libnm support for the new InterfaceFlags property of NMDevice.
This commit is contained in:
Beniamino Galvani 2019-10-10 10:04:06 +02:00
parent 1b90ad41bb
commit e397582cca
4 changed files with 61 additions and 0 deletions

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

@ -1640,6 +1640,7 @@ 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;

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