Finish driving a stake through the heart of netns and the associated

ifdefs scattered around the place - its dead Jim!

The SMB stuff had stolen AF_NS, make it official.
This commit is contained in:
Peter Wemm 2003-03-05 19:24:24 +00:00
parent f3634ced5c
commit 3c6b084e96
48 changed files with 5 additions and 6281 deletions

View File

@ -356,8 +356,6 @@ options COMPILING_LINT
#
# Protocol families:
# Only the INET (Internet) family is officially supported in FreeBSD.
# Source code for the NS (Xerox Network Service) is provided for amusement
# value.
#
options INET #Internet communications protocols
options INET6 #IPv6 communications protocols
@ -387,10 +385,6 @@ options IPTUNNEL #IP in IPX encapsulation (not available)
options NETATALK #Appletalk communications protocols
options NETATALKDEBUG #Appletalk debugging
# These are currently broken but are shipped due to interest.
#options NS #Xerox NS protocols
#options NSIP #XNS over IP
#
# SMB/CIFS requester
# NETSMB enables support for SMB protocol, it requires LIBMCHAIN and LIBICONV

View File

@ -1421,16 +1421,6 @@ netncp/ncp_nls.c optional ncp
netncp/ncp_rq.c optional ncp
netncp/ncp_sock.c optional ncp
netncp/ncp_subr.c optional ncp
netns/idp_usrreq.c optional ns
netns/ns.c optional ns
netns/ns_error.c optional ns
netns/ns_input.c optional ns
netns/ns_ip.c optional ns
netns/ns_output.c optional ns
netns/ns_pcb.c optional ns
netns/ns_proto.c optional ns
netns/spp_debug.c optional ns
netns/spp_usrreq.c optional ns
netsmb/smb_conn.c optional netsmb
netsmb/smb_crypt.c optional netsmb
netsmb/smb_dev.c optional netsmb

View File

@ -353,7 +353,6 @@ IPTUNNEL opt_ipx.h
LIBMCHAIN
NCP opt_ncp.h
NETATALK opt_atalk.h
NS opt_ns.h
PPP_BSDCOMP opt_ppp.h
PPP_DEFLATE opt_ppp.h
PPP_FILTER opt_ppp.h

View File

@ -45,11 +45,6 @@
#include <net/if_dl.h>
#include <net/if_media.h>
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#include <net/bpf.h>
#include <sys/sockio.h>
#include <sys/bus.h>

View File

@ -108,11 +108,6 @@
#include <netinet/ip.h>
#endif
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#include <net/bpf.h>
#include <net/bpfdesc.h>

View File

@ -83,11 +83,6 @@
#include <netinet/if_ether.h>
#endif
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#include <net/bpf.h>
#include <machine/md_var.h>

View File

@ -45,7 +45,6 @@ COMM= ${SYS}/dev/advansys/*.[ch] \
${SYS}/netipx/*.[ch] \
${SYS}/netkey/*.[ch] \
${SYS}/netnatm/*.[ch] \
${SYS}/netns/*.[ch] \
${SYS}/nfs/*.[ch] \
${SYS}/pci/*.[ch] \
${SYS}/posix4/*.[ch] \
@ -63,7 +62,6 @@ COMMDIR1= ${SYS}/conf \
${SYS}/netipx \
${SYS}/netkey \
${SYS}/netnatm \
${SYS}/netns \
${SYS}/nfs \
${SYS}/pci \
${SYS}/posix4 \

View File

@ -37,7 +37,7 @@ DGEN= conf \
fs/specfs fs/umapfs fs/unionfs \
hp hp/dev hp/hpux \
kern libkern \
net netccitt netinet netiso netns nfs scripts sys \
net netinet nfs scripts sys \
ufs ufs/ffs ufs/lfs ufs/ufs \
vm

View File

@ -3,14 +3,11 @@
.PATH: ${.CURDIR}/../../net ${.CURDIR}/../../netinet
KMOD= if_gre
SRCS= if_gre.c ip_gre.c opt_inet.h opt_ns.h opt_atalk.h
SRCS= if_gre.c ip_gre.c opt_inet.h opt_atalk.h
opt_inet.h:
echo "#define INET 1" > ${.TARGET}
opt_ns.h:
echo "#define NS 1" > ${.TARGET}
opt_atalk.h:
echo "#define NETATALK 1" > ${.TARGET}

View File

@ -83,14 +83,6 @@ int (*ef_outputp)(struct ifnet *ifp, struct mbuf **mp,
struct sockaddr *dst, short *tp, int *hlen);
#endif
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
ushort ns_nettype;
int ether_outputdebug = 0;
int ether_inputdebug = 0;
#endif
#ifdef NETATALK
#include <netatalk/at.h>
#include <netatalk/at_var.h>
@ -230,43 +222,6 @@ ether_output(ifp, m, dst, rt0)
break;
}
#endif /* NETATALK */
#ifdef NS
case AF_NS:
switch(ns_nettype){
default:
case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
type = 0x8137;
break;
case 0x0: /* Novell 802.3 */
type = htons( m->m_pkthdr.len);
break;
case 0xe0e0: /* Novell 802.2 and Token-Ring */
M_PREPEND(m, 3, M_TRYWAIT);
type = htons( m->m_pkthdr.len);
cp = mtod(m, u_char *);
*cp++ = 0xE0;
*cp++ = 0xE0;
*cp++ = 0x03;
break;
}
bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
(caddr_t)edst, sizeof (edst));
/*
* XXX if ns_thishost is the same as the node's ethernet
* address then just the default code will catch this anyhow.
* So I'm not sure if this next clause should be here at all?
* [JRE]
*/
if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))){
m->m_pkthdr.rcvif = ifp;
netisr_queue(NETISR_NS, m);
return (error);
}
if (!bcmp((caddr_t)edst, (caddr_t)&ns_broadhost, sizeof(edst))){
m->m_flags |= M_BCAST;
}
break;
#endif /* NS */
case pseudo_AF_HDRCMPLT:
hdrcmplt = 1;
@ -777,12 +732,6 @@ ether_demux(struct ifnet *ifp, struct mbuf *m)
isr = NETISR_IPV6;
break;
#endif
#ifdef NS
case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
isr = NETISR_NS;
break;
#endif /* NS */
#ifdef NETATALK
case ETHERTYPE_AT:
isr = NETISR_ATALK1;
@ -796,20 +745,6 @@ ether_demux(struct ifnet *ifp, struct mbuf *m)
if (ef_inputp && ef_inputp(ifp, eh, m) == 0)
return;
#endif /* IPX */
#ifdef NS
checksum = mtod(m, ushort *);
/* Novell 802.3 */
if ((ether_type <= ETHERMTU) &&
((*checksum == 0xffff) || (*checksum == 0xE0E0))) {
if (*checksum == 0xE0E0) {
m->m_pkthdr.len -= 3;
m->m_len -= 3;
m->m_data += 3;
}
isr = NETISR_NS;
break;
}
#endif /* NS */
#if defined(NETATALK)
if (ether_type > ETHERMTU)
goto discard;
@ -978,31 +913,6 @@ ether_ioctl(ifp, command, data)
ifp->if_init(ifp->if_softc);
break;
}
#endif
#ifdef NS
/*
* XXX - This code is probably wrong
*/
case AF_NS:
{
struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
struct arpcom *ac = IFP2AC(ifp);
if (ns_nullhost(*ina))
ina->x_host =
*(union ns_host *) (ac->ac_enaddr);
else {
bcopy((caddr_t) ina->x_host.c_host,
(caddr_t) ac->ac_enaddr,
sizeof(ac->ac_enaddr));
}
/*
* Set new address
*/
ifp->if_init(ifp->if_softc);
break;
}
#endif
default:
ifp->if_init(ifp->if_softc);

View File

@ -75,11 +75,6 @@
#include <netipx/ipx_if.h>
#endif
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#ifdef DECNET
#include <netdnet/dn.h>
#endif
@ -201,13 +196,6 @@ fddi_output(ifp, m, dst, rt0)
break;
}
#endif /* NETATALK */
#ifdef NS
case AF_NS:
type = htons(ETHERTYPE_NS);
bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
(caddr_t)edst, FDDI_ADDR_LEN);
break;
#endif
case pseudo_AF_HDRCMPLT:
{
@ -467,11 +455,6 @@ fddi_input(ifp, m)
isr = NETISR_IPX;
break;
#endif
#ifdef NS
case ETHERTYPE_NS:
isr = NETISR_NS;
break;
#endif
#ifdef DECNET
case ETHERTYPE_DECNET:
isr = NETISR_DECNET;

View File

@ -48,7 +48,6 @@
#include "opt_atalk.h"
#include "opt_inet.h"
#include "opt_ns.h"
#include <sys/param.h>
#include <sys/kernel.h>
@ -336,11 +335,6 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
case AF_APPLETALK:
etype = ETHERTYPE_ATALK;
break;
#endif
#ifdef NS
case AF_NS:
etype = ETHERTYPE_NS;
break;
#endif
default:
_IF_DROP(&ifp->if_snd);

View File

@ -82,11 +82,6 @@
#include <netinet/ip6.h>
#endif
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#ifdef NETATALK
#include <netatalk/at.h>
#include <netatalk/at_var.h>
@ -250,7 +245,6 @@ looutput(ifp, m, dst, rt)
case AF_INET:
case AF_INET6:
case AF_IPX:
case AF_NS:
case AF_APPLETALK:
break;
default:
@ -349,11 +343,6 @@ if_simloop(ifp, m, af, hlen)
isr = NETISR_IPX;
break;
#endif
#ifdef NS
case AF_NS:
isr = NETISR_NS;
break;
#endif
#ifdef NETATALK
case AF_APPLETALK:
isr = NETISR_ATALK2;

View File

@ -89,11 +89,6 @@
#include <netipx/ipx_if.h>
#endif
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#include <net/if_sppp.h>
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
@ -663,14 +658,6 @@ sppp_input(struct ifnet *ifp, struct mbuf *m)
isr = NETISR_IPX;
do_account++;
break;
#endif
#ifdef NS
case PPP_XNS:
/* XNS IDPCP not implemented yet */
if (sp->pp_phase == PHASE_NETWORK)
isr = NETISR_NS;
do_account++;
break;
#endif
}
break;
@ -711,12 +698,6 @@ sppp_input(struct ifnet *ifp, struct mbuf *m)
isr = NETISR_IPX;
do_account++;
break;
#endif
#ifdef NS
case ETHERTYPE_NS:
isr = NETISR_NS;
do_account++;
break;
#endif
}
break;
@ -941,12 +922,6 @@ sppp_output(struct ifnet *ifp, struct mbuf *m,
}
break;
#endif
#ifdef NS
case AF_NS: /* Xerox NS Protocol */
h->protocol = htons (sp->pp_mode == IFF_CISCO ?
ETHERTYPE_NS : PPP_XNS);
break;
#endif
#ifdef IPX
case AF_IPX: /* Novell IPX Protocol */
h->protocol = htons (sp->pp_mode == IFF_CISCO ?

View File

@ -805,11 +805,6 @@ tunwrite(dev_t dev, struct uio *uio, int flag)
isr = NETISR_IPX;
break;
#endif
#ifdef NS
case AF_NS:
isr = NETISR_NS;
break;
#endif
#ifdef NETATALK
case AF_APPLETALK:
isr = NETISR_ATALK2;

View File

@ -54,7 +54,6 @@
*/
#define NETISR_POLL 0 /* polling callback, must be first */
#define NETISR_IP 2 /* same as AF_INET */
#define NETISR_NS 6 /* same as AF_NS */
#define NETISR_AARP 15 /* Appletalk ARP */
#define NETISR_ATALK2 16 /* Appletalk phase 2 */
#define NETISR_ATALK1 17 /* Appletalk phase 1 */

View File

@ -258,7 +258,6 @@ struct route_cb {
int ip_count;
int ip6_count;
int ipx_count;
int ns_count;
int any_count;
};

View File

@ -141,9 +141,6 @@ rts_attach(struct socket *so, int proto, struct thread *td)
case AF_IPX:
route_cb.ipx_count++;
break;
case AF_NS:
route_cb.ns_count++;
break;
}
rp->rcb_faddr = &route_src;
route_cb.any_count++;
@ -194,9 +191,6 @@ rts_detach(struct socket *so)
case AF_IPX:
route_cb.ipx_count--;
break;
case AF_NS:
route_cb.ns_count--;
break;
}
route_cb.any_count--;
}

View File

@ -108,7 +108,6 @@ const static struct iffam gFamilies[] = {
{ AF_IPX, NG_GIF_DEMUX_HOOK_IPX },
{ AF_ATM, NG_GIF_DEMUX_HOOK_ATM },
{ AF_NATM, NG_GIF_DEMUX_HOOK_NATM },
{ AF_NS, NG_GIF_DEMUX_HOOK_NS },
};
#define NUM_FAMILIES (sizeof(gFamilies) / sizeof(*gFamilies))

View File

@ -45,6 +45,5 @@
#define NG_GIF_DEMUX_HOOK_IPX "ipx"
#define NG_GIF_DEMUX_HOOK_ATM "atm"
#define NG_GIF_DEMUX_HOOK_NATM "natm"
#define NG_GIF_DEMUX_HOOK_NS "ns"
#endif /* _NETGRAPH_NG_GIF_DEMUX_H_ */

View File

@ -97,7 +97,6 @@ const static struct iffam gFamilies[] = {
{ AF_IPX, NG_IFACE_HOOK_IPX },
{ AF_ATM, NG_IFACE_HOOK_ATM },
{ AF_NATM, NG_IFACE_HOOK_NATM },
{ AF_NS, NG_IFACE_HOOK_NS },
};
#define NUM_FAMILIES (sizeof(gFamilies) / sizeof(*gFamilies))
@ -770,11 +769,6 @@ ng_iface_rcvdata(hook_p hook, item_p item)
isr = NETISR_IPX;
break;
#endif
#ifdef NS
case AF_NS:
isr = NETISR_NS;
break;
#endif
#ifdef NETATALK
case AF_APPLETALK:
isr = NETISR_ATALK2;

View File

@ -58,7 +58,6 @@
#define NG_IFACE_HOOK_IPX "ipx"
#define NG_IFACE_HOOK_ATM "atm"
#define NG_IFACE_HOOK_NATM "natm"
#define NG_IFACE_HOOK_NS "ns"
/* MTU bounds */
#define NG_IFACE_MTU_MIN 72

View File

