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