diff options
Diffstat (limited to 'sysdep/unix')
-rw-r--r-- | sysdep/unix/io.c | 32 | ||||
-rw-r--r-- | sysdep/unix/main.c | 3 | ||||
-rw-r--r-- | sysdep/unix/wg_user.c | 13 |
3 files changed, 43 insertions, 5 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 22c96d63..295bee16 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -797,6 +797,8 @@ sk_free(resource *r) { sock *s = (sock *) r; + log(L_TRACE "sk_free %d %d", s->fd, s->type); + sk_free_bufs(s); #ifdef HAVE_LIBSSH @@ -1520,29 +1522,50 @@ sk_open_unix(sock *s, char *name) return 0; } +static void hexdump(const char *data, socklen_t size) +{ + char buf[1024]=""; + + for (unsigned int i = 0; i < size; i++) + { + sprintf(buf + i*3, "%02x ", data[i]); + } + log(L_TRACE "sk_connect_unix: %s", buf); +} + int sk_connect_unix(sock *s, char *name, socklen_t namelen) { struct sockaddr_un sa; int fd; + log(L_TRACE "sk_connect_unix %d %s", name[0], name + 1); + if (namelen > sizeof(sa.sun_path)) return -1; + log(L_TRACE "sk_connect_unix 2"); + /* We are sloppy during error (leak fd and not set s->err), but we die anyway */ fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) - return -1; + return -2; + + log(L_TRACE "sk_connect_unix 3"); if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) - return -1; + return -3; + + log(L_TRACE "sk_connect_unix 4"); /* Path length checked in test_old_bird() */ memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; memcpy(sa.sun_path, name, namelen); + hexdump((const char*)&sa, sizeof(sa.sun_family) + namelen); + s->fd = fd; s->type = SK_UNIX_ACTIVE; s->ttx = ""; /* Force s->ttx != s->tpos */ @@ -1555,6 +1578,8 @@ sk_connect_unix(sock *s, char *name, socklen_t namelen) ERR2("connect"); } + log(L_TRACE "sk_connect_unix 5"); + sk_insert(s); /* sk_alloc_bufs(s); Shouldn't be needed with SK_UNIX_ACTIVE */ return 0; @@ -1930,7 +1955,10 @@ sk_read(sock *s, int revents) } } else if (!c) + { + if (s->type == SK_UNIX) log(L_TRACE "Unix socket nothing to read"); s->err_hook(s, 0); + } else { s->rpos += c; diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 2c7e3cef..eb5d3528 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -567,6 +567,7 @@ unlink_pid_file(void) void cmd_shutdown(void) { + log_msg(L_INFO "cmd_shutdown"); if (cli_access_restricted()) return; @@ -577,6 +578,7 @@ cmd_shutdown(void) void async_shutdown(void) { + log_msg(L_INFO "async_shutdown"); DBG("Shutting down...\n"); order_shutdown(0); } @@ -584,6 +586,7 @@ async_shutdown(void) void sysdep_shutdown_done(void) { + log_msg(L_INFO "sysdep_shutdown_done"); unlink_pid_file(); unlink(path_control_socket); log_msg(L_FATAL "Shutdown completed"); diff --git a/sysdep/unix/wg_user.c b/sysdep/unix/wg_user.c index e7144d20..62c53412 100644 --- a/sysdep/unix/wg_user.c +++ b/sysdep/unix/wg_user.c @@ -1,8 +1,11 @@ +#define LOCAL_DEBUG + #include <stdio.h> #include <stdbool.h> #include <sys/stat.h> #include <sys/un.h> #include <unistd.h> +#include <errno.h> #include "lib/lists.h" #include "lib/ip.h" #include "lib/socket.h" @@ -42,6 +45,7 @@ bool wg_has_userspace(const char *ifname) else { DBG(L_TRACE "WG: no socket %s", tmp); + log(L_TRACE "WG: no socket %s", tmp); return false; } } @@ -50,7 +54,9 @@ bool wg_has_userspace(const char *ifname) static int user_rx_hook(struct birdsock *sk UNUSED, uint size UNUSED) { - DBG(L_TRACE "WG: RX %p %d", sk, size); + char buf[1024]=""; + strncpy(buf, sk->rbuf, size); + log(L_TRACE "WG: RX %p %d '%s'", sk, size, buf); rfree(sk); return 1; } @@ -58,7 +64,7 @@ int user_rx_hook(struct birdsock *sk UNUSED, uint size UNUSED) static void user_tx_hook(struct birdsock *bs) { - DBG(L_TRACE "WG: TX %p %d", bs, bs->tpos - bs->ttx); + log(L_TRACE "WG: TX %p %d", bs, bs->tpos - bs->ttx); uint size = (uintptr_t)bs->data; @@ -263,7 +269,7 @@ wg_user_set_device(struct pool *pool, uint size = tbsize; int len = user_put_device(dev, &pos, &size); - DBG(L_TRACE "WG: put %d %s", size, sock->tbuf); + log(L_TRACE "WG: put %d %d %s", len, size, sock->tbuf); if (len < 0) { @@ -274,6 +280,7 @@ wg_user_set_device(struct pool *pool, sock->data = (void*)(uintptr_t)size; int res = sk_connect_unix(sock, path, pathlen); + log(L_TRACE "WG: socket %s %d %d %d %s %d %s %d", res<0?strerror(errno):NULL, res, res<0?errno:0, sock->fd, ifname, path[0], path + 1, pathlen); DBG(L_TRACE "WG: socket %d %d %s", res, sock->fd, path); if (res < 0) { |