* 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.
#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"
// 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 ?
{
// 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 ?
{
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 ?
{
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 ?
{
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
--- /dev/null
+/* 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;
+}
/* COVERAGE: socketpair close */
#include <sys/types.h>
#include <sys/socket.h>
+#include <netinet/ip.h>
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
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