| 1 |
// TCP tapset |
| 2 |
// Copyright (C) 2006 IBM Corp. |
| 3 |
// Copyright (C) 2006 Intel Corporation. |
| 4 |
// Copyright (C) 2007, 2010, 2012-2024 Red Hat, Inc. |
| 5 |
// |
| 6 |
// This file is part of systemtap, and is free software. You can |
| 7 |
// redistribute it and/or modify it under the terms of the GNU General |
| 8 |
// Public License (GPL); either version 2, or (at your option) any |
| 9 |
// later version. |
| 10 |
// <tapsetdescription> |
| 11 |
// This family of probe points is used to probe events that occur in the TCP layer, |
| 12 |
// </tapsetdescription> |
| 13 |
|
| 14 |
// See the BZ1546179 block comment in tapset/linux/networking.stp for |
| 15 |
// an explanation of the try/catch statements around sk_buff structure |
| 16 |
// accesses. |
| 17 |
|
| 18 |
%{ |
| 19 |
#include <linux/version.h> |
| 20 |
#include <net/sock.h> |
| 21 |
#include <net/tcp.h> |
| 22 |
#include <net/ip.h> |
| 23 |
#include <linux/skbuff.h> |
| 24 |
%} |
| 25 |
|
| 26 |
// Get retransmission timeout in usecs. RTO is initialized from default |
| 27 |
// retransmission time, but can be adjusted (increased) each time we |
| 28 |
// retransmit. It should always be less than the max value of TCP retransmission |
| 29 |
// timeout (TCP_RTO_MAX) |
| 30 |
function tcp_get_info_rto:long(sock:long) |
| 31 |
%{ /* pure */ |
| 32 |
struct sock *sk = (struct sock *)(uintptr_t) STAP_ARG_sock; |
| 33 |
const struct inet_connection_sock *icsk = inet_csk(sk); |
| 34 |
STAP_RETVALUE = (int64_t) jiffies_to_usecs(kread(&(icsk->icsk_rto))); |
| 35 |
CATCH_DEREF_FAULT(); |
| 36 |
%} |
| 37 |
|
| 38 |
//Get congestion window segment size. Initial value of congestion window size |
| 39 |
//typically set to one segment (i.e., slow start algorithm, each segment can be 512 bytes). |
| 40 |
//This congestion window size can be dynamically increased based on whether TCP |
| 41 |
//is performing slow start or congestion avoidance. |
| 42 |
function tcp_get_info_snd_cwnd:long(sock:long) |
| 43 |
%{ /* pure */ |
| 44 |
struct sock *sk = (struct sock *)(uintptr_t) STAP_ARG_sock; |
| 45 |
struct tcp_sock *tp = tcp_sk(sk); |
| 46 |
STAP_RETVALUE = (int64_t) kread(&(tp->snd_cwnd)); |
| 47 |
CATCH_DEREF_FAULT(); |
| 48 |
%} |
| 49 |
|
| 50 |
// |
| 51 |
//Definitions of the TCP protocol sk_state field listed below. |
| 52 |
// |
| 53 |
// TCP_ESTABLISHED = 1, Normal data transfer |
| 54 |
// TCP_SYN_SENT = 2, App. has started to open a connection |
| 55 |
// TCP_SYN_RECV = 3, A connection request has arrived; wait for ACK |
| 56 |
// TCP_FIN_WAIT1 = 4, App. has said it is finished |
| 57 |
// TCP_FIN_WAIT2 = 5, The other side has agreed to close |
| 58 |
// TCP_TIME_WAIT = 6, Wait for all packets to die off |
| 59 |
// TCP_CLOSE = 7, No connection is active or pending |
| 60 |
// TCP_CLOSE_WAIT = 8, The other side has initiated a release |
| 61 |
// TCP_LAST_ACK = 9, Last ACK, wait for all packets to die off |
| 62 |
// TCP_LISTEN = 10, Waiting for incoming call |
| 63 |
// TCP_CLOSING = 11, Both sides have tried to close simultaneously |
| 64 |
// TCP_MAX_STATES = 12 Max states number |
| 65 |
// |
| 66 |
function tcp_ts_get_info_state:long(sock:long) |
| 67 |
%{ /* pure */ |
| 68 |
struct sock *sk = (struct sock *)(uintptr_t) STAP_ARG_sock; |
| 69 |
STAP_RETVALUE = (int64_t) kread(&(sk->sk_state)); |
| 70 |
CATCH_DEREF_FAULT(); |
| 71 |
%} |
| 72 |
|
| 73 |
/* return the TCP destination port for a given sock */ |
| 74 |
function __tcp_sock_dport:long (sock:long) |
| 75 |
{ |
| 76 |
port = @choose_defined(@inet_sock_cast(sock)->sk->__sk_common->skc_dport, # kernel >= 3.8 |
| 77 |
@choose_defined(@inet_sock_cast(sock)->inet_dport, # kernel >= 2.6.33 |
| 78 |
@choose_defined(@inet_sock_cast(sock)->dport, # kernel >= 2.6.11 |
| 79 |
@inet_sock_cast(sock)->inet->dport))) |
| 80 |
return ntohs(port) |
| 81 |
} |
| 82 |
|
| 83 |
/* returns the TCP header for recent (<2.6.21) kernel */ |
| 84 |
@__private30 function __get_skb_tcphdr_new:long(skb:long) |
| 85 |
%{ /* pure */ |
| 86 |
struct sk_buff *skb; |
| 87 |
skb = (struct sk_buff *)(uintptr_t)STAP_ARG_skb; |
| 88 |
/* as done by skb_transport_header() */ |
| 89 |
#ifdef NET_SKBUFF_DATA_USES_OFFSET |
| 90 |
STAP_RETVALUE = (long)(kread(&(skb->head)) + kread(&(skb->transport_header))); |
| 91 |
#else |
| 92 |
STAP_RETVALUE = (long)kread(&(skb->transport_header)); |
| 93 |
#endif |
| 94 |
CATCH_DEREF_FAULT(); |
| 95 |
%} |
| 96 |
|
| 97 |
/* returns the TCP header for a given sk_buff structure */ |
| 98 |
function __get_skb_tcphdr:long(skb:long) |
| 99 |
{ |
| 100 |
%( kernel_v < "2.6.21" %? |
| 101 |
tcphdr = @cast(skb, "sk_buff")->h->raw |
| 102 |
return tcphdr |
| 103 |
%: |
| 104 |
return __get_skb_tcphdr_new(skb) |
| 105 |
%) |
| 106 |
} |
| 107 |
|
| 108 |
/* returns TCP URG flag for a given sk_buff structure */ |
| 109 |
function __tcp_skb_urg:long (tcphdr:long) |
| 110 |
{ |
| 111 |
return @cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->urg |
| 112 |
} |
| 113 |
|
| 114 |
/* returns TCP ACK flag for a given sk_buff structure */ |
| 115 |
function __tcp_skb_ack:long (tcphdr:long) |
| 116 |
{ |
| 117 |
return @cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->ack |
| 118 |
} |
| 119 |
|
| 120 |
/* returns TCP PSH flag for a given sk_buff structure */ |
| 121 |
function __tcp_skb_psh:long (tcphdr:long) |
| 122 |
{ |
| 123 |
return @cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->psh |
| 124 |
} |
| 125 |
|
| 126 |
/* returns TCP RST flag for a given sk_buff structure */ |
| 127 |
function __tcp_skb_rst:long (tcphdr:long) |
| 128 |
{ |
| 129 |
return @cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->rst |
| 130 |
} |
| 131 |
|
| 132 |
/* returns TCP SYN flag for a given sk_buff structure */ |
| 133 |
function __tcp_skb_syn:long (tcphdr:long) |
| 134 |
{ |
| 135 |
return @cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->syn |
| 136 |
} |
| 137 |
|
| 138 |
/* returns TCP FIN flag for a given sk_buff structure */ |
| 139 |
function __tcp_skb_fin:long (tcphdr:long) |
| 140 |
{ |
| 141 |
return @cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->fin |
| 142 |
} |
| 143 |
|
| 144 |
/* returns TCP source port for a given sk_buff structure */ |
| 145 |
function __tcp_skb_sport:long (tcphdr:long) |
| 146 |
{ |
| 147 |
return ntohs(@cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->source) |
| 148 |
} |
| 149 |
|
| 150 |
/* returns TCP destination port for a given sk_buff structure */ |
| 151 |
function __tcp_skb_dport:long (tcphdr:long){ |
| 152 |
return ntohs(@cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->dest) |
| 153 |
} |
| 154 |
|
| 155 |
/* return the TCP source port for a given sock */ |
| 156 |
function __tcp_sock_sport:long (sock:long) |
| 157 |
{ |
| 158 |
port = @choose_defined(@inet_sock_cast(sock)->inet_sport, # kernel >= 2.6.33 |
| 159 |
@choose_defined(@inet_sock_cast(sock)->sport, # kernel >= 2.6.11 |
| 160 |
@inet_sock_cast(sock)->inet->sport)) |
| 161 |
return ntohs(port) |
| 162 |
} |
| 163 |
|
| 164 |
function __tcp_skb_seq:long (tcphdr:long) |
| 165 |
{ |
| 166 |
return ntohl(@cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->seq) |
| 167 |
} |
| 168 |
|
| 169 |
function __tcp_skb_ackseq:long (tcphdr:long) |
| 170 |
{ |
| 171 |
return ntohl(@cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->ack_seq) |
| 172 |
} |
| 173 |
|
| 174 |
function __tcp_skb_window:long (tcphdr:long) |
| 175 |
{ |
| 176 |
return ntohs(@cast(tcphdr, "tcphdr", "kernel<linux/tcp.h>")->window) |
| 177 |
} |
| 178 |
|
| 179 |
@__private30 global sockstate[12] |
| 180 |
probe init { |
| 181 |
sockstate[1] = "TCP_ESTABLISHED" |
| 182 |
sockstate[2] = "TCP_SYN_SENT" |
| 183 |
sockstate[3] = "TCP_SYN_RECV" |
| 184 |
sockstate[4] = "TCP_FIN_WAIT1" |
| 185 |
sockstate[5] = "TCP_FIN_WAIT2" |
| 186 |
sockstate[6] = "TCP_TIME_WAIT" |
| 187 |
sockstate[7] = "TCP_CLOSE" |
| 188 |
sockstate[8] = "TCP_CLOSE_WAIT" |
| 189 |
sockstate[9] = "TCP_LAST_ACK" |
| 190 |
sockstate[10] = "TCP_LISTEN" |
| 191 |
sockstate[11] = "TCP_CLOSING" |
| 192 |
sockstate[12] = "TCP_MAX_STATES" |
| 193 |
} |
| 194 |
|
| 195 |
function tcp_sockstate_str:string (state:long) { |
| 196 |
return (state in sockstate ? sockstate[state] : "UNDEF") |
| 197 |
} |
| 198 |
|
| 199 |
// Get slow start threshold size. If cwnd size is less than or equal to |
| 200 |
// threshold size, then TCP is in slow start; otherwise TCP is in congestion |
| 201 |
// avoidance. |
| 202 |
function tcp_ts_get_info_snd_ssthresh:long(sock:long) |
| 203 |
%{ /* pure */ |
| 204 |
struct sock *sk = (struct sock *)(uintptr_t) STAP_ARG_sock; |
| 205 |
struct tcp_sock *tp = tcp_sk(sk); |
| 206 |
STAP_RETVALUE = (int64_t) kread(&(tp->snd_ssthresh)); |
| 207 |
CATCH_DEREF_FAULT(); |
| 208 |
%} |
| 209 |
|
| 210 |
// Get receiver's advertised segment size. TCP typically never sends more |
| 211 |
// than what receiver can accept. |
| 212 |
function tcp_ts_get_info_rcv_mss:long(sock:long) |
| 213 |
%{ /* pure */ |
| 214 |
struct sock *sk = (struct sock *)(uintptr_t) STAP_ARG_sock; |
| 215 |
const struct inet_connection_sock *icsk = inet_csk(sk); |
| 216 |
STAP_RETVALUE = (int64_t) kread(&(icsk->icsk_ack.rcv_mss)); |
| 217 |
CATCH_DEREF_FAULT(); |
| 218 |
%} |
| 219 |
|
| 220 |
%{ |
| 221 |
// Define newer IPv4 sockopt constants for older kernels. |
| 222 |
#ifndef TCP_CONGESTION |
| 223 |
#define TCP_CONGESTION 0 |
| 224 |
#endif |
| 225 |
#ifndef TCP_MD5SIG |
| 226 |
#define TCP_MD5SIG 0 |
| 227 |
#endif |
| 228 |
#ifndef TCP_COOKIE_TRANSACTIONS |
| 229 |
#define TCP_COOKIE_TRANSACTIONS 0 |
| 230 |
#endif |
| 231 |
#ifndef TCP_THIN_LINEAR_TIMEOUTS |
| 232 |
#define TCP_THIN_LINEAR_TIMEOUTS 0 |
| 233 |
#endif |
| 234 |
#ifndef TCP_THIN_DUPACK |
| 235 |
#define TCP_THIN_DUPACK 0 |
| 236 |
#endif |
| 237 |
#ifndef TCP_USER_TIMEOUT |
| 238 |
#define TCP_USER_TIMEOUT 0 |
| 239 |
#endif |
| 240 |
%} |
| 241 |
|
| 242 |
@__private30 global __sockopt[18] |
| 243 |
probe init { |
| 244 |
__sockopt[@const("TCP_NODELAY")] = "TCP_NODELAY" |
| 245 |
__sockopt[@const("TCP_MAXSEG")] = "TCP_MAXSEG" |
| 246 |
__sockopt[@const("TCP_CORK")] = "TCP_CORK" |
| 247 |
__sockopt[@const("TCP_KEEPIDLE")] = "TCP_KEEPIDLE" |
| 248 |
__sockopt[@const("TCP_KEEPINTVL")] = "TCP_KEEPINTVL" |
| 249 |
__sockopt[@const("TCP_KEEPCNT")] = "TCP_KEEPCNT" |
| 250 |
__sockopt[@const("TCP_SYNCNT")] = "TCP_SYNCNT" |
| 251 |
__sockopt[@const("TCP_LINGER2")] = "TCP_LINGER2" |
| 252 |
__sockopt[@const("TCP_DEFER_ACCEPT")] = "TCP_DEFER_ACCEPT" |
| 253 |
__sockopt[@const("TCP_WINDOW_CLAMP")] = "TCP_WINDOW_CLAMP" |
| 254 |
__sockopt[@const("TCP_INFO")] = "TCP_INFO" |
| 255 |
__sockopt[@const("TCP_QUICKACK")] = "TCP_QUICKACK" |
| 256 |
if (@const("TCP_CONGESTION") > 0) |
| 257 |
__sockopt[@const("TCP_CONGESTION")] |
| 258 |
= "TCP_CONGESTION" |
| 259 |
if (@const("TCP_MD5SIG") > 0) |
| 260 |
__sockopt[@const("TCP_MD5SIG")] = "TCP_MD5SIG" |
| 261 |
if (@const("TCP_COOKIE_TRANSACTIONS") > 0) |
| 262 |
__sockopt[@const("TCP_COOKIE_TRANSACTIONS")] |
| 263 |
= "TCP_COOKIE_TRANSACTIONS" |
| 264 |
if (@const("TCP_THIN_LINEAR_TIMEOUTS") > 0) |
| 265 |
__sockopt[@const("TCP_THIN_LINEAR_TIMEOUTS")] |
| 266 |
= "TCP_THIN_LINEAR_TIMEOUTS" |
| 267 |
if (@const("TCP_THIN_DUPACK") > 0) |
| 268 |
__sockopt[@const("TCP_THIN_DUPACK")] |
| 269 |
= "TCP_THIN_DUPACK" |
| 270 |
if (@const("TCP_USER_TIMEOUT") > 0) |
| 271 |
__sockopt[@const("TCP_USER_TIMEOUT")] |
| 272 |
= "TCP_USER_TIMEOUT" |
| 273 |
} |
| 274 |
|
| 275 |
function tcp_sockopt_str:string (optname:long) |
| 276 |
{ |
| 277 |
return (optname in __sockopt ? __sockopt[optname] |
| 278 |
: sprintf("UNDEF_SOCKOPT(%d)", optname)) |
| 279 |
} |
| 280 |
|
| 281 |
%{ |
| 282 |
// Define newer IPv6 sockopt constants for older kernels. |
| 283 |
#include <linux/in6.h> |
| 284 |
#ifndef IPV6_2292PKTINFO |
| 285 |
#define IPV6_2292PKTINFO 0 |
| 286 |
#endif |
| 287 |
#ifndef IPV6_2292HOPOPTS |
| 288 |
#define IPV6_2292HOPOPTS 0 |
| 289 |
#endif |
| 290 |
#ifndef IPV6_2292DSTOPTS |
| 291 |
#define IPV6_2292DSTOPTS 0 |
| 292 |
#endif |
| 293 |
#ifndef IPV6_2292RTHDR |
| 294 |
#define IPV6_2292RTHDR 0 |
| 295 |
#endif |
| 296 |
#ifndef IPV6_2292PKTOPTIONS |
| 297 |
#define IPV6_2292PKTOPTIONS 0 |
| 298 |
#endif |
| 299 |
#ifndef IPV6_2292HOPLIMIT |
| 300 |
#define IPV6_2292HOPLIMIT 0 |
| 301 |
#endif |
| 302 |
#ifndef IPV6_RECVPKTINFO |
| 303 |
#define IPV6_RECVPKTINFO 0 |
| 304 |
#endif |
| 305 |
#ifndef IPV6_RECVHOPLIMIT |
| 306 |
#define IPV6_RECVHOPLIMIT 0 |
| 307 |
#endif |
| 308 |
#ifndef IPV6_RECVHOPOPTS |
| 309 |
#define IPV6_RECVHOPOPTS 0 |
| 310 |
#endif |
| 311 |
#ifndef IPV6_RTHDRDSTOPTS |
| 312 |
#define IPV6_RTHDRDSTOPTS 0 |
| 313 |
#endif |
| 314 |
#ifndef IPV6_RECVRTHDR |
| 315 |
#define IPV6_RECVRTHDR 0 |
| 316 |
#endif |
| 317 |
#ifndef IPV6_RECVDSTOPTS |
| 318 |
#define IPV6_RECVDSTOPTS 0 |
| 319 |
#endif |
| 320 |
#ifndef IPV6_RECVPATHMTU |
| 321 |
#define IPV6_RECVPATHMTU 0 |
| 322 |
#endif |
| 323 |
#ifndef IPV6_PATHMTU |
| 324 |
#define IPV6_PATHMTU 0 |
| 325 |
#endif |
| 326 |
#ifndef IPV6_DONTFRAG |
| 327 |
#define IPV6_DONTFRAG 0 |
| 328 |
#endif |
| 329 |
#ifndef IPV6_ADDR_PREFERENCES |
| 330 |
#define IPV6_ADDR_PREFERENCES 0 |
| 331 |
#endif |
| 332 |
#ifndef IPV6_MINHOPCOUNT |
| 333 |
#define IPV6_MINHOPCOUNT 0 |
| 334 |
#endif |
| 335 |
#ifndef IPV6_RECVORIGDSTADDR |
| 336 |
#define IPV6_RECVORIGDSTADDR 0 |
| 337 |
#endif |
| 338 |
#ifndef IPV6_TRANSPARENT |
| 339 |
#define IPV6_TRANSPARENT 0 |
| 340 |
#endif |
| 341 |
%} |
| 342 |
|
| 343 |
@__private30 global __ipv6_sockopt[55] |
| 344 |
probe init { |
| 345 |
__ipv6_sockopt[@const("IPV6_ADDRFORM")] = "IPV6_ADDRFORM" |
| 346 |
if (@const("IPV6_2292PKTINFO") > 0) |
| 347 |
__ipv6_sockopt[@const("IPV6_2292PKTINFO")] |
| 348 |
= "IPV6_2292PKTINFO" |
| 349 |
if (@const("IPV6_2292HOPOPTS") > 0) |
| 350 |
__ipv6_sockopt[@const("IPV6_2292HOPOPTS")] |
| 351 |
= "IPV6_2292HOPOPTS" |
| 352 |
if (@const("IPV6_2292DSTOPTS") > 0) |
| 353 |
__ipv6_sockopt[@const("IPV6_2292DSTOPTS")] |
| 354 |
= "IPV6_2292DSTOPTS" |
| 355 |
if (@const("IPV6_2292RTHDR") > 0) |
| 356 |
__ipv6_sockopt[@const("IPV6_2292RTHDR")] |
| 357 |
= "IPV6_2292RTHDR" |
| 358 |
if (@const("IPV6_2292PKTOPTIONS") > 0) |
| 359 |
__ipv6_sockopt[@const("IPV6_2292PKTOPTIONS")] |
| 360 |
= "IPV6_2292PKTOPTIONS" |
| 361 |
__ipv6_sockopt[@const("IPV6_CHECKSUM")] = "IPV6_CHECKSUM" |
| 362 |
if (@const("IPV6_2292HOPLIMIT") > 0) |
| 363 |
__ipv6_sockopt[@const("IPV6_2292HOPLIMIT")] |
| 364 |
= "IPV6_2292HOPLIMIT" |
| 365 |
__ipv6_sockopt[@const("IPV6_NEXTHOP")] = "IPV6_NEXTHOP" |
| 366 |
__ipv6_sockopt[@const("IPV6_AUTHHDR")] = "IPV6_AUTHHDR" |
| 367 |
__ipv6_sockopt[@const("IPV6_FLOWINFO")] = "IPV6_FLOWINFO" |
| 368 |
__ipv6_sockopt[@const("IPV6_UNICAST_HOPS")] |
| 369 |
= "IPV6_UNICAST_HOPS" |
| 370 |
__ipv6_sockopt[@const("IPV6_MULTICAST_IF")] |
| 371 |
= "IPV6_MULTICAST_IF" |
| 372 |
__ipv6_sockopt[@const("IPV6_MULTICAST_HOPS")] |
| 373 |
= "IPV6_MULTICAST_HOPS" |
| 374 |
__ipv6_sockopt[@const("IPV6_MULTICAST_LOOP")] |
| 375 |
= "IPV6_MULTICAST_LOOP" |
| 376 |
__ipv6_sockopt[@const("IPV6_ADD_MEMBERSHIP")] |
| 377 |
= "IPV6_ADD_MEMBERSHIP" |
| 378 |
__ipv6_sockopt[@const("IPV6_DROP_MEMBERSHIP")] |
| 379 |
= "IPV6_DROP_MEMBERSHIP" |
| 380 |
__ipv6_sockopt[@const("IPV6_ROUTER_ALERT")] |
| 381 |
= "IPV6_ROUTER_ALERT" |
| 382 |
__ipv6_sockopt[@const("IPV6_MTU_DISCOVER")] |
| 383 |
= "IPV6_MTU_DISCOVER" |
| 384 |
__ipv6_sockopt[@const("IPV6_MTU")] = "IPV6_MTU" |
| 385 |
__ipv6_sockopt[@const("IPV6_RECVERR")] = "IPV6_RECVERR" |
| 386 |
__ipv6_sockopt[@const("IPV6_V6ONLY")] = "IPV6_V6ONLY" |
| 387 |
__ipv6_sockopt[@const("IPV6_JOIN_ANYCAST")] |
| 388 |
= "IPV6_JOIN_ANYCAST" |
| 389 |
__ipv6_sockopt[@const("IPV6_LEAVE_ANYCAST")] |
| 390 |
= "IPV6_LEAVE_ANYCAST" |
| 391 |
__ipv6_sockopt[@const("IPV6_FLOWLABEL_MGR")] |
| 392 |
= "IPV6_FLOWLABEL_MGR" |
| 393 |
__ipv6_sockopt[@const("IPV6_FLOWINFO_SEND")] |
| 394 |
= "IPV6_FLOWINFO_SEND" |
| 395 |
__ipv6_sockopt[@const("IPV6_IPSEC_POLICY")] |
| 396 |
= "IPV6_IPSEC_POLICY" |
| 397 |
__ipv6_sockopt[@const("IPV6_XFRM_POLICY")] |
| 398 |
= "IPV6_XFRM_POLICY" |
| 399 |
__ipv6_sockopt[@const("MCAST_JOIN_GROUP")] |
| 400 |
= "MCAST_JOIN_GROUP" |
| 401 |
__ipv6_sockopt[@const("MCAST_BLOCK_SOURCE")] |
| 402 |
= "MCAST_BLOCK_SOURCE" |
| 403 |
__ipv6_sockopt[@const("MCAST_UNBLOCK_SOURCE")] |
| 404 |
= "MCAST_UNBLOCK_SOURCE" |
| 405 |
__ipv6_sockopt[@const("MCAST_LEAVE_GROUP")] |
| 406 |
= "MCAST_LEAVE_GROUP" |
| 407 |
__ipv6_sockopt[@const("MCAST_JOIN_SOURCE_GROUP")] |
| 408 |
= "MCAST_JOIN_SOURCE_GROUP" |
| 409 |
__ipv6_sockopt[@const("MCAST_LEAVE_SOURCE_GROUP")] |
| 410 |
= "MCAST_LEAVE_SOURCE_GROUP" |
| 411 |
__ipv6_sockopt[@const("MCAST_MSFILTER")] = "MCAST_MSFILTER" |
| 412 |
if (@const("IPV6_RECVPKTINFO") > 0) |
| 413 |
__ipv6_sockopt[@const("IPV6_RECVPKTINFO")] |
| 414 |
= "IPV6_RECVPKTINFO" |
| 415 |
__ipv6_sockopt[@const("IPV6_PKTINFO")] = "IPV6_PKTINFO" |
| 416 |
if (@const("IPV6_RECVHOPLIMIT") > 0) |
| 417 |
__ipv6_sockopt[@const("IPV6_RECVHOPLIMIT")] |
| 418 |
= "IPV6_RECVHOPLIMIT" |
| 419 |
__ipv6_sockopt[@const("IPV6_HOPLIMIT")] = "IPV6_HOPLIMIT" |
| 420 |
if (@const("IPV6_RECVHOPOPTS") > 0) |
| 421 |
__ipv6_sockopt[@const("IPV6_RECVHOPOPTS")] |
| 422 |
= "IPV6_RECVHOPOPTS" |
| 423 |
__ipv6_sockopt[@const("IPV6_HOPOPTS")] = "IPV6_HOPOPTS" |
| 424 |
if (@const("IPV6_RTHDRDSTOPTS") > 0) |
| 425 |
__ipv6_sockopt[@const("IPV6_RTHDRDSTOPTS")] |
| 426 |
= "IPV6_RTHDRDSTOPTS" |
| 427 |
if (@const("IPV6_RECVRTHDR") > 0) |
| 428 |
__ipv6_sockopt[@const("IPV6_RECVRTHDR")] |
| 429 |
= "IPV6_RECVRTHDR" |
| 430 |
__ipv6_sockopt[@const("IPV6_RTHDR")] = "IPV6_RTHDR" |
| 431 |
if (@const("IPV6_RECVDSTOPTS") > 0) |
| 432 |
__ipv6_sockopt[@const("IPV6_RECVDSTOPTS")] |
| 433 |
= "IPV6_RECVDSTOPTS" |
| 434 |
__ipv6_sockopt[@const("IPV6_DSTOPTS")] = "IPV6_DSTOPTS" |
| 435 |
if (@const("IPV6_RECVPATHMTU") > 0) |
| 436 |
__ipv6_sockopt[@const("IPV6_RECVPATHMTU")] |
| 437 |
= "IPV6_RECVPATHMTU" |
| 438 |
if (@const("IPV6_PATHMTU") > 0) |
| 439 |
__ipv6_sockopt[@const("IPV6_PATHMTU")] |
| 440 |
= "IPV6_PATHMTU" |
| 441 |
if (@const("IPV6_DONTFRAG") > 0) |
| 442 |
__ipv6_sockopt[@const("IPV6_DONTFRAG")] |
| 443 |
= "IPV6_DONTFRAG" |
| 444 |
__ipv6_sockopt[@const("IPV6_RECVTCLASS")] |
| 445 |
= "IPV6_RECVTCLASS" |
| 446 |
__ipv6_sockopt[@const("IPV6_TCLASS")] = "IPV6_TCLASS" |
| 447 |
if (@const("IPV6_ADDR_PREFERENCES") > 0) |
| 448 |
__ipv6_sockopt[@const("IPV6_ADDR_PREFERENCES")] |
| 449 |
= "IPV6_ADDR_PREFERENCES" |
| 450 |
if (@const("IPV6_MINHOPCOUNT") > 0) |
| 451 |
__ipv6_sockopt[@const("IPV6_MINHOPCOUNT")] |
| 452 |
= "IPV6_MINHOPCOUNT" |
| 453 |
if (@const("IPV6_RECVORIGDSTADDR") > 0) |
| 454 |
__ipv6_sockopt[@const("IPV6_RECVORIGDSTADDR")] |
| 455 |
= "IPV6_RECVORIGDSTADDR" |
| 456 |
if (@const("IPV6_TRANSPARENT") > 0) |
| 457 |
__ipv6_sockopt[@const("IPV6_TRANSPARENT")] |
| 458 |
= "IPV6_TRANSPARENT" |
| 459 |
} |
| 460 |
|
| 461 |
function tcp_ipv6_sockopt_str:string (optname:long) |
| 462 |
{ |
| 463 |
return (optname in __ipv6_sockopt ? __ipv6_sockopt[optname] |
| 464 |
: sprintf("UNDEF_SOCKOPT(%d)", optname)) |
| 465 |
} |
| 466 |
|
| 467 |
/** |
| 468 |
* probe tcp.sendmsg - Sending a tcp message |
| 469 |
* @name: Name of this probe |
| 470 |
* @sock: Network socket |
| 471 |
* @family: IP address family |
| 472 |
* @size: Number of bytes to send |
| 473 |
* |
| 474 |
* Context: |
| 475 |
* The process which sends a tcp message |
| 476 |
*/ |
| 477 |
probe tcp.sendmsg = kernel.function("tcp_sendmsg") { |
| 478 |
name = "tcp.sendmsg" |
| 479 |
sock = (@defined($sock) ? $sock->sk : $sk) |
| 480 |
family = __ip_sock_family(@defined($sock) ? $sock->sk : $sk) |
| 481 |
size = $size |
| 482 |
} |
| 483 |
|
| 484 |
/** |
| 485 |
* probe tcp.sendmsg.return - Sending TCP message is done |
| 486 |
* @name: Name of this probe |
| 487 |
* @size: Number of bytes sent or error code if an error occurred. |
| 488 |
* |
| 489 |
* Context: |
| 490 |
* The process which sends a tcp message |
| 491 |
*/ |
| 492 |
probe tcp.sendmsg.return = kernel.function("tcp_sendmsg").return { |
| 493 |
name = "tcp.sendmsg" |
| 494 |
size = $return |
| 495 |
} |
| 496 |
|
| 497 |
/** |
| 498 |
* probe tcp.recvmsg - Receiving TCP message |
| 499 |
* @name: Name of this probe |
| 500 |
* @sock: Network socket |
| 501 |
* @size: Number of bytes to be received |
| 502 |
* @family: IP address family |
| 503 |
* @saddr: A string representing the source IP address |
| 504 |
* @daddr: A string representing the destination IP address |
| 505 |
* @sport: TCP source port |
| 506 |
* @dport: TCP destination port |
| 507 |
* Context: |
| 508 |
* The process which receives a tcp message |
| 509 |
*/ |
| 510 |
probe tcp.recvmsg = kernel.function("tcp_recvmsg") { |
| 511 |
name = "tcp.recvmsg" |
| 512 |
sock = $sk |
| 513 |
size = $len |
| 514 |
family = __ip_sock_family($sk) |
| 515 |
saddr = format_ipaddr(__ip_sock_saddr($sk), __ip_sock_family($sk)) |
| 516 |
daddr = format_ipaddr(__ip_sock_daddr($sk), __ip_sock_family($sk)) |
| 517 |
sport = __tcp_sock_sport($sk) |
| 518 |
dport = __tcp_sock_dport($sk) |
| 519 |
} |
| 520 |
|
| 521 |
/** |
| 522 |
* probe tcp.recvmsg.return - Receiving TCP message complete |
| 523 |
* @name: Name of this probe |
| 524 |
* @size: Number of bytes received or error code if an error occurred. |
| 525 |
* @family: IP address family |
| 526 |
* @saddr: A string representing the source IP address |
| 527 |
* @daddr: A string representing the destination IP address |
| 528 |
* @sport: TCP source port |
| 529 |
* @dport: TCP destination port |
| 530 |
* |
| 531 |
* Context: |
| 532 |
* The process which receives a tcp message |
| 533 |
*/ |
| 534 |
probe tcp.recvmsg.return = kernel.function("tcp_recvmsg").return { |
| 535 |
name = "tcp.recvmsg" |
| 536 |
size = $return |
| 537 |
family = __ip_sock_family(@entry($sk)) |
| 538 |
saddr = format_ipaddr(__ip_sock_saddr(@entry($sk)), __ip_sock_family(@entry($sk))) |
| 539 |
daddr = format_ipaddr(__ip_sock_daddr(@entry($sk)), __ip_sock_family(@entry($sk))) |
| 540 |
sport = __tcp_sock_sport(@entry($sk)) |
| 541 |
dport = __tcp_sock_dport(@entry($sk)) |
| 542 |
} |
| 543 |
|
| 544 |
/** |
| 545 |
* probe tcp.disconnect - TCP socket disconnection |
| 546 |
* @name: Name of this probe |
| 547 |
* @sock: Network socket |
| 548 |
* @family: IP address family |
| 549 |
* @flags: TCP flags (e.g. FIN, etc) |
| 550 |
* @saddr: A string representing the source IP address |
| 551 |
* @daddr: A string representing the destination IP address |
| 552 |
* @sport: TCP source port |
| 553 |
* @dport: TCP destination port |
| 554 |
* |
| 555 |
* Context: |
| 556 |
* The process which disconnects tcp |
| 557 |
*/ |
| 558 |
probe tcp.disconnect = kernel.function("tcp_disconnect") { |
| 559 |
name = "tcp.disconnect" |
| 560 |
sock = $sk |
| 561 |
family = __ip_sock_family($sk) |
| 562 |
flags = $flags |
| 563 |
saddr = format_ipaddr(__ip_sock_saddr($sk), __ip_sock_family($sk)) |
| 564 |
daddr = format_ipaddr(__ip_sock_daddr($sk), __ip_sock_family($sk)) |
| 565 |
sport = __tcp_sock_sport($sk) |
| 566 |
dport = __tcp_sock_dport($sk) |
| 567 |
} |
| 568 |
|
| 569 |
/** |
| 570 |
* probe tcp.disconnect.return - TCP socket disconnection complete |
| 571 |
* @name: Name of this probe |
| 572 |
* @ret: Error code (0: no error) |
| 573 |
* |
| 574 |
* Context: |
| 575 |
* The process which disconnects tcp |
| 576 |
*/ |
| 577 |
probe tcp.disconnect.return = kernel.function("tcp_disconnect").return { |
| 578 |
name = "tcp.disconnect" |
| 579 |
ret = $return |
| 580 |
} |
| 581 |
|
| 582 |
/** |
| 583 |
* probe tcp.setsockopt - Call to setsockopt() |
| 584 |
* @name: Name of this probe |
| 585 |
* @sock: Network socket |
| 586 |
* @family: IP address family |
| 587 |
* @level: The level at which the socket options will be manipulated |
| 588 |
* @optname: TCP socket options (e.g. TCP_NODELAY, TCP_MAXSEG, etc) |
| 589 |
* @optstr: Resolves optname to a human-readable format |
| 590 |
* @optlen: Used to access values for setsockopt() |
| 591 |
* |
| 592 |
* Context: |
| 593 |
* The process which calls setsockopt |
| 594 |
*/ |
| 595 |
probe tcp.setsockopt = tcp.ipv4.setsockopt, tcp.ipv6.setsockopt |
| 596 |
{ |
| 597 |
} |
| 598 |
probe tcp.ipv4.setsockopt = kernel.function("tcp_setsockopt") |
| 599 |
{ |
| 600 |
name = "tcp.ipv4.setsockopt" |
| 601 |
sock = $sk |
| 602 |
family = __ip_sock_family($sk) |
| 603 |
level = $level |
| 604 |
optname = $optname |
| 605 |
optstr = tcp_sockopt_str($optname) |
| 606 |
optlen = $optlen |
| 607 |
} |
| 608 |
probe tcp.ipv6.setsockopt = kernel.function("ipv6_setsockopt")!, |
| 609 |
module("ipv6").function("ipv6_setsockopt") |
| 610 |
{ |
| 611 |
name = "tcp.ipv6.setsockopt" |
| 612 |
sock = $sk |
| 613 |
family = __ip_sock_family($sk) |
| 614 |
level = $level |
| 615 |
optname = $optname |
| 616 |
optstr = tcp_ipv6_sockopt_str($optname) |
| 617 |
optlen = $optlen |
| 618 |
} |
| 619 |
|
| 620 |
/** |
| 621 |
* probe tcp.setsockopt.return - Return from setsockopt() |
| 622 |
* @name: Name of this probe |
| 623 |
* @ret: Error code (0: no error) |
| 624 |
* |
| 625 |
* Context: |
| 626 |
* The process which calls setsockopt |
| 627 |
*/ |
| 628 |
probe tcp.setsockopt.return = tcp.ipv4.setsockopt.return, |
| 629 |
tcp.ipv6.setsockopt.return |
| 630 |
{ |
| 631 |
} |
| 632 |
probe tcp.ipv4.setsockopt.return = kernel.function("tcp_setsockopt").return |
| 633 |
{ |
| 634 |
name = "tcp.ipv4.setsockopt" |
| 635 |
ret = $return |
| 636 |
} |
| 637 |
probe tcp.ipv6.setsockopt.return = kernel.function("ipv6_setsockopt").return!, |
| 638 |
module("ipv6").function("ipv6_setsockopt").return |
| 639 |
{ |
| 640 |
name = "tcp.ipv6.setsockopt" |
| 641 |
ret = $return |
| 642 |
} |
| 643 |
|
| 644 |
/** |
| 645 |
* probe tcp.receive - Called when a TCP packet is received |
| 646 |
* @name: Name of the probe point |
| 647 |
* @iphdr: IP header address |
| 648 |
* @protocol: Packet protocol from driver |
| 649 |
* @family: IP address family |
| 650 |
* @saddr: A string representing the source IP address |
| 651 |
* @daddr: A string representing the destination IP address |
| 652 |
* @sport: TCP source port |
| 653 |
* @dport: TCP destination port |
| 654 |
* @urg: TCP URG flag |
| 655 |
* @ack: TCP ACK flag |
| 656 |
* @psh: TCP PSH flag |
| 657 |
* @rst: TCP RST flag |
| 658 |
* @syn: TCP SYN flag |
| 659 |
* @fin: TCP FIN flag |
| 660 |
*/ |
| 661 |
probe tcp.receive = tcp.ipv4.receive, tcp.ipv6.receive |
| 662 |
{ |
| 663 |
} |
| 664 |
|
| 665 |
probe tcp.ipv4.receive = kernel.function("tcp_v4_rcv") |
| 666 |
{ |
| 667 |
name = "tcp.ipv4.receive" |
| 668 |
# If we're here, by definition we're doing AF_INET, not AF_INET6. |
| 669 |
family = @const("AF_INET") |
| 670 |
try { |
| 671 |
iphdr = __get_skb_iphdr($skb) |
| 672 |
saddr = format_ipaddr(__ip_skb_saddr(iphdr), @const("AF_INET")) |
| 673 |
daddr = format_ipaddr(__ip_skb_daddr(iphdr), @const("AF_INET")) |
| 674 |
protocol = __ip_skb_proto(iphdr) |
| 675 |
} catch { } |
| 676 |
|
| 677 |
try { |
| 678 |
tcphdr = __get_skb_tcphdr($skb) |
| 679 |
dport = __tcp_skb_dport(tcphdr) |
| 680 |
sport = __tcp_skb_sport(tcphdr) |
| 681 |
urg = __tcp_skb_urg(tcphdr) |
| 682 |
ack = __tcp_skb_ack(tcphdr) |
| 683 |
psh = __tcp_skb_psh(tcphdr) |
| 684 |
rst = __tcp_skb_rst(tcphdr) |
| 685 |
syn = __tcp_skb_syn(tcphdr) |
| 686 |
fin = __tcp_skb_fin(tcphdr) |
| 687 |
seq = __tcp_skb_seq(tcphdr) |
| 688 |
ackseq = __tcp_skb_ackseq(tcphdr) |
| 689 |
window = __tcp_skb_window(tcphdr) |
| 690 |
} catch { } |
| 691 |
} |
| 692 |
|
| 693 |
probe tcp.ipv6.receive = kernel.function("tcp_v6_rcv")!, |
| 694 |
module("ipv6").function("tcp_v6_rcv") |
| 695 |
{ |
| 696 |
name = "tcp.ipv6.receive" |
| 697 |
# If we're here, by definition we're doing AF_INET6, not AF_INET. |
| 698 |
family = @const("AF_INET6") |
| 699 |
try { |
| 700 |
iphdr = __get_skb_iphdr(@choose_defined($skb, kernel_pointer($pskb))) |
| 701 |
saddr = format_ipaddr(&@cast(iphdr, "ipv6hdr", |
| 702 |
"kernel<linux/ipv6.h>")->saddr, |
| 703 |
@const("AF_INET6")) |
| 704 |
daddr = format_ipaddr(&@cast(iphdr, "ipv6hdr", |
| 705 |
"kernel<linux/ipv6.h>")->daddr, |
| 706 |
@const("AF_INET6")) |
| 707 |
} catch { } |
| 708 |
|
| 709 |
# If we're here, by definition we're doing IPPROTO_TCP. There |
| 710 |
# isn't a protocol field in 'struct ipv6hdr'. There is one in |
| 711 |
# 'struct sk_buff', but that protocol field is an Ethernet |
| 712 |
# Procol ID (ETH_P_*), not an IP protocol ID (IPPROTO_*). |
| 713 |
protocol = @const("IPPROTO_TCP") |
| 714 |
|
| 715 |
try { |
| 716 |
tcphdr = __get_skb_tcphdr(@choose_defined($skb, |
| 717 |
kernel_pointer($pskb))) |
| 718 |
dport = __tcp_skb_dport(tcphdr) |
| 719 |
sport = __tcp_skb_sport(tcphdr) |
| 720 |
urg = __tcp_skb_urg(tcphdr) |
| 721 |
ack = __tcp_skb_ack(tcphdr) |
| 722 |
psh = __tcp_skb_psh(tcphdr) |
| 723 |
rst = __tcp_skb_rst(tcphdr) |
| 724 |
syn = __tcp_skb_syn(tcphdr) |
| 725 |
fin = __tcp_skb_fin(tcphdr) |
| 726 |
seq = __tcp_skb_seq(tcphdr) |
| 727 |
ackseq = __tcp_skb_ackseq(tcphdr) |
| 728 |
window = __tcp_skb_window(tcphdr) |
| 729 |
} catch { } |
| 730 |
} |
| 731 |
|
| 732 |
|