@ -85,11 +85,6 @@
#include <netipx/ipx_ip.h>
#endif
#ifdef NSIP
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
extern struct domain inetdomain;
static struct pr_usrreqs nousrreqs;
@ -220,14 +215,6 @@ struct protosw inetsw[] = {
0, 0, 0, 0,
&rip_usrreqs
},
#endif
#ifdef NSIP
{ SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
idpip_input, 0, nsip_ctlinput, 0,
0,
0, 0, 0, 0,
&rip_usrreqs
},
#endif
/* raw wildcard */
{ SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR,

View File

@ -44,7 +44,6 @@
*/
#include "opt_inet.h"
#include "opt_ns.h"
#include "opt_atalk.h"
#include <sys/param.h>
@ -76,11 +75,6 @@
#error ip_gre input without IP?
#endif
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#ifdef NETATALK
#include <netatalk/at.h>
#include <netatalk/at_var.h>
@ -181,11 +175,6 @@ gre_input2(struct mbuf *m ,int hlen, u_char proto)
case WCCP_PROTOCOL_TYPE: /* we are in ip_input */
isr = NETISR_IP;
break;
#ifdef NS
case ETHERTYPE_NS:
isr = NETISR_NS;
break;
#endif
#ifdef NETATALK
case ETHERTYPE_ATALK:
isr = NETISR_ATALK1;

View File

@ -1,52 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)idp.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_IDP_H_
#define _NETNS_IDP_H_
/*
* Definitions for NS(tm) Internet Datagram Protocol
*/
struct idp {
u_short idp_sum; /* Checksum */
u_short idp_len; /* Length, in bytes, including header */
u_char idp_tc; /* Transport Control (i.e. hop count) */
u_char idp_pt; /* Packet Type (i.e. level 2 protocol) */
struct ns_addr idp_dna; /* Destination Network Address */
struct ns_addr idp_sna; /* Source Network Address */
};
#endif

View File

@ -1,562 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)idp_usrreq.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <net/if.h>
#include <net/route.h>
#include <netns/ns.h>
#include <netns/ns_pcb.h>
#include <netns/ns_if.h>
#include <netns/idp.h>
#include <netns/idp_var.h>
#include <netns/ns_error.h>
/*
* IDP protocol implementation.
*/
struct sockaddr_ns idp_ns = { sizeof(idp_ns), AF_NS };
/*
* This may also be called for raw listeners.
*/
idp_input(m, nsp)
struct mbuf *m;
register struct nspcb *nsp;
{
register struct idp *idp = mtod(m, struct idp *);
struct ifnet *ifp = m->m_pkthdr.rcvif;
if (nsp==0)
panic("No nspcb");
/*
* Construct sockaddr format source address.
* Stuff source address and datagram in user buffer.
*/
idp_ns.sns_addr = idp->idp_sna;
if (ns_neteqnn(idp->idp_sna.x_net, ns_zeronet) && ifp) {
register struct ifaddr *ifa;
for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family == AF_NS) {
idp_ns.sns_addr.x_net =
IA_SNS(ifa)->sns_addr.x_net;
break;
}
}
}
nsp->nsp_rpt = idp->idp_pt;
if ( ! (nsp->nsp_flags & NSP_RAWIN) ) {
m->m_len -= sizeof (struct idp);
m->m_pkthdr.len -= sizeof (struct idp);
m->m_data += sizeof (struct idp);
}
if (sbappendaddr(&nsp->nsp_socket->so_rcv, (struct sockaddr *)&idp_ns,
m, (struct mbuf *)0) == 0)
goto bad;
sorwakeup(nsp->nsp_socket);
return;
bad:
m_freem(m);
}
idp_abort(nsp)
struct nspcb *nsp;
{
struct socket *so = nsp->nsp_socket;
ns_pcbdisconnect(nsp);
soisdisconnected(so);
}
/*
* Drop connection, reporting
* the specified error.
*/
struct nspcb *
idp_drop(nsp, errno)
register struct nspcb *nsp;
int errno;
{
struct socket *so = nsp->nsp_socket;
/*
* someday, in the xerox world
* we will generate error protocol packets
* announcing that the socket has gone away.
*/
/*if (TCPS_HAVERCVDSYN(tp->t_state)) {
tp->t_state = TCPS_CLOSED;
(void) tcp_output(tp);
}*/
so->so_error = errno;
ns_pcbdisconnect(nsp);
soisdisconnected(so);
}
int noIdpRoute;
idp_output(nsp, m0)
struct nspcb *nsp;
struct mbuf *m0;
{
register struct mbuf *m;
register struct idp *idp;
register struct socket *so;
register int len;
register struct route *ro;
struct mbuf *mprev;
extern int idpcksum;
len = m_length(m0, &mprev);
/*
* Make sure packet is actually of even length.
*/
if (len & 1) {
m = mprev;
if ((m->m_flags & M_EXT) == 0 &&
(m->m_len + m->m_data < &m->m_dat[MLEN])) {
m->m_len++;
} else {
struct mbuf *m1 = m_get(M_DONTWAIT, MT_DATA);
if (m1 == 0) {
m_freem(m0);
return (ENOBUFS);
}
m1->m_len = 1;
* mtod(m1, char *) = 0;
m->m_next = m1;
}
m0->m_pkthdr.len++;
}
/*
* Fill in mbuf with extended IDP header
* and addresses and length put into network format.
*/
m = m0;
if (nsp->nsp_flags & NSP_RAWOUT) {
idp = mtod(m, struct idp *);
} else {
M_PREPEND(m, sizeof (struct idp), M_DONTWAIT);
if (m == 0)
return (ENOBUFS);
idp = mtod(m, struct idp *);
idp->idp_tc = 0;
idp->idp_pt = nsp->nsp_dpt;
idp->idp_sna = nsp->nsp_laddr;
idp->idp_dna = nsp->nsp_faddr;
len += sizeof (struct idp);
}
idp->idp_len = htons((u_short)len);
if (idpcksum) {
idp->idp_sum = 0;
len = ((len - 1) | 1) + 1;
idp->idp_sum = ns_cksum(m, len);
} else
idp->idp_sum = 0xffff;
/*
* Output datagram.
*/
so = nsp->nsp_socket;
if (so->so_options & SO_DONTROUTE)
return (ns_output(m, (struct route *)0,
(so->so_options & SO_BROADCAST) | NS_ROUTETOIF));
/*
* Use cached route for previous datagram if
* possible. If the previous net was the same
* and the interface was a broadcast medium, or
* if the previous destination was identical,
* then we are ok.
*
* NB: We don't handle broadcasts because that
* would require 3 subroutine calls.
*/
ro = &nsp->nsp_route;
#ifdef ancient_history
/*
* I think that this will all be handled in ns_pcbconnect!
*/
if (ro->ro_rt) {
if(ns_neteq(nsp->nsp_lastdst, idp->idp_dna)) {
/*
* This assumes we have no GH type routes
*/
if (ro->ro_rt->rt_flags & RTF_HOST) {
if (!ns_hosteq(nsp->nsp_lastdst, idp->idp_dna))
goto re_route;
}
if ((ro->ro_rt->rt_flags & RTF_GATEWAY) == 0) {
register struct ns_addr *dst =
&satons_addr(ro->ro_dst);
dst->x_host = idp->idp_dna.x_host;
}
/*
* Otherwise, we go through the same gateway
* and dst is already set up.
*/
} else {
re_route:
RTFREE(ro->ro_rt);
ro->ro_rt = (struct rtentry *)0;
}
}
nsp->nsp_lastdst = idp->idp_dna;
#endif /* ancient_history */
if (noIdpRoute) ro = 0;
return (ns_output(m, ro, so->so_options & SO_BROADCAST));
}
/* ARGSUSED */
idp_ctloutput(req, so, level, name, value)
int req, level;
struct socket *so;
int name;
struct mbuf **value;
{
register struct mbuf *m;
struct nspcb *nsp = sotonspcb(so);
int mask, error = 0;
extern long ns_pexseq;
if (nsp == NULL)
return (EINVAL);
switch (req) {
case PRCO_GETOPT:
if (value==NULL)
return (EINVAL);
m = m_get(M_DONTWAIT, MT_DATA);
if (m==NULL)
return (ENOBUFS);
switch (name) {
case SO_ALL_PACKETS:
mask = NSP_ALL_PACKETS;
goto get_flags;
case SO_HEADERS_ON_INPUT:
mask = NSP_RAWIN;
goto get_flags;
case SO_HEADERS_ON_OUTPUT:
mask = NSP_RAWOUT;
get_flags:
m->m_len = sizeof(short);
*mtod(m, short *) = nsp->nsp_flags & mask;
break;
case SO_DEFAULT_HEADERS:
m->m_len = sizeof(struct idp);
{
register struct idp *idp = mtod(m, struct idp *);
idp->idp_len = 0;
idp->idp_sum = 0;
idp->idp_tc = 0;
idp->idp_pt = nsp->nsp_dpt;
idp->idp_dna = nsp->nsp_faddr;
idp->idp_sna = nsp->nsp_laddr;
}
break;
case SO_SEQNO:
m->m_len = sizeof(long);
*mtod(m, long *) = ns_pexseq++;
break;
default:
error = EINVAL;
}
*value = m;
break;
case PRCO_SETOPT:
switch (name) {
int *ok;
case SO_ALL_PACKETS:
mask = NSP_ALL_PACKETS;
goto set_head;
case SO_HEADERS_ON_INPUT:
mask = NSP_RAWIN;
goto set_head;
case SO_HEADERS_ON_OUTPUT:
mask = NSP_RAWOUT;
set_head:
if (value && *value) {
ok = mtod(*value, int *);
if (*ok)
nsp->nsp_flags |= mask;
else
nsp->nsp_flags &= ~mask;
} else error = EINVAL;
break;
case SO_DEFAULT_HEADERS:
{
register struct idp *idp
= mtod(*value, struct idp *);
nsp->nsp_dpt = idp->idp_pt;
}
break;
#ifdef NSIP
case SO_NSIP_ROUTE:
error = nsip_route(*value);
break;
#endif /* NSIP */
default:
error = EINVAL;
}
if (value && *value)
m_freem(*value);
break;
}
return (error);
}
/*ARGSUSED*/
idp_usrreq(so, req, m, nam, control)
struct socket *so;
int req;
struct mbuf *m, *nam, *control;
{
struct nspcb *nsp = sotonspcb(so);
int error = 0;
if (req == PRU_CONTROL)
return (ns_control(so, (int)m, (caddr_t)nam,
(struct ifnet *)control));
if (control && control->m_len) {
error = EINVAL;
goto release;
}
if (nsp == NULL && req != PRU_ATTACH) {
error = EINVAL;
goto release;
}
switch (req) {
case PRU_ATTACH:
if (nsp != NULL) {
error = EINVAL;
break;
}
error = ns_pcballoc(so, &nspcb);
if (error)
break;
error = soreserve(so, (u_long) 2048, (u_long) 2048);
if (error)
break;
break;
case PRU_DETACH:
if (nsp == NULL) {
error = ENOTCONN;
break;
}
ns_pcbdetach(nsp);
break;
case PRU_BIND:
error = ns_pcbbind(nsp, nam);
break;
case PRU_LISTEN:
error = EOPNOTSUPP;
break;
case PRU_CONNECT:
if (!ns_nullhost(nsp->nsp_faddr)) {
error = EISCONN;
break;
}
error = ns_pcbconnect(nsp, nam);
if (error == 0)
soisconnected(so);
break;
case PRU_CONNECT2:
error = EOPNOTSUPP;
break;
case PRU_ACCEPT:
error = EOPNOTSUPP;
break;
case PRU_DISCONNECT:
if (ns_nullhost(nsp->nsp_faddr)) {
error = ENOTCONN;
break;
}
ns_pcbdisconnect(nsp);
soisdisconnected(so);
break;
case PRU_SHUTDOWN:
socantsendmore(so);
break;
case PRU_SEND:
{
struct ns_addr laddr;
int s;
if (nam) {
laddr = nsp->nsp_laddr;
if (!ns_nullhost(nsp->nsp_faddr)) {
error = EISCONN;
break;
}
/*
* Must block input while temporarily connected.
*/
s = splnet();
error = ns_pcbconnect(nsp, nam);
if (error) {
splx(s);
break;
}
} else {
if (ns_nullhost(nsp->nsp_faddr)) {
error = ENOTCONN;
break;
}
}
error = idp_output(nsp, m);
m = NULL;
if (nam) {
ns_pcbdisconnect(nsp);
splx(s);
nsp->nsp_laddr.x_host = laddr.x_host;
nsp->nsp_laddr.x_port = laddr.x_port;
}
}
break;
case PRU_ABORT:
ns_pcbdetach(nsp);
sotryfree(so);
soisdisconnected(so); /* XXX huh, called after sofree()? */
break;
case PRU_SOCKADDR:
ns_setsockaddr(nsp, nam);
break;
case PRU_PEERADDR:
ns_setpeeraddr(nsp, nam);
break;
case PRU_SENSE:
/*
* stat: don't bother with a blocksize.
*/
return (0);
case PRU_SENDOOB:
case PRU_FASTTIMO:
case PRU_SLOWTIMO:
case PRU_PROTORCV:
case PRU_PROTOSEND:
error = EOPNOTSUPP;
break;
case PRU_CONTROL:
case PRU_RCVD:
case PRU_RCVOOB:
return (EOPNOTSUPP); /* do not free mbuf's */
default:
panic("idp_usrreq");
}
release:
if (control != NULL)
m_freem(control);
if (m != NULL)
m_freem(m);
return (error);
}
/*ARGSUSED*/
idp_raw_usrreq(so, req, m, nam, control)
struct socket *so;
int req;
struct mbuf *m, *nam, *control;
{
int error = 0;
struct nspcb *nsp = sotonspcb(so);
extern struct nspcb nsrawpcb;
switch (req) {
case PRU_ATTACH:
if (!(so->so_state & SS_PRIV) || (nsp != NULL)) {
error = EINVAL;
break;
}
error = ns_pcballoc(so, &nsrawpcb);
if (error)
break;
error = soreserve(so, (u_long) 2048, (u_long) 2048);
if (error)
break;
nsp = sotonspcb(so);
nsp->nsp_faddr.x_host = ns_broadhost;
nsp->nsp_flags = NSP_RAWIN | NSP_RAWOUT;
break;
default:
error = idp_usrreq(so, req, m, nam, control);
}
return (error);
}

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)idp_var.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_IDP_VAR_H_
#define _NETNS_IDP_VAR_H_
/*
* IDP Kernel Structures and Variables
*/
struct idpstat {
int idps_badsum; /* checksum bad */
int idps_tooshort; /* packet too short */
int idps_toosmall; /* not enough data */
int idps_badhlen; /* ip header length < data size */
int idps_badlen; /* ip length < ip header length */
};
#ifdef _KERNEL
struct idpstat idpstat;
#endif
#endif

View File

