1: /*
   2:  * Copyright (c) 1983 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: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)timer.c	5.3 (Berkeley) 11/20/85";
   9: #endif not lint
  10: 
  11: /*
  12:  * Routing Table Management Daemon
  13:  */
  14: #include "defs.h"
  15: 
  16: int timeval = -TIMER_RATE;
  17: 
  18: /*
  19:  * Timer routine.  Performs routing information supply
  20:  * duties and manages timers on routing table entries.
  21:  */
  22: timer()
  23: {
  24:     register struct rthash *rh;
  25:     register struct rt_entry *rt;
  26:     struct rthash *base = hosthash;
  27:     int doinghost = 1, timetobroadcast;
  28:     extern int externalinterfaces;
  29: 
  30:     timeval += TIMER_RATE;
  31:     if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0)
  32:         ifinit();
  33:     timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;
  34: again:
  35:     for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
  36:         rt = rh->rt_forw;
  37:         for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
  38:             /*
  39: 			 * We don't advance time on a routing entry for
  40: 			 * a passive gateway, or any interface if we're
  41: 			 * not acting as supplier.
  42: 			 */
  43:             if (!(rt->rt_state & RTS_PASSIVE) &&
  44:                 (supplier || !(rt->rt_state & RTS_INTERFACE)))
  45:                 rt->rt_timer += TIMER_RATE;
  46:             if (rt->rt_timer >= EXPIRE_TIME)
  47:                 rt->rt_metric = HOPCNT_INFINITY;
  48:             if (rt->rt_timer >= GARBAGE_TIME) {
  49:                 rt = rt->rt_back;
  50:                 rtdelete(rt->rt_forw);
  51:                 continue;
  52:             }
  53:             if (rt->rt_state & RTS_CHANGED) {
  54:                 rt->rt_state &= ~RTS_CHANGED;
  55:                 /* don't send extraneous packets */
  56:                 if (!supplier || timetobroadcast)
  57:                     continue;
  58:                 msg->rip_cmd = RIPCMD_RESPONSE;
  59:                 msg->rip_vers = RIPVERSION;
  60:                 msg->rip_nets[0].rip_dst = rt->rt_dst;
  61:                 msg->rip_nets[0].rip_dst.sa_family =
  62:                    htons(msg->rip_nets[0].rip_dst.sa_family);
  63:                 msg->rip_nets[0].rip_metric =
  64:                    htonl(min(rt->rt_metric+1, HOPCNT_INFINITY));
  65:                 toall(sendmsg);
  66:             }
  67:         }
  68:     }
  69:     if (doinghost) {
  70:         doinghost = 0;
  71:         base = nethash;
  72:         goto again;
  73:     }
  74:     if (timetobroadcast)
  75:         toall(supply);
  76:     alarm(TIMER_RATE);
  77: }
  78: 
  79: /*
  80:  * On hangup, let everyone know we're going away.
  81:  */
  82: hup()
  83: {
  84:     register struct rthash *rh;
  85:     register struct rt_entry *rt;
  86:     struct rthash *base = hosthash;
  87:     int doinghost = 1;
  88: 
  89:     if (supplier) {
  90: again:
  91:         for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
  92:             rt = rh->rt_forw;
  93:             for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
  94:                 rt->rt_metric = HOPCNT_INFINITY;
  95:         }
  96:         if (doinghost) {
  97:             doinghost = 0;
  98:             base = nethash;
  99:             goto again;
 100:         }
 101:         toall(supply);
 102:     }
 103:     exit(1);
 104: }

Defined functions

hup defined in line 82; used 3 times
timer defined in line 22; used 2 times

Defined variables

sccsid defined in line 8; never used
timeval defined in line 16; used 3 times
Last modified: 1985-11-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1098
Valid CSS Valid XHTML 1.0 Strict