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
4 changed files with 40 additions and 50 deletions
|
@ -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,
|
static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
return ctrl_iface_attach(&hapd->ctrl_dst, from, 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,
|
static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
return ctrl_iface_detach(&hapd->ctrl_dst, from, 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,
|
static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen,
|
socklen_t fromlen,
|
||||||
char *level)
|
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,
|
static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
|
||||||
char *buf, char *reply,
|
char *buf, char *reply,
|
||||||
int reply_size,
|
int reply_size,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
int reply_len, res;
|
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;
|
struct hostapd_data *hapd = eloop_ctx;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
int res;
|
int res;
|
||||||
struct sockaddr_un from;
|
struct sockaddr_storage from;
|
||||||
socklen_t fromlen = sizeof(from);
|
socklen_t fromlen = sizeof(from);
|
||||||
char *reply;
|
char *reply;
|
||||||
const int reply_size = 4096;
|
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,
|
static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
return ctrl_iface_attach(&interfaces->global_ctrl_dst, from, 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,
|
static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces *interfaces,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
return ctrl_iface_detach(&interfaces->global_ctrl_dst, from, 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,
|
const char *ifname,
|
||||||
char *buf, char *reply,
|
char *buf, char *reply,
|
||||||
int reply_size,
|
int reply_size,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
struct hostapd_data *hapd;
|
struct hostapd_data *hapd;
|
||||||
|
@ -2845,7 +2845,7 @@ static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
|
||||||
void *interfaces = eloop_ctx;
|
void *interfaces = eloop_ctx;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int res;
|
int res;
|
||||||
struct sockaddr_un from;
|
struct sockaddr_storage from;
|
||||||
socklen_t fromlen = sizeof(from);
|
socklen_t fromlen = sizeof(from);
|
||||||
char *reply;
|
char *reply;
|
||||||
int reply_len;
|
int reply_len;
|
||||||
|
@ -3160,9 +3160,8 @@ static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
|
||||||
idx = 0;
|
idx = 0;
|
||||||
dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
|
dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
|
||||||
if (level >= dst->debug_level) {
|
if (level >= dst->debug_level) {
|
||||||
wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
|
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor send",
|
||||||
(u8 *) dst->addr.sun_path, dst->addrlen -
|
&dst->addr, dst->addrlen);
|
||||||
offsetof(struct sockaddr_un, sun_path));
|
|
||||||
msg.msg_name = &dst->addr;
|
msg.msg_name = &dst->addr;
|
||||||
msg.msg_namelen = dst->addrlen;
|
msg.msg_namelen = dst->addrlen;
|
||||||
if (sendmsg(s, &msg, 0) < 0) {
|
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)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
struct wpa_ctrl_dst *dst;
|
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;
|
dst->debug_level = MSG_INFO;
|
||||||
dl_list_add(ctrl_dst, &dst->list);
|
dl_list_add(ctrl_dst, &dst->list);
|
||||||
|
|
||||||
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor attached",
|
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor attached", from, fromlen);
|
||||||
(struct sockaddr_storage *) from, fromlen);
|
|
||||||
return 0;
|
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)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
struct wpa_ctrl_dst *dst;
|
struct wpa_ctrl_dst *dst;
|
||||||
|
|
||||||
dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
|
dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
|
||||||
if (!sockaddr_compare((struct sockaddr_storage *) from,
|
if (!sockaddr_compare(from, fromlen,
|
||||||
fromlen,
|
&dst->addr, dst->addrlen)) {
|
||||||
(struct sockaddr_storage *) &dst->addr,
|
|
||||||
dst->addrlen)) {
|
|
||||||
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor detached",
|
sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor detached",
|
||||||
(struct sockaddr_storage *) from,
|
from, fromlen);
|
||||||
fromlen);
|
|
||||||
dl_list_del(&dst->list);
|
dl_list_del(&dst->list);
|
||||||
os_free(dst);
|
os_free(dst);
|
||||||
return 0;
|
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)
|
socklen_t fromlen, const char *level)
|
||||||
{
|
{
|
||||||
struct wpa_ctrl_dst *dst;
|
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);
|
wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
|
||||||
|
|
||||||
dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
|
dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
|
||||||
if (!sockaddr_compare((struct sockaddr_storage *) from,
|
if (!sockaddr_compare(from, fromlen,
|
||||||
fromlen,
|
&dst->addr, dst->addrlen)) {
|
||||||
(struct sockaddr_storage *) &dst->addr,
|
|
||||||
dst->addrlen)) {
|
|
||||||
sockaddr_print(MSG_DEBUG,
|
sockaddr_print(MSG_DEBUG,
|
||||||
"CTRL_IFACE changed monitor level",
|
"CTRL_IFACE changed monitor level",
|
||||||
(struct sockaddr_storage *) from,
|
from, fromlen);
|
||||||
fromlen);
|
|
||||||
dst->debug_level = atoi(level);
|
dst->debug_level = atoi(level);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
struct wpa_ctrl_dst {
|
struct wpa_ctrl_dst {
|
||||||
struct dl_list list;
|
struct dl_list list;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_storage addr;
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
int debug_level;
|
int debug_level;
|
||||||
int errors;
|
int errors;
|
||||||
|
@ -28,11 +28,11 @@ struct wpa_ctrl_dst {
|
||||||
void sockaddr_print(int level, const char *msg, struct sockaddr_storage *sock,
|
void sockaddr_print(int level, const char *msg, struct sockaddr_storage *sock,
|
||||||
socklen_t socklen);
|
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);
|
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);
|
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);
|
socklen_t fromlen, const char *level);
|
||||||
|
|
||||||
#endif /* CONTROL_IFACE_COMMON_H */
|
#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,
|
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)
|
socklen_t fromlen, int global)
|
||||||
{
|
{
|
||||||
return ctrl_iface_attach(ctrl_dst, from, fromlen);
|
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,
|
static int wpa_supplicant_ctrl_iface_detach(struct dl_list *ctrl_dst,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen)
|
socklen_t fromlen)
|
||||||
{
|
{
|
||||||
return ctrl_iface_detach(ctrl_dst, from, 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,
|
static int wpa_supplicant_ctrl_iface_level(struct ctrl_iface_priv *priv,
|
||||||
struct sockaddr_un *from,
|
struct sockaddr_storage *from,
|
||||||
socklen_t fromlen,
|
socklen_t fromlen,
|
||||||
char *level)
|
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;
|
struct ctrl_iface_priv *priv = sock_ctx;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
int res;
|
int res;
|
||||||
struct sockaddr_un from;
|
struct sockaddr_storage from;
|
||||||
socklen_t fromlen = sizeof(from);
|
socklen_t fromlen = sizeof(from);
|
||||||
char *reply = NULL, *reply_buf = NULL;
|
char *reply = NULL, *reply_buf = NULL;
|
||||||
size_t reply_len = 0;
|
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) {
|
dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
|
||||||
int _errno;
|
int _errno;
|
||||||
char addr_txt[200];
|
char txt[200];
|
||||||
|
|
||||||
if (level < dst->debug_level)
|
if (level < dst->debug_level)
|
||||||
continue;
|
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_name = (void *) &dst->addr;
|
||||||
msg.msg_namelen = dst->addrlen;
|
msg.msg_namelen = dst->addrlen;
|
||||||
wpas_ctrl_sock_debug("ctrl_sock-sendmsg", sock, buf, len);
|
wpas_ctrl_sock_debug("ctrl_sock-sendmsg", sock, buf, len);
|
||||||
if (sendmsg(sock, &msg, MSG_DONTWAIT) >= 0) {
|
if (sendmsg(sock, &msg, MSG_DONTWAIT) >= 0) {
|
||||||
wpa_printf(MSG_MSGDUMP,
|
sockaddr_print(MSG_MSGDUMP,
|
||||||
"CTRL_IFACE monitor sent successfully to %s",
|
"CTRL_IFACE monitor sent successfully to",
|
||||||
addr_txt);
|
&dst->addr, dst->addrlen);
|
||||||
dst->errors = 0;
|
dst->errors = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_errno = errno;
|
_errno = errno;
|
||||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor[%s]: %d - %s",
|
os_snprintf(txt, sizeof(txt), "CTRL_IFACE monitor: %d (%s) for",
|
||||||
addr_txt, errno, strerror(errno));
|
_errno, strerror(_errno));
|
||||||
|
sockaddr_print(MSG_DEBUG, txt, &dst->addr, dst->addrlen);
|
||||||
dst->errors++;
|
dst->errors++;
|
||||||
|
|
||||||
if (dst->errors > 10 || _errno == ENOENT || _errno == EPERM) {
|
if (dst->errors > 10 || _errno == ENOENT || _errno == EPERM) {
|
||||||
wpa_printf(MSG_INFO, "CTRL_IFACE: Detach monitor %s that cannot receive messages",
|
sockaddr_print(MSG_INFO, "CTRL_IFACE: Detach monitor that cannot receive messages:",
|
||||||
addr_txt);
|
&dst->addr, dst->addrlen);
|
||||||
wpa_supplicant_ctrl_iface_detach(ctrl_dst, &dst->addr,
|
wpa_supplicant_ctrl_iface_detach(ctrl_dst, &dst->addr,
|
||||||
dst->addrlen);
|
dst->addrlen);
|
||||||
}
|
}
|
||||||
|
@ -988,7 +986,7 @@ void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int res;
|
int res;
|
||||||
struct sockaddr_un from;
|
struct sockaddr_storage from;
|
||||||
socklen_t fromlen = sizeof(from);
|
socklen_t fromlen = sizeof(from);
|
||||||
|
|
||||||
if (priv->sock == -1)
|
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;
|
struct ctrl_iface_global_priv *priv = sock_ctx;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
int res;
|
int res;
|
||||||
struct sockaddr_un from;
|
struct sockaddr_storage from;
|
||||||
socklen_t fromlen = sizeof(from);
|
socklen_t fromlen = sizeof(from);
|
||||||
char *reply = NULL, *reply_buf = NULL;
|
char *reply = NULL, *reply_buf = NULL;
|
||||||
size_t reply_len;
|
size_t reply_len;
|
||||||
|
|
Loading…
Reference in a new issue