Sync usage with man page.
[netbsd-mini2440.git] / sys / netiso / tp_subr2.c
blob512622208121d271a98ec7103d7cba64bd5ab7ed
1 /* $NetBSD: tp_subr2.c,v 1.40 2009/03/18 17:06:53 cegger Exp $ */
3 /*-
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
31 * @(#)tp_subr2.c 8.1 (Berkeley) 6/10/93
34 /***********************************************************
35 Copyright IBM Corporation 1987
37 All Rights Reserved
39 Permission to use, copy, modify, and distribute this software and its
40 documentation for any purpose and without fee is hereby granted,
41 provided that the above copyright notice appear in all copies and that
42 both that copyright notice and this permission notice appear in
43 supporting documentation, and that the name of IBM not be
44 used in advertising or publicity pertaining to distribution of the
45 software without specific, written prior permission.
47 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
48 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
49 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
50 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
51 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
52 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
53 SOFTWARE.
55 ******************************************************************/
58 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
61 * Some auxiliary routines: tp_protocol_error: required by xebec- called when
62 * a combo of state, event, predicate isn't covered for by the transition
63 * file. tp_indicate: gives indications(signals) to the user process
64 * tp_getoptions: initializes variables that are affected by the options
65 * chosen.
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: tp_subr2.c,v 1.40 2009/03/18 17:06:53 cegger Exp $");
72 * this def'n is to cause the expansion of this macro in the routine
73 * tp_local_credit :
75 #define LOCAL_CREDIT_EXPAND
77 #include "opt_inet.h"
78 #include "opt_iso.h"
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/mbuf.h>
83 #include <sys/socket.h>
84 #include <sys/socketvar.h>
85 #include <sys/domain.h>
86 #include <sys/protosw.h>
87 #include <sys/errno.h>
88 #include <sys/time.h>
89 #include <sys/kernel.h>
90 #include <sys/queue.h>
92 #include <net/if.h>
93 #include <net/if_types.h>
95 #include <netiso/argo_debug.h>
96 #include <netiso/tp_param.h>
97 #include <netiso/tp_ip.h>
98 #include <netiso/iso.h>
99 #include <netiso/iso_errno.h>
100 #include <netiso/iso_pcb.h>
101 #include <netiso/iso_var.h>
102 #include <netiso/tp_timer.h>
103 #include <netiso/tp_stat.h>
104 #include <netiso/tp_tpdu.h>
105 #include <netiso/tp_pcb.h>
106 #include <netiso/tp_seq.h>
107 #include <netiso/tp_trace.h>
108 #include <netiso/tp_user.h>
109 #include <netiso/tp_var.h>
110 #include <netiso/cons.h>
111 #include <netiso/clnp.h>
113 #if 0
114 static void copyQOSparms (struct tp_conn_param *, struct tp_conn_param *);
115 #endif
118 * NAME: tp_local_credit()
120 * CALLED FROM:
121 * tp_emit(), tp_usrreq()
123 * FUNCTION and ARGUMENTS:
124 * Computes the local credit and stashes it in tpcb->tp_lcredit.
125 * It's a macro in the production system rather than a procdure.
127 * RETURNS:
129 * SIDE EFFECTS:
131 * NOTES:
132 * This doesn't actually get called in a production system -
133 * the macro gets expanded instead in place of calls to this proc.
134 * But for debugging, we call this and that allows us to add
135 * debugging messages easily here.
137 void
138 tp_local_credit(struct tp_pcb *tpcb)
140 LOCAL_CREDIT(tpcb);
141 #ifdef ARGO_DEBUG
142 if (argo_debug[D_CREDIT]) {
143 printf("ref 0x%x lcdt 0x%x l_tpdusize 0x%x decbit 0x%x cong_win 0x%lx\n",
144 tpcb->tp_lref,
145 tpcb->tp_lcredit,
146 tpcb->tp_l_tpdusize,
147 tpcb->tp_decbit,
148 tpcb->tp_cong_win
151 #endif
152 #ifdef TPPT
153 if (tp_traceflags[D_CREDIT]) {
154 tptraceTPCB(TPPTmisc,
155 "lcdt tpdusz \n",
156 tpcb->tp_lcredit, tpcb->tp_l_tpdusize, 0, 0);
158 #endif
162 * NAME: tp_protocol_error()
164 * CALLED FROM:
165 * tp_driver(), when it doesn't know what to do with
166 * a combo of event, state, predicate
168 * FUNCTION and ARGUMENTS:
169 * print error mesg
171 * RETURN VALUE:
172 * EIO - always
174 * SIDE EFFECTS:
176 * NOTES:
179 tp_protocol_error(struct tp_event *e, struct tp_pcb *tpcb)
181 printf("TP PROTOCOL ERROR! tpcb %p event 0x%x, state 0x%x\n",
182 tpcb, e->ev_number, tpcb->tp_state);
183 #ifdef TPPT
184 if (tp_traceflags[D_DRIVER]) {
185 tptraceTPCB(TPPTmisc, "PROTOCOL ERROR tpcb event state",
186 tpcb, e->ev_number, tpcb->tp_state, 0);
188 #endif
189 return EIO; /* for lack of anything better */
193 /* Not used at the moment */
194 void
195 tp_drain(void)
201 * NAME: tp_indicate()
203 * CALLED FROM:
204 * tp.trans when XPD arrive, when a connection is being disconnected by
205 * the arrival of a DR or ER, and when a connection times out.
207 * FUNCTION and ARGUMENTS:
208 * (ind) is the type of indication : T_DISCONNECT, T_XPD
209 * (error) is an E* value that will be put in the socket structure
210 * to be passed along to the user later.
211 * Gives a SIGURG to the user process or group indicated by the socket
212 * attached to the tpcb.
214 * RETURNS: Rien
216 * SIDE EFFECTS:
218 * NOTES:
220 void
221 tp_indicate(int ind, struct tp_pcb *tpcb, u_int error)
223 struct socket *so = tpcb->tp_sock;
224 #ifdef TPPT
225 if (tp_traceflags[D_INDICATION]) {
226 tptraceTPCB(TPPTindicate, ind, *(u_short *) (tpcb->tp_lsuffix),
227 *(u_short *) (tpcb->tp_fsuffix), error, so->so_pgid);
229 #endif
230 #ifdef ARGO_DEBUG
231 if (argo_debug[D_INDICATION]) {
232 char *ls, *fs;
233 ls = tpcb->tp_lsuffix,
234 fs = tpcb->tp_fsuffix,
236 printf(
237 "indicate 0x%x lsuf 0x%02x%02x fsuf 0x%02x%02x err 0x%x noind 0x%x ref 0x%x\n",
238 ind,
239 *ls, *(ls + 1), *fs, *(fs + 1),
240 error, /* so->so_pgrp, */
241 tpcb->tp_no_disc_indications,
242 tpcb->tp_lref);
244 #endif
246 if (ind == ER_TPDU) {
247 struct mbuf *m;
248 struct tp_disc_reason x;
250 if ((so->so_state & SS_CANTRCVMORE) == 0 &&
251 (m = m_get(M_DONTWAIT, MT_OOBDATA)) != 0) {
253 x.dr_hdr.cmsg_len = m->m_len = sizeof(x);
254 x.dr_hdr.cmsg_level = SOL_TRANSPORT;
255 x.dr_hdr.cmsg_type = TPOPT_DISC_REASON;
256 x.dr_reason = error;
257 *mtod(m, struct tp_disc_reason *) = x;
258 sbappendrecord(&tpcb->tp_Xrcv, m);
259 error = 0;
260 } else
261 error = ECONNRESET;
263 so->so_error = error;
265 if (ind == T_DISCONNECT) {
266 if (error == 0)
267 so->so_error = ENOTCONN;
268 if (tpcb->tp_no_disc_indications)
269 return;
271 #ifdef TPPT
272 if (tp_traceflags[D_INDICATION]) {
273 tptraceTPCB(TPPTmisc, "doing sohasoutofband(so)", so, 0, 0, 0);
275 #endif
276 sohasoutofband(so);
280 * NAME : tp_getoptions()
282 * CALLED FROM:
283 * tp.trans whenever we go into OPEN state
285 * FUNCTION and ARGUMENTS:
286 * sets the proper flags and values in the tpcb, to control
287 * the appropriate actions for the given class, options,
288 * sequence space, etc, etc.
290 * RETURNS: Nada
292 * SIDE EFFECTS:
294 * NOTES:
296 void
297 tp_getoptions(struct tp_pcb *tpcb)
299 tpcb->tp_seqmask =
300 tpcb->tp_xtd_format ? TP_XTD_FMT_MASK : TP_NML_FMT_MASK;
301 tpcb->tp_seqbit =
302 tpcb->tp_xtd_format ? TP_XTD_FMT_BIT : TP_NML_FMT_BIT;
303 tpcb->tp_seqhalf = tpcb->tp_seqbit >> 1;
304 tpcb->tp_dt_ticks =
305 max(tpcb->tp_dt_ticks, (tpcb->tp_peer_acktime + 2));
306 tp_rsyset(tpcb);
311 * NAME: tp_recycle_tsuffix()
313 * CALLED FROM:
314 * Called when a ref is frozen.
316 * FUNCTION and ARGUMENTS:
317 * allows the suffix to be reused.
319 * RETURNS: zilch
321 * SIDE EFFECTS:
323 * NOTES:
325 void
326 tp_recycle_tsuffix(void *v)
328 struct tp_pcb *tpcb = v;
329 memset((void *) tpcb->tp_lsuffix, 0, sizeof(tpcb->tp_lsuffix));
330 memset((void *) tpcb->tp_fsuffix, 0, sizeof(tpcb->tp_fsuffix));
331 tpcb->tp_fsuffixlen = tpcb->tp_lsuffixlen = 0;
333 (tpcb->tp_nlproto->nlp_recycle_suffix) (tpcb->tp_npcb);
337 * NAME: tp_quench()
339 * CALLED FROM:
340 * tp{af}_quench() when ICMP source quench or similar thing arrives.
342 * FUNCTION and ARGUMENTS:
343 * Drop the congestion window back to 1.
344 * Congestion window scheme:
345 * Initial value is 1. ("slow start" as Nagle, et. al. call it)
346 * For each good ack that arrives, the congestion window is increased
347 * by 1 (up to max size of logical infinity, which is to say,
348 * it doesn't wrap around).
349 * Source quench causes it to drop back to 1.
350 * tp_send() uses the smaller of (regular window, congestion window).
351 * One retransmission strategy option is to have any retransmission
352 * cause reset the congestion window back to 1.
354 * (cmd) is either PRC_QUENCH: source quench, or
355 * PRC_QUENCH2: dest. quench (dec bit)
357 * RETURNS:
359 * SIDE EFFECTS:
361 * NOTES:
363 void
364 tp_quench(struct inpcb *ipcb, int cmd)
366 struct tp_pcb *tpcb = (struct tp_pcb *) ipcb;
367 #ifdef ARGO_DEBUG
368 if (argo_debug[D_QUENCH]) {
369 printf("tp_quench tpcb %p ref 0x%x sufx 0x%x\n",
370 tpcb, tpcb->tp_lref, *(u_short *) (tpcb->tp_lsuffix));
371 printf("cong_win 0x%lx decbit 0x%x \n",
372 tpcb->tp_cong_win, tpcb->tp_decbit);
374 #endif
375 switch (cmd) {
376 case PRC_QUENCH:
377 tpcb->tp_cong_win = tpcb->tp_l_tpdusize;
378 IncStat(ts_quench);
379 break;
380 case PRC_QUENCH2:
381 /* might as well quench source also */
382 tpcb->tp_cong_win = tpcb->tp_l_tpdusize;
383 tpcb->tp_decbit = TP_DECBIT_CLEAR_COUNT;
384 IncStat(ts_rcvdecbit);
385 break;
391 * NAME: tp_netcmd()
393 * CALLED FROM:
395 * FUNCTION and ARGUMENTS:
397 * RETURNS:
399 * SIDE EFFECTS:
401 * NOTES:
403 void
404 tp_netcmd(struct tp_pcb *tpcb, int cmd)
406 printf("tp_netcmd(): X25 NOT CONFIGURED!!\n");
410 * CALLED FROM:
411 * tp_ctloutput() and tp_emit()
412 * FUNCTION and ARGUMENTS:
413 * Convert a class mask to the highest numeric value it represents.
416 tp_mask_to_num(u_char x)
418 int j;
420 for (j = 4; j >= 0; j--) {
421 if (x & (1 << j))
422 break;
424 ASSERT((j == 4) || (j == 0)); /* for now */
425 if ((j != 4) && (j != 0)) {
426 printf("ASSERTION ERROR: tp_mask_to_num: x 0x%x j %d\n",
427 x, j);
429 #ifdef TPPT
430 if (tp_traceflags[D_TPINPUT]) {
431 tptrace(TPPTmisc, "tp_mask_to_num(x) returns j", x, j, 0, 0);
433 #endif
434 #ifdef ARGO_DEBUG
435 if (argo_debug[D_TPINPUT]) {
436 printf("tp_mask_to_num(0x%x) returns 0x%x\n", x, j);
438 #endif
439 return j;
442 #if 0
443 static void
444 copyQOSparms(const struct tp_conn_param *src, struct tp_conn_params *dst)
446 /* copy all but the bits stuff at the end */
447 #define COPYSIZE (12 * sizeof(short))
449 memcpy((void *) dst, (void *) src, COPYSIZE);
450 dst->p_tpdusize = src->p_tpdusize;
451 dst->p_ack_strat = src->p_ack_strat;
452 dst->p_rx_strat = src->p_rx_strat;
453 #undef COPYSIZE
455 #endif
458 * Determine a reasonable value for maxseg size.
459 * If the route is known, check route for mtu.
460 * We also initialize the congestion/slow start
461 * window to be a single segment if the destination isn't local.
462 * While looking at the routing entry, we also initialize other path-dependent
463 * parameters from pre-set or cached values in the routing entry.
465 void
466 tp_mss(struct tp_pcb *tpcb, int nhdr_size)
468 struct rtentry *rt;
469 struct ifnet *ifp;
470 int rtt, mss;
471 u_long bufsize;
472 int i, ssthresh = 0, rt_mss;
473 struct socket *so;
475 if (tpcb->tp_ptpdusize)
476 mss = tpcb->tp_ptpdusize << 7;
477 else
478 mss = 1 << tpcb->tp_tpdusize;
479 so = tpcb->tp_sock;
480 if ((rt = rtcache_validate(tpcb->tp_routep)) == NULL) {
481 bufsize = so->so_rcv.sb_hiwat;
482 goto punt_route;
484 ifp = rt->rt_ifp;
486 #ifdef RTV_MTU /* if route characteristics exist ... */
488 * While we're here, check if there's an initial rtt
489 * or rttvar. Convert from the route-table units
490 * to hz ticks for the smoothed timers and slow-timeout units
491 * for other inital variables.
493 if (tpcb->tp_rtt == 0 && (rtt = rt->rt_rmx.rmx_rtt)) {
494 tpcb->tp_rtt = rtt * hz / RTM_RTTUNIT;
495 if (rt->rt_rmx.rmx_rttvar)
496 tpcb->tp_rtv = rt->rt_rmx.rmx_rttvar
497 * hz / RTM_RTTUNIT;
498 else
499 tpcb->tp_rtv = tpcb->tp_rtt;
502 * if there's an mtu associated with the route, use it
504 if (rt->rt_rmx.rmx_mtu)
505 rt_mss = rt->rt_rmx.rmx_mtu - nhdr_size;
506 else
507 #endif /* RTV_MTU */
508 rt_mss = (ifp->if_mtu - nhdr_size);
509 if (tpcb->tp_ptpdusize == 0 || /* assume application doesn't care */
510 mss > rt_mss /* network won't support what was asked for */ )
511 mss = rt_mss;
512 /* can propose mtu which are multiples of 128 */
513 mss &= ~0x7f;
515 * If there's a pipesize, change the socket buffer
516 * to that size.
518 #ifdef RTV_SPIPE
519 if ((bufsize = rt->rt_rmx.rmx_sendpipe) > 0) {
520 #endif
521 bufsize = min(bufsize, so->so_snd.sb_hiwat);
522 (void) sbreserve(&so->so_snd, bufsize, so);
524 #ifdef RTV_SPIPE
525 if ((bufsize = rt->rt_rmx.rmx_recvpipe) > 0) {
526 #endif
527 bufsize = min(bufsize, so->so_rcv.sb_hiwat);
528 (void) sbreserve(&so->so_rcv, bufsize, so);
529 } else
530 bufsize = so->so_rcv.sb_hiwat;
531 #ifdef RTV_SSTHRESH
533 * There's some sort of gateway or interface
534 * buffer limit on the path. Use this to set
535 * the slow start threshhold, but set the
536 * threshold to no less than 2*mss.
538 ssthresh = rt->rt_rmx.rmx_ssthresh;
539 punt_route:
541 * The current mss is initialized to the default value.
542 * If we compute a smaller value, reduce the current mss.
543 * If we compute a larger value, return it for use in sending
544 * a max seg size option.
545 * If we received an offer, don't exceed it.
546 * However, do not accept offers under 128 bytes.
548 if (tpcb->tp_l_tpdusize)
549 mss = min(mss, tpcb->tp_l_tpdusize);
551 * We want a minimum recv window of 4 packets to
552 * signal packet loss by duplicate acks.
554 mss = min(mss, bufsize >> 2) & ~0x7f;
555 mss = max(mss, 128); /* sanity */
556 tpcb->tp_cong_win =
557 (rt == 0 || (rt->rt_flags & RTF_GATEWAY)) ? mss : bufsize;
558 tpcb->tp_l_tpdusize = mss;
559 tp_rsyset(tpcb);
560 tpcb->tp_ssthresh = max(2 * mss, ssthresh);
561 /* Calculate log2 of mss */
562 for (i = TP_MIN_TPDUSIZE + 1; i <= TP_MAX_TPDUSIZE; i++)
563 if ((1 << i) > mss)
564 break;
565 i--;
566 tpcb->tp_tpdusize = i;
567 #endif /* RTV_MTU */
571 * CALLED FROM:
572 * tp_usrreq on PRU_CONNECT and tp_input on receipt of CR
574 * FUNCTION and ARGUMENTS:
575 * -- An mbuf containing the peer's network address.
576 * -- Our control block, which will be modified
577 * -- In the case of cons, a control block for that layer.
580 * RETURNS:
581 * errno value :
582 * EAFNOSUPPORT if can't find an nl_protosw for x.25 (really could panic)
583 * ECONNREFUSED if trying to run TP0 with non-type 37 address
584 * possibly other E* returned from cons_netcmd()
586 * SIDE EFFECTS:
587 * Determines recommended tpdusize, buffering and intial delays
588 * based on information cached on the route.
591 tp_route_to(struct mbuf *m, struct tp_pcb *tpcb, void *channel)
593 struct sockaddr_iso *siso; /* NOTE: this may be a
594 * sockaddr_in */
595 int error = 0, save_netservice = tpcb->tp_netservice;
596 struct rtentry *rt = 0;
597 int nhdr_size;
599 siso = mtod(m, struct sockaddr_iso *);
600 #ifdef TPPT
601 if (tp_traceflags[D_CONN]) {
602 tptraceTPCB(TPPTmisc,
603 "route_to: so afi netservice class",
604 tpcb->tp_sock, siso->siso_addr.isoa_genaddr[0], tpcb->tp_netservice,
605 tpcb->tp_class);
607 #endif
608 #ifdef ARGO_DEBUG
609 if (argo_debug[D_CONN]) {
610 printf("tp_route_to( m %p, channel %p, tpcb %p netserv 0x%x)\n",
611 m, channel, tpcb, tpcb->tp_netservice);
612 printf("m->mlen x%x, m->m_data:\n", m->m_len);
613 dump_buf(mtod(m, void *), m->m_len);
615 #endif
616 if (channel == NULL) {
617 switch (siso->siso_family) {
618 default:
619 error = EAFNOSUPPORT;
620 goto done;
621 #ifdef ISO
622 case AF_ISO:
624 struct isopcb *isop = (struct isopcb *) tpcb->tp_npcb;
625 int flags = tpcb->tp_sock->so_options & SO_DONTROUTE;
626 tpcb->tp_netservice = ISO_CLNS;
627 if (clnp_route(&siso->siso_addr, &isop->isop_route,
628 flags, NULL, NULL) == 0) {
629 rt = rtcache_validate(&isop->isop_route);
630 if (rt && rt->rt_flags & RTF_PROTO1)
631 tpcb->tp_netservice = ISO_CONS;
633 } break;
634 #endif
635 #ifdef INET
636 case AF_INET:
637 tpcb->tp_netservice = IN_CLNS;
638 #endif
640 if (tpcb->tp_nlproto->nlp_afamily != siso->siso_family) {
641 #ifdef ARGO_DEBUG
642 if (argo_debug[D_CONN]) {
643 printf("tp_route_to( CHANGING nlproto old 0x%x new 0x%x)\n",
644 save_netservice, tpcb->tp_netservice);
646 #endif
647 if ((error = tp_set_npcb(tpcb)) != 0)
648 goto done;
650 #ifdef ARGO_DEBUG
651 if (argo_debug[D_CONN]) {
652 printf("tp_route_to calling nlp_pcbconn, netserv %d\n",
653 tpcb->tp_netservice);
655 #endif
656 tpcb->tp_nlproto = nl_protosw + tpcb->tp_netservice;
657 error = (*tpcb->tp_nlproto->nlp_pcbconn) (tpcb->tp_npcb, m, NULL);
659 if (error)
660 goto done;
661 /* only gets common info */
662 nhdr_size = (*tpcb->tp_nlproto->nlp_mtu)(tpcb);
663 tp_mss(tpcb, nhdr_size);
664 done:
665 #ifdef ARGO_DEBUG
666 if (argo_debug[D_CONN]) {
667 printf("tp_route_to returns 0x%x\n", error);
669 #endif
670 #ifdef TPPT
671 if (tp_traceflags[D_CONN]) {
672 tptraceTPCB(TPPTmisc, "route_to: returns: error netserv class", error,
673 tpcb->tp_netservice, tpcb->tp_class, 0);
675 #endif
676 return error;
679 /* class zero version */
680 void
681 tp0_stash(struct tp_pcb *tpcb, struct tp_event *e)
683 #define E e->TPDU_ATTR(DT)
685 struct sockbuf *sb = &tpcb->tp_sock->so_rcv;
687 #ifdef TP_PERF_MEAS
688 if (DOPERF(tpcb)) {
689 PStat(tpcb, Nb_from_ll) += E.e_datalen;
690 tpmeas(tpcb->tp_lref, TPtime_from_ll, &e->e_time,
691 E.e_seq, PStat(tpcb, Nb_from_ll), E.e_datalen);
693 #endif
695 #ifdef ARGO_DEBUG
696 if (argo_debug[D_STASH]) {
697 printf("stash EQ: seq 0x%x datalen 0x%x eot 0x%x",
698 E.e_seq, E.e_datalen, E.e_eot);
700 #endif
702 #ifdef TPPT
703 if (tp_traceflags[D_STASH]) {
704 tptraceTPCB(TPPTmisc, "stash EQ: seq len eot",
705 E.e_seq, E.e_datalen, E.e_eot, 0);
707 #endif
709 if (E.e_eot) {
710 struct mbuf *n = E.e_data;
711 n->m_flags |= M_EOR;
712 n->m_nextpkt = NULL; /* set on tp_input */
714 sbappend(sb, E.e_data);
715 #ifdef ARGO_DEBUG
716 if (argo_debug[D_STASH]) {
717 dump_mbuf(sb->sb_mb, "stash 0: so_rcv after appending");
719 #endif
720 if (tpcb->tp_netservice != ISO_CONS)
721 printf("tp0_stash: tp running over something weird\n");
724 void
725 tp0_openflow(struct tp_pcb *tpcb)
727 if (tpcb->tp_netservice != ISO_CONS)
728 printf("tp0_openflow: tp running over something weird\n");
731 #ifdef TP_PERF_MEAS
733 * CALLED FROM:
734 * tp_ctloutput() when the user sets TPOPT_PERF_MEAS on
735 * and tp_newsocket() when a new connection is made from
736 * a listening socket with tp_perf_on == true.
737 * FUNCTION and ARGUMENTS:
738 * (tpcb) is the usual; this procedure gets a clear cluster mbuf for
739 * a tp_pmeas structure, and makes tpcb->tp_p_meas point to it.
740 * RETURN VALUE:
741 * ENOBUFS if it cannot get a cluster mbuf.
745 tp_setup_perf(struct tp_pcb *tpcb)
747 if (tpcb->tp_p_meas == 0) {
748 tpcb->tp_p_meas = malloc(sizeof(struct tp_pmeas), M_PCB, M_WAITOK|M_ZERO);
749 #ifdef ARGO_DEBUG
750 if (argo_debug[D_PERF_MEAS]) {
751 printf(
752 "tpcb 0x%x so 0x%x ref 0x%x tp_p_meas 0x%x tp_perf_on 0x%x\n",
753 tpcb, tpcb->tp_sock, tpcb->tp_lref,
754 tpcb->tp_p_meas, tpcb->tp_perf_on);
756 #endif
757 tpcb->tp_perf_on = 1;
759 return 0;
761 #endif /* TP_PERF_MEAS */
763 #ifdef ARGO_DEBUG
764 void
765 dump_addr(struct sockaddr *addr)
767 switch (addr->sa_family) {
768 #ifdef INET
769 case AF_INET:
770 dump_inaddr(satosin(addr));
771 break;
772 #endif
773 #ifdef ISO
774 case AF_ISO:
775 dump_isoaddr(satosiso(addr));
776 break;
777 #endif /* ISO */
778 default:
779 printf("BAD AF: 0x%x\n", addr->sa_family);
780 break;
784 #define MAX_COLUMNS 8
786 * Dump the buffer to the screen in a readable format. Format is:
788 * hex/dec where hex is the hex format, dec is the decimal format.
789 * columns of hex/dec numbers will be printed, followed by the
790 * character representations (if printable).
792 void
793 Dump_buf(const void *buf, size_t len)
795 int i, j;
796 #define Buf ((const u_char *)buf)
797 printf("Dump buf %p len 0x%lx\n", buf, (unsigned long)len);
798 for (i = 0; i < len; i += MAX_COLUMNS) {
799 printf("+%d:\t", i);
800 for (j = 0; j < MAX_COLUMNS; j++) {
801 if (i + j < len) {
802 printf("%x/%d\t", Buf[i + j], Buf[i + j]);
803 } else {
804 printf(" ");
808 for (j = 0; j < MAX_COLUMNS; j++) {
809 if (i + j < len) {
810 if (((Buf[i + j]) > 31) && ((Buf[i + j]) < 128))
811 printf("%c", Buf[i + j]);
812 else
813 printf(".");
816 printf("\n");
819 #endif /* ARGO_DEBUG */