about summary refs log tree commit diff
path: root/src/libnm-core-impl/nm-setting-generic.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2024-02-22 17:21:11 +0100
committerMichael Biebl <biebl@debian.org>2024-02-22 17:21:11 +0100
commitbba2e4b4de668db525cbfdfc35292e5a0b51671a (patch)
tree38d20cddfcc6f71572b9e169deefab5fa96e8d0c /src/libnm-core-impl/nm-setting-generic.c
parent6681f77b757bbc42ce5c8868ee9142b7ebc8c059 (diff)
New upstream version 1.46.0 upstream/1.46.0
Diffstat (limited to 'src/libnm-core-impl/nm-setting-generic.c')
-rw-r--r--src/libnm-core-impl/nm-setting-generic.c128
1 files changed, 125 insertions, 3 deletions
diff --git a/src/libnm-core-impl/nm-setting-generic.c b/src/libnm-core-impl/nm-setting-generic.c
index 6623e71f..8a38118a 100644
--- a/src/libnm-core-impl/nm-setting-generic.c
+++ b/src/libnm-core-impl/nm-setting-generic.c
@@ -23,13 +23,20 @@
 
 /*****************************************************************************/
 
+NM_GOBJECT_PROPERTIES_DEFINE(NMSettingGeneric, PROP_DEVICE_HANDLER, );
+
+typedef struct {
+    char *device_handler;
+} NMSettingGenericPrivate;
+
 /**
  * NMSettingGeneric:
  *
  * Generic Link Settings
  */
 struct _NMSettingGeneric {
-    NMSetting parent;
+    NMSetting               parent;
+    NMSettingGenericPrivate _priv;
 };
 
 struct _NMSettingGenericClass {
@@ -38,6 +45,82 @@ struct _NMSettingGenericClass {
 
 G_DEFINE_TYPE(NMSettingGeneric, nm_setting_generic, NM_TYPE_SETTING)
 
+#define NM_SETTING_GENERIC_GET_PRIVATE(self) \
+    _NM_GET_PRIVATE(self, NMSettingGeneric, NM_IS_SETTING_GENERIC, NMSetting)
+
+/*****************************************************************************/
+
+/**
+ * nm_setting_generic_get_device_handler:
+ * @setting: the #NMSettingGeneric
+ *
+ * Returns the #NMSettingGeneric:device-handler property of the connection.
+ *
+ * Returns: the device handler name, or %NULL if no device handler is set
+ *
+ * Since: 1.46
+ **/
+const char *
+nm_setting_generic_get_device_handler(NMSettingGeneric *setting)
+{
+    g_return_val_if_fail(NM_IS_SETTING_GENERIC(setting), NULL);
+
+    return NM_SETTING_GENERIC_GET_PRIVATE(setting)->device_handler;
+}
+
+static gboolean
+verify(NMSetting *setting, NMConnection *connection, GError **error)
+{
+    NMSettingGenericPrivate *priv = NM_SETTING_GENERIC_GET_PRIVATE(setting);
+
+    if (priv->device_handler) {
+        if (NM_IN_SET(priv->device_handler[0], '\0', '.')
+            || !NM_STRCHAR_ALL(priv->device_handler,
+                               ch,
+                               g_ascii_isalnum(ch) || NM_IN_SET(ch, '-', '_', '.'))) {
+            g_set_error_literal(error,
+                                NM_CONNECTION_ERROR,
+                                NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                                _("property is invalid"));
+            g_prefix_error(error,
+                           "%s.%s: ",
+                           NM_SETTING_GENERIC_SETTING_NAME,
+                           NM_SETTING_GENERIC_DEVICE_HANDLER);
+            return FALSE;
+        }
+
+        if (connection) {
+            NMSettingConnection *s_con;
+
+            s_con = nm_connection_get_setting_connection(connection);
+            if (!s_con) {
+                g_set_error(error,
+                            NM_CONNECTION_ERROR,
+                            NM_CONNECTION_ERROR_MISSING_SETTING,
+                            _("missing setting"));
+                g_prefix_error(error, "%s: ", NM_SETTING_CONNECTION_SETTING_NAME);
+                return FALSE;
+            }
+
+            if (!nm_setting_connection_get_interface_name(s_con)) {
+                g_set_error(error,
+                            NM_CONNECTION_ERROR,
+                            NM_CONNECTION_ERROR_MISSING_PROPERTY,
+                            _("the property is required when %s.%s is set"),
+                            NM_SETTING_GENERIC_SETTING_NAME,
+                            NM_SETTING_GENERIC_DEVICE_HANDLER);
+                g_prefix_error(error,
+                               "%s.%s: ",
+                               NM_SETTING_CONNECTION_SETTING_NAME,
+                               NM_SETTING_CONNECTION_INTERFACE_NAME);
+                return FALSE;
+            }
+        }
+    }
+
+    return TRUE;
+}
+
 /*****************************************************************************/
 
 static void
@@ -60,7 +143,46 @@ nm_setting_generic_new(void)
 static void
 nm_setting_generic_class_init(NMSettingGenericClass *klass)
 {
-    NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
+    GObjectClass   *object_class        = G_OBJECT_CLASS(klass);
+    NMSettingClass *setting_class       = NM_SETTING_CLASS(klass);
+    GArray         *properties_override = _nm_sett_info_property_override_create_array();
+
+    object_class->get_property = _nm_setting_property_get_property_direct;
+    object_class->set_property = _nm_setting_property_set_property_direct;
+
+    setting_class->verify = verify;
+
+    /**
+     * NMSettingGeneric:device-handler:
+     *
+     * Name of the device handler that will be invoked to add and delete
+     * the device for this connection. The name can only contain ASCII
+     * alphanumeric characters and '-', '_', '.'. It cannot start with '.'.
+     *
+     * See the NetworkManager-dispatcher(8) man page for more details
+     * about how to write the device handler.
+     *
+     * By setting this property the generic connection becomes "virtual",
+     * meaning that it can be activated without an existing device; the device
+     * will be created at the time the connection is started by invoking the
+     * device-handler.
+     *
+     * Since: 1.46
+     **/
+    _nm_setting_property_define_direct_string(properties_override,
+                                              obj_properties,
+                                              NM_SETTING_GENERIC_DEVICE_HANDLER,
+                                              PROP_DEVICE_HANDLER,
+                                              NM_SETTING_PARAM_FUZZY_IGNORE
+                                                  | NM_SETTING_PARAM_INFERRABLE,
+                                              NMSettingGeneric,
+                                              _priv.device_handler);
+
+    g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
 
-    _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_GENERIC, NULL, NULL, 0);
+    _nm_setting_class_commit(setting_class,
+                             NM_META_SETTING_TYPE_GENERIC,
+                             NULL,
+                             properties_override,
+                             0);
 }