From owner-p4-projects@FreeBSD.ORG Wed Jun 10 14:17:23 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 39C0710656B1; Wed, 10 Jun 2009 14:17:23 +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 EA47B1065670 for ; Wed, 10 Jun 2009 14:17:22 +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 D7BBD8FC20 for ; Wed, 10 Jun 2009 14:17:22 +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 n5AEHM4S070204 for ; Wed, 10 Jun 2009 14:17:22 GMT (envelope-from pgj@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5AEHMq5070202 for perforce@freebsd.org; Wed, 10 Jun 2009 14:17:22 GMT (envelope-from pgj@FreeBSD.org) Date: Wed, 10 Jun 2009 14:17:22 GMT Message-Id: <200906101417.n5AEHMq5070202@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 163997 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 14:17:24 -0000 http://perforce.freebsd.org/chv.cgi?CH=163997 Change 163997 by pgj@petymeg-current on 2009/06/10 14:16:41 Replace st_listening for NETSTAT_SOCKET_ALL, so the application itself does not have to filter the received list (and it more abstract) Affected files ... .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#16 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#14 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#11 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#13 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#8 edit Differences ... ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#16 (text+ko) ==== @@ -14,6 +14,7 @@ #include #define TCPSTATES #include +#include #include #include #include @@ -54,7 +55,7 @@ "#11", "#12", "#13", "#14", "#15", "#16", "udp" }; static int -net_local_pcblist_sysctl(int type, struct socket_type_list *list) +net_local_pcblist_sysctl(int type, struct socket_type_list *list, int flags) { char *buf; size_t len; @@ -100,7 +101,7 @@ } static int -net_inet_pcblist_sysctl(int protocol, struct socket_type_list *list) +net_inet_pcblist_sysctl(int protocol, struct socket_type_list *list, int flags) { char *buf; size_t len; @@ -161,6 +162,18 @@ ) continue; + if ((flags & NETSTAT_SOCKET_ALL) == 0 && + ( + (protocol == IPPROTO_TCP && tp->t_state == TCPS_LISTEN) + || ((inp->inp_vflag & INP_IPV4) != 0 && + inet_lnaof(inp->inp_laddr) == INADDR_ANY) +#ifdef INET6 + || ((inp->inp_vflag & INP_IPV6) != 0 && + IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) +#endif + )) + continue; + stp = _netstat_st_allocate(list, PF_INET, protocol, ipproto[protocol]); extract_inet_data(tp, inp, so, stp); @@ -179,7 +192,7 @@ static int net_local_pcblist_kvm(int type, struct socket_type_list *list, - kvm_t *kvm, struct nlist *nlistp) + kvm_t *kvm, struct nlist *nlistp, int flags) { struct unp_head head; struct unpcb *unp, unp_conn; @@ -247,7 +260,7 @@ static int net_inet_pcblist_kvm(int protocol, struct socket_type_list *list, - kvm_t *kvm, struct nlist *nlistp) + kvm_t *kvm, struct nlist *nlistp, int flags) { /* XXX: to be filled in. */ return (0); @@ -272,15 +285,16 @@ } } -#define NPCB_KVM(family, type, list, kvm, nl) do { \ - if (net_##family##_pcblist_kvm((type), (list), (kvm), (nl)) != 0) { \ +#define NPCB_KVM(family, type, list, kvm, nl, flags) do { \ + if (net_##family##_pcblist_kvm((type), (list), (kvm), (nl), \ + (flags)) != 0) { \ list->stl_error = NETSTAT_ERROR_UNDEFINED; \ return (-1); \ } \ } while (0) -#define NPCB_SCT(family, type, list) do { \ - if (net_##family##_pcblist_sysctl((type), (list)) != 0) { \ +#define NPCB_SCT(family, type, list, flags) do { \ + if (net_##family##_pcblist_sysctl((type), (list), (flags)) != 0) { \ list->stl_error = NETSTAT_ERROR_UNDEFINED; \ return (-1); \ } \ @@ -292,19 +306,21 @@ case SOCK_STREAM: case SOCK_DGRAM: if (use_kvm) - NPCB_KVM(local, type, list, kvm, nl); + NPCB_KVM(local, type, list, kvm, nl, flags); else /* Use sysctl (or something else). */ - NPCB_SCT(local, type, list); + NPCB_SCT(local, type, list, flags); break; /* All PF_LOCAL */ case 0: if (use_kvm) { - NPCB_KVM(local, SOCK_STREAM, list, kvm, nl); - NPCB_KVM(local, SOCK_DGRAM, list, kvm, nl); + NPCB_KVM(local, SOCK_STREAM, list, kvm, nl, + flags); + NPCB_KVM(local, SOCK_DGRAM, list, kvm, nl, + flags); } else { - NPCB_SCT(local, SOCK_STREAM, list); - NPCB_SCT(local, SOCK_DGRAM, list); + NPCB_SCT(local, SOCK_STREAM, list, flags); + NPCB_SCT(local, SOCK_DGRAM, list, flags); } break; default: @@ -317,18 +333,20 @@ case IPPROTO_TCP: case IPPROTO_UDP: if (use_kvm) - NPCB_KVM(inet, protocol, list, kvm, nl); + NPCB_KVM(inet, protocol, list, kvm, nl, flags); else - NPCB_SCT(inet, protocol, list); + NPCB_SCT(inet, protocol, list, flags); break; /* All PF_INET */ case 0: if (use_kvm) { - NPCB_KVM(inet, IPPROTO_TCP, list, kvm, nl); - NPCB_KVM(inet, IPPROTO_UDP, list, kvm, nl); + NPCB_KVM(inet, IPPROTO_TCP, list, kvm, nl, + flags); + NPCB_KVM(inet, IPPROTO_UDP, list, kvm, nl, + flags); } else { - NPCB_SCT(inet, IPPROTO_TCP, list); - NPCB_SCT(inet, IPPROTO_UDP, list); + NPCB_SCT(inet, IPPROTO_TCP, list, flags); + NPCB_SCT(inet, IPPROTO_UDP, list, flags); } break; default: @@ -382,7 +400,6 @@ } else { stp->st_address[0] = '\0'; } - stp->st_listening = 0; stp->st_tcpstate[0] = '\0'; } @@ -423,7 +440,6 @@ stp->XXX_xsocket = *so; /* XXX: address is missing. */ stp->st_address[0] = '\0'; - stp->st_listening = (tp->t_state == TCPS_LISTEN); if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES) sprintf(stp->st_tcpstate, "%d", tp->t_state); else { ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#14 (text+ko) ==== @@ -19,7 +19,8 @@ #define NETSTAT_ERROR_UNSUPPORTED 6 /* Flags for netstat_socket(): */ -#define NETSTAT_SOCKET_KVM 1 /* Use KVM. */ +#define NETSTAT_SOCKET_KVM 0x01 /* Use KVM. */ +#define NETSTAT_SOCKET_ALL 0x02 /* Return all connections. */ struct socket_type; struct socket_type_list; @@ -81,7 +82,6 @@ u_long netstat_st_get_refs(const struct socket_type *stp); u_long netstat_st_get_reflink(const struct socket_type *stp); const char *netstat_st_get_address(const struct socket_type *stp); -int netstat_st_get_listening(const struct socket_type *stp); const char *netstat_st_get_tcpstate(const struct socket_type *stp); /* XXX: Remove this hacks. */ struct tcpcb XXX_netstat_st_get_tcpcb(const struct socket_type *stp); ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#11 (text+ko) ==== @@ -62,7 +62,6 @@ u_long st_reflink; /* link in references list */ char st_address[SOCKTYPE_MAXADDR]; char st_tcpstate[16]; - int st_listening; /* XXX: Removables. */ struct tcpcb XXX_tcpcb; ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#13 (text+ko) ==== @@ -396,12 +396,6 @@ return (stp->st_address); } -int -netstat_st_get_listening(const struct socket_type *stp) -{ - return (stp->st_listening); -} - const char * netstat_st_get_tcpstate(const struct socket_type *stp) { ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#8 (text+ko) ==== @@ -581,6 +581,8 @@ st_flags = 0; if (!live) st_flags |= NETSTAT_SOCKET_KVM; + if (aflag) + st_flags |= NETSTAT_SOCKET_ALL; if (netstat_socket(PF_INET, 0, proto, stlp, st_flags, kvm) < 0) { error = netstat_stl_geterror(stlp); @@ -623,26 +625,6 @@ tp = XXX_netstat_st_get_tcpcb(stp); istcp = 1; } - if (!aflag && - ( - (istcp && netstat_st_get_listening(stp)) - || (netstat_st_get_family(stp) == AF_INET && - inet_lnaof(inp.inp_laddr) == INADDR_ANY) -#ifdef INET6 - || (netstat_st_get_family(stp) == AF_INET6 && - IN6_IS_ADDR_UNSPECIFIED(&inp.in6p_laddr)) -#endif /* INET6 */ - || (netstat_st_get_family(stp) == AF_UNSPEC && - (((inp.inp_vflag & INP_IPV4) != 0 && - inet_lnaof(inp.inp_laddr) == INADDR_ANY) -#ifdef INET6 - || ((inp.inp_vflag & INP_IPV6) != 0 && - IN6_IS_ADDR_UNSPECIFIED(&inp.in6p_laddr)) -#endif - )) - )) - return; - if (first) { if (!Lflag) { printf("Active Internet connections");