PERFORCE change 166020 for review
Gabor Pali
pgj at FreeBSD.org
Mon Jul 13 17:43:34 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166020
Change 166020 by pgj at 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)
{
More information about the p4-projects
mailing list