@ -1,370 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)ns.c 8.2 (Berkeley) 11/15/93
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/ioctl.h>
#include <sys/protosw.h>
#include <sys/errno.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <net/if.h>
#include <net/route.h>
#include <netns/ns.h>
#include <netns/ns_if.h>
#ifdef NS
struct ns_ifaddr *ns_ifaddr;
int ns_interfaces;
extern struct sockaddr_ns ns_netmask, ns_hostmask;
/*
* Generic internet control operations (ioctl's).
*/
/* ARGSUSED */
ns_control(so, cmd, data, ifp)
struct socket *so;
int cmd;
caddr_t data;
register struct ifnet *ifp;
{
register struct ifreq *ifr = (struct ifreq *)data;
register struct ns_aliasreq *ifra = (struct ns_aliasreq *)data;
register struct ns_ifaddr *ia;
struct ifaddr *ifa;
struct ns_ifaddr *oia;
int error, dstIsNew, hostIsNew;
/*
* Find address for this interface, if it exists.
*/
if (ifp == 0)
return (EADDRNOTAVAIL);
for (ia = ns_ifaddr; ia; ia = ia->ia_next)
if (ia->ia_ifp == ifp)
break;
switch (cmd) {
case SIOCGIFADDR:
if (ia == (struct ns_ifaddr *)0)
return (EADDRNOTAVAIL);
*(struct sockaddr_ns *)&ifr->ifr_addr = ia->ia_addr;
return (0);
case SIOCGIFBRDADDR:
if (ia == (struct ns_ifaddr *)0)
return (EADDRNOTAVAIL);
if ((ifp->if_flags & IFF_BROADCAST) == 0)
return (EINVAL);
*(struct sockaddr_ns *)&ifr->ifr_dstaddr = ia->ia_broadaddr;
return (0);
case SIOCGIFDSTADDR:
if (ia == (struct ns_ifaddr *)0)
return (EADDRNOTAVAIL);
if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
return (EINVAL);
*(struct sockaddr_ns *)&ifr->ifr_dstaddr = ia->ia_dstaddr;
return (0);
}
if ((so->so_state & SS_PRIV) == 0)
return (EPERM);
switch (cmd) {
case SIOCAIFADDR:
case SIOCDIFADDR:
if (ifra->ifra_addr.sns_family == AF_NS)
for (oia = ia; ia; ia = ia->ia_next) {
if (ia->ia_ifp == ifp &&
ns_neteq(ia->ia_addr.sns_addr,
ifra->ifra_addr.sns_addr))
break;
}
if (cmd == SIOCDIFADDR && ia == 0)
return (EADDRNOTAVAIL);
/* FALLTHROUGH */
case SIOCSIFADDR:
case SIOCSIFDSTADDR:
if (ia == (struct ns_ifaddr *)0) {
oia = (struct ns_ifaddr *)
malloc(sizeof *ia, M_IFADDR, M_WAITOK);
if (oia == (struct ns_ifaddr *)NULL)
return (ENOBUFS);
bzero((caddr_t)oia, sizeof(*oia));
if (ia = ns_ifaddr) {
for ( ; ia->ia_next; ia = ia->ia_next)
;
ia->ia_next = oia;
} else
ns_ifaddr = oia;
ia = oia;
if (ifa = ifp->if_addrlist) {
for ( ; ifa->ifa_next; ifa = ifa->ifa_next)
;
ifa->ifa_next = (struct ifaddr *) ia;
} else
ifp->if_addrlist = (struct ifaddr *) ia;
ia->ia_ifp = ifp;
ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
ia->ia_ifa.ifa_netmask =
(struct sockaddr *)&ns_netmask;
ia->ia_ifa.ifa_dstaddr =
(struct sockaddr *)&ia->ia_dstaddr;
if (ifp->if_flags & IFF_BROADCAST) {
ia->ia_broadaddr.sns_family = AF_NS;
ia->ia_broadaddr.sns_len = sizeof(ia->ia_addr);
ia->ia_broadaddr.sns_addr.x_host = ns_broadhost;
}
ns_interfaces++;
}
}
switch (cmd) {
int error;
case SIOCSIFDSTADDR:
if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
return (EINVAL);
if (ia->ia_flags & IFA_ROUTE) {
rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
ia->ia_flags &= ~IFA_ROUTE;
}
if (ifp->if_ioctl) {
error = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR, ia);
if (error)
return (error);
}
*(struct sockaddr *)&ia->ia_dstaddr = ifr->ifr_dstaddr;
return (0);
case SIOCSIFADDR:
return (ns_ifinit(ifp, ia,
(struct sockaddr_ns *)&ifr->ifr_addr, 1));
case SIOCDIFADDR:
ns_ifscrub(ifp, ia);
if ((ifa = ifp->if_addrlist) == (struct ifaddr *)ia)
ifp->if_addrlist = ifa->ifa_next;
else {
while (ifa->ifa_next &&
(ifa->ifa_next != (struct ifaddr *)ia))
ifa = ifa->ifa_next;
if (ifa->ifa_next)
ifa->ifa_next = ((struct ifaddr *)ia)->ifa_next;
else
printf("Couldn't unlink nsifaddr from ifp\n");
}
oia = ia;
if (oia == (ia = ns_ifaddr)) {
ns_ifaddr = ia->ia_next;
} else {
while (ia->ia_next && (ia->ia_next != oia)) {
ia = ia->ia_next;
}
if (ia->ia_next)
ia->ia_next = oia->ia_next;
else
printf("Didn't unlink nsifadr from list\n");
}
IFAFREE((&oia->ia_ifa));
if (0 == --ns_interfaces) {
/*
* We reset to virginity and start all over again
*/
ns_thishost = ns_zerohost;
}
return (0);
case SIOCAIFADDR:
dstIsNew = 0; hostIsNew = 1;
if (ia->ia_addr.sns_family == AF_NS) {
if (ifra->ifra_addr.sns_len == 0) {
ifra->ifra_addr = ia->ia_addr;
hostIsNew = 0;
} else if (ns_neteq(ifra->ifra_addr.sns_addr,
ia->ia_addr.sns_addr))
hostIsNew = 0;
}
if ((ifp->if_flags & IFF_POINTOPOINT) &&
(ifra->ifra_dstaddr.sns_family == AF_NS)) {
if (hostIsNew == 0)
ns_ifscrub(ifp, ia);
ia->ia_dstaddr = ifra->ifra_dstaddr;
dstIsNew = 1;
}
if (ifra->ifra_addr.sns_family == AF_NS &&
(hostIsNew || dstIsNew))
error = ns_ifinit(ifp, ia, &ifra->ifra_addr, 0);
return (error);
default:
if (ifp->if_ioctl == 0)
return (EOPNOTSUPP);
return ((*ifp->if_ioctl)(ifp, cmd, data));
}
}
/*
* Delete any previous route for an old address.
*/
ns_ifscrub(ifp, ia)
register struct ifnet *ifp;
register struct ns_ifaddr *ia;
{
if (ia->ia_flags & IFA_ROUTE) {
if (ifp->if_flags & IFF_POINTOPOINT) {
rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
} else
rtinit(&(ia->ia_ifa), (int)RTM_DELETE, 0);
ia->ia_flags &= ~IFA_ROUTE;
}
}
/*
* Initialize an interface's internet address
* and routing table entry.
*/
ns_ifinit(ifp, ia, sns, scrub)
register struct ifnet *ifp;
register struct ns_ifaddr *ia;
register struct sockaddr_ns *sns;
{
struct sockaddr_ns oldaddr;
register union ns_host *h = &ia->ia_addr.sns_addr.x_host;
int s = splimp(), error;
/*
* Set up new addresses.
*/
oldaddr = ia->ia_addr;
ia->ia_addr = *sns;
/*
* The convention we shall adopt for naming is that
* a supplied address of zero means that "we don't care".
* if there is a single interface, use the address of that
* interface as our 6 byte host address.
* if there are multiple interfaces, use any address already
* used.
*
* Give the interface a chance to initialize
* if this is its first address,
* and to validate the address if necessary.
*/
if (ns_hosteqnh(ns_thishost, ns_zerohost)) {
if (ifp->if_ioctl &&
(error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, ia))) {
ia->ia_addr = oldaddr;
splx(s);
return (error);
}
ns_thishost = *h;
} else if (ns_hosteqnh(sns->sns_addr.x_host, ns_zerohost)
|| ns_hosteqnh(sns->sns_addr.x_host, ns_thishost)) {
*h = ns_thishost;
if (ifp->if_ioctl &&
(error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, ia))) {
ia->ia_addr = oldaddr;
splx(s);
return (error);
}
if (!ns_hosteqnh(ns_thishost,*h)) {
ia->ia_addr = oldaddr;
splx(s);
return (EINVAL);
}
} else {
ia->ia_addr = oldaddr;
splx(s);
return (EINVAL);
}
ia->ia_ifa.ifa_metric = ifp->if_metric;
/*
* Add route for the network.
*/
if (scrub) {
ia->ia_ifa.ifa_addr = (struct sockaddr *)&oldaddr;
ns_ifscrub(ifp, ia);
ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
}
if (ifp->if_flags & IFF_POINTOPOINT)
rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
else {
ia->ia_broadaddr.sns_addr.x_net = ia->ia_addr.sns_addr.x_net;
rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_UP);
}
ia->ia_flags |= IFA_ROUTE;
return (0);
}
/*
* Return address info for specified internet network.
*/
struct ns_ifaddr *
ns_iaonnetof(dst)
register struct ns_addr *dst;
{
register struct ns_ifaddr *ia;
register struct ns_addr *compare;
register struct ifnet *ifp;
struct ns_ifaddr *ia_maybe = 0;
union ns_net net = dst->x_net;
for (ia = ns_ifaddr; ia; ia = ia->ia_next) {
if (ifp = ia->ia_ifp) {
if (ifp->if_flags & IFF_POINTOPOINT) {
compare = &satons_addr(ia->ia_dstaddr);
if (ns_hosteq(*dst, *compare))
return (ia);
if (ns_neteqnn(net, ia->ia_addr.sns_addr.x_net))
ia_maybe = ia;
} else {
if (ns_neteqnn(net, ia->ia_addr.sns_addr.x_net))
return (ia);
}
}
}
return (ia_maybe);
}
#endif

View File

@ -1,154 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)ns.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_NS_H_
#define _NETNS_NS_H_
/*
* Constants and Structures defined by the Xerox Network Software
* per "Internet Transport Protocols", XSIS 028112, December 1981
*/
/*
* Protocols
*/
#define NSPROTO_RI 1 /* Routing Information */
#define NSPROTO_ECHO 2 /* Echo Protocol */
#define NSPROTO_ERROR 3 /* Error Protocol */
#define NSPROTO_PE 4 /* Packet Exchange */
#define NSPROTO_SPP 5 /* Sequenced Packet */
#define NSPROTO_RAW 255 /* Placemarker*/
#define NSPROTO_MAX 256 /* Placemarker*/
/*
* Port/Socket numbers: network standard functions
*/
#define NSPORT_RI 1 /* Routing Information */
#define NSPORT_ECHO 2 /* Echo */
#define NSPORT_RE 3 /* Router Error */
/*
* Ports < NSPORT_RESERVED are reserved for priveleged
* processes (e.g. root).
*/
#define NSPORT_RESERVED 3000
/* flags passed to ns_output as last parameter */
#define NS_FORWARDING 0x1 /* most of idp header exists */
#define NS_ROUTETOIF 0x10 /* same as SO_DONTROUTE */
#define NS_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
#define NS_MAXHOPS 15
/* flags passed to get/set socket option */
#define SO_HEADERS_ON_INPUT 1
#define SO_HEADERS_ON_OUTPUT 2
#define SO_DEFAULT_HEADERS 3
#define SO_LAST_HEADER 4
#define SO_NSIP_ROUTE 5
#define SO_SEQNO 6
#define SO_ALL_PACKETS 7
#define SO_MTU 8
/*
* NS addressing
*/
union ns_host {
u_char c_host[6];
u_short s_host[3];
};
union ns_net {
u_char c_net[4];
u_short s_net[2];
};
union ns_net_u {
union ns_net net_e;
u_long long_e;
};
struct ns_addr {
union ns_net x_net;
union ns_host x_host;
u_short x_port;
};
/*
* Socket address, Xerox style
*/
struct sockaddr_ns {
u_char sns_len;
u_char sns_family;
struct ns_addr sns_addr;
char sns_zero[2];
};
#define sns_port sns_addr.x_port
#define ns_neteqnn(a,b) (((a).s_net[0]==(b).s_net[0]) && \
((a).s_net[1]==(b).s_net[1]))
#define ns_neteq(a,b) ns_neteqnn((a).x_net, (b).x_net)
#define satons_addr(sa) (((struct sockaddr_ns *)&(sa))->sns_addr)
#define ns_hosteqnh(s,t) ((s).s_host[0] == (t).s_host[0] && \
(s).s_host[1] == (t).s_host[1] && (s).s_host[2] == (t).s_host[2])
#define ns_hosteq(s,t) (ns_hosteqnh((s).x_host,(t).x_host))
#define ns_nullhost(x) (((x).x_host.s_host[0]==0) && \
((x).x_host.s_host[1]==0) && ((x).x_host.s_host[2]==0))
#ifdef _KERNEL
extern struct domain nsdomain;
extern union ns_host ns_thishost;
extern union ns_host ns_zerohost;
extern union ns_host ns_broadhost;
extern union ns_net ns_zeronet;
extern union ns_net ns_broadnet;
u_short ns_cksum(void);
#else
#include <sys/cdefs.h>
__BEGIN_DECLS
extern struct ns_addr ns_addr(const char *);
extern char *ns_ntoa(struct ns_addr);
__END_DECLS
#endif
#endif

View File

