diff options
Diffstat (limited to 'libnm-core/nm-setting-connection.c')
-rw-r--r-- | libnm-core/nm-setting-connection.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index 2e8fa37a2c..545dd8168c 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -16,6 +16,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 +64,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMSettingConnection, PROP_STABLE_ID, PROP_AUTH_RETRIES, PROP_WAIT_DEVICE_TIMEOUT, + PROP_MUD_URL, ); typedef struct { @@ -76,6 +78,7 @@ typedef struct { char *master; char *slave_type; char *zone; + char *mud_url; guint64 timestamp; int autoconnect_priority; int autoconnect_retries; @@ -751,6 +754,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 +1231,27 @@ 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 (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 (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 +1508,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 +1606,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 +1659,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 +2335,30 @@ 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. + * + * 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, |