| 1 |
// networking tapset |
| 2 |
// Copyright (C) 2005, 2006 IBM Corp. |
| 3 |
// |
| 4 |
// This file is part of systemtap, and is free software. You can |
| 5 |
// redistribute it and/or modify it under the terms of the GNU General |
| 6 |
// Public License (GPL); either version 2, or (at your option) any |
| 7 |
// later version. |
| 8 |
// <tapsetdescription> |
| 9 |
// This family of probe points is used to probe the activities of the network device. |
| 10 |
// </tapsetdescription> |
| 11 |
|
| 12 |
// =================================================================== |
| 13 |
// |
| 14 |
// BZ1546179 fix notes. |
| 15 |
// |
| 16 |
// The following kernel commit changed the sk_buff structure: |
| 17 |
// |
| 18 |
// commit bffa72cf7f9df842f0016ba03586039296b4caaf |
| 19 |
// Author: Eric Dumazet <[email protected]> |
| 20 |
// Date: Tue Sep 19 05:14:24 2017 -0700 |
| 21 |
// |
| 22 |
// net: sk_buff rbnode reorg |
| 23 |
// |
| 24 |
// skb->rbnode shares space with skb->next, skb->prev and skb->tstamp |
| 25 |
// |
| 26 |
// The sk_buff structure now looks like this: |
| 27 |
// |
| 28 |
// ==== |
| 29 |
// struct sk_buff { |
| 30 |
// union { |
| 31 |
// struct { |
| 32 |
// /* These two members must be first. */ |
| 33 |
// struct sk_buff *next; |
| 34 |
// struct sk_buff *prev; |
| 35 |
// |
| 36 |
// union { |
| 37 |
// struct net_device *dev; |
| 38 |
// /* Some protocols might use this space to store information, |
| 39 |
// * while device pointer would be NULL. |
| 40 |
// * UDP receive path is one user. |
| 41 |
// */ |
| 42 |
// unsigned long dev_scratch; |
| 43 |
// }; |
| 44 |
// }; |
| 45 |
// struct rb_node rbnode; /* used in netem & tcp stack */ |
| 46 |
// }; |
| 47 |
// ... stuff deleted ... |
| 48 |
// }; |
| 49 |
// ==== |
| 50 |
// |
| 51 |
// There doesn't seem to be a way by looking at the sk_buf structure |
| 52 |
// to know which of those union values are valid. If a probe does |
| 53 |
// something like "dev_name = kernel_string($skb->dev->name)", that |
| 54 |
// could fail in a variety of ways (since it is difficult to know if |
| 55 |
// $skb->dev is supposed to be valid). To avoid a probe user getting a |
| 56 |
// read error (with no way to trap that error), accesses to sk_buff |
| 57 |
// structs have been surrounded with "try { .. } catch { }" in probes. |
| 58 |
// |
| 59 |
// Note that this is done only in probes, not in functions. A user |
| 60 |
// doing his own probing might want to try to catch an error in a |
| 61 |
// function himself. |
| 62 |
// |
| 63 |
// Also note that statements accessing the same sk_buff structure |
| 64 |
// field are grouped in a single try/catch statement. Statements |
| 65 |
// accessing different sk_buff structure fields each have their own |
| 66 |
// try/catch statement. |
| 67 |
// |
| 68 |
// =================================================================== |
| 69 |
|
| 70 |
/* A function that returns the device name given the net_device struct */ |
| 71 |
function get_netdev_name:string (addr:long) { |
| 72 |
return kernel_string(@cast(addr, "net_device", "kernel")->name) |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* probe netdev.receive - Data received from network device. |
| 77 |
* @dev_name: The name of the device. e.g: eth0, ath1. |
| 78 |
* @length: The length of the receiving buffer. |
| 79 |
* @protocol: Protocol of received packet. |
| 80 |
* |
| 81 |
*/ |
| 82 |
/// <varlistentry><term>protocol</term> |
| 83 |
/// <listitem><para>The possible values of protocol could be: |
| 84 |
/// <table frame='all'><title>Protocol Values</title> |
| 85 |
/// <tgroup cols='2' align='left' colsep='1' rowsep='1'> |
| 86 |
/// <colspec colname='Value'/> |
| 87 |
/// <colspec colname='Protocol'/> |
| 88 |
/// <thead> |
| 89 |
/// <row><entry>Value(Hex)</entry><entry>Protocol</entry></row> |
| 90 |
/// </thead> |
| 91 |
/// <tbody> |
| 92 |
/// <row><entry>0001</entry><entry>802.3</entry></row> |
| 93 |
/// <row><entry>0002</entry><entry>AX.25</entry></row> |
| 94 |
/// <row><entry>0004</entry><entry>802.2</entry></row> |
| 95 |
/// <row><entry>0005</entry><entry>SNAP</entry></row> |
| 96 |
/// <row><entry>0009</entry><entry>Localtalk</entry></row> |
| 97 |
/// <row><entry>0800</entry><entry>IP</entry></row> |
| 98 |
/// <row><entry>0805</entry><entry>X.25</entry></row> |
| 99 |
/// <row><entry>0806</entry><entry>ARP</entry></row> |
| 100 |
/// <row><entry>8035</entry><entry>RARP</entry></row> |
| 101 |
/// <row><entry>8100</entry><entry>802.1Q VLAN</entry></row> |
| 102 |
/// <row><entry>8137</entry><entry>IPX</entry></row> |
| 103 |
/// <row><entry>86DD</entry><entry>IPv6</entry></row> |
| 104 |
/// </tbody> |
| 105 |
/// </tgroup> |
| 106 |
/// </table> |
| 107 |
/// </para></listitem> |
| 108 |
/// </varlistentry> |
| 109 |
/// |
| 110 |
/// <varlistentry><term>truesize</term> |
| 111 |
/// <listitem><para> |
| 112 |
/// The size of the received data. |
| 113 |
/// </para></listitem> |
| 114 |
/// </varlistentry> |
| 115 |
/// |
| 116 |
/// </variablelist> |
| 117 |
///</para> |
| 118 |
// Main device receive routine, be called when packet arrives on network device |
| 119 |
probe netdev.receive |
| 120 |
= kernel.trace("netif_receive_skb") !, |
| 121 |
kernel.function("netif_receive_skb_internal") !, |
| 122 |
kernel.function("netif_receive_skb") |
| 123 |
{ |
| 124 |
try { dev_name = get_netdev_name($skb->dev) } catch { } |
| 125 |
try { length = $skb->len } catch { } |
| 126 |
try { protocol = $skb->protocol } catch { } |
| 127 |
try { truesize = $skb->truesize } catch { } |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* probe netdev.transmit - Network device transmitting buffer |
| 132 |
* @dev_name: The name of the device. e.g: eth0, ath1. |
| 133 |
* @length: The length of the transmit buffer. |
| 134 |
* @protocol: The protocol of this packet(defined in include/linux/if_ether.h). |
| 135 |
* @truesize: The size of the data to be transmitted. |
| 136 |
* |
| 137 |
*/ |
| 138 |
// Queue a buffer for transmission to a network device |
| 139 |
probe netdev.transmit |
| 140 |
= kernel.function("__dev_queue_xmit") !, |
| 141 |
kernel.function("dev_queue_xmit") |
| 142 |
{ |
| 143 |
try { dev_name = get_netdev_name($skb->dev) } catch { } |
| 144 |
try { length = $skb->len } catch { } |
| 145 |
try { protocol = $skb->protocol } catch { } |
| 146 |
try { truesize = $skb->truesize } catch { } |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* probe netdev.change_mtu - Called when the netdev MTU is changed |
| 151 |
* @dev_name: The device that will have the MTU changed |
| 152 |
* @old_mtu: The current MTU |
| 153 |
* @new_mtu: The new MTU |
| 154 |
*/ |
| 155 |
probe netdev.change_mtu |
| 156 |
= kernel.function("netif_set_mtu_ext") !, |
| 157 |
kernel.function("dev_set_mtu_ext") !, |
| 158 |
kernel.function("dev_set_mtu") |
| 159 |
{ |
| 160 |
old_mtu = $dev->mtu |
| 161 |
new_mtu = $new_mtu |
| 162 |
dev_name = get_netdev_name($dev) |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* probe netdev.open - Called when the device is opened |
| 167 |
* @dev_name: The device that is going to be opened |
| 168 |
*/ |
| 169 |
probe netdev.open |
| 170 |
= kernel.function("dev_open") |
| 171 |
{ |
| 172 |
dev_name = get_netdev_name($dev) |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* probe netdev.close - Called when the device is closed |
| 177 |
* @dev_name: The device that is going to be closed |
| 178 |
*/ |
| 179 |
probe netdev.close |
| 180 |
= kernel.function("dev_close") |
| 181 |
{ |
| 182 |
dev_name = get_netdev_name($dev) |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* probe netdev.hard_transmit - Called when the devices is going to TX (hard) |
| 187 |
* @dev_name: The device scheduled to transmit |
| 188 |
* @protocol: The protocol used in the transmission |
| 189 |
* @length: The length of the transmit buffer. |
| 190 |
* @truesize: The size of the data to be transmitted. |
| 191 |
*/ |
| 192 |
probe netdev.hard_transmit |
| 193 |
= kernel.function("dev_hard_start_xmit") ? |
| 194 |
{ |
| 195 |
dev_name = get_netdev_name($dev) |
| 196 |
try { protocol = @choose_defined($first, $skb)->protocol } catch { } |
| 197 |
try { length = @choose_defined($first, $skb)->len } catch { } |
| 198 |
try { truesize = @choose_defined($first, $skb)->truesize } catch { } |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* probe netdev.rx - Called when the device is going to receive a packet |
| 203 |
* @dev_name: The device received the packet |
| 204 |
* @protocol: The packet protocol |
| 205 |
*/ |
| 206 |
probe netdev.rx |
| 207 |
= kernel.function("netif_rx") |
| 208 |
{ |
| 209 |
try { |
| 210 |
netdev = $skb->dev |
| 211 |
dev_name = get_netdev_name(netdev) |
| 212 |
} catch { } |
| 213 |
try { protocol = $skb->protocol } catch { } |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* probe netdev.change_rx_flag - Called when the device RX flag will be changed |
| 218 |
* @dev_name: The device that will be changed |
| 219 |
* @flags: The new flags |
| 220 |
*/ |
| 221 |
probe netdev.change_rx_flag |
| 222 |
= kernel.function("dev_change_rx_flags") ? |
| 223 |
{ |
| 224 |
dev_name = (@defined($dev) ? get_netdev_name($dev) : "unknown") |
| 225 |
flags = @choose_defined($flags, 0) |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* probe netdev.set_promiscuity - Called when the device enters/leaves promiscuity |
| 230 |
* @dev_name: The device that is entering/leaving promiscuity mode |
| 231 |
* @enable: If the device is entering promiscuity mode |
| 232 |
* @disable: If the device is leaving promiscuity mode |
| 233 |
* @inc: Count the number of promiscuity openers |
| 234 |
*/ |
| 235 |
probe netdev.set_promiscuity |
| 236 |
= kernel.function("dev_set_promiscuity") |
| 237 |
{ |
| 238 |
dev_name = get_netdev_name($dev) |
| 239 |
if ($inc){ |
| 240 |
enable = 1 |
| 241 |
} else { |
| 242 |
disable = 1 |
| 243 |
} |
| 244 |
inc = $inc |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* probe netdev.ioctl - Called when the device suffers an IOCTL |
| 249 |
* @cmd: The IOCTL request |
| 250 |
* @arg: The IOCTL argument (usually the netdev interface) |
| 251 |
*/ |
| 252 |
probe netdev.ioctl |
| 253 |
= kernel.function("dev_ioctl") |
| 254 |
{ |
| 255 |
cmd = $cmd |
| 256 |
arg = user_string_quoted(@choose_defined($ifr, $arg)) |
| 257 |
} |
| 258 |
|
| 259 |
/** |
| 260 |
* probe netdev.register - Called when the device is registered |
| 261 |
* @dev_name: The device that is going to be registered |
| 262 |
*/ |
| 263 |
probe netdev.register |
| 264 |
= kernel.function("register_netdevice"), |
| 265 |
kernel.function("register_netdev") |
| 266 |
{ |
| 267 |
dev_name = get_netdev_name($dev) |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* probe netdev.unregister - Called when the device is being unregistered |
| 272 |
* @dev_name: The device that is going to be unregistered |
| 273 |
*/ |
| 274 |
probe netdev.unregister |
| 275 |
= kernel.function("unregister_netdev") |
| 276 |
{ |
| 277 |
dev_name = get_netdev_name($dev) |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* probe netdev.get_stats - Called when someone asks the device statistics |
| 282 |
* @dev_name: The device that is going to provide the statistics |
| 283 |
*/ |
| 284 |
probe netdev.get_stats |
| 285 |
= kernel.function("dev_get_stats") ? |
| 286 |
{ |
| 287 |
dev_name = get_netdev_name($dev) |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* probe netdev.change_mac - Called when the netdev_name has the MAC changed |
| 292 |
* @dev_name: The device that will have the MAC changed |
| 293 |
* @mac_len: The MAC length |
| 294 |
* @old_mac: The current MAC address |
| 295 |
* @new_mac: The new MAC address |
| 296 |
*/ |
| 297 |
probe netdev.change_mac |
| 298 |
= kernel.function("dev_set_mac_address") ? |
| 299 |
{ |
| 300 |
dev_name = get_netdev_name($dev) |
| 301 |
mac_len = $dev->addr_len |
| 302 |
|
| 303 |
// Old MAC Address |
| 304 |
old_mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x", |
| 305 |
$dev->dev_addr[0], $dev->dev_addr[1], |
| 306 |
$dev->dev_addr[2], $dev->dev_addr[3], |
| 307 |
$dev->dev_addr[4], $dev->dev_addr[5]) |
| 308 |
|
| 309 |
// New MAC Address |
| 310 |
new_mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x", |
| 311 |
$sa->sa_data[0], $sa->sa_data[1], |
| 312 |
$sa->sa_data[2], $sa->sa_data[3], |
| 313 |
$sa->sa_data[4], $sa->sa_data[5]) |
| 314 |
} |