diff options
-rw-r--r-- | sys/netipx/ipx.c | 384 | ||||
-rw-r--r-- | sys/netipx/ipx.h | 233 | ||||
-rw-r--r-- | sys/netipx/ipx_cksum.c | 214 | ||||
-rw-r--r-- | sys/netipx/ipx_error.c | 387 | ||||
-rw-r--r-- | sys/netipx/ipx_error.h | 106 | ||||
-rw-r--r-- | sys/netipx/ipx_if.h | 104 | ||||
-rw-r--r-- | sys/netipx/ipx_input.c | 569 | ||||
-rw-r--r-- | sys/netipx/ipx_ip.c | 457 | ||||
-rw-r--r-- | sys/netipx/ipx_ip.h | 76 | ||||
-rw-r--r-- | sys/netipx/ipx_outputfl.c | 163 | ||||
-rw-r--r-- | sys/netipx/ipx_pcb.c | 410 | ||||
-rw-r--r-- | sys/netipx/ipx_pcb.h | 109 | ||||
-rw-r--r-- | sys/netipx/ipx_proto.c | 104 | ||||
-rw-r--r-- | sys/netipx/ipx_tun.c | 75 | ||||
-rw-r--r-- | sys/netipx/ipx_usrreq.c | 612 | ||||
-rw-r--r-- | sys/netipx/ipx_var.h | 62 | ||||
-rw-r--r-- | sys/netipx/spx.h | 208 | ||||
-rw-r--r-- | sys/netipx/spx_debug.c | 178 | ||||
-rw-r--r-- | sys/netipx/spx_debug.h | 81 | ||||
-rw-r--r-- | sys/netipx/spx_timer.h | 133 | ||||
-rw-r--r-- | sys/netipx/spx_usrreq.c | 1846 | ||||
-rw-r--r-- | sys/netipx/spx_var.h | 138 |
22 files changed, 6649 insertions, 0 deletions
diff --git a/sys/netipx/ipx.c b/sys/netipx/ipx.c new file mode 100644 index 00000000000..46fa58d7cf8 --- /dev/null +++ b/sys/netipx/ipx.c @@ -0,0 +1,384 @@ +/* $OpenBSD: ipx.c,v 1.1 1996/08/16 09:15:57 mickey Exp $ */ +/* $NOWHERE: ipx.c,v 1.2 1996/05/07 09:49:37 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx.c + * + * from FreeBSD Id: ipx.c,v 1.4 1996/03/11 15:13:46 davidg Exp + */ + +#include <sys/param.h> +#include <sys/queue.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 <netipx/ipx.h> +#include <netipx/ipx_if.h> + +int ipx_interfaces; + +/* + * Generic internet control operations (ioctl's). + */ +/* ARGSUSED */ +int +ipx_control(so, cmd, data, ifp) + struct socket *so; + u_long cmd; + caddr_t data; + register struct ifnet *ifp; +{ + register struct ifreq *ifr = (struct ifreq *)data; + register struct ipx_aliasreq *ifra = (struct ipx_aliasreq *)data; + register struct ipx_ifaddr *ia; + struct ifaddr *ifa; + int dstIsNew, hostIsNew; + int error = 0; + + /* + * Find address for this interface, if it exists. + */ + if (ifp) + for (ia = ipx_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) + if (ia->ia_ifp == ifp) + break; + + switch (cmd) { + case SIOCAIFADDR: + case SIOCDIFADDR: + if (ifra->ifra_addr.sipx_family == AF_IPX) + for (; ia; ia = ia->ia_list.tqe_next) { + if (ia->ia_ifp == ifp && + ipx_neteq(ia->ia_addr.sipx_addr, + ifra->ifra_addr.sipx_addr)) + break; + } + if (cmd == SIOCDIFADDR && ia == 0) + return (EADDRNOTAVAIL); + /* FALLTHROUGH */ + + case SIOCSIFADDR: + case SIOCSIFDSTADDR: + if ((so->so_state & SS_PRIV) == 0) + return (EPERM); + + if (ia == (struct ipx_ifaddr *)NULL) { + ia = (struct ipx_ifaddr *) + malloc(sizeof *ia, M_IFADDR, M_WAITOK); + if (ia == (struct ipx_ifaddr *)NULL) + return (ENOBUFS); + bzero((caddr_t)ia, sizeof(*ia)); + TAILQ_INSERT_TAIL(&ifp->if_addrlist, + (struct ifaddr *)ia, ifa_list); + TAILQ_INSERT_TAIL(&ipx_ifaddr, ia, ia_list); + ia->ia_ifp = ifp; + ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr; + + ia->ia_ifa.ifa_netmask = + (struct sockaddr *)&ipx_netmask; + + ia->ia_ifa.ifa_dstaddr = + (struct sockaddr *)&ia->ia_dstaddr; + if (ifp->if_flags & IFF_BROADCAST) { + ia->ia_broadaddr.sipx_family = AF_IPX; + ia->ia_broadaddr.sipx_len = sizeof(ia->ia_addr); + ia->ia_broadaddr.sipx_addr.ipx_host = ipx_broadhost; + } + ipx_interfaces++; + } + break; + + case SIOCSIFBRDADDR: + if ((so->so_state & SS_PRIV) == 0) + return (EPERM); + /* FALLTHROUGH */ + + case SIOCGIFADDR: + case SIOCGIFDSTADDR: + case SIOCGIFBRDADDR: + if (ia == (struct ipx_ifaddr *)NULL) + return (EADDRNOTAVAIL); + break; + } + + switch (cmd) { + + case SIOCGIFADDR: + *(struct sockaddr_ipx *)&ifr->ifr_addr = ia->ia_addr; + return (0); + + case SIOCGIFBRDADDR: + if ((ifp->if_flags & IFF_BROADCAST) == 0) + return (EINVAL); + *(struct sockaddr_ipx *)&ifr->ifr_dstaddr = ia->ia_broadaddr; + return (0); + + case SIOCGIFDSTADDR: + if ((ifp->if_flags & IFF_POINTOPOINT) == 0) + return (EINVAL); + *(struct sockaddr_ipx *)&ifr->ifr_dstaddr = ia->ia_dstaddr; + return (0); + + 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, (void *)ia); + if (error) + return (error); + } + *(struct sockaddr *)&ia->ia_dstaddr = ifr->ifr_dstaddr; + return (0); + + case SIOCSIFADDR: + return (ipx_ifinit(ifp, ia, + (struct sockaddr_ipx *)&ifr->ifr_addr, 1)); + + case SIOCDIFADDR: + ipx_ifscrub(ifp, ia); + TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list); + TAILQ_REMOVE(&ipx_ifaddr, ia, ia_list); + IFAFREE((&ia->ia_ifa)); + if (0 == --ipx_interfaces) { + /* + * We reset to virginity and start all over again + */ + ipx_thishost = ipx_zerohost; + } + return (0); + + case SIOCAIFADDR: + dstIsNew = 0; hostIsNew = 1; + if (ia->ia_addr.sipx_family == AF_IPX) { + if (ifra->ifra_addr.sipx_len == 0) { + ifra->ifra_addr = ia->ia_addr; + hostIsNew = 0; + } else if (ipx_neteq(ifra->ifra_addr.sipx_addr, + ia->ia_addr.sipx_addr)) + hostIsNew = 0; + } + if ((ifp->if_flags & IFF_POINTOPOINT) && + (ifra->ifra_dstaddr.sipx_family == AF_IPX)) { + if (hostIsNew == 0) + ipx_ifscrub(ifp, ia); + ia->ia_dstaddr = ifra->ifra_dstaddr; + dstIsNew = 1; + } + if (ifra->ifra_addr.sipx_family == AF_IPX && + (hostIsNew || dstIsNew)) + error = ipx_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. + */ +void +ipx_ifscrub(ifp, ia) + register struct ifnet *ifp; + register struct ipx_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 IPX address + * and routing table entry. + */ +int +ipx_ifinit(ifp, ia, sipx, scrub) + register struct ifnet *ifp; + register struct ipx_ifaddr *ia; + register struct sockaddr_ipx *sipx; + int scrub; +{ + struct sockaddr_ipx oldaddr; + register union ipx_host *h = &ia->ia_addr.sipx_addr.ipx_host; + int s = splimp(), error; + + /* + * Set up new addresses. + */ + oldaddr = ia->ia_addr; + ia->ia_addr = *sipx; + + /* + * 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 (ipx_hosteqnh(ipx_thishost, ipx_zerohost)) { + if (ifp->if_ioctl && + (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (void *)ia))) { + ia->ia_addr = oldaddr; + splx(s); + return (error); + } + ipx_thishost = *h; + } else if (ipx_hosteqnh(sipx->sipx_addr.ipx_host, ipx_zerohost) + || ipx_hosteqnh(sipx->sipx_addr.ipx_host, ipx_thishost)) { + *h = ipx_thishost; + if (ifp->if_ioctl && + (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (void *)ia))) { + ia->ia_addr = oldaddr; + splx(s); + return (error); + } + if (!ipx_hosteqnh(ipx_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; + ipx_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.sipx_addr.ipx_net = ia->ia_addr.sipx_addr.ipx_net; + rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_UP); + } + ia->ia_flags |= IFA_ROUTE; + splx(s); + return (0); +} + +/* + * Return address info for specified IPX network. + */ +struct ipx_ifaddr * +ipx_iaonnetof(dst) + register struct ipx_addr *dst; +{ + register struct ipx_ifaddr *ia; + register struct ipx_addr *compare; + register struct ifnet *ifp; + struct ipx_ifaddr *ia_maybe = 0; + union ipx_net net = dst->ipx_net; + + for (ia = ipx_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) { + if ((ifp = ia->ia_ifp)) { + if (ifp->if_flags & IFF_POINTOPOINT) { + compare = &satoipx_addr(ia->ia_dstaddr); + if (ipx_hosteq(*dst, *compare)) + return (ia); + if (ipx_neteqnn(net, ia->ia_addr.sipx_addr.ipx_net)) + ia_maybe = ia; + } else { + if (ipx_neteqnn(net, ia->ia_addr.sipx_addr.ipx_net)) + return (ia); + } + } + } + return (ia_maybe); +} + +#ifdef IPXDEBUG +struct ipx_addr +ipx_addr(str) + const char *str; +{ + struct ipx_addr ret; + + + return ret; +} + +char * +ipx_ntoa(ipx) + struct ipx_addr ipx; +{ + static char bufs[4][4+1+(3*6)+5], *cbuf = bufs[4]; + + if (cbuf == bufs[4]) + cbuf = bufs[0]; + else + cbuf++; + + sprintf(cbuf, "%04x.%02x:%02x:%02x:%02x:%02x:%02x.%u", + ipx.ipx_net.l_net, + ipx.ipx_host.c_host[0], ipx.ipx_host.c_host[1], + ipx.ipx_host.c_host[2], ipx.ipx_host.c_host[3], + ipx.ipx_host.c_host[4], ipx.ipx_host.c_host[5], + ipx.ipx_port); + + return cbuf; +} + +#endif diff --git a/sys/netipx/ipx.h b/sys/netipx/ipx.h new file mode 100644 index 00000000000..864652da831 --- /dev/null +++ b/sys/netipx/ipx.h @@ -0,0 +1,233 @@ +/* $OpenBSD: ipx.h,v 1.1 1996/08/16 09:15:58 mickey Exp $ */ +/* $NOWHERE: ipx.h,v 1.3 1996/05/07 12:32:01 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx.h + * + * from FreeBSD Id: ipx.h,v 1.7 1996/01/30 22:58:48 mpp Exp + */ + +#ifndef _NETIPX_IPX_H_ +#define _NETIPX_IPX_H_ + +/* + * Constants and Structures + */ + +/* + * Protocols + */ +#define IPXPROTO_UNKWN 0 /* Unknown */ +#define IPXPROTO_RI 1 /* RIP Routing Information */ +#define IPXPROTO_ECHO 2 /* Echo Protocol */ +#define IPXPROTO_ERROR 3 /* Error Protocol */ +#define IPXPROTO_PXP 4 /* PXP Packet Exchange */ +#define IPXPROTO_SPX 5 /* SPX Sequenced Packet */ +#define IPXPROTO_NCP 17 /* NCP NetWare Core */ +#define IPXPROTO_PPROP 20 /* complicated flood w/ bcast */ +#define IPXPROTO_RAW 255 /* Placemarker*/ +#define IPXPROTO_MAX 256 /* Placemarker*/ + +/* + * Port/Socket numbers: network standard functions + */ + +#define IPXPORT_RI 1 /* NS RIP Routing Information */ +#define IPXPORT_ECHO 2 /* NS Echo */ +#define IPXPORT_RE 3 /* NS Router Error */ +#define IPXPORT_FSP 0x0451 /* NW FSP File Service */ +#define IPXPORT_SAP 0x0452 /* NW SAP Service Advertising */ +#define IPXPORT_RIP 0x0453 /* NW RIP Routing Information */ +#define IPXPORT_NETBIOS 0x0455 /* NW NetBIOS */ +#define IPXPORT_DIAGS 0x0456 /* NW Diagnostics */ +#define IPXPORT_WDOG 0x4001 /* NW Watchdog Packets */ +#define IPXPORT_SHELL 0x4003 /* NW Shell Socket */ +#define IPXPORT_MAX 0x8000 /* Maximum User Addressable Port */ + +/* flags passed to ipx_outputfl as last parameter */ + +#define IPX_FORWARDING 0x1 /* most of ipx header exists */ +#define IPX_ROUTETOIF 0x10 /* same as SO_DONTROUTE */ +#define IPX_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */ + +#define IPX_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_IPXIP_ROUTE 5 +#define SO_SEQNO 6 +#define SO_ALL_PACKETS 7 +#define SO_MTU 8 +#define SO_IPXTUN_ROUTE 9 + +/* + * IPX addressing + */ +#define IPX_HOSTADDRLEN 6 +#define IPX_NETADDRLEN 4 +#define XXX __attribute__((packed)) + +typedef +union ipx_host { + u_int8_t c_host[IPX_HOSTADDRLEN] XXX; + u_int16_t s_host[IPX_HOSTADDRLEN/2] XXX; +} ipx_host_t; + +typedef +union ipx_net { + u_int8_t c_net[IPX_NETADDRLEN] XXX; + u_int16_t s_net[IPX_NETADDRLEN/2] XXX; + u_int32_t l_net XXX; +} ipx_net_t; + +typedef u_int16_t ipx_port_t; + +typedef +struct ipx_addr { + ipx_net_t ipx_net XXX; + ipx_host_t ipx_host XXX; + ipx_port_t ipx_port XXX; +} ipx_addr_t; + +/* + * Socket address + */ +struct sockaddr_ipx { + u_int8_t sipx_len; + u_int8_t sipx_family; + struct ipx_addr sipx_addr; + u_int16_t sipx_type; +}; +#define sipx_net sipx_addr.ipx_net +#define sipx_network sipx_addr.ipx_net.l_net +#define sipx_node sipx_addr.ipx_host.c_host +#define sipx_port sipx_addr.ipx_port + +/* + * Definitions for IPX Internet Datagram Protocol + */ +struct ipx { + u_int16_t ipx_sum XXX; /* Checksum */ + u_int16_t ipx_len XXX; /* Length, in bytes, including header */ + u_int8_t ipx_tc XXX; /* Transport Control (i.e. hop count) */ + u_int8_t ipx_pt XXX; /* Packet Type (i.e. lev 2 protocol) */ + ipx_addr_t ipx_dna XXX; /* Destination Network Address */ + ipx_addr_t ipx_sna XXX; /* Source Network Address */ +}; +#undef XXX + +#define ipx_neteqnn(a,b) \ + (((a).s_net[0]==(b).s_net[0]) && ((a).s_net[1]==(b).s_net[1])) +#define ipx_neteq(a,b) ipx_neteqnn((a).ipx_net, (b).ipx_net) +#define satoipx_addr(sa) (((struct sockaddr_ipx *)&(sa))->sipx_addr) +#define ipx_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 ipx_hosteq(s,t) (ipx_hosteqnh((s).ipx_host,(t).ipx_host)) +#define ipx_nullnet(x) \ + (((x).ipx_net.s_net[0]==0) && ((x).ipx_net.s_net[1]==0)) +#define ipx_nullhost(x) (((x).ipx_host.s_host[0]==0) && \ + ((x).ipx_host.s_host[1]==0) && ((x).ipx_host.s_host[2]==0)) +#define ipx_wildnet(x) (((x).ipx_net.s_net[0]==0xffff) && \ + ((x).ipx_net.s_net[1]==0xffff)) +#define ipx_wildhost(x) (((x).ipx_host.s_host[0]==0xffff) && \ + ((x).ipx_host.s_host[1]==0xffff) && ((x).ipx_host.s_host[2]==0xffff)) + +#ifdef _KERNEL + +#define satosipx(a) ((struct sockaddr_ipx *)(a)) +#define sipxtosa(a) ((struct sockaddr *)(a)) + +extern int ipxcksum; +extern struct domain ipxdomain; +extern struct sockaddr_ipx ipx_netmask; +extern struct sockaddr_ipx ipx_hostmask; + +extern union ipx_host ipx_thishost; +extern union ipx_net ipx_zeronet; +extern union ipx_host ipx_zerohost; +extern union ipx_net ipx_broadnet; +extern union ipx_host ipx_broadhost; + +extern u_long ipx_pexseq; +extern u_char ipxctlerrmap[]; + +struct route; +struct sockaddr; +struct socket; +struct ipxpcb; +void ipx_abort __P((struct ipxpcb *ipxp)); +u_short ipx_cksum __P((struct mbuf *m, int len)); +int ipx_control __P((struct socket *so, u_long cmd, caddr_t data, + struct ifnet *ifp)); +void *ipx_ctlinput __P((int cmd, struct sockaddr *arg_as_sa, void *dummy)); +int ipx_ctloutput __P((int req, struct socket *so, int level, int name, + struct mbuf **value)); +int ipx_do_route __P((struct ipx_addr *src, struct route *ro)); +void ipx_drop __P((struct ipxpcb *ipxp, int errno)); +void ipx_forward __P((struct mbuf *m)); +void ipx_init __P((void)); +void ipx_input __P((struct mbuf *, ...)); +void ipxintr __P((void)); +int ipx_output __P((struct mbuf *m0, ...)); +int ipx_outputfl __P((struct mbuf *m0, struct route *ro, int flags)); +int ipx_raw_usrreq __P((struct socket *so, int req, struct mbuf *m, + struct mbuf *nam, struct mbuf *control)); +void ipx_undo_route __P((struct route *ro)); +int ipx_usrreq __P((struct socket *so, int req, struct mbuf *m, + struct mbuf *nam, struct mbuf *control)); +void ipx_watch_output __P((struct mbuf *m, struct ifnet *ifp)); + +#ifdef IPXDEBUG +struct ipx_addr ipx_addr __P((const char *)); +char *ipx_ntoa __P((struct ipx_addr)); +#endif + +#else + +#include <sys/cdefs.h> + +__BEGIN_DECLS +struct ipx_addr ipx_addr __P((const char *)); +char *ipx_ntoa __P((struct ipx_addr)); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_NETIPX_IPX_H_ */ diff --git a/sys/netipx/ipx_cksum.c b/sys/netipx/ipx_cksum.c new file mode 100644 index 00000000000..7d863648af9 --- /dev/null +++ b/sys/netipx/ipx_cksum.c @@ -0,0 +1,214 @@ +/* $OpenBSD: ipx_cksum.c,v 1.1 1996/08/16 09:15:58 mickey Exp $ */ +/* $NOWHERE: ipx_cksum.c,v 1.2 1996/05/07 09:49:39 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_cksum.c + * + * from FreeBSD Id: ipx_cksum.c,v 1.3 1995/11/04 09:02:40 julian Exp + */ + +#include <sys/param.h> +#include <sys/mbuf.h> + +#include <netipx/ipx.h> + +/* + * Checksum routine for Internetwork Packet Exchange 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 +ipx_cksum(m, len) + struct mbuf *m; + 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); +} diff --git a/sys/netipx/ipx_error.c b/sys/netipx/ipx_error.c new file mode 100644 index 00000000000..a7fe4c8c3ff --- /dev/null +++ b/sys/netipx/ipx_error.c @@ -0,0 +1,387 @@ +/* $OpenBSD: ipx_error.c,v 1.1 1996/08/16 09:15:58 mickey Exp $ */ +/* $NOWHERE: ipx_error.c,v 1.2 1996/05/07 09:49:40 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_error.c + * + * from FreeBSD Id: ipx_error.c,v 1.4 1995/12/16 02:14:32 bde Exp + */ + +#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/if.h> +#include <net/route.h> + +#include <netipx/ipx.h> +#include <netipx/spx.h> +#include <netipx/ipx_pcb.h> +#include <netipx/ipx_error.h> + +/* + * IPX_ERR routines: error generation, receive packet processing, and + * routines to turnaround packets back to the originator. + */ +#ifndef IPX_ERRPRINTFS +#define IPX_ERRPRINTFS 0 +#endif +int ipx_errprintfs = IPX_ERRPRINTFS; + +struct ipx_errstat ipx_errstat; + +int +ipx_err_x(c) +int c; +{ + register u_short *w, *lim, *base = ipx_errstat.ipx_es_codes; + u_short x = c; + + /* + * zero is a legit error code, handle specially + */ + if (x == 0) + return (0); + lim = base + IPX_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. + */ + +void +ipx_error(om, type, param) + struct mbuf *om; + int type, param; +{ + register struct ipx_epipx *ep; + struct mbuf *m; + struct ipx *nip; + register struct ipx *oip = mtod(om, struct ipx *); + + /* + * If this packet was sent to the echo port, + * and nobody was there, just echo it. + * (Yes, this is a wart!) + */ + if (type == IPX_ERR_NOSOCK && + oip->ipx_dna.ipx_port == htons(2) && + (type = ipx_echo(om))==0) + return; + + if (ipx_errprintfs) + printf("ipx_error(%x, %u, %d)\n", oip, type, param); + + /* + * Don't Generate error packets in response to multicasts. + */ + if (oip->ipx_dna.ipx_host.c_host[0] & 1) + goto freeit; + + ipx_errstat.ipx_es_error++; + /* + * Make sure that the old IPX packet had 30 bytes of data to return; + * if not, don't bother. Also don't EVER error if the old + * packet protocol was IPX_ERR. + */ + if (oip->ipx_len < sizeof(struct ipx)) { + ipx_errstat.ipx_es_oldshort++; + goto freeit; + } + if (oip->ipx_pt == IPXPROTO_ERROR) { + ipx_errstat.ipx_es_oldipx_err++; + goto freeit; + } + + /* + * First, formulate ipx_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 ipx_epipx *); + if ((u_int)type > IPX_ERR_TOO_BIG) + panic("ipx_err_error"); + ipx_errstat.ipx_es_outhist[ipx_err_x(type)]++; + ep->ipx_ep_errp.ipx_err_num = htons((u_short)type); + ep->ipx_ep_errp.ipx_err_param = htons((u_short)param); + bcopy((caddr_t)oip, (caddr_t)&ep->ipx_ep_errp.ipx_err_ipx, 42); + nip = &ep->ipx_ep_ipx; + nip->ipx_len = sizeof(*ep); + nip->ipx_len = htons((u_short)nip->ipx_len); + nip->ipx_pt = IPXPROTO_ERROR; + nip->ipx_tc = 0; + nip->ipx_dna.ipx_host = oip->ipx_sna.ipx_host; + nip->ipx_sna.ipx_host = oip->ipx_dna.ipx_host; + if (ipxcksum) { + nip->ipx_sum = 0; + nip->ipx_sum = ipx_cksum(m, sizeof(*ep)); + } else + nip->ipx_sum = 0xffff; + (void) ipx_outputfl(m, (struct route *)0, 0); + +freeit: + m_freem(om); +} + +void +ipx_printhost(addr) + register ipx_addr_t *addr; +{ + u_short port; + struct ipx_addr work = *addr; + register char *p; register u_char *q; + register char *net = "", *host = ""; + char cport[10], chost[15], cnet[15]; + + port = ntohs(work.ipx_port); + + if (ipx_nullnet(work) && ipx_nullhost(work)) { + + if (port) + printf("*.%x", port); + else + printf("*.*"); + + return; + } + + if (ipx_wildnet(work)) + net = "any"; + else if (ipx_nullnet(work)) + net = "*"; + else { + q = work.ipx_net.c_net; + sprintf(cnet, "%x%x%x%x", + q[0], q[1], q[2], q[3]); + for (p = cnet; *p == '0' && p < cnet + 8; p++) + continue; + net = p; + } + + if (ipx_wildhost(work)) + host = "any"; + else if (ipx_nullhost(work)) + host = "*"; + else { + q = work.ipx_host.c_host; + sprintf(chost, "%x%x%x%x%x%x", + q[0], q[1], q[2], q[3], q[4], q[5]); + for (p = chost; *p == '0' && p < chost + 12; p++) + continue; + host = p; + } + + if (port) { + if (strcmp(host, "*") == 0) { + host = ""; + sprintf(cport, "%x", port); + } else + sprintf(cport, ".%x", port); + } else + *cport = 0; + + printf("%s.%s%s", net, host, cport); +} + +/* + * Process a received IPX_ERR message. + */ +void +ipx_err_input(m) + struct mbuf *m; +{ + register struct ipx_errp *ep; + register struct ipx_epipx *epipx = mtod(m, struct ipx_epipx *); + register int i; + int type, code, param; + + /* + * Locate ipx_err structure in mbuf, and check + * that not corrupted and of at least minimum length. + */ + + if (ipx_errprintfs) { + printf("ipx_err_input "); + ipx_printhost(&epipx->ipx_ep_ipx.ipx_sna); + printf("%d\n", ntohs(epipx->ipx_ep_ipx.ipx_len)); + } + + i = sizeof (struct ipx_epipx); + if (((m->m_flags & M_EXT) || m->m_len < i) && + (m = m_pullup(m, i)) == 0) { + ipx_errstat.ipx_es_tooshort++; + return; + } + ep = &(mtod(m, struct ipx_epipx *)->ipx_ep_errp); + type = ntohs(ep->ipx_err_num); + param = ntohs(ep->ipx_err_param); + ipx_errstat.ipx_es_inhist[ipx_err_x(type)]++; + + /* + * Message type specific processing. + */ + if (ipx_errprintfs) + printf("ipx_err_input, type %d param %d\n", type, param); + + if (type >= IPX_ERR_TOO_BIG) { + goto badcode; + } + ipx_errstat.ipx_es_outhist[ipx_err_x(type)]++; + switch (type) { + + case IPX_ERR_UNREACH_HOST: + code = PRC_UNREACH_NET; + goto deliver; + + case IPX_ERR_TOO_OLD: + code = PRC_TIMXCEED_INTRANS; + goto deliver; + + case IPX_ERR_TOO_BIG: + code = PRC_MSGSIZE; + goto deliver; + + case IPX_ERR_FULLUP: + code = PRC_QUENCH; + goto deliver; + + case IPX_ERR_NOSOCK: + code = PRC_UNREACH_PORT; + goto deliver; + + case IPX_ERR_UNSPEC_T: + case IPX_ERR_BADSUM_T: + case IPX_ERR_BADSUM: + case IPX_ERR_UNSPEC: + code = PRC_PARAMPROB; + goto deliver; + + deliver: + /* + * Problem with datagram; advise higher level routines. + */ + + if (ipx_errprintfs) + printf("deliver to protocol %d\n", + ep->ipx_err_ipx.ipx_pt); + + switch(ep->ipx_err_ipx.ipx_pt) { + case IPXPROTO_SPX: + spx_ctlinput(code, (/* XXX */ struct sockaddr *)ep, + (void *)NULL); + break; + + default: + ipx_ctlinput(code, (/* XXX */ struct sockaddr *)ep, + (void *)NULL); + } + + goto freeit; + + default: + badcode: + ipx_errstat.ipx_es_badcode++; + goto freeit; + + } +freeit: + m_freem(m); +} + +#ifdef notdef +u_long +ipxtime() +{ + int s = splclock(); + u_long t; + + t = (time.tv_sec % (24*60*60)) * 1000 + time.tv_usec / 1000; + splx(s); + return (htonl(t)); +} +#endif + +int +ipx_echo(m) +struct mbuf *m; +{ + register struct ipx *ipx = mtod(m, struct ipx *); + register struct echo { + struct ipx ec_ipx; + u_short ec_op; /* Operation, 1 = request, 2 = reply */ + } *ec = (struct echo *)ipx; + struct ipx_addr temp; + + if (ipx->ipx_pt!=IPXPROTO_ECHO) + return(IPX_ERR_NOSOCK); + if (ec->ec_op!=htons(1)) + return(IPX_ERR_UNSPEC); + + ec->ec_op = htons(2); + + temp = ipx->ipx_dna; + ipx->ipx_dna = ipx->ipx_sna; + ipx->ipx_sna = temp; + + if (ipxcksum && ipx->ipx_sum != 0xffff) { + ipx->ipx_sum = 0; + ipx->ipx_sum = ipx_cksum(m, + (int)(((ntohs(ipx->ipx_len) - 1)|1)+1)); + } + else + ipx->ipx_sum = 0xffff; + + (void) ipx_outputfl(m, (struct route *)0, IPX_FORWARDING); + + return(0); +} diff --git a/sys/netipx/ipx_error.h b/sys/netipx/ipx_error.h new file mode 100644 index 00000000000..12cde2dc91b --- /dev/null +++ b/sys/netipx/ipx_error.h @@ -0,0 +1,106 @@ +/* $OpenBSD: ipx_error.h,v 1.1 1996/08/16 09:15:59 mickey Exp $ */ +/* $NOWHERE: ipx_error.h,v 1.2 1996/05/07 09:49:41 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_error.h + * + * from FreeBSD Id: ipx_error.h,v 1.5 1995/11/24 12:25:04 bde Exp + */ + +#ifndef _NETIPX_IPX_ERROR_H_ +#define _NETIPX_IPX_ERROR_H_ + +/* + * IPX error messages + */ + +struct ipx_errp { + u_int32_t ipx_err_num; /* Error Number */ + u_int32_t ipx_err_param; /* Error Parameter */ + struct ipx ipx_err_ipx; /* Initial segment of offending pkt */ + u_int8_t ipx_err_lev2[12];/* this is higher level protocol */ +}; + +struct ipx_epipx { + struct ipx ipx_ep_ipx; + struct ipx_errp ipx_ep_errp; +}; + +#define IPX_ERR_UNSPEC 0 /* Unspecified Error detected at dest. */ +#define IPX_ERR_BADSUM 1 /* Bad Checksum detected at dest */ +#define IPX_ERR_NOSOCK 2 /* Specified socket does not exist at dest*/ +#define IPX_ERR_FULLUP 3 /* Dest. refuses packet due to resource lim.*/ +#define IPX_ERR_UNSPEC_T 0x200 /* Unspec. Error occured before reaching dest*/ +#define IPX_ERR_BADSUM_T 0x201 /* Bad Checksum detected in transit */ +#define IPX_ERR_UNREACH_HOST 0x202 /* Dest cannot be reached from here*/ +#define IPX_ERR_TOO_OLD 0x203 /* Packet x'd 15 routers without delivery*/ +#define IPX_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 IPX_ERR_MAX 20 + +/* + * Variables related to this implementation + * of the IPX error message protocol. + */ +struct ipx_errstat { +/* statistics related to ipx_err packets generated */ + int ipx_es_error; /* # of calls to ipx_error */ + int ipx_es_oldshort; /* no error 'cuz old ip too short */ + int ipx_es_oldipx_err; /* no error 'cuz old was ipx_err */ + int ipx_es_outhist[IPX_ERR_MAX]; /* statistics related to input messages processed */ + int ipx_es_badcode; /* ipx_err_code out of range */ + int ipx_es_tooshort; /* packet < IPX_MINLEN */ + int ipx_es_checksum; /* bad checksum */ + int ipx_es_badlen; /* calculated bound mismatch */ + int ipx_es_reflect; /* number of responses */ + int ipx_es_inhist[IPX_ERR_MAX]; + u_short ipx_es_codes[IPX_ERR_MAX];/* which error code for outhist since we might not know all */ +}; + +#ifdef _KERNEL +extern struct ipx_errstat ipx_errstat; + +int ipx_echo __P((struct mbuf *m)); +void ipx_err_input __P((struct mbuf *m)); +int ipx_err_x __P((int c)); +void ipx_error __P((struct mbuf *om, int type, int param)); +void ipx_printhost __P((ipx_addr_t *addr)); +#endif + +#endif /* !_NETIPX_IPX_ERROR_H_ */ diff --git a/sys/netipx/ipx_if.h b/sys/netipx/ipx_if.h new file mode 100644 index 00000000000..9438ed9e2ab --- /dev/null +++ b/sys/netipx/ipx_if.h @@ -0,0 +1,104 @@ +/* $OpenBSD: ipx_if.h,v 1.1 1996/08/16 09:15:59 mickey Exp $ */ +/* $NOWHERE: ipx_if.h,v 1.2 1996/05/07 09:49:41 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_if.h + * + * from FreeBSD Id: ipx_if.h,v 1.5 1995/11/24 12:25:05 bde Exp + */ + +#ifndef _NETIPX_IPX_IF_H_ +#define _NETIPX_IPX_IF_H_ + +/* + * Interface address. 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 ipx_ifaddr { + struct ifaddr ia_ifa; /* protocol-independent info */ +#define ia_ifp ia_ifa.ifa_ifp +#define ia_flags ia_ifa.ifa_flags + TAILQ_ENTRY(ipx_ifaddr) ia_list;/* list of IPX addresses */ + struct sockaddr_ipx ia_addr; /* reserve space for my address */ + struct sockaddr_ipx ia_dstaddr;/* space for my broadcast address */ +#define ia_broadaddr ia_dstaddr + struct sockaddr_ipx ia_netmask;/* space for my network mask */ +}; + +struct ipx_aliasreq { + char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + struct sockaddr_ipx ifra_addr; + struct sockaddr_ipx ifra_dstaddr; +#define ifra_broadaddr ifra_dstaddr +}; +/* + * Given a pointer to an ipx_ifaddr (ifaddr), + * return a pointer to the addr as a sockadd_ipx. + */ + +#define IA_SIPX(ia) (&(((struct ipx_ifaddr *)(ia))->ia_addr)) + +#define ETHERTYPE_8023 0x0001 /* Ethernet_802.3 */ +#define ETHERTYPE_8022 0x0004 /* Ethernet_802.2 */ +#define ETHERTYPE_SNAP 0x0005 /* Ethernet_SNAP, internal use only */ +#define ETHERTYPE_8022TR 0x0011 /* Ethernet_802.2 w/ trailers */ +#define ETHERTYPE_II 0x8137 /* Ethernet_II */ + +#ifdef IPXIP +struct ipxip_req { + struct sockaddr rq_ipx; /* must be ipx format destination */ + struct sockaddr rq_ip; /* must be ip format gateway */ + u_int16_t rq_flags; +}; +#endif + +#ifdef _KERNEL +TAILQ_HEAD(ipx_ifaddrhead, ipx_ifaddr); +extern struct ifqueue ipxintrq; /* IPX input packet queue */ +extern struct ipx_ifaddrhead ipx_ifaddr; + +struct ipx_ifaddr * + ipx_iaonnetof __P((struct ipx_addr *dst)); +int ipx_ifinit __P((struct ifnet *ifp, struct ipx_ifaddr *ia, + struct sockaddr_ipx *sipx, int scrub)); +void ipx_ifscrub __P((struct ifnet *ifp, struct ipx_ifaddr *ia)); +#endif + +#endif /* !_NETIPX_IPX_IF_H_ */ diff --git a/sys/netipx/ipx_input.c b/sys/netipx/ipx_input.c new file mode 100644 index 00000000000..9c59e553f59 --- /dev/null +++ b/sys/netipx/ipx_input.c @@ -0,0 +1,569 @@ +/* $OpenBSD: ipx_input.c,v 1.1 1996/08/16 09:15:59 mickey Exp $ */ +/* $NOWHERE: ipx_input.c,v 1.2 1996/05/07 09:49:42 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_input.c + * + * from FreeBSD Id: ipx_input.c,v 1.8 1996/03/11 15:13:48 davidg Exp + */ + +#include <sys/param.h> +#include <sys/queue.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 <sys/proc.h> +#include <vm/vm.h> + +#include <net/if.h> +#include <net/route.h> +#include <net/netisr.h> +#include <net/raw_cb.h> + +#include <netipx/ipx.h> +#include <netipx/spx.h> +#include <netipx/ipx_if.h> +#include <netipx/ipx_pcb.h> +#include <netipx/ipx_var.h> +#include <netipx/ipx_error.h> + +#ifndef IPXPRINTFS +#define IPXPRINTFS 1 /* printing forwarding information */ +#endif + +int ipxprintfs = IPXPRINTFS; +int ipxcksum = 0; +int ipxdonosocks = 0; +int ipxforwarding = 0; + +union ipx_host ipx_thishost; +union ipx_net ipx_zeronet; +union ipx_host ipx_zerohost; + +union ipx_net ipx_broadnet; +union ipx_host ipx_broadhost; + +struct ipxstat ipxstat; +struct sockaddr_ipx ipx_netmask, ipx_hostmask; + +int ipxintr_getpck = 0; +int ipxintr_swtch = 0; + +static u_int16_t allones[] = {0xffff, 0xffff, 0xffff}; + +#ifndef IPXCBHASHSIZE +#define IPXCBHASHSIZE 32 +#endif +struct ipxpcbtable ipxrawcbtable; +int ipxrawcbhashsize = IPXCBHASHSIZE; + +struct ipx_ifaddrhead ipx_ifaddr; +struct ifqueue ipxintrq; +int ipxqmaxlen = IFQ_MAXLEN; + +u_long ipx_pexseq; + +/* + * IPX initialization. + */ + +void +ipx_init() +{ + ipx_broadnet = * (union ipx_net *) allones; + ipx_broadhost = * (union ipx_host *) allones; + + ipx_pexseq = time.tv_usec; + ipxintrq.ifq_maxlen = ipxqmaxlen; + + ipx_netmask.sipx_len = 6; + ipx_netmask.sipx_addr.ipx_net = ipx_broadnet; + + ipx_hostmask.sipx_len = 12; + ipx_hostmask.sipx_addr.ipx_net = ipx_broadnet; + ipx_hostmask.sipx_addr.ipx_host = ipx_broadhost; + + ipx_pcbinit(&ipxrawcbtable, ipxrawcbhashsize); + + TAILQ_INIT(&ipx_ifaddr); +} + +/* + * IPX input routine. Pass to next level. + */ +void +ipxintr() +{ + register struct ipx *ipx; + register struct mbuf *m; + register struct ipxpcb *ipxp; + register int i; + int len, s, error; + char oddpacketp; + +next: + /* + * Get next datagram off input queue and get IPX header + * in first mbuf. + */ + s = splimp(); + IF_DEQUEUE(&ipxintrq, m); + splx(s); + ipxintr_getpck++; + if (m == 0) { + return; + } +#ifdef DIAGNOSTIC + if ((m->m_flags & M_PKTHDR) == 0) + panic("ipxintr: no hdr"); +#endif +#ifdef IPXDEBUG + if (0) { + u_int8_t *p = (u_int8_t *)mtod(m, struct ipx *), i; + + printf("ipx: "); + for (i = sizeof(struct ipx); i--; p++) + printf("%x ", *p); + printf("\n"); + } +#endif + if ((m->m_flags & M_EXT || m->m_len < sizeof (struct ipx)) && + (m = m_pullup(m, sizeof (struct ipx))) == 0) { + ipxstat.ipxs_toosmall++; +#ifdef IPXDEBUG + printf("ipxintr: too small [%u]\n", m->m_len); +#endif + goto next; + } + + /* + * Give any raw listeners a crack at the packet + */ + for (ipxp = ipxrawcbtable.ipxpt_queue.cqh_first; + ipxp != (struct ipxpcb *)&ipxrawcbtable.ipxpt_queue; + ipxp = ipxp->ipxp_queue.cqe_next) { + struct mbuf *m1 = m_copy(m, 0, (int)M_COPYALL); + if (m1) + ipx_input(m1, ipxp); + } + + ipx = mtod(m, struct ipx *); + len = ntohs(ipx->ipx_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 IPX 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) { + ipxstat.ipxs_tooshort++; +#ifdef IPXDEBUG + printf("ipxintr: too short [%u]\n", m->m_pkthdr.len); +#endif + 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 (ipxcksum && ((i = ipx->ipx_sum)!=0xffff)) { + ipx->ipx_sum = 0; + if (i != (ipx->ipx_sum = ipx_cksum(m, len))) { + ipxstat.ipxs_badsum++; +#ifdef IPXDEBUG + printf("ipxintr: bad sum [%u]\n", i); +#endif + ipx->ipx_sum = i; + if (ipx_hosteqnh(ipx_thishost, ipx->ipx_dna.ipx_host)) + error = IPX_ERR_BADSUM; + else + error = IPX_ERR_BADSUM_T; + ipx_error(m, error, 0); + goto next; + } + } + /* + * Is this a directed broadcast? + */ + if (ipx_hosteqnh(ipx_broadhost,ipx->ipx_dna.ipx_host)) { + if ((!ipx_neteq(ipx->ipx_dna, ipx->ipx_sna)) && + (!ipx_neteqnn(ipx->ipx_dna.ipx_net, ipx_broadnet)) && + (!ipx_neteqnn(ipx->ipx_sna.ipx_net, ipx_zeronet)) && + (!ipx_neteqnn(ipx->ipx_dna.ipx_net, ipx_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 (ipx->ipx_tc < IPX_MAXHOPS) { +#ifdef IPXDEBUG + printf("ipxintr: forwarding bcast\n"); +#endif + ipx_forward(m); + goto next; + } + } + /* + * Is this our packet? If not, forward. + */ + } else if (!ipx_hosteqnh(ipx_thishost,ipx->ipx_dna.ipx_host)) { +#ifdef IPXDEBUG + printf("ipxintr: forwarding to %s\n", ipx_ntoa(ipx->ipx_dna)); +#endif + ipx_forward(m); + goto next; + } + /* + * Locate pcb for datagram. + */ + ipxp = ipx_pcblookup(&ipx->ipx_sna, ipx->ipx_dna.ipx_port, IPX_WILDCARD); + /* + * Switch out to protocol's input routine. + */ + ipxintr_swtch++; + if (ipxp) { + if (oddpacketp) { + m_adj(m, -1); + } + if ((ipxp->ipxp_flags & IPXP_ALL_PACKETS)==0) + switch (ipx->ipx_pt) { + + case IPXPROTO_SPX: +#ifdef IPXDEBUG + printf("ipxintr: spx packet\n"); +#endif + spx_input(m, ipxp); + goto next; + + case IPXPROTO_ERROR: +#ifdef IPXDEBUG + printf("ipxintr: error packet\n"); +#endif + ipx_err_input(m); + goto next; + } +#ifdef IPXDEBUG + printf("ipxintr: ipx packet\n"); +#endif + ipx_input(m, ipxp); + } else + ipx_error(m, IPX_ERR_NOSOCK, 0); + + goto next; + +bad: + m_freem(m); + goto next; +} + +u_char ipxctlerrmap[PRC_NCMDS] = { + ECONNABORTED, ECONNABORTED, 0, 0, + 0, 0, EHOSTDOWN, EHOSTUNREACH, + ENETUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED, + EMSGSIZE, 0, 0, 0, + 0, 0, 0, 0 +}; + +void * +ipx_ctlinput(cmd, arg_as_sa, dummy) + int cmd; + struct sockaddr *arg_as_sa; /* XXX should be swapped with dummy */ + void *dummy; +{ + caddr_t arg = (/* XXX */ caddr_t)arg_as_sa; + struct ipx_addr *ipx; + struct ipxpcb *ipxp; + struct ipx_errp *errp; + int type; + + if (cmd < 0 || cmd > PRC_NCMDS) + return; + if (ipxctlerrmap[cmd] == 0) + return; /* XXX */ + type = IPX_ERR_UNREACH_HOST; + errp = (struct ipx_errp *)arg; + switch (cmd) { + struct sockaddr_ipx *sipx; + + case PRC_IFDOWN: + case PRC_HOSTDEAD: + case PRC_HOSTUNREACH: + sipx = (struct sockaddr_ipx *)arg; + if (sipx->sipx_family != AF_IPX) + return; + ipx = &sipx->sipx_addr; + break; + + default: + ipx = &errp->ipx_err_ipx.ipx_dna; + type = errp->ipx_err_num; + type = ntohs((u_short)type); + break; + } + switch (type) { + + case IPX_ERR_UNREACH_HOST: + ipx_pcbnotify(ipx, (int)ipxctlerrmap[cmd], ipx_abort, (long)0); + break; + + case IPX_ERR_NOSOCK: + ipxp = ipx_pcblookup(ipx, errp->ipx_err_ipx.ipx_sna.ipx_port, + IPX_WILDCARD); + if(ipxp && ipxdonosocks && ! ipx_nullhost(ipxp->ipxp_faddr)) + (void) ipx_drop(ipxp, (int)ipxctlerrmap[cmd]); + } + return NULL; +} + +/* + * 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 IPX errors don't have a large enough repetoire + * of codes and types. + */ +struct route ipx_droute; +struct route ipx_sroute; + +void +ipx_forward(m) +struct mbuf *m; +{ + register struct ipx *ipx = mtod(m, struct ipx *); + register int error, type, code; + struct mbuf *mcopy = NULL; + int agedelta = 1; + int flags = IPX_FORWARDING; + int ok_there = 0; + int ok_back = 0; + + if (ipxforwarding == 0) { + /* can't tell difference between net and host */ + type = IPX_ERR_UNREACH_HOST, code = 0; + goto senderror; + } + ipx->ipx_tc++; + if (ipx->ipx_tc > IPX_MAXHOPS) { + type = IPX_ERR_TOO_OLD, code = 0; + goto senderror; + } + /* + * Save at most 42 bytes of the packet in case + * we need to generate an IPX error message to the src. + */ + mcopy = m_copy(m, 0, imin((int)ntohs(ipx->ipx_len), 42)); + + if ((ok_there = ipx_do_route(&ipx->ipx_dna,&ipx_droute))==0) { + type = IPX_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 (ipx->ipx_dna.ipx_host.c_host[0] & 0x1) { + struct ipx_ifaddr *ia = ipx_iaonnetof(&ipx->ipx_dna); + struct ifnet *ifp; + if (ia) { + /* I'm gonna hafta eat this packet */ + agedelta += IPX_MAXHOPS - ipx->ipx_tc; + ipx->ipx_tc = IPX_MAXHOPS; + } + if ((ok_back = ipx_do_route(&ipx->ipx_sna,&ipx_sroute))==0) { + /* error = ENETUNREACH; He'll never get it! */ + m_freem(m); + goto cleanup; + } + if (ipx_droute.ro_rt && + (ifp=ipx_droute.ro_rt->rt_ifp) && + ipx_sroute.ro_rt && + (ifp!=ipx_sroute.ro_rt->rt_ifp)) { + flags |= IPX_ALLOWBROADCAST; + } else { + type = IPX_ERR_UNREACH_HOST, code = 0; + goto senderror; + } + } + /* need to adjust checksum */ + if (ipxcksum && ipx->ipx_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(ipx->ipx_len))+1)>>1)-2) & 0xf; + x.l = ipx->ipx_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) ipx->ipx_sum = 0; else ipx->ipx_sum = x.l; + } else + ipx->ipx_sum = 0xffff; + + error = ipx_outputfl(m, &ipx_droute, flags); + + if (ipxprintfs && !error) { + printf("forward: "); + ipx_printhost(&ipx->ipx_sna); + printf(" to "); + ipx_printhost(&ipx->ipx_dna); + printf(" hops %d\n", ipx->ipx_tc); + } + + if (error && mcopy != NULL) { + ipx = mtod(mcopy, struct ipx *); + type = IPX_ERR_UNSPEC_T, code = 0; + switch (error) { + + case ENETUNREACH: + case EHOSTDOWN: + case EHOSTUNREACH: + case ENETDOWN: + case EPERM: + type = IPX_ERR_UNREACH_HOST; + break; + + case EMSGSIZE: + type = IPX_ERR_TOO_BIG; + code = 576; /* too hard to figure out mtu here */ + break; + + case ENOBUFS: + type = IPX_ERR_UNSPEC_T; + break; + } + mcopy = NULL; + senderror: + ipx_error(m, type, code); + } +cleanup: + if (ok_there) + ipx_undo_route(&ipx_droute); + if (ok_back) + ipx_undo_route(&ipx_sroute); + if (mcopy != NULL) + m_freem(mcopy); +} + +int +ipx_do_route(src, ro) +struct ipx_addr *src; +struct route *ro; +{ + struct sockaddr_ipx *dst; + + bzero((caddr_t)ro, sizeof (*ro)); + dst = (struct sockaddr_ipx *)&ro->ro_dst; + + dst->sipx_len = sizeof(*dst); + dst->sipx_family = AF_IPX; + dst->sipx_addr = *src; + dst->sipx_addr.ipx_port = 0; + rtalloc(ro); + if (ro->ro_rt == 0 || ro->ro_rt->rt_ifp == 0) { + return (0); + } + ro->ro_rt->rt_use++; + return (1); +} + +void +ipx_undo_route(ro) +register struct route *ro; +{ + if (ro->ro_rt) {RTFREE(ro->ro_rt);} +} + +void +ipx_watch_output(m, ifp) +struct mbuf *m; +struct ifnet *ifp; +{ + register struct ipxpcb *ipxp; + register struct ifaddr *ifa; + /* + * Give any raw listeners a crack at the packet + */ + for (ipxp = ipxrawcbtable.ipxpt_queue.cqh_first; + ipxp != (struct ipxpcb *)&ipxrawcbtable.ipxpt_queue; + ipxp = ipxp->ipxp_queue.cqe_next) { + struct mbuf *m0 = m_copy(m, 0, (int)M_COPYALL); + if (m0) { + register struct ipx *ipx; + + M_PREPEND(m0, sizeof (*ipx), M_DONTWAIT); + if (m0 == NULL) + continue; + ipx = mtod(m0, struct ipx *); + ipx->ipx_sna.ipx_net = ipx_zeronet; + ipx->ipx_sna.ipx_host = ipx_thishost; + if (ifp && (ifp->if_flags & IFF_POINTOPOINT)) + for(ifa = ifp->if_addrlist.tqh_first; ifa; + ifa = ifa->ifa_list.tqe_next) { + if (ifa->ifa_addr->sa_family == AF_IPX) { + ipx->ipx_sna = IA_SIPX(ifa)->sipx_addr; + break; + } + } + ipx->ipx_len = ntohl(m0->m_pkthdr.len); + ipx_input(m0, ipxp); + } + } +} diff --git a/sys/netipx/ipx_ip.c b/sys/netipx/ipx_ip.c new file mode 100644 index 00000000000..7788f2a405e --- /dev/null +++ b/sys/netipx/ipx_ip.c @@ -0,0 +1,457 @@ +/* $OpenBSD: ipx_ip.c,v 1.1 1996/08/16 09:16:00 mickey Exp $ */ +/* $NOWHERE: ipx_ip.c,v 1.2 1996/05/07 09:49:43 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_ip.c + * + * from FreeBSD Id: ipx_ip.c,v 1.7 1996/03/11 15:13:50 davidg Exp + */ + +/* + * Software interface driver for encapsulating IPX in IP. + */ + +#ifdef IPXIP +#include <sys/param.h> +#include <sys/queue.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/if_types.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 <netipx/ipx.h> +#include <netipx/ipx_if.h> +#include <netipx/ipx_ip.h> + +#include <machine/stdarg.h> + +struct ifnet ipxipif; +struct ifnet_en *ipxip_list; /* list of all hosts and gateways or broadcast addrs */ + +void +ipxipprotoinit(void) +{ + (void) ipxipattach(); +} + +struct ifnet_en * +ipxipattach(void) +{ + register struct ifnet_en *m; + register struct ifnet *ifp; + + if (ipxipif.if_mtu == 0) { + ifp = &ipxipif; + sprintf(ifp->if_xname, "ipx0"); + ifp->if_mtu = LOMTU; + ifp->if_ioctl = ipxipioctl; + ifp->if_output = ipxipoutput; + ifp->if_start = ipxipstart; + ifp->if_flags = IFF_POINTOPOINT; + ifp->if_type = IFT_NSIP; + } + + MALLOC((m), struct ifnet_en *, sizeof(*m), M_PCB, M_NOWAIT); + if (m == NULL) return (NULL); + m->ifen_next = ipxip_list; + ipxip_list = m; + ifp = &m->ifen_ifnet; + + sprintf(ifp->if_xname, "ipx0"); + ifp->if_mtu = LOMTU; + ifp->if_ioctl = ipxipioctl; + ifp->if_output = ipxipoutput; + ifp->if_start = ipxipstart; + ifp->if_flags = IFF_POINTOPOINT; + if_attach(ifp); + + return (m); +} + + +/* + * Process an ioctl request. + */ +/* ARGSUSED */ +int +ipxipioctl(ifp, cmd, data) + register struct ifnet *ifp; + u_long cmd; + caddr_t data; +{ + int error = 0; + struct ifreq *ifr; + + switch (cmd) { + + case SIOCSIFADDR: + ifp->if_flags |= IFF_UP; + /* fall into: */ + + 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 = ipxip_free(ifp); + + + default: + error = EINVAL; + } + return (error); +} + +struct mbuf *ipxip_badlen; +struct mbuf *ipxip_lastin; +int ipxip_hold_input; + +void +ipxip_input( struct mbuf *m, ...) +{ + struct ifnet *ifp; + register struct ip *ip; + register struct ipx *ipx; + register struct ifqueue *ifq = &ipxintrq; + int len, s; + va_list ap; + + va_start(ap, m); + ifp = va_arg(ap, struct ifnet *); + va_end(ap); + + if (ipxip_hold_input) { + if (ipxip_lastin) { + m_freem(ipxip_lastin); + } + ipxip_lastin = m_copym(m, 0, (int)M_COPYALL, M_DONTWAIT); + } + /* + * Get IP and IPX header together in first mbuf. + */ + ipxipif.if_ipackets++; + s = sizeof (struct ip) + sizeof (struct ipx); + if (((m->m_flags & M_EXT) || m->m_len < s) && + (m = m_pullup(m, s)) == 0) { + ipxipif.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) { + ipxipif.if_ierrors++; + return; + } + ip = mtod(m, struct ip *); + } + } + + /* + * Make mbuf data length reflect IPX length. + * If not enough data to reflect IPX length, drop. + */ + m->m_data += sizeof (struct ip); + m->m_len -= sizeof (struct ip); + m->m_pkthdr.len -= sizeof (struct ip); + ipx = mtod(m, struct ipx *); + len = ntohs(ipx->ipx_len); + if (len & 1) len++; /* Preserve Garbage Byte */ + if (ip->ip_len != len) { + if (len > ip->ip_len) { + ipxipif.if_ierrors++; + if (ipxip_badlen) m_freem(ipxip_badlen); + ipxip_badlen = m; + return; + } + /* Any extra will be trimmed off by the IPX routines */ + } + + /* + * Place interface pointer before the data + * for the receiving protocol. + */ + m->m_pkthdr.rcvif = ifp; + /* + * Deliver to IPX + */ + s = splimp(); + if (IF_QFULL(ifq)) { + IF_DROP(ifq); +bad: + m_freem(m); + splx(s); + return; + } + IF_ENQUEUE(ifq, m); + schednetisr(NETISR_IPX); + splx(s); + return; +} + +/* ARGSUSED */ +int +ipxipoutput(ifp, m, dst, rt) + struct ifnet *ifp; + register struct mbuf *m; + struct sockaddr *dst; + struct rtentry *rt; +{ + register struct ifnet_en *ifn = (struct ifnet_en *)ifp; + register struct ip *ip; + register struct route *ro = &(ifn->ifen_route); + register int len = 0; + register struct ipx *ipx = mtod(m, struct ipx *); + int error; + + ifn->ifen_ifnet.if_opackets++; + ipxipif.if_opackets++; + + /* + * Calculate data length and make space + * for IP header. + */ + len = ntohs(ipx->ipx_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); +} + +void +ipxipstart(ifp) +struct ifnet *ifp; +{ + panic("ipxip_start called\n"); +} + +struct ifreq ifr_ipxip = {"ipx0"}; + +int +ipxip_route(m) + register struct mbuf *m; +{ + register struct ipxip_req *rq = mtod(m, struct ipxip_req *); + struct sockaddr_ipx *ipx_dst = (struct sockaddr_ipx *)&rq->rq_ipx; + 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 IPX address: + */ + if (ipx_hosteqnh(ipx_thishost, ipx_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.tqh_first; ia; ia = ia->ia_list.tqe_next) + if (ia->ia_ifp == ifp) + break; + if (ia == NULL) + ia = in_ifaddr.tqh_first; + if (ia == NULL) { + RTFREE(ro.ro_rt); + return (EADDRNOTAVAIL); + } + src = (struct sockaddr_in *)&ia->ia_addr; + } + + /* + * Is there a free (pseudo-)interface or space? + */ + for (ifn = ipxip_list; ifn; ifn = ifn->ifen_next) { + if ((ifn->ifen_ifnet.if_flags & IFF_UP) == 0) + break; + } + if (ifn == NULL) + ifn = ipxipattach(); + 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_ipxip.ifr_dstaddr = * (struct sockaddr *) ipx_dst; + ipx_control((struct socket *)0, (int)SIOCSIFDSTADDR, + (caddr_t)&ifr_ipxip, (struct ifnet *)ifn); + satoipx_addr(ifr_ipxip.ifr_addr).ipx_host = ipx_thishost; + return (ipx_control((struct socket *)0, (int)SIOCSIFADDR, + (caddr_t)&ifr_ipxip, (struct ifnet *)ifn)); +} + +int +ipxip_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); +} + +void * +ipxip_ctlinput(cmd, sa, dummy) + int cmd; + struct sockaddr *sa; + void *dummy; +{ + /*extern u_char inetctlerrmap[]; */ /*XXX*/ /*JRE*/ + struct sockaddr_in *sin; + /* int in_rtchange(); */ /*XXX*/ /*JRE*/ + + if ((unsigned)cmd >= PRC_NCMDS) + return NULL; + if (sa->sa_family != AF_INET && sa->sa_family != AF_IMPLINK) + return NULL; + sin = (struct sockaddr_in *)sa; + if (sin->sin_addr.s_addr == INADDR_ANY) + return NULL; + + switch (cmd) { + + case PRC_ROUTEDEAD: + case PRC_REDIRECT_NET: + case PRC_REDIRECT_HOST: + case PRC_REDIRECT_TOSNET: + case PRC_REDIRECT_TOSHOST: + ipxip_rtchange(&sin->sin_addr); + break; + } + return NULL; +} + +void +ipxip_rtchange(dst) + register struct in_addr *dst; +{ + register struct ifnet_en *ifn; + + for (ifn = ipxip_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 diff --git a/sys/netipx/ipx_ip.h b/sys/netipx/ipx_ip.h new file mode 100644 index 00000000000..2ea48a7a41a --- /dev/null +++ b/sys/netipx/ipx_ip.h @@ -0,0 +1,76 @@ +/* $OpenBSD: ipx_ip.h,v 1.1 1996/08/16 09:16:00 mickey Exp $ */ +/* $NOWHERE: ipx_ip.h,v 1.2 1996/05/07 09:49:44 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipxip.h + * + * from FreeBSD Id: ipx_ip.h,v 1.5 1995/12/16 03:43:49 bde Exp + */ + +#ifndef _NETIPX_IPXIP_H_ +#define _NETIPX_IPXIP_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; +}; + +#define LOMTU (1024+512) /* XXX this is TINY_LOMTU */ + +#ifdef _KERNEL + +extern struct ifnet ipxipif; +extern struct ifnet_en *ipxip_list; + +void ipxipprotoinit __P((void)); +struct ifnet_en * ipxipattach __P((void)); +void *ipxip_ctlinput __P((int cmd, struct sockaddr *sa, void *arg)); +int ipxip_free __P((struct ifnet *ifp)); +void ipxip_input __P((struct mbuf *m, ... )); +int ipxipioctl __P((struct ifnet *ifp, u_long cmd, caddr_t data)); +int ipxipoutput __P((struct ifnet *ifp, struct mbuf *m, + struct sockaddr *dst, struct rtentry *rt)); +int ipxip_route __P((struct mbuf *m)); +void ipxip_rtchange __P((struct in_addr *dst)); +void ipxipstart __P((struct ifnet *ifp)); + +#endif /* _KERNEL */ + +#endif /* !_NETIPX_IPXIP_H_ */ diff --git a/sys/netipx/ipx_outputfl.c b/sys/netipx/ipx_outputfl.c new file mode 100644 index 00000000000..df38a10ec36 --- /dev/null +++ b/sys/netipx/ipx_outputfl.c @@ -0,0 +1,163 @@ +/* $OpenBSD: ipx_outputfl.c,v 1.1 1996/08/16 09:16:00 mickey Exp $ */ +/* $NOWHERE: ipx_outputfl.c,v 1.2 1996/05/07 09:49:45 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_outputfl.c + * + * from FreeBSD Id: ipx_outputfl.c,v 1.4 1996/03/11 15:13:52 davidg Exp + */ + +#include <sys/param.h> +#include <sys/queue.h> +#include <sys/systm.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 <netipx/ipx.h> +#include <netipx/ipx_if.h> +#include <netipx/ipx_var.h> + +int ipx_hold_output = 0; +int ipx_copy_output = 0; +int ipx_outputfl_cnt = 0; +struct mbuf *ipx_lastout; + +int +ipx_outputfl(m0, ro, flags) + struct mbuf *m0; + struct route *ro; + int flags; +{ + register struct ipx *ipx = mtod(m0, struct ipx *); + register struct ifnet *ifp = 0; + int error = 0; + struct sockaddr_ipx *dst; + struct route ipxroute; + + if (ipx_hold_output) { + if (ipx_lastout) { + (void)m_free(ipx_lastout); + } + ipx_lastout = m_copy(m0, 0, (int)M_COPYALL); + } + /* + * Route packet. + */ + if (ro == 0) { + ro = &ipxroute; + bzero((caddr_t)ro, sizeof (*ro)); + } + dst = (struct sockaddr_ipx *)&ro->ro_dst; + if (ro->ro_rt == 0) { + dst->sipx_family = AF_IPX; + dst->sipx_len = sizeof (*dst); + dst->sipx_addr = ipx->ipx_dna; + dst->sipx_addr.ipx_port = 0; + /* + * If routing to interface only, + * short circuit routing lookup. + */ + if (flags & IPX_ROUTETOIF) { + struct ipx_ifaddr *ia = ipx_iaonnetof(&ipx->ipx_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_ipx *)ro->ro_rt->rt_gateway; +gotif: + /* + * Look for multicast addresses and + * verify user is allowed to send + * such a packet. + */ + if (dst->sipx_addr.ipx_host.c_host[0]&1) { + if ((ifp->if_flags & IFF_BROADCAST) == 0) { + error = EADDRNOTAVAIL; + goto bad; + } + if ((flags & IPX_ALLOWBROADCAST) == 0) { + error = EACCES; + goto bad; + } + } + + if (htons(ipx->ipx_len) <= ifp->if_mtu) { + ipx_outputfl_cnt++; + if (ipx_copy_output) { + ipx_watch_output(m0, ifp); + } + error = (*ifp->if_output)(ifp, m0, + (struct sockaddr *)dst, ro->ro_rt); + goto done; + } else error = EMSGSIZE; +bad: + if (ipx_copy_output) { + ipx_watch_output(m0, ifp); + } + m_freem(m0); +done: + if (ro == &ipxroute && (flags & IPX_ROUTETOIF) == 0 && ro->ro_rt) { + RTFREE(ro->ro_rt); + ro->ro_rt = 0; + } + return (error); +} diff --git a/sys/netipx/ipx_pcb.c b/sys/netipx/ipx_pcb.c new file mode 100644 index 00000000000..9002e308366 --- /dev/null +++ b/sys/netipx/ipx_pcb.c @@ -0,0 +1,410 @@ +/* $OpenBSD: ipx_pcb.c,v 1.1 1996/08/16 09:16:01 mickey Exp $ */ +/* $NOWHERE: ipx_pcb.c,v 1.2 1996/05/07 09:49:46 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_pcb.c + * + * from FreeBSD Id: ipx_pcb.c,v 1.5 1996/03/11 15:13:53 davidg Exp + */ + +#include <sys/param.h> +#include <sys/queue.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 <netipx/ipx.h> +#include <netipx/ipx_if.h> +#include <netipx/ipx_pcb.h> + +struct ipx_addr zeroipx_addr; + +#define IPXPCBHASH(table, faddr, fport, laddr, lport) \ + &(table)->ipxpt_hashtbl[(ntohl((faddr)->ipx_net.l_net) \ + + ntohs((fport)) \ + + ntohs((lport))) & (table->ipxpt_hash)] +void +ipx_pcbinit(table, hashsize) + struct ipxpcbtable *table; + int hashsize; +{ + CIRCLEQ_INIT(&table->ipxpt_queue); + table->ipxpt_hashtbl = hashinit(hashsize, M_PCB, &table->ipxpt_hash); + table->ipxpt_lport = 0; +} + +int +ipx_pcballoc(so, head) + struct socket *so; + struct ipxpcbtable *head; +{ + register struct ipxpcb *ipxp; + + ipxp = malloc(sizeof(*ipxp), M_PCB, M_DONTWAIT); + if (ipxp == NULL) + return (ENOBUFS); + bzero((caddr_t)ipxp, sizeof(*ipxp)); + ipxp->ipxp_socket = so; + ipxp->ipxp_table = head; + CIRCLEQ_INSERT_HEAD(&head->ipxpt_queue, ipxp, ipxp_queue); + LIST_INSERT_HEAD(IPXPCBHASH(head, &ipxp->ipxp_faddr, ipxp->ipxp_fport, + &ipxp->ipxp_laddr, ipxp->ipxp_lport), ipxp, ipxp_hash); + so->so_pcb = (caddr_t)ipxp; + return (0); +} + +int +ipx_pcbbind(ipxp, nam) + register struct ipxpcb *ipxp; + struct mbuf *nam; +{ + register struct sockaddr_ipx *sipx; + u_short lport = 0; + + if (ipxp->ipxp_lport || !ipx_nullhost(ipxp->ipxp_laddr)) + return (EINVAL); + if (nam == 0) + goto noname; + sipx = mtod(nam, struct sockaddr_ipx *); + if (nam->m_len != sizeof (*sipx)) + return (EINVAL); + if (!ipx_nullhost(sipx->sipx_addr)) { + int tport = sipx->sipx_port; + + sipx->sipx_port = 0; /* yech... */ + if (ifa_ifwithaddr((struct sockaddr *)sipx) == 0) + return (EADDRNOTAVAIL); + sipx->sipx_port = tport; + } + lport = sipx->sipx_port; + if (lport) { + u_short aport = ntohs(lport); + + if (aport < IPXPORT_MAX && + (ipxp->ipxp_socket->so_state & SS_PRIV) == 0) + return (EACCES); + if (ipx_pcblookup(&zeroipx_addr, lport, 0)) + return (EADDRINUSE); + } + ipxp->ipxp_laddr = sipx->sipx_addr; +noname: + if (lport == 0) + do { + if (ipxcbtable.ipxpt_lport++ < IPXPORT_MAX) + ipxcbtable.ipxpt_lport = IPXPORT_MAX; + lport = htons(ipxcbtable.ipxpt_lport); + } while (ipx_pcblookup(&zeroipx_addr, lport, 0)); + ipxp->ipxp_lport = lport; + return (0); +} + +/* + * Connect from a socket to a specified address. + * Both address and port must be specified in argument sipx. + * If don't have a local address for this socket yet, + * then pick one. + */ +int +ipx_pcbconnect(ipxp, nam) + struct ipxpcb *ipxp; + struct mbuf *nam; +{ + struct ipx_ifaddr *ia; + register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); + register struct ipx_addr *dst; + register struct route *ro; + struct ifnet *ifp; + + if (nam->m_len != sizeof (*sipx)) + return (EINVAL); + if (sipx->sipx_family != AF_IPX) { +#ifdef DEBUG + printf("ipx_connect: af=%x\n", sipx->sipx_family); +#endif + return (EAFNOSUPPORT); + } + if (sipx->sipx_port==0 || ipx_nullhost(sipx->sipx_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 = &ipxp->ipxp_route; + dst = &satoipx_addr(ro->ro_dst); + if (ipxp->ipxp_socket->so_options & SO_DONTROUTE) + goto flush; + if (!ipx_neteq(ipxp->ipxp_lastdst, sipx->sipx_addr)) + goto flush; + if (!ipx_hosteq(ipxp->ipxp_lastdst, sipx->sipx_addr)) { + if (ro->ro_rt && ! (ro->ro_rt->rt_flags & RTF_HOST)) { + /* can patch route to avoid rtalloc */ + *dst = sipx->sipx_addr; + } else { + flush: + if (ro->ro_rt) + RTFREE(ro->ro_rt); + ro->ro_rt = (struct rtentry *)0; + ipxp->ipxp_laddr.ipx_net = ipx_zeronet; + } + }/* else cached route is ok; do nothing */ + ipxp->ipxp_lastdst = sipx->sipx_addr; + if ((ipxp->ipxp_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_IPX; + ro->ro_dst.sa_len = sizeof(ro->ro_dst); + *dst = sipx->sipx_addr; + dst->ipx_port = 0; + rtalloc(ro); + } + if (ipx_neteqnn(ipxp->ipxp_laddr.ipx_net, ipx_zeronet)) { + /* + * If route is known or can be allocated now, + * our src addr is taken from the i/f, else punt. + */ + + ia = (struct ipx_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 = ipx_ifaddr.tqh_first; ia; + ia = ia->ia_list.tqe_next) + if (ia->ia_ifp == ifp) + break; + if (ia == NULL) { + u_short fport = sipx->sipx_addr.ipx_port; + sipx->sipx_addr.ipx_port = 0; + ia = (struct ipx_ifaddr *) + ifa_ifwithdstaddr((struct sockaddr *)sipx); + sipx->sipx_addr.ipx_port = fport; + if (ia == NULL) + ia = ipx_iaonnetof(&sipx->sipx_addr); + if (ia == NULL) + ia = ipx_ifaddr.tqh_first; + if (ia == 0) + return (EADDRNOTAVAIL); + } + ipxp->ipxp_laddr.ipx_net = satoipx_addr(ia->ia_addr).ipx_net; + } + if (ipx_pcblookup(&sipx->sipx_addr, ipxp->ipxp_lport, 0)) + return (EADDRINUSE); + if (ipx_nullhost(ipxp->ipxp_laddr)) { + if (ipxp->ipxp_lport == 0) + (void) ipx_pcbbind(ipxp, (struct mbuf *)0); + ipxp->ipxp_laddr.ipx_host = ipx_thishost; + } + ipxp->ipxp_faddr = sipx->sipx_addr; + /* Includes ipxp->ipxp_fport = sipx->sipx_port; */ + return (0); +} + +void +ipx_pcbdisconnect(ipxp) + struct ipxpcb *ipxp; +{ + + ipxp->ipxp_faddr = zeroipx_addr; + if (ipxp->ipxp_socket->so_state & SS_NOFDREF) + ipx_pcbdetach(ipxp); +} + +void +ipx_pcbdetach(ipxp) + struct ipxpcb *ipxp; +{ + struct socket *so = ipxp->ipxp_socket; + int s; + + so->so_pcb = 0; + sofree(so); + if (ipxp->ipxp_route.ro_rt) + rtfree(ipxp->ipxp_route.ro_rt); + s = splnet(); + LIST_REMOVE(ipxp, ipxp_hash); + CIRCLEQ_REMOVE(&ipxp->ipxp_table->ipxpt_queue, ipxp, ipxp_queue); + splx(s); + FREE(ipxp, M_PCB); +} + +void +ipx_setsockaddr(ipxp, nam) + register struct ipxpcb *ipxp; + struct mbuf *nam; +{ + register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); + + nam->m_len = sizeof (*sipx); + sipx = mtod(nam, struct sockaddr_ipx *); + bzero((caddr_t)sipx, sizeof (*sipx)); + sipx->sipx_len = sizeof(*sipx); + sipx->sipx_family = AF_IPX; + sipx->sipx_addr = ipxp->ipxp_laddr; +} + +void +ipx_setpeeraddr(ipxp, nam) + register struct ipxpcb *ipxp; + struct mbuf *nam; +{ + register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); + + nam->m_len = sizeof (*sipx); + sipx = mtod(nam, struct sockaddr_ipx *); + bzero((caddr_t)sipx, sizeof (*sipx)); + sipx->sipx_len = sizeof(*sipx); + sipx->sipx_family = AF_IPX; + sipx->sipx_addr = ipxp->ipxp_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 ipxpcb. (which may in fact + * be a parameter list!) + */ +void +ipx_pcbnotify(dst, errno, notify, param) + register struct ipx_addr *dst; + int errno; + void (*notify)(struct ipxpcb *); + long param; +{ + register struct ipxpcb *ipxp, *oinp; + int s = splimp(); + + for (ipxp = ipxcbtable.ipxpt_queue.cqh_first; + ipxp != (struct ipxpcb *)&ipxcbtable.ipxpt_queue;) { + if (!ipx_hosteq(*dst,ipxp->ipxp_faddr)) { + next: + ipxp = ipxp->ipxp_queue.cqe_next; + continue; + } + if (ipxp->ipxp_socket == 0) + goto next; + if (errno) + ipxp->ipxp_socket->so_error = errno; + oinp = ipxp; + ipxp = ipxp->ipxp_queue.cqe_next; + oinp->ipxp_notify_param = param; + (*notify)(oinp); + } + splx(s); +} + +#ifdef notdef +/* + * After a routing change, flush old routing + * and allocate a (hopefully) better one. + */ +ipx_rtchange(ipxp) + struct ipxpcb *ipxp; +{ + if (ipxp->ipxp_route.ro_rt) { + rtfree(ipxp->ipxp_route.ro_rt); + ipxp->ipxp_route.ro_rt = 0; + /* + * A new route can be allocated the next time + * output is attempted. + */ + } + /* SHOULD NOTIFY HIGHER-LEVEL PROTOCOLS */ +} +#endif + +struct ipxpcb * +ipx_pcblookup(faddr, lport, wildp) + struct ipx_addr *faddr; + u_short lport; + int wildp; +{ + register struct ipxpcb *ipxp, *match = 0; + int matchwild = 3, wildcard; + u_short fport; + + fport = faddr->ipx_port; + for (ipxp = ipxcbtable.ipxpt_queue.cqh_first; + ipxp != (struct ipxpcb *)&ipxcbtable.ipxpt_queue; + ipxp = ipxp->ipxp_queue.cqe_next) { + if (ipxp->ipxp_lport != lport) + continue; + wildcard = 0; + if (ipx_nullhost(ipxp->ipxp_faddr)) { + if (!ipx_nullhost(*faddr)) + wildcard++; + } else { + if (ipx_nullhost(*faddr)) + wildcard++; + else { + if (!ipx_hosteq(ipxp->ipxp_faddr, *faddr)) + continue; + if (ipxp->ipxp_fport != fport) { + if (ipxp->ipxp_fport != 0) + continue; + else + wildcard++; + } + } + } + if (wildcard && wildp==0) + continue; + if (wildcard < matchwild) { + match = ipxp; + matchwild = wildcard; + if (wildcard == 0) + break; + } + } + return (match); +} diff --git a/sys/netipx/ipx_pcb.h b/sys/netipx/ipx_pcb.h new file mode 100644 index 00000000000..7b842ba12e1 --- /dev/null +++ b/sys/netipx/ipx_pcb.h @@ -0,0 +1,109 @@ +/* $OpenBSD: ipx_pcb.h,v 1.1 1996/08/16 09:16:01 mickey Exp $ */ +/* $NOWHERE: ipx_pcb.h,v 1.2 1996/05/07 09:49:47 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_pcb.h + * + * from FreeBSD Id: ipx_pcb.h,v 1.5 1995/11/24 12:25:10 bde Exp + */ + +#ifndef _NETIPX_IPX_PCB_H_ +#define _NETIPX_IPX_PCB_H_ + +/* + * IPX protocol interface control block. + */ +struct ipxpcb { + LIST_ENTRY(ipxpcb) ipxp_hash; + CIRCLEQ_ENTRY(ipxpcb) ipxp_queue; + struct ipxpcbtable *ipxp_table; /* back pointer to the table */ + struct socket *ipxp_socket; /* back pointer to socket */ + struct ipx_addr ipxp_faddr; /* destination address */ + struct ipx_addr ipxp_laddr; /* socket's address */ +#define ipxp_lport ipxp_laddr.ipx_port +#define ipxp_fport ipxp_faddr.ipx_port + caddr_t ipxp_ppcb; /* protocol specific stuff */ + struct route ipxp_route; /* routing information */ + struct ipx_addr ipxp_lastdst; /* validate cached route for dg socks*/ + u_long ipxp_notify_param; /* extra info passed via ipx_pcbnotify*/ + u_short ipxp_flags; + u_char ipxp_dpt; /* default packet type for ipx_output */ + u_char ipxp_rpt; /* last received packet type by ipx_input() */ +}; + +struct ipxpcbtable { + CIRCLEQ_HEAD(, ipxpcb) ipxpt_queue; + LIST_HEAD(ipxppcbhead, ipxpcb) *ipxpt_hashtbl; + u_long ipxpt_hash; + u_int16_t ipxpt_lport; +}; + +/* possible flags */ + +#define IPXP_IN_ABORT 0x1 /* calling abort through socket */ +#define IPXP_RAWIN 0x2 /* show headers on input */ +#define IPXP_RAWOUT 0x4 /* show header on output */ +#define IPXP_ALL_PACKETS 0x8 /* Turn off higher proto processing */ + +#define IPX_WILDCARD 1 + +#define sotoipxpcb(so) ((struct ipxpcb *)((so)->so_pcb)) + +/* + * Nominal space allocated to a IPX socket. + */ +#define IPXSNDQ 2048 +#define IPXRCVQ 2048 + +#ifdef _KERNEL +extern struct ipxpcbtable ipxcbtable, ipxrawcbtable; /* head of list */ + +void ipx_pcbinit __P((struct ipxpcbtable *, int)); +int ipx_pcballoc __P((struct socket *so, struct ipxpcbtable *head)); +int ipx_pcbbind __P((struct ipxpcb *ipxp, struct mbuf *nam)); +int ipx_pcbconnect __P((struct ipxpcb *ipxp, struct mbuf *nam)); +void ipx_pcbdetach __P((struct ipxpcb *ipxp)); +void ipx_pcbdisconnect __P((struct ipxpcb *ipxp)); +struct ipxpcb * + ipx_pcblookup __P((struct ipx_addr *faddr, int lport, int wildp)); +void ipx_pcbnotify __P((struct ipx_addr *dst, int errno, + void (*notify)(struct ipxpcb *), long param)); +void ipx_setpeeraddr __P((struct ipxpcb *ipxp, struct mbuf *nam)); +void ipx_setsockaddr __P((struct ipxpcb *ipxp, struct mbuf *nam)); +#endif + +#endif /* !_NETIPX_IPX_PCB_H_ */ diff --git a/sys/netipx/ipx_proto.c b/sys/netipx/ipx_proto.c new file mode 100644 index 00000000000..360fb471b8e --- /dev/null +++ b/sys/netipx/ipx_proto.c @@ -0,0 +1,104 @@ +/* $OpenBSD: ipx_proto.c,v 1.1 1996/08/16 09:16:01 mickey Exp $ */ +/* $NOWHERE: ipx_proto.c,v 1.2 1996/05/07 09:49:48 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_proto.c + * + * from FreeBSD Id: ipx_proto.c,v 1.4 1996/01/05 20:47:05 wollman Exp + */ + +#include <sys/param.h> +#include <sys/socket.h> +#include <sys/protosw.h> +#include <sys/domain.h> +#include <sys/kernel.h> +#include <sys/mbuf.h> + +#include <net/radix.h> + +#include <netipx/ipx.h> +#include <netipx/spx.h> + +/* + * IPX protocol family: IPX, ERR, PXP, SPX, ROUTE. + */ + +struct protosw ipxsw[] = { +{ 0, &ipxdomain, 0, 0, + 0, ipx_output, 0, 0, + 0, + ipx_init, 0, 0, 0 +}, +{ SOCK_DGRAM, &ipxdomain, 0, PR_ATOMIC|PR_ADDR, + 0, 0, ipx_ctlinput, ipx_ctloutput, + ipx_usrreq, + 0, 0, 0, 0 +}, +{ SOCK_STREAM, &ipxdomain, IPXPROTO_SPX, PR_CONNREQUIRED|PR_WANTRCVD, + spx_input, 0, spx_ctlinput, spx_ctloutput, + spx_usrreq, + spx_init, spx_fasttimo, spx_slowtimo, 0 +}, +{ SOCK_SEQPACKET,&ipxdomain, IPXPROTO_SPX, PR_CONNREQUIRED|PR_WANTRCVD|PR_ATOMIC, + spx_input, 0, spx_ctlinput, spx_ctloutput, + spx_usrreq_sp, + 0, 0, 0, 0 +}, +{ SOCK_RAW, &ipxdomain, IPXPROTO_RAW, PR_ATOMIC|PR_ADDR, + ipx_input, ipx_output, 0, ipx_ctloutput, + ipx_raw_usrreq, + 0, 0, 0, 0 +}, +{ SOCK_RAW, &ipxdomain, IPXPROTO_ERROR, PR_ATOMIC|PR_ADDR, + 0, ipx_output, ipx_ctlinput, ipx_ctloutput, + ipx_raw_usrreq, + 0, 0, 0, 0 +}, +#ifdef IPTUNNEL +{ SOCK_RAW, &ipxdomain, IPPROTO_IPX, PR_ATOMIC|PR_ADDR, + iptun_input, rip_output, iptun_ctlinput, 0, + rip_usrreq, + 0, 0, 0, 0, +}, +#endif +}; + +struct domain ipxdomain = + { AF_IPX, "Internetwork Packet Exchange", 0, 0, 0, + ipxsw, &ipxsw[sizeof(ipxsw)/sizeof(ipxsw[0])], 0, + rn_inithead, 16, sizeof(struct sockaddr_ipx)}; + diff --git a/sys/netipx/ipx_tun.c b/sys/netipx/ipx_tun.c new file mode 100644 index 00000000000..0f0426232a0 --- /dev/null +++ b/sys/netipx/ipx_tun.c @@ -0,0 +1,75 @@ +/* $OpenBSD: ipx_tun.c,v 1.1 1996/08/16 09:16:02 mickey Exp $ */ +/* $NOWHERE: ipx_tun.c,v 1.2 1996/05/07 09:49:49 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Modifications Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_tun.c + * + * from FreeBSD Id: ipx_tun.c,v 1.4 1996/03/11 15:13:55 davidg Exp + */ + +/* + * Software interface driver for encapsulating IP in IPX. + */ + +#ifdef IPTUNNEL +#include <sys/param.h> +#include <sys/queue.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 <netipx/ipx.h> +#include <netipx/ipx_if.h> + +#endif diff --git a/sys/netipx/ipx_usrreq.c b/sys/netipx/ipx_usrreq.c new file mode 100644 index 00000000000..8208e1d0284 --- /dev/null +++ b/sys/netipx/ipx_usrreq.c @@ -0,0 +1,612 @@ +/* $OpenBSD: ipx_usrreq.c,v 1.1 1996/08/16 09:16:02 mickey Exp $ */ +/* $NOWHERE: ipx_usrreq.c,v 1.2 1996/05/07 09:49:50 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_usrreq.c + * + * from FreeBSD Id: ipx_usrreq.c,v 1.5 1996/03/11 15:13:57 davidg Exp + */ + +#include <sys/param.h> +#include <sys/queue.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 <netinet/in.h> + +#include <netipx/ipx.h> +#include <netipx/ipx_pcb.h> +#include <netipx/ipx_if.h> +#include <netipx/ipx_var.h> +#include <netipx/ipx_error.h> +#include <netipx/ipx_ip.h> + +#include <machine/stdarg.h> + +/* + * IPX protocol implementation. + */ + +int noipxRoute; + +/* + * This may also be called for raw listeners. + */ +void +#if __STDC__ +ipx_input(struct mbuf *m, ...) +#else +ipx_input(m, va_alist) + struct mbuf *m; + va_decl +#endif +{ + register struct ipxpcb *ipxp; + register struct ipx *ipx = mtod(m, struct ipx *); + struct ifnet *ifp = m->m_pkthdr.rcvif; + struct sockaddr_ipx ipx_ipx = { sizeof(ipx_ipx), AF_IPX }; + va_list ap; + + va_start(ap, m); + ipxp = va_arg(ap, struct ipxpcb *); + va_end(ap); + + if (ipxp == NULL) + panic("No ipxpcb"); + /* + * Construct sockaddr format source address. + * Stuff source address and datagram in user buffer. + */ + ipx_ipx.sipx_addr = ipx->ipx_sna; + if (ipx_neteqnn(ipx->ipx_sna.ipx_net, ipx_zeronet) && ifp) { + register struct ifaddr *ifa; + + for (ifa = ifp->if_addrlist.tqh_first; + ifa; ifa = ifa->ifa_list.tqe_next) { + if (ifa->ifa_addr->sa_family == AF_IPX) { + ipx_ipx.sipx_addr.ipx_net = + IA_SIPX(ifa)->sipx_addr.ipx_net; + break; + } + } + } + ipxp->ipxp_rpt = ipx->ipx_pt; + if ( ! (ipxp->ipxp_flags & IPXP_RAWIN) ) { + m->m_len -= sizeof (struct ipx); + m->m_pkthdr.len -= sizeof (struct ipx); + m->m_data += sizeof (struct ipx); + } + if (sbappendaddr(&ipxp->ipxp_socket->so_rcv, (struct sockaddr *)&ipx_ipx, + m, (struct mbuf *)0) == 0) + goto bad; + sorwakeup(ipxp->ipxp_socket); + return; +bad: + m_freem(m); +} + +void +ipx_abort(ipxp) + struct ipxpcb *ipxp; +{ + struct socket *so = ipxp->ipxp_socket; + + ipx_pcbdisconnect(ipxp); + soisdisconnected(so); +} +/* + * Drop connection, reporting + * the specified error. + */ +/* struct ipxpcb * DELETE THIS */ +void +ipx_drop(ipxp, errno) + register struct ipxpcb *ipxp; + int errno; +{ + struct socket *so = ipxp->ipxp_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; + ipx_pcbdisconnect(ipxp); + soisdisconnected(so); +} + +int +#if __STDC__ +ipx_output(struct mbuf *m0, ...) +#else +ipx_output(m0, va_alist) + struct mbuf *m0; + va_decl +#endif +{ + register struct mbuf *m; + register struct ipx *ipx; + struct ipxpcb *ipxp; + register struct socket *so; + register int len = 0; + register struct route *ro; + struct mbuf *mprev = NULL; + va_list ap; + + va_start(ap, m0); + ipxp = va_arg(ap, struct ipxpcb *); + va_end(ap); + + /* + * Calculate data length. + */ + for (m = m0; m; m = m->m_next) { + mprev = m; + len += m->m_len; + } + /* + * 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 IPX header + * and addresses and length put into network format. + */ + m = m0; + if (ipxp->ipxp_flags & IPXP_RAWOUT) { + ipx = mtod(m, struct ipx *); + } else { + M_PREPEND(m, sizeof (struct ipx), M_DONTWAIT); + if (m == 0) + return (ENOBUFS); + ipx = mtod(m, struct ipx *); + ipx->ipx_tc = 0; + ipx->ipx_pt = ipxp->ipxp_dpt; + ipx->ipx_sna = ipxp->ipxp_laddr; + ipx->ipx_dna = ipxp->ipxp_faddr; + len += sizeof (struct ipx); + } + + ipx->ipx_len = htons((u_short)len); + + if (ipxcksum) { + ipx->ipx_sum = 0; + len = ((len - 1) | 1) + 1; + ipx->ipx_sum = ipx_cksum(m, len); + } else + ipx->ipx_sum = 0xffff; + + /* + * Output datagram. + */ + so = ipxp->ipxp_socket; + if (so->so_options & SO_DONTROUTE) + return (ipx_outputfl(m, (struct route *)0, + (so->so_options & SO_BROADCAST) | IPX_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 = &ipxp->ipxp_route; +#ifdef ancient_history + /* + * I think that this will all be handled in ipx_pcbconnect! + */ + if (ro->ro_rt) { + if(ipx_neteq(ipxp->ipxp_lastdst, ipx->ipx_dna)) { + /* + * This assumes we have no GH type routes + */ + if (ro->ro_rt->rt_flags & RTF_HOST) { + if (!ipx_hosteq(ipxp->ipxp_lastdst, ipx->ipx_dna)) + goto re_route; + + } + if ((ro->ro_rt->rt_flags & RTF_GATEWAY) == 0) { + register struct ipx_addr *dst = + &satoipx_addr(ro->ro_dst); + dst->ipx_host = ipx->ipx_dna.ipx_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; + } + } + ipxp->ipxp_lastdst = ipx->ipx_dna; +#endif /* ancient_history */ + if (noipxRoute) ro = 0; + return (ipx_outputfl(m, ro, so->so_options & SO_BROADCAST)); +} + +/* ARGSUSED */ +int +ipx_ctloutput(req, so, level, name, value) + int req, level; + struct socket *so; + int name; + struct mbuf **value; +{ + register struct mbuf *m; + struct ipxpcb *ipxp = sotoipxpcb(so); + int mask, error = 0; + /*extern long ipx_pexseq;*/ /*XXX*//*JRE*/ + + if (ipxp == 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 = IPXP_ALL_PACKETS; + goto get_flags; + + case SO_HEADERS_ON_INPUT: + mask = IPXP_RAWIN; + goto get_flags; + + case SO_HEADERS_ON_OUTPUT: + mask = IPXP_RAWOUT; + get_flags: + m->m_len = sizeof(short); + *mtod(m, short *) = ipxp->ipxp_flags & mask; + break; + + case SO_DEFAULT_HEADERS: + m->m_len = sizeof(struct ipx); + { + register struct ipx *ipx = mtod(m, struct ipx *); + ipx->ipx_len = 0; + ipx->ipx_sum = 0; + ipx->ipx_tc = 0; + ipx->ipx_pt = ipxp->ipxp_dpt; + ipx->ipx_dna = ipxp->ipxp_faddr; + ipx->ipx_sna = ipxp->ipxp_laddr; + } + break; + + case SO_SEQNO: + m->m_len = sizeof(long); + *mtod(m, long *) = ipx_pexseq++; + break; + + default: + error = EINVAL; + } + *value = m; + break; + + case PRCO_SETOPT: + switch (name) { + int *ok; + + case SO_ALL_PACKETS: + mask = IPXP_ALL_PACKETS; + goto set_head; + + case SO_HEADERS_ON_INPUT: + mask = IPXP_RAWIN; + goto set_head; + + case SO_HEADERS_ON_OUTPUT: + mask = IPXP_RAWOUT; + set_head: + if (value && *value) { + ok = mtod(*value, int *); + if (*ok) + ipxp->ipxp_flags |= mask; + else + ipxp->ipxp_flags &= ~mask; + } else error = EINVAL; + break; + + case SO_DEFAULT_HEADERS: + { + register struct ipx *ipx + = mtod(*value, struct ipx *); + ipxp->ipxp_dpt = ipx->ipx_pt; + } + break; +#ifdef IPXIP + case SO_IPXIP_ROUTE: + error = ipxip_route(*value); + break; +#endif /* IPXIP */ +#ifdef IPXTUNNEL + case SO_IPXTUNNEL_ROUTE: + error = ipxtun_route(*value); + break; +#endif + default: + error = EINVAL; + } + if (value && *value) + m_freem(*value); + break; + } + return (error); +} + +/*ARGSUSED*/ +int +ipx_usrreq(so, req, m, nam, control) + struct socket *so; + int req; + struct mbuf *m, *nam, *control; +{ + struct ipxpcb *ipxp = sotoipxpcb(so); + int error = 0; + + if (req == PRU_CONTROL) + return (ipx_control(so, (int)m, (caddr_t)nam, + (struct ifnet *)control)); + if (control && control->m_len) { + error = EINVAL; + goto release; + } + if (ipxp == NULL && req != PRU_ATTACH) { + error = EINVAL; + goto release; + } + switch (req) { + + case PRU_ATTACH: + if (ipxp != NULL) { + error = EINVAL; + break; + } + error = ipx_pcballoc(so, &ipxcbtable); + if (error) + break; + error = soreserve(so, (u_long) 2048, (u_long) 2048); + if (error) + break; + break; + + case PRU_DETACH: + if (ipxp == NULL) { + error = ENOTCONN; + break; + } + ipx_pcbdetach(ipxp); + break; + + case PRU_BIND: + error = ipx_pcbbind(ipxp, nam); + break; + + case PRU_LISTEN: + error = EOPNOTSUPP; + break; + + case PRU_CONNECT: + if (!ipx_nullhost(ipxp->ipxp_faddr)) { + error = EISCONN; + break; + } + error = ipx_pcbconnect(ipxp, nam); + if (error == 0) + soisconnected(so); + break; + + case PRU_CONNECT2: + error = EOPNOTSUPP; + break; + + case PRU_ACCEPT: + error = EOPNOTSUPP; + break; + + case PRU_DISCONNECT: + if (ipx_nullhost(ipxp->ipxp_faddr)) { + error = ENOTCONN; + break; + } + ipx_pcbdisconnect(ipxp); + soisdisconnected(so); + break; + + case PRU_SHUTDOWN: + socantsendmore(so); + break; + + case PRU_SEND: + { + struct ipx_addr laddr; + int s = 0; + + if (nam) { + laddr = ipxp->ipxp_laddr; + if (!ipx_nullhost(ipxp->ipxp_faddr)) { + error = EISCONN; + break; + } + /* + * Must block input while temporarily connected. + */ + s = splnet(); + error = ipx_pcbconnect(ipxp, nam); + if (error) { + splx(s); + break; + } + } else { + if (ipx_nullhost(ipxp->ipxp_faddr)) { + error = ENOTCONN; + break; + } + } + error = ipx_output(m, ipxp); + m = NULL; + if (nam) { + ipx_pcbdisconnect(ipxp); + splx(s); + ipxp->ipxp_laddr.ipx_host = laddr.ipx_host; + ipxp->ipxp_laddr.ipx_port = laddr.ipx_port; + } + } + break; + + case PRU_ABORT: + ipx_pcbdetach(ipxp); + sofree(so); + soisdisconnected(so); + break; + + case PRU_SOCKADDR: + ipx_setsockaddr(ipxp, nam); + break; + + case PRU_PEERADDR: + ipx_setpeeraddr(ipxp, 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("ipx_usrreq"); + } +release: + if (control != NULL) + m_freem(control); + if (m != NULL) + m_freem(m); + return (error); +} +/*ARGSUSED*/ +int +ipx_raw_usrreq(so, req, m, nam, control) + struct socket *so; + int req; + struct mbuf *m, *nam, *control; +{ + int error = 0; + struct ipxpcb *ipxp = sotoipxpcb(so); + /*extern struct ipxpcb ipxrawpcb;*//*XXX*//*JRE*/ + + switch (req) { + + case PRU_ATTACH: + + if (!(so->so_state & SS_PRIV) || (ipxp != NULL)) { + error = EINVAL; + break; + } + error = ipx_pcballoc(so, &ipxrawcbtable); + if (error) + break; + error = soreserve(so, (u_long) 2048, (u_long) 2048); + if (error) + break; + ipxp = sotoipxpcb(so); + ipxp->ipxp_faddr.ipx_host = ipx_broadhost; + ipxp->ipxp_flags = IPXP_RAWIN | IPXP_RAWOUT; + break; + default: + error = ipx_usrreq(so, req, m, nam, control); + } + return (error); +} + diff --git a/sys/netipx/ipx_var.h b/sys/netipx/ipx_var.h new file mode 100644 index 00000000000..13eaf504edc --- /dev/null +++ b/sys/netipx/ipx_var.h @@ -0,0 +1,62 @@ +/* $OpenBSD: ipx_var.h,v 1.1 1996/08/16 09:16:02 mickey Exp $ */ +/* $NOWHERE: ipx_var.h,v 1.2 1996/05/07 09:49:51 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)ipx_var.h + * + * from FreeBSD Id: ipx_var.h,v 1.3 1995/11/04 09:03:27 julian Exp + */ + +#ifndef _NETIPX_IPX_VAR_H_ +#define _NETIPX_IPX_VAR_H_ + +/* + * IPX Kernel Structures and Variables + */ +struct ipxstat { + int ipxs_badsum; /* checksum bad */ + int ipxs_tooshort; /* packet too short */ + int ipxs_toosmall; /* not enough data */ + int ipxs_badhlen; /* ip header length < data size */ + int ipxs_badlen; /* ip length < ip header length */ +}; + +#ifdef _KERNEL +extern struct ipxstat ipxstat; +#endif + +#endif diff --git a/sys/netipx/spx.h b/sys/netipx/spx.h new file mode 100644 index 00000000000..0448b72de1f --- /dev/null +++ b/sys/netipx/spx.h @@ -0,0 +1,208 @@ +/* $OpenBSD: spx.h,v 1.1 1996/08/16 09:16:03 mickey Exp $ */ +/* $NOWHERE: spx.h,v 1.2 1996/05/07 09:49:52 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)spx.h + * + * from FreeBSD Id: spx.h,v 1.7 1996/01/30 22:58:51 mpp Exp + */ + +#ifndef _NETIPX_SPX_H_ +#define _NETIPX_SPX_H_ + +#include <sys/queue.h> + +#define XXX __attribute__((packed)); + +/* + * Definitions for IPX style Sequenced Packet Protocol + */ + +struct spxhdr { + u_int8_t spx_cc XXX; /* connection control */ + u_int8_t spx_dt XXX; /* datastream type */ +#define SPX_SP 0x80 /* system packet */ +#define SPX_SA 0x40 /* send acknowledgement */ +#define SPX_OB 0x20 /* attention (out of band data) */ +#define SPX_EM 0x10 /* end of message */ + u_int16_t spx_sid XXX; /* source connection identifier */ + u_int16_t spx_did XXX; /* destination connection identifier */ + u_int16_t spx_seq XXX; /* sequence number */ + u_int16_t spx_ack XXX; /* acknowledge number */ + u_int16_t spx_alo XXX; /* allocation number */ +}; + +/* + * Definitions for NS(tm) Internet Datagram Protocol + * containing a Sequenced Packet Protocol packet. + */ +struct spx { + struct ipx si_i XXX; + struct spxhdr si_s XXX; +}; + +#define SI(x) ((struct spx *)x) +#define si_sum si_i.ipx_sum +#define si_len si_i.ipx_len +#define si_tc si_i.ipx_tc +#define si_pt si_i.ipx_pt +#define si_dna si_i.ipx_dna +#define si_sna si_i.ipx_sna +#define si_sport si_i.ipx_sna.ipx_port +#define si_cc si_s.spx_cc +#define si_dt si_s.spx_dt +#define si_sid si_s.spx_sid +#define si_did si_s.spx_did +#define si_seq si_s.spx_seq +#define si_ack si_s.spx_ack +#define si_alo si_s.spx_alo + +struct spx_q { + TAILQ_ENTRY(spx_q) list; + caddr_t data; +}; + +/* + * SPX control block, one per connection + */ +struct spxpcb { + TAILQ_HEAD(, spx_q) spxp_queue; + struct ipxpcb *s_ipxpcb; /* backpointer to ipx 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 ipx *s_ipx; + struct spxhdr s_shdr; /* prototype header to transmit */ +#define s_cc s_shdr.spx_cc /* connection control (for EM bit) */ +#define s_dt s_shdr.spx_dt /* datastream type */ +#define s_sid s_shdr.spx_sid /* source connection identifier */ +#define s_did s_shdr.spx_did /* destination connection identifier */ +#define s_seq s_shdr.spx_seq /* sequence number */ +#define s_ack s_shdr.spx_ack /* acknowledge number */ +#define s_alo s_shdr.spx_alo /* allocation number */ +#define s_dport s_ipx->ipx_dna.ipx_port /* where we are sending */ + struct spxhdr 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 spx_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 threshold 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 */ +#define SPXT_NTIMERS 4 + short s_timer[SPXT_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 spx_output */ + char s_inx; /* exit taken from spx_input */ + u_short s_flags2; /* more flags for testing */ +#define SF_NEWCALL 0x100 /* for new_recvmsg */ +#define SO_NEWCALL 10 /* for new_recvmsg */ +}; + +#define ipxtospxpcb(np) ((struct spxpcb *)(np)->ipxp_ppcb) +#define sotospxpcb(so) (ipxtospxpcb(sotoipxpcb(so))) + +#ifdef _KERNEL + +void spx_abort __P((struct ipxpcb *ipxp)); +struct spxpcb *spx_close __P((struct spxpcb *cb)); +void *spx_ctlinput __P((int cmd, struct sockaddr *arg_as_sa, void *dummy)); +int spx_ctloutput __P((int req, struct socket *so, int level, int name, + struct mbuf **value)); +struct spxpcb *spx_disconnect __P((struct spxpcb *cb)); +struct spxpcb *spx_drop __P((struct spxpcb *cb, int errno)); +void spx_fasttimo __P((void)); +void spx_init __P((void)); +void spx_input __P((struct mbuf *m, ...)); +int spx_output __P((struct spxpcb *cb, struct mbuf *m0)); +void spx_quench __P((struct ipxpcb *ipxp)); +int spx_reass __P((struct spxpcb *cb, struct spx *si)); +void spx_setpersist __P((struct spxpcb *cb)); +void spx_slowtimo __P((void)); +void spx_template __P((struct spxpcb *cb)); +struct spxpcb *spx_timers __P((struct spxpcb *cb, int timer)); +struct spxpcb *spx_usrclosed __P((struct spxpcb *cb)); +int spx_usrreq __P((struct socket *so, int req, struct mbuf *m, + struct mbuf *nam, struct mbuf *controlp)); +int spx_usrreq_sp __P((struct socket *so, int req, struct mbuf *m, + struct mbuf *nam, struct mbuf *controlp)); + +#endif /* _KERNEL */ + +#endif /* !_NETIPX_SPX_H_ */ diff --git a/sys/netipx/spx_debug.c b/sys/netipx/spx_debug.c new file mode 100644 index 00000000000..d49e78a9294 --- /dev/null +++ b/sys/netipx/spx_debug.c @@ -0,0 +1,178 @@ +/* $OpenBSD: spx_debug.c,v 1.1 1996/08/16 09:16:03 mickey Exp $ */ +/* $NOWHERE: spx_debug.c,v 1.2 1996/05/07 09:49:53 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)spx_debug.c + * + * from FreeBSD Id: spx_debug.c,v 1.5 1996/03/11 15:13:58 davidg Exp + */ + +#include <sys/param.h> +#include <sys/queue.h> +#include <sys/systm.h> +#include <sys/mbuf.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#define PRUREQUESTS +#include <sys/protosw.h> +#include <sys/errno.h> + +#include <net/route.h> +#include <net/if.h> +#include <netinet/in_systm.h> +#define TCPSTATES +#include <netinet/tcp_fsm.h> + +#include <netipx/ipx.h> +#include <netipx/ipx_error.h> +#include <netipx/ipx_pcb.h> +#include <netipx/ipx.h> +#include <netipx/ipx_var.h> +#include <netipx/spx.h> +#define SPXTIMERS +#include <netipx/spx_timer.h> +#include <netipx/spx_var.h> +#define SANAMES +#include <netipx/spx_debug.h> + +int spxconsdebug = 0; +/* + * spx debug routines + */ +void +spx_trace(act, ostate, sp, si, req) + short act; + u_char ostate; + struct spxpcb *sp; + struct spx *si; + int req; +{ +#ifdef IPX +#ifdef IPXDEBUG + u_short seq, ack, len, alo; + int flags; + struct spx_debug *sd = &spx_debug[spx_debx++]; + + if (spx_debx == SPX_NDEBUG) + spx_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 (spxconsdebug == 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 ", spxnames[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 & SPX_ ## 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 + ipx_printhost(&si->si_sna); + ipx_printhost(&si->si_dna); + + if (act==SA_RESPOND) { + printf("ipx_len = %x, ", + ((struct ipx *)si)->ipx_len); + } + break; + + case SA_USER: + printf("%s", prurequests[req&0xff]); + if ((req & 0xff) == PRU_SLOWTIMO) + printf("<%s>", spxtimers[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 +} diff --git a/sys/netipx/spx_debug.h b/sys/netipx/spx_debug.h new file mode 100644 index 00000000000..576be18d17b --- /dev/null +++ b/sys/netipx/spx_debug.h @@ -0,0 +1,81 @@ +/* $OpenBSD: spx_debug.h,v 1.1 1996/08/16 09:16:03 mickey Exp $ */ +/* $NOWHERE: spx_debug.h,v 1.2 1996/05/07 09:49:53 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)spx_debug.h + * + * from FreeBSD Id: spx_debug.h,v 1.5 1995/11/24 12:25:13 bde Exp + */ + +#ifndef _NETIPX_SPX_DEBUG_H_ +#define _NETIPX_SPX_DEBUG_H_ + +struct spx_debug { + u_long sd_time; + short sd_act; + short sd_ostate; + caddr_t sd_cb; + short sd_req; + struct spx sd_si; + struct spxpcb 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 *spxnames[] = + { "input", "output", "user", "respond", "drop" }; +#endif + +#define SPX_NDEBUG 100 +struct spx_debug spx_debug[SPX_NDEBUG]; +int spx_debx; + +#ifdef _KERNEL +extern char *prurequests[]; +extern char *sanames[]; +extern char *tcpstates[]; + +void spx_trace __P((int act, int ostate, struct spxpcb *sp, struct spx *si, + int req)); +#endif + +#endif /* !_NETIPX_SPX_DEBUG_H_ */ diff --git a/sys/netipx/spx_timer.h b/sys/netipx/spx_timer.h new file mode 100644 index 00000000000..84d70942fae --- /dev/null +++ b/sys/netipx/spx_timer.h @@ -0,0 +1,133 @@ +/* $OpenBSD: spx_timer.h,v 1.1 1996/08/16 09:16:03 mickey Exp $ */ +/* $NOWHERE: spx_timer.h,v 1.2 1996/05/07 09:49:54 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)spx_timer.h + * + * from FreeBSD Id: spx_timer.h,v 1.5 1996/01/30 22:58:53 mpp Exp + */ + +#ifndef _NETIPX_SPX_TIMER_H_ +#define _NETIPX_SPX_TIMER_H_ + +/* + * Definitions of the SPX timers. These timers are counted + * down PR_SLOWHZ times a second. + */ +#define SPXT_REXMT 0 /* retransmit */ +#define SPXT_PERSIST 1 /* retransmit persistence */ +#define SPXT_KEEP 2 /* keep alive */ +#define SPXT_2MSL 3 /* 2*msl quiet time timer */ + +/* + * The SPXT_REXMT timer is used to force retransmissions. + * The SPX has the SPXT_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 SPXT_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 SPXT_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 SPXT_PERSMIN time intervals, + * but no more frequently than the current estimate of round-trip + * packet time. The SPXT_PERSIST timer is cleared whenever we receive + * a window update from the peer. + * + * The SPXT_KEEP timer is used to keep connections alive. If an + * connection is idle (no segments received) for SPXTV_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 SPXT_KEEP + * initiated segments we cannot elicit a response from a peer in SPXT_MAXIDLE + * amount of time, then we drop the connection. + */ + +#define SPX_TTL 30 /* default time to live for SPX segs */ +/* + * Time constants. + */ +#define SPXTV_MSL ( 15*PR_SLOWHZ) /* max seg lifetime */ +#define SPXTV_SRTTBASE 0 /* base roundtrip time; + if 0, no idea yet */ +#define SPXTV_SRTTDFLT ( 3*PR_SLOWHZ) /* assumed RTT if no info */ + +#define SPXTV_PERSMIN ( 5*PR_SLOWHZ) /* retransmit persistence */ +#define SPXTV_PERSMAX ( 60*PR_SLOWHZ) /* maximum persist interval */ + +#define SPXTV_KEEP ( 75*PR_SLOWHZ) /* keep alive - 75 secs */ +#define SPXTV_MAXIDLE ( 8*SPXTV_KEEP) /* maximum allowable idle + time before drop conn */ + +#define SPXTV_MIN ( 1*PR_SLOWHZ) /* minimum allowable value */ +#define SPXTV_REXMTMAX ( 64*PR_SLOWHZ) /* max allowable REXMT value */ + +#define SPX_LINGERTIME 120 /* linger at most 2 minutes */ + +#define SPX_MAXRXTSHIFT 12 /* maximum retransmits */ + +#ifdef SPXTIMERS +char *spxtimers[] = + { "REXMT", "PERSIST", "KEEP", "2MSL" }; +#endif + +/* + * Force a time value to be in a certain range. + */ +#define SPXT_RANGESET(tv, value, tvmin, tvmax) { \ + (tv) = (value); \ + if ((tv) < (tvmin)) \ + (tv) = (tvmin); \ + else if ((tv) > (tvmax)) \ + (tv) = (tvmax); \ +} + +#ifdef _KERNEL +extern int spx_backoff[]; +#endif + +#endif diff --git a/sys/netipx/spx_usrreq.c b/sys/netipx/spx_usrreq.c new file mode 100644 index 00000000000..8fc3aa5f031 --- /dev/null +++ b/sys/netipx/spx_usrreq.c @@ -0,0 +1,1846 @@ +/* $OpenBSD: spx_usrreq.c,v 1.1 1996/08/16 09:16:04 mickey Exp $ */ +/* $NOWHERE: spx_usrreq.c,v 1.2 1996/05/07 09:49:55 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)spx_usrreq.h + * + * from FreeBSD Id: spx_usrreq.c,v 1.7 1995/12/16 02:14:35 bde Exp + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/malloc.h> +#include <sys/mbuf.h> +#include <sys/protosw.h> +#include <sys/queue.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#include <sys/errno.h> + +#include <net/if.h> +#include <net/route.h> +#include <netinet/tcp_fsm.h> + +#include <netipx/ipx.h> +#include <netipx/ipx_pcb.h> +#include <netipx/ipx_var.h> +#include <netipx/ipx_error.h> +#include <netipx/spx.h> +#include <netipx/spx_timer.h> +#include <netipx/spx_var.h> +#include <netipx/spx_debug.h> + +#include <machine/stdarg.h> + +/* + * SPX protocol implementation. + */ + +struct spx spx_savesi; +int traceallspxs = 0; +extern int spxconsdebug; +int spx_hardnosed; +int spx_use_delack = 0; +u_short spx_newchecks[50]; + +struct spx_istat spx_istat; +u_short spx_iss; + +#ifndef SPXCBHASHSIZE +#define SPXCBHASHSIZE 32 +#endif +struct ipxpcbtable ipxcbtable; +int ipxcbhashsize = SPXCBHASHSIZE; + +void +spx_init() +{ + ipx_pcbinit(&ipxcbtable, ipxcbhashsize); + spx_iss = 1; /* WRONG !! should fish it out of TODR */ +} + +/*ARGSUSED*/ +void +spx_input(struct mbuf *m, ...) +{ + struct ipxpcb *ipxpcbp; + register struct spxpcb *cb; + register struct spx *si = mtod(m, struct spx *); + register struct socket *so; + int dropsocket = 0; + short ostate = 0; + va_list ap; + + va_start(ap, m); + ipxpcbp = va_arg(ap, struct ipxpcb *); + va_end(ap); + + spxstat.spxs_rcvtotal++; + if (ipxpcbp == NULL) + panic("spx_input: no ipxpcb"); + + cb = ipxtospxpcb(ipxpcbp); + if (cb == 0) goto bad; + + if (m->m_len < sizeof(*si)) { + if ((m = m_pullup(m, sizeof(*si))) == 0) { + spxstat.spxs_rcvshort++; + return; + } + si = mtod(m, struct spx *); + } + si->si_seq = ntohs(si->si_seq); + si->si_ack = ntohs(si->si_ack); + si->si_alo = ntohs(si->si_alo); + + so = ipxpcbp->ipxp_socket; + + if (so->so_options & SO_DEBUG || traceallspxs) { + ostate = cb->s_state; + spx_savesi = *si; + } + if (so->so_options & SO_ACCEPTCONN) { + struct spxpcb *ocb = cb; + + so = sonewconn(so, 0); + if (so == 0) { + goto drop; + } + /* + * This is ugly, but .... + * + * Mark socket as temporary until we're + * committed to keeping it. The code at + * ``drop'' and ``dropwithreset'' check the + * flag dropsocket to see if the temporary + * socket created here should be discarded. + * We mark the socket as discardable until + * we're committed to it below in TCPS_LISTEN. + */ + dropsocket++; + ipxpcbp = (struct ipxpcb *)so->so_pcb; + ipxpcbp->ipxp_laddr = si->si_dna; + cb = ipxtospxpcb(ipxpcbp); + cb->s_mtu = ocb->s_mtu; /* preserve sockopts */ + cb->s_flags = ocb->s_flags; /* preserve sockopts */ + cb->s_flags2 = ocb->s_flags2; /* preserve sockopts */ + cb->s_state = TCPS_LISTEN; + } + + /* + * Packet received on connection. + * reset idle time and keep-alive timer; + */ + cb->s_idle = 0; + cb->s_timer[SPXT_KEEP] = SPXTV_KEEP; + + switch (cb->s_state) { + + case TCPS_LISTEN:{ + struct mbuf *am; + register struct sockaddr_ipx *sipx; + struct ipx_addr laddr; + + /* + * If somebody here was carying on a conversation + * and went away, and his pen pal thinks he can + * still talk, we get the misdirected packet. + */ + if (spx_hardnosed && (si->si_did != 0 || si->si_seq != 0)) { + spx_istat.gonawy++; + goto dropwithreset; + } + am = m_get(M_DONTWAIT, MT_SONAME); + if (am == NULL) + goto drop; + am->m_len = sizeof (struct sockaddr_ipx); + sipx = mtod(am, struct sockaddr_ipx *); + sipx->sipx_len = sizeof(*sipx); + sipx->sipx_family = AF_IPX; + sipx->sipx_addr = si->si_sna; + laddr = ipxpcbp->ipxp_laddr; + if (ipx_nullhost(laddr)) + ipxpcbp->ipxp_laddr = si->si_dna; + if (ipx_pcbconnect(ipxpcbp, am)) { + ipxpcbp->ipxp_laddr = laddr; + (void) m_free(am); + spx_istat.noconn++; + goto drop; + } + (void) m_free(am); + spx_template(cb); + dropsocket = 0; /* committed to socket */ + cb->s_did = si->si_sid; + cb->s_rack = si->si_ack; + cb->s_ralo = si->si_alo; +#define THREEWAYSHAKE +#ifdef THREEWAYSHAKE + cb->s_state = TCPS_SYN_RECEIVED; + cb->s_force = 1 + SPXT_KEEP; + spxstat.spxs_accepts++; + cb->s_timer[SPXT_KEEP] = SPXTV_KEEP; + } + break; + /* + * This state means that we have heard a response + * to our acceptance of their connection + * It is probably logically unnecessary in this + * implementation. + */ + case TCPS_SYN_RECEIVED: { + if (si->si_did!=cb->s_sid) { + spx_istat.wrncon++; + goto drop; + } +#endif + ipxpcbp->ipxp_fport = si->si_sport; + cb->s_timer[SPXT_REXMT] = 0; + cb->s_timer[SPXT_KEEP] = SPXTV_KEEP; + soisconnected(so); + cb->s_state = TCPS_ESTABLISHED; + spxstat.spxs_accepts++; + } + break; + + /* + * This state means that we have gotten a response + * to our attempt to establish a connection. + * We fill in the data from the other side, + * telling us which port to respond to, instead of the well- + * known one we might have sent to in the first place. + * We also require that this is a response to our + * connection id. + */ + case TCPS_SYN_SENT: + if (si->si_did!=cb->s_sid) { + spx_istat.notme++; + goto drop; + } + spxstat.spxs_connects++; + cb->s_did = si->si_sid; + cb->s_rack = si->si_ack; + cb->s_ralo = si->si_alo; + cb->s_dport = ipxpcbp->ipxp_fport = si->si_sport; + cb->s_timer[SPXT_REXMT] = 0; + cb->s_flags |= SF_ACKNOW; + soisconnected(so); + cb->s_state = TCPS_ESTABLISHED; + /* Use roundtrip time of connection request for initial rtt */ + if (cb->s_rtt) { + cb->s_srtt = cb->s_rtt << 3; + cb->s_rttvar = cb->s_rtt << 1; + SPXT_RANGESET(cb->s_rxtcur, + ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1, + SPXTV_MIN, SPXTV_REXMTMAX); + cb->s_rtt = 0; + } + } + if (so->so_options & SO_DEBUG || traceallspxs) + spx_trace(SA_INPUT, (u_char)ostate, cb, &spx_savesi, 0); + + m->m_len -= sizeof (struct ipx); + m->m_pkthdr.len -= sizeof (struct ipx); + m->m_data += sizeof (struct ipx); + + if (spx_reass(cb, si)) { + (void) m_freem(m); + } + if (cb->s_force || (cb->s_flags & (SF_ACKNOW|SF_WIN|SF_RXT))) + (void) spx_output(cb, (struct mbuf *)0); + cb->s_flags &= ~(SF_WIN|SF_RXT); + return; + +dropwithreset: + if (dropsocket) + (void) soabort(so); + si->si_seq = ntohs(si->si_seq); + si->si_ack = ntohs(si->si_ack); + si->si_alo = ntohs(si->si_alo); + ipx_error(dtom(si), IPX_ERR_NOSOCK, 0); + if (cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG || traceallspxs) + spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0); + return; + +drop: +bad: + if (cb == 0 || cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG || + traceallspxs) + spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0); + m_freem(m); +} + +int spxrexmtthresh = 3; + +/* + * This is structurally similar to the tcp reassembly routine + * but its function is somewhat different: It merely queues + * packets up, and suppresses duplicates. + */ +int +spx_reass(cb, si) +register struct spxpcb *cb; +register struct spx *si; +{ + register struct spx_q *q; + register struct mbuf *m; + register struct socket *so = cb->s_ipxpcb->ipxp_socket; + char packetp = cb->s_flags & SF_HI; + int incr; + char wakeup = 0; + + if (si == NULL) + goto present; + /* + * Update our news from them. + */ + if (si->si_cc & SPX_SA) + cb->s_flags |= (spx_use_delack ? SF_DELACK : SF_ACKNOW); + if (SSEQ_GT(si->si_alo, cb->s_ralo)) + cb->s_flags |= SF_WIN; + if (SSEQ_LEQ(si->si_ack, cb->s_rack)) { + if ((si->si_cc & SPX_SP) && cb->s_rack != (cb->s_smax + 1)) { + spxstat.spxs_rcvdupack++; + /* + * If this is a completely duplicate ack + * and other conditions hold, we assume + * a packet has been dropped and retransmit + * it exactly as in tcp_input(). + */ + if (si->si_ack != cb->s_rack || + si->si_alo != cb->s_ralo) + cb->s_dupacks = 0; + else if (++cb->s_dupacks == spxrexmtthresh) { + u_short onxt = cb->s_snxt; + int cwnd = cb->s_cwnd; + + cb->s_snxt = si->si_ack; + cb->s_cwnd = CUNIT; + cb->s_force = 1 + SPXT_REXMT; + (void) spx_output(cb, (struct mbuf *)0); + cb->s_timer[SPXT_REXMT] = cb->s_rxtcur; + cb->s_rtt = 0; + if (cwnd >= 4 * CUNIT) + cb->s_cwnd = cwnd / 2; + if (SSEQ_GT(onxt, cb->s_snxt)) + cb->s_snxt = onxt; + return (1); + } + } else + cb->s_dupacks = 0; + goto update_window; + } + cb->s_dupacks = 0; + /* + * If our correspondent acknowledges data we haven't sent + * TCP would drop the packet after acking. We'll be a little + * more permissive + */ + if (SSEQ_GT(si->si_ack, (cb->s_smax + 1))) { + spxstat.spxs_rcvacktoomuch++; + si->si_ack = cb->s_smax + 1; + } + spxstat.spxs_rcvackpack++; + /* + * If transmit timer is running and timed sequence + * number was acked, update smoothed round trip time. + * See discussion of algorithm in tcp_input.c + */ + if (cb->s_rtt && SSEQ_GT(si->si_ack, cb->s_rtseq)) { + spxstat.spxs_rttupdated++; + if (cb->s_srtt != 0) { + register short delta; + delta = cb->s_rtt - (cb->s_srtt >> 3); + if ((cb->s_srtt += delta) <= 0) + cb->s_srtt = 1; + if (delta < 0) + delta = -delta; + delta -= (cb->s_rttvar >> 2); + if ((cb->s_rttvar += delta) <= 0) + cb->s_rttvar = 1; + } else { + /* + * No rtt measurement yet + */ + cb->s_srtt = cb->s_rtt << 3; + cb->s_rttvar = cb->s_rtt << 1; + } + cb->s_rtt = 0; + cb->s_rxtshift = 0; + SPXT_RANGESET(cb->s_rxtcur, + ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1, + SPXTV_MIN, SPXTV_REXMTMAX); + } + /* + * If all outstanding data is acked, stop retransmit + * timer and remember to restart (more output or persist). + * If there is more data to be acked, restart retransmit + * timer, using current (possibly backed-off) value; + */ + if (si->si_ack == cb->s_smax + 1) { + cb->s_timer[SPXT_REXMT] = 0; + cb->s_flags |= SF_RXT; + } else if (cb->s_timer[SPXT_PERSIST] == 0) + cb->s_timer[SPXT_REXMT] = cb->s_rxtcur; + /* + * When new data is acked, open the congestion window. + * If the window gives us less than ssthresh packets + * in flight, open exponentially (maxseg at a time). + * Otherwise open linearly (maxseg^2 / cwnd at a time). + */ + incr = CUNIT; + if (cb->s_cwnd > cb->s_ssthresh) + incr = max(incr * incr / cb->s_cwnd, 1); + cb->s_cwnd = min(cb->s_cwnd + incr, cb->s_cwmx); + /* + * Trim Acked data from output queue. + */ + while ((m = so->so_snd.sb_mb) != NULL) { + if (SSEQ_LT((mtod(m, struct spx *))->si_seq, si->si_ack)) + sbdroprecord(&so->so_snd); + else + break; + } + sowwakeup(so); + cb->s_rack = si->si_ack; +update_window: + if (SSEQ_LT(cb->s_snxt, cb->s_rack)) + cb->s_snxt = cb->s_rack; + if (SSEQ_LT(cb->s_swl1, si->si_seq) || cb->s_swl1 == si->si_seq && + (SSEQ_LT(cb->s_swl2, si->si_ack) || + cb->s_swl2 == si->si_ack && SSEQ_LT(cb->s_ralo, si->si_alo))) { + /* keep track of pure window updates */ + if ((si->si_cc & SPX_SP) && cb->s_swl2 == si->si_ack + && SSEQ_LT(cb->s_ralo, si->si_alo)) { + spxstat.spxs_rcvwinupd++; + spxstat.spxs_rcvdupack--; + } + cb->s_ralo = si->si_alo; + cb->s_swl1 = si->si_seq; + cb->s_swl2 = si->si_ack; + cb->s_swnd = (1 + si->si_alo - si->si_ack); + if (cb->s_swnd > cb->s_smxw) + cb->s_smxw = cb->s_swnd; + cb->s_flags |= SF_WIN; + } + /* + * If this packet number is higher than that which + * we have allocated refuse it, unless urgent + */ + if (SSEQ_GT(si->si_seq, cb->s_alo)) { + if (si->si_cc & SPX_SP) { + spxstat.spxs_rcvwinprobe++; + return (1); + } else + spxstat.spxs_rcvpackafterwin++; + if (si->si_cc & SPX_OB) { + if (SSEQ_GT(si->si_seq, cb->s_alo + 60)) { + ipx_error(dtom(si), IPX_ERR_FULLUP, 0); + return (0); + } /* else queue this packet; */ + } else { + /*register struct socket *so = cb->s_ipxpcb->ipxp_socket; + if (so->so_state && SS_NOFDREF) { + ipx_error(dtom(si), IPX_ERR_NOSOCK, 0); + (void)spx_close(cb); + } else + would crash system*/ + spx_istat.notyet++; + ipx_error(dtom(si), IPX_ERR_FULLUP, 0); + return (0); + } + } + /* + * If this is a system packet, we don't need to + * queue it up, and won't update acknowledge # + */ + if (si->si_cc & SPX_SP) { + return (1); + } + /* + * We have already seen this packet, so drop. + */ + if (SSEQ_LT(si->si_seq, cb->s_ack)) { + spx_istat.bdreas++; + spxstat.spxs_rcvduppack++; + if (si->si_seq == cb->s_ack - 1) + spx_istat.lstdup++; + return (1); + } + /* + * Loop through all packets queued up to insert in + * appropriate sequence. + */ + for (q = cb->spxp_queue.tqh_first; q != NULL; q = q->list.tqe_next) { + if (si->si_seq == SI(q)->si_seq) { + spxstat.spxs_rcvduppack++; + return (1); + } + if (SSEQ_LT(si->si_seq, SI(q)->si_seq)) { + spxstat.spxs_rcvoopack++; + break; + } + } + { + register struct spx_q *p; + if ((p = malloc(sizeof(*p),M_DEVBUF,M_NOWAIT)) != NULL) + { + p->data = (caddr_t)si; + TAILQ_INSERT_AFTER(&cb->spxp_queue, q, p, list); + } else + return 1; + } + + /* + * If this packet is urgent, inform process + */ + if (si->si_cc & SPX_OB) { + cb->s_iobc = ((char *)si)[1 + sizeof(*si)]; + sohasoutofband(so); + cb->s_oobflags |= SF_IOOB; + } +present: +#define SPINC sizeof(struct spxhdr) + /* + * Loop through all packets queued up to update acknowledge + * number, and present all acknowledged data to user; + * If in packet interface mode, show packet headers. + */ + for (q = cb->spxp_queue.tqh_first; q != NULL; q = q->list.tqe_next) { + if (SI(q)->si_seq == cb->s_ack) { + cb->s_ack++; + m = dtom(q); + if (SI(q)->si_cc & SPX_OB) { + cb->s_oobflags &= ~SF_IOOB; + if (so->so_rcv.sb_cc) + so->so_oobmark = so->so_rcv.sb_cc; + else + so->so_state |= SS_RCVATMARK; + } + TAILQ_REMOVE(&cb->spxp_queue, q, list); + free(q, M_DEVBUF); + wakeup = 1; + spxstat.spxs_rcvpack++; +#ifdef SF_NEWCALL + if (cb->s_flags2 & SF_NEWCALL) { + struct spxhdr *sp = mtod(m, struct spxhdr *); + u_char dt = sp->spx_dt; + spx_newchecks[4]++; + if (dt != cb->s_rhdr.spx_dt) { + struct mbuf *mm = + m_getclr(M_DONTWAIT, MT_CONTROL); + spx_newchecks[0]++; + if (mm != NULL) { + u_short *s = + mtod(mm, u_short *); + cb->s_rhdr.spx_dt = dt; + mm->m_len = 5; /*XXX*/ + s[0] = 5; + s[1] = 1; + *(u_char *)(&s[2]) = dt; + sbappend(&so->so_rcv, mm); + } + } + if (sp->spx_cc & SPX_OB) { + MCHTYPE(m, MT_OOBDATA); + spx_newchecks[1]++; + so->so_oobmark = 0; + so->so_state &= ~SS_RCVATMARK; + } + if (packetp == 0) { + m->m_data += SPINC; + m->m_len -= SPINC; + m->m_pkthdr.len -= SPINC; + } + if ((sp->spx_cc & SPX_EM) || packetp) { + sbappendrecord(&so->so_rcv, m); + spx_newchecks[9]++; + } else + sbappend(&so->so_rcv, m); + } else +#endif + if (packetp) { + sbappendrecord(&so->so_rcv, m); + } else { + cb->s_rhdr = *mtod(m, struct spxhdr *); + m->m_data += SPINC; + m->m_len -= SPINC; + m->m_pkthdr.len -= SPINC; + sbappend(&so->so_rcv, m); + } + } else + break; + } + if (wakeup) sorwakeup(so); + return (0); +} + +void * +spx_ctlinput(cmd, arg_as_sa, dummy) + int cmd; + struct sockaddr *arg_as_sa; /* XXX should be swapped with dummy */ + void *dummy; +{ + caddr_t arg = (/* XXX */ caddr_t)arg_as_sa; + struct ipx_addr *na; + struct ipx_errp *errp = (struct ipx_errp *)arg; + struct ipxpcb *ipxp; + struct sockaddr_ipx *sipx; + int type; + + if (cmd < 0 || cmd > PRC_NCMDS) + return NULL; + type = IPX_ERR_UNREACH_HOST; + + switch (cmd) { + + case PRC_ROUTEDEAD: + return NULL; + + case PRC_IFDOWN: + case PRC_HOSTDEAD: + case PRC_HOSTUNREACH: + sipx = (struct sockaddr_ipx *)arg; + if (sipx->sipx_family != AF_IPX) + return NULL; + na = &sipx->sipx_addr; + break; + + default: + errp = (struct ipx_errp *)arg; + na = &errp->ipx_err_ipx.ipx_dna; + type = errp->ipx_err_num; + type = ntohs((u_short)type); + break; + } + switch (type) { + + case IPX_ERR_UNREACH_HOST: + ipx_pcbnotify(na, (int)ipxctlerrmap[cmd], spx_abort, (long)0); + break; + + case IPX_ERR_TOO_BIG: + case IPX_ERR_NOSOCK: + ipxp = ipx_pcblookup(na, errp->ipx_err_ipx.ipx_sna.ipx_port, + IPX_WILDCARD); + if (ipxp) { + if(ipxp->ipxp_ppcb) + (void)spx_drop((struct spxpcb *)ipxp->ipxp_ppcb, + (int)ipxctlerrmap[cmd]); + else + (void)ipx_drop(ipxp, (int)ipxctlerrmap[cmd]); + } + break; + + case IPX_ERR_FULLUP: + ipx_pcbnotify(na, 0, spx_quench, (long)0); + break; + } + + return NULL; +} +/* + * When a source quench is received, close congestion window + * to one packet. We will gradually open it again as we proceed. + */ +void +spx_quench(ipxp) + struct ipxpcb *ipxp; +{ + struct spxpcb *cb = ipxtospxpcb(ipxp); + + if (cb) + cb->s_cwnd = CUNIT; +} + +#ifdef notdef +int +spx_fixmtu(ipxp) +register struct ipxpcb *ipxp; +{ + register struct spxpcb *cb = (struct spxpcb *)(ipxp->ipxp_ppcb); + register struct mbuf *m; + register struct spx *si; + struct ipx_errp *ep; + struct sockbuf *sb; + int badseq, len; + struct mbuf *firstbad, *m0; + + if (cb) { + /* + * The notification that we have sent + * too much is bad news -- we will + * have to go through queued up so far + * splitting ones which are too big and + * reassigning sequence numbers and checksums. + * we should then retransmit all packets from + * one above the offending packet to the last one + * we had sent (or our allocation) + * then the offending one so that the any queued + * data at our destination will be discarded. + */ + ep = (struct ipx_errp *)ipxp->ipxp_notify_param; + sb = &ipxp->ipxp_socket->so_snd; + cb->s_mtu = ep->ipx_err_param; + badseq = SI(&ep->ipx_err_ipx)->si_seq; + for (m = sb->sb_mb; m; m = m->m_act) { + si = mtod(m, struct spx *); + if (si->si_seq == badseq) + break; + } + if (m == 0) return; + firstbad = m; + /*for (;;) {*/ + /* calculate length */ + for (m0 = m, len = 0; m ; m = m->m_next) + len += m->m_len; + if (len > cb->s_mtu) { + } + /* FINISH THIS + } */ + } +} +#endif + +int +spx_output(cb, m0) + register struct spxpcb *cb; + struct mbuf *m0; +{ + struct socket *so = cb->s_ipxpcb->ipxp_socket; + register struct mbuf *m; + register struct spx *si = (struct spx *) 0; + register struct sockbuf *sb = &so->so_snd; + int len = 0, win, rcv_win; + short span, off, recordp = 0; + u_short alo; + int error = 0, sendalot; +#ifdef notdef + int idle; +#endif + struct mbuf *mprev; + + if (m0) { + int mtu = cb->s_mtu; + int datalen; + /* + * Make sure that packet isn't too big. + */ + for (m = m0; m ; m = m->m_next) { + mprev = m; + len += m->m_len; + if (m->m_flags & M_EOR) + recordp = 1; + } + datalen = (cb->s_flags & SF_HO) ? + len - sizeof (struct spxhdr) : len; + if (datalen > mtu) { + if (cb->s_flags & SF_PI) { + m_freem(m0); + return (EMSGSIZE); + } else { + int oldEM = cb->s_cc & SPX_EM; + + cb->s_cc &= ~SPX_EM; + while (len > mtu) { + /* + * Here we are only being called + * from usrreq(), so it is OK to + * block. + */ + m = m_copym(m0, 0, mtu, M_WAIT); + if (cb->s_flags & SF_NEWCALL) { + struct mbuf *mm = m; + spx_newchecks[7]++; + while (mm) { + mm->m_flags &= ~M_EOR; + mm = mm->m_next; + } + } + error = spx_output(cb, m); + if (error) { + cb->s_cc |= oldEM; + m_freem(m0); + return(error); + } + m_adj(m0, mtu); + len -= mtu; + } + cb->s_cc |= oldEM; + } + } + /* + * Force length even, by adding a "garbage byte" if + * necessary. + */ + if (len & 1) { + m = mprev; + if (M_TRAILINGSPACE(m) >= 1) + 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, u_char *)) = 0; + m->m_next = m1; + } + } + m = m_gethdr(M_DONTWAIT, MT_HEADER); + if (m == 0) { + m_freem(m0); + return (ENOBUFS); + } + /* + * Fill in mbuf with extended SP header + * and addresses and length put into network format. + */ + MH_ALIGN(m, sizeof (struct spx)); + m->m_len = sizeof (struct spx); + m->m_next = m0; + si = mtod(m, struct spx *); + si->si_i = *cb->s_ipx; + si->si_s = cb->s_shdr; + if ((cb->s_flags & SF_PI) && (cb->s_flags & SF_HO)) { + register struct spxhdr *sh; + if (m0->m_len < sizeof (*sh)) { + if((m0 = m_pullup(m0, sizeof(*sh))) == NULL) { + (void) m_free(m); + m_freem(m0); + return (EINVAL); + } + m->m_next = m0; + } + sh = mtod(m0, struct spxhdr *); + si->si_dt = sh->spx_dt; + si->si_cc |= sh->spx_cc & SPX_EM; + m0->m_len -= sizeof (*sh); + m0->m_data += sizeof (*sh); + len -= sizeof (*sh); + } + len += sizeof(*si); + if ((cb->s_flags2 & SF_NEWCALL) && recordp) { + si->si_cc |= SPX_EM; + spx_newchecks[8]++; + } + if (cb->s_oobflags & SF_SOOB) { + /* + * Per jqj@cornell: + * make sure OB packets convey exactly 1 byte. + * If the packet is 1 byte or larger, we + * have already guaranted there to be at least + * one garbage byte for the checksum, and + * extra bytes shouldn't hurt! + */ + if (len > sizeof(*si)) { + si->si_cc |= SPX_OB; + len = (1 + sizeof(*si)); + } + } + si->si_len = htons((u_short)len); + m->m_pkthdr.len = ((len - 1) | 1) + 1; + /* + * queue stuff up for output + */ + sbappendrecord(sb, m); + cb->s_seq++; + } +#ifdef notdef + idle = (cb->s_smax == (cb->s_rack - 1)); +#endif +again: + sendalot = 0; + off = cb->s_snxt - cb->s_rack; + win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)); + + /* + * If in persist timeout with window of 0, send a probe. + * Otherwise, if window is small but nonzero + * and timer expired, send what we can and go into + * transmit state. + */ + if (cb->s_force == 1 + SPXT_PERSIST) { + if (win != 0) { + cb->s_timer[SPXT_PERSIST] = 0; + cb->s_rxtshift = 0; + } + } + span = cb->s_seq - cb->s_rack; + len = min(span, win) - off; + + if (len < 0) { + /* + * Window shrank after we went into it. + * If window shrank to 0, cancel pending + * restransmission and pull s_snxt back + * to (closed) window. We will enter persist + * state below. If the widndow didn't close completely, + * just wait for an ACK. + */ + len = 0; + if (win == 0) { + cb->s_timer[SPXT_REXMT] = 0; + cb->s_snxt = cb->s_rack; + } + } + if (len > 1) + sendalot = 1; + rcv_win = sbspace(&so->so_rcv); + + /* + * Send if we owe peer an ACK. + */ + if (cb->s_oobflags & SF_SOOB) { + /* + * must transmit this out of band packet + */ + cb->s_oobflags &= ~ SF_SOOB; + sendalot = 1; + spxstat.spxs_sndurg++; + goto found; + } + if (cb->s_flags & SF_ACKNOW) + goto send; + if (cb->s_state < TCPS_ESTABLISHED) + goto send; + /* + * Silly window can't happen in spx. + * Code from tcp deleted. + */ + if (len) + goto send; + /* + * Compare available window to amount of window + * known to peer (as advertised window less + * next expected input.) If the difference is at least two + * packets or at least 35% of the mximum possible window, + * then want to send a window update to peer. + */ + if (rcv_win > 0) { + u_short delta = 1 + cb->s_alo - cb->s_ack; + int adv = rcv_win - (delta * cb->s_mtu); + + if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) || + (100 * adv / so->so_rcv.sb_hiwat >= 35)) { + spxstat.spxs_sndwinup++; + cb->s_flags |= SF_ACKNOW; + goto send; + } + + } + /* + * Many comments from tcp_output.c are appropriate here + * including . . . + * If send window is too small, there is data to transmit, and no + * retransmit or persist is pending, then go to persist state. + * If nothing happens soon, send when timer expires: + * if window is nonzero, transmit what we can, + * otherwise send a probe. + */ + if (so->so_snd.sb_cc && cb->s_timer[SPXT_REXMT] == 0 && + cb->s_timer[SPXT_PERSIST] == 0) { + cb->s_rxtshift = 0; + spx_setpersist(cb); + } + /* + * No reason to send a packet, just return. + */ + cb->s_outx = 1; + return (0); + +send: + /* + * Find requested packet. + */ + si = 0; + if (len > 0) { + cb->s_want = cb->s_snxt; + for (m = sb->sb_mb; m; m = m->m_act) { + si = mtod(m, struct spx *); + if (SSEQ_LEQ(cb->s_snxt, si->si_seq)) + break; + } + found: + if (si) { + if (si->si_seq == cb->s_snxt) + cb->s_snxt++; + else + spxstat.spxs_sndvoid++, si = 0; + } + } + /* + * update window + */ + if (rcv_win < 0) + rcv_win = 0; + alo = cb->s_ack - 1 + (rcv_win / ((short)cb->s_mtu)); + if (SSEQ_LT(alo, cb->s_alo)) + alo = cb->s_alo; + + if (si) { + /* + * must make a copy of this packet for + * ipx_output to monkey with + */ + m = m_copy(dtom(si), 0, (int)M_COPYALL); + if (m == NULL) { + return (ENOBUFS); + } + si = mtod(m, struct spx *); + if (SSEQ_LT(si->si_seq, cb->s_smax)) + spxstat.spxs_sndrexmitpack++; + else + spxstat.spxs_sndpack++; + } else if (cb->s_force || cb->s_flags & SF_ACKNOW) { + /* + * Must send an acknowledgement or a probe + */ + if (cb->s_force) + spxstat.spxs_sndprobe++; + if (cb->s_flags & SF_ACKNOW) + spxstat.spxs_sndacks++; + m = m_gethdr(M_DONTWAIT, MT_HEADER); + if (m == 0) + return (ENOBUFS); + /* + * Fill in mbuf with extended SP header + * and addresses and length put into network format. + */ + MH_ALIGN(m, sizeof (struct spx)); + m->m_len = sizeof (*si); + m->m_pkthdr.len = sizeof (*si); + si = mtod(m, struct spx *); + si->si_i = *cb->s_ipx; + si->si_s = cb->s_shdr; + si->si_seq = cb->s_smax + 1; + si->si_len = htons(sizeof (*si)); + si->si_cc |= SPX_SP; + } else { + cb->s_outx = 3; + if (so->so_options & SO_DEBUG || traceallspxs) + spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0); + return (0); + } + /* + * Stuff checksum and output datagram. + */ + if ((si->si_cc & SPX_SP) == 0) { + if (cb->s_force != (1 + SPXT_PERSIST) || + cb->s_timer[SPXT_PERSIST] == 0) { + /* + * If this is a new packet and we are not currently + * timing anything, time this one. + */ + if (SSEQ_LT(cb->s_smax, si->si_seq)) { + cb->s_smax = si->si_seq; + if (cb->s_rtt == 0) { + spxstat.spxs_segstimed++; + cb->s_rtseq = si->si_seq; + cb->s_rtt = 1; + } + } + /* + * Set rexmt timer if not currently set, + * Initial value for retransmit timer is smoothed + * round-trip time + 2 * round-trip time variance. + * Initialize shift counter which is used for backoff + * of retransmit time. + */ + if (cb->s_timer[SPXT_REXMT] == 0 && + cb->s_snxt != cb->s_rack) { + cb->s_timer[SPXT_REXMT] = cb->s_rxtcur; + if (cb->s_timer[SPXT_PERSIST]) { + cb->s_timer[SPXT_PERSIST] = 0; + cb->s_rxtshift = 0; + } + } + } else if (SSEQ_LT(cb->s_smax, si->si_seq)) { + cb->s_smax = si->si_seq; + } + } else if (cb->s_state < TCPS_ESTABLISHED) { + if (cb->s_rtt == 0) + cb->s_rtt = 1; /* Time initial handshake */ + if (cb->s_timer[SPXT_REXMT] == 0) + cb->s_timer[SPXT_REXMT] = cb->s_rxtcur; + } + { + /* + * Do not request acks when we ack their data packets or + * when we do a gratuitous window update. + */ + if (((si->si_cc & SPX_SP) == 0) || cb->s_force) + si->si_cc |= SPX_SA; + si->si_seq = htons(si->si_seq); + si->si_alo = htons(alo); + si->si_ack = htons(cb->s_ack); + + if (ipxcksum) { + si->si_sum = 0; + len = ntohs(si->si_len); + if (len & 1) + len++; + si->si_sum = ipx_cksum(m, len); + } else + si->si_sum = 0xffff; + + cb->s_outx = 4; + if (so->so_options & SO_DEBUG || traceallspxs) + spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0); + + if (so->so_options & SO_DONTROUTE) + error = ipx_outputfl(m, (struct route *)0, IPX_ROUTETOIF); + else + error = ipx_outputfl(m, &cb->s_ipxpcb->ipxp_route, 0); + } + if (error) { + return (error); + } + spxstat.spxs_sndtotal++; + /* + * Data sent (as far as we can tell). + * If this advertises a larger window than any other segment, + * then remember the size of the advertized window. + * Any pending ACK has now been sent. + */ + cb->s_force = 0; + cb->s_flags &= ~(SF_ACKNOW|SF_DELACK); + if (SSEQ_GT(alo, cb->s_alo)) + cb->s_alo = alo; + if (sendalot) + goto again; + cb->s_outx = 5; + return (0); +} + +int spx_do_persist_panics = 0; + +void +spx_setpersist(cb) + register struct spxpcb *cb; +{ + register t = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1; + + if (cb->s_timer[SPXT_REXMT] && spx_do_persist_panics) + panic("spx_output REXMT"); + /* + * Start/restart persistance timer. + */ + SPXT_RANGESET(cb->s_timer[SPXT_PERSIST], + t*spx_backoff[cb->s_rxtshift], + SPXTV_PERSMIN, SPXTV_PERSMAX); + if (cb->s_rxtshift < SPX_MAXRXTSHIFT) + cb->s_rxtshift++; +} + +/*ARGSUSED*/ +int +spx_ctloutput(req, so, level, name, value) + int req; + struct socket *so; + int level, name; + struct mbuf **value; +{ + register struct mbuf *m; + struct ipxpcb *ipxp = sotoipxpcb(so); + register struct spxpcb *cb; + int mask, error = 0; + + if (level != IPXPROTO_SPX) { + /* This will have to be changed when we do more general + stacking of protocols */ + return (ipx_ctloutput(req, so, level, name, value)); + } + if (ipxp == NULL) { + error = EINVAL; + goto release; + } else + cb = ipxtospxpcb(ipxp); + + 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_HEADERS_ON_INPUT: + mask = SF_HI; + goto get_flags; + + case SO_HEADERS_ON_OUTPUT: + mask = SF_HO; + get_flags: + m->m_len = sizeof(short); + *mtod(m, short *) = cb->s_flags & mask; + break; + + case SO_MTU: + m->m_len = sizeof(u_short); + *mtod(m, short *) = cb->s_mtu; + break; + + case SO_LAST_HEADER: + m->m_len = sizeof(struct spxhdr); + *mtod(m, struct spxhdr *) = cb->s_rhdr; + break; + + case SO_DEFAULT_HEADERS: + m->m_len = sizeof(struct spx); + *mtod(m, struct spxhdr *) = cb->s_shdr; + break; + + default: + error = EINVAL; + } + *value = m; + break; + + case PRCO_SETOPT: + if (value == 0 || *value == 0) { + error = EINVAL; + break; + } + switch (name) { + int *ok; + + case SO_HEADERS_ON_INPUT: + mask = SF_HI; + goto set_head; + + case SO_HEADERS_ON_OUTPUT: + mask = SF_HO; + set_head: + if (cb->s_flags & SF_PI) { + ok = mtod(*value, int *); + if (*ok) + cb->s_flags |= mask; + else + cb->s_flags &= ~mask; + } else error = EINVAL; + break; + + case SO_MTU: + cb->s_mtu = *(mtod(*value, u_short *)); + break; + +#ifdef SF_NEWCALL + case SO_NEWCALL: + ok = mtod(*value, int *); + if (*ok) { + cb->s_flags2 |= SF_NEWCALL; + spx_newchecks[5]++; + } else { + cb->s_flags2 &= ~SF_NEWCALL; + spx_newchecks[6]++; + } + break; +#endif + + case SO_DEFAULT_HEADERS: + { + register struct spxhdr *sp + = mtod(*value, struct spxhdr *); + cb->s_dt = sp->spx_dt; + cb->s_cc = sp->spx_cc & SPX_EM; + } + break; + + default: + error = EINVAL; + } + m_freem(*value); + break; + } + release: + return (error); +} + +/*ARGSUSED*/ +int +spx_usrreq(so, req, m, nam, controlp) + struct socket *so; + int req; + struct mbuf *m, *nam, *controlp; +{ + struct ipxpcb *ipxp = sotoipxpcb(so); + register struct spxpcb *cb = NULL; + int s = splnet(); + int error = 0, ostate; + register struct sockbuf *sb; + + if (req == PRU_CONTROL) + return (ipx_control(so, (int)m, (caddr_t)nam, + (struct ifnet *)controlp)); + if (ipxp == NULL) { + if (req != PRU_ATTACH) { + error = EINVAL; + goto release; + } + } else + cb = ipxtospxpcb(ipxp); + + ostate = cb ? cb->s_state : 0; + + switch (req) { + + case PRU_ATTACH: + if (ipxp != NULL) { + error = EISCONN; + break; + } + error = ipx_pcballoc(so, &ipxcbtable); + if (error) + break; + if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + error = soreserve(so, (u_long) 3072, (u_long) 3072); + if (error) + break; + } + ipxp = sotoipxpcb(so); + sb = &so->so_snd; + + cb = malloc(sizeof(*cb), M_PCB, M_NOWAIT); + if (cb == NULL) { + error = ENOBUFS; + break; + } + bzero((caddr_t)cb, sizeof(*cb)); + cb->s_ipx = malloc(sizeof(*cb->s_ipx), M_PCB, M_NOWAIT); + if (cb->s_ipx == NULL) { + (void) free(cb, M_PCB); + error = ENOBUFS; + break; + } + bzero((caddr_t)cb->s_ipx, sizeof(*cb->s_ipx)); + cb->s_state = TCPS_LISTEN; + cb->s_smax = -1; + cb->s_swl1 = -1; + TAILQ_INIT(&cb->spxp_queue); + cb->s_ipxpcb = ipxp; + cb->s_mtu = 576 - sizeof (struct spx); + cb->s_cwnd = sbspace(sb) * CUNIT / cb->s_mtu; + cb->s_ssthresh = cb->s_cwnd; + cb->s_cwmx = sbspace(sb) * CUNIT / + (2 * sizeof (struct spx)); + /* Above is recomputed when connecting to account + for changed buffering or mtu's */ + cb->s_rtt = SPXTV_SRTTBASE; + cb->s_rttvar = SPXTV_SRTTDFLT << 2; + SPXT_RANGESET(cb->s_rxtcur, + ((SPXTV_SRTTBASE >> 2) + (SPXTV_SRTTDFLT << 2)) >> 1, + SPXTV_MIN, SPXTV_REXMTMAX); + ipxp->ipxp_ppcb = (caddr_t) cb; + break; + + case PRU_DETACH: + if (ipxp == NULL) { + error = ENOTCONN; + break; + } + if (cb->s_state > TCPS_LISTEN) + cb = spx_disconnect(cb); + else + cb = spx_close(cb); + break; + + case PRU_BIND: + error = ipx_pcbbind(ipxp, nam); + break; + + case PRU_LISTEN: + if (ipxp->ipxp_lport == 0) + error = ipx_pcbbind(ipxp, (struct mbuf *)0); + if (error == 0) + cb->s_state = TCPS_LISTEN; + break; + + /* + * Initiate connection to peer. + * Enter SYN_SENT state, and mark socket as connecting. + * Start keep-alive timer, setup prototype header, + * Send initial system packet requesting connection. + */ + case PRU_CONNECT: + if (ipxp->ipxp_lport == 0) { + error = ipx_pcbbind(ipxp, (struct mbuf *)0); + if (error) + break; + } + error = ipx_pcbconnect(ipxp, nam); + if (error) + break; + soisconnecting(so); + spxstat.spxs_connattempt++; + cb->s_state = TCPS_SYN_SENT; + cb->s_did = 0; + spx_template(cb); + cb->s_timer[SPXT_KEEP] = SPXTV_KEEP; + cb->s_force = 1 + SPXTV_KEEP; + /* + * Other party is required to respond to + * the port I send from, but he is not + * required to answer from where I am sending to, + * so allow wildcarding. + * original port I am sending to is still saved in + * cb->s_dport. + */ + ipxp->ipxp_fport = 0; + error = spx_output(cb, (struct mbuf *) 0); + break; + + case PRU_CONNECT2: + error = EOPNOTSUPP; + break; + + /* + * We may decide later to implement connection closing + * handshaking at the spx level optionally. + * here is the hook to do it: + */ + case PRU_DISCONNECT: + cb = spx_disconnect(cb); + break; + + /* + * Accept a connection. Essentially all the work is + * done at higher levels; just return the address + * of the peer, storing through addr. + */ + case PRU_ACCEPT: { + struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); + + nam->m_len = sizeof (struct sockaddr_ipx); + sipx->sipx_family = AF_IPX; + sipx->sipx_addr = ipxp->ipxp_faddr; + break; + } + + case PRU_SHUTDOWN: + socantsendmore(so); + cb = spx_usrclosed(cb); + if (cb) + error = spx_output(cb, (struct mbuf *) 0); + break; + + /* + * After a receive, possibly send acknowledgment + * updating allocation. + */ + case PRU_RCVD: + cb->s_flags |= SF_RVD; + (void) spx_output(cb, (struct mbuf *) 0); + cb->s_flags &= ~SF_RVD; + break; + + case PRU_ABORT: + (void) spx_drop(cb, ECONNABORTED); + break; + + case PRU_SENSE: + case PRU_CONTROL: + m = NULL; + error = EOPNOTSUPP; + break; + + case PRU_RCVOOB: + if ((cb->s_oobflags & SF_IOOB) || so->so_oobmark || + (so->so_state & SS_RCVATMARK)) { + m->m_len = 1; + *mtod(m, caddr_t) = cb->s_iobc; + break; + } + error = EINVAL; + break; + + case PRU_SENDOOB: + if (sbspace(&so->so_snd) < -512) { + error = ENOBUFS; + break; + } + cb->s_oobflags |= SF_SOOB; + /* fall into */ + case PRU_SEND: + if (controlp) { + u_short *p = mtod(controlp, u_short *); + spx_newchecks[2]++; + if ((p[0] == 5) && p[1] == 1) { /* XXXX, for testing */ + cb->s_shdr.spx_dt = *(u_char *)(&p[2]); + spx_newchecks[3]++; + } + m_freem(controlp); + } + controlp = NULL; + error = spx_output(cb, m); + m = NULL; + break; + + case PRU_SOCKADDR: + ipx_setsockaddr(ipxp, nam); + break; + + case PRU_PEERADDR: + ipx_setpeeraddr(ipxp, nam); + break; + + case PRU_SLOWTIMO: + cb = spx_timers(cb, (int)nam); + req |= ((int)nam) << 8; + break; + + case PRU_FASTTIMO: + case PRU_PROTORCV: + case PRU_PROTOSEND: + error = EOPNOTSUPP; + break; + + default: + panic("spx_usrreq"); + } + if (cb && (so->so_options & SO_DEBUG || traceallspxs)) + spx_trace(SA_USER, (u_char)ostate, cb, (struct spx *)0, req); +release: + if (controlp != NULL) + m_freem(controlp); + if (m != NULL) + m_freem(m); + splx(s); + return (error); +} + +int +spx_usrreq_sp(so, req, m, nam, controlp) + struct socket *so; + int req; + struct mbuf *m, *nam, *controlp; +{ + int error = spx_usrreq(so, req, m, nam, controlp); + + if (req == PRU_ATTACH && error == 0) { + struct ipxpcb *ipxp = sotoipxpcb(so); + ((struct spxpcb *)ipxp->ipxp_ppcb)->s_flags |= + (SF_HI | SF_HO | SF_PI); + } + return (error); +} + +/* + * Create template to be used to send spx packets on a connection. + * Called after host entry created, fills + * in a skeletal spx header (choosing connection id), + * minimizing the amount of work necessary when the connection is used. + */ +void +spx_template(cb) + register struct spxpcb *cb; +{ + register struct ipxpcb *ipxp = cb->s_ipxpcb; + register struct ipx *ipx = cb->s_ipx; + register struct sockbuf *sb = &(ipxp->ipxp_socket->so_snd); + + ipx->ipx_pt = IPXPROTO_SPX; + ipx->ipx_sna = ipxp->ipxp_laddr; + ipx->ipx_dna = ipxp->ipxp_faddr; + cb->s_sid = htons(spx_iss); + spx_iss += SPX_ISSINCR/2; + cb->s_alo = 1; + cb->s_cwnd = (sbspace(sb) * CUNIT) / cb->s_mtu; + cb->s_ssthresh = cb->s_cwnd; /* Try to expand fast to full complement + of large packets */ + cb->s_cwmx = (sbspace(sb) * CUNIT) / (2 * sizeof(struct spx)); + cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd); + /* But allow for lots of little packets as well */ +} + +/* + * Close a SPIP control block: + * discard spx control block itself + * discard ipx protocol control block + * wake up any sleepers + */ +struct spxpcb * +spx_close(cb) + register struct spxpcb *cb; +{ + register struct spx_q *s; + struct ipxpcb *ipxp = cb->s_ipxpcb; + struct socket *so = ipxp->ipxp_socket; + register struct mbuf *m; + + s = cb->spxp_queue.tqh_first; + while (s != NULL) { + m = dtom(s->data); + s = s->list.tqe_next; + free(s, M_DEVBUF); + m_freem(m); + } + TAILQ_INIT(&cb->spxp_queue); + (void) m_free(dtom(cb->s_ipx)); + (void) m_free(dtom(cb)); + ipxp->ipxp_ppcb = 0; + soisdisconnected(so); + ipx_pcbdetach(ipxp); + spxstat.spxs_closed++; + return ((struct spxpcb *)0); +} +/* + * Someday we may do level 3 handshaking + * to close a connection or send a xerox style error. + * For now, just close. + */ +struct spxpcb * +spx_usrclosed(cb) + register struct spxpcb *cb; +{ + return (spx_close(cb)); +} +struct spxpcb * +spx_disconnect(cb) + register struct spxpcb *cb; +{ + return (spx_close(cb)); +} +/* + * Drop connection, reporting + * the specified error. + */ +struct spxpcb * +spx_drop(cb, errno) + register struct spxpcb *cb; + int errno; +{ + struct socket *so = cb->s_ipxpcb->ipxp_socket; + + /* + * someday, in the xerox world + * we will generate error protocol packets + * announcing that the socket has gone away. + */ + if (TCPS_HAVERCVDSYN(cb->s_state)) { + spxstat.spxs_drops++; + cb->s_state = TCPS_CLOSED; + /*(void) tcp_output(cb);*/ + } else + spxstat.spxs_conndrops++; + so->so_error = errno; + return (spx_close(cb)); +} + +void +spx_abort(ipxp) + struct ipxpcb *ipxp; +{ + + (void) spx_close((struct spxpcb *)ipxp->ipxp_ppcb); +} + +int spx_backoff[SPX_MAXRXTSHIFT+1] = + { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 }; +/* + * Fast timeout routine for processing delayed acks + */ +void +spx_fasttimo() +{ + register struct ipxpcb *ipxp; + register struct spxpcb *cb; + int s = splnet(); + + ipxp = ipxcbtable.ipxpt_queue.cqh_first; + if (ipxp) + for (; ipxp != (struct ipxpcb *)&ipxcbtable.ipxpt_queue; + ipxp = ipxp->ipxp_queue.cqe_next) + if ((cb = (struct spxpcb *)ipxp->ipxp_ppcb) && + (cb->s_flags & SF_DELACK)) { + cb->s_flags &= ~SF_DELACK; + cb->s_flags |= SF_ACKNOW; + spxstat.spxs_delack++; + (void) spx_output(cb, (struct mbuf *) 0); + } + splx(s); +} + +/* + * spx protocol timeout routine called every 500 ms. + * Updates the timers in all active pcb's and + * causes finite state machine actions if timers expire. + */ +void +spx_slowtimo() +{ + register struct ipxpcb *ipx, *ipxnxt; + register struct spxpcb *cb; + int s = splnet(); + register int i; + + /* + * Search through tcb's and update active timers. + */ + ipx = ipxcbtable.ipxpt_queue.cqh_first; + if (ipx == 0) { + splx(s); + return; + } + while (ipx != (struct ipxpcb *)&ipxcbtable.ipxpt_queue) { + cb = ipxtospxpcb(ipx); + ipxnxt = ipx->ipxp_queue.cqe_next; + if (cb == 0) + goto tpgone; + for (i = 0; i < SPXT_NTIMERS; i++) { + if (cb->s_timer[i] && --cb->s_timer[i] == 0) { + (void) spx_usrreq(cb->s_ipxpcb->ipxp_socket, + PRU_SLOWTIMO, (struct mbuf *)0, + (struct mbuf *)i, (struct mbuf *)0); + if (ipxnxt->ipxp_queue.cqe_prev != ipx) + goto tpgone; + } + } + cb->s_idle++; + if (cb->s_rtt) + cb->s_rtt++; +tpgone: + ipx = ipxnxt; + } + spx_iss += SPX_ISSINCR/PR_SLOWHZ; /* increment iss */ + splx(s); +} +/* + * SPX timer processing. + */ +struct spxpcb * +spx_timers(cb, timer) + register struct spxpcb *cb; + int timer; +{ + long rexmt; + int win; + + cb->s_force = 1 + timer; + switch (timer) { + + /* + * 2 MSL timeout in shutdown went off. TCP deletes connection + * control block. + */ + case SPXT_2MSL: + printf("spx: SPXT_2MSL went off for no reason\n"); + cb->s_timer[timer] = 0; + break; + + /* + * Retransmission timer went off. Message has not + * been acked within retransmit interval. Back off + * to a longer retransmit interval and retransmit one packet. + */ + case SPXT_REXMT: + if (++cb->s_rxtshift > SPX_MAXRXTSHIFT) { + cb->s_rxtshift = SPX_MAXRXTSHIFT; + spxstat.spxs_timeoutdrop++; + cb = spx_drop(cb, ETIMEDOUT); + break; + } + spxstat.spxs_rexmttimeo++; + rexmt = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1; + rexmt *= spx_backoff[cb->s_rxtshift]; + SPXT_RANGESET(cb->s_rxtcur, rexmt, SPXTV_MIN, SPXTV_REXMTMAX); + cb->s_timer[SPXT_REXMT] = cb->s_rxtcur; + /* + * If we have backed off fairly far, our srtt + * estimate is probably bogus. Clobber it + * so we'll take the next rtt measurement as our srtt; + * move the current srtt into rttvar to keep the current + * retransmit times until then. + */ + if (cb->s_rxtshift > SPX_MAXRXTSHIFT / 4 ) { + cb->s_rttvar += (cb->s_srtt >> 2); + cb->s_srtt = 0; + } + cb->s_snxt = cb->s_rack; + /* + * If timing a packet, stop the timer. + */ + cb->s_rtt = 0; + /* + * See very long discussion in tcp_timer.c about congestion + * window and sstrhesh + */ + win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)) / 2; + if (win < 2) + win = 2; + cb->s_cwnd = CUNIT; + cb->s_ssthresh = win * CUNIT; + (void) spx_output(cb, (struct mbuf *) 0); + break; + + /* + * Persistance timer into zero window. + * Force a probe to be sent. + */ + case SPXT_PERSIST: + spxstat.spxs_persisttimeo++; + spx_setpersist(cb); + (void) spx_output(cb, (struct mbuf *) 0); + break; + + /* + * Keep-alive timer went off; send something + * or drop connection if idle for too long. + */ + case SPXT_KEEP: + spxstat.spxs_keeptimeo++; + if (cb->s_state < TCPS_ESTABLISHED) + goto dropit; + if (cb->s_ipxpcb->ipxp_socket->so_options & SO_KEEPALIVE) { + if (cb->s_idle >= SPXTV_MAXIDLE) + goto dropit; + spxstat.spxs_keepprobe++; + (void) spx_output(cb, (struct mbuf *) 0); + } else + cb->s_idle = 0; + cb->s_timer[SPXT_KEEP] = SPXTV_KEEP; + break; + dropit: + spxstat.spxs_keepdrops++; + cb = spx_drop(cb, ETIMEDOUT); + break; + } + return (cb); +} diff --git a/sys/netipx/spx_var.h b/sys/netipx/spx_var.h new file mode 100644 index 00000000000..ee737a702f6 --- /dev/null +++ b/sys/netipx/spx_var.h @@ -0,0 +1,138 @@ +/* $OpenBSD: spx_var.h,v 1.1 1996/08/16 09:16:04 mickey Exp $ */ +/* $NOWHERE: spx_var.h,v 1.2 1996/05/07 09:49:57 mickey Exp $ */ + +/*- + * + * Copyright (c) 1996 Michael Shalayeff + * Copyright (c) 1995, Mike Mitchell + * 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. + * + * @(#)spx_var.h + * + * from FreeBSD Id: spx_var.h,v 1.4 1995/11/04 09:03:47 julian Exp + */ + +#ifndef _NETIPX_SPX_VAR_H_ +#define _NETIPX_SPX_VAR_H_ + +struct spxstat { + long spxs_connattempt; /* connections initiated */ + long spxs_accepts; /* connections accepted */ + long spxs_connects; /* connections established */ + long spxs_drops; /* connections dropped */ + long spxs_conndrops; /* embryonic connections dropped */ + long spxs_closed; /* conn. closed (includes drops) */ + long spxs_segstimed; /* segs where we tried to get rtt */ + long spxs_rttupdated; /* times we succeeded */ + long spxs_delack; /* delayed acks sent */ + long spxs_timeoutdrop; /* conn. dropped in rxmt timeout */ + long spxs_rexmttimeo; /* retransmit timeouts */ + long spxs_persisttimeo; /* persist timeouts */ + long spxs_keeptimeo; /* keepalive timeouts */ + long spxs_keepprobe; /* keepalive probes sent */ + long spxs_keepdrops; /* connections dropped in keepalive */ + + long spxs_sndtotal; /* total packets sent */ + long spxs_sndpack; /* data packets sent */ + long spxs_sndbyte; /* data bytes sent */ + long spxs_sndrexmitpack; /* data packets retransmitted */ + long spxs_sndrexmitbyte; /* data bytes retransmitted */ + long spxs_sndacks; /* ack-only packets sent */ + long spxs_sndprobe; /* window probes sent */ + long spxs_sndurg; /* packets sent with URG only */ + long spxs_sndwinup; /* window update-only packets sent */ + long spxs_sndctrl; /* control (SYN|FIN|RST) packets sent */ + long spxs_sndvoid; /* couldn't find requested packet*/ + + long spxs_rcvtotal; /* total packets received */ + long spxs_rcvpack; /* packets received in sequence */ + long spxs_rcvbyte; /* bytes received in sequence */ + long spxs_rcvbadsum; /* packets received with ccksum errs */ + long spxs_rcvbadoff; /* packets received with bad offset */ + long spxs_rcvshort; /* packets received too short */ + long spxs_rcvduppack; /* duplicate-only packets received */ + long spxs_rcvdupbyte; /* duplicate-only bytes received */ + long spxs_rcvpartduppack; /* packets with some duplicate data */ + long spxs_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ + long spxs_rcvoopack; /* out-of-order packets received */ + long spxs_rcvoobyte; /* out-of-order bytes received */ + long spxs_rcvpackafterwin; /* packets with data after window */ + long spxs_rcvbyteafterwin; /* bytes rcvd after window */ + long spxs_rcvafterclose; /* packets rcvd after "close" */ + long spxs_rcvwinprobe; /* rcvd window probe packets */ + long spxs_rcvdupack; /* rcvd duplicate acks */ + long spxs_rcvacktoomuch; /* rcvd acks for unsent data */ + long spxs_rcvackpack; /* rcvd ack packets */ + long spxs_rcvackbyte; /* bytes acked by rcvd acks */ + long spxs_rcvwinupd; /* rcvd window update packets */ +}; + +struct spx_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 spxstat newstats; +}; + +#ifdef _KERNEL +extern struct spx_istat spx_istat; +extern u_short spx_iss; + +/* Following was struct spxstat spxstat; */ +#ifndef spxstat +#define spxstat spx_istat.newstats +#endif + +#endif + +#define SPX_ISSINCR 128 +/* + * spx sequence numbers are 16 bit integers operated + * on with modular arithmetic. These macros can be + * used to compare such integers. + */ +#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 |