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