We have agreed upon a generic mechanism for proxy configuration on which i have started working . The included patch is the first step towards achieving the goal in a step wise manner . It includes the implementation of our desired object along with Fixes in dhcp-manager for stuffing url into the right object . We already have the wpad-via-dhcp fixup ( bug #368423 ) . The Object (patch) currently lacks Integration with NMSetting and also it's not currently doing any useful work with the received pac url . Tasks have been broken down into multiple steps and this is the initial one .
Patch has been tested with current NM-master and good news is that NM is dumping url into the log successfully and creating the Proxy config .
Patch can be merged easily :
https://github.com/NetworkManager/NetworkManager/pull/6
diff --git a/src/Makefile.am b/src/Makefile.am
index 1df9ce2..da1af87 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -419,6 +419,8 @@ libNetworkManager_la_SOURCES = \
nm-exported-object.h \
nm-firewall-manager.c \
nm-firewall-manager.h \
+ nm-proxy-config.c \
+ nm-proxy-config.h \
nm-ip4-config.c \
nm-ip4-config.h \
nm-ip6-config.c \
@@ -569,6 +571,8 @@ libnm_iface_helper_la_SOURCES = \
\
nm-exported-object.c \
nm-exported-object.h \
+ nm-proxy-config.c \
+ nm-proxy-config.h \
nm-ip4-config.c \
nm-ip4-config.h \
nm-ip6-config.c \
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c
index 3490c0d..25f8a2c 100644
--- a/src/dhcp-manager/nm-dhcp-client.c
+++ b/src/dhcp-manager/nm-dhcp-client.c
@@ -716,6 +716,7 @@ nm_dhcp_client_handle_event (gpointer unused,
guint32 old_state;
guint32 new_state;
GHashTable *str_options = NULL;
+ GObject *proxy_config = NULL;
GObject *ip_config = NULL;
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE);
@@ -749,6 +750,15 @@ nm_dhcp_client_handle_event (gpointer unused,
g_variant_unref (value);
}
+ /* Create the Proxy Config */
+ g_warn_if_fail (g_hash_table_size (str_options));
+ if (g_hash_table_size (str_options))
+ proxy_config = (GObject *) nm_dhcp_utils_proxy_config_from_options (str_options);
+ if (proxy_config == NULL)
+ _LOGW ("Proxy config not created");
+ else
+ _LOGI ("Proxy Config created");
+
/* Create the IP config */
g_warn_if_fail (g_hash_table_size (str_options));
if (g_hash_table_size (str_options)) {
@@ -778,6 +788,7 @@ nm_dhcp_client_handle_event (gpointer unused,
if (str_options)
g_hash_table_destroy (str_options);
+ g_clear_object (&proxy_config);
g_clear_object (&ip_config);
return TRUE;
diff --git a/src/dhcp-manager/nm-dhcp-utils.c b/src/dhcp-manager/nm-dhcp-utils.c
index 3c397ce..7dedf46 100644
--- a/src/dhcp-manager/nm-dhcp-utils.c
+++ b/src/dhcp-manager/nm-dhcp-utils.c
@@ -365,6 +365,28 @@ process_domain_search (const char *str, GFunc add_func, gpointer user_data)
g_free (unescaped);
}
+NMProxyConfig *
+nm_dhcp_utils_proxy_config_from_options (GHashTable *options)
+{
+ NMProxyConfig *proxy_config = NULL;
+ char *str = NULL;
+
+ g_return_val_if_fail (options !=NULL, NULL);
+
+ proxy_config = nm_proxy_config_new ();
+ nm_proxy_config_set_method (proxy_config, NM_PROXY_CONFIG_METHOD_AUTO);
+
+ str = g_hash_table_lookup (options, "wpad");
+ if (str) {
+ nm_log_info (LOGD_DHCP4, " wpad '%s'", str);
+ nm_proxy_config_set_pac_url (proxy_config, str);
+ } else if (str == NULL) {
+ nm_log_info (LOGD_DHCP4, " PAC url not obtained ");
+ }
+
+ return proxy_config;
+}
+
static void
ip4_add_domain_search (gpointer data, gpointer user_data)
{
diff --git a/src/dhcp-manager/nm-dhcp-utils.h b/src/dhcp-manager/nm-dhcp-utils.h
index 056982c..d431186 100644
--- a/src/dhcp-manager/nm-dhcp-utils.h
+++ b/src/dhcp-manager/nm-dhcp-utils.h
@@ -21,11 +21,14 @@
#include <stdlib.h>
+#include <nm-proxy-config.h>
#include <nm-ip4-config.h>
#include <nm-ip6-config.h>
#include "nm-default.h"
+NMProxyConfig *nm_dhcp_utils_proxy_config_from_options (GHashTable *options);
+
NMIP4Config *nm_dhcp_utils_ip4_config_from_options (int ifindex,
const char *iface,
GHashTable *options,
diff --git a/src/nm-proxy-config.c b/src/nm-proxy-config.c
new file mode 100644
index 0000000..084ccbb
--- /dev/null
+++ b/src/nm-proxy-config.c
@@ -0,0 +1,223 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#include "nm-default.h"
+
+#include "nm-proxy-config.h"
+
+#include <string.h>
+
+#include "nm-utils.h"
+#include "NetworkManagerUtils.h"
+
+#define NM_PROXY_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PROXY_CONFIG, NMProxyConfigPrivate))
+
+G_DEFINE_TYPE (NMProxyConfig, nm_proxy_config, G_TYPE_OBJECT)
+
+typedef struct {
+ NMProxyConfigMethod method;
+ GPtrArray *proxies;
+ char *pac_url;
+ char *pac_script;
+} NMProxyConfigPrivate;
+
+NM_GOBJECT_PROPERTIES_DEFINE (NMProxyConfig,
+ PROP_METHOD,
+ PROP_PROXIES,
+ PROP_PAC_URL,
+ PROP_PAC_SCRIPT,
+);
+
+NMProxyConfig *
+nm_proxy_config_new (void)
+{
+ return NM_PROXY_CONFIG (g_object_new (NM_TYPE_PROXY_CONFIG, NULL));
+}
+
+void
+nm_proxy_config_set_method (NMProxyConfig *config, NMProxyConfigMethod method)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ priv->method = method;
+}
+
+NMProxyConfigMethod
+nm_proxy_config_get_method (const NMProxyConfig *config)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ return priv->method;
+}
+
+void
+nm_proxy_config_reset_proxies (NMProxyConfig *config)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ if (priv->proxies->len !=0) {
+ g_ptr_array_set_size (priv->proxies, 0);
+ _notify (config, PROP_PROXIES);
+ }
+}
+
+void
+nm_proxy_config_add_proxy (NMProxyConfig *config, const char *proxy)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+ int i;
+
+ g_return_if_fail (proxy != NULL);
+ g_return_if_fail (proxy[0] != '\0');
+
+ for (i = 0; i < priv->proxies->len; i++)
+ if (!g_strcmp0 (g_ptr_array_index (priv->proxies, i), proxy))
+ return;
+
+ g_ptr_array_add (priv->proxies, g_strdup (proxy));
+ _notify (config, PROP_PROXIES);
+}
+
+void
+nm_proxy_config_del_proxy (NMProxyConfig *config, guint i)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ g_return_if_fail (i < priv->proxies->len);
+
+ g_ptr_array_remove_index (priv->proxies, i);
+ _notify (config, PROP_PROXIES);
+}
+
+guint32
+nm_proxy_config_get_num_proxies (const NMProxyConfig *config)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ return priv->proxies->len;
+}
+
+const char *
+nm_proxy_config_get_proxy (const NMProxyConfig *config, guint i)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ return g_ptr_array_index (priv->proxies, i);
+}
+
+void
+nm_proxy_config_set_pac_url (NMProxyConfig *config, const char *url)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ g_free (priv->pac_url);
+ priv->pac_url = g_strdup (url);
+}
+
+const char *
+nm_proxy_config_get_pac_url (const NMProxyConfig *config)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ return priv->pac_url;
+}
+
+void
+nm_proxy_config_set_pac_script (NMProxyConfig *config, const char *script)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ g_free (priv->pac_script);
+ priv->pac_script = g_strdup (script);
+}
+
+const char *
+nm_proxy_config_get_pac_script (const NMProxyConfig *config)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ return priv->pac_script;
+}
+
+static void
+nm_proxy_config_init (NMProxyConfig *config)
+{
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ priv->method = NM_PROXY_CONFIG_METHOD_NONE;
+ priv->proxies = g_ptr_array_new_with_free_func (g_free);
+}
+
+static void
+finalize (GObject *object)
+{
+ NMProxyConfig *self = NM_PROXY_CONFIG (object);
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (self);
+
+ g_ptr_array_unref (priv->proxies);
+ g_free (priv->pac_url);
+ g_free (priv->pac_script);
+
+ G_OBJECT_CLASS (nm_proxy_config_parent_class)->finalize (object);
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ NMProxyConfig *config = NM_PROXY_CONFIG (object);
+ NMProxyConfigPrivate *priv = NM_PROXY_CONFIG_GET_PRIVATE (config);
+
+ switch (prop_id) {
+ case PROP_METHOD:
+ g_value_set_int (value, priv->method);
+ break;
+ case PROP_PROXIES:
+ nm_utils_g_value_set_strv (value, priv->proxies);
+ break;
+ case PROP_PAC_URL:
+ g_value_set_string (value, priv->pac_url);
+ break;
+ case PROP_PAC_SCRIPT:
+ g_value_set_string (value, priv->pac_script);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nm_proxy_config_class_init (NMProxyConfigClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (NMProxyConfigPrivate));
+
+ /* virtual methods */
+ object_class->get_property = get_property;
+ object_class->finalize = finalize;
+
+ obj_properties[PROP_METHOD] =
+ g_param_spec_int (NM_PROXY_CONFIG_METHOD, "", "",
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_PROXIES] =
+ g_param_spec_boxed (NM_PROXY_CONFIG_PROXIES, "", "",
+ G_TYPE_STRV,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_PAC_URL] =
+ g_param_spec_string (NM_PROXY_CONFIG_PAC_URL, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_PAC_SCRIPT] =
+ g_param_spec_string (NM_PROXY_CONFIG_PAC_SCRIPT, "", "",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
+}
diff --git a/src/nm-proxy-config.h b/src/nm-proxy-config.h
new file mode 100644
index 0000000..b709e82
--- /dev/null
+++ b/src/nm-proxy-config.h
@@ -0,0 +1,53 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+#include "nm-default.h"
+
+#ifndef __NETWORKMANAGER_PROXY_CONFIG_H__
+#define __NETWORKMANAGER_PROXY_CONFIG_H__
+
+typedef enum {
+ NM_PROXY_CONFIG_METHOD_NONE = 0,
+ NM_PROXY_CONFIG_METHOD_AUTO,
+ NM_PROXY_CONFIG_METHOD_MANUAL
+} NMProxyConfigMethod;
+
+#define NM_TYPE_PROXY_CONFIG (nm_proxy_config_get_type ())
+#define NM_PROXY_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PROXY_CONFIG, NMProxyConfig))
+#define NM_PROXY_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_PROXY_CONFIG, NMProxyConfigClass))
+#define NM_IS_PROXY_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_PROXY_CONFIG))
+#define NM_IS_PROXY_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_PROXY_CONFIG))
+#define NM_PROXY_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_PROXY_CONFIG, NMProxyConfigClass))
+
+struct _NMProxyConfig {
+ GObject parent;
+};
+
+typedef struct {
+ GObjectClass parent;
+} NMProxyConfigClass;
+
+#define NM_PROXY_CONFIG_METHOD "method"
+#define NM_PROXY_CONFIG_PROXIES "proxies"
+#define NM_PROXY_CONFIG_PAC_URL "pac-url"
+#define NM_PROXY_CONFIG_PAC_SCRIPT "pac-script"
+
+GType nm_proxy_config_get_type (void);
+
+NMProxyConfig * nm_proxy_config_new (void);
+
+void nm_proxy_config_set_method (NMProxyConfig *config, NMProxyConfigMethod method);
+NMProxyConfigMethod nm_proxy_config_get_method (const NMProxyConfig *config);
+
+void nm_proxy_config_reset_proxies (NMProxyConfig *config);
+void nm_proxy_config_add_proxy (NMProxyConfig *config, const char *proxy);
+void nm_proxy_config_del_proxy (NMProxyConfig *config, guint i);
+guint32 nm_proxy_config_get_num_proxies (const NMProxyConfig *config);
+const char * nm_proxy_config_get_proxy (const NMProxyConfig *config, guint i);
+
+void nm_proxy_config_set_pac_url (NMProxyConfig *config, const char *url);
+const char * nm_proxy_config_get_pac_url (const NMProxyConfig *config);
+
+void nm_proxy_config_set_pac_script (NMProxyConfig *config, const char *script);
+const char * nm_proxy_config_get_pac_script (const NMProxyConfig *config);
+
+#endif /* __NETWORKMANAGER_PROXY_CONFIG_H__ */
diff --git a/src/nm-types.h b/src/nm-types.h
index fa70372..678fb23 100644
--- a/src/nm-types.h
+++ b/src/nm-types.h
@@ -44,6 +44,7 @@ typedef struct _NMDhcp4Config NMDhcp4Config;
typedef struct _NMDhcp6Config NMDhcp6Config;
typedef struct _NMIP4Config NMIP4Config;
typedef struct _NMIP6Config NMIP6Config;
+typedef struct _NMProxyConfig NMProxyConfig;
typedef struct _NMManager NMManager;
typedef struct _NMPolicy NMPolicy;
typedef struct _NMRfkillManager NMRfkillManager;
Regards ,
Atul