device: move tracking of parent device from NMDeviceIPTunnel to NMDevice

This commit is contained in:
Thomas Haller
2016-12-30 12:06:30 +01:00
parent f703f4bb65
commit 3be1811a7d
3 changed files with 9 additions and 34 deletions

View File

@@ -46,7 +46,6 @@ _LOG_DECLARE_SELF(NMDeviceIPTunnel);
NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceIPTunnel, NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceIPTunnel,
PROP_MODE, PROP_MODE,
PROP_PARENT,
PROP_LOCAL, PROP_LOCAL,
PROP_REMOTE, PROP_REMOTE,
PROP_TTL, PROP_TTL,
@@ -60,8 +59,6 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceIPTunnel,
typedef struct { typedef struct {
NMIPTunnelMode mode; NMIPTunnelMode mode;
NMDevice *parent;
int parent_ifindex;
char *local; char *local;
char *remote; char *remote;
guint8 ttl; guint8 ttl;
@@ -126,8 +123,7 @@ update_properties_from_ifindex (NMDevice *device, int ifindex)
{ {
NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL (device); NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL (device);
NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (self); NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (self);
NMDevice *parent; int parent_ifindex = 0;
int parent_ifindex;
in_addr_t local4, remote4; in_addr_t local4, remote4;
struct in6_addr local6, remote6; struct in6_addr local6, remote6;
guint8 ttl = 0, tos = 0, encap_limit = 0; guint8 ttl = 0, tos = 0, encap_limit = 0;
@@ -137,11 +133,7 @@ update_properties_from_ifindex (NMDevice *device, int ifindex)
if (ifindex <= 0) { if (ifindex <= 0) {
clear: clear:
if (priv->parent || priv->parent_ifindex) { nm_device_parent_set_ifindex (device, 0);
g_clear_object (&priv->parent);
priv->parent_ifindex = 0;
_notify (self, PROP_PARENT);
}
if (priv->local) { if (priv->local) {
g_clear_pointer (&priv->local, g_free); g_clear_pointer (&priv->local, g_free);
_notify (self, PROP_LOCAL); _notify (self, PROP_LOCAL);
@@ -257,14 +249,7 @@ clear:
} else } else
g_return_if_reached (); g_return_if_reached ();
if (priv->parent_ifindex != parent_ifindex) { nm_device_parent_set_ifindex (device, parent_ifindex);
g_clear_object (&priv->parent);
priv->parent_ifindex = parent_ifindex;
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex);
if (parent)
priv->parent = g_object_ref (parent);
_notify (self, PROP_PARENT);
}
if (priv->addr_family == AF_INET) { if (priv->addr_family == AF_INET) {
if (!address_equal_pn (AF_INET, priv->local, &local4)) { if (!address_equal_pn (AF_INET, priv->local, &local4)) {
@@ -383,8 +368,7 @@ update_connection (NMDevice *device, NMConnection *connection)
if (nm_setting_ip_tunnel_get_mode (s_ip_tunnel) != priv->mode) if (nm_setting_ip_tunnel_get_mode (s_ip_tunnel) != priv->mode)
g_object_set (G_OBJECT (s_ip_tunnel), NM_SETTING_IP_TUNNEL_MODE, priv->mode, NULL); g_object_set (G_OBJECT (s_ip_tunnel), NM_SETTING_IP_TUNNEL_MODE, priv->mode, NULL);
if (priv->parent_ifindex > 0) parent = nm_device_parent_get_device (device);
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->parent_ifindex);
/* Update parent in the connection; default to parent's interface name */ /* Update parent in the connection; default to parent's interface name */
if (parent) { if (parent) {
@@ -513,7 +497,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
/* Check parent interface; could be an interface name or a UUID */ /* Check parent interface; could be an interface name or a UUID */
parent = nm_setting_ip_tunnel_get_parent (s_ip_tunnel); parent = nm_setting_ip_tunnel_get_parent (s_ip_tunnel);
if (parent) { if (parent) {
if (!match_parent (priv->parent, parent)) if (!match_parent (nm_device_parent_get_device (device), parent))
return FALSE; return FALSE;
} }
@@ -799,16 +783,11 @@ get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec) GValue *value, GParamSpec *pspec)
{ {
NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE ((NMDeviceIPTunnel *) object); NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE ((NMDeviceIPTunnel *) object);
NMDevice *parent;
switch (prop_id) { switch (prop_id) {
case PROP_MODE: case PROP_MODE:
g_value_set_uint (value, priv->mode); g_value_set_uint (value, priv->mode);
break; break;
case PROP_PARENT:
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->parent_ifindex);
nm_utils_g_value_set_object_path (value, parent);
break;
case PROP_LOCAL: case PROP_LOCAL:
g_value_set_string (value, priv->local); g_value_set_string (value, priv->local);
break; break;
@@ -911,12 +890,6 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
obj_properties[PROP_PARENT] =
g_param_spec_string (NM_DEVICE_IP_TUNNEL_PARENT, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_LOCAL] = obj_properties[PROP_LOCAL] =
g_param_spec_string (NM_DEVICE_IP_TUNNEL_LOCAL, "", "", g_param_spec_string (NM_DEVICE_IP_TUNNEL_LOCAL, "", "",
NULL, NULL,

View File

@@ -32,7 +32,6 @@
#define NM_DEVICE_IP_TUNNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_IP_TUNNEL, NMDeviceIPTunnelClass)) #define NM_DEVICE_IP_TUNNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_IP_TUNNEL, NMDeviceIPTunnelClass))
#define NM_DEVICE_IP_TUNNEL_MODE "mode" #define NM_DEVICE_IP_TUNNEL_MODE "mode"
#define NM_DEVICE_IP_TUNNEL_PARENT "parent"
#define NM_DEVICE_IP_TUNNEL_LOCAL "local" #define NM_DEVICE_IP_TUNNEL_LOCAL "local"
#define NM_DEVICE_IP_TUNNEL_REMOTE "remote" #define NM_DEVICE_IP_TUNNEL_REMOTE "remote"
#define NM_DEVICE_IP_TUNNEL_TTL "ttl" #define NM_DEVICE_IP_TUNNEL_TTL "ttl"
@@ -43,6 +42,9 @@
#define NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT "encapsulation-limit" #define NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT "encapsulation-limit"
#define NM_DEVICE_IP_TUNNEL_FLOW_LABEL "flow-label" #define NM_DEVICE_IP_TUNNEL_FLOW_LABEL "flow-label"
/* defined in the parent class, but exposed on D-Bus by the subclass. */
#define NM_DEVICE_IP_TUNNEL_PARENT NM_DEVICE_PARENT
typedef struct _NMDeviceIPTunnel NMDeviceIPTunnel; typedef struct _NMDeviceIPTunnel NMDeviceIPTunnel;
typedef struct _NMDeviceIPTunnelClass NMDeviceIPTunnelClass; typedef struct _NMDeviceIPTunnelClass NMDeviceIPTunnelClass;

View File

@@ -66,7 +66,7 @@
#define NM_DEVICE_LLDP_NEIGHBORS "lldp-neighbors" #define NM_DEVICE_LLDP_NEIGHBORS "lldp-neighbors"
#define NM_DEVICE_REAL "real" #define NM_DEVICE_REAL "real"
/* "parent" will later be exposed by some subclasses */ /* "parent" is exposed on D-Bus by subclasses like NMDeviceIPTunnel */
#define NM_DEVICE_PARENT "parent" #define NM_DEVICE_PARENT "parent"
/* the "slaves" property is internal in the parent class, but exposed /* the "slaves" property is internal in the parent class, but exposed