|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1985 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * This file includes significant work done at Cornell University by ! 6: * Bill Nesheim. That work included by permission. ! 7: * ! 8: * Redistribution and use in source and binary forms are permitted ! 9: * provided that: (1) source distributions retain this entire copyright ! 10: * notice and comment, and (2) distributions including binaries display ! 11: * the following acknowledgement: ``This product includes software ! 12: * developed by the University of California, Berkeley and its contributors'' ! 13: * in the documentation or other materials provided with the distribution ! 14: * and in all advertising materials mentioning features or use of this ! 15: * software. Neither the name of the University nor the names of its ! 16: * contributors may be used to endorse or promote products derived ! 17: * from this software without specific prior written permission. ! 18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 19: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 20: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 21: */ ! 22: ! 23: #ifndef lint ! 24: static char sccsid[] = "@(#)af.c 5.10 (Berkeley) 6/1/90"; ! 25: #endif /* not lint */ ! 26: ! 27: #include "defs.h" ! 28: ! 29: /* ! 30: * Address family support routines ! 31: */ ! 32: int null_hash(), null_netmatch(), null_output(), ! 33: null_portmatch(), null_portcheck(), ! 34: null_checkhost(), null_ishost(), null_canon(); ! 35: int xnnet_hash(), xnnet_netmatch(), xnnet_output(), ! 36: xnnet_portmatch(), ! 37: xnnet_checkhost(), xnnet_ishost(), xnnet_canon(); ! 38: #define NIL \ ! 39: { null_hash, null_netmatch, null_output, \ ! 40: null_portmatch, null_portcheck, null_checkhost, \ ! 41: null_ishost, null_canon } ! 42: #define XNSNET \ ! 43: { xnnet_hash, xnnet_netmatch, xnnet_output, \ ! 44: xnnet_portmatch, xnnet_portmatch, xnnet_checkhost, \ ! 45: xnnet_ishost, xnnet_canon } ! 46: ! 47: struct afswitch afswitch[AF_MAX] = ! 48: { NIL, NIL, NIL, NIL, NIL, NIL, XNSNET, NIL, NIL, NIL, NIL }; ! 49: ! 50: struct sockaddr_ns xnnet_default = { sizeof(struct sockaddr_ns), AF_NS }; ! 51: ! 52: union ns_net ns_anynet; ! 53: union ns_net ns_zeronet; ! 54: ! 55: xnnet_hash(sns, hp) ! 56: register struct sockaddr_ns *sns; ! 57: struct afhash *hp; ! 58: { ! 59: register long hash = 0; ! 60: register u_short *s = sns->sns_addr.x_host.s_host; ! 61: union ns_net_u net; ! 62: ! 63: net.net_e = sns->sns_addr.x_net; ! 64: hp->afh_nethash = net.long_e; ! 65: hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s; ! 66: hp->afh_hosthash = hash; ! 67: } ! 68: ! 69: xnnet_netmatch(sxn1, sxn2) ! 70: struct sockaddr_ns *sxn1, *sxn2; ! 71: { ! 72: return (ns_neteq(sxn1->sns_addr, sxn2->sns_addr)); ! 73: } ! 74: ! 75: /* ! 76: * Verify the message is from the right port. ! 77: */ ! 78: xnnet_portmatch(sns) ! 79: register struct sockaddr_ns *sns; ! 80: { ! 81: ! 82: return (ntohs(sns->sns_addr.x_port) == IDPPORT_RIF ); ! 83: } ! 84: ! 85: ! 86: /* ! 87: * xns output routine. ! 88: */ ! 89: #ifdef DEBUG ! 90: int do_output = 0; ! 91: #endif ! 92: xnnet_output(flags, sns, size) ! 93: int flags; ! 94: struct sockaddr_ns *sns; ! 95: int size; ! 96: { ! 97: struct sockaddr_ns dst; ! 98: ! 99: dst = *sns; ! 100: sns = &dst; ! 101: if (sns->sns_addr.x_port == 0) ! 102: sns->sns_addr.x_port = htons(IDPPORT_RIF); ! 103: #ifdef DEBUG ! 104: if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST) ! 105: #endif ! 106: /* ! 107: * Kludge to allow us to get routes out to machines that ! 108: * don't know their addresses yet; send to that address on ! 109: * ALL connected nets ! 110: */ ! 111: if (ns_neteqnn(sns->sns_addr.x_net, ns_zeronet)) { ! 112: extern struct interface *ifnet; ! 113: register struct interface *ifp; ! 114: ! 115: for (ifp = ifnet; ifp; ifp = ifp->int_next) { ! 116: sns->sns_addr.x_net = ! 117: satons_addr(ifp->int_addr).x_net; ! 118: (void) sendto(s, msg, size, flags, sns, sizeof (*sns)); ! 119: } ! 120: return; ! 121: } ! 122: ! 123: (void) sendto(s, msg, size, flags, sns, sizeof (*sns)); ! 124: } ! 125: ! 126: /* ! 127: * Return 1 if we want this route. ! 128: * We use this to disallow route net G entries for one for multiple ! 129: * point to point links. ! 130: */ ! 131: xnnet_checkhost(sns) ! 132: struct sockaddr_ns *sns; ! 133: { ! 134: register struct interface *ifp = if_ifwithnet(sns); ! 135: /* ! 136: * We want this route if there is no more than one ! 137: * point to point interface with this network. ! 138: */ ! 139: if (ifp == 0 || (ifp->int_flags & IFF_POINTOPOINT)==0) return (1); ! 140: return (ifp->int_sq.n == ifp->int_sq.p); ! 141: } ! 142: ! 143: /* ! 144: * Return 1 if the address is ! 145: * for a host, 0 for a network. ! 146: */ ! 147: xnnet_ishost(sns) ! 148: struct sockaddr_ns *sns; ! 149: { ! 150: register u_short *s = sns->sns_addr.x_host.s_host; ! 151: ! 152: if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff)) ! 153: return (0); ! 154: else ! 155: return (1); ! 156: } ! 157: ! 158: xnnet_canon(sns) ! 159: struct sockaddr_ns *sns; ! 160: { ! 161: ! 162: sns->sns_addr.x_port = 0; ! 163: } ! 164: ! 165: /*ARGSUSED*/ ! 166: null_hash(addr, hp) ! 167: struct sockaddr *addr; ! 168: struct afhash *hp; ! 169: { ! 170: ! 171: hp->afh_nethash = hp->afh_hosthash = 0; ! 172: } ! 173: ! 174: /*ARGSUSED*/ ! 175: null_netmatch(a1, a2) ! 176: struct sockaddr *a1, *a2; ! 177: { ! 178: ! 179: return (0); ! 180: } ! 181: ! 182: /*ARGSUSED*/ ! 183: null_output(s, f, a1, n) ! 184: int s, f; ! 185: struct sockaddr *a1; ! 186: int n; ! 187: { ! 188: ! 189: ; ! 190: } ! 191: ! 192: /*ARGSUSED*/ ! 193: null_portmatch(a1) ! 194: struct sockaddr *a1; ! 195: { ! 196: ! 197: return (0); ! 198: } ! 199: ! 200: /*ARGSUSED*/ ! 201: null_portcheck(a1) ! 202: struct sockaddr *a1; ! 203: { ! 204: ! 205: return (0); ! 206: } ! 207: ! 208: /*ARGSUSED*/ ! 209: null_ishost(a1) ! 210: struct sockaddr *a1; ! 211: { ! 212: ! 213: return (0); ! 214: } ! 215: ! 216: /*ARGSUSED*/ ! 217: null_checkhost(a1) ! 218: struct sockaddr *a1; ! 219: { ! 220: ! 221: return (0); ! 222: } ! 223: ! 224: /*ARGSUSED*/ ! 225: null_canon(a1) ! 226: struct sockaddr *a1; ! 227: { ! 228: ! 229: ; ! 230: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.