On Fri, 2016-06-24 at 00:42 +0530, Atul Anand wrote: > Fields for storing ProxyConfig added to store proxy details > for that Object. > --- > src/devices/nm-device.c | 51 > +++++++++++++++++++++++++++++++++++++ > src/devices/nm-device.h | 3 +++ > src/vpn-manager/nm-vpn-connection.c | 24 +++++++++++++++++ > src/vpn-manager/nm-vpn-connection.h | 2 ++ > 4 files changed, 80 insertions(+) > > diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c > index 5fd0bf3..cc99bd1 100644 > --- a/src/devices/nm-device.c > +++ b/src/devices/nm-device.c > @@ -45,6 +45,7 @@ > #include "nm-lndp-rdisc.h" > #include "nm-dhcp-manager.h" > #include "nm-activation-request.h" > +#include "nm-proxy-config.h" > #include "nm-ip4-config.h" > #include "nm-ip6-config.h" > #include "nm-dnsmasq-manager.h" > @@ -111,6 +112,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDevice, > PROP_CARRIER, > PROP_MTU, > PROP_IP4_ADDRESS, > + PROP_PROXY_CONFIG, > PROP_IP4_CONFIG, > PROP_DHCP4_CONFIG, > PROP_IP6_CONFIG, > @@ -288,6 +290,9 @@ typedef struct _NMDevicePrivate { > guint32 dhcp_timeout; > char * dhcp_anycast_address; > > + /* Proxy Configuration */ > + NMProxyConfig * proxy_config; > + > /* IP4 configuration info */ > NMIP4Config * ip4_config; /* Combined config from VPN, > settings, and device */ > IpState ip4_state; > @@ -396,6 +401,8 @@ typedef struct _NMDevicePrivate { > guint check_delete_unrealized_id; > } NMDevicePrivate; > > +static void nm_device_set_proxy_config (NMDevice *self, GHashTable > *options); > + > static gboolean nm_device_set_ip4_config (NMDevice *self, > NMIP4Config *config, > guint32 > default_route_metric, > @@ -4790,6 +4797,8 @@ dhcp4_state_changed (NMDhcpClient *client, > break; > } > > + nm_device_set_proxy_config (self, options); > + > nm_dhcp4_config_set_options (priv->dhcp4.config, > options); > _notify (self, PROP_DHCP4_CONFIG); > priv->dhcp4.num_tries_left = DHCP_NUM_TRIES_MAX; > @@ -8223,6 +8232,39 @@ nm_device_get_dhcp4_config (NMDevice *self) > return NM_DEVICE_GET_PRIVATE (self)->dhcp4.config; > } > > +NMProxyConfig * > +nm_device_get_proxy_config (NMDevice *self) > +{ > + g_return_val_if_fail (NM_IS_DEVICE (self), NULL); > + > + return NM_DEVICE_GET_PRIVATE (self)->proxy_config; > +} > + > +static void > +nm_device_set_proxy_config (NMDevice *self, GHashTable *options) > +{ > + NMDevicePrivate *priv; > + char *pac = NULL; > + > + g_return_if_fail (NM_IS_DEVICE (self)); > + > + priv = NM_DEVICE_GET_PRIVATE (self); > + if (!options) > + _LOGI (LOGD_DEVICE, "Failed to get DHCP options"); > + > + priv->proxy_config = nm_proxy_config_new ();
This will leak any existing proxy config object, I think. This function gets called from dhcp4_state_changed() in state BOUND, which can happen multiple times when a DHCP renew occurs. You probably want do: g_clear_object (&priv->proxy_config); right before you set it to release the old proxy config object, if any. + pac = g_hash_table_lookup (options, "wpad"); > + if (pac) { > + nm_proxy_config_set_method (priv->proxy_config, > NM_PROXY_CONFIG_METHOD_AUTO); > + nm_proxy_config_set_pac_url (priv->proxy_config, > pac); > + _LOGD (LOGD_PROXY, "Device's proxy config method: > AUTO"); > + } else { > + nm_proxy_config_set_method (priv->proxy_config, > NM_PROXY_CONFIG_METHOD_NONE); > + _LOGI (LOGD_PROXY, "PAC url not obtained from DHCP > server"); > + } > +} > + > NMIP4Config * > nm_device_get_ip4_config (NMDevice *self) > { > @@ -10477,6 +10519,7 @@ _cleanup_generic_post (NMDevice *self, > CleanupType cleanup_type) > */ > nm_device_set_ip4_config (self, NULL, 0, TRUE, TRUE, NULL); > nm_device_set_ip6_config (self, NULL, TRUE, TRUE, NULL); > + g_clear_object (&priv->proxy_config); > g_clear_object (&priv->con_ip4_config); > g_clear_object (&priv->dev_ip4_config); > g_clear_object (&priv->ext_ip4_config); > @@ -11889,6 +11932,9 @@ get_property (GObject *object, guint prop_id, > case PROP_MTU: > g_value_set_uint (value, priv->mtu); > break; > + case PROP_PROXY_CONFIG: > + nm_utils_g_value_set_object_path (value, > ip_config_valid (priv->state) ? priv->proxy_config : NULL); > + break; > The NMProxyConfig objects aren't exported over D-Bus, so I don't think this is going to work, since they won't have object paths. Do we even need an NMDevice property for the proxy config at all? If the NMDevice always pushes the proxy config down to the dispatcher and PACRunnerManager then we don't need it to be an NMDevice property at all. > case PROP_IP4_CONFIG: > nm_utils_g_value_set_object_path (value, > ip_config_valid (priv->state) ? priv->ip4_config : NULL); > break; > @@ -12093,6 +12139,11 @@ nm_device_class_init (NMDeviceClass *klass) > 0, G_MAXUINT32, 0, /* FIXME */ > G_PARAM_READWRITE | > G_PARAM_STATIC_STRINGS); > + obj_properties[PROP_PROXY_CONFIG] = > + g_param_spec_string (NM_DEVICE_PROXY_CONFIG, "", "", > + NULL, > + G_PARAM_READWRITE | > + G_PARAM_STATIC_STRINGS); Same here since this is property-related code, does it need to be a property? > obj_properties[PROP_IP4_CONFIG] = > g_param_spec_string (NM_DEVICE_IP4_CONFIG, "", "", > NULL, > diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h > index 4b365d6..f058eea 100644 > --- a/src/devices/nm-device.h > +++ b/src/devices/nm-device.h > @@ -40,6 +40,7 @@ > #define NM_DEVICE_CAPABILITIES "capabilities" > #define NM_DEVICE_CARRIER "carrier" > #define NM_DEVICE_IP4_ADDRESS "ip4-address" > +#define NM_DEVICE_PROXY_CONFIG "proxy-config" > #define NM_DEVICE_IP4_CONFIG "ip4-config" > #define NM_DEVICE_DHCP4_CONFIG "dhcp4-config" > #define NM_DEVICE_IP6_CONFIG "ip6-config" > @@ -359,6 +360,8 @@ const char * nm_device_get_initial_hw_address > (NMDevice *dev); > NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *dev); > NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *dev); > > +NMProxyConfig * nm_device_get_proxy_config (NMDevice *dev); > + > NMIP4Config * nm_device_get_ip4_config (NMDevice *dev); > void nm_device_replace_vpn4_config (NMDevice *dev, > NMIP4Config *old, > diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn- > manager/nm-vpn-connection.c > index b2aa8f6..6ed79cd 100644 > --- a/src/vpn-manager/nm-vpn-connection.c > +++ b/src/vpn-manager/nm-vpn-connection.c > @@ -31,6 +31,7 @@ > #include <syslog.h> > > #include "nm-vpn-connection.h" > +#include "nm-proxy-config.h" > #include "nm-ip4-config.h" > #include "nm-ip6-config.h" > #include "nm-platform.h" > @@ -107,6 +108,7 @@ typedef struct { > GCancellable *cancellable; > GVariant *connect_hash; > guint connect_timeout; > + NMProxyConfig *proxy_config; > gboolean has_ip4; > NMIP4Config *ip4_config; > guint32 ip4_internal_gw; > @@ -511,6 +513,7 @@ _set_vpn_state (NMVpnConnection *self, > _get_applied_connection > (self), > parent_dev, > priv->ip_iface, > + priv->proxy_config, > priv->ip4_config, > priv->ip6_config, > dispatcher_pre_up_done, > @@ -530,6 +533,7 @@ _set_vpn_state (NMVpnConnection *self, > _get_applied_connection > (self), > parent_dev, > priv->ip_iface, > + priv->proxy_config, > priv->ip4_config, > priv->ip6_config, > NULL, > @@ -543,6 +547,7 @@ _set_vpn_state (NMVpnConnection *self, > _get_applied_co > nnection (self), > parent_dev, > priv->ip_iface, > + priv- > >proxy_config, > priv- > >ip4_config, > priv- > >ip6_config); > } else { > @@ -551,6 +556,7 @@ _set_vpn_state (NMVpnConnection *self, > _get_applied_co > nnection (self), > parent_dev, > priv->ip_iface, > + priv- > >proxy_config, > priv- > >ip4_config, > priv- > >ip6_config, > dispatcher_pre_ > down_done, > @@ -573,6 +579,7 @@ _set_vpn_state (NMVpnConnection *self, > parent_ > dev, > priv- > >ip_iface, > NULL, > + NULL, > NULL); > } else { > nm_dispatcher_call_vpn > (DISPATCHER_ACTION_VPN_DOWN, > @@ -584,6 +591,7 @@ _set_vpn_state (NMVpnConnection *self, > NULL, > NULL, > NULL, > + NULL, > NULL); > } > } > @@ -1251,6 +1259,12 @@ process_generic_config (NMVpnConnection *self, > GVariant *dict) > g_object_notify (G_OBJECT (self), > NM_VPN_CONNECTION_BANNER); > } > > + if (g_variant_lookup (dict, NM_VPN_PLUGIN_CONFIG_PROXY_PAC, > "&s", &str)) { > + nm_proxy_config_set_method (priv->proxy_config, > NM_PROXY_CONFIG_METHOD_AUTO); > + nm_proxy_config_set_pac_url (priv->proxy_config, > str); > + } else > + nm_proxy_config_set_method (priv->proxy_config, > NM_PROXY_CONFIG_METHOD_NONE); > + > /* External world-visible address of the VPN server */ > priv->ip4_external_gw = 0; > g_clear_pointer (&priv->ip6_external_gw, g_free); > @@ -2135,6 +2149,14 @@ nm_vpn_connection_get_banner (NMVpnConnection > *self) > return NM_VPN_CONNECTION_GET_PRIVATE (self)->banner; > } > > +NMProxyConfig * > +nm_vpn_connection_get_proxy_config (NMVpnConnection *self) > +{ > + g_return_val_if_fail (NM_IS_VPN_CONNECTION (self), NULL); > + > + return NM_VPN_CONNECTION_GET_PRIVATE (self)->proxy_config; > +} > + > NMIP4Config * > nm_vpn_connection_get_ip4_config (NMVpnConnection *self) > { > @@ -2509,6 +2531,7 @@ nm_vpn_connection_init (NMVpnConnection *self) > > priv->vpn_state = STATE_WAITING; > priv->secrets_idx = SECRETS_REQ_SYSTEM; > + priv->proxy_config = g_object_ref (nm_proxy_config_new ()); Objects are created with an initial refcount of 1, so we don't need to ref it on creation. Things that get it with nm_vpn_connection_get_proxy_config() should be ref-ing the proxy config if they need it for long-term. You might have C&P-ed this from the defualt_route_manager stuff just below, but it's refed there because the DefaultRouteManager is a singleton. The ProxyConfig objects aren't. > priv->default_route_manager = g_object_ref > (nm_default_route_manager_get ()); > priv->route_manager = g_object_ref (nm_route_manager_get > ()); > } > @@ -2533,6 +2556,7 @@ dispose (GObject *object) > g_cancellable_cancel (priv->cancellable); > g_clear_object (&priv->cancellable); > } > + g_clear_object (&priv->proxy_config); > nm_exported_object_clear_and_unexport (&priv->ip4_config); > nm_exported_object_clear_and_unexport (&priv->ip6_config); > g_clear_object (&priv->proxy); > diff --git a/src/vpn-manager/nm-vpn-connection.h b/src/vpn- > manager/nm-vpn-connection.h > index 6837432..09a0379 100644 > --- a/src/vpn-manager/nm-vpn-connection.h > +++ b/src/vpn-manager/nm-vpn-connection.h > @@ -89,6 +89,8 @@ > void nm_vpn_connection_disconnect (NMVpnConnecti > on *self, > NMVpnConnect > ionStateReason reason, > gboolean > quitting); > > +NMProxyConfig * nm_vpn_connection_get_proxy_config > (NMVpnConnection *self); > + > NMIP4Config > * nm_vpn_connection_get_ip4_config (NMVpnConnection *self); > NMIP6Config > * nm_vpn_connection_get_ip6_config (NMVpnConnection *self); > const char > * nm_vpn_connection_get_ip_iface (NMVpnConnection *self, > gboolean fallback_device); _______________________________________________ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list