2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1991, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * @(#)tp_pcb.c 8.1 (Berkeley) 6/10/93
57 /***********************************************************
58 Copyright IBM Corporation 1987
62 Permission to use, copy, modify, and distribute this software and its
63 documentation for any purpose and without fee is hereby granted,
64 provided that the above copyright notice appear in all copies and that
65 both that copyright notice and this permission notice appear in
66 supporting documentation, and that the name of IBM not be
67 used in advertising or publicity pertaining to distribution of the
68 software without specific, written prior permission.
70 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
71 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
72 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
73 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
74 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
75 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
78 ******************************************************************/
81 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
87 * This is the initialization and cleanup stuff -
88 * for the tp machine in general as well as for the individual pcbs.
89 * tp_init() is called at system startup. tp_attach() and tp_getref() are
90 * called when a socket is created. tp_detach() and tp_freeref()
91 * are called during the closing stage and/or when the reference timer
93 * tp_soisdisconnecting() and tp_soisdisconnected() are tp-specific
94 * versions of soisconnect*
95 * and are called (obviously) during the closing phase.
99 #include <sys/param.h>
100 #include <sys/systm.h>
101 #include <sys/mbuf.h>
102 #include <sys/socket.h>
103 #include <sys/socketvar.h>
104 #include <sys/domain.h>
105 #include <sys/protosw.h>
106 #include <sys/errno.h>
107 #include <sys/time.h>
109 #include <netiso/argo_debug.h>
110 #include <netiso/tp_param.h>
111 #include <netiso/tp_timer.h>
112 #include <netiso/tp_ip.h>
113 #include <netiso/tp_stat.h>
114 #include <netiso/tp_pcb.h>
115 #include <netiso/tp_tpdu.h>
116 #include <netiso/tp_trace.h>
117 #include <netiso/tp_meas.h>
118 #include <netiso/tp_seq.h>
119 #include <netiso/tp_clnp.h>
121 /* ticks are in units of:
122 * 500 nano-fortnights ;-) or
127 struct tp_conn_param tp_conn_param
[] = {
128 /* ISO_CLNS: TP4 CONNECTION LESS */
130 TP_NRETRANS
, /* short p_Nretrans; */
131 20, /* 10 sec */ /* short p_dr_ticks; */
133 20, /* 10 sec */ /* short p_cc_ticks; */
134 20, /* 10 sec */ /* short p_dt_ticks; */
136 40, /* 20 sec */ /* short p_x_ticks; */
137 80, /* 40 sec */ /* short p_cr_ticks;*/
139 240, /* 2 min */ /* short p_keepalive_ticks;*/
140 10, /* 5 sec */ /* short p_sendack_ticks; */
142 600, /* 5 min */ /* short p_ref_ticks; */
143 360, /* 3 min */ /* short p_inact_ticks; */
145 (short) 100, /* short p_lcdtfract */
146 (short) TP_SOCKBUFSIZE
, /* short p_winsize */
147 TP_TPDUSIZE
, /* u_char p_tpdusize */
149 TPACK_WINDOW
, /* 4 bits p_ack_strat */
150 TPRX_USE_CW
| TPRX_FASTSTART
,
151 /* 4 bits p_rx_strat*/
152 TP_CLASS_4
| TP_CLASS_0
,/* 5 bits p_class */
153 1, /* 1 bit xtd format */
154 1, /* 1 bit xpd service */
155 1, /* 1 bit use_checksum */
156 0, /* 1 bit use net xpd */
157 0, /* 1 bit use rcc */
158 0, /* 1 bit use efc */
159 1, /* no disc indications */
160 0, /* don't change params */
161 ISO_CLNS
, /* p_netservice */
163 /* IN_CLNS: TP4 CONNECTION LESS */
165 TP_NRETRANS
, /* short p_Nretrans; */
166 20, /* 10 sec */ /* short p_dr_ticks; */
168 20, /* 10 sec */ /* short p_cc_ticks; */
169 20, /* 10 sec */ /* short p_dt_ticks; */
171 40, /* 20 sec */ /* short p_x_ticks; */
172 80, /* 40 sec */ /* short p_cr_ticks;*/
174 240, /* 2 min */ /* short p_keepalive_ticks;*/
175 10, /* 5 sec */ /* short p_sendack_ticks; */
177 600, /* 5 min */ /* short p_ref_ticks; */
178 360, /* 3 min */ /* short p_inact_ticks; */
180 (short) 100, /* short p_lcdtfract */
181 (short) TP_SOCKBUFSIZE
, /* short p_winsize */
182 TP_TPDUSIZE
, /* u_char p_tpdusize */
184 TPACK_WINDOW
, /* 4 bits p_ack_strat */
185 TPRX_USE_CW
| TPRX_FASTSTART
,
186 /* 4 bits p_rx_strat*/
187 TP_CLASS_4
, /* 5 bits p_class */
188 1, /* 1 bit xtd format */
189 1, /* 1 bit xpd service */
190 1, /* 1 bit use_checksum */
191 0, /* 1 bit use net xpd */
192 0, /* 1 bit use rcc */
193 0, /* 1 bit use efc */
194 1, /* no disc indications */
195 0, /* don't change params */
196 IN_CLNS
, /* p_netservice */
198 /* ISO_CONS: TP0 CONNECTION MODE */
200 TP_NRETRANS
, /* short p_Nretrans; */
201 0, /* n/a */ /* short p_dr_ticks; */
203 40, /* 20 sec */ /* short p_cc_ticks; */
204 0, /* n/a */ /* short p_dt_ticks; */
206 0, /* n/a */ /* short p_x_ticks; */
207 360, /* 3 min */ /* short p_cr_ticks;*/
209 0, /* n/a */ /* short p_keepalive_ticks;*/
210 0, /* n/a */ /* short p_sendack_ticks; */
212 600, /* for cr/cc to clear *//* short p_ref_ticks; */
213 0, /* n/a */ /* short p_inact_ticks; */
215 /* Use tp4 defaults just in case the user changes ONLY
218 (short) 100, /* short p_lcdtfract */
219 (short) TP0_SOCKBUFSIZE
, /* short p_winsize */
220 TP0_TPDUSIZE
, /* 8 bits p_tpdusize */
222 0, /* 4 bits p_ack_strat */
223 0, /* 4 bits p_rx_strat*/
224 TP_CLASS_0
, /* 5 bits p_class */
225 0, /* 1 bit xtd format */
226 0, /* 1 bit xpd service */
227 0, /* 1 bit use_checksum */
228 0, /* 1 bit use net xpd */
229 0, /* 1 bit use rcc */
230 0, /* 1 bit use efc */
231 0, /* no disc indications */
232 0, /* don't change params */
233 ISO_CONS
, /* p_netservice */
235 /* ISO_COSNS: TP4 CONNECTION LESS SERVICE over CONSNS */
237 TP_NRETRANS
, /* short p_Nretrans; */
238 40, /* 20 sec */ /* short p_dr_ticks; */
240 40, /* 20 sec */ /* short p_cc_ticks; */
241 80, /* 40 sec */ /* short p_dt_ticks; */
243 120, /* 1 min */ /* short p_x_ticks; */
244 360, /* 3 min */ /* short p_cr_ticks;*/
246 360, /* 3 min */ /* short p_keepalive_ticks;*/
247 20, /* 10 sec */ /* short p_sendack_ticks; */
249 600, /* 5 min */ /* short p_ref_ticks; */
250 480, /* 4 min */ /* short p_inact_ticks; */
252 (short) 100, /* short p_lcdtfract */
253 (short) TP0_SOCKBUFSIZE
, /* short p_winsize */
254 TP0_TPDUSIZE
, /* u_char p_tpdusize */
256 TPACK_WINDOW
, /* 4 bits p_ack_strat */
257 TPRX_USE_CW
, /* No fast start */
258 /* 4 bits p_rx_strat*/
259 TP_CLASS_4
| TP_CLASS_0
,/* 5 bits p_class */
260 0, /* 1 bit xtd format */
261 1, /* 1 bit xpd service */
262 1, /* 1 bit use_checksum */
263 0, /* 1 bit use net xpd */
264 0, /* 1 bit use rcc */
265 0, /* 1 bit use efc */
266 0, /* no disc indications */
267 0, /* don't change params */
268 ISO_COSNS
, /* p_netservice */
278 int in_recycle_tsuffix();
282 int in_pcbdisconnect();
286 int tpip_output_dg();
287 struct inpcb tp_inpcb
;
290 int iso_putnetaddr();
291 int iso_getnetaddr();
292 int iso_cmpnetaddr();
295 int iso_recycle_tsuffix();
298 int iso_pcbconnect();
299 int iso_pcbdisconnect();
303 int tpclnp_output_dg();
304 int iso_nlctloutput();
305 struct isopcb tp_isopcb
;
308 int iso_putnetaddr();
309 int iso_getnetaddr();
310 int iso_cmpnetaddr();
313 int iso_recycle_tsuffix();
315 int tpcons_pcbconnect();
317 int iso_pcbdisconnect();
321 struct isopcb tp_isopcb
;
325 struct nl_protosw nl_protosw
[] = {
328 { AF_ISO
, iso_putnetaddr
, iso_getnetaddr
, iso_cmpnetaddr
,
329 iso_putsufx
, iso_getsufx
,
331 tpclnp_mtu
, iso_pcbbind
, iso_pcbconnect
,
332 iso_pcbdisconnect
, iso_pcbdetach
,
334 tpclnp_output
, tpclnp_output_dg
, iso_nlctloutput
,
335 (caddr_t
) &tp_isopcb
,
342 { AF_INET
, in_putnetaddr
, in_getnetaddr
, in_cmpnetaddr
,
343 in_putsufx
, in_getsufx
,
345 tpip_mtu
, in_pcbbind
, in_pcbconnect
,
346 in_pcbdisconnect
, in_pcbdetach
,
348 tpip_output
, tpip_output_dg
, /* nl_ctloutput */ NULL
,
355 #if defined(ISO) && defined(TPCONS)
356 { AF_ISO
, iso_putnetaddr
, iso_getnetaddr
, iso_cmpnetaddr
,
357 iso_putsufx
, iso_getsufx
,
359 tpclnp_mtu
, iso_pcbbind
, tpcons_pcbconnect
,
360 iso_pcbdisconnect
, iso_pcbdetach
,
362 tpcons_output
, tpcons_output
, iso_nlctloutput
,
363 (caddr_t
) &tp_isopcb
,
367 #endif /* ISO_CONS */
368 /* End of protosw marker */
372 u_long tp_sendspace
= 1024 * 4;
373 u_long tp_recvspace
= 1024 * 4;
379 * autoconf through the protosw structure
382 * initialize tp machine
393 static int init_done
=0;
401 tp_inpcb
.inp_next
= tp_inpcb
.inp_prev
= &tp_inpcb
;
403 tp_isopcb
.isop_next
= tp_isopcb
.isop_prev
= &tp_isopcb
;
408 bzero((caddr_t
)&tp_stat
, sizeof(struct tp_stat
));
413 * NAME: tp_soisdisconnecting()
418 * FUNCTION and ARGUMENTS:
419 * Set state of the socket (so) to reflect that fact that we're disconnectING
426 * This differs from the regular soisdisconnecting() in that the latter
427 * also sets the SS_CANTRECVMORE and SS_CANTSENDMORE flags.
428 * We don't want to set those flags because those flags will cause
429 * a SIGPIPE to be delivered in sosend() and we don't like that.
430 * If anyone else is sleeping on this socket, wake 'em up.
433 tp_soisdisconnecting(so
)
434 register struct socket
*so
;
436 soisdisconnecting(so
);
437 so
->so_state
&= ~SS_CANTSENDMORE
;
439 register struct tp_pcb
*tpcb
= sototpcb(so
);
442 bcopy ((caddr_t
)tpcb
->tp_fsuffix
, (caddr_t
)&fsufx
, sizeof(u_int
) );
443 bcopy ((caddr_t
)tpcb
->tp_lsuffix
, (caddr_t
)&lsufx
, sizeof(u_int
) );
445 tpmeas(tpcb
->tp_lref
, TPtime_close
, &time
, fsufx
, lsufx
, tpcb
->tp_fref
);
446 tpcb
->tp_perf_on
= 0; /* turn perf off */
452 * NAME: tp_soisdisconnected()
457 * FUNCTION and ARGUMENTS:
458 * Set state of the socket (so) to reflect that fact that we're disconnectED
459 * Set the state of the reference structure to closed, and
460 * recycle the suffix.
461 * Start a reference timer.
468 * This differs from the regular soisdisconnected() in that the latter
469 * also sets the SS_CANTRECVMORE and SS_CANTSENDMORE flags.
470 * We don't want to set those flags because those flags will cause
471 * a SIGPIPE to be delivered in sosend() and we don't like that.
472 * If anyone else is sleeping on this socket, wake 'em up.
475 tp_soisdisconnected(tpcb
)
476 register struct tp_pcb
*tpcb
;
478 register struct socket
*so
= tpcb
->tp_sock
;
480 soisdisconnecting(so
);
481 so
->so_state
&= ~SS_CANTSENDMORE
;
483 register struct tp_pcb
*ttpcb
= sototpcb(so
);
487 bcopy ((caddr_t
)ttpcb
->tp_fsuffix
, (caddr_t
)&fsufx
, sizeof(u_int
) );
488 bcopy ((caddr_t
)ttpcb
->tp_lsuffix
, (caddr_t
)&lsufx
, sizeof(u_int
) );
490 tpmeas(ttpcb
->tp_lref
, TPtime_close
,
491 &time
, &lsufx
, &fsufx
, ttpcb
->tp_fref
);
492 tpcb
->tp_perf_on
= 0; /* turn perf off */
495 tpcb
->tp_refstate
= REF_FROZEN
;
496 tp_recycle_tsuffix(tpcb
);
497 tp_etimeout(tpcb
, TM_reference
, (int)tpcb
->tp_refer_ticks
);
504 * tp.trans when the reference timer goes off, and
505 * from tp_attach() and tp_detach() when a tpcb is partially set up but not
506 * set up enough to have a ref timer set for it, and it's discarded
507 * due to some sort of error or an early close()
509 * FUNCTION and ARGUMENTS:
510 * Frees the reference represented by (r) for re-use.
516 * NOTES: better be called at clock priority !!!!!
522 register struct tp_ref
*r
= tp_ref
+ n
;
523 register struct tp_pcb
*tpcb
;
527 printf("tp_freeref called for ref %d pcb %x maxrefopen %d\n",
528 n
, tpcb
, tp_refinfo
.tpr_maxopen
);
531 tptrace(TPPTmisc
, "tp_freeref ref maxrefopen pcb",
532 n
, tp_refinfo
.tpr_maxopen
, tpcb
, 0);
537 printf("tp_freeref: CLEARING tpr_pcb 0x%x\n", tpcb
);
539 r
->tpr_pcb
= (struct tp_pcb
*)0;
540 tpcb
->tp_refstate
= REF_FREE
;
542 for (r
= tp_ref
+ tp_refinfo
.tpr_maxopen
; r
> tp_ref
; r
--)
545 tp_refinfo
.tpr_maxopen
= r
- tp_ref
;
546 tp_refinfo
.tpr_numopen
--;
549 printf("tp_freeref ends w/ maxrefopen %d\n", tp_refinfo
.tpr_maxopen
);
559 * FUNCTION and ARGUMENTS:
560 * obtains the next free reference and allocates the appropriate
561 * ref structure, links that structure to (tpcb)
573 register struct tp_pcb
*tpcb
;
575 register struct tp_ref
*r
, *rlim
;
580 if (++tp_refinfo
.tpr_numopen
< tp_refinfo
.tpr_size
)
581 for (r
= tp_refinfo
.tpr_base
, rlim
= r
+ tp_refinfo
.tpr_size
;
582 ++r
< rlim
; ) /* tp_ref[0] is never used */
585 /* else have to allocate more space */
587 obase
= (caddr_t
)tp_refinfo
.tpr_base
;
588 size
= tp_refinfo
.tpr_size
* sizeof(struct tp_ref
);
589 // r = (struct tp_ref *) malloc(size + size, M_PCB, M_NOWAIT);
590 MALLOC(r
, struct tp_ref
*, size
+ size
, M_PCB
, M_NOWAIT
);
592 return (--tp_refinfo
.tpr_numopen
, TP_ENOREF
);
593 tp_refinfo
.tpr_base
= tp_ref
= r
;
594 tp_refinfo
.tpr_size
*= 2;
595 bcopy(obase
, (caddr_t
)r
, size
);
597 r
= (struct tp_ref
*)(size
+ (caddr_t
)r
);
598 bzero((caddr_t
)r
, size
);
602 tpcb
->tp_refstate
= REF_OPENING
;
603 i
= r
- tp_refinfo
.tpr_base
;
604 if (tp_refinfo
.tpr_maxopen
< i
)
605 tp_refinfo
.tpr_maxopen
= i
;
610 * NAME: tp_set_npcb()
613 * tp_attach(), tp_route_to()
615 * FUNCTION and ARGUMENTS:
616 * given a tpcb, allocate an appropriate lower-lever npcb, freeing
617 * any old ones that might need re-assigning.
620 register struct tp_pcb
*tpcb
;
622 register struct socket
*so
= tpcb
->tp_sock
;
625 if (tpcb
->tp_nlproto
&& tpcb
->tp_npcb
) {
626 short so_state
= so
->so_state
;
627 so
->so_state
&= ~SS_NOFDREF
;
628 tpcb
->tp_nlproto
->nlp_pcbdetach(tpcb
->tp_npcb
);
629 so
->so_state
= so_state
;
631 tpcb
->tp_nlproto
= &nl_protosw
[tpcb
->tp_netservice
];
632 /* xx_pcballoc sets so_pcb */
633 error
= tpcb
->tp_nlproto
->nlp_pcballoc(so
, tpcb
->tp_nlproto
->nlp_pcblist
);
634 tpcb
->tp_npcb
= so
->so_pcb
;
635 so
->so_pcb
= (caddr_t
)tpcb
;
642 * tp_usrreq, PRU_ATTACH
644 * FUNCTION and ARGUMENTS:
645 * given a socket (so) and a protocol family (dom), allocate a tpcb
646 * and ref structure, initialize everything in the structures that
647 * needs to be initialized.
651 * EINVAL if DEBUG(X) in is on and a disaster has occurred
652 * ENOPROTOOPT if TP hasn't been configured or if the
653 * socket wasn't created with tp as its protocol
654 * EISCONN if this socket is already part of a connection
655 * ETOOMANYREFS if ran out of tp reference numbers.
656 * E* whatever error is returned from soreserve()
657 * for from the network-layer pcb allocation routine
663 tp_attach(so
, protocol
)
667 register struct tp_pcb
*tpcb
;
669 int dom
= so
->so_proto
->pr_domain
->dom_family
;
671 extern struct tp_conn_param tp_conn_param
[];
674 printf("tp_attach:dom 0x%x so 0x%x ", dom
, so
);
677 tptrace(TPPTmisc
, "tp_attach:dom so", dom
, so
, 0, 0);
680 if (so
->so_pcb
!= NULL
) {
681 return EISCONN
; /* socket already part of a connection*/
684 if (so
->so_snd
.sb_hiwat
== 0 || so
->so_rcv
.sb_hiwat
== 0)
685 error
= soreserve(so
, tp_sendspace
, tp_recvspace
);
686 /* later an ioctl will allow reallocation IF still in closed state */
691 MALLOC(tpcb
, struct tp_pcb
*, sizeof(*tpcb
), M_PCB
, M_NOWAIT
);
696 bzero( (caddr_t
)tpcb
, sizeof (struct tp_pcb
) );
698 if ( ((lref
= tp_getref(tpcb
)) & TP_ENOREF
) != 0 ) {
699 error
= ETOOMANYREFS
;
702 tpcb
->tp_lref
= lref
;
704 tpcb
->tp_domain
= dom
;
705 tpcb
->tp_rhiwat
= so
->so_rcv
.sb_hiwat
;
706 /* tpcb->tp_proto = protocol; someday maybe? */
707 if (protocol
&& protocol
<ISOPROTO_TP4
) {
708 tpcb
->tp_netservice
= ISO_CONS
;
709 tpcb
->tp_snduna
= (SeqNum
) -1;/* kludge so the pseudo-ack from the CR/CC
710 * will generate correct fake-ack values
713 tpcb
->tp_netservice
= (dom
== AF_INET
)?IN_CLNS
:ISO_CLNS
;
716 tpcb
->_tp_param
= tp_conn_param
[tpcb
->tp_netservice
];
718 tpcb
->tp_state
= TP_CLOSED
;
719 tpcb
->tp_vers
= TP_VERSION
;
720 tpcb
->tp_notdetached
= 1;
722 /* Spec says default is 128 octets,
723 * that is, if the tpdusize argument never appears, use 128.
724 * As the initiator, we will always "propose" the 2048
725 * size, that is, we will put this argument in the CR
726 * always, but accept what the other side sends on the CC.
727 * If the initiator sends us something larger on a CR,
728 * we'll respond w/ this.
729 * Our maximum is 4096. See tp_chksum.c comments.
732 tpcb
->tp_l_tpdusize
= 1 << tpcb
->tp_tpdusize
;
734 tpcb
->tp_seqmask
= TP_NML_FMT_MASK
;
735 tpcb
->tp_seqbit
= TP_NML_FMT_BIT
;
736 tpcb
->tp_seqhalf
= tpcb
->tp_seqbit
>> 1;
738 /* attach to a network-layer protoswitch */
739 if ( error
= tp_set_npcb(tpcb
))
741 ASSERT( tpcb
->tp_nlproto
->nlp_afamily
== tpcb
->tp_domain
);
743 /* nothing to do for iso case */
745 sotoinpcb(so
)->inp_ppcb
= (caddr_t
) tpcb
;
751 printf("BAD4 in tp_attach, so 0x%x\n", so
);
753 tp_freeref(tpcb
->tp_lref
);
757 printf("BAD3 in tp_attach, so 0x%x\n", so
);
760 FREE((caddr_t
)tpcb
, M_PCB
); /* never a cluster */
764 printf("BAD2 in tp_attach, so 0x%x\n", so
);
770 printf("BAD in tp_attach, so 0x%x\n", so
);
779 * tp.trans, on behalf of a user close request
780 * and when the reference timer goes off
781 * (if the disconnect was initiated by the protocol entity
782 * rather than by the user)
784 * FUNCTION and ARGUMENTS:
785 * remove the tpcb structure from the list of active or
786 * partially active connections, recycle all the mbufs
787 * associated with the pcb, ref structure, sockbufs, etc.
788 * Only free the ref structure if you know that a ref timer
789 * wasn't set for this tpcb.
796 * tp_soisdisconnected() was already when this is called
800 register struct tp_pcb
*tpcb
;
802 void tp_freeref(), tp_rsyflush();
803 register struct socket
*so
= tpcb
->tp_sock
;
806 printf("tp_detach(tpcb 0x%x, so 0x%x)\n",
810 tptraceTPCB(TPPTmisc
, "tp_detach tpcb so lsufx",
811 tpcb
, so
, *(u_short
*)(tpcb
->tp_lsuffix
), 0);
815 printf("so_snd at 0x%x so_rcv at 0x%x\n", &so
->so_snd
, &so
->so_rcv
);
816 dump_mbuf(so
->so_snd
.sb_mb
, "so_snd at detach ");
817 printf("about to call LL detach, nlproto 0x%x, nl_detach 0x%x\n",
818 tpcb
->tp_nlproto
, tpcb
->tp_nlproto
->nlp_pcbdetach
);
821 if (tpcb
->tp_Xsnd
.sb_mb
) {
822 printf("Unsent Xdata on detach; would panic");
823 sbflush(&tpcb
->tp_Xsnd
);
825 if (tpcb
->tp_ucddata
)
826 m_freem(tpcb
->tp_ucddata
);
829 printf("reassembly info cnt %d rsyq 0x%x\n",
830 tpcb
->tp_rsycnt
, tpcb
->tp_rsyq
);
837 tpcb
->tp_next
= tpcb
->tp_prev
= 0;
839 tpcb
->tp_notdetached
= 0;
842 printf("calling (...nlproto->...)(0x%x, so 0x%x)\n",
844 printf("so 0x%x so_head 0x%x, qlen %d q0len %d qlimit %d\n",
846 so
->so_q0len
, so
->so_qlen
, so
->so_qlimit
);
849 (tpcb
->tp_nlproto
->nlp_pcbdetach
)(tpcb
->tp_npcb
);
850 /* does an so->so_pcb = 0; sofree(so) */
853 printf("after xxx_pcbdetach\n");
856 if (tpcb
->tp_state
== TP_LISTENING
) {
857 register struct tp_pcb
**tt
;
858 for (tt
= &tp_listeners
; *tt
; tt
= &((*tt
)->tp_nextlisten
))
862 *tt
= tpcb
->tp_nextlisten
;
864 printf("tp_detach from listen: should panic\n");
866 if (tpcb
->tp_refstate
== REF_OPENING
) {
867 /* no connection existed here so no reference timer will be called */
869 printf("SETTING ref %d to REF_FREE\n", tpcb
->tp_lref
);
872 tp_freeref(tpcb
->tp_lref
);
876 * Get rid of the cluster mbuf allocated for performance measurements, if
877 * there is one. Note that tpcb->tp_perf_on says nothing about whether or
878 * not a cluster mbuf was allocated, so you have to check for a pointer
879 * to one (that is, we need the TP_PERF_MEASs around the following section
880 * of code, not the IFPERFs)
882 if (tpcb
->tp_p_mbuf
) {
883 register struct mbuf
*m
= tpcb
->tp_p_mbuf
;
886 printf("freeing tp_p_meas 0x%x ", tpcb
->tp_p_meas
);
895 #endif /* TP_PERF_MEAS */
898 printf( "end of detach, NOT single, tpcb 0x%x\n", tpcb
);
900 /* FREE((caddr_t)tpcb, M_PCB); WHere to put this ? */
907 {(struct tp_pcb
*)&tp_bound_pcbs
, (struct tp_pcb
*)&tp_bound_pcbs
};
911 tp_tselinuse(tlen
, tsel
, siso
, reuseaddr
)
913 register struct sockaddr_iso
*siso
;
915 struct tp_pcb
*b
= tp_bound_pcbs
.next
, *l
= tp_listeners
;
916 register struct tp_pcb
*t
;
919 if (b
!= (struct tp_pcb
*)&tp_bound_pcbs
) {
920 t
= b
; b
= t
->tp_next
;
922 t
= l
; l
= t
->tp_nextlisten
;
925 if (tlen
== t
->tp_lsuffixlen
&& bcmp(tsel
, t
->tp_lsuffix
, tlen
) == 0) {
926 if (t
->tp_flags
& TPF_GENERAL_ADDR
) {
927 if (siso
== 0 || reuseaddr
== 0)
930 if (siso
->siso_family
== t
->tp_domain
&&
931 t
->tp_nlproto
->nlp_cmpnetaddr(t
->tp_npcb
, siso
, TP_LOCAL
))
933 } else if (reuseaddr
== 0)
942 tp_pcbbind(tpcb
, nam
)
943 register struct tp_pcb
*tpcb
;
944 register struct mbuf
*nam
;
946 register struct sockaddr_iso
*siso
= 0;
947 int tlen
= 0, wrapped
= 0;
951 if (tpcb
->tp_state
!= TP_CLOSED
)
954 siso
= mtod(nam
, struct sockaddr_iso
*);
955 switch (siso
->siso_family
) {
957 return (EAFNOSUPPORT
);
960 tlen
= siso
->siso_tlen
;
962 if (siso
->siso_nlen
== 0)
968 tsel
= (caddr_t
)&tutil
;
969 if (tutil
= ((struct sockaddr_in
*)siso
)->sin_port
) {
972 if (((struct sockaddr_in
*)siso
)->sin_addr
.s_addr
== 0)
977 if (tpcb
->tp_lsuffixlen
== 0) {
979 if (tp_tselinuse(tlen
, tsel
, siso
,
980 tpcb
->tp_sock
->so_options
& SO_REUSEADDR
))
983 for (tsel
= (caddr_t
)&tutil
, tlen
= 2;;){
984 if (tp_unique
++ < ISO_PORT_RESERVED
||
985 tp_unique
> ISO_PORT_USERRESERVED
) {
988 tp_unique
= ISO_PORT_RESERVED
;
990 tutil
= htons(tp_unique
);
991 if (tp_tselinuse(tlen
, tsel
, siso
, 0) == 0)
994 if (siso
) switch (siso
->siso_family
) {
997 bcopy(tsel
, TSEL(siso
), tlen
);
998 siso
->siso_tlen
= tlen
;
1003 ((struct sockaddr_in
*)siso
)->sin_port
= tutil
;
1007 bcopy(tsel
, tpcb
->tp_lsuffix
, (tpcb
->tp_lsuffixlen
= tlen
));
1008 insque(tpcb
, &tp_bound_pcbs
);
1010 if (tlen
|| siso
== 0)
1014 tpcb
->tp_flags
|= TPF_GENERAL_ADDR
;
1017 return tpcb
->tp_nlproto
->nlp_pcbbind(tpcb
->tp_npcb
, nam
);