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

2016-06-28 Thread Atul Anand
I was trying to keep update_proxy() together with dns & routes update
because the state changes are clearly visible in policy.c. .But the
later really uses more information from policy. Whereas update_proxy()
has just to do with states of Device / VPN. Will edit to update
PacRunnerManager directly from nm-device.c & nm-vpn-connection.c.

On 6/29/16, Dan Williams  wrote:
> On Fri, 2016-06-24 at 00:42 +0530, Atul Anand wrote:
>> 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
>> ,
>> +   

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

2016-06-28 Thread Dan Williams
On Fri, 2016-06-24 at 00:42 +0530, Atul Anand wrote:
> 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 

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

2016-06-23 Thread Atul Anand
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);
+
+