From patchwork Wed Feb 19 14:53:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuel Taube X-Patchwork-Id: 321932 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5EB032C00C7 for ; Thu, 20 Feb 2014 01:54:13 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 8F8899D0D3; Wed, 19 Feb 2014 09:54:08 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0jvphjrxcx3G; Wed, 19 Feb 2014 09:54:08 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 1938F9C193; Wed, 19 Feb 2014 09:54:03 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id CD6909C193 for ; Wed, 19 Feb 2014 09:54:01 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V9g-QjpzyH5D for ; Wed, 19 Feb 2014 09:53:56 -0500 (EST) Received: from mail-ee0-f49.google.com (mail-ee0-f49.google.com [74.125.83.49]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id C9C059C164 for ; Wed, 19 Feb 2014 09:53:55 -0500 (EST) Received: by mail-ee0-f49.google.com with SMTP id d17so286098eek.8 for ; Wed, 19 Feb 2014 06:53:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=3h6Yl1Iss4rZohSrNLc2oDyRdxdzKXcadmFVbHTiGGQ=; b=oayzTIUP7IHmNX6Buz47sLjBpbOpKyjSNa9q4cgBx4rgrJWngYBcVPmkXkc1/tpr+3 Fpys3+ubffeTuaLzN5yuE/ziBdp3WHCy37wRBYwqqw/OrJgTgwD0Vn0tvIOdnylls+Ii 1MWnrBoPLmKRPVBSUfp4nbNZgdpzvhSXsElNwSd+CLdUKYLIWeZ47p566mL9GAZ4hXPb JWoQgrvJMH8Eu8Zv9a3B6K12f5Ngbw0+coLNHtG74Sn29EkNuI7XAjn2SJmQkmD6sfB1 aiz7cC5P0d12Ni8/k+AgdDQryZwNod4CBE8LR9xwJ9yYdkOueE/fXaFZfEsqywyueH2q OQCA== X-Received: by 10.15.61.134 with SMTP id i6mr2632996eex.106.1392821633337; Wed, 19 Feb 2014 06:53:53 -0800 (PST) Received: from eMsRechner.intranet.astaro.de (port-92-198-130-130.static.qsc.de. [92.198.130.130]) by mx.google.com with ESMTPSA id j41sm1584994eeg.10.2014.02.19.06.53.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Feb 2014 06:53:53 -0800 (PST) From: Emanuel Taube To: hostap@lists.shmoo.com Subject: [PATCHv2 1/2] hostapd: make it possible to remove addresses from maclists Date: Wed, 19 Feb 2014 15:53:15 +0100 Message-Id: <1392821596-3034-1-git-send-email-emanuel.taube@gmail.com> X-Mailer: git-send-email 1.7.10.4 X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com It is already possible to add mac addresses at runtime. This patch allows also to remove some of them by the prefix "-" in the address file. Signed-off-by: Emanuel Taube --- hostapd/config_file.c | 23 +++++++++++++++++++++-- src/utils/os.h | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index 19d6ad3..35e1438 100644 --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -116,6 +116,8 @@ static int hostapd_config_read_maclist(const char *fname, char buf[128], *pos; int line = 0; u8 addr[ETH_ALEN]; + Boolean remove; + int i; struct mac_acl_entry *newacl; int vlan_id; @@ -143,14 +145,31 @@ static int hostapd_config_read_maclist(const char *fname, } if (buf[0] == '\0') continue; + pos = buf; + if (buf[0] == '-') { + remove = TRUE; + pos++; + } else + remove = FALSE; - if (hwaddr_aton(buf, addr)) { + if (hwaddr_aton(pos, addr)) { wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at " - "line %d in '%s'", buf, line, fname); + "line %d in '%s'", pos, line, fname); fclose(f); return -1; } + if (remove) { + for (i = 0; i < *num; i++) + if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == + 0) { + os_remove_in_array( + *acl, *num, + sizeof(**acl), i--); + (*num)--; + } + continue; + } vlan_id = 0; pos = buf; while (*pos != '\0' && *pos != ' ' && *pos != '\t') diff --git a/src/utils/os.h b/src/utils/os.h index 2e2350a..3786bdf 100644 --- a/src/utils/os.h +++ b/src/utils/os.h @@ -549,6 +549,22 @@ static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size) return os_realloc(ptr, nmemb * size); } +/** + * os_remove_in_array - Remove a member from an array by index + * @ptr: pointer to the array + * @nmemb: current member count of the array + * @size: the size per member of the array + * @idx: index of the member which should be removed + */ +static inline void os_remove_in_array(void *ptr, size_t nmemb, size_t size, + unsigned int idx) +{ + if (idx >= nmemb) + return; + if (idx < nmemb - 1) + os_memmove(ptr + idx * size, ptr + (idx + 1) * size, + (nmemb - idx - 1) * size); +} /** * os_strlcpy - Copy a string with size bound and NUL-termination