From patchwork Wed Feb 17 12:14:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz.Dziedzic@tieto.com X-Patchwork-Id: 584089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 15FD9140324 for ; Wed, 17 Feb 2016 23:15:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=tieto.com header.i=@tieto.com header.b=GGm3AclO; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aW10s-0008Hl-LS; Wed, 17 Feb 2016 12:15:22 +0000 Received: from mail-lb0-x234.google.com ([2a00:1450:4010:c04::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aW10g-0006yS-7a for hostap@lists.infradead.org; Wed, 17 Feb 2016 12:15:13 +0000 Received: by mail-lb0-x234.google.com with SMTP id x1so8232088lbj.3 for ; Wed, 17 Feb 2016 04:14:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R5yppvynePj1Nu0/QxJTFUtv9FwBhp53WRyBQ7SGhvQ=; b=GGm3AclOtqpI83mpFJG+Wlh+ghlFjKm3vrJOtL7pl5Xs7NBS03iXB8MEygMJriwyyW nW8unU5+0lwGT1EpvTuL/7fYe/Ih1MCWGXjLBKXRSGyWFBwsCk2oH8Ke7hFWbeIsPkC+ u2cq4lvfHkG3anTWkrFsx/0yau70P4aqUfEzE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=R5yppvynePj1Nu0/QxJTFUtv9FwBhp53WRyBQ7SGhvQ=; b=cvdk6llpajdbfUGCm/1V7SJxpY1jJwY2lQKgatMMz9VPsStXUBAK+ALnL6w3tuzDc2 NQz1+UcVMkr4lz8zWMNu1EKMRV9CPpbQP1u9V3OxbUewTseOvLl33Tb7hDrUMYdf+eId PYJkwlHdRDCPTxwPUrh9gI0fjbB1oUWZ/sp3a+vTJJDGbBicOxEeC+sOc0Lu+d6RN77d Oo8ELso70081w95VS01iyyu6Wipgz96u45RepWFFWugKVO2axar5h5MZksPh+3hdoalN sm/Lb2XRVaFrVvNa55PJgU6vf6ZmF5ZHlCylUG+VKOCIyeDeAUeoUSujLc6oUL1mA8XY 9LFg== X-Gm-Message-State: AG10YOTJwA/8Mu6Z8FzyCZKwvQJN5jc5MX7ApmlGHVJWnD8j6/h9lvhjOVylRLKh2npsGjQ8kddCrYgwrC/X6eY6H7ijMVESjOQB3jtrlCO9r1dlm/R7vaE5Xr1ExyjVTLhsDSRnOGHA1fzq7dvGG7t3rbHryr2G/mJCp97fQPJNi8E1bPRxNs73BF/WPo8Y9MdO X-Received: by 10.112.13.193 with SMTP id j1mr641975lbc.24.1455711288274; Wed, 17 Feb 2016 04:14:48 -0800 (PST) Received: from dell6430.guest.wifi ([91.198.246.8]) by smtp.gmail.com with ESMTPSA id t5sm169075lbg.15.2016.02.17.04.14.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 04:14:47 -0800 (PST) From: Janusz Dziedzic To: hostap@lists.infradead.org Subject: [PATCH v3 07/26] hostapd: ctrl unix use common ctrl code Date: Wed, 17 Feb 2016 13:14:10 +0100 Message-Id: <1455711269-12929-8-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455711269-12929-1-git-send-email-janusz.dziedzic@tieto.com> References: <1455711269-12929-1-git-send-email-janusz.dziedzic@tieto.com> X-DomainID: tieto.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160217_041510_886521_502D77AC X-CRM114-Status: GOOD ( 15.16 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c04:0:0:0:234 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: j@w1.fi, Janusz Dziedzic MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Use common ctrl code. Signed-off-by: Janusz Dziedzic --- hostapd/Makefile | 1 + hostapd/ctrl_iface.c | 139 ++++++--------------------------------------------- hostapd/main.c | 2 +- src/ap/hostapd.h | 4 +- 4 files changed, 20 insertions(+), 126 deletions(-) diff --git a/hostapd/Makefile b/hostapd/Makefile index 45afedf..ab0d8f6 100644 --- a/hostapd/Makefile +++ b/hostapd/Makefile @@ -201,6 +201,7 @@ endif ifdef CONFIG_NO_CTRL_IFACE CFLAGS += -DCONFIG_NO_CTRL_IFACE else +OBJS += ../src/common/ctrl_iface_common.o OBJS += ctrl_iface.o OBJS += ../src/ap/ctrl_iface_ap.o endif diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index cb6fb17..ffcded3 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -47,18 +47,11 @@ #include "fst/fst_ctrl_iface.h" #include "config_file.h" #include "ctrl_iface.h" +#include "common/ctrl_iface_common.h" #define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256 -struct wpa_ctrl_dst { - struct wpa_ctrl_dst *next; - struct sockaddr_un addr; - socklen_t addrlen; - int debug_level; - int errors; -}; - static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level, enum wpa_msg_type type, @@ -69,20 +62,7 @@ static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd, struct sockaddr_un *from, socklen_t fromlen) { - struct wpa_ctrl_dst *dst; - - dst = os_zalloc(sizeof(*dst)); - if (dst == NULL) - return -1; - os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un)); - dst->addrlen = fromlen; - dst->debug_level = MSG_INFO; - dst->next = hapd->ctrl_dst; - hapd->ctrl_dst = dst; - wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached", - (u8 *) from->sun_path, - fromlen - offsetof(struct sockaddr_un, sun_path)); - return 0; + return ctrl_iface_attach(&hapd->ctrl_dst, from, fromlen); } @@ -90,29 +70,7 @@ static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd, struct sockaddr_un *from, socklen_t fromlen) { - struct wpa_ctrl_dst *dst, *prev = NULL; - - dst = hapd->ctrl_dst; - while (dst) { - if (fromlen == dst->addrlen && - os_memcmp(from->sun_path, dst->addr.sun_path, - fromlen - offsetof(struct sockaddr_un, sun_path)) - == 0) { - wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor detached", - (u8 *) from->sun_path, - fromlen - - offsetof(struct sockaddr_un, sun_path)); - if (prev == NULL) - hapd->ctrl_dst = dst->next; - else - prev->next = dst->next; - os_free(dst); - return 0; - } - prev = dst; - dst = dst->next; - } - return -1; + return ctrl_iface_detach(&hapd->ctrl_dst, from, fromlen); } @@ -121,26 +79,7 @@ static int hostapd_ctrl_iface_level(struct hostapd_data *hapd, socklen_t fromlen, char *level) { - struct wpa_ctrl_dst *dst; - - wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level); - - dst = hapd->ctrl_dst; - while (dst) { - if (fromlen == dst->addrlen && - os_memcmp(from->sun_path, dst->addr.sun_path, - fromlen - offsetof(struct sockaddr_un, sun_path)) - == 0) { - wpa_hexdump(MSG_DEBUG, "CTRL_IFACE changed monitor " - "level", (u8 *) from->sun_path, fromlen - - offsetof(struct sockaddr_un, sun_path)); - dst->debug_level = atoi(level); - return 0; - } - dst = dst->next; - } - - return -1; + return ctrl_iface_level(&hapd->ctrl_dst, from, fromlen, level); } @@ -2508,6 +2447,7 @@ int hostapd_ctrl_iface_init(struct hostapd_data *hapd) return -1; } hapd->msg_ctx = hapd; + dl_list_init(&hapd->ctrl_dst); wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb); return 0; @@ -2552,13 +2492,8 @@ void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd) } } - dst = hapd->ctrl_dst; - hapd->ctrl_dst = NULL; - while (dst) { - prev = dst; - dst = dst->next; - os_free(prev); - } + dl_list_for_each_safe(dst, prev, &hapd->ctrl_dst, struct wpa_ctrl_dst, list) + os_free(dst); #ifdef CONFIG_TESTING_OPTIONS l2_packet_deinit(hapd->l2_test); @@ -2593,20 +2528,7 @@ static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces, struct sockaddr_un *from, socklen_t fromlen) { - struct wpa_ctrl_dst *dst; - - dst = os_zalloc(sizeof(*dst)); - if (dst == NULL) - return -1; - os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un)); - dst->addrlen = fromlen; - dst->debug_level = MSG_INFO; - dst->next = interfaces->global_ctrl_dst; - interfaces->global_ctrl_dst = dst; - wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached (global)", - from->sun_path, - fromlen - offsetof(struct sockaddr_un, sun_path)); - return 0; + return ctrl_iface_attach(&interfaces->global_ctrl_dst, from, fromlen); } @@ -2614,30 +2536,7 @@ static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces *interfaces, struct sockaddr_un *from, socklen_t fromlen) { - struct wpa_ctrl_dst *dst, *prev = NULL; - - dst = interfaces->global_ctrl_dst; - while (dst) { - if (fromlen == dst->addrlen && - os_memcmp(from->sun_path, dst->addr.sun_path, - fromlen - offsetof(struct sockaddr_un, sun_path)) - == 0) { - wpa_hexdump(MSG_DEBUG, - "CTRL_IFACE monitor detached (global)", - from->sun_path, - fromlen - - offsetof(struct sockaddr_un, sun_path)); - if (prev == NULL) - interfaces->global_ctrl_dst = dst->next; - else - prev->next = dst->next; - os_free(dst); - return 0; - } - prev = dst; - dst = dst->next; - } - return -1; + return ctrl_iface_detach(&interfaces->global_ctrl_dst, from, fromlen); } @@ -3139,13 +3038,8 @@ void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces) os_free(interfaces->global_iface_path); interfaces->global_iface_path = NULL; - dst = interfaces->global_ctrl_dst; - interfaces->global_ctrl_dst = NULL; - while (dst) { - prev = dst; - dst = dst->next; - os_free(prev); - } + dl_list_for_each_safe(dst, prev, &interfaces->global_ctrl_dst, struct wpa_ctrl_dst, list) + os_free(dst); } @@ -3154,6 +3048,7 @@ static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level, const char *buf, size_t len) { struct wpa_ctrl_dst *dst, *next; + struct dl_list *ctrl_dst; struct msghdr msg; int idx; struct iovec io[2]; @@ -3162,13 +3057,13 @@ static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level, if (type != WPA_MSG_ONLY_GLOBAL) { s = hapd->ctrl_sock; - dst = hapd->ctrl_dst; + ctrl_dst = &hapd->ctrl_dst; } else { s = hapd->iface->interfaces->global_ctrl_sock; - dst = hapd->iface->interfaces->global_ctrl_dst; + ctrl_dst = &hapd->iface->interfaces->global_ctrl_dst; } - if (s < 0 || dst == NULL) + if (s < 0 || dl_list_empty(ctrl_dst)) return; os_snprintf(levelstr, sizeof(levelstr), "<%d>", level); @@ -3181,8 +3076,7 @@ static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level, msg.msg_iovlen = 2; idx = 0; - while (dst) { - next = dst->next; + dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) { if (level >= dst->debug_level) { wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send", (u8 *) dst->addr.sun_path, dst->addrlen - @@ -3210,7 +3104,6 @@ static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level, dst->errors = 0; } idx++; - dst = next; } } diff --git a/hostapd/main.c b/hostapd/main.c index 4913cbd..ee16ccc 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -586,7 +586,7 @@ int main(int argc, char *argv[]) interfaces.global_iface_path = NULL; interfaces.global_iface_name = NULL; interfaces.global_ctrl_sock = -1; - interfaces.global_ctrl_dst = NULL; + dl_list_init(&interfaces.global_ctrl_dst); for (;;) { c = getopt(argc, argv, "b:Bde:f:hKP:STtu:vg:G:"); diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 7b59f80..f822590 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -41,7 +41,7 @@ struct hapd_interfaces { size_t count; int global_ctrl_sock; - struct wpa_ctrl_dst *global_ctrl_dst; + struct dl_list global_ctrl_dst; char *global_iface_path; char *global_iface_name; #ifndef CONFIG_NATIVE_WINDOWS @@ -155,7 +155,7 @@ struct hostapd_data { int tkip_countermeasures; int ctrl_sock; - struct wpa_ctrl_dst *ctrl_dst; + struct dl_list ctrl_dst; void *ssl_ctx; void *eap_sim_db_priv;