// global InTruncatedPkts
global InDiscards // included counts of InHdrErrors InTruncatedPkts
// global InDelivers
+%( kernel_v >= "2.6.24" %?
global ForwDatagrams
+%)
global OutRequests
// global OutDiscards
// global OutNoRoutes
%{
struct sk_buff *skb = (struct sk_buff *)(long)THIS->skb;
/* as done by skb_network_header() */
+ #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
+ THIS->__retvalue=(long)kread(&(skb->nh.raw)) +
+ (long)sizeof(struct tcphdr);
+ #else
#ifdef NET_SKBUFF_DATA_USES_OFFSET
THIS->__retvalue=(long)kread(&(skb->network_header)) +
(long)(kread(&(skb->head))) +
THIS->__retvalue=(long)kread(&(skb->network_header)) +
(long)sizeof(struct tcphdr);
#endif
+ #endif
CATCH_DEREF_FAULT();
%}
* MIB: IPSTATS_MIB_OUTFORWDATAGRAMS
*
*/
+%( kernel_v >= "2.6.24" %?
probe ipmib.ForwDatagrams=kernel.function("ip_forward_finish")
{
skb = $skb;
key = ipmib_filter_key(skb,op,SourceIsLocal);
if ( key ) ForwDatagrams[key] += op;
}
+%)
/**
* probe tcpmib.OutRequests - Count a request to send a packet.
%}
global ActiveOpens
+%( kernel_v > "2.6.21" %?
global AttemptFails
+%)
+%( kernel_v > "2.6.24" %?
global CurrEstab
+%)
+%( kernel_v > "2.6.24" %?
global EstabResets
+%)
// global InErrs, this mib is not yet supported
global InSegs
global OutRsts
* MIB: TCP_MIB_ATTEMPTFAILS
*
*/
+%( kernel_v > "2.6.21" %?
probe
tcpmib.AttemptFails=kernel.function("tcp_done")
{
if ( key ) AttemptFails[key] += op;
}
}
+%)
/**
* probe tcpmib.CurrEstab - Update the count of open sockets.
* MIB: TCP_MIB_CURRESTAB
*
*/
+%( kernel_v > "2.6.24" %?
probe
tcpmib.CurrEstab=kernel.function("tcp_set_state")
{
}
}
}
+%)
/**
* probe tcpmib.EstabResets - Count the reset of a socket.
* MIB: TCP_MIB_ESTABRESETS
*
*/
+%( kernel_v > "2.6.24" %?
probe
tcpmib.EstabResets=kernel.function("tcp_set_state")
{
if ( key ) EstabResets[key] += op;
}
}
+%)
/**
* probe tcpmib.InSegs - Count an incomming tcp segment.
* MIB: TCP_MIB_INSEGS
*
*/
+%( kernel_v > "2.6.24" %?
probe
tcpmib.InSegs=kernel.function("__inet_lookup_established").return ?
{
key = tcpmib_filter_key(sk,op);
if ( key ) InSegs[key] += op;
}
+%:
+probe
+tcpmib.InSegs=kernel.function("tcp_v4_rcv")
+{
+ skb=$skb
+ op=1;
+ key = ipmib_filter_key(skb,op,0);
+ if ( key ) InSegs[key] += op;
+}
+%)
/**
* probe tcpmib.OutRsts - Count the sending of a reset packet.
struct tcphdr *th;
struct sk_buff *skb = (struct sk_buff *)(long)THIS->skb;
+ #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
+ th = (struct tcphdr *)kread(&(skb->h.th));
+ #else
+
#ifdef NET_SKBUFF_DATA_USES_OFFSET
th = (struct tcphdr *)(kread(&(skb->network_header)) + kread(&(skb->head)));
#else
th = (struct tcphdr *)kread(&(skb->network_header));
#endif
+ #endif
THIS->__retvalue = th->rst;
CATCH_DEREF_FAULT();
%}
function _tcpmib_input_route_type:long (skb:long)
-{
-%( kernel_v < "2.6.31" %?
- return __tcpmib_input_route_type_old(skb)
-%:
- return __tcpmib_input_route_type_new(skb)
-%)
-}
-
-function __tcpmib_input_route_type_old:long (skb:long)
%{ /* pure */
struct rtable *rt;
struct sk_buff *skb = (struct sk_buff *)(long)THIS->skb;
- rt = (struct rtable *)kread(&(skb->rtable));
- if ( rt )
- THIS->__retvalue = kread(&(rt->rt_type));
- else
- THIS->__retvalue = RTN_UNSPEC;
- CATCH_DEREF_FAULT();
-%}
-function __tcpmib_input_route_type_new:long (skb:long)
-%{ /* pure */
- struct rtable *rt;
- struct sk_buff *skb = (struct sk_buff *)(long)THIS->skb;
- rt = (struct rtable *)kread(&(skb->_skb_dst));
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
+ rt = (struct rtable *)kread(&(skb->_skb_dst));
+ #else
+
+ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
+ rt = (struct rtable *)kread(&(skb->dst));
+ #else
+ rt = (struct rtable *)kread(&(skb->rtable));
+ #endif
+ #endif
+
if ( rt )
THIS->__retvalue = kread(&(rt->rt_type));
else
if ( _is_reset(skb) ) next
if (_tcpmib_input_route_type($skb) != _rtn_local() )
next;
+%( kernel_v > "2.6.20" %?
key = tcpmib_filter_key(sk,op);
+%:
+ key = ipmib_filter_key(skb,op,1);
+%)
if ( key ) OutRsts[key] += op;
}
find_timer[key] = @cast(sk, "inet_connection_sock")->icsk_pending
}
+%( kernel_v > "2.6.24" %?
probe kernel.function("tcp_set_state")
{
sk = $sk
clean_up(key);
}
}
+%)
function print_header()
{
printf("\n");
}
+%( kernel_v > "2.6.24" %?
function print_close:long (key:long, new_state:long)
{
foreach ( [laddr, raddr, lport, rport] in key_list ){
printf("%-12s",state_num2str(new_state))
printf("\n");
}
+%)
/*
* Update the values in the data collection arrays, returns 1 if one or more
snd_wnd_flg = 1; continue };
if ( byte == "srtt" ) {
srtt_flg = 1; continue };
+%( kernel_v > "2.6.24" %?
if ( byte == "state" ) {
state_flg = 1; continue };
+%:
+ state_flg = 0;
+%)
if ( byte == "txq" ) {
txq_flg = 1; continue };
if ( byte == "rxq" ) {
length_flg = 1; continue };
if ( byte == "all" ) {
snd_cwnd_flg = snd_wnd_flg = srtt_flg =
- state_flg = txq_flg = rxq_flg =
+ txq_flg = rxq_flg =
rexmit_flg = pmtu_flg = ssthresh_flg =
timer_flg = rcvwnd_flg = length_flg = 1;
+%( kernel_v > "2.6.24" %?
+ state_flg = 1;
+%)
continue
};
usage("Unknown filter value given!")
/* default filter is all */
if ( !filter_given )
snd_cwnd_flg = snd_wnd_flg = srtt_flg =
- state_flg = txq_flg = rxq_flg =
+ txq_flg = rxq_flg =
rexmit_flg = pmtu_flg = ssthresh_flg =
timer_flg = rcvwnd_flg = length_flg = 1;
-
+%( kernel_v > "2.6.24" %?
+ state_flg = 1;
+%)
return filter_number;
}
}
/* Free up a slot in the data arrays */
+%( kernel_v > "2.6.24" %?
function clean_up (key:long)
{
foreach ( [laddr, raddr, lport, rport] in key_list ){
if (rcvwnd_flg) delete rcvwnd[key];
delete length[key];
}
+%)
/* Terminates the run in timeout seconds, using global timeout value */
probe timer.s(1) {
printf("\t\t\t[update=change|all] Rule\n\n");
printf("\tRule format:");
printf("<local address>:<local-port>-<remote address>:<remote-port>\n");
+%( kernel_v > "2.6.24" %?
printf("\tFilter values: all|state|txq|rxq|srtt|snd_cwnd|snd_wnd|\n");
+%:
+ printf("\tFilter values: all|txq|rxq|srtt|snd_cwnd|snd_wnd|\n");
+%)
printf("\t\t\trexmit|pmtu|ssthresh|timer|rcvwnd\n\n");
printf("%s\n\n",msg);
error(msg);
printf("Tcp:\n");
if (ActiveOpens[key]||!nozeros)
printf("\tActiveOpens = %d\n", ActiveOpens[key]);
+%( kernel_v > "2.6.21" %?
if (AttemptFails[key]||!nozeros)
printf("\tAttemptFails = %d\n", AttemptFails[key]);
+%)
+%( kernel_v > "2.6.24" %?
if (CurrEstab[key]||!nozeros)
printf("\tCurrEstab = %d\n", CurrEstab[key]);
+%)
+%( kernel_v > "2.6.24" %?
if (EstabResets[key]||!nozeros)
printf("\tEstabResets = %d\n", EstabResets[key]);
+%)
// if (InErrs[key]||!nozeros)
// printf("\tInErrs = %d\n", InErrs[key]);
if (InSegs[key]||!nozeros)
}
key = key_list[laddr, raddr, lport, rport]
+%( kernel_v > "2.6.24" %?
if ( onclose && (CurrEstab[key] < 0) )
printf("Stats were not collected for the entire socket life.\n")
+%)
printf("-----------------------------------------\n");
print_sockmib(key)
* the dump off all stats for this socket. This feature only makes sense
* when index=tuple.
*/
+%( kernel_v > "2.6.24" %?
probe tcpmib.CurrEstab
{
if (!onclose) next
delete key_list[laddr, raddr, lport, rport]
delete CurrEstab[key]
}
+%)
/* SNMP has no counter for the number of bytes sent or received by TCP.
global SockSendbytes;
global SockSendmsg;
probe tcp.sendmsg.return {
- sk = $sock->sk;
+%( kernel_v < "2.6.23" %?
+ sk=$sk;
+%:
+ sk = $sock->sk;
+%)
op = size; // $return
if ( op <= 0 ) next;
if ( !sk ) next;