@ -1,205 +0,0 @@
/*
* Copyright (c) 1982, 1992, 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.
*
* @(#)ns_cksum.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/mbuf.h>
/*
* Checksum routine for Network Systems Protocol Packets (Big-Endian).
*
* This routine is very heavily used in the network
* code and should be modified for each CPU to be as fast as possible.
*/
#define ADDCARRY(x) { if ((x) > 65535) (x) -= 65535; }
#define FOLD(x) {l_util.l = (x); (x) = l_util.s[0] + l_util.s[1]; ADDCARRY(x);}
u_short
ns_cksum(m, len)
register struct mbuf *m;
register int len;
{
register u_short *w;
register int sum = 0;
register int mlen = 0;
register int sum2;
union {
u_short s[2];
long l;
} l_util;
for (;m && len; m = m->m_next) {
if (m->m_len == 0)
continue;
/*
* Each trip around loop adds in
* word from one mbuf segment.
*/
w = mtod(m, u_short *);
if (mlen == -1) {
/*
* There is a byte left from the last segment;
* ones-complement add it into the checksum.
*/
#if BYTE_ORDER == BIG_ENDIAN
sum += *(u_char *)w;
#else
sum += *(u_char *)w << 8;
#endif
sum += sum;
w = (u_short *)(1 + (char *)w);
mlen = m->m_len - 1;
len--;
FOLD(sum);
} else
mlen = m->m_len;
if (len < mlen)
mlen = len;
len -= mlen;
/*
* We can do a 16 bit ones complement sum using
* 32 bit arithmetic registers for adding,
* with carries from the low added
* into the high (by normal carry-chaining)
* so long as we fold back before 16 carries have occured.
*/
if (1 & (int) w)
goto uuuuglyy;
#ifndef TINY
/* -DTINY reduces the size from 1250 to 550, but slows it down by 22% */
while ((mlen -= 32) >= 0) {
sum += w[0]; sum += sum; sum += w[1]; sum += sum;
sum += w[2]; sum += sum; sum += w[3]; sum += sum;
sum += w[4]; sum += sum; sum += w[5]; sum += sum;
sum += w[6]; sum += sum; sum += w[7]; sum += sum;
FOLD(sum);
sum += w[8]; sum += sum; sum += w[9]; sum += sum;
sum += w[10]; sum += sum; sum += w[11]; sum += sum;
sum += w[12]; sum += sum; sum += w[13]; sum += sum;
sum += w[14]; sum += sum; sum += w[15]; sum += sum;
FOLD(sum);
w += 16;
}
mlen += 32;
#endif
while ((mlen -= 8) >= 0) {
sum += w[0]; sum += sum; sum += w[1]; sum += sum;
sum += w[2]; sum += sum; sum += w[3]; sum += sum;
FOLD(sum);
w += 4;
}
mlen += 8;
while ((mlen -= 2) >= 0) {
sum += *w++; sum += sum;
}
goto commoncase;
uuuuglyy:
#if BYTE_ORDER == BIG_ENDIAN
#define ww(n) (((u_char *)w)[n + n + 1])
#define vv(n) (((u_char *)w)[n + n])
#else
#if BYTE_ORDER == LITTLE_ENDIAN
#define vv(n) (((u_char *)w)[n + n + 1])
#define ww(n) (((u_char *)w)[n + n])
#endif
#endif
sum2 = 0;
#ifndef TINY
while ((mlen -= 32) >= 0) {
sum += ww(0); sum += sum; sum += ww(1); sum += sum;
sum += ww(2); sum += sum; sum += ww(3); sum += sum;
sum += ww(4); sum += sum; sum += ww(5); sum += sum;
sum += ww(6); sum += sum; sum += ww(7); sum += sum;
FOLD(sum);
sum += ww(8); sum += sum; sum += ww(9); sum += sum;
sum += ww(10); sum += sum; sum += ww(11); sum += sum;
sum += ww(12); sum += sum; sum += ww(13); sum += sum;
sum += ww(14); sum += sum; sum += ww(15); sum += sum;
FOLD(sum);
sum2 += vv(0); sum2 += sum2; sum2 += vv(1); sum2 += sum2;
sum2 += vv(2); sum2 += sum2; sum2 += vv(3); sum2 += sum2;
sum2 += vv(4); sum2 += sum2; sum2 += vv(5); sum2 += sum2;
sum2 += vv(6); sum2 += sum2; sum2 += vv(7); sum2 += sum2;
FOLD(sum2);
sum2 += vv(8); sum2 += sum2; sum2 += vv(9); sum2 += sum2;
sum2 += vv(10); sum2 += sum2; sum2 += vv(11); sum2 += sum2;
sum2 += vv(12); sum2 += sum2; sum2 += vv(13); sum2 += sum2;
sum2 += vv(14); sum2 += sum2; sum2 += vv(15); sum2 += sum2;
FOLD(sum2);
w += 16;
}
mlen += 32;
#endif
while ((mlen -= 8) >= 0) {
sum += ww(0); sum += sum; sum += ww(1); sum += sum;
sum += ww(2); sum += sum; sum += ww(3); sum += sum;
FOLD(sum);
sum2 += vv(0); sum2 += sum2; sum2 += vv(1); sum2 += sum2;
sum2 += vv(2); sum2 += sum2; sum2 += vv(3); sum2 += sum2;
FOLD(sum2);
w += 4;
}
mlen += 8;
while ((mlen -= 2) >= 0) {
sum += ww(0); sum += sum;
sum2 += vv(0); sum2 += sum2;
w++;
}
sum += (sum2 << 8);
commoncase:
if (mlen == -1) {
#if BYTE_ORDER == BIG_ENDIAN
sum += *(u_char *)w << 8;
#else
sum += *(u_char *)w;
#endif
}
FOLD(sum);
}
if (mlen == -1) {
/* We had an odd number of bytes to sum; assume a garbage
byte of zero and clean up */
sum += sum;
FOLD(sum);
}
/*
* sum has already been kept to low sixteen bits.
* just examine result and exit.
*/
if(sum==0xffff) sum = 0;
return (sum);
}

View File

@ -1,324 +0,0 @@
/*
* Copyright (c) 1984, 1988, 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.
*
* @(#)ns_error.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <net/route.h>
#include <netns/ns.h>
#include <netns/ns_pcb.h>
#include <netns/idp.h>
#include <netns/ns_error.h>
#ifdef lint
#define NS_ERRPRINTFS 1
#endif
#ifdef NS_ERRPRINTFS
/*
* NS_ERR routines: error generation, receive packet processing, and
* routines to turnaround packets back to the originator.
*/
int ns_errprintfs = 0;
#endif
ns_err_x(c)
{
register u_short *w, *lim, *base = ns_errstat.ns_es_codes;
u_short x = c;
/*
* zero is a legit error code, handle specially
*/
if (x == 0)
return (0);
lim = base + NS_ERR_MAX - 1;
for (w = base + 1; w < lim; w++) {
if (*w == 0)
*w = x;
if (*w == x)
break;
}
return (w - base);
}
/*
* Generate an error packet of type error
* in response to bad packet.
*/
ns_error(om, type, param)
struct mbuf *om;
int type;
{
register struct ns_epidp *ep;
struct mbuf *m;
struct idp *nip;
register struct idp *oip = mtod(om, struct idp *);
extern int idpcksum;
/*
* If this packet was sent to the echo port,
* and nobody was there, just echo it.
* (Yes, this is a wart!)
*/
if (type == NS_ERR_NOSOCK &&
oip->idp_dna.x_port == htons(2) &&
(type = ns_echo(om))==0)
return;
#ifdef NS_ERRPRINTFS
if (ns_errprintfs)
printf("ns_err_error(%x, %d, %d)\n", oip, type, param);
#endif
/*
* Don't Generate error packets in response to multicasts.
*/
if (oip->idp_dna.x_host.c_host[0] & 1)
goto freeit;
ns_errstat.ns_es_error++;
/*
* Make sure that the old IDP packet had 30 bytes of data to return;
* if not, don't bother. Also don't EVER error if the old
* packet protocol was NS_ERR.
*/
if (oip->idp_len < sizeof(struct idp)) {
ns_errstat.ns_es_oldshort++;
goto freeit;
}
if (oip->idp_pt == NSPROTO_ERROR) {
ns_errstat.ns_es_oldns_err++;
goto freeit;
}
/*
* First, formulate ns_err message
*/
m = m_gethdr(M_DONTWAIT, MT_HEADER);
if (m == NULL)
goto freeit;
m->m_len = sizeof(*ep);
MH_ALIGN(m, m->m_len);
ep = mtod(m, struct ns_epidp *);
if ((u_int)type > NS_ERR_TOO_BIG)
panic("ns_err_error");
ns_errstat.ns_es_outhist[ns_err_x(type)]++;
ep->ns_ep_errp.ns_err_num = htons((u_short)type);
ep->ns_ep_errp.ns_err_param = htons((u_short)param);
bcopy((caddr_t)oip, (caddr_t)&ep->ns_ep_errp.ns_err_idp, 42);
nip = &ep->ns_ep_idp;
nip->idp_len = sizeof(*ep);
nip->idp_len = htons((u_short)nip->idp_len);
nip->idp_pt = NSPROTO_ERROR;
nip->idp_tc = 0;
nip->idp_dna = oip->idp_sna;
nip->idp_sna = oip->idp_dna;
if (idpcksum) {
nip->idp_sum = 0;
nip->idp_sum = ns_cksum(m, sizeof(*ep));
} else
nip->idp_sum = 0xffff;
(void) ns_output(m, (struct route *)0, 0);
freeit:
m_freem(om);
}
ns_printhost(p)
register struct ns_addr *p;
{
printf("<net:%x%x,host:%x%x%x,port:%x>",
p->x_net.s_net[0],
p->x_net.s_net[1],
p->x_host.s_host[0],
p->x_host.s_host[1],
p->x_host.s_host[2],
p->x_port);
}
/*
* Process a received NS_ERR message.
*/
ns_err_input(m)
struct mbuf *m;
{
register struct ns_errp *ep;
register struct ns_epidp *epidp = mtod(m, struct ns_epidp *);
register int i;
int type, code, param;
/*
* Locate ns_err structure in mbuf, and check
* that not corrupted and of at least minimum length.
*/
#ifdef NS_ERRPRINTFS
if (ns_errprintfs) {
printf("ns_err_input from ");
ns_printhost(&epidp->ns_ep_idp.idp_sna);
printf("len %d\n", ntohs(epidp->ns_ep_idp.idp_len));
}
#endif
i = sizeof (struct ns_epidp);
if (((m->m_flags & M_EXT) || m->m_len < i) &&
(m = m_pullup(m, i)) == 0) {
ns_errstat.ns_es_tooshort++;
return;
}
ep = &(mtod(m, struct ns_epidp *)->ns_ep_errp);
type = ntohs(ep->ns_err_num);
param = ntohs(ep->ns_err_param);
ns_errstat.ns_es_inhist[ns_err_x(type)]++;
#ifdef NS_ERRPRINTFS
/*
* Message type specific processing.
*/
if (ns_errprintfs)
printf("ns_err_input, type %d param %d\n", type, param);
#endif
if (type >= NS_ERR_TOO_BIG) {
goto badcode;
}
ns_errstat.ns_es_outhist[ns_err_x(type)]++;
switch (type) {
case NS_ERR_UNREACH_HOST:
code = PRC_UNREACH_NET;
goto deliver;
case NS_ERR_TOO_OLD:
code = PRC_TIMXCEED_INTRANS;
goto deliver;
case NS_ERR_TOO_BIG:
code = PRC_MSGSIZE;
goto deliver;
case NS_ERR_FULLUP:
code = PRC_QUENCH;
goto deliver;
case NS_ERR_NOSOCK:
code = PRC_UNREACH_PORT;
goto deliver;
case NS_ERR_UNSPEC_T:
case NS_ERR_BADSUM_T:
case NS_ERR_BADSUM:
case NS_ERR_UNSPEC:
code = PRC_PARAMPROB;
goto deliver;
deliver:
/*
* Problem with datagram; advise higher level routines.
*/
#ifdef NS_ERRPRINTFS
if (ns_errprintfs)
printf("deliver to protocol %d\n",
ep->ns_err_idp.idp_pt);
#endif
switch(ep->ns_err_idp.idp_pt) {
case NSPROTO_SPP:
spp_ctlinput(code, (caddr_t)ep);
break;
default:
idp_ctlinput(code, (caddr_t)ep);
}
goto freeit;
default:
badcode:
ns_errstat.ns_es_badcode++;
goto freeit;
}
freeit:
m_freem(m);
}
#ifdef notdef
u_long
nstime()
{
int s = splclock();
u_long t;
t = (time.tv_sec % (24*60*60)) * 1000 + time.tv_usec / 1000;
splx(s);
return (htonl(t));
}
#endif
ns_echo(m)
struct mbuf *m;
{
register struct idp *idp = mtod(m, struct idp *);
register struct echo {
struct idp ec_idp;
u_short ec_op; /* Operation, 1 = request, 2 = reply */
} *ec = (struct echo *)idp;
struct ns_addr temp;
if (idp->idp_pt!=NSPROTO_ECHO) return(NS_ERR_NOSOCK);
if (ec->ec_op!=htons(1)) return(NS_ERR_UNSPEC);
ec->ec_op = htons(2);
temp = idp->idp_dna;
idp->idp_dna = idp->idp_sna;
idp->idp_sna = temp;
if (idp->idp_sum != 0xffff) {
idp->idp_sum = 0;
idp->idp_sum = ns_cksum(m,
(int)(((ntohs(idp->idp_len) - 1)|1)+1));
}
(void) ns_output(m, (struct route *)0, NS_FORWARDING);
return(0);
}

View File

@ -1,96 +0,0 @@
/*
* Copyright (c) 1984, 1988, 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.
*
* @(#)ns_error.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_NS_ERROR_H_
#define _NETNS_NS_ERROR_H_
/*
* Xerox NS error messages
*/
struct ns_errp {
u_short ns_err_num; /* Error Number */
u_short ns_err_param; /* Error Parameter */
struct idp ns_err_idp; /* Initial segment of offending
packet */
u_char ns_err_lev2[12]; /* at least this much higher
level protocol */
};
struct ns_epidp {
struct idp ns_ep_idp;
struct ns_errp ns_ep_errp;
};
#define NS_ERR_UNSPEC 0 /* Unspecified Error detected at dest. */
#define NS_ERR_BADSUM 1 /* Bad Checksum detected at dest */
#define NS_ERR_NOSOCK 2 /* Specified socket does not exist at dest*/
#define NS_ERR_FULLUP 3 /* Dest. refuses packet due to resource lim.*/
#define NS_ERR_UNSPEC_T 0x200 /* Unspec. Error occured before reaching dest*/
#define NS_ERR_BADSUM_T 0x201 /* Bad Checksum detected in transit */
#define NS_ERR_UNREACH_HOST 0x202 /* Dest cannot be reached from here*/
#define NS_ERR_TOO_OLD 0x203 /* Packet x'd 15 routers without delivery*/
#define NS_ERR_TOO_BIG 0x204 /* Packet too large to be forwarded through
some intermediate gateway. The error
parameter field contains the max packet
size that can be accommodated */
#define NS_ERR_MAX 20
/*
* Variables related to this implementation
* of the network systems error message protocol.
*/
struct ns_errstat {
/* statistics related to ns_err packets generated */
int ns_es_error; /* # of calls to ns_error */
int ns_es_oldshort; /* no error 'cuz old ip too short */
int ns_es_oldns_err; /* no error 'cuz old was ns_err */
int ns_es_outhist[NS_ERR_MAX];
/* statistics related to input messages processed */
int ns_es_badcode; /* ns_err_code out of range */
int ns_es_tooshort; /* packet < IDP_MINLEN */
int ns_es_checksum; /* bad checksum */
int ns_es_badlen; /* calculated bound mismatch */
int ns_es_reflect; /* number of responses */
int ns_es_inhist[NS_ERR_MAX];
u_short ns_es_codes[NS_ERR_MAX];/* which error code for outhist
since we might not know all */
};
#ifdef _KERNEL
struct ns_errstat ns_errstat;
#endif
#endif

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)ns_if.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_NS_IF_H_
#define _NETNS_NS_IF_H_
/*
* Interface address, xerox version. One of these structures
* is allocated for each interface with an internet address.
* The ifaddr structure contains the protocol-independent part
* of the structure and is assumed to be first.
*/
struct ns_ifaddr {
struct ifaddr ia_ifa; /* protocol-independent info */
#define ia_ifp ia_ifa.ifa_ifp
#define ia_flags ia_ifa.ifa_flags
struct ns_ifaddr *ia_next; /* next in list of xerox addresses */
struct sockaddr_ns ia_addr; /* reserve space for my address */
struct sockaddr_ns ia_dstaddr; /* space for my broadcast address */
#define ia_broadaddr ia_dstaddr
struct sockaddr_ns ia_netmask; /* space for my network mask */
};
struct ns_aliasreq {
char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
struct sockaddr_ns ifra_addr;
struct sockaddr_ns ifra_broadaddr;
#define ifra_dstaddr ifra_broadaddr
};
/*
* Given a pointer to an ns_ifaddr (ifaddr),
* return a pointer to the addr as a sockadd_ns.
*/
#define IA_SNS(ia) (&(((struct ns_ifaddr *)(ia))->ia_addr))
/* This is not the right place for this but where is? */
#define ETHERTYPE_NS 0x0600
#ifdef NSIP
struct nsip_req {
struct sockaddr rq_ns; /* must be ns format destination */
struct sockaddr rq_ip; /* must be ip format gateway */
short rq_flags;
};
#endif
#ifdef _KERNEL
extern struct ns_ifaddr *ns_ifaddr;
struct ns_ifaddr *ns_iaonnetof(void);
void nsintr(struct mbuf *);
#endif
#endif

