]> sourceware.org Git - systemtap.git/commitdiff
Fix PR16580 by decoding the 'protocol' argument of 'syscall.socket{pair}'.
authorDavid Smith <dsmith@redhat.com>
Thu, 13 Feb 2014 19:54:35 +0000 (13:54 -0600)
committerDavid Smith <dsmith@redhat.com>
Thu, 13 Feb 2014 19:54:35 +0000 (13:54 -0600)
* tapset/linux/aux_syscalls.stp (_sock_protocol_str): New function.
* tapset/linux/syscalls2.stp: Decode the 'protocol' argument in
  syscall.socket and syscall.socketpair with _sock_protocol_str().
* tapset/linux/nd_syscalls2.stp: Ditto.
* testsuite/systemtap.syscall/socket.c: New test.
* testsuite/systemtap.syscall/socketpair.c: Updated test to expect decoded
  'protocol' arguments.
* testsuite/systemtap.syscall/net1.c: Ditto.

tapset/linux/aux_syscalls.stp
tapset/linux/nd_syscalls2.stp
tapset/linux/syscalls2.stp
testsuite/systemtap.syscall/net1.c
testsuite/systemtap.syscall/socket.c [new file with mode: 0644]
testsuite/systemtap.syscall/socketpair.c

index c66f6168651f9598c88a1f8e84eb564f3a7de173..c99ef976d907391d328bf64ef0f6a574b5e2b8a5 100644 (file)
@@ -1787,6 +1787,55 @@ function _sock_flags_str:string(f:long)
 #endif
 %}
 
