home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
comm
/
amitcp-3.0ß2.lha
/
AmiTCP
/
src
/
amitcp
/
netinet
/
tcp_usrreq.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-12
|
15KB
|
569 lines
RCS_ID_C="$Id: tcp_usrreq.c,v 1.10 1993/06/04 11:16:15 jraja Exp $";
/*
* Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>,
* Helsinki University of Technology, Finland.
* All rights reserved.
*
* HISTORY
* $Log: tcp_usrreq.c,v $
* Revision 1.10 1993/06/04 11:16:15 jraja
* Fixes for first public release.
*
* Revision 1.9 1993/05/17 00:16:44 ppessi
* Changed RCS version. Added rcsid.
*
* Revision 1.8 1993/04/24 17:48:13 jraja
* Removed MCLBYTES, set default buffer size to 8 kilobytes.
*
* Revision 1.7 93/04/19 02:39:50 02:39:50 ppessi (Pekka Pessi)
* Default socket buffer space made bigger
*
* Revision 1.6 93/04/05 19:06:44 19:06:44 jraja (Jarno Tapio Rajahalme)
* Changed storage of the spl functions return values to type spl_t.
* Added include for conf.h to every .c file.
*
* Revision 1.5 93/03/16 08:28:51 08:28:51 jraja (Jarno Tapio Rajahalme)
* Made PRU_SENSE (stat) unsupported on AmiTCP
*
* Revision 1.4 93/03/05 21:09:45 21:09:45 jraja (Jarno Tapio Rajahalme)
* Fixed includes (again).
*
* Revision 1.3 93/03/03 21:28:27 21:28:27 jraja (Jarno Tapio Rajahalme)
* Moved various data definitions from header files to here.
*
* Revision 1.2 93/02/26 09:59:47 09:59:47 jraja (Jarno Tapio Rajahalme)
* Made this compile with ANSI C (added prototypes).
* Changed so_linger to so_linger.tv_sec, since so_linger changed from short
*
* Revision 1.1 92/11/17 16:31:09 16:31:09 jraja (Jarno Tapio Rajahalme)
* Initial revision
*
*/
/*
* Copyright (c) 1982, 1986, 1988 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.
*
* @(#)tcp_usrreq.c 7.15 (Berkeley) 6/28/90
*/
#include <conf.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <sys/errno.h>
#include <sys/synch.h>
#include <net/if.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/in_pcb.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/tcp_fsm.h>
#include <netinet/tcp_seq.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
#include <netinet/tcpip.h>
#include <netinet/tcp_debug.h>
#include <netinet/tcp_usrreq_protos.h>
#include <netinet/tcp_output_protos.h>
#include <netinet/tcp_subr_protos.h>
#include <netinet/tcp_timer_protos.h>
#include <netinet/in_protos.h>
#include <netinet/in_pcb_protos.h>
#include <kern/uipc_socket2_protos.h>
#include <netinet/tcp_debug_protos.h>
#include <netinet/ip_output_protos.h>
struct inpcb tcb = { 0 }; /* head of queue of active tcpcb's */
struct tcpstat tcpstat = { 0 }; /* tcp statistics */
tcp_seq tcp_iss = { 0 }; /* tcp initial send seq # */
#ifdef KPROF
int tcp_acounts[TCP_NSTATES][PRU_NREQ] = { 0 };
#endif
/*
* Configurable variables
*/
u_long tcp_sendspace = 8 * 1024;
u_long tcp_recvspace = 8 * 1024;
/*
* TCP protocol interface to socket abstraction.
*/
extern char *tcpstates[];
struct tcpcb *tcp_newtcpcb();
/*
* Process a TCP user request for TCP tb. If this is a send request
* then m is the mbuf chain of send data. If this is a timer expiration
* (called from the software clock routine), then timertype tells which timer.
*/
int
tcp_usrreq(so, req, m, nam, control)
struct socket *so;
int req;
struct mbuf *m, *nam, *control;
{
register struct inpcb *inp;
register struct tcpcb *tp;
spl_t s;
int error = 0;
int ostate;
if (req == PRU_CONTROL)
return (in_control(so, (int)m, (caddr_t)nam,
(struct ifnet *)control));
if (control && control->m_len) {
m_freem(control);
if (m)
m_freem(m);
return (EINVAL);
}
s = splnet();
inp = sotoinpcb(so);
/*
* When a TCP is attached to a socket, then there will be
* a (struct inpcb) pointed at by the socket, and this
* structure will point at a subsidary (struct tcpcb).
*/
if (inp == 0 && req != PRU_ATTACH) {
splx(s);
return (EINVAL); /* XXX */
}
if (inp) {
tp = intotcpcb(inp);
/* WHAT IF TP IS 0? */
#ifdef KPROF
tcp_acounts[tp->t_state][req]++;
#endif
ostate = tp->t_state;
} else
ostate = 0;
switch (req) {
/*
* TCP attaches to socket via PRU_ATTACH, reserving space,
* and an internet control block.
*/
case PRU_ATTACH:
if (inp) {
error = EISCONN;
break;
}
error = tcp_attach(so);
if (error)
break;
if ((so->so_options & SO_LINGER) && so->so_linger.tv_sec == 0)
so->so_linger.tv_sec = TCP_LINGERTIME;
tp = sototcpcb(so);
break;
/*
* PRU_DETACH detaches the TCP protocol from the socket.
* If the protocol state is non-embryonic, then can't
* do this directly: have to initiate a PRU_DISCONNECT,
* which may finish later; embryonic TCB's can just
* be discarded here.
*/
case PRU_DETACH:
if (tp->t_state > TCPS_LISTEN)
tp = tcp_disconnect(tp);
else
tp = tcp_close(tp);
break;
/*
* Give the socket an address.
*/
case PRU_BIND:
error = in_pcbbind(inp, nam);
if (error)
break;
break;
/*
* Prepare to accept connections.
*/
case PRU_LISTEN:
if (inp->inp_lport == 0)
error = in_pcbbind(inp, (struct mbuf *)0);
if (error == 0)
tp->t_state = TCPS_LISTEN;
break;
/*
* Initiate connection to peer.
* Create a template for use in transmissions on this connection.
* Enter SYN_SENT state, and mark socket as connecting.
* Start keep-alive timer, and seed output sequence space.
* Send initial segment on connection.
*/
case PRU_CONNECT:
if (inp->inp_lport == 0) {
error = in_pcbbind(inp, (struct mbuf *)0);
if (error)
break;
}
error = in_pcbconnect(inp, nam);
if (error)
break;
tp->t_template = tcp_template(tp);
if (tp->t_template == 0) {
in_pcbdisconnect(inp);
error = ENOBUFS;
break;
}
soisconnecting(so);
tcpstat.tcps_connattempt++;
tp->t_state = TCPS_SYN_SENT;
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
tp->iss = tcp_iss; tcp_iss += TCP_ISSINCR/2;
tcp_sendseqinit(tp);
error = tcp_output(tp);
break;
/*
* Create a TCP connection between two sockets.
*/
case PRU_CONNECT2:
error = EOPNOTSUPP;
break;
/*
* Initiate disconnect from peer.
* If connection never passed embryonic stage, just drop;
* else if don't need to let data drain, then can just drop anyways,
* else have to begin TCP shutdown process: mark socket disconnecting,
* drain unread data, state