summary refs log tree commit diff
path: root/src/devices/nm-device-gre.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/nm-device-gre.c')
-rw-r--r--src/devices/nm-device-gre.c117
1 files changed, 62 insertions, 55 deletions
diff --git a/src/devices/nm-device-gre.c b/src/devices/nm-device-gre.c
index 0412e993..9c25b398 100644
--- a/src/devices/nm-device-gre.c
+++ b/src/devices/nm-device-gre.c
@@ -21,6 +21,7 @@
 #include "config.h"
 
 #include <string.h>
+#include <arpa/inet.h>
 
 #include "nm-device-gre.h"
 #include "nm-device-private.h"
@@ -28,9 +29,14 @@
 #include "nm-logging.h"
 #include "nm-manager.h"
 #include "nm-platform.h"
+#include "nm-device-factory.h"
+#include "nm-core-internal.h"
 
 #include "nm-device-gre-glue.h"
 
+#include "nm-device-logging.h"
+_LOG_DECLARE_SELF(NMDeviceGre);
+
 G_DEFINE_TYPE (NMDeviceGre, nm_device_gre, NM_TYPE_DEVICE_GENERIC)
 
 #define NM_DEVICE_GRE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GRE, NMDeviceGrePrivate))
@@ -60,13 +66,13 @@ enum {
 static void
 update_properties (NMDevice *device)
 {
-	NMDeviceGrePrivate *priv = NM_DEVICE_GRE_GET_PRIVATE (device);
+	NMDeviceGre *self = NM_DEVICE_GRE (device);
+	NMDeviceGrePrivate *priv = NM_DEVICE_GRE_GET_PRIVATE (self);
 	GObject *object = G_OBJECT (device);
 	NMPlatformGreProperties props;
 
 	if (!nm_platform_gre_get_properties (nm_device_get_ifindex (device), &props)) {
-		nm_log_warn (LOGD_HW, "(%s): could not read gre properties",
-		             nm_device_get_iface (device));
+		_LOGW (LOGD_HW, "could not read gre properties");
 		return;
 	}
 
@@ -107,18 +113,6 @@ link_changed (NMDevice *device, NMPlatformLink *info)
 
 /**************************************************************/
 
-NMDevice *
-nm_device_gre_new (NMPlatformLink *platform_device)
-{
-	g_return_val_if_fail (platform_device != NULL, NULL);
-
-	return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GRE,
-	                                  NM_DEVICE_PLATFORM_DEVICE, platform_device,
-	                                  NM_DEVICE_TYPE_DESC, "Gre",
-	                                  NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
-	                                  NULL);
-}
-
 static void
 nm_device_gre_init (NMDeviceGre *self)
 {
@@ -194,85 +188,98 @@ nm_device_gre_class_init (NMDeviceGreClass *klass)
 	/* properties */
 	g_object_class_install_property
 		(object_class, PROP_PARENT,
-		 g_param_spec_boxed (NM_DEVICE_GRE_PARENT,
-		                     "Parent",
-		                     "Parent device",
+		 g_param_spec_boxed (NM_DEVICE_GRE_PARENT, "", "",
 		                     DBUS_TYPE_G_OBJECT_PATH,
-		                     G_PARAM_READABLE));
+		                     G_PARAM_READABLE |
+		                     G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_INPUT_FLAGS,
-		 g_param_spec_uint (NM_DEVICE_GRE_INPUT_FLAGS,
-		                    "Input flags",
-		                    "Input flags",
+		 g_param_spec_uint (NM_DEVICE_GRE_INPUT_FLAGS, "", "",
 		                    0, G_MAXUINT16, 0,
-		                    G_PARAM_READABLE));
+		                    G_PARAM_READABLE |
+		                    G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_OUTPUT_FLAGS,
-		 g_param_spec_uint (NM_DEVICE_GRE_OUTPUT_FLAGS,
-		                    "Output flags",
-		                    "Output flags",
+		 g_param_spec_uint (NM_DEVICE_GRE_OUTPUT_FLAGS, "", "",
 		                    0, G_MAXUINT16, 0,
-		                    G_PARAM_READABLE));
+		                    G_PARAM_READABLE |
+		                    G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_INPUT_KEY,
-		 g_param_spec_uint (NM_DEVICE_GRE_INPUT_KEY,
-		                    "Input key",
-		                    "Input key",
+		 g_param_spec_uint (NM_DEVICE_GRE_INPUT_KEY, "", "",
 		                    0, G_MAXUINT32, 0,
-		                    G_PARAM_READABLE));
+		                    G_PARAM_READABLE |
+		                    G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_OUTPUT_KEY,
-		 g_param_spec_uint (NM_DEVICE_GRE_OUTPUT_KEY,
-		                    "Output key",
-		                    "Output key",
+		 g_param_spec_uint (NM_DEVICE_GRE_OUTPUT_KEY, "", "",
 		                    0, G_MAXUINT32, 0,
-		                    G_PARAM_READABLE));
+		                    G_PARAM_READABLE |
+		                    G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_LOCAL,
-		 g_param_spec_string (NM_DEVICE_GRE_LOCAL,
-		                      "Local",
-		                      "Local",
+		 g_param_spec_string (NM_DEVICE_GRE_LOCAL, "", "",
 		                      NULL,
-		                      G_PARAM_READABLE));
+		                      G_PARAM_READABLE |
+		                      G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_REMOTE,
-		 g_param_spec_string (NM_DEVICE_GRE_REMOTE,
-		                      "Remote",
-		                      "Remote",
+		 g_param_spec_string (NM_DEVICE_GRE_REMOTE, "", "",
 		                      NULL,
-		                      G_PARAM_READABLE));
+		                      G_PARAM_READABLE |
+		                      G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_TTL,
-		 g_param_spec_uchar (NM_DEVICE_GRE_TTL,
-		                     "TTL",
-		                     "TTL",
+		 g_param_spec_uchar (NM_DEVICE_GRE_TTL, "", "",
 		                     0, 255, 0,
-		                     G_PARAM_READABLE));
+		                     G_PARAM_READABLE |
+		                     G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_TOS,
-		 g_param_spec_uchar (NM_DEVICE_GRE_TOS,
-		                     "ToS",
-		                     "ToS",
+		 g_param_spec_uchar (NM_DEVICE_GRE_TOS, "", "",
 		                     0, 255, 0,
-		                     G_PARAM_READABLE));
+		                     G_PARAM_READABLE |
+		                     G_PARAM_STATIC_STRINGS));
 
 	g_object_class_install_property
 		(object_class, PROP_PATH_MTU_DISCOVERY,
-		 g_param_spec_boolean (NM_DEVICE_GRE_PATH_MTU_DISCOVERY,
-		                       "Path MTU Discovery",
-		                       "Path MTU Discovery",
+		 g_param_spec_boolean (NM_DEVICE_GRE_PATH_MTU_DISCOVERY, "", "",
 		                       FALSE,
-		                       G_PARAM_READABLE));
+		                       G_PARAM_READABLE |
+		                       G_PARAM_STATIC_STRINGS));
 
 	nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
 	                                        G_TYPE_FROM_CLASS (klass),
 	                                        &dbus_glib_nm_device_gre_object_info);
 }
+
+/*************************************************************/
+
+#define NM_TYPE_GRE_FACTORY (nm_gre_factory_get_type ())
+#define NM_GRE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_GRE_FACTORY, NMGreFactory))
+
+static NMDevice *
+new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
+{
+	if (plink->type == NM_LINK_TYPE_GRE || plink->type == NM_LINK_TYPE_GRETAP) {
+		return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GRE,
+		                                  NM_DEVICE_PLATFORM_DEVICE, plink,
+		                                  NM_DEVICE_TYPE_DESC, "Gre",
+		                                  NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
+		                                  NULL);
+	}
+	return NULL;
+}
+
+DEFINE_DEVICE_FACTORY_INTERNAL_WITH_DEVTYPE(GRE, Gre, gre, ETHERNET, \
+	factory_iface->new_link = new_link; \
+	)
+