diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | libnm-core/nm-dbus-interface.h | 2 | ||||
-rw-r--r-- | libnm/nm-device.c | 3 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/devices/nm-device-6lowpan.c | 375 | ||||
-rw-r--r-- | src/devices/nm-device-6lowpan.h | 37 | ||||
-rw-r--r-- | src/devices/nm-device-factory.c | 1 | ||||
-rw-r--r-- | src/devices/nm-device.c | 2 | ||||
-rw-r--r-- | src/meson.build | 1 |
9 files changed, 424 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 52d8da8761..ea43127e81 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1572,6 +1572,8 @@ src_libNetworkManager_la_SOURCES = \ src/devices/nm-device-logging.h \ src/devices/nm-device-private.h \ \ + src/devices/nm-device-6lowpan.c \ + src/devices/nm-device-6lowpan.h \ src/devices/nm-device-bond.c \ src/devices/nm-device-bond.h \ src/devices/nm-device-bridge.c \ diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h index ae78755eb6..c8e442f478 100644 --- a/libnm-core/nm-dbus-interface.h +++ b/libnm-core/nm-dbus-interface.h @@ -215,6 +215,7 @@ typedef enum { * @NM_DEVICE_TYPE_OVS_PORT: a OpenVSwitch port * @NM_DEVICE_TYPE_OVS_BRIDGE: a OpenVSwitch bridge * @NM_DEVICE_TYPE_WPAN: a IEEE 802.15.4 (WPAN) MAC Layer Device + * @NM_DEVICE_TYPE_6LOWPAN: 6LoWPAN interface * * #NMDeviceType values indicate the type of hardware represented by a * device object. @@ -248,6 +249,7 @@ typedef enum { NM_DEVICE_TYPE_OVS_PORT = 25, NM_DEVICE_TYPE_OVS_BRIDGE = 26, NM_DEVICE_TYPE_WPAN = 27, + NM_DEVICE_TYPE_6LOWPAN = 28, } NMDeviceType; /** diff --git a/libnm/nm-device.c b/libnm/nm-device.c index da4b51a2c5..d872df7b51 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -285,6 +285,7 @@ coerce_type (NMDeviceType type) case NM_DEVICE_TYPE_DUMMY: case NM_DEVICE_TYPE_PPP: case NM_DEVICE_TYPE_WPAN: + case NM_DEVICE_TYPE_6LOWPAN: return type; } return NM_DEVICE_TYPE_UNKNOWN; @@ -1348,6 +1349,8 @@ get_type_name (NMDevice *device) return _("PPP"); case NM_DEVICE_TYPE_WPAN: return _("IEEE 802.15.4"); + case NM_DEVICE_TYPE_6LOWPAN: + return _("6LoWPAN"); case NM_DEVICE_TYPE_GENERIC: case NM_DEVICE_TYPE_UNUSED1: case NM_DEVICE_TYPE_UNUSED2: diff --git a/po/POTFILES.in b/po/POTFILES.in index f9b99f3430..8fe7d35cb6 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -172,6 +172,7 @@ src/dns/nm-dns-manager.c src/devices/adsl/nm-device-adsl.c src/devices/bluetooth/nm-bluez-device.c src/devices/bluetooth/nm-device-bt.c +src/devices/nm-device-6lowpan.c src/devices/nm-device-bond.c src/devices/nm-device-bridge.c src/devices/nm-device-dummy.c diff --git a/src/devices/nm-device-6lowpan.c b/src/devices/nm-device-6lowpan.c new file mode 100644 index 0000000000..9119ab00c3 --- /dev/null +++ b/src/devices/nm-device-6lowpan.c @@ -0,0 +1,375 @@ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2018 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-device-6lowpan.h" + +#include "nm-device-private.h" +#include "settings/nm-settings.h" +#include "platform/nm-platform.h" +#include "nm-device-factory.h" +#include "nm-setting-6lowpan.h" +#include "nm-utils.h" + +#include "nm-device-logging.h" +_LOG_DECLARE_SELF(NMDevice6Lowpan); + +/*****************************************************************************/ + +typedef struct { + gulong parent_state_id; +} NMDevice6LowpanPrivate; + +struct _NMDevice6Lowpan { + NMDevice parent; + NMDevice6LowpanPrivate _priv; +}; + +struct _NMDevice6LowpanClass { + NMDeviceClass parent; +}; + +G_DEFINE_TYPE (NMDevice6Lowpan, nm_device_6lowpan, NM_TYPE_DEVICE) + +#define NM_DEVICE_6LOWPAN_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDevice6Lowpan, NM_IS_DEVICE_6LOWPAN) + +/*****************************************************************************/ + +static void +parent_state_changed (NMDevice *parent, + NMDeviceState new_state, + NMDeviceState old_state, + NMDeviceStateReason reason, + gpointer user_data) +{ + NMDevice6Lowpan *self = NM_DEVICE_6LOWPAN (user_data); + + nm_device_set_unmanaged_by_flags (NM_DEVICE (self), NM_UNMANAGED_PARENT, !nm_device_get_managed (parent, FALSE), reason); +} + +static void +parent_changed_notify (NMDevice *device, + int old_ifindex, + NMDevice *old_parent, + int new_ifindex, + NMDevice *new_parent) +{ + NMDevice6Lowpan *self = NM_DEVICE_6LOWPAN (device); + NMDevice6LowpanPrivate *priv = NM_DEVICE_6LOWPAN_GET_PRIVATE (self); + + NM_DEVICE_CLASS (nm_device_6lowpan_parent_class)->parent_changed_notify (device, old_ifindex, old_parent, new_ifindex, new_parent); + + /* note that @self doesn't have to clear @parent_state_id on dispose, + * because NMDevice's dispose() will unset the parent, which in turn calls + * parent_changed_notify(). */ + nm_clear_g_signal_handler (old_parent, &priv->parent_state_id); + + if (new_parent) { + priv->parent_state_id = g_signal_connect (new_parent, + NM_DEVICE_STATE_CHANGED, + G_CALLBACK (parent_state_changed), + device); + + /* Set parent-dependent unmanaged flag */ + nm_device_set_unmanaged_by_flags (device, + NM_UNMANAGED_PARENT, + !nm_device_get_managed (new_parent, FALSE), + NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED); + } + + if (new_ifindex > 0) { + /* Recheck availability now that the parent has changed */ + nm_device_queue_recheck_available (device, + NM_DEVICE_STATE_REASON_PARENT_CHANGED, + NM_DEVICE_STATE_REASON_PARENT_CHANGED); + } +} + +static gboolean +create_and_realize (NMDevice *device, + NMConnection *connection, + NMDevice *parent, + const NMPlatformLink **out_plink, + GError **error) +{ + const char *iface = nm_device_get_iface (device); + NMPlatformError plerr; + NMSetting6Lowpan *s_6lowpan; + int parent_ifindex; + + s_6lowpan = nm_connection_get_setting_6lowpan (connection); + g_return_val_if_fail (s_6lowpan, FALSE); + + parent_ifindex = parent ? nm_device_get_ifindex (parent) : 0; + + if (parent_ifindex <= 0) { + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES, + "6LoWPAN devices can not be created without a parent interface"); + g_return_val_if_fail (!parent, FALSE); + return FALSE; + } + + plerr = nm_platform_link_6lowpan_add (nm_device_get_platform (device), iface, parent_ifindex, out_plink); + if (plerr != NM_PLATFORM_ERROR_SUCCESS) { + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "Failed to create 6lowpan interface '%s' for '%s': %s", + iface, + nm_connection_get_id (connection), + nm_platform_error_to_string_a (plerr)); + return FALSE; + } + + nm_device_parent_set_ifindex (device, parent_ifindex); + + return TRUE; +} + +static NMDeviceCapabilities +get_generic_capabilities (NMDevice *dev) +{ + return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE; +} + +static void +link_changed (NMDevice *device, + const NMPlatformLink *pllink) +{ + NMDevice6Lowpan *self = NM_DEVICE_6LOWPAN (device); + int parent = 0; + int ifindex; + + NM_DEVICE_CLASS (nm_device_6lowpan_parent_class)->link_changed (device, pllink); + + ifindex = nm_device_get_ifindex (device); + if (!nm_platform_link_6lowpan_get_properties (nm_device_get_platform (device), ifindex, &parent)) { + _LOGW (LOGD_DEVICE, "could not get 6lowpan properties"); + return; + } + + nm_device_parent_set_ifindex (device, parent); +} + +static gboolean +is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags) +{ + if (!nm_device_parent_get_device (device)) + return FALSE; + return NM_DEVICE_CLASS (nm_device_6lowpan_parent_class)->is_available (device, flags); +} + +static gboolean +check_connection_compatible (NMDevice *device, NMConnection *connection) +{ + NMSetting6Lowpan *s_6lowpan; + + if (!NM_DEVICE_CLASS (nm_device_6lowpan_parent_class)->check_connection_compatible (device, connection)) + return FALSE; + + s_6lowpan = nm_connection_get_setting_6lowpan (connection); + if (!s_6lowpan) + return FALSE; + + return TRUE; +} + +static gboolean +complete_connection (NMDevice *device, + NMConnection *connection, + const char *specific_object, + NMConnection *const*existing_connections, + GError **error) +{ + NMSetting6Lowpan *s_6lowpan; + + nm_utils_complete_generic (nm_device_get_platform (device), + connection, + NM_SETTING_6LOWPAN_SETTING_NAME, + existing_connections, + NULL, + _("6LOWPAN connection"), + NULL, + TRUE); + + s_6lowpan = nm_connection_get_setting_6lowpan (connection); + if (!s_6lowpan) { + g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, + "A '6lowpan' setting is required."); + return FALSE; + } + + /* If there's no 6LoWPAN interface, no parent, and no hardware address in the + * settings, then there's not enough information to complete the setting. + */ + if ( !nm_setting_6lowpan_get_parent (s_6lowpan) + && !nm_device_match_hwaddr (device, connection, TRUE)) { + g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, + "The '6lowpan' setting had no interface name, parent, or hardware address."); + return FALSE; + } + + return TRUE; +} + +static void +update_connection (NMDevice *device, NMConnection *connection) +{ + NMSetting6Lowpan *s_6lowpan = nm_connection_get_setting_6lowpan (connection); + NMDevice *parent_device; + const char *setting_parent, *new_parent; + + if (!s_6lowpan) { + s_6lowpan = (NMSetting6Lowpan *) nm_setting_6lowpan_new (); + nm_connection_add_setting (connection, (NMSetting *) s_6lowpan); + } + + /* Update parent in the connection; default to parent's interface name */ + parent_device = nm_device_parent_get_device (device); + if (parent_device) { + new_parent = nm_device_get_iface (parent_device); + setting_parent = nm_setting_6lowpan_get_parent (s_6lowpan); + if (setting_parent && nm_utils_is_uuid (setting_parent)) { + NMConnection *parent_connection; + + /* Don't change a parent specified by UUID if it's still valid */ + parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent); + if (parent_connection && nm_device_check_connection_compatible (parent_device, parent_connection)) + new_parent = NULL; + } + if (new_parent) + g_object_set (s_6lowpan, NM_SETTING_6LOWPAN_PARENT, new_parent, NULL); + } else + g_object_set (s_6lowpan, NM_SETTING_6LOWPAN_PARENT, NULL, NULL); + +} + +static NMActStageReturn +act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *out_failure_reason) +{ + NMActStageReturn ret; + + ret = NM_DEVICE_CLASS (nm_device_6lowpan_parent_class)->act_stage1_prepare (dev, out_failure_reason); + if (ret != NM_ACT_STAGE_RETURN_SUCCESS) + return ret; + + if (!nm_device_hw_addr_set_cloned (dev, nm_device_get_applied_connection (dev), FALSE)) + return NM_ACT_STAGE_RETURN_FAILURE; + return NM_ACT_STAGE_RETURN_SUCCESS; +} + +/*****************************************************************************/ + +static void +nm_device_6lowpan_init (NMDevice6Lowpan *self) +{ +} + +static const NMDBusInterfaceInfoExtended interface_info_device_6lowpan = { + .parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT ( + NM_DBUS_INTERFACE_DEVICE_6LOWPAN, + .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS ( + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("HwAddress", "s", NM_DEVICE_HW_ADDRESS), + NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("Parent", "o", NM_DEVICE_PARENT), + ), + ), +}; + +static void +nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass) +{ + NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS (klass); + + NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_6LOWPAN) + + dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_device_6lowpan); + + device_class->act_stage1_prepare = act_stage1_prepare; + device_class->check_connection_compatible = check_connection_compatible; + device_class->complete_connection = complete_connection; + device_class->connection_type = NM_SETTING_6LOWPAN_SETTING_NAME; + device_class->create_and_realize = create_and_realize; + device_class->get_generic_capabilities = get_generic_capabilities; + device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired; + device_class->link_changed = link_changed; + device_class->is_available = is_available; + device_class->parent_changed_notify = parent_changed_notify; + device_class->update_connection = update_connection; +} + +/*****************************************************************************/ + +#define NM_TYPE_6LOWPAN_DEVICE_FACTORY (nm_6lowpan_device_factory_get_type ()) +#define NM_6LOWPAN_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_6LOWPAN_DEVICE_FACTORY, NM6LowpanDeviceFactory)) + +static NMDevice * +create_device (NMDeviceFactory *factory, + const char *iface, + const NMPlatformLink *plink, + NMConnection *connection, + gboolean *out_ignore) +{ + return (NMDevice *) g_object_new (NM_TYPE_DEVICE_6LOWPAN, + NM_DEVICE_IFACE, iface, + NM_DEVICE_TYPE_DESC, "6LoWPAN", + NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_6LOWPAN, + NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_6LOWPAN, + NULL); +} + +static const char * +get_connection_parent (NMDeviceFactory *factory, NMConnection *connection) +{ + NMSetting6Lowpan *s_6lowpan; + + g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_6LOWPAN_SETTING_NAME), NULL); + + s_6lowpan = nm_connection_get_setting_6lowpan (connection); + g_assert (s_6lowpan); + + return nm_setting_6lowpan_get_parent (s_6lowpan); +} + +static char * +get_connection_iface (NMDeviceFactory *factory, + NMConnection *connection, + const char *parent_iface) +{ + NMSetting6Lowpan *s_6lowpan; + const char *ifname; + + g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_6LOWPAN_SETTING_NAME), NULL); + + s_6lowpan = nm_connection_get_setting_6lowpan (connection); + g_assert (s_6lowpan); + + if (!parent_iface) + return NULL; + + ifname = nm_connection_get_interface_name (connection); + return g_strdup (ifname); +} + +NM_DEVICE_FACTORY_DEFINE_INTERNAL (6LOWPAN, 6Lowpan, 6lowpan, + NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_6LOWPAN) + NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_6LOWPAN_SETTING_NAME), + factory_class->create_device = create_device; + factory_class->get_connection_parent = get_connection_parent; + factory_class->get_connection_iface = get_connection_iface; +); diff --git a/src/devices/nm-device-6lowpan.h b/src/devices/nm-device-6lowpan.h new file mode 100644 index 0000000000..86edf4af59 --- /dev/null +++ b/src/devices/nm-device-6lowpan.h @@ -0,0 +1,37 @@ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2018 Red Hat, Inc. + */ + +#ifndef __NETWORKMANAGER_DEVICE_6LOWPAN_H__ +#define __NETWORKMANAGER_DEVICE_6LOWPAN_H__ + +#include "nm-device.h" + +#define NM_TYPE_DEVICE_6LOWPAN (nm_device_6lowpan_get_type ()) +#define NM_DEVICE_6LOWPAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_6LOWPAN, NMDevice6Lowpan)) +#define NM_DEVICE_6LOWPAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_6LOWPAN, NMDevice6LowpanClass)) +#define NM_IS_DEVICE_6LOWPAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_6LOWPAN)) +#define NM_IS_DEVICE_6LOWPAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_6LOWPAN)) +#define NM_DEVICE_6LOWPAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_6LOWPAN, NMDevice6LowpanClass)) + +typedef struct _NMDevice6Lowpan NMDevice6Lowpan; +typedef struct _NMDevice6LowpanClass NMDevice6LowpanClass; + +GType nm_device_6lowpan_get_type (void); + +#endif /* __NETWORKMANAGER_DEVICE_6LOWPAN_H__ */ diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index ced6b4bef4..30f6aa9910 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -417,6 +417,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call callback, user_data); \ } G_STMT_END + _ADD_INTERNAL (nm_6lowpan_device_factory_get_type); _ADD_INTERNAL (nm_bond_device_factory_get_type); _ADD_INTERNAL (nm_bridge_device_factory_get_type); _ADD_INTERNAL (nm_dummy_device_factory_get_type); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 023a7676b0..f56370baf6 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1940,6 +1940,8 @@ nm_device_get_route_metric_default (NMDeviceType device_type) return 700; case NM_DEVICE_TYPE_BT: return 750; + case NM_DEVICE_TYPE_6LOWPAN: + return 775; case NM_DEVICE_TYPE_OVS_BRIDGE: case NM_DEVICE_TYPE_OVS_INTERFACE: case NM_DEVICE_TYPE_OVS_PORT: diff --git a/src/meson.build b/src/meson.build index 93cd1e5b63..abc3069a17 100644 --- a/src/meson.build +++ b/src/meson.build @@ -93,6 +93,7 @@ libnetwork_manager_base = static_library( sources = files( 'devices/nm-acd-manager.c', + 'devices/nm-device-6lowpan.c', 'devices/nm-device-bond.c', 'devices/nm-device-bridge.c', 'devices/nm-device.c', |