View File

@ -1,483 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)ns_input.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/kernel.h>
#include <net/if.h>
#include <net/route.h>
#include <net/raw_cb.h>
#include <net/netisr.h>
#include <netns/ns.h>
#include <netns/ns_if.h>
#include <netns/ns_pcb.h>
#include <netns/idp.h>
#include <netns/idp_var.h>
#include <netns/ns_error.h>
/*
* NS initialization.
*/
union ns_host ns_thishost;
union ns_host ns_zerohost;
union ns_host ns_broadhost;
union ns_net ns_zeronet;
union ns_net ns_broadnet;
struct sockaddr_ns ns_netmask, ns_hostmask;
static u_short allones[] = {-1, -1, -1};
static struct ifqueue nsintrq;
struct nspcb nspcb;
struct nspcb nsrawpcb;
int nsqmaxlen = IFQ_MAXLEN;
int idpcksum = 1;
long ns_pexseq;
ns_init()
{
extern struct timeval time;
ns_broadhost = * (union ns_host *) allones;
ns_broadnet = * (union ns_net *) allones;
nspcb.nsp_next = nspcb.nsp_prev = &nspcb;
nsrawpcb.nsp_next = nsrawpcb.nsp_prev = &nsrawpcb;
ns_pexseq = time.tv_usec;
ns_netmask.sns_len = 6;
ns_netmask.sns_addr.x_net = ns_broadnet;
ns_hostmask.sns_len = 12;
ns_hostmask.sns_addr.x_net = ns_broadnet;
ns_hostmask.sns_addr.x_host = ns_broadhost;
nsintrq.ifq_maxlen = nsqmaxlen;
mtx_init(&nsintrq.ifq_mtx, "ns_inq", NULL, MTX_DEF);
netisr_register(NETISR_NS, nsintr, &nsintrq);
}
/*
* Idp input routine. Pass to next level.
*/
int nsintr_getpck = 0;
int nsintr_swtch = 0;
void
nsintr(struct mbuf *m)
{
register struct idp *idp;
register struct nspcb *nsp;
register int i;
int len, s, error;
char oddpacketp;
/*
* Get next datagram off input queue and get IDP header
* in first mbuf.
*/
nsintr_getpck++;
if ((m->m_flags & M_EXT || m->m_len < sizeof (struct idp)) &&
(m = m_pullup(m, sizeof (struct idp))) == 0) {
idpstat.idps_toosmall++;
return;
}
/*
* Give any raw listeners a crack at the packet
*/
for (nsp = nsrawpcb.nsp_next; nsp != &nsrawpcb; nsp = nsp->nsp_next) {
struct mbuf *m1 = m_copy(m, 0, (int)M_COPYALL);
if (m1) idp_input(m1, nsp);
}
idp = mtod(m, struct idp *);
len = ntohs(idp->idp_len);
if (oddpacketp = len & 1) {
len++; /* If this packet is of odd length,
preserve garbage byte for checksum */
}
/*
* Check that the amount of data in the buffers
* is as at least much as the IDP header would have us expect.
* Trim mbufs if longer than we expect.
* Drop packet if shorter than we expect.
*/
if (m->m_pkthdr.len < len) {
idpstat.idps_tooshort++;
goto bad;
}
if (m->m_pkthdr.len > len) {
if (m->m_len == m->m_pkthdr.len) {
m->m_len = len;
m->m_pkthdr.len = len;
} else
m_adj(m, len - m->m_pkthdr.len);
}
if (idpcksum && ((i = idp->idp_sum)!=0xffff)) {
idp->idp_sum = 0;
if (i != (idp->idp_sum = ns_cksum(m, len))) {
idpstat.idps_badsum++;
idp->idp_sum = i;
if (ns_hosteqnh(ns_thishost, idp->idp_dna.x_host))
error = NS_ERR_BADSUM;
else
error = NS_ERR_BADSUM_T;
ns_error(m, error, 0);
return;
}
}
/*
* Is this a directed broadcast?
*/
if (ns_hosteqnh(ns_broadhost,idp->idp_dna.x_host)) {
if ((!ns_neteq(idp->idp_dna, idp->idp_sna)) &&
(!ns_neteqnn(idp->idp_dna.x_net, ns_broadnet)) &&
(!ns_neteqnn(idp->idp_sna.x_net, ns_zeronet)) &&
(!ns_neteqnn(idp->idp_dna.x_net, ns_zeronet)) ) {
/*
* Look to see if I need to eat this packet.
* Algorithm is to forward all young packets
* and prematurely age any packets which will
* by physically broadcasted.
* Any very old packets eaten without forwarding
* would die anyway.
*
* Suggestion of Bill Nesheim, Cornell U.
*/
if (idp->idp_tc < NS_MAXHOPS) {
idp_forward(m);
return;
}
}
/*
* Is this our packet? If not, forward.
*/
} else if (!ns_hosteqnh(ns_thishost,idp->idp_dna.x_host)) {
idp_forward(m);
return;
}
/*
* Locate pcb for datagram.
*/
nsp = ns_pcblookup(&idp->idp_sna, idp->idp_dna.x_port, NS_WILDCARD);
/*
* Switch out to protocol's input routine.
*/
nsintr_swtch++;
if (nsp) {
if (oddpacketp) {
m_adj(m, -1);
}
if ((nsp->nsp_flags & NSP_ALL_PACKETS)==0)
switch (idp->idp_pt) {
case NSPROTO_SPP:
spp_input(m, nsp);
return;
case NSPROTO_ERROR:
ns_err_input(m);
return;
}
idp_input(m, nsp);
} else {
ns_error(m, NS_ERR_NOSOCK, 0);
}
return;
bad:
m_freem(m);
return;
}
u_char nsctlerrmap[PRC_NCMDS] = {
ECONNABORTED, ECONNABORTED, 0, 0,
0, 0, EHOSTDOWN, EHOSTUNREACH,
ENETUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
EMSGSIZE, 0, 0, 0,
0, 0, 0, 0
};
int idp_donosocks = 1;
idp_ctlinput(cmd, arg)
int cmd;
caddr_t arg;
{
struct ns_addr *ns;
struct nspcb *nsp;
struct ns_errp *errp;
int idp_abort();
extern struct nspcb *idp_drop();
int type;
if (cmd < 0 || cmd > PRC_NCMDS)
return;
if (nsctlerrmap[cmd] == 0)
return; /* XXX */
type = NS_ERR_UNREACH_HOST;
switch (cmd) {
struct sockaddr_ns *sns;
case PRC_IFDOWN:
case PRC_HOSTDEAD:
case PRC_HOSTUNREACH:
sns = (struct sockaddr_ns *)arg;
if (sns->sns_family != AF_NS)
return;
ns = &sns->sns_addr;
break;
default:
errp = (struct ns_errp *)arg;
ns = &errp->ns_err_idp.idp_dna;
type = errp->ns_err_num;
type = ntohs((u_short)type);
}
switch (type) {
case NS_ERR_UNREACH_HOST:
ns_pcbnotify(ns, (int)nsctlerrmap[cmd], idp_abort, (long)0);
break;
case NS_ERR_NOSOCK:
nsp = ns_pcblookup(ns, errp->ns_err_idp.idp_sna.x_port,
NS_WILDCARD);
if(nsp && idp_donosocks && ! ns_nullhost(nsp->nsp_faddr))
(void) idp_drop(nsp, (int)nsctlerrmap[cmd]);
}
}
int idpprintfs = 0;
int idpforwarding = 1;
/*
* Forward a packet. If some error occurs return the sender
* an error packet. Note we can't always generate a meaningful
* error message because the NS errors don't have a large enough repetoire
* of codes and types.
*/
struct route idp_droute;
struct route idp_sroute;
idp_forward(m)
struct mbuf *m;
{
register struct idp *idp = mtod(m, struct idp *);
register int error, type, code;
struct mbuf *mcopy = NULL;
int agedelta = 1;
int flags = NS_FORWARDING;
int ok_there = 0;
int ok_back = 0;
if (idpprintfs) {
printf("forward: src ");
ns_printhost(&idp->idp_sna);
printf(", dst ");
ns_printhost(&idp->idp_dna);
printf("hop count %d\n", idp->idp_tc);
}
if (idpforwarding == 0) {
/* can't tell difference between net and host */
type = NS_ERR_UNREACH_HOST, code = 0;
goto senderror;
}
idp->idp_tc++;
if (idp->idp_tc > NS_MAXHOPS) {
type = NS_ERR_TOO_OLD, code = 0;
goto senderror;
}
/*
* Save at most 42 bytes of the packet in case
* we need to generate an NS error message to the src.
*/
mcopy = m_copy(m, 0, imin((int)ntohs(idp->idp_len), 42));
if ((ok_there = idp_do_route(&idp->idp_dna,&idp_droute))==0) {
type = NS_ERR_UNREACH_HOST, code = 0;
goto senderror;
}
/*
* Here we think about forwarding broadcast packets,
* so we try to insure that it doesn't go back out
* on the interface it came in on. Also, if we
* are going to physically broadcast this, let us
* age the packet so we can eat it safely the second time around.
*/
if (idp->idp_dna.x_host.c_host[0] & 0x1) {
struct ns_ifaddr *ia = ns_iaonnetof(&idp->idp_dna);
struct ifnet *ifp;
if (ia) {
/* I'm gonna hafta eat this packet */
agedelta += NS_MAXHOPS - idp->idp_tc;
idp->idp_tc = NS_MAXHOPS;
}
if ((ok_back = idp_do_route(&idp->idp_sna,&idp_sroute))==0) {
/* error = ENETUNREACH; He'll never get it! */
m_freem(m);
goto cleanup;
}
if (idp_droute.ro_rt &&
(ifp=idp_droute.ro_rt->rt_ifp) &&
idp_sroute.ro_rt &&
(ifp!=idp_sroute.ro_rt->rt_ifp)) {
flags |= NS_ALLOWBROADCAST;
} else {
type = NS_ERR_UNREACH_HOST, code = 0;
goto senderror;
}
}
/* need to adjust checksum */
if (idp->idp_sum!=0xffff) {
union bytes {
u_char c[4];
u_short s[2];
long l;
} x;
register int shift;
x.l = 0; x.c[0] = agedelta;
shift = (((((int)ntohs(idp->idp_len))+1)>>1)-2) & 0xf;
x.l = idp->idp_sum + (x.s[0] << shift);
x.l = x.s[0] + x.s[1];
x.l = x.s[0] + x.s[1];
if (x.l==0xffff) idp->idp_sum = 0; else idp->idp_sum = x.l;
}
if ((error = ns_output(m, &idp_droute, flags)) &&
(mcopy!=NULL)) {
idp = mtod(mcopy, struct idp *);
type = NS_ERR_UNSPEC_T, code = 0;
switch (error) {
case ENETUNREACH:
case EHOSTDOWN:
case EHOSTUNREACH:
case ENETDOWN:
case EPERM:
type = NS_ERR_UNREACH_HOST;
break;
case EMSGSIZE:
type = NS_ERR_TOO_BIG;
code = 576; /* too hard to figure out mtu here */
break;
case ENOBUFS:
type = NS_ERR_UNSPEC_T;
break;
}
mcopy = NULL;
senderror:
ns_error(m, type, code);
}
cleanup:
if (ok_there)
idp_undo_route(&idp_droute);
if (ok_back)
idp_undo_route(&idp_sroute);
if (mcopy != NULL)
m_freem(mcopy);
}
idp_do_route(src, ro)
struct ns_addr *src;
struct route *ro;
{
struct sockaddr_ns *dst;
bzero((caddr_t)ro, sizeof (*ro));
dst = (struct sockaddr_ns *)&ro->ro_dst;
dst->sns_len = sizeof(*dst);
dst->sns_family = AF_NS;
dst->sns_addr = *src;
dst->sns_addr.x_port = 0;
rtalloc(ro);
if (ro->ro_rt == 0 || ro->ro_rt->rt_ifp == 0) {
return (0);
}
ro->ro_rt->rt_use++;
return (1);
}
idp_undo_route(ro)
register struct route *ro;
{
if (ro->ro_rt) {RTFREE(ro->ro_rt);}
}
ns_watch_output(m, ifp)
struct mbuf *m;
struct ifnet *ifp;
{
register struct nspcb *nsp;
register struct ifaddr *ifa;
/*
* Give any raw listeners a crack at the packet
*/
for (nsp = nsrawpcb.nsp_next; nsp != &nsrawpcb; nsp = nsp->nsp_next) {
struct mbuf *m0 = m_copy(m, 0, (int)M_COPYALL);
if (m0) {
register struct idp *idp;
M_PREPEND(m0, sizeof (*idp), M_DONTWAIT);
if (m0 == NULL)
continue;
idp = mtod(m0, struct idp *);
idp->idp_sna.x_net = ns_zeronet;
idp->idp_sna.x_host = ns_thishost;
if (ifp && (ifp->if_flags & IFF_POINTOPOINT))
for(ifa = ifp->if_addrlist; ifa;
ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family==AF_NS) {
idp->idp_sna = IA_SNS(ifa)->sns_addr;
break;
}
}
idp->idp_len = ntohl(m0->m_pkthdr.len);
idp_input(m0, nsp);
}
}
}

View File

