]> sourceware.org Git - systemtap.git/commitdiff
Add and use a new macro @inet_sock_cast().
authorDavid Smith <dsmith@redhat.com>
Tue, 22 Aug 2017 19:44:03 +0000 (14:44 -0500)
committerDavid Smith <dsmith@redhat.com>
Tue, 22 Aug 2017 19:44:03 +0000 (14:44 -0500)
* tapset/linux/inet.stpm: Added new macro file.
* tapset/linux/inet_sock.stp: Use new @inet_sock_cast() macro to
  standardize casting a pointer to a "struct inet_sock".
* tapset/linux/ip.stp: Ditto.
* tapset/linux/tcp.stp: Ditto.

tapset/linux/inet.stpm [new file with mode: 0644]
tapset/linux/inet_sock.stp
tapset/linux/ip.stp
tapset/linux/tcp.stp

diff --git a/tapset/linux/inet.stpm b/tapset/linux/inet.stpm
new file mode 100644 (file)
index 0000000..80022a5
--- /dev/null
@@ -0,0 +1,11 @@
+// inet tapset macros
+// Copyright (C) 2017 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
+// later version.
+
+@define inet_sock_cast(ptr) %(
+    @cast(@ptr, "inet_sock", "kernel<net/ip.h><net/inet_sock.h>")
+%)
index e686e5bac3f0901fb093c9cd03995ba8a48fd0fd..ab452aeeb462167f4ba6628a015eef3b905979de 100644 (file)
  */
 function inet_get_local_port:long(sock:long)
 {
-    return @choose_defined(@cast(sock, "inet_sock")->sk->__sk_common->skc_num,
+    return @choose_defined(@inet_sock_cast(sock)->sk->__sk_common->skc_num,
             # kernel >= 2.6.33
-            @choose_defined(@cast(sock, "inet_sock")->inet_num,
+            @choose_defined(@inet_sock_cast(sock)->inet_num,
               # kernel >= 2.6.11
-              @choose_defined(@cast(sock, "inet_sock")->num,
-                @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->num)))
+              @choose_defined(@inet_sock_cast(sock)->num,
+                @inet_sock_cast(sock)->inet->num)))
 }
 
 /**
index 4f132280cddec8594516fa0f9fe2e170a7cd518b..5370084491438ec17c2c8567c81250a24146482d 100644 (file)
@@ -82,15 +82,15 @@ function ip_ntop:string (addr:long)
 
 function __ip_sock_saddr:long (sock:long)
 {
-    family = @cast(sock, "inet_sock", "kernel<net/ip.h>")->sk->__sk_common->skc_family
+    family = @inet_sock_cast(sock)->sk->__sk_common->skc_family
     if (family == @const("AF_INET")) {
-       return @choose_defined(@cast(sock, "inet_sock")->inet_saddr, # kernel >= 2.6.33
-               @choose_defined(@cast(sock, "inet_sock")->saddr, # kernel >= 2.6.11
-                   @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->saddr))
+       return @choose_defined(@inet_sock_cast(sock)->inet_saddr, # kernel >= 2.6.33
+               @choose_defined(@inet_sock_cast(sock)->saddr, # kernel >= 2.6.11
+                   @inet_sock_cast(sock)->inet->saddr))
     }
 %( CONFIG_IPV6 == "[ym]" %?
     else if (family == @const("AF_INET6")) {
-       return (&@cast(sock, "inet_sock", "kernel<net/ip.h>")->pinet6->saddr)
+       return (&@inet_sock_cast(sock)->pinet6->saddr)
     }
 %)
     return 0
@@ -99,17 +99,17 @@ function __ip_sock_saddr:long (sock:long)
 /* return the destination IP address for a given sock */
 function __ip_sock_daddr:long (sock:long)
 {
-    family = @cast(sock, "inet_sock", "kernel<net/ip.h>")->sk->__sk_common->skc_family
+    family = @inet_sock_cast(sock)->sk->__sk_common->skc_family
     if (family == @const("AF_INET")) {
-       return @choose_defined(@cast(sock, "inet_sock")->sk->__sk_common->skc_daddr, # kernel >= 2.6.38
-               @choose_defined(@cast(sock, "inet_sock")->inet_daddr, # kernel >= 2.6.33
-                   @choose_defined(@cast(sock, "inet_sock")->daddr, # kernel >= 2.6.11
-                       @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->daddr)))
+       return @choose_defined(@inet_sock_cast(sock)->sk->__sk_common->skc_daddr, # kernel >= 2.6.38
+               @choose_defined(@inet_sock_cast(sock)->inet_daddr, # kernel >= 2.6.33
+                   @choose_defined(@inet_sock_cast(sock)->daddr, # kernel >= 2.6.11
+                       @inet_sock_cast(sock)->inet->daddr)))
     }
 %( CONFIG_IPV6 == "[ym]" %?
     else if (family == @const("AF_INET6")) {
-       return @choose_defined(&@cast(sock, "inet_sock", "kernel<net/ip.h>")->sk->__sk_common->skc_v6_daddr,
-                              &@cast(sock, "inet_sock", "kernel<net/ip.h>")->pinet6->daddr)
+       return @choose_defined(&@inet_sock_cast(sock)->sk->__sk_common->skc_v6_daddr,
+                              &@inet_sock_cast(sock)->pinet6->daddr)
     }
 %)
     return 0
@@ -118,7 +118,7 @@ function __ip_sock_daddr:long (sock:long)
 /* return the IP address family for a given sock */
 function __ip_sock_family:long (sock:long)
 {
-    return (@cast(sock, "inet_sock", "kernel<net/ip.h>")->sk->__sk_common->skc_family)
+    return (@inet_sock_cast(sock)->sk->__sk_common->skc_family)
 }
 
 /* Get the IP header from a sk_buff struct */
index 9daefb27b7b7687a462f35101adabba3ca70b247..35796fbd690a43492a53eca16f433aae18324f89 100644 (file)
@@ -77,10 +77,10 @@ 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)
 {
-  port = @choose_defined(@cast(sock, "inet_sock", "kernel<net/inet_sock.h>")->sk->__sk_common->skc_dport, # kernel >= 3.8
-          @choose_defined(@cast(sock, "inet_sock")->inet_dport, # kernel >= 2.6.33
-           @choose_defined(@cast(sock, "inet_sock", "kernel")->dport, # kernel >= 2.6.11
-                           @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->dport)))
+  port = @choose_defined(@inet_sock_cast(sock)->sk->__sk_common->skc_dport, # kernel >= 3.8
+          @choose_defined(@inet_sock_cast(sock)->inet_dport, # kernel >= 2.6.33
+           @choose_defined(@inet_sock_cast(sock)->dport, # kernel >= 2.6.11
+                           @inet_sock_cast(sock)->inet->dport)))
   return ntohs(port)
 }
 
@@ -159,9 +159,9 @@ function __tcp_skb_dport:long (tcphdr:long){
 /* return the TCP source port for a given sock */
 function __tcp_sock_sport:long (sock:long)
 {
-    port = @choose_defined(@cast(sock, "inet_sock")->inet_sport, # kernel >= 2.6.33
-           @choose_defined(@cast(sock, "inet_sock", "kernel")->sport, # kernel >= 2.6.11
-               @cast(sock, "inet_sock", "kernel<net/ip.h>")->inet->sport))
+    port = @choose_defined(@inet_sock_cast(sock)->inet_sport, # kernel >= 2.6.33
+           @choose_defined(@inet_sock_cast(sock)->sport, # kernel >= 2.6.11
+               @inet_sock_cast(sock)->inet->sport))
     return ntohs(port)
 }
 
This page took 1.494461 seconds and 5 git commands to generate.