From owner-p4-projects@FreeBSD.ORG Sun Jul 10 23:42:15 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7BCE816A420; Sun, 10 Jul 2005 23:42:14 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3F1B116A41C for ; Sun, 10 Jul 2005 23:42:14 +0000 (GMT) (envelope-from soc-anders@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id E373343D48 for ; Sun, 10 Jul 2005 23:42:13 +0000 (GMT) (envelope-from soc-anders@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j6ANgDCG043159 for ; Sun, 10 Jul 2005 23:42:13 GMT (envelope-from soc-anders@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6ANgD8N043156 for perforce@freebsd.org; Sun, 10 Jul 2005 23:42:13 GMT (envelope-from soc-anders@freebsd.org) Date: Sun, 10 Jul 2005 23:42:13 GMT Message-Id: <200507102342.j6ANgD8N043156@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-anders@freebsd.org using -f From: soc-anders To: Perforce Change Reviews Cc: Subject: PERFORCE change 79944 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jul 2005 23:42:15 -0000 http://perforce.freebsd.org/chv.cgi?CH=79944 Change 79944 by soc-anders@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 #include #include -/*#include */ #include -/*#include */ #include #include @@ -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 */ } }