@ -1,429 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)ns_ip.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
/*
* Software interface driver for encapsulating ns in ip.
*/
#ifdef NSIP
#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/errno.h>
#include <sys/ioctl.h>
#include <sys/protosw.h>
#include <net/if.h>
#include <net/netisr.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <machine/mtpr.h>
#include <netns/ns.h>
#include <netns/ns_if.h>
#include <netns/idp.h>
struct ifnet_en {
struct ifnet ifen_ifnet;
struct route ifen_route;
struct in_addr ifen_src;
struct in_addr ifen_dst;
struct ifnet_en *ifen_next;
};
int nsipoutput(), nsipioctl(), nsipstart();
#define LOMTU (1024+512);
struct ifnet nsipif;
struct ifnet_en *nsip_list; /* list of all hosts and gateways or
broadcast addrs */
struct ifnet_en *
nsipattach()
{
register struct ifnet_en *m;
register struct ifnet *ifp;
if (nsipif.if_mtu == 0) {
ifp = &nsipif;
ifp->if_name = "nsip";
ifp->if_mtu = LOMTU;
ifp->if_ioctl = nsipioctl;
ifp->if_output = nsipoutput;
ifp->if_start = nsipstart;
ifp->if_flags = IFF_POINTOPOINT;
}
MALLOC((m), struct ifnet_en *, sizeof(*m), M_PCB, M_NOWAIT);
if (m == NULL) return (NULL);
m->ifen_next = nsip_list;
nsip_list = m;
ifp = &m->ifen_ifnet;
ifp->if_name = "nsip";
ifp->if_mtu = LOMTU;
ifp->if_ioctl = nsipioctl;
ifp->if_output = nsipoutput;
ifp->if_start = nsipstart;
ifp->if_flags = IFF_POINTOPOINT;
ifp->if_unit = nsipif.if_unit++;
if_attach(ifp);
return (m);
}
/*
* Process an ioctl request.
*/
/* ARGSUSED */
nsipioctl(ifp, cmd, data)
register struct ifnet *ifp;
int cmd;
caddr_t data;
{
int error = 0;
struct ifreq *ifr;
switch (cmd) {
case SIOCSIFADDR:
ifp->if_flags |= IFF_UP;
/* FALLTHROUGH */
case SIOCSIFDSTADDR:
/*
* Everything else is done at a higher level.
*/
break;
case SIOCSIFFLAGS:
ifr = (struct ifreq *)data;
if ((ifr->ifr_flags & IFF_UP) == 0)
error = nsip_free(ifp);
default:
error = EINVAL;
}
return (error);
}
struct mbuf *nsip_badlen;
struct mbuf *nsip_lastin;
int nsip_hold_input;
idpip_input(m, ifp)
register struct mbuf *m;
struct ifnet *ifp;
{
register struct ip *ip;
register struct idp *idp;
int len, s;
if (nsip_hold_input) {
if (nsip_lastin) {
m_freem(nsip_lastin);
}
nsip_lastin = m_copym(m, 0, (int)M_COPYALL, M_DONTWAIT);
}
/*
* Get IP and IDP header together in first mbuf.
*/
nsipif.if_ipackets++;
s = sizeof (struct ip) + sizeof (struct idp);
if (((m->m_flags & M_EXT) || m->m_len < s) &&
(m = m_pullup(m, s)) == 0) {
nsipif.if_ierrors++;
return;
}
ip = mtod(m, struct ip *);
if (ip->ip_hl > (sizeof (struct ip) >> 2)) {
ip_stripoptions(m, (struct mbuf *)0);
if (m->m_len < s) {
if ((m = m_pullup(m, s)) == 0) {
nsipif.if_ierrors++;
return;
}
ip = mtod(m, struct ip *);
}
}
/*
* Make mbuf data length reflect IDP length.
* If not enough data to reflect IDP length, drop.
*/
m->m_data += sizeof (struct ip);
m->m_len -= sizeof (struct ip);
m->m_pkthdr.len -= sizeof (struct ip);
idp = mtod(m, struct idp *);
len = ntohs(idp->idp_len);
if (len & 1) len++; /* Preserve Garbage Byte */
if (ip->ip_len != len) {
if (len > ip->ip_len) {
nsipif.if_ierrors++;
if (nsip_badlen) m_freem(nsip_badlen);
nsip_badlen = m;
return;
}
/* Any extra will be trimmed off by the NS routines */
}
/*
* Place interface pointer before the data
* for the receiving protocol.
*/
m->m_pkthdr.rcvif = ifp;
/*
* Deliver to NS
*/
netisr_dispatch(NETISR_NS, m);
}
/* ARGSUSED */
nsipoutput(ifn, m, dst)
struct ifnet_en *ifn;
register struct mbuf *m;
struct sockaddr *dst;
{
register struct ip *ip;
register struct route *ro = &(ifn->ifen_route);
register int len = 0;
register struct idp *idp = mtod(m, struct idp *);
int error;
ifn->ifen_ifnet.if_opackets++;
nsipif.if_opackets++;
/*
* Calculate data length and make space
* for IP header.
*/
len = ntohs(idp->idp_len);
if (len & 1) len++; /* Preserve Garbage Byte */
/* following clause not necessary on vax */
if (3 & (int)m->m_data) {
/* force longword alignment of ip hdr */
struct mbuf *m0 = m_gethdr(MT_HEADER, M_DONTWAIT);
if (m0 == 0) {
m_freem(m);
return (ENOBUFS);
}
MH_ALIGN(m0, sizeof (struct ip));
m0->m_flags = m->m_flags & M_COPYFLAGS;
m0->m_next = m;
m0->m_len = sizeof (struct ip);
m0->m_pkthdr.len = m0->m_len + m->m_len;
m->m_flags &= ~M_PKTHDR;
} else {
M_PREPEND(m, sizeof (struct ip), M_DONTWAIT);
if (m == 0)
return (ENOBUFS);
}
/*
* Fill in IP header.
*/
ip = mtod(m, struct ip *);
*(long *)ip = 0;
ip->ip_p = IPPROTO_IDP;
ip->ip_src = ifn->ifen_src;
ip->ip_dst = ifn->ifen_dst;
ip->ip_len = (u_short)len + sizeof (struct ip);
ip->ip_ttl = MAXTTL;
/*
* Output final datagram.
*/
error = (ip_output(m, (struct mbuf *)0, ro, SO_BROADCAST, NULL));
if (error) {
ifn->ifen_ifnet.if_oerrors++;
ifn->ifen_ifnet.if_ierrors = error;
}
return (error);
bad:
m_freem(m);
return (ENETUNREACH);
}
nsipstart(ifp)
struct ifnet *ifp;
{
panic("nsip_start called");
}
struct ifreq ifr = {"nsip0"};
nsip_route(m)
register struct mbuf *m;
{
register struct nsip_req *rq = mtod(m, struct nsip_req *);
struct sockaddr_ns *ns_dst = (struct sockaddr_ns *)&rq->rq_ns;
struct sockaddr_in *ip_dst = (struct sockaddr_in *)&rq->rq_ip;
struct route ro;
struct ifnet_en *ifn;
struct sockaddr_in *src;
/*
* First, make sure we already have an ns address:
*/
if (ns_hosteqnh(ns_thishost, ns_zerohost))
return (EADDRNOTAVAIL);
/*
* Now, determine if we can get to the destination
*/
bzero((caddr_t)&ro, sizeof (ro));
ro.ro_dst = *(struct sockaddr *)ip_dst;
rtalloc(&ro);
if (ro.ro_rt == 0 || ro.ro_rt->rt_ifp == 0) {
return (ENETUNREACH);
}
/*
* And see how he's going to get back to us:
* i.e., what return ip address do we use?
*/
{
register struct in_ifaddr *ia;
struct ifnet *ifp = ro.ro_rt->rt_ifp;
for (ia = in_ifaddr; ia; ia = ia->ia_next)
if (ia->ia_ifp == ifp)
break;
if (ia == 0)
ia = in_ifaddr;
if (ia == 0) {
RTFREE(ro.ro_rt);
return (EADDRNOTAVAIL);
}
src = (struct sockaddr_in *)&ia->ia_addr;
}
/*
* Is there a free (pseudo-)interface or space?
*/
for (ifn = nsip_list; ifn; ifn = ifn->ifen_next) {
if ((ifn->ifen_ifnet.if_flags & IFF_UP) == 0)
break;
}
if (ifn == NULL)
ifn = nsipattach();
if (ifn == NULL) {
RTFREE(ro.ro_rt);
return (ENOBUFS);
}
ifn->ifen_route = ro;
ifn->ifen_dst = ip_dst->sin_addr;
ifn->ifen_src = src->sin_addr;
/*
* now configure this as a point to point link
*/
ifr.ifr_name[4] = '0' + nsipif.if_unit - 1;
ifr.ifr_dstaddr = * (struct sockaddr *) ns_dst;
(void)ns_control((struct socket *)0, (int)SIOCSIFDSTADDR, (caddr_t)&ifr,
(struct ifnet *)ifn);
satons_addr(ifr.ifr_addr).x_host = ns_thishost;
return (ns_control((struct socket *)0, (int)SIOCSIFADDR, (caddr_t)&ifr,
(struct ifnet *)ifn));
}
nsip_free(ifp)
struct ifnet *ifp;
{
register struct ifnet_en *ifn = (struct ifnet_en *)ifp;
struct route *ro = & ifn->ifen_route;
if (ro->ro_rt) {
RTFREE(ro->ro_rt);
ro->ro_rt = 0;
}
ifp->if_flags &= ~IFF_UP;
return (0);
}
nsip_ctlinput(cmd, sa)
int cmd;
struct sockaddr *sa;
{
extern u_char inetctlerrmap[];
struct sockaddr_in *sin;
int in_rtchange();
if ((unsigned)cmd >= PRC_NCMDS)
return;
if (sa->sa_family != AF_INET && sa->sa_family != AF_IMPLINK)
return;
sin = (struct sockaddr_in *)sa;
if (sin->sin_addr.s_addr == INADDR_ANY)
return;
switch (cmd) {
case PRC_ROUTEDEAD:
case PRC_REDIRECT_NET:
case PRC_REDIRECT_HOST:
case PRC_REDIRECT_TOSNET:
case PRC_REDIRECT_TOSHOST:
nsip_rtchange(&sin->sin_addr);
break;
}
}
nsip_rtchange(dst)
register struct in_addr *dst;
{
register struct ifnet_en *ifn;
for (ifn = nsip_list; ifn; ifn = ifn->ifen_next) {
if (ifn->ifen_dst.s_addr == dst->s_addr &&
ifn->ifen_route.ro_rt) {
RTFREE(ifn->ifen_route.ro_rt);
ifn->ifen_route.ro_rt = 0;
}
}
}
#endif

View File

@ -1,158 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)ns_output.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/errno.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <net/if.h>
#include <net/route.h>
#include <netns/ns.h>
#include <netns/ns_if.h>
#include <netns/idp.h>
#include <netns/idp_var.h>
int ns_hold_output = 0;
int ns_copy_output = 0;
int ns_output_cnt = 0;
struct mbuf *ns_lastout;
ns_output(m0, ro, flags)
struct mbuf *m0;
struct route *ro;
int flags;
{
register struct idp *idp = mtod(m0, struct idp *);
register struct ifnet *ifp = 0;
int error = 0;
struct route idproute;
struct sockaddr_ns *dst;
extern int idpcksum;
if (ns_hold_output) {
if (ns_lastout) {
(void)m_free(ns_lastout);
}
ns_lastout = m_copy(m0, 0, (int)M_COPYALL);
}
/*
* Route packet.
*/
if (ro == 0) {
ro = &idproute;
bzero((caddr_t)ro, sizeof (*ro));
}
dst = (struct sockaddr_ns *)&ro->ro_dst;
if (ro->ro_rt == 0) {
dst->sns_family = AF_NS;
dst->sns_len = sizeof (*dst);
dst->sns_addr = idp->idp_dna;
dst->sns_addr.x_port = 0;
/*
* If routing to interface only,
* short circuit routing lookup.
*/
if (flags & NS_ROUTETOIF) {
struct ns_ifaddr *ia = ns_iaonnetof(&idp->idp_dna);
if (ia == 0) {
error = ENETUNREACH;
goto bad;
}
ifp = ia->ia_ifp;
goto gotif;
}
rtalloc(ro);
} else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
/*
* The old route has gone away; try for a new one.
*/
rtfree(ro->ro_rt);
ro->ro_rt = NULL;
rtalloc(ro);
}
if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
error = ENETUNREACH;
goto bad;
}
ro->ro_rt->rt_use++;
if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
dst = (struct sockaddr_ns *)ro->ro_rt->rt_gateway;
gotif:
/*
* Look for multicast addresses and
* and verify user is allowed to send
* such a packet.
*/
if (dst->sns_addr.x_host.c_host[0]&1) {
if ((ifp->if_flags & IFF_BROADCAST) == 0) {
error = EADDRNOTAVAIL;
goto bad;
}
if ((flags & NS_ALLOWBROADCAST) == 0) {
error = EACCES;
goto bad;
}
}
if (htons(idp->idp_len) <= ifp->if_mtu) {
ns_output_cnt++;
if (ns_copy_output) {
ns_watch_output(m0, ifp);
}
error = (*ifp->if_output)(ifp, m0,
(struct sockaddr *)dst, ro->ro_rt);
goto done;
} else error = EMSGSIZE;
bad:
if (ns_copy_output) {
ns_watch_output(m0, ifp);
}
m_freem(m0);
done:
if (ro == &idproute && (flags & NS_ROUTETOIF) == 0 && ro->ro_rt) {
RTFREE(ro->ro_rt);
ro->ro_rt = 0;
}
return (error);
}

View File

