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