From owner-p4-projects@FreeBSD.ORG Wed Jun 10 10:37:27 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 223591065687; Wed, 10 Jun 2009 10:37:27 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D0FEF10656A4 for ; Wed, 10 Jun 2009 10:37:26 +0000 (UTC) (envelope-from pgj@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id BEC878FC21 for ; Wed, 10 Jun 2009 10:37:26 +0000 (UTC) (envelope-from pgj@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n5AAbQLF037262 for ; Wed, 10 Jun 2009 10:37:26 GMT (envelope-from pgj@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5AAbQfA037260 for perforce@freebsd.org; Wed, 10 Jun 2009 10:37:26 GMT (envelope-from pgj@FreeBSD.org) Date: Wed, 10 Jun 2009 10:37:26 GMT Message-Id: <200906101037.n5AAbQfA037260@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to pgj@FreeBSD.org using -f From: Gabor Pali To: Perforce Change Reviews Cc: Subject: PERFORCE change 163965 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: Wed, 10 Jun 2009 10:37:28 -0000 http://perforce.freebsd.org/chv.cgi?CH=163965 Change 163965 by pgj@petymeg-current on 2009/06/10 10:37:14 Some code re-organization Affected files ... .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#11 edit Differences ... ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#11 (text+ko) ==== @@ -99,6 +99,74 @@ } static int +net_inet_pcblist_sysctl(int protocol, struct socket_type_list *list) +{ + char *buf; + size_t len; + char mibvar[64]; + + struct xinpgen *xig, *oxig; + struct tcpcb *tp = NULL; + struct inpcb *inp; + struct xsocket *so; + + struct socket_type *stp; + + sprintf(mibvar, "net.inet.%s.pcblist", ipproto[protocol]); + + len = 0; + if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) { + if (errno != ENOENT) + warn("sysctl: %s", mibvar); + return (-1); + } + if ((buf = malloc(len)) == 0) { + warnx("malloc %lu bytes", (u_long)len); + return (-2); + } + if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) { + warn("sysctl: %s", mibvar); + free(buf); + return (-2); + } + + oxig = xig = (struct xinpgen *)buf; + for (xig = (struct xinpgen *)((char *)xig + xig->xig_len); + xig->xig_len > sizeof(struct xinpgen); + xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { + if (protocol == IPPROTO_TCP) { + tp = &((struct xtcpcb *)xig)->xt_tp; + inp = &((struct xtcpcb *)xig)->xt_inp; + so = &((struct xtcpcb *)xig)->xt_socket; + } else { + inp = &((struct xinpcb *)xig)->xi_inp; + so = &((struct xinpcb *)xig)->xi_socket; + } + + /* Ignore sockets for protocols other than the desired one. + XXX: is this needed? */ + if (so->xso_protocol != protocol) + continue; + + if (inp->inp_gencnt <= oxig->xig_gen) { + stp = _netstat_st_allocate(list, PF_INET, protocol, + ipproto[protocol]); + extract_inet_data(tp, inp, so, stp); + } + } + + free(buf); + return (0); +} + +#define KREAD(off, buf, len) do { \ + if (kread(kvm, (uintptr_t)(off), (buf), (len)) != 0) { \ + list->stl_error = NETSTAT_ERROR_UNDEFINED; \ + return (-1); \ + } \ +} while (0); + +static int net_local_pcblist_kvm(int type, struct socket_type_list *list, kvm_t *kvm, struct nlist *nlistp) { @@ -131,13 +199,6 @@ return (-1); } -#define KREAD(off, buf, len) do { \ - if (kread(kvm, (uintptr_t)(off), (buf), (len)) != 0) { \ - list->stl_error = NETSTAT_ERROR_UNDEFINED; \ - return (-1); \ - } \ -} while (0); - KREAD(count_off, &unp_count, sizeof(unp_count)); KREAD(gencnt_off, &unp_gencnt, sizeof(unp_gencnt)); KREAD(head_off, &head, sizeof(head)); @@ -171,71 +232,9 @@ } return (0); -#undef KREAD } static int -net_inet_pcblist_sysctl(int protocol, struct socket_type_list *list) -{ - char *buf; - size_t len; - char mibvar[64]; - - struct xinpgen *xig, *oxig; - struct tcpcb *tp = NULL; - struct inpcb *inp; - struct xsocket *so; - - struct socket_type *stp; - - sprintf(mibvar, "net.inet.%s.pcblist", ipproto[protocol]); - - len = 0; - if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) { - if (errno != ENOENT) - warn("sysctl: %s", mibvar); - return (-1); - } - if ((buf = malloc(len)) == 0) { - warnx("malloc %lu bytes", (u_long)len); - return (-2); - } - if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) { - warn("sysctl: %s", mibvar); - free(buf); - return (-2); - } - - oxig = xig = (struct xinpgen *)buf; - for (xig = (struct xinpgen *)((char *)xig + xig->xig_len); - xig->xig_len > sizeof(struct xinpgen); - xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { - if (protocol == IPPROTO_TCP) { - tp = &((struct xtcpcb *)xig)->xt_tp; - inp = &((struct xtcpcb *)xig)->xt_inp; - so = &((struct xtcpcb *)xig)->xt_socket; - } else { - inp = &((struct xinpcb *)xig)->xi_inp; - so = &((struct xinpcb *)xig)->xi_socket; - } - - /* Ignore sockets for protocols other than the desired one. - XXX: is this needed? */ - if (so->xso_protocol != protocol) - continue; - - if (inp->inp_gencnt <= oxig->xig_gen) { - stp = _netstat_st_allocate(list, PF_INET, protocol, - ipproto[protocol]); - extract_inet_data(tp, inp, so, stp); - } - } - - free(buf); - return (0); -} - -static int net_inet_pcblist_kvm(int protocol, struct socket_type_list *list, kvm_t *kvm, struct nlist *nlistp) { @@ -243,6 +242,8 @@ return (0); } +#undef KREAD + int netstat_socket(int domain, int type, int protocol, struct socket_type_list *list, int flags, void *kvm_handle)