Improve PAC URL Mutation and PAC URL and WISPr Proxy Failure Logging
cover Improve PAC URL Mutation and PAC URL and WISPr Proxy Failure Logging
There appear to be a population of premises ISP equipment (some possibly correlated with Spectrum Communications in Southern California, United States) in which the ISP equipment sporadically and incorrectly emits DHCP Option 252 ("Web Proxy Auto-Discovery (WPAD)") with an invalid proxy auto-configuration (PAC) URL (such as 'http://wpad.lan/wpad.dat'), even when neither the customer nor the ISP has such an option actively configured on the equipment.
This URL, per the WPAD specification, leads the Connection Manager to believe that it must use a proxy to reach HTTP- or HTTPS-based resources, including those specified for WISPr online reachability checks. Because neither the PAC file ('wpad.dat' in the example above) nor the host ('wpad.lan' in the example above) associated with the PAC URL exist, those online reachability checks unconditionally fail despite such resources being directly reachable, without an intervening proxy.
Because:
* PAC configuration (or lack thereof) has not been historically
* POSIX error codes are themselves limited (for example, there are no -ENOPROXY, -EBADPROXY, or -EPROXYLOOKUP codes)
* POSIX error code usage for WISPr failures is similarly limited (for example, -EINVAL)
insight into the actual nature of an online reachability check failure is, by extension, limited, particularly when proxy failures are involved. Consequently, log messages generated from these changes provide crucial insight into triaging and resolving such failures.
Finally, there have been three (3) call sites in the network service code where the network service proxy auto-configuration (PAC) URL was set. However, it was never (but now, with these changes, is) set in '__connman_service_set_proxy_autoconfig', where it is invoked by the DHCP client code when DHCP option 252 (Web Proxy Auto-Discovery (WPAD)) is encountered.
Grant Erickson (15):
service: Add 'service_log_pac' function.
service: Add 'service_set_pac' function.
service: Leverage 'service_set_pac' function.
service: Ensure the PAC URL is set in
'__connman_service_set_proxy_autoconfig'.
service: Document 'service_log_pac'.
service: Document 'service_set_pac'.
service: Add 'service_set_proxy_method' function.
service: Leverage 'service_set_proxy_method'.
service: Leverage 'service_set_proxy_method'.
service: Document 'service_set_proxy_method'.
service: Document 'service_set_proxy_method_auto_handler'.
service: Document '__connman_service_set_proxy_autoconfig'.
wispr: Add 'wispr_log_proxy_failure' function.
wispr: Leverage 'wispr_log_proxy_failure'.
wispr: Document 'wispr_log_proxy_failure'.
src/service.c | 273 +++++++++++++++++++++++++++++++++++++++++++------- src/wispr.c | 42 +++++++- 2 files changed, 276 insertions(+), 39 deletions(-)
Signature · 1 line
2.45.0
PATCH 1/15 service: Add 'service_log_pac' function.
Logs the network service interface name and type at the info level when the proxy auto-configuration (PAC) URL is set or cleared.
Frequently, a spurious, misconfigured, or otherwise incorrect PAC URL is the source of connectivity problems, particularly for online reachability checks.
--- src/service.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
src/service.c +13 -0
@@ -555,6 +555,19 @@ int __connman_service_load_modifiable(struct connman_service *service)return 0 ; } +static void service_log_pac (const struct connman_service *service, +const char *url) +{ + g_autofree char *interface = NULL; + + interface =connman_service_get_interface (service); + +connman_info ("Interface %s [ %s ] proxy auto-configuration (PAC) URL %s." , + interface, +__connman_service_type2string (service->type), + url ? url :"is not set" ); +} +static int service_load (struct connman_service *service) {GKeyFile *keyfile;
Signature · 1 line
2.45.0
PATCH 2/15 service: Add 'service_set_pac' function.
In reply to Grant EricksonAllows for logging, setting, and dispatching property changed notifications from a single place.
--- src/service.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
src/service.c +27 -0
@@ -233,6 +233,7 @@ static struct connman_ipconfig *create_ip4config(struct connman_service *servicestatic struct connman_ipconfig *create_ip6config (struct connman_service *service,int index);static void dns_changed (struct connman_service *service); +static void proxy_changed (struct connman_service *service);static void vpn_auto_connect (void );static void trigger_autoconnect (struct connman_service *service);static void service_list_sort (const char *function);
@@ -568,6 +569,32 @@ static void service_log_pac(const struct connman_service *service, url ? url : "is not set"); } +static void service_set_pac (struct connman_service *service, +const char *pac, +bool dochanged) +{ +DBG ("service %p (%s) pac %p (%s) dochanged %u" , + service,connman_service_get_identifier (service), + pac, + pac ? pac :"<null>" , + dochanged); + +if (service->hidden) +return ; + +service_log_pac (service, pac); + +g_free (service->pac); + +if (pac &&strlen (pac) >0 ) + service->pac =g_strstrip (g_strdup (pac)); +else + service->pac =NULL ; + +if (dochanged) +proxy_changed (service); +} +static int service_load (struct connman_service *service) {GKeyFile *keyfile;
Signature · 1 line
2.45.0
PATCH 3/15 service: Leverage 'service_set_pac' function.
In reply to Grant EricksonLeverage 'service_set_pac' at the three call sites the proxy auto-configuration (PAC) URL is currently set or cleared for a network service.
Frequently, a spurious, misconfigured, or otherwise incorrect PAC URL is the source of connectivity problems, particularly for online reachability checks. Consequently, being able to log all such mutations can be helpful in triaging such problems.
--- src/service.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
src/service.c +4 -13
@@ -770,8 +770,7 @@ static int service_load(struct connman_service *service) str =g_key_file_get_string (keyfile, service->identifier,"Proxy.URL" ,NULL );if (str) { -g_free (service->pac); - service->pac = str; +service_set_pac (service, str, false); } service->mdns_config = g_key_file_get_boolean(keyfile,
@@ -5757,12 +5756,9 @@ void __connman_service_timeserver_changed(struct connman_service *service,void __connman_service_set_pac (struct connman_service *service,const char *pac) { -if (service->hidden) -return ; -g_free (service->pac); - service->pac =g_strdup (pac); +const bool dochanged = true; -proxy_changed (service); +service_set_pac (service, pac, dochanged); } void __connman_service_set_agent_identity(struct connman_service *service,
@@ -6049,12 +6045,7 @@ static int update_proxy_configuration(struct connman_service *service,break ;case CONNMAN_SERVICE_PROXY_METHOD_AUTO : -g_free (service->pac); - -if (url &&strlen (url) >0 ) - service->pac =g_strstrip (g_strdup (url)); -else - service->pac =NULL ; +service_set_pac (service, url, false);/* if we are connected: - if service->pac == NULL
Signature · 1 line
2.45.0
PATCH 4/15 service: Ensure the PAC URL is set in '__connman_service_set_proxy_autoconfig'.
In reply to Grant EricksonHistorically, there have been three (3) call sites in the network service code where the network service proxy auto-configuration (PAC) URL is set. However, it was never (but now, with this change, is) set in '__connman_service_set_proxy_autoconfig', where it is invoked by the DHCP client code when DHCP option 252 (Web Proxy Auto-Discovery (WPAD)) is encountered.
--- src/service.c | 4 ++++ 1 file changed, 4 insertions(+)
src/service.c +4 -0
@@ -5600,9 +5600,13 @@ const char *connman_service_get_proxy_url(const struct connman_service *service)void __connman_service_set_proxy_autoconfig (struct connman_service *service,const char *url) { +const bool dochanged = true; +if (!service || service->hidden)return ; +service_set_pac (service, url, !dochanged); + service->proxy =CONNMAN_SERVICE_PROXY_METHOD_AUTO ;if (service->ipconfig_ipv4) {
Signature · 1 line
2.45.0
PATCH 5/15 service: Document 'service_log_pac'.
In reply to Grant EricksonAdd documentation to the 'service_log_pac' function.
--- src/service.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
src/service.c +15 -0
@@ -556,6 +556,21 @@ int __connman_service_load_modifiable(struct connman_service *service)return 0 ; } +/** +* @brief +* Log the proxy auto-configuration (PAC) URL associated with the +* specified service. +* +* @param[in] service A pointer to the immutable network +* service for which to log the proxy +* auto-configuration (PAC) URL. +* @param[in] url An optional pointer to the immutable null- +* terminated C string containing the proxy +* auto-configuration (PAC) URL. +* +* @private +* +*/ static void service_log_pac (const struct connman_service *service,const char *url) {
Signature · 1 line
2.45.0
PATCH 6/15 service: Document 'service_set_pac'.
In reply to Grant EricksonAdd documentation to the 'service_set_pac' function.
--- src/service.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
src/service.c +24 -0
@@ -584,6 +584,30 @@ static void service_log_pac(const struct connman_service *service, url ? url : "is not set"); } +/** +* @brief +* Set and log the proxy auto-configuration (PAC) URL for the +* specified service. +* +* If the specified service is a hidden service, no set or log +* actions are taken. +* +* @param[in,out] service A pointer to the mutable network +* service for which to set the proxy +* auto-configuration (PAC) URL. +* @param[in] url An pointer to the immutable null- +* terminated C string containing the proxy +* auto-configuration (PAC) URL to set. +* @param[in] dochanged A Boolean indicating whether or a D-Bus +* change notification should be sent for +* the service "Proxy" property. +* +* @sa proxy_changed +* @sa service_log_pac +* +* @private +* +*/ static void service_set_pac (struct connman_service *service,const char *pac,bool dochanged)
Signature · 1 line
2.45.0
PATCH 7/15 service: Add 'service_set_proxy_method' function.
In reply to Grant EricksonAllows for logging, setting, and dispatching property changed notifications for the network service proxy method and associated URL, if any, from a single place.
--- src/service.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
src/service.c +31 -0
@@ -5568,6 +5568,37 @@ const char * const *connman_service_get_timeservers(const struct connman_servicereturn (const char *const *)service->timeservers; } +static void service_set_proxy_method (struct connman_service *service, +enum connman_service_proxy_method method, +bool donotifier, +bool (*handler)(struct connman_service *service, +enum connman_service_proxy_method method, +const void *context), +const void *context) +{ +DBG ("service %p (%s) method %d (%s) donotifier %u " +"handler %p, context %p" , + service,connman_service_get_identifier (service), + method,proxymethod2string (method), + donotifier, + handler, + context); + +if (!service || service->hidden) +return ; + + service->proxy = method; + +if (handler !=NULL ) +if (handler (service, method, context) != true) +return ; + +proxy_changed (service); + +if (donotifier) +__connman_notifier_proxy_changed (service); +} +/** * @brief * Set the web proxy method of the specified service.
Signature · 1 line
2.45.0
PATCH 8/15 service: Leverage 'service_set_proxy_method'.
In reply to Grant EricksonLeverage 'service_set_proxy_method' for 'connman_service_set_proxy_method', the first of two call sites.
--- src/service.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
src/service.c +7 -12
@@ -5617,19 +5617,14 @@ static void service_set_proxy_method(struct connman_service *service,void connman_service_set_proxy_method (struct connman_service *service,enum connman_service_proxy_method method) { -DBG ("service %p (%s) method %d (%s)" , - service,connman_service_get_identifier (service), - method,proxymethod2string (method)); - -if (!service || service->hidden) -return ; - - service->proxy = method; +const bool donotifier = method !=CONNMAN_SERVICE_PROXY_METHOD_AUTO ; +void *const context =NULL ; -proxy_changed (service); - -if (method !=CONNMAN_SERVICE_PROXY_METHOD_AUTO ) -__connman_notifier_proxy_changed (service); +service_set_proxy_method (service, + method, + donotifier, +NULL , + context); } enum connman_service_proxy_method connman_service_get_proxy_method(
Signature · 1 line
2.45.0
PATCH 9/15 service: Leverage 'service_set_proxy_method'.
In reply to Grant EricksonLeverage 'service_set_proxy_method' for '__connman_service_set_proxy_autoconfig', the second of two call sites.
--- src/service.c | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-)
src/service.c +32 -17
@@ -5662,32 +5662,47 @@ const char *connman_service_get_proxy_url(const struct connman_service *service)return service->pac; } -void __connman_service_set_proxy_autoconfig (struct connman_service *service, -const char *url) +static bool service_set_proxy_method_auto_handler ( +struct connman_service *service, +enum connman_service_proxy_method method, +const void *context) { -const bool dochanged = true; - -if (!service || service->hidden) -return ; - -service_set_pac (service, url, !dochanged); - - service->proxy =CONNMAN_SERVICE_PROXY_METHOD_AUTO ; +const char *const url = context;if (service->ipconfig_ipv4) {if (__connman_ipconfig_set_proxy_autoconfig ( - service->ipconfig_ipv4, url) <0 ) -return ; + service->ipconfig_ipv4, url) <0 ) +return false; }else if (service->ipconfig_ipv6) {if (__connman_ipconfig_set_proxy_autoconfig ( - service->ipconfig_ipv6, url) <0 ) -return ; + service->ipconfig_ipv6, url) <0 ) +return false; }else -return ; +return false; -proxy_changed (service); +return true; +} + +void __connman_service_set_proxy_autoconfig (struct connman_service *service, +const char *url) +{ +const bool dochanged = true; +const bool donotifier = true; +const void *context = url; -__connman_notifier_proxy_changed (service); +DBG ("service %p (%s) url %p (%s)" , + service, +connman_service_get_identifier (service), + url, + url ? url :"<null>" ); + +service_set_pac (service, url, !dochanged); + +service_set_proxy_method (service, +CONNMAN_SERVICE_PROXY_METHOD_AUTO , + donotifier, + service_set_proxy_method_auto_handler, + context); }const char *connman_service_get_proxy_autoconfig (struct connman_service *service)
Signature · 1 line
2.45.0
PATCH 10/15 service: Document 'service_set_proxy_method'.
In reply to Grant EricksonAdd documentation to the 'service_set_proxy_method' function.
--- src/service.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
src/service.c +35 -0
@@ -5568,6 +5568,41 @@ const char * const *connman_service_get_timeservers(const struct connman_servicereturn (const char *const *)service->timeservers; } +/** +* @brief +* Set the proxy method for the specified service. +* +* This attempts to set the proxy method for the specified +* service. If the service is null or if the service is hidden, no +* action is taken. If specified, a handler will be invoked, with the +* specified context, after setting the proxy method. +* +* If the handler is specified and it returns true, following, a +* D-Bus change notification should be sent for the service "Proxy" +* property and, if requested by @a donotifier, the proxy changed +* notifier chain will be run. +* +* @param[in,out] service A pointer to the mutable network +* service for which to set the proxy +* method. +* @param[in] method The network service proxy method to set +* on @a service. +* @param[in] donotifier A Boolean indicating whether the proxy +* changed notifier chain should be run +* after @a method is set on @a service. +* @param[in] handler An optional pointer to a handler that, +* if specified, will be invoked after @a +* method is set on @a service. +* @param[in] context An optional pointer to immutable context +* that will be passed to @a handler, +* along with @a service and @a method. +* +* @sa __connman_notifier_proxy_changed +* @sa proxy_changed +* +* @private +* +*/ static void service_set_proxy_method(struct connman_service *service, enum connman_service_proxy_method method, bool donotifier,
Signature · 1 line
2.45.0
PATCH 11/15 service: Document 'service_set_proxy_method_auto_handler'.
In reply to Grant EricksonAdd documentation to the 'service_set_proxy_method_auto_handler' function.
--- src/service.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
src/service.c +30 -0
@@ -5697,6 +5697,36 @@ const char *connman_service_get_proxy_url(const struct connman_service *service)return service->pac; } +/** +* @brief +* A post-mutation handler for the service proxy method when the +* method is #CONNMAN_SERVICE_PROXY_METHOD_AUTO. +* +* @param[in,out] service A pointer to the mutable network +* service for which the proxy method was +* set. +* @param[in] method The network service proxy method @a +* service was set to. +* @param[in] context An pointer to immutable context +* that was passed, along with @a +* service, @a method, and this handler, +* to #service_set_proxy_method. For this +* handler, @a context is an optional +* null-terminated C string containing +* the service proxy auto-configuration +* (PAC) URL. +* +* @returns +* True if #service_set_proxy_method should continue with state +* change notifications and processing proxy notifier changes after +* the handler returns; otherwise, false. +* +* @sa __connman_ipconfig_set_proxy_autoconfig +* @sa service_set_proxy_method +* +* @private +* +*/ static bool service_set_proxy_method_auto_handler( struct connman_service *service, enum connman_service_proxy_method method,
Signature · 1 line
2.45.0
PATCH 12/15 service: Document '__connman_service_set_proxy_autoconfig'.
In reply to Grant EricksonAdd documentation to the '__connman_service_set_proxy_autoconfig' function.
--- src/service.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
src/service.c +17 -0
@@ -5748,6 +5748,23 @@ static bool service_set_proxy_method_auto_handler(return true; } +/** +* @brief +* Set the network service proxy method to # and proxy +* auto-configuation (PAC) URL. +* +* @param[in,out] service A pointer to the mutable network +* service for which to set the proxy +* method. +* @param[in] url An optional pointer to the immutable +* null-terminated C string containing the +* proxy auto-configuration (PAC) URL. +* +* @sa service_set_pac +* @sa service_set_proxy_method +* @sa service_set_proxy_method_auto_handler +* +*/ void __connman_service_set_proxy_autoconfig (struct connman_service *service,const char *url) {
Signature · 1 line
2.45.0
PATCH 13/15 wispr: Add 'wispr_log_proxy_failure' function.
In reply to Grant EricksonLogs the network service interface name, type, proxy auto-configuration (PAC) URL, online check URL, and proxy failure reason at the error level when a Wireless Internet Service Provider roaming (WISPr) online reachability check proxy failure occurs.
Frequently, a spurious, misconfigured, or otherwise incorrect PAC URL is the source of WISPr online reachability check failures. Because POSIX error codes are themselves limited (for example, there is no -EBADPROXY or -EPROXYLKUP codes) and their usage for WISPr failures is similarly limited (for example, -EINVAL), insight into the actual nature of an online reachability check failure is, by extension, limited. Consequently, log messages generated from this function provide crucial insight into triaging and resolving such failures.
--- src/wispr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
src/wispr.c +18 -0
@@ -1118,6 +1118,24 @@ static char *parse_proxy(const char *proxy)return proxy_server; } +static void wispr_log_proxy_failure ( +struct connman_wispr_portal_context const *wp_context, +const char *reason) +{ + g_autofree char *interface = NULL; + + interface =connman_service_get_interface (wp_context->service); + +connman_error ("%s with proxy auto-configuration (PAC) URL %s " +"for %s [ %s ] online check URL %s" , + reason, +connman_service_get_proxy_url (wp_context->service), + interface, +__connman_service_type2string ( +connman_service_get_type (wp_context->service)), + wp_context->status_url); +} +static void proxy_callback (const char *proxy,void *user_data) {struct connman_wispr_portal_context *wp_context = user_data;
Signature · 1 line
2.45.0
PATCH 14/15 wispr: Leverage 'wispr_log_proxy_failure'.
In reply to Grant EricksonLeverage 'wispr_log_proxy_failure' from 'proxy_callback' with the "No valid proxy" reason and from 'wispr_portal_detect' with the "Failed to lookup" reason on Wireless Internet Service Provider roaming (WISPr) online reachability check proxy failures.
--- src/wispr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
src/wispr.c +3 -1
@@ -1147,7 +1147,7 @@ static void proxy_callback(const char *proxy, void *user_data)return ;if (!proxy) { -DBG ("no valid proxy" ); +wispr_log_proxy_failure (wp_context,"No valid proxy" ); wp_context->cb(wp_context->service, wp_context->type,
@@ -1320,6 +1320,8 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context, proxy_callback, wp_context);if (wp_context->proxy_token ==0 ) { +wispr_log_proxy_failure (wp_context,"Failed to lookup" ); + err = -EINVAL ;wispr_portal_context_unref (wp_context); }
Signature · 1 line
2.45.0
PATCH 15/15 wispr: Document 'wispr_log_proxy_failure'.
In reply to Grant EricksonAdd documentation to the 'wispr_log_proxy_failure' function.
--- src/wispr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
src/wispr.c +20 -0
@@ -1118,6 +1118,26 @@ static char *parse_proxy(const char *proxy)return proxy_server; } +/** +* @brief +* Log a Wireless Internet Service Provider roaming (WISPr) proxy +* auto-configuration (PAC)-related online reachability check +* failure. +* +* @param[in] wp_context A pointer to the immutable WISPr/portal +* context for which to log the proxy +* auto-configuration (PAC)-related online +* reachability check failure. +* @param[in] reason A pointer to an immutable, null-terminated +* C string containing the reason for the +* proxy auto-configuration (PAC)-related +* online reachability check failure which +* will be included at the start of the log +* message. +* +* @private +* +*/ static void wispr_log_proxy_failure (struct connman_wispr_portal_context const *wp_context,const char *reason)
Signature · 1 line
2.45.0