vlan(4) interfaces have wrong interface type in sockaddr_dl
address
John Baldwin
jhb at freebsd.org
Tue Aug 3 17:06:49 UTC 2010
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
More information about the freebsd-net
mailing list