1 | #if HAVE_CONFIG_H |
---|
2 | #include "config.h" |
---|
3 | #endif |
---|
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/sockio.h> |
---|
13 | #include <sys/mbuf.h> |
---|
14 | #include <net/if.h> |
---|
15 | #include <net/if_var.h> |
---|
16 | #include <net/if_dl.h> |
---|
17 | #include <net/if_types.h> |
---|
18 | #include <netinet/in.h> |
---|
19 | |
---|
20 | #include <rtems/rtems_bsdnet.h> |
---|
21 | |
---|
22 | /* |
---|
23 | * Display an address |
---|
24 | */ |
---|
25 | static int |
---|
26 | showaddress (char *name, struct sockaddr *a) |
---|
27 | { |
---|
28 | struct sockaddr_in *sa; |
---|
29 | char buf[17]; |
---|
30 | |
---|
31 | if (!a) |
---|
32 | return 0; |
---|
33 | printf ("%s:", name); |
---|
34 | sa = (struct sockaddr_in *)a; |
---|
35 | printf ("%-16s", inet_ntop (AF_INET, &sa->sin_addr, buf, sizeof(buf))); |
---|
36 | return 1; |
---|
37 | } |
---|
38 | |
---|
39 | /* |
---|
40 | * Display interface statistics |
---|
41 | */ |
---|
42 | void |
---|
43 | rtems_bsdnet_show_if_stats (void) |
---|
44 | { |
---|
45 | struct ifnet *ifp; |
---|
46 | struct ifaddr *ifa; |
---|
47 | unsigned short bit, flags; |
---|
48 | |
---|
49 | printf ("************ INTERFACE STATISTICS ************\n"); |
---|
50 | for (ifp = ifnet; ifp; ifp = ifp->if_next) { |
---|
51 | printf ("***** %s%d *****\n", ifp->if_name, ifp->if_unit); |
---|
52 | for (ifa = ifp->if_addrlist ; ifa ; ifa = ifa->ifa_next) { |
---|
53 | |
---|
54 | if ( !ifa->ifa_addr ) |
---|
55 | continue; |
---|
56 | |
---|
57 | switch ( ifa->ifa_addr->sa_family ) { |
---|
58 | case AF_LINK: |
---|
59 | { |
---|
60 | struct sockaddr_dl *sdl = (struct sockaddr_dl *)ifa->ifa_addr; |
---|
61 | unsigned char *cp = (unsigned char *)LLADDR(sdl); |
---|
62 | int i; |
---|
63 | |
---|
64 | switch ( sdl->sdl_type ) { |
---|
65 | case IFT_ETHER: |
---|
66 | if ( (i=sdl->sdl_alen) > 0 ) { |
---|
67 | printf("Ethernet Address: "); |
---|
68 | do { |
---|
69 | i--; |
---|
70 | printf("%02X%c", *cp++, i ? ':' : '\n'); |
---|
71 | } while ( i>0 ); |
---|
72 | } |
---|
73 | break; |
---|
74 | |
---|
75 | default: |
---|
76 | break; |
---|
77 | } |
---|
78 | } |
---|
79 | break; |
---|
80 | |
---|
81 | case AF_INET: |
---|
82 | { |
---|
83 | int printed; |
---|
84 | printed = showaddress ("Address", ifa->ifa_addr); |
---|
85 | if (ifp->if_flags & IFF_BROADCAST) |
---|
86 | printed |= showaddress ("Broadcast Address", ifa->ifa_broadaddr); |
---|
87 | if (ifp->if_flags & IFF_POINTOPOINT) |
---|
88 | printed |= showaddress ("Destination Address", ifa->ifa_dstaddr); |
---|
89 | printed |= showaddress ("Net mask", ifa->ifa_netmask); |
---|
90 | if (printed) |
---|
91 | printf ("\n"); |
---|
92 | } |
---|
93 | break; |
---|
94 | |
---|
95 | default: |
---|
96 | break; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | printf ("Flags:"); |
---|
101 | for (bit = 1, flags = ifp->if_flags ; flags ; bit <<= 1) { |
---|
102 | char *cp; |
---|
103 | char xbuf[20]; |
---|
104 | switch (flags & bit) { |
---|
105 | case 0: cp = NULL; break; |
---|
106 | case IFF_UP: cp = "Up"; break; |
---|
107 | case IFF_BROADCAST: cp = "Broadcast"; break; |
---|
108 | case IFF_DEBUG: cp = "Debug"; break; |
---|
109 | case IFF_LOOPBACK: cp = "Loopback"; break; |
---|
110 | case IFF_POINTOPOINT: cp = "Point-to-point"; break; |
---|
111 | case IFF_RUNNING: cp = "Running"; break; |
---|
112 | case IFF_NOARP: cp = "No-ARP"; break; |
---|
113 | case IFF_PROMISC: cp = "Promiscuous"; break; |
---|
114 | case IFF_ALLMULTI: cp = "All-multicast"; break; |
---|
115 | case IFF_OACTIVE: cp = "Active"; break; |
---|
116 | case IFF_SIMPLEX: cp = "Simplex"; break; |
---|
117 | case IFF_LINK0: cp = "Link0"; break; |
---|
118 | case IFF_LINK1: cp = "Link1"; break; |
---|
119 | case IFF_LINK2: cp = "Link2"; break; |
---|
120 | case IFF_MULTICAST: cp = "Multicast"; break; |
---|
121 | default: sprintf (xbuf, "%#x", bit); cp = xbuf; break; |
---|
122 | } |
---|
123 | if (cp) { |
---|
124 | flags &= ~bit; |
---|
125 | printf (" %s", cp); |
---|
126 | } |
---|
127 | } |
---|
128 | printf ("\n"); |
---|
129 | |
---|
130 | printf ("Send queue limit:%-4d length:%-4d Dropped:%-8d\n", |
---|
131 | ifp->if_snd.ifq_maxlen, |
---|
132 | ifp->if_snd.ifq_len, |
---|
133 | ifp->if_snd.ifq_drops); |
---|
134 | |
---|
135 | /* |
---|
136 | * FIXME: Could print if_data statistics here, |
---|
137 | * but right now the drivers maintain their |
---|
138 | * own statistics. |
---|
139 | */ |
---|
140 | |
---|
141 | /* |
---|
142 | * Grab the network semaphore. |
---|
143 | * In most cases this is not necessary, but it's |
---|
144 | * easier to always call the driver ioctl function |
---|
145 | * while holding the semaphore than to try |
---|
146 | * and explain why some ioctl commands are invoked |
---|
147 | * while holding the semaphore and others are |
---|
148 | * invoked while not holding the semaphore. |
---|
149 | */ |
---|
150 | rtems_bsdnet_semaphore_obtain (); |
---|
151 | (*ifp->if_ioctl)(ifp, SIO_RTEMS_SHOW_STATS, NULL); |
---|
152 | rtems_bsdnet_semaphore_release (); |
---|
153 | } |
---|
154 | printf ("\n"); |
---|
155 | } |
---|