1996-03-17 02:13:45 +03:00
|
|
|
/* $NetBSD: tp_pcb.c,v 1.13 1996/03/16 23:13:58 christos Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*-
|
1994-05-13 10:08:03 +04:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1994-06-29 10:39:25 +04:00
|
|
|
* @(#)tp_pcb.c 8.1 (Berkeley) 6/10/93
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
Copyright IBM Corporation 1987
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
1993-04-09 16:00:07 +04:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
1996-02-14 01:07:57 +03:00
|
|
|
both that copyright notice and this permission notice appear in
|
1993-04-09 16:00:07 +04:00
|
|
|
supporting documentation, and that the name of IBM not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
1996-02-14 01:07:57 +03:00
|
|
|
software without specific, written prior permission.
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY 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 THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
1994-05-13 10:08:03 +04:00
|
|
|
#include <sys/systm.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1994-05-13 10:08:03 +04:00
|
|
|
#include <sys/domain.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#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>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <netiso/tp_var.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* ticks are in units of: 500 nano-fortnights ;-) or 500 ms or 1/2 second
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct tp_conn_param tp_conn_param[] = {
|
|
|
|
/* ISO_CLNS: TP4 CONNECTION LESS */
|
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
TP_NRETRANS, /* short p_Nretrans; */
|
|
|
|
20, /* 10 sec *//* short p_dr_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
20, /* 10 sec *//* short p_cc_ticks; */
|
|
|
|
20, /* 10 sec *//* short p_dt_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
40, /* 20 sec *//* short p_x_ticks; */
|
|
|
|
80, /* 40 sec *//* short p_cr_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
240, /* 2 min *//* short p_keepalive_ticks; */
|
|
|
|
10, /* 5 sec *//* short p_sendack_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
600, /* 5 min *//* short p_ref_ticks; */
|
|
|
|
360, /* 3 min *//* short p_inact_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
(short) 100, /* short p_lcdtfract */
|
1993-04-09 16:00:07 +04:00
|
|
|
(short) TP_SOCKBUFSIZE, /* short p_winsize */
|
1996-02-14 01:07:57 +03:00
|
|
|
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 */
|
1993-04-09 16:00:07 +04:00
|
|
|
},
|
|
|
|
/* IN_CLNS: TP4 CONNECTION LESS */
|
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
TP_NRETRANS, /* short p_Nretrans; */
|
|
|
|
20, /* 10 sec *//* short p_dr_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
20, /* 10 sec *//* short p_cc_ticks; */
|
|
|
|
20, /* 10 sec *//* short p_dt_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
40, /* 20 sec *//* short p_x_ticks; */
|
|
|
|
80, /* 40 sec *//* short p_cr_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
240, /* 2 min *//* short p_keepalive_ticks; */
|
|
|
|
10, /* 5 sec *//* short p_sendack_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
600, /* 5 min *//* short p_ref_ticks; */
|
|
|
|
360, /* 3 min *//* short p_inact_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
(short) 100, /* short p_lcdtfract */
|
1993-04-09 16:00:07 +04:00
|
|
|
(short) TP_SOCKBUFSIZE, /* short p_winsize */
|
1996-02-14 01:07:57 +03:00
|
|
|
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 */
|
1993-04-09 16:00:07 +04:00
|
|
|
},
|
|
|
|
/* ISO_CONS: TP0 CONNECTION MODE */
|
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
TP_NRETRANS, /* short p_Nretrans; */
|
|
|
|
0, /* n/a *//* short p_dr_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
40, /* 20 sec *//* short p_cc_ticks; */
|
|
|
|
0, /* n/a *//* short p_dt_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
0, /* n/a *//* short p_x_ticks; */
|
|
|
|
360, /* 3 min *//* short p_cr_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
0, /* n/a *//* short p_keepalive_ticks; */
|
|
|
|
0, /* n/a *//* short p_sendack_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
600, /* for cr/cc to clear *//* short p_ref_ticks; */
|
|
|
|
0, /* n/a *//* short p_inact_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Use tp4 defaults just in case the user changes ONLY the
|
|
|
|
* class
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
(short) 100, /* short p_lcdtfract */
|
1993-04-09 16:00:07 +04:00
|
|
|
(short) TP0_SOCKBUFSIZE, /* short p_winsize */
|
1996-02-14 01:07:57 +03:00
|
|
|
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 */
|
1993-04-09 16:00:07 +04:00
|
|
|
},
|
|
|
|
/* ISO_COSNS: TP4 CONNECTION LESS SERVICE over CONSNS */
|
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
TP_NRETRANS, /* short p_Nretrans; */
|
|
|
|
40, /* 20 sec *//* short p_dr_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
40, /* 20 sec *//* short p_cc_ticks; */
|
|
|
|
80, /* 40 sec *//* short p_dt_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
120, /* 1 min *//* short p_x_ticks; */
|
|
|
|
360, /* 3 min *//* short p_cr_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
360, /* 3 min *//* short p_keepalive_ticks; */
|
|
|
|
20, /* 10 sec *//* short p_sendack_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
600, /* 5 min *//* short p_ref_ticks; */
|
|
|
|
480, /* 4 min *//* short p_inact_ticks; */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
(short) 100, /* short p_lcdtfract */
|
1993-04-09 16:00:07 +04:00
|
|
|
(short) TP0_SOCKBUFSIZE, /* short p_winsize */
|
1996-02-14 01:07:57 +03:00
|
|
|
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 */
|
1993-04-09 16:00:07 +04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef INET
|
1996-02-14 01:07:57 +03:00
|
|
|
struct inpcbtable tp_inpcb;
|
|
|
|
#endif /* INET */
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef ISO
|
1996-02-14 01:07:57 +03:00
|
|
|
struct isopcb tp_isopcb;
|
|
|
|
#endif /* ISO */
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef TPCONS
|
1996-02-14 01:07:57 +03:00
|
|
|
struct isopcb tp_isopcb;
|
|
|
|
#endif /* TPCONS */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
struct nl_protosw nl_protosw[] = {
|
|
|
|
/* ISO_CLNS */
|
|
|
|
#ifdef ISO
|
1996-02-14 01:07:57 +03:00
|
|
|
{AF_ISO, iso_putnetaddr, iso_getnetaddr, iso_cmpnetaddr,
|
1993-04-09 16:00:07 +04:00
|
|
|
iso_putsufx, iso_getsufx,
|
|
|
|
iso_recycle_tsuffix,
|
|
|
|
tpclnp_mtu, iso_pcbbind, iso_pcbconnect,
|
1996-02-14 01:07:57 +03:00
|
|
|
iso_pcbdisconnect, iso_pcbdetach,
|
1993-04-09 16:00:07 +04:00
|
|
|
iso_pcballoc,
|
|
|
|
tpclnp_output, tpclnp_output_dg, iso_nlctloutput,
|
1996-02-14 01:07:57 +03:00
|
|
|
(caddr_t) & tp_isopcb,
|
|
|
|
},
|
1993-04-09 16:00:07 +04:00
|
|
|
#else
|
1996-02-14 01:07:57 +03:00
|
|
|
{0},
|
|
|
|
#endif /* ISO */
|
1993-04-09 16:00:07 +04:00
|
|
|
/* IN_CLNS */
|
|
|
|
#ifdef INET
|
1996-02-14 01:07:57 +03:00
|
|
|
{AF_INET, in_putnetaddr, in_getnetaddr, in_cmpnetaddr,
|
1993-04-09 16:00:07 +04:00
|
|
|
in_putsufx, in_getsufx,
|
|
|
|
in_recycle_tsuffix,
|
|
|
|
tpip_mtu, in_pcbbind, in_pcbconnect,
|
1996-02-14 01:07:57 +03:00
|
|
|
in_pcbdisconnect, in_pcbdetach,
|
1993-04-09 16:00:07 +04:00
|
|
|
in_pcballoc,
|
|
|
|
tpip_output, tpip_output_dg, /* nl_ctloutput */ NULL,
|
1996-02-14 01:07:57 +03:00
|
|
|
(caddr_t) & tp_inpcb,
|
|
|
|
},
|
1993-04-09 16:00:07 +04:00
|
|
|
#else
|
1996-02-14 01:07:57 +03:00
|
|
|
{0},
|
|
|
|
#endif /* INET */
|
1993-04-09 16:00:07 +04:00
|
|
|
/* ISO_CONS */
|
|
|
|
#if defined(ISO) && defined(TPCONS)
|
1996-02-14 01:07:57 +03:00
|
|
|
{AF_ISO, iso_putnetaddr, iso_getnetaddr, iso_cmpnetaddr,
|
1993-04-09 16:00:07 +04:00
|
|
|
iso_putsufx, iso_getsufx,
|
|
|
|
iso_recycle_tsuffix,
|
|
|
|
tpclnp_mtu, iso_pcbbind, tpcons_pcbconnect,
|
1996-02-14 01:07:57 +03:00
|
|
|
iso_pcbdisconnect, iso_pcbdetach,
|
1993-04-09 16:00:07 +04:00
|
|
|
iso_pcballoc,
|
|
|
|
tpcons_output, tpcons_output, iso_nlctloutput,
|
1996-02-14 01:07:57 +03:00
|
|
|
(caddr_t) & tp_isopcb,
|
|
|
|
},
|
1993-04-09 16:00:07 +04:00
|
|
|
#else
|
1996-02-14 01:07:57 +03:00
|
|
|
{0},
|
|
|
|
#endif /* ISO_CONS */
|
1993-04-09 16:00:07 +04:00
|
|
|
/* End of protosw marker */
|
1996-02-14 01:07:57 +03:00
|
|
|
{0}
|
1993-04-09 16:00:07 +04:00
|
|
|
};
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
u_long tp_sendspace = 1024 * 4;
|
|
|
|
u_long tp_recvspace = 1024 * 4;
|
1994-05-13 10:08:03 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* NAME: tp_init()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* autoconf through the protosw structure
|
|
|
|
*
|
|
|
|
* FUNCTION:
|
|
|
|
* initialize tp machine
|
|
|
|
*
|
|
|
|
* RETURNS: Nada
|
|
|
|
*
|
|
|
|
* SIDE EFFECTS:
|
1996-02-14 01:07:57 +03:00
|
|
|
*
|
1993-04-09 16:00:07 +04:00
|
|
|
* NOTES:
|
|
|
|
*/
|
1994-05-13 10:08:03 +04:00
|
|
|
void
|
1993-04-09 16:00:07 +04:00
|
|
|
tp_init()
|
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
static int init_done = 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (init_done++)
|
1994-05-13 10:08:03 +04:00
|
|
|
return;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* FOR INET */
|
1996-02-03 00:47:37 +03:00
|
|
|
in_pcbinit(&tp_inpcb, 1);
|
1993-04-09 16:00:07 +04:00
|
|
|
/* FOR ISO */
|
|
|
|
tp_isopcb.isop_next = tp_isopcb.isop_prev = &tp_isopcb;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
tp_start_win = 2;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
tp_timerinit();
|
1996-02-14 01:07:57 +03:00
|
|
|
bzero((caddr_t) & tp_stat, sizeof(struct tp_stat));
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
tp_soisdisconnecting(so)
|
|
|
|
register struct socket *so;
|
|
|
|
{
|
|
|
|
soisdisconnecting(so);
|
|
|
|
so->so_state &= ~SS_CANTSENDMORE;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef TP_PERF_MEAS
|
|
|
|
if (DOPERF(sototpcb(so))) {
|
1993-04-09 16:00:07 +04:00
|
|
|
register struct tp_pcb *tpcb = sototpcb(so);
|
1996-02-14 01:07:57 +03:00
|
|
|
u_int fsufx, lsufx;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) tpcb->tp_fsuffix, (caddr_t) &fsufx,
|
|
|
|
sizeof(u_int));
|
|
|
|
bcopy((caddr_t) tpcb->tp_lsuffix, (caddr_t) &lsufx,
|
|
|
|
sizeof(u_int));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
tpmeas(tpcb->tp_lref, TPtime_close, &time, fsufx, lsufx,
|
|
|
|
tpcb->tp_fref);
|
|
|
|
tpcb->tp_perf_on = 0; /* turn perf off */
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tp_soisdisconnected()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
1996-02-14 01:07:57 +03:00
|
|
|
* tp.trans
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
tp_soisdisconnected(tpcb)
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct tp_pcb *tpcb;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct socket *so = tpcb->tp_sock;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
soisdisconnecting(so);
|
|
|
|
so->so_state &= ~SS_CANTSENDMORE;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef TP_PERF_MEAS
|
|
|
|
if (DOPERF(tpcb)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
register struct tp_pcb *ttpcb = sototpcb(so);
|
1996-02-14 01:07:57 +03:00
|
|
|
u_int fsufx, lsufx;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* CHOKE */
|
1996-02-14 01:07:57 +03:00
|
|
|
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 */
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_refstate = REF_FROZEN;
|
|
|
|
tp_recycle_tsuffix(tpcb);
|
1996-02-14 01:07:57 +03:00
|
|
|
tp_etimeout(tpcb, TM_reference, (int) tpcb->tp_refer_ticks);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
1996-02-14 01:07:57 +03:00
|
|
|
*
|
1993-04-09 16:00:07 +04:00
|
|
|
* SIDE EFFECTS:
|
|
|
|
*
|
|
|
|
* NOTES: better be called at clock priority !!!!!
|
|
|
|
*/
|
|
|
|
void
|
1994-05-13 10:08:03 +04:00
|
|
|
tp_freeref(n)
|
1996-02-14 01:07:57 +03:00
|
|
|
RefNum n;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1994-05-13 10:08:03 +04:00
|
|
|
register struct tp_ref *r = tp_ref + n;
|
|
|
|
register struct tp_pcb *tpcb;
|
|
|
|
|
|
|
|
tpcb = r->tpr_pcb;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_TIMER]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("tp_freeref called for ref %d pcb %p maxrefopen %d\n",
|
1996-02-14 01:07:57 +03:00
|
|
|
n, tpcb, tp_refinfo.tpr_maxopen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef TPPT
|
|
|
|
if (tp_traceflags[D_TIMER]) {
|
1994-05-13 10:08:03 +04:00
|
|
|
tptrace(TPPTmisc, "tp_freeref ref maxrefopen pcb",
|
1996-02-14 01:07:57 +03:00
|
|
|
n, tp_refinfo.tpr_maxopen, tpcb, 0);
|
|
|
|
}
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
if (tpcb == 0)
|
|
|
|
return;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("tp_freeref: CLEARING tpr_pcb %p\n", tpcb);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
r->tpr_pcb = (struct tp_pcb *) 0;
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_refstate = REF_FREE;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
for (r = tp_ref + tp_refinfo.tpr_maxopen; r > tp_ref; r--)
|
|
|
|
if (r->tpr_pcb)
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
1994-05-13 10:08:03 +04:00
|
|
|
tp_refinfo.tpr_maxopen = r - tp_ref;
|
|
|
|
tp_refinfo.tpr_numopen--;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_TIMER]) {
|
1994-05-13 10:08:03 +04:00
|
|
|
printf("tp_freeref ends w/ maxrefopen %d\n", tp_refinfo.tpr_maxopen);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tp_getref()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp_attach()
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* obtains the next free reference and allocates the appropriate
|
1996-02-14 01:07:57 +03:00
|
|
|
* ref structure, links that structure to (tpcb)
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* RETURN VALUE:
|
|
|
|
* a reference number
|
|
|
|
* or TP_ENOREF
|
|
|
|
*
|
|
|
|
* SIDE EFFECTS:
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
*/
|
1994-05-13 10:08:03 +04:00
|
|
|
u_long
|
1996-02-14 01:07:57 +03:00
|
|
|
tp_getref(tpcb)
|
1993-04-09 16:00:07 +04:00
|
|
|
register struct tp_pcb *tpcb;
|
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct tp_ref *r, *rlim;
|
|
|
|
register int i;
|
|
|
|
caddr_t obase;
|
|
|
|
unsigned size;
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
if (++tp_refinfo.tpr_numopen < tp_refinfo.tpr_size)
|
|
|
|
for (r = tp_refinfo.tpr_base, rlim = r + tp_refinfo.tpr_size;
|
1996-02-14 01:07:57 +03:00
|
|
|
++r < rlim;) /* tp_ref[0] is never used */
|
1994-05-13 10:08:03 +04:00
|
|
|
if (r->tpr_pcb == 0)
|
|
|
|
goto got_one;
|
|
|
|
/* else have to allocate more space */
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
obase = (caddr_t) tp_refinfo.tpr_base;
|
1994-05-13 10:08:03 +04:00
|
|
|
size = tp_refinfo.tpr_size * sizeof(struct tp_ref);
|
|
|
|
r = (struct tp_ref *) malloc(size + size, M_PCB, M_NOWAIT);
|
|
|
|
if (r == 0)
|
|
|
|
return (--tp_refinfo.tpr_numopen, TP_ENOREF);
|
|
|
|
tp_refinfo.tpr_base = tp_ref = r;
|
|
|
|
tp_refinfo.tpr_size *= 2;
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy(obase, (caddr_t) r, size);
|
1994-05-13 10:08:03 +04:00
|
|
|
free(obase, M_PCB);
|
1996-02-14 01:07:57 +03:00
|
|
|
r = (struct tp_ref *) (size + (caddr_t) r);
|
|
|
|
bzero((caddr_t) r, size);
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
got_one:
|
1993-04-09 16:00:07 +04:00
|
|
|
r->tpr_pcb = tpcb;
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_refstate = REF_OPENING;
|
|
|
|
i = r - tp_refinfo.tpr_base;
|
1996-02-14 01:07:57 +03:00
|
|
|
if (tp_refinfo.tpr_maxopen < i)
|
1994-05-13 10:08:03 +04:00
|
|
|
tp_refinfo.tpr_maxopen = i;
|
1996-02-14 01:07:57 +03:00
|
|
|
return (u_long) i;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
/*
|
|
|
|
* NAME: tp_set_npcb()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp_attach(), tp_route_to()
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* given a tpcb, allocate an appropriate lower-lever npcb, freeing
|
|
|
|
* any old ones that might need re-assigning.
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
1994-05-13 10:08:03 +04:00
|
|
|
tp_set_npcb(tpcb)
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct tp_pcb *tpcb;
|
1994-05-13 10:08:03 +04:00
|
|
|
{
|
|
|
|
register struct socket *so = tpcb->tp_sock;
|
1996-02-14 01:07:57 +03:00
|
|
|
int error;
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
if (tpcb->tp_nlproto && tpcb->tp_npcb) {
|
1996-02-14 01:07:57 +03:00
|
|
|
short so_state = so->so_state;
|
1994-05-13 10:08:03 +04:00
|
|
|
so->so_state &= ~SS_NOFDREF;
|
1996-02-14 01:07:57 +03:00
|
|
|
(*tpcb->tp_nlproto->nlp_pcbdetach)(tpcb->tp_npcb);
|
1994-05-13 10:08:03 +04:00
|
|
|
so->so_state = so_state;
|
|
|
|
}
|
|
|
|
tpcb->tp_nlproto = &nl_protosw[tpcb->tp_netservice];
|
|
|
|
/* xx_pcballoc sets so_pcb */
|
1996-02-14 01:07:57 +03:00
|
|
|
error = (*tpcb->tp_nlproto->nlp_pcballoc)(so,
|
|
|
|
tpcb->tp_nlproto->nlp_pcblist);
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_npcb = so->so_pcb;
|
1995-08-17 06:57:20 +04:00
|
|
|
so->so_pcb = tpcb;
|
1994-05-13 10:08:03 +04:00
|
|
|
return (error);
|
|
|
|
}
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* NAME: tp_attach()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp_usrreq, PRU_ATTACH
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* given a socket (so) and a protocol family (dom), allocate a tpcb
|
|
|
|
* and ref structure, initialize everything in the structures that
|
|
|
|
* needs to be initialized.
|
|
|
|
*
|
|
|
|
* RETURN VALUE:
|
|
|
|
* 0 ok
|
|
|
|
* EINVAL if DEBUG(X) in is on and a disaster has occurred
|
|
|
|
* ENOPROTOOPT if TP hasn't been configured or if the
|
|
|
|
* socket wasn't created with tp as its protocol
|
|
|
|
* EISCONN if this socket is already part of a connection
|
|
|
|
* ETOOMANYREFS if ran out of tp reference numbers.
|
|
|
|
* E* whatever error is returned from soreserve()
|
|
|
|
* for from the network-layer pcb allocation routine
|
|
|
|
*
|
|
|
|
* SIDE EFFECTS:
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
1994-05-13 10:08:03 +04:00
|
|
|
tp_attach(so, protocol)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct socket *so;
|
|
|
|
long protocol;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct tp_pcb *tpcb;
|
|
|
|
int error = 0;
|
|
|
|
int dom = so->so_proto->pr_domain->dom_family;
|
|
|
|
u_long lref;
|
1993-04-09 16:00:07 +04:00
|
|
|
extern struct tp_conn_param tp_conn_param[];
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("tp_attach:dom 0x%x so %p ", dom, so);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef TPPT
|
|
|
|
if (tp_traceflags[D_CONN]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
tptrace(TPPTmisc, "tp_attach:dom so", dom, so, 0, 0);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if (so->so_pcb != NULL) {
|
|
|
|
return EISCONN; /* socket already part of a connection */
|
|
|
|
}
|
1994-05-13 10:08:03 +04:00
|
|
|
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0)
|
|
|
|
error = soreserve(so, tp_sendspace, tp_recvspace);
|
1996-02-14 01:07:57 +03:00
|
|
|
/* later an ioctl will allow reallocation IF still in closed state */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
goto bad2;
|
|
|
|
|
|
|
|
MALLOC(tpcb, struct tp_pcb *, sizeof(*tpcb), M_PCB, M_NOWAIT);
|
|
|
|
if (tpcb == NULL) {
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad2;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
bzero((caddr_t) tpcb, sizeof(struct tp_pcb));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if (((lref = tp_getref(tpcb)) & TP_ENOREF) != 0) {
|
|
|
|
error = ETOOMANYREFS;
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad3;
|
|
|
|
}
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_lref = lref;
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_sock = so;
|
1993-04-09 16:00:07 +04:00
|
|
|
tpcb->tp_domain = dom;
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_rhiwat = so->so_rcv.sb_hiwat;
|
|
|
|
/* tpcb->tp_proto = protocol; someday maybe? */
|
1996-02-14 01:07:57 +03:00
|
|
|
if (protocol && protocol < ISOPROTO_TP4) {
|
1993-04-09 16:00:07 +04:00
|
|
|
tpcb->tp_netservice = ISO_CONS;
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_snduna = (SeqNum) - 1; /* kludge so the pseudo-ack
|
|
|
|
* from the CR/CC will
|
|
|
|
* generate correct fake-ack
|
|
|
|
* values */
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_netservice = (dom == AF_INET) ? IN_CLNS : ISO_CLNS;
|
1993-04-09 16:00:07 +04:00
|
|
|
/* the default */
|
|
|
|
}
|
|
|
|
tpcb->_tp_param = tp_conn_param[tpcb->tp_netservice];
|
|
|
|
|
|
|
|
tpcb->tp_state = TP_CLOSED;
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_vers = TP_VERSION;
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_notdetached = 1;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Spec says default is 128 octets, that is, if the tpdusize argument
|
|
|
|
* never appears, use 128. As the initiator, we will always "propose"
|
|
|
|
* the 2048 size, that is, we will put this argument in the CR
|
|
|
|
* always, but accept what the other side sends on the CC. If the
|
|
|
|
* initiator sends us something larger on a CR, we'll respond w/
|
|
|
|
* this. Our maximum is 4096. See tp_chksum.c comments.
|
|
|
|
*/
|
|
|
|
tpcb->tp_cong_win =
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_l_tpdusize = 1 << tpcb->tp_tpdusize;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_seqmask = TP_NML_FMT_MASK;
|
|
|
|
tpcb->tp_seqbit = TP_NML_FMT_BIT;
|
|
|
|
tpcb->tp_seqhalf = tpcb->tp_seqbit >> 1;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* attach to a network-layer protoswitch */
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((error = tp_set_npcb(tpcb)) != 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad4;
|
1996-02-14 01:07:57 +03:00
|
|
|
ASSERT(tpcb->tp_nlproto->nlp_afamily == tpcb->tp_domain);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
/* nothing to do for iso case */
|
1996-02-14 01:07:57 +03:00
|
|
|
if (dom == AF_INET)
|
1993-04-09 16:00:07 +04:00
|
|
|
sotoinpcb(so)->inp_ppcb = (caddr_t) tpcb;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad4:
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("BAD4 in tp_attach, so %p\n", so);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
tp_freeref(tpcb->tp_lref);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
bad3:
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("BAD3 in tp_attach, so %p\n", so);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
free((caddr_t) tpcb, M_PCB); /* never a cluster */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
bad2:
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("BAD2 in tp_attach, so %p\n", so);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
so->so_pcb = 0;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/* bad: */
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("BAD in tp_attach, so %p\n", so);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tp_detach()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp.trans, on behalf of a user close request
|
|
|
|
* and when the reference timer goes off
|
1996-02-14 01:07:57 +03:00
|
|
|
* (if the disconnect was initiated by the protocol entity
|
1993-04-09 16:00:07 +04:00
|
|
|
* rather than by the user)
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* remove the tpcb structure from the list of active or
|
|
|
|
* partially active connections, recycle all the mbufs
|
|
|
|
* associated with the pcb, ref structure, sockbufs, etc.
|
|
|
|
* Only free the ref structure if you know that a ref timer
|
|
|
|
* wasn't set for this tpcb.
|
|
|
|
*
|
|
|
|
* RETURNS: Nada
|
|
|
|
*
|
|
|
|
* SIDE EFFECTS:
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* tp_soisdisconnected() was already when this is called
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
tp_detach(tpcb)
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct tp_pcb *tpcb;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct socket *so = tpcb->tp_sock;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("tp_detach(tpcb %p, so %p)\n",
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb, so);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef TPPT
|
|
|
|
if (tp_traceflags[D_CONN]) {
|
|
|
|
tptraceTPCB(TPPTmisc, "tp_detach tpcb so lsufx",
|
|
|
|
tpcb, so, *(u_short *) (tpcb->tp_lsuffix), 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("so_snd at %p so_rcv at %p\n", &so->so_snd, &so->so_rcv);
|
1993-04-09 16:00:07 +04:00
|
|
|
dump_mbuf(so->so_snd.sb_mb, "so_snd at detach ");
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("about to call LL detach, nlproto %p, nl_detach %p\n",
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_nlproto, tpcb->tp_nlproto->nlp_pcbdetach);
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
if (tpcb->tp_Xsnd.sb_mb) {
|
|
|
|
printf("Unsent Xdata on detach; would panic");
|
|
|
|
sbflush(&tpcb->tp_Xsnd);
|
|
|
|
}
|
1993-04-09 16:00:07 +04:00
|
|
|
if (tpcb->tp_ucddata)
|
|
|
|
m_freem(tpcb->tp_ucddata);
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("reassembly info cnt %d rsyq %p\n",
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_rsycnt, tpcb->tp_rsyq);
|
|
|
|
}
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
if (tpcb->tp_rsyq)
|
|
|
|
tp_rsyflush(tpcb);
|
|
|
|
|
|
|
|
if (tpcb->tp_next) {
|
|
|
|
remque(tpcb);
|
|
|
|
tpcb->tp_next = tpcb->tp_prev = 0;
|
|
|
|
}
|
|
|
|
tpcb->tp_notdetached = 0;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("calling (...nlproto->...)(%p, so %p)\n",
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_npcb, so);
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("so %p so_head %p, qlen %d q0len %d qlimit %d\n",
|
1996-02-14 01:07:57 +03:00
|
|
|
so, so->so_head,
|
|
|
|
so->so_q0len, so->so_qlen, so->so_qlimit);
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
(*tpcb->tp_nlproto->nlp_pcbdetach)(tpcb->tp_npcb);
|
|
|
|
/* does an so->so_pcb = 0; sofree(so) */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("after xxx_pcbdetach\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
if (tpcb->tp_state == TP_LISTENING) {
|
|
|
|
register struct tp_pcb **tt;
|
|
|
|
for (tt = &tp_listeners; *tt; tt = &((*tt)->tp_nextlisten))
|
|
|
|
if (*tt == tpcb)
|
|
|
|
break;
|
|
|
|
if (*tt)
|
|
|
|
*tt = tpcb->tp_nextlisten;
|
|
|
|
else
|
|
|
|
printf("tp_detach from listen: should panic\n");
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
if (tpcb->tp_refstate == REF_OPENING) {
|
|
|
|
/*
|
|
|
|
* no connection existed here so no reference timer will be
|
|
|
|
* called
|
|
|
|
*/
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1994-05-13 10:08:03 +04:00
|
|
|
printf("SETTING ref %d to REF_FREE\n", tpcb->tp_lref);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
tp_freeref(tpcb->tp_lref);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1994-05-13 10:08:03 +04:00
|
|
|
#ifdef TP_PERF_MEAS
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Get rid of the cluster mbuf allocated for performance
|
|
|
|
* measurements, if there is one. Note that tpcb->tp_perf_on says
|
|
|
|
* nothing about whether or not a cluster mbuf was allocated, so you
|
|
|
|
* have to check for a pointer to one (that is, we need the
|
|
|
|
* TP_PERF_MEASs around the following section of code, not the
|
|
|
|
* IFPERFs)
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1995-08-16 04:38:53 +04:00
|
|
|
if (tpcb->tp_p_meas) {
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct mbuf *m = tpcb->tp_p_mbuf;
|
|
|
|
struct mbuf *n;
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_PERF_MEAS]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("freeing tp_p_meas 0x%x ", tpcb->tp_p_meas);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1995-08-16 04:38:53 +04:00
|
|
|
free(tpcb->tp_p_meas, M_PCB);
|
1993-04-09 16:00:07 +04:00
|
|
|
tpcb->tp_p_meas = 0;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* TP_PERF_MEAS */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1996-03-17 02:13:45 +03:00
|
|
|
printf("end of detach, NOT single, tpcb %p\n", tpcb);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
/* free((caddr_t)tpcb, M_PCB); WHere to put this ? */
|
|
|
|
}
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
struct que {
|
1996-02-14 01:07:57 +03:00
|
|
|
struct tp_pcb *next;
|
|
|
|
struct tp_pcb *prev;
|
|
|
|
} tp_bound_pcbs =
|
|
|
|
{
|
|
|
|
(struct tp_pcb *) & tp_bound_pcbs, (struct tp_pcb *) & tp_bound_pcbs
|
|
|
|
};
|
1994-05-13 10:08:03 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
u_short tp_unique;
|
1994-05-13 10:08:03 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
1994-05-13 10:08:03 +04:00
|
|
|
tp_tselinuse(tlen, tsel, siso, reuseaddr)
|
1996-02-14 01:07:57 +03:00
|
|
|
int tlen;
|
|
|
|
caddr_t tsel;
|
|
|
|
register struct sockaddr_iso *siso;
|
|
|
|
int reuseaddr;
|
1994-05-13 10:08:03 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct tp_pcb *b = tp_bound_pcbs.next, *l = tp_listeners;
|
1994-05-13 10:08:03 +04:00
|
|
|
register struct tp_pcb *t;
|
|
|
|
|
|
|
|
for (;;) {
|
1996-02-14 01:07:57 +03:00
|
|
|
if (b != (struct tp_pcb *) & tp_bound_pcbs) {
|
|
|
|
t = b;
|
|
|
|
b = t->tp_next;
|
1994-05-13 10:08:03 +04:00
|
|
|
} else if (l) {
|
1996-02-14 01:07:57 +03:00
|
|
|
t = l;
|
|
|
|
l = t->tp_nextlisten;
|
1994-05-13 10:08:03 +04:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
if (tlen == t->tp_lsuffixlen && bcmp(tsel, t->tp_lsuffix, tlen) == 0) {
|
|
|
|
if (t->tp_flags & TPF_GENERAL_ADDR) {
|
|
|
|
if (siso == 0 || reuseaddr == 0)
|
|
|
|
return 1;
|
|
|
|
} else if (siso) {
|
|
|
|
if (siso->siso_family == t->tp_domain &&
|
1996-02-14 01:07:57 +03:00
|
|
|
(*t->tp_nlproto->nlp_cmpnetaddr)(t->tp_npcb,
|
|
|
|
(struct sockaddr *) siso, TP_LOCAL))
|
|
|
|
return 1;
|
1994-05-13 10:08:03 +04:00
|
|
|
} else if (reuseaddr == 0)
|
1996-02-14 01:07:57 +03:00
|
|
|
return 1;
|
1994-05-13 10:08:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
|
|
|
tp_pcbbind(v, nam)
|
|
|
|
register void *v;
|
|
|
|
register struct mbuf *nam;
|
1994-05-13 10:08:03 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct tp_pcb *tpcb = v;
|
1994-05-13 10:08:03 +04:00
|
|
|
register struct sockaddr_iso *siso = 0;
|
1996-02-14 01:07:57 +03:00
|
|
|
int tlen = 0, wrapped = 0;
|
|
|
|
caddr_t tsel = NULL;
|
|
|
|
u_short tutil;
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
if (tpcb->tp_state != TP_CLOSED)
|
|
|
|
return (EINVAL);
|
|
|
|
if (nam) {
|
|
|
|
siso = mtod(nam, struct sockaddr_iso *);
|
|
|
|
switch (siso->siso_family) {
|
|
|
|
default:
|
|
|
|
return (EAFNOSUPPORT);
|
|
|
|
#ifdef ISO
|
|
|
|
case AF_ISO:
|
|
|
|
tlen = siso->siso_tlen;
|
|
|
|
tsel = TSEL(siso);
|
|
|
|
if (siso->siso_nlen == 0)
|
|
|
|
siso = 0;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1996-02-14 01:07:57 +03:00
|
|
|
tsel = (caddr_t) & tutil;
|
|
|
|
if ((tutil = satosin(siso)->sin_port) != 0)
|
1994-05-13 10:08:03 +04:00
|
|
|
tlen = 2;
|
1995-06-13 11:13:14 +04:00
|
|
|
if (satosin(siso)->sin_addr.s_addr == 0)
|
1994-05-13 10:08:03 +04:00
|
|
|
siso = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (tpcb->tp_lsuffixlen == 0) {
|
|
|
|
if (tlen) {
|
|
|
|
if (tp_tselinuse(tlen, tsel, siso,
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb->tp_sock->so_options & SO_REUSEADDR))
|
1994-05-13 10:08:03 +04:00
|
|
|
return (EINVAL);
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
for (tsel = (caddr_t) & tutil, tlen = 2;;) {
|
1994-05-13 10:08:03 +04:00
|
|
|
if (tp_unique++ < ISO_PORT_RESERVED ||
|
1996-02-14 01:07:57 +03:00
|
|
|
tp_unique > ISO_PORT_USERRESERVED) {
|
|
|
|
if (wrapped++)
|
|
|
|
return ESRCH;
|
|
|
|
tp_unique = ISO_PORT_RESERVED;
|
1994-05-13 10:08:03 +04:00
|
|
|
}
|
|
|
|
tutil = htons(tp_unique);
|
|
|
|
if (tp_tselinuse(tlen, tsel, siso, 0) == 0)
|
|
|
|
break;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
if (siso)
|
|
|
|
switch (siso->siso_family) {
|
1994-05-13 10:08:03 +04:00
|
|
|
#ifdef ISO
|
|
|
|
case AF_ISO:
|
|
|
|
bcopy(tsel, TSEL(siso), tlen);
|
|
|
|
siso->siso_tlen = tlen;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1995-06-13 11:13:14 +04:00
|
|
|
satosin(siso)->sin_port = tutil;
|
1994-05-13 10:08:03 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bcopy(tsel, tpcb->tp_lsuffix, (tpcb->tp_lsuffixlen = tlen));
|
|
|
|
insque(tpcb, &tp_bound_pcbs);
|
|
|
|
} else {
|
|
|
|
if (tlen || siso == 0)
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if (siso == 0) {
|
|
|
|
tpcb->tp_flags |= TPF_GENERAL_ADDR;
|
|
|
|
return (0);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
return (*tpcb->tp_nlproto->nlp_pcbbind)(tpcb->tp_npcb, nam);
|
1994-05-13 10:08:03 +04:00
|
|
|
}
|