* Copyright (c) 1991 The Regents of the University of California.
* %sccs.include.redist.c%
* @(#)tp_subr2.c 7.15 (Berkeley) %G%
/***********************************************************
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_subr2.c,v 5.5 88/11/18 17:28:55 nhall Exp $
* $Source: /usr/argo/sys/netiso/RCS/tp_subr2.c,v $
* Some auxiliary routines:
* tp_protocol_error: required by xebec- called when a combo of state,
* event, predicate isn't covered for by the transition file.
* tp_indicate: gives indications(signals) to the user process
* tp_getoptions: initializes variables that are affected by the options
/* this def'n is to cause the expansion of this macro in the
* routine tp_local_credit :
#define LOCAL_CREDIT_EXPAND
#include "../net/if_types.h"
#include "../netccitt/x25.h"
#include "../netccitt/pk.h"
#include "../netccitt/pk_var.h"
* NAME: tp_local_credit()
* FUNCTION and ARGUMENTS:
* Computes the local credit and stashes it in tpcb->tp_lcredit.
* It's a macro in the production system rather than a procdure.
* This doesn't actually get called in a production system -
* the macro gets expanded instead in place of calls to this proc.
* But for debugging, we call this and that allows us to add
* debugging messages easily here.
printf("ref 0x%x lcdt 0x%x l_tpdusize 0x%x decbit 0x%x\n",
tpcb
->tp_lcredit
, tpcb
->tp_l_tpdusize
, 0, 0);
* NAME: tp_protocol_error()
* tp_driver(), when it doesn't know what to do with
* a combo of event, state, predicate
* FUNCTION and ARGUMENTS:
tp_protocol_error(e
,tpcb
)
printf("TP PROTOCOL ERROR! tpcb 0x%x event 0x%x, state 0x%x\n",
tpcb
, e
->ev_number
, tpcb
->tp_state
);
tptraceTPCB(TPPTmisc
, "PROTOCOL ERROR tpcb event state",
tpcb
, e
->ev_number
, tpcb
->tp_state
, 0 );
return EIO
; /* for lack of anything better */
/* Not used at the moment */
* tp.trans when XPD arrive, when a connection is being disconnected by
* the arrival of a DR or ER, and when a connection times out.
* FUNCTION and ARGUMENTS:
* (ind) is the type of indication : T_DISCONNECT, T_XPD
* (error) is an E* value that will be put in the socket structure
* to be passed along to the user later.
* Gives a SIGURG to the user process or group indicated by the socket
tp_indicate(ind
, tpcb
, error
)
register struct tp_pcb
*tpcb
;
register struct socket
*so
= tpcb
->tp_sock
;
tptraceTPCB(TPPTindicate
, ind
, *(u_short
*)(tpcb
->tp_lsuffix
),
*(u_short
*)(tpcb
->tp_fsuffix
), error
,so
->so_pgid
);
"indicate 0x%x lsuf 0x%02x%02x fsuf 0x%02x%02x err 0x%x noind 0x%x ref 0x%x\n",
*ls
, *(ls
+1), *fs
, *(fs
+1),
tpcb
->tp_no_disc_indications
,
if ((so
->so_state
& SS_CANTRCVMORE
) == 0 &&
(m
= m_get(M_DONTWAIT
, MT_OOBDATA
)) != 0) {
x
.dr_hdr
.cmsg_len
= m
->m_len
= sizeof(x
);
x
.dr_hdr
.cmsg_level
= SOL_TRANSPORT
;
x
.dr_hdr
.cmsg_type
= TPOPT_DISC_REASON
;
*mtod(m
, struct tp_disc_reason
*) = x
;
sbappendrecord(&tpcb
->tp_Xrcv
, m
);
if (ind
== T_DISCONNECT
) {
if ( tpcb
->tp_no_disc_indications
)
tptraceTPCB(TPPTmisc
, "doing sohasoutofband(so)", so
,0,0,0);
* tp.trans whenever we go into OPEN state
* FUNCTION and ARGUMENTS:
* sets the proper flags and values in the tpcb, to control
* the appropriate actions for the given class, options,
* sequence space, etc, etc.
tpcb
->tp_xtd_format
? TP_XTD_FMT_MASK
: TP_NML_FMT_MASK
;
tpcb
->tp_xtd_format
? TP_XTD_FMT_BIT
: TP_NML_FMT_BIT
;
tpcb
->tp_seqhalf
= tpcb
->tp_seqbit
>> 1;
MAX(tpcb
->tp_dt_ticks
, (tpcb
->tp_peer_acktime
+ 2));
* NAME: tp_recycle_tsuffix()
* Called when a ref is frozen.
* FUNCTION and ARGUMENTS:
* allows the suffix to be reused.
bzero((caddr_t
)tpcb
->tp_lsuffix
, sizeof( tpcb
->tp_lsuffix
));
bzero((caddr_t
)tpcb
->tp_fsuffix
, sizeof( tpcb
->tp_fsuffix
));
tpcb
->tp_fsuffixlen
= tpcb
->tp_lsuffixlen
= 0;
(tpcb
->tp_nlproto
->nlp_recycle_suffix
)(tpcb
->tp_npcb
);
* tp{af}_quench() when ICMP source quench or similar thing arrives.
* FUNCTION and ARGUMENTS:
* Drop the congestion window back to 1.
* Congestion window scheme:
* Initial value is 1. ("slow start" as Nagle, et. al. call it)
* For each good ack that arrives, the congestion window is increased
* by 1 (up to max size of logical infinity, which is to say,
* it doesn't wrap around).
* Source quench causes it to drop back to 1.
* tp_send() uses the smaller of (regular window, congestion window).
* One retransmission strategy option is to have any retransmission
* cause reset the congestion window back to 1.
* (cmd) is either PRC_QUENCH: source quench, or
* PRC_QUENCH2: dest. quench (dec bit)
printf("tp_quench tpcb 0x%x ref 0x%x sufx 0x%x\n",
tpcb
, tpcb
->tp_lref
, *(u_short
*)(tpcb
->tp_lsuffix
));
printf("cong_win 0x%x decbit 0x%x \n",
tpcb
->tp_cong_win
, tpcb
->tp_decbit
);
tpcb
->tp_cong_win
= tpcb
->tp_l_tpdusize
;
tpcb
->tp_cong_win
= tpcb
->tp_l_tpdusize
; /* might as well quench source also */
tpcb
->tp_decbit
= TP_DECBIT_CLEAR_COUNT
;
* FUNCTION and ARGUMENTS:
if (tpcb
->tp_netservice
!= ISO_CONS
)
isop
= (struct isopcb
*)tpcb
->tp_npcb
;
lcp
= (struct pklcd
*)isop
->isop_chan
;
if (isop
->isop_refcnt
== 1) {
/* This is really superfluous, since it would happen
anyway in iso_pcbdetach, although it is a courtesy
to free up the x.25 channel before the refwait timer
printf("tp_netcmd(0x%x, 0x%x) NOT IMPLEMENTED\n", tpcb
, cmd
);
printf("tp_netcmd(): X25 NOT CONFIGURED!!\n");
* tp_ctloutput() and tp_emit()
* FUNCTION and ARGUMENTS:
* Convert a class mask to the highest numeric value it represents.
ASSERT( (j
== 4) || (j
== 0) ); /* for now */
if( (j
!= 4) && (j
!= 0) ) {
printf("ASSERTION ERROR: tp_mask_to_num: x 0x%x j %d\n",
tptrace(TPPTmisc
, "tp_mask_to_num(x) returns j", x
, j
, 0, 0);
printf("tp_mask_to_num(0x%x) returns 0x%x\n", x
, j
);
struct tp_conn_param
*src
, *dst
;
/* copy all but the bits stuff at the end */
#define COPYSIZE (12 * sizeof(short))
bcopy((caddr_t
)src
, (caddr_t
)dst
, COPYSIZE
);
dst
->p_tpdusize
= src
->p_tpdusize
;
dst
->p_ack_strat
= src
->p_ack_strat
;
dst
->p_rx_strat
= src
->p_rx_strat
;
* tp_usrreq on PRU_CONNECT and tp_input on receipt of CR
* FUNCTION and ARGUMENTS:
* route directly to x.25 if the address is type 37 - GROT.
* furthermore, let TP0 handle only type-37 addresses
* Since this assumes that its address argument is in a mbuf, the
* parameter was changed to reflect this assumtion. This also
* implies that an mbuf must be allocated when this is
* EAFNOSUPPORT if can't find an nl_protosw for x.25 (really could panic)
* ECONNREFUSED if trying to run TP0 with non-type 37 address
* possibly other E* returned from cons_netcmd()
* Would like to eliminate as much of this as possible --
* only one set of defaults (let the user set the parms according
* to parameters provided in the directory service).
* Left here for now 'cause we don't yet have a clean way to handle
tp_route_to( m
, tpcb
, channel
)
register struct tp_pcb
*tpcb
;
register struct sockaddr_iso
*siso
; /* NOTE: this may be a sockaddr_in */
extern struct tp_conn_param tp_conn_param
[];
int error
= 0, save_netservice
= tpcb
->tp_netservice
;
register struct rtentry
*rt
= 0;
siso
= mtod(m
, struct sockaddr_iso
*);
"route_to: so afi netservice class",
tpcb
->tp_sock
, siso
->siso_addr
.isoa_genaddr
[0], tpcb
->tp_netservice
,
printf("tp_route_to( m x%x, channel 0x%x, tpcb 0x%x netserv 0x%x)\n",
m
, channel
, tpcb
, tpcb
->tp_netservice
);
printf("m->mlen x%x, m->m_data:\n", m
->m_len
);
dump_buf(mtod(m
, caddr_t
), m
->m_len
);
struct pklcd
*lcp
= (struct pklcd
*)channel
;
struct isopcb
*isop
= (struct isopcb
*)lcp
->lcd_upnext
,
*isop_new
= (struct isopcb
*)tpcb
->tp_npcb
;
/* The next 2 lines believe that you haven't
set any network level options or done a pcbconnect
and XXXXXXX'edly apply to both inpcb's and isopcb's */
tpcb
->tp_npcb
= (caddr_t
)isop
;
tpcb
->tp_netservice
= ISO_CONS
;
tpcb
->tp_nlproto
= nl_protosw
+ ISO_CONS
;
isop
->isop_socket
= tpcb
->tp_sock
;
if (isop
->isop_refcnt
== 0)
iso_putsufx(isop
, tpcb
->tp_lsuffix
, tpcb
->tp_lsuffixlen
, TP_LOCAL
);
/* there are already connections sharing this */;
switch (siso
->siso_family
) {
tpcb
->tp_netservice
= ISO_CLNS
;
if (rt
= rtalloc1((struct sockaddr
*)siso
, 0)) {
if (rt
->rt_flags
& RTF_PROTO1
)
tpcb
->tp_netservice
= ISO_CONS
;
tpcb
->tp_netservice
= IN_CLNS
;
if (tpcb
->tp_nlproto
->nlp_afamily
!= siso
->siso_family
) {
printf("tp_route_to( CHANGING nlproto old 0x%x new 0x%x)\n",
save_netservice
, tpcb
->tp_netservice
);
if (error
= tp_set_npcb(tpcb
))
printf("tp_route_to calling nlp_pcbconn, netserv %d\n",
tpcb
->tp_nlproto
= nl_protosw
+ tpcb
->tp_netservice
;
error
= (tpcb
->tp_nlproto
->nlp_pcbconn
)(tpcb
->tp_npcb
, m
);
switch(tpcb
->tp_netservice
) {
/* This is a kludge but seems necessary so the passive end
* can get long enough timers. sigh.
if( siso->siso_addr.osinet_idi[1] == (u_char)IDI_OSINET )
if (rt
&& rt
->rt_ifp
&& rt
->rt_ifp
->if_type
== IFT_X25
) {
if( tpcb
->tp_dont_change_params
== 0) {
copyQOSparms( &tp_conn_param
[ISO_COSNS
],
tpcb
->tp_flags
|= TPF_NLQOS_PDN
;
/* drop through to IN_CLNS*/
tpcb
->tp_flags
|= TPF_PEER_ON_SAMENET
;
if((tpcb
->tp_class
& TP_CLASS_4
) == 0) {
tpcb
->tp_class
= TP_CLASS_4
; /* IGNORE dont_change_parms */
tpcb
->tp_flags
|= TPF_NLQOS_PDN
;
if( tpcb
->tp_dont_change_params
== 0 ) {
copyQOSparms( &tp_conn_param
[ISO_CONS
],
* for use over x.25 really need a small receive window,
* need to start slowly, need small max negotiable tpdu size,
* and need to use the congestion window to the max
* IGNORES tp_dont_change_params for these!
if( tpcb
->tp_sock
->so_snd
.sb_hiwat
> 512 ) {
(void) soreserve(tpcb
->tp_sock
, 512, 512 );/* GAG */
tpcb
->tp_rx_strat
= TPRX_USE_CW
;
/* class 4 doesn't need to open a vc now - may use one already
* opened or may open one only when it sends a pkt.
tp_netcmd( tpcb
, CONN_CLOSE
);
{ /* start with the global rtt, rtv stats */
(int) tpcb
->tp_flags
& (TPF_PEER_ON_SAMENET
| TPF_NLQOS_PDN
);
tpcb
->tp_rtt
= tp_stat
.ts_rtt
[i
];
tpcb
->tp_rtv
= tp_stat
.ts_rtv
[i
];
printf("tp_route_to returns 0x%x\n", error
);
tptraceTPCB(TPPTmisc
, "route_to: returns: error netserv class", error
,
tpcb
->tp_netservice
, tpcb
->tp_class
, 0);
register struct tp_pcb
*tpcb
;
register struct tp_event
*e
;
#define E e->ATTR(DT_TPDU)
#define E e->ev_union.EV_DT_TPDU
register struct sockbuf
*sb
= &tpcb
->tp_sock
->so_rcv
;
register struct isopcb
*isop
= (struct isopcb
*)tpcb
->tp_npcb
;
PStat(tpcb
, Nb_from_ll
) += E
.e_datalen
;
tpmeas(tpcb
->tp_lref
, TPtime_from_ll
, &e
->e_time
,
E
.e_seq
, PStat(tpcb
, Nb_from_ll
), E
.e_datalen
);
printf("stash EQ: seq 0x%x datalen 0x%x eot 0x%x",
E
.e_seq
, E
.e_datalen
, E
.e_eot
);
tptraceTPCB(TPPTmisc
, "stash EQ: seq len eot",
E
.e_seq
, E
.e_datalen
, E
.e_eot
, 0);
register struct mbuf
*n
= E
.e_data
;
n
->m_act
= MNULL
; /* set on tp_input */
dump_mbuf(sb
->sb_mb
, "stash 0: so_rcv after appending");
if (tpcb
->tp_netservice
!= ISO_CONS
)
printf("tp0_stash: tp running over something wierd\n");
register struct pklcd
*lcp
= (struct pklcd
*)isop
->isop_chan
;
pk_flowcontrol(lcp
, sbspace(sb
) <= 0, 1);
register struct tp_pcb
*tpcb
;
register struct isopcb
*isop
= (struct isopcb
*)tpcb
->tp_npcb
;
if (tpcb
->tp_netservice
!= ISO_CONS
)
printf("tp0_openflow: tp running over something wierd\n");
register struct pklcd
*lcp
= (struct pklcd
*)isop
->isop_chan
;
if (lcp
->lcd_rxrnr_condition
)
pk_flowcontrol(lcp
, 0, 0);
* tp_ctloutput() when the user sets TPOPT_PERF_MEAS on
* and tp_newsocket() when a new connection is made from
* a listening socket with tp_perf_on == true.
* FUNCTION and ARGUMENTS:
* (tpcb) is the usual; this procedure gets a clear cluster mbuf for
* a tp_pmeas structure, and makes tpcb->tp_p_meas point to it.
* ENOBUFS if it cannot get a cluster mbuf.
register struct tp_pcb
*tpcb
;
if( tpcb
->tp_p_meas
== 0 ) {
MGET(q
, M_WAITOK
, MT_PCB
);
if ((q
->m_flags
& M_EXT
) == 0) {
q
->m_len
= sizeof (struct tp_pmeas
);
tpcb
->tp_p_meas
= mtod(q
, struct tp_pmeas
*);
bzero( (caddr_t
)tpcb
->tp_p_meas
, sizeof (struct tp_pmeas
) );
"tpcb 0x%x so 0x%x ref 0x%x tp_p_meas 0x%x tp_perf_on 0x%x\n",
tpcb
, tpcb
->tp_sock
, tpcb
->tp_lref
,
tpcb
->tp_p_meas
, tpcb
->tp_perf_on
);
register struct sockaddr
*addr
;
switch( addr
->sa_family
) {
dump_inaddr((struct sockaddr_in
*)addr
);
dump_isoaddr((struct sockaddr_iso
*)addr
);
printf("BAD AF: 0x%x\n", addr
->sa_family
);
* Dump the buffer to the screen in a readable format. Format is:
* hex/dec where hex is the hex format, dec is the decimal format.
* columns of hex/dec numbers will be printed, followed by the
* character representations (if printable).
#define Buf ((u_char *)buf)
printf("Dump buf 0x%x len 0x%x\n", buf
, len
);
for (i
= 0; i
< len
; i
+= MAX_COLUMNS
) {
for (j
= 0; j
< MAX_COLUMNS
; j
++) {
printf("%x/%d\t", Buf
[i
+j
], Buf
[i
+j
]);
for (j
= 0; j
< MAX_COLUMNS
; j
++) {
if (((Buf
[i
+j
]) > 31) && ((Buf
[i
+j
]) < 128))