home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-B.05 / NETKIT-B / NetKit-B-0.05 / routed / timer.c,v < prev    next >
Encoding:
Text File  |  1994-05-23  |  4.2 KB  |  154 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks
  5.     rzsfl:1.1; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    94.05.23.09.08.13;    author rzsfl;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @Original
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  * Copyright (c) 1983, 1988 Regents of the University of California.
  27.  * All rights reserved.
  28.  *
  29.  * Redistribution and use in source and binary forms, with or without
  30.  * modification, are permitted provided that the following conditions
  31.  * are met:
  32.  * 1. Redistributions of source code must retain the above copyright
  33.  *    notice, this list of conditions and the following disclaimer.
  34.  * 2. Redistributions in binary form must reproduce the above copyright
  35.  *    notice, this list of conditions and the following disclaimer in the
  36.  *    documentation and/or other materials provided with the distribution.
  37.  * 3. All advertising materials mentioning features or use of this software
  38.  *    must display the following acknowledgement:
  39.  *    This product includes software developed by the University of
  40.  *    California, Berkeley and its contributors.
  41.  * 4. Neither the name of the University nor the names of its contributors
  42.  *    may be used to endorse or promote products derived from this software
  43.  *    without specific prior written permission.
  44.  *
  45.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  46.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  47.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  48.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  49.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  50.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  51.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  52.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  54.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  55.  * SUCH DAMAGE.
  56.  */
  57.  
  58. #ifndef lint
  59. /*static char sccsid[] = "from: @@(#)timer.c    5.10 (Berkeley) 2/28/91";*/
  60. static char rcsid[] = "$Id: timer.c,v 1.4 1993/08/01 18:24:19 mycroft Exp $";
  61. #endif /* not lint */
  62.  
  63. /*
  64.  * Routing Table Management Daemon
  65.  */
  66. #include "defs.h"
  67.  
  68. int    faketime;
  69.  
  70. /*
  71.  * Timer routine.  Performs routing information supply
  72.  * duties and manages timers on routing table entries.
  73.  * Management of the RTS_CHANGED bit assumes that we broadcast
  74.  * each time called.
  75.  */
  76. void
  77. timer()
  78. {
  79.     register struct rthash *rh;
  80.     register struct rt_entry *rt;
  81.     struct rthash *base = hosthash;
  82.     int doinghost = 1, timetobroadcast;
  83.     extern int externalinterfaces;
  84.  
  85.     (void) gettimeofday(&now, (struct timezone *)NULL);
  86.     faketime += TIMER_RATE;
  87.     if (lookforinterfaces && (faketime % CHECK_INTERVAL) == 0)
  88.         ifinit();
  89.     timetobroadcast = supplier && (faketime % SUPPLY_INTERVAL) == 0;
  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.             /*
  95.              * We don't advance time on a routing entry for
  96.              * a passive gateway, or any interface if we're
  97.              * not acting as supplier.
  98.              */
  99.             if (!(rt->rt_state & RTS_PASSIVE) &&
  100.                 (supplier || !(rt->rt_state & RTS_INTERFACE)))
  101.                 rt->rt_timer += TIMER_RATE;
  102.             if (rt->rt_timer >= GARBAGE_TIME) {
  103.                 rt = rt->rt_back;
  104.                 rtdelete(rt->rt_forw);
  105.                 continue;
  106.             }
  107.             if (rt->rt_timer >= EXPIRE_TIME &&
  108.                 rt->rt_metric < HOPCNT_INFINITY)
  109.                 rtchange(rt, &rt->rt_router, HOPCNT_INFINITY);
  110.             rt->rt_state &= ~RTS_CHANGED;
  111.         }
  112.     }
  113.     if (doinghost) {
  114.         doinghost = 0;
  115.         base = nethash;
  116.         goto again;
  117.     }
  118.     if (timetobroadcast) {
  119.         toall(supply, 0, (struct interface *)NULL);
  120.         lastbcast = now;
  121.         lastfullupdate = now;
  122.         needupdate = 0;        /* cancel any pending dynamic update */
  123.         nextbcast.tv_sec = 0;
  124.     }
  125. }
  126.  
  127. /*
  128.  * On hangup, let everyone know we're going away.
  129.  */
  130. hup()
  131. {
  132.     register struct rthash *rh;
  133.     register struct rt_entry *rt;
  134.     struct rthash *base = hosthash;
  135.     int doinghost = 1;
  136.  
  137.     if (supplier) {
  138. again:
  139.         for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
  140.             rt = rh->rt_forw;
  141.             for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
  142.                 rt->rt_metric = HOPCNT_INFINITY;
  143.         }
  144.         if (doinghost) {
  145.             doinghost = 0;
  146.             base = nethash;
  147.             goto again;
  148.         }
  149.         toall(supply, 0, (struct interface *)NULL);
  150.     }
  151.     exit(1);
  152. }
  153. @
  154.