From owner-p4-projects@FreeBSD.ORG Mon Jul 13 17:43:33 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C168B10656EA; Mon, 13 Jul 2009 17:43:30 +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 B09A01065676 for ; Mon, 13 Jul 2009 17:43:29 +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 936B88FC12 for ; Mon, 13 Jul 2009 17:43:29 +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 n6DHhTDm031218 for ; Mon, 13 Jul 2009 17:43:29 GMT (envelope-from pgj@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6DHhTqQ031216 for perforce@freebsd.org; Mon, 13 Jul 2009 17:43:29 GMT (envelope-from pgj@FreeBSD.org) Date: Mon, 13 Jul 2009 17:43:29 GMT Message-Id: <200907131743.n6DHhTqQ031216@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 166020 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: Mon, 13 Jul 2009 17:43:34 -0000 http://perforce.freebsd.org/chv.cgi?CH=166020 Change 166020 by pgj@petymeg-current on 2009/07/13 17:43:17 Add enum tcp_state, so applications can access the tcp state of a connection directly in a relatively type-safe way. Affected files ... .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#41 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#24 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#23 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#25 edit Differences ... ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#41 (text+ko) ==== @@ -77,6 +77,11 @@ static const char *const inp_symbol[] = { "_tcbinfo", "_udbinfo", "_divcbinfo", "_ripcbinfo" }; +static const enum tcp_state tcp_states[] = + { tcps_Closed, tcps_Listen, tcps_SynSent, tcps_SynReceived, + tcps_Established, tcps_CloseWait, tcps_FinWait1, tcps_Closing, + tcps_LastAck, tcps_FinWait2, tcps_TimeWait }; + static void extract_xunpcb_data(struct xunpcb *, struct socket_type *); static void extract_unpcb_data(struct unpcb_data *, struct socket_type *); static void extract_inet_data(struct tcpcb *, struct inpcb *, @@ -705,6 +710,7 @@ stp->st_addrcnt += 1; } stp->st_tcpstate[0] = '\0'; + stp->st_tcps = tcps_Invalid; } void @@ -745,6 +751,7 @@ stp->st_addrcnt += 1; } stp->st_tcpstate[0] = '\0'; + stp->st_tcps = tcps_Invalid; } void @@ -779,15 +786,18 @@ stp->st_flags = 0; stp->st_addrcnt = 0; if (tp != NULL) { - if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES) + if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES) { sprintf(stp->st_tcpstate, "%d", tp->t_state); - else { + stp->st_tcps = tcps_Invalid; + } else { sprintf(stp->st_tcpstate, "%s", tcpstates[tp->t_state]); + stp->st_tcps = tcp_states[tp->t_state]; #if defined(TF_NEEDSYN) && defined(TF_NEEDFIN) /* T/TCP `hidden state' */ if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) { stp->st_tcpstate[0] = '*'; stp->st_tcpstate[1] = '\0'; + stp->st_tcps = tcps_Hidden; } #endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */ } @@ -795,6 +805,7 @@ } else { /* Has no TCP state. */ stp->st_tcpstate[0] = '\0'; + stp->st_tcps = tcps_Invalid; } #ifdef INET6 if ((inp->inp_vflag & INP_IPV6) != 0) @@ -863,15 +874,19 @@ stp->st_rcv.sbt_mbmax = idp->id_rcv_mbmax; stp->st_pcb = idp->id_pcb; if (idp->id_protocol == IPPROTO_TCP) { - if (idp->id_state >= TCP_NSTATES) + if (idp->id_state >= TCP_NSTATES) { sprintf(stp->st_tcpstate, "%d", idp->id_state); - else { + stp->st_tcps = tcps_Invalid; + } else { sprintf(stp->st_tcpstate, "%s", tcpstates[idp->id_state]); + stp->st_tcps = tcp_states[idp->id_state]; #if defined(TF_NEEDSYN) && defined(TF_NEEDFIN) /* T/TCP `hidden state` */ - if (idp->id_flags & (TF_NEEDSYN | TF_NEEDFIN)) + if (idp->id_flags & (TF_NEEDSYN | TF_NEEDFIN)) { strcpy(stp->st_tcpstate, "*"); + stp->st_tcps = tcps_Hidden; + } #endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */ } stp->st_flags |= SOCKTYPE_TCP; ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#24 (text+ko) ==== @@ -50,6 +50,24 @@ #define NETSTAT_SOCKET_KVM 0x01 /* Use KVM. */ #define NETSTAT_SOCKET_ALL 0x02 /* Return all connections. */ +/* Enum for TCP states: */ +enum tcp_state { + tcps_Closed, + tcps_Listen, + tcps_SynSent, + tcps_SynReceived, + tcps_Established, + tcps_CloseWait, + tcps_FinWait1, + tcps_FinWait2, + tcps_Closing, + tcps_LastAck, + tcps_TimeWait, + tcps_Hidden, + tcps_Invalid, + tcps_MAX, +}; + struct socket_type; struct socket_type_list; struct socket_type_iterator; @@ -100,6 +118,7 @@ u_int64_t netstat_st_get_refs(const struct socket_type *stp); u_int64_t netstat_st_get_reflink(const struct socket_type *stp); const char *netstat_st_get_tcpstate(const struct socket_type *stp); +enum tcp_state netstat_st_get_tcps(const struct socket_type *stp); /* Addresses: */ int netstat_st_get_addrcnt(const struct socket_type *stp); struct addr_type *netstat_st_get_address(const struct socket_type *stp, ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#23 (text+ko) ==== @@ -109,6 +109,7 @@ u_int64_t st_conn; /* control block of connected socket */ u_int64_t st_refs; /* referencing socket linked list */ u_int64_t st_reflink; /* link in references list */ + enum tcp_state st_tcps; char st_tcpstate[16]; /* list of types */ ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#25 (text+ko) ==== @@ -444,6 +444,12 @@ return (stp->st_tcpstate); } +enum tcp_state +netstat_st_get_tcps(const struct socket_type *stp) +{ + return (stp->st_tcps); +} + int netstat_st_get_addrcnt(const struct socket_type *stp) {