1 /* 2 * Copyright (c) 1985 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * This file include significant work done at Cornell University 7 * by Bill Nesheim. That work included by permission. 8 */ 9 10 #ifndef lint 11 static char sccsid[] = "@(#)af.c 5.4 (Berkeley) 09/17/85"; 12 #endif not lint 13 14 15 #include "defs.h" 16 17 /* 18 * Address family support routines 19 */ 20 int null_hash(), null_netmatch(), null_output(), 21 null_portmatch(), null_portcheck(), 22 null_checkhost(), null_ishost(), null_canon(); 23 int xnnet_hash(), xnnet_netmatch(), xnnet_output(), 24 xnnet_portmatch(); 25 xnnet_checkhost(), xnnet_ishost(), xnnet_canon(); 26 #define NIL \ 27 { null_hash, null_netmatch, null_output, \ 28 null_portmatch, null_portcheck, null_checkhost, \ 29 null_ishost, null_canon } 30 #define XNSNET \ 31 { xnnet_hash, xnnet_netmatch, xnnet_output, \ 32 xnnet_portmatch, xnnet_portmatch, xnnet_checkhost, \ 33 xnnet_ishost, xnnet_canon } 34 35 struct afswitch afswitch[AF_MAX] = 36 { NIL, NIL, NIL, NIL, NIL, NIL, XNSNET, NIL, NIL, NIL, NIL }; 37 38 struct sockaddr_ns xnnet_default = { AF_NS }; 39 40 xnnet_hash(sns, hp) 41 register struct sockaddr_ns *sns; 42 struct afhash *hp; 43 { 44 register long hash = 0; 45 register u_short *s = sns->sns_addr.x_host.s_host; 46 hp->afh_nethash = xnnet(sns->sns_addr.x_net); 47 hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s; 48 hp->afh_hosthash = hash; 49 } 50 51 xnnet_netmatch(sxn1, sxn2) 52 struct sockaddr_ns *sxn1, *sxn2; 53 { 54 55 return (xnnet(sxn1->sns_addr.x_net) == xnnet(sxn2->sns_addr.x_net)); 56 } 57 58 /* 59 * Verify the message is from the right port. 60 */ 61 xnnet_portmatch(sns) 62 register struct sockaddr_ns *sns; 63 { 64 65 return (ntohs(sns->sns_addr.x_port) == IDPPORT_RIF ); 66 } 67 68 69 /* 70 * xns output routine. 71 */ 72 #ifdef DEBUG 73 int do_output = 0; 74 #endif 75 xnnet_output(flags, sns, size) 76 int flags; 77 struct sockaddr_ns *sns; 78 int size; 79 { 80 struct sockaddr_ns dst; 81 82 dst = *sns; 83 sns = &dst; 84 if (sns->sns_addr.x_port == 0) 85 sns->sns_addr.x_port = htons(IDPPORT_RIF); 86 #ifdef DEBUG 87 if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST) 88 #endif 89 /* 90 * Kludge to allow us to get routes out to machines that 91 * don't know their addresses yet; send to that address on 92 * ALL connected nets 93 */ 94 if (ns_netof(sns->sns_addr) == 0L) { 95 extern struct interface *ifnet; 96 register struct interface *ifp; 97 98 for (ifp = ifnet; ifp; ifp = ifp->int_next) { 99 ns_netof(sns->sns_addr) = 100 ns_netof(((struct sockaddr_ns *)&ifp->int_addr)->sns_addr); 101 if (sendto(s, msg, size, flags, sns, sizeof (*sns)) < 0) 102 syslog(LOG_ERR,"sendto: %m"); 103 } 104 return; 105 } 106 107 if (sendto(s, msg, size, flags, sns, sizeof (*sns)) < 0) 108 syslog(LOG_ERR,"sendto: %m"); 109 } 110 111 /* 112 * Return 1 if we want this route. 113 * We use this to disallow route net G entries for one for multiple 114 * point to point links. 115 */ 116 xnnet_checkhost(sns) 117 struct sockaddr_ns *sns; 118 { 119 register struct interface *ifp = if_ifwithnet(sns); 120 /* 121 * We want this route if there is no more than one 122 * point to point interface with this network. 123 */ 124 if (ifp == 0 || (ifp->int_flags & IFF_POINTOPOINT)==0) return (1); 125 return (ifp->int_sq.n == ifp->int_sq.p); 126 } 127 128 /* 129 * Return 1 if the address is 130 * for a host, 0 for a network. 131 */ 132 xnnet_ishost(sns) 133 struct sockaddr_ns *sns; 134 { 135 register u_short *s = sns->sns_addr.x_host.s_host; 136 137 if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff)) 138 return (0); 139 else 140 return (1); 141 } 142 143 xnnet_canon(sns) 144 struct sockaddr_ns *sns; 145 { 146 147 sns->sns_addr.x_port = 0; 148 } 149 150 /*ARGSUSED*/ 151 null_hash(addr, hp) 152 struct sockaddr *addr; 153 struct afhash *hp; 154 { 155 156 hp->afh_nethash = hp->afh_hosthash = 0; 157 } 158 159 /*ARGSUSED*/ 160 null_netmatch(a1, a2) 161 struct sockaddr *a1, *a2; 162 { 163 164 return (0); 165 } 166 167 /*ARGSUSED*/ 168 null_output(s, f, a1, n) 169 int s, f; 170 struct sockaddr *a1; 171 int n; 172 { 173 174 ; 175 } 176 177 /*ARGSUSED*/ 178 null_portmatch(a1) 179 struct sockaddr *a1; 180 { 181 182 return (0); 183 } 184 185 /*ARGSUSED*/ 186 null_portcheck(a1) 187 struct sockaddr *a1; 188 { 189 190 return (0); 191 } 192 193 /*ARGSUSED*/ 194 null_ishost(a1) 195 struct sockaddr *a1; 196 { 197 198 return (0); 199 } 200 201 /*ARGSUSED*/ 202 null_checkhost(a1) 203 struct sockaddr *a1; 204 { 205 206 return (0); 207 } 208 209 /*ARGSUSED*/ 210 null_canon(a1) 211 struct sockaddr *a1; 212 { 213 214 ; 215 } 216