[PATCH v3 10/26] hostapd: ctrl udp allow to set port

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

 



Allow to setup port for ctrl and global UDP iface.
The format is:
udp:<port_no>

eg.
wpa_supplicant -Dnl80211 -ddt -g udp:8888
or in conf file
ctrl_interface=udp:8877

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@xxxxxxxxx>
---
 hostapd/ctrl_iface.c | 28 ++++++++++++++++++++++++++--
 hostapd/main.c       |  5 +++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index d5fc54d..951854e 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -2367,6 +2367,7 @@ int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
 {
 	int port = HOSTAPD_CTRL_IFACE_PORT;
 	char p[32]={0};
+	char *pos;
 	struct addrinfo hints = { 0 }, *res, *saveres;
 	int n;
 
@@ -2378,6 +2379,16 @@ int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
 	if (hapd->conf->ctrl_interface == NULL)
 		return 0;
 
+	pos = os_strstr(hapd->conf->ctrl_interface, "udp:");
+	if (pos) {
+		pos += 4;
+		port = atoi(pos);
+		if (!port) {
+			wpa_printf(MSG_ERROR, "invalid ctrl udp port");
+			goto fail;
+		}
+	}
+
 	dl_list_init(&hapd->ctrl_dst);
 	hapd->ctrl_sock = -1;
 	os_get_random(cookie, COOKIE_LEN);
@@ -2410,7 +2421,8 @@ try_again:
 
 	if (bind(hapd->ctrl_sock, res->ai_addr, res->ai_addrlen) < 0) {
 		port--;
-		if ((HOSTAPD_CTRL_IFACE_PORT - port) < HOSTAPD_CTRL_IFACE_PORT_LIMIT)
+		if ((HOSTAPD_CTRL_IFACE_PORT - port) < HOSTAPD_CTRL_IFACE_PORT_LIMIT &&
+		    !pos)
 			goto try_again;
 		wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
 		goto fail;
@@ -3084,6 +3096,7 @@ int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
 {
 	int port = HOSTAPD_GLOBAL_CTRL_IFACE_PORT;
 	char p[32]={0};
+	char *pos;
 	struct addrinfo hints = { 0 }, *res, *saveres;
 	int n;
 
@@ -3095,6 +3108,16 @@ int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
 	if (interface->global_iface_path == NULL)
 		return 0;
 
+	pos = os_strstr(interface->global_iface_path, "udp:");
+	if (pos) {
+		pos += 4;
+		port = atoi(pos);
+		if (!port) {
+			wpa_printf(MSG_ERROR, "invalid global ctrl udp port");
+			goto fail;
+		}
+	}
+
 	dl_list_init(&interface->global_ctrl_dst);
 	interface->global_ctrl_sock = -1;
 	os_get_random(gcookie, COOKIE_LEN);
@@ -3127,7 +3150,8 @@ try_again:
 
 	if (bind(interface->global_ctrl_sock, res->ai_addr, res->ai_addrlen) < 0) {
 		port++;
-		if ((port - HOSTAPD_GLOBAL_CTRL_IFACE_PORT) < HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT)
+		if ((port - HOSTAPD_GLOBAL_CTRL_IFACE_PORT) < HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT &&
+		    !pos)
 			goto try_again;
 		wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
 		goto fail;
diff --git a/hostapd/main.c b/hostapd/main.c
index ee16ccc..74a350d 100644
--- a/hostapd/main.c
+++ b/hostapd/main.c
@@ -482,6 +482,11 @@ static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces,
 	interfaces->global_iface_path = os_strdup(path);
 	if (interfaces->global_iface_path == NULL)
 		return -1;
+
+#ifdef CONFIG_CTRL_IFACE_UDP
+	return 0;
+#endif
+
 	pos = os_strrchr(interfaces->global_iface_path, '/');
 	if (pos == NULL) {
 		wpa_printf(MSG_ERROR, "No '/' in the global control interface "
-- 
1.9.1


_______________________________________________
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