]> git.saurik.com Git - apple/network_cmds.git/blame - netstat.tproj/mroute.c
network_cmds-356.9.tar.gz
[apple/network_cmds.git] / netstat.tproj / mroute.c
CommitLineData
b7080c8e 1/*
fdfd5971 2 * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
b7080c8e 3 *
9c859447 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
b7080c8e 5 *
9c859447
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
b7080c8e 14 *
9c859447
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
b7080c8e
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
9c859447
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
b7080c8e 25 *
9c859447 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
b7080c8e
A
27 */
28/*
29 * Copyright (c) 1989 Stephen Deering
30 * Copyright (c) 1992, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * This code is derived from software contributed to Berkeley by
34 * Stephen Deering of Stanford University.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
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
67/*
68 * Print DVMRP multicast routing structures and statistics.
69 *
70 * MROUTING 1.0
71 */
72
73#include <sys/param.h>
74#include <sys/queue.h>
75#include <sys/socket.h>
76#include <sys/socketvar.h>
b7080c8e
A
77#include <sys/mbuf.h>
78#include <sys/time.h>
2b484d24 79#include <sys/sysctl.h>
b7080c8e
A
80
81#include <net/if.h>
82#include <netinet/in.h>
83#include <netinet/igmp.h>
84#include <net/route.h>
85#include <netinet/ip_mroute.h>
86
87#include <stdio.h>
88#include <stdlib.h>
89#include "netstat.h"
90
91void
2b484d24 92mroutepr(void)
b7080c8e 93{
2b484d24 94 struct mfc **mfctable = 0;
b8dff150
A
95 struct vif viftable[CONFIG_MAXVIFS];
96 struct mfc *m;
b7080c8e
A
97 register struct vif *v;
98 register vifi_t vifi;
99 register int i;
100 register int banner_printed;
101 register int saved_nflag;
102 vifi_t maxvif = 0;
2b484d24
A
103 size_t len;
104
105 saved_nflag = nflag;
106 nflag = 1;
b7080c8e 107
b8dff150 108 len = CONFIG_MAXVIFS * sizeof(struct vif);
2b484d24 109 if (sysctlbyname("net.inet.ip.viftable", viftable, &len, 0, 0) == -1) {
fdfd5971 110 //printf("No IPv4 multicast routing compiled into this system.\n");
b7080c8e
A
111 return;
112 }
113
b7080c8e 114 banner_printed = 0;
b8dff150 115 for (vifi = 0, v = viftable; vifi < CONFIG_MAXVIFS; ++vifi, ++v) {
b7080c8e
A
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 /* opposite math of add_vif() */
129 vifi, v->v_threshold, v->v_rate_limit * 1000 / 1024,
130 routename(v->v_lcl_addr.s_addr));
131 printf(" %-15.15s", (v->v_flags & VIFF_TUNNEL) ?
132 routename(v->v_rmt_addr.s_addr) : "");
133
9c859447 134 printf(" %9u %9u\n", v->v_pkt_in, v->v_pkt_out);
b7080c8e
A
135 }
136 if (!banner_printed)
137 printf("\nVirtual Interface Table is empty\n");
138
2b484d24 139 if (sysctlbyname("net.inet.ip.mfctable", 0, &len, 0, 0) == -1) {
fdfd5971 140 //printf("No IPv4 multicast routing compiled into this system.\n");
2b484d24
A
141 return;
142 }
143 mfctable = malloc(len);
144 if (mfctable == 0)
145 return;
146 if (sysctlbyname("net.inet.ip.mfctable", mfctable, &len, 0, 0) == -1) {
fdfd5971 147 //printf("No IPv4 multicast routing compiled into this system.\n");
2b484d24
A
148 return;
149 }
b7080c8e 150 banner_printed = 0;
b8dff150 151 for (i = 0; i < CONFIG_MFCTBLSIZ; ++i) {
b7080c8e
A
152 m = mfctable[i];
153 while(m) {
b7080c8e 154 if (!banner_printed) {
7ba0088d 155 printf("\nIPv4 Multicast Forwarding Cache\n"
b7080c8e
A
156 " Origin Group "
157 " Packets In-Vif Out-Vifs:Ttls\n");
158 banner_printed = 1;
159 }
160
b8dff150
A
161 printf(" %-15.15s", routename(m->mfc_origin.s_addr));
162 printf(" %-15.15s", routename(m->mfc_mcastgrp.s_addr));
9c859447 163 printf(" %9u", m->mfc_pkt_cnt);
b8dff150 164 printf(" %3d ", m->mfc_parent);
b7080c8e 165 for (vifi = 0; vifi <= maxvif; vifi++) {
b8dff150 166 if (m->mfc_ttls[vifi] > 0)
b7080c8e 167 printf(" %u:%u", vifi,
b8dff150 168 m->mfc_ttls[vifi]);
b7080c8e
A
169 }
170 printf("\n");
b8dff150 171 m = m->mfc_next;
b7080c8e
A
172 }
173 }
174 if (!banner_printed)
175 printf("\nMulticast Routing Table is empty\n");
176
177 printf("\n");
178 nflag = saved_nflag;
2b484d24
A
179
180 free(mfctable);
b7080c8e
A
181}
182
183
184void
2b484d24 185mrt_stats()
b7080c8e
A
186{
187 struct mrtstat mrtstat;
2b484d24 188 size_t len = sizeof(struct mrtstat);
b7080c8e 189
2b484d24 190 if(sysctlbyname("net.inet.ip.mrtstat", &mrtstat, &len, 0, 0) == -1) {
fdfd5971 191 //printf("No IPv4 multicast routing compiled into this system.\n");
b7080c8e
A
192 return;
193 }
194
7ba0088d 195 printf("IPv4 multicast forwarding:\n");
b8dff150 196 printf(" %10u multicast forwarding cache lookup%s\n",
b7080c8e 197 mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups));
b8dff150 198 printf(" %10u multicast forwarding cache miss%s\n",
b7080c8e 199 mrtstat.mrts_mfc_misses, plurales(mrtstat.mrts_mfc_misses));
b8dff150 200 printf(" %10u upcall%s to mrouted\n",
b7080c8e 201 mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
b8dff150 202 printf(" %10u upcall queue overflow%s\n",
b7080c8e 203 mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
b8dff150 204 printf(" %10u upcall%s dropped due to full socket buffer\n",
b7080c8e 205 mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull));
b8dff150 206 printf(" %10u cache cleanup%s\n",
b7080c8e 207 mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
b8dff150 208 printf(" %10u datagram%s with no route for origin\n",
b7080c8e 209 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
b8dff150 210 printf(" %10u datagram%s arrived with bad tunneling\n",
b7080c8e 211 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
b8dff150 212 printf(" %10u datagram%s could not be tunneled\n",
b7080c8e 213 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
b8dff150 214 printf(" %10u datagram%s arrived on wrong interface\n",
b7080c8e 215 mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
b8dff150 216 printf(" %10u datagram%s selectively dropped\n",
b7080c8e 217 mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
b8dff150 218 printf(" %10u datagram%s dropped due to queue overflow\n",
b7080c8e 219 mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
b8dff150 220 printf(" %10u datagram%s dropped for being too large\n",
b7080c8e
A
221 mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
222}