xref: /csrg-svn/sys/netiso/tp_pcb.h (revision 36409)
1*36409Ssklower /***********************************************************
2*36409Ssklower 		Copyright IBM Corporation 1987
3*36409Ssklower 
4*36409Ssklower                       All Rights Reserved
5*36409Ssklower 
6*36409Ssklower Permission to use, copy, modify, and distribute this software and its
7*36409Ssklower documentation for any purpose and without fee is hereby granted,
8*36409Ssklower provided that the above copyright notice appear in all copies and that
9*36409Ssklower both that copyright notice and this permission notice appear in
10*36409Ssklower supporting documentation, and that the name of IBM not be
11*36409Ssklower used in advertising or publicity pertaining to distribution of the
12*36409Ssklower software without specific, written prior permission.
13*36409Ssklower 
14*36409Ssklower IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15*36409Ssklower ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
16*36409Ssklower IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
17*36409Ssklower ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18*36409Ssklower WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
19*36409Ssklower ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
20*36409Ssklower SOFTWARE.
21*36409Ssklower 
22*36409Ssklower ******************************************************************/
23*36409Ssklower 
24*36409Ssklower /*
25*36409Ssklower  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
26*36409Ssklower  */
27*36409Ssklower /*
28*36409Ssklower  * ARGO TP
29*36409Ssklower  *
30*36409Ssklower  * $Header: tp_pcb.h,v 5.2 88/11/18 17:09:32 nhall Exp $
31*36409Ssklower  * $Source: /usr/argo/sys/netiso/RCS/tp_pcb.h,v $
32*36409Ssklower  *
33*36409Ssklower  *
34*36409Ssklower  * This file defines the transport protocol control block (tpcb).
35*36409Ssklower  * and a bunch of #define values that are used in the tpcb.
36*36409Ssklower  */
37*36409Ssklower 
38*36409Ssklower #ifndef  __TP_PCB__
39*36409Ssklower #define  __TP_PCB__
40*36409Ssklower 
41*36409Ssklower #include "../netiso/tp_param.h"
42*36409Ssklower #include "../netiso/tp_timer.h"
43*36409Ssklower #include "../netiso/tp_user.h"
44*36409Ssklower #ifndef sblock
45*36409Ssklower #include "../h/socketvar.h"
46*36409Ssklower #endif sblock
47*36409Ssklower 
48*36409Ssklower /* NOTE: the code depends on REF_CLOSED > REF_OPEN > the rest, and
49*36409Ssklower  * on REF_FREE being zero
50*36409Ssklower  *
51*36409Ssklower  * Possible improvement:
52*36409Ssklower  * think about merging the tp_ref w/ the tpcb and doing a search
53*36409Ssklower  * through the tpcb list, from tpb. This would slow down lookup
54*36409Ssklower  * during data transfer
55*36409Ssklower  * It would be a little nicer also to have something based on the
56*36409Ssklower  * clock (like top n bits of the reference is part of the clock, to
57*36409Ssklower  * minimize the likelihood  of reuse after a crash)
58*36409Ssklower  * also, need to keep the timer servicing part to a minimum (although
59*36409Ssklower  * the cost of this is probably independent of whether the timers are
60*36409Ssklower  * in the pcb or in an array..
61*36409Ssklower  * Last, would have to make the number of timers a function of the amount of
62*36409Ssklower  * mbufs available, plus some for the frozen references.
63*36409Ssklower  *
64*36409Ssklower  * Possible improvement:
65*36409Ssklower  * Might not need the ref_state stuff either...
66*36409Ssklower  * REF_FREE could correspond to tp_state == CLOSED or nonexistend tpcb,
67*36409Ssklower  * REF_OPEN to tp_state anywhere from AK_WAIT or CR_SENT to CLOSING
68*36409Ssklower  * REF_OPENING could correspond to LISTENING, because that's the
69*36409Ssklower  * way it's used, not because the correspondence is exact.
70*36409Ssklower  * REF_CLOSED could correspond to REFWAIT
71*36409Ssklower  */
72*36409Ssklower #define REF_FROZEN 3	/* has ref timer only */
73*36409Ssklower #define REF_OPEN 2		/* has timers, possibly active */
74*36409Ssklower #define REF_OPENING 1	/* in use (has a pcb) but no timers */
75*36409Ssklower #define REF_FREE 0		/* free to reallocate */
76*36409Ssklower 
77*36409Ssklower #define N_CTIMERS 		4
78*36409Ssklower #define N_ETIMERS 		2
79*36409Ssklower 
80*36409Ssklower struct tp_ref {
81*36409Ssklower 	u_char	 			tpr_state; /* values REF_FROZEN, etc. above */
82*36409Ssklower 	struct Ccallout 	tpr_callout[N_CTIMERS]; /* C timers */
83*36409Ssklower 	struct Ecallout		tpr_calltodo;			/* list of active E timers */
84*36409Ssklower 	struct tp_pcb 		*tpr_pcb;	/* back ptr to PCB */
85*36409Ssklower };
86*36409Ssklower 
87*36409Ssklower struct tp_param {
88*36409Ssklower 	/* PER system stuff (one static structure instead of a bunch of names) */
89*36409Ssklower 	unsigned 	tpp_configed:1;			/* Has TP been initialized? */
90*36409Ssklower };
91*36409Ssklower 
92*36409Ssklower 
93*36409Ssklower /*
94*36409Ssklower  * retransmission control and performance measurement
95*36409Ssklower  */
96*36409Ssklower struct tp_rtc {
97*36409Ssklower 	struct tp_rtc	*tprt_next; /* ptr to next rtc structure in the list */
98*36409Ssklower 	SeqNum 			tprt_seq;	/* seq # of this TPDU */
99*36409Ssklower 	int				tprt_eot;	/* Will this TPDU have the eot bit set? */
100*36409Ssklower 	int				tprt_octets;/* # octets in this TPDU */
101*36409Ssklower 	struct mbuf		*tprt_data; /* ptr to the octets of data */
102*36409Ssklower };
103*36409Ssklower 
104*36409Ssklower extern
105*36409Ssklower struct nl_protosw {
106*36409Ssklower 	int		nlp_afamily;			/* address family */
107*36409Ssklower 	int		(*nlp_putnetaddr)();	/* puts addresses in nl pcb */
108*36409Ssklower 	int		(*nlp_getnetaddr)();	/* gets addresses from nl pcb */
109*36409Ssklower 	int		(*nlp_putsufx)();		/* puts transport suffixes in nl pcb */
110*36409Ssklower 	int		(*nlp_getsufx)();		/* gets transport suffixes from nl pcb */
111*36409Ssklower 	int		(*nlp_recycle_suffix)();/* clears suffix from nl pcb */
112*36409Ssklower 	int		(*nlp_mtu)();			/* figures out mtu based on nl used */
113*36409Ssklower 	int		(*nlp_pcbbind)();		/* bind to pcb for net level */
114*36409Ssklower 	int		(*nlp_pcbconn)();		/* connect for net level */
115*36409Ssklower 	int		(*nlp_pcbdisc)();		/* disconnect net level */
116*36409Ssklower 	int		(*nlp_pcbdetach)();		/* detach net level pcb */
117*36409Ssklower 	int		(*nlp_pcballoc)();		/* allocate a net level pcb */
118*36409Ssklower 	int		(*nlp_output)();		/* prepare a packet to give to nl */
119*36409Ssklower 	int		(*nlp_dgoutput)();		/* prepare a packet to give to nl */
120*36409Ssklower 	int		(*nlp_ctloutput)();		/* hook for network set/get options */
121*36409Ssklower 	caddr_t	nlp_pcblist;			/* list of xx_pcb's for connections */
122*36409Ssklower } nl_protosw[];
123*36409Ssklower 
124*36409Ssklower struct tp_pcb_aux {
125*36409Ssklower 	/* addressing */
126*36409Ssklower 	u_short				tpa_domain;		/* domain (INET, ISO) */
127*36409Ssklower 	/* for compatibility with the *old* way and with INET, be sure that
128*36409Ssklower 	 * that lsuffix and fsuffix are aligned to a short addr.
129*36409Ssklower 	 * having them follow the u_short *suffixlen should suffice (choke)
130*36409Ssklower 	 */
131*36409Ssklower 	u_short				tpa_fsuffixlen;	/* foreign suffix */
132*36409Ssklower 	u_char				tpa_fsuffix[MAX_TSAP_SEL_LEN];
133*36409Ssklower 	u_short				tpa_lsuffixlen;	/* local suffix */
134*36409Ssklower 	u_char				tpa_lsuffix[MAX_TSAP_SEL_LEN];
135*36409Ssklower #define SHORT_LSUFXP(tpcb) ((short *)((tpcb)->tp_aux->tpa_lsuffix))
136*36409Ssklower #define SHORT_FSUFXP(tpcb) ((short *)((tpcb)->tp_aux->tpa_fsuffix))
137*36409Ssklower 
138*36409Ssklower 	u_char 				tpa_vers;		/* protocol version */
139*36409Ssklower 	u_char 				tpa_peer_acktime; /* used to compute DT retrans time */
140*36409Ssklower 
141*36409Ssklower 	struct sockbuf		tpa_Xsnd;		/* for expedited data */
142*36409Ssklower 	struct sockbuf		tpa_Xrcv;		/* for expedited data */
143*36409Ssklower 	SeqNum				tpa_Xsndnxt;	/* next XPD seq # to send */
144*36409Ssklower 	SeqNum				tpa_Xuna;		/* seq # of unacked XPD */
145*36409Ssklower 	SeqNum				tpa_Xrcvnxt;	/* next XPD seq # expect to recv */
146*36409Ssklower 
147*36409Ssklower 	/* AK subsequencing */
148*36409Ssklower 	u_short				tpa_s_subseq;	/* next subseq to send */
149*36409Ssklower 	u_short				tpa_r_subseq;	/* highest recv subseq */
150*36409Ssklower 
151*36409Ssklower };
152*36409Ssklower 
153*36409Ssklower struct tp_pcb {
154*36409Ssklower 	u_short 			tp_state;		/* state of fsm */
155*36409Ssklower 	short 				tp_retrans;		/* # times can still retrans */
156*36409Ssklower 	struct tp_ref 		*tp_refp;		/* rest of pcb	*/
157*36409Ssklower 	struct tp_pcb_aux	*tp_aux;		/* second half of the tpcb */
158*36409Ssklower 	caddr_t				tp_npcb;		/* to lower layer pcb */
159*36409Ssklower 	struct nl_protosw	*tp_nlproto;	/* lower-layer dependent routines */
160*36409Ssklower 	struct socket 		*tp_sock;		/* back ptr */
161*36409Ssklower 
162*36409Ssklower #define tp_Xsnd tp_aux->tpa_Xsnd
163*36409Ssklower #define tp_Xrcv tp_aux->tpa_Xrcv
164*36409Ssklower 
165*36409Ssklower 	RefNum				tp_lref;	 	/* local reference */
166*36409Ssklower 	RefNum 				tp_fref;		/* foreign reference */
167*36409Ssklower 
168*36409Ssklower 	u_int				tp_seqmask;		/* mask for seq space */
169*36409Ssklower 	u_int				tp_seqbit;		/* bit for seq number wraparound */
170*36409Ssklower 	u_int				tp_seqhalf;		/* half the seq space */
171*36409Ssklower 
172*36409Ssklower #define		tp_vers	tp_aux->tpa_vers
173*36409Ssklower #define		tp_peer_acktime tp_aux->tpa_peer_acktime
174*36409Ssklower 
175*36409Ssklower 	/* credit & sequencing info for SENDING */
176*36409Ssklower 	u_short 			tp_fcredit;		/* current remote credit in # packets */
177*36409Ssklower 
178*36409Ssklower 	u_short				tp_cong_win;	/* congestion window : set to 1 on
179*36409Ssklower 										 * source quench
180*36409Ssklower 										 * Minimizes the amount of retrans-
181*36409Ssklower 										 * missions (independently of the
182*36409Ssklower 										 * retrans strategy).  Increased
183*36409Ssklower 										 * by one for each good ack received.
184*36409Ssklower 										 * Minimizes the amount sent in a
185*36409Ssklower 										 * regular tp_send() also.
186*36409Ssklower 										 */
187*36409Ssklower #define tp_Xsndnxt  tp_aux->tpa_Xsndnxt
188*36409Ssklower #define tp_Xuna  	tp_aux->tpa_Xuna
189*36409Ssklower 	SeqNum				tp_snduna;		/* seq # of lowest unacked DT */
190*36409Ssklower 	struct tp_rtc		*tp_snduna_rtc;	/* lowest unacked stuff sent so far */
191*36409Ssklower 	SeqNum				tp_sndhiwat;	/* highest seq # sent so far */
192*36409Ssklower 	struct tp_rtc		*tp_sndhiwat_rtc;	/* last stuff sent so far */
193*36409Ssklower 	int					tp_Nwindow;		/* for perf. measurement */
194*36409Ssklower 
195*36409Ssklower 	/* credit & sequencing info for RECEIVING */
196*36409Ssklower 	SeqNum	 			tp_sent_lcdt;	/* cdt according to last ack sent */
197*36409Ssklower 	SeqNum	 			tp_sent_uwe;	/* uwe according to last ack sent */
198*36409Ssklower 	SeqNum	 			tp_sent_rcvnxt;	/* rcvnxt according to last ack sent
199*36409Ssklower 										 * needed for perf measurements only
200*36409Ssklower 										 */
201*36409Ssklower 	u_short				tp_lcredit;		/* current local credit in # packets */
202*36409Ssklower 	SeqNum				tp_rcvnxt;		/* next DT seq # expect to recv */
203*36409Ssklower 	struct tp_rtc		*tp_rcvnxt_rtc;	/* unacked stuff recvd out of order */
204*36409Ssklower #define	tp_Xrcvnxt		tp_aux->tpa_Xrcvnxt
205*36409Ssklower #define tp_domain		tp_aux->tpa_domain
206*36409Ssklower #define tp_fsuffix		tp_aux->tpa_fsuffix
207*36409Ssklower #define tp_fsuffixlen		tp_aux->tpa_fsuffixlen
208*36409Ssklower #define tp_lsuffix		tp_aux->tpa_lsuffix
209*36409Ssklower #define tp_lsuffixlen		tp_aux->tpa_lsuffixlen
210*36409Ssklower 
211*36409Ssklower 	/* parameters per-connection controllable by user */
212*36409Ssklower 	struct tp_conn_param _tp_param;
213*36409Ssklower 
214*36409Ssklower #define	tp_Nretrans _tp_param.p_Nretrans
215*36409Ssklower #define	tp_dr_ticks _tp_param.p_dr_ticks
216*36409Ssklower #define	tp_cc_ticks _tp_param.p_cc_ticks
217*36409Ssklower #define	tp_dt_ticks _tp_param.p_dt_ticks
218*36409Ssklower #define	tp_xpd_ticks _tp_param.p_x_ticks
219*36409Ssklower #define	tp_cr_ticks _tp_param.p_cr_ticks
220*36409Ssklower #define	tp_keepalive_ticks _tp_param.p_keepalive_ticks
221*36409Ssklower #define	tp_sendack_ticks _tp_param.p_sendack_ticks
222*36409Ssklower #define	tp_refer_ticks _tp_param.p_ref_ticks
223*36409Ssklower #define	tp_inact_ticks _tp_param.p_inact_ticks
224*36409Ssklower #define	tp_xtd_format _tp_param.p_xtd_format
225*36409Ssklower #define	tp_xpd_service _tp_param.p_xpd_service
226*36409Ssklower #define	tp_ack_strat _tp_param.p_ack_strat
227*36409Ssklower #define	tp_rx_strat _tp_param.p_rx_strat
228*36409Ssklower #define	tp_use_checksum _tp_param.p_use_checksum
229*36409Ssklower #define	tp_use_efc _tp_param.p_use_efc
230*36409Ssklower #define	tp_use_nxpd _tp_param.p_use_nxpd
231*36409Ssklower #define	tp_use_rcc _tp_param.p_use_rcc
232*36409Ssklower #define	tp_tpdusize _tp_param.p_tpdusize
233*36409Ssklower #define	tp_class _tp_param.p_class
234*36409Ssklower #define	tp_winsize _tp_param.p_winsize
235*36409Ssklower #define	tp_no_disc_indications _tp_param.p_no_disc_indications
236*36409Ssklower #define	tp_dont_change_params _tp_param.p_dont_change_params
237*36409Ssklower #define	tp_netservice _tp_param.p_netservice
238*36409Ssklower 
239*36409Ssklower 	int tp_l_tpdusize;
240*36409Ssklower 		/* whereas tp_tpdusize is log2(the negotiated max size)
241*36409Ssklower 		 * l_tpdusize is the size we'll use when sending, in # chars
242*36409Ssklower 		 */
243*36409Ssklower 
244*36409Ssklower 	struct timeval	tp_rtv;					/* max round-trip time variance */
245*36409Ssklower 	struct timeval	tp_rtt; 					/* smoothed round-trip time */
246*36409Ssklower 	struct timeval 	tp_rttemit[ TP_RTT_NUM + 1 ];
247*36409Ssklower 					/* times that the last TP_RTT_NUM DT_TPDUs were emitted */
248*36409Ssklower 	unsigned
249*36409Ssklower 		tp_sendfcc:1,			/* shall next ack include FCC parameter? */
250*36409Ssklower 		tp_trace:1,				/* is this pcb being traced? (not used yet) */
251*36409Ssklower 		tp_perf_on:1,			/* 0/1 -> performance measuring on  */
252*36409Ssklower 		tp_reneged:1,			/* have we reneged on cdt since last ack? */
253*36409Ssklower 		tp_decbit:4,			/* dec bit was set, we're in reneg mode  */
254*36409Ssklower 		tp_flags:8,				/* values: */
255*36409Ssklower #define TPF_CONN_DATA_OUT	TPFLAG_CONN_DATA_OUT
256*36409Ssklower #define TPF_CONN_DATA_IN	TPFLAG_CONN_DATA_IN
257*36409Ssklower #define TPF_DISC_DATA_IN	TPFLAG_DISC_DATA_IN
258*36409Ssklower #define TPF_DISC_DATA_OUT	TPFLAG_DISC_DATA_OUT
259*36409Ssklower #define TPF_XPD_PRESENT 	TPFLAG_XPD_PRESENT
260*36409Ssklower #define TPF_NLQOS_PDN	 	TPFLAG_NLQOS_PDN
261*36409Ssklower #define TPF_PEER_ON_SAMENET	TPFLAG_PEER_ON_SAMENET
262*36409Ssklower 
263*36409Ssklower #define PEER_IS_LOCAL(t) \
264*36409Ssklower 			(((t)->tp_flags & TPF_PEER_ON_SAME_NET)==TPF_PEER_ON_SAME_NET)
265*36409Ssklower #define USES_PDN(t)	\
266*36409Ssklower 			(((t)->tp_flags & TPF_NLQOS_PDN)==TPF_NLQOS_PDN)
267*36409Ssklower 
268*36409Ssklower 		tp_unused:16;
269*36409Ssklower 
270*36409Ssklower #define tp_s_subseq tp_aux->tpa_s_subseq
271*36409Ssklower #define tp_r_subseq tp_aux->tpa_r_subseq
272*36409Ssklower 
273*36409Ssklower #ifdef TP_PERF_MEAS
274*36409Ssklower 	/* performance stats - see tp_stat.h */
275*36409Ssklower 	struct tp_pmeas *tp_p_meas;
276*36409Ssklower #endif TP_PERF_MEAS
277*36409Ssklower };
278*36409Ssklower 
279*36409Ssklower extern struct timeval 	time;
280*36409Ssklower extern struct tp_ref 	tp_ref[];
281*36409Ssklower extern struct tp_param	tp_param;
282*36409Ssklower 
283*36409Ssklower #ifdef lint
284*36409Ssklower #define	sototpcb(so) 	((struct tp_pcb *)0)
285*36409Ssklower #define	sototpref(so)	((struct tp_ref *)0)
286*36409Ssklower #define	tpcbtoso(tp)	((struct socket *)0)
287*36409Ssklower #define	tpcbtoref(tp)	((struct tp_ref *)0)
288*36409Ssklower #else
289*36409Ssklower #define	sototpcb(so) 	((struct tp_pcb *)(so->so_tpcb))
290*36409Ssklower #define	sototpref(so)	((struct tp_ref *)((so)->so_tpcb->tp_ref))
291*36409Ssklower #define	tpcbtoso(tp)	((struct socket *)((tp)->tp_sock))
292*36409Ssklower #define	tpcbtoref(tp)	((struct tp_ref *)((tp)->tp_ref))
293*36409Ssklower #endif
294*36409Ssklower 
295*36409Ssklower #endif  __TP_PCB__
296