This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Additions to TCP tapset


Hi,

I have added three routines, tcp_sockstate_str(), tcp_sockopt_str(), and
tcp_setsockopt(). I also added two lookup tables, sockopt and sockstate.

- tcp_sockstate_str() returns the string version of the socket state values.
- tcp_sockopt_str() returns the string version of optname/tcp socket options.
- tcp_setsockopt() displays TCP_* socket options when setsockopt() is called.

Kindly review please. I will commit the changes if there are no objection.

Thanks!

Eugene
 tapset/ChangeLog |    6 ++++
 tapset/tcp.stp   |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)

diff -Nurp src.default/tapset/ChangeLog src/tapset/ChangeLog
--- src.default/tapset/ChangeLog	2007-07-10 23:57:47.000000000 +0800
+++ src/tapset/ChangeLog	2007-07-10 23:57:17.000000000 +0800
@@ -1,3 +1,9 @@
+2007-07-10  Eugene Teo  <eteo@redhat.com>
+
+	* tcp.stp (tcp_sockstate_str, tcp_sockopt_str,
+	tcp_setsockopt): New. Also added sockopt and sockstate
+	lookup tables.
+
 2007-07-09  Martin Hunt  <hunt@redhat.com>
 
 	* syscalls2.stp (compat_sys_utimes): New.
diff -Nurp src.default/tapset/tcp.stp src/tapset/tcp.stp
--- src.default/tapset/tcp.stp	2007-07-10 23:58:11.000000000 +0800
+++ src/tapset/tcp.stp	2007-07-10 23:53:44.000000000 +0800
@@ -1,6 +1,7 @@
 // TCP tapset
 // Copyright (C) 2006 IBM Corp.
 // Copyright (C) 2006 Intel Corporation.
+// Copyright (C) 2007 Red Hat, Inc., Eugene Teo <eteo@redhat.com>
 //
 // This file is part of systemtap, and is free software.  You can
 // redistribute it and/or modify it under the terms of the GNU General
@@ -14,6 +15,40 @@
 #include <net/ip.h>
 %}
 
+%{
+const char *const sockopt[] = {
+        [1] = "TCP_NODELAY",
+        [2] = "TCP_MAXSEG",
+        [3] = "TCP_CORK",
+        [4] = "TCP_KEEPIDLE",
+        [5] = "TCP_KEEPINTVL",
+        [6] = "TCP_KEEPCNT",
+        [7] = "TCP_SYNCNT",
+        [8] = "TCP_LINGER2",
+        [9] = "TCP_DEFER_ACCEPT",
+        [10] = "TCP_WINDOW_CLAMP",
+        [11] = "TCP_INFO",
+        [12] = "TCP_QUICKACK",
+        [13] = "TCP_CONGESTION",
+        [14] = "TCP_MD5SIG",
+};
+
+const char *const sockstate[] = {
+	[1] = "TCP_ESTABLISED",
+	[2] = "TCP_SYN_SENT",
+	[3] = "TCP_SYN_RECV",
+	[4] = "TCP_FIN_WAIT1",
+	[5] = "TCP_FIN_WAIT2",
+	[6] = "TCP_TIME_WAIT",
+	[7] = "TCP_CLOSE",
+	[8] = "TCP_CLOSE_WAIT",
+	[9] = "TCP_LAST_ACK",
+	[10] = "TCP_LISTEN",
+	[11] = "TCP_CLOSING",
+	[12] = "TCP_MAX_STATES",
+};
+%}
+
 // Get retransmission timeout in usecs. RTO is initialized from default
 // retransmission time, but can be adjusted (increased) each time we 
 // retransmit. It should always be less than the max value of TCP retransmission 
@@ -70,6 +105,14 @@ function tcp_ts_get_info_state:long(sock
 	CATCH_DEREF_FAULT();
 %}
 
+function tcp_sockstate_str:string (state:long) %{ /* pure */
+	long state = THIS->state;
+	if (state > 0 && state < 13)
+		strlcpy(THIS->__retvalue, sockstate[state], MAXSTRINGLEN);
+	else
+		strlcpy(THIS->__retvalue, "N/A", MAXSTRINGLEN);
+	CATCH_DEREF_FAULT();
+%}
 
 // Get slow start threshold size.  If cwnd size is less than or equal to
 // threshold size, then TCP is in slow start; otherwise TCP is in congestion
@@ -101,6 +144,15 @@ function tcp_ts_get_info_rcv_mss:long(so
 	CATCH_DEREF_FAULT();
 %}
 
+function tcp_sockopt_str:string (optname:long) %{ /* pure */
+	long optname = THIS->optname;
+	if (optname > 0 && optname < 15)
+		strlcpy(THIS->__retvalue, sockopt[optname], MAXSTRINGLEN);
+	else
+		strlcpy(THIS->__retvalue, "N/A", MAXSTRINGLEN);
+	CATCH_DEREF_FAULT();
+%}
+
 // probe tcp.sendmsg
 //
 //  Fires whenever sending a tcp message  
@@ -190,3 +242,29 @@ probe tcp.disconnect = kernel.function("
 probe tcp.disconnect.return = kernel.function("tcp_disconnect").return {
 	ret = $return 
 }
+
+// probe tcp.setsockopt
+//
+//  Fires whenever setsockopt(s, IPPROTO_TCP, TCP_*, ...) is called
+//
+// Context:
+//  The process which calls setsockopt
+//
+// Arguments:
+// sock	      - network socket
+// level      - the level at which the socket options will be manipulated
+// optname    - TCP socket options (e.g. TCP_NODELAY, TCP_MAXSEG, etc)
+// optstr     - resolves optname to a human-readable format
+// optlen     - used to access values for setsockopt()
+//
+probe tcp.setsockopt = kernel.function("tcp_setsockopt") {
+	sock = $sk
+	level = $level
+	optname = $optname
+	optstr = tcp_sockopt_str($optname)
+	optlen = $optlen
+}
+
+probe tcp.setsockopt.return = kernel.function("tcp_setsockopt").return {
+	ret = $return
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]