From patchwork Tue Sep 3 14:19:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bilal Hatipoglu X-Patchwork-Id: 1157036 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="rczrGLJV"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=airties.onmicrosoft.com header.i=@airties.onmicrosoft.com header.b="KgKzlFTm"; 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 46N8HC0ytVz9s7T for ; Wed, 4 Sep 2019 00:20:07 +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=VUM7kkhdxc12Kxcuk1uBx+Rq+jXTFTSgAssLs6L/Y5A=; b=rczrGLJVtbEyEK HZZBx3BmBg7oR+kJmgTc6doOrbUB8mAC4VgL2dLJzBesTybikOsr6JK3gDy500/yd4vIrPnowLOJB ZNgMtGKGRHmqHBOhUTJA9t4/n0LYREeQmF4CfC6UaZcj9bAN6VNTMfhLN/SydAKubEZu4yHaX+Fjb 5qrxSOaoDFNh5vFkPAo+WQuAIKh6gGd/uB7wiQZT8AUYAMZuPUKhjGikgaJ14tZ9HOMBUQ87zvJQ5 vgSBjB6Pzmrsb0KCrUOXs719ao5lnbO6PV0hCrV90uf5O9k/Ec2XVo/aUERpBN3x04e1gHqf6W7c5 qS83dsMC9hBpt6fE0YJA==; 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 1i59f8-0001Yp-Rq; Tue, 03 Sep 2019 14:20:02 +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 1i59ez-0001Nh-BG for hostap@lists.infradead.org; Tue, 03 Sep 2019 14:19:56 +0000 Received: from airtiesesg.westeurope.cloudapp.azure.com (esg.airties.com [13.94.148.158]) by rly03b.srv.mailcontrol.com (MailControl) with ESMTPS id x83EJgan100541 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 3 Sep 2019 15:19:42 +0100 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (unknown [104.47.12.59]) by Forcepoint Email with ESMTPS id B5874C53291AC for ; Tue, 3 Sep 2019 16:48:08 +0300 (AST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jCEqcDKWLzUhhAEdiblCXajPmKhgCHH9IXgUVgvAO3SiCkS5OMleHPx2DzSeN1L4eUY6/8J2JkYy2UukzBm5lUSVSVm1LJ+7Al48sWHzBmijqmPk2YxQKZDg3UpjuEcrXdumCa8obvrgVIbvTGfm0jeoYemRMLzyUi94Dhs0TqWvB1UXptm8Cy5hgVGN3CraaR4MuH7zKzKfR1+1IcixICkkJG2PbhvwNAvWnmPG9918G5NIqcMQTVI8fT9I6sORRE+4mtRR/7Z0Bw2M7+AphBW/GnZPaUdJvJx6/pDW+/0iahG6INhOqjun3IqTCw9TzlbiJ83WzGXcVLoeljKoCg== 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=7IfkrSqbJAca8xOSsWAeuAcsrGoQd21KNCIhLr6oI34=; b=Ebt2GJV31x0SvXkSBD4h1FX6TOQ47yiVPylZY4Ps/P+Ok75QQJfh9YBPFxMIuB/f77w2pPaSmye5JgoCX4Kt2pRL52h+ptS7zxAEztFEpDHuQLj6QyFybpx+PhLjned/8VKscbDCl4nCeWNOUftcXMI2N9fmnUplR6FIb9qdLZBykdyQgmmzu4RPBqmfu+LwUlthOSfD2gSJkIQIc7y8C2Ga8g11kgJxDQNrWrMFrS4AKI6yRSaLtUQIbDisTXJvWEydz2EJRta8HipJ37DyVvz8ishwDNmlSNKCEoQx+2amNaOCY2/ozLUm+Wuvd+fsKqyVnljIBKSvR2zJXILxhw== 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=7IfkrSqbJAca8xOSsWAeuAcsrGoQd21KNCIhLr6oI34=; b=KgKzlFTmSxlgJ62Drm7g/5yVm+70aNVSwz649lPsyPJBqSvrjLlfzyQUeZsjx9Vw/DtwpcgfEoGXRILlFfPO14RUPGaRyPA3fZEvD9wtvNGKppPKVCRTEXCzNK1BpZmczECt1GHm9X1oZ7uTJAJs0CYcIk5b5qrOm3QrGrhu+fk= Received: from AM6PR10MB2310.EURPRD10.PROD.OUTLOOK.COM (20.177.113.75) by AM6PR10MB2741.EURPRD10.PROD.OUTLOOK.COM (20.179.0.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2220.19; Tue, 3 Sep 2019 14:19:40 +0000 Received: from AM6PR10MB2310.EURPRD10.PROD.OUTLOOK.COM ([fe80::1cb:7112:7cf9:539d]) by AM6PR10MB2310.EURPRD10.PROD.OUTLOOK.COM ([fe80::1cb:7112:7cf9:539d%6]) with mapi id 15.20.2220.021; Tue, 3 Sep 2019 14:19:40 +0000 From: Bilal Hatipoglu To: "hostap@lists.infradead.org" Subject: [PATCH v2] Add "reconnect" cmdline argument to hostapd_cli/wpa_cli Thread-Topic: [PATCH v2] Add "reconnect" cmdline argument to hostapd_cli/wpa_cli Thread-Index: AQHVYmKfUMFBiXQv1UqPNOnS+2iSNw== Date: Tue, 3 Sep 2019 14:19:39 +0000 Message-ID: <1567520371-24875-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: PR0P264CA0117.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:19::33) To AM6PR10MB2310.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:45::11) 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: a69db978-249c-4db1-1cf9-08d73079c1d2 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:AM6PR10MB2741; x-ms-traffictypediagnostic: AM6PR10MB2741: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:247; x-forefront-prvs: 01494FA7F7 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(136003)(376002)(366004)(396003)(346002)(39850400004)(199004)(189003)(2351001)(2616005)(486006)(6436002)(44832011)(8676002)(53936002)(102836004)(478600001)(36756003)(81166006)(81156014)(476003)(1730700003)(71190400001)(71200400001)(14454004)(25786009)(2501003)(6512007)(86362001)(386003)(66556008)(64756008)(66946007)(66066001)(186003)(26005)(50226002)(6486002)(66446008)(7736002)(5640700003)(6306002)(5024004)(3846002)(6506007)(99286004)(52116002)(8936002)(2906002)(6916009)(316002)(14444005)(305945005)(5660300002)(6116002)(256004)(66476007); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR10MB2741; H:AM6PR10MB2310.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: zqXDreRWPy2yP4Lv3SINi9Bri8Xe6uTfvZaWHktK2l1YCC/mQxPCWNt3LMH71tF4LpOqfuA/6pa5nzg7obsTRorMbHZnfrKNzprHxSHyVPaeKmvc/AdssnXnZfyE8/0qi5OR4bDWgVnyvxYHzIzUqn0vnslNTYoDH2IH20900Vsinnhig3GnTxnRjaP1nECGWfJPgTHtKHzuEPOpPieqCdSZ47Nwcs/0MbSNKE+H3ZdMYmu8dm8tMr5Yo8GMJk/HW7uqtQFU4yp9To8IQfCxFdsUgpxhLq+GVjeyTSvE76D/BUwGt9bPzpSWbUrAOLzPs0a4WUaa9+KXMo5gq/EYqNrHQ7bRo8yEFdAO0ctO9dx0Th4bNjy4VwnkaGh8UCZxg3cBPTXp7mGamPbcXUpzCoNSzvcUkPZwU/n6UL+GI/U= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: airties.com X-MS-Exchange-CrossTenant-Network-Message-Id: a69db978-249c-4db1-1cf9-08d73079c1d2 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Sep 2019 14:19:40.0581 (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: I/QXZHhlTrTwN3Fx45U4ynNfP09xZvXtFAUE+201VenN3nyETMCceCwfAdvERH7JOzvRpBSxOWEpzlc4wBjdefE7C02n4kExWHKrrndqoZU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR10MB2741 X-MailControl-OutInfo: MTU2NzUyMDM4NDpGUEtleTEucHJpdjrTRk49xIgVjt4vCm3NBcmyBIA0JMlWUoyH8y1pLktsLfppyTbXV1t42ubExVGwfAL4iHl2yzMttZYQxvcNc79CeESEg29M83dSQdH5ubpQHxg7zsorDnAMZ/imR4inxjEPxKDAIFNwwWzFGhOTwmZPsw+tpjt+fIltaz7La+N1mP+FL5mn61g3VrpGm5oANzNY1fIgvSwV2E6lthwjsGLXhvtErzbLOgme6hv8vyLkBuNDvha7CDB9iiT4seFh1mQrbVdEpX08JoPLWaDwmlOvLbH5Xznz7LnxGpG3frRT3VcwRaz6kN5JoEHI8l+GaiIodUnW9dgyfgHO/roRz9F4 X-Scanned-By: MailControl 44278.2072 (www.mailcontrol.com) on 10.66.0.113 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190903_071953_683741_FE24AD0B X-CRM114-Status: GOOD ( 13.27 ) 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 only when used with -a to take action to retrieve events or 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 --- hostapd/hostapd_cli.c | 25 +++++++++++++++++++------ wpa_supplicant/wpa_cli.c | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 10 deletions(-) -- 2.7.4 [http://www.airties.com.tr/images/internal/IMZA_ALT_BANNER.jpg] This message has been scanned for malware by Websense. www.websense.com diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 0460243..83ce6f1 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -54,7 +54,7 @@ static void usage(void) fprintf(stderr, "%s\n", hostapd_cli_version); fprintf(stderr, "\n" -"usage: hostapd_cli [-p] [-i] [-hvB] " +"usage: hostapd_cli [-p] [-i] [-hvBr] " "[-a] \\\n" " [-P] [-G] [command..]\n" "\n" @@ -68,6 +68,9 @@ static void usage(void) " -a run in daemon mode executing the action file " "based on events\n" " from hostapd\n" +" -r try to reconnect when client socket is " +"disconnected.\n" +" this is useful only when used with -a\n" " -B run a daemon in the background\n" " -i Interface to listen on (default: first " "interface found in the\n" @@ -2011,12 +2014,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 +2052,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 +2094,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 +2112,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..7e1e59b 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; @@ -80,7 +81,7 @@ static void update_ifnames(struct wpa_ctrl *ctrl); static void usage(void) { -printf("wpa_cli [-p] [-i] [-hvB] " +printf("wpa_cli [-p] [-i] [-hvBr] " "[-a] \\\n" " [-P] [-g] [-G] " "\\\n" @@ -91,6 +92,8 @@ static void usage(void) " -a = run in daemon mode executing the action file based on " "events from\n" " wpa_supplicant\n" + " -r = try to reconnect when client socket is disconnected.\n" + " this is useful only when used with -a\n" " -B = run a daemon in the background\n" " default path: " CONFIG_CTRL_IFACE_DIR "\n" " default interface: first interface found in socket path\n"); @@ -4039,7 +4042,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 +4236,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 +4587,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 +4667,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 +4702,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 +4727,24 @@ 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 &&