From owner-freebsd-net@FreeBSD.ORG Tue Aug 3 17:06:49 2010 Return-Path: Delivered-To: net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 99BA41065672 for ; Tue, 3 Aug 2010 17:06:49 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 54BFB8FC12 for ; Tue, 3 Aug 2010 17:06:49 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id C0D8B46B53 for ; Tue, 3 Aug 2010 13:06:48 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 06A3C8A03C for ; Tue, 3 Aug 2010 13:06:48 -0400 (EDT) From: John Baldwin To: net@freebsd.org Date: Tue, 3 Aug 2010 12:17:27 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100217; KDE/4.4.5; amd64; ; ) References: <201008031029.11284.jhb@freebsd.org> In-Reply-To: <201008031029.11284.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201008031217.27479.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Tue, 03 Aug 2010 13:06:48 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Subject: Re: vlan(4) interfaces have wrong interface type in sockaddr_dl address X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Aug 2010 17:06:49 -0000 On Tuesday, August 03, 2010 10:29:11 am John Baldwin wrote: > Currently vlan(4) interfaces have an interface type of IFT_ETHER instead of > IFT_L2VLAN in the sockaddr_dl that is returned by getifaddrs(3). If you do a > route lookup for a route that goes across a vlan then the sockaddr_dl > generated for the routing message will specify IFT_L2VLAN (you can see it as > 'arp -a' shows [vlan] instead of [ethernet] for those routes). However, the > address returned via getifaddrs(3) has a type of IFT_ETHER. I think this is a > bug of omission in that the vlan attach code needs to update the sockaddr_dl > that is initialized in ether_ifattach(). This patch does that and fixes > getifaddrs(3). Any objections? A few places in userland also need fixing to catch up to this I think. I did not patch getnameinfo(3) in libc since it explicitly claims in the comments that IFT_L2VLAN interfaces have a zero-length address (even though this claim is false in practice). Updated patch: Index: sys/net/if_vlan.c =================================================================== --- sys/net/if_vlan.c (revision 211312) +++ sys/net/if_vlan.c (working copy) @@ -640,6 +640,8 @@ struct ifvlan *ifv; struct ifnet *ifp; struct ifnet *p; + struct ifaddr *ifa; + struct sockaddr_dl *sdl; struct vlanreq vlr; static const u_char eaddr[ETHER_ADDR_LEN]; /* 00:00:00:00:00:00 */ @@ -738,6 +740,9 @@ ifp->if_baudrate = 0; ifp->if_type = IFT_L2VLAN; ifp->if_hdrlen = ETHER_VLAN_ENCAP_LEN; + ifa = ifp->if_addr; + sdl = (struct sockaddr_dl *)ifa->ifa_addr; + sdl->sdl_type = IFT_L2VLAN; if (ethertag) { error = vlan_config(ifv, p, tag); Index: sbin/ifconfig/af_link.c =================================================================== --- sbin/ifconfig/af_link.c (revision 211312) +++ sbin/ifconfig/af_link.c (working copy) @@ -58,7 +58,9 @@ struct sockaddr_dl *sdl = (struct sockaddr_dl *) ifa->ifa_addr; if (sdl != NULL && sdl->sdl_alen > 0) { - if (sdl->sdl_type == IFT_ETHER && + if ((sdl->sdl_type == IFT_ETHER || + sdl->sdl_type == IFT_L2VLAN || + sdl->sdl_type == IFT_BRIDGE) && sdl->sdl_alen == ETHER_ADDR_LEN) printf("\tether %s\n", ether_ntoa((struct ether_addr *)LLADDR(sdl))); Index: usr.sbin/ndp/ndp.c =================================================================== --- usr.sbin/ndp/ndp.c (revision 211312) +++ usr.sbin/ndp/ndp.c (working copy) @@ -433,6 +433,7 @@ switch (sdl->sdl_type) { case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023: case IFT_ISO88024: case IFT_ISO88025: + case IFT_L2VLAN: case IFT_BRIDGE: goto overwrite; } } Index: usr.sbin/ppp/ipv6cp.c =================================================================== --- usr.sbin/ppp/ipv6cp.c (revision 211312) +++ usr.sbin/ppp/ipv6cp.c (working copy) @@ -148,6 +148,7 @@ switch(sdl->sdl_type) { case IFT_ETHER: case IFT_FDDI: + case IFT_L2VLAN: /* XXX need more cases? */ break; default: -- John Baldwin