NetBSD Problem Report #7589

Received: (qmail 5158 invoked from network); 16 May 1999 15:21:51 -0000
Message-Id: <19990516152141.865.qmail@subzero.campus.luth.se>
Date: 16 May 1999 15:21:41 -0000
From: jens@subzero.campus.luth.se
Reply-To: jnilsson@ludd.luth.se
To: gnats-bugs@gnats.netbsd.org
Subject: machine responds to wrong IP address
X-Send-Pr-Version: 3.95

>Number:         7589
>Category:       kern
>Synopsis:       machine responds to wrong IP address
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May 16 08:35:00 +0000 1999
>Closed-Date:    Sun May 16 19:35:00 +0000 1999
>Last-Modified:  Sun May 16 19:37:57 +0000 1999
>Originator:     Jens A Nilsson
>Release:        NetBSD 1.4
>Organization:

>Environment:
System: NetBSD subzero 1.4 NetBSD 1.4 (SUBZERO) #4: Sun May 16 16:37:58 CEST 1999 jens@subzero:/home/jens/netsys/sys-1.4/arch/i386/compile/SUBZERO i386


>Description:
I found a strange error in the 1.4 release. When I send pings for
130.240.16.109 through the machine, it responds to the ping even
though it's supposed to just route it. A funny thing with this
response is that the source IP is 127.0.0.1. The problem is that
the INADDR_TO_IA macro in netinet/in_var.h is broken.
>How-To-Repeat:
Set a route for 130.240.16.109 to a NetBSD 1.4 machine, it is possible
that there need to be some interfaces unconfigured on the 1.4 machine.
lo0 need to be configured to 127.0.0.1 also.
>Fix:
Change INADDR_TO_IA to:

#define INADDR_TO_IA(addr, ia) \
	/* struct in_addr addr; */ \
	/* struct in_ifaddr *ia; */ \
{ \
	for (ia = IN_IFADDR_HASH((addr).s_addr).lh_first; \
	    ia != NULL && ( \
		!in_hosteq(ia->ia_addr.sin_addr, (addr)) || \
		(ia->ia_ifp->if_flags & IFF_UP) == 0); \
	ia = ia->ia_hash.le_next) \
	continue; \
}

It's how the macro is used in ip_input.c that causes this behavior.

I'm not completely satisfied with that solution, I have a feeling
that something else is wrong too, because I have only found one IP
address that triggers the bug and that's 130.240.16.109.  I'm sure
that there are more but I can't see the pattern.
>Release-Note:
>Audit-Trail:

From: Jason Thorpe <thorpej@nas.nasa.gov>
To: jnilsson@ludd.luth.se
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/7589
Date: Sun, 16 May 1999 12:05:52 -0700

 Can you try this, please?  I agree that INADDR_TO_IA() is a little
 suspect there... Sigh, and I was the last one to touch it :(

 This should fix the problem, and also makes the macro a little more
 obvious.

         -- Jason R. Thorpe <thorpej@nas.nasa.gov>

 Index: in_var.h
 ===================================================================
 RCS file: /cvsroot/src/sys/netinet/in_var.h,v
 retrieving revision 1.33
 diff -c -r1.33 in_var.h
 *** in_var.h	1999/05/03 22:12:45	1.33
 --- in_var.h	1999/05/16 19:01:44
 ***************
 *** 153,162 ****
   	/* struct in_ifaddr *ia; */ \
   { \
   	for (ia = IN_IFADDR_HASH((addr).s_addr).lh_first; \
 ! 	    ia != NULL && !in_hosteq(ia->ia_addr.sin_addr, (addr)) && \
 ! 	    (ia->ia_ifp->if_flags & IFF_UP) == 0; \
 ! 	    ia = ia->ia_hash.le_next) \
 ! 		 continue; \
   }

   /*
 --- 153,164 ----
   	/* struct in_ifaddr *ia; */ \
   { \
   	for (ia = IN_IFADDR_HASH((addr).s_addr).lh_first; \
 ! 	     ia != NULL; \
 ! 	     ia = ia->ia_hash.le_next) { \
 ! 		if (in_hosteq(ia->ia_addr.sin_addr, (addr)) && \
 ! 		    (ia->ia_ifp->if_flags & IFF_UP) != 0) \
 ! 			break; \
 ! 	} \
   }

   /*
State-Changed-From-To: open->feedback 
State-Changed-By: thorpej 
State-Changed-When: Sun May 16 12:33:33 PDT 1999 
State-Changed-Why:  
Patch send to submitter committed.  Patch works in normal case, and should 
fix submitter's case. 

From: Jens A Nilsson <jnilsson@ludd.luth.se>
To: Jason Thorpe <thorpej@nas.nasa.gov>
Cc: jnilsson@ludd.luth.se, gnats-bugs@netbsd.org
Subject: Re: kern/7589
Date: Sun, 16 May 1999 21:25:09 +0200

 Jason Thorpe <thorpej@nas.nasa.gov>,wrote on May 16, 1999 at 12:05 -0700: 
 > Can you try this, please?  I agree that INADDR_TO_IA() is a little
 > suspect there... Sigh, and I was the last one to touch it :(
 > 
 > This should fix the problem, and also makes the macro a little more
 > obvious.
 > 
 >         -- Jason R. Thorpe <thorpej@nas.nasa.gov>
 The patch works :-) , but I'm still a bit worried that something
 strange is going on somewere.

 -- 
 mvh Jens

 NetBSD - where do you want to go Tuesday?
State-Changed-From-To: feedback->closed 
State-Changed-By: thorpej 
State-Changed-When: Sun May 16 12:35:00 PDT 1999 
State-Changed-Why:  
Submitter confirms that bug is fixed. 

From: Jason Thorpe <thorpej@nas.nasa.gov>
To: jnilsson@ludd.luth.se
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/7589 
Date: Sun, 16 May 1999 12:37:31 -0700

 On Sun, 16 May 1999 21:25:09 +0200 
  Jens A Nilsson <jnilsson@ludd.luth.se> wrote:

  > The patch works :-) , but I'm still a bit worried that something
  > strange is going on somewere.

 It's actually pretty obvious why it worked only with that IP address...

 It happened to hash to the same bucket as an IP address on your host,
 and it picked an interface with a different dest addr that happened to
 be up.

 Anyhow, I've closed the report, and sent a pullup for 1.4.1.  Thanks for the
 quick reply!

         -- Jason R. Thorpe <thorpej@nas.nasa.gov>

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.