[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.17

1.17    ! claudio     1: /*     $OpenBSD: mroute6.c,v 1.16 2015/01/17 07:09:50 deraadt 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.
1.7       millert    48:  * 3. Neither the name of the University nor the names of its contributors
1.1       itojun     49:  *    may be used to endorse or promote products derived from this software
                     50:  *    without specific prior written permission.
                     51:  *
                     52:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     53:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     54:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     55:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     56:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     57:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     58:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     59:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     60:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     61:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     62:  * SUCH DAMAGE.
                     63:  *
                     64:  *     @(#)mroute.c    8.2 (Berkeley) 4/28/95
                     65:  */
                     66:
1.15      deraadt    67: #include <sys/types.h>
1.1       itojun     68: #include <sys/socket.h>
1.10      deraadt    69: #include <sys/sysctl.h>
1.1       itojun     70:
                     71: #include <net/if.h>
                     72: #include <netinet/in.h>
                     73: #include <netinet6/ip6_mroute.h>
                     74:
1.11      chl        75: #include <err.h>
                     76: #include <errno.h>
1.1       itojun     77: #include <stdio.h>
1.17    ! claudio    78: #include <util.h>
1.1       itojun     79: #include "netstat.h"
                     80:
                     81: #define        WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */
                     82: #define        WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */
                     83:
                     84: void
1.17    ! claudio    85: mroute6pr(void)
1.1       itojun     86: {
1.17    ! claudio    87:        char *buf;
        !            88:        char fmtbuf[FMT_SCALED_STRSIZE];
        !            89:        struct mf6cinfo *mfc;
        !            90:        struct mif6info *mif;
        !            91:        size_t needed, mifi, nummifs, mfci, nummfcs;
        !            92:        int banner_printed, saved_nflag;
        !            93:        mifi_t maxmif = 0;
1.6       deraadt    94:        u_int mrtproto;
1.13      guenther   95:        int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_MRTPROTO };
1.10      deraadt    96:        size_t len = sizeof(int);
1.1       itojun     97:
1.10      deraadt    98:        if (sysctl(mib, sizeof(mib) / sizeof(mib[0]),
                     99:            &mrtproto, &len, NULL, 0) == -1) {
                    100:                if (errno != ENOPROTOOPT)
                    101:                        warn("mroute");
1.1       itojun    102:                return;
                    103:        }
                    104:        switch (mrtproto) {
1.5       deraadt   105:        case 0:
                    106:                printf("no IPv6 multicast routing compiled into this system\n");
                    107:                return;
                    108:        case IPPROTO_PIM:
                    109:                break;
                    110:        default:
                    111:                printf("IPv6 multicast routing protocol %u, unknown\n",
1.6       deraadt   112:                    mrtproto);
1.5       deraadt   113:                return;
1.1       itojun    114:        }
                    115:
                    116:        saved_nflag = nflag;
                    117:        nflag = 1;
                    118:
1.17    ! claudio   119:        mib[3] = IPV6CTL_MRTMIF;
        !           120:        needed = get_sysctl(mib, sizeof(mib) / sizeof(mib[0]), &buf);
        !           121:        nummifs = needed / sizeof(*mif);
        !           122:        mif = (struct mif6info *)buf;
        !           123:        if (nummifs)
        !           124:                maxmif = mif[nummifs - 1].m6_mifi;
        !           125:
1.1       itojun    126:        banner_printed = 0;
1.17    ! claudio   127:        for (mifi = 0; mifi < nummifs; ++mifi, ++mif) {
1.1       itojun    128:                char ifname[IFNAMSIZ];
                    129:
1.17    ! claudio   130:                if (mif->m6_ifindex == 0)
1.1       itojun    131:                        continue;
                    132:
                    133:                if (!banner_printed) {
                    134:                        printf("\nIPv6 Multicast Interface Table\n"
1.5       deraadt   135:                            " Mif   Rate   PhyIF   "
                    136:                            "Pkts-In   Pkts-Out\n");
1.1       itojun    137:                        banner_printed = 1;
                    138:                }
                    139:
                    140:                printf("  %2u   %4d",
1.17    ! claudio   141:                    mif->m6_mifi, mif->m6_rate_limit);
        !           142:                printf("   %5s", (mif->m6_flags & MIFF_REGISTER) ?
        !           143:                    "reg0" : if_indextoname(mif->m6_ifindex, ifname));
1.1       itojun    144:
1.17    ! claudio   145:                printf(" %9llu  %9llu\n", mif->m6_pkt_in, mif->m6_pkt_out);
1.1       itojun    146:        }
                    147:        if (!banner_printed)
1.10      deraadt   148:                printf("IPv6 Multicast Interface Table is empty\n");
1.1       itojun    149:
1.17    ! claudio   150:        mib[3] = IPV6CTL_MRTMFC;
        !           151:        needed = get_sysctl(mib, sizeof(mib) / sizeof(mib[0]), &buf);
        !           152:        nummfcs = needed / sizeof(*mfc);
        !           153:        mfc = (struct mf6cinfo *)buf;
        !           154:
1.1       itojun    155:        banner_printed = 0;
1.17    ! claudio   156:        for (mfci = 0; mfci < nummfcs; ++mfci, ++mfc) {
        !           157:                if (!banner_printed) {
        !           158:                        printf("\nIPv6 Multicast Forwarding Cache\n");
        !           159:                        printf(" %-*.*s %-*.*s %s",
        !           160:                            WID_ORG, WID_ORG, "Origin",
        !           161:                            WID_GRP, WID_GRP, "Group",
        !           162:                            "  Packets Waits In-Mif  Out-Mifs\n");
        !           163:                        banner_printed = 1;
        !           164:                }
1.1       itojun    165:
1.17    ! claudio   166:                printf(" %-*.*s", WID_ORG, WID_ORG,
        !           167:                    routename6(&mfc->mf6c_origin));
        !           168:                printf(" %-*.*s", WID_GRP, WID_GRP,
        !           169:                    routename6(&mfc->mf6c_mcastgrp));
        !           170:                fmt_scaled(mfc->mf6c_pkt_cnt, fmtbuf);
        !           171:                printf(" %9s", fmtbuf);
        !           172:
        !           173:                printf("   %3llu", mfc->mf6c_stall_cnt);
        !           174:
        !           175:                if (mfc->mf6c_parent == MF6C_INCOMPLETE_PARENT)
        !           176:                        printf("  ---   ");
        !           177:                else
        !           178:                        printf("  %3d   ", mfc->mf6c_parent);
        !           179:                for (mifi = 0; mifi <= MAXMIFS; mifi++) {
        !           180:                        if (IF_ISSET(mifi, &mfc->mf6c_ifset))
        !           181:                                printf(" %zu", mifi);
1.1       itojun    182:                }
1.17    ! claudio   183:                printf("\n");
1.1       itojun    184:        }
                    185:        if (!banner_printed)
1.10      deraadt   186:                printf("IPv6 Multicast Routing Table is empty");
1.1       itojun    187:
                    188:        printf("\n");
                    189:        nflag = saved_nflag;
                    190: }
                    191:
                    192: void
