/usr/share/systemtap/tapset/linux/ip.stp is in systemtap-common 2.6-0.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | // IP tapset
//
// Copyright (C) 2009, IBM Inc.
// Copyright (C) 2010, 2014 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
// the terms of the GNU General Public License (GPL), version 2.
//
// Based on previous work done by Arnaldo Carvalho de Melo <acme@redhat.com>
%{
#include <linux/skbuff.h>
#include <linux/socket.h> // For AF_INET & AF_INET6
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
#include <linux/types.h>
#include <linux/in6.h>
#endif /* CONFIG_IPV6 || CONFIG_IPV6_MODULE */
%}
/**
* sfunction format_ipaddr - Returns a string representation for an IP address
*
* @addr: the IP address
* @family: the IP address family (either AF_INET or AF_INET6)
*/
function format_ipaddr:string (addr:long, family:long)
%{ /* pure */
if (STAP_ARG_family == AF_INET) {
__be32 ip = (__be32)STAP_ARG_addr;
#ifndef NIPQUAD_FMT // kver >= 2.6.36
snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%pI4", &ip);
#else
snprintf(STAP_RETVALUE, MAXSTRINGLEN, NIPQUAD_FMT,
NIPQUAD(ip));
#endif
}
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
else if (STAP_ARG_family == AF_INET6) {
struct in6_addr *ipv6 = (struct in6_addr *)(uintptr_t)STAP_ARG_addr;
// We need to derefence the memory safely from the
// address passed to us that contains the IPv6 address.
// However, kderef()/kread() only handle data with a
// size of 1, 2, 4, or 8. So, we'll use
// kderef_buffer() which goes byte by byte.
kderef_buffer(NULL, ipv6, sizeof(struct in6_addr));
#ifndef NIP6_FMT // kver >= 2.6.36
snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%pI6", ipv6);
#else
snprintf(STAP_RETVALUE, MAXSTRINGLEN, NIP6_FMT, NIP6(*ipv6));
#endif
}
#endif /* CONFIG_IPV6 || CONFIG_IPV6_MODULE */
else
strncpy(STAP_RETVALUE, "*unknown address family*",
MAXSTRINGLEN);
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
CATCH_DEREF_FAULT();
#endif /* CONFIG_IPV6 || CONFIG_IPV6_MODULE */
%}
/**
* sfunction ip_ntop - Returns a string representation for an IPv4 address
*
* @addr: the IPv4 address represented as an integer
*/
function ip_ntop:string (addr:long)
{
return format_ipaddr(addr, %{ /* pure */ /* unprivileged */ AF_INET %})
}
/*
* Return the source IP address for a given sock.
*
* Note that the probes that use this function typically get a 'struct
* sock' pointer, not a 'struct inet_sock' pointer. This is expected.
* To use a 'struct sock' pointer, you typically call inet_sk() on the
* pointer, which just returns the pointer (since the 1st member of
* 'struct inet_sock' is a 'struct sock').
*/
function __ip_sock_saddr:long (sock:long)
{
family = @cast(sock, "inet_sock", "kernel<net/ip.h>")->sk->__sk_common->skc_family
if (family == %{ /* pure */ /* unprivileged */ 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))
}
%( CONFIG_IPV6 == "[ym]" %?
else if (family == %{ /* pure */ /* unprivileged */ AF_INET6 %}) {
return (&@cast(sock, "inet_sock", "kernel<net/ip.h>")->pinet6->saddr)
}
%)
return 0
}
/* 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
if (family == %{ /* pure */ /* unprivileged */ 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)))
}
%( CONFIG_IPV6 == "[ym]" %?
else if (family == %{ /* pure */ /* unprivileged */ 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 0
}
/* 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)
}
/* Get the IP header from a sk_buff struct */
function __get_skb_iphdr:long(skb:long)
%( kernel_v < "2.6.21" %?
{
iphdr = @cast(skb, "sk_buff")->nh->raw
return iphdr
}
%:
%{ /* pure */
struct sk_buff *skb;
skb = (struct sk_buff *)(long)STAP_ARG_skb;
/* as done by skb_network_header() */
#ifdef NET_SKBUFF_DATA_USES_OFFSET
STAP_RETVALUE = (long)(kread(&(skb->head)) + kread(&(skb->network_header)));
#else
STAP_RETVALUE = (long)kread(&(skb->network_header));
#endif
CATCH_DEREF_FAULT();
%}
%)
/* return the source next layer protocol for a given sk_buff structure */
function __ip_skb_proto:long (iphdr)
{
return @cast(iphdr, "iphdr")->protocol
}
/* return the source IP address for a given sk_buff structure */
function __ip_skb_saddr:long (iphdr)
{
return @cast(iphdr, "iphdr")->saddr
}
/* return the destination IP address for a given skb */
function __ip_skb_daddr:long (iphdr)
{
return @cast(iphdr, "iphdr")->daddr
}
|