framework to add af-dependent data structure to struct ifnet.

as discussed at bsd-api-discuss.  sync w/kame
This commit is contained in:
itojun 2002-05-27 02:53:49 +00:00
parent 44e7d056da
commit e5aa199677
3 changed files with 25 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.105 2002/05/23 21:34:39 matt Exp $ */
/* $NetBSD: if.c,v 1.106 2002/05/27 02:53:49 itojun Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@ -101,7 +101,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.105 2002/05/23 21:34:39 matt Exp $");
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.106 2002/05/27 02:53:49 itojun Exp $");
#include "opt_inet.h"
@ -359,6 +359,7 @@ if_attach(ifp)
{
static size_t if_indexlim = 0;
int indexlim = 0;
struct domain *dp;
if (if_indexlim == 0) {
TAILQ_INIT(&ifnet);
@ -465,6 +466,14 @@ if_attach(ifp)
ifp->if_xname);
#endif
/* address family dependent data region */
memset(ifp->if_afdata, 0, sizeof(ifp->if_afdata));
for (dp = domains; dp; dp = dp->dom_next) {
if (dp->dom_ifattach)
ifp->if_afdata[dp->dom_family] =
(*dp->dom_ifattach)(ifp);
}
/* Announce the interface. */
rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
}
@ -599,6 +608,12 @@ if_detach(ifp)
(void) (*rnh->rnh_walktree)(rnh, if_rt_walktree, ifp);
}
for (dp = domains; dp; dp = dp->dom_next) {
if (dp->dom_ifdetach && ifp->if_afdata[dp->dom_family])
(*dp->dom_ifdetach)(ifp,
ifp->if_afdata[dp->dom_family]);
}
/* Announce that the interface is gone. */
rt_ifannouncemsg(ifp, IFAN_DEPARTURE);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.h,v 1.76 2002/05/23 21:34:40 matt Exp $ */
/* $NetBSD: if.h,v 1.77 2002/05/27 02:53:49 itojun Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@ -286,6 +286,8 @@ struct ifnet { /* and the entries */
*/
int if_csum_flags_tx; /* M_CSUM_* flags for Tx */
int if_csum_flags_rx; /* M_CSUM_* flags for Rx */
void *if_afdata[AF_MAX];
};
#define if_mtu if_data.ifi_mtu
#define if_type if_data.ifi_type

View File

@ -1,4 +1,4 @@
/* $NetBSD: domain.h,v 1.12 2002/05/12 20:36:58 matt Exp $ */
/* $NetBSD: domain.h,v 1.13 2002/05/27 02:53:49 itojun Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -46,6 +46,7 @@
* Forward structure declarations for function prototypes [sic].
*/
struct mbuf;
struct ifnet;
struct domain {
int dom_family; /* AF_xxx */
@ -62,6 +63,9 @@ struct domain {
__P((void **, int));
int dom_rtoffset; /* an arg to rtattach, in bits */
int dom_maxrtkey; /* for routing layer */
void *(*dom_ifattach) __P((struct ifnet *));
void (*dom_ifdetach) __P((struct ifnet *, void *));
/* af-dependent data on ifnet */
};
#ifdef _KERNEL