[PATCH 5/9] pptp: Do not clear credentials on connection error

Jussi Laakkonen <[email protected]> Mon, 26 Jan 2026 15:43:44 +0200
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
Utilize the authentication and connection errors to detect which error
should be reported back on the pppd error code 16 (modem hangup).
Connection errors will be reset when connection succeeds, or the service
is saved. If there is at least one authentication error code 16 means
the credentials need to be cleared.
---
 vpn/plugins/pptp.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/vpn/plugins/pptp.c b/vpn/plugins/pptp.c
index 2ae4e0f3..2e91300a 100644
--- a/vpn/plugins/pptp.c
+++ b/vpn/plugins/pptp.c
@@ -660,14 +660,29 @@ error:
 
 static int pptp_error_code(struct vpn_provider *provider, int exit_code)
 {
-	DBG("exit code %d", exit_code);
-
+	unsigned int conn_errors = vpn_provider_get_connection_errors(
+								provider);
+	unsigned int auth_errors = vpn_provider_get_authentication_errors(
+								provider);
+
+	DBG("exit code %d connection errors %d auth errors %d", exit_code,
+						conn_errors, auth_errors);
+
+	/* With PPTP the exit code comes from pppd */
 	switch (exit_code) {
 	case 1:
 		return CONNMAN_PROVIDER_ERROR_CONNECT_FAILED;
 	case 2:
 		return CONNMAN_PROVIDER_ERROR_LOGIN_FAILED;
-	case 16:
+	case 16: // The link was terminated by the modem hanging up.
+		/*
+		 * These values are reset when connection is success or the
+		 * provider is saved. If there are connection errors do not
+		 * reset the credentials.
+		 */
+		if (conn_errors && !auth_errors)
+			return CONNMAN_PROVIDER_ERROR_CONNECT_FAILED;
+
 		return CONNMAN_PROVIDER_ERROR_AUTH_FAILED;
 	default:
 		return CONNMAN_PROVIDER_ERROR_UNKNOWN;
-- 
2.47.3