On Thu Nov 19, 2026 at 11:49:02AM +0200, Kapetanakis Giannis wrote:
> Hi,
> 
> After upgrading a firewall/load balancer to 8.0, relayd logs warnings
> like these whenever it uses "check icmp":
> 
> Nov 19 11:31:44  relayd[50427]: recv_icmp: ping for unknown host received: 
> Operation now in progress
> Nov 19 11:31:44  relayd[50427]: recv_icmp: ping for unknown host received: 
> Undefined error: 0
> Nov 19 11:31:44  relayd[50427]: recv_icmp: ping for unknown host received: 
> Undefined error: 0
> Nov 19 11:31:44  relayd[50427]: recv_icmp: ping for unknown host received: 
> Undefined error: 0
> Nov 19 11:31:44  relayd[50427]: recv_icmp: ping for unknown host received: 
> Undefined error: 0
> Nov 19 11:31:44  relayd[50427]: recv_icmp: ping for unknown host received: 
> Undefined error: 0
> Nov 19 11:32:54  relayd[50427]: recv_icmp: ping for unknown host received: 
> Undefined error: 0
> Nov 19 11:35:44  relayd[50427]: recv_icmp: ping for unknown host received: 
> Undefined error: 0
> 
> The ICMP checks themselves keep working: hosts stay up and the check counters 
> increase.
> 
> redirect FTP-PASV {
>    listen on $mirrors port 21000:21999
>    match pftag RELAYD_mirrors
>    session timeout 7800
>    forward to <mirrors> mode source-hash "relayd" check icmp
> }
>    
> redirect FTP-PASV-v6 {
>    listen on $mirrors_v6 port 21000:21999
>    match pftag RELAYD_mirrors
>    session timeout 7800
>    forward to <mirrors_v6> mode source-hash "relayd" check icmp
> }
> relayctl show sum|grep -A3 FTP-PASV
> 9    rdr    FTP-PASV                                  active
> 9    table  mirrors:21000                             active
> 17   host   ftp1                     100.00% 600/600  up
> 18   host   ftp2                     100.00% 573/573  up
> --
> 10   rdr    FTP-PASV-v6                               active
> 10   table  mirrors_v6:21000                          active
> 19   host   ftp1_v6                  100.00% 600/600  up
> 20   host   ftp2_v6                  100.00% 573/573  up
> 
> 
> Clause tracked this to:
> 
> === claude
> check_icmp.c rev 1.51 ("use a per-host random ICMP echo id") removed
> the early filter in recv_icmp():
> 
>   -    if (icpid != cie->env->sc_id)
>   -        goto retry;
> 
> Raw ICMP sockets receive all ICMP delivered to the host, not just
> replies to relayd's pings. The sc_id check used to drop everything else
> silently. Now any foreign packet that passes the size check goes to
> host_find() with arbitrary payload bytes as the host id, fails, and hits
> the log_warn(). Since the read event is only armed during a check
> cycle, queued packets drain in a burst at each interval.
> 
> The errno text is meaningless because log_warn() is used where
> log_warnx() was intended.
> 
> How to reproduce
> ----------------
> 
> On any 8.0 host with IPv6, using a reachable IPv6 address as the
> table host:
> 
>   # cat /tmp/relayd-icmp.conf
>   table <t> { 2001:db8::10 }
>   redirect test {
>           listen on ::1 port 8080
>           forward to <t> check icmp
>   }
>   # relayd -d -f /tmp/relayd-icmp.conf
> 
> Then, in another shell on the same host, ping any IPv6 address:
> 
>   # ping6 -c 5 2001:db8::1
> 
> The echo replies are also delivered to relayd's raw ICMPv6 socket, and
> relayd logs one warning per reply at its next check cycle.
> 
> Proposed patch:
> Check the ICMP type, and treat an unknown host or an ident mismatch as
> foreign traffic, logged only at debug level. The existing address
> comparison still catches spoofed replies.
> 
> Index: check_icmp.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/relayd/check_icmp.c,v
> diff -u -p -r1.51 check_icmp.c
> --- check_icmp.c
> +++ check_icmp.c
> @@ -315,22 +315,22 @@
>  
>       if (cie->af == AF_INET) {
>               icp = (struct icmp *)(packet + sizeof(struct ip));
> +             if (icp->icmp_type != ICMP_ECHOREPLY)
> +                     goto retry;
>               icpid = icp->icmp_id;
>               id = icp->icmp_mask;
>       } else {
>               icp6 = (struct icmp6_hdr *)packet;
> +             if (icp6->icmp6_type != ICMP6_ECHO_REPLY)
> +                     goto retry;
>               icpid = icp6->icmp6_id;
>               memcpy(&id, packet + sizeof(*icp6), sizeof(id));
>       }
>       id = ntohl(id);
>       host = host_find(cie->env, id);
> -     if (host == NULL) {
> -             log_warn("%s: ping for unknown host received", __func__);
> -             goto retry;
> -     }
> -     if (icpid != host->icmp_ident) {
> -             log_warn("%s: bad icmp ident from %s", __func__,
> -                 host->conf.name);
> +     if (host == NULL || icpid != host->icmp_ident) {
> +             /* not ours: raw sockets see all ICMP delivered to the host */
> +             log_debug("%s: ignoring foreign icmp packet", __func__);
>               goto retry;
>       }
> 
> 
> === end claude
> 
> I was able to reproduce it also manually with normal ping and ping6 from the 
> host itself.
> The logs I get are coming from a remote router doing router advertisements.
> 
> Haven't tested the proposed patch at all.
> 
> regards,
> 
> Giannis


Thanks Giannis for the report. I've been able to reproduce it and the patch
is entirely correct as it stands. For debugging purposes, I added the
host from which the ICMP is coming to the log. It helps with debugging:

recv_icmp: ignoring icmp packet from 127.0.0.

OK?

diff --git a/check_icmp.c b/check_icmp.c
index 46d01fa..e17e413 100644
--- a/check_icmp.c
+++ b/check_icmp.c
@@ -287,6 +287,7 @@ recv_icmp(int s, short event, void *arg)
 {
        struct ctl_icmp_event   *cie = arg;
        u_char                   packet[ICMP_BUF_SIZE];
+       char                     hbuf[HOST_NAME_MAX + 1];
        socklen_t                slen;
        struct sockaddr_storage  ss;
        struct icmp             *icp;
@@ -315,22 +316,22 @@ recv_icmp(int s, short event, void *arg)
 
        if (cie->af == AF_INET) {
                icp = (struct icmp *)(packet + sizeof(struct ip));
+               if (icp->icmp_type != ICMP_ECHOREPLY)
+                       goto retry;
                icpid = icp->icmp_id;
                id = icp->icmp_mask;
        } else {
                icp6 = (struct icmp6_hdr *)packet;
+               if (icp6->icmp6_type != ICMP6_ECHO_REPLY)
+                       goto retry;
                icpid = icp6->icmp6_id;
                memcpy(&id, packet + sizeof(*icp6), sizeof(id));
        }
        id = ntohl(id);
        host = host_find(cie->env, id);
-       if (host == NULL) {
-               log_warn("%s: ping for unknown host received", __func__);
-               goto retry;
-       }
-       if (icpid != host->icmp_ident) {
-               log_warn("%s: bad icmp ident from %s", __func__,
-                   host->conf.name);
+       if (host == NULL || icpid != host->icmp_ident) {
+               log_debug("%s: ignoring icmp packet from %s", __func__,
+                   print_host(&ss, hbuf, sizeof(hbuf)));
                goto retry;
        }
 

Reply via email to