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

Annotation of src/usr.bin/netstat/mroute6.c, Revision 1.4

1.4     ! deraadt     1: /*     $OpenBSD: mroute6.c,v 1.3 2002/01/17 21:34:58 mickey Exp $      */
1.1       itojun      2:
                      3: /*
                      4:  * Copyright (C) 1998 WIDE Project.
                      5:  * All rights reserved.
1.3       mickey      6:  *
1.1       itojun      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. Neither the name of the project nor the names of its contributors
                     16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
1.3       mickey     18:  *
1.1       itojun     19:  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  */
                     31:
                     32: /*
                     33:  * Copyright (c) 1989 Stephen Deering
                     34:  * Copyright (c) 1992, 1993
                     35:  *     The Regents of the University of California.  All rights reserved.
                     36:  *
                     37:  * This code is derived from software contributed to Berkeley by
                     38:  * Stephen Deering of Stanford University.
                     39:  *
                     40:  * Redistribution and use in source and binary forms, with or without
                     41:  * modification, are permitted provided that the following conditions
                     42:  * are met:
                     43:  * 1. Redistributions of source code must retain the above copyright
                     44:  *    notice, this list of conditions and the following disclaimer.
                     45:  * 2. Redistributions in binary form must reproduce the above copyright
                     46:  *    notice, this list of conditions and the following disclaimer in the
                     47:  *    documentation and/or other materials provided with the distribution.
                     48:  * 3. All advertising materials mentioning features or use of this software
                     49:  *    must display the following acknowledgement:
                     50:  *     This product includes software developed by the University of
                     51:  *     California, Berkeley and its contributors.
                     52:  * 4. Neither the name of the University nor the names of its contributors
                     53:  *    may be used to endorse or promote products derived from this software
                     54:  *    without specific prior written permission.
                     55:  *
                     56:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     57:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     58:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     59:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     60:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     61:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     62:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     63:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     64:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     65:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     66:  * SUCH DAMAGE.
                     67:  *
                     68:  *     @(#)mroute.c    8.2 (Berkeley) 4/28/95
                     69:  */
                     70:
                     71: #include <sys/param.h>
                     72: #include <sys/queue.h>
                     73: #include <sys/socket.h>
                     74: #include <sys/socketvar.h>
                     75: #include <sys/protosw.h>
                     76:
                     77: #include <net/if.h>
                     78:
                     79: #include <netinet/in.h>
                     80:
                     81: #define _KERNEL 1
                     82: #include <netinet6/ip6_mroute.h>
                     83: #undef _KERNEL
                     84:
                     85: #include <stdio.h>
                     86: #include "netstat.h"
                     87:
                     88: #ifdef INET6
                     89:
                     90: #define        WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */
                     91: #define        WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */
                     92:
                     93: void
                     94: mroute6pr(mrpaddr, mfcaddr, mifaddr)
                     95:        u_long mrpaddr, mfcaddr, mifaddr;
                     96: {
                     97:        u_int mrtproto;
                     98:        struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
                     99:        struct mif6 mif6table[MAXMIFS];
                    100:        struct mf6c mfc;
                    101:        struct rtdetq rte, *rtep;
1.2       mpech     102:        struct mif6 *mifp;
                    103:        mifi_t mifi;
                    104:        int i;
                    105:        int banner_printed;
                    106:        int saved_nflag;
1.1       itojun    107:        mifi_t maxmif = 0;
                    108:        int waitings;
                    109:
                    110:        if (mrpaddr == 0) {
                    111:                printf("mroute6pr: symbol not in namelist\n");
                    112:                return;
                    113:        }
                    114:
                    115:        kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
                    116:        switch (mrtproto) {
                    117:
                    118:         case 0:
                    119:                 printf("no IPv6 multicast routing compiled into this system\n");
                    120:                 return;
                    121:
                    122:         case IPPROTO_PIM:
                    123:                 break;
                    124:
                    125:         default:
                    126:                 printf("IPv6 multicast routing protocol %u, unknown\n",
                    127:                        mrtproto);
                    128:                 return;
                    129:        }
                    130:
                    131:        if (mfcaddr == 0) {
                    132:                printf("mf6ctable: symbol not in namelist\n");
                    133:                return;
                    134:        }
                    135:        if (mifaddr == 0) {
                    136:                printf("miftable: symbol not in namelist\n");
                    137:                return;
                    138:        }
                    139:
                    140:        saved_nflag = nflag;
                    141:        nflag = 1;
                    142:
                    143:        kread(mifaddr, (char *)&mif6table, sizeof(mif6table));
                    144:        banner_printed = 0;
                    145:        for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
                    146:                struct ifnet ifnet;
                    147:                char ifname[IFNAMSIZ];
                    148:
                    149:                if (mifp->m6_ifp == NULL)
                    150:                        continue;
                    151:
                    152:                kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
                    153:                maxmif = mifi;
                    154:                if (!banner_printed) {
                    155:                        printf("\nIPv6 Multicast Interface Table\n"
                    156:                               " Mif   Rate   PhyIF   "
                    157:                               "Pkts-In   Pkts-Out\n");
                    158:                        banner_printed = 1;
                    159:                }
                    160:
                    161:                printf("  %2u   %4d",
                    162:                       mifi, mifp->m6_rate_limit);
                    163:                printf("   %5s", (mifp->m6_flags & MIFF_REGISTER) ?
                    164:                       "reg0" : if_indextoname(ifnet.if_index, ifname));
                    165:
                    166:                printf(" %9qu  %9qu\n", mifp->m6_pkt_in, mifp->m6_pkt_out);
                    167:        }
                    168:        if (!banner_printed)
                    169:                printf("\nIPv6 Multicast Interface Table is empty\n");
                    170:
                    171:        kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable));
                    172:        banner_printed = 0;
                    173:        for (i = 0; i < MF6CTBLSIZ; ++i) {
                    174:                mfcp = mf6ctable[i];
1.4     ! deraadt   175:                while (mfcp) {
1.1       itojun    176:                        kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
                    177:                        if (!banner_printed) {
                    178:                                printf ("\nIPv6 Multicast Forwarding Cache\n");
                    179:                                printf(" %-*.*s %-*.*s %s",
                    180:                                       WID_ORG, WID_ORG, "Origin",
                    181:                                       WID_GRP, WID_GRP, "Group",
                    182:                                       "  Packets Waits In-Mif  Out-Mifs\n");
                    183:                                banner_printed = 1;
                    184:                        }
1.3       mickey    185:
1.1       itojun    186:                        printf(" %-*.*s", WID_ORG, WID_ORG,
                    187:                               routename6(&mfc.mf6c_origin));
                    188:                        printf(" %-*.*s", WID_GRP, WID_GRP,
                    189:                               routename6(&mfc.mf6c_mcastgrp));
                    190:                        printf(" %9qu", mfc.mf6c_pkt_cnt);
                    191:
                    192:                        for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
                    193:                                waitings++;
                    194:                                kread((u_long)rtep, (char *)&rte, sizeof(rte));
                    195:                                rtep = rte.next;
                    196:                        }
                    197:                        printf("   %3d", waitings);
                    198:
                    199:                        if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
                    200:                                printf("  ---   ");
                    201:                        else
                    202:                                printf("  %3d   ", mfc.mf6c_parent);
                    203:                        for (mifi = 0; mifi <= MAXMIFS; mifi++) {
                    204:                                if (IF_ISSET(mifi, &mfc.mf6c_ifset))
                    205:                                        printf(" %u", mifi);
                    206:                        }
                    207:                        printf("\n");
                    208:
                    209:                        mfcp = mfc.mf6c_next;
                    210:                }
                    211:        }
                    212:        if (!banner_printed)
                    213:                printf("\nIPv6 Multicast Routing Table is empty\n");
                    214:
                    215:        printf("\n");
                    216:        nflag = saved_nflag;
                    217: }
                    218:
                    219: void
                    220: mrt6_stats(mrpaddr, mstaddr)
                    221:        u_long mrpaddr, mstaddr;
                    222: {
                    223:        u_int mrtproto;
                    224:        struct mrt6stat mrtstat;
                    225:
1.4     ! deraadt   226:        if (mrpaddr == 0) {
1.1       itojun    227:                printf("mrt6_stats: symbol not in namelist\n");
                    228:                return;
                    229:        }
                    230:
                    231:        kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
                    232:        switch (mrtproto) {
1.4     ! deraadt   233:        case 0:
1.1       itojun    234:                 printf("no IPv6 multicast routing compiled into this system\n");
                    235:                 return;
                    236:
1.4     ! deraadt   237:        case IPPROTO_PIM:
1.1       itojun    238:                 break;
                    239:
1.4     ! deraadt   240:        default:
1.1       itojun    241:                 printf("IPv6 multicast routing protocol %u, unknown\n",
                    242:                        mrtproto);
                    243:                 return;
                    244:        }
                    245:
                    246:        if (mstaddr == 0) {
                    247:                printf("mrt6_stats: symbol not in namelist\n");
                    248:                return;
                    249:        }
                    250:
                    251:        kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
                    252:        printf("multicast forwarding:\n");
                    253:        printf(" %10qu multicast forwarding cache lookup%s\n",
                    254:               mrtstat.mrt6s_mfc_lookups, plural(mrtstat.mrt6s_mfc_lookups));
                    255:        printf(" %10qu multicast forwarding cache miss%s\n",
                    256:               mrtstat.mrt6s_mfc_misses, plurales(mrtstat.mrt6s_mfc_misses));
                    257:        printf(" %10qu upcall%s to mrouted\n",
                    258:               mrtstat.mrt6s_upcalls, plural(mrtstat.mrt6s_upcalls));
                    259:        printf(" %10qu upcall queue overflow%s\n",
                    260:          mrtstat.mrt6s_upq_ovflw, plural(mrtstat.mrt6s_upq_ovflw));
                    261:        printf(" %10qu upcall%s dropped due to full socket buffer\n",
                    262:          mrtstat.mrt6s_upq_sockfull, plural(mrtstat.mrt6s_upq_sockfull));
                    263:        printf(" %10qu cache cleanup%s\n",
                    264:          mrtstat.mrt6s_cache_cleanups, plural(mrtstat.mrt6s_cache_cleanups));
                    265:        printf(" %10qu datagram%s with no route for origin\n",
                    266:          mrtstat.mrt6s_no_route, plural(mrtstat.mrt6s_no_route));
                    267:        printf(" %10qu datagram%s arrived with bad tunneling\n",
                    268:          mrtstat.mrt6s_bad_tunnel, plural(mrtstat.mrt6s_bad_tunnel));
                    269:        printf(" %10qu datagram%s could not be tunneled\n",
                    270:          mrtstat.mrt6s_cant_tunnel, plural(mrtstat.mrt6s_cant_tunnel));
                    271:        printf(" %10qu datagram%s arrived on wrong interface\n",
                    272:          mrtstat.mrt6s_wrong_if, plural(mrtstat.mrt6s_wrong_if));
                    273:        printf(" %10qu datagram%s selectively dropped\n",
                    274:          mrtstat.mrt6s_drop_sel, plural(mrtstat.mrt6s_drop_sel));
                    275:        printf(" %10qu datagram%s dropped due to queue overflow\n",
                    276:          mrtstat.mrt6s_q_overflow, plural(mrtstat.mrt6s_q_overflow));
                    277:        printf(" %10qu datagram%s dropped for being too large\n",
                    278:          mrtstat.mrt6s_pkt2large, plural(mrtstat.mrt6s_pkt2large));
                    279: }
                    280: #endif /*INET6*/