From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 531D95A0271 for ; Fri, 8 Mar 2024 07:06:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709878014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z7uF51uSChBNoFTiCXUeJfjO4mKV+5uNRtadS7C1jZw=; b=ELcHraitRa+VjytkZRww9KHr83ZbkOmhBejvvXQFDVo4UZ0hqQn01Vi6H5bcTFFjPL+o4a 3XnbLvswaxA4F32FjAIYPRKMtyJ9eSTCKmw+vF7iUmnywOCUAkNMZIhSLy5JHn6wAOiaLF lu0EpAhve12HiQZBOBTm9eH59KhBDDQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-c9p-Yu83PUiBHYhXw5WkUQ-1; Fri, 08 Mar 2024 01:06:52 -0500 X-MC-Unique: c9p-Yu83PUiBHYhXw5WkUQ-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5670557f9aeso213430a12.3 for ; Thu, 07 Mar 2024 22:06:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709878011; x=1710482811; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Z7uF51uSChBNoFTiCXUeJfjO4mKV+5uNRtadS7C1jZw=; b=b3ibVRbxqsgh9xfk+gCyfxp2W+iaFu9DBEmPNzvkpqQO6/l3U4w5y7FE1a4DlOQowB e7tD7YEgm0j8vMxn5La4uVnKory4Uf+NyQGqkVSX9EKI8VRiqcdEUBmDynWGh8vLr71c /42qAV6MxK7SdQ6gJg2Uwnd98jkswMYbcjXHmTYr7waZlHDnUaHEMo1mqlicWgEAVnfV epWEpa5Q1YNqCxfL+VvkqfDBQ4BuVchqvP9PdY+RStOUvyZga2Cjm0Ebo+1Y6dD0eEEA CdDU+HWo3R3XyGcqCUwI++NCpNpOphyr06fR522jBqOObgTCzqHZmCbC/LhBiQahDEPn VbeA== X-Gm-Message-State: AOJu0YwQshqJQ3kYEc1YxNPBpIrBYyXTHC/TJYY+/yVV8FjY9UAw/BMr XL/LN05YaKcDqmtvURuL+AWI/qqiv9FSfzAoL3+WtlNjlyb8UEhntQZsU4BVZ0EJZm9VD/HeNaM oZVyn9ZEXhLWuqLU4im/ZxBJd1ZJ3kwN3UMleQ6YRm+x2OlKBnQP/qxY5dO3i X-Received: by 2002:a50:a446:0:b0:568:1f9f:eca4 with SMTP id v6-20020a50a446000000b005681f9feca4mr1025971edb.42.1709878010781; Thu, 07 Mar 2024 22:06:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6xgfSKbh8w54bGtuOxiTqjvnnqxdHk5zpC11NpY740HB9fNNoxKILJFIZiG92e2sgckqiSg== X-Received: by 2002:a50:a446:0:b0:568:1f9f:eca4 with SMTP id v6-20020a50a446000000b005681f9feca4mr1025963edb.42.1709878010285; Thu, 07 Mar 2024 22:06:50 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id ef12-20020a05640228cc00b005671d898b32sm6271022edb.23.2024.03.07.22.06.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2024 22:06:49 -0800 (PST) Date: Fri, 8 Mar 2024 07:06:15 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/3] icmp: Flow based error reporting Message-ID: <20240308070615.2f1fd6e9@elisabeth> In-Reply-To: References: <20240229041534.2573559-1-david@gibson.dropbear.id.au> <20240229041534.2573559-3-david@gibson.dropbear.id.au> <20240308002640.15b631b9@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: U3QUKBDU2WP3MARZ73XSU2YEBURQNLZC X-Message-ID-Hash: U3QUKBDU2WP3MARZ73XSU2YEBURQNLZC X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri, 8 Mar 2024 11:49:27 +1100 David Gibson wrote: > On Fri, Mar 08, 2024 at 12:26:40AM +0100, Stefano Brivio wrote: > > On Thu, 29 Feb 2024 15:15:33 +1100 > > David Gibson wrote: > > > > > Use flow_dbg() and flow_err() helpers to generate flow-linked error > > > messages in most places. Make a few small improvements to the messages > > > while we're at it. This allows us to avoid the awkward 'pname' variables > > > since whether we're dealing with ICMP or ICMPv6 is already built into the > > > flow type which these helpers include. > > > > > > Signed-off-by: David Gibson > > > --- > > > icmp.c | 31 ++++++++++++++----------------- > > > 1 file changed, 14 insertions(+), 17 deletions(-) > > > > > > diff --git a/icmp.c b/icmp.c > > > index 1caf791d..63adafcf 100644 > > > --- a/icmp.c > > > +++ b/icmp.c > > > @@ -61,7 +61,6 @@ void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref) > > > { > > > struct icmp_ping_flow *pingf = af == AF_INET > > > ? icmp_id_map[V4][ref.icmp.id] : icmp_id_map[V6][ref.icmp.id]; > > > - const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6"; > > > union sockaddr_inany sr; > > > socklen_t sl = sizeof(sr); > > > char buf[USHRT_MAX]; > > > @@ -75,8 +74,7 @@ void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref) > > > > > > n = recvfrom(ref.fd, buf, sizeof(buf), 0, &sr.sa, &sl); > > > if (n < 0) { > > > - warn("%s: recvfrom() error on ping socket: %s", > > > - pname, strerror(errno)); > > > + flow_err(pingf, "recvfrom() error: %s", strerror(errno)); > > > return; > > > } > > > if (sr.sa_family != af) > > > @@ -113,8 +111,9 @@ void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref) > > > pingf->seq = seq; > > > } > > > > > > - debug("%s: echo reply to tap, ID: %"PRIu16", seq: %"PRIu16, pname, > > > - ref.icmp.id, seq); > > > + flow_dbg(pingf, "echo reply to tap, ID: %"PRIu16", seq: %"PRIu16, > > > + ref.icmp.id, seq); > > > + > > > if (af == AF_INET) > > > tap_icmp4_send(c, sr.sa4.sin_addr, tap_ip4_daddr(c), buf, n); > > > else if (af == AF_INET6) > > > @@ -123,7 +122,7 @@ void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref) > > > return; > > > > > > unexpected: > > > - warn("%s: Unexpected packet on ping socket", pname); > > > + flow_err(pingf, "Unexpected packet on ping socket"); > > > } > > > > > > /** > > > @@ -158,7 +157,6 @@ static struct icmp_ping_flow *icmp_ping_new(const struct ctx *c, > > > struct icmp_ping_flow **id_sock, > > > sa_family_t af, uint16_t id) > > > { > > > - const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6"; > > > uint8_t flowtype = af == AF_INET ? FLOW_PING4 : FLOW_PING6; > > > union icmp_epoll_ref iref = { .id = id }; > > > union flow *flow = flow_alloc(); > > > @@ -195,9 +193,9 @@ static struct icmp_ping_flow *icmp_ping_new(const struct ctx *c, > > > if (pingf->sock > FD_REF_MAX) > > > goto cancel; > > > > > > - *id_sock = pingf; > > > + flow_dbg(pingf, "new socket %i for echo ID %"PRIu16, pingf->sock, id); > > > > > > - debug("%s: new socket %i for echo ID %"PRIu16, pname, pingf->sock, id); > > > + *id_sock = pingf; > > > > > > return pingf; > > > > > > @@ -222,7 +220,6 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > > > const void *saddr, const void *daddr, > > > const struct pool *p, const struct timespec *now) > > > { > > > - const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6"; > > > union sockaddr_inany sa = { .sa_family = af }; > > > const socklen_t sl = af == AF_INET ? sizeof(sa.sa4) : sizeof(sa.sa6); > > > struct icmp_ping_flow *pingf, **id_sock; > > > @@ -276,13 +273,13 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > > > > > > pingf->ts = now->tv_sec; > > > > > > - if (sendto(pingf->sock, pkt, plen, MSG_NOSIGNAL, &sa.sa, sl) < 0) { > > > - debug("%s: failed to relay request to socket: %s", > > > - pname, strerror(errno)); > > > - } else { > > > - debug("%s: echo request to socket, ID: %"PRIu16", seq: %"PRIu16, > > > - pname, id, seq); > > > - } > > > + if (sendto(pingf->sock, pkt, plen, MSG_NOSIGNAL, &sa.sa, sl) < 0) > > > + flow_dbg(pingf, "failed to relay request to socket: %s", > > > + strerror(errno)); > > > + else > > > + flow_dbg(pingf, > > > + "echo request to socket, ID: %"PRIu16", seq: %"PRIu16, > > > + id, seq); > > > > I can add the usual curly brackets on merge. The rest of the series > > looks good to me. > > Thanks. It may take me a minute to internalise the "braces if > 1 > physical line" rule. It took me years. I mean, we don't have to adhere to "Linux -net" style, but it has a couple of advantages such as being somewhat formalised and the existence of checkpatch.pl. I also happen to be familiar with it. If we decide not to, though, then we should probably fix up everything at once. -- Stefano