From patchwork Mon Nov 7 19:25:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintao Lin X-Patchwork-Id: 1700826 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=fBDxQXVx; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=aJxpnqAZ; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N5jnZ60l0z23lW for ; Tue, 8 Nov 2022 07:41:38 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Qu51EYSX/fzVfwgWkCFp9rVZ2Txsi2+/jhK8xOTrywc=; b=fBDxQXVxE3SrqH CF16zhUke0SeH3FPQX1kEoLqset62Sk05t5QDIWr78t5cr0k3YVhllhFxgI28g+6ZUUGN4TXDTgCr 3nrt5b9dK/1IZGyA79qFoFde40JBAfN6HCWPoJOX3hWVGRxTHYwAWqSW/VIr7H3SzydTsZ1CUJ8c+ ESl1eC6ZRcknotjar1WOpVRW3XgXSRQSUdKDH/gGmZ0ZZqmxcPBTfewgj95tp9+xCcJ0Xk6yTHrjH 6fnhEtJQQbbc1tk1e0/AJYm8Pk5enGKv/+GphHSq5h0274u8+ijMR0AR1+V6RoHB80sTp3RmIPcyP ueKPB33CPEDXg5qMVKBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1os8v4-000LJA-QJ; Mon, 07 Nov 2022 20:40:34 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1os7ks-00Haq5-Dg for hostap@lists.infradead.org; Mon, 07 Nov 2022 19:26:00 +0000 Received: by mail-pg1-x52b.google.com with SMTP id b62so11353945pgc.0 for ; Mon, 07 Nov 2022 11:25:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=82mOqFSK6CH6xTr1rvW9dkx6lVQX/aRO7Q7ZZwYDz1o=; b=aJxpnqAZEIR1int5CC8RigXiMkNKKJJ4YtK2zj3cfNIsQPc3d1/Ug9HcdgQaTQoMlg yOTDZGCyxLpMoYe05nmcSQyxuk7yqwazucA2Ln3kmNDhlEmKv7bDy9pOGIDBSKt/ebD5 Oqea6wwteIeK0KPZP8mR/4nIldIcL00Xc55ww= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=82mOqFSK6CH6xTr1rvW9dkx6lVQX/aRO7Q7ZZwYDz1o=; b=bZnFCuGm1EYZMcJz7DjRQA8K//x6vz4zsfnYF9LF+LuvVBN5mjQgtPnr4nvx+iqVoA iTa/iRFgU5MeabOM4lCxBCDF0/PH2Fy4VwGqDZ3Wmg2T/paPeLhVg09e1KWXtN794Vjo c13EgfEdBhvzBjJtSJ2BPPe1KUXtLQVt/CA6b5NM4d/3QIC0wSqa3penJAlxQNQs/Jh6 jq7H/xGCTeuzd5Mm7jnHIKo10cUBgsII/QEF7HRAUn2eurpn+uh7Ht6w65pbZ/VmFsOb leTgXbrTp/m7nPKOSueAikOYb2ynVz7w8jtfEOEdHLxD9+prePW33ZiqiMpDbVWn/o8P cg5g== X-Gm-Message-State: ACrzQf0MlXNTCyuBygEz+DBkmESdKmWQqvdAS30PGQZuEVEH6lPYb23+ iq/bTrMUXUVByDtjhgH2J3ai7g== X-Google-Smtp-Source: AMsMyM6a1sgeVPobEfAPtRDJSCEYivb+XIWkjfZD/r/SMjLIcm7/NAskhXXuP7yYBKsdoKznmEUc8w== X-Received: by 2002:a63:f50e:0:b0:470:274b:53a2 with SMTP id w14-20020a63f50e000000b00470274b53a2mr19457222pgh.524.1667849153448; Mon, 07 Nov 2022 11:25:53 -0800 (PST) Received: from jintaolin.c.googlers.com.com (139.60.82.34.bc.googleusercontent.com. [34.82.60.139]) by smtp.gmail.com with ESMTPSA id x190-20020a6231c7000000b0056bbebbcafbsm4863373pfx.100.2022.11.07.11.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 11:25:53 -0800 (PST) From: Jintao Lin To: j@w1.fi Cc: hostap@lists.infradead.org, matthewmwang@chromium.org, Jintao Lin Subject: [PATCH v2] dbus: Add virtual interface create/remove logic to be inline with ctrl_iface Date: Mon, 7 Nov 2022 19:25:26 +0000 Message-Id: <20221107192526.496194-1-jintaolin@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221107_112558_513651_087B5112 X-CRM114-Status: GOOD ( 18.60 ) X-Spam-Score: -0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: There is no way to create or remove a virtual interface with wpa_supplicant dbus methods. The platform has to use out-of-band methods to manage the virtual interfaces. This change adds virtual interface create/remove logic to the dbus methods CreateInterface and RemoveInterface to achieve similar functionalities as wpa_cli commands interface_add and interface_remove [...] Content analysis details: (-0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:52b listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-Mailman-Approved-At: Mon, 07 Nov 2022 12:40:33 -0800 X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 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 There is no way to create or remove a virtual interface with wpa_supplicant dbus methods. The platform has to use out-of-band methods to manage the virtual interfaces. This change adds virtual interface create/remove logic to the dbus methods CreateInterface and RemoveInterface to achieve similar functionalities as wpa_cli commands interface_add and interface_remove. Signed-off-by: Jintao Lin --- doc/dbus.doxygen | 2 + wpa_supplicant/dbus/dbus_new_handlers.c | 54 ++++++++++++++++++++++++- wpa_supplicant/wpa_supplicant_i.h | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen index 075c2d5bf..a23817983 100644 --- a/doc/dbus.doxygen +++ b/doc/dbus.doxygen @@ -41,6 +41,8 @@ registered in the bus with fi.w1.wpa_supplicant1 name. BridgeIfnamesName of the bridge interface to control, e.g., br0No DriversDriver name which the interface uses, e.g., nl80211No ConfigFilesConfiguration file pathNo + CreatebWhether to create a new interface in the kernelNo + TypesInterface type to create (sta or ap)No diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index c1f147398..776956059 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -755,6 +755,8 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, char *ifname = NULL; char *confname = NULL; char *bridge_ifname = NULL; + bool create_iface = false; + enum wpa_driver_if_type if_type = WPA_IF_STATION; dbus_message_iter_init(message, &iter); @@ -791,6 +793,20 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, wpa_dbus_dict_entry_clear(&entry); if (bridge_ifname == NULL) goto oom; + } else if (os_strcmp(entry.key, "Create") == 0 && + entry.type == DBUS_TYPE_BOOLEAN) { + create_iface = entry.bool_value; + wpa_dbus_dict_entry_clear(&entry); + } else if (os_strcmp(entry.key, "Type") == 0 && + entry.type == DBUS_TYPE_STRING) { + if (os_strcmp(entry.str_value, "sta") == 0) { + if_type = WPA_IF_STATION; + } else if (os_strcmp(entry.str_value, "ap") == 0) { + if_type = WPA_IF_AP_BSS; + } else { + goto error; + } + wpa_dbus_dict_entry_clear(&entry); } else { wpa_dbus_dict_entry_clear(&entry); goto error; @@ -812,6 +828,20 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, struct wpa_supplicant *wpa_s; struct wpa_interface iface; + if (create_iface) { + u8 mac_addr[ETH_ALEN]; + + wpa_printf(MSG_DEBUG, "%s[dbus]: creating an interface '%s'", + __func__, ifname); + if (!global->ifaces || wpa_drv_if_add(global->ifaces, if_type, ifname, + NULL, NULL, NULL, mac_addr, NULL) < 0) { + reply = wpas_dbus_error_unknown_error( + message, + "interface creation failed."); + goto out; + } + } + os_memset(&iface, 0, sizeof(iface)); iface.driver = driver; iface.ifname = ifname; @@ -822,6 +852,8 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, if (wpa_s && wpa_s->dbus_new_path) { const char *path = wpa_s->dbus_new_path; + wpa_s->added_vif = create_iface; + wpa_s->added_vif_type = create_iface? if_type : WPA_IF_MAX; reply = dbus_message_new_method_return(message); dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); @@ -829,6 +861,8 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, reply = wpas_dbus_error_unknown_error( message, "wpa_supplicant couldn't grab this interface."); + if (create_iface) + wpa_drv_if_remove(global->ifaces, wpa_s->added_vif_type, ifname); } } @@ -865,19 +899,35 @@ DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message, struct wpa_supplicant *wpa_s; char *path; DBusMessage *reply = NULL; + unsigned int delete_iface; dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); wpa_s = get_iface_by_dbus_path(global, path); - if (wpa_s == NULL) + if (wpa_s == NULL) { reply = wpas_dbus_error_iface_unknown(message); - else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) { + goto out; + } + delete_iface = wpa_s->added_vif; + if (wpa_supplicant_remove_iface(global, wpa_s, 0)) { reply = wpas_dbus_error_unknown_error( message, "wpa_supplicant couldn't remove this interface."); + goto out; + } + + if (delete_iface) { + wpa_printf(MSG_DEBUG, "%s[dbus]: deleting the interface '%s'", + __func__, wpa_s->ifname); + if (wpa_drv_if_remove(global->ifaces, wpa_s->added_vif_type, wpa_s->ifname)) { + reply = wpas_dbus_error_unknown_error( + message, + "wpa_supplicant couldn't delete this interface."); + } } +out: return reply; } diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 858ca23d1..af6cf893e 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -857,6 +857,7 @@ struct wpa_supplicant { unsigned int connection_vht:1; unsigned int connection_he:1; unsigned int disable_mbo_oce:1; + enum wpa_driver_if_type added_vif_type; struct os_reltime last_mac_addr_change; int last_mac_addr_style;