1/*-
2 * Copyright (c) 1984, 1985, 1986, 1987, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * Copyright (c) 1995, Mike Mitchell
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 *    notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 *    notice, this list of conditions and the following disclaimer in the
38 *    documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 *    must display the following acknowledgement:
41 *	This product includes software developed by the University of
42 *	California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 *    may be used to endorse or promote products derived from this software
45 *    without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
59 *	@(#)spx.h
60 *
61 * $FreeBSD$
62 */
63
64#ifndef _NETIPX_SPX_H_
65#define	_NETIPX_SPX_H_
66
67/*
68 * Definitions for IPX style Sequenced Packet Protocol
69 */
70
71struct spxhdr {
72	u_char	spx_cc;		/* connection control */
73	u_char	spx_dt;		/* datastream type */
74#define	SPX_SP	0x80		/* system packet */
75#define	SPX_SA	0x40		/* send acknowledgement */
76#define	SPX_OB	0x20		/* attention (out of band data) */
77#define	SPX_EM	0x10		/* end of message */
78	u_short	spx_sid;	/* source connection identifier */
79	u_short	spx_did;	/* destination connection identifier */
80	u_short	spx_seq;	/* sequence number */
81	u_short	spx_ack;	/* acknowledge number */
82	u_short	spx_alo;	/* allocation number */
83} __packed;
84
85/*
86 * Definitions for NS(tm) Internet Datagram Protocol
87 * containing a Sequenced Packet Protocol packet.
88 */
89struct spx {
90	struct ipx	si_i;
91	struct spxhdr 	si_s;
92} __packed;
93struct spx_q {
94	struct mbuf		*sq_msi;
95	struct spx		*sq_si;
96	LIST_ENTRY(spx_q)	 sq_entry;
97};
98#define SI(x)	((struct spx *)x)
99#define si_sum	si_i.ipx_sum
100#define si_len	si_i.ipx_len
101#define si_tc	si_i.ipx_tc
102#define si_pt	si_i.ipx_pt
103#define si_dna	si_i.ipx_dna
104#define si_sna	si_i.ipx_sna
105#define si_sport	si_i.ipx_sna.x_port
106#define si_cc	si_s.spx_cc
107#define si_dt	si_s.spx_dt
108#define si_sid	si_s.spx_sid
109#define si_did	si_s.spx_did
110#define si_seq	si_s.spx_seq
111#define si_ack	si_s.spx_ack
112#define si_alo	si_s.spx_alo
113
114/*
115 * SPX control block, one per connection
116 */
117struct spxpcb {
118	LIST_HEAD(, spx_q)	s_q;	/* queue for out-of-order receipt */
119	struct	ipxpcb	*s_ipxpcb;	/* backpointer to internet pcb */
120	u_char	s_state;
121	u_char	s_flags;
122#define	SF_ACKNOW	0x01		/* Ack peer immediately */
123#define	SF_DELACK	0x02		/* Ack, but try to delay it */
124#define	SF_HI	0x04			/* Show headers on input */
125#define	SF_HO	0x08			/* Show headers on output */
126#define	SF_PI	0x10			/* Packet (datagram) interface */
127#define SF_WIN	0x20			/* Window info changed */
128#define SF_RXT	0x40			/* Rxt info changed */
129#define SF_RVD	0x80			/* Calling from read usrreq routine */
130	u_short s_mtu;			/* Max packet size for this stream */
131/* use sequence fields in headers to store sequence numbers for this
132   connection */
133	struct	ipx	s_ipx;
134	struct	spxhdr	s_shdr;		/* prototype header to transmit */
135#define s_cc s_shdr.spx_cc		/* connection control (for EM bit) */
136#define s_dt s_shdr.spx_dt		/* datastream type */
137#define s_sid s_shdr.spx_sid		/* source connection identifier */
138#define s_did s_shdr.spx_did		/* destination connection identifier */
139#define s_seq s_shdr.spx_seq		/* sequence number */
140#define s_ack s_shdr.spx_ack		/* acknowledge number */
141#define s_alo s_shdr.spx_alo		/* allocation number */
142#define s_dport s_ipx.ipx_dna.x_port	/* where we are sending */
143	struct spxhdr s_rhdr;		/* last received header (in effect!)*/
144	u_short s_rack;			/* their acknowledge number */
145	u_short s_ralo;			/* their allocation number */
146	u_short s_smax;			/* highest packet # we have sent */
147	u_short	s_snxt;			/* which packet to send next */
148
149/* congestion control */
150#define	CUNIT	1024			/* scaling for ... */
151	int	s_cwnd;			/* Congestion-controlled window */
152					/* in packets * CUNIT */
153	short	s_swnd;			/* == tcp snd_wnd, in packets */
154	short	s_smxw;			/* == tcp max_sndwnd */
155					/* difference of two spx_seq's can be
156					   no bigger than a short */
157	u_short	s_swl1;			/* == tcp snd_wl1 */
158	u_short	s_swl2;			/* == tcp snd_wl2 */
159	int	s_cwmx;			/* max allowable cwnd */
160	int	s_ssthresh;		/* s_cwnd size threshold for
161					 * slow start exponential-to-
162					 * linear switch */
163/* transmit timing stuff
164 * srtt and rttvar are stored as fixed point, for convenience in smoothing.
165 * srtt has 3 bits to the right of the binary point, rttvar has 2.
166 */
167	short	s_idle;			/* time idle */
168#define	SPXT_NTIMERS	4
169	short	s_timer[SPXT_NTIMERS];	/* timers */
170	short	s_rxtshift;		/* log(2) of rexmt exp. backoff */
171	short	s_rxtcur;		/* current retransmit value */
172	u_short	s_rtseq;		/* packet being timed */
173	short	s_rtt;			/* timer for round trips */
174	short	s_srtt;			/* averaged timer */
175	short	s_rttvar;		/* variance in round trip time */
176	char	s_force;		/* which timer expired */
177	char	s_dupacks;		/* counter to intuit xmt loss */
178
179/* out of band data */
180	char	s_oobflags;
181#define SF_SOOB	0x08			/* sending out of band data */
182#define SF_IOOB 0x10			/* receiving out of band data */
183	char	s_iobc;			/* input characters */
184/* debug stuff */
185	u_short	s_want;			/* Last candidate for sending */
186	char	s_outx;			/* exit taken from spx_output */
187	char	s_inx;			/* exit taken from spx_input */
188	u_short	s_flags2;		/* more flags for testing */
189#define SF_NEWCALL	0x100		/* for new_recvmsg */
190#define SO_NEWCALL	10		/* for new_recvmsg */
191};
192
193#define	ipxtospxpcb(np)	((struct spxpcb *)(np)->ipxp_pcb)
194#define	sotospxpcb(so)	(ipxtospxpcb(sotoipxpcb(so)))
195
196#ifdef _KERNEL
197
198extern struct pr_usrreqs spx_usrreqs;
199extern struct pr_usrreqs spx_usrreq_sps;
200
201void	spx_ctlinput(int cmd, struct sockaddr *arg_as_sa, void *dummy);
202int	spx_ctloutput(struct socket *so, struct sockopt *sopt);
203void	spx_fasttimo(void);
204void	spx_init(void);
205void	spx_input(struct mbuf *m, struct ipxpcb *ipxp);
206void	spx_slowtimo(void);
207
208#endif /* _KERNEL */
209
210#endif /* !_NETIPX_SPX_H_ */
211