From patchwork Tue Aug 20 08:37:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bilal Hatipoglu X-Patchwork-Id: 1149924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=airties.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZZ/eVWRB"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=airties.onmicrosoft.com header.i=@airties.onmicrosoft.com header.b="LEVSgciJ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46CPNq5F7mz9s3Z for ; Tue, 20 Aug 2019 18:39:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=xijyzYTU9U6xKqEL8A++sbH9h8nUT8ezGpOF2zs67a8=; b=ZZ/eVWRBsou9t1 Ni+qqyIhPWL00eCuXj9dpNIWlHmH8MWoMrVKtpH9bTERPfMSSSlq/qLwiESbqtWbrRhuZkYd3wz8y vqIm4wLHkTA63vianuBl9dkmKWHCQrGBppfofOZUdn+F5XDUq5H+vp29dvm9vHWBWz8T+U2ilPBUA oAjiha61WHnTh0H9vfBdUKv4SRT+tZzflaWWWj6qcosQ3Xyw7d+tYnyX8bONwRkopWsrXPkagplvq 6eEbRUD+8uZuUwQbHqykmnXcTWzfkwXOJLY7W4iZoeiMaIkk47H/DtXUI2WcbaKXugDkmujOjKQEf Ipu5m6R0k4owKSu3EFVA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hzzfw-0003Da-Ni; Tue, 20 Aug 2019 08:39:32 +0000 Received: from cluster-b.mailcontrol.com ([85.115.56.190]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hzze6-0001On-FU for hostap@lists.infradead.org; Tue, 20 Aug 2019 08:37:42 +0000 Received: from airtiesesg.westeurope.cloudapp.azure.com (esg.airties.com [13.94.148.158]) by rly37b.srv.mailcontrol.com (MailControl) with ESMTPS id x7K8bCAI028031 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Aug 2019 09:37:12 +0100 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (unknown [104.47.5.57]) by Forcepoint Email with ESMTPS id C5FEA9D5223E4 for ; Tue, 20 Aug 2019 11:06:22 +0300 (AST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K/3J77sCgtqIWHAngMqSgNzWre4PrElpV5JIkipGJ+koUjOfWjDLOPSS6DzeuS1QWD64PBIokAsx1UQjsdcc0hJwUriTSAhtW38kq8gFDSiefnFh026cTfbvNLKHa7rkoxus8/4t5JbrRgjHXz2yQ0XLcI4/W2QDUnmsKeZiqrX7myhBLj8DVbZ6kAvOXk9PYck4/x/D4OhuGwNqc8V0wqcPu2i1SogM8QPf7zYWiMkOiaZ/5k2oXiSpCC2AW1od/rFVLBuEU0Gx+Wbz7qiZSL3ASbiXjAkFBWwFjTbHs5lh979N4CjzElUZNu85Yqv8Sz7yQjpWp4LQT6DZTBNxKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Onls/u2Nha5Okn0s6oeUaSNSv1znYmUvTz0TL/v6ejY=; b=WLL5LcMooriJ7PIPt7qIEQ2oRog57vWDkZNhVhGianII0p4itZC1B5fYxs0rutFgml4QJlT/z74H7M5T3QUC34hTUHmR/q3pkYNZQj9ikEHMYxYMd139+L468zcR/tHfxTsss6qqgdmQ5R2tA70kSD4HeLKr4JQUBR5EOy1UlIOfe7s4gk9DBkt8dL2thOIMpB2sLqoneeNuQtx+r78fvfREn7J7yDEIiSD7+mdLSjEjUEn5E6V075XzMLEawD5B1h+r1bvBIWZImj/wvN6Fng+W3pct9OeEUpsBfa1ZWLSiH9n505RECKaopu7jVp+M20NLFpE8P3D6BXPH0rjaGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=airties.com; dmarc=pass action=none header.from=airties.com; dkim=pass header.d=airties.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=airties.onmicrosoft.com; s=selector2-airties-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Onls/u2Nha5Okn0s6oeUaSNSv1znYmUvTz0TL/v6ejY=; b=LEVSgciJHcWmgZ2wFLDOs5wfNLZMrFDpEbAQlN1jZMz/G7isKjrd5hu/rExYNbKwAx2GlAFX6TuunbzzPT/qASW27GmnJwxyHL0WuSFTqeScbM/+BfVlgS6VrmyN891voUzzW2MmT6uHzHjzyN+gA07VAOC2ZDmoizjBzoa/wmU= Received: from VI1PR10MB2317.EURPRD10.PROD.OUTLOOK.COM (20.177.62.81) by VI1PR10MB3631.EURPRD10.PROD.OUTLOOK.COM (10.186.162.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.16; Tue, 20 Aug 2019 08:37:10 +0000 Received: from VI1PR10MB2317.EURPRD10.PROD.OUTLOOK.COM ([fe80::f4bd:415c:9bdd:caa7]) by VI1PR10MB2317.EURPRD10.PROD.OUTLOOK.COM ([fe80::f4bd:415c:9bdd:caa7%5]) with mapi id 15.20.2178.018; Tue, 20 Aug 2019 08:37:10 +0000 From: Bilal Hatipoglu To: "hostap@lists.infradead.org" Subject: [PATCH] Add "reconnect" cmdline argument to hostapd_cli/wpa_cli Thread-Topic: [PATCH] Add "reconnect" cmdline argument to hostapd_cli/wpa_cli Thread-Index: AQHVVzJ1QkQMBHLUGUaum3w4IC2YrQ== Date: Tue, 20 Aug 2019 08:37:10 +0000 Message-ID: <1566290223-26218-1-git-send-email-bilal.hatipoglu@airties.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: LO2P265CA0383.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a3::35) To VI1PR10MB2317.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:89::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=bilal.hatipoglu@airties.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [91.220.65.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 17507a27-25e4-4b2d-39d3-08d72549976f x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(7021145)(8989299)(5600148)(711020)(4605104)(1401327)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(2017052603328)(7193020); SRVR:VI1PR10MB3631; x-ms-traffictypediagnostic: VI1PR10MB3631: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:154; x-forefront-prvs: 013568035E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(396003)(39850400004)(346002)(136003)(366004)(199004)(189003)(99286004)(53936002)(64756008)(66446008)(66556008)(66476007)(66946007)(6116002)(2351001)(6916009)(25786009)(52116002)(3846002)(81166006)(71200400001)(50226002)(476003)(71190400001)(66066001)(44832011)(2906002)(8936002)(316002)(486006)(6486002)(6512007)(36756003)(5640700003)(26005)(14454004)(102836004)(1730700003)(386003)(6506007)(2616005)(8676002)(81156014)(305945005)(5024004)(14444005)(7736002)(2501003)(86362001)(186003)(5660300002)(256004)(508600001)(6436002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR10MB3631; H:VI1PR10MB2317.EURPRD10.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: airties.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: o5YCkyKpSMGvLo+Tw0jTScxhvK/E56NFYoWJcESfAiFmJQGbgRPBaqNqBmKuHix8Hee4XFGzDuWGxXVNaVOZDwbmHV6Mte8zIsJdipRt+lpE/dYLBl+dj6Gb4yYoi/kkr5Q+kJsiOFxeEDmbp4+RztfzvdP0XSrq8o/VsFf68lWXuWEoz2TKNA/ta0Cru2tJXkgTtuDhJIyrkFRYr+mppJETeRozNhuH3AQAaHXUltX3aXLxf76dq54m+BhxhSM0rEmmK7HDK9WewExAy+AC3Qu2XOJjqsSHGH+6rtRZjgv+sP3ppv7X/Rh/aIbdx889+UkzaSXYCt1lZH8UBLLuVPrMVLhCf88LUkw7nwaGbQYkOOcM12f34Ksq3aICAwwZd7QJ0r/T29066/jAUZG1fhw5ndbr1FUwFi4CmAbKTHk= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: airties.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17507a27-25e4-4b2d-39d3-08d72549976f X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Aug 2019 08:37:10.2122 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 316fd558-a5a6-42fd-9da7-d0f38e0864f6 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: k3jK5eYVCDsw2NyI+zg2BNtJXzyydFDgzzY6zoz980P1U8EOnTrG1ZryjbQ0Num5NLaQ0nPsqa5Bbb/o7U7LYb15QGeVS/UbbTLR7ucSQTY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB3631 X-MailControl-OutInfo: MTU2NjI5MDIzMjpGUEtleTEucHJpdjodfIOtOxdQ2ZM6D7fhqxuFAfCMINm9upj0wafGUEm6ItF8T40QKHz7ZXGvEwJq8NqZzV1gI+jJLIVe4Xpk3ftD3JGfLkGu01IIabNi0xhun4Tra4BEtFX0wn4I7/PnceYwiASoo6Aep5VnDQqaaJ0/2obEi/48OZi/FJFFyZGAOiCAuonGl1SPpJ1NS3SLNkLPNc4aPUPnOi8k012et3lNG39+I0Us7GPXkxP8sgn/HBqzcaoI6ETg4qe1QV2tR8gGL/jOCb0DEo3KhfRNC5TNR4mVKVOVNyJ/C055ak17WakaSlPmRWloEmV2CAlPhv7+hPto/mMIXCfY3hoUcaKN X-Scanned-By: MailControl 44278.2072 (www.mailcontrol.com) on 10.66.0.147 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190820_013739_250390_3B1E09EB X-CRM114-Status: GOOD ( 14.46 ) X-Spam-Score: -0.5 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [85.115.56.190 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Bilal Hatipoglu When newly added "-r" parameter is used, both clis will try to reconnect forever on connection lost until signalled (ctrl+c) or terminated. This is useful for using a single instance cli to retrieve events & get status and the cli process stays even if hostapd/wpa_supplicant daemons restart for some reason (e.g. configuration change). Signed-off-by: Veli Demirel Signed-off-by: Veli Demirel --- hostapd/hostapd_cli.c | 20 +++++++++++++++----- wpa_supplicant/wpa_cli.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 0460243..07b6ed0 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -2011,12 +2011,13 @@ int main(int argc, char *argv[]) int warning_displayed = 0; int c; int daemonize = 0; + int reconnect = 0; if (os_program_init()) return -1; for (;;) { - c = getopt(argc, argv, "a:BhG:i:p:P:s:v"); + c = getopt(argc, argv, "a:BhG:i:p:P:s:vr"); if (c < 0) break; switch (c) { @@ -2048,6 +2049,9 @@ int main(int argc, char *argv[]) case 's': client_socket_dir = optarg; break; + case 'r': + reconnect = 1; + break; default: usage(); return -1; @@ -2087,8 +2091,7 @@ int main(int argc, char *argv[]) printf("Connection established.\n"); break; } - - if (!interactive) { + if (!interactive && !reconnect) { perror("Failed to connect to hostapd - " "wpa_ctrl_open"); return -1; @@ -2106,8 +2109,15 @@ int main(int argc, char *argv[]) return -1; if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue()) return -1; - - if (interactive) + if (reconnect && action_file && ctrl_ifname != NULL) { + do { + if (ctrl_conn) { + hostapd_cli_action(ctrl_conn); + } + os_sleep(1, 0); + hostapd_cli_reconnect(ctrl_ifname); + } while(!hostapd_cli_quit); + } else if (interactive) hostapd_cli_interactive(); else if (action_file) hostapd_cli_action(ctrl_conn); diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 43ac427..1c7d885 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -52,6 +52,7 @@ static char *ctrl_ifname = NULL; static const char *global = NULL; static const char *pid_file = NULL; static const char *action_file = NULL; +static int reconnect = 0; static int ping_interval = 5; static int interactive = 0; static char *ifname_prefix = NULL; @@ -4039,7 +4040,9 @@ static void wpa_cli_action_process(const char *msg) wpa_cli_exec(action_file, ifname, pos); } else if (str_starts(pos, WPA_EVENT_TERMINATING)) { printf("wpa_supplicant is terminating - stop monitoring\n"); - wpa_cli_quit = 1; + if (!reconnect) { + wpa_cli_quit = 1; + } } } @@ -4231,6 +4234,10 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int action_monitor) if (wpa_ctrl_pending(ctrl) < 0) { printf("Connection to wpa_supplicant lost - trying to " "reconnect\n"); + if (reconnect) { + eloop_terminate(); + return; + } wpa_cli_reconnect(); } } @@ -4578,6 +4585,9 @@ static void wpa_cli_cleanup(void) static void wpa_cli_terminate(int sig, void *ctx) { eloop_terminate(); + if (reconnect) { + wpa_cli_quit = 1; + } } @@ -4655,7 +4665,7 @@ int main(int argc, char *argv[]) return -1; for (;;) { - c = getopt(argc, argv, "a:Bg:G:hi:p:P:s:v"); + c = getopt(argc, argv, "a:Bg:G:hi:p:P:s:vr"); if (c < 0) break; switch (c) { @@ -4690,6 +4700,9 @@ int main(int argc, char *argv[]) case 's': client_socket_dir = optarg; break; + case 'r': + reconnect = 1; + break; default: usage(); return -1; @@ -4712,7 +4725,23 @@ int main(int argc, char *argv[]) if (ctrl_ifname == NULL) ctrl_ifname = wpa_cli_get_default_ifname(); - if (interactive) { + if (reconnect && action_file && ctrl_ifname) { + do { + if (ctrl_conn) { + wpa_cli_action(ctrl_conn); + } else + os_sleep(1, 0); + wpa_cli_close_connection(); + wpa_cli_open_connection(ctrl_ifname, 0); + if (ctrl_conn) { + if (wpa_ctrl_attach(ctrl_conn) != 0) { + wpa_cli_close_connection(); + } else { + wpa_cli_attached = 1; + } + } + } while (!wpa_cli_quit); + } else if (interactive) { wpa_cli_interactive(); } else { if (!global &&