Skip to content

Commit

Permalink
[connman] Service autoconnect: use service type and reason. Contribut…
Browse files Browse the repository at this point in the history
…es to JB#42337

Run auto connect for both transport services and VPN services if the
changed service is not a VPN service and reason is specified. If the
changed service is VPN run only VPN auto connect, which is triggered by,
for example, disconnection of a VPN that does not require service auto
connection to be run.

If the do_auto_connect() is run with VPN service without reason (the
reason is CONNMAN_SERVICE_CONNECT_REASON_NONE), ignore it.
  • Loading branch information
LaakkonenJussi committed Aug 21, 2018
1 parent ce51fc2 commit ecf3ce0
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions connman/src/service.c
Expand Up @@ -4493,16 +4493,26 @@ static int update_proxy_configuration(struct connman_service *service,
return -EINVAL;
}

static void do_auto_connect(struct connman_service *service)
static void do_auto_connect(struct connman_service *service,
enum connman_service_connect_reason reason)
{
if (!service)
/*
* CONNMAN_SERVICE_CONNECT_REASON_NONE must be ignored for VPNs. VPNs
* always have reason CONNMAN_SERVICE_CONNECT_REASON_USER/AUTO.
*/
if (!service || (service->type == CONNMAN_SERVICE_TYPE_VPN &&
reason == CONNMAN_SERVICE_CONNECT_REASON_NONE))
return;

if (service->type == CONNMAN_SERVICE_TYPE_VPN)
vpn_auto_connect();
else
__connman_service_auto_connect(
CONNMAN_SERVICE_CONNECT_REASON_AUTO);
/*
* Run service auto connect when a service is changed. This is not
* needed to be run when VPN service changes, then vpn auto connect is
* sufficient.
*/
if (service->type != CONNMAN_SERVICE_TYPE_VPN)
__connman_service_auto_connect(reason);

vpn_auto_connect();
}

int __connman_service_reset_ipconfig(struct connman_service *service,
Expand Down Expand Up @@ -4570,7 +4580,7 @@ int __connman_service_reset_ipconfig(struct connman_service *service,

settings_changed(service, new_ipconfig);

do_auto_connect(service);
do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
}

DBG("err %d ipconfig %p type %d method %d state %s", err,
Expand Down Expand Up @@ -4638,7 +4648,8 @@ static DBusMessage *set_property(DBusConnection *conn,
if (service_set_autoconnect(service, autoconnect)) {
service_save(service);
if (autoconnect)
do_auto_connect(service);
do_auto_connect(service,
CONNMAN_SERVICE_CONNECT_REASON_AUTO);
}

/* Disable autoconnect for all other VPN providers
Expand Down Expand Up @@ -5024,7 +5035,7 @@ static void service_complete(struct connman_service *service)
reply_pending(service, EIO);

if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
do_auto_connect(service);
do_auto_connect(service, service->connect_reason);

g_get_current_time(&service->modified);
service_save(service);
Expand Down Expand Up @@ -5598,7 +5609,7 @@ static gboolean service_retry_connect(gpointer data)
state_changed(service);

/* Schedule the next auto-connect round */
do_auto_connect(service);
do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
}

return FALSE;
Expand Down Expand Up @@ -5640,7 +5651,7 @@ static gboolean connect_timeout(gpointer user_data)
if (autoconnect &&
service->connect_reason !=
CONNMAN_SERVICE_CONNECT_REASON_USER)
do_auto_connect(service);
do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);

return FALSE;
}
Expand Down Expand Up @@ -7300,7 +7311,7 @@ static int service_indicate_state(struct connman_service *service)
*/
downgrade_connected_services();

do_auto_connect(service);
do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
break;

case CONNMAN_SERVICE_STATE_FAILURE:
Expand Down Expand Up @@ -8338,7 +8349,7 @@ const char *__connman_service_create(enum connman_service_type type,
if (service->autoconnect) {
service->favorite = true;

do_auto_connect(service);
do_auto_connect(service, CONNMAN_SERVICE_CONNECT_REASON_AUTO);
}

/* Save the service */
Expand Down Expand Up @@ -8949,7 +8960,8 @@ bool __connman_service_create_from_network(struct connman_network *network)
__connman_connection_update_gateway();

if (service->autoconnect)
do_auto_connect(service);
do_auto_connect(service,
CONNMAN_SERVICE_CONNECT_REASON_AUTO);

return true;
}
Expand Down

0 comments on commit ecf3ce0

Please sign in to comment.