xref: /csrg-svn/sys/netiso/tp_subr2.c (revision 37469)
136414Ssklower /***********************************************************
236414Ssklower 		Copyright IBM Corporation 1987
336414Ssklower 
436414Ssklower                       All Rights Reserved
536414Ssklower 
636414Ssklower Permission to use, copy, modify, and distribute this software and its
736414Ssklower documentation for any purpose and without fee is hereby granted,
836414Ssklower provided that the above copyright notice appear in all copies and that
936414Ssklower both that copyright notice and this permission notice appear in
1036414Ssklower supporting documentation, and that the name of IBM not be
1136414Ssklower used in advertising or publicity pertaining to distribution of the
1236414Ssklower software without specific, written prior permission.
1336414Ssklower 
1436414Ssklower IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
1536414Ssklower ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
1636414Ssklower IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
1736414Ssklower ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
1836414Ssklower WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
1936414Ssklower ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2036414Ssklower SOFTWARE.
2136414Ssklower 
2236414Ssklower ******************************************************************/
2336414Ssklower 
2436414Ssklower /*
2536414Ssklower  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
2636414Ssklower  */
2736414Ssklower /*
2836414Ssklower  * ARGO TP
2936414Ssklower  *
3036414Ssklower  * $Header: tp_subr2.c,v 5.5 88/11/18 17:28:55 nhall Exp $
3136414Ssklower  * $Source: /usr/argo/sys/netiso/RCS/tp_subr2.c,v $
3236414Ssklower  *
3336414Ssklower  * Some auxiliary routines:
3436414Ssklower  * 		tp_protocol_error: required by xebec- called when a combo of state,
3536414Ssklower  *			event, predicate isn't covered for by the transition file.
3636414Ssklower  *		tp_indicate: gives indications(signals) to the user process
3736414Ssklower  *		tp_getoptions: initializes variables that are affected by the options
3836414Ssklower  *          chosen.
3936414Ssklower  */
4036414Ssklower 
4136414Ssklower #ifndef lint
4236414Ssklower static char *rcsid = "$Header: tp_subr2.c,v 5.5 88/11/18 17:28:55 nhall Exp $";
4336414Ssklower #endif lint
4436414Ssklower 
4536414Ssklower #include "argoxtwentyfive.h"
4636414Ssklower 
4736414Ssklower /* this def'n is to cause the expansion of this macro in the
4836414Ssklower  * routine tp_local_credit :
4936414Ssklower  */
5036414Ssklower #define LOCAL_CREDIT_EXPAND
5136414Ssklower 
5236414Ssklower #include "param.h"
5336414Ssklower #include "mbuf.h"
5436414Ssklower #include "socket.h"
5536414Ssklower #include "socketvar.h"
5636414Ssklower #include "domain.h"
5736414Ssklower #include "protosw.h"
5836414Ssklower #include "errno.h"
5936414Ssklower #include "types.h"
6036414Ssklower #include "time.h"
6136414Ssklower #include "kernel.h"
6236414Ssklower #undef MNULL
63*37469Ssklower #include "argo_debug.h"
64*37469Ssklower #include "tp_param.h"
65*37469Ssklower #include "tp_ip.h"
66*37469Ssklower #include "iso.h"
67*37469Ssklower #include "iso_errno.h"
68*37469Ssklower #include "iso_pcb.h"
69*37469Ssklower #include "tp_timer.h"
70*37469Ssklower #include "tp_stat.h"
71*37469Ssklower #include "tp_tpdu.h"
72*37469Ssklower #include "tp_pcb.h"
73*37469Ssklower #include "tp_seq.h"
74*37469Ssklower #include "tp_trace.h"
75*37469Ssklower #include "tp_user.h"
76*37469Ssklower #include "cons.h"
7736414Ssklower 
7836414Ssklower /*
7936414Ssklower  * NAME: 	tp_local_credit()
8036414Ssklower  *
8136414Ssklower  * CALLED FROM:
8236414Ssklower  *  tp_emit(), tp_usrreq()
8336414Ssklower  *
8436414Ssklower  * FUNCTION and ARGUMENTS:
8536414Ssklower  *	Computes the local credit and stashes it in tpcb->tp_lcredit.
8636414Ssklower  *  It's a macro in the production system rather than a procdure.
8736414Ssklower  *
8836414Ssklower  * RETURNS:
8936414Ssklower  *
9036414Ssklower  * SIDE EFFECTS:
9136414Ssklower  *
9236414Ssklower  * NOTES:
9336414Ssklower  *  This doesn't actually get called in a production system -
9436414Ssklower  *  the macro gets expanded instead in place of calls to this proc.
9536414Ssklower  *  But for debugging, we call this and that allows us to add
9636414Ssklower  *  debugging messages easily here.
9736414Ssklower  */
9836414Ssklower void
9936414Ssklower tp_local_credit(tpcb)
10036414Ssklower 	struct tp_pcb *tpcb;
10136414Ssklower {
10236414Ssklower 	LOCAL_CREDIT(tpcb);
10336414Ssklower 	IFDEBUG(D_CREDIT)
10436414Ssklower 		printf("ref 0x%x lcdt 0x%x l_tpdusize 0x%x decbit 0x%x\n",
10536414Ssklower 			tpcb->tp_refp - tp_ref,
10636414Ssklower 			tpcb->tp_lcredit,
10736414Ssklower 			tpcb->tp_l_tpdusize,
10836414Ssklower 			tpcb->tp_decbit,
10936414Ssklower 			tpcb->tp_cong_win
11036414Ssklower 			);
11136414Ssklower 	ENDDEBUG
11236414Ssklower 	IFTRACE(D_CREDIT)
11336414Ssklower 		tptraceTPCB(TPPTmisc,
11436414Ssklower 			"lcdt tpdusz \n",
11536414Ssklower 			 tpcb->tp_lcredit, tpcb->tp_l_tpdusize, 0, 0);
11636414Ssklower 	ENDTRACE
11736414Ssklower }
11836414Ssklower 
11936414Ssklower /*
12036414Ssklower  * NAME:  tp_protocol_error()
12136414Ssklower  *
12236414Ssklower  * CALLED FROM:
12336414Ssklower  *  tp_driver(), when it doesn't know what to do with
12436414Ssklower  * 	a combo of event, state, predicate
12536414Ssklower  *
12636414Ssklower  * FUNCTION and ARGUMENTS:
12736414Ssklower  *  print error mesg
12836414Ssklower  *
12936414Ssklower  * RETURN VALUE:
13036414Ssklower  *  EIO - always
13136414Ssklower  *
13236414Ssklower  * SIDE EFFECTS:
13336414Ssklower  *
13436414Ssklower  * NOTES:
13536414Ssklower  */
13636414Ssklower int
13736414Ssklower tp_protocol_error(e,tpcb)
13836414Ssklower 	struct tp_event	*e;
13936414Ssklower 	struct tp_pcb	*tpcb;
14036414Ssklower {
14136414Ssklower 	printf("TP PROTOCOL ERROR! tpcb 0x%x event 0x%x, state 0x%x\n",
14236414Ssklower 		tpcb, e->ev_number, tpcb->tp_state);
14336414Ssklower 	IFTRACE(D_DRIVER)
14436414Ssklower 		tptraceTPCB(TPPTmisc, "PROTOCOL ERROR tpcb event state",
14536414Ssklower 			tpcb, e->ev_number, tpcb->tp_state, 0 );
14636414Ssklower 	ENDTRACE
14736414Ssklower 	return EIO; /* for lack of anything better */
14836414Ssklower }
14936414Ssklower 
15036414Ssklower 
15136414Ssklower /* Not used at the moment */
15236414Ssklower ProtoHook
15336414Ssklower tp_drain()
15436414Ssklower {
15536414Ssklower 	return 0;
15636414Ssklower }
15736414Ssklower 
15836414Ssklower 
15936414Ssklower /*
16036414Ssklower  * NAME: tp_indicate()
16136414Ssklower  *
16236414Ssklower  * CALLED FROM:
16336414Ssklower  * 	tp.trans when XPD arrive, when a connection is being disconnected by
16436414Ssklower  *  the arrival of a DR or ER, and when a connection times out.
16536414Ssklower  *
16636414Ssklower  * FUNCTION and ARGUMENTS:
16736414Ssklower  *  (ind) is the type of indication : T_DISCONNECT, T_XPD
16836414Ssklower  *  (error) is an E* value that will be put in the socket structure
16936414Ssklower  *  to be passed along to the user later.
17036414Ssklower  * 	Gives a SIGURG to the user process or group indicated by the socket
17136414Ssklower  * 	attached to the tpcb.
17236414Ssklower  *
17336414Ssklower  * RETURNS:  Rien
17436414Ssklower  *
17536414Ssklower  * SIDE EFFECTS:
17636414Ssklower  *
17736414Ssklower  * NOTES:
17836414Ssklower  */
17936414Ssklower void
18036414Ssklower tp_indicate(ind, tpcb, error)
18136414Ssklower 	int				ind;
18236414Ssklower 	u_short			error;
18336414Ssklower 	register struct tp_pcb	*tpcb;
18436414Ssklower {
18536414Ssklower 	register struct socket *so = tpcb->tp_sock;
18636414Ssklower 	IFTRACE(D_INDICATION)
18736414Ssklower 		tptraceTPCB(TPPTindicate, ind, *(int *)(tpcb->tp_lsuffix),
188*37469Ssklower 			*(int *)(tpcb->tp_fsuffix), error,so->so_pgid);
18936414Ssklower 	ENDTRACE
19036414Ssklower 	IFDEBUG(D_INDICATION)
191*37469Ssklower 		char *ls, *fs;
19236414Ssklower 		ls = tpcb->tp_lsuffix,
19336414Ssklower 		fs = tpcb->tp_fsuffix,
19436414Ssklower 
19536414Ssklower 		printf(
196*37469Ssklower "indicate 0x%x lsuf 0x%02x%02x fsuf 0x%02x%02x err 0x%x  noind 0x%x ref 0x%x\n",
19736414Ssklower 		ind,
19836414Ssklower 		*ls, *(ls+1), *fs, *(fs+1),
199*37469Ssklower 		error, /*so->so_pgrp,*/
20036414Ssklower 		tpcb->tp_no_disc_indications,
20136414Ssklower 		tpcb->tp_lref);
20236414Ssklower 	ENDDEBUG
20336414Ssklower 
20436414Ssklower 	so->so_error = error;
20536414Ssklower 
20636414Ssklower 	if (ind == T_DISCONNECT)  {
20736414Ssklower 		if ( tpcb->tp_no_disc_indications )
20836414Ssklower 			return;
20936414Ssklower 	}
21036414Ssklower 	IFTRACE(D_INDICATION)
21136414Ssklower 		tptraceTPCB(TPPTmisc, "doing sohasoutofband(so)", so,0,0,0);
21236414Ssklower 	ENDTRACE
21336414Ssklower 	sohasoutofband(so);
21436414Ssklower }
21536414Ssklower 
21636414Ssklower /*
21736414Ssklower  * NAME : tp_getoptions()
21836414Ssklower  *
21936414Ssklower  * CALLED FROM:
22036414Ssklower  * 	tp.trans whenever we go into OPEN state
22136414Ssklower  *
22236414Ssklower  * FUNCTION and ARGUMENTS:
22336414Ssklower  *  sets the proper flags and values in the tpcb, to control
22436414Ssklower  *  the appropriate actions for the given class, options,
22536414Ssklower  *  sequence space, etc, etc.
22636414Ssklower  *
22736414Ssklower  * RETURNS: Nada
22836414Ssklower  *
22936414Ssklower  * SIDE EFFECTS:
23036414Ssklower  *
23136414Ssklower  * NOTES:
23236414Ssklower  */
23336414Ssklower void
23436414Ssklower tp_getoptions(tpcb)
23536414Ssklower struct tp_pcb *tpcb;
23636414Ssklower {
23736414Ssklower 	tpcb->tp_seqmask =
23836414Ssklower 		tpcb->tp_xtd_format ?	TP_XTD_FMT_MASK :	TP_NML_FMT_MASK ;
23936414Ssklower 	tpcb->tp_seqbit =
24036414Ssklower 		tpcb->tp_xtd_format ?	TP_XTD_FMT_BIT :	TP_NML_FMT_BIT ;
24136414Ssklower 	tpcb->tp_seqhalf = tpcb->tp_seqbit >> 1;
24236414Ssklower 	tpcb->tp_dt_ticks =
24336414Ssklower 		MAX(tpcb->tp_dt_ticks, (tpcb->tp_peer_acktime + 2));
24436414Ssklower 
24536414Ssklower }
24636414Ssklower 
24736414Ssklower /*
24836414Ssklower  * NAME:  tp_recycle_tsuffix()
24936414Ssklower  *
25036414Ssklower  * CALLED FROM:
25136414Ssklower  *  Called when a ref is frozen.
25236414Ssklower  *
25336414Ssklower  * FUNCTION and ARGUMENTS:
25436414Ssklower  *  allows the suffix to be reused.
25536414Ssklower  *
25636414Ssklower  * RETURNS: zilch
25736414Ssklower  *
25836414Ssklower  * SIDE EFFECTS:
25936414Ssklower  *
26036414Ssklower  * NOTES:
26136414Ssklower  */
26236414Ssklower void
26336414Ssklower tp_recycle_tsuffix(tpcb)
26436414Ssklower 	struct tp_pcb	*tpcb;
26536414Ssklower {
266*37469Ssklower 	bzero((caddr_t)tpcb->tp_lsuffix, sizeof( tpcb->tp_lsuffix));
267*37469Ssklower 	bzero((caddr_t)tpcb->tp_fsuffix, sizeof( tpcb->tp_fsuffix));
26836414Ssklower 	tpcb->tp_fsuffixlen = tpcb->tp_lsuffixlen = 0;
26936414Ssklower 
27036414Ssklower 	(tpcb->tp_nlproto->nlp_recycle_suffix)(tpcb->tp_npcb);
27136414Ssklower }
27236414Ssklower 
27336414Ssklower /*
27436414Ssklower  * NAME: tp_quench()
27536414Ssklower  *
27636414Ssklower  * CALLED FROM:
27736414Ssklower  *  tp{af}_quench() when ICMP source quench or similar thing arrives.
27836414Ssklower  *
27936414Ssklower  * FUNCTION and ARGUMENTS:
28036414Ssklower  *  Drop the congestion window back to 1.
28136414Ssklower  *  Congestion window scheme:
28236414Ssklower  *  Initial value is 1.  ("slow start" as Nagle, et. al. call it)
28336414Ssklower  *  For each good ack that arrives, the congestion window is increased
28436414Ssklower  *  by 1 (up to max size of logical infinity, which is to say,
28536414Ssklower  *	it doesn't wrap around).
28636414Ssklower  *  Source quench causes it to drop back to 1.
28736414Ssklower  *  tp_send() uses the smaller of (regular window, congestion window).
28836414Ssklower  *  One retransmission strategy option is to have any retransmission
28936414Ssklower  *	cause reset the congestion window back  to 1.
29036414Ssklower  *
29136414Ssklower  *	(cmd) is either PRC_QUENCH: source quench, or
29236414Ssklower  *		PRC_QUENCH2: dest. quench (dec bit)
29336414Ssklower  *
29436414Ssklower  * RETURNS:
29536414Ssklower  *
29636414Ssklower  * SIDE EFFECTS:
29736414Ssklower  *
29836414Ssklower  * NOTES:
29936414Ssklower  */
30036414Ssklower void
30136414Ssklower tp_quench( tpcb, cmd )
30236414Ssklower 	struct tp_pcb *tpcb;
30336414Ssklower 	int cmd;
30436414Ssklower {
30536414Ssklower 	IFDEBUG(D_QUENCH)
30636414Ssklower 		printf("tp_quench tpcb 0x%x ref 0x%x sufx 0x%x\n",
30736414Ssklower 			tpcb, tpcb->tp_lref, *(int *)(tpcb->tp_lsuffix));
30836414Ssklower 		printf("cong_win 0x%x decbit 0x%x \n",
30936414Ssklower 			tpcb->tp_cong_win, tpcb->tp_decbit);
31036414Ssklower 	ENDDEBUG
31136414Ssklower 	switch(cmd) {
31236414Ssklower 		case PRC_QUENCH:
31336414Ssklower 			tpcb->tp_cong_win = 1;
31436414Ssklower 			IncStat(ts_quench);
31536414Ssklower 			break;
31636414Ssklower 		case PRC_QUENCH2:
31736414Ssklower 			tpcb->tp_cong_win = 1; /* might as well quench source also */
31836414Ssklower 			tpcb->tp_decbit = TP_DECBIT_CLEAR_COUNT;
31936414Ssklower 			IncStat(ts_rcvdecbit);
32036414Ssklower 			break;
32136414Ssklower 	}
32236414Ssklower }
32336414Ssklower 
32436414Ssklower 
32536414Ssklower /*
32636414Ssklower  * NAME:	tp_netcmd()
32736414Ssklower  *
32836414Ssklower  * CALLED FROM:
32936414Ssklower  *
33036414Ssklower  * FUNCTION and ARGUMENTS:
33136414Ssklower  *
33236414Ssklower  * RETURNS:
33336414Ssklower  *
33436414Ssklower  * SIDE EFFECTS:
33536414Ssklower  *
33636414Ssklower  * NOTES:
33736414Ssklower  */
33836414Ssklower tp_netcmd( tpcb, cmd )
33936414Ssklower 	struct tp_pcb *tpcb;
34036414Ssklower 	int cmd;
34136414Ssklower {
34236414Ssklower #if NARGOXTWENTYFIVE > 0
34336414Ssklower 	switch (cmd) {
34436414Ssklower 
34536414Ssklower 	case CONN_CLOSE:
34636414Ssklower 	case CONN_REFUSE:
34736414Ssklower 		cons_netcmd( cmd, tpcb->tp_npcb, 0, tpcb->tp_class == TP_CLASS_4);
34836414Ssklower 		/* TODO: can this last param be replaced by
34936414Ssklower 	 	*	tpcb->tp_netserv != ISO_CONS?)
35036414Ssklower 		*/
35136414Ssklower 		break;
35236414Ssklower 
35336414Ssklower 	default:
35436414Ssklower 		printf("tp_netcmd(0x%x, 0x%x) NOT IMPLEMENTED\n", tpcb, cmd);
35536414Ssklower 		break;
35636414Ssklower 	}
35736414Ssklower #else NARGOXTWENTYFIVE
35836414Ssklower 	printf("tp_netcmd(): X25 NOT CONFIGURED!!\n");
35936414Ssklower #endif NARGOXTWENTYFIVE > 0
36036414Ssklower }
36136414Ssklower /*
36236414Ssklower  * CALLED FROM:
36336414Ssklower  *  tp_ctloutput() and tp_emit()
36436414Ssklower  * FUNCTION and ARGUMENTS:
36536414Ssklower  * 	Convert a class mask to the highest numeric value it represents.
36636414Ssklower  */
36736414Ssklower 
36836414Ssklower int
36936414Ssklower tp_mask_to_num(x)
37036414Ssklower 	u_char x;
37136414Ssklower {
37236414Ssklower 	register int j;
37336414Ssklower 
37436414Ssklower 	for(j = 4; j>=0 ;j--) {
37536414Ssklower 		if(x & (1<<j))
37636414Ssklower 			break;
37736414Ssklower 	}
37836414Ssklower 	ASSERT( (j == 4) || (j == 0) ); /* for now */
37936414Ssklower 	if( (j != 4) && (j != 0) ) {
38036414Ssklower 		printf("ASSERTION ERROR: tp_mask_to_num: x 0x%x j %d\n",
38136414Ssklower 			x, j);
38236414Ssklower 	}
38336414Ssklower 	IFTRACE(D_TPINPUT)
38436414Ssklower 		tptrace(TPPTmisc, "tp_mask_to_num(x) returns j", x, j, 0, 0);
38536414Ssklower 	ENDTRACE
38636414Ssklower 	IFDEBUG(D_TPINPUT)
38736414Ssklower 		printf("tp_mask_to_num(0x%x) returns 0x%x\n", x, j);
38836414Ssklower 	ENDDEBUG
38936414Ssklower 	return j;
39036414Ssklower }
39136414Ssklower 
39236414Ssklower static
39336414Ssklower copyQOSparms(src, dst)
39436414Ssklower 	struct tp_conn_param *src, *dst;
39536414Ssklower {
39636414Ssklower 	/* copy all but the bits stuff at the end */
39736414Ssklower #define COPYSIZE (12 * sizeof(short))
39836414Ssklower 
399*37469Ssklower 	bcopy((caddr_t)src, (caddr_t)dst, COPYSIZE);
40036414Ssklower 	dst->p_tpdusize = src->p_tpdusize;
40136414Ssklower 	dst->p_ack_strat = src->p_ack_strat;
40236414Ssklower 	dst->p_rx_strat = src->p_rx_strat;
40336414Ssklower #undef COPYSIZE
40436414Ssklower }
40536414Ssklower 
40636414Ssklower /*
40736414Ssklower  * CALLED FROM:
40836414Ssklower  *  tp_usrreq on PRU_CONNECT and tp_input on receipt of CR
40936414Ssklower  *
41036414Ssklower  * FUNCTION and ARGUMENTS:
41136414Ssklower  * 	route directly to x.25 if the address is type 37 - GROT.
41236414Ssklower  *  furthermore, let TP0 handle only type-37 addresses
41336414Ssklower  *
41436414Ssklower  *	Since this assumes that its address argument is in a mbuf, the
41536414Ssklower  *	parameter was changed to reflect this assumtion. This also
41636414Ssklower  *	implies that an mbuf must be allocated when this is
41736414Ssklower  *	called from tp_input
41836414Ssklower  *
41936414Ssklower  * RETURNS:
42036414Ssklower  *	errno value	 :
42136414Ssklower  *	EAFNOSUPPORT if can't find an nl_protosw for x.25 (really could panic)
42236414Ssklower  *	ECONNREFUSED if trying to run TP0 with non-type 37 address
42336414Ssklower  *  possibly other E* returned from cons_netcmd()
42436414Ssklower  * NOTE:
42536414Ssklower  *  Would like to eliminate as much of this as possible --
42636414Ssklower  *  only one set of defaults (let the user set the parms according
42736414Ssklower  *  to parameters provided in the directory service).
42836414Ssklower  *  Left here for now 'cause we don't yet have a clean way to handle
42936414Ssklower  *  it on the passive end.
43036414Ssklower  */
43136414Ssklower int
43236414Ssklower tp_route_to( m, tpcb, channel)
43336414Ssklower 	struct mbuf					*m;
43436414Ssklower 	register struct tp_pcb		*tpcb;
43536414Ssklower 	u_int 						channel;
43636414Ssklower {
43736414Ssklower 	register struct sockaddr_iso *siso;	/* NOTE: this may be a sockaddr_in */
43836414Ssklower 	extern struct tp_conn_param tp_conn_param[];
43936414Ssklower 	int error = 0;
44036414Ssklower 	int	vc_to_kill = 0; /* kludge */
44136414Ssklower 
44236414Ssklower 	siso = mtod(m, struct sockaddr_iso *);
44336414Ssklower 	IFTRACE(D_CONN)
44436414Ssklower 		tptraceTPCB(TPPTmisc,
44536414Ssklower 		"route_to: so  afi netservice class",
446*37469Ssklower 		tpcb->tp_sock, siso->siso_addr.isoa_genaddr[0], tpcb->tp_netservice,
44736414Ssklower 			tpcb->tp_class);
44836414Ssklower 	ENDTRACE
44936414Ssklower 	IFDEBUG(D_CONN)
45036414Ssklower 		printf("tp_route_to( m x%x, channel 0x%x, tpcb 0x%x netserv 0x%x)\n",
45136414Ssklower 			m, channel, tpcb, tpcb->tp_netservice);
45236414Ssklower 		printf("m->mlen x%x, m->m_data:\n", m->m_len);
45336414Ssklower 		dump_buf(mtod(m, caddr_t), m->m_len);
45436414Ssklower 	ENDDEBUG
45536414Ssklower 	if( siso->siso_family != tpcb->tp_domain ) {
45636414Ssklower 		error = EAFNOSUPPORT;
45736414Ssklower 		goto done;
45836414Ssklower 	}
459*37469Ssklower 	IFDEBUG(D_CONN)
460*37469Ssklower 		printf("tp_route_to  calling nlp_pcbconn, netserv %d\n",
461*37469Ssklower 			tpcb->tp_netservice);
462*37469Ssklower 	ENDDEBUG
463*37469Ssklower 	error = (tpcb->tp_nlproto->nlp_pcbconn)(tpcb->tp_sock->so_pcb, m);
464*37469Ssklower 	if( error )
465*37469Ssklower 		goto done;
466*37469Ssklower 
46736414Ssklower 	{
46836414Ssklower 		register int save_netservice = tpcb->tp_netservice;
46936414Ssklower 
47036414Ssklower 		switch(tpcb->tp_netservice) {
47136414Ssklower 		case ISO_COSNS:
47236414Ssklower 		case ISO_CLNS:
47336414Ssklower 			/* This is a kludge but seems necessary so the passive end
47436414Ssklower 			 * can get long enough timers. sigh.
475*37469Ssklower 			if( siso->siso_addr.osinet_idi[1] == (u_char)IDI_OSINET )
47636414Ssklower 			 */
477*37469Ssklower 			if( siso->siso_addr.isoa_genaddr[2] == (char)IDI_OSINET ) {
47836414Ssklower 				if( tpcb->tp_dont_change_params == 0) {
47936414Ssklower 					copyQOSparms( &tp_conn_param[ISO_COSNS],
48036414Ssklower 							&tpcb->_tp_param);
48136414Ssklower 				}
48236414Ssklower 				tpcb->tp_flags |= TPF_NLQOS_PDN;
48336414Ssklower 			}
48436414Ssklower 			/* drop through to IN_CLNS*/
48536414Ssklower 		case IN_CLNS:
486*37469Ssklower 			if (iso_localifa(siso))
487*37469Ssklower 				tpcb->tp_flags |= TPF_PEER_ON_SAMENET;
48836414Ssklower 			if( (tpcb->tp_class & TP_CLASS_4)==0 ) {
48936414Ssklower 				error = EPROTOTYPE;
49036414Ssklower 				break;
49136414Ssklower 			}
49236414Ssklower 			tpcb->tp_class = TP_CLASS_4;  /* IGNORE dont_change_parms */
49336414Ssklower 			break;
49436414Ssklower 
49536414Ssklower 		case ISO_CONS:
49636414Ssklower #if NARGOXTWENTYFIVE > 0
49736414Ssklower 			tpcb->tp_flags |= TPF_NLQOS_PDN;
49836414Ssklower 			if( tpcb->tp_dont_change_params == 0 ) {
49936414Ssklower 				copyQOSparms( &tp_conn_param[ISO_CONS],
50036414Ssklower 							&tpcb->_tp_param);
50136414Ssklower 			}
50236414Ssklower 			/*
50336414Ssklower 			 * for use over x.25 really need a small receive window,
50436414Ssklower 			 * need to start slowly, need small max negotiable tpdu size,
50536414Ssklower 			 * and need to use the congestion window to the max
50636414Ssklower 			 * IGNORES tp_dont_change_params for these!
50736414Ssklower 			 */
50836414Ssklower 			if( tpcb->tp_sock->so_snd.sb_hiwat > 512 ) {
50936414Ssklower 				(void) soreserve(tpcb->tp_sock, 512, 512 );/* GAG */
51036414Ssklower 			}
51136414Ssklower 			tpcb->tp_rx_strat =  TPRX_USE_CW;
51236414Ssklower 
51336414Ssklower 			if( (tpcb->tp_nlproto != &nl_protosw[ISO_CONS]) ) {
51436414Ssklower 				/* if the listener was restricting us to clns,
51536414Ssklower 				 * ( we never get here if the listener isn't af_iso )
51636414Ssklower 				 * refuse the connection :
51736414Ssklower 				 * but we don't have a way to restrict thus - it's
51836414Ssklower 				 * utterly permissive.
51936414Ssklower 					if(channel)  {
52036414Ssklower 						(void) cons_netcmd(CONN_REFUSE, tpcb->tp_npcb,
52136414Ssklower 								channel, tpcb->tp_class == TP_CLASS_4);
52236414Ssklower 						error = EPFNOSUPPORT;
52336414Ssklower 						goto done;
52436414Ssklower 					}
52536414Ssklower 				 */
52636414Ssklower 				IFDEBUG(D_CONN)
52736414Ssklower 					printf(
52836414Ssklower 					"tp_route_to( CHANGING nlproto old 0x%x new 0x%x)\n",
52936414Ssklower 							tpcb->tp_nlproto , &nl_protosw[ISO_CONS]);
53036414Ssklower 				ENDDEBUG
53136414Ssklower 				tpcb->tp_nlproto = &nl_protosw[ISO_CONS];
53236414Ssklower 			}
53336414Ssklower 			/* Now we've got the right nl_protosw.
53436414Ssklower 			 * If we already have a channel (we were called from tp_input())
53536414Ssklower 			 * tell cons that we'll hang onto this channel.
53636414Ssklower 			 * If we don't already have one (we were called from usrreq())
53736414Ssklower 			 * -and if it's TP0 open a net connection and wait for it to finish.
53836414Ssklower 			 */
53936414Ssklower 			if( channel ) {
54036414Ssklower 				error = cons_netcmd( CONN_CONFIRM, tpcb->tp_npcb,
54136414Ssklower 								channel, tpcb->tp_class == TP_CLASS_4);
54236414Ssklower 				vc_to_kill ++;
54336414Ssklower 			} else if( tpcb->tp_class != TP_CLASS_4 /* class 4 only */) {
54436414Ssklower 				/* better open vc if any possibility of ending up
54536414Ssklower 				 * in non-multiplexing class
54636414Ssklower 				 */
54736414Ssklower 				error = cons_openvc(tpcb->tp_npcb, siso, tpcb->tp_sock);
54836414Ssklower 				vc_to_kill ++;
54936414Ssklower 			}
55036414Ssklower 			/* class 4 doesn't need to open a vc now - may use one already
55136414Ssklower 			 * opened or may open one only when it sends a pkt.
55236414Ssklower 			 */
55336414Ssklower #else NARGOXTWENTYFIVE > 0
55436414Ssklower 			error = ECONNREFUSED;
55536414Ssklower #endif NARGOXTWENTYFIVE > 0
55636414Ssklower 			break;
55736414Ssklower 		default:
55836414Ssklower 			error = EPROTOTYPE;
55936414Ssklower 		}
56036414Ssklower 
56136414Ssklower 		ASSERT( save_netservice == tpcb->tp_netservice);
56236414Ssklower 	}
56336414Ssklower 	if( error && vc_to_kill ) {
56436414Ssklower 		tp_netcmd( tpcb, CONN_CLOSE);
56536414Ssklower 		goto done;
56636414Ssklower 	}
56736414Ssklower 	{	/* start with the global rtt, rtv stats */
56836414Ssklower 		register int i =
56936414Ssklower 		   (int) tpcb->tp_flags & (TPF_PEER_ON_SAMENET | TPF_NLQOS_PDN);
57036414Ssklower 
57136414Ssklower 		tpcb->tp_rtt = tp_stat.ts_rtt[i];
57236414Ssklower 		tpcb->tp_rtv = tp_stat.ts_rtv[i];
57336414Ssklower 	}
57436414Ssklower done:
57536414Ssklower 	IFDEBUG(D_CONN)
57636414Ssklower 		printf("tp_route_to  returns 0x%x\n", error);
57736414Ssklower 	ENDDEBUG
57836414Ssklower 	IFTRACE(D_CONN)
57936414Ssklower 		tptraceTPCB(TPPTmisc, "route_to: returns: error netserv class", error,
58036414Ssklower 			tpcb->tp_netservice, tpcb->tp_class, 0);
58136414Ssklower 	ENDTRACE
58236414Ssklower 	return error;
58336414Ssklower }
58436414Ssklower 
58536414Ssklower #ifdef TP_PERF_MEAS
58636414Ssklower /*
58736414Ssklower  * CALLED FROM:
58836414Ssklower  *  tp_ctloutput() when the user sets TPOPT_PERF_MEAS on
58936414Ssklower  *  and tp_newsocket() when a new connection is made from
59036414Ssklower  *  a listening socket with tp_perf_on == true.
59136414Ssklower  * FUNCTION and ARGUMENTS:
59236414Ssklower  *  (tpcb) is the usual; this procedure gets a clear cluster mbuf for
59336414Ssklower  *  a tp_pmeas structure, and makes tpcb->tp_p_meas point to it.
59436414Ssklower  * RETURN VALUE:
59536414Ssklower  *  ENOBUFS if it cannot get a cluster mbuf.
59636414Ssklower  */
59736414Ssklower 
59836414Ssklower int
59936414Ssklower tp_setup_perf(tpcb)
60036414Ssklower 	register struct tp_pcb *tpcb;
60136414Ssklower {
60236414Ssklower 	register struct mbuf *q;
60336414Ssklower 
604*37469Ssklower 	if( tpcb->tp_p_meas == 0 ) {
605*37469Ssklower 		MGET(q, M_WAITOK, MT_PCB);
60636414Ssklower 		if (q == 0)
60736414Ssklower 			return ENOBUFS;
608*37469Ssklower 		MCLGET(q, M_WAITOK);
609*37469Ssklower 		if ((q->m_flags & M_EXT) == 0) {
610*37469Ssklower 			(void) m_free(q);
61136414Ssklower 			return ENOBUFS;
61236414Ssklower 		}
613*37469Ssklower 		q->m_len = sizeof (struct tp_pmeas);
614*37469Ssklower 		tpcb->tp_p_mbuf = q;
615*37469Ssklower 		tpcb->tp_p_meas = mtod(q, struct tp_pmeas *);
616*37469Ssklower 		bzero( (caddr_t)tpcb->tp_p_meas, sizeof (struct tp_pmeas) );
617*37469Ssklower 		IFDEBUG(D_PERF_MEAS)
618*37469Ssklower 			printf(
619*37469Ssklower 			"tpcb 0x%x so 0x%x ref 0x%x tp_p_meas 0x%x tp_perf_on 0x%x\n",
620*37469Ssklower 				tpcb, tpcb->tp_sock, tpcb->tp_lref,
621*37469Ssklower 				tpcb->tp_p_meas, tpcb->tp_perf_on);
622*37469Ssklower 		ENDDEBUG
623*37469Ssklower 		tpcb->tp_perf_on = 1;
62436414Ssklower 	}
62536414Ssklower 	return 0;
62636414Ssklower }
62736414Ssklower #endif TP_PERF_MEAS
62836414Ssklower 
62936414Ssklower #ifdef ARGO_DEBUG
63036414Ssklower dump_addr (addr)
63136414Ssklower 	register struct sockaddr *addr;
63236414Ssklower {
63336414Ssklower 	switch( addr->sa_family ) {
63436414Ssklower 		case AF_INET:
635*37469Ssklower 			dump_inaddr((struct sockaddr_in *)addr);
63636414Ssklower 			break;
637*37469Ssklower #ifdef ISO
63836414Ssklower 		case AF_ISO:
639*37469Ssklower 			dump_isoaddr((struct sockaddr_iso *)addr);
64036414Ssklower 			break;
641*37469Ssklower #endif ISO
64236414Ssklower 		default:
64336414Ssklower 			printf("BAD AF: 0x%x\n", addr->sa_family);
64436414Ssklower 			break;
64536414Ssklower 	}
64636414Ssklower }
64736414Ssklower 
648*37469Ssklower #define	MAX_COLUMNS	8
649*37469Ssklower /*
650*37469Ssklower  *	Dump the buffer to the screen in a readable format. Format is:
651*37469Ssklower  *
652*37469Ssklower  *		hex/dec  where hex is the hex format, dec is the decimal format.
653*37469Ssklower  *		columns of hex/dec numbers will be printed, followed by the
654*37469Ssklower  *		character representations (if printable).
655*37469Ssklower  */
656*37469Ssklower Dump_buf(buf, len)
657*37469Ssklower caddr_t	buf;
658*37469Ssklower int		len;
659*37469Ssklower {
660*37469Ssklower 	int		i,j;
661*37469Ssklower 
662*37469Ssklower 	printf("Dump buf 0x%x len 0x%x\n", buf, len);
663*37469Ssklower 	for (i = 0; i < len; i += MAX_COLUMNS) {
664*37469Ssklower 		printf("+%d:\t", i);
665*37469Ssklower 		for (j = 0; j < MAX_COLUMNS; j++) {
666*37469Ssklower 			if (i + j < len) {
667*37469Ssklower 				printf("%x/%d\t", buf[i+j]&0xff, buf[i+j]);
668*37469Ssklower 			} else {
669*37469Ssklower 				printf("	");
670*37469Ssklower 			}
671*37469Ssklower 		}
672*37469Ssklower 
673*37469Ssklower 		for (j = 0; j < MAX_COLUMNS; j++) {
674*37469Ssklower 			if (i + j < len) {
675*37469Ssklower 				if (((buf[i+j]) > 31) && ((buf[i+j]) < 128))
676*37469Ssklower 					printf("%c", buf[i+j]&0xff);
677*37469Ssklower 				else
678*37469Ssklower 					printf(".");
679*37469Ssklower 			}
680*37469Ssklower 		}
681*37469Ssklower 		printf("\n");
682*37469Ssklower 	}
683*37469Ssklower }
684*37469Ssklower 
685*37469Ssklower 
68636414Ssklower #endif ARGO_DEBUG
68736414Ssklower 
688