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.6 (Berkeley) 6/5/86";
  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: union ns_net ns_anynet;
  41: union ns_net ns_zeronet;
  42: 
  43: xnnet_hash(sns, hp)
  44:     register struct sockaddr_ns *sns;
  45:     struct afhash *hp;
  46: {
  47:     register long hash = 0;
  48:     register u_short *s = sns->sns_addr.x_host.s_host;
  49:     union ns_net_u net;
  50: 
  51:     net.net_e = sns->sns_addr.x_net;
  52:     hp->afh_nethash = net.long_e;
  53:     hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s;
  54:     hp->afh_hosthash = hash;
  55: }
  56: 
  57: xnnet_netmatch(sxn1, sxn2)
  58:     struct sockaddr_ns *sxn1, *sxn2;
  59: {
  60:     return (ns_neteq(sxn1->sns_addr, sxn2->sns_addr));
  61: }
  62: 
  63: /*
  64:  * Verify the message is from the right port.
  65:  */
  66: xnnet_portmatch(sns)
  67:     register struct sockaddr_ns *sns;
  68: {
  69: 
  70:     return (ntohs(sns->sns_addr.x_port) == IDPPORT_RIF );
  71: }
  72: 
  73: 
  74: /*
  75:  * xns output routine.
  76:  */
  77: #ifdef DEBUG
  78: int do_output = 0;
  79: #endif
  80: xnnet_output(flags, sns, size)
  81:     int flags;
  82:     struct sockaddr_ns *sns;
  83:     int size;
  84: {
  85:     struct sockaddr_ns dst;
  86: 
  87:     dst = *sns;
  88:     sns = &dst;
  89:     if (sns->sns_addr.x_port == 0)
  90:         sns->sns_addr.x_port = htons(IDPPORT_RIF);
  91: #ifdef DEBUG
  92:     if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST)
  93: #endif
  94:     /*
  95: 	 * Kludge to allow us to get routes out to machines that
  96: 	 * don't know their addresses yet; send to that address on
  97: 	 * ALL connected nets
  98: 	 */
  99:      if (ns_neteqnn(sns->sns_addr.x_net, ns_zeronet)) {
 100:         extern  struct interface *ifnet;
 101:         register struct interface *ifp;
 102: 
 103:         for (ifp = ifnet; ifp; ifp = ifp->int_next) {
 104:             sns->sns_addr.x_net =
 105:                 satons_addr(ifp->int_addr).x_net;
 106:             (void) sendto(s, msg, size, flags, sns, sizeof (*sns));
 107:         }
 108:         return;
 109:     }
 110: 
 111:     (void) sendto(s, msg, size, flags, sns, sizeof (*sns));
 112: }
 113: 
 114: /*
 115:  * Return 1 if we want this route.
 116:  * We use this to disallow route net G entries for one for multiple
 117:  * point to point links.
 118:  */
 119: xnnet_checkhost(sns)
 120:     struct sockaddr_ns *sns;
 121: {
 122:     register struct interface *ifp = if_ifwithnet(sns);
 123:     /*
 124: 	 * We want this route if there is no more than one
 125: 	 * point to point interface with this network.
 126: 	 */
 127:     if (ifp == 0 || (ifp->int_flags & IFF_POINTOPOINT)==0) return (1);
 128:     return (ifp->int_sq.n == ifp->int_sq.p);
 129: }
 130: 
 131: /*
 132:  * Return 1 if the address is
 133:  * for a host, 0 for a network.
 134:  */
 135: xnnet_ishost(sns)
 136: struct sockaddr_ns *sns;
 137: {
 138:     register u_short *s = sns->sns_addr.x_host.s_host;
 139: 
 140:     if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff))
 141:         return (0);
 142:     else
 143:         return (1);
 144: }
 145: 
 146: xnnet_canon(sns)
 147:     struct sockaddr_ns *sns;
 148: {
 149: 
 150:     sns->sns_addr.x_port = 0;
 151: }
 152: 
 153: /*ARGSUSED*/
 154: null_hash(addr, hp)
 155:     struct sockaddr *addr;
 156:     struct afhash *hp;
 157: {
 158: 
 159:     hp->afh_nethash = hp->afh_hosthash = 0;
 160: }
 161: 
 162: /*ARGSUSED*/
 163: null_netmatch(a1, a2)
 164:     struct sockaddr *a1, *a2;
 165: {
 166: 
 167:     return (0);
 168: }
 169: 
 170: /*ARGSUSED*/
 171: null_output(s, f, a1, n)
 172:     int s, f;
 173:     struct sockaddr *a1;
 174:     int n;
 175: {
 176: 
 177:     ;
 178: }
 179: 
 180: /*ARGSUSED*/
 181: null_portmatch(a1)
 182:     struct sockaddr *a1;
 183: {
 184: 
 185:     return (0);
 186: }
 187: 
 188: /*ARGSUSED*/
 189: null_portcheck(a1)
 190:     struct sockaddr *a1;
 191: {
 192: 
 193:     return (0);
 194: }
 195: 
 196: /*ARGSUSED*/
 197: null_ishost(a1)
 198:     struct sockaddr *a1;
 199: {
 200: 
 201:     return (0);
 202: }
 203: 
 204: /*ARGSUSED*/
 205: null_checkhost(a1)
 206:     struct sockaddr *a1;
 207: {
 208: 
 209:     return (0);
 210: }
 211: 
 212: /*ARGSUSED*/
 213: null_canon(a1)
 214:     struct sockaddr *a1;
 215: {
 216: 
 217:     ;
 218: }

Defined functions

null_canon defined in line 213; used 2 times
null_checkhost defined in line 205; used 2 times
null_hash defined in line 154; used 2 times
null_ishost defined in line 197; used 2 times
null_netmatch defined in line 163; used 2 times
null_output defined in line 171; used 2 times
null_portcheck defined in line 189; used 2 times
null_portmatch defined in line 181; used 2 times
xnnet_canon defined in line 146; used 2 times
xnnet_checkhost defined in line 119; used 2 times
xnnet_hash defined in line 43; used 2 times
xnnet_ishost defined in line 135; used 2 times
xnnet_netmatch defined in line 57; used 2 times
xnnet_output defined in line 80; used 2 times
xnnet_portmatch defined in line 66; used 3 times

Defined variables

afswitch defined in line 35; never used
do_output defined in line 78; used 1 times
  • in line 92
ns_anynet defined in line 40; never used
ns_zeronet defined in line 41; used 1 times
  • in line 99
sccsid defined in line 11; never used
xnnet_default defined in line 38; never used

Defined macros

NIL defined in line 26; used 10 times
  • in line 36(10)
XNSNET defined in line 30; used 1 times
  • in line 36
Last modified: 1986-06-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1431
Valid CSS Valid XHTML 1.0 Strict