summary refs log tree commit diff
path: root/libnm-core/nm-setting-connection.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2020-06-28 18:58:14 +0200
committerMichael Biebl <biebl@debian.org>2020-06-28 18:58:14 +0200
commita54ac63bbf9b2c71026ac9028a8ffaf186cf3c82 (patch)
tree6a32883bd916c4096357b35298beff6db8bcd0b5 /libnm-core/nm-setting-connection.c
parent45e8e1149027529194982212c804c0468aa01d98 (diff)
New upstream version 1.25.90 upstream/1.25.90
Diffstat (limited to 'libnm-core/nm-setting-connection.c')
-rw-r--r--libnm-core/nm-setting-connection.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c
index 2e8fa37a..018129be 100644
--- a/libnm-core/nm-setting-connection.c
+++ b/libnm-core/nm-setting-connection.c
@@ -8,6 +8,7 @@
 
 #include "nm-setting-connection.h"
 
+#include "nm-libnm-core-intern/nm-common-macros.h"
 #include "nm-utils.h"
 #include "nm-utils-private.h"
 #include "nm-core-enum-types.h"
@@ -16,6 +17,7 @@
 #include "nm-setting-bridge.h"
 #include "nm-setting-team.h"
 #include "nm-setting-vlan.h"
+#include "systemd/nm-sd-utils-shared.h"
 
 /**
  * SECTION:nm-setting-connection
@@ -63,6 +65,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMSettingConnection,
 	PROP_STABLE_ID,
 	PROP_AUTH_RETRIES,
 	PROP_WAIT_DEVICE_TIMEOUT,
+	PROP_MUD_URL,
 );
 
 typedef struct {
@@ -76,6 +79,7 @@ typedef struct {
 	char *master;
 	char *slave_type;
 	char *zone;
+	char *mud_url;
 	guint64 timestamp;
 	int autoconnect_priority;
 	int autoconnect_retries;
@@ -751,6 +755,23 @@ nm_setting_connection_get_secondary (NMSettingConnection *setting, guint32 idx)
 }
 
 /**
+ * nm_setting_connection_get_mud_url:
+ * @setting: the #NMSettingConnection
+ *
+ * Returns the value contained in the #NMSettingConnection:mud-url
+ * property.
+ *
+ * Since: 1.26
+ **/
+const char *
+nm_setting_connection_get_mud_url (NMSettingConnection *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
+
+	return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->mud_url;
+}
+
+/**
  * nm_setting_connection_add_secondary:
  * @setting: the #NMSettingConnection
  * @sec_uuid: the secondary connection UUID to add
@@ -1211,6 +1232,31 @@ after_interface_name:
 		return FALSE;
 	}
 
+	if (priv->mud_url) {
+		if (!priv->mud_url[0]) {
+			g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY,
+			                     _("property is empty"));
+			g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_CONNECTION_MUD_URL);
+			return FALSE;
+		}
+		if (nm_streq (priv->mud_url, NM_CONNECTION_MUD_URL_NONE)) {
+			/* pass */
+		} else {
+			if (strlen (priv->mud_url) > 255) {
+				g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY,
+				                     _("DHCP option cannot be longer than 255 characters"));
+				g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_CONNECTION_MUD_URL);
+				return FALSE;
+			}
+			if (!nm_sd_http_url_is_valid_https (priv->mud_url)) {
+				g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY,
+				                     _("MUD URL is not a valid URL"));
+				g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), NM_SETTING_CONNECTION_MUD_URL);
+				return FALSE;
+			}
+		}
+	}
+
 	/* *** errors above here should be always fatal, below NORMALIZABLE_ERROR *** */
 
 	if (!priv->uuid) {
@@ -1467,6 +1513,9 @@ get_property (GObject *object, guint prop_id,
 	case PROP_WAIT_DEVICE_TIMEOUT:
 		g_value_set_int (value, priv->wait_device_timeout);
 		break;
+	case PROP_MUD_URL:
+		g_value_set_string (value, priv->mud_url);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -1562,6 +1611,10 @@ set_property (GObject *object, guint prop_id,
 	case PROP_WAIT_DEVICE_TIMEOUT:
 		priv->wait_device_timeout = g_value_get_int (value);
 		break;
+	case PROP_MUD_URL:
+		g_free (priv->mud_url);
+		priv->mud_url = g_value_dup_string (value);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -1611,6 +1664,7 @@ finalize (GObject *object)
 	g_free (priv->zone);
 	g_free (priv->master);
 	g_free (priv->slave_type);
+	g_free (priv->mud_url);
 	g_slist_free_full (priv->permissions, (GDestroyNotify) permission_free);
 	g_slist_free_full (priv->secondaries, g_free);
 
@@ -2286,6 +2340,35 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass)
 	                      G_PARAM_READWRITE |
 	                      G_PARAM_STATIC_STRINGS);
 
+
+	/**
+	 * NMSettingConnection:mud-url:
+	 *
+	 * If configured, set to a Manufacturer Usage Description (MUD) URL that points
+	 * to manufacturer-recommended network policies for IoT devices. It is transmitted
+	 * as a DHCPv4 or DHCPv6 option. The value must be a valid URL starting with "https://".
+	 *
+	 * The special value "none" is allowed to indicate that no MUD URL is used.
+	 *
+	 * If the per-profile value is unspecified (the default), a global connection default gets
+	 * consulted. If still unspecified, the ultimate default is "none".
+	 *
+	 * Since: 1.26
+	 **/
+	/* ---ifcfg-rh---
+	 * property: mud-url
+	 * variable: MUD_URL
+	 * values: a valid URL that points to recommended policy for this device
+	 * description: MUD_URL to be sent by device (See RFC 8520).
+	 * example: https://yourdevice.example.com/model.json
+	 * ---end---
+	 */
+	obj_properties[PROP_MUD_URL] =
+	    g_param_spec_string (NM_SETTING_CONNECTION_MUD_URL, "", "",
+	                         NULL,
+	                         G_PARAM_READWRITE |
+	                         G_PARAM_STATIC_STRINGS);
+
 	g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
 
 	_nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_CONNECTION,