1.10      deraadt   193: mrt6_stats(void)
1.1       itojun    194: {
1.10      deraadt   195:        struct mrt6stat mrt6stat;
                    196:        u_int mrt6proto;
1.13      guenther  197:        int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_MRTPROTO };
                    198:        int mib2[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_MRTSTATS };
1.10      deraadt   199:        size_t len = sizeof(int);
                    200:
                    201:        if (sysctl(mib, sizeof(mib) / sizeof(mib[0]),
                    202:            &mrt6proto, &len, NULL, 0) == -1) {
                    203:                if (errno != ENOPROTOOPT)
                    204:                        warn("mroute");
1.1       itojun    205:                return;
                    206:        }
1.10      deraadt   207:        switch (mrt6proto) {
1.4       deraadt   208:        case 0:
1.10      deraadt   209:                printf("no IPv6 multicast routing compiled into this system\n");
                    210:                return;
1.4       deraadt   211:        case IPPROTO_PIM:
1.10      deraadt   212:                break;
1.4       deraadt   213:        default:
1.5       deraadt   214:                printf("IPv6 multicast routing protocol %u, unknown\n",
1.10      deraadt   215:                    mrt6proto);
1.5       deraadt   216:                return;
1.1       itojun    217:        }
                    218:
1.10      deraadt   219:        len = sizeof(mrt6stat);
                    220:        if (sysctl(mib2, sizeof(mib2) / sizeof(mib2[0]),
                    221:            &mrt6stat, &len, NULL, 0) == -1) {
                    222:                if (errno != ENOPROTOOPT)
                    223:                        warn("mroute");
1.1       itojun    224:                return;
                    225:        }
                    226:
                    227:        printf("multicast forwarding:\n");
1.10      deraadt   228:        printf("\t%llu multicast forwarding cache lookup%s\n",
                    229:            mrt6stat.mrt6s_mfc_lookups, plural(mrt6stat.mrt6s_mfc_lookups));
                    230:        printf("\t%llu multicast forwarding cache miss%s\n",
                    231:            mrt6stat.mrt6s_mfc_misses, plurales(mrt6stat.mrt6s_mfc_misses));
                    232:        printf("\t%llu upcall%s to mrouted\n",
                    233:            mrt6stat.mrt6s_upcalls, plural(mrt6stat.mrt6s_upcalls));
                    234:        printf("\t%llu upcall queue overflow%s\n",
                    235:            mrt6stat.mrt6s_upq_ovflw, plural(mrt6stat.mrt6s_upq_ovflw));
                    236:        printf("\t%llu upcall%s dropped due to full socket buffer\n",
                    237:            mrt6stat.mrt6s_upq_sockfull, plural(mrt6stat.mrt6s_upq_sockfull));
                    238:        printf("\t%llu cache cleanup%s\n",
                    239:            mrt6stat.mrt6s_cache_cleanups, plural(mrt6stat.mrt6s_cache_cleanups));
                    240:        printf("\t%llu datagram%s with no route for origin\n",
                    241:            mrt6stat.mrt6s_no_route, plural(mrt6stat.mrt6s_no_route));
                    242:        printf("\t%llu datagram%s arrived with bad tunneling\n",
                    243:            mrt6stat.mrt6s_bad_tunnel, plural(mrt6stat.mrt6s_bad_tunnel));
                    244:        printf("\t%llu datagram%s could not be tunneled\n",
                    245:            mrt6stat.mrt6s_cant_tunnel, plural(mrt6stat.mrt6s_cant_tunnel));
                    246:        printf("\t%llu datagram%s arrived on wrong interface\n",
                    247:            mrt6stat.mrt6s_wrong_if, plural(mrt6stat.mrt6s_wrong_if));
                    248:        printf("\t%llu datagram%s selectively dropped\n",
                    249:            mrt6stat.mrt6s_drop_sel, plural(mrt6stat.mrt6s_drop_sel));
                    250:        printf("\t%llu datagram%s dropped due to queue overflow\n",
                    251:            mrt6stat.mrt6s_q_overflow, plural(mrt6stat.mrt6s_q_overflow));
                    252:        printf("\t%llu datagram%s dropped for being too large\n",
                    253:            mrt6stat.mrt6s_pkt2large, plural(mrt6stat.mrt6s_pkt2large));
1.1       itojun    254: }