not every value return in an nlist structure was being
[unix-history] / usr / src / usr.bin / netstat / mroute.c
CommitLineData
c89b6165
KS
1/*
2 * Copyright (c) 1989 Stephen Deering
3 * Copyright (c) 1992 Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Stephen Deering of Stanford University.
8 *
9 * %sccs.include.redist.c%
10 *
d1cfb820 11 * @(#)mroute.c 7.2 (Berkeley) %G%
c89b6165
KS
12 */
13
14/*
15 * Print DVMRP multicast routing structures and statistics.
16 *
17 * MROUTING 1.0
18 */
19
20#include <sys/param.h>
21#include <sys/socket.h>
22#include <sys/socketvar.h>
23#include <sys/protosw.h>
24
25#include <netinet/in.h>
26#include <netinet/igmp.h>
27#define KERNEL 1
28#include <netinet/ip_mroute.h>
29#undef KERNEL
30
31#include <stdio.h>
32#include <stdlib.h>
33#include "netstat.h"
34
35void
36mroutepr(mrpaddr, mrtaddr, vifaddr)
d1cfb820 37 u_long mrpaddr, mrtaddr, vifaddr;
c89b6165
KS
38{
39 u_int mrtproto;
40 struct mrt *mrttable[MRTHASHSIZ];
41 struct vif viftable[MAXVIFS];
42 register struct mrt *mrt;
43 struct mrt smrt;
44 register struct vif *v;
45 register vifi_t vifi;
46 register struct in_addr *grp;
47 register int i, n;
48 register int banner_printed;
49 register int saved_nflag;
50
51 if (mrpaddr == 0) {
52 printf("ip_mrtproto: symbol not in namelist\n");
53 return;
54 }
55
d1cfb820 56 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
c89b6165
KS
57 switch (mrtproto) {
58
59 case 0:
60 printf("no multicast routing compiled into this system\n");
61 return;
62
63 case IGMP_DVMRP:
64 break;
65
66 default:
67 printf("multicast routing protocol %u, unknown\n", mrtproto);
68 return;
69 }
70
71 if (mrtaddr == 0) {
72 printf("mrttable: symbol not in namelist\n");
73 return;
74 }
75 if (vifaddr == 0) {
76 printf("viftable: symbol not in namelist\n");
77 return;
78 }
79
80 saved_nflag = nflag;
81 nflag = 1;
82
d1cfb820 83 kread(vifaddr, (char *)&viftable, sizeof(viftable));
c89b6165
KS
84 banner_printed = 0;
85 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
86 if (v->v_lcl_addr.s_addr == 0)
87 continue;
88
89 if (!banner_printed) {
90 printf("\nVirtual Interface Table\n%s%s",
91 " Vif Threshold Local-Address ",
92 "Remote-Address Groups\n");
93 banner_printed = 1;
94 }
95
96 printf(" %2u %3u %-15.15s",
97 vifi, v->v_threshold, routename(v->v_lcl_addr.s_addr));
98 printf(" %-15.15s\n", (v->v_flags & VIFF_TUNNEL) ?
99 routename(v->v_rmt_addr.s_addr) : "");
100
101 n = v->v_lcl_grps_n;
102 grp = (struct in_addr *)malloc(n * sizeof(*grp));
103 if (grp == NULL) {
104 printf("v_lcl_grps_n: malloc failed\n");
105 return;
106 }
d1cfb820 107 kread((u_long)v->v_lcl_grps, (caddr_t)grp, n * sizeof(*grp));
c89b6165
KS
108 for (i = 0; i < n; ++i)
109 printf("%51s %-15.15s\n",
110 "", routename((grp++)->s_addr));
111 free(grp);
112 }
113 if (!banner_printed)
114 printf("\nVirtual Interface Table is empty\n");
115
d1cfb820 116 kread(mrtaddr, (char *)&mrttable, sizeof(mrttable));
c89b6165
KS
117 banner_printed = 0;
118 for (i = 0; i < MRTHASHSIZ; ++i) {
119 for (mrt = mrttable[i]; mrt != NULL; mrt = mrt->mrt_next) {
120 if (!banner_printed) {
121 printf("\nMulticast Routing Table\n%s",
122 " Hash Origin-Subnet In-Vif Out-Vifs\n");
123 banner_printed = 1;
124 }
125
d1cfb820 126 kread((u_long)mrt, (char *)&smrt, sizeof(*mrt));
c89b6165
KS
127 mrt = &smrt;
128 printf(" %3u %-15.15s %2u ",
129 i, netname(mrt->mrt_origin.s_addr,
130 ntohl(mrt->mrt_originmask.s_addr)),
131 mrt->mrt_parent);
132 for (vifi = 0; vifi < MAXVIFS; ++vifi)
133 if (VIFM_ISSET(vifi, mrt->mrt_children))
134 printf(" %u%c",
135 vifi,
136 VIFM_ISSET(vifi, mrt->mrt_leaves) ?
137 '*' : ' ');
138 printf("\n");
139 }
140 }
141 if (!banner_printed)
142 printf("\nMulticast Routing Table is empty\n");
143
144 printf("\n");
145 nflag = saved_nflag;
146}
147
148
149void
150mrt_stats(mrpaddr, mstaddr)
d1cfb820 151 u_long mrpaddr, mstaddr;
c89b6165
KS
152{
153 u_int mrtproto;
154 struct mrtstat mrtstat;
155
156 if(mrpaddr == 0) {
157 printf("ip_mrtproto: symbol not in namelist\n");
158 return;
159 }
160
d1cfb820 161 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
c89b6165
KS
162 switch (mrtproto) {
163 case 0:
164 printf("no multicast routing compiled into this system\n");
165 return;
166
167 case IGMP_DVMRP:
168 break;
169
170 default:
171 printf("multicast routing protocol %u, unknown\n", mrtproto);
172 return;
173 }
174
175 if (mstaddr == 0) {
176 printf("mrtstat: symbol not in namelist\n");
177 return;
178 }
179
d1cfb820 180 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
c89b6165
KS
181 printf("multicast routing:\n");
182 printf(" %10u multicast route lookup%s\n",
183 mrtstat.mrts_mrt_lookups, plural(mrtstat.mrts_mrt_lookups));
184 printf(" %10u multicast route cache miss%s\n",
185 mrtstat.mrts_mrt_misses, plurales(mrtstat.mrts_mrt_misses));
186 printf(" %10u group address lookup%s\n",
187 mrtstat.mrts_grp_lookups, plural(mrtstat.mrts_grp_lookups));
188 printf(" %10u group address cache miss%s\n",
189 mrtstat.mrts_grp_misses, plurales(mrtstat.mrts_grp_misses));
190 printf(" %10u datagram%s with no route for origin\n",
191 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
192 printf(" %10u datagram%s with malformed tunnel options\n",
193 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
194 printf(" %10u datagram%s with no room for tunnel options\n",
195 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
196}