/***********************************************************
Copyright IBM Corporation 1987
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
******************************************************************/
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
* $Header: tp_pcb.c,v 5.4 88/11/18 17:28:24 nhall Exp $
* $Source: /usr/argo/sys/netiso/RCS/tp_pcb.c,v $
* This is the initialization and cleanup stuff -
* for the tp machine in general as well as for the individual pcbs.
* tp_init() is called at system startup. tp_attach() and tp_getref() are
* called when a socket is created. tp_detach() and tp_freeref()
* are called during the closing stage and/or when the reference timer
* tp_soisdisconnecting() and tp_soisdisconnected() are tp-specific
* versions of soisconnect*
* and are called (obviously) during the closing phase.
static char *rcsid
= "$Header: tp_pcb.c,v 5.4 88/11/18 17:28:24 nhall Exp $";
#include "argoxtwentyfive.h"
#include "../netiso/tp_param.h"
#include "../netiso/tp_timer.h"
#include "../netiso/tp_ip.h"
#include "../netiso/tp_stat.h"
#include "../netiso/tp_pcb.h"
#include "../netiso/argo_debug.h"
#include "../netiso/tp_tpdu.h"
#include "../netiso/tp_trace.h"
#include "../netiso/tp_meas.h"
#include "../netiso/tp_seq.h"
#include "../netiso/tp_clnp.h"
/* list of reference structures */
struct tp_ref tp_ref
[N_TPREF
];
struct tp_param tp_param
= {
/* ticks are in units of:
* 500 nano-fortnights ;-) or
struct tp_conn_param tp_conn_param
[] = {
/* ISO_CLNS: TP4 CONNECTION LESS */
TP_NRETRANS
, /* short p_Nretrans; */
20, /* 10 sec */ /* short p_dr_ticks; */
20, /* 10 sec */ /* short p_cc_ticks; */
20, /* 10 sec */ /* short p_dt_ticks; */
40, /* 20 sec */ /* short p_x_ticks; */
80, /* 40 sec */ /* short p_cr_ticks;*/
240, /* 2 min */ /* short p_keepalive_ticks;*/
10, /* 5 sec */ /* short p_sendack_ticks; */
600, /* 5 min */ /* short p_ref_ticks; */
360, /* 3 min */ /* short p_inact_ticks; */
(short) 100, /* short p_lcdtfract */
(short) TP_SOCKBUFSIZE
, /* short p_winsize */
TP_TPDUSIZE
, /* u_char p_tpdusize */
TPACK_WINDOW
, /* 4 bits p_ack_strat */
TPRX_USE_CW
| TPRX_FASTSTART
,
TP_CLASS_4
| TP_CLASS_0
,/* 5 bits p_class */
1, /* 1 bit xtd format */
1, /* 1 bit xpd service */
1, /* 1 bit use_checksum */
0, /* 1 bit use net xpd */
0, /* no disc indications */
0, /* don't change params */
ISO_CLNS
, /* p_netservice */
/* IN_CLNS: TP4 CONNECTION LESS */
TP_NRETRANS
, /* short p_Nretrans; */
20, /* 10 sec */ /* short p_dr_ticks; */
20, /* 10 sec */ /* short p_cc_ticks; */
20, /* 10 sec */ /* short p_dt_ticks; */
40, /* 20 sec */ /* short p_x_ticks; */
80, /* 40 sec */ /* short p_cr_ticks;*/
240, /* 2 min */ /* short p_keepalive_ticks;*/
10, /* 5 sec */ /* short p_sendack_ticks; */
600, /* 5 min */ /* short p_ref_ticks; */
360, /* 3 min */ /* short p_inact_ticks; */
(short) 100, /* short p_lcdtfract */
(short) TP_SOCKBUFSIZE
, /* short p_winsize */
TP_TPDUSIZE
, /* u_char p_tpdusize */
TPACK_WINDOW
, /* 4 bits p_ack_strat */
TPRX_USE_CW
| TPRX_FASTSTART
,
TP_CLASS_4
, /* 5 bits p_class */
1, /* 1 bit xtd format */
1, /* 1 bit xpd service */
1, /* 1 bit use_checksum */
0, /* 1 bit use net xpd */
0, /* no disc indications */
0, /* don't change params */
IN_CLNS
, /* p_netservice */
/* ISO_CONS: TP0 CONNECTION MODE */
TP_NRETRANS
, /* short p_Nretrans; */
0, /* n/a */ /* short p_dr_ticks; */
40, /* 20 sec */ /* short p_cc_ticks; */
0, /* n/a */ /* short p_dt_ticks; */
0, /* n/a */ /* short p_x_ticks; */
360, /* 3 min */ /* short p_cr_ticks;*/
0, /* n/a */ /* short p_keepalive_ticks;*/
0, /* n/a */ /* short p_sendack_ticks; */
600, /* for cr/cc to clear *//* short p_ref_ticks; */
0, /* n/a */ /* short p_inact_ticks; */
/* Use tp4 defaults just in case the user changes ONLY
(short) 100, /* short p_lcdtfract */
(short) TP0_SOCKBUFSIZE
, /* short p_winsize */
TP0_TPDUSIZE
, /* 8 bits p_tpdusize */
0, /* 4 bits p_ack_strat */
0, /* 4 bits p_rx_strat*/
TP_CLASS_0
, /* 5 bits p_class */
0, /* 1 bit xtd format */
0, /* 1 bit xpd service */
0, /* 1 bit use_checksum */
0, /* 1 bit use net xpd */
0, /* no disc indications */
0, /* don't change params */
ISO_CONS
, /* p_netservice */
/* ISO_COSNS: TP4 CONNECTION LESS SERVICE over CONSNS */
TP_NRETRANS
, /* short p_Nretrans; */
40, /* 20 sec */ /* short p_dr_ticks; */
40, /* 20 sec */ /* short p_cc_ticks; */
80, /* 40 sec */ /* short p_dt_ticks; */
120, /* 1 min */ /* short p_x_ticks; */
360, /* 3 min */ /* short p_cr_ticks;*/
360, /* 3 min */ /* short p_keepalive_ticks;*/
20, /* 10 sec */ /* short p_sendack_ticks; */
600, /* 5 min */ /* short p_ref_ticks; */
480, /* 4 min */ /* short p_inact_ticks; */
(short) 100, /* short p_lcdtfract */
(short) TP0_SOCKBUFSIZE
, /* short p_winsize */
TP0_TPDUSIZE
, /* u_char p_tpdusize */
TPACK_WINDOW
, /* 4 bits p_ack_strat */
TPRX_USE_CW
, /* No fast start */
TP_CLASS_4
| TP_CLASS_0
,/* 5 bits p_class */
0, /* 1 bit xtd format */
1, /* 1 bit xpd service */
1, /* 1 bit use_checksum */
0, /* 1 bit use net xpd */
0, /* no disc indications */
0, /* don't change params */
ISO_COSNS
, /* p_netservice */
int in_recycle_tsuffix();
int iso_recycle_tsuffix();
int iso_recycle_tsuffix();
struct nl_protosw nl_protosw
[] = {
{ AF_ISO
, iso_putnetaddr
, iso_getnetaddr
,
iso_putsufx
, iso_getsufx
,
tpclnp_mtu
, iso_pcbbind
, iso_pcbconnect
,
iso_pcbdisconnect
, iso_pcbdetach
,
tpclnp_output
, tpclnp_output_dg
, iso_nlctloutput
,
{ AF_INET
, in_putnetaddr
, in_getnetaddr
,
tpip_mtu
, in_pcbbind
, in_pcbconnect
,
in_pcbdisconnect
, in_pcbdetach
,
tpip_output
, tpip_output_dg
, /* nl_ctloutput */ NULL
,
{ AF_ISO
, iso_putnetaddr
, iso_getnetaddr
,
iso_putsufx
, iso_getsufx
,
tpcons_mtu
, iso_pcbbind
, iso_pcbconnect
,
iso_pcbdisconnect
, iso_pcbdetach
,
tpcons_output
, tpcons_output_dg
, iso_nlctloutput
,
* autoconf through the protosw structure
if ( (sizeof(struct tp_pcb
) >= MLEN
) || (sizeof(struct tp_pcb_aux
) >= MLEN
) ){
tp_param
.tpp_configed
= 0;
"TP not configured !!! pcb (0x%x, %d) or aux (0x%x, %d) too big!\n",
sizeof(struct tp_pcb
), sizeof(struct tp_pcb
),
sizeof(struct tp_pcb_aux
), sizeof(struct tp_pcb_aux
));
printf("MLEN (0x%x, %d)\n", MLEN
, MLEN
);
tp_inpcb
.inp_next
= tp_inpcb
.inp_prev
= &tp_inpcb
;
tp_isopcb
.isop_next
= tp_isopcb
.isop_prev
= &tp_isopcb
;
bzero((caddr_t
)&tp_stat
, sizeof(struct tp_stat
));
* NAME: tp_soisdisconnecting()
* FUNCTION and ARGUMENTS:
* Set state of the socket (so) to reflect that fact that we're disconnectING
* This differs from the regular soisdisconnecting() in that the latter
* also sets the SS_CANTRECVMORE and SS_CANTSENDMORE flags.
* We don't want to set those flags because those flags will cause
* a SIGPIPE to be delivered in sosend() and we don't like that.
* If anyone else is sleeping on this socket, wake 'em up.
register struct socket
*so
;
so
->so_state
&= ~SS_ISCONNECTING
;
so
->so_state
|= SS_ISDISCONNECTING
;
if (!soqremque(so
, 0) && !soqremque(so
, 1))
panic("tp_soisdisconnecting");
wakeup((caddr_t
)&so
->so_timeo
);
register struct tp_pcb
*tpcb
= sototpcb(so
);
bcopy ( tpcb
->tp_fsuffix
, &fsufx
, sizeof(u_int
) );
bcopy ( tpcb
->tp_lsuffix
, &lsufx
, sizeof(u_int
) );
tpmeas( tpcb
->tp_lref
, TPtime_close
,
&time
, fsufx
, lsufx
, tpcb
->tp_fref
);
tpcb
->tp_perf_on
= 0; /* turn perf off */
* NAME: tp_soisdisconnected()
* FUNCTION and ARGUMENTS:
* Set state of the socket (so) to reflect that fact that we're disconnectED
* Set the state of the reference structure to closed, and
* Start a reference timer.
* This differs from the regular soisdisconnected() in that the latter
* also sets the SS_CANTRECVMORE and SS_CANTSENDMORE flags.
* We don't want to set those flags because those flags will cause
* a SIGPIPE to be delivered in sosend() and we don't like that.
* If anyone else is sleeping on this socket, wake 'em up.
tp_soisdisconnected(tpcb
)
register struct tp_pcb
*tpcb
;
register struct socket
*so
= tpcb
->tp_sock
;
so
->so_state
&= ~(SS_ISCONNECTING
|SS_ISCONNECTED
|SS_ISDISCONNECTING
);
if (!soqremque(so
, 0) && !soqremque(so
, 1))
panic("tp_soisdisconnected");
wakeup((caddr_t
)&so
->so_timeo
);
register struct tp_pcb
*tpcb
= sototpcb(so
);
bcopy ( tpcb
->tp_fsuffix
, &fsufx
, sizeof(u_int
) );
bcopy ( tpcb
->tp_lsuffix
, &lsufx
, sizeof(u_int
) );
tpmeas( tpcb
->tp_lref
, TPtime_close
,
&time
, &lsufx
, &fsufx
, tpcb
->tp_fref
);
tpcb
->tp_perf_on
= 0; /* turn perf off */
tpcb
->tp_refp
->tpr_state
= REF_FROZEN
;
tp_recycle_tsuffix( tpcb
);
tp_etimeout(tpcb
->tp_refp
, TM_reference
, 0,0,0, (int)tpcb
->tp_refer_ticks
);
int tp_maxrefopen
; /* highest reference # of the set of open tp connections */
* tp.trans when the reference timer goes off, and
* from tp_attach() and tp_detach() when a tpcb is partially set up but not
* set up enough to have a ref timer set for it, and it's discarded
* due to some sort of error or an early close()
* FUNCTION and ARGUMENTS:
* Frees the reference represented by (r) for re-use.
* NOTES: better be called at clock priority !!!!!
register struct tp_ref
*r
;
printf("tp_freeref called for ref %d maxrefopen %d\n",
r
- tp_ref
, tp_maxrefopen
);
tptrace(TPPTmisc
, "tp_freeref ref tp_maxrefopen",
r
- tp_ref
, tp_maxrefopen
, 0, 0);
printf("tp_freeref: CLEARING tpr_pcb 0x%x\n", r
->tpr_pcb
);
r
->tpr_pcb
= (struct tp_pcb
*)0;
r
= &tp_ref
[tp_maxrefopen
];
while( tp_maxrefopen
> 0 ) {
printf("tp_freeref ends w/ maxrefopen %d\n", tp_maxrefopen
);
* FUNCTION and ARGUMENTS:
* obtains the next free reference and allocates the appropriate
* ref structure, links that structure to (tpcb)
register struct tp_pcb
*tpcb
;
register struct tp_ref
*r
= tp_ref
;
r
++; /* tp_ref[0] is never used */
r
->tpr_state
= REF_OPENING
;
* FUNCTION and ARGUMENTS:
* given a socket (so) and a protocol family (dom), allocate a tpcb
* and ref structure, initialize everything in the structures that
* needs to be initialized.
* EINVAL if DEBUG(X) in is on and a disaster has occurred
* ENOPROTOOPT if TP hasn't been configured or if the
* socket wasn't created with tp as its protocol
* EISCONN if this socket is already part of a connection
* ETOOMANYREFS if ran out of tp reference numbers.
* E* whatever error is returned from soreserve()
* for from the network-layer pcb allocation routine
register struct tp_pcb
*tpcb
;
int protocol
= so
->so_proto
->pr_protocol
;
extern struct tp_conn_param tp_conn_param
[];
printf("tp_attach:dom 0x%x so 0x%x ", dom
, so
);
tptrace(TPPTmisc
, "tp_attach:dom so", dom
, so
, 0, 0);
if ( ! tp_param
.tpp_configed
) {
error
= ENOPROTOOPT
; /* protocol not available */
if (so
->so_pcb
!= NULL
) {
return EISCONN
; /* socket already part of a connection*/
error
= soreserve(so
, TP_SOCKBUFSIZE
, TP_SOCKBUFSIZE
);
/* later an ioctl will allow reallocation IF still in closed state */
MGET(m
, M_DONTWAIT
, TPMT_PCB
); /* for tpcb, main half */
tpcb
= mtod( m
, struct tp_pcb
* );
bzero( (caddr_t
)tpcb
, sizeof (struct tp_pcb
) );
MGET(p
, M_DONTWAIT
, TPMT_PCB
); /* for the tpcb, auxilliary half */
m_free(m
); /* which is tpcb */
p
->m_len
= sizeof(struct tp_pcb_aux
);
tpcb
->tp_aux
= mtod(p
, struct tp_pcb_aux
*);
bzero( (caddr_t
)tpcb
->tp_aux
, sizeof (struct tp_pcb_aux
) );
if ( ((tpcb
->tp_lref
= tp_getref(tpcb
)) & TP_ENOREF
) != 0 ) {
if (protocol
<ISOPROTO_TP4
) {
tpcb
->tp_netservice
= ISO_CONS
;
tpcb
->tp_snduna
= (SeqNum
) -1;/* kludge so the pseudo-ack from the CR/CC
* will generate correct fake-ack values
tpcb
->tp_netservice
= (dom
== AF_INET
)?IN_CLNS
:ISO_CLNS
;
tpcb
->_tp_param
= tp_conn_param
[tpcb
->tp_netservice
];
tpcb
->tp_state
= TP_CLOSED
;
tpcb
->tp_vers
= TP_VERSION
;
/* Spec says default is 128 octets,
* that is, if the tpdusize argument never appears, use 128.
* As the initiator, we will always "propose" the 2048
* size, that is, we will put this argument in the CR
* always, but accept what the other side sends on the CC.
* If the initiator sends us something larger on a CR,
* Our maximum is 4096. See tp_chksum.c comments.
tpcb
->tp_l_tpdusize
= 1 << tpcb
->tp_tpdusize
;
tpcb
->tp_seqmask
= TP_NML_FMT_MASK
;
tpcb
->tp_seqbit
= TP_NML_FMT_BIT
;
tpcb
->tp_seqhalf
= tpcb
->tp_seqbit
>> 1;
tpcb
->tp_sndhiwat
= (SeqNum
) - 1; /* a kludge but it works */
/* attach to a network-layer protoswitch */
tpcb
->tp_nlproto
= & nl_protosw
[tpcb
->tp_netservice
];
ASSERT( tpcb
->tp_nlproto
->nlp_afamily
== tpcb
->tp_domain
);
/* TODO: properly, this search would be on the basis of
* domain,netservice or just netservice only (if you have
* IN_CLNS, ISO_CLNS, and ISO_CONS)
tpcb
->tp_nlproto
= nl_protosw
;
while(tpcb
->tp_nlproto
->nlp_afamily
!= tpcb
->tp_domain
) {
if( tpcb
->tp_nlproto
->nlp_afamily
== 0 ) {
/* xx_pcballoc sets so_pcb */
if ( error
= (tpcb
->tp_nlproto
->nlp_pcballoc
) (
so
, tpcb
->tp_nlproto
->nlp_pcblist
) ) {
sotoinpcb(so
)->inp_ppcb
= (caddr_t
) tpcb
;
/* nothing to do for iso case */
tpcb
->tp_npcb
= (caddr_t
) so
->so_pcb
;
so
->so_tpcb
= (caddr_t
) tpcb
;
printf("BAD4 in tp_attach, so 0x%x\n", so
);
tp_freeref(tpcb
->tp_refp
);
printf("BAD3 in tp_attach, so 0x%x\n", so
);
m_free(dtom(tpcb
)); /* never a cluster */
m_free(dtom(tpcb
->tp_aux
)); /* never a cluster */
printf("BAD2 in tp_attach, so 0x%x\n", so
);
printf("BAD in tp_attach, so 0x%x\n", so
);
* tp.trans, on behalf of a user close request
* and when the reference timer goes off
* (if the disconnect was initiated by the protocol entity
* rather than by the user)
* FUNCTION and ARGUMENTS:
* remove the tpcb structure from the list of active or
* partially active connections, recycle all the mbufs
* associated with the pcb, ref structure, sockbufs, etc.
* Only free the ref structure if you know that a ref timer
* wasn't set for this tpcb.
* tp_soisdisconnected() was already when this is called
register struct tp_pcb
*tpcb
;
register struct socket
*so
= tpcb
->tp_sock
;
printf("tp_detach(tpcb 0x%x, so 0x%x) freelist 0%x\n",
tptraceTPCB(TPPTmisc
, "tp_detach tpcb so lsufx",
tpcb
, so
, *(int *)(tpcb
->tp_lsuffix
), 0);
if (!soqremque(so
, 0) && !soqremque(so
, 1))
printf("tp_detach(freeing RTC list snduna 0x%x rcvnxt 0x%x)\n",
#define FREE_RTC_LIST(XXX)\
{ register struct tp_rtc *xxr = XXX, *xxs; while (xxr) {\
m_freem( xxr->tprt_data );\
m_free( dtom(xxr) ); xxr = xxs; }\
XXX = (struct tp_rtc *)0;\
FREE_RTC_LIST( tpcb
->tp_snduna_rtc
);
tpcb
->tp_sndhiwat_rtc
= (struct tp_rtc
*)0;
FREE_RTC_LIST( tpcb
->tp_rcvnxt_rtc
);
printf("calling (...nlproto->...)(0x%x, so 0x%x)\n",
printf("so 0x%x so_head 0x%x, qlen %d q0len %d qlimit %d\n",
so
->so_q0len
, so
->so_qlen
, so
->so_qlimit
);
if ( tpcb
->tp_flags
& (TPF_CONN_DATA_OUT
| TPF_DISC_DATA_OUT
) ) {
ASSERT( so
->so_snd
.sb_cc
!= 0 );
"detach, flags 0x%x doing sbdrop on so_snd, mb 0x%x cc 0x%x\n",
tpcb
->tp_flags
, so
->so_snd
.sb_mb
, so
->so_snd
.sb_cc
);
dump_mbuf( so
->so_snd
.sb_mb
, "detach so snd: \n");
if ( so
->so_snd
.sb_cc
!= 0 )
sbdrop( &so
->so_snd
, so
->so_snd
.sb_cc
);
tpcb
->tp_flags
&= ~(TPF_CONN_DATA_OUT
| TPF_DISC_DATA_OUT
);
if ( tpcb
->tp_flags
& (TPF_DISC_DATA_IN
| TPF_CONN_DATA_IN
) ) {
ASSERT( tpcb
->tp_Xrcv
.sb_cc
!= 0 );
"detach, flags 0x%x doing sbdrop on tp_Xrcv, mb 0x%x cc 0x%x\n",
tpcb
->tp_flags
, tpcb
->tp_Xrcv
.sb_mb
, tpcb
->tp_Xrcv
.sb_cc
);
dump_mbuf( tpcb
->tp_Xrcv
.sb_mb
, "detach Xrcv: \n");
if( tpcb
->tp_Xrcv
.sb_cc
!= 0 )
sbdrop( &tpcb
->tp_Xrcv
, tpcb
->tp_Xrcv
.sb_cc
);
tpcb
->tp_flags
&= ~(TPF_CONN_DATA_IN
| TPF_DISC_DATA_IN
);
printf("so_snd at 0x%x so_rcv at 0x%x\n", &so
->so_snd
, &so
->so_rcv
);
dump_mbuf(so
->so_snd
.sb_mb
, "so_snd at detach ");
printf("about to call LL detach, nlproto 0x%x, nl_detach 0x%x\n",
tpcb
->tp_nlproto
, tpcb
->tp_nlproto
->nlp_pcbdetach
);
if ((tpcb
->tp_nlproto
->nlp_pcbdetach
) (
(struct inpcb
*)so
->so_pcb
) /* does an sofree(so) */ < 0 ) {
printf("tp: nl_detach failed: tpcb 0x%x so 0x%x\n", tpcb
, so
);
printf("after xxx_pcbdetach\n");
if( tpcb
->tp_refp
->tpr_state
== REF_OPENING
) {
/* no connection existed here so no reference timer will be called */
printf("SETTING ref %d, 0x%x to REF_FREE\n", tpcb
->tp_lref
,
tpcb
->tp_refp
- &tp_ref
[0]);
tp_freeref(tpcb
->tp_refp
);
so
->so_tpcb
= (caddr_t
)0;
* Get rid of the cluster mbuf allocated for performance measurements, if
* there is one. Note that tpcb->tp_perf_on says nothing about whether or
* not a cluster mbuf was allocated, so you have to check for a pointer
* to one (that is, we need the TP_PERF_MEASs around the following section
* of code, not the IFPERFs)
if( tpcb
->tp_p_meas
!= (struct tp_pmeas
*)0 ) {
n
= MTOCL((struct mbuf
*)(tpcb
->tp_p_meas
));
printf("freeing tp_p_meas 0x%x ", tpcb
->tp_p_meas
);
if (--mclrefcnt
[mtocl(n
)] == 0) {
"end of detach, NOT single, tpcb 0x%x, dtom(tpcb) 0x%x tp_aux 0x%x dtom(aux) 0x%x\n",
tpcb
, dtom(tpcb
), tpcb
->tp_aux
, dtom(tpcb
->tp_aux
));
m_free(dtom(tpcb
->tp_aux
));