home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / crh / freebsd / rootkit / netstat / mroute.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-27  |  7.1 KB  |  236 lines

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