1243730Srwatson/*-
2243730Srwatson * Copyright (c) 1984, 1985, 1986, 1987, 1993
3243730Srwatson *	The Regents of the University of California.
4243730Srwatson * Copyright (c) 2004-2006 Robert N. M. Watson
5243730Srwatson * All rights reserved.
6243730Srwatson *
7243730Srwatson * Redistribution and use in source and binary forms, with or without
8243730Srwatson * modification, are permitted provided that the following conditions
9243730Srwatson * are met:
10243730Srwatson * 1. Redistributions of source code must retain the above copyright
11243730Srwatson *    notice, this list of conditions and the following disclaimer.
12243730Srwatson * 2. Redistributions in binary form must reproduce the above copyright
13243730Srwatson *    notice, this list of conditions and the following disclaimer in the
14243730Srwatson *    documentation and/or other materials provided with the distribution.
15243730Srwatson * 4. Neither the name of the University nor the names of its contributors
16243730Srwatson *    may be used to endorse or promote products derived from this software
17243730Srwatson *    without specific prior written permission.
18243730Srwatson *
19243730Srwatson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20243730Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21243730Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22243730Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23243730Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24243730Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25243730Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26243730Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27243730Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28243730Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29243734Srwatson * SUCH DAMAGE.
30243730Srwatson *
31243730Srwatson * Copyright (c) 1995, Mike Mitchell
32243730Srwatson * All rights reserved.
33243730Srwatson *
34243734Srwatson * Redistribution and use in source and binary forms, with or without
35243730Srwatson * modification, are permitted provided that the following conditions
36243730Srwatson * are met:
37243730Srwatson * 1. Redistributions of source code must retain the above copyright
38243730Srwatson *    notice, this list of conditions and the following disclaimer.
39243730Srwatson * 2. Redistributions in binary form must reproduce the above copyright
40243730Srwatson *    notice, this list of conditions and the following disclaimer in the
41243730Srwatson *    documentation and/or other materials provided with the distribution.
42243730Srwatson * 3. All advertising materials mentioning features or use of this software
43243730Srwatson *    must display the following acknowledgement:
44243730Srwatson *	This product includes software developed by the University of
45243730Srwatson *	California, Berkeley and its contributors.
46243730Srwatson * 4. Neither the name of the University nor the names of its contributors
47243730Srwatson *    may be used to endorse or promote products derived from this software
48243730Srwatson *    without specific prior written permission.
49243730Srwatson *
50243730Srwatson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51243730Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52243730Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53243730Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54243730Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55243730Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56243730Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57243730Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58243730Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59243730Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60243730Srwatson * SUCH DAMAGE.
61243730Srwatson *
62243730Srwatson *	@(#)ipx_pcb.h
63243730Srwatson *
64243730Srwatson * $FreeBSD$
65243730Srwatson */
66243730Srwatson
67243730Srwatson#ifndef _NETIPX_IPX_PCB_H_
68243730Srwatson#define	_NETIPX_IPX_PCB_H_
69243730Srwatson
70243730Srwatson/*
71243730Srwatson * IPX protocol interface control block.
72243730Srwatson */
73243730Srwatsonstruct ipxpcb {
74243730Srwatson	LIST_ENTRY(ipxpcb) ipxp_list;
75243730Srwatson	struct	socket *ipxp_socket;	/* back pointer to socket */
76243730Srwatson	struct	ipx_addr ipxp_faddr;	/* destination address */
77243730Srwatson	struct	ipx_addr ipxp_laddr;	/* socket's address */
78243730Srwatson	caddr_t	ipxp_pcb;		/* protocol specific stuff */
79243730Srwatson	struct	route ipxp_route;	/* routing information */
80243730Srwatson	struct	ipx_addr ipxp_lastdst;	/* validate cached route for dg socks*/
81243730Srwatson	short	ipxp_flags;
82243730Srwatson	u_char	ipxp_dpt;		/* default packet type for ipx_output */
83243730Srwatson	u_char	ipxp_rpt;		/* last received packet type by ipx_input() */
84243730Srwatson	struct	mtx ipxp_mtx;
85243730Srwatson};
86243730Srwatson
87243730Srwatson/*
88243730Srwatson * Additional IPX pcb-related types and variables.
89243730Srwatson */
90243730SrwatsonLIST_HEAD(ipxpcbhead, ipxpcb);
91243730Srwatsonextern struct ipxpcbhead ipxpcb_list;
92243730Srwatsonextern struct ipxpcbhead ipxrawpcb_list;
93243730Srwatson
94243730Srwatson#ifdef _KERNEL
95243730Srwatsonextern struct mtx	ipxpcb_list_mtx;
96243730Srwatson#endif
97243730Srwatson
98243730Srwatson/*
99243730Srwatson * IPX/SPX PCB flags.
100243730Srwatson */
101243730Srwatson#define IPXP_IN_ABORT		0x1	/* Calling abort through socket. */
102243730Srwatson#define IPXP_RAWIN		0x2	/* Show headers on input. */
103243730Srwatson#define IPXP_RAWOUT		0x4	/* Show header on output. */
104243730Srwatson#define IPXP_ALL_PACKETS	0x8	/* Turn off higher proto processing. */
105243730Srwatson#define	IPXP_CHECKSUM		0x10	/* Use checksum on this socket. */
106243730Srwatson#define	IPXP_DROPPED		0x20	/* Connection dropped. */
107243730Srwatson#define	IPXP_SPX		0x40	/* SPX PCB. */
108243730Srwatson
109243730Srwatson#define	IPX_WILDCARD		1
110243730Srwatson
111243730Srwatson#define ipxp_lport ipxp_laddr.x_port
112243730Srwatson#define ipxp_fport ipxp_faddr.x_port
113243730Srwatson
114243730Srwatson#define	sotoipxpcb(so)		((struct ipxpcb *)((so)->so_pcb))
115243730Srwatson
116243730Srwatson/*
117243730Srwatson * Nominal space allocated to an IPX socket.
118243730Srwatson */
119243730Srwatson#define	IPXSNDQ		16384
120243730Srwatson#define	IPXRCVQ		40960
121243730Srwatson
122243730Srwatson#ifdef _KERNEL
123243730Srwatsonint	ipx_pcballoc(struct socket *so, struct ipxpcbhead *head,
124243730Srwatson	    struct thread *p);
125243730Srwatsonint	ipx_pcbbind(struct ipxpcb *ipxp, struct sockaddr *nam,
126243730Srwatson	    struct thread *p);
127243730Srwatsonint	ipx_pcbconnect(struct ipxpcb *ipxp, struct sockaddr *nam,
128243730Srwatson	    struct thread *p);
129243730Srwatsonvoid	ipx_pcbdetach(struct ipxpcb *ipxp);
130243730Srwatsonvoid	ipx_pcbdisconnect(struct ipxpcb *ipxp);
131243730Srwatsonvoid	ipx_pcbfree(struct ipxpcb *ipxp);
132243730Srwatsonstruct ipxpcb *ipx_pcblookup(struct ipx_addr *faddr, u_short lport, int wildp);
133243730Srwatsonvoid	ipx_getpeeraddr(struct ipxpcb *ipxp, struct sockaddr **nam);
134243730Srwatsonvoid	ipx_getsockaddr(struct ipxpcb *ipxp, struct sockaddr **nam);
135243730Srwatson
136243730Srwatson#define	IPX_LIST_LOCK_INIT()	mtx_init(&ipxpcb_list_mtx, "ipx_list_mtx", \
137243730Srwatson				    NULL, MTX_DEF | MTX_RECURSE)
138243730Srwatson#define	IPX_LIST_LOCK()		mtx_lock(&ipxpcb_list_mtx)
139243730Srwatson#define	IPX_LIST_UNLOCK()	mtx_unlock(&ipxpcb_list_mtx)
140243730Srwatson#define	IPX_LIST_LOCK_ASSERT()	mtx_assert(&ipxpcb_list_mtx, MA_OWNED)
141243730Srwatson
142243730Srwatson#define	IPX_LOCK_INIT(ipx)	mtx_init(&(ipx)->ipxp_mtx, "ipx_mtx", NULL, \
143243730Srwatson				    MTX_DEF)
144243730Srwatson#define	IPX_LOCK_DESTROY(ipx)	mtx_destroy(&(ipx)->ipxp_mtx)
145243730Srwatson#define	IPX_LOCK(ipx)		mtx_lock(&(ipx)->ipxp_mtx)
146243730Srwatson#define	IPX_UNLOCK(ipx)		mtx_unlock(&(ipx)->ipxp_mtx)
147243730Srwatson#define	IPX_LOCK_ASSERT(ipx)	mtx_assert(&(ipx)->ipxp_mtx, MA_OWNED)
148243730Srwatson#endif /* _KERNEL */
149243730Srwatson
150243730Srwatson#endif /* !_NETIPX_IPX_PCB_H_ */
151243730Srwatson