+%{
+// Be sure we have the IPPROTO_* defines. But, on some older kernels
+// we don't have all of them defined. Also note that on some older
+// kernels these values are enum values, not defines. But, the
+// following code should work anyway.
+#include <linux/in.h>
+#ifndef IPPROTO_TP
+#define IPPROTO_TP 29
+#endif
+#ifndef IPPROTO_MTP
+#define IPPROTO_MTP 92
+#endif
+#ifndef IPPROTO_ENCAP
+#define IPPROTO_ENCAP 98
+#endif
+#ifndef IPPROTO_UDPLITE
+#define IPPROTO_UDPLITE 136
+#endif
+%}
+
+function _sock_protocol_str:string(family:long, protocol:long) {
+    if (family == %{ PF_INET %} || family == %{ PF_INET6 %}) {
+       if (protocol == %{ IPPROTO_IP %}) return "IPPROTO_IP"
+       if (protocol == %{ IPPROTO_ICMP %}) return "IPPROTO_ICMP"
+       if (protocol == %{ IPPROTO_IGMP %}) return "IPPROTO_IGMP"
+       if (protocol == %{ IPPROTO_IPIP %}) return "IPPROTO_IPIP"
+       if (protocol == %{ IPPROTO_TCP %}) return "IPPROTO_TCP"
+       if (protocol == %{ IPPROTO_EGP %}) return "IPPROTO_EGP"
+       if (protocol == %{ IPPROTO_PUP %}) return "IPPROTO_PUP"
+       if (protocol == %{ IPPROTO_UDP %}) return "IPPROTO_UDP"
+       if (protocol == %{ IPPROTO_IDP %}) return "IPPROTO_IDP"
+       if (protocol == %{ IPPROTO_TP %}) return "IPPROTO_TP"
+       if (protocol == %{ IPPROTO_DCCP %}) return "IPPROTO_DCCP"
+       if (protocol == %{ IPPROTO_IPV6 %}) return "IPPROTO_IPV6"
+       if (protocol == %{ IPPROTO_RSVP %}) return "IPPROTO_RSVP"
+       if (protocol == %{ IPPROTO_GRE %}) return "IPPROTO_GRE"
+       if (protocol == %{ IPPROTO_ESP %}) return "IPPROTO_ESP"
+       if (protocol == %{ IPPROTO_AH %}) return "IPPROTO_AH"
+       if (protocol == %{ IPPROTO_MTP %}) return "IPPROTO_MTP"
+       if (protocol == %{ IPPROTO_ENCAP %}) return "IPPROTO_ENCAP"
+       if (protocol == %{ IPPROTO_PIM %}) return "IPPROTO_PIM"
+       if (protocol == %{ IPPROTO_COMP %}) return "IPPROTO_COMP"
+       if (protocol == %{ IPPROTO_SCTP %}) return "IPPROTO_SCTP"
+       if (protocol == %{ IPPROTO_UDPLITE %}) return "IPPROTO_UDPLITE"
+       if (protocol == %{ IPPROTO_RAW %}) return "IPPROTO_RAW"
+    }
+    return sprintf("%d", protocol)
+}
+
 function _opoll_op_str(o) {
    if(o==1) return "EPOLL_CTL_ADD"
    if(o==3) return "EPOLL_CTL_MOD"
index 019ed365dad433a8ca6ad7e5901ce20d7e7dc67c..2eded10834810517b722f7a26152d354e5ecfc95 100644 (file)
@@ -3424,16 +3424,16 @@ probe nd_syscall.socket = kprobe.function("sys_socket") ?
        // family = $family
        // type = $type
        // protocol = $protocol
-       // argstr = sprintf("%s, %s, %d", _sock_family_str($family),
+       // argstr = sprintf("%s, %s, %s", _sock_family_str($family),
        //                      _sock_type_str($type),
-       //                      $protocol)
+       //                      _sock_protocol_str($family, $protocol))
        asmlinkage()
        family = int_arg(1)
        type = int_arg(2)
        protocol = int_arg(3)
-       argstr = sprintf("%s, %s, %d", _sock_family_str(family),
-                               _sock_type_str(type),
-                               protocol)
+       argstr = sprintf("%s, %s, %s", _sock_family_str(family),
+                        _sock_type_str(type),
+                        _sock_protocol_str(family, protocol))
 }
 probe nd_syscall.socket.return = kprobe.function("sys_socket").return ?
 {
@@ -3472,19 +3472,19 @@ probe nd_syscall.socketpair = kprobe.function("sys_socketpair") ?
        // type = $type
        // protocol = $protocol
        // sv_uaddr = $usockvec
-       // argstr = sprintf("%s, %s, %d, %p",
+       // argstr = sprintf("%s, %s, %s, %p",
        //                      _sock_family_str($family),
        //                      _sock_type_str($type),
-       //                      $protocol, sv_uaddr)
+       //                      _sock_protocol_str($family, $protocol),
+       //                      sv_uaddr)
        asmlinkage()
        family = int_arg(1)
        type = int_arg(2)
        protocol = int_arg(3)
        sv_uaddr = pointer_arg(4)
-       argstr = sprintf("%s, %s, %d, %p",
-                               _sock_family_str(family),
-                               _sock_type_str(type),
-                               protocol, sv_uaddr)
+       argstr = sprintf("%s, %s, %s, %p", _sock_family_str(family),
+                        _sock_type_str(type),
+                        _sock_protocol_str(family, protocol), sv_uaddr)
 }
 probe nd_syscall.socketpair.return = kprobe.function("sys_socketpair").return ?
 {
index fee448bef84c7fbf55c7dda96f220a48cc30e86c..5962cddeae9f7030ed1079cae2fbf1ba82cbc253 100644 (file)
@@ -2872,9 +2872,9 @@ probe syscall.socket = kernel.function("sys_socket").call ?
        family = $family
        type = $type
        protocol = $protocol
-       argstr = sprintf("%s, %s, %d", _sock_family_str($family),
-               _sock_type_str($type),
-               $protocol)
+       argstr = sprintf("%s, %s, %s", _sock_family_str($family),
+                        _sock_type_str($type),
+                        _sock_protocol_str($family, $protocol))
 }
 probe syscall.socket.return = kernel.function("sys_socket").return ?
 {
@@ -2913,10 +2913,10 @@ probe syscall.socketpair = kernel.function("sys_socketpair").call ?
        type = $type
        protocol = $protocol
        sv_uaddr = $usockvec
-       argstr = sprintf("%s, %s, %d, %p",
+       argstr = sprintf("%s, %s, %s, %p",
                _sock_family_str($family),
                _sock_type_str($type),
-               $protocol, sv_uaddr)
+               _sock_protocol_str($family, $protocol), sv_uaddr)
 }
 probe syscall.socketpair.return = kernel.function("sys_socketpair").return ?
 {
index 434d8f2bb59a44e2db8adf733bbdadd72b706961..7762dccef675218d57f6db967b342fafc92ccf9e 100644 (file)
@@ -13,7 +13,7 @@ int main()
   
 
   listenfd = socket(AF_INET, SOCK_STREAM, 0);
-  //staptest// socket (PF_INET, SOCK_STREAM, 0) = NNNN
+  //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_IP) = NNNN
 
   flags = fcntl(listenfd, F_GETFL, 0);
   //staptest// fcntl[64]* (NNNN, F_GETFL, 0x[0]+) = NNNN
diff --git a/testsuite/systemtap.syscall/socket.c b/testsuite/systemtap.syscall/socket.c
new file mode 100644 (file)
index 0000000..6df618b
--- /dev/null
@@ -0,0 +1,76 @@
+/* COVERAGE: socket */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/ip.h>
+
+int main()
+{
+  int s;
+
+  s = socket(PF_LOCAL, SOCK_STREAM, 0);
+  //staptest// socket (PF_LOCAL, SOCK_STREAM, 0) = NNNN
+
+  close(s);
+  //staptest// close (NNNN) = 0
+
+  socket(0, SOCK_STREAM, 0);
+  //staptest// socket (PF_UNSPEC, SOCK_STREAM, 0) = -NNNN (EAFNOSUPPORT)
+
+  socket(PF_INET, 75, IPPROTO_IP);
+  //staptest// socket (PF_INET, UNKNOWN VALUE: NNNN, IPPROTO_IP) = -NNNN (EINVAL)
+
+  s = socket(PF_LOCAL, SOCK_DGRAM, 0);
+  //staptest// socket (PF_LOCAL, SOCK_DGRAM, 0) = NNNN
+
+  close(s);
+  //staptest// close (NNNN) = 0
+
+  s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+  //staptest// socket (PF_INET, SOCK_DGRAM, IPPROTO_IP) = NNNN
+
+  close(s);
+  //staptest// close (NNNN) = 0
+
+  s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+  //staptest// socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP) = NNNN
+
+  close(s);
+  //staptest// close (NNNN) = 0
+
+  socket(PF_INET, SOCK_STREAM, IPPROTO_UDP);
+  //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_UDP) = -NNNN (EPROTONOSUPPORT)
+
+  socket(PF_INET, SOCK_DGRAM, IPPROTO_TCP);
+  //staptest// socket (PF_INET, SOCK_DGRAM, IPPROTO_TCP) = -NNNN (EPROTONOSUPPORT)
+
+  s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+  //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_TCP) = NNNN
+
+  close(s);
+  //staptest// close (NNNN) = 0
+
+  socket(PF_INET, SOCK_STREAM, IPPROTO_ICMP);
+  //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_ICMP) = -NNNN (EPROTONOSUPPORT)
+
+#ifdef SOCK_CLOEXEC
+  s = socket(PF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_IP);
+  //staptest// socket (PF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = NNNN
+
+  close(s);
+  //staptest// close (NNNN) = 0
+#endif
+
+#ifdef SOCK_NONBLOCK
+  s = socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_IP);
+  //staptest// socket (PF_INET, SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_IP) = NNNN
+
+  close(s);
+  //staptest// close (NNNN) = 0
+#endif
+
+  return 0;
+}
index e03d4ba5fd3460c4e63fd029ec36d86909475852..7319041684fa580aad186124dbcd835c756c14c4 100644 (file)
@@ -1,6 +1,7 @@
 /* COVERAGE: socketpair close */
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <netinet/ip.h>
 
 int main()
 {
@@ -9,23 +10,23 @@ int main()
     socketpair(0, SOCK_STREAM, 0, fds);
     //staptest// socketpair (PF_UNSPEC, SOCK_STREAM, 0, XXXX) = -NNNN (EAFNOSUPPORT)
 
-    socketpair(PF_INET, 75, 0, fds);
-    //staptest// socketpair (PF_INET, UNKNOWN VALUE: NNNN, 0, XXXX) = -NNNN (EINVAL)
+    socketpair(PF_INET, 75, IPPROTO_IP, fds);
+    //staptest// socketpair (PF_INET, UNKNOWN VALUE: NNNN, IPPROTO_IP, XXXX) = -NNNN (EINVAL)
 
     socketpair(PF_UNIX, SOCK_STREAM, 0, 0);
     //staptest// socketpair (PF_LOCAL, SOCK_STREAM, 0, 0x0) = -NNNN (EFAULT)
 
-    socketpair(PF_INET, SOCK_DGRAM, 17, fds);
-    //staptest// socketpair (PF_INET, SOCK_DGRAM, 17, XXXX) = -NNNN (EOPNOTSUPP)
+    socketpair(PF_INET, SOCK_DGRAM, IPPROTO_UDP, fds);
+    //staptest// socketpair (PF_INET, SOCK_DGRAM, IPPROTO_UDP, XXXX) = -NNNN (EOPNOTSUPP)
 
-    socketpair(PF_INET, SOCK_DGRAM, 6, fds);
-    //staptest// socketpair (PF_INET, SOCK_DGRAM, 6, XXXX) = -NNNN (EPROTONOSUPPORT)
+    socketpair(PF_INET, SOCK_DGRAM, IPPROTO_TCP, fds);
+    //staptest// socketpair (PF_INET, SOCK_DGRAM, IPPROTO_TCP, XXXX) = -NNNN (EPROTONOSUPPORT)
 
-    socketpair(PF_INET, SOCK_STREAM, 6, fds);
-    //staptest// socketpair (PF_INET, SOCK_STREAM, 6, XXXX) = -NNNN (EOPNOTSUPP)
+    socketpair(PF_INET, SOCK_STREAM, IPPROTO_TCP, fds);
+    //staptest// socketpair (PF_INET, SOCK_STREAM, IPPROTO_TCP, XXXX) = -NNNN (EOPNOTSUPP)
 
-    socketpair(PF_INET, SOCK_STREAM, 1, fds);
-    //staptest// socketpair (PF_INET, SOCK_STREAM, 1, XXXX) = -NNNN (EPROTONOSUPPORT)
+    socketpair(PF_INET, SOCK_STREAM, IPPROTO_ICMP, fds);
+    //staptest// socketpair (PF_INET, SOCK_STREAM, IPPROTO_ICMP, XXXX) = -NNNN (EPROTONOSUPPORT)
 
     socketpair(PF_UNIX, SOCK_DGRAM, 0, fds);
     //staptest// socketpair (PF_LOCAL, SOCK_DGRAM, 0, XXXX) = 0
@@ -43,6 +44,16 @@ int main()
     close(fds[1]);
     //staptest// close (NNNN) = 0
 
+#ifdef SOCK_CLOEXEC
+    socketpair(PF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds);
+    //staptest// socketpair (PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0, XXXX) = 0
+
+    close(fds[0]);
+    //staptest// close (NNNN) = 0
+    close(fds[1]);
+    //staptest// close (NNNN) = 0
+#endif
+
 #ifdef SOCK_NONBLOCK
     socketpair(PF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0, fds);
     //staptest// socketpair (PF_LOCAL, SOCK_STREAM|SOCK_NONBLOCK, 0, XXXX) = 0
This page took 0.047778 seconds and 5 git commands to generate.