diff options
-rw-r--r-- | libnm-core/nm-setting-ip-config.c | 2 | ||||
-rw-r--r-- | libnm-core/nm-setting-ip4-config.c | 71 | ||||
-rw-r--r-- | libnm-core/nm-setting-ip4-config.h | 4 | ||||
-rw-r--r-- | libnm-core/tests/test-general.c | 1 | ||||
-rw-r--r-- | libnm/libnm.ver | 1 |
5 files changed, 78 insertions, 1 deletions
diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index b36a8531b4..7e719aae19 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -2595,6 +2595,8 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *setting_class) * * If the #NMSettingIPConfig:dhcp-send-hostname property is %TRUE, then the * specified name will be sent to the DHCP server when acquiring a lease. + * This property and #NMSettingIP4Config:dhcp-fqdn are mutually exclusive and + * cannot be set at the same time. **/ g_object_class_install_property (object_class, PROP_DHCP_HOSTNAME, diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index 83026958ee..15949db161 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -59,12 +59,14 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG) typedef struct { char *dhcp_client_id; int dhcp_timeout; + char *dhcp_fqdn; } NMSettingIP4ConfigPrivate; enum { PROP_0, PROP_DHCP_CLIENT_ID, PROP_DHCP_TIMEOUT, + PROP_DHCP_FQDN, LAST_PROP }; @@ -120,6 +122,25 @@ nm_setting_ip4_config_get_dhcp_timeout (NMSettingIP4Config *setting) return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_timeout; } +/** + * nm_setting_ip4_config_get_dhcp_fqdn: + * @setting: the #NMSettingIP4Config + * + * Returns the value contained in the #NMSettingIP4Config:dhcp-fqdn + * property. + * + * Returns: the configured FQDN to send to the DHCP server + * + * Since: 1.2 + **/ +const char * +nm_setting_ip4_config_get_dhcp_fqdn (NMSettingIP4Config *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL); + + return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dhcp_fqdn; +} + static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { @@ -201,6 +222,31 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } + if (priv->dhcp_fqdn && !*priv->dhcp_fqdn) { + g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("property is empty")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_FQDN); + return FALSE; + } + + if (priv->dhcp_fqdn && !strchr (priv->dhcp_fqdn, '.')) { + g_set_error (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("'%s' is not a valid FQDN"), priv->dhcp_fqdn); + g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_FQDN); + return FALSE; + } + + if (priv->dhcp_fqdn && nm_setting_ip_config_get_dhcp_hostname (s_ip)) { + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("property cannot be set when dhcp-hostname is also set")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_DHCP_FQDN); + return FALSE; + } + return TRUE; } @@ -215,6 +261,7 @@ finalize (GObject *object) NMSettingIP4ConfigPrivate *priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (object); g_free (priv->dhcp_client_id); + g_free (priv->dhcp_fqdn); G_OBJECT_CLASS (nm_setting_ip4_config_parent_class)->finalize (object); } @@ -233,6 +280,10 @@ set_property (GObject *object, guint prop_id, case PROP_DHCP_TIMEOUT: priv->dhcp_timeout = g_value_get_uint (value); break; + case PROP_DHCP_FQDN: + g_free (priv->dhcp_fqdn); + priv->dhcp_fqdn = g_value_dup_string (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -252,6 +303,9 @@ get_property (GObject *object, guint prop_id, case PROP_DHCP_TIMEOUT: g_value_set_uint (value, nm_setting_ip4_config_get_dhcp_timeout (s_ip4)); break; + case PROP_DHCP_FQDN: + g_value_set_string (value, nm_setting_ip4_config_get_dhcp_fqdn (s_ip4)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -647,6 +701,23 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *ip4_class) NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS)); + /** + * NMSettingIP4Config:dhcp-fqdn: + * + * If the #NMSettingIPConfig:dhcp-send-hostname property is %TRUE, then the + * specified FQDN will be sent to the DHCP server when acquiring a lease. This + * property and #NMSettingIPConfig:dhcp-hostname are mutually exclusive and + * cannot be set at the same time. + * + * Since: 1.2 + */ + g_object_class_install_property + (object_class, PROP_DHCP_FQDN, + g_param_spec_string (NM_SETTING_IP4_CONFIG_DHCP_FQDN, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + /* IP4-specific property overrides */ /* ---dbus--- diff --git a/libnm-core/nm-setting-ip4-config.h b/libnm-core/nm-setting-ip4-config.h index 23e9e99d44..a78df70334 100644 --- a/libnm-core/nm-setting-ip4-config.h +++ b/libnm-core/nm-setting-ip4-config.h @@ -41,8 +41,8 @@ G_BEGIN_DECLS #define NM_SETTING_IP4_CONFIG_SETTING_NAME "ipv4" #define NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID "dhcp-client-id" - #define NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT "dhcp-timeout" +#define NM_SETTING_IP4_CONFIG_DHCP_FQDN "dhcp-fqdn" /** * NM_SETTING_IP4_CONFIG_METHOD_AUTO: @@ -106,6 +106,8 @@ NMSetting *nm_setting_ip4_config_new (void); const char *nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting); NM_AVAILABLE_IN_1_2 int nm_setting_ip4_config_get_dhcp_timeout (NMSettingIP4Config *setting); +NM_AVAILABLE_IN_1_2 +const char *nm_setting_ip4_config_get_dhcp_fqdn (NMSettingIP4Config *setting); G_END_DECLS diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 2111e59574..f4dec283ce 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -2043,6 +2043,7 @@ test_connection_diff_a_only (void) { NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, NM_SETTING_DIFF_RESULT_IN_A }, + { NM_SETTING_IP4_CONFIG_DHCP_FQDN, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_IP_CONFIG_NEVER_DEFAULT, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_IP_CONFIG_MAY_FAIL, NM_SETTING_DIFF_RESULT_IN_A }, { NULL, NM_SETTING_DIFF_RESULT_UNKNOWN }, diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 4692f12eba..7feed07577 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -885,6 +885,7 @@ global: nm_setting_gsm_get_device_id; nm_setting_gsm_get_sim_id; nm_setting_gsm_get_sim_operator_id; + nm_setting_ip4_config_get_dhcp_fqdn; nm_setting_ip4_config_get_dhcp_timeout; nm_setting_ip6_config_addr_gen_mode_get_type; nm_setting_ip6_config_get_addr_gen_mode; |