mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 10:18:21 -05:00
ctrl_iface_common: Use sockaddr_storage instead of sockaddr_un
This is a step towards allowing UDP sockets to be used with the common implementation. Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
This commit is contained in:
parent
89b781bc89
commit
acf57fae76
@ -59,7 +59,7 @@ static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
|
||||
|
||||
|
||||
static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
return ctrl_iface_attach(&hapd->ctrl_dst, from, fromlen);
|
||||
@ -67,7 +67,7 @@ static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
|
||||
|
||||
|
||||
static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
return ctrl_iface_detach(&hapd->ctrl_dst, from, fromlen);
|
||||
@ -75,7 +75,7 @@ static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
|
||||
|
||||
|
||||
static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen,
|
||||
char *level)
|
||||
{
|
||||
@ -2061,7 +2061,7 @@ static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data *hapd,
|
||||
static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
|
||||
char *buf, char *reply,
|
||||
int reply_size,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
int reply_len, res;
|
||||
@ -2314,7 +2314,7 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
|
||||
struct hostapd_data *hapd = eloop_ctx;
|
||||
char buf[4096];
|
||||
int res;
|
||||
struct sockaddr_un from;
|
||||
struct sockaddr_storage from;
|
||||
socklen_t fromlen = sizeof(from);
|
||||
char *reply;
|
||||
const int reply_size = 4096;
|
||||
@ -2606,7 +2606,7 @@ static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
|
||||
|
||||
|
||||
static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
return ctrl_iface_attach(&interfaces->global_ctrl_dst, from, fromlen);
|
||||
@ -2614,7 +2614,7 @@ static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
|
||||
|
||||
|
||||
static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces *interfaces,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
return ctrl_iface_detach(&interfaces->global_ctrl_dst, from, fromlen);
|
||||
@ -2819,7 +2819,7 @@ static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces *interfaces,
|
||||
const char *ifname,
|
||||
char *buf, char *reply,
|
||||
int reply_size,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
struct hostapd_data *hapd;
|
||||
@ -2845,7 +2845,7 @@ static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
|
||||
void *interfaces = eloop_ctx;
|
||||
char buf[256];
|
||||
int res;
|
||||
struct sockaddr_un from;
|
||||
struct sockaddr_storage from;
|
||||
socklen_t fromlen = sizeof(from);
|
||||
char *reply;
|
||||
int reply_len;
|
||||
@ -3160,9 +3160,8 @@ static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
|
||||
idx = 0;
|
||||
dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
|
||||
if (level >= dst->debug_level) {
|
||||
wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
|
||||
(u8 *) dst->addr.sun_path, dst->addrlen -
|
||||
offsetof(struct sockaddr_un, sun_path));
|
||||
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor send",
|
||||
&dst->addr, dst->addrlen);
|
||||
msg.msg_name = &dst->addr;
|
||||
msg.msg_namelen = dst->addrlen;
|
||||
if (sendmsg(s, &msg, 0) < 0) {
|
||||
|
@ -92,7 +92,7 @@ void sockaddr_print(int level, const char *msg, struct sockaddr_storage *sock,
|
||||
}
|
||||
|
||||
|
||||
int ctrl_iface_attach(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
int ctrl_iface_attach(struct dl_list *ctrl_dst, struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst;
|
||||
@ -105,25 +105,21 @@ int ctrl_iface_attach(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
dst->debug_level = MSG_INFO;
|
||||
dl_list_add(ctrl_dst, &dst->list);
|
||||
|
||||
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor attached",
|
||||
(struct sockaddr_storage *) from, fromlen);
|
||||
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor attached", from, fromlen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int ctrl_iface_detach(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
int ctrl_iface_detach(struct dl_list *ctrl_dst, struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst;
|
||||
|
||||
dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
|
||||
if (!sockaddr_compare((struct sockaddr_storage *) from,
|
||||
fromlen,
|
||||
(struct sockaddr_storage *) &dst->addr,
|
||||
dst->addrlen)) {
|
||||
if (!sockaddr_compare(from, fromlen,
|
||||
&dst->addr, dst->addrlen)) {
|
||||
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor detached",
|
||||
(struct sockaddr_storage *) from,
|
||||
fromlen);
|
||||
from, fromlen);
|
||||
dl_list_del(&dst->list);
|
||||
os_free(dst);
|
||||
return 0;
|
||||
@ -134,7 +130,7 @@ int ctrl_iface_detach(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
}
|
||||
|
||||
|
||||
int ctrl_iface_level(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
int ctrl_iface_level(struct dl_list *ctrl_dst, struct sockaddr_storage *from,
|
||||
socklen_t fromlen, const char *level)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst;
|
||||
@ -142,14 +138,11 @@ int ctrl_iface_level(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
|
||||
|
||||
dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
|
||||
if (!sockaddr_compare((struct sockaddr_storage *) from,
|
||||
fromlen,
|
||||
(struct sockaddr_storage *) &dst->addr,
|
||||
dst->addrlen)) {
|
||||
if (!sockaddr_compare(from, fromlen,
|
||||
&dst->addr, dst->addrlen)) {
|
||||
sockaddr_print(MSG_DEBUG,
|
||||
"CTRL_IFACE changed monitor level",
|
||||
(struct sockaddr_storage *) from,
|
||||
fromlen);
|
||||
from, fromlen);
|
||||
dst->debug_level = atoi(level);
|
||||
return 0;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
*/
|
||||
struct wpa_ctrl_dst {
|
||||
struct dl_list list;
|
||||
struct sockaddr_un addr;
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addrlen;
|
||||
int debug_level;
|
||||
int errors;
|
||||
@ -28,11 +28,11 @@ struct wpa_ctrl_dst {
|
||||
void sockaddr_print(int level, const char *msg, struct sockaddr_storage *sock,
|
||||
socklen_t socklen);
|
||||
|
||||
int ctrl_iface_attach(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
int ctrl_iface_attach(struct dl_list *ctrl_dst, struct sockaddr_storage *from,
|
||||
socklen_t fromlen);
|
||||
int ctrl_iface_detach(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
int ctrl_iface_detach(struct dl_list *ctrl_dst, struct sockaddr_storage *from,
|
||||
socklen_t fromlen);
|
||||
int ctrl_iface_level(struct dl_list *ctrl_dst, struct sockaddr_un *from,
|
||||
int ctrl_iface_level(struct dl_list *ctrl_dst, struct sockaddr_storage *from,
|
||||
socklen_t fromlen, const char *level);
|
||||
|
||||
#endif /* CONTROL_IFACE_COMMON_H */
|
||||
|
@ -101,7 +101,7 @@ static void wpas_ctrl_sock_debug(const char *title, int sock, const char *buf,
|
||||
|
||||
|
||||
static int wpa_supplicant_ctrl_iface_attach(struct dl_list *ctrl_dst,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen, int global)
|
||||
{
|
||||
return ctrl_iface_attach(ctrl_dst, from, fromlen);
|
||||
@ -109,7 +109,7 @@ static int wpa_supplicant_ctrl_iface_attach(struct dl_list *ctrl_dst,
|
||||
|
||||
|
||||
static int wpa_supplicant_ctrl_iface_detach(struct dl_list *ctrl_dst,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen)
|
||||
{
|
||||
return ctrl_iface_detach(ctrl_dst, from, fromlen);
|
||||
@ -117,7 +117,7 @@ static int wpa_supplicant_ctrl_iface_detach(struct dl_list *ctrl_dst,
|
||||
|
||||
|
||||
static int wpa_supplicant_ctrl_iface_level(struct ctrl_iface_priv *priv,
|
||||
struct sockaddr_un *from,
|
||||
struct sockaddr_storage *from,
|
||||
socklen_t fromlen,
|
||||
char *level)
|
||||
{
|
||||
@ -134,7 +134,7 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
|
||||
struct ctrl_iface_priv *priv = sock_ctx;
|
||||
char buf[4096];
|
||||
int res;
|
||||
struct sockaddr_un from;
|
||||
struct sockaddr_storage from;
|
||||
socklen_t fromlen = sizeof(from);
|
||||
char *reply = NULL, *reply_buf = NULL;
|
||||
size_t reply_len = 0;
|
||||
@ -928,33 +928,31 @@ static void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant *wpa_s,
|
||||
|
||||
dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
|
||||
int _errno;
|
||||
char addr_txt[200];
|
||||
char txt[200];
|
||||
|
||||
if (level < dst->debug_level)
|
||||
continue;
|
||||
|
||||
printf_encode(addr_txt, sizeof(addr_txt),
|
||||
(u8 *) dst->addr.sun_path, dst->addrlen -
|
||||
offsetof(struct sockaddr_un, sun_path));
|
||||
msg.msg_name = (void *) &dst->addr;
|
||||
msg.msg_namelen = dst->addrlen;
|
||||
wpas_ctrl_sock_debug("ctrl_sock-sendmsg", sock, buf, len);
|
||||
if (sendmsg(sock, &msg, MSG_DONTWAIT) >= 0) {
|
||||
wpa_printf(MSG_MSGDUMP,
|
||||
"CTRL_IFACE monitor sent successfully to %s",
|
||||
addr_txt);
|
||||
sockaddr_print(MSG_MSGDUMP,
|
||||
"CTRL_IFACE monitor sent successfully to",
|
||||
&dst->addr, dst->addrlen);
|
||||
dst->errors = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
_errno = errno;
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor[%s]: %d - %s",
|
||||
addr_txt, errno, strerror(errno));
|
||||
os_snprintf(txt, sizeof(txt), "CTRL_IFACE monitor: %d (%s) for",
|
||||
_errno, strerror(_errno));
|
||||
sockaddr_print(MSG_DEBUG, txt, &dst->addr, dst->addrlen);
|
||||
dst->errors++;
|
||||
|
||||
if (dst->errors > 10 || _errno == ENOENT || _errno == EPERM) {
|
||||
wpa_printf(MSG_INFO, "CTRL_IFACE: Detach monitor %s that cannot receive messages",
|
||||
addr_txt);
|
||||
sockaddr_print(MSG_INFO, "CTRL_IFACE: Detach monitor that cannot receive messages:",
|
||||
&dst->addr, dst->addrlen);
|
||||
wpa_supplicant_ctrl_iface_detach(ctrl_dst, &dst->addr,
|
||||
dst->addrlen);
|
||||
}
|
||||
@ -988,7 +986,7 @@ void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
|
||||
{
|
||||
char buf[256];
|
||||
int res;
|
||||
struct sockaddr_un from;
|
||||
struct sockaddr_storage from;
|
||||
socklen_t fromlen = sizeof(from);
|
||||
|
||||
if (priv->sock == -1)
|
||||
@ -1051,7 +1049,7 @@ static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
|
||||
struct ctrl_iface_global_priv *priv = sock_ctx;
|
||||
char buf[4096];
|
||||
int res;
|
||||
struct sockaddr_un from;
|
||||
struct sockaddr_storage from;
|
||||
socklen_t fromlen = sizeof(from);
|
||||
char *reply = NULL, *reply_buf = NULL;
|
||||
size_t reply_len;
|
||||
|
Loading…
Reference in New Issue
Block a user