[PATCH] neighbor: Allow removing neigh by bssid alone.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ben Greear <greearb@xxxxxxxxxxxxxxx>

Let users delete a neighbor by BSSID alone if they prefer.
The underlying code already properly handled a null SSID, so
just relax the CLI calling restrictions.

And, if user tries to delete a neigh entry that is already deleted,
return OK instead of failure.

Signed-off-by: Ben Greear <greearb@xxxxxxxxxxxxxxx>
---
 hostapd/ctrl_iface.c  | 16 +++++++++++-----
 hostapd/hostapd_cli.c |  8 ++++----
 src/ap/neighbor_db.c  |  2 +-
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index f47d21e..ff2fd65 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -2779,6 +2779,7 @@ static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data *hapd,
 					      char *buf)
 {
 	struct wpa_ssid_value ssid;
+	struct wpa_ssid_value *ssidp = &ssid;
 	u8 bssid[ETH_ALEN];
 	char *tmp;
 
@@ -2788,13 +2789,18 @@ static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data *hapd,
 	}
 
 	tmp = os_strstr(buf, "ssid=");
-	if (!tmp || ssid_parse(tmp + 5, &ssid)) {
-		wpa_printf(MSG_ERROR,
-			   "CTRL: REMOVE_NEIGHBORr: Bad or missing SSID");
-		return -1;
+	if (!tmp) {
+		ssidp = NULL;
+	}
+	else {
+		if (ssid_parse(tmp + 5, &ssid)) {
+			wpa_printf(MSG_ERROR,
+				   "CTRL: REMOVE_NEIGHBORr: Bad SSID");
+			return -1;
+		}
 	}
 
-	return hostapd_neighbor_remove(hapd, bssid, &ssid);
+	return hostapd_neighbor_remove(hapd, bssid, ssidp);
 }
 
 
diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
index 4b1c877..14d0c3b 100644
--- a/hostapd/hostapd_cli.c
+++ b/hostapd/hostapd_cli.c
@@ -1316,13 +1316,13 @@ static int hostapd_cli_cmd_remove_neighbor(struct wpa_ctrl *ctrl, int argc,
 	char cmd[400];
 	int res;
 
-	if (argc != 2) {
-		printf("Invalid remove_neighbor command: needs 2 arguments\n");
+	if (argc < 1) {
+		printf("Invalid remove_neighbor command: needs at least bssid specified.\n");
 		return -1;
 	}
 
 	res = os_snprintf(cmd, sizeof(cmd), "REMOVE_NEIGHBOR %s %s",
-			  argv[0], argv[1]);
+			  argv[0], (argc > 1) ? argv[1] : "");
 	if (os_snprintf_error(sizeof(cmd), res)) {
 		printf("Too long REMOVE_NEIGHBOR command.\n");
 		return -1;
@@ -1637,7 +1637,7 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
 	{ "show_neighbor", hostapd_cli_cmd_show_neighbor, NULL,
 	  "  = show neighbor database entries" },
 	{ "remove_neighbor", hostapd_cli_cmd_remove_neighbor, NULL,
-	  "<addr> <ssid=> = remove AP from neighbor database" },
+	  "<addr> [ssid=] = remove AP from neighbor database" },
 	{ "req_lci", hostapd_cli_cmd_req_lci, hostapd_complete_stations,
 	  "<addr> = send LCI request to a station"},
 	{ "req_range", hostapd_cli_cmd_req_range, NULL,
diff --git a/src/ap/neighbor_db.c b/src/ap/neighbor_db.c
index f54b065..451716d 100644
--- a/src/ap/neighbor_db.c
+++ b/src/ap/neighbor_db.c
@@ -181,7 +181,7 @@ int hostapd_neighbor_remove(struct hostapd_data *hapd, const u8 *bssid,
 
 	nr = hostapd_neighbor_get(hapd, bssid, ssid);
 	if (!nr)
-		return -1;
+		return 0; /* already gone, treat as success */
 
 	hostapd_neighbor_clear_entry(nr);
 	dl_list_del(&nr->list);
-- 
2.7.5


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux