PERFORCE change 79944 for review
soc-anders
soc-anders at FreeBSD.org
Sun Jul 10 23:42:15 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=79944
Change 79944 by soc-anders at soc-anders_gimli on 2005/07/10 23:41:12
Multicast information (-a switch) now works and all if_var.h
references have been removed from if.c. Request count info
(ifmultiaddr.ifma_refcount) is currently not available.
Affected files ...
.. //depot/projects/soc2005/ifcleanup/src/src/usr.bin/netstat/if.c#4 edit
Differences ...
==== //depot/projects/soc2005/ifcleanup/src/src/usr.bin/netstat/if.c#4 (text+ko) ====
@@ -52,9 +52,7 @@
#include <net/bridge.h>
#include <net/ethernet.h>
#include <netinet/in.h>
-/*#include <netinet/in_var.h>*/
#include <netipx/ipx.h>
-/*#include <netipx/ipx_if.h>*/
#include <arpa/inet.h>
#include <signal.h>
@@ -175,7 +173,8 @@
struct if_msghdr *ifm;
struct ifa_msghdr *ifam;
struct sockaddr *addr, *mask, *brd;
- u_long mtu;
+ u_long if_mtu;
+ int if_index;
if (_interval) {
sidewaysintpr((unsigned)_interval, ifnetaddr);
@@ -186,6 +185,7 @@
return;
if ((buf = malloc(len)) == NULL) {
printf("malloc\n");
+ free(buf);
return;
}
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
@@ -247,7 +247,8 @@
*cp++ = '*';
*cp = '\0';
}
- mtu = ifm->ifm_data.ifi_mtu;
+ if_mtu = ifm->ifm_data.ifi_mtu;
+ if_index = ifm->ifm_index;
} else if (ifm->ifm_type == RTM_NEWADDR) {
int addrs = ifm->ifm_addrs;
@@ -305,7 +306,7 @@
printf("%-7.7s", name);
else
printf("%-5.5s", name);
- printf(" %5lu ", mtu);
+ printf(" %5lu ", if_mtu);
switch (addr->sa_family) {
case AF_UNSPEC:
printf("%-13.13s ", "none");
@@ -444,16 +445,11 @@
show_stat("d", 3, drops, link_layer);
}
putchar('\n');
- /* IFCLEANUP
- * Skip mcast for now
- */
-#if 0
- if (aflag && ifaddrfound) {
+
+ if (aflag) {
/*
* Print family's multicast addresses
*/
- struct ifmultiaddr *multiaddr;
- struct ifmultiaddr ifma;
union {
struct sockaddr sa;
struct sockaddr_in in;
@@ -461,20 +457,49 @@
struct sockaddr_in6 in6;
#endif /* INET6 */
struct sockaddr_dl dl;
- } msa;
+ } msa;
const char *fmt;
+ struct ifma_msghdr *ifmam;
+ char *mbuf, *mcur, *mend;
+ size_t mlen;
- TAILQ_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) {
- if (kread((u_long)multiaddr, (char *)&ifma,
- sizeof ifma))
- break;
- multiaddr = &ifma;
- if (kread((u_long)ifma.ifma_addr, (char *)&msa,
- sizeof msa))
- break;
- if (msa.sa.sa_family != sa->sa_family)
- continue;
-
+ /* Request only the mcast MIB for the current if and af */
+ mib[3] = addr->sa_family;
+ mib[4] = NET_RT_IFMALIST;
+ mib[5] = if_index;
+ if (sysctl(mib, 6, NULL, &mlen, NULL, 0) < 0)
+ continue;
+ if ((mbuf = malloc(mlen)) == NULL) {
+ printf("malloc\n");
+ exit(1);
+ }
+ if (sysctl(mib, 6, mbuf, &mlen, NULL, 0) < 0) {
+ free(mbuf);
+ continue;
+ }
+
+ mcur = mbuf;
+ mend = mcur + mlen;
+ while (mcur < mend) {
+ ifmam = (struct ifma_msghdr *)mcur;
+ int addrs = ifmam->ifmam_addrs;
+ mcur += sizeof(*ifmam);
+ while (addrs != 0) {
+ struct sockaddr *tmp =
+ (struct sockaddr *)mcur;
+ mcur += SA_SIZE(tmp);
+ if (addrs & RTA_GATEWAY)
+ addrs &= ~RTA_GATEWAY;
+ else if (addrs & RTA_IFP)
+ addrs &= ~RTA_IFP;
+ else if (addrs & RTA_IFA) {
+ bcopy(tmp, &msa, tmp->sa_len);
+ addrs &= ~RTA_IFA;
+ } else {
+ printf("UNEXPECTED: %x\n", addrs);
+ continue;
+ }
+ }
fmt = 0;
switch (msa.sa.sa_family) {
case AF_INET:
@@ -488,7 +513,11 @@
&msa.in6.sin6_addr,
ntop_buf,
sizeof(ntop_buf)),
- ifma.ifma_refcount);
+ /* IFCLEANUP
+ * ifma.ifma_refcount
+ */
+ 0);
+
break;
#endif /* INET6 */
case AF_LINK:
@@ -515,7 +544,6 @@
}
}
}
-#endif /* if 0 */
}
}
More information about the p4-projects
mailing list