PERFORCE change 163718 for review
Gabor Pali
pgj at FreeBSD.org
Sun Jun 7 17:03:25 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=163718
Change 163718 by pgj at petymeg-current on 2009/06/07 17:02:23
- Add and use new properties: snd_cc, rcv_cc, qlen, incqlen, qlimit
- Enable compilation with debugging symbols for both libnetstat and
netstat
- Add extract_xsocket_data() for extracing common properties from
a PF_LOCAL-type socket
- sotoxsocket() has no return value, so do not check it :)
- Fix an sti_iterator bug
Affected files ...
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/Makefile#4 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#6 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#9 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#6 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#8 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/Makefile#3 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/unix.c#8 edit
Differences ...
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/Makefile#4 (text+ko) ====
@@ -7,6 +7,7 @@
INCS= netstat.h
CFLAGS+= -I. -I${.CURDIR}
+CFLAGS+= -g
SHLIB_MAJOR= 1
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.c#6 (text+ko) ====
@@ -26,6 +26,8 @@
{ .n_name = NULL },
};
+static void extract_xsocket_data(struct xsocket *, struct socket_type *);
+
static const char *const socktype[] =
{ "#0", "stream", "dgram", "raw", "rdm", "seqpacket" };
@@ -62,10 +64,12 @@
for (xug = (struct xunpgen *)((char *)xug + xug->xug_len);
xug->xug_len > sizeof(struct xunpgen);
xug = (struct xunpgen *)((char *)xug + xug->xug_len)) {
+ xunp = (struct xunpcb *)xug;
/* Keep active PCBs only. */
if (xunp->xu_unp.unp_gencnt <= oxug->xug_gen) {
stp = _netstat_st_allocate(list, PF_LOCAL, type,
socktype[type]);
+ extract_xsocket_data(&xunp->xu_socket, stp);
stp->xup = *((struct xunpcb *)xug);
}
}
@@ -140,12 +144,10 @@
}
}
KREAD(unp->unp_socket, &so, sizeof(so));
- if (sotoxsocket(&so, &xu.xu_socket) != 0) {
- list->stl_error = NETSTAT_ERROR_UNDEFINED;
- return (-1);
- }
+ sotoxsocket(&so, &xu.xu_socket);
stp = _netstat_st_allocate(list, PF_LOCAL, type,
socktype[type]);
+ extract_xsocket_data(&xu.xu_socket, stp);
stp->xup = xu;
}
@@ -217,3 +219,13 @@
#undef NLP_SCT
return (0);
}
+
+void
+extract_xsocket_data(struct xsocket *xso, struct socket_type *stp)
+{
+ stp->st_qlen = xso->so_qlen;
+ stp->st_incqlen = xso->so_incqlen;
+ stp->st_qlimit = xso->so_qlimit;
+ stp->st_snd_cc = xso->so_snd.sb_cc;
+ stp->st_rcv_cc = xso->so_rcv.sb_cc;
+}
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#9 (text+ko) ====
@@ -2,6 +2,8 @@
#ifndef _NETSTAT_H_
#define _NETSTAT_H_
+#include <sys/sockbuf.h>
+
#define NETSTAT_MAXCALLER 16
#define SOCKTYPE_MAXNAME 32
@@ -49,10 +51,17 @@
struct socket_type_list *, int flags, void *kvm_handle);
/* Accessor functions: */
-int netstat_st_get_family(const struct socket_type *stp);
-int netstat_st_get_protocol(const struct socket_type *stp);
-const char *netstat_st_get_name(const struct socket_type *stp);
-void *netstat_st_get_pcb(const struct socket_type *stp);
+int netstat_st_get_family(const struct socket_type *stp);
+int netstat_st_get_protocol(const struct socket_type *stp);
+const char *netstat_st_get_name(const struct socket_type *stp);
+u_int netstat_st_get_snd_cc(const struct socket_type *stp);
+u_int netstat_st_get_rcv_cc(const struct socket_type *stp);
+u_short netstat_st_get_qlen(const struct socket_type *stp);
+u_short netstat_st_get_incqlen(const struct socket_type *stp);
+u_short netstat_st_get_qlimit(const struct socket_type *stp);
+
+/* XXX: Remove this hack :) */
+void *netstat_st_get_pcb(const struct socket_type *stp);
__END_DECLS
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#6 (text+ko) ====
@@ -26,16 +26,19 @@
int st_flags;
char st_name[SOCKTYPE_MAXNAME];
- /* Mixed properties, needed for different reasons, to be refined
- * continuously.
- */
struct address_type *st_address; /* address(es) */
int st_addrcnt; /* address count */
- struct sockcred st_credentials;
- struct xsockbuf st_rcv; /* receive queue */
- struct xsockbuf st_snd; /* send queue */
+ u_int st_snd_cc; /* actual chars in the send buffer */
+ u_int st_rcv_cc; /* actual chars in the receive buffer */
+ u_short st_qlen; /* number of unaccepted connections */
+ u_short st_incqlen; /* number of unaccepted incomplete
+ connections */
+ u_short st_qlimit; /* max number queued connections */
+ /* Mixed properties, needed for different reasons, to be refined
+ * continuously.
+ */
struct xunpcb xup; /* xun */
/* list of types */
@@ -62,6 +65,5 @@
const char *name);
void _netstat_st_reset_stats(struct socket_type *list);
-int sotoxsocket(struct socket *, struct xsocket *);
-
+void sotoxsocket(struct socket *so, struct xsocket *xso);
#endif /* !_NETSTAT_INTERNAL_H_ */
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#8 (text+ko) ====
@@ -194,6 +194,9 @@
{
struct socket_type *stp;
+ if (iterator->sti_first == NULL)
+ return (NULL);
+
stp = malloc(sizeof(*stp));
if (stp == NULL)
return (NULL);
@@ -207,6 +210,9 @@
{
struct socket_type *stp;
+ if (iterator->sti_next == NULL)
+ return (NULL);
+
stp = malloc(sizeof(*stp));
if (stp == NULL)
return (NULL);
@@ -246,6 +252,36 @@
return (stp->st_name);
}
+u_int
+netstat_st_get_rcv_cc(const struct socket_type *stp)
+{
+ return (stp->st_rcv_cc);
+}
+
+u_int
+netstat_st_get_snd_cc(const struct socket_type *stp)
+{
+ return (stp->st_snd_cc);
+}
+
+u_short
+netstat_st_get_qlen(const struct socket_type *stp)
+{
+ return (stp->st_qlen);
+}
+
+u_short
+netstat_st_get_incqlen(const struct socket_type *stp)
+{
+ return (stp->st_incqlen);
+}
+
+u_short
+netstat_st_get_qlimit(const struct socket_type *stp)
+{
+ return (stp->st_qlimit);
+}
+
/* XXX: hack alert :) */
void *
netstat_st_get_pcb(const struct socket_type *stp)
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/Makefile#3 (text+ko) ====
@@ -24,7 +24,7 @@
LDADD= -lkvm -lmemstat -lutil -lnetstat
# XXX: temp. solution
-CFLAGS+= -I../../lib/libnetstat
+CFLAGS+= -I../../lib/libnetstat -g
LDFLAGS+= -L../../lib/libnetstat
.if ${MK_NETGRAPH_SUPPORT} != "no"
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/unix.c#8 (text+ko) ====
@@ -150,17 +150,20 @@
first = 0;
}
- if (Lflag && so->so_qlimit == 0)
+ if (Lflag && netstat_st_get_qlimit(stp) == 0)
return;
if (Lflag) {
- snprintf(buf1, 15, "%d/%d/%d", so->so_qlen,
- so->so_incqlen, so->so_qlimit);
+ snprintf(buf1, 15, "%d/%d/%d", netstat_st_get_qlen(stp),
+ netstat_st_get_incqlen(stp), netstat_st_get_qlimit(stp));
printf("unix %-14.14s", buf1);
} else {
printf("%8lx %-6.6s %6u %6u %8lx %8lx %8lx %8lx",
- (long)so->so_pcb, netstat_st_get_name(stp),
- so->so_rcv.sb_cc, so->so_snd.sb_cc, (long)unp->unp_vnode,
+ (long)so->so_pcb,
+ netstat_st_get_name(stp),
+ netstat_st_get_rcv_cc(stp),
+ netstat_st_get_snd_cc(stp),
+ (long)unp->unp_vnode,
(long)unp->unp_conn,
(long)LIST_FIRST(&unp->unp_refs),
(long)LIST_NEXT(unp, unp_reflink));
More information about the p4-projects
mailing list