From: Daniel Wagner <wagi@monom.org>
To: connman@lists.linux.dev
Cc: Daniel Wagner <wagi@monom.org>
Subject: [PATCH] wisrp: Handle wispr_portal_detect failures
Date: Sun, 28 Aug 2022 15:53:22 +0200 [thread overview]
Message-ID: <20220828135322.21582-1-wagi@monom.org> (raw)
__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.
---
src/wispr.c | 56 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 32 insertions(+), 24 deletions(-)
diff --git a/src/wispr.c b/src/wispr.c
index 84bed33f217d..9b27af5fff55 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)
--
2.37.2
next reply other threads:[~2022-08-28 13:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-28 13:53 Daniel Wagner [this message]
2022-08-28 18:31 ` [PATCH] wisrp: Handle wispr_portal_detect failures Daniel Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220828135322.21582-1-wagi@monom.org \
--to=wagi@monom.org \
--cc=connman@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).