summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Wagner <wagi@monom.org>2022-08-28 15:53:22 +0200
committerDaniel Wagner <wagi@monom.org>2022-08-28 20:30:36 +0200
commit3e96694507cfc5f8af756834e0b7d7c45fd3e6c3 (patch)
treed95c97ced61cf4b137c42a18fb41814d1da86066
parent33389f7edcab6d4acb1f30f51a6d838fe49ac022 (diff)
downloadconnman-3e96694507cfc5f8af756834e0b7d7c45fd3e6c3.tar.gz
wisrp: Handle wispr_portal_detect failures
__connman_wispr_start() should handle any errors reported by wispr_portal_detect. While at it also return early if the service type is not supported.
-rw-r--r--src/wispr.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/wispr.c b/src/wispr.c
index 84bed33f..9b27af5f 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -916,7 +916,6 @@ static gboolean no_proxy_callback(gpointer user_data)
static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
{
enum connman_service_proxy_method proxy_method;
- enum connman_service_type service_type;
char *interface = NULL;
char **nameservers = NULL;
int if_index;
@@ -926,23 +925,6 @@ static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
DBG("wispr/portal context %p service %p", wp_context,
wp_context->service);
- service_type = connman_service_get_type(wp_context->service);
-
- switch (service_type) {
- case CONNMAN_SERVICE_TYPE_ETHERNET:
- case CONNMAN_SERVICE_TYPE_WIFI:
- case CONNMAN_SERVICE_TYPE_BLUETOOTH:
- case CONNMAN_SERVICE_TYPE_CELLULAR:
- case CONNMAN_SERVICE_TYPE_GADGET:
- break;
- case CONNMAN_SERVICE_TYPE_UNKNOWN:
- case CONNMAN_SERVICE_TYPE_SYSTEM:
- case CONNMAN_SERVICE_TYPE_GPS:
- case CONNMAN_SERVICE_TYPE_VPN:
- case CONNMAN_SERVICE_TYPE_P2P:
- return -EOPNOTSUPP;
- }
-
interface = connman_service_get_interface(wp_context->service);
if (!interface)
return -EINVAL;
@@ -1012,13 +994,28 @@ int __connman_wispr_start(struct connman_service *service,
{
struct connman_wispr_portal_context *wp_context = NULL;
struct connman_wispr_portal *wispr_portal = NULL;
- int index;
+ int index, err;
DBG("service %p", service);
if (!wispr_portal_hash)
return -EINVAL;
+ switch (connman_service_get_type(service)) {
+ case CONNMAN_SERVICE_TYPE_ETHERNET:
+ case CONNMAN_SERVICE_TYPE_WIFI:
+ case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+ case CONNMAN_SERVICE_TYPE_CELLULAR:
+ case CONNMAN_SERVICE_TYPE_GADGET:
+ break;
+ case CONNMAN_SERVICE_TYPE_UNKNOWN:
+ case CONNMAN_SERVICE_TYPE_SYSTEM:
+ case CONNMAN_SERVICE_TYPE_GPS:
+ case CONNMAN_SERVICE_TYPE_VPN:
+ case CONNMAN_SERVICE_TYPE_P2P:
+ return -EOPNOTSUPP;
+ }
+
index = __connman_service_get_index(service);
if (index < 0)
return -EINVAL;
@@ -1038,16 +1035,20 @@ int __connman_wispr_start(struct connman_service *service,
wp_context = wispr_portal->ipv4_context;
else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
wp_context = wispr_portal->ipv6_context;
- else
- return -EINVAL;
+ else {
+ err = -EINVAL;
+ goto free_wp;
+ }
/* If there is already an existing context, we wipe it */
if (wp_context)
wispr_portal_context_unref(wp_context);
wp_context = create_wispr_portal_context();
- if (!wp_context)
- return -ENOMEM;
+ if (!wp_context) {
+ err = -ENOMEM;
+ goto free_wp;
+ }
wp_context->service = service;
wp_context->type = type;
@@ -1058,7 +1059,14 @@ int __connman_wispr_start(struct connman_service *service,
else
wispr_portal->ipv6_context = wp_context;
- return wispr_portal_detect(wp_context);
+ err = wispr_portal_detect(wp_context);
+ if (err)
+ goto free_wp;
+ return 0;
+
+free_wp:
+ g_hash_table_remove(wispr_portal_hash, GINT_TO_POINTER(index));
+ return err;
}
void __connman_wispr_stop(struct connman_service *service)