@ -1,364 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)ns_pcb.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/errno.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <net/if.h>
#include <net/route.h>
#include <netns/ns.h>
#include <netns/ns_if.h>
#include <netns/ns_pcb.h>
struct ns_addr zerons_addr;
ns_pcballoc(so, head)
struct socket *so;
struct nspcb *head;
{
struct mbuf *m;
register struct nspcb *nsp;
m = m_getclr(M_DONTWAIT, MT_PCB);
if (m == NULL)
return (ENOBUFS);
nsp = mtod(m, struct nspcb *);
nsp->nsp_socket = so;
insque(nsp, head);
so->so_pcb = (caddr_t)nsp;
return (0);
}
ns_pcbbind(nsp, nam)
register struct nspcb *nsp;
struct mbuf *nam;
{
register struct sockaddr_ns *sns;
u_short lport = 0;
if (nsp->nsp_lport || !ns_nullhost(nsp->nsp_laddr))
return (EINVAL);
if (nam == 0)
goto noname;
sns = mtod(nam, struct sockaddr_ns *);
if (nam->m_len != sizeof (*sns))
return (EINVAL);
if (!ns_nullhost(sns->sns_addr)) {
int tport = sns->sns_port;
sns->sns_port = 0; /* yech... */
if (ifa_ifwithaddr((struct sockaddr *)sns) == 0)
return (EADDRNOTAVAIL);
sns->sns_port = tport;
}
lport = sns->sns_port;
if (lport) {
u_short aport = ntohs(lport);
if (aport < NSPORT_RESERVED &&
(nsp->nsp_socket->so_state & SS_PRIV) == 0)
return (EACCES);
if (ns_pcblookup(&zerons_addr, lport, 0))
return (EADDRINUSE);
}
nsp->nsp_laddr = sns->sns_addr;
noname:
if (lport == 0)
do {
if (nspcb.nsp_lport++ < NSPORT_RESERVED)
nspcb.nsp_lport = NSPORT_RESERVED;
lport = htons(nspcb.nsp_lport);
} while (ns_pcblookup(&zerons_addr, lport, 0));
nsp->nsp_lport = lport;
return (0);
}
/*
* Connect from a socket to a specified address.
* Both address and port must be specified in argument sns.
* If don't have a local address for this socket yet,
* then pick one.
*/
ns_pcbconnect(nsp, nam)
struct nspcb *nsp;
struct mbuf *nam;
{
struct ns_ifaddr *ia;
register struct sockaddr_ns *sns = mtod(nam, struct sockaddr_ns *);
register struct ns_addr *dst;
register struct route *ro;
struct ifnet *ifp;
if (nam->m_len != sizeof (*sns))
return (EINVAL);
if (sns->sns_family != AF_NS)
return (EAFNOSUPPORT);
if (sns->sns_port==0 || ns_nullhost(sns->sns_addr))
return (EADDRNOTAVAIL);
/*
* If we haven't bound which network number to use as ours,
* we will use the number of the outgoing interface.
* This depends on having done a routing lookup, which
* we will probably have to do anyway, so we might
* as well do it now. On the other hand if we are
* sending to multiple destinations we may have already
* done the lookup, so see if we can use the route
* from before. In any case, we only
* chose a port number once, even if sending to multiple
* destinations.
*/
ro = &nsp->nsp_route;
dst = &satons_addr(ro->ro_dst);
if (nsp->nsp_socket->so_options & SO_DONTROUTE)
goto flush;
if (!ns_neteq(nsp->nsp_lastdst, sns->sns_addr))
goto flush;
if (!ns_hosteq(nsp->nsp_lastdst, sns->sns_addr)) {
if (ro->ro_rt && ! (ro->ro_rt->rt_flags & RTF_HOST)) {
/* can patch route to avoid rtalloc */
*dst = sns->sns_addr;
} else {
flush:
if (ro->ro_rt)
RTFREE(ro->ro_rt);
ro->ro_rt = (struct rtentry *)0;
nsp->nsp_laddr.x_net = ns_zeronet;
}
}/* else cached route is ok; do nothing */
nsp->nsp_lastdst = sns->sns_addr;
if ((nsp->nsp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/
(ro->ro_rt == (struct rtentry *)0 ||
ro->ro_rt->rt_ifp == (struct ifnet *)0)) {
/* No route yet, so try to acquire one */
ro->ro_dst.sa_family = AF_NS;
ro->ro_dst.sa_len = sizeof(ro->ro_dst);
*dst = sns->sns_addr;
dst->x_port = 0;
rtalloc(ro);
}
if (ns_neteqnn(nsp->nsp_laddr.x_net, ns_zeronet)) {
/*
* If route is known or can be allocated now,
* our src addr is taken from the i/f, else punt.
*/
ia = (struct ns_ifaddr *)0;
/*
* If we found a route, use the address
* corresponding to the outgoing interface
*/
if (ro->ro_rt && (ifp = ro->ro_rt->rt_ifp))
for (ia = ns_ifaddr; ia; ia = ia->ia_next)
if (ia->ia_ifp == ifp)
break;
if (ia == 0) {
u_short fport = sns->sns_addr.x_port;
sns->sns_addr.x_port = 0;
ia = (struct ns_ifaddr *)
ifa_ifwithdstaddr((struct sockaddr *)sns);
sns->sns_addr.x_port = fport;
if (ia == 0)
ia = ns_iaonnetof(&sns->sns_addr);
if (ia == 0)
ia = ns_ifaddr;
if (ia == 0)
return (EADDRNOTAVAIL);
}
nsp->nsp_laddr.x_net = satons_addr(ia->ia_addr).x_net;
}
if (ns_pcblookup(&sns->sns_addr, nsp->nsp_lport, 0))
return (EADDRINUSE);
if (ns_nullhost(nsp->nsp_laddr)) {
if (nsp->nsp_lport == 0)
(void) ns_pcbbind(nsp, (struct mbuf *)0);
nsp->nsp_laddr.x_host = ns_thishost;
}
nsp->nsp_faddr = sns->sns_addr;
/* Includes nsp->nsp_fport = sns->sns_port; */
return (0);
}
ns_pcbdisconnect(nsp)
struct nspcb *nsp;
{
nsp->nsp_faddr = zerons_addr;
if (nsp->nsp_socket->so_state & SS_NOFDREF)
ns_pcbdetach(nsp);
}
ns_pcbdetach(nsp)
struct nspcb *nsp;
{
struct socket *so = nsp->nsp_socket;
so->so_pcb = 0;
sotryfree(so);
if (nsp->nsp_route.ro_rt)
rtfree(nsp->nsp_route.ro_rt);
remque(nsp);
(void) m_free(dtom(nsp));
}
ns_setsockaddr(nsp, nam)
register struct nspcb *nsp;
struct mbuf *nam;
{
register struct sockaddr_ns *sns = mtod(nam, struct sockaddr_ns *);
nam->m_len = sizeof (*sns);
sns = mtod(nam, struct sockaddr_ns *);
bzero((caddr_t)sns, sizeof (*sns));
sns->sns_len = sizeof(*sns);
sns->sns_family = AF_NS;
sns->sns_addr = nsp->nsp_laddr;
}
ns_setpeeraddr(nsp, nam)
register struct nspcb *nsp;
struct mbuf *nam;
{
register struct sockaddr_ns *sns = mtod(nam, struct sockaddr_ns *);
nam->m_len = sizeof (*sns);
sns = mtod(nam, struct sockaddr_ns *);
bzero((caddr_t)sns, sizeof (*sns));
sns->sns_len = sizeof(*sns);
sns->sns_family = AF_NS;
sns->sns_addr = nsp->nsp_faddr;
}
/*
* Pass some notification to all connections of a protocol
* associated with address dst. Call the
* protocol specific routine to handle each connection.
* Also pass an extra paramter via the nspcb. (which may in fact
* be a parameter list!)
*/
ns_pcbnotify(dst, errno, notify, param)
register struct ns_addr *dst;
long param;
int errno, (*notify)();
{
register struct nspcb *nsp, *oinp;
int s = splimp();
for (nsp = (&nspcb)->nsp_next; nsp != (&nspcb);) {
if (!ns_hosteq(*dst,nsp->nsp_faddr)) {
next:
nsp = nsp->nsp_next;
continue;
}
if (nsp->nsp_socket == 0)
goto next;
if (errno)
nsp->nsp_socket->so_error = errno;
oinp = nsp;
nsp = nsp->nsp_next;
oinp->nsp_notify_param = param;
(*notify)(oinp);
}
splx(s);
}
#ifdef notdef
/*
* After a routing change, flush old routing
* and allocate a (hopefully) better one.
*/
ns_rtchange(nsp)
struct nspcb *nsp;
{
if (nsp->nsp_route.ro_rt) {
rtfree(nsp->nsp_route.ro_rt);
nsp->nsp_route.ro_rt = 0;
/*
* A new route can be allocated the next time
* output is attempted.
*/
}
/* SHOULD NOTIFY HIGHER-LEVEL PROTOCOLS */
}
#endif
struct nspcb *
ns_pcblookup(faddr, lport, wildp)
struct ns_addr *faddr;
u_short lport;
{
register struct nspcb *nsp, *match = 0;
int matchwild = 3, wildcard;
u_short fport;
fport = faddr->x_port;
for (nsp = (&nspcb)->nsp_next; nsp != (&nspcb); nsp = nsp->nsp_next) {
if (nsp->nsp_lport != lport)
continue;
wildcard = 0;
if (ns_nullhost(nsp->nsp_faddr)) {
if (!ns_nullhost(*faddr))
wildcard++;
} else {
if (ns_nullhost(*faddr))
wildcard++;
else {
if (!ns_hosteq(nsp->nsp_faddr, *faddr))
continue;
if (nsp->nsp_fport != fport) {
if (nsp->nsp_fport != 0)
continue;
else
wildcard++;
}
}
}
if (wildcard && wildp==0)
continue;
if (wildcard < matchwild) {
match = nsp;
matchwild = wildcard;
if (wildcard == 0)
break;
}
}
return (match);
}

View File

@ -1,85 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)ns_pcb.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_NS_PCB_H_
#define _NETNS_NS_PCB_H_
/*
* Ns protocol interface control block.
*/
struct nspcb {
struct nspcb *nsp_next; /* doubly linked list */
struct nspcb *nsp_prev;
struct socket *nsp_socket; /* back pointer to socket */
struct ns_addr nsp_faddr; /* destination address */
struct ns_addr nsp_laddr; /* socket's address */
caddr_t nsp_pcb; /* protocol specific stuff */
struct route nsp_route; /* routing information */
struct ns_addr nsp_lastdst; /* validate cached route for dg socks*/
long nsp_notify_param; /* extra info passed via ns_pcbnotify*/
short nsp_flags;
u_char nsp_dpt; /* default packet type for idp_output*/
u_char nsp_rpt; /* last received packet type by
idp_input() */
};
/* possible flags */
#define NSP_IN_ABORT 0x1 /* calling abort through socket */
#define NSP_RAWIN 0x2 /* show headers on input */
#define NSP_RAWOUT 0x4 /* show header on output */
#define NSP_ALL_PACKETS 0x8 /* Turn off higher proto processing */
#define NS_WILDCARD 1
#define nsp_lport nsp_laddr.x_port
#define nsp_fport nsp_faddr.x_port
#define sotonspcb(so) ((struct nspcb *)((so)->so_pcb))
/*
* Nominal space allocated to a ns socket.
*/
#define NSSNDQ 2048
#define NSRCVQ 2048
#ifdef _KERNEL
struct nspcb nspcb; /* head of list */
struct nspcb *ns_pcblookup();
#endif
#endif

View File

@ -1,99 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* From: @(#)ns_proto.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/socket.h>
#include <sys/protosw.h>
#include <sys/domain.h>
#include <sys/mbuf.h>
#include <net/radix.h>
#include <netns/ns.h>
/*
* NS protocol family: IDP, ERR, PE, SPP, ROUTE.
*/
int ns_init();
int idp_input(), idp_output(), idp_ctlinput(), idp_usrreq();
int idp_raw_usrreq(), idp_ctloutput();
int spp_input(), spp_ctlinput();
int spp_usrreq(), spp_usrreq_sp(), spp_ctloutput();
int spp_init(), spp_fasttimo(), spp_slowtimo();
extern int raw_usrreq();
extern struct domain nsdomain;
struct protosw nssw[] = {
{ 0, &nsdomain, 0, 0,
0, idp_output, 0, 0,
0,
ns_init, 0, 0, 0,
},
{ SOCK_DGRAM, &nsdomain, 0, PR_ATOMIC|PR_ADDR,
0, 0, idp_ctlinput, idp_ctloutput,
idp_usrreq,
0, 0, 0, 0,
},
{ SOCK_STREAM, &nsdomain, NSPROTO_SPP, PR_CONNREQUIRED|PR_WANTRCVD,
spp_input, 0, spp_ctlinput, spp_ctloutput,
spp_usrreq,
spp_init, spp_fasttimo, spp_slowtimo, 0,
},
{ SOCK_SEQPACKET,&nsdomain, NSPROTO_SPP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ATOMIC,
spp_input, 0, spp_ctlinput, spp_ctloutput,
spp_usrreq_sp,
0, 0, 0, 0,
},
{ SOCK_RAW, &nsdomain, NSPROTO_RAW, PR_ATOMIC|PR_ADDR,
idp_input, idp_output, 0, idp_ctloutput,
idp_raw_usrreq,
0, 0, 0, 0,
},
{ SOCK_RAW, &nsdomain, NSPROTO_ERROR, PR_ATOMIC|PR_ADDR,
idp_ctlinput, idp_output, 0, idp_ctloutput,
idp_raw_usrreq,
0, 0, 0, 0,
},
};
struct domain nsdomain =
{ AF_NS, "network systems", 0, 0, 0,
nssw, &nssw[sizeof(nssw)/sizeof(nssw[0])], 0,
rn_inithead, 16, sizeof(struct sockaddr_ns)};
DOMAIN_SET(ns);

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)sp.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_SP_H_
#define _NETNS_SP_H_
/*
* Definitions for Xerox NS style sequenced packet protocol
*/
struct sphdr {
u_char sp_cc; /* connection control */
u_char sp_dt; /* datastream type */
#define SP_SP 0x80 /* system packet */
#define SP_SA 0x40 /* send acknowledgement */
#define SP_OB 0x20 /* attention (out of band data) */
#define SP_EM 0x10 /* end of message */
u_short sp_sid; /* source connection identifier */
u_short sp_did; /* destination connection identifier */
u_short sp_seq; /* sequence number */
u_short sp_ack; /* acknowledge number */
u_short sp_alo; /* allocation number */
};
#endif

View File

@ -1,68 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)spidp.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_SPIDP_H_
#define _NETNS_SPIDP_H_
/*
* Definitions for NS(tm) Internet Datagram Protocol
* containing a Sequenced Packet Protocol packet.
*/
struct spidp {
struct idp si_i;
struct sphdr si_s;
};
struct spidp_q {
struct spidp_q *si_next;
struct spidp_q *si_prev;
};
#define SI(x) ((struct spidp *)x)
#define si_sum si_i.idp_sum
#define si_len si_i.idp_len
#define si_tc si_i.idp_tc
#define si_pt si_i.idp_pt
#define si_dna si_i.idp_dna
#define si_sna si_i.idp_sna
#define si_sport si_i.idp_sna.x_port
#define si_cc si_s.sp_cc
#define si_dt si_s.sp_dt
#define si_sid si_s.sp_sid
#define si_did si_s.sp_did
#define si_seq si_s.sp_seq
#define si_ack si_s.sp_ack
#define si_alo si_s.sp_alo
#endif

View File

@ -1,173 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)spp_debug.c 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#include "opt_inet.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <sys/errno.h>
#include <net/route.h>
#include <net/if.h>
#include <netinet/tcp_fsm.h>
#include <netns/ns.h>
#include <netns/ns_pcb.h>
#include <netns/idp.h>
#include <netns/idp_var.h>
#include <netns/sp.h>
#include <netns/spidp.h>
#define SPPTIMERS
#include <netns/spp_timer.h>
#include <netns/spp_var.h>
#define SANAMES
#include <netns/spp_debug.h>
int sppconsdebug = 0;
/*
* spp debug routines
*/
spp_trace(act, ostate, sp, si, req)
short act;
u_char ostate;
struct sppcb *sp;
struct spidp *si;
int req;
{
#ifdef INET
#ifdef TCPDEBUG
u_short seq, ack, len, alo;
unsigned long iptime();
int flags;
struct spp_debug *sd = &spp_debug[spp_debx++];
extern char *prurequests[];
extern char *sanames[];
extern char *tcpstates[];
extern char *spptimers[];
if (spp_debx == SPP_NDEBUG)
spp_debx = 0;
sd->sd_time = iptime();
sd->sd_act = act;
sd->sd_ostate = ostate;
sd->sd_cb = (caddr_t)sp;
if (sp)
sd->sd_sp = *sp;
else
bzero((caddr_t)&sd->sd_sp, sizeof (*sp));
if (si)
sd->sd_si = *si;
else
bzero((caddr_t)&sd->sd_si, sizeof (*si));
sd->sd_req = req;
if (sppconsdebug == 0)
return;
if (ostate >= TCP_NSTATES) ostate = 0;
if (act >= SA_DROP) act = SA_DROP;
if (sp)
printf("%x %s:", sp, tcpstates[ostate]);
else
printf("???????? ");
printf("%s ", sanames[act]);
switch (act) {
case SA_RESPOND:
case SA_INPUT:
case SA_OUTPUT:
case SA_DROP:
if (si == 0)
break;
seq = si->si_seq;
ack = si->si_ack;
alo = si->si_alo;
len = si->si_len;
if (act == SA_OUTPUT) {
seq = ntohs(seq);
ack = ntohs(ack);
alo = ntohs(alo);
len = ntohs(len);
}
#ifndef lint
#define p1(f) { printf("%s = %x, ", "f", f); }
p1(seq); p1(ack); p1(alo); p1(len);
#endif
flags = si->si_cc;
if (flags) {
char *cp = "<";
#ifndef lint
#define pf(f) { if (flags&SP_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
pf(SP); pf(SA); pf(OB); pf(EM);
#else
cp = cp;
#endif
printf(">");
}
#ifndef lint
#define p2(f) { printf("%s = %x, ", "f", si->si_/**/f); }
p2(sid);p2(did);p2(dt);p2(pt);
#endif
ns_printhost(&si->si_sna);
ns_printhost(&si->si_dna);
if (act==SA_RESPOND) {
printf("idp_len = %x, ",
((struct idp *)si)->idp_len);
}
break;
case SA_USER:
printf("%s", prurequests[req&0xff]);
if ((req & 0xff) == PRU_SLOWTIMO)
printf("<%s>", spptimers[req>>8]);
break;
}
if (sp)
printf(" -> %s", tcpstates[sp->s_state]);
/* print out internal state of sp !?! */
printf("\n");
if (sp == 0)
return;
#ifndef lint
#define p3(f) { printf("%s = %x, ", "f", sp->s_/**/f); }
printf("\t"); p3(rack);p3(ralo);p3(smax);p3(flags); printf("\n");
#endif
#endif
#endif
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)spp_debug.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_SPP_DEBUG_H_
#define _NETNS_SPP_DEBUG_H_
struct spp_debug {
u_long sd_time;
short sd_act;
short sd_ostate;
caddr_t sd_cb;
short sd_req;
struct spidp sd_si;
struct sppcb sd_sp;
};
#define SA_INPUT 0
#define SA_OUTPUT 1
#define SA_USER 2
#define SA_RESPOND 3
#define SA_DROP 4
#ifdef SANAMES
char *sanames[] =
{ "input", "output", "user", "respond", "drop" };
#endif
#define SPP_NDEBUG 100
struct spp_debug spp_debug[SPP_NDEBUG];
int spp_debx;
#endif

