1996-02-14 01:07:57 +03:00
|
|
|
/* $NetBSD: tp_inet.c,v 1.10 1996/02/13 22:11:02 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_inet.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
|
|
|
/*
|
|
|
|
* Here is where you find the inet-dependent code. We've tried keep all
|
|
|
|
* net-level and (primarily) address-family-dependent stuff out of the tp
|
|
|
|
* source, and everthing here is reached indirectly through a switch table
|
|
|
|
* (struct nl_protosw *) tpcb->tp_nlproto (see tp_pcb.c). The routines here
|
|
|
|
* are: in_getsufx: gets transport suffix out of an inpcb structure.
|
|
|
|
* in_putsufx: put transport suffix into an inpcb structure. in_putnetaddr:
|
|
|
|
* put a whole net addr into an inpcb. in_getnetaddr: get a whole net addr
|
|
|
|
* from an inpcb. in_cmpnetaddr: compare a whole net addr from an isopcb.
|
|
|
|
* in_recycle_suffix: clear suffix for reuse in inpcb tpip_mtu: figure out
|
|
|
|
* what size tpdu to use tpip_input: take a pkt from ip, strip off its ip
|
|
|
|
* header, give to tp tpip_output_dg: package a pkt for ip given 2 addresses
|
|
|
|
* & some data tpip_output: package a pkt for ip given an inpcb & some data
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/time.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <sys/systm.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <netiso/tp_param.h>
|
|
|
|
#include <netiso/argo_debug.h>
|
|
|
|
#include <netiso/tp_stat.h>
|
|
|
|
#include <netiso/tp_ip.h>
|
|
|
|
#include <netiso/tp_pcb.h>
|
|
|
|
#include <netiso/tp_trace.h>
|
|
|
|
#include <netiso/tp_stat.h>
|
|
|
|
#include <netiso/tp_tpdu.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <netiso/tp_var.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netinet/in_var.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
#ifndef ISO
|
1993-12-18 07:54:21 +03:00
|
|
|
#include <netiso/iso_chksum.c>
|
1993-04-09 16:00:07 +04:00
|
|
|
#endif
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <machine/stdarg.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* NAME: in_getsufx()
|
|
|
|
*
|
|
|
|
* CALLED FROM: pr_usrreq() on PRU_BIND,
|
|
|
|
* PRU_CONNECT, PRU_ACCEPT, and PRU_PEERADDR
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* FUNCTION, ARGUMENTS, and RETURN VALUE:
|
|
|
|
* Get a transport suffix from an inpcb structure (inp).
|
|
|
|
* The argument (which) takes the value TP_LOCAL or TP_FOREIGN.
|
|
|
|
*
|
|
|
|
* RETURNS: internet port / transport suffix
|
|
|
|
* (CAST TO AN INT)
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
|
|
|
in_getsufx(v, lenp, data_out, which)
|
|
|
|
void *v;
|
|
|
|
u_short *lenp;
|
|
|
|
caddr_t data_out;
|
|
|
|
int which;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct inpcb *inp = v;
|
1993-04-09 16:00:07 +04:00
|
|
|
*lenp = sizeof(u_short);
|
|
|
|
switch (which) {
|
|
|
|
case TP_LOCAL:
|
1996-02-14 01:07:57 +03:00
|
|
|
*(u_short *) data_out = inp->inp_lport;
|
1993-04-09 16:00:07 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case TP_FOREIGN:
|
1996-02-14 01:07:57 +03:00
|
|
|
*(u_short *) data_out = inp->inp_fport;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NAME: in_putsufx()
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* CALLED FROM: tp_newsocket(); i.e., when a connection
|
1993-04-09 16:00:07 +04:00
|
|
|
* is being established by an incoming CR_TPDU.
|
|
|
|
*
|
|
|
|
* FUNCTION, ARGUMENTS:
|
|
|
|
* Put a transport suffix (found in name) into an inpcb structure (inp).
|
|
|
|
* The argument (which) takes the value TP_LOCAL or TP_FOREIGN.
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: Nada
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
/* ARGSUSED */
|
1993-04-09 16:00:07 +04:00
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
in_putsufx(v, sufxloc, sufxlen, which)
|
|
|
|
void *v;
|
|
|
|
caddr_t sufxloc;
|
|
|
|
int sufxlen;
|
|
|
|
int which;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct inpcb *inp = v;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (which == TP_FOREIGN) {
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy(sufxloc, (caddr_t) & inp->inp_fport, sizeof(inp->inp_fport));
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NAME: in_recycle_tsuffix()
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* CALLED FROM: tp.trans whenever we go into REFWAIT state.
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENT:
|
1996-02-14 01:07:57 +03:00
|
|
|
* Called when a ref is frozen, to allow the suffix to be reused.
|
|
|
|
* (inp) is the net level pcb.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* RETURNS: Nada
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: This really shouldn't have to be done in a NET level pcb
|
1993-04-09 16:00:07 +04:00
|
|
|
* but... for the internet world that just the way it is done in BSD...
|
|
|
|
* The alternative is to have the port unusable until the reference
|
|
|
|
* timer goes off.
|
|
|
|
*/
|
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
in_recycle_tsuffix(v)
|
|
|
|
void *v;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct inpcb *inp = v;
|
1993-04-09 16:00:07 +04:00
|
|
|
inp->inp_fport = inp->inp_lport = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: in_putnetaddr()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp_newsocket(); i.e., when a connection is being established by an
|
|
|
|
* incoming CR_TPDU.
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Copy a whole net addr from a struct sockaddr (name).
|
|
|
|
* into an inpcb (inp).
|
|
|
|
* The argument (which) takes values TP_LOCAL or TP_FOREIGN
|
|
|
|
*
|
|
|
|
* RETURNS: Nada
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
|
|
|
*/
|
1993-04-09 16:00:07 +04:00
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
in_putnetaddr(v, nm, which)
|
|
|
|
register void *v;
|
|
|
|
struct sockaddr *nm;
|
|
|
|
int which;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct inpcb *inp = v;
|
|
|
|
struct sockaddr_in *name = (struct sockaddr_in *) nm;
|
1993-04-09 16:00:07 +04:00
|
|
|
switch (which) {
|
|
|
|
case TP_LOCAL:
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) & name->sin_addr,
|
|
|
|
(caddr_t) & inp->inp_laddr, sizeof(struct in_addr));
|
|
|
|
/* won't work if the dst address (name) is INADDR_ANY */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
case TP_FOREIGN:
|
1996-02-14 01:07:57 +03:00
|
|
|
if (name != (struct sockaddr_in *) 0) {
|
|
|
|
bcopy((caddr_t) & name->sin_addr,
|
|
|
|
(caddr_t) & inp->inp_faddr, sizeof(struct in_addr));
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NAME: in_cmpnetaddr()
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp_input() when a connection is being established by an
|
|
|
|
* incoming CR_TPDU, and considered for interception.
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Compare a whole net addr from a struct sockaddr (name),
|
|
|
|
* with that implicitly stored in an inpcb (inp).
|
|
|
|
* The argument (which) takes values TP_LOCAL or TP_FOREIGN
|
|
|
|
*
|
|
|
|
* RETURNS: Nada
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
in_cmpnetaddr(v, nm, which)
|
|
|
|
register void *v;
|
|
|
|
register struct sockaddr *nm;
|
|
|
|
int which;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct inpcb *inp = v;
|
|
|
|
struct sockaddr_in *name = (struct sockaddr_in *) nm;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (which == TP_LOCAL) {
|
|
|
|
if (name->sin_port && name->sin_port != inp->inp_lport)
|
|
|
|
return 0;
|
|
|
|
return (name->sin_addr.s_addr == inp->inp_laddr.s_addr);
|
|
|
|
}
|
|
|
|
if (name->sin_port && name->sin_port != inp->inp_fport)
|
|
|
|
return 0;
|
|
|
|
return (name->sin_addr.s_addr == inp->inp_faddr.s_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: in_getnetaddr()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* pr_usrreq() PRU_SOCKADDR, PRU_ACCEPT, PRU_PEERADDR
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Copy a whole net addr from an inpcb (inp) into
|
|
|
|
* an mbuf (name);
|
|
|
|
* The argument (which) takes values TP_LOCAL or TP_FOREIGN.
|
|
|
|
*
|
|
|
|
* RETURNS: Nada
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
|
|
|
*/
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
in_getnetaddr(v, name, which)
|
|
|
|
void *v;
|
1993-04-09 16:00:07 +04:00
|
|
|
register struct mbuf *name;
|
1996-02-14 01:07:57 +03:00
|
|
|
int which;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct inpcb *inp = v;
|
1993-04-09 16:00:07 +04:00
|
|
|
register struct sockaddr_in *sin = mtod(name, struct sockaddr_in *);
|
1996-02-14 01:07:57 +03:00
|
|
|
bzero((caddr_t) sin, sizeof(*sin));
|
1993-04-09 16:00:07 +04:00
|
|
|
switch (which) {
|
|
|
|
case TP_LOCAL:
|
|
|
|
sin->sin_addr = inp->inp_laddr;
|
|
|
|
sin->sin_port = inp->inp_lport;
|
|
|
|
break;
|
|
|
|
case TP_FOREIGN:
|
|
|
|
sin->sin_addr = inp->inp_faddr;
|
|
|
|
sin->sin_port = inp->inp_fport;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
name->m_len = sin->sin_len = sizeof(*sin);
|
1993-04-09 16:00:07 +04:00
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tpip_mtu()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
1994-05-13 10:08:03 +04:00
|
|
|
* tp_route_to() on incoming CR, CC, and pr_usrreq() for PRU_CONNECT
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* FUNCTION, ARGUMENTS, and RETURN VALUE:
|
|
|
|
*
|
1994-05-13 10:08:03 +04:00
|
|
|
* Perform subnetwork dependent part of determining MTU information.
|
|
|
|
* It appears that setting a double pointer to the rtentry associated with
|
|
|
|
* the destination, and returning the header size for the network protocol
|
|
|
|
* suffices.
|
1996-02-14 01:07:57 +03:00
|
|
|
*
|
1993-04-09 16:00:07 +04:00
|
|
|
* SIDE EFFECTS:
|
1994-05-13 10:08:03 +04:00
|
|
|
* Sets tp_routep pointer in pcb.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
|
|
|
tpip_mtu(v)
|
|
|
|
void *v;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
register struct tp_pcb *tpcb = v;
|
|
|
|
struct inpcb *inp = (struct inpcb *) tpcb->tp_npcb;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CONN]) {
|
1994-05-13 10:08:03 +04:00
|
|
|
printf("tpip_mtu(tpcb)\n", tpcb);
|
|
|
|
printf("tpip_mtu routing to addr 0x%x\n", inp->inp_faddr.s_addr);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
tpcb->tp_routep = &(inp->inp_route.ro_rt);
|
1996-02-14 01:07:57 +03:00
|
|
|
return (sizeof(struct ip));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tpip_output()
|
|
|
|
*
|
|
|
|
* CALLED FROM: tp_emit()
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Take a packet(m0) from tp and package it so that ip will accept it.
|
|
|
|
* This means prepending space for the ip header and filling in a few
|
|
|
|
* of the fields.
|
|
|
|
* inp is the inpcb structure; datalen is the length of the data in the
|
|
|
|
* mbuf string m0.
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS:
|
1993-04-09 16:00:07 +04:00
|
|
|
* whatever (E*) is returned form the net layer output routine.
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1996-02-14 01:07:57 +03:00
|
|
|
#if __STDC__
|
|
|
|
tpip_output(struct mbuf *m0, ...)
|
|
|
|
#else
|
|
|
|
tpip_output(m0, va_alist)
|
|
|
|
struct mbuf *m0;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
int datalen;
|
|
|
|
struct inpcb *inp;
|
|
|
|
int nochksum;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, m0);
|
|
|
|
datalen = va_arg(ap, int);
|
|
|
|
inp = va_arg(ap, struct inpcb *);
|
|
|
|
nochksum = va_arg(ap, int);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return tpip_output_dg(m0, datalen, &inp->inp_laddr, &inp->inp_faddr,
|
|
|
|
&inp->inp_route, nochksum);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tpip_output_dg()
|
|
|
|
*
|
|
|
|
* CALLED FROM: tp_error_emit()
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* This is a copy of tpip_output that takes the addresses
|
|
|
|
* instead of a pcb. It's used by the tp_error_emit, when we
|
|
|
|
* don't have an in_pcb with which to call the normal output rtn.
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: ENOBUFS or whatever (E*) is
|
1993-04-09 16:00:07 +04:00
|
|
|
* returned form the net layer output routine.
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/* ARGSUSED */
|
1993-04-09 16:00:07 +04:00
|
|
|
int
|
1996-02-14 01:07:57 +03:00
|
|
|
#if __STDC__
|
|
|
|
tpip_output_dg(struct mbuf *m0, ...)
|
|
|
|
#else
|
|
|
|
tpip_output_dg(m0, va_alist)
|
|
|
|
struct mbuf *m0;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
int datalen;
|
|
|
|
struct in_addr *laddr, *faddr;
|
|
|
|
struct route *ro;
|
|
|
|
int nochksum;
|
|
|
|
register struct mbuf *m;
|
1993-04-09 16:00:07 +04:00
|
|
|
register struct ip *ip;
|
1996-02-14 01:07:57 +03:00
|
|
|
int error;
|
|
|
|
va_list ap;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
va_start(ap, m0);
|
|
|
|
datalen = va_arg(ap, int);
|
|
|
|
laddr = va_arg(ap, struct in_addr *);
|
|
|
|
faddr = va_arg(ap, struct in_addr *);
|
|
|
|
ro = va_arg(ap, struct route *);
|
|
|
|
nochksum = va_arg(ap, int);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_EMIT]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("tpip_output_dg datalen 0x%x m0 0x%x\n", datalen, m0);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, TPMT_IPHDR);
|
|
|
|
if (m == 0) {
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
m->m_next = m0;
|
|
|
|
MH_ALIGN(m, sizeof(struct ip));
|
|
|
|
m->m_len = sizeof(struct ip);
|
|
|
|
|
|
|
|
ip = mtod(m, struct ip *);
|
1996-02-14 01:07:57 +03:00
|
|
|
bzero((caddr_t) ip, sizeof *ip);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
ip->ip_p = IPPROTO_TP;
|
|
|
|
m->m_pkthdr.len = ip->ip_len = sizeof(struct ip) + datalen;
|
1996-02-14 01:07:57 +03:00
|
|
|
ip->ip_ttl = MAXTTL;
|
|
|
|
/*
|
|
|
|
* don't know why you need to set ttl; overlay doesn't even make this
|
|
|
|
* available
|
|
|
|
*/
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
ip->ip_src = *laddr;
|
|
|
|
ip->ip_dst = *faddr;
|
|
|
|
|
|
|
|
IncStat(ts_tpdu_sent);
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_EMIT]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
dump_mbuf(m, "tpip_output_dg before ip_output\n");
|
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
|
|
|
error = ip_output(m, (struct mbuf *) 0, ro, IP_ALLOWBROADCAST, NULL);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_EMIT]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("tpip_output_dg after ip_output\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(m);
|
|
|
|
IncStat(ts_send_drop);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tpip_input()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* ip's input routine, indirectly through the protosw.
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Take a packet (m) from ip, strip off the ip header and give it to tp
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: No return value.
|
|
|
|
*
|
1993-04-09 16:00:07 +04:00
|
|
|
* SIDE EFFECTS:
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
*/
|
1994-05-13 10:08:03 +04:00
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
#if __STDC__
|
|
|
|
tpip_input(struct mbuf *m, ...)
|
|
|
|
#else
|
|
|
|
tpip_input(m, va_alist)
|
|
|
|
struct mbuf *m;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
int iplen;
|
|
|
|
struct sockaddr_in src, dst;
|
|
|
|
register struct ip *ip;
|
|
|
|
int s = splsoftnet(), hdrlen;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, m);
|
|
|
|
iplen = va_arg(ap, int);
|
|
|
|
va_end(ap);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
IncStat(ts_pkt_rcvd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IP layer has already pulled up the IP header,
|
|
|
|
* but the first byte after the IP header may not be there,
|
|
|
|
* e.g. if you came in via loopback, so you have to do an
|
|
|
|
* m_pullup to before you can even look to see how much you
|
|
|
|
* really need. The good news is that m_pullup will round
|
|
|
|
* up to almost the next mbuf's worth.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((m = m_pullup(m, iplen + 1)) == MNULL)
|
1993-04-09 16:00:07 +04:00
|
|
|
goto discard;
|
|
|
|
CHANGE_MTYPE(m, TPMT_DATA);
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* Now pull up the whole tp header:
|
|
|
|
* Unfortunately, there may be IP options to skip past so we
|
|
|
|
* just fetch it as an unsigned char.
|
|
|
|
*/
|
|
|
|
hdrlen = iplen + 1 + mtod(m, u_char *)[iplen];
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if (m->m_len < hdrlen) {
|
|
|
|
if ((m = m_pullup(m, hdrlen)) == MNULL) {
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_TPINPUT]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("tp_input, pullup 2!\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
goto discard;
|
|
|
|
}
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* cannot use tp_inputprep() here 'cause you don't have quite the
|
|
|
|
* same situation
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_TPINPUT]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
dump_mbuf(m, "after tpip_input both pullups");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*
|
1993-04-09 16:00:07 +04:00
|
|
|
* m_pullup may have returned a different mbuf
|
|
|
|
*/
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* drop the ip header from the front of the mbuf
|
|
|
|
* this is necessary for the tp checksum
|
|
|
|
*/
|
|
|
|
m->m_len -= iplen;
|
|
|
|
m->m_data += iplen;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
src.sin_addr = *(struct in_addr *) & (ip->ip_src);
|
|
|
|
src.sin_family = AF_INET;
|
|
|
|
src.sin_len = sizeof(src);
|
|
|
|
dst.sin_addr = *(struct in_addr *) & (ip->ip_dst);
|
|
|
|
dst.sin_family = AF_INET;
|
|
|
|
dst.sin_len = sizeof(dst);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1995-06-13 11:13:14 +04:00
|
|
|
tp_input(m, sintosa(&src), sintosa(&dst), 0, tpip_output_dg, 0);
|
1994-05-13 10:08:03 +04:00
|
|
|
return;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
discard:
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_TPINPUT]) {
|
1993-04-09 16:00:07 +04:00
|
|
|
printf("tpip_input DISCARD\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef TPPT
|
|
|
|
if (tp_traceflags[D_TPINPUT]) {
|
|
|
|
tptrace(TPPTmisc, "tpip_input DISCARD m", m, 0, 0, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
m_freem(m);
|
1993-04-09 16:00:07 +04:00
|
|
|
IncStat(ts_recv_drop);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tpin_quench()
|
|
|
|
*
|
|
|
|
* CALLED FROM: tpip_ctlinput()
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS: find the tpcb pointer and pass it to tp_quench
|
|
|
|
*
|
|
|
|
* RETURNS: Nada
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
tpin_quench(inp, dummy)
|
|
|
|
struct inpcb *inp;
|
|
|
|
int dummy;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
tp_quench((struct inpcb *) inp->inp_socket->so_pcb, PRC_QUENCH);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tpip_ctlinput()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* The network layer through the protosw table.
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* When clnp gets an ICMP msg this gets called.
|
|
|
|
* It either returns an error status to the user or
|
|
|
|
* causes all connections on this address to be aborted
|
|
|
|
* by calling the appropriate xx_notify() routine.
|
1996-02-14 01:07:57 +03:00
|
|
|
* (cmd) is the type of ICMP error.
|
1993-04-09 16:00:07 +04:00
|
|
|
* (sa) the address of the sender
|
|
|
|
*
|
|
|
|
* RETURNS: Nothing
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void *
|
|
|
|
tpip_ctlinput(cmd, sa, dummy)
|
|
|
|
int cmd;
|
|
|
|
struct sockaddr *sa;
|
|
|
|
void *dummy;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct sockaddr_in *sin = (struct sockaddr_in *) sa;
|
|
|
|
extern int inetctlerrmap[];
|
|
|
|
void (*notify) __P((struct inpcb *, int));
|
|
|
|
int errno;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1995-06-13 11:13:14 +04:00
|
|
|
if (cmd < 0 || cmd >= PRC_NCMDS)
|
1996-02-14 01:07:57 +03:00
|
|
|
return NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (sin->sin_family != AF_INET && sin->sin_family != AF_IMPLINK)
|
1996-02-14 01:07:57 +03:00
|
|
|
return NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (sin->sin_addr.s_addr == INADDR_ANY)
|
1996-02-14 01:07:57 +03:00
|
|
|
return NULL;
|
1995-06-13 11:13:14 +04:00
|
|
|
errno = inetctlerrmap[cmd];
|
1993-04-09 16:00:07 +04:00
|
|
|
switch (cmd) {
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
case PRC_QUENCH:
|
|
|
|
notify = tp_quench;
|
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
case PRC_ROUTEDEAD:
|
|
|
|
case PRC_HOSTUNREACH:
|
|
|
|
case PRC_UNREACH_NET:
|
|
|
|
case PRC_IFDOWN:
|
|
|
|
case PRC_HOSTDEAD:
|
|
|
|
notify = in_rtchange;
|
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
default:
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
case PRC_MSGSIZE:
|
|
|
|
case PRC_UNREACH_HOST:
|
|
|
|
case PRC_UNREACH_PROTOCOL:
|
|
|
|
case PRC_UNREACH_PORT:
|
|
|
|
case PRC_UNREACH_NEEDFRAG:
|
|
|
|
case PRC_UNREACH_SRCFAIL:
|
|
|
|
case PRC_REDIRECT_NET:
|
|
|
|
case PRC_REDIRECT_HOST:
|
|
|
|
case PRC_REDIRECT_TOSNET:
|
|
|
|
case PRC_REDIRECT_TOSHOST:
|
|
|
|
case PRC_TIMXCEED_INTRANS:
|
|
|
|
case PRC_TIMXCEED_REASS:
|
|
|
|
case PRC_PARAMPROB:
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
notify = tpin_abort;
|
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1995-06-13 11:13:14 +04:00
|
|
|
in_pcbnotifyall(&tp_inpcb, sintosa(sin), errno, notify);
|
1996-02-14 01:07:57 +03:00
|
|
|
return NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME: tpin_abort()
|
|
|
|
*
|
|
|
|
* CALLED FROM:
|
|
|
|
* xxx_notify() from tp_ctlinput() when
|
|
|
|
* net level gets some ICMP-equiv. type event.
|
|
|
|
*
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Cause the connection to be aborted with some sort of error
|
|
|
|
* reason indicating that the network layer caused the abort.
|
|
|
|
* Fakes an ER TPDU so we can go through the driver.
|
|
|
|
*
|
|
|
|
* RETURNS: Nothing
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
void
|
|
|
|
tpin_abort(inp, n)
|
1996-02-14 01:07:57 +03:00
|
|
|
struct inpcb *inp;
|
|
|
|
int n;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
struct tp_event e;
|
|
|
|
|
|
|
|
e.ev_number = ER_TPDU;
|
1996-02-14 01:07:57 +03:00
|
|
|
e.TPDU_ATTR(ER).e_reason = ENETRESET;
|
|
|
|
tp_driver((struct tp_pcb *) inp->inp_ppcb, &e);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
1993-04-09 16:00:07 +04:00
|
|
|
dump_inaddr(addr)
|
|
|
|
register struct sockaddr_in *addr;
|
|
|
|
{
|
|
|
|
printf("INET: port 0x%x; addr 0x%x\n", addr->sin_port, addr->sin_addr);
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* ARGO_DEBUG */
|
|
|
|
#endif /* INET */
|