natm.h revision 148125
1/*	$NetBSD: natm.h,v 1.1 1996/07/04 03:20:12 chuck Exp $	*/
2/* $FreeBSD: head/sys/netnatm/natm.h 148125 2005-07-18 16:55:46Z rwatson $ */
3
4/*-
5 *
6 * Copyright (c) 1996 Charles D. Cranor and Washington University.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *      This product includes software developed by Charles D. Cranor and
20 *      Washington University.
21 * 4. The name of the author may not be used to endorse or promote products
22 *    derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36/*
37 * natm.h: native mode atm
38 */
39
40/*
41 * supported protocols
42 */
43#define	PROTO_NATMAAL0		1
44#define	PROTO_NATMAAL5		2
45
46/*
47 * sockaddr_natm
48 */
49
50struct sockaddr_natm {
51	unsigned char	snatm_len;		/* length */
52	sa_family_t	snatm_family;		/* AF_NATM */
53	char		snatm_if[IFNAMSIZ];	/* interface name */
54	u_int16_t	snatm_vci;		/* vci */
55	u_int8_t	snatm_vpi;		/* vpi */
56};
57
58#if defined(__FreeBSD__) && defined(_KERNEL)
59
60#define	SPLSOFTNET() splnet()
61
62#elif defined(__NetBSD__) || defined(__OpenBSD__)
63
64#define	SPLSOFTNET() splsoftnet()
65
66#endif
67
68#ifdef _KERNEL
69
70/*
71 * natm protocol control block
72 */
73struct natmpcb {
74	LIST_ENTRY(natmpcb) pcblist;	/* list pointers */
75	u_int		npcb_inq;	/* # of our pkts in proto q */
76	struct socket	*npcb_socket;	/* backpointer to socket */
77	struct ifnet	*npcb_ifp;	/* pointer to hardware */
78	struct in_addr	ipaddr;		/* remote IP address, if APCB_IP */
79	u_int16_t	npcb_vci;	/* VCI */
80	u_int8_t	npcb_vpi;	/* VPI */
81	u_int8_t	npcb_flags;	/* flags */
82};
83
84/* flags */
85#define	NPCB_FREE	0x01		/* free (not on any list) */
86#define	NPCB_CONNECTED	0x02		/* connected */
87#define	NPCB_IP		0x04		/* used by IP */
88#define	NPCB_DRAIN	0x08		/* destory as soon as inq == 0 */
89
90/* flag arg to npcb_free */
91#define	NPCB_REMOVE	0		/* remove from global list */
92#define	NPCB_DESTROY	1		/* destroy and be free */
93
94LIST_HEAD(npcblist, natmpcb);
95
96/* global data structures */
97
98extern struct mtx natm_mtx;		/* global netnatm lock */
99extern struct npcblist natm_pcbs;	/* global list of pcbs */
100#define	NATM_STAT
101#ifdef NATM_STAT
102extern	u_int	natm_sodropcnt;
103extern	u_int	natm_sodropbytes;	/* account of droppage */
104extern	u_int	natm_sookcnt;
105extern	u_int	natm_sookbytes;		/* account of ok */
106#endif
107
108/* locking macros */
109#define	NATM_LOCK_INIT()	mtx_init(&natm_mtx, "natm_mtx", NULL, MTX_DEF)
110#define	NATM_LOCK()		mtx_lock(&natm_mtx)
111#define	NATM_UNLOCK()		mtx_unlock(&natm_mtx)
112#define	NATM_LOCK_ASSERT()	mtx_assert(&natm_mtx, MA_OWNED)
113
114/* external functions */
115
116/* natm_pcb.c */
117struct	natmpcb *npcb_alloc(int);
118void	npcb_free(struct natmpcb *, int);
119struct	natmpcb *npcb_add(struct natmpcb *, struct ifnet *, uint16_t, uint8_t);
120
121/* natm.c */
122#if defined(__NetBSD__) || defined(__OpenBSD__)
123int	natm_usrreq(struct socket *, int, struct mbuf *,
124	    struct mbuf *, struct mbuf *, struct proc *);
125#elif defined(__FreeBSD__)
126#if __FreeBSD__ > 2
127/*
128 * FreeBSD new usrreqs style appeared since 2.2.  compatibility to old style
129 * has gone since 3.0.
130 */
131#define	FREEBSD_USRREQS
132extern struct pr_usrreqs natm_usrreqs;
133#else /* !( __FreeBSD__ > 2) */
134int	natm_usrreq(struct socket *, int, struct mbuf *,
135	    struct mbuf *, struct mbuf *);
136#endif /* !( __FreeBSD__ > 2) */
137#endif
138
139#ifdef SYSCTL_HANDLER_ARGS
140int	natm0_sysctl(SYSCTL_HANDLER_ARGS);
141int	natm5_sysctl(SYSCTL_HANDLER_ARGS);
142#endif
143
144void	natmintr(struct mbuf *);
145
146#endif
147