View File

@ -1,128 +0,0 @@
/*
* Copyright (c) 1982, 1986, 1988, 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.
*
* @(#)spp_timer.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_SPP_TIMER_H_
#define _NETNS_SPP_TIMER_H_
/*
* Definitions of the SPP timers. These timers are counted
* down PR_SLOWHZ times a second.
*/
#define SPPT_NTIMERS 4
#define SPPT_REXMT 0 /* retransmit */
#define SPPT_PERSIST 1 /* retransmit persistance */
#define SPPT_KEEP 2 /* keep alive */
#define SPPT_2MSL 3 /* 2*msl quiet time timer */
/*
* The SPPT_REXMT timer is used to force retransmissions.
* The SPP has the SPPT_REXMT timer set whenever segments
* have been sent for which ACKs are expected but not yet
* received. If an ACK is received which advances tp->snd_una,
* then the retransmit timer is cleared (if there are no more
* outstanding segments) or reset to the base value (if there
* are more ACKs expected). Whenever the retransmit timer goes off,
* we retransmit one unacknowledged segment, and do a backoff
* on the retransmit timer.
*
* The SPPT_PERSIST timer is used to keep window size information
* flowing even if the window goes shut. If all previous transmissions
* have been acknowledged (so that there are no retransmissions in progress),
* and the window is too small to bother sending anything, then we start
* the SPPT_PERSIST timer. When it expires, if the window is nonzero,
* we go to transmit state. Otherwise, at intervals send a single byte
* into the peer's window to force him to update our window information.
* We do this at most as often as SPPT_PERSMIN time intervals,
* but no more frequently than the current estimate of round-trip
* packet time. The SPPT_PERSIST timer is cleared whenever we receive
* a window update from the peer.
*
* The SPPT_KEEP timer is used to keep connections alive. If an
* connection is idle (no segments received) for SPPTV_KEEP amount of time,
* but not yet established, then we drop the connection. If the connection
* is established, then we force the peer to send us a segment by sending:
* <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
* This segment is (deliberately) outside the window, and should elicit
* an ack segment in response from the peer. If, despite the SPPT_KEEP
* initiated segments we cannot elicit a response from a peer in SPPT_MAXIDLE
* amount of time, then we drop the connection.
*/
#define SPP_TTL 30 /* default time to live for SPP segs */
/*
* Time constants.
*/
#define SPPTV_MSL ( 15*PR_SLOWHZ) /* max seg lifetime */
#define SPPTV_SRTTBASE 0 /* base roundtrip time;
if 0, no idea yet */
#define SPPTV_SRTTDFLT ( 3*PR_SLOWHZ) /* assumed RTT if no info */
#define SPPTV_PERSMIN ( 5*PR_SLOWHZ) /* retransmit persistance */
#define SPPTV_PERSMAX ( 60*PR_SLOWHZ) /* maximum persist interval */
#define SPPTV_KEEP ( 75*PR_SLOWHZ) /* keep alive - 75 secs */
#define SPPTV_MAXIDLE ( 8*SPPTV_KEEP) /* maximum allowable idle
time before drop conn */
#define SPPTV_MIN ( 1*PR_SLOWHZ) /* minimum allowable value */
#define SPPTV_REXMTMAX ( 64*PR_SLOWHZ) /* max allowable REXMT value */
#define SPP_LINGERTIME 120 /* linger at most 2 minutes */
#define SPP_MAXRXTSHIFT 12 /* maximum retransmits */
#ifdef SPPTIMERS
char *spptimers[] =
{ "REXMT", "PERSIST", "KEEP", "2MSL" };
#endif
/*
* Force a time value to be in a certain range.
*/
#define SPPT_RANGESET(tv, value, tvmin, tvmax) { \
(tv) = (value); \
if ((tv) < (tvmin)) \
(tv) = (tvmin); \
else if ((tv) > (tvmax)) \
(tv) = (tvmax); \
}
#ifdef _KERNEL
extern int spp_backoff[];
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,221 +0,0 @@
/*
* Copyright (c) 1984, 1985, 1986, 1987, 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.
*
* @(#)spp_var.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _NETNS_SPP_VAR_H_
#define _NETNS_SPP_VAR_H_
/*
* Sp control block, one per connection
*/
struct sppcb {
struct spidp_q s_q; /* queue for out-of-order receipt */
struct nspcb *s_nspcb; /* backpointer to internet pcb */
u_char s_state;
u_char s_flags;
#define SF_ACKNOW 0x01 /* Ack peer immediately */
#define SF_DELACK 0x02 /* Ack, but try to delay it */
#define SF_HI 0x04 /* Show headers on input */
#define SF_HO 0x08 /* Show headers on output */
#define SF_PI 0x10 /* Packet (datagram) interface */
#define SF_WIN 0x20 /* Window info changed */
#define SF_RXT 0x40 /* Rxt info changed */
#define SF_RVD 0x80 /* Calling from read usrreq routine */
u_short s_mtu; /* Max packet size for this stream */
/* use sequence fields in headers to store sequence numbers for this
connection */
struct idp *s_idp;
struct sphdr s_shdr; /* prototype header to transmit */
#define s_cc s_shdr.sp_cc /* connection control (for EM bit) */
#define s_dt s_shdr.sp_dt /* datastream type */
#define s_sid s_shdr.sp_sid /* source connection identifier */
#define s_did s_shdr.sp_did /* destination connection identifier */
#define s_seq s_shdr.sp_seq /* sequence number */
#define s_ack s_shdr.sp_ack /* acknowledge number */
#define s_alo s_shdr.sp_alo /* allocation number */
#define s_dport s_idp->idp_dna.x_port /* where we are sending */
struct sphdr s_rhdr; /* last received header (in effect!)*/
u_short s_rack; /* their acknowledge number */
u_short s_ralo; /* their allocation number */
u_short s_smax; /* highest packet # we have sent */
u_short s_snxt; /* which packet to send next */
/* congestion control */
#define CUNIT 1024 /* scaling for ... */
int s_cwnd; /* Congestion-controlled window */
/* in packets * CUNIT */
short s_swnd; /* == tcp snd_wnd, in packets */
short s_smxw; /* == tcp max_sndwnd */
/* difference of two spp_seq's can be
no bigger than a short */
u_short s_swl1; /* == tcp snd_wl1 */
u_short s_swl2; /* == tcp snd_wl2 */
int s_cwmx; /* max allowable cwnd */
int s_ssthresh; /* s_cwnd size threshhold for
* slow start exponential-to-
* linear switch */
/* transmit timing stuff
* srtt and rttvar are stored as fixed point, for convenience in smoothing.
* srtt has 3 bits to the right of the binary point, rttvar has 2.
*/
short s_idle; /* time idle */
short s_timer[SPPT_NTIMERS]; /* timers */
short s_rxtshift; /* log(2) of rexmt exp. backoff */
short s_rxtcur; /* current retransmit value */
u_short s_rtseq; /* packet being timed */
short s_rtt; /* timer for round trips */
short s_srtt; /* averaged timer */
short s_rttvar; /* variance in round trip time */
char s_force; /* which timer expired */
char s_dupacks; /* counter to intuit xmt loss */
/* out of band data */
char s_oobflags;
#define SF_SOOB 0x08 /* sending out of band data */
#define SF_IOOB 0x10 /* receiving out of band data */
char s_iobc; /* input characters */
/* debug stuff */
u_short s_want; /* Last candidate for sending */
char s_outx; /* exit taken from spp_output */
char s_inx; /* exit taken from spp_input */
u_short s_flags2; /* more flags for testing */
#define SF_NEWCALL 0x100 /* for new_recvmsg */
#define SO_NEWCALL 10 /* for new_recvmsg */
};
#define nstosppcb(np) ((struct sppcb *)(np)->nsp_pcb)
#define sotosppcb(so) (nstosppcb(sotonspcb(so)))
struct sppstat {
long spps_connattempt; /* connections initiated */
long spps_accepts; /* connections accepted */
long spps_connects; /* connections established */
long spps_drops; /* connections dropped */
long spps_conndrops; /* embryonic connections dropped */
long spps_closed; /* conn. closed (includes drops) */
long spps_segstimed; /* segs where we tried to get rtt */
long spps_rttupdated; /* times we succeeded */
long spps_delack; /* delayed acks sent */
long spps_timeoutdrop; /* conn. dropped in rxmt timeout */
long spps_rexmttimeo; /* retransmit timeouts */
long spps_persisttimeo; /* persist timeouts */
long spps_keeptimeo; /* keepalive timeouts */
long spps_keepprobe; /* keepalive probes sent */
long spps_keepdrops; /* connections dropped in keepalive */
long spps_sndtotal; /* total packets sent */
long spps_sndpack; /* data packets sent */
long spps_sndbyte; /* data bytes sent */
long spps_sndrexmitpack; /* data packets retransmitted */
long spps_sndrexmitbyte; /* data bytes retransmitted */
long spps_sndacks; /* ack-only packets sent */
long spps_sndprobe; /* window probes sent */
long spps_sndurg; /* packets sent with URG only */
long spps_sndwinup; /* window update-only packets sent */
long spps_sndctrl; /* control (SYN|FIN|RST) packets sent */
long spps_sndvoid; /* couldn't find requested packet*/
long spps_rcvtotal; /* total packets received */
long spps_rcvpack; /* packets received in sequence */
long spps_rcvbyte; /* bytes received in sequence */
long spps_rcvbadsum; /* packets received with ccksum errs */
long spps_rcvbadoff; /* packets received with bad offset */
long spps_rcvshort; /* packets received too short */
long spps_rcvduppack; /* duplicate-only packets received */
long spps_rcvdupbyte; /* duplicate-only bytes received */
long spps_rcvpartduppack; /* packets with some duplicate data */
long spps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
long spps_rcvoopack; /* out-of-order packets received */
long spps_rcvoobyte; /* out-of-order bytes received */
long spps_rcvpackafterwin; /* packets with data after window */
long spps_rcvbyteafterwin; /* bytes rcvd after window */
long spps_rcvafterclose; /* packets rcvd after "close" */
long spps_rcvwinprobe; /* rcvd window probe packets */
long spps_rcvdupack; /* rcvd duplicate acks */
long spps_rcvacktoomuch; /* rcvd acks for unsent data */
long spps_rcvackpack; /* rcvd ack packets */
long spps_rcvackbyte; /* bytes acked by rcvd acks */
long spps_rcvwinupd; /* rcvd window update packets */
};
struct spp_istat {
short hdrops;
short badsum;
short badlen;
short slotim;
short fastim;
short nonucn;
short noconn;
short notme;
short wrncon;
short bdreas;
short gonawy;
short notyet;
short lstdup;
struct sppstat newstats;
};
#ifdef _KERNEL
struct spp_istat spp_istat;
/* Following was struct sppstat sppstat; */
#ifndef sppstat
#define sppstat spp_istat.newstats
#endif
u_short spp_iss;
extern struct sppcb *spp_close(), *spp_disconnect(),
*spp_usrclosed(), *spp_timers(), *spp_drop();
#endif
#define SPP_ISSINCR 128
/*
* SPP sequence numbers are 16 bit integers operated
* on with modular arithmetic. These macros can be
* used to compare such integers.
*/
#ifdef sun
short xnsCbug;
#define SSEQ_LT(a,b) ((xnsCbug = (short)((a)-(b))) < 0)
#define SSEQ_LEQ(a,b) ((xnsCbug = (short)((a)-(b))) <= 0)
#define SSEQ_GT(a,b) ((xnsCbug = (short)((a)-(b))) > 0)
#define SSEQ_GEQ(a,b) ((xnsCbug = (short)((a)-(b))) >= 0)
#else
#define SSEQ_LT(a,b) (((short)((a)-(b))) < 0)
#define SSEQ_LEQ(a,b) (((short)((a)-(b))) <= 0)
#define SSEQ_GT(a,b) (((short)((a)-(b))) > 0)
#define SSEQ_GEQ(a,b) (((short)((a)-(b))) >= 0)
#endif
#endif

View File

@ -45,9 +45,6 @@
#include <netipx/ipx.h>
#endif
#define AF_NETBIOS AF_NS /* XXX: should go to socket.h */
#define PF_NETBIOS AF_NETBIOS
#define NBPROTO_TCPSSN 1 /* NETBIOS session over TCP */
#define NBPROTO_IPXSSN 11 /* NETBIOS over IPX */

View File

@ -171,7 +171,7 @@ struct accept_filter_arg {
#define AF_IMPLINK 3 /* arpanet imp addresses */
#define AF_PUP 4 /* pup protocols: e.g. BSP */
#define AF_CHAOS 5 /* mit CHAOS protocols */
#define AF_NS 6 /* XEROX NS protocols */
#define AF_NETBIOS 6 /* SMB protocols */
#define AF_ISO 7 /* ISO protocols */
#define AF_OSI AF_ISO
#define AF_ECMA 8 /* European computer manufacturers */
@ -260,7 +260,7 @@ struct sockaddr_storage {
#define PF_IMPLINK AF_IMPLINK
#define PF_PUP AF_PUP
#define PF_CHAOS AF_CHAOS
#define PF_NS AF_NS
#define PF_NETBIOS AF_NETBIOS
#define PF_ISO AF_ISO
#define PF_OSI AF_ISO
#define PF_ECMA AF_ECMA
@ -278,7 +278,7 @@ struct sockaddr_storage {
#define PF_COIP AF_COIP
#define PF_CNT AF_CNT
#define PF_SIP AF_SIP
#define PF_IPX AF_IPX /* same format as AF_NS */
#define PF_IPX AF_IPX
#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
#define PF_PIP pseudo_AF_PIP
#define PF_ISDN AF_ISDN