Annotation of 43BSDReno/sbin/XNSrouted/timer.c, revision 1.1.1.1

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[] = "@(#)timer.c    5.6 (Berkeley) 6/1/90";
                     25: #endif /* not lint */
                     26: 
                     27: /*
                     28:  * Routing Table Management Daemon
                     29:  */
                     30: #include "defs.h"
                     31: 
                     32: int    timeval = -TIMER_RATE;
                     33: 
                     34: /*
                     35:  * Timer routine.  Performs routing information supply
                     36:  * duties and manages timers on routing table entries.
                     37:  */
                     38: timer()
                     39: {
                     40:        register struct rthash *rh;
                     41:        register struct rt_entry *rt;
                     42:        struct rthash *base = hosthash;
                     43:        int doinghost = 1, timetobroadcast;
                     44: 
                     45:        timeval += TIMER_RATE;
                     46:        if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0)
                     47:                ifinit();
                     48:        timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0;
                     49: again:
                     50:        for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
                     51:                rt = rh->rt_forw;
                     52:                for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
                     53:                        /*
                     54:                         * We don't advance time on a routing entry for
                     55:                         * a passive gateway or that for our only interface. 
                     56:                         * The latter is excused because we don't act as
                     57:                         * a routing information supplier and hence would
                     58:                         * time it out.  This is fair as if it's down
                     59:                         * we're cut off from the world anyway and it's
                     60:                         * not likely we'll grow any new hardware in
                     61:                         * the mean time.
                     62:                         */
                     63:                        if (!(rt->rt_state & RTS_PASSIVE) &&
                     64:                            (supplier || !(rt->rt_state & RTS_INTERFACE)))
                     65:                                rt->rt_timer += TIMER_RATE;
                     66:                        if (rt->rt_timer >= EXPIRE_TIME)
                     67:                                rt->rt_metric = HOPCNT_INFINITY;
                     68:                        if (rt->rt_timer >= GARBAGE_TIME) {
                     69:                                rt = rt->rt_back;
                     70:                                /* Perhaps we should send a REQUEST for this route? */
                     71:                                rtdelete(rt->rt_forw);
                     72:                                continue;
                     73:                        }
                     74:                        if (rt->rt_state & RTS_CHANGED) {
                     75:                                rt->rt_state &= ~RTS_CHANGED;
                     76:                                /* don't send extraneous packets */
                     77:                                if (!supplier || timetobroadcast)
                     78:                                        continue;
                     79:                                msg->rip_cmd = htons(RIPCMD_RESPONSE);
                     80:                                msg->rip_nets[0].rip_dst =
                     81:                                        (satons_addr(rt->rt_dst)).x_net;
                     82:                                msg->rip_nets[0].rip_metric =
                     83:                                        htons(min(rt->rt_metric+1, HOPCNT_INFINITY));
                     84:                                toall(sendmsg);
                     85:                        }
                     86:                }
                     87:        }
                     88:        if (doinghost) {
                     89:                doinghost = 0;
                     90:                base = nethash;
                     91:                goto again;
                     92:        }
                     93:        if (timetobroadcast)
                     94:                toall(supply);
                     95:        alarm(TIMER_RATE);
                     96: }
                     97: 
                     98: /*
                     99:  * On hangup, let everyone know we're going away.
                    100:  */
                    101: hup()
                    102: {
                    103:        register struct rthash *rh;
                    104:        register struct rt_entry *rt;
                    105:        struct rthash *base = hosthash;
                    106:        int doinghost = 1;
                    107: 
                    108:        if (supplier) {
                    109: again:
                    110:                for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) {
                    111:                        rt = rh->rt_forw;
                    112:                        for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw)
                    113:                                rt->rt_metric = HOPCNT_INFINITY;
                    114:                }
                    115:                if (doinghost) {
                    116:                        doinghost = 0;
                    117:                        base = nethash;
                    118:                        goto again;
                    119:                }
                    120:                toall(supply);
                    121:        }
                    122:        exit(1);
                    123: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.