Subject: Re: ifp->if_addrlen uninitialized in if_attach()
To: <>
From: Ignatios Souvatzis <is@jocelyn.rhein.de>
List: tech-net
Date: 08/25/1999 21:19:01
On Wed, Aug 25, 1999 at 11:01:04AM +0200, Andreas Johansson wrote:
> Hello!
>
> I have discovered a potential problem in NetBSD 1.3 & 1.4. The problem is
> that if_attach() in net/if.c uses the mac address size ifp->if_addrlen to
> setup the size of the interface's sockaddr_dl structure like this:
>
> namelen = strlen(ifp->if_xname);
> masklen = offsetof(struct sockaddr_dl, sdl_data[0]) + namelen;
> socksize = masklen + ifp->if_addrlen;
> #define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
> if (socksize < sizeof(*sdl))
> socksize = sizeof(*sdl);
> socksize = ROUNDUP(socksize);
> [...]
> sdl->sdl_len = socksize;
>
> But unfortunately, ifp->if_addrlen is setup in ether_ifattach() (or the
> corresponding function for other interface types). This function must be
> called after if_attach(), and therefore if_addrlen is uninitialized by the
> time if_attach() uses it.
Looks like I'm the culprit, from back then when I reworked the ARP stuff.
Hm.
we need the sizes before if_attach(), and to write back the link level
address after it.
I see three possibilities...
- call ether_ifattach before AND after (won't do any harm)
- split it into two, and call the before part before, and something
like ether_writelladdr() after
- _only_ call ether_ifattach(), and make ether_ifattach() call if_attach()
at an appropriate moment.
(similar would have to be done for token,fddi and arc.)
what do people think?
-is