af.c revision 12620
111820Sjulian/* 211820Sjulian * Copyright (c) 1985, 1993 311820Sjulian * The Regents of the University of California. All rights reserved. 411820Sjulian * 511820Sjulian * Copyright (c) 1995 John Hay. All rights reserved. 611820Sjulian * 711820Sjulian * This file includes significant work done at Cornell University by 811820Sjulian * Bill Nesheim. That work included by permission. 911820Sjulian * 1011820Sjulian * Redistribution and use in source and binary forms, with or without 1111820Sjulian * modification, are permitted provided that the following conditions 1211820Sjulian * are met: 1311820Sjulian * 1. Redistributions of source code must retain the above copyright 1411820Sjulian * notice, this list of conditions and the following disclaimer. 1511820Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1611820Sjulian * notice, this list of conditions and the following disclaimer in the 1711820Sjulian * documentation and/or other materials provided with the distribution. 1811820Sjulian * 3. All advertising materials mentioning features or use of this software 1911820Sjulian * must display the following acknowledgement: 2011820Sjulian * This product includes software developed by the University of 2111820Sjulian * California, Berkeley and its contributors. 2211820Sjulian * 4. Neither the name of the University nor the names of its contributors 2311820Sjulian * may be used to endorse or promote products derived from this software 2411820Sjulian * without specific prior written permission. 2511820Sjulian * 2611820Sjulian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2711820Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2811820Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2911820Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3011820Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3111820Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3211820Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3311820Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3411820Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3511820Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3611820Sjulian * SUCH DAMAGE. 3711820Sjulian * 3812620Sjulian * $Id: af.c,v 1.1 1995/10/26 21:28:13 julian Exp $ 3911820Sjulian */ 4011820Sjulian 4111820Sjulian#ifndef lint 4211820Sjulianstatic char sccsid[] = "@(#)af.c 8.1 (Berkeley) 6/5/93"; 4311820Sjulian#endif /* not lint */ 4411820Sjulian 4511820Sjulian#include "defs.h" 4611820Sjulian 4711820Sjulian/* 4811820Sjulian * Address family support routines 4911820Sjulian */ 5011820Sjulianaf_hash_t null_hash; 5111820Sjulianaf_netmatch_t null_netmatch; 5211820Sjulianaf_output_t null_output; 5311820Sjulianaf_portmatch_t null_portmatch; 5411820Sjulianaf_portcheck_t null_portcheck; 5511820Sjulianaf_checkhost_t null_checkhost; 5611820Sjulianaf_ishost_t null_ishost; 5711820Sjulianaf_canon_t null_canon; 5811820Sjulian 5911820Sjulianvoid ipxnet_hash(struct sockaddr_ipx *, struct afhash *); 6011820Sjulianint ipxnet_netmatch(struct sockaddr_ipx *, struct sockaddr_ipx *); 6111820Sjulianvoid ipxnet_output(int, int, struct sockaddr_ipx *, int); 6211820Sjulianint ipxnet_portmatch(struct sockaddr_ipx *); 6311820Sjulianint ipxnet_checkhost(struct sockaddr_ipx *); 6411820Sjulianint ipxnet_ishost(struct sockaddr_ipx *); 6511820Sjulianvoid ipxnet_canon(struct sockaddr_ipx *); 6611820Sjulian 6711820Sjulian#define NIL \ 6811820Sjulian { null_hash, null_netmatch, null_output, \ 6911820Sjulian null_portmatch, null_portcheck, null_checkhost, \ 7011820Sjulian null_ishost, null_canon } 7111820Sjulian#define IPXNET \ 7211820Sjulian { (af_hash_t *)ipxnet_hash, \ 7311820Sjulian (af_netmatch_t *)ipxnet_netmatch, \ 7411820Sjulian (af_output_t *)ipxnet_output, \ 7511820Sjulian (af_portmatch_t *)ipxnet_portmatch, \ 7611820Sjulian (af_portcheck_t *)ipxnet_portmatch, \ 7711820Sjulian (af_checkhost_t *)ipxnet_checkhost, \ 7811820Sjulian (af_ishost_t *)ipxnet_ishost, \ 7911820Sjulian (af_canon_t *)ipxnet_canon } 8011820Sjulian 8111820Sjulianstruct afswitch afswitch[AF_MAX] = 8211820Sjulian { NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, 8311820Sjulian NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, 8411820Sjulian NIL, NIL, NIL, IPXNET, NIL, NIL }; 8511820Sjulian 8611820Sjulianstruct sockaddr_ipx ipxnet_default = { sizeof(struct sockaddr_ipx), AF_IPX }; 8711820Sjulian 8811820Sjulianunion ipx_net ipx_anynet; 8911820Sjulianunion ipx_net ipx_zeronet; 9011820Sjulian 9111820Sjulianvoid 9211820Sjulianipxnet_hash(sipx, hp) 9311820Sjulian register struct sockaddr_ipx *sipx; 9411820Sjulian struct afhash *hp; 9511820Sjulian{ 9611820Sjulian register long hash = 0; 9711820Sjulian register u_short *s = sipx->sipx_addr.x_host.s_host; 9811820Sjulian union ipx_net_u net; 9911820Sjulian 10011820Sjulian net.net_e = sipx->sipx_addr.x_net; 10111820Sjulian hp->afh_nethash = net.long_e; 10211820Sjulian hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s; 10311820Sjulian hp->afh_hosthash = hash; 10411820Sjulian} 10511820Sjulian 10611820Sjulianint 10711820Sjulianipxnet_netmatch(sxn1, sxn2) 10811820Sjulian struct sockaddr_ipx *sxn1, *sxn2; 10911820Sjulian{ 11011820Sjulian return (ipx_neteq(sxn1->sipx_addr, sxn2->sipx_addr)); 11111820Sjulian} 11211820Sjulian 11311820Sjulian/* 11411820Sjulian * Verify the message is from the right port. 11511820Sjulian */ 11611820Sjulianint 11711820Sjulianipxnet_portmatch(sipx) 11811820Sjulian register struct sockaddr_ipx *sipx; 11911820Sjulian{ 12011820Sjulian 12111820Sjulian return (ntohs(sipx->sipx_addr.x_port) == IPXPORT_RIP ); 12211820Sjulian} 12311820Sjulian 12411820Sjulian 12511820Sjulian/* 12611820Sjulian * ipx output routine. 12711820Sjulian */ 12811820Sjulian#ifdef DEBUG 12911820Sjulianint do_output = 0; 13011820Sjulian#endif 13111820Sjulianvoid 13211820Sjulianipxnet_output(s, flags, sipx, size) 13311820Sjulian int s; 13411820Sjulian int flags; 13511820Sjulian struct sockaddr_ipx *sipx; 13611820Sjulian int size; 13711820Sjulian{ 13811820Sjulian struct sockaddr_ipx dst; 13911820Sjulian 14011820Sjulian dst = *sipx; 14111820Sjulian sipx = &dst; 14211820Sjulian if (sipx->sipx_addr.x_port == 0) 14311820Sjulian sipx->sipx_addr.x_port = htons(IPXPORT_RIP); 14411820Sjulian#ifdef DEBUG 14511820Sjulian if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST) 14611820Sjulian#endif 14711820Sjulian /* 14811820Sjulian * Kludge to allow us to get routes out to machines that 14911820Sjulian * don't know their addresses yet; send to that address on 15011820Sjulian * ALL connected nets 15111820Sjulian */ 15211820Sjulian if (ipx_neteqnn(sipx->sipx_addr.x_net, ipx_zeronet)) { 15311820Sjulian extern struct interface *ifnet; 15411820Sjulian register struct interface *ifp; 15511820Sjulian 15611820Sjulian for (ifp = ifnet; ifp; ifp = ifp->int_next) { 15711820Sjulian sipx->sipx_addr.x_net = 15811820Sjulian satoipx_addr(ifp->int_addr).x_net; 15911820Sjulian (void) sendto(s, msg, size, flags, 16011820Sjulian (struct sockaddr *)sipx, sizeof (*sipx)); 16111820Sjulian } 16211820Sjulian return; 16311820Sjulian } 16411820Sjulian 16511820Sjulian (void) sendto(s, msg, size, flags, 16611820Sjulian (struct sockaddr *)sipx, sizeof (*sipx)); 16711820Sjulian} 16811820Sjulian 16911820Sjulian/* 17011820Sjulian * Return 1 if we want this route. 17111820Sjulian * We use this to disallow route net G entries for one for multiple 17211820Sjulian * point to point links. 17311820Sjulian */ 17411820Sjulianint 17511820Sjulianipxnet_checkhost(sipx) 17611820Sjulian struct sockaddr_ipx *sipx; 17711820Sjulian{ 17811820Sjulian register struct interface *ifp = if_ifwithnet((struct sockaddr *)sipx); 17911820Sjulian /* 18011820Sjulian * We want this route if there is no more than one 18111820Sjulian * point to point interface with this network. 18211820Sjulian */ 18311820Sjulian if (ifp == 0 || (ifp->int_flags & IFF_POINTOPOINT)==0) return (1); 18411820Sjulian return (ifp->int_sq.n == ifp->int_sq.p); 18511820Sjulian} 18611820Sjulian 18711820Sjulian/* 18811820Sjulian * Return 1 if the address is 18911820Sjulian * for a host, 0 for a network. 19011820Sjulian */ 19111820Sjulianint 19211820Sjulianipxnet_ishost(sipx) 19311820Sjulianstruct sockaddr_ipx *sipx; 19411820Sjulian{ 19511820Sjulian register u_short *s = sipx->sipx_addr.x_host.s_host; 19611820Sjulian 19712620Sjulian if ((s[0]==0x0000) && (s[1]==0x0000) && (s[2]==0x0000)) 19812620Sjulian return (0); 19911820Sjulian if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff)) 20011820Sjulian return (0); 20112620Sjulian 20212620Sjulian return (1); 20311820Sjulian} 20411820Sjulian 20511820Sjulianvoid 20611820Sjulianipxnet_canon(sipx) 20711820Sjulian struct sockaddr_ipx *sipx; 20811820Sjulian{ 20911820Sjulian 21011820Sjulian sipx->sipx_addr.x_port = 0; 21111820Sjulian} 21211820Sjulian 21311820Sjulianvoid 21411820Sjuliannull_hash(addr, hp) 21511820Sjulian struct sockaddr *addr; 21611820Sjulian struct afhash *hp; 21711820Sjulian{ 21811820Sjulian 21911820Sjulian hp->afh_nethash = hp->afh_hosthash = 0; 22011820Sjulian} 22111820Sjulian 22211820Sjulianint 22311820Sjuliannull_netmatch(a1, a2) 22411820Sjulian struct sockaddr *a1, *a2; 22511820Sjulian{ 22611820Sjulian 22711820Sjulian return (0); 22811820Sjulian} 22911820Sjulian 23011820Sjulianvoid 23111820Sjuliannull_output(s, f, a1, n) 23211820Sjulian int s; 23311820Sjulian int f; 23411820Sjulian struct sockaddr *a1; 23511820Sjulian int n; 23611820Sjulian{ 23711820Sjulian 23811820Sjulian ; 23911820Sjulian} 24011820Sjulian 24111820Sjulianint 24211820Sjuliannull_portmatch(a1) 24311820Sjulian struct sockaddr *a1; 24411820Sjulian{ 24511820Sjulian 24611820Sjulian return (0); 24711820Sjulian} 24811820Sjulian 24911820Sjulianint 25011820Sjuliannull_portcheck(a1) 25111820Sjulian struct sockaddr *a1; 25211820Sjulian{ 25311820Sjulian 25411820Sjulian return (0); 25511820Sjulian} 25611820Sjulian 25711820Sjulianint 25811820Sjuliannull_ishost(a1) 25911820Sjulian struct sockaddr *a1; 26011820Sjulian{ 26111820Sjulian 26211820Sjulian return (0); 26311820Sjulian} 26411820Sjulian 26511820Sjulianint 26611820Sjuliannull_checkhost(a1) 26711820Sjulian struct sockaddr *a1; 26811820Sjulian{ 26911820Sjulian 27011820Sjulian return (0); 27111820Sjulian} 27211820Sjulian 27311820Sjulianvoid 27411820Sjuliannull_canon(a1) 27511820Sjulian struct sockaddr *a1; 27611820Sjulian{ 27711820Sjulian 27811820Sjulian ; 27911820Sjulian} 28011820Sjulian 281