/* * Author: Kais Belgaied */ #pragma D option quiet #pragma D option dynvarsize=128m dtrace:::BEGIN { printf("Tracing... Hit Ctrl-C to end.\n"); tstamp = timestamp; } fbt:sockfs:socket_sendmsg:entry, fbt:sockfs:socket_recvmsg:entry /args[2] != NULL/ /* struct uio */ { self->uio = args[2]; /* struct uio */ self->uio_resid = self->uio->uio_resid; /* residual count */ } fbt::udp_send_not_connected:entry /self->uio != NULL/ { this->sin = &(args[2]->sa_data[2]); /* struct sockaddr */ self->addrv4 = stringof(inet_ntoa((ipaddr_t *)this->sin)); } fbt::udp_send_connected:entry /self->uio != NULL/ { this->v6addr = &args[0]->conn_proto_priv.cp_udp->udp_v6dst; /* conn_t, udp_v6dst is the connected destination */ /* Convert the IP address pointer to an IPv4 string */ self->addrv4 = stringof(inet_ntop(AF_INET, this->v6addr)); } fbt::udp_output_v4:entry /self->uio / { self->dst_port = args[3]; /* destination port*/ self->proto = "UDP"; } fbt::tcp_sendmsg:entry /self->uio / { this->tcp_conn = (conn_t *)args[0]; /* sock_lower_handle_t */ self->dst_port = this->tcp_conn->u_port.tcpu_ports.tcpu_fport; /* destination port */ /* Convert the IP address pointer to an IPv4 string */ self->addrv4 = stringof(inet_ntoa6(&(this->tcp_conn->connua_v6addr.connua_faddr))); self->proto = "TCP"; } /* * Aggregate the results */ fbt:sockfs:socket_sendmsg:return /self->uio != NULL && self->addrv4 != NULL && self->proto != NULL/ { /* Aggregate the results, converting bytes to bits */ @rw[execname, zonename, self->proto, self->addrv4, ntohs(self->dst_port)] = sum((self->uio_resid - self->uio->uio_resid)*8); self->uid = 0; self->uio_resid = 0; self->addrv4 = 0; } fbt:sockfs:socket_sendmsg:return { /* reset the thread-local variables */ self->uid = 0; self->uio_resid = 0; } dtrace:::END { printf("%-20s %-10s %-10s %-15s %5s %15s\n", "Process", "Zone", "Protocol", "Destination", "Port", "Bits\n"); printa("%-20s %-10s %-10s %-15s %5d %@15u\n", @rw); printf("\nTrace ran for %d seconds\n", (timestamp - tstamp)/1000000000); }