hi Hans-Peter
the good news is this will be a lot easier soon - we
recently integrated a DTrace tcp provider, and it
will be as easy as
tcp:::send
/ args[1]->cs_pid == $1 /
{
...
}
See:
http://wikis.sun.com/display/DTrace/tcp+Provider
...for more details.
In the interim (assuming you are using OpenSolaris
not Solaris 10), it might be worth tracing at the tcp
layer rather than at the socket layer (assuming
you're not doing anything timing-wise that
needs to be done at the socket layer):
fbt:ip:tcp_send_data:entry
/ args[0]->tcp_connp->conn_ixa->ixa_cpid == $1 /
{
printf("TCP send : pid %d laddr/port : %s/%d raddr/port %s/%d\n",
args[0]->tcp_connp->conn_ixa->ixa_cpid,
inet_ntoa6(&args[0]->tcp_connp->connua_v6addr.connua_laddr),
ntohs(args[0]->tcp_connp->u_port.connu_ports.connu_lport),
inet_ntoa6(&args[0]->tcp_connp->connua_v6addr.connua_faddr),
ntohs(args[0]->tcp_connp->u_port.connu_ports.connu_fport));
}
Sample output:
1 46446 tcp_send_data:entry TCP send : pid 132408
laddr/port : 129.150.120.230/46294 raddr/port 208.52.173.220/443
1 46446 tcp_send_data:entry TCP send : pid 132408
laddr/port : 129.150.120.230/34961 raddr/port 12.129.147.65/80
1 46446 tcp_send_data:entry TCP send : pid 132408
laddr/port : 129.150.120.230/34961 raddr/port 12.129.147.65/80
You'll need to use fbt::fuse-output:entry too for
TCP-fused localhost connections (where TCP
doesn't bother encapsulating localhost traffic
in TCP headers for performance reasons), and
this will also miss some TCP control segments,
but it may be good enough to see what's going on.
This will only work on reasonably recent builds
(130ish+) of OpenSolaris I suspect.
Hope this helps,
Alan
On 03/06/2010 11:35, Hans-Peter wrote:
Hi
I am trying to make a dtrace script that captures tcp packets sent by a
specific process.
But I receive the message:
dtrace: error on enabled probe ID 3 (ID 35884:
fbt:sockfs:sostream_direct:return): invalid address (0x106390000) in action #1
at DIF offset 12
Can someone explain why this happens?
regards HansP
#!/usr/sbin/dtrace -Cs
/*
* Command line arguments
*/
#include<sys/file.h>
#include<inet/common.h>
#include<sys/byteorder.h>
#include<sys/socket.h>
#include<sys/socketvar.h>
/*
* Print header
*/
dtrace:::BEGIN
{
/* starting values */
counts = COUNTER;
secs = INTERVAL;
TCP_out = 0;
TCP_in = 0;
printf("Tracing... Please wait.\n");
start = 0;
}
fbt:sockfs:sostream_direct:entry
/ pid == $1&& start == 0 /
{
self->sop = 1;
self->nsop = (struct sonode *)arg1;
self->tcpp = (tcp_t *)self->nsop->so_priv;
self->laddrs = self->nsop->so_laddr_sa;
start = 1;
printf("%50s :
%10d\n","fbt:sockfs:sostream_direct:entry",self->nsop->so_sndbuf);
}
fbt:sockfs:sostream_direct:return
/ pid == $1&& start == 1 /
{
self->connp = (conn_t *)self->tcpp->tcp_connp;
/*printf("%50s
%10d\n","fbt:sockfs:sostream_direct:return",self->laddr->soa_len); */
printf("%50s \n","fbt:sockfs:sostream_direct:return");
}
_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org