NetBSD Problem Report #44412

From oscar@beastie-1.foobar  Tue Jan 18 16:48:35 2011
Return-Path: <oscar@beastie-1.foobar>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 83E6463B883
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 18 Jan 2011 16:48:35 +0000 (UTC)
Message-Id: <20110118153129.AD13279606@beastie-1.foobar>
Date: Tue, 18 Jan 2011 10:31:29 -0500 (EST)
From: fraveydank@gmail.com
Reply-To: fraveydank@gmail.com
To: gnats-bugs@gnats.NetBSD.org
Subject: Appletalk interface addressing problem; fix available
X-Send-Pr-Version: 3.95

>Number:         44412
>Category:       kern
>Synopsis:       Appletalk packets sent via interface to own address do not loop back
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    hauke
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 18 16:50:00 +0000 2011
>Closed-Date:    Sun Apr 22 17:49:45 +0000 2012
>Last-Modified:  Sun Apr 22 17:49:45 +0000 2012
>Originator:     David Riley
>Release:        NetBSD 5.0.2 (src from release; still unchanged in CVS)
>Organization:
>Environment:
System: NetBSD beastie-1.foobar 5.0.2 NetBSD 5.0.2 (BEASTIE) #37: Fri Aug 13 19:05:00 EDT 2010 oscar@beastie-1.foobar:/usr/src/sys/arch/macppc/compile/BEASTIE macppc
Architecture: powerpc
Machine: macppc
>Description:
When packets (e.g. name registration packets) are sent via an interface to the interface address (e.g. mc0 is appletalk addr 42.42 and a packet is sent to 42.42), the packet is sent out over the interface (mc0 in this example) instead of loopback (inet, for example, is sent over lo0 in a similar case).

Broadcasts have a similar problem; they are not copied to the loopback, and on
occasion, the stack needs to hear its own broadcasts (e.g. for NBP name lookups).


>How-To-Repeat:
Install netatalk and start up atalkd.  It will fail to register.  tcpdump will show the registration packets going out over the interface, but not being received.  Further debugging of the kernel will find the packets going out over the external interface but never coming back.

>Fix:
I've fixed the problem and have a patch once it's cleaned up, but I'm not sure how to submit it properly other than just pasting the diff in, nor am I sure I've gone about this the entirely right way; inet does all this in if_arp in the RESOLVE section of arp_rtrequest, whereas I fixed ddp_route to switch the ifp for the first case (sending to the interface's own address) to lo0ifp and just copy the packet to lo0ifp for the second case (similar to how the IP stack does for broadcast/multicast data).

Patch will be made available soon once I've backed out all my debug printf()s and made sure it works applied to a clean source tree.

>Release-Note:

>Audit-Trail:
From: Hauke Fath <hauke@Espresso.Rhein-Neckar.DE>
To: gnats-bugs@netbsd.org
Cc: Hauke Fath <hauke@Espresso.Rhein-Neckar.DE>
Subject: Re: kern/44412: Appletalk interface addressing problem; fix available
Date: Tue, 13 Dec 2011 21:11:27 +0100

 [ Submitting the patch posted by the originator of the PR under
 <http://mail-index.NetBSD.org/tech-kern/2011/07/22/msg010980.html> ]

 Index: netatalk/aarp.c
 ===================================================================
 RCS file: /cvsroot/src/sys/netatalk/aarp.c,v
 retrieving revision 1.35
 diff -u -r1.35 aarp.c
 --- netatalk/aarp.c	8 May 2011 13:51:31 -0000	1.35
 +++ netatalk/aarp.c	10 Jul 2011 14:20:11 -0000
 @@ -222,10 +222,18 @@
  		ea->aarp_tpa = sat->sat_addr.s_node;
  	}

 +	/* If we're talking to ourselves, use the loopback interface. */
 +	if(AA_SAT(aa)->sat_addr.s_net == sat->sat_addr.s_net &&
 +	   AA_SAT(aa)->sat_addr.s_node == sat->sat_addr.s_node)
 +	   ifp = lo0ifp;
 +
  #ifdef NETATALKDEBUG
 -	printf("aarp: sending request via %u.%u seaking %u.%u\n",
 -	    ntohs(AA_SAT(aa)->sat_addr.s_net), AA_SAT(aa)->sat_addr.s_node,
 -	    ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node);
 +	printf("aarp: sending request via %u.%u through %s seeking %u.%u\n",
 +            ntohs(AA_SAT(aa)->sat_addr.s_net),
 +            AA_SAT(aa)->sat_addr.s_node,
 +	    ifp->if_xname,
 +            ntohs(sat->sat_addr.s_net),
 +            sat->sat_addr.s_node);
  #endif	/* NETATALKDEBUG */

  	sa.sa_len = sizeof(struct sockaddr);
 Index: netatalk/ddp_output.c
 ===================================================================
 RCS file: /cvsroot/src/sys/netatalk/ddp_output.c,v
 retrieving revision 1.14
 diff -u -r1.14 ddp_output.c
 --- netatalk/ddp_output.c	6 Apr 2008 18:46:56 -0000	1.14
 +++ netatalk/ddp_output.c	10 Jul 2011 14:20:11 -0000
 @@ -128,20 +128,43 @@
  	struct elaphdr *elh;
  	struct at_ifaddr *aa = NULL;
  	struct ifnet   *ifp = NULL;
 -	u_short         net;
 +	uint16_t        net;
 +	uint8_t         node;
 +	uint8_t         loopback = 0;

  	if ((rt = rtcache_validate(ro)) != NULL && (ifp = rt->rt_ifp) != NULL) {
 +		const struct sockaddr_at *dst = satocsat(rtcache_getdst(ro));
 +		uint16_t dnet = dst->sat_addr.s_net;
 +		uint8_t dnode = dst->sat_addr.s_node;
  		net = satosat(rt->rt_gateway)->sat_addr.s_net;
 +		node = satosat(rt->rt_gateway)->sat_addr.s_node;
 +
  		TAILQ_FOREACH(aa, &at_ifaddr, aa_list) {
 -			if (aa->aa_ifp == ifp &&
 -			    ntohs(net) >= ntohs(aa->aa_firstnet) &&
 +			if (ntohs(net) >= ntohs(aa->aa_firstnet) &&
  			    ntohs(net) <= ntohs(aa->aa_lastnet)) {
 +				/* Are we talking to ourselves? */
 +				if(dnet == aa->aa_addr.sat_addr.s_net &&
 +				   dnode == aa->aa_addr.sat_addr.s_node)
 +				{
 +					/* If to us, redirect to lo0. */
 +					ifp = lo0ifp;
 +				}
 +				/* Or is it a broadcast? */
 +				else if(dnet == aa->aa_addr.sat_addr.s_net &&
 +					dnode == 255)
 +				{
 +					/* If broadcast, loop back a copy. */
 +					loopback = 1;
 +				}
  				break;
  			}
  		}
  	}
  	if (aa == NULL) {
 +		#ifdef NETATALKDEBUG
  		printf("%s: no address found\n", __func__);
 +		#endif
 +
  		m_freem(m);
  		return EINVAL;
  	}
 @@ -184,5 +207,16 @@
  #endif

  	/* XXX */
 +	if(loopback && rtcache_getdst(ro)->sa_family == AF_APPLETALK)
 +	{
 +		struct mbuf *copym = m_copypacket(m, M_DONTWAIT);
 +		
 +		#ifdef NETATALKDEBUG
 +		printf("Looping back (not AARP).\n");
 +		#endif
 +
 +		looutput(lo0ifp, copym, rtcache_getdst(ro), NULL);
 +	}
 +
  	return (*ifp->if_output)(ifp, m, (struct sockaddr *)&gate, NULL);
  }

From: Georg Schwarz <georg.schwarz@freenet.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/44412
Date: Sat, 31 Dec 2011 19:13:48 +0100

 for the record: I used the patch on a stock 5.1 kernel, and it resolved =
 the bug (still present in 5.1) of Netatalk not talking to an EtherTalk =
 printer on the LAN. Things just worked as described by the original =
 problem reporter. This was done on an i386 as well as on an amd64 =
 installation (in Virtualbox, but that shouldn't matter).



From: "Hauke Fath" <hauke@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/44412 CVS commit: src/sys/netatalk
Date: Tue, 31 Jan 2012 09:53:44 +0000

 Module Name:	src
 Committed By:	hauke
 Date:		Tue Jan 31 09:53:44 UTC 2012

 Modified Files:
 	src/sys/netatalk: aarp.c ddp_output.c

 Log Message:
 Fix AppleTalk name registration, as discussed on the port-macppc list
 <http://mail-index.netbsd.org/port-macppc/2010/07/09/msg001119.html>
 and in PR kern/44412, by looping back ddp broadcasts.

 Patch submitted by David Riley against netbsd-5, adaptation for
 -current and minor KNF touchup by me.

 Needs to be pulled up to netbsd-5.


 To generate a diff of this commit:
 cvs rdiff -u -r1.35 -r1.36 src/sys/netatalk/aarp.c
 cvs rdiff -u -r1.15 -r1.16 src/sys/netatalk/ddp_output.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->pending-pullups
State-Changed-By: hauke@NetBSD.org
State-Changed-When: Tue, 31 Jan 2012 09:57:43 +0000
State-Changed-Why:
I applied the submitted patch to -current.
It needs to be pulled up to netbsd-5.

Thanks for the PR and the patch!


Responsible-Changed-From-To: kern-bug-people->hauke
Responsible-Changed-By: hauke@NetBSD.org
Responsible-Changed-When: Tue, 31 Jan 2012 09:59:07 +0000
Responsible-Changed-Why:
I'll take that.


From: "Jeff Rizzo" <riz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/44412 CVS commit: [netbsd-5] src/sys/netatalk
Date: Sat, 21 Apr 2012 16:03:28 +0000

 Module Name:	src
 Committed By:	riz
 Date:		Sat Apr 21 16:03:27 UTC 2012

 Modified Files:
 	src/sys/netatalk [netbsd-5]: aarp.c ddp_output.c

 Log Message:
 Pull up following revision(s) (requested by hauke in ticket #1749):
 	sys/netatalk/aarp.c: revision 1.36
 	sys/netatalk/ddp_output.c: revision 1.16
 Fix AppleTalk name registration, as discussed on the port-macppc list
 <http://mail-index.netbsd.org/port-macppc/2010/07/09/msg001119.html>
 and in PR kern/44412, by looping back ddp broadcasts.
 Patch submitted by David Riley against netbsd-5, adaptation for
 -current and minor KNF touchup by me.
 Needs to be pulled up to netbsd-5.


 To generate a diff of this commit:
 cvs rdiff -u -r1.27.12.1 -r1.27.12.2 src/sys/netatalk/aarp.c
 cvs rdiff -u -r1.14 -r1.14.14.1 src/sys/netatalk/ddp_output.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 22 Apr 2012 17:49:45 +0000
State-Changed-Why:
pulled up.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.