aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd
diff options
context:
space:
mode:
authorJanusz Dziedzic <janusz.dziedzic@tieto.com>2016-03-04 09:20:25 (GMT)
committerJouni Malinen <j@w1.fi>2016-03-05 15:44:43 (GMT)
commitb9066c638af5daf74e7ce64bd441aebf8572ee41 (patch)
treef29aa54331249636aa16d6ba55c4a289294cbaae /hostapd
parent56885eecf4026b0199d5ba75bd50395a17d323cc (diff)
downloadhostap-b9066c638af5daf74e7ce64bd441aebf8572ee41.zip
hostap-b9066c638af5daf74e7ce64bd441aebf8572ee41.tar.gz
hostap-b9066c638af5daf74e7ce64bd441aebf8572ee41.tar.bz2
hostapd: Allow UDP ctrl_iface configuration to set the UDP port
This allows the UDP port to be set for the per-interface and global control interfaces. The format is: udp:<port_no> For example: hostapd -ddt -g udp:8888 And in the configuration file: ctrl_interface=udp:8877 Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
Diffstat (limited to 'hostapd')
-rw-r--r--hostapd/ctrl_iface.c26
-rw-r--r--hostapd/main.c6
2 files changed, 30 insertions, 2 deletions
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 237f02c..9c388b2 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -2444,6 +2444,7 @@ int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
#ifdef CONFIG_CTRL_IFACE_UDP
int port = HOSTAPD_CTRL_IFACE_PORT;
char p[32] = { 0 };
+ char *pos;
struct addrinfo hints = { 0 }, *res, *saveres;
int n;
@@ -2455,6 +2456,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 <= 0) {
+ wpa_printf(MSG_ERROR, "Invalid ctrl_iface UDP port");
+ goto fail;
+ }
+ }
+
dl_list_init(&hapd->ctrl_dst);
hapd->ctrl_sock = -1;
os_get_random(cookie, COOKIE_LEN);
@@ -2489,7 +2500,7 @@ 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)
+ HOSTAPD_CTRL_IFACE_PORT_LIMIT && !pos)
goto try_again;
wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
goto fail;
@@ -3147,6 +3158,7 @@ int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
#ifdef CONFIG_CTRL_IFACE_UDP
int port = HOSTAPD_GLOBAL_CTRL_IFACE_PORT;
char p[32] = { 0 };
+ char *pos;
struct addrinfo hints = { 0 }, *res, *saveres;
int n;
@@ -3158,6 +3170,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 <= 0) {
+ 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);
@@ -3193,7 +3215,7 @@ try_again:
0) {
port++;
if ((port - HOSTAPD_GLOBAL_CTRL_IFACE_PORT) <
- HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT)
+ 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 6c4e195..06aa4b2 100644
--- a/hostapd/main.c
+++ b/hostapd/main.c
@@ -484,11 +484,16 @@ static const char * hostapd_msg_ifname_cb(void *ctx)
static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces,
const char *path)
{
+#ifndef CONFIG_CTRL_IFACE_UDP
char *pos;
+#endif /* !CONFIG_CTRL_IFACE_UDP */
+
os_free(interfaces->global_iface_path);
interfaces->global_iface_path = os_strdup(path);
if (interfaces->global_iface_path == NULL)
return -1;
+
+#ifndef CONFIG_CTRL_IFACE_UDP
pos = os_strrchr(interfaces->global_iface_path, '/');
if (pos == NULL) {
wpa_printf(MSG_ERROR, "No '/' in the global control interface "
@@ -500,6 +505,7 @@ static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces,
*pos = '\0';
interfaces->global_iface_name = pos + 1;
+#endif /* !CONFIG_CTRL_IFACE_UDP */
return 0;
}