public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, Paul Holzinger <pholzing@redhat.com>
Subject: Re: [PATCH 3/4] icmp: Add debugging messages for handled replies and requests
Date: Thu, 27 Oct 2022 08:57:48 +1100	[thread overview]
Message-ID: <Y1mtXFMKi37M7FsE@yekko> (raw)
In-Reply-To: <20221026162531.545374-4-sbrivio@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4058 bytes --]

On Wed, Oct 26, 2022 at 06:25:30PM +0200, Stefano Brivio wrote:
> ...instead of just reporting errors.
> 
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  icmp.c | 30 +++++++++++++++++++++++++-----
>  1 file changed, 25 insertions(+), 5 deletions(-)
> 
> diff --git a/icmp.c b/icmp.c
> index 233acf9..9caa7e6 100644
> --- a/icmp.c
> +++ b/icmp.c
> @@ -88,6 +88,7 @@ void icmp_sock_handler(const struct ctx *c, union epoll_ref ref,
>  		struct icmp6hdr *ih = (struct icmp6hdr *)buf;
>  
>  		id = ntohs(ih->icmp6_identifier);
> +		seq = ntohs(ih->icmp6_sequence);
>  
>  		/* If bind() fails e.g. because of a broken SELinux policy, this
>  		 * might happen. Fix up the identifier to match the sent one.
> @@ -97,14 +98,15 @@ void icmp_sock_handler(const struct ctx *c, union epoll_ref ref,
>  
>  		/* In PASTA mode, we'll get any reply we send, discard them. */
>  		if (c->mode == MODE_PASTA) {
> -			seq = ntohs(ih->icmp6_sequence);
> -
>  			if (icmp_id_map[V6][id].seq == seq)
>  				return;
>  
>  			icmp_id_map[V6][id].seq = seq;
>  		}
>  
> +		debug("ICMPv6: echo %s to tap, ID: %i, seq: %i",
> +		      (ih->icmp6_type == 128) ? "request" : "reply", id, seq);
> +
>  		tap_icmp6_send(c, &sr6->sin6_addr,
>  			       tap_ip6_daddr(c, &sr6->sin6_addr), buf, n);
>  	} else {
> @@ -112,11 +114,12 @@ void icmp_sock_handler(const struct ctx *c, union epoll_ref ref,
>  		struct icmphdr *ih = (struct icmphdr *)buf;
>  
>  		id = ntohs(ih->un.echo.id);
> +		seq = ntohs(ih->un.echo.sequence);
> +
>  		if (id != iref->icmp.id)
>  			ih->un.echo.id = htons(iref->icmp.id);
>  
>  		if (c->mode == MODE_PASTA) {
> -			seq = ntohs(ih->un.echo.sequence);
>  
>  			if (icmp_id_map[V4][id].seq == seq)
>  				return;
> @@ -124,6 +127,9 @@ void icmp_sock_handler(const struct ctx *c, union epoll_ref ref,
>  			icmp_id_map[V4][id].seq = seq;
>  		}
>  
> +		debug("ICMP: echo %s to tap, ID: %i, seq: %i",
> +		      (ih->type == ICMP_ECHO) ? "request" : "reply", id, seq);
> +
>  		tap_icmp4_send(c, sr4->sin_addr.s_addr, tap_ip4_daddr(c),
>  			       buf, n);
>  	}
> @@ -175,14 +181,21 @@ int icmp_tap_handler(const struct ctx *c, int af, const void *addr,
>  			}
>  
>  			icmp_id_map[V4][id].sock = s;
> +
> +			debug("ICMP: new socket %i for echo ID %i", s, id);
>  		}
>  		icmp_id_map[V4][id].ts = now->tv_sec;
>  		bitmap_set(icmp_act[V4], id);
>  
>  		sa.sin_addr = *(struct in_addr *)addr;
>  		if (sendto(s, ih, sizeof(*ih) + plen, MSG_NOSIGNAL,
> -			   (struct sockaddr *)&sa, sizeof(sa)) < 0)
> +			   (struct sockaddr *)&sa, sizeof(sa)) < 0) {
>  			debug("ICMP: failed to relay request to socket");
> +		} else {
> +			debug("ICMP: echo %s to socket, ID: %i, seq: %i",
> +			      (ih->type == ICMP_ECHO) ? "request" : "reply",
> +			      id, ntohs(ih->un.echo.sequence));
> +		}
>  	} else if (af == AF_INET6) {
>  		union icmp_epoll_ref iref = { .icmp.v6 = 1 };
>  		struct sockaddr_in6 sa = {
> @@ -214,14 +227,21 @@ int icmp_tap_handler(const struct ctx *c, int af, const void *addr,
>  			}
>  
>  			icmp_id_map[V6][id].sock = s;
> +
> +			debug("ICMPv6: new socket %i for echo ID %i", s, id);
>  		}
>  		icmp_id_map[V6][id].ts = now->tv_sec;
>  		bitmap_set(icmp_act[V6], id);
>  
>  		sa.sin6_addr = *(struct in6_addr *)addr;
>  		if (sendto(s, ih, sizeof(*ih) + plen, MSG_NOSIGNAL,
> -			   (struct sockaddr *)&sa, sizeof(sa)) < 1)
> +			   (struct sockaddr *)&sa, sizeof(sa)) < 1) {
>  			debug("ICMPv6: failed to relay request to socket");
> +		} else {
> +			debug("ICMPv6: echo %s to socket, ID: %i, seq: %i",
> +			      (ih->icmp6_type == 128) ? "request" : "reply",
> +			      id, ntohs(ih->icmp6_sequence));
> +		}
>  	}
>  
>  	return 1;

-- 
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 --]

  reply	other threads:[~2022-10-26 22:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 16:25 [PATCH 0/4] Debugging improvements, fix for 0 sequence echo reply Stefano Brivio
2022-10-26 16:25 ` [PATCH 1/4] conf, passt.1: Don't imply --foreground with --debug Stefano Brivio
2022-10-26 21:52   ` David Gibson
2022-10-26 16:25 ` [PATCH 2/4] tap: Trace received (outbound) ICMP packets in debug mode, too Stefano Brivio
2022-10-26 21:55   ` David Gibson
2022-10-26 16:25 ` [PATCH 3/4] icmp: Add debugging messages for handled replies and requests Stefano Brivio
2022-10-26 21:57   ` David Gibson [this message]
2022-10-26 16:25 ` [PATCH 4/4] icmp: Don't discard first reply sequence for a given echo ID Stefano Brivio
2022-10-26 21:59   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y1mtXFMKi37M7FsE@yekko \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=pholzing@redhat.com \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).