2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
1997-05-09 07:48:14 +00:00
|
|
|
* Copyright (c) 1996 Charles D. Cranor and Washington University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Charles D. Cranor and
|
|
|
|
* Washington University.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2007-01-08 22:30:39 +00:00
|
|
|
*
|
|
|
|
* $NetBSD: natm_pcb.c,v 1.4 1996/11/09 03:26:27 chuck Exp $
|
1997-05-09 07:48:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* atm_pcb.c: manage atm protocol control blocks and keep IP and NATM
|
|
|
|
* from trying to use each other's VCs.
|
|
|
|
*/
|
|
|
|
|
2006-04-23 15:23:31 +00:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
2003-06-11 05:37:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1997-05-09 07:48:14 +00:00
|
|
|
#include <sys/param.h>
|
2006-04-23 15:23:31 +00:00
|
|
|
#include <sys/kernel.h>
|
1997-05-09 07:48:14 +00:00
|
|
|
#include <sys/malloc.h>
|
2006-04-23 15:23:31 +00:00
|
|
|
#include <sys/systm.h>
|
1997-10-12 20:26:33 +00:00
|
|
|
#include <sys/socket.h>
|
1997-12-20 00:13:51 +00:00
|
|
|
#include <sys/socketvar.h>
|
1997-05-09 07:48:14 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <netnatm/natm.h>
|
|
|
|
|
2006-04-23 15:23:31 +00:00
|
|
|
#include <ddb/ddb.h>
|
|
|
|
|
1997-12-20 00:13:51 +00:00
|
|
|
struct npcblist natm_pcbs;
|
|
|
|
|
1997-05-09 07:48:14 +00:00
|
|
|
/*
|
|
|
|
* npcb_alloc: allocate a npcb [in the free state]
|
|
|
|
*/
|
2003-08-06 13:46:15 +00:00
|
|
|
struct natmpcb *
|
|
|
|
npcb_alloc(int wait)
|
1997-05-09 07:48:14 +00:00
|
|
|
|
|
|
|
{
|
2003-08-06 13:46:15 +00:00
|
|
|
struct natmpcb *npcb;
|
1997-05-09 07:48:14 +00:00
|
|
|
|
2003-08-06 13:46:15 +00:00
|
|
|
npcb = malloc(sizeof(*npcb), M_PCB, wait | M_ZERO);
|
|
|
|
if (npcb != NULL)
|
|
|
|
npcb->npcb_flags = NPCB_FREE;
|
|
|
|
return (npcb);
|
1997-05-09 07:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* npcb_free: free a npcb
|
|
|
|
*/
|
2003-08-06 13:46:15 +00:00
|
|
|
void
|
|
|
|
npcb_free(struct natmpcb *npcb, int op)
|
1997-05-09 07:48:14 +00:00
|
|
|
{
|
Lock down netnatm and mark as MPSAFE:
- Introduce a subsystem mutex, natm_mtx, manipulated with accessor macros
NATM_LOCK_INIT(), NATM_LOCK(), NATM_UNLOCK(), NATM_LOCK_ASSERT(). It
protects the consistency of pcb-related data structures. Finer grained
locking is possible, but should be done in the context of specific
measurements (as very little work is done in netnatm -- most is in the
ATM device driver or socket layer, so there's probably not much
contention).
- Remove GIANT_REQUIRED, mark as NETISR_MPSAFE, remove
NET_NEEDS_GIANT("netnatm").
- Conditionally acquire Giant when entering network interfaces for
ifp->if_ioctl() using IFF_LOCKGIANT(ifp)/IFF_UNLOCKGIANT(ifp) in order
to coexist with non-MPSAFE atm ifnet drivers..
- De-spl.
MFC after: 2 weeks
Reviewed by: harti, bms (various versions)
2005-07-18 16:55:46 +00:00
|
|
|
|
|
|
|
NATM_LOCK_ASSERT();
|
2003-08-06 13:46:15 +00:00
|
|
|
|
|
|
|
if ((npcb->npcb_flags & NPCB_FREE) == 0) {
|
|
|
|
LIST_REMOVE(npcb, pcblist);
|
|
|
|
npcb->npcb_flags = NPCB_FREE;
|
|
|
|
}
|
|
|
|
if (op == NPCB_DESTROY) {
|
|
|
|
if (npcb->npcb_inq) {
|
|
|
|
npcb->npcb_flags = NPCB_DRAIN; /* flag for distruct. */
|
|
|
|
} else {
|
|
|
|
FREE(npcb, M_PCB); /* kill it! */
|
|
|
|
}
|
|
|
|
}
|
1997-05-09 07:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* npcb_add: add or remove npcb from main list
|
|
|
|
* returns npcb if ok
|
|
|
|
*/
|
2003-08-06 13:46:15 +00:00
|
|
|
struct natmpcb *
|
|
|
|
npcb_add(struct natmpcb *npcb, struct ifnet *ifp, u_int16_t vci, u_int8_t vpi)
|
1997-05-09 07:48:14 +00:00
|
|
|
{
|
2003-08-06 13:46:15 +00:00
|
|
|
struct natmpcb *cpcb = NULL; /* current pcb */
|
|
|
|
|
Lock down netnatm and mark as MPSAFE:
- Introduce a subsystem mutex, natm_mtx, manipulated with accessor macros
NATM_LOCK_INIT(), NATM_LOCK(), NATM_UNLOCK(), NATM_LOCK_ASSERT(). It
protects the consistency of pcb-related data structures. Finer grained
locking is possible, but should be done in the context of specific
measurements (as very little work is done in netnatm -- most is in the
ATM device driver or socket layer, so there's probably not much
contention).
- Remove GIANT_REQUIRED, mark as NETISR_MPSAFE, remove
NET_NEEDS_GIANT("netnatm").
- Conditionally acquire Giant when entering network interfaces for
ifp->if_ioctl() using IFF_LOCKGIANT(ifp)/IFF_UNLOCKGIANT(ifp) in order
to coexist with non-MPSAFE atm ifnet drivers..
- De-spl.
MFC after: 2 weeks
Reviewed by: harti, bms (various versions)
2005-07-18 16:55:46 +00:00
|
|
|
NATM_LOCK_ASSERT();
|
2003-08-06 13:46:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* lookup required
|
|
|
|
*/
|
|
|
|
LIST_FOREACH(cpcb, &natm_pcbs, pcblist)
|
|
|
|
if (ifp == cpcb->npcb_ifp && vci == cpcb->npcb_vci &&
|
|
|
|
vpi == cpcb->npcb_vpi)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add & something already there?
|
|
|
|
*/
|
|
|
|
if (cpcb) {
|
|
|
|
cpcb = NULL;
|
|
|
|
goto done; /* fail */
|
|
|
|
}
|
1997-05-09 07:48:14 +00:00
|
|
|
|
2003-08-06 13:46:15 +00:00
|
|
|
/*
|
|
|
|
* need to allocate a pcb?
|
|
|
|
*/
|
|
|
|
if (npcb == NULL) {
|
|
|
|
/* could be called from lower half */
|
|
|
|
cpcb = npcb_alloc(M_NOWAIT);
|
|
|
|
if (cpcb == NULL)
|
|
|
|
goto done; /* fail */
|
|
|
|
} else {
|
|
|
|
cpcb = npcb;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpcb->npcb_ifp = ifp;
|
|
|
|
cpcb->ipaddr.s_addr = 0;
|
|
|
|
cpcb->npcb_vci = vci;
|
|
|
|
cpcb->npcb_vpi = vpi;
|
|
|
|
cpcb->npcb_flags = NPCB_CONNECTED;
|
|
|
|
|
|
|
|
LIST_INSERT_HEAD(&natm_pcbs, cpcb, pcblist);
|
1997-05-09 07:48:14 +00:00
|
|
|
|
|
|
|
done:
|
2003-08-06 13:46:15 +00:00
|
|
|
return (cpcb);
|
1997-05-09 07:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DDB
|
2006-04-23 15:23:31 +00:00
|
|
|
DB_SHOW_COMMAND(natm, db_show_natm)
|
1997-05-09 07:48:14 +00:00
|
|
|
{
|
2003-08-06 13:46:15 +00:00
|
|
|
struct natmpcb *cpcb;
|
|
|
|
|
2006-04-23 15:23:31 +00:00
|
|
|
db_printf("npcb dump:\n");
|
2003-08-06 13:46:15 +00:00
|
|
|
LIST_FOREACH(cpcb, &natm_pcbs, pcblist) {
|
2006-04-23 15:23:31 +00:00
|
|
|
db_printf("if=%s, vci=%d, vpi=%d, IP=0x%x, sock=%p, "
|
|
|
|
"flags=0x%x, inq=%d\n", cpcb->npcb_ifp->if_xname,
|
|
|
|
cpcb->npcb_vci, cpcb->npcb_vpi, cpcb->ipaddr.s_addr,
|
|
|
|
cpcb->npcb_socket, cpcb->npcb_flags, cpcb->npcb_inq);
|
2003-08-06 13:46:15 +00:00
|
|
|
}
|
1997-05-09 07:48:14 +00:00
|
|
|
}
|
|
|
|
#endif
|