diff options
author | Thomas Haller <thaller@redhat.com> | 2014-03-10 16:32:38 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-04-11 11:31:34 +0200 |
commit | 325d89fc850ef7e77555325c027c8007d5f7aeb1 (patch) | |
tree | f64bf7bdb412cded14f41227686390e23a96b849 | |
parent | d14ffbdb9c2713f151d5c4510fe421246da80344 (diff) |
dhcp: refactor not to pass on NMSettingIP4Config objects
These settings are mostly unused. Do not pass them when starting the client,
instead only pass the argument that is actually used (dhcp_client_id).
This simplifies the code later, when we delay starting of DHCP6 clients --
because there is no need to clone the setting.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/dhcp-manager/nm-dhcp-client.c | 6 | ||||
-rw-r--r-- | src/dhcp-manager/nm-dhcp-client.h | 6 | ||||
-rw-r--r-- | src/dhcp-manager/nm-dhcp-dhclient-utils.c | 29 | ||||
-rw-r--r-- | src/dhcp-manager/nm-dhcp-dhclient-utils.h | 3 | ||||
-rw-r--r-- | src/dhcp-manager/nm-dhcp-dhclient.c | 17 | ||||
-rw-r--r-- | src/dhcp-manager/nm-dhcp-dhcpcd.c | 3 | ||||
-rw-r--r-- | src/dhcp-manager/nm-dhcp-manager.c | 11 | ||||
-rw-r--r-- | src/dhcp-manager/tests/test-dhcp-dhclient.c | 7 |
8 files changed, 31 insertions, 51 deletions
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index a765f125bb..9f726ab302 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -295,7 +295,7 @@ start_monitor (NMDHCPClient *self) gboolean nm_dhcp_client_start_ip4 (NMDHCPClient *self, - NMSettingIP4Config *s_ip4, + const char *dhcp_client_id, GByteArray *dhcp_anycast_addr, const char *hostname) { @@ -311,7 +311,7 @@ nm_dhcp_client_start_ip4 (NMDHCPClient *self, nm_log_info (LOGD_DHCP, "Activation (%s) Beginning DHCPv4 transaction (timeout in %d seconds)", priv->iface, priv->timeout); - priv->pid = NM_DHCP_CLIENT_GET_CLASS (self)->ip4_start (self, s_ip4, dhcp_anycast_addr, hostname); + priv->pid = NM_DHCP_CLIENT_GET_CLASS (self)->ip4_start (self, dhcp_client_id, dhcp_anycast_addr, hostname); if (priv->pid) start_monitor (self); @@ -449,7 +449,6 @@ get_duid (NMDHCPClient *self) gboolean nm_dhcp_client_start_ip6 (NMDHCPClient *self, - NMSettingIP6Config *s_ip6, GByteArray *dhcp_anycast_addr, const char *hostname, gboolean info_only) @@ -482,7 +481,6 @@ nm_dhcp_client_start_ip6 (NMDHCPClient *self, priv->iface, priv->timeout); priv->pid = NM_DHCP_CLIENT_GET_CLASS (self)->ip6_start (self, - s_ip6, dhcp_anycast_addr, hostname, info_only, diff --git a/src/dhcp-manager/nm-dhcp-client.h b/src/dhcp-manager/nm-dhcp-client.h index 4daef103e9..2506547c08 100644 --- a/src/dhcp-manager/nm-dhcp-client.h +++ b/src/dhcp-manager/nm-dhcp-client.h @@ -78,12 +78,11 @@ typedef struct { /* Methods */ GPid (*ip4_start) (NMDHCPClient *self, - NMSettingIP4Config *s_ip4, + const char *dhcp_client_id, GByteArray *anycast_addr, const char *hostname); GPid (*ip6_start) (NMDHCPClient *self, - NMSettingIP6Config *s_ip6, GByteArray *anycast_addr, const char *hostname, gboolean info_only, @@ -121,12 +120,11 @@ gboolean nm_dhcp_client_get_ipv6 (NMDHCPClient *self); const char *nm_dhcp_client_get_uuid (NMDHCPClient *self); gboolean nm_dhcp_client_start_ip4 (NMDHCPClient *self, - NMSettingIP4Config *s_ip4, + const char *dhcp_client_id, GByteArray *dhcp_anycast_addr, const char *hostname); gboolean nm_dhcp_client_start_ip6 (NMDHCPClient *self, - NMSettingIP6Config *s_ip6, GByteArray *dhcp_anycast_addr, const char *hostname, gboolean info_only); diff --git a/src/dhcp-manager/nm-dhcp-dhclient-utils.c b/src/dhcp-manager/nm-dhcp-dhclient-utils.c index d95eeaeb62..3e7173aec3 100644 --- a/src/dhcp-manager/nm-dhcp-dhclient-utils.c +++ b/src/dhcp-manager/nm-dhcp-dhclient-utils.c @@ -70,21 +70,18 @@ add_hostname (GString *str, const char *format, const char *hostname) } static void -add_ip4_config (GString *str, NMSettingIP4Config *s_ip4, const char *hostname) +add_ip4_config (GString *str, const char *dhcp_client_id, const char *hostname) { - const char *tmp; - - tmp = nm_setting_ip4_config_get_dhcp_client_id (s_ip4); - if (tmp) { + if (dhcp_client_id) { gboolean is_octets = TRUE; int i = 0; - while (tmp[i]) { - if ((i % 3) != 2 && !g_ascii_isxdigit (tmp[i])) { + while (dhcp_client_id[i]) { + if ((i % 3) != 2 && !g_ascii_isxdigit (dhcp_client_id[i])) { is_octets = FALSE; break; } - if ((i % 3) == 2 && tmp[i] != ':') { + if ((i % 3) == 2 && dhcp_client_id[i] != ':') { is_octets = FALSE; break; } @@ -96,9 +93,9 @@ add_ip4_config (GString *str, NMSettingIP4Config *s_ip4, const char *hostname) * array formated as hex octets separated by : */ if (is_octets) - g_string_append_printf (str, CLIENTID_FORMAT_OCTETS "\n", tmp); + g_string_append_printf (str, CLIENTID_FORMAT_OCTETS "\n", dhcp_client_id); else - g_string_append_printf (str, CLIENTID_FORMAT "\n", tmp); + g_string_append_printf (str, CLIENTID_FORMAT "\n", dhcp_client_id); } add_hostname (str, HOSTNAME4_FORMAT "\n", hostname); @@ -117,7 +114,7 @@ add_ip4_config (GString *str, NMSettingIP4Config *s_ip4, const char *hostname) } static void -add_ip6_config (GString *str, NMSettingIP6Config *s_ip6, const char *hostname) +add_ip6_config (GString *str, const char *hostname) { add_hostname (str, HOSTNAME6_FORMAT "\n", hostname); g_string_append (str, @@ -129,8 +126,7 @@ add_ip6_config (GString *str, NMSettingIP6Config *s_ip6, const char *hostname) char * nm_dhcp_dhclient_create_config (const char *interface, gboolean is_ip6, - NMSettingIP4Config *s_ip4, - NMSettingIP6Config *s_ip6, + const char *dhcp_client_id, GByteArray *anycast_addr, const char *hostname, const char *orig_path, @@ -159,8 +155,7 @@ nm_dhcp_dhclient_create_config (const char *interface, /* Override config file "dhcp-client-id" and use one from the * connection. */ - if ( nm_setting_ip4_config_get_dhcp_client_id (s_ip4) - && !strncmp (p, CLIENTID_TAG, strlen (CLIENTID_TAG))) + if (dhcp_client_id && !strncmp (p, CLIENTID_TAG, strlen (CLIENTID_TAG))) continue; /* Override config file hostname and use one from the connection */ @@ -225,13 +220,13 @@ nm_dhcp_dhclient_create_config (const char *interface, g_string_append_c (new_contents, '\n'); if (is_ip6) { - add_ip6_config (new_contents, s_ip6, hostname); + add_ip6_config (new_contents, hostname); add_also_request (alsoreq, "dhcp6.name-servers"); add_also_request (alsoreq, "dhcp6.domain-search"); add_also_request (alsoreq, "dhcp6.client-id"); add_also_request (alsoreq, "dhcp6.server-id"); } else { - add_ip4_config (new_contents, s_ip4, hostname); + add_ip4_config (new_contents, dhcp_client_id, hostname); add_also_request (alsoreq, "rfc3442-classless-static-routes"); add_also_request (alsoreq, "ms-classless-static-routes"); add_also_request (alsoreq, "static-routes"); diff --git a/src/dhcp-manager/nm-dhcp-dhclient-utils.h b/src/dhcp-manager/nm-dhcp-dhclient-utils.h index a405d65b2d..e8d91b3147 100644 --- a/src/dhcp-manager/nm-dhcp-dhclient-utils.h +++ b/src/dhcp-manager/nm-dhcp-dhclient-utils.h @@ -27,8 +27,7 @@ char *nm_dhcp_dhclient_create_config (const char *interface, gboolean is_ip6, - NMSettingIP4Config *s_ip4, - NMSettingIP6Config *s_ip6, + const char *dhcp_client_id, GByteArray *anycast_addr, const char *hostname, const char *orig_path, diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c index 06ebe8a064..9874074fb1 100644 --- a/src/dhcp-manager/nm-dhcp-dhclient.c +++ b/src/dhcp-manager/nm-dhcp-dhclient.c @@ -165,8 +165,7 @@ static gboolean merge_dhclient_config (const char *iface, const char *conf_file, gboolean is_ip6, - NMSettingIP4Config *s_ip4, - NMSettingIP6Config *s_ip6, + const char *dhcp_client_id, GByteArray *anycast_addr, const char *hostname, const char *orig_path, @@ -188,7 +187,7 @@ merge_dhclient_config (const char *iface, } } - new = nm_dhcp_dhclient_create_config (iface, is_ip6, s_ip4, s_ip6, anycast_addr, hostname, orig_path, orig); + new = nm_dhcp_dhclient_create_config (iface, is_ip6, dhcp_client_id, anycast_addr, hostname, orig_path, orig); g_assert (new); success = g_file_set_contents (conf_file, new, -1, error); g_free (new); @@ -272,8 +271,7 @@ static char * create_dhclient_config (const char *iface, gboolean is_ip6, const char *uuid, - NMSettingIP4Config *s_ip4, - NMSettingIP6Config *s_ip6, + const char *dhcp_client_id, GByteArray *dhcp_anycast_addr, const char *hostname) { @@ -300,7 +298,7 @@ create_dhclient_config (const char *iface, } error = NULL; - success = merge_dhclient_config (iface, new, is_ip6, s_ip4, s_ip6, dhcp_anycast_addr, hostname, orig, &error); + success = merge_dhclient_config (iface, new, is_ip6, dhcp_client_id, dhcp_anycast_addr, hostname, orig, &error); if (!success) { nm_log_warn (LOGD_DHCP, "(%s): error creating dhclient%s configuration: %s", iface, is_ip6 ? "6" : "", error->message); @@ -475,7 +473,7 @@ dhclient_start (NMDHCPClient *client, static GPid ip4_start (NMDHCPClient *client, - NMSettingIP4Config *s_ip4, + const char *dhcp_client_id, GByteArray *dhcp_anycast_addr, const char *hostname) { @@ -485,7 +483,7 @@ ip4_start (NMDHCPClient *client, iface = nm_dhcp_client_get_iface (client); uuid = nm_dhcp_client_get_uuid (client); - priv->conf_file = create_dhclient_config (iface, FALSE, uuid, s_ip4, NULL, dhcp_anycast_addr, hostname); + priv->conf_file = create_dhclient_config (iface, FALSE, uuid, dhcp_client_id, dhcp_anycast_addr, hostname); if (!priv->conf_file) { nm_log_warn (LOGD_DHCP4, "(%s): error creating dhclient configuration file.", iface); return -1; @@ -496,7 +494,6 @@ ip4_start (NMDHCPClient *client, static GPid ip6_start (NMDHCPClient *client, - NMSettingIP6Config *s_ip6, GByteArray *dhcp_anycast_addr, const char *hostname, gboolean info_only, @@ -508,7 +505,7 @@ ip6_start (NMDHCPClient *client, iface = nm_dhcp_client_get_iface (client); uuid = nm_dhcp_client_get_uuid (client); - priv->conf_file = create_dhclient_config (iface, TRUE, uuid, NULL, s_ip6, dhcp_anycast_addr, hostname); + priv->conf_file = create_dhclient_config (iface, TRUE, uuid, NULL, dhcp_anycast_addr, hostname); if (!priv->conf_file) { nm_log_warn (LOGD_DHCP6, "(%s): error creating dhclient6 configuration file.", iface); return -1; diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c index 1ab32308c4..acfbee2692 100644 --- a/src/dhcp-manager/nm-dhcp-dhcpcd.c +++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c @@ -88,7 +88,7 @@ dhcpcd_child_setup (gpointer user_data G_GNUC_UNUSED) static GPid ip4_start (NMDHCPClient *client, - NMSettingIP4Config *s_ip4, + const char *dhcp_client_id, GByteArray *dhcp_anycast_addr, const char *hostname) { @@ -167,7 +167,6 @@ ip4_start (NMDHCPClient *client, static GPid ip6_start (NMDHCPClient *client, - NMSettingIP6Config *s_ip6, GByteArray *dhcp_anycast_addr, const char *hostname, gboolean info_only, diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index 932eaad546..4f37768972 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -453,8 +453,7 @@ client_start (NMDHCPManager *self, const GByteArray *hwaddr, const char *uuid, gboolean ipv6, - NMSettingIP4Config *s_ip4, - NMSettingIP6Config *s_ip6, + const char *dhcp_client_id, guint32 timeout, GByteArray *dhcp_anycast_addr, const char *hostname, @@ -493,9 +492,9 @@ client_start (NMDHCPManager *self, add_client (self, client); if (ipv6) - success = nm_dhcp_client_start_ip6 (client, s_ip6, dhcp_anycast_addr, hostname, info_only); + success = nm_dhcp_client_start_ip6 (client, dhcp_anycast_addr, hostname, info_only); else - success = nm_dhcp_client_start_ip4 (client, s_ip4, dhcp_anycast_addr, hostname); + success = nm_dhcp_client_start_ip4 (client, dhcp_client_id, dhcp_anycast_addr, hostname); if (!success) { remove_client (self, client); @@ -547,7 +546,7 @@ nm_dhcp_manager_start_ip4 (NMDHCPManager *self, } else hostname = NULL; - return client_start (self, iface, hwaddr, uuid, FALSE, s_ip4, NULL, timeout, dhcp_anycast_addr, hostname, FALSE); + return client_start (self, iface, hwaddr, uuid, FALSE, nm_setting_ip4_config_get_dhcp_client_id (s_ip4), timeout, dhcp_anycast_addr, hostname, FALSE); } /* Caller owns a reference to the NMDHCPClient on return */ @@ -577,7 +576,7 @@ nm_dhcp_manager_start_ip6 (NMDHCPManager *self, hostname = NULL; } - return client_start (self, iface, hwaddr, uuid, TRUE, NULL, s_ip6, timeout, dhcp_anycast_addr, hostname, info_only); + return client_start (self, iface, hwaddr, uuid, TRUE, NULL, timeout, dhcp_anycast_addr, hostname, info_only); } static void diff --git a/src/dhcp-manager/tests/test-dhcp-dhclient.c b/src/dhcp-manager/tests/test-dhcp-dhclient.c index a912d0022e..c1711f095d 100644 --- a/src/dhcp-manager/tests/test-dhcp-dhclient.c +++ b/src/dhcp-manager/tests/test-dhcp-dhclient.c @@ -36,16 +36,11 @@ test_config (const char *orig, const char *iface, GByteArray *anycast_addr) { - NMSettingIP4Config *s_ip4; char *new; - s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); - g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, dhcp_client_id, NULL); - new = nm_dhcp_dhclient_create_config (iface, FALSE, - s_ip4, - NULL, + dhcp_client_id, anycast_addr, hostname, "/path/to/dhclient.conf", |