diff options
author | Ben Greear <greearb@candelatech.com> | 2020-05-13 20:48:12 (GMT) |
---|---|---|
committer | Jouni Malinen <j@w1.fi> | 2021-02-27 08:51:15 (GMT) |
commit | 827b43b3ca17b5a8de2fdac367ec9140385f7b31 (patch) | |
tree | 4223d8aecf3efd2782f9bbea551962e5e16b91be /src/radius | |
parent | 3a05f89edc130d025a128858f06b90ced1c24132 (diff) | |
download | hostap-827b43b3ca17b5a8de2fdac367ec9140385f7b31.zip hostap-827b43b3ca17b5a8de2fdac367ec9140385f7b31.tar.gz hostap-827b43b3ca17b5a8de2fdac367ec9140385f7b31.tar.bz2 |
RADIUS client: Support SO_BINDTODEVICE
Allow the RADIUS client socket to be bound to a specific netdev. This
helps hostapd work better in VRF and other fancy network environments.
Signed-off-by: Ben Greear <greearb@candelatech.com>
Signed-off-by: Andreas Tobler <andreas.tobler at onway.ch>
Diffstat (limited to 'src/radius')
-rw-r--r-- | src/radius/radius_client.c | 29 | ||||
-rw-r--r-- | src/radius/radius_client.h | 5 |
2 files changed, 29 insertions, 5 deletions
diff --git a/src/radius/radius_client.c b/src/radius/radius_client.c index bfcb944..4f0ff07 100644 --- a/src/radius/radius_client.c +++ b/src/radius/radius_client.c @@ -7,6 +7,7 @@ */ #include "includes.h" +#include <net/if.h> #include "common.h" #include "radius.h" @@ -1168,6 +1169,29 @@ radius_change_server(struct radius_client_data *radius, return -1; } + /* Force a reconnect by disconnecting the socket first */ + if (connect(sel_sock, (struct sockaddr *) &disconnect_addr, + sizeof(disconnect_addr)) < 0) + wpa_printf(MSG_INFO, "disconnect[radius]: %s", strerror(errno)); + +#ifdef __linux__ + if (conf->force_client_dev && conf->force_client_dev[0]) { + if (setsockopt(sel_sock, SOL_SOCKET, SO_BINDTODEVICE, + conf->force_client_dev, + os_strlen(conf->force_client_dev)) < 0) { + wpa_printf(MSG_ERROR, + "RADIUS: setsockopt[SO_BINDTODEVICE]: %s", + strerror(errno)); + /* Probably not a critical error; continue on and hope + * for the best. */ + } else { + wpa_printf(MSG_DEBUG, + "RADIUS: Bound client socket to device: %s", + conf->force_client_dev); + } + } +#endif /* __linux__ */ + if (conf->force_client_addr) { switch (conf->client_addr.af) { case AF_INET: @@ -1200,11 +1224,6 @@ radius_change_server(struct radius_client_data *radius, } } - /* Force a reconnect by disconnecting the socket first */ - if (connect(sel_sock, (struct sockaddr *) &disconnect_addr, - sizeof(disconnect_addr)) < 0) - wpa_printf(MSG_INFO, "disconnect[radius]: %s", strerror(errno)); - if (connect(sel_sock, addr, addrlen) < 0) { wpa_printf(MSG_INFO, "connect[radius]: %s", strerror(errno)); return -1; diff --git a/src/radius/radius_client.h b/src/radius/radius_client.h index 8ca0874..687cd81 100644 --- a/src/radius/radius_client.h +++ b/src/radius/radius_client.h @@ -174,6 +174,11 @@ struct hostapd_radius_servers { * force_client_addr - Whether to force client (local) address */ int force_client_addr; + + /** + * force_client_dev - Bind the socket to a specified interface, if set + */ + char *force_client_dev; }; |