Include missing data structure definitions.
[unix-history] / usr.bin / netstat / mroute.c
CommitLineData
06131096
JH
1/*
2 * Print DVMRP multicast routing structures and statistics.
3 *
4 * MROUTING 1.0
5 */
6
7#include <stdio.h>
8#include <sys/param.h>
9#include <sys/mbuf.h>
10#include <netinet/in.h>
11#include <netinet/igmp.h>
12#define KERNEL 1
136e01b9 13#include <sys/socketvar.h>
06131096
JH
14#include <netinet/ip_mroute.h>
15#undef KERNEL
16
17extern int kmem;
18extern int nflag;
19extern char *routename();
20extern char *netname();
21extern char *plural();
22
23char *plurales(n)
24 int n;
25{
26 return (n == 1? "" : "es");
27}
28
29mroutepr(mrpaddr, mrtaddr, vifaddr)
30 off_t mrpaddr, mrtaddr, vifaddr;
31{
32 u_int mrtproto;
33#if BSD >= 199006
34 struct mrt *mrttable[MRTHASHSIZ];
35 struct mrt *mp;
36 struct mrt mb;
37 struct mrt *mrt = &mb;
38#else
39 struct mbuf *mrttable[MRTHASHSIZ];
40 struct mbuf *mp;
41 struct mbuf mb;
42 struct mrt *mrt = mtod(&mb, struct mrt *);
43#endif
44 struct vif viftable[MAXVIFS];
45 register struct vif *v;
46 register vifi_t vifi;
47 struct in_addr *grp;
48 int i, n;
49 int banner_printed;
50 int saved_nflag;
51
52 if(mrpaddr == 0) {
53 printf("ip_mrtproto: symbol not in namelist\n");
54 return;
55 }
56
57 kvm_read(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
58 switch (mrtproto) {
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
83 kvm_read(vifaddr, (char *)viftable, sizeof(viftable));
84 banner_printed = 0;
85 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
86 struct in_addr v_lcl_grps[1024];
87
88 if (v->v_lcl_addr.s_addr == 0) continue;
89
90 if (!banner_printed) {
91 printf("\nVirtual Interface Table\n%s%s",
92 " Vif Threshold Local-Address ",
93 "Remote-Address Groups\n");
94 banner_printed = 1;
95 }
96
97 printf(" %2u %3u %-15.15s",
98 vifi, v->v_threshold, routename(v->v_lcl_addr));
99 printf(" %-15.15s\n",
100 (v->v_flags & VIFF_TUNNEL) ?
101 routename(v->v_rmt_addr) : "");
102
103 n = v->v_lcl_grps_n;
104 if (n == 0)
105 continue;
106 if (n < 0 || n > 1024)
107 printf("[v_lcl_grps_n = %d!]\n", n);
108
109 kvm_read(v->v_lcl_grps, (char *)v_lcl_grps,
110 n * sizeof(struct in_addr));
111 for (i = 0; i < n; ++i)
112 printf("%51s %-15.15s\n", "",
113 routename(v_lcl_grps[i]));
114 }
115 if (!banner_printed) printf("\nVirtual Interface Table is empty\n");
116
117 kvm_read(mrtaddr, (char *)mrttable, sizeof(mrttable));
118 banner_printed = 0;
119 for (i = 0; i < MRTHASHSIZ; ++i) {
120 for (mp = mrttable[i]; mp != NULL;
121#if BSD >= 199006
122 mp = mb.mrt_next
123#else
124 mp = mb.m_next
125#endif
126 ) {
127
128 if (!banner_printed) {
129 printf("\nMulticast Routing Table\n%s",
130 " Hash Origin-Subnet In-Vif Out-Vifs\n");
131 banner_printed = 1;
132 }
133 kvm_read(mp, (char *)&mb, sizeof(mb));
134
135
136 printf(" %3u %-15.15s %2u ",
137 i,
138 netname(mrt->mrt_origin.s_addr,
139 ntohl(mrt->mrt_originmask.s_addr)),
140 mrt->mrt_parent);
141 for (vifi = 0; vifi < MAXVIFS; ++vifi) {
142 if (viftable[vifi].v_lcl_addr.s_addr) {
143 if (VIFM_ISSET(vifi, mrt->mrt_children)) {
144 printf(" %u%c",
145 vifi,
146 VIFM_ISSET(vifi,
147 mrt->mrt_leaves) ?
148 '*' : ' ');
149 } else
150 printf(" ");
151 }
152 }
153 printf("\n");
154 }
155 }
156 if (!banner_printed) printf("\nMulticast Routing Table is empty\n");
157
158 printf("\n");
159 nflag = saved_nflag;
160}
161
162
163mrt_stats(mrpaddr, mstaddr)
164 off_t mrpaddr, mstaddr;
165{
166 u_int mrtproto;
167 struct mrtstat mrtstat;
168
169 if(mrpaddr == 0) {
170 printf("ip_mrtproto: symbol not in namelist\n");
171 return;
172 }
173
174 kvm_read(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
175 switch (mrtproto) {
176 case 0:
177 printf("no multicast routing compiled into this system\n");
178 return;
179
180 case IGMP_DVMRP:
181 break;
182
183 default:
184 printf("multicast routing protocol %u, unknown\n", mrtproto);
185 return;
186 }
187
188 if (mstaddr == 0) {
189 printf("mrtstat: symbol not in namelist\n");
190 return;
191 }
192
193 kvm_read(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
194 printf("multicast routing:\n");
195 printf(" %10u multicast route lookup%s\n",
196 mrtstat.mrts_mrt_lookups, plural(mrtstat.mrts_mrt_lookups));
197 printf(" %10u multicast route cache miss%s\n",
198 mrtstat.mrts_mrt_misses, plurales(mrtstat.mrts_mrt_misses));
199 printf(" %10u group address lookup%s\n",
200 mrtstat.mrts_grp_lookups, plural(mrtstat.mrts_grp_lookups));
201 printf(" %10u group address cache miss%s\n",
202 mrtstat.mrts_grp_misses, plurales(mrtstat.mrts_grp_misses));
203 printf(" %10u datagram%s with no route for origin\n",
204 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
205 printf(" %10u datagram%s with malformed tunnel options\n",
206 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
207 printf(" %10u datagram%s with no room for tunnel options\n",
208 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
209 printf(" %10u datagram%s arrived on wrong interface\n",
210 mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
211}