xref: /csrg-svn/sys/netiso/tp_pcb.h (revision 51213)
149268Sbostic /*-
249268Sbostic  * Copyright (c) 1991 The Regents of the University of California.
349268Sbostic  * All rights reserved.
449268Sbostic  *
549268Sbostic  * %sccs.include.redist.c%
649268Sbostic  *
7*51213Ssklower  *	@(#)tp_pcb.h	7.18 (Berkeley) 09/30/91
849268Sbostic  */
949268Sbostic 
1036409Ssklower /***********************************************************
1136409Ssklower 		Copyright IBM Corporation 1987
1236409Ssklower 
1336409Ssklower                       All Rights Reserved
1436409Ssklower 
1536409Ssklower Permission to use, copy, modify, and distribute this software and its
1636409Ssklower documentation for any purpose and without fee is hereby granted,
1736409Ssklower provided that the above copyright notice appear in all copies and that
1836409Ssklower both that copyright notice and this permission notice appear in
1936409Ssklower supporting documentation, and that the name of IBM not be
2036409Ssklower used in advertising or publicity pertaining to distribution of the
2136409Ssklower software without specific, written prior permission.
2236409Ssklower 
2336409Ssklower IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
2436409Ssklower ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
2536409Ssklower IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
2636409Ssklower ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
2736409Ssklower WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
2836409Ssklower ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2936409Ssklower SOFTWARE.
3036409Ssklower 
3136409Ssklower ******************************************************************/
3236409Ssklower 
3336409Ssklower /*
3436409Ssklower  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
3536409Ssklower  */
3636409Ssklower /*
3736409Ssklower  * ARGO TP
3836409Ssklower  *
3936409Ssklower  * $Header: tp_pcb.h,v 5.2 88/11/18 17:09:32 nhall Exp $
4036409Ssklower  * $Source: /usr/argo/sys/netiso/RCS/tp_pcb.h,v $
4136409Ssklower  *
4236409Ssklower  *
4336409Ssklower  * This file defines the transport protocol control block (tpcb).
4436409Ssklower  * and a bunch of #define values that are used in the tpcb.
4536409Ssklower  */
4636409Ssklower 
4736409Ssklower #ifndef  __TP_PCB__
4836409Ssklower #define  __TP_PCB__
4936409Ssklower 
5036409Ssklower #include "../netiso/tp_param.h"
5136409Ssklower #include "../netiso/tp_timer.h"
5236409Ssklower #include "../netiso/tp_user.h"
5336409Ssklower #ifndef sblock
5437536Smckusick #include "socketvar.h"
5536409Ssklower #endif sblock
5636409Ssklower 
5736409Ssklower /* NOTE: the code depends on REF_CLOSED > REF_OPEN > the rest, and
5836409Ssklower  * on REF_FREE being zero
5936409Ssklower  *
6036409Ssklower  * Possible improvement:
6136409Ssklower  * think about merging the tp_ref w/ the tpcb and doing a search
6236409Ssklower  * through the tpcb list, from tpb. This would slow down lookup
6336409Ssklower  * during data transfer
6436409Ssklower  * It would be a little nicer also to have something based on the
6536409Ssklower  * clock (like top n bits of the reference is part of the clock, to
6636409Ssklower  * minimize the likelihood  of reuse after a crash)
6736409Ssklower  * also, need to keep the timer servicing part to a minimum (although
6836409Ssklower  * the cost of this is probably independent of whether the timers are
6936409Ssklower  * in the pcb or in an array..
7036409Ssklower  * Last, would have to make the number of timers a function of the amount of
7136409Ssklower  * mbufs available, plus some for the frozen references.
7236409Ssklower  *
7336409Ssklower  * Possible improvement:
7436409Ssklower  * Might not need the ref_state stuff either...
7536409Ssklower  * REF_FREE could correspond to tp_state == CLOSED or nonexistend tpcb,
7636409Ssklower  * REF_OPEN to tp_state anywhere from AK_WAIT or CR_SENT to CLOSING
7736409Ssklower  * REF_OPENING could correspond to LISTENING, because that's the
7836409Ssklower  * way it's used, not because the correspondence is exact.
7936409Ssklower  * REF_CLOSED could correspond to REFWAIT
8036409Ssklower  */
8136409Ssklower #define REF_FROZEN 3	/* has ref timer only */
8236409Ssklower #define REF_OPEN 2		/* has timers, possibly active */
8336409Ssklower #define REF_OPENING 1	/* in use (has a pcb) but no timers */
8436409Ssklower #define REF_FREE 0		/* free to reallocate */
8536409Ssklower 
8651204Ssklower #define TM_NTIMERS 		6
8736409Ssklower 
8836409Ssklower struct tp_ref {
8951007Ssklower /*	u_char	 			tpr_state; /* values REF_FROZEN, etc. above */
9051007Ssklower #define	tpr_state		tpr_pcb->tp_refstate
9136409Ssklower 	struct tp_pcb 		*tpr_pcb;	/* back ptr to PCB */
9236409Ssklower };
9336409Ssklower 
9451006Ssklower struct tp_refinfo {
9551006Ssklower 	struct tp_ref		*tpr_base;
9651006Ssklower 	int					tpr_size;
9751007Ssklower 	int					tpr_maxopen;
9851007Ssklower 	int					tpr_numopen;
9951006Ssklower };
10051006Ssklower 
10136409Ssklower struct tp_param {
10236409Ssklower 	/* PER system stuff (one static structure instead of a bunch of names) */
10336409Ssklower 	unsigned 	tpp_configed:1;			/* Has TP been initialized? */
10436409Ssklower };
10536409Ssklower 
10636409Ssklower 
10736409Ssklower struct nl_protosw {
10836409Ssklower 	int		nlp_afamily;			/* address family */
10936409Ssklower 	int		(*nlp_putnetaddr)();	/* puts addresses in nl pcb */
11036409Ssklower 	int		(*nlp_getnetaddr)();	/* gets addresses from nl pcb */
11144424Ssklower 	int		(*nlp_cmpnetaddr)();	/* compares address in pcb with sockaddr */
11236409Ssklower 	int		(*nlp_putsufx)();		/* puts transport suffixes in nl pcb */
11336409Ssklower 	int		(*nlp_getsufx)();		/* gets transport suffixes from nl pcb */
11436409Ssklower 	int		(*nlp_recycle_suffix)();/* clears suffix from nl pcb */
11536409Ssklower 	int		(*nlp_mtu)();			/* figures out mtu based on nl used */
11636409Ssklower 	int		(*nlp_pcbbind)();		/* bind to pcb for net level */
11736409Ssklower 	int		(*nlp_pcbconn)();		/* connect for net level */
11836409Ssklower 	int		(*nlp_pcbdisc)();		/* disconnect net level */
11936409Ssklower 	int		(*nlp_pcbdetach)();		/* detach net level pcb */
12036409Ssklower 	int		(*nlp_pcballoc)();		/* allocate a net level pcb */
12136409Ssklower 	int		(*nlp_output)();		/* prepare a packet to give to nl */
12236409Ssklower 	int		(*nlp_dgoutput)();		/* prepare a packet to give to nl */
12336409Ssklower 	int		(*nlp_ctloutput)();		/* hook for network set/get options */
12436409Ssklower 	caddr_t	nlp_pcblist;			/* list of xx_pcb's for connections */
12544424Ssklower };
12636409Ssklower 
12736409Ssklower 
12836409Ssklower struct tp_pcb {
12944424Ssklower 	struct tp_pcb		*tp_next;
13044424Ssklower 	struct tp_pcb		*tp_prev;
13144424Ssklower 	struct tp_pcb		*tp_nextlisten; /* chain all listeners */
132*51213Ssklower 	struct socket 		*tp_sock;		/* back ptr */
13336409Ssklower 	u_short 			tp_state;		/* state of fsm */
13436409Ssklower 	short 				tp_retrans;		/* # times can still retrans */
13536409Ssklower 	caddr_t				tp_npcb;		/* to lower layer pcb */
13636409Ssklower 	struct nl_protosw	*tp_nlproto;	/* lower-layer dependent routines */
137*51213Ssklower 	struct rtentry		**tp_routep;	/* obtain mtu; inside npcb */
13836409Ssklower 
13936409Ssklower 
14036409Ssklower 	RefNum				tp_lref;	 	/* local reference */
14136409Ssklower 	RefNum 				tp_fref;		/* foreign reference */
14236409Ssklower 
14336409Ssklower 	u_int				tp_seqmask;		/* mask for seq space */
14436409Ssklower 	u_int				tp_seqbit;		/* bit for seq number wraparound */
14536409Ssklower 	u_int				tp_seqhalf;		/* half the seq space */
14636409Ssklower 
14750904Ssklower 	struct mbuf			*tp_ucddata;	/* user connect/disconnect data */
14850904Ssklower 
14936409Ssklower 	/* credit & sequencing info for SENDING */
15036409Ssklower 	u_short 			tp_fcredit;		/* current remote credit in # packets */
15151204Ssklower 	u_short 			tp_maxfcredit;	/* max remote credit in # packets */
15251204Ssklower 	u_short				tp_dupacks;		/* intuit packet loss before rxt timo */
15351204Ssklower 	u_long				tp_cong_win;	/* congestion window in bytes.
15451204Ssklower 										 * see profuse comments in TCP code
15551204Ssklower 										 */
15651204Ssklower 	u_long				tp_ssthresh;	/* cong_win threshold for slow start
15751138Ssklower 										 * exponential to linear switch
15851138Ssklower 										 */
15936409Ssklower 	SeqNum				tp_snduna;		/* seq # of lowest unacked DT */
16051204Ssklower 	SeqNum				tp_sndnew;		/* seq # of lowest unsent DT  */
16150904Ssklower 	SeqNum				tp_sndnum;		/* next seq # to be assigned */
16251204Ssklower 	SeqNum				tp_sndnxt;		/* what to do next; poss. rxt */
16351204Ssklower 	struct mbuf			*tp_sndnxt_m;	/* packet corres. to sndnxt*/
16436409Ssklower 	int					tp_Nwindow;		/* for perf. measurement */
16536409Ssklower 
16636409Ssklower 	/* credit & sequencing info for RECEIVING */
16751204Ssklower 	SeqNum				tp_rcvnxt;		/* next DT seq # expect to recv */
16836409Ssklower 	SeqNum	 			tp_sent_lcdt;	/* cdt according to last ack sent */
16936409Ssklower 	SeqNum	 			tp_sent_uwe;	/* uwe according to last ack sent */
17036409Ssklower 	SeqNum	 			tp_sent_rcvnxt;	/* rcvnxt according to last ack sent
17136409Ssklower 										 * needed for perf measurements only
17236409Ssklower 										 */
17336409Ssklower 	u_short				tp_lcredit;		/* current local credit in # packets */
17450904Ssklower 	u_short				tp_maxlcredit;	/* needed for reassembly queue */
17550904Ssklower 	struct mbuf			**tp_rsyq;		/* unacked stuff recvd out of order */
17651204Ssklower 	int					tp_rsycnt;		/* number of packets "" "" "" ""    */
17736409Ssklower 
17839919Ssklower 	/* receiver congestion state stuff ...  */
17939919Ssklower 	u_int               tp_win_recv;
18039919Ssklower 
18139919Ssklower 	/* receive window as a scaled int (8 bit fraction part) */
18239919Ssklower 
18339919Ssklower 	struct cong_sample {
18439919Ssklower 		ushort  cs_size; 				/* current window size */
18539919Ssklower 		ushort  cs_received;   			/* PDUs received in this sample */
18639919Ssklower 		ushort  cs_ce_set;    /* PDUs received in this sample with CE bit set */
18739919Ssklower 	} tp_cong_sample;
18839919Ssklower 
18939919Ssklower 
19036409Ssklower 	/* parameters per-connection controllable by user */
19136409Ssklower 	struct tp_conn_param _tp_param;
19236409Ssklower 
19336409Ssklower #define	tp_Nretrans _tp_param.p_Nretrans
19436409Ssklower #define	tp_dr_ticks _tp_param.p_dr_ticks
19536409Ssklower #define	tp_cc_ticks _tp_param.p_cc_ticks
19636409Ssklower #define	tp_dt_ticks _tp_param.p_dt_ticks
19736409Ssklower #define	tp_xpd_ticks _tp_param.p_x_ticks
19836409Ssklower #define	tp_cr_ticks _tp_param.p_cr_ticks
19936409Ssklower #define	tp_keepalive_ticks _tp_param.p_keepalive_ticks
20036409Ssklower #define	tp_sendack_ticks _tp_param.p_sendack_ticks
20136409Ssklower #define	tp_refer_ticks _tp_param.p_ref_ticks
20236409Ssklower #define	tp_inact_ticks _tp_param.p_inact_ticks
20336409Ssklower #define	tp_xtd_format _tp_param.p_xtd_format
20436409Ssklower #define	tp_xpd_service _tp_param.p_xpd_service
20536409Ssklower #define	tp_ack_strat _tp_param.p_ack_strat
20636409Ssklower #define	tp_rx_strat _tp_param.p_rx_strat
20736409Ssklower #define	tp_use_checksum _tp_param.p_use_checksum
20836409Ssklower #define	tp_use_efc _tp_param.p_use_efc
20936409Ssklower #define	tp_use_nxpd _tp_param.p_use_nxpd
21036409Ssklower #define	tp_use_rcc _tp_param.p_use_rcc
21136409Ssklower #define	tp_tpdusize _tp_param.p_tpdusize
21236409Ssklower #define	tp_class _tp_param.p_class
21336409Ssklower #define	tp_winsize _tp_param.p_winsize
21436409Ssklower #define	tp_no_disc_indications _tp_param.p_no_disc_indications
21536409Ssklower #define	tp_dont_change_params _tp_param.p_dont_change_params
21636409Ssklower #define	tp_netservice _tp_param.p_netservice
21742490Ssklower #define	tp_version _tp_param.p_version
21836409Ssklower 
21951138Ssklower 	int					tp_l_tpdusize;
22036409Ssklower 		/* whereas tp_tpdusize is log2(the negotiated max size)
22136409Ssklower 		 * l_tpdusize is the size we'll use when sending, in # chars
22236409Ssklower 		 */
22336409Ssklower 
22451138Ssklower 	int					tp_rtv;			/* max round-trip time variance */
22551138Ssklower 	int					tp_rtt; 		/* smoothed round-trip time */
22651138Ssklower 	SeqNum				tp_rttseq;		/* packet being timed */
22751138Ssklower 	int					tp_rttemit;		/* when emitted, in ticks */
22851138Ssklower 	int					tp_idle;		/* last activity, in ticks */
22951138Ssklower 	short				tp_rxtcur;		/* current retransmit value */
23051138Ssklower 	short				tp_rxtshift;	/* log(2) of rexmt exp. backoff */
23151138Ssklower 
23236409Ssklower 	unsigned
23336409Ssklower 		tp_sendfcc:1,			/* shall next ack include FCC parameter? */
23436409Ssklower 		tp_trace:1,				/* is this pcb being traced? (not used yet) */
23536409Ssklower 		tp_perf_on:1,			/* 0/1 -> performance measuring on  */
23636409Ssklower 		tp_reneged:1,			/* have we reneged on cdt since last ack? */
23739919Ssklower 		tp_decbit:3,			/* dec bit was set, we're in reneg mode  */
23839919Ssklower 		tp_cebit_off:1,			/* the real DEC bit algorithms not in use */
23936409Ssklower 		tp_flags:8,				/* values: */
24036409Ssklower #define TPF_NLQOS_PDN	 	TPFLAG_NLQOS_PDN
24136409Ssklower #define TPF_PEER_ON_SAMENET	TPFLAG_PEER_ON_SAMENET
24250851Ssklower #define TPF_GENERAL_ADDR	TPFLAG_GENERAL_ADDR
24351007Ssklower #define TPF_DELACK			0x8
24451007Ssklower #define TPF_ACKNOW			0x10
24536409Ssklower 
24650851Ssklower #define PEER_IS_LOCAL(t)	(((t)->tp_flags & TPF_PEER_ON_SAME_NET) != 0)
24750851Ssklower #define USES_PDN(t)			(((t)->tp_flags & TPF_NLQOS_PDN) != 0)
24836409Ssklower 
24950904Ssklower 		tp_oktonagle:1,			/* Last unsent packet that may be append to */
25050940Ssklower 		tp_notdetached:1,		/* Call tp_detach before freeing XXXXXXX */
25150940Ssklower 		tp_unused:14;
25236409Ssklower 
25336409Ssklower 
25436409Ssklower #ifdef TP_PERF_MEAS
25536409Ssklower 	/* performance stats - see tp_stat.h */
25637469Ssklower 	struct tp_pmeas		*tp_p_meas;
25737469Ssklower 	struct mbuf			*tp_p_mbuf;
25836409Ssklower #endif TP_PERF_MEAS
25937469Ssklower 	/* addressing */
26037469Ssklower 	u_short				tp_domain;		/* domain (INET, ISO) */
26137469Ssklower 	/* for compatibility with the *old* way and with INET, be sure that
26237469Ssklower 	 * that lsuffix and fsuffix are aligned to a short addr.
26337469Ssklower 	 * having them follow the u_short *suffixlen should suffice (choke)
26437469Ssklower 	 */
26537469Ssklower 	u_short				tp_fsuffixlen;	/* foreign suffix */
26637469Ssklower 	char				tp_fsuffix[MAX_TSAP_SEL_LEN];
26737469Ssklower 	u_short				tp_lsuffixlen;	/* local suffix */
26837469Ssklower 	char				tp_lsuffix[MAX_TSAP_SEL_LEN];
26937469Ssklower #define SHORT_LSUFXP(tpcb) ((short *)((tpcb)->tp_lsuffix))
27037469Ssklower #define SHORT_FSUFXP(tpcb) ((short *)((tpcb)->tp_fsuffix))
27137469Ssklower 
27251007Ssklower 	/* Timer stuff */
27351007Ssklower 	u_char 				tp_vers;			/* protocol version */
27451007Ssklower 	u_char 				tp_peer_acktime;	/* used for DT retrans time */
27551007Ssklower 	u_char	 			tp_refstate;		/* values REF_FROZEN, etc. above */
27651007Ssklower 	struct tp_pcb		*tp_fasttimeo;		/* limit pcbs to examine */
27751204Ssklower 	u_int			 	tp_timer[TM_NTIMERS]; /* C timers */
27851007Ssklower 	struct Ecallarg		tp_retransargs;		/* dunt ask ... */
27937469Ssklower 
28037469Ssklower 	struct sockbuf		tp_Xsnd;		/* for expedited data */
28137469Ssklower /*	struct sockbuf		tp_Xrcv;		/* for expedited data */
28237469Ssklower #define tp_Xrcv tp_sock->so_rcv
28337469Ssklower 	SeqNum				tp_Xsndnxt;	/* next XPD seq # to send */
28437469Ssklower 	SeqNum				tp_Xuna;		/* seq # of unacked XPD */
28537469Ssklower 	SeqNum				tp_Xrcvnxt;	/* next XPD seq # expect to recv */
28637469Ssklower 
28737469Ssklower 	/* AK subsequencing */
28837469Ssklower 	u_short				tp_s_subseq;	/* next subseq to send */
28937469Ssklower 	u_short				tp_r_subseq;	/* highest recv subseq */
29037469Ssklower 
29136409Ssklower };
29236409Ssklower 
29339919Ssklower u_int	tp_start_win;
29439919Ssklower 
29539919Ssklower #define ROUND(scaled_int) (((scaled_int) >> 8) + (((scaled_int) & 0x80) ? 1:0))
29639919Ssklower 
29739919Ssklower /* to round off a scaled int with an 8 bit fraction part */
29839919Ssklower 
29939919Ssklower #define CONG_INIT_SAMPLE(pcb) \
30039919Ssklower 	pcb->tp_cong_sample.cs_received = \
30139919Ssklower     pcb->tp_cong_sample.cs_ce_set = 0; \
30239919Ssklower     pcb->tp_cong_sample.cs_size = MAX(pcb->tp_lcredit, 1) << 1;
30339919Ssklower 
30439919Ssklower #define CONG_UPDATE_SAMPLE(pcb, ce_bit) \
30539919Ssklower     pcb->tp_cong_sample.cs_received++; \
30639919Ssklower     if (ce_bit) { \
30739919Ssklower         pcb->tp_cong_sample.cs_ce_set++; \
30839919Ssklower     } \
30939919Ssklower     if (pcb->tp_cong_sample.cs_size <= pcb->tp_cong_sample.cs_received) { \
31039919Ssklower         if ((pcb->tp_cong_sample.cs_ce_set << 1) >=  \
31139919Ssklower                     pcb->tp_cong_sample.cs_size ) { \
31239919Ssklower             pcb->tp_win_recv -= pcb->tp_win_recv >> 3; /* multiply by .875 */ \
31339919Ssklower             pcb->tp_win_recv = MAX(1 << 8, pcb->tp_win_recv); \
31439919Ssklower         } \
31539919Ssklower         else { \
31639919Ssklower             pcb->tp_win_recv += (1 << 8); /* add one to the scaled int */ \
31739919Ssklower         } \
31839919Ssklower         pcb->tp_lcredit = ROUND(pcb->tp_win_recv); \
31939919Ssklower         CONG_INIT_SAMPLE(pcb); \
32039919Ssklower     }
32139919Ssklower 
32244424Ssklower #ifdef KERNEL
32351138Ssklower extern struct tp_refinfo 	tp_refinfo;
32436409Ssklower extern struct timeval 	time;
32551138Ssklower extern struct tp_ref	*tp_ref;
32636409Ssklower extern struct tp_param	tp_param;
32744424Ssklower extern struct nl_protosw  nl_protosw[];
32844424Ssklower extern struct tp_pcb	*tp_listeners;
32951007Ssklower extern struct tp_pcb	*tp_ftimeolist;
33044424Ssklower #endif
33136409Ssklower 
33250435Ssklower #define	sototpcb(so) 	((struct tp_pcb *)(so->so_pcb))
33350435Ssklower #define	sototpref(so)	((sototpcb(so)->tp_ref))
33436409Ssklower #define	tpcbtoso(tp)	((struct socket *)((tp)->tp_sock))
33536409Ssklower #define	tpcbtoref(tp)	((struct tp_ref *)((tp)->tp_ref))
33636409Ssklower 
33736409Ssklower #endif  __TP_PCB__
338