Debian Codegraph @

tapset/linux/ipmib.stp

raw
1 /*
2 * Copyright (C) 2009 IBM Corp.
3 * Copyright (C) 2010-2018 Red Hat Inc.
4 *
5 * This file is part of systemtap, and is free software. You can
6 * redistribute it and/or modify it under the terms of the GNU General
7 * Public License (GPL); either version 2, or (at your option) any
8 * later version.
9 *
10 * Version 1.0 [email protected] 2009-07-06
11 */
12
13 // See the BZ1546179 block comment in tapset/linux/networking.stp for
14 // an explanation of the try/catch statements around sk_buff structure
15 // accesses.
16
17 %{ /* pure */
18 #include <net/route.h>
19 #include <linux/skbuff.h>
20 #include <linux/icmp.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/tcp.h>
23 %}
24
25
26 /* Commented globals represent statistics that are not supported in this
27 * version.
28 */
29 global InReceives
30 // global InHdrErrors
31 // global InTooBigErrors
32 global InNoRoutes
33 global InAddrErrors
34 global InUnknownProtos
35 // global InTruncatedPkts
36 global InDiscards // included counts of InHdrErrors InTruncatedPkts
37 // global InDelivers
38 %( kernel_v >= "2.6.24" %?
39 global ForwDatagrams
40 %)
41 global OutRequests
42 // global OutDiscards
43 // global OutNoRoutes
44 global ReasmTimeout
45 global ReasmReqds
46 //global ReasmOKs
47 // global ReasmFails
48 global FragOKs
49 global FragFails
50 // global FragCreates
51 // global InMcastPkts
52 // global OutMcastPkts
53 // global InBcastPkts
54 // global OutBcastPkts
55
56 /**
57 * sfunction ipmib_remote_addr - Get the remote ip address
58 * @skb: pointer to a struct sk_buff
59 * @SourceIsLocal: flag to indicate whether local operation
60 *
61 * Returns the remote ip address from @skb.
62 */
63 function ipmib_remote_addr:long (skb:long, SourceIsLocal:long)
64 {
65 iphdr = __get_skb_iphdr(skb);
66 if ( SourceIsLocal )
67 return ntohl(__ip_skb_daddr(iphdr));
68 return ntohl(__ip_skb_saddr(iphdr));
69 }
70
71 /**
72 * sfunction ipmib_local_addr - Get the local ip address
73 * @skb: pointer to a struct sk_buff
74 * @SourceIsLocal: flag to indicate whether local operation
75 *
76 * Returns the local ip address @skb.
77 */
78 function ipmib_local_addr:long (skb:long, SourceIsLocal:long)
79 {
80 iphdr = __get_skb_iphdr(skb);
81 if ( SourceIsLocal )
82 return ntohl(__ip_skb_saddr(iphdr));
83 return ntohl(__ip_skb_daddr(iphdr));
84 }
85
86 /**
87 * sfunction ipmib_tcp_remote_port - Get the remote tcp port
88 * @skb: pointer to a struct sk_buff
89 * @SourceIsLocal: flag to indicate whether local operation
90 *
91 * Returns the remote tcp port from @skb.
92 */
93 function ipmib_tcp_remote_port:long (skb:long, SourceIsLocal:long)
94 {
95 th = _plunge_into_tcphdr(skb);
96 if ( SourceIsLocal )
97 return __tcp_skb_dport(th);
98 return __tcp_skb_sport(th);
99 }
100
101 /**
102 * sfunction ipmib_tcp_local_port - Get the local tcp port
103 * @skb: pointer to a struct sk_buff
104 * @SourceIsLocal: flag to indicate whether local operation
105 *
106 * Returns the local tcp port from @skb.
107 */
108 function ipmib_tcp_local_port:long (skb:long, SourceIsLocal:long)
109 {
110 th = _plunge_into_tcphdr(skb);
111 if ( SourceIsLocal )
112 return __tcp_skb_sport(th);
113 return __tcp_skb_dport(th);
114 }
115
116 /**
117 * sfunction ipmib_get_proto - Get the protocol value
118 * @skb: pointer to a struct sk_buff
119 *
120 * Returns the protocol value from @skb.
121 */
122 function ipmib_get_proto:long (skb:long)
123 {
124 iphdr = __get_skb_iphdr(skb);
125 return __ip_skb_proto(iphdr);
126 }
127
128 /* Internal functions */
129
130 /*
131 * We can't assume the pointer to the sk_buff->transport_header
132 * has been updated, so we must calculate the value from the network_header.
133 * The caller must verify the skb is for a tcpip packet.
134 */
135 @__private30 function _plunge_into_tcphdr:long (skb:long)
136 %{
137 struct sk_buff *skb = (struct sk_buff *)(uintptr_t)STAP_ARG_skb;
138 /* as done by skb_network_header() */
139 #ifdef NET_SKBUFF_DATA_USES_OFFSET
140 STAP_RETVALUE=(long)kread(&(skb->network_header)) +
141 (long)(kread(&(skb->head))) +
142 (long)sizeof(struct tcphdr);
143 #else
144 STAP_RETVALUE=(long)kread(&(skb->network_header)) +
145 (long)sizeof(struct tcphdr);
146 #endif
147 CATCH_DEREF_FAULT();
148 %}
149
150 @__private30 function _ehostunreach:long ()
151 {
152 return @const("EHOSTUNREACH")
153 }
154
155 @__private30 function _enetunreach:long ()
156 {
157 return @const("ENETUNREACH")
158 }
159
160 @__private30 function _icmp_dest_unreach:long ()
161 {
162 return @const("ICMP_DEST_UNREACH")
163 }
164
165 @__private30 function _icmp_prot_unreach:long ()
166 {
167 return @const("ICMP_PROT_UNREACH")
168 }
169
170 @__private30 function _net_rx_drop:long ()
171 {
172 return @const("NET_RX_DROP")
173 }
174
175 @__private30 function _icmp_time_exceeded:long ()
176 {
177 return @const("ICMP_TIME_EXCEEDED")
178 }
179
180 @__private30 function _icmp_exc_fragtime:long ()
181 {
182 return @const("ICMP_EXC_FRAGTIME")
183 }
184
185 @__private30 function _rtn_multicast:long ()
186 {
187 return @const("RTN_MULTICAST")
188 }
189
190 @__private30 function _rtn_broadcast:long ()
191 {
192 return @const("RTN_BROADCAST")
193 }
194
195 /**
196 * probe ipmib.InReceives - Count an arriving packet
197 * @skb: pointer to the struct sk_buff being acted on
198 * @op: value to be added to the counter (default value of 1)
199 *
200 * The packet pointed to by @skb is filtered by the function
201 * ipmib_filter_key(). If the packet passes the filter is is
202 * counted in the global @InReceives (equivalent to SNMP's MIB
203 * IPSTATS_MIB_INRECEIVES)
204 */
205 probe ipmib.InReceives=kernel.function("ip_rcv")
206 {
207 skb = $skb;
208 op = 1;
209 SourceIsLocal = 0;
210 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
211 if ( key ) InReceives[key] += op;
212 }
213
214 /**
215 * probe ipmib.InNoRoutes - Count an arriving packet with no matching socket
216 * @skb: pointer to the struct sk_buff being acted on
217 * @op: value to be added to the counter (default value of 1)
218 *
219 * The packet pointed to by @skb is filtered by the function
220 * ipmib_filter_key(). If the packet passes the filter is is
221 * counted in the global @InNoRoutes (equivalent to SNMP's MIB
222 * IPSTATS_MIB_INNOROUTES)
223 */
224 probe ipmib.InNoRoutes=kernel.function("ip_route_input_noref").return!,
225 kernel.function("ip_route_input_common").return!,
226 kernel.function("ip_route_input").return
227 {
228 skb = @entry($skb);
229 op = 1;
230 SourceIsLocal = 0;
231 if ( $return != -_enetunreach()) next;
232 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
233 if ( key ) InNoRoutes[key] += op;
234 }
235
236 /**
237 * probe ipmib.InAddrErrors - Count arriving packets with an incorrect address
238 * @skb: pointer to the struct sk_buff being acted on
239 * @op: value to be added to the counter (default value of 1)
240 *
241 * The packet pointed to by @skb is filtered by the function
242 * ipmib_filter_key(). If the packet passes the filter is is
243 * counted in the global @InAddrErrors (equivalent to SNMP's MIB
244 * IPSTATS_MIB_INADDRERRORS)
245 */
246 probe ipmib.InAddrErrors=kernel.function("ip_route_input_noref").return!,
247 kernel.function("ip_route_input_common").return!,
248 kernel.function("ip_route_input").return
249 {
250 skb = @entry($skb);
251 op = 1;
252 SourceIsLocal = 0;
253 if ( $return != -_ehostunreach()) next;
254 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
255 if ( key ) InAddrErrors[key] += op;
256 }
257
258 /**
259 * probe ipmib.InUnknownProtos - Count arriving packets with an unbound proto
260 * @skb: pointer to the struct sk_buff being acted on
261 * @op: value to be added to the counter (default value of 1)
262 *
263 * The packet pointed to by @skb is filtered by the function
264 * ipmib_filter_key(). If the packet passes the filter is is
265 * counted in the global @InUnknownProtos (equivalent to SNMP's MIB
266 * IPSTATS_MIB_INUNKNOWNPROTOS)
267 */
268 /* icmp_send() is called by ip_local_deliver_finish() */
269 probe ipmib.InUnknownProtos=kernel.function("icmp_send")
270 {
271 skb = $skb_in;
272 op = 1;
273 SourceIsLocal = 0;
274 if (($type==_icmp_dest_unreach())&&($code==_icmp_prot_unreach())){
275 try {
276 key = ipmib_filter_key(skb, op, SourceIsLocal)
277 } catch { }
278 if ( key ) InUnknownProtos[key] += op;
279 }
280 }
281
282 /**
283 * probe ipmib.InDiscards - Count discarded inbound packets
284 * @skb: pointer to the struct sk_buff being acted on
285 * @op: value to be added to the counter (default value of 1)
286 *
287 * The packet pointed to by @skb is filtered by the function
288 * ipmib_filter_key(). If the packet passes the filter is is
289 * counted in the global @InDiscards (equivalent to SNMP's MIB
290 * STATS_MIB_INDISCARDS)
291 */
292
293 /*
294 This stat combines all instances of IPSTATS_MIB_INHDRERRORS,
295 IPSTATS_MIB_INTRUNCATEDPKTS, and STATS_MIB_INDISCARDS.
296 */
297 probe ipmib.InDiscards=kernel.function("ip_rcv").return
298 {
299 skb = @entry($skb);
300 op = 1;
301 SourceIsLocal = 0;
302 if ( $return != _net_rx_drop() ) next;
303 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
304 if ( key ) InDiscards[key] += op;
305 }
306
307 /**
308 * probe ipmib.ForwDatagrams - Count forwarded packet
309 * @skb: pointer to the struct sk_buff being acted on
310 * @op: value to be added to the counter (default value of 1)
311 *
312 * The packet pointed to by @skb is filtered by the function
313 * ipmib_filter_key(). If the packet passes the filter is is
314 * counted in the global @ForwDatagrams (equivalent to SNMP's MIB
315 * IPSTATS_MIB_OUTFORWDATAGRAMS)
316 */
317 %( kernel_v >= "2.6.24" %?
318 probe ipmib.ForwDatagrams=kernel.function("ip_forward_finish")
319 {
320 skb = $skb;
321 op = 1;
322 SourceIsLocal = 0;
323 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
324 if ( key ) ForwDatagrams[key] += op;
325 }
326 %)
327
328 /**
329 * probe ipmib.OutRequests - Count a request to send a packet
330 * @skb: pointer to the struct sk_buff being acted on
331 * @op: value to be added to the counter (default value of 1)
332 *
333 * The packet pointed to by @skb is filtered by the function
334 * ipmib_filter_key(). If the packet passes the filter is is
335 * counted in the global @OutRequests (equivalent to SNMP's MIB
336 * IPSTATS_MIB_OUTREQUESTS)
337 */
338 probe ipmib.OutRequests=kernel.function("ip_output"),
339 kernel.function("ip_mc_output")
340 {
341 skb = @choose_defined($skb, kernel_pointer($pskb));
342 op = 1;
343 SourceIsLocal = 1;
344 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
345 if ( key ) OutRequests[key] += op;
346 }
347
348 /**
349 * probe ipmib.ReasmTimeout - Count Reassembly Timeouts
350 * @skb: pointer to the struct sk_buff being acted on
351 * @op: value to be added to the counter (default value of 1)
352 *
353 * The packet pointed to by @skb is filtered by the function
354 * ipmib_filter_key(). If the packet passes the filter is is
355 * counted in the global @ReasmTimeout (equivalent to SNMP's MIB
356 * IPSTATS_MIB_REASMTIMEOUT)
357 */
358 probe ipmib.ReasmTimeout=kernel.function("icmp_send")
359 {
360 skb = $skb_in;
361 op = 0;
362 SourceIsLocal = 1;
363 if(($type==_icmp_time_exceeded())&&($code==_icmp_exc_fragtime())){
364 try {
365 key = ipmib_filter_key(skb, op, SourceIsLocal)
366 } catch { }
367 if ( key ) ReasmTimeout[key] += op;
368 }
369 }
370
371 /**
372 * probe ipmib.ReasmReqds - Count number of packet fragments reassembly requests
373 * @skb: pointer to the struct sk_buff being acted on
374 * @op: value to be added to the counter (default value of 1)
375 *
376 * The packet pointed to by @skb is filtered by the function
377 * ipmib_filter_key(). If the packet passes the filter is is
378 * counted in the global @ReasmReqds (equivalent to SNMP's MIB
379 * IPSTATS_MIB_REASMREQDS)
380 */
381 probe ipmib.ReasmReqds=kernel.function("ip_defrag")
382 {
383 skb = $skb;
384 op = 0;
385 SourceIsLocal = 1;
386 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
387 if ( key ) ReasmReqds[key] += op;
388 }
389
390 /**
391 * probe ipmib.FragOKs - Count datagram fragmented successfully
392 * @skb: pointer to the struct sk_buff being acted on
393 * @op: value to be added to the counter (default value of 1)
394 *
395 * The packet pointed to by @skb is filtered by the function
396 * ipmib_filter_key(). If the packet passes the filter is is
397 * counted in the global @FragOKs (equivalent to SNMP's MIB
398 * IPSTATS_MIB_FRAGOKS)
399 */
400 probe ipmib.FragOKs=kernel.function("ip_fragment").return
401 {
402 skb = @entry($skb);
403 op = 1;
404 SourceIsLocal = 1;
405 if ( $return ) next
406 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
407 if ( key ) FragOKs [key] += op;
408 }
409
410 /**
411 * probe ipmib.FragFails - Count datagram fragmented unsuccessfully
412 * @skb: pointer to the struct sk_buff being acted on
413 * @op: Value to be added to the counter (default value of 1)
414 *
415 * The packet pointed to by @skb is filtered by the function
416 * ipmib_filter_key(). If the packet passes the filter is is
417 * counted in the global @FragFails (equivalent to SNMP's MIB
418 * IPSTATS_MIB_FRAGFAILS)
419 */
420 probe ipmib.FragFails=kernel.function("ip_fragment").return
421 {
422 skb = @entry($skb);
423 op = 1;
424 SourceIsLocal = 1;
425 if (!$return ) next
426 try { key = ipmib_filter_key(skb, op, SourceIsLocal) } catch { }
427 if ( key ) FragFails [key] += op;
428 }
429
430 @__private30 function _rtn_unspec:long ()
431 {
432 return @const("RTN_UNSPEC")
433 }
434
435 function _input_route_type:long (skb:long)
436 {
437 rt = @choose_defined(@cast(skb, "sk_buff")->_skb_dst,
438 @choose_defined(@cast(skb, "sk_buff")->rtable, 0))
439 return rt ? @cast(rt, "rtable")->rt_type : _rtn_unspec()
440 }
441
442 @__private30 function _output_route_type:long (skb:long)
443 {
444 rt = @choose_defined(@cast(skb, "sk_buff")->_skb_dst,
445 @choose_defined(@cast(skb, "sk_buff")->dst, 0))
446 return rt ? @cast(rt, "rtable")->rt_type : _rtn_unspec()
447 }