Annotation of 43BSD/etc/XNSrouted/output.c, revision 1.1

1.1     ! root        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:  * Includes material written at Cornell University by Bill Nesheim,
        !             7:  * by permission of the author.
        !             8:  */
        !             9: 
        !            10: #ifndef lint
        !            11: static char sccsid[] = "@(#)output.c   5.5 (Berkeley) 2/14/86";
        !            12: #endif
        !            13: 
        !            14: /*
        !            15:  * Routing Table Management Daemon
        !            16:  */
        !            17: #include "defs.h"
        !            18: 
        !            19: /*
        !            20:  * Apply the function "f" to all non-passive
        !            21:  * interfaces.  If the interface supports the
        !            22:  * use of broadcasting use it, otherwise address
        !            23:  * the output to the known router.
        !            24:  */
        !            25: toall(f)
        !            26:        int (*f)();
        !            27: {
        !            28:        register struct interface *ifp;
        !            29:        register struct sockaddr *dst;
        !            30:        register int flags;
        !            31:        extern struct interface *ifnet;
        !            32: 
        !            33:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
        !            34:                if (ifp->int_flags & IFF_PASSIVE)
        !            35:                        continue;
        !            36:                dst = ifp->int_flags & IFF_BROADCAST ? &ifp->int_broadaddr :
        !            37:                      ifp->int_flags & IFF_POINTOPOINT ? &ifp->int_dstaddr :
        !            38:                      &ifp->int_addr;
        !            39:                flags = ifp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0;
        !            40:                (*f)(dst, flags, ifp);
        !            41:        }
        !            42: }
        !            43: 
        !            44: /*
        !            45:  * Output a preformed packet.
        !            46:  */
        !            47: /*ARGSUSED*/
        !            48: sendmsg(dst, flags, ifp)
        !            49:        struct sockaddr *dst;
        !            50:        int flags;
        !            51:        struct interface *ifp;
        !            52: {
        !            53: 
        !            54:        (*afswitch[dst->sa_family].af_output)
        !            55:                (flags, dst, sizeof (struct rip));
        !            56:        TRACE_OUTPUT(ifp, dst, sizeof (struct rip));
        !            57: }
        !            58: 
        !            59: /*
        !            60:  * Supply dst with the contents of the routing tables.
        !            61:  * If this won't fit in one packet, chop it up into several.
        !            62:  */
        !            63: supply(dst, flags, ifp)
        !            64:        struct sockaddr *dst;
        !            65:        int flags;
        !            66:        struct interface *ifp;
        !            67: {
        !            68:        register struct rt_entry *rt;
        !            69:        register struct rthash *rh;
        !            70:        register struct netinfo *nn;
        !            71:        register struct netinfo *n = msg->rip_nets;
        !            72:        struct rthash *base = hosthash;
        !            73:        struct sockaddr_ns *sns =  (struct sockaddr_ns *) dst;
        !            74:        int (*output)() = afswitch[dst->sa_family].af_output;
        !            75:        int doinghost = 1, size, metric;
        !            76:        union ns_net net;
        !            77: 
        !            78:        msg->rip_cmd = ntohs(RIPCMD_RESPONSE);
        !            79: again:
        !            80:        for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)
        !            81:        for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
        !            82:                size = (char *)n - (char *)msg;
        !            83:                if (size > MAXPACKETSIZE - sizeof (struct netinfo)) {
        !            84:                        (*output)(flags, dst, size);
        !            85:                        TRACE_OUTPUT(ifp, dst, size);
        !            86:                        n = msg->rip_nets;
        !            87:                }
        !            88:                sns = (struct sockaddr_ns *)&rt->rt_dst;
        !            89:                if ((rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST)
        !            90:                        sns = (struct sockaddr_ns *)&rt->rt_router;
        !            91:                metric = min(rt->rt_metric + 1, HOPCNT_INFINITY);
        !            92:                net = sns->sns_addr.x_net;
        !            93:                /*
        !            94:                 * Make sure that we don't put out a two net entries
        !            95:                 * for a pt to pt link (one for the G route, one for the if)
        !            96:                 * This is a kludge, and won't work if there are lots of nets.
        !            97:                 */
        !            98:                for (nn = msg->rip_nets; nn < n; nn++) {
        !            99:                        if (ns_neteqnn(net, nn->rip_dst)) {
        !           100:                                if (metric < ntohs(nn->rip_metric))
        !           101:                                        nn->rip_metric = htons(metric);
        !           102:                                goto next;
        !           103:                        }
        !           104:                }
        !           105:                n->rip_dst = net;
        !           106:                n->rip_metric = htons(metric);
        !           107:                n++;
        !           108:        next:;
        !           109:        }
        !           110:        if (doinghost) {
        !           111:                doinghost = 0;
        !           112:                base = nethash;
        !           113:                goto again;
        !           114:        }
        !           115:        if (n != msg->rip_nets) {
        !           116:                size = (char *)n - (char *)msg;
        !           117:                (*output)(flags, dst, size);
        !           118:                TRACE_OUTPUT(ifp, dst, size);
        !           119:        }
        !           120: }

unix.superglobalmegacorp.com

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