summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Smith <dsmith@redhat.com>2010-03-26 13:24:38 -0500
committerDavid Smith <dsmith@redhat.com>2010-03-26 13:24:38 -0500
commit961479c253ded0d1a7331e8d064ffbc0ca3358d7 (patch)
tree21b11aca671c8d74c5584fec7dbd4b255b81b832
parentfc80eab8cc1cbebad78df914a885cb74cbd91f22 (diff)
downloadsystemtap-steved-961479c253ded0d1a7331e8d064ffbc0ca3358d7.tar.gz
systemtap-steved-961479c253ded0d1a7331e8d064ffbc0ca3358d7.tar.xz
systemtap-steved-961479c253ded0d1a7331e8d064ffbc0ca3358d7.zip
PR 9871/11338 fix in tcpmib.stp by removing embedded-C and using @defined.
* tapset/tcpmib.stp (tcpmib_get_state): Changed from embedded-C to script code. (tcpmib_local_addr): Instead of an embedded-C function, now calls function from ip.stp/tcp.stp. (tcpmib_remote_addr): Ditto. (tcpmib_local_port): Ditto. (tcpmib_remote_port): Ditto. (tcpmib.OutRsts.A): Used '@defined' instead of a kernel version check. * tapset/ip.stp (__ip_sock_saddr): Used '@defined' instead of a kernel version check. Added RHEL4 support. (__ip_sock_daddr): Ditto. * tapset/tcp.stp (__tcp_sock_dport): Ditto. (__tcp_sock_sport): Ditto.
-rw-r--r--tapset/ip.stp23
-rw-r--r--tapset/tcp.stp54
-rw-r--r--tapset/tcpmib.stp80
3 files changed, 69 insertions, 88 deletions
diff --git a/tapset/ip.stp b/tapset/ip.stp
index ec17b7c0..123a2728 100644
--- a/tapset/ip.stp
+++ b/tapset/ip.stp
@@ -1,5 +1,8 @@
// IP tapset
+//
// Copyright (C) 2009, IBM Inc.
+// Copyright (C) 2010, Red Hat Inc.
+//
// Author : Breno Leitao <leitao@linux.vnet.ibm.com>
//
// This file is free software. You can redistribute it and/or modify it under
@@ -26,21 +29,21 @@ function ip_ntop:string (addr:long)
/* return the source IP address for a given sock */
function __ip_sock_saddr:long (sock:long)
{
-%(kernel_v < "2.6.33" %?
- return @cast(sock, "inet_sock")->saddr
-%:
- return @cast(sock, "inet_sock")->inet_saddr
-%)
+ return (@defined(@cast(sock, "inet_sock")->inet_saddr)
+ ? @cast(sock, "inet_sock")->inet_saddr # kernel >= 2.6.33
+ : (@defined(@cast(sock, "inet_sock")->saddr)
+ ? @cast(sock, "inet_sock", "kernel")->saddr # kernel >= 2.6.11
+ : @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->saddr))
}
/* return the destination IP address for a given sock */
function __ip_sock_daddr:long (sock:long)
{
-%(kernel_v < "2.6.33" %?
- return @cast(sock, "inet_sock")->daddr
-%:
- return @cast(sock, "inet_sock")->inet_daddr
-%)
+ return (@defined(@cast(sock, "inet_sock")->inet_daddr)
+ ? @cast(sock, "inet_sock")->inet_daddr # kernel >= 2.6.33
+ : (@defined(@cast(sock, "inet_sock")->daddr)
+ ? @cast(sock, "inet_sock", "kernel")->daddr # kernel >= 2.6.11
+ : @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->daddr))
}
/* Get the IP header for recent (> 2.6.21) kernels */
diff --git a/tapset/tcp.stp b/tapset/tcp.stp
index 094161c9..cf6c36d8 100644
--- a/tapset/tcp.stp
+++ b/tapset/tcp.stp
@@ -1,7 +1,7 @@
// TCP tapset
// Copyright (C) 2006 IBM Corp.
// Copyright (C) 2006 Intel Corporation.
-// Copyright (C) 2007 Red Hat, Inc.
+// Copyright (C) 2007,2010 Red Hat, Inc.
//
// This file is part of systemtap, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
@@ -75,12 +75,13 @@ function tcp_ts_get_info_state:long(sock:long)
%}
/* return the TCP destination port for a given sock */
-function __tcp_sock_dport:long (sock:long){
-%(kernel_v < "2.6.33" %?
- return @cast(sock, "inet_sock")->dport
-%:
- return @cast(sock, "inet_sock")->inet_dport
-%)
+function __tcp_sock_dport:long (sock:long)
+{
+ return (@defined(@cast(sock, "inet_sock")->inet_dport)
+ ? @cast(sock, "inet_sock")->inet_dport # kernel >= 2.6.33
+ : (@defined(@cast(sock, "inet_sock")->dport)
+ ? @cast(sock, "inet_sock", "kernel")->dport # kernel >= 2.6.11
+ : @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->dport))
}
/* returns the TCP header for recent (<2.6.21) kernel */
@@ -98,7 +99,8 @@ function __get_skb_tcphdr_new:long(skb:long)
%}
/* returns the TCP header for a given sk_buff structure */
-function __get_skb_tcphdr:long(skb:long){
+function __get_skb_tcphdr:long(skb:long)
+{
%( kernel_v < "2.6.21" %?
tcphdr = @cast(skb, "sk_buff")->h->raw
return tcphdr
@@ -108,52 +110,60 @@ function __get_skb_tcphdr:long(skb:long){
}
/* returns TCP URG flag for a given sk_buff structure */
-function __tcp_skb_urg:long (tcphdr){
+function __tcp_skb_urg:long (tcphdr:long)
+{
return @cast(tcphdr, "tcphdr")->urg
}
/* returns TCP ACK flag for a given sk_buff structure */
-function __tcp_skb_ack:long (tcphdr){
+function __tcp_skb_ack:long (tcphdr:long)
+{
return @cast(tcphdr, "tcphdr")->ack
}
/* returns TCP PSH flag for a given sk_buff structure */
-function __tcp_skb_psh:long (tcphdr){
+function __tcp_skb_psh:long (tcphdr:long)
+{
return @cast(tcphdr, "tcphdr")->psh
}
/* returns TCP RST flag for a given sk_buff structure */
-function __tcp_skb_rst:long (tcphdr){
+function __tcp_skb_rst:long (tcphdr:long)
+{
return @cast(tcphdr, "tcphdr")->rst
}
/* returns TCP SYN flag for a given sk_buff structure */
-function __tcp_skb_syn:long (tcphdr){
+function __tcp_skb_syn:long (tcphdr:long)
+{
return @cast(tcphdr, "tcphdr")->syn
}
/* returns TCP FIN flag for a given sk_buff structure */
-function __tcp_skb_fin:long (tcphdr){
+function __tcp_skb_fin:long (tcphdr:long)
+{
return @cast(tcphdr, "tcphdr")->fin
}
/* returns TCP source port for a given sk_buff structure */
-function __tcp_skb_sport:long (tcphdr){
+function __tcp_skb_sport:long (tcphdr:long)
+{
return ntohs(@cast(tcphdr, "tcphdr")->source)
}
/* returns TCP destination port for a given sk_buff structure */
-function __tcp_skb_dport:long (tcphdr){
+function __tcp_skb_dport:long (tcphdr:long){
return @cast(tcphdr, "tcphdr")->dest
}
/* return the TCP source port for a given sock */
-function __tcp_sock_sport:long (sock:long){
-%(kernel_v < "2.6.33" %?
- return @cast(sock, "inet_sock")->sport
-%:
- return @cast(sock, "inet_sock")->inet_sport
-%)
+function __tcp_sock_sport:long (sock:long)
+{
+ return (@defined(@cast(sock, "inet_sock")->inet_sport)
+ ? @cast(sock, "inet_sock")->inet_sport # kernel >= 2.6.33
+ : (@defined(@cast(sock, "inet_sock")->sport)
+ ? @cast(sock, "inet_sock", "kernel")->sport # kernel >= 2.6.11
+ : @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->sport))
}
global sockstate[13], sockstate_init_p
diff --git a/tapset/tcpmib.stp b/tapset/tcpmib.stp
index 6a9b8145..45b94cc6 100644
--- a/tapset/tcpmib.stp
+++ b/tapset/tcpmib.stp
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2009 IBM Corp.
+ * Copyright (C) 2010 Red Hat Inc.
+ *
* This file is part of systemtap, and is free software. You can
* redistribute it and/or modify it under the terms of the GNU General
* Public License (GPL); either version 2, or (at your option) any
@@ -13,7 +15,6 @@
%{
#include <net/sock.h>
#include <linux/tcp.h>
-#include <net/tcp_states.h>
#include <linux/skbuff.h>
#include <net/route.h>
%}
@@ -43,83 +44,57 @@ global RetransSegs
*
*/
function tcpmib_get_state:long (sk:long)
-%{ /* pure */
- struct sock *sk = (struct sock *)(long)THIS->sk;
- THIS->__retvalue = kread(&(sk->sk_state));
- CATCH_DEREF_FAULT();
-%}
+{
+ return @cast(sk, "sock", "kernel")->__sk_common->skc_state;
+}
/**
* sfunction tcpmib_local_addr - Get the source address.
*
- * Returns the saddr from a struct inet_sock.
+ * Returns the saddr from a struct inet_sock in host order.
* @sk: Pointer to a struct inet_sock.
*
*/
function tcpmib_local_addr:long(sk:long)
-%{ /* pure */
- struct inet_sock *inet = (struct inet_sock *) (long) THIS->sk;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
- THIS->__retvalue = ntohl(kread(&(inet->inet_saddr)));
-#else
- THIS->__retvalue = ntohl(kread(&(inet->saddr)));
-#endif
- CATCH_DEREF_FAULT();
-%}
+{
+ return ntohl(__ip_sock_saddr(sk))
+}
/**
* sfunction tcpmib_remote_addr - Get the remote address.
*
- * Returns the daddr from a struct inet_sock.
+ * Returns the daddr from a struct inet_sock in host order.
* @sk: Pointer to a struct inet_sock.
*
*/
function tcpmib_remote_addr:long(sk:long)
-%{ /* pure */
- struct inet_sock *inet = (struct inet_sock *) (long) THIS->sk;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
- THIS->__retvalue = ntohl(kread(&(inet->inet_daddr)));
-#else
- THIS->__retvalue = ntohl(kread(&(inet->daddr)));
-#endif
- CATCH_DEREF_FAULT();
-%}
+{
+ return ntohl(__ip_sock_daddr(sk))
+}
/**
* sfunction tcpmib_local_port - Get the local port.
*
- * Returns the sport from a struct inet_sock.
+ * Returns the sport from a struct inet_sock in host order.
* @sk: Pointer to a struct inet_sock.
*
*/
function tcpmib_local_port:long(sk:long)
-%{ /* pure */
- struct inet_sock *inet = (struct inet_sock *) (long) THIS->sk;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
- THIS->__retvalue = ntohs(kread(&(inet->inet_sport)));
-#else
- THIS->__retvalue = ntohs(kread(&(inet->sport)));
-#endif
- CATCH_DEREF_FAULT();
-%}
+{
+ return ntohs(__tcp_sock_sport(sk))
+}
/**
* sfunction tcpmib_remote_port - Get the remote port.
*
- * Returns the dport from a struct inet_sock.
+ * Returns the dport from a struct inet_sock in host order.
* @sk: Pointer to a struct inet_sock.
*
*/
function tcpmib_remote_port:long(sk:long)
-%{ /* pure */
- struct inet_sock *inet = (struct inet_sock *) (long) THIS->sk;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
- THIS->__retvalue = ntohs(kread(&(inet->inet_dport)));
-#else
- THIS->__retvalue = ntohs(kread(&(inet->dport)));
-#endif
- CATCH_DEREF_FAULT();
-%}
+{
+ return ntohs(__tcp_sock_dport(sk))
+}
/**
* probe tcpmib.ActiveOpens - Count an active opening of a socket.
@@ -327,21 +302,14 @@ function _tcpmib_input_route_type:long (skb:long)
probe
tcpmib.OutRsts.A=kernel.function("tcp_v4_send_reset")
{
-%( kernel_v >= "2.6.20" %?
- sk = $sk;
-%:
- sk = 0;
-%)
+ sk = (@defined($sk) ? $sk : 0)
skb = $skb
op = 1;
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);
-%)
+ key = (@defined($sk) ? tcpmib_filter_key(sk,op)
+ : ipmib_filter_key(skb,op,1))
if ( key ) OutRsts[key] += op;
}