diff mbox

[v5,10/25] wpa_supplicant: udp ctrl setup ctrl_interface

Message ID 1457083241-7492-11-git-send-email-janusz.dziedzic@tieto.com
State Changes Requested
Headers show

Commit Message

Janusz.Dziedzic@tieto.com March 4, 2016, 9:20 a.m. UTC
Setup ctrl_interface name. This should be used
to check interface <-> udp port assigment.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
---
 wpa_supplicant/ctrl_iface_udp.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

Jouni Malinen March 5, 2016, 1:43 p.m. UTC | #1
On Fri, Mar 04, 2016 at 10:20:26AM +0100, Janusz Dziedzic wrote:
> Setup ctrl_interface name. This should be used
> to check interface <-> udp port assigment.

> diff --git a/wpa_supplicant/ctrl_iface_udp.c b/wpa_supplicant/ctrl_iface_udp.c
> @@ -380,10 +381,8 @@ wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
>  	priv->sock = -1;
>  	os_get_random(priv->cookie, COOKIE_LEN);
>  
> -	if (wpa_s->conf->ctrl_interface == NULL)
> -		return priv;
> -
> -	pos = os_strstr(wpa_s->conf->ctrl_interface, "udp:");
> +	if (wpa_s->conf->ctrl_interface)
> +	    pos = os_strstr(wpa_s->conf->ctrl_interface, "udp:");

Could you please clarify what this is trying to do? This would end up
opening the control interface socket even if the configuration has the
control interface disabled (wpa_s->conf->ctrl_interface == NULL). That
does not sound correct and the commit message is not very clear on the
purpose of this change.
Janusz.Dziedzic@tieto.com March 6, 2016, 11 a.m. UTC | #2
On 5 March 2016 at 14:43, Jouni Malinen <j@w1.fi> wrote:
> On Fri, Mar 04, 2016 at 10:20:26AM +0100, Janusz Dziedzic wrote:
>> Setup ctrl_interface name. This should be used
>> to check interface <-> udp port assigment.
>
>> diff --git a/wpa_supplicant/ctrl_iface_udp.c b/wpa_supplicant/ctrl_iface_udp.c
>> @@ -380,10 +381,8 @@ wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
>>       priv->sock = -1;
>>       os_get_random(priv->cookie, COOKIE_LEN);
>>
>> -     if (wpa_s->conf->ctrl_interface == NULL)
>> -             return priv;
>> -
>> -     pos = os_strstr(wpa_s->conf->ctrl_interface, "udp:");
>> +     if (wpa_s->conf->ctrl_interface)
>> +         pos = os_strstr(wpa_s->conf->ctrl_interface, "udp:");
>
> Could you please clarify what this is trying to do? This would end up
> opening the control interface socket even if the configuration has the
> control interface disabled (wpa_s->conf->ctrl_interface == NULL). That
> does not sound correct and the commit message is not very clear on the
> purpose of this change.
>
Added this check while strstr() segfault when NULL passed.

But yes, I added this because p2p_group_add() failed (ctrl_interface
derived from main in such case).
Will split/describe this better and resend.

BR
Janusz

> --
> Jouni Malinen                                            PGP id EFC895FA
diff mbox

Patch

diff --git a/wpa_supplicant/ctrl_iface_udp.c b/wpa_supplicant/ctrl_iface_udp.c
index 8ab8ee8..f13ba4a 100644
--- a/wpa_supplicant/ctrl_iface_udp.c
+++ b/wpa_supplicant/ctrl_iface_udp.c
@@ -363,8 +363,9 @@  struct ctrl_iface_priv *
 wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
 {
 	struct ctrl_iface_priv *priv;
+	char port_str[40];
 	int port = WPA_CTRL_IFACE_PORT;
-	char *pos;
+	char *pos = NULL;
 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
 	struct sockaddr_in6 addr;
 	int domain = PF_INET6;
@@ -380,10 +381,8 @@  wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
 	priv->sock = -1;
 	os_get_random(priv->cookie, COOKIE_LEN);
 
-	if (wpa_s->conf->ctrl_interface == NULL)
-		return priv;
-
-	pos = os_strstr(wpa_s->conf->ctrl_interface, "udp:");
+	if (wpa_s->conf->ctrl_interface)
+	    pos = os_strstr(wpa_s->conf->ctrl_interface, "udp:");
 	if (pos) {
 		pos += 4;
 		port = atoi(pos);
@@ -424,12 +423,21 @@  try_again:
 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
 	if (bind(priv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 		port--;
-		if ((WPA_CTRL_IFACE_PORT - port) < WPA_CTRL_IFACE_PORT_LIMIT && !pos)
+		if ((WPA_CTRL_IFACE_PORT - port) < WPA_CTRL_IFACE_PORT_LIMIT)
 			goto try_again;
 		wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
 		goto fail;
 	}
 
+	/* Setup correct ctrl_interface */
+	os_snprintf(port_str, sizeof(port_str), "udp:%d", port);
+	os_free(wpa_s->conf->ctrl_interface);
+	wpa_s->conf->ctrl_interface = os_strdup(port_str);
+	if (!wpa_s->conf->ctrl_interface) {
+		wpa_msg(wpa_s, MSG_DEBUG, "failed to malloc ctrl_inteface");
+		goto fail;
+	}
+
 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
 	wpa_msg(wpa_s, MSG_DEBUG, "ctrl_iface_init UDP port: %d", port);
 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */