Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Apr 2008 15:29:10 +0900
From:      gnn@freebsd.org
To:        vijay singh <vijjus@rocketmail.com>
Cc:        freebsd-net@freebsd.org
Subject:   Re: Regarding if_alloc()
Message-ID:  <m2iqyfptft.wl%gnn@neville-neil.com>
In-Reply-To: <490341.95478.qm@web33501.mail.mud.yahoo.com>
References:  <490341.95478.qm@web33501.mail.mud.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
At Thu, 17 Apr 2008 18:35:23 -0700 (PDT),
vijay singh wrote:
> 
> Hi all. How do we avoid a race in populating the ifindex_table? Id
> this is a TODO, as it seems from the code below, would it be
> acceptable if I wrote a patch and reused the ifnet_lock
> [IFNET_WLOCK, IFNET_WUNLOCK]?
> 

It is almost always acceptable to submit a patch :-)

> 
> if_alloc(u_char type)
> {
>     struct ifnet *ifp;
> 
>     ifp = malloc(sizeof(struct ifnet), M_IFNET, M_WAITOK|M_ZERO);
> 
>     /*
>      * Try to find an empty slot below if_index.  If we fail, take
>      * the next slot.
>      *
>      * XXX: should be locked!
>      */
>     for (ifp->if_index = 1; ifp->if_index <= if_index; ifp->if_index++) {
>         if (ifnet_byindex(ifp->if_index) == NULL)
>             break;
>     }
> 
> 

There are still parts of the network device infrastructure that need
some locking, and it would seem that this is one of them.  I know
Brooks Davis was also looking at this stuff so he may comment as well.

Best,
George



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m2iqyfptft.wl%gnn>