From owner-p4-projects@FreeBSD.ORG Wed Aug 5 20:45:24 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id B9B7C1065670; Wed, 5 Aug 2009 20:45: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 794D0106566B for ; Wed, 5 Aug 2009 20:45:23 +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 673428FC1B for ; Wed, 5 Aug 2009 20:45:23 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n75KjNcF099115 for ; Wed, 5 Aug 2009 20:45:23 GMT (envelope-from pgj@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n75KjNbG099113 for perforce@freebsd.org; Wed, 5 Aug 2009 20:45:23 GMT (envelope-from pgj@FreeBSD.org) Date: Wed, 5 Aug 2009 20:45:23 GMT Message-Id: <200908052045.n75KjNbG099113@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 167051 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, 05 Aug 2009 20:45:24 -0000 http://perforce.freebsd.org/chv.cgi?CH=167051 Change 167051 by pgj@petymeg-current on 2009/08/05 20:44:26 - Introduce session_type, as a possibility for handling multiple network stack instances (in the future) and create access to the kernel in a more abstract way (suggested by: rwatson). - Move an IPsec-related section into an #ifdef in netstat.h, because it caused problems when compiling applications. - Chase the API changes in the applications. Affected files ... .. //depot/projects/soc2009/pgj_libstat/src/contrib/bsnmp/snmp_mibII/mibII_tcp.c#5 edit .. //depot/projects/soc2009/pgj_libstat/src/contrib/bsnmp/snmp_mibII/mibII_udp.c#5 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#58 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_bpf.c#2 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_if.c#4 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#55 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_mbuf.c#3 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_socket.c#3 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_stat.c#25 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#63 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/bpf.c#4 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#35 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/if.c#5 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#33 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#45 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/mbuf.c#4 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/unix.c#21 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/nettop/main.c#12 edit Differences ... ==== //depot/projects/soc2009/pgj_libstat/src/contrib/bsnmp/snmp_mibII/mibII_tcp.c#5 (text+ko) ==== @@ -72,11 +72,14 @@ struct socket_type_iterator *stip; const struct socket_type *stp; struct sockaddr_type *satp; + struct session_type *session; int error; struct in_addr in; in_addr_t inaddr; + session = netstat_session_new(NULL); + len = sizeof(tcpstat); if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len, NULL, 0) == -1) { syslog(LOG_ERR, "net.inet.tcp.stats: %m"); @@ -92,8 +95,8 @@ syslog(LOG_ERR, "netstat_stl_alloc() in fetch_tcp()"); return (-1); } - if (netstat_socket(PF_INET, 0, IPPROTO_TCP, stlp, NETSTAT_SOCKET_ALL, - NULL) < 0) { + if (netstat_socket(session, PF_INET, 0, IPPROTO_TCP, stlp, + NETSTAT_SOCKET_ALL) < 0) { error = netstat_stl_geterror(stlp); syslog(LOG_ERR, "netstat_socket: %s", netstat_strerror(error)); return (-1); @@ -155,6 +158,7 @@ qsort(tcpoids, tcp_total, sizeof(tcpoids[0]), tcp_compare); netstat_sti_free(stip); netstat_stl_free(stlp); + netstat_session_free(session); return (0); } ==== //depot/projects/soc2009/pgj_libstat/src/contrib/bsnmp/snmp_mibII/mibII_udp.c#5 (text+ko) ==== @@ -63,12 +63,15 @@ struct socket_type_iterator *stip; const struct socket_type *stp; struct sockaddr_type *satp; + struct session_type *session; int error; struct asn_oid *oid; struct in_addr in; in_addr_t inaddr; + session = netstat_session_new(NULL); + len = sizeof(udpstat); if (sysctlbyname("net.inet.udp.stats", &udpstat, &len, NULL, 0) == -1) { syslog(LOG_ERR, "net.inet.udp.stats: %m"); @@ -84,8 +87,8 @@ syslog(LOG_ERR, "netstat_stl_alloc() in fetch_udp()"); return (-1); } - if (netstat_socket(PF_INET, 0, IPPROTO_UDP, stlp, NETSTAT_SOCKET_ALL, - NULL) < 0) { + if (netstat_socket(session, PF_INET, 0, IPPROTO_UDP, stlp, + NETSTAT_SOCKET_ALL) < 0) { error = netstat_stl_geterror(stlp); syslog(LOG_ERR, "netstat_socket: %s", netstat_strerror(error)); return (-1); @@ -129,6 +132,7 @@ qsort(udpoids, udp_total, sizeof(udpoids[0]), udp_compare); netstat_sti_free(stip); netstat_stl_free(stlp); + netstat_session_free(session); return (0); } ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#58 (text+ko) ==== @@ -60,22 +60,11 @@ #define NETSTAT_ERROR_INVALID 7 /* Flags for netstat_socket(): */ -#define NETSTAT_SOCKET_KVM 0x01 /* Use KVM. */ -#define NETSTAT_SOCKET_ALL 0x02 /* Return all connections. */ - -/* netstat_mbuf(): */ -#define NETSTAT_MBUF_KVM 0x01 +#define NETSTAT_SOCKET_ALL 0x01 /* Return all connections. */ /* netstat_interface(): */ -#define NETSTAT_INTERFACE_KVM 0x01 -#define NETSTAT_INTERFACE_ALL 0x02 - -/* netstat_bpf(): */ -#define NETSTAT_BPF_KVM 0x01 +#define NETSTAT_INTERFACE_ALL 0x01 -/* netstat_stat(): */ -#define NETSTAT_STAT_KVM 0x01 - /* Testing flags for interface_type: */ #define NETSTAT_IF_UP 0x01 /* interface is up */ @@ -137,11 +126,13 @@ bpfdir_MAX, }; +#ifdef IPSEC enum pfkey_msgtarget { pfkey_Sendup_One = KEY_SENDUP_ONE, pfkey_Sendup_All = KEY_SENDUP_ALL, pfkey_Sendup_Registered = KEY_SENDUP_REGISTERED, }; +#endif /* !IPSEC */ enum stat { stat_TCP = 0, @@ -182,6 +173,8 @@ stat_Invalid, }; +struct session_type; + struct socket_type; struct sockaddr_type; struct sockbuf_type; @@ -241,7 +234,13 @@ __BEGIN_DECLS const char *netstat_strerror(int); +const char *netstat_kvmerror(const struct session_type *); + +/* "Session" */ +struct session_type *netstat_session_new(void* kvm_handle); +void netstat_session_free(struct session_type *); + /* "Socket" */ /* Socket list: */ @@ -265,8 +264,8 @@ void netstat_st_free(struct socket_type *stp); void netstat_sat_free(struct sockaddr_type *satp); -int netstat_socket(int domain, int type, int protocol, - struct socket_type_list *, int flags, void *kvm_handle); +int netstat_socket(const struct session_type *, int domain, int type, + int protocol, struct socket_type_list *, int flags); /* Accessor functions: */ int netstat_st_get_family(const struct socket_type *stp); @@ -311,7 +310,8 @@ void netstat_mbt_free(struct mbuf_type *); int netstat_mbt_geterror(const struct mbuf_type *); -int netstat_mbuf(struct mbuf_type *stats, int flags, void *kvm_handle); +int netstat_mbuf(const struct session_type *, struct mbuf_type *stats, + int flags); const struct buffer_type *netstat_mbt_get_mbuf(const struct mbuf_type *); const struct buffer_type *netstat_mbt_get_cluster(const struct mbuf_type *); @@ -353,8 +353,8 @@ void netstat_it_free(struct interface_type *); void netstat_iat_free(struct intfaddr_type *); -int netstat_interface(const char *name, int domain, - struct interface_type_list *list, int flags, void *kvm_handle); +int netstat_interface(const struct session_type *, const char *name, + int domain, struct interface_type_list *list, int flags); const char *netstat_it_get_name(const struct interface_type *); u_int64_t netstat_it_get_mtu(const struct interface_type *); @@ -402,8 +402,8 @@ void netstat_bpti_free(struct bpf_type_iterator *); void netstat_bpt_free(struct bpf_type *); -int netstat_bpf(const char *name, struct bpf_type_list *list, int flags, - void *kvm_handle); +int netstat_bpf(const struct session_type *, const char *name, + struct bpf_type_list *list, int flags); int netstat_bpt_get_flags(const struct bpf_type *); enum bpf_dir netstat_bpt_get_direction(const struct bpf_type *); @@ -425,9 +425,9 @@ void netstat_stat_free(struct stat_type *); int netstat_stat_geterror(const struct stat_type *); -int netstat_stat(enum stat, struct stat_type *, int flags, - void *kvm_handle); -int netstat_zerostat(enum stat); +int netstat_stat(const struct session_type *, enum stat, struct stat_type *, + int flags); +int netstat_zerostat(const struct session_type *, enum stat); const struct tcp_stat *netstat_get_tcpstats(const struct stat_type *); @@ -614,7 +614,7 @@ #ifdef INET6 const char *netstat_icmp6name(int); #endif -int netstat_icmp_get_maskrepl(void *kvm_handle); +int netstat_icmp_get_maskrepl(const struct session_type *); const struct pim_stat *netstat_get_pimstats(const struct stat_type *); ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_bpf.c#2 (text+ko) ==== @@ -75,16 +75,14 @@ static const char *get_procname_kvm(kvm_t *kvm, pid_t pid, u_long ap); int -netstat_bpf(const char *name, struct bpf_type_list *list, int flags, - void *kvm_handle) +netstat_bpf(const struct session_type *session, const char *name, + struct bpf_type_list *list, __unused int flags) { - kvm_t *kvm; int result; result = -1; - if (flags & NETSTAT_BPF_KVM) { - kvm = (kvm_t *)kvm_handle; - result = bpf_iflist_kvm(list, name, kvm); + if (session->sst_flags & NETSTAT_SESSION_KVM) { + result = bpf_iflist_kvm(list, name, session->sst_kvm); } else result = bpf_iflist_sysctl(list, name); return (result); ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_if.c#4 (text+ko) ==== @@ -61,18 +61,17 @@ void *saddr, struct interface_type *itp); #define KREAD(off, dst) do { \ - if ((list->itl_error = (kread_data(kvm, (uintptr_t)(off), &(dst), \ - sizeof(dst)))) != 0) { \ + if ((list->itl_error = (kread_data(session->sst_kvm, \ + (uintptr_t)(off), &(dst), sizeof(dst)))) != 0) { \ result = -1; \ goto end; \ } \ } while (0); int -netstat_interface(const char *name, int domain, - struct interface_type_list *list, int flags, void *kvm_handle) +netstat_interface(const struct session_type *session, const char *name, + int domain, struct interface_type_list *list, __unused int flags) { - kvm_t *kvm; int result, i; struct nlist nls[nlIF_MAX + 1]; @@ -104,14 +103,12 @@ result = -1; bzero(nls, sizeof(nls)); - if (flags & NETSTAT_INTERFACE_KVM) { + if (session->sst_flags & NETSTAT_SESSION_KVM) { /* Using kvm(3). */ - kvm = (kvm_t *)kvm_handle; - nls[nlIF_ifnet].n_name = strdup(if_symbol[nlIF_ifnet]); nls[nlIF_MAX].n_name = NULL; - if (kvm_nlist(kvm, nls) < 0) { + if (kvm_nlist(session->sst_kvm, nls) < 0) { list->itl_error = NETSTAT_ERROR_KVM; goto end; } ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#55 (text+ko) ==== @@ -81,6 +81,11 @@ #include "netstat.h" +struct session_type { + int sst_flags; + kvm_t *sst_kvm; +}; + /* Address type: * local, foreign, node (Netgraph), raw (domain) */ @@ -125,6 +130,8 @@ #define NETSTAT_IF_IFADDR 0 #define NETSTAT_IF_IFMULTIADDR 1 +#define NETSTAT_SESSION_KVM 0x01 + /* Socket (PCB) type: a connection. */ struct socket_type { /* Static properties. */ ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_mbuf.c#3 (text+ko) ==== @@ -60,7 +60,8 @@ static int fill_bt(struct memory_type_list *mtlp, struct buffer_type *btp, int allocator, const char *name); -int netstat_mbuf(struct mbuf_type *stats, int flags, void *kvm_handle) +int netstat_mbuf(const struct session_type *session, struct mbuf_type *stats, + __unused int flags) { struct memory_type_list *mtlp; struct nlist nls[nlMBF_MAX + 1]; @@ -68,7 +69,6 @@ struct mbstat_data mbsd; struct mbstat mbstat; - kvm_t *kvm; int error, result, i, len, bucket; const char *sfstats_mib = "kern.ipc.sfbstats"; @@ -85,15 +85,13 @@ bzero(&mbsd, sizeof(struct mbstat_data)); bzero(nls, sizeof(nls)); - if (flags & NETSTAT_MBUF_KVM) { + if (session->sst_flags & NETSTAT_SESSION_KVM) { /* kvm(3)-based monitoring */ - kvm = (kvm_t *)kvm_handle; - - if (memstat_kvm_all(mtlp, kvm_handle) < 0) { + if (memstat_kvm_all(mtlp, session->sst_kvm) < 0) { error = memstat_mtl_geterror(mtlp); if (error == MEMSTAT_ERROR_KVM) warnx("netstat_mbuf: memstat_kvm_all: %s", - kvm_geterr(kvm_handle)); + kvm_geterr(session->sst_kvm)); else warnx("netstat_mbuf: memstat_kvm_all: %s", memstat_strerror(error)); @@ -105,13 +103,14 @@ nls[i].n_name = strdup(mbstat_symbol[i]); nls[nlMBF_MAX].n_name = NULL; - if (kvm_nlist(kvm, nls) < 0) { + if (kvm_nlist(session->sst_kvm, nls) < 0) { stats->mbt_error = NETSTAT_ERROR_KVM; goto out; } #define KREAD(idx, dst) do { \ - if (kread_data(kvm, nls[idx].n_value, &(dst), sizeof(dst)) != 0) { \ + if (kread_data(session->sst_kvm, nls[idx].n_value, &(dst), \ + sizeof(dst)) != 0) { \ stats->mbt_error = NETSTAT_ERROR_KVM; \ goto out; \ } \ ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_socket.c#3 (text+ko) ==== @@ -97,9 +97,9 @@ int type, struct in6_addr *in, u_short port); static int netstat_local_sockets(int, struct socket_type_list *, kvm_t *, - struct nlist *, int); + struct nlist *, int, int); static int netstat_inet_sockets(int, int, struct socket_type_list *, - kvm_t *, struct nlist *, int); + kvm_t *, struct nlist *, int, int); /* type names */ static const char *const socktype[] = @@ -494,10 +494,8 @@ int netstat_local_sockets(int type, struct socket_type_list *list, kvm_t *kvm, - struct nlist *nlp, int flags) + struct nlist *nlp, int flags, int use_kvm) { - int use_kvm = flags & NETSTAT_SOCKET_KVM; - switch (type) { case SOCK_STREAM: case SOCK_DGRAM: @@ -531,10 +529,8 @@ int netstat_inet_sockets(int domain, int protocol, struct socket_type_list *list, - kvm_t *kvm, struct nlist *nlp, int flags) + kvm_t *kvm, struct nlist *nlp, int flags, int use_kvm) { - int use_kvm = flags & NETSTAT_SOCKET_KVM; - switch (protocol) { case IPPROTO_TCP: case IPPROTO_UDP: @@ -585,17 +581,16 @@ int -netstat_socket(int domain, int type, int protocol, - struct socket_type_list *list, int flags, void *kvm_handle) +netstat_socket(const struct session_type *session, int domain, int type, + int protocol, struct socket_type_list *list, int flags) { - kvm_t *kvm; + int use_kvm = session->sst_flags & NETSTAT_SESSION_KVM; int result, i; struct nlist nls[nlUNP_MAX + 1 + nlINP_MAX + 1]; bzero(nls, sizeof(nls)); - if (flags & NETSTAT_SOCKET_KVM) { + if (use_kvm) { /* Use KVM to retrieve data. */ - kvm = (kvm_t *)kvm_handle; switch (domain) { case PF_UNSPEC: for (i = 0; i < nlUNP_MAX; i++) @@ -621,7 +616,7 @@ default: break; } - if (kvm_nlist(kvm, nls) < 0) { + if (kvm_nlist(session->sst_kvm, nls) < 0) { list->stl_error = NETSTAT_ERROR_KVM; result = -1; goto end; @@ -630,26 +625,28 @@ switch (domain) { case PF_UNSPEC: /* "Everything" */ - result = netstat_local_sockets(0, list, kvm, nls, flags); + result = netstat_local_sockets(0, list, session->sst_kvm, nls, + flags, use_kvm); if (result < 0) goto end; - result = netstat_inet_sockets(PF_INET, 0, list, kvm, - &nls[nlUNP_MAX + 1], flags); + result = netstat_inet_sockets(PF_INET, 0, list, + session->sst_kvm, &nls[nlUNP_MAX + 1], flags, use_kvm); if (result < 0) goto end; - result = netstat_inet_sockets(PF_INET6, 0, list, kvm, - &nls[nlUNP_MAX + 1], flags); + result = netstat_inet_sockets(PF_INET6, 0, list, + session->sst_kvm, &nls[nlUNP_MAX + 1], flags, use_kvm); if (result < 0) goto end; break; case PF_LOCAL: - result = (netstat_local_sockets(type, list, kvm, nls, flags)); + result = (netstat_local_sockets(type, list, session->sst_kvm, + nls, flags, use_kvm)); goto end; break; case PF_INET: case PF_INET6: - result = (netstat_inet_sockets(domain, protocol, list, kvm, - nls, flags)); + result = (netstat_inet_sockets(domain, protocol, list, + session->sst_kvm, nls, flags, use_kvm)); goto end; break; default: ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_stat.c#25 (text+ko) ==== @@ -102,8 +102,8 @@ }; int -netstat_stat(enum stat type, struct stat_type *sttp, int flags, - void *kvm_handle) +netstat_stat(const struct session_type *session, enum stat type, + struct stat_type *sttp, __unused int flags) { char *buffer; char symbuf[64]; @@ -123,9 +123,9 @@ sttp->stt_type = type; bzero(&head, sizeof(head)); - if (flags & NETSTAT_STAT_KVM) { + if (session->sst_flags & NETSTAT_SESSION_KVM) { sprintf(symbuf, "%s_header", stat_info[sttp->stt_type].kvm); - res = read_kvm(kvm_handle, symbuf, &head, sizeof(head)); + res = read_kvm(session->sst_kvm, symbuf, &head, sizeof(head)); if (res != 0) { sttp->stt_error = NETSTAT_ERROR_KVM; return (-1); @@ -139,7 +139,7 @@ sttp->stt_error = NETSTAT_ERROR_NOMEMORY; return (-1); } - res = read_kvm(kvm_handle, stat_info[sttp->stt_type].kvm, + res = read_kvm(session->sst_kvm, stat_info[sttp->stt_type].kvm, buffer, head.sth_len); if (res != 0) { sttp->stt_error = NETSTAT_ERROR_KVM; @@ -188,20 +188,20 @@ } int -netstat_icmp_get_maskrepl(void *kvm_handle) +netstat_icmp_get_maskrepl(const struct session_type *session) { int res; res = 0; - if (kvm_handle == NULL) { - if (read_sysctl("net.inet.icmp.maskrepl", &res, + if (session->sst_flags & NETSTAT_SESSION_KVM) { + if (read_kvm(session->sst_kvm, "_icmpmaskrepl", &res, sizeof(res)) < 0) { warn("netstat_icmp_get_maskrepl"); return (res); } } else { - if (read_kvm(kvm_handle, "_icmpmaskrepl", &res, + if (read_sysctl("net.inet.icmp.maskrepl", &res, sizeof(res)) < 0) { warn("netstat_icmp_get_maskrepl"); return (res); @@ -249,12 +249,15 @@ } int -netstat_zerostat(enum stat type) +netstat_zerostat(const struct session_type *session, enum stat type) { char symbuf[64]; char buffer[1024]; struct stat_header head; + if (session->sst_flags & NETSTAT_SESSION_KVM) + return (-1); /* unsupported */ + if (type >= stat_MAX) { return (-1); } ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#63 (text+ko) ==== @@ -152,6 +152,38 @@ } } +const char * +netstat_kvmerror(const struct session_type *session) +{ + if (session->sst_flags & NETSTAT_SESSION_KVM) + return (kvm_geterr(session->sst_kvm)); + return ("Unknown error"); +} + +struct session_type * +netstat_session_new(void *kvm_handle) +{ + struct session_type *sstp; + + sstp = malloc(sizeof(*sstp)); + if (sstp == NULL) + return (NULL); + + bzero(sstp, sizeof(*sstp)); + + if (kvm_handle != NULL) { + sstp->sst_flags |= NETSTAT_SESSION_KVM; + sstp->sst_kvm = (kvm_t *)kvm_handle; + } + return (sstp); +} + +void +netstat_session_free(struct session_type *session) +{ + free(session); +} + struct socket_type_list * netstat_stl_alloc(void) { ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/bpf.c#4 (text+ko) ==== @@ -56,21 +56,15 @@ /* print bpf stats */ void -bpf_stats(char *ifname, void *kvmd) +bpf_stats(const struct session_type *session, char *ifname) { struct bpf_type_list *bptlp; struct bpf_type_iterator *bptip = NULL; const struct bpf_type *bptp; - int bpt_flags, error; + int error; char flagbuf[12]; - kvm_t *kvm; - - kvm = (kvm_t *)kvmd; - bpt_flags = 0; - if (kvmd != NULL) - bpt_flags |= NETSTAT_BPF_KVM; bptlp = netstat_bptl_alloc(); if (bptlp == NULL) { @@ -78,10 +72,10 @@ return; } - if (netstat_bpf(ifname, bptlp, bpt_flags, kvm)) { + if (netstat_bpf(session, ifname, bptlp, 0)) { error = netstat_bptl_geterror(bptlp); if (error == NETSTAT_ERROR_KVM) { - warnx("netstat_bpf: %s", kvm_geterr(kvm)); + warnx("netstat_bpf: %s", netstat_kvmerror(session)); } else { warnx("netstat_bpf: %s", netstat_strerror(error)); } ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#35 (text+ko) ==== @@ -71,7 +71,7 @@ const char *pluralies(uintmax_t); int sotoxsocket(struct socket *, struct xsocket *); -void inetpr(void *, int, int); +void inetpr(const struct session_type *, int, int); void inetppr(const struct socket_type *); void unixdomainpr(const struct socket_type *); void tcp_stats(const struct stat_type *); @@ -111,12 +111,12 @@ void inet6print(struct in6_addr *, int, const char *, int); #endif /*INET6*/ -void mbpr(void *); +void mbpr(const struct session_type *); void hostpr(u_long, u_long); void impstats(u_long, u_long); -void intpr(int, void *, void (*)(char *)); +void intpr(const struct session_type *, int, void (*)(char *)); void pr_rthdr(int); void pr_family(int); @@ -151,7 +151,7 @@ void netgraphprotopr(u_long, const char *, int, int); #endif -void unixpr(void *); +void unixpr(const struct session_type *); void esis_stats(u_long, const char *, int, int); void clnp_stats(u_long, const char *, int, int); @@ -164,4 +164,4 @@ void mroutepr(u_long, u_long, u_long); void mrt_stats(const struct stat_type *); -void bpf_stats(char *, void *); +void bpf_stats(const struct session_type *, char *); ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/if.c#5 (text+ko) ==== @@ -79,7 +79,7 @@ #define YES 1 #define NO 0 -static void sidewaysintpr(int, void *); +static void sidewaysintpr(const struct session_type *, int); static void catchalarm(int); /* @@ -160,10 +160,9 @@ * Print a description of the network interfaces. */ void -intpr(int interval1, void *kvm_handle, void (*pfunc)(char *)) +intpr(const struct session_type *session, int interval1, void (*pfunc)(char *)) { int it_flags; - kvm_t *kvm; struct interface_type_list *itlp; struct interface_type_iterator *itip; @@ -175,18 +174,13 @@ char if_name[16]; int error, i, network_layer, link_layer; - if (kvm_handle == NULL) - return; - if (interval1) { - sidewaysintpr(interval1, kvm_handle); + sidewaysintpr(session, interval1); return; } - kvm = (kvm_t *)kvm_handle; it_flags = 0; it_flags |= NETSTAT_INTERFACE_ALL; - it_flags |= NETSTAT_INTERFACE_KVM; itlp = netstat_itl_alloc(); if (itlp == NULL) { @@ -194,10 +188,11 @@ return; } - if (netstat_interface(interface, af, itlp, it_flags, kvm) < 0) { + if (netstat_interface(session, interface, af, itlp, it_flags) < 0) { error = netstat_itl_geterror(itlp); if (error == NETSTAT_ERROR_KVM) { - warnx("netstat_interface: %s", kvm_geterr(kvm)); + warnx("netstat_interface: %s", + netstat_kvmerror(session)); } else warnx("netstat_interface: %s", netstat_strerror(error)); goto out; @@ -342,9 +337,8 @@ * First line printed at top of screen is always cumulative. */ static void -sidewaysintpr(int interval1, void *kvm_handle) +sidewaysintpr(const struct session_type *session, int interval1) { - kvm_t *kvm; int it_flags; struct itimerval interval_it; @@ -359,13 +353,8 @@ const struct face_type *fin, *fout; const struct interface_type *itp; - if (kvm_handle == NULL) - return; - it_flags = 0; - it_flags |= NETSTAT_INTERFACE_KVM; it_flags |= NETSTAT_INTERFACE_ALL; - kvm = (kvm_t *)kvm_handle; (void)signal(SIGALRM, catchalarm); signalled = NO; @@ -380,10 +369,11 @@ warn("netstat_itl_alloc()"); return; } - if (netstat_interface(interface, PF_UNSPEC, itlp, it_flags, kvm) < 0) { + if (netstat_interface(session, interface, PF_UNSPEC, itlp, + it_flags) < 0) { error = netstat_itl_geterror(itlp); if (error == NETSTAT_ERROR_KVM) { - warnx("netstat_interface: %s", kvm_geterr(kvm)); + warnx("netstat_interface: %s", netstat_kvmerror(session)); } else warnx("netstat_interface: %s", netstat_strerror(error)); netstat_itl_free(itlp); @@ -413,10 +403,12 @@ warn("netstat_itl_alloc()"); return; } - if (netstat_interface(interface, PF_UNSPEC, itlp, it_flags, kvm) < 0) { + if (netstat_interface(session, interface, PF_UNSPEC, itlp, + it_flags) < 0) { error = netstat_itl_geterror(itlp); if (error == NETSTAT_ERROR_KVM) { - warnx("netstat_interface: %s", kvm_geterr(kvm)); + warnx("netstat_interface: %s", + netstat_kvmerror(session)); } else warnx("netstat_interface: %s", netstat_strerror(error)); netstat_itl_free(itlp); ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#33 (text+ko) ==== @@ -105,17 +105,15 @@ * -a (all) flag is specified. */ void -inetpr(void *kvmd, int family, int proto) +inetpr(const struct session_type *session, int family, int proto) { struct socket_type_list *stlp; int error, st_flags; - kvm_t *kvm; #ifdef USE_ITERATOR_TYPE struct socket_type_iterator *stip; const struct socket_type *stp; #endif - kvm = (kvm_t *)kvmd; stlp = netstat_stl_alloc(); if (stlp == NULL) { warn("netstat_stl_alloc"); @@ -123,15 +121,13 @@ } st_flags = 0; - if (!live) - st_flags |= NETSTAT_SOCKET_KVM; if (aflag) st_flags |= NETSTAT_SOCKET_ALL; - if (netstat_socket(family, 0, proto, stlp, st_flags, kvm) < 0) { + if (netstat_socket(session, family, 0, proto, stlp, st_flags) < 0) { error = netstat_stl_geterror(stlp); if (error == NETSTAT_ERROR_KVM) - warnx("netstat_socket: %s", kvm_geterr(kvm)); + warnx("netstat_socket: %s", netstat_kvmerror(session)); else warnx("netstat_socket: %s", netstat_strerror(error)); return; @@ -546,9 +542,6 @@ #undef p #undef p1a #undef p2 - if (live) - printf("\tICMP address mask responses are %sabled\n", - netstat_icmp_get_maskrepl(NULL) ? "en" : "dis"); } /* ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#45 (text+ko) ==== @@ -222,8 +222,10 @@ atalkprotox, NULL }; static void connpr(const struct socket_type *); -static void statpr(void (*)(const struct stat_type *), enum stat, const char *); -static void printproto(struct protox *, const char *); +static void statpr(const struct session_type *, + void (*)(const struct stat_type *), enum stat, const char *); +static void printproto(const struct session_type *, struct protox *, + const char *); static void usage(void); static struct protox *name2protox(const char *); static struct protox *knownname(const char *); @@ -269,6 +271,7 @@ int error, st_flags; struct socket_type_iterator *stip; const struct socket_type *stp; + struct session_type *session; af = AF_UNSPEC; @@ -423,13 +426,17 @@ if (Bflag) { if (!live) kread(0, NULL, 0); - bpf_stats(interface, kvmd); + session = netstat_session_new(kvmd); + bpf_stats(session, interface); + netstat_session_free(session); exit(0); } if (mflag) { if (!live) kread(0, NULL, 0); - mbpr(kvmd); + session = netstat_session_new(kvmd); + mbpr(session); + netstat_session_free(session); exit(0); } #if 0 @@ -448,30 +455,35 @@ #endif if (iflag && !sflag) { kread(0, NULL, 0); - intpr(interval, kvmd, NULL); + session = netstat_session_new(kvmd); + intpr(session, interval, NULL); + netstat_session_free(session); exit(0); } if (rflag) { if (sflag) { if (!live) kread(0, NULL, 0); - statpr(rt_stats, stat_route, "routing"); + session = netstat_session_new(kvmd); + statpr(session, rt_stats, stat_route, "routing"); + netstat_session_free(session); } else { kread(0, NULL, 0); routepr(nl[N_RTREE].n_value); - } + } exit(0); } if (gflag) { kread(0, NULL, 0); + session = netstat_session_new(kvmd); if (sflag) { if (af == AF_INET || af == AF_UNSPEC) - statpr(mrt_stats, stat_mroute, + statpr(session, mrt_stats, stat_mroute, "IPv4 multicast forwarding"); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) - statpr(mrt6_stats, stat_mroute6, + statpr(session, mrt6_stats, stat_mroute6, "IPv6 multicast forwarding"); #endif } else { @@ -485,38 +497,54 @@ nl[N_MIF6TABLE].n_value); #endif } + netstat_session_free(session); exit(0); } if (tp) { if (!live) kread(0, NULL, 0); - printproto(tp, tp->pr_name); + session = netstat_session_new(kvmd); + printproto(session, tp, tp->pr_name); + netstat_session_free(session); exit(0); } #ifdef IPSEC - if (af == PF_KEY || af == AF_UNSPEC) + if (af == PF_KEY || af == AF_UNSPEC) { + session = netstat_session_new(kvmd); for (tp = pfkeyprotox; tp->pr_name; tp++) - printproto(tp, tp->pr_name); + printproto(session, tp, tp->pr_name); + netstat_session_free(session); + } #endif /*IPSEC*/ #ifdef IPX if (af == AF_IPX || af == AF_UNSPEC) { + session = netstat_session_new(kvmd); for (tp = ipxprotox; tp->pr_name; tp++) - printproto(tp, tp->pr_name); + printproto(session, tp, tp->pr_name); + netstat_session_free(session); } #endif /* IPX */ - if (af == AF_APPLETALK || af == AF_UNSPEC) + if (af == AF_APPLETALK || af == AF_UNSPEC) { + session = netstat_session_new(kvmd); for (tp = atalkprotox; tp->pr_name; tp++) - printproto(tp, tp->pr_name); + printproto(session, tp, tp->pr_name); + netstat_session_free(session); + } #ifdef NETGRAPH - if (af == AF_NETGRAPH || af == AF_UNSPEC) + if (af == AF_NETGRAPH || af == AF_UNSPEC) { + session = netstat_session_new(kvmd); for (tp = netgraphprotox; tp->pr_name; tp++) - printproto(tp, tp->pr_name); + printproto(session, tp, tp->pr_name); + netstat_session_free(session); + } #endif /* NETGRAPH */ if (af == AF_UNIX && !sflag) { if (!live) kread(0, NULL, 0); - unixpr(kvmd); + session = netstat_session_new(kvmd); + unixpr(session); + netstat_session_free(session); >>> TRUNCATED FOR MAIL (1000 lines) <<<