The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netiso/tp_subr2.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: tp_subr2.c,v 1.41 2009/04/18 14:58:06 tsutsui 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.41 2009/04/18 14:58:06 tsutsui 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         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;
  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         printf("tp_netcmd(): X25 NOT CONFIGURED!!\n");
  407 }
  408 
  409 /*
  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.
  414  */
  415 int
  416 tp_mask_to_num(u_char x)
  417 {
  418         int    j;
  419 
  420         for (j = 4; j >= 0; j--) {
  421                 if (x & (1 << j))
  422                         break;
  423         }
  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);
  428         }
  429 #ifdef TPPT
  430         if (tp_traceflags[D_TPINPUT]) {
  431                 tptrace(TPPTmisc, "tp_mask_to_num(x) returns j", x, j, 0, 0);
  432         }
  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);
  437         }
  438 #endif
  439         return j;
  440 }
  441 
  442 #if 0
  443 static void
  444 copyQOSparms(const struct tp_conn_param *src, struct tp_conn_params *dst)
  445 {
  446         /* copy all but the bits stuff at the end */
  447 #define COPYSIZE (12 * sizeof(short))
  448 
  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
  454 }
  455 #endif
  456 
  457 /*
  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.
  464  */
  465 void
  466 tp_mss(struct tp_pcb *tpcb, int nhdr_size)
  467 {
  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;
  474 
  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;
  483         }
  484         ifp = rt->rt_ifp;
  485 
  486 #ifdef RTV_MTU                  /* if route characteristics exist ... */
  487         /*
  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.
  492          */
  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;
  500         }
  501         /*
  502          * if there's an mtu associated with the route, use it
  503          */
  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;
  514         /*
  515          * If there's a pipesize, change the socket buffer
  516          * to that size.
  517          */
  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);
  523         }
  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
  532         /*
  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.
  537          */
  538         ssthresh = rt->rt_rmx.rmx_ssthresh;
  539 punt_route:
  540         /*
  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.
  547          */
  548         if (tpcb->tp_l_tpdusize)
  549                 mss = min(mss, tpcb->tp_l_tpdusize);
  550         /*
  551          * We want a minimum recv window of 4 packets to
  552          * signal packet loss by duplicate acks.
  553          */
  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 */
  568 }
  569 
  570 /*
  571  * CALLED FROM:
  572  *  tp_usrreq on PRU_CONNECT and tp_input on receipt of CR
  573  *
  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.
  578  *
  579  *
  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()
  585  *
  586  * SIDE EFFECTS:
  587  *   Determines recommended tpdusize, buffering and intial delays
  588  *       based on information cached on the route.
  589  */
  590 int
  591 tp_route_to(struct mbuf *m, struct tp_pcb *tpcb, void *channel)
  592 {
  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;
  598 
  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);
  606         }
  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);
  614         }
  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:
  623                         {
  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;
  632                                 }
  633                         } break;
  634 #endif
  635 #ifdef INET
  636                 case AF_INET:
  637                         tpcb->tp_netservice = IN_CLNS;
  638 #endif
  639                 }
  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);
  645                         }
  646 #endif
  647                         if ((error = tp_set_npcb(tpcb)) != 0)
  648                                 goto done;
  649                 }
  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);
  654                 }
  655 #endif
  656                 tpcb->tp_nlproto = nl_protosw + tpcb->tp_netservice;
  657                 error = (*tpcb->tp_nlproto->nlp_pcbconn) (tpcb->tp_npcb, m, NULL);
  658         }
  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);
  668         }
  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);
  674         }
  675 #endif
  676         return error;
  677 }
  678 
  679 /* class zero version */
  680 void
  681 tp0_stash(struct tp_pcb *tpcb, struct tp_event *e)
  682 {
  683 #define E e->TPDU_ATTR(DT)
  684 
  685         struct sockbuf *sb = &tpcb->tp_sock->so_rcv;
  686 
  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);
  692         }
  693 #endif
  694 
  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);
  699         }
  700 #endif
  701 
  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);
  706         }
  707 #endif
  708 
  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 */
  713         }
  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");
  718         }
  719 #endif
  720         if (tpcb->tp_netservice != ISO_CONS)
  721                 printf("tp0_stash: tp running over something weird\n");
  722 }
  723 
  724 void
  725 tp0_openflow(struct tp_pcb *tpcb)
  726 {
  727         if (tpcb->tp_netservice != ISO_CONS)
  728                 printf("tp0_openflow: tp running over something weird\n");
  729 }
  730 
  731 #ifdef TP_PERF_MEAS
  732 /*
  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.
  742  */
  743 
  744 int
  745 tp_setup_perf(struct tp_pcb *tpcb)
  746 {
  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);
  755                 }
  756 #endif
  757                 tpcb->tp_perf_on = 1;
  758         }
  759         return 0;
  760 }
  761 #endif                          /* TP_PERF_MEAS */
  762 
  763 #ifdef ARGO_DEBUG
  764 void
  765 dump_addr(struct sockaddr *addr)
  766 {
  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;
  781         }
  782 }
  783 
  784 #define MAX_COLUMNS     8
  785 /*
  786  *      Dump the buffer to the screen in a readable format. Format is:
  787  *
  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).
  791  */
  792 void
  793 Dump_buf(const void *buf, size_t len)
  794 {
  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("        ");
  805                         }
  806                 }
  807 
  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(".");
  814                         }
  815                 }
  816                 printf("\n");
  817         }
  818 }
  819 #endif /* ARGO_DEBUG */

Cache object: 91ef6142c8b5eb6846084ca99036be25


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.