[PATCH 5/5] fixes in src/policy.c and other minor fixes.



src/policy.c fixed to update pacrunner with connection activation
and deactivation.Previous sent configs are destroyed before updating
PacRunner with new cofigs.
---
 libnm-core/nm-vpn-dbus-interface.h |  3 ++
 src/nm-logging.c                   |  3 +-
 src/nm-logging.h                   |  1 +
 src/nm-policy.c                    | 75 +++++++++++++++++++++++++++++++++++++-
 src/nm-types.h                     |  2 +
 5 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/libnm-core/nm-vpn-dbus-interface.h b/libnm-core/nm-vpn-dbus-interface.h
index 9226458..e557e81 100644
--- a/libnm-core/nm-vpn-dbus-interface.h
+++ b/libnm-core/nm-vpn-dbus-interface.h
@@ -183,6 +183,9 @@ typedef enum {
 /* string: VPN interface name (tun0, tap0, etc) */
 #define NM_VPN_PLUGIN_CONFIG_TUNDEV      "tundev"
 
+/* string: Proxy PAC */
+#define NM_VPN_PLUGIN_CONFIG_PROXY_PAC   "pac"
+
 /* string: Login message */
 #define NM_VPN_PLUGIN_CONFIG_BANNER      "banner"
 
diff --git a/src/nm-logging.c b/src/nm-logging.c
index 15e1492..0aa2b2b 100644
--- a/src/nm-logging.c
+++ b/src/nm-logging.c
@@ -129,7 +129,7 @@ static struct {
        char *logging_domains_to_string;
        const LogLevelDesc level_desc[_LOGL_N];
 
-#define _DOMAIN_DESC_LEN 38
+#define _DOMAIN_DESC_LEN 39
        /* Would be nice to use C99 flexible array member here,
         * but that feature doesn't seem well supported. */
        const LogDesc domain_desc[_DOMAIN_DESC_LEN];
@@ -185,6 +185,7 @@ static struct {
                { LOGD_AUDIT,     "AUDIT" },
                { LOGD_SYSTEMD,   "SYSTEMD" },
                { LOGD_VPN_PLUGIN,"VPN_PLUGIN" },
+               { LOGD_PROXY,     "PROXY" },
                { 0, NULL }
                /* keep _DOMAIN_DESC_LEN in sync */
        },
diff --git a/src/nm-logging.h b/src/nm-logging.h
index 655f675..655175d 100644
--- a/src/nm-logging.h
+++ b/src/nm-logging.h
@@ -66,6 +66,7 @@ typedef enum  { /*< skip >*/
        LOGD_AUDIT      = (1LL << 34),
        LOGD_SYSTEMD    = (1LL << 35),
        LOGD_VPN_PLUGIN = (1LL << 36),
+       LOGD_PROXY      = (1LL << 37),
 
        __LOGD_MAX,
        LOGD_ALL       = (((__LOGD_MAX - 1LL) << 1) - 1LL),
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 0c63b1c..29ea05c 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -34,6 +34,7 @@
 #include "nm-setting-ip4-config.h"
 #include "nm-setting-connection.h"
 #include "nm-platform.h"
+#include "nm-pacrunner-manager.h"
 #include "nm-dns-manager.h"
 #include "nm-vpn-manager.h"
 #include "nm-auth-utils.h"
@@ -78,6 +79,7 @@ struct _NMPolicyPrivate {
        GResolver *resolver;
        GInetAddress *lookup_addr;
        GCancellable *lookup_cancellable;
+       NMPacRunnerManager *pacrunner_manager;
        NMDnsManager *dns_manager;
        gulong config_changed_id;
 
@@ -414,6 +416,64 @@ update_default_ac (NMPolicy *self,
                set_active_func (best, TRUE);
 }
 
+static void
+update_proxy (NMPolicy *self)
+{
+       NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
+       NMDevice *device = NULL;
+       const GSList *connections = NULL, *iter;
+
+       connections = nm_manager_get_active_connections (priv->manager);
+       if (!connections)
+               return;
+
+       for (iter = connections; iter; iter = g_slist_next (iter)) {
+               NMActiveConnection *active = iter->data;
+               NMProxyConfig *proxy_config = NULL;
+               NMIP4Config *ip4_config = NULL;
+               NMIP6Config *ip6_config = NULL;
+               const char *ip_iface = NULL;
+
+               if (NM_IS_VPN_CONNECTION (active)) {
+                       ip_iface = nm_vpn_connection_get_ip_iface (NM_VPN_CONNECTION (active), TRUE);
+                       nm_pacrunner_manager_remove (priv->pacrunner_manager, ip_iface);
+
+                       proxy_config = nm_vpn_connection_get_proxy_config (NM_VPN_CONNECTION (active));
+                       ip4_config = nm_vpn_connection_get_ip4_config (NM_VPN_CONNECTION (active));
+                       ip6_config = nm_vpn_connection_get_ip6_config (NM_VPN_CONNECTION (active));
+
+                       if (!nm_pacrunner_manager_send (priv->pacrunner_manager,
+                                                       ip_iface,
+                                                       proxy_config,
+                                                       ip4_config,
+                                                       ip6_config,
+                                                       NM_PROXY_IP_CONFIG_TYPE_VPN))
+                               _LOGI (LOGD_PROXY, "Couldn't update pacrunner for %s",ip_iface);
+
+                       continue;
+               }
+
+               device = nm_active_connection_get_device (active);
+               if (!device)
+                       continue;
+
+               ip_iface = nm_device_get_ip_iface (device);
+               nm_pacrunner_manager_remove (priv->pacrunner_manager, ip_iface);
+
+               proxy_config = nm_device_get_proxy_config (device);
+               ip4_config = nm_device_get_ip4_config (device);
+               ip6_config = nm_device_get_ip6_config (device);
+
+               if (!nm_pacrunner_manager_send (priv->pacrunner_manager,
+                                               ip_iface,
+                                               proxy_config,
+                                               ip4_config,
+                                               ip6_config,
+                                               NM_PROXY_IP_CONFIG_TYPE_DEFAULT))
+                       _LOGI (LOGD_PROXY, "Couldn't update pacrunner for %s",ip_iface);
+       }
+}
+
 static NMIP4Config *
 get_best_ip4_config (NMPolicy *self,
                      gboolean ignore_never_default,
@@ -1204,6 +1264,8 @@ device_state_changed (NMDevice *device,
                        nm_connection_clear_secrets (NM_CONNECTION (connection));
                }
 
+               update_proxy (self);
+
                /* Add device's new IPv4 and IPv6 configs to DNS */
 
                nm_dns_manager_begin_updates (priv->dns_manager, __func__);
@@ -1247,8 +1309,10 @@ device_state_changed (NMDevice *device,
                if (reason == NM_DEVICE_STATE_REASON_CARRIER && old_state == NM_DEVICE_STATE_UNAVAILABLE)
                        reset_autoconnect_all (self, device);
 
-               if (old_state > NM_DEVICE_STATE_DISCONNECTED)
+               if (old_state > NM_DEVICE_STATE_DISCONNECTED) {
+                       update_proxy (self);
                        update_routing_and_dns (self, FALSE);
+               }
 
                /* Device is now available for auto-activation */
                schedule_activate_check (self, device);
@@ -1440,6 +1504,8 @@ vpn_connection_activated (NMPolicy *self, NMVpnConnection *vpn)
        NMIP6Config *ip6_config;
        const char *ip_iface;
 
+       update_proxy (self);
+
        nm_dns_manager_begin_updates (priv->dns_manager, __func__);
 
        ip_iface = nm_vpn_connection_get_ip_iface (vpn, TRUE);
@@ -1466,6 +1532,8 @@ vpn_connection_deactivated (NMPolicy *self, NMVpnConnection *vpn)
        NMIP4Config *ip4_config;
        NMIP6Config *ip6_config;
 
+       update_proxy (self);
+
        nm_dns_manager_begin_updates (priv->dns_manager, __func__);
 
        ip4_config = nm_vpn_connection_get_ip4_config (vpn);
@@ -1871,6 +1939,8 @@ constructed (GObject *object)
        priv->fw_started_id = g_signal_connect (priv->firewall_manager, NM_FIREWALL_MANAGER_STARTED,
                                                G_CALLBACK (firewall_started), self);
 
+       priv->pacrunner_manager = g_object_ref (nm_pacrunner_manager_get ());
+
        priv->dns_manager = g_object_ref (nm_dns_manager_get ());
        nm_dns_manager_set_initial_hostname (priv->dns_manager, priv->orig_hostname);
        priv->config_changed_id = g_signal_connect (priv->dns_manager, NM_DNS_MANAGER_CONFIG_CHANGED,
@@ -1933,6 +2003,9 @@ dispose (GObject *object)
                g_clear_object (&priv->firewall_manager);
        }
 
+       if (priv->pacrunner_manager)
+               g_clear_object (&priv->pacrunner_manager);
+
        if (priv->dns_manager) {
                nm_clear_g_signal_handler (priv->dns_manager, &priv->config_changed_id);
                g_clear_object (&priv->dns_manager);
diff --git a/src/nm-types.h b/src/nm-types.h
index 1fbf043..4e80200 100644
--- a/src/nm-types.h
+++ b/src/nm-types.h
@@ -42,11 +42,13 @@ typedef struct _NMDefaultRouteManager NMDefaultRouteManager;
 typedef struct _NMDevice             NMDevice;
 typedef struct _NMDhcp4Config        NMDhcp4Config;
 typedef struct _NMDhcp6Config        NMDhcp6Config;
+typedef struct _NMProxyConfig        NMProxyConfig;
 typedef struct _NMIP4Config          NMIP4Config;
 typedef struct _NMIP6Config          NMIP6Config;
 typedef struct _NMManager            NMManager;
 typedef struct _NMPolicy             NMPolicy;
 typedef struct _NMRfkillManager      NMRfkillManager;
+typedef struct _NMPacRunnerManager   NMPacRunnerManager;
 typedef struct _NMRouteManager       NMRouteManager;
 typedef struct _NMSessionMonitor     NMSessionMonitor;
 typedef struct _NMSleepMonitor       NMSleepMonitor;
-- 
2.5.5



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]