libnm-core: add a 'dhcp-fqdn' property to NMSettingIP4Config
authorBeniamino Galvani <bgalvani@redhat.com>
Tue, 13 Oct 2015 12:10:01 +0000 (14:10 +0200)
committerBeniamino Galvani <bgalvani@redhat.com>
Mon, 23 Nov 2015 15:31:52 +0000 (16:31 +0100)
The property contains the fully qualified domain name to be sent to
DHCP server using the FQDN option. The property is mutually exclusive
with 'dhcp-hostname'.

libnm-core/nm-setting-ip-config.c
libnm-core/nm-setting-ip4-config.c
libnm-core/nm-setting-ip4-config.h
libnm-core/tests/test-general.c
libnm/libnm.ver

index b36a853..7e719aa 100644 (file)
@@ -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,
index 8302695..15949db 100644 (file)
@@ -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---
index 23e9e99..a78df70 100644 (file)
@@ -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
 
index 2111e59..f4dec28 100644 (file)
@@ -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 },
index 4692f12..7feed07 100644 (file)
@@ -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;