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