|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*-
26: * Copyright (c) 1991, 1993
27: * The Regents of the University of California. All rights reserved.
28: *
29: * Redistribution and use in source and binary forms, with or without
30: * modification, are permitted provided that the following conditions
31: * are met:
32: * 1. Redistributions of source code must retain the above copyright
33: * notice, this list of conditions and the following disclaimer.
34: * 2. Redistributions in binary form must reproduce the above copyright
35: * notice, this list of conditions and the following disclaimer in the
36: * documentation and/or other materials provided with the distribution.
37: * 3. All advertising materials mentioning features or use of this software
38: * must display the following acknowledgement:
39: * This product includes software developed by the University of
40: * California, Berkeley and its contributors.
41: * 4. Neither the name of the University nor the names of its contributors
42: * may be used to endorse or promote products derived from this software
43: * without specific prior written permission.
44: *
45: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55: * SUCH DAMAGE.
56: *
57: * @(#)tp_pcb.h 8.1 (Berkeley) 6/10/93
58: */
59:
60: /***********************************************************
61: Copyright IBM Corporation 1987
62:
63: All Rights Reserved
64:
65: Permission to use, copy, modify, and distribute this software and its
66: documentation for any purpose and without fee is hereby granted,
67: provided that the above copyright notice appear in all copies and that
68: both that copyright notice and this permission notice appear in
69: supporting documentation, and that the name of IBM not be
70: used in advertising or publicity pertaining to distribution of the
71: software without specific, written prior permission.
72:
73: IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
74: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
75: IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
76: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
77: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
78: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
79: SOFTWARE.
80:
81: ******************************************************************/
82:
83: /*
84: * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
85: */
86: /*
87: * ARGO TP
88: *
89: * This file defines the transport protocol control block (tpcb).
90: * and a bunch of #define values that are used in the tpcb.
91: */
92:
93: #ifndef __TP_PCB__
94: #define __TP_PCB__
95:
96: #include <netiso/tp_param.h>
97: #include <netiso/tp_timer.h>
98: #include <netiso/tp_user.h>
99: #ifndef sblock
100: #include <sys/socketvar.h>
101: #endif /* sblock */
102:
103: /* NOTE: the code depends on REF_CLOSED > REF_OPEN > the rest, and
104: * on REF_FREE being zero
105: *
106: * Possible improvement:
107: * think about merging the tp_ref w/ the tpcb and doing a search
108: * through the tpcb list, from tpb. This would slow down lookup
109: * during data transfer
110: * It would be a little nicer also to have something based on the
111: * clock (like top n bits of the reference is part of the clock, to
112: * minimize the likelihood of reuse after a crash)
113: * also, need to keep the timer servicing part to a minimum (although
114: * the cost of this is probably independent of whether the timers are
115: * in the pcb or in an array..
116: * Last, would have to make the number of timers a function of the amount of
117: * mbufs available, plus some for the frozen references.
118: *
119: * Possible improvement:
120: * Might not need the ref_state stuff either...
121: * REF_FREE could correspond to tp_state == CLOSED or nonexistend tpcb,
122: * REF_OPEN to tp_state anywhere from AK_WAIT or CR_SENT to CLOSING
123: * REF_OPENING could correspond to LISTENING, because that's the
124: * way it's used, not because the correspondence is exact.
125: * REF_CLOSED could correspond to REFWAIT
126: */
127: #define REF_FROZEN 3 /* has ref timer only */
128: #define REF_OPEN 2 /* has timers, possibly active */
129: #define REF_OPENING 1 /* in use (has a pcb) but no timers */
130: #define REF_FREE 0 /* free to reallocate */
131:
132: #define TM_NTIMERS 6
133:
134: struct tp_ref {
135: struct tp_pcb *tpr_pcb; /* back ptr to PCB */
136: };
137:
138: /* PER system stuff (one static structure instead of a bunch of names) */
139: struct tp_refinfo {
140: struct tp_ref *tpr_base;
141: int tpr_size;
142: int tpr_maxopen;
143: int tpr_numopen;
144: };
145:
146: struct nl_protosw {
147: int nlp_afamily; /* address family */
148: int (*nlp_putnetaddr)(); /* puts addresses in nl pcb */
149: int (*nlp_getnetaddr)(); /* gets addresses from nl pcb */
150: int (*nlp_cmpnetaddr)(); /* compares address in pcb with sockaddr */
151: int (*nlp_putsufx)(); /* puts transport suffixes in nl pcb */
152: int (*nlp_getsufx)(); /* gets transport suffixes from nl pcb */
153: int (*nlp_recycle_suffix)();/* clears suffix from nl pcb */
154: int (*nlp_mtu)(); /* figures out mtu based on nl used */
155: int (*nlp_pcbbind)(); /* bind to pcb for net level */
156: int (*nlp_pcbconn)(); /* connect for net level */
157: int (*nlp_pcbdisc)(); /* disconnect net level */
158: int (*nlp_pcbdetach)(); /* detach net level pcb */
159: int (*nlp_pcballoc)(); /* allocate a net level pcb */
160: int (*nlp_output)(); /* prepare a packet to give to nl */
161: int (*nlp_dgoutput)(); /* prepare a packet to give to nl */
162: int (*nlp_ctloutput)(); /* hook for network set/get options */
163: caddr_t nlp_pcblist; /* list of xx_pcb's for connections */
164: };
165:
166:
167: struct tp_pcb {
168: struct tp_pcb *tp_next;
169: struct tp_pcb *tp_prev;
170: struct tp_pcb *tp_nextlisten; /* chain all listeners */
171: struct socket *tp_sock; /* back ptr */
172: u_short tp_state; /* state of fsm */
173: short tp_retrans; /* # times can still retrans */
174: caddr_t tp_npcb; /* to lower layer pcb */
175: struct nl_protosw *tp_nlproto; /* lower-layer dependent routines */
176: struct rtentry **tp_routep; /* obtain mtu; inside npcb */
177:
178:
179: RefNum tp_lref; /* local reference */
180: RefNum tp_fref; /* foreign reference */
181:
182: u_int tp_seqmask; /* mask for seq space */
183: u_int tp_seqbit; /* bit for seq number wraparound */
184: u_int tp_seqhalf; /* half the seq space */
185:
186: struct mbuf *tp_ucddata; /* user connect/disconnect data */
187:
188: /* credit & sequencing info for SENDING */
189: u_short tp_fcredit; /* current remote credit in # packets */
190: u_short tp_maxfcredit; /* max remote credit in # packets */
191: u_short tp_dupacks; /* intuit packet loss before rxt timo */
192: u_long tp_cong_win; /* congestion window in bytes.
193: * see profuse comments in TCP code
194: */
195: u_long tp_ssthresh; /* cong_win threshold for slow start
196: * exponential to linear switch
197: */
198: SeqNum tp_snduna; /* seq # of lowest unacked DT */
199: SeqNum tp_sndnew; /* seq # of lowest unsent DT */
200: SeqNum tp_sndnum; /* next seq # to be assigned */
201: SeqNum tp_sndnxt; /* what to do next; poss. rxt */
202: struct mbuf *tp_sndnxt_m; /* packet corres. to sndnxt*/
203: int tp_Nwindow; /* for perf. measurement */
204:
205: /* credit & sequencing info for RECEIVING */
206: SeqNum tp_rcvnxt; /* next DT seq # expect to recv */
207: SeqNum tp_sent_lcdt; /* cdt according to last ack sent */
208: SeqNum tp_sent_uwe; /* uwe according to last ack sent */
209: SeqNum tp_sent_rcvnxt; /* rcvnxt according to last ack sent
210: * needed for perf measurements only
211: */
212: u_short tp_lcredit; /* current local credit in # packets */
213: u_short tp_maxlcredit; /* needed for reassembly queue */
214: struct mbuf **tp_rsyq; /* unacked stuff recvd out of order */
215: int tp_rsycnt; /* number of packets "" "" "" "" */
216: u_long tp_rhiwat; /* remember original RCVBUF size */
217:
218: /* receiver congestion state stuff ... */
219: u_int tp_win_recv;
220:
221: /* receive window as a scaled int (8 bit fraction part) */
222:
223: struct cong_sample {
224: ushort cs_size; /* current window size */
225: ushort cs_received; /* PDUs received in this sample */
226: ushort cs_ce_set; /* PDUs received in this sample with CE bit set */
227: } tp_cong_sample;
228:
229:
230: /* parameters per-connection controllable by user */
231: struct tp_conn_param _tp_param;
232:
233: #define tp_Nretrans _tp_param.p_Nretrans
234: #define tp_dr_ticks _tp_param.p_dr_ticks
235: #define tp_cc_ticks _tp_param.p_cc_ticks
236: #define tp_dt_ticks _tp_param.p_dt_ticks
237: #define tp_xpd_ticks _tp_param.p_x_ticks
238: #define tp_cr_ticks _tp_param.p_cr_ticks
239: #define tp_keepalive_ticks _tp_param.p_keepalive_ticks
240: #define tp_sendack_ticks _tp_param.p_sendack_ticks
241: #define tp_refer_ticks _tp_param.p_ref_ticks
242: #define tp_inact_ticks _tp_param.p_inact_ticks
243: #define tp_xtd_format _tp_param.p_xtd_format
244: #define tp_xpd_service _tp_param.p_xpd_service
245: #define tp_ack_strat _tp_param.p_ack_strat
246: #define tp_rx_strat _tp_param.p_rx_strat
247: #define tp_use_checksum _tp_param.p_use_checksum
248: #define tp_use_efc _tp_param.p_use_efc
249: #define tp_use_nxpd _tp_param.p_use_nxpd
250: #define tp_use_rcc _tp_param.p_use_rcc
251: #define tp_tpdusize _tp_param.p_tpdusize
252: #define tp_class _tp_param.p_class
253: #define tp_winsize _tp_param.p_winsize
254: #define tp_no_disc_indications _tp_param.p_no_disc_indications
255: #define tp_dont_change_params _tp_param.p_dont_change_params
256: #define tp_netservice _tp_param.p_netservice
257: #define tp_version _tp_param.p_version
258: #define tp_ptpdusize _tp_param.p_ptpdusize
259:
260: int tp_l_tpdusize;
261: /* whereas tp_tpdusize is log2(the negotiated max size)
262: * l_tpdusize is the size we'll use when sending, in # chars
263: */
264:
265: int tp_rtv; /* max round-trip time variance */
266: int tp_rtt; /* smoothed round-trip time */
267: SeqNum tp_rttseq; /* packet being timed */
268: int tp_rttemit; /* when emitted, in ticks */
269: int tp_idle; /* last activity, in ticks */
270: short tp_rxtcur; /* current retransmit value */
271: short tp_rxtshift; /* log(2) of rexmt exp. backoff */
272: u_char tp_cebit_off; /* real DEC bit algorithms not in use */
273: u_char tp_oktonagle; /* Last unsent pckt may be append to */
274: u_char tp_flags; /* values: */
275: #define TPF_NLQOS_PDN TPFLAG_NLQOS_PDN
276: #define TPF_PEER_ON_SAMENET TPFLAG_PEER_ON_SAMENET
277: #define TPF_GENERAL_ADDR TPFLAG_GENERAL_ADDR
278: #define TPF_DELACK 0x8
279: #define TPF_ACKNOW 0x10
280:
281: #define PEER_IS_LOCAL(t) (((t)->tp_flags & TPF_PEER_ON_SAME_NET) != 0)
282: #define USES_PDN(t) (((t)->tp_flags & TPF_NLQOS_PDN) != 0)
283:
284:
285: unsigned
286: tp_sendfcc:1, /* shall next ack include FCC parameter? */
287: tp_trace:1, /* is this pcb being traced? (not used yet) */
288: tp_perf_on:1, /* 0/1 -> performance measuring on */
289: tp_reneged:1, /* have we reneged on cdt since last ack? */
290: tp_decbit:3, /* dec bit was set, we're in reneg mode */
291: tp_notdetached:1; /* Call tp_detach before freeing XXXXXXX */
292:
293: #ifdef TP_PERF_MEAS
294: /* performance stats - see tp_stat.h */
295: struct tp_pmeas *tp_p_meas;
296: struct mbuf *tp_p_mbuf;
297: #endif /* TP_PERF_MEAS */
298:
299: /* addressing */
300: u_short tp_domain; /* domain (INET, ISO) */
301: /* for compatibility with the *old* way and with INET, be sure that
302: * that lsuffix and fsuffix are aligned to a short addr.
303: * having them follow the u_short *suffixlen should suffice (choke)
304: */
305: u_short tp_fsuffixlen; /* foreign suffix */
306: char tp_fsuffix[MAX_TSAP_SEL_LEN];
307: u_short tp_lsuffixlen; /* local suffix */
308: char tp_lsuffix[MAX_TSAP_SEL_LEN];
309: #define SHORT_LSUFXP(tpcb) ((short *)((tpcb)->tp_lsuffix))
310: #define SHORT_FSUFXP(tpcb) ((short *)((tpcb)->tp_fsuffix))
311:
312: /* Timer stuff */
313: u_char tp_vers; /* protocol version */
314: u_char tp_peer_acktime; /* used for DT retrans time */
315: u_char tp_refstate; /* values REF_FROZEN, etc. above */
316: struct tp_pcb *tp_fasttimeo; /* limit pcbs to examine */
317: u_int tp_timer[TM_NTIMERS]; /* C timers */
318:
319: struct sockbuf tp_Xsnd; /* for expedited data */
320: /* struct sockbuf tp_Xrcv; /* for expedited data */
321: #define tp_Xrcv tp_sock->so_rcv
322: SeqNum tp_Xsndnxt; /* next XPD seq # to send */
323: SeqNum tp_Xuna; /* seq # of unacked XPD */
324: SeqNum tp_Xrcvnxt; /* next XPD seq # expect to recv */
325:
326: /* AK subsequencing */
327: u_short tp_s_subseq; /* next subseq to send */
328: u_short tp_r_subseq; /* highest recv subseq */
329:
330: };
331:
332: u_int tp_start_win;
333:
334: #define ROUND(scaled_int) (((scaled_int) >> 8) + (((scaled_int) & 0x80) ? 1:0))
335:
336: /* to round off a scaled int with an 8 bit fraction part */
337:
338: #define CONG_INIT_SAMPLE(pcb) \
339: pcb->tp_cong_sample.cs_received = \
340: pcb->tp_cong_sample.cs_ce_set = 0; \
341: pcb->tp_cong_sample.cs_size = max(pcb->tp_lcredit, 1) << 1;
342:
343: #define CONG_UPDATE_SAMPLE(pcb, ce_bit) \
344: pcb->tp_cong_sample.cs_received++; \
345: if (ce_bit) { \
346: pcb->tp_cong_sample.cs_ce_set++; \
347: } \
348: if (pcb->tp_cong_sample.cs_size <= pcb->tp_cong_sample.cs_received) { \
349: if ((pcb->tp_cong_sample.cs_ce_set << 1) >= \
350: pcb->tp_cong_sample.cs_size ) { \
351: pcb->tp_win_recv -= pcb->tp_win_recv >> 3; /* multiply by .875 */ \
352: pcb->tp_win_recv = max(1 << 8, pcb->tp_win_recv); \
353: } \
354: else { \
355: pcb->tp_win_recv += (1 << 8); /* add one to the scaled int */ \
356: } \
357: pcb->tp_lcredit = ROUND(pcb->tp_win_recv); \
358: CONG_INIT_SAMPLE(pcb); \
359: }
360:
361: #ifdef _KERNEL
362: extern struct tp_refinfo tp_refinfo;
363: extern struct timeval time;
364: extern struct tp_ref *tp_ref;
365: extern struct tp_param tp_param;
366: extern struct nl_protosw nl_protosw[];
367: extern struct tp_pcb *tp_listeners;
368: extern struct tp_pcb *tp_ftimeolist;
369: #endif
370:
371: #define sototpcb(so) ((struct tp_pcb *)(so->so_pcb))
372: #define sototpref(so) ((sototpcb(so)->tp_ref))
373: #define tpcbtoso(tp) ((struct socket *)((tp)->tp_sock))
374: #define tpcbtoref(tp) ((struct tp_ref *)((tp)->tp_ref))
375:
376: #endif /* __TP_PCB__ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.