1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #include <sys/param.h> |
---|
6 | #include <sys/queue.h> |
---|
7 | #include <sys/systm.h> |
---|
8 | #include <sys/kernel.h> |
---|
9 | #include <sys/sysctl.h> |
---|
10 | #include <sys/proc.h> |
---|
11 | #include <sys/socket.h> |
---|
12 | #include <sys/ioctl.h> |
---|
13 | #include <net/if.h> |
---|
14 | #include <netinet/in.h> |
---|
15 | |
---|
16 | /* |
---|
17 | * Display an address |
---|
18 | */ |
---|
19 | static int |
---|
20 | showaddress (char *name, struct sockaddr *a) |
---|
21 | { |
---|
22 | struct sockaddr_in *sa; |
---|
23 | |
---|
24 | if (!a || (a->sa_family != AF_INET)) |
---|
25 | return 0; |
---|
26 | printf ("%s:", name); |
---|
27 | sa = (struct sockaddr_in *)a; |
---|
28 | printf ("%-16s", inet_ntoa (sa->sin_addr)); |
---|
29 | return 1; |
---|
30 | } |
---|
31 | |
---|
32 | /* |
---|
33 | * Display interface statistics |
---|
34 | */ |
---|
35 | void |
---|
36 | rtems_bsdnet_show_if_stats (void) |
---|
37 | { |
---|
38 | struct ifnet *ifp; |
---|
39 | struct ifaddr *ifa; |
---|
40 | unsigned short bit, flags; |
---|
41 | int printed; |
---|
42 | |
---|
43 | printf ("************ INTERFACE STATISTICS ************\n"); |
---|
44 | for (ifp = ifnet; ifp; ifp = ifp->if_next) { |
---|
45 | printf ("***** %s%d *****\n", ifp->if_name, ifp->if_unit); |
---|
46 | for (ifa = ifp->if_addrlist ; ifa ; ifa = ifa->ifa_next) { |
---|
47 | printed = showaddress ("Address", ifa->ifa_addr); |
---|
48 | if (ifp->if_flags & IFF_BROADCAST) |
---|
49 | printed |= showaddress ("Broadcast Address", ifa->ifa_broadaddr); |
---|
50 | if (ifp->if_flags & IFF_POINTOPOINT) |
---|
51 | printed |= showaddress ("Destination Address", ifa->ifa_dstaddr); |
---|
52 | printed |= showaddress ("Net mask", ifa->ifa_netmask); |
---|
53 | if (printed) |
---|
54 | printf ("\n"); |
---|
55 | } |
---|
56 | |
---|
57 | printf ("Flags:"); |
---|
58 | for (bit = 1, flags = ifp->if_flags ; flags ; bit <<= 1) { |
---|
59 | char *cp; |
---|
60 | char xbuf[20]; |
---|
61 | switch (flags & bit) { |
---|
62 | case 0: cp = NULL; break; |
---|
63 | case IFF_UP: cp = "Up"; break; |
---|
64 | case IFF_BROADCAST: cp = "Broadcast"; break; |
---|
65 | case IFF_DEBUG: cp = "Debug"; break; |
---|
66 | case IFF_LOOPBACK: cp = "Loopback"; break; |
---|
67 | case IFF_POINTOPOINT: cp = "Point-to-point"; break; |
---|
68 | case IFF_RUNNING: cp = "Running"; break; |
---|
69 | case IFF_NOARP: cp = "No-ARP"; break; |
---|
70 | case IFF_PROMISC: cp = "Promiscuous"; break; |
---|
71 | case IFF_ALLMULTI: cp = "All-multicast"; break; |
---|
72 | case IFF_OACTIVE: cp = "Active"; break; |
---|
73 | case IFF_SIMPLEX: cp = "Simplex"; break; |
---|
74 | case IFF_LINK0: cp = "Link0"; break; |
---|
75 | case IFF_LINK1: cp = "Link1"; break; |
---|
76 | case IFF_LINK2: cp = "Link2"; break; |
---|
77 | case IFF_MULTICAST: cp = "Multicast"; break; |
---|
78 | default: sprintf (xbuf, "%#x", bit); cp = xbuf; break; |
---|
79 | } |
---|
80 | if (cp) { |
---|
81 | flags &= ~bit; |
---|
82 | printf (" %s", cp); |
---|
83 | } |
---|
84 | } |
---|
85 | printf ("\n"); |
---|
86 | |
---|
87 | printf ("Send queue limit:%-4d length:%-4d Dropped:%-8d\n", |
---|
88 | ifp->if_snd.ifq_maxlen, |
---|
89 | ifp->if_snd.ifq_len, |
---|
90 | ifp->if_snd.ifq_drops); |
---|
91 | |
---|
92 | /* |
---|
93 | * FIXME: Could print if_data statistics here, |
---|
94 | * but right now the drivers maintain their |
---|
95 | * own statistics. |
---|
96 | */ |
---|
97 | |
---|
98 | /* |
---|
99 | * Grab the network semaphore. |
---|
100 | * In most cases this is not necessary, but it's |
---|
101 | * easier to always call the driver ioctl function |
---|
102 | * while holding the semaphore than to try |
---|
103 | * and explain why some ioctl commands are invoked |
---|
104 | * while holding the semaphore and others are |
---|
105 | * invoked while not holding the semaphore. |
---|
106 | */ |
---|
107 | rtems_bsdnet_semaphore_obtain (); |
---|
108 | (*ifp->if_ioctl)(ifp, SIO_RTEMS_SHOW_STATS, NULL); |
---|
109 | rtems_bsdnet_semaphore_release (); |
---|
110 | } |
---|
111 | printf ("\n"); |
---|
112 | } |
---|