[BACK]Return to mroute.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / netstat

Annotation of src/usr.bin/netstat/mroute.c, Revision 1.1

1.1     ! deraadt     1: /*     $NetBSD: mroute.c,v 1.9 1995/10/03 21:42:42 thorpej Exp $       */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1989 Stephen Deering
        !             5:  * Copyright (c) 1992, 1993
        !             6:  *     The Regents of the University of California.  All rights reserved.
        !             7:  *
        !             8:  * This code is derived from software contributed to Berkeley by
        !             9:  * Stephen Deering of Stanford University.
        !            10:  *
        !            11:  * Redistribution and use in source and binary forms, with or without
        !            12:  * modification, are permitted provided that the following conditions
        !            13:  * are met:
        !            14:  * 1. Redistributions of source code must retain the above copyright
        !            15:  *    notice, this list of conditions and the following disclaimer.
        !            16:  * 2. Redistributions in binary form must reproduce the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer in the
        !            18:  *    documentation and/or other materials provided with the distribution.
        !            19:  * 3. All advertising materials mentioning features or use of this software
        !            20:  *    must display the following acknowledgement:
        !            21:  *     This product includes software developed by the University of
        !            22:  *     California, Berkeley and its contributors.
        !            23:  * 4. Neither the name of the University nor the names of its contributors
        !            24:  *    may be used to endorse or promote products derived from this software
        !            25:  *    without specific prior written permission.
        !            26:  *
        !            27:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            28:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            29:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            30:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            31:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            32:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            33:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            34:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            35:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            36:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            37:  * SUCH DAMAGE.
        !            38:  *
        !            39:  *     from: @(#)mroute.c      8.1 (Berkeley) 6/6/93
        !            40:  */
        !            41:
        !            42: /*
        !            43:  * Print DVMRP multicast routing structures and statistics.
        !            44:  *
        !            45:  * MROUTING 1.0
        !            46:  */
        !            47:
        !            48: #include <sys/param.h>
        !            49: #include <sys/socket.h>
        !            50: #include <sys/socketvar.h>
        !            51: #include <sys/protosw.h>
        !            52:
        !            53: #include <net/if.h>
        !            54: #include <net/route.h>
        !            55: #include <netinet/in.h>
        !            56: #include <netinet/igmp.h>
        !            57: #define _KERNEL
        !            58: #include <netinet/ip_mroute.h>
        !            59: #undef _KERNEL
        !            60:
        !            61: #include <stdio.h>
        !            62: #include <stdlib.h>
        !            63: #include "netstat.h"
        !            64:
        !            65: char *
        !            66: pktscale(n)
        !            67:        u_long n;
        !            68: {
        !            69:        static char buf[8];
        !            70:        char t;
        !            71:
        !            72:        if (n < 1024)
        !            73:                t = ' ';
        !            74:        else if (n < 1024 * 1024) {
        !            75:                t = 'k';
        !            76:                n /= 1024;
        !            77:        } else {
        !            78:                t = 'm';
        !            79:                n /= 1048576;
        !            80:        }
        !            81:
        !            82:        sprintf(buf, "%u%c", n, t);
        !            83:        return (buf);
        !            84: }
        !            85:
        !            86: void
        !            87: mroutepr(mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr)
        !            88:        u_long mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr;
        !            89: {
        !            90:        u_int mrtproto;
        !            91:        LIST_HEAD(, mfc) *mfchashtbl;
        !            92:        u_long mfchash;
        !            93:        struct vif viftable[MAXVIFS];
        !            94:        struct mfc *mfcp, mfc;
        !            95:        register struct vif *v;
        !            96:        register vifi_t vifi;
        !            97:        struct in_addr *grp;
        !            98:        int i;
        !            99:        int banner_printed;
        !           100:        int saved_nflag;
        !           101:        int numvifs;
        !           102:        int nmfc;               /* No. of cache entries */
        !           103:
        !           104:        if (mrpaddr == 0) {
        !           105:                printf("ip_mrtproto: symbol not in namelist\n");
        !           106:                return;
        !           107:        }
        !           108:
        !           109:        kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
        !           110:        switch (mrtproto) {
        !           111:        case 0:
        !           112:                printf("no multicast routing compiled into this system\n");
        !           113:                return;
        !           114:
        !           115:        case IGMP_DVMRP:
        !           116:                break;
        !           117:
        !           118:        default:
        !           119:                printf("multicast routing protocol %u, unknown\n", mrtproto);
        !           120:                return;
        !           121:        }
        !           122:
        !           123:        if (mfchashtbladdr == 0) {
        !           124:                printf("mfchashtbl: symbol not in namelist\n");
        !           125:                return;
        !           126:        }
        !           127:        if (mfchashaddr == 0) {
        !           128:                printf("mfchash: symbol not in namelist\n");
        !           129:                return;
        !           130:        }
        !           131:        if (vifaddr == 0) {
        !           132:                printf("viftable: symbol not in namelist\n");
        !           133:                return;
        !           134:        }
        !           135:
        !           136:        saved_nflag = nflag;
        !           137:        nflag = 1;
        !           138:
        !           139:        kread(vifaddr, (char *)&viftable, sizeof(viftable));
        !           140:        banner_printed = 0;
        !           141:        numvifs = 0;
        !           142:
        !           143:        for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
        !           144:                if (v->v_lcl_addr.s_addr == 0)
        !           145:                        continue;
        !           146:                numvifs = vifi;
        !           147:
        !           148:                if (!banner_printed) {
        !           149:                        printf("\nVirtual Interface Table\n %s%s",
        !           150:                            "Vif  Thresh  Limit  Local-Address    ",
        !           151:                            "Remote-Address   Pkt_in  Pkt_out\n");
        !           152:                        banner_printed = 1;
        !           153:                }
        !           154:
        !           155:                printf(" %3u     %3u  %5u  %-15.15s",
        !           156:                    vifi, v->v_threshold, v->v_rate_limit,
        !           157:                    routename(v->v_lcl_addr.s_addr));
        !           158:                printf("  %-15.15s  %6u  %7u\n", (v->v_flags & VIFF_TUNNEL) ?
        !           159:                    routename(v->v_rmt_addr.s_addr) : "",
        !           160:                    v->v_pkt_in, v->v_pkt_out);
        !           161:        }
        !           162:        if (!banner_printed)
        !           163:                printf("\nVirtual Interface Table is empty\n");
        !           164:
        !           165:        kread(mfchashtbladdr, (char *)&mfchashtbl, sizeof(mfchashtbl));
        !           166:        kread(mfchashaddr, (char *)&mfchash, sizeof(mfchash));
        !           167:        banner_printed = 0;
        !           168:        nmfc = 0;
        !           169:
        !           170:        for (i = 0; i <= mfchash; ++i) {
        !           171:                kread((u_long)&mfchashtbl[i], (char *)&mfcp, sizeof(mfcp));
        !           172:
        !           173:                for (; mfcp != 0; mfcp = mfc.mfc_hash.le_next) {
        !           174:                        if (!banner_printed) {
        !           175:                                printf("\nMulticast Forwarding Cache\n %s%s",
        !           176:                                    "Hash  Origin           Mcastgroup       ",
        !           177:                                    "Traffic  In-Vif  Out-Vifs/Forw-ttl\n");
        !           178:                                banner_printed = 1;
        !           179:                        }
        !           180:
        !           181:                        kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
        !           182:                        printf("  %3u  %-15.15s",
        !           183:                            i, routename(mfc.mfc_origin.s_addr));
        !           184:                        printf("  %-15.15s  %7s     %3u ",
        !           185:                            routename(mfc.mfc_mcastgrp.s_addr),
        !           186:                            pktscale(mfc.mfc_pkt_cnt), mfc.mfc_parent);
        !           187:                        for (vifi = 0; vifi <= numvifs; ++vifi)
        !           188:                                if (mfc.mfc_ttls[vifi])
        !           189:                                        printf(" %u/%u", vifi, mfc.mfc_ttls[vifi]);
        !           190:
        !           191:                        printf("\n");
        !           192:                        nmfc++;
        !           193:                }
        !           194:        }
        !           195:        if (!banner_printed)
        !           196:                printf("\nMulticast Forwarding Cache is empty\n");
        !           197:        else
        !           198:                printf("\nTotal no. of entries in cache: %d\n", nmfc);
        !           199:
        !           200:        printf("\n");
        !           201:        nflag = saved_nflag;
        !           202: }
        !           203:
        !           204:
        !           205: void
        !           206: mrt_stats(mrpaddr, mstaddr)
        !           207:        u_long mrpaddr, mstaddr;
        !           208: {
        !           209:        u_int mrtproto;
        !           210:        struct mrtstat mrtstat;
        !           211:
        !           212:        if (mrpaddr == 0) {
        !           213:                printf("ip_mrtproto: symbol not in namelist\n");
        !           214:                return;
        !           215:        }
        !           216:
        !           217:        kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
        !           218:        switch (mrtproto) {
        !           219:        case 0:
        !           220:                printf("no multicast routing compiled into this system\n");
        !           221:                return;
        !           222:
        !           223:        case IGMP_DVMRP:
        !           224:                break;
        !           225:
        !           226:        default:
        !           227:                printf("multicast routing protocol %u, unknown\n", mrtproto);
        !           228:                return;
        !           229:        }
        !           230:
        !           231:        if (mstaddr == 0) {
        !           232:                printf("mrtstat: symbol not in namelist\n");
        !           233:                return;
        !           234:        }
        !           235:
        !           236:        kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
        !           237:        printf("multicast routing:\n");
        !           238:        printf("\t%d datagram%s with no route for origin\n",
        !           239:            mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
        !           240:        printf("\t%d upcall%s made to mrouted\n",
        !           241:            mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
        !           242:        printf("\t%d datagram%s with malformed tunnel options\n",
        !           243:            mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
        !           244:        printf("\t%d datagram%s with no room for tunnel options\n",
        !           245:            mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
        !           246:        printf("\t%d datagram%s arrived on wrong interface\n",
        !           247:            mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
        !           248:        printf("\t%d datagram%s dropped due to upcall Q overflow\n",
        !           249:            mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
        !           250:        printf("\t%d datagram%s dropped due to upcall socket overflow\n",
        !           251:            mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull));
        !           252:        printf("\t%d datagram%s cleaned up by the cache\n",
        !           253:            mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
        !           254:        printf("\t%d datagram%s dropped selectively by ratelimiter\n",
        !           255:            mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
        !           256:        printf("\t%d datagram%s dropped - bucket Q overflow\n",
        !           257:            mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
        !           258:        printf("\t%d datagram%s dropped - larger than bkt size\n",
        !           259:            mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
        !           260: }