[PATCHv3 1/2] hostapd: make it possible to remove addresses from maclists

Emanuel Taube emanuel.taube
Tue Feb 25 01:59:44 PST 2014


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 <emanuel.taube at gmail.com>
---
 hostapd/config_file.c |   26 ++++++++++++++++++++++++--
 src/utils/os.h        |   16 ++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index 19d6ad3..ab35439 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,34 @@ 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) {
+			i = 0;
+			while (i < *num) {
+				if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) ==
+				    0) {
+					os_remove_in_array(
+						*acl, *num,
+						sizeof(**acl), i);
+					(*num)--;
+				} else
+					i++;
+			}
+			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
-- 
1.7.10.4




More information about the Hostap mailing list