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