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