FreeBSD/Linux Kernel Cross Reference
sys/netiso/tp_subr2.c
1 /* $NetBSD: tp_subr2.c,v 1.33 2006/11/16 01:33:51 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
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.
18 *
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.
30 *
31 * @(#)tp_subr2.c 8.1 (Berkeley) 6/10/93
32 */
33
34 /***********************************************************
35 Copyright IBM Corporation 1987
36
37 All Rights Reserved
38
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.
46
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.
54
55 ******************************************************************/
56
57 /*
58 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
59 */
60 /*
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.
66 */
67
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: tp_subr2.c,v 1.33 2006/11/16 01:33:51 christos Exp $");
70
71 /*
72 * this def'n is to cause the expansion of this macro in the routine
73 * tp_local_credit :
74 */
75 #define LOCAL_CREDIT_EXPAND
76
77 #include "opt_inet.h"
78 #include "opt_iso.h"
79
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>
91
92 #include <net/if.h>
93 #include <net/if_types.h>
94
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>
112
113 #if 0
114 static void copyQOSparms (struct tp_conn_param *, struct tp_conn_param *);
115 #endif
116
117 /*
118 * NAME: tp_local_credit()
119 *
120 * CALLED FROM:
121 * tp_emit(), tp_usrreq()
122 *
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.
126 *
127 * RETURNS:
128 *
129 * SIDE EFFECTS:
130 *
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.
136 */
137 void
138 tp_local_credit(struct tp_pcb *tpcb)
139 {
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
149 );
150 }
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);
157 }
158 #endif
159 }
160
161 /*
162 * NAME: tp_protocol_error()
163 *
164 * CALLED FROM:
165 * tp_driver(), when it doesn't know what to do with
166 * a combo of event, state, predicate
167 *
168 * FUNCTION and ARGUMENTS:
169 * print error mesg
170 *
171 * RETURN VALUE:
172 * EIO - always
173 *
174 * SIDE EFFECTS:
175 *
176 * NOTES:
177 */
178 int
179 tp_protocol_error(struct tp_event *e, struct tp_pcb *tpcb)
180 {
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);
187 }
188 #endif
189 return EIO; /* for lack of anything better */
190 }
191
192
193 /* Not used at the moment */
194 void
195 tp_drain(void)
196 {
197 }
198
199
200 /*
201 * NAME: tp_indicate()
202 *
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.
206 *
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.
213 *
214 * RETURNS: Rien
215 *
216 * SIDE EFFECTS:
217 *
218 * NOTES:
219 */
220 void
221 tp_indicate(int ind, struct tp_pcb *tpcb, u_int error)
222 {
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);
228 }
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,
235
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);
243 }
244 #endif
245
246 if (ind == ER_TPDU) {
247 struct mbuf *m;
248 struct tp_disc_reason x;
249
250 if ((so->so_state & SS_CANTRCVMORE) == 0 &&
251 (m = m_get(M_DONTWAIT, MT_OOBDATA)) != 0) {
252
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;
262 }
263 so->so_error = error;
264
265 if (ind == T_DISCONNECT) {
266 if (error == 0)
267 so->so_error = ENOTCONN;
268 if (tpcb->tp_no_disc_indications)
269 return;
270 }
271 #ifdef TPPT
272 if (tp_traceflags[D_INDICATION]) {
273 tptraceTPCB(TPPTmisc, "doing sohasoutofband(so)", so, 0, 0, 0);
274 }
275 #endif
276 sohasoutofband(so);
277 }
278
279 /*
280 * NAME : tp_getoptions()
281 *
282 * CALLED FROM:
283 * tp.trans whenever we go into OPEN state
284 *
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.
289 *
290 * RETURNS: Nada
291 *
292 * SIDE EFFECTS:
293 *
294 * NOTES:
295 */
296 void
297 tp_getoptions(struct tp_pcb *tpcb)
298 {
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);
307
308 }
309
310 /*
311 * NAME: tp_recycle_tsuffix()
312 *
313 * CALLED FROM:
314 * Called when a ref is frozen.
315 *
316 * FUNCTION and ARGUMENTS:
317 * allows the suffix to be reused.
318 *
319 * RETURNS: zilch
320 *
321 * SIDE EFFECTS:
322 *
323 * NOTES:
324 */
325 void
326 tp_recycle_tsuffix(void *v)
327 {
328 struct tp_pcb *tpcb = v;
329 bzero((caddr_t) tpcb->tp_lsuffix, sizeof(tpcb->tp_lsuffix));
330 bzero((caddr_t) tpcb->tp_fsuffix, sizeof(tpcb->tp_fsuffix));
331 tpcb->tp_fsuffixlen = tpcb->tp_lsuffixlen = 0;
332
333 (tpcb->tp_nlproto->nlp_recycle_suffix) (tpcb->tp_npcb);
334 }
335
336 /*
337 * NAME: tp_quench()
338 *
339 * CALLED FROM:
340 * tp{af}_quench() when ICMP source quench or similar thing arrives.
341 *
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.
353 *
354 * (cmd) is either PRC_QUENCH: source quench, or
355 * PRC_QUENCH2: dest. quench (dec bit)
356 *
357 * RETURNS:
358 *
359 * SIDE EFFECTS:
360 *
361 * NOTES:
362 */
363 void
364 tp_quench(struct inpcb *ipcb, int cmd)
365 {
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);
373 }
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;
386 }
387 }
388
389
390 /*
391 * NAME: tp_netcmd()
392 *
393 * CALLED FROM:
394 *
395 * FUNCTION and ARGUMENTS:
396 *
397 * RETURNS:
398 *
399 * SIDE EFFECTS:
400 *
401 * NOTES:
402 */
403 void
404 tp_netcmd(struct tp_pcb *tpcb, int cmd)
405 {
406 #ifdef TPCONS
407 struct isopcb *isop;
408 struct pklcd *lcp;
409
410 if (tpcb->tp_netservice != ISO_CONS)
411 return;
412 isop = (struct isopcb *) tpcb->tp_npcb;
413 lcp = (struct pklcd *) isop->isop_chan;
414 switch (cmd) {
415
416 case CONN_CLOSE:
417 case CONN_REFUSE:
418 if (isop->isop_refcnt == 1) {
419 /*
420 * This is really superfluous, since it would happen
421 * anyway in iso_pcbdetach, although it is a courtesy
422 * to free up the x.25 channel before the refwait
423 * timer expires.
424 */
425 lcp->lcd_upper = 0;
426 lcp->lcd_upnext = 0;
427 pk_disconnect(lcp);
428 isop->isop_chan = 0;
429 isop->isop_refcnt = 0;
430 }
431 break;
432
433 default:
434 printf("tp_netcmd(%p, %#x) NOT IMPLEMENTED\n", tpcb, cmd);
435 break;
436 }
437 #else /* TPCONS */
438 printf("tp_netcmd(): X25 NOT CONFIGURED!!\n");
439 #endif
440 }
441
442 /*
443 * CALLED FROM:
444 * tp_ctloutput() and tp_emit()
445 * FUNCTION and ARGUMENTS:
446 * Convert a class mask to the highest numeric value it represents.
447 */
448 int
449 tp_mask_to_num(u_char x)
450 {
451 int j;
452
453 for (j = 4; j >= 0; j--) {
454 if (x & (1 << j))
455 break;
456 }
457 ASSERT((j == 4) || (j == 0)); /* for now */
458 if ((j != 4) && (j != 0)) {
459 printf("ASSERTION ERROR: tp_mask_to_num: x 0x%x j %d\n",
460 x, j);
461 }
462 #ifdef TPPT
463 if (tp_traceflags[D_TPINPUT]) {
464 tptrace(TPPTmisc, "tp_mask_to_num(x) returns j", x, j, 0, 0);
465 }
466 #endif
467 #ifdef ARGO_DEBUG
468 if (argo_debug[D_TPINPUT]) {
469 printf("tp_mask_to_num(0x%x) returns 0x%x\n", x, j);
470 }
471 #endif
472 return j;
473 }
474
475 #if 0
476 static void
477 copyQOSparms(const struct tp_conn_param *src, struct tp_conn_params *dst)
478 {
479 /* copy all but the bits stuff at the end */
480 #define COPYSIZE (12 * sizeof(short))
481
482 bcopy((caddr_t) src, (caddr_t) dst, COPYSIZE);
483 dst->p_tpdusize = src->p_tpdusize;
484 dst->p_ack_strat = src->p_ack_strat;
485 dst->p_rx_strat = src->p_rx_strat;
486 #undef COPYSIZE
487 }
488 #endif
489
490 /*
491 * Determine a reasonable value for maxseg size.
492 * If the route is known, check route for mtu.
493 * We also initialize the congestion/slow start
494 * window to be a single segment if the destination isn't local.
495 * While looking at the routing entry, we also initialize other path-dependent
496 * parameters from pre-set or cached values in the routing entry.
497 */
498 void
499 tp_mss(struct tp_pcb *tpcb, int nhdr_size)
500 {
501 struct rtentry *rt;
502 struct ifnet *ifp;
503 int rtt, mss;
504 u_long bufsize;
505 int i, ssthresh = 0, rt_mss;
506 struct socket *so;
507
508 if (tpcb->tp_ptpdusize)
509 mss = tpcb->tp_ptpdusize << 7;
510 else
511 mss = 1 << tpcb->tp_tpdusize;
512 so = tpcb->tp_sock;
513 if ((rt = *(tpcb->tp_routep)) == 0) {
514 bufsize = so->so_rcv.sb_hiwat;
515 goto punt_route;
516 }
517 ifp = rt->rt_ifp;
518
519 #ifdef RTV_MTU /* if route characteristics exist ... */
520 /*
521 * While we're here, check if there's an initial rtt
522 * or rttvar. Convert from the route-table units
523 * to hz ticks for the smoothed timers and slow-timeout units
524 * for other inital variables.
525 */
526 if (tpcb->tp_rtt == 0 && (rtt = rt->rt_rmx.rmx_rtt)) {
527 tpcb->tp_rtt = rtt * hz / RTM_RTTUNIT;
528 if (rt->rt_rmx.rmx_rttvar)
529 tpcb->tp_rtv = rt->rt_rmx.rmx_rttvar
530 * hz / RTM_RTTUNIT;
531 else
532 tpcb->tp_rtv = tpcb->tp_rtt;
533 }
534 /*
535 * if there's an mtu associated with the route, use it
536 */
537 if (rt->rt_rmx.rmx_mtu)
538 rt_mss = rt->rt_rmx.rmx_mtu - nhdr_size;
539 else
540 #endif /* RTV_MTU */
541 rt_mss = (ifp->if_mtu - nhdr_size);
542 if (tpcb->tp_ptpdusize == 0 || /* assume application doesn't care */
543 mss > rt_mss /* network won't support what was asked for */ )
544 mss = rt_mss;
545 /* can propose mtu which are multiples of 128 */
546 mss &= ~0x7f;
547 /*
548 * If there's a pipesize, change the socket buffer
549 * to that size.
550 */
551 #ifdef RTV_SPIPE
552 if ((bufsize = rt->rt_rmx.rmx_sendpipe) > 0) {
553 #endif
554 bufsize = min(bufsize, so->so_snd.sb_hiwat);
555 (void) sbreserve(&so->so_snd, bufsize, so);
556 }
557 #ifdef RTV_SPIPE
558 if ((bufsize = rt->rt_rmx.rmx_recvpipe) > 0) {
559 #endif
560 bufsize = min(bufsize, so->so_rcv.sb_hiwat);
561 (void) sbreserve(&so->so_rcv, bufsize, so);
562 } else
563 bufsize = so->so_rcv.sb_hiwat;
564 #ifdef RTV_SSTHRESH
565 /*
566 * There's some sort of gateway or interface
567 * buffer limit on the path. Use this to set
568 * the slow start threshhold, but set the
569 * threshold to no less than 2*mss.
570 */
571 ssthresh = rt->rt_rmx.rmx_ssthresh;
572 punt_route:
573 /*
574 * The current mss is initialized to the default value.
575 * If we compute a smaller value, reduce the current mss.
576 * If we compute a larger value, return it for use in sending
577 * a max seg size option.
578 * If we received an offer, don't exceed it.
579 * However, do not accept offers under 128 bytes.
580 */
581 if (tpcb->tp_l_tpdusize)
582 mss = min(mss, tpcb->tp_l_tpdusize);
583 /*
584 * We want a minimum recv window of 4 packets to
585 * signal packet loss by duplicate acks.
586 */
587 mss = min(mss, bufsize >> 2) & ~0x7f;
588 mss = max(mss, 128); /* sanity */
589 tpcb->tp_cong_win =
590 (rt == 0 || (rt->rt_flags & RTF_GATEWAY)) ? mss : bufsize;
591 tpcb->tp_l_tpdusize = mss;
592 tp_rsyset(tpcb);
593 tpcb->tp_ssthresh = max(2 * mss, ssthresh);
594 /* Calculate log2 of mss */
595 for (i = TP_MIN_TPDUSIZE + 1; i <= TP_MAX_TPDUSIZE; i++)
596 if ((1 << i) > mss)
597 break;
598 i--;
599 tpcb->tp_tpdusize = i;
600 #endif /* RTV_MTU */
601 }
602
603 /*
604 * CALLED FROM:
605 * tp_usrreq on PRU_CONNECT and tp_input on receipt of CR
606 *
607 * FUNCTION and ARGUMENTS:
608 * -- An mbuf containing the peer's network address.
609 * -- Our control block, which will be modified
610 * -- In the case of cons, a control block for that layer.
611 *
612 *
613 * RETURNS:
614 * errno value :
615 * EAFNOSUPPORT if can't find an nl_protosw for x.25 (really could panic)
616 * ECONNREFUSED if trying to run TP0 with non-type 37 address
617 * possibly other E* returned from cons_netcmd()
618 *
619 * SIDE EFFECTS:
620 * Determines recommended tpdusize, buffering and intial delays
621 * based on information cached on the route.
622 */
623 int
624 tp_route_to(struct mbuf *m, struct tp_pcb *tpcb, caddr_t channel)
625 {
626 struct sockaddr_iso *siso; /* NOTE: this may be a
627 * sockaddr_in */
628 int error = 0, save_netservice = tpcb->tp_netservice;
629 struct rtentry *rt = 0;
630 int nhdr_size;
631
632 siso = mtod(m, struct sockaddr_iso *);
633 #ifdef TPPT
634 if (tp_traceflags[D_CONN]) {
635 tptraceTPCB(TPPTmisc,
636 "route_to: so afi netservice class",
637 tpcb->tp_sock, siso->siso_addr.isoa_genaddr[0], tpcb->tp_netservice,
638 tpcb->tp_class);
639 }
640 #endif
641 #ifdef ARGO_DEBUG
642 if (argo_debug[D_CONN]) {
643 printf("tp_route_to( m %p, channel %p, tpcb %p netserv 0x%x)\n",
644 m, channel, tpcb, tpcb->tp_netservice);
645 printf("m->mlen x%x, m->m_data:\n", m->m_len);
646 dump_buf(mtod(m, caddr_t), m->m_len);
647 }
648 #endif
649 if (channel) {
650 #ifdef TPCONS
651 struct pklcd *lcp = (struct pklcd *) channel;
652 struct isopcb *isop = (struct isopcb *) lcp->lcd_upnext,
653 *isop_new = (struct isopcb *) tpcb->tp_npcb;
654 /*
655 * The next 2 lines believe that you haven't set any network
656 * level options or done a pcbconnect and XXXXXXX'edly apply
657 * to both inpcb's and isopcb's
658 */
659 remque(isop_new);
660 free(isop_new, M_PCB);
661 tpcb->tp_npcb = (caddr_t) isop;
662 tpcb->tp_netservice = ISO_CONS;
663 tpcb->tp_nlproto = nl_protosw + ISO_CONS;
664 if (isop->isop_refcnt++ == 0) {
665 iso_putsufx(isop, tpcb->tp_lsuffix,
666 tpcb->tp_lsuffixlen, TP_LOCAL);
667 isop->isop_socket = tpcb->tp_sock;
668 }
669 #endif
670 } else {
671 switch (siso->siso_family) {
672 default:
673 error = EAFNOSUPPORT;
674 goto done;
675 #ifdef ISO
676 case AF_ISO:
677 {
678 struct isopcb *isop = (struct isopcb *) tpcb->tp_npcb;
679 int flags = tpcb->tp_sock->so_options & SO_DONTROUTE;
680 tpcb->tp_netservice = ISO_CLNS;
681 if (clnp_route(&siso->siso_addr, &isop->isop_route,
682 flags, NULL, NULL) == 0) {
683 rt = isop->isop_route.ro_rt;
684 if (rt && rt->rt_flags & RTF_PROTO1)
685 tpcb->tp_netservice = ISO_CONS;
686 }
687 } break;
688 #endif
689 #ifdef INET
690 case AF_INET:
691 tpcb->tp_netservice = IN_CLNS;
692 #endif
693 }
694 if (tpcb->tp_nlproto->nlp_afamily != siso->siso_family) {
695 #ifdef ARGO_DEBUG
696 if (argo_debug[D_CONN]) {
697 printf("tp_route_to( CHANGING nlproto old 0x%x new 0x%x)\n",
698 save_netservice, tpcb->tp_netservice);
699 }
700 #endif
701 if ((error = tp_set_npcb(tpcb)) != 0)
702 goto done;
703 }
704 #ifdef ARGO_DEBUG
705 if (argo_debug[D_CONN]) {
706 printf("tp_route_to calling nlp_pcbconn, netserv %d\n",
707 tpcb->tp_netservice);
708 }
709 #endif
710 tpcb->tp_nlproto = nl_protosw + tpcb->tp_netservice;
711 error = (*tpcb->tp_nlproto->nlp_pcbconn) (tpcb->tp_npcb, m, NULL);
712 }
713 if (error)
714 goto done;
715 /* only gets common info */
716 nhdr_size = (*tpcb->tp_nlproto->nlp_mtu)(tpcb);
717 tp_mss(tpcb, nhdr_size);
718 done:
719 #ifdef ARGO_DEBUG
720 if (argo_debug[D_CONN]) {
721 printf("tp_route_to returns 0x%x\n", error);
722 }
723 #endif
724 #ifdef TPPT
725 if (tp_traceflags[D_CONN]) {
726 tptraceTPCB(TPPTmisc, "route_to: returns: error netserv class", error,
727 tpcb->tp_netservice, tpcb->tp_class, 0);
728 }
729 #endif
730 return error;
731 }
732
733 /* class zero version */
734 void
735 tp0_stash(struct tp_pcb *tpcb, struct tp_event *e)
736 {
737 #define E e->TPDU_ATTR(DT)
738
739 struct sockbuf *sb = &tpcb->tp_sock->so_rcv;
740
741 #ifdef TP_PERF_MEAS
742 if (DOPERF(tpcb)) {
743 PStat(tpcb, Nb_from_ll) += E.e_datalen;
744 tpmeas(tpcb->tp_lref, TPtime_from_ll, &e->e_time,
745 E.e_seq, PStat(tpcb, Nb_from_ll), E.e_datalen);
746 }
747 #endif
748
749 #ifdef ARGO_DEBUG
750 if (argo_debug[D_STASH]) {
751 printf("stash EQ: seq 0x%x datalen 0x%x eot 0x%x",
752 E.e_seq, E.e_datalen, E.e_eot);
753 }
754 #endif
755
756 #ifdef TPPT
757 if (tp_traceflags[D_STASH]) {
758 tptraceTPCB(TPPTmisc, "stash EQ: seq len eot",
759 E.e_seq, E.e_datalen, E.e_eot, 0);
760 }
761 #endif
762
763 if (E.e_eot) {
764 struct mbuf *n = E.e_data;
765 n->m_flags |= M_EOR;
766 n->m_nextpkt = NULL; /* set on tp_input */
767 }
768 sbappend(sb, E.e_data);
769 #ifdef ARGO_DEBUG
770 if (argo_debug[D_STASH]) {
771 dump_mbuf(sb->sb_mb, "stash 0: so_rcv after appending");
772 }
773 #endif
774 if (tpcb->tp_netservice != ISO_CONS)
775 printf("tp0_stash: tp running over something weird\n");
776 }
777
778 void
779 tp0_openflow(struct tp_pcb *tpcb)
780 {
781 if (tpcb->tp_netservice != ISO_CONS)
782 printf("tp0_openflow: tp running over something weird\n");
783 }
784
785 #ifdef TP_PERF_MEAS
786 /*
787 * CALLED FROM:
788 * tp_ctloutput() when the user sets TPOPT_PERF_MEAS on
789 * and tp_newsocket() when a new connection is made from
790 * a listening socket with tp_perf_on == true.
791 * FUNCTION and ARGUMENTS:
792 * (tpcb) is the usual; this procedure gets a clear cluster mbuf for
793 * a tp_pmeas structure, and makes tpcb->tp_p_meas point to it.
794 * RETURN VALUE:
795 * ENOBUFS if it cannot get a cluster mbuf.
796 */
797
798 int
799 tp_setup_perf(struct tp_pcb *tpcb)
800 {
801 if (tpcb->tp_p_meas == 0) {
802 tpcb->tp_p_meas = malloc(sizeof(struct tp_pmeas), M_PCB, M_WAITOK|M_ZERO);
803 #ifdef ARGO_DEBUG
804 if (argo_debug[D_PERF_MEAS]) {
805 printf(
806 "tpcb 0x%x so 0x%x ref 0x%x tp_p_meas 0x%x tp_perf_on 0x%x\n",
807 tpcb, tpcb->tp_sock, tpcb->tp_lref,
808 tpcb->tp_p_meas, tpcb->tp_perf_on);
809 }
810 #endif
811 tpcb->tp_perf_on = 1;
812 }
813 return 0;
814 }
815 #endif /* TP_PERF_MEAS */
816
817 #ifdef ARGO_DEBUG
818 void
819 dump_addr(struct sockaddr *addr)
820 {
821 switch (addr->sa_family) {
822 #ifdef INET
823 case AF_INET:
824 dump_inaddr(satosin(addr));
825 break;
826 #endif
827 #ifdef ISO
828 case AF_ISO:
829 dump_isoaddr(satosiso(addr));
830 break;
831 #endif /* ISO */
832 default:
833 printf("BAD AF: 0x%x\n", addr->sa_family);
834 break;
835 }
836 }
837
838 #define MAX_COLUMNS 8
839 /*
840 * Dump the buffer to the screen in a readable format. Format is:
841 *
842 * hex/dec where hex is the hex format, dec is the decimal format.
843 * columns of hex/dec numbers will be printed, followed by the
844 * character representations (if printable).
845 */
846 void
847 Dump_buf(const void *buf, size_t len)
848 {
849 int i, j;
850 #define Buf ((const u_char *)buf)
851 printf("Dump buf %p len 0x%lx\n", buf, (unsigned long)len);
852 for (i = 0; i < len; i += MAX_COLUMNS) {
853 printf("+%d:\t", i);
854 for (j = 0; j < MAX_COLUMNS; j++) {
855 if (i + j < len) {
856 printf("%x/%d\t", Buf[i + j], Buf[i + j]);
857 } else {
858 printf(" ");
859 }
860 }
861
862 for (j = 0; j < MAX_COLUMNS; j++) {
863 if (i + j < len) {
864 if (((Buf[i + j]) > 31) && ((Buf[i + j]) < 128))
865 printf("%c", Buf[i + j]);
866 else
867 printf(".");
868 }
869 }
870 printf("\n");
871 }
872 }
873 #endif /* ARGO_DEBUG */
Cache object: ef0a5808fa37445859bec1cc0584ffa6
|