* [PATCH] tap: Add informational messages for UNIX domain socket connections
@ 2022-06-16 13:10 Stefano Brivio
2022-06-17 3:17 ` David Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2022-06-16 13:10 UTC (permalink / raw)
To: passt-dev
[-- Attachment #1: Type: text/plain, Size: 1366 bytes --]
...namely, as connections are discarded or accepted. This was quite
useful to debug an issue with libvirtd failing to start qemu (because
passt refused the new connection) as a previous qemu instance was
still active.
Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
tap.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/tap.c b/tap.c
index 04ceade..23414db 100644
--- a/tap.c
+++ b/tap.c
@@ -856,12 +856,19 @@ static void tap_sock_unix_new(struct ctx *c)
{
struct epoll_event ev = { 0 };
int v = INT_MAX / 2;
+ struct ucred ucred;
+ socklen_t len;
+
+ len = sizeof(ucred);
/* Another client is already connected: accept and close right away. */
if (c->fd_tap != -1) {
int discard = accept4(c->fd_tap_listen, NULL, NULL,
SOCK_NONBLOCK);
+ if (!getsockopt(discard, SOL_SOCKET, SO_PEERCRED, &ucred, &len))
+ info("discardingq connection from PID %i", ucred.pid);
+
if (discard != -1)
close(discard);
@@ -870,6 +877,9 @@ static void tap_sock_unix_new(struct ctx *c)
c->fd_tap = accept4(c->fd_tap_listen, NULL, NULL, 0);
+ if (!getsockopt(c->fd_tap, SOL_SOCKET, SO_PEERCRED, &ucred, &len))
+ info("accepted connection from PID %i", ucred.pid);
+
if (!c->low_rmem &&
setsockopt(c->fd_tap, SOL_SOCKET, SO_RCVBUF, &v, sizeof(v)))
trace("tap: failed to set SO_RCVBUF to %i", v);
--
@@ -856,12 +856,19 @@ static void tap_sock_unix_new(struct ctx *c)
{
struct epoll_event ev = { 0 };
int v = INT_MAX / 2;
+ struct ucred ucred;
+ socklen_t len;
+
+ len = sizeof(ucred);
/* Another client is already connected: accept and close right away. */
if (c->fd_tap != -1) {
int discard = accept4(c->fd_tap_listen, NULL, NULL,
SOCK_NONBLOCK);
+ if (!getsockopt(discard, SOL_SOCKET, SO_PEERCRED, &ucred, &len))
+ info("discardingq connection from PID %i", ucred.pid);
+
if (discard != -1)
close(discard);
@@ -870,6 +877,9 @@ static void tap_sock_unix_new(struct ctx *c)
c->fd_tap = accept4(c->fd_tap_listen, NULL, NULL, 0);
+ if (!getsockopt(c->fd_tap, SOL_SOCKET, SO_PEERCRED, &ucred, &len))
+ info("accepted connection from PID %i", ucred.pid);
+
if (!c->low_rmem &&
setsockopt(c->fd_tap, SOL_SOCKET, SO_RCVBUF, &v, sizeof(v)))
trace("tap: failed to set SO_RCVBUF to %i", v);
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tap: Add informational messages for UNIX domain socket connections
2022-06-16 13:10 [PATCH] tap: Add informational messages for UNIX domain socket connections Stefano Brivio
@ 2022-06-17 3:17 ` David Gibson
0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2022-06-17 3:17 UTC (permalink / raw)
To: passt-dev
[-- Attachment #1: Type: text/plain, Size: 1712 bytes --]
On Thu, Jun 16, 2022 at 03:10:47PM +0200, Stefano Brivio wrote:
> ...namely, as connections are discarded or accepted. This was quite
> useful to debug an issue with libvirtd failing to start qemu (because
> passt refused the new connection) as a previous qemu instance was
> still active.
>
> Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
> ---
> tap.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/tap.c b/tap.c
> index 04ceade..23414db 100644
> --- a/tap.c
> +++ b/tap.c
> @@ -856,12 +856,19 @@ static void tap_sock_unix_new(struct ctx *c)
> {
> struct epoll_event ev = { 0 };
> int v = INT_MAX / 2;
> + struct ucred ucred;
> + socklen_t len;
> +
> + len = sizeof(ucred);
>
> /* Another client is already connected: accept and close right away. */
> if (c->fd_tap != -1) {
> int discard = accept4(c->fd_tap_listen, NULL, NULL,
> SOCK_NONBLOCK);
>
> + if (!getsockopt(discard, SOL_SOCKET, SO_PEERCRED, &ucred, &len))
> + info("discardingq connection from PID %i", ucred.pid);
> +
"discardingq"
> if (discard != -1)
> close(discard);
>
> @@ -870,6 +877,9 @@ static void tap_sock_unix_new(struct ctx *c)
>
> c->fd_tap = accept4(c->fd_tap_listen, NULL, NULL, 0);
>
> + if (!getsockopt(c->fd_tap, SOL_SOCKET, SO_PEERCRED, &ucred, &len))
> + info("accepted connection from PID %i", ucred.pid);
> +
> if (!c->low_rmem &&
> setsockopt(c->fd_tap, SOL_SOCKET, SO_RCVBUF, &v, sizeof(v)))
> trace("tap: failed to set SO_RCVBUF to %i", v);
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-17 3:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 13:10 [PATCH] tap: Add informational messages for UNIX domain socket connections Stefano Brivio
2022-06-17 3:17 ` David Gibson
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).