📄 tp_pcb.c
字号:
/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)tp_pcb.c 8.1 (Berkeley) 6/10/93 *//*********************************************************** Copyright IBM Corporation 1987 All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the name of IBM not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLIBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************//* * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison *//* * ARGO TP * * $Header: tp_pcb.c,v 5.4 88/11/18 17:28:24 nhall Exp $ * $Source: /usr/argo/sys/netiso/RCS/tp_pcb.c,v $ * * * This is the initialization and cleanup stuff - * for the tp machine in general as well as for the individual pcbs. * tp_init() is called at system startup. tp_attach() and tp_getref() are * called when a socket is created. tp_detach() and tp_freeref() * are called during the closing stage and/or when the reference timer * goes off. * tp_soisdisconnecting() and tp_soisdisconnected() are tp-specific * versions of soisconnect* * and are called (obviously) during the closing phase. * */#include <sys/param.h>#include <sys/systm.h>#include <sys/mbuf.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <sys/domain.h>#include <sys/protosw.h>#include <sys/errno.h>#include <sys/time.h>#include <netiso/argo_debug.h>#include <netiso/tp_param.h>#include <netiso/tp_timer.h>#include <netiso/tp_ip.h>#include <netiso/tp_stat.h>#include <netiso/tp_pcb.h>#include <netiso/tp_tpdu.h>#include <netiso/tp_trace.h>#include <netiso/tp_meas.h>#include <netiso/tp_seq.h>#include <netiso/tp_clnp.h>/* ticks are in units of: * 500 nano-fortnights ;-) or * 500 ms or * 1/2 second */struct tp_conn_param tp_conn_param[] = { /* ISO_CLNS: TP4 CONNECTION LESS */ { TP_NRETRANS, /* short p_Nretrans; */ 20, /* 10 sec */ /* short p_dr_ticks; */ 20, /* 10 sec */ /* short p_cc_ticks; */ 20, /* 10 sec */ /* short p_dt_ticks; */ 40, /* 20 sec */ /* short p_x_ticks; */ 80, /* 40 sec */ /* short p_cr_ticks;*/ 240, /* 2 min */ /* short p_keepalive_ticks;*/ 10, /* 5 sec */ /* short p_sendack_ticks; */ 600, /* 5 min */ /* short p_ref_ticks; */ 360, /* 3 min */ /* short p_inact_ticks; */ (short) 100, /* short p_lcdtfract */ (short) TP_SOCKBUFSIZE, /* short p_winsize */ TP_TPDUSIZE, /* u_char p_tpdusize */ TPACK_WINDOW, /* 4 bits p_ack_strat */ TPRX_USE_CW | TPRX_FASTSTART, /* 4 bits p_rx_strat*/ TP_CLASS_4 | TP_CLASS_0,/* 5 bits p_class */ 1, /* 1 bit xtd format */ 1, /* 1 bit xpd service */ 1, /* 1 bit use_checksum */ 0, /* 1 bit use net xpd */ 0, /* 1 bit use rcc */ 0, /* 1 bit use efc */ 1, /* no disc indications */ 0, /* don't change params */ ISO_CLNS, /* p_netservice */ }, /* IN_CLNS: TP4 CONNECTION LESS */ { TP_NRETRANS, /* short p_Nretrans; */ 20, /* 10 sec */ /* short p_dr_ticks; */ 20, /* 10 sec */ /* short p_cc_ticks; */ 20, /* 10 sec */ /* short p_dt_ticks; */ 40, /* 20 sec */ /* short p_x_ticks; */ 80, /* 40 sec */ /* short p_cr_ticks;*/ 240, /* 2 min */ /* short p_keepalive_ticks;*/ 10, /* 5 sec */ /* short p_sendack_ticks; */ 600, /* 5 min */ /* short p_ref_ticks; */ 360, /* 3 min */ /* short p_inact_ticks; */ (short) 100, /* short p_lcdtfract */ (short) TP_SOCKBUFSIZE, /* short p_winsize */ TP_TPDUSIZE, /* u_char p_tpdusize */ TPACK_WINDOW, /* 4 bits p_ack_strat */ TPRX_USE_CW | TPRX_FASTSTART, /* 4 bits p_rx_strat*/ TP_CLASS_4, /* 5 bits p_class */ 1, /* 1 bit xtd format */ 1, /* 1 bit xpd service */ 1, /* 1 bit use_checksum */ 0, /* 1 bit use net xpd */ 0, /* 1 bit use rcc */ 0, /* 1 bit use efc */ 1, /* no disc indications */ 0, /* don't change params */ IN_CLNS, /* p_netservice */ }, /* ISO_CONS: TP0 CONNECTION MODE */ { TP_NRETRANS, /* short p_Nretrans; */ 0, /* n/a */ /* short p_dr_ticks; */ 40, /* 20 sec */ /* short p_cc_ticks; */ 0, /* n/a */ /* short p_dt_ticks; */ 0, /* n/a */ /* short p_x_ticks; */ 360, /* 3 min */ /* short p_cr_ticks;*/ 0, /* n/a */ /* short p_keepalive_ticks;*/ 0, /* n/a */ /* short p_sendack_ticks; */ 600, /* for cr/cc to clear *//* short p_ref_ticks; */ 0, /* n/a */ /* short p_inact_ticks; */ /* Use tp4 defaults just in case the user changes ONLY * the class */ (short) 100, /* short p_lcdtfract */ (short) TP0_SOCKBUFSIZE, /* short p_winsize */ TP0_TPDUSIZE, /* 8 bits p_tpdusize */ 0, /* 4 bits p_ack_strat */ 0, /* 4 bits p_rx_strat*/ TP_CLASS_0, /* 5 bits p_class */ 0, /* 1 bit xtd format */ 0, /* 1 bit xpd service */ 0, /* 1 bit use_checksum */ 0, /* 1 bit use net xpd */ 0, /* 1 bit use rcc */ 0, /* 1 bit use efc */ 0, /* no disc indications */ 0, /* don't change params */ ISO_CONS, /* p_netservice */ }, /* ISO_COSNS: TP4 CONNECTION LESS SERVICE over CONSNS */ { TP_NRETRANS, /* short p_Nretrans; */ 40, /* 20 sec */ /* short p_dr_ticks; */ 40, /* 20 sec */ /* short p_cc_ticks; */ 80, /* 40 sec */ /* short p_dt_ticks; */ 120, /* 1 min */ /* short p_x_ticks; */ 360, /* 3 min */ /* short p_cr_ticks;*/ 360, /* 3 min */ /* short p_keepalive_ticks;*/ 20, /* 10 sec */ /* short p_sendack_ticks; */ 600, /* 5 min */ /* short p_ref_ticks; */ 480, /* 4 min */ /* short p_inact_ticks; */ (short) 100, /* short p_lcdtfract */ (short) TP0_SOCKBUFSIZE, /* short p_winsize */ TP0_TPDUSIZE, /* u_char p_tpdusize */ TPACK_WINDOW, /* 4 bits p_ack_strat */ TPRX_USE_CW , /* No fast start */ /* 4 bits p_rx_strat*/ TP_CLASS_4 | TP_CLASS_0,/* 5 bits p_class */ 0, /* 1 bit xtd format */ 1, /* 1 bit xpd service */ 1, /* 1 bit use_checksum */ 0, /* 1 bit use net xpd */ 0, /* 1 bit use rcc */ 0, /* 1 bit use efc */ 0, /* no disc indications */ 0, /* don't change params */ ISO_COSNS, /* p_netservice */ },};#ifdef INETint in_putnetaddr();int in_getnetaddr();int in_cmpnetaddr();int in_putsufx(); int in_getsufx(); int in_recycle_tsuffix(); int tpip_mtu(); int in_pcbbind(); int in_pcbconnect(); int in_pcbdisconnect(); int in_pcbdetach(); int in_pcballoc(); int tpip_output(); int tpip_output_dg(); struct inpcb tp_inpcb;#endif /* INET */#ifdef ISOint iso_putnetaddr();int iso_getnetaddr();int iso_cmpnetaddr();int iso_putsufx(); int iso_getsufx(); int iso_recycle_tsuffix(); int tpclnp_mtu(); int iso_pcbbind(); int iso_pcbconnect(); int iso_pcbdisconnect(); int iso_pcbdetach(); int iso_pcballoc(); int tpclnp_output(); int tpclnp_output_dg(); int iso_nlctloutput();struct isopcb tp_isopcb;#endif /* ISO */#ifdef TPCONSint iso_putnetaddr();int iso_getnetaddr();int iso_cmpnetaddr();int iso_putsufx(); int iso_getsufx(); int iso_recycle_tsuffix(); int iso_pcbbind(); int tpcons_pcbconnect(); int tpclnp_mtu();int iso_pcbdisconnect(); int iso_pcbdetach(); int iso_pcballoc(); int tpcons_output(); struct isopcb tp_isopcb;#endif /* TPCONS */struct nl_protosw nl_protosw[] = { /* ISO_CLNS */#ifdef ISO { AF_ISO, iso_putnetaddr, iso_getnetaddr, iso_cmpnetaddr, iso_putsufx, iso_getsufx, iso_recycle_tsuffix, tpclnp_mtu, iso_pcbbind, iso_pcbconnect, iso_pcbdisconnect, iso_pcbdetach, iso_pcballoc, tpclnp_output, tpclnp_output_dg, iso_nlctloutput, (caddr_t) &tp_isopcb, },#else { 0 },#endif /* ISO */ /* IN_CLNS */#ifdef INET { AF_INET, in_putnetaddr, in_getnetaddr, in_cmpnetaddr, in_putsufx, in_getsufx, in_recycle_tsuffix, tpip_mtu, in_pcbbind, in_pcbconnect, in_pcbdisconnect, in_pcbdetach, in_pcballoc, tpip_output, tpip_output_dg, /* nl_ctloutput */ NULL, (caddr_t) &tp_inpcb, },#else { 0 },#endif /* INET */ /* ISO_CONS */#if defined(ISO) && defined(TPCONS) { AF_ISO, iso_putnetaddr, iso_getnetaddr, iso_cmpnetaddr, iso_putsufx, iso_getsufx, iso_recycle_tsuffix, tpclnp_mtu, iso_pcbbind, tpcons_pcbconnect, iso_pcbdisconnect, iso_pcbdetach, iso_pcballoc, tpcons_output, tpcons_output, iso_nlctloutput, (caddr_t) &tp_isopcb, },#else { 0 },#endif /* ISO_CONS */ /* End of protosw marker */ { 0 }};u_long tp_sendspace = 1024 * 4;u_long tp_recvspace = 1024 * 4;/* * NAME: tp_init() * * CALLED FROM: * autoconf through the protosw structure * * FUNCTION: * initialize tp machine * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: */inttp_init(){ static int init_done=0; void tp_timerinit(); if (init_done++) return 0; /* FOR INET */ tp_inpcb.inp_next = tp_inpcb.inp_prev = &tp_inpcb; /* FOR ISO */ tp_isopcb.isop_next = tp_isopcb.isop_prev = &tp_isopcb; tp_start_win = 2; tp_timerinit(); bzero((caddr_t)&tp_stat, sizeof(struct tp_stat)); return 0;}/* * NAME: tp_soisdisconnecting() * * CALLED FROM: * tp.trans * * FUNCTION and ARGUMENTS: * Set state of the socket (so) to reflect that fact that we're disconnectING * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: * This differs from the regular soisdisconnecting() in that the latter * also sets the SS_CANTRECVMORE and SS_CANTSENDMORE flags. * We don't want to set those flags because those flags will cause * a SIGPIPE to be delivered in sosend() and we don't like that. * If anyone else is sleeping on this socket, wake 'em up. */voidtp_soisdisconnecting(so) register struct socket *so;{ soisdisconnecting(so); so->so_state &= ~SS_CANTSENDMORE; IFPERF(sototpcb(so)) register struct tp_pcb *tpcb = sototpcb(so); u_int fsufx, lsufx; bcopy ((caddr_t)tpcb->tp_fsuffix, (caddr_t)&fsufx, sizeof(u_int) ); bcopy ((caddr_t)tpcb->tp_lsuffix, (caddr_t)&lsufx, sizeof(u_int) ); tpmeas(tpcb->tp_lref, TPtime_close, &time, fsufx, lsufx, tpcb->tp_fref); tpcb->tp_perf_on = 0; /* turn perf off */ ENDPERF}/* * NAME: tp_soisdisconnected() * * CALLED FROM: * tp.trans * * FUNCTION and ARGUMENTS: * Set state of the socket (so) to reflect that fact that we're disconnectED * Set the state of the reference structure to closed, and * recycle the suffix. * Start a reference timer. * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: * This differs from the regular soisdisconnected() in that the latter * also sets the SS_CANTRECVMORE and SS_CANTSENDMORE flags. * We don't want to set those flags because those flags will cause * a SIGPIPE to be delivered in sosend() and we don't like that. * If anyone else is sleeping on this socket, wake 'em up. */voidtp_soisdisconnected(tpcb) register struct tp_pcb *tpcb;{ register struct socket *so = tpcb->tp_sock; soisdisconnecting(so); so->so_state &= ~SS_CANTSENDMORE; IFPERF(tpcb) register struct tp_pcb *ttpcb = sototpcb(so); u_int fsufx, lsufx; /* CHOKE */ bcopy ((caddr_t)ttpcb->tp_fsuffix, (caddr_t)&fsufx, sizeof(u_int) ); bcopy ((caddr_t)ttpcb->tp_lsuffix, (caddr_t)&lsufx, sizeof(u_int) ); tpmeas(ttpcb->tp_lref, TPtime_close, &time, &lsufx, &fsufx, ttpcb->tp_fref); tpcb->tp_perf_on = 0; /* turn perf off */ ENDPERF tpcb->tp_refstate = REF_FROZEN; tp_recycle_tsuffix(tpcb); tp_etimeout(tpcb, TM_reference, (int)tpcb->tp_refer_ticks);}/* * NAME: tp_freeref() * * CALLED FROM: * tp.trans when the reference timer goes off, and * from tp_attach() and tp_detach() when a tpcb is partially set up but not * set up enough to have a ref timer set for it, and it's discarded * due to some sort of error or an early close() * * FUNCTION and ARGUMENTS: * Frees the reference represented by (r) for re-use. * * RETURNS: Nothing * * SIDE EFFECTS: * * NOTES: better be called at clock priority !!!!! */void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -