source: rtems-libbsd/freebsd-userspace/commands/usr.bin/netstat/mroute6.c @ f1710b6

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since f1710b6 was f1710b6, checked in by Joel Sherrill <joel.sherrill@…>, on 09/07/12 at 17:50:18

netstat: New command - Almost completely compiles

Currently disable in Makefile until all builds. Adding it so
others can assist in debugging issues.

  • Property mode set to 100644
File size: 8.6 KB
Line 
1/*-
2 * Copyright (C) 1998 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29/*-
30 * Copyright (c) 1989 Stephen Deering
31 * Copyright (c) 1992, 1993
32 *      The Regents of the University of California.  All rights reserved.
33 *
34 * This code is derived from software contributed to Berkeley by
35 * Stephen Deering of Stanford University.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 *    notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 *    notice, this list of conditions and the following disclaimer in the
44 *    documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 *    must display the following acknowledgement:
47 *      This product includes software developed by the University of
48 *      California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 *    may be used to endorse or promote products derived from this software
51 *    without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 *      @(#)mroute.c    8.2 (Berkeley) 4/28/95
66 */
67
68#include <sys/cdefs.h>
69__FBSDID("$FreeBSD$");
70
71#ifdef INET6
72#include <sys/param.h>
73#include <sys/queue.h>
74#include <sys/socket.h>
75#include <sys/socketvar.h>
76#include <sys/sysctl.h>
77#ifdef __rtems__
78#include <freebsd/sys/protosw.h>
79#else
80#include <sys/protosw.h>
81#endif
82#ifdef __rtems__
83#include <freebsd/sys/mbuf.h>
84#else
85#include <sys/mbuf.h>
86#endif
87#include <sys/time.h>
88
89#include <net/if.h>
90#include <net/if_var.h>
91#include <net/route.h>
92
93#include <netinet/in.h>
94
95#include <err.h>
96#include <stdint.h>
97#include <stdio.h>
98#include <stdlib.h>
99
100#define KERNEL 1
101#include <netinet6/ip6_mroute.h>
102#undef KERNEL
103
104#include "netstat.h"
105
106#define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */
107#define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */
108
109void
110mroute6pr(u_long mfcaddr, u_long mifaddr)
111{
112        struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
113        struct mif6 mif6table[MAXMIFS];
114        struct mf6c mfc;
115        struct rtdetq rte, *rtep;
116        struct mif6 *mifp;
117        mifi_t mifi;
118        int i;
119        int banner_printed;
120        int saved_numeric_addr;
121        mifi_t maxmif = 0;
122        long int waitings;
123        size_t len;
124
125        len = sizeof(mif6table);
126        if (live) {
127                if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len,
128                    NULL, 0) < 0) {
129                        warn("sysctl: net.inet6.ip6.mif6table");
130                        return;
131                }
132        } else
133                kread(mifaddr, (char *)mif6table, sizeof(mif6table));
134
135        saved_numeric_addr = numeric_addr;
136        numeric_addr = 1;
137        banner_printed = 0;
138
139        for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
140                struct ifnet ifnet;
141                char ifname[IFNAMSIZ];
142
143                if (mifp->m6_ifp == NULL)
144                        continue;
145
146                /* XXX KVM */
147                kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
148
149                maxmif = mifi;
150                if (!banner_printed) {
151                        printf("\nIPv6 Multicast Interface Table\n"
152                               " Mif   Rate   PhyIF   "
153                               "Pkts-In   Pkts-Out\n");
154                        banner_printed = 1;
155                }
156
157                printf("  %2u   %4d",
158                       mifi, mifp->m6_rate_limit);
159                printf("   %5s", (mifp->m6_flags & MIFF_REGISTER) ?
160                       "reg0" : if_indextoname(ifnet.if_index, ifname));
161
162                printf(" %9ju  %9ju\n", (uintmax_t)mifp->m6_pkt_in,
163                    (uintmax_t)mifp->m6_pkt_out);
164        }
165        if (!banner_printed)
166                printf("\nIPv6 Multicast Interface Table is empty\n");
167
168        len = sizeof(mf6ctable);
169        if (live) {
170                if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len,
171                    NULL, 0) < 0) {
172                        warn("sysctl: net.inet6.ip6.mf6ctable");
173                        return;
174                }
175        } else
176                kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable));
177
178        banner_printed = 0;
179
180        for (i = 0; i < MF6CTBLSIZ; ++i) {
181                mfcp = mf6ctable[i];
182                while(mfcp) {
183                        kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
184                        if (!banner_printed) {
185                                printf ("\nIPv6 Multicast Forwarding Cache\n");
186                                printf(" %-*.*s %-*.*s %s",
187                                       WID_ORG, WID_ORG, "Origin",
188                                       WID_GRP, WID_GRP, "Group",
189                                       "  Packets Waits In-Mif  Out-Mifs\n");
190                                banner_printed = 1;
191                        }
192
193                        printf(" %-*.*s", WID_ORG, WID_ORG,
194                               routename6(&mfc.mf6c_origin));
195                        printf(" %-*.*s", WID_GRP, WID_GRP,
196                               routename6(&mfc.mf6c_mcastgrp));
197                        printf(" %9ju", (uintmax_t)mfc.mf6c_pkt_cnt);
198
199                        for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
200                                waitings++;
201                                /* XXX KVM */
202                                kread((u_long)rtep, (char *)&rte, sizeof(rte));
203                                rtep = rte.next;
204                        }
205                        printf("   %3ld", waitings);
206
207                        if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
208                                printf(" ---   ");
209                        else
210                                printf("  %3d   ", mfc.mf6c_parent);
211                        for (mifi = 0; mifi <= maxmif; mifi++) {
212                                if (IF_ISSET(mifi, &mfc.mf6c_ifset))
213                                        printf(" %u", mifi);
214                        }
215                        printf("\n");
216
217                        mfcp = mfc.mf6c_next;
218                }
219        }
220        if (!banner_printed)
221                printf("\nIPv6 Multicast Forwarding Table is empty\n");
222
223        printf("\n");
224        numeric_addr = saved_numeric_addr;
225}
226
227void
228mrt6_stats(u_long mstaddr)
229{
230        struct mrt6stat mrtstat;
231        size_t len = sizeof mrtstat;
232
233        if (live) {
234                if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len,
235                    NULL, 0) < 0) {
236                        warn("sysctl: net.inet6.ip6.mrt6stat");
237                        return;
238                }
239        } else
240                kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
241
242        printf("IPv6 multicast forwarding:\n");
243
244#define p(f, m) if (mrtstat.f || sflag <= 1) \
245        printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f))
246#define p2(f, m) if (mrtstat.f || sflag <= 1) \
247        printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f))
248
249        p(mrt6s_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n");
250        p2(mrt6s_mfc_misses, "\t%ju multicast forwarding cache miss%s\n");
251        p(mrt6s_upcalls, "\t%ju upcall%s to multicast routing daemon\n");
252        p(mrt6s_upq_ovflw, "\t%ju upcall queue overflow%s\n");
253        p(mrt6s_upq_sockfull,
254            "\t%ju upcall%s dropped due to full socket buffer\n");
255        p(mrt6s_cache_cleanups, "\t%ju cache cleanup%s\n");
256        p(mrt6s_no_route, "\t%ju datagram%s with no route for origin\n");
257        p(mrt6s_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n");
258        p(mrt6s_cant_tunnel, "\t%ju datagram%s could not be tunneled\n");
259        p(mrt6s_wrong_if, "\t%ju datagram%s arrived on wrong interface\n");
260        p(mrt6s_drop_sel, "\t%ju datagram%s selectively dropped\n");
261        p(mrt6s_q_overflow,
262            "\t%ju datagram%s dropped due to queue overflow\n");
263        p(mrt6s_pkt2large, "\t%ju datagram%s dropped for being too large\n");
264
265#undef  p2
266#undef  p
267}
268#endif /*INET6*/
Note: See TracBrowser for help on using the repository browser.