af.c revision 11820
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 *
3811820Sjulian * $Id: af.c,v 1.4 1995/10/11 18:57:05 jhay 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
19711820Sjulian	if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff))
19811820Sjulian		return (0);
19911820Sjulian	else
20011820Sjulian		return (1);
20111820Sjulian}
20211820Sjulian
20311820Sjulianvoid
20411820Sjulianipxnet_canon(sipx)
20511820Sjulian	struct sockaddr_ipx *sipx;
20611820Sjulian{
20711820Sjulian
20811820Sjulian	sipx->sipx_addr.x_port = 0;
20911820Sjulian}
21011820Sjulian
21111820Sjulianvoid
21211820Sjuliannull_hash(addr, hp)
21311820Sjulian	struct sockaddr *addr;
21411820Sjulian	struct afhash *hp;
21511820Sjulian{
21611820Sjulian
21711820Sjulian	hp->afh_nethash = hp->afh_hosthash = 0;
21811820Sjulian}
21911820Sjulian
22011820Sjulianint
22111820Sjuliannull_netmatch(a1, a2)
22211820Sjulian	struct sockaddr *a1, *a2;
22311820Sjulian{
22411820Sjulian
22511820Sjulian	return (0);
22611820Sjulian}
22711820Sjulian
22811820Sjulianvoid
22911820Sjuliannull_output(s, f, a1, n)
23011820Sjulian	int s;
23111820Sjulian	int f;
23211820Sjulian	struct sockaddr *a1;
23311820Sjulian	int n;
23411820Sjulian{
23511820Sjulian
23611820Sjulian	;
23711820Sjulian}
23811820Sjulian
23911820Sjulianint
24011820Sjuliannull_portmatch(a1)
24111820Sjulian	struct sockaddr *a1;
24211820Sjulian{
24311820Sjulian
24411820Sjulian	return (0);
24511820Sjulian}
24611820Sjulian
24711820Sjulianint
24811820Sjuliannull_portcheck(a1)
24911820Sjulian	struct sockaddr *a1;
25011820Sjulian{
25111820Sjulian
25211820Sjulian	return (0);
25311820Sjulian}
25411820Sjulian
25511820Sjulianint
25611820Sjuliannull_ishost(a1)
25711820Sjulian	struct sockaddr *a1;
25811820Sjulian{
25911820Sjulian
26011820Sjulian	return (0);
26111820Sjulian}
26211820Sjulian
26311820Sjulianint
26411820Sjuliannull_checkhost(a1)
26511820Sjulian	struct sockaddr *a1;
26611820Sjulian{
26711820Sjulian
26811820Sjulian	return (0);
26911820Sjulian}
27011820Sjulian
27111820Sjulianvoid
27211820Sjuliannull_canon(a1)
27311820Sjulian	struct sockaddr *a1;
27411820Sjulian{
27511820Sjulian
27611820Sjulian	;
27711820Sjulian}
27811820Sjulian
279