ipx_pcb.h revision 157051
1/*-
2 * Copyright (c) 1984, 1985, 1986, 1987, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 * Copyright (c) 1995, Mike Mitchell
5 * Copyright (c) 2004-2005 Robert N. M. Watson
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by the University of
18 *	California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 *	@(#)ipx_pcb.h
36 *
37 * $FreeBSD: head/sys/netipx/ipx_pcb.h 157051 2006-03-23 19:58:12Z rwatson $
38 */
39
40#ifndef _NETIPX_IPX_PCB_H_
41#define	_NETIPX_IPX_PCB_H_
42
43/*
44 * IPX protocol interface control block.
45 */
46struct ipxpcb {
47	LIST_ENTRY(ipxpcb) ipxp_list;
48	struct	socket *ipxp_socket;	/* back pointer to socket */
49	struct	ipx_addr ipxp_faddr;	/* destination address */
50	struct	ipx_addr ipxp_laddr;	/* socket's address */
51	caddr_t	ipxp_pcb;		/* protocol specific stuff */
52	struct	route ipxp_route;	/* routing information */
53	struct	ipx_addr ipxp_lastdst;	/* validate cached route for dg socks*/
54	short	ipxp_flags;
55	u_char	ipxp_dpt;		/* default packet type for ipx_output */
56	u_char	ipxp_rpt;		/* last received packet type by ipx_input() */
57	struct	mtx ipxp_mtx;
58};
59
60/*
61 * Additional IPX pcb-related types and variables.
62 */
63LIST_HEAD(ipxpcbhead, ipxpcb);
64extern struct ipxpcbhead ipxpcb_list;
65extern struct ipxpcbhead ipxrawpcb_list;
66
67#ifdef _KERNEL
68extern struct mtx	ipxpcb_list_mtx;
69#endif
70
71/* possible flags */
72
73#define IPXP_IN_ABORT		0x1	/* calling abort through socket */
74#define IPXP_RAWIN		0x2	/* show headers on input */
75#define IPXP_RAWOUT		0x4	/* show header on output */
76#define IPXP_ALL_PACKETS	0x8	/* Turn off higher proto processing */
77#define	IPXP_CHECKSUM		0x10	/* use checksum on this socket */
78
79#define	IPX_WILDCARD		1
80
81#define ipxp_lport ipxp_laddr.x_port
82#define ipxp_fport ipxp_faddr.x_port
83
84#define	sotoipxpcb(so)		((struct ipxpcb *)((so)->so_pcb))
85
86/*
87 * Nominal space allocated to an IPX socket.
88 */
89#define	IPXSNDQ		16384
90#define	IPXRCVQ		40960
91
92#ifdef _KERNEL
93int	ipx_pcballoc(struct socket *so, struct ipxpcbhead *head,
94			  struct thread *p);
95int	ipx_pcbbind(struct ipxpcb *ipxp, struct sockaddr *nam,
96			 struct thread *p);
97int	ipx_pcbconnect(struct ipxpcb *ipxp, struct sockaddr *nam,
98			    struct thread *p);
99void	ipx_pcbdetach(struct ipxpcb *ipxp);
100void	ipx_pcbdisconnect(struct ipxpcb *ipxp);
101struct ipxpcb *
102	ipx_pcblookup(struct ipx_addr *faddr, int lport, int wildp);
103void	ipx_setpeeraddr(struct ipxpcb *ipxp, struct sockaddr **nam);
104void	ipx_setsockaddr(struct ipxpcb *ipxp, struct sockaddr **nam);
105
106#define	IPX_LIST_LOCK_INIT()	mtx_init(&ipxpcb_list_mtx, "ipx_list_mtx", \
107				    NULL, MTX_DEF | MTX_RECURSE)
108#define	IPX_LIST_LOCK()		mtx_lock(&ipxpcb_list_mtx)
109#define	IPX_LIST_UNLOCK()	mtx_unlock(&ipxpcb_list_mtx)
110#define	IPX_LIST_LOCK_ASSERT()	mtx_assert(&ipxpcb_list_mtx, MA_OWNED)
111
112#define	IPX_LOCK_INIT(ipx)	mtx_init(&(ipx)->ipxp_mtx, "ipx_mtx", NULL, \
113				    MTX_DEF)
114#define	IPX_LOCK_DESTROY(ipx)	mtx_destroy(&(ipx)->ipxp_mtx)
115#define	IPX_LOCK(ipx)		mtx_lock(&(ipx)->ipxp_mtx)
116#define	IPX_UNLOCK(ipx)		mtx_unlock(&(ipx)->ipxp_mtx)
117#define	IPX_LOCK_ASSERT(ipx)	mtx_assert(&(ipx)->ipxp_mtx, MA_OWNED)
118#endif /* _KERNEL */
119
120#endif /* !_NETIPX_IPX_PCB_H_ */
121