Debian Codegraph @

tapset/linux/socket.stp

raw
1 // Socket tapset
2 // Copyright (C) 2006 IBM Corp.
3 // Copyright (C) 2010-2017 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 // <tapsetdescription>
10 // This family of probe points is used to probe socket activities.
11 // </tapsetdescription>
12 %{
13 #include <net/sock.h>
14 #include <asm/bitops.h>
15 %}
16
17 ###################
18 # INTERNAL MACROS #
19 ###################
20
21 // Note that since these macros are defined in this file, they are
22 // local to this file. They are internal only.
23 //
24 // Note the '&@sock[0]' usage below. This allows calling the macros
25 // with either a dwarf variable (like '$sock') or casts (like
26 // '@cast(_sock, "socket", "kernel") without needing additional casts
27 // inside the macros (which would then lose type information when
28 // called with a dwarf variable).
29
30 // Return whether the operation was successful.
31 @define _sock_success_check(ret)
32 %(
33 ( @ret >= 0 ? 1 : 0 )
34 %)
35
36 // Return the socket protocol number.
37 @define _sock_prot_num(sock)
38 %(
39 ( &@sock[0] ? ( @sock->sk ? @sock->sk->sk_protocol : -1 ) : -1 )
40 %)
41
42 // Return the socket family number.
43 @define _sock_fam_num(sock)
44 %(
45 ( &@sock[0] ? ( @sock->ops ? @sock->ops->family : -1 ) : -1 )
46 %)
47
48 // Return the socket state number.
49 @define _sock_state_num(sock)
50 %(
51 ( &@sock[0] ? @sock->state : -1 )
52 %)
53
54 // Return the socket type number.
55 @define _sock_type_num(sock)
56 %(
57 ( &@sock[0] ? @sock->type : -1 )
58 %)
59
60 // Return the socket flags number.
61 @define _sock_flags_num(sock)
62 %(
63 ( &@sock[0] ? @sock->flags : -1 )
64 %)
65
66 // A macro that acts just like the kernel's iov_iter_count() (which is
67 // an inlined function in include/linux/uio.h).
68 @define iov_iter_count(i) %(
69 ( @i->count )
70 %)
71
72 // A macro that acts just like the kernel's msg_data_left() (which is
73 // an inlined function in include/linux/socket.h).
74 @define msg_data_left(msg) %(
75 ( @iov_iter_count(@msg->msg_iter) )
76 %)
77
78 #################
79 # PROBE ALIASES #
80 #################
81
82 ### GENERAL SEND/RECEIVE PROBES ###
83
84 /**
85 * probe socket.send - Message sent on a socket.
86 * @name: Name of this probe
87 * @size: Size of message sent (in bytes) or error code if success = 0
88 * @protocol: Protocol value
89 * @family: Protocol family value
90 * @state: Socket state value
91 * @flags: Socket flags value
92 * @type: Socket type value
93 * @success: Was send successful? (1 = yes, 0 = no)
94 *
95 * Context:
96 * The message sender
97 */
98 probe socket.send = socket.sendmsg.return,
99 socket.writev.return ?,
100 socket.aio_write.return ?,
101 socket.write_iter.return ?
102 {
103 name = "socket.send"
104 }
105
106 /**
107 * probe socket.receive - Message received on a socket.
108 * @name: Name of this probe
109 * @size: Size of message received (in bytes) or error code if success = 0
110 * @protocol: Protocol value
111 * @family: Protocol family value
112 * @state: Socket state value
113 * @flags: Socket flags value
114 * @type: Socket type value
115 * @success: Was send successful? (1 = yes, 0 = no)
116 *
117 * Context:
118 * The message receiver
119 */
120 probe socket.receive = socket.recvmsg.return,
121 socket.readv.return ?,
122 socket.aio_read.return ?,
123 socket.read_iter.return ?
124 {
125 name = "socket.receive"
126 }
127
128 ### FUNCTION SPECIFIC SEND/RECEIVE PROBES ###
129
130 /**
131 * probe socket.sendmsg - Message is currently being sent on a socket.
132 * @name: Name of this probe
133 * @size: Message size in bytes
134 * @protocol: Protocol value
135 * @family: Protocol family value
136 * @state: Socket state value
137 * @flags: Socket flags value
138 * @type: Socket type value
139 *
140 * Context:
141 * The message sender
142 *
143 * Fires at the beginning of sending a message on a socket
144 * via the sock_sendmsg() function
145 */
146 //
147 // 4.1-rc1:
148 // int sock_sendmsg(struct socket *sock, struct msghdr *msg);
149 // before 4.1-rc1:
150 // int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size);
151 //
152 probe socket.sendmsg = kernel.function ("sock_sendmsg")
153 {
154 name = "socket.sendmsg"
155 size = @choose_defined($size, @msg_data_left($msg))
156 protocol = @_sock_prot_num($sock)
157 family = @_sock_fam_num($sock)
158 state = @_sock_state_num($sock)
159 flags = @_sock_flags_num($sock)
160 type = @_sock_type_num($sock)
161 }
162
163 /**
164 * probe socket.sendmsg.return - Return from socket.sendmsg.
165 * @name: Name of this probe
166 * @size: Size of message sent (in bytes) or error code if success = 0
167 * @protocol: Protocol value
168 * @family: Protocol family value
169 * @state: Socket state value
170 * @flags: Socket flags value
171 * @type: Socket type value
172 * @success: Was send successful? (1 = yes, 0 = no)
173 *
174 * Context:
175 * The message sender.
176 *
177 * Fires at the conclusion of sending a message on a socket
178 * via the sock_sendmsg() function
179 */
180 probe socket.sendmsg.return = kernel.function("sock_sendmsg").return
181 {
182 name = "socket.sendmsg.return"
183 size = $return
184 protocol = @entry(@_sock_prot_num($sock))
185 family = @entry(@_sock_fam_num($sock))
186 state = @entry(@_sock_state_num($sock))
187 flags = @entry(@_sock_flags_num($sock))
188 type = @entry(@_sock_type_num($sock))
189 success = @_sock_success_check($return)
190 }
191
192 /**
193 * probe socket.recvmsg - Message being received on socket
194 * @name: Name of this probe
195 * @size: Message size in bytes
196 * @protocol: Protocol value
197 * @family: Protocol family value
198 * @state: Socket state value
199 * @flags: Socket flags value
200 * @type: Socket type value
201 *
202 * Context:
203 * The message receiver.
204 *
205 * Fires at the beginning of receiving a message on a socket
206 * via the sock_recvmsg() function
207 *
208 */
209 probe socket.recvmsg = kernel.function("sock_recvmsg")
210 {
211 name = "socket.recvmsg"
212 size = @choose_defined($size, @msg_data_left($msg))
213 protocol = @_sock_prot_num($sock)
214 family = @_sock_fam_num($sock)
215 state = @_sock_state_num($sock)
216 flags = @_sock_flags_num($sock)
217 type = @_sock_type_num($sock)
218 }
219
220 /**
221 * probe socket.recvmsg.return - Return from Message being received on socket
222 * @name: Name of this probe
223 * @size: Size of message received (in bytes) or error code if success = 0
224 * @protocol: Protocol value
225 * @family: Protocol family value
226 * @state: Socket state value
227 * @flags: Socket flags value
228 * @type: Socket type value
229 * @success: Was receive successful? (1 = yes, 0 = no)
230 *
231 * Context:
232 * The message receiver.
233 *
234 * Fires at the conclusion of receiving a message on a socket
235 * via the sock_recvmsg() function.
236 *
237 *
238 */
239 probe socket.recvmsg.return = kernel.function("sock_recvmsg").return
240 {
241 name = "socket.recvmsg.return"
242 size = $return
243 protocol = @entry(@_sock_prot_num($sock))
244 family = @entry(@_sock_fam_num($sock))
245 state = @entry(@_sock_state_num($sock))
246 flags = @entry(@_sock_flags_num($sock))
247 type = @entry(@_sock_type_num($sock))
248 success = @_sock_success_check($return)
249 }
250
251 /**
252 * probe socket.aio_write - Message send via sock_aio_write()
253 * @name: Name of this probe
254 * @size: Message size in bytes
255 * @protocol: Protocol value
256 * @family: Protocol family value
257 * @state: Socket state value
258 * @flags: Socket flags value
259 * @type: Socket type value
260 *
261 * Context:
262 * The message sender
263 *
264 * Fires at the beginning of sending a message on a socket
265 * via the sock_aio_write() function
266 */
267 //
268 // 2.6.9~2.6.15:
269 // static ssize_t sock_aio_write(struct kiocb *iocb,
270 // const char __user *ubuf, size_t size, loff_t pos);
271 // 2.6.16~2.6.18:
272 // static ssize_t sock_aio_write(struct kiocb *iocb,
273 // const char __user *ubuf, size_t count, loff_t pos);
274 // 2.6.19~2.6.26:
275 // static ssize_t sock_aio_write(struct kiocb *iocb,
276 // const struct iovec *iov, unsigned long nr_segs, loff_t pos);
277 // 4.0:
278 // sock_aio_write() was removed in kernel 4.0 in favor of
279 // sock_write_iter().
280
281 probe socket.aio_write = kernel.function("sock_aio_write") ?
282 {
283 name = "socket.aio_write"
284 _sock = _get_sock_addr($iocb->ki_filp)
285 size = (@defined($iov) ? _get_sock_size($iov, $nr_segs)
286 : @choose_defined($count, $size))
287 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
288 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
289 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
290 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
291 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
292 }
293
294 /**
295 * probe socket.aio_write.return - Conclusion of message send via sock_aio_write()
296 * @name: Name of this probe
297 * @size: Size of message received (in bytes) or error code if success = 0
298 * @protocol: Protocol value
299 * @family: Protocol family value
300 * @state: Socket state value
301 * @flags: Socket flags value
302 * @type: Socket type value
303 * @success: Was receive successful? (1 = yes, 0 = no)
304 *
305 * Context:
306 * The message receiver.
307 *
308 * Fires at the conclusion of sending a message on a socket
309 * via the sock_aio_write() function
310 */
311 probe socket.aio_write.return = kernel.function("sock_aio_write").return ?
312 {
313 name = "socket.aio_write.return"
314 size = $return
315 _sock = _get_sock_addr(@entry($iocb->ki_filp))
316 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
317 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
318 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
319 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
320 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
321 success = @_sock_success_check($return)
322 }
323
324 /**
325 * probe socket.aio_read - Receiving message via sock_aio_read()
326 * @name: Name of this probe
327 * @size: Message size in bytes
328 * @protocol: Protocol value
329 * @family: Protocol family value
330 * @state: Socket state value
331 * @flags: Socket flags value
332 * @type: Socket type value
333 *
334 * Context:
335 * The message sender
336 *
337 * Fires at the beginning of receiving a message on a socket
338 * via the sock_aio_read() function
339 */
340 //
341 // 2.6.9~2.6.15:
342 // static ssize_t sock_aio_read(struct kiocb *iocb, char __user *ubuf,
343 // size_t size, loff_t pos);
344 // 2.6.16~2.6.18:
345 // static ssize_t sock_aio_read(struct kiocb *iocb, char __user *ubuf,
346 // size_t count, loff_t pos);
347 // 2.6.19~2.6.26:
348 // static ssize_t sock_aio_read(struct kiocb *iocb,
349 // const struct iovec *iov, unsigned long nr_segs, loff_t pos);
350 // 4.0:
351 // sock_aio_read() was removed in kernel 4.0 in favor of
352 // sock_read_iter().
353
354 probe socket.aio_read = kernel.function("sock_aio_read") ?
355 {
356 name = "socket.aio_read"
357 _sock = _get_sock_addr($iocb->ki_filp)
358 size = (@defined($iov) ? _get_sock_size($iov, $nr_segs)
359 : @choose_defined($count, $size))
360 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
361 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
362 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
363 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
364 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
365 }
366
367 /**
368 * probe socket.aio_read.return - Conclusion of message received via sock_aio_read()
369 * @name: Name of this probe
370 * @size: Size of message received (in bytes) or error code if success = 0
371 * @protocol: Protocol value
372 * @family: Protocol family value
373 * @state: Socket state value
374 * @flags: Socket flags value
375 * @type: Socket type value
376 * @success: Was receive successful? (1 = yes, 0 = no)
377 *
378 * Context:
379 * The message receiver.
380 *
381 * Fires at the conclusion of receiving a message on a socket
382 * via the sock_aio_read() function
383 */
384 probe socket.aio_read.return = kernel.function("sock_aio_read").return ?
385 {
386 name = "socket.aio_read.return"
387 size = $return
388 _sock = _get_sock_addr(@entry($iocb->ki_filp))
389 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
390 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
391 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
392 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
393 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
394 success = @_sock_success_check($return)
395 }
396
397 /**
398 * probe socket.write_iter - Message send via sock_write_iter()
399 * @name: Name of this probe
400 * @size: Message size in bytes
401 * @protocol: Protocol value
402 * @family: Protocol family value
403 * @state: Socket state value
404 * @flags: Socket flags value
405 * @type: Socket type value
406 *
407 * Context:
408 * The message sender
409 *
410 * Fires at the beginning of sending a message on a socket
411 * via the sock_write_iter() function
412 */
413 //
414 // 4.0:
415 // static ssize_t sock_write_iter(struct kiocb *iocb,
416 // struct iov_iter *from);
417
418 probe socket.write_iter = kernel.function("sock_write_iter") ?
419 {
420 name = "socket.write_iter"
421 _sock = _get_sock_addr($iocb->ki_filp)
422 if ($from->type & @const("ITER_IOVEC"))
423 size = __iov_length($from->iov, $from->nr_segs, 1,
424 @const("VERIFY_READ"))
425 else
426 size = 0
427 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
428 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
429 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
430 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
431 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
432 }
433
434 /**
435 * probe socket.write_iter.return - Conclusion of message send via sock_write_iter()
436 * @name: Name of this probe
437 * @size: Size of message received (in bytes) or error code if success = 0
438 * @protocol: Protocol value
439 * @family: Protocol family value
440 * @state: Socket state value
441 * @flags: Socket flags value
442 * @type: Socket type value
443 * @success: Was receive successful? (1 = yes, 0 = no)
444 *
445 * Context:
446 * The message receiver.
447 *
448 * Fires at the conclusion of sending a message on a socket
449 * via the sock_write_iter() function
450 */
451 probe socket.write_iter.return = kernel.function("sock_write_iter").return ?
452 {
453 name = "socket.write_iter.return"
454 size = $return
455 _sock = _get_sock_addr(@entry($iocb->ki_filp))
456 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
457 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
458 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
459 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
460 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
461 success = @_sock_success_check($return)
462 }
463
464 /**
465 * probe socket.read_iter - Receiving message via sock_read_iter()
466 * @name: Name of this probe
467 * @size: Message size in bytes
468 * @protocol: Protocol value
469 * @family: Protocol family value
470 * @state: Socket state value
471 * @flags: Socket flags value
472 * @type: Socket type value
473 *
474 * Context:
475 * The message sender
476 *
477 * Fires at the beginning of receiving a message on a socket
478 * via the sock_read_iter() function
479 */
480 //
481 // 4.0:
482 // static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to);
483
484 probe socket.read_iter = kernel.function("sock_read_iter") ?
485 {
486 name = "socket.read_iter"
487 _sock = _get_sock_addr($iocb->ki_filp)
488 if ($to->type & @const("ITER_IOVEC"))
489 size = __iov_length($to->iov, $to->nr_segs, 1,
490 @const("VERIFY_WRITE"))
491 else
492 size = 0
493 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
494 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
495 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
496 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
497 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
498 }
499
500 /**
501 * probe socket.read_iter.return - Conclusion of message received via sock_read_iter()
502 * @name: Name of this probe
503 * @size: Size of message received (in bytes) or error code if success = 0
504 * @protocol: Protocol value
505 * @family: Protocol family value
506 * @state: Socket state value
507 * @flags: Socket flags value
508 * @type: Socket type value
509 * @success: Was receive successful? (1 = yes, 0 = no)
510 *
511 * Context:
512 * The message receiver.
513 *
514 * Fires at the conclusion of receiving a message on a socket
515 * via the sock_read_iter() function
516 */
517 probe socket.read_iter.return = kernel.function("sock_read_iter").return ?
518 {
519 name = "socket.read_iter.return"
520 size = $return
521 _sock = _get_sock_addr(@entry($iocb->ki_filp))
522 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
523 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
524 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
525 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
526 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
527 success = @_sock_success_check($return)
528 }
529
530 /**
531 * probe socket.writev - Message sent via socket_writev()
532 * @name: Name of this probe
533 * @size: Message size in bytes
534 * @protocol: Protocol value
535 * @family: Protocol family value
536 * @state: Socket state value
537 * @flags: Socket flags value
538 * @type: Socket type value
539 *
540 * Context:
541 * The message sender
542 *
543 * Fires at the beginning of sending a message on a socket
544 * via the sock_writev() function
545 */
546 probe socket.writev = kernel.function("sock_writev") ?
547 {
548 name = "socket.writev"
549 _sock = _get_sock_addr($file)
550 size = (@defined($iov) ? _get_sock_size($iov, $nr_segs)
551 : _get_sock_size($vector, $count))
552 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
553 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
554 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
555 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
556 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
557 }
558
559 /**
560 * probe socket.writev.return - Conclusion of message sent via socket_writev()
561 * @name: Name of this probe
562 * @size: Size of message sent (in bytes) or error code if success = 0
563 * @protocol: Protocol value
564 * @family: Protocol family value
565 * @state: Socket state value
566 * @flags: Socket flags value
567 * @type: Socket type value
568 * @success: Was send successful? (1 = yes, 0 = no)
569 *
570 * Context:
571 * The message receiver.
572 *
573 * Fires at the conclusion of sending a message on a socket
574 * via the sock_writev() function
575 */
576 probe socket.writev.return = kernel.function("sock_writev").return ?
577 {
578 name = "socket.writev.return"
579 size = $return
580 _sock = _get_sock_addr(@entry($file))
581 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
582 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
583 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
584 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
585 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
586 success = @_sock_success_check($return)
587 }
588
589 /**
590 * probe socket.readv - Receiving a message via sock_readv()
591 * @name: Name of this probe
592 * @size: Message size in bytes
593 * @protocol: Protocol value
594 * @family: Protocol family value
595 * @state: Socket state value
596 * @flags: Socket flags value
597 * @type: Socket type value
598 *
599 * Context:
600 * The message sender
601 *
602 * Fires at the beginning of receiving a message on a socket
603 * via the sock_readv() function
604 */
605 probe socket.readv = kernel.function("sock_readv") ?
606 {
607 name = "socket.readv"
608 _sock = _get_sock_addr($file)
609 size = (@defined($iov) ? _get_sock_size($iov, $nr_segs)
610 : _get_sock_size($vector, $count))
611 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
612 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
613 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
614 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
615 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
616 }
617
618 /**
619 * probe socket.readv.return - Conclusion of receiving a message via sock_readv()
620 * @name: Name of this probe
621 * @size: Size of message received (in bytes) or error code if success = 0
622 * @protocol: Protocol value
623 * @family: Protocol family value
624 * @state: Socket state value
625 * @flags: Socket flags value
626 * @type: Socket type value
627 * @success: Was receive successful? (1 = yes, 0 = no)
628 *
629 * Context:
630 * The message receiver.
631 *
632 * Fires at the conclusion of receiving a message on a socket
633 * via the sock_readv() function
634 */
635 probe socket.readv.return = kernel.function("sock_readv").return ?
636 {
637 name = "socket.readv.return"
638 size = $return
639 _sock = _get_sock_addr(@entry($file))
640 protocol = @_sock_prot_num(@cast(_sock, "socket", "kernel"))
641 family = @_sock_fam_num(@cast(_sock, "socket", "kernel"))
642 state = @_sock_state_num(@cast(_sock, "socket", "kernel"))
643 flags = @_sock_flags_num(@cast(_sock, "socket", "kernel"))
644 type = @_sock_type_num(@cast(_sock, "socket", "kernel"))
645 success = @_sock_success_check($return)
646 }
647
648 /**
649 * probe socket.create - Creation of a socket
650 * @name: Name of this probe
651 * @protocol: Protocol value
652 * @family: Protocol family value
653 * @type: Socket type value
654 * @requester: Requested by user process or the kernel (1 = kernel, 0 = user)
655 *
656 * Context:
657 * The requester (see requester variable)
658 *
659 * Fires at the beginning of creating a socket.
660 */
661 probe socket.create = kernel.function("__sock_create")
662 {
663 name = "socket.create"
664 protocol = $protocol
665 family = $family
666 type = $type
667 requester = $kern
668 }
669
670 /**
671 * probe socket.create.return - Return from Creation of a socket
672 * @name: Name of this probe
673 * @protocol: Protocol value
674 * @family: Protocol family value
675 * @type: Socket type value
676 * @requester: Requested by user process or the kernel (1 = kernel, 0 = user)
677 * @err: Error code if success == 0
678 * @success: Was socket creation successful? (1 = yes, 0 = no)
679 *
680 * Context:
681 * The requester (user process or kernel)
682 *
683 * Fires at the conclusion of creating a socket.
684 */
685 probe socket.create.return = kernel.function("__sock_create").return
686 {
687 name = "socket.create.return"
688 protocol = @entry($protocol)
689 family = @entry($family)
690 type = @entry($type)
691 requester = @entry($kern)
692 err = $return
693 success = @_sock_success_check($return)
694 }
695
696 /**
697 * probe socket.close - Close a socket
698 * @name: Name of this probe
699 * @protocol: Protocol value
700 * @family: Protocol family value
701 * @state: Socket state value
702 * @flags: Socket flags value
703 * @type: Socket type value
704 *
705 * Context:
706 * The requester (user process or kernel)
707 *
708 * Fires at the beginning of closing a socket.
709 */
710 probe socket.close = kernel.function("sock_release")
711 {
712 name = "socket.close"
713 protocol = @_sock_prot_num($sock)
714 family = @_sock_fam_num($sock)
715 state = @_sock_state_num($sock)
716 flags = @_sock_flags_num($sock)
717 type = @_sock_type_num($sock)
718 }
719
720 /**
721 * probe socket.close.return - Return from closing a socket
722 * @name: Name of this probe
723 *
724 * Context:
725 * The requester (user process or kernel)
726 *
727 * Fires at the conclusion of closing a socket.
728 */
729 probe socket.close.return = kernel.function("sock_release").return
730 {
731 name = "socket.close.return"
732 /* void return */
733 }
734
735
736 ##################
737 # USER FUNCTIONS #
738 ##################
739
740 ####### PROTOCOL HELPER FUNCTIONS ########
741
742 /**
743 * sfunction sock_prot_num2str - Given a protocol number, return a string representation
744 * @proto: The protocol number
745 */
746 function sock_prot_num2str:string(proto:long)
747 {
748 return (proto in _prot_num2str ? _prot_num2str[proto] : "UNDEF")
749 }
750
751 /**
752 * sfunction sock_prot_str2num - Given a protocol name (string), return the corresponding protocol number
753 * @proto: The protocol name
754 */
755 function sock_prot_str2num:long(proto:string)
756 {
757 return (proto in _prot_str2num ? _prot_str2num[proto] : -1)
758 }
759
760 ######### PROTOCOL FAMILY HELPER FUNCTIONS ###########
761
762 /**
763 * sfunction sock_fam_num2str - Given a protocol family number, return a string representation
764 * @family: The family number
765 */
766 function sock_fam_num2str:string(family:long)
767 {
768 return (family in _fam_num2str ? _fam_num2str[family] : "UNDEF")
769 }
770
771 /**
772 * sfunction sock_fam_str2num - Given a protocol family name (string), return the corresponding protocol family number
773 * @family: The family name
774 */
775 function sock_fam_str2num:long(family:string)
776 {
777 return (family in _fam_str2num ? _fam_str2num[family] : -1)
778 }
779
780 ######### SOCKET STATE HELPER FUNCTIONS ##########
781
782 /**
783 * sfunction sock_state_num2str - Given a socket state number, return a string representation
784 * @state: The state number
785 */
786 function sock_state_num2str:string(state:long)
787 {
788 return (state in _state_num2str ? _state_num2str[state] : "UNDEF")
789 }
790
791 /**
792 * sfunction sock_state_str2num - Given a socket state string, return the corresponding state number
793 * @state: The state name
794 */
795 function sock_state_str2num:long(state:string)
796 {
797 return (state in _state_str2num ? _state_str2num[state] : -1)
798 }
799
800 ######## SOCKET TYPE HELPER FUNCTIONS ########
801
802 function sock_type_num2str:string(type:long)
803 {
804 return (type in _type_num2str ? _type_num2str[type] : "UNDEF")
805 }
806
807 function sock_type_str2num:long(type:string)
808 {
809 return (type in _type_str2num ? _type_str2num[type] : -1)
810 }
811
812 ######### SOCKET FLAGS HELPER FUNCTIONS #########
813
814 function sock_flags_num2str:string(flags:long)
815 %{ /* pure */
816 #ifndef SOCK_PASSCRED
817 #define SOCK_PASSCRED 3 /* introduced in 2.6.12? */
818 #endif
819 #ifndef SOCK_PASSSEC
820 #define SOCK_PASSSEC 4 /* introduced in 2.6.18 */
821 #endif
822 #ifndef SOCKWQ_ASYNC_NOSPACE /* renamed in 4.4 */
823 #define SOCKWQ_ASYNC_NOSPACE SOCK_ASYNC_NOSPACE
824 #endif
825 #ifndef SOCKWQ_ASYNC_WAITDATA /* renamed in 4.4 */
826 #define SOCKWQ_ASYNC_WAITDATA SOCK_ASYNC_WAITDATA
827 #endif
828 unsigned long flags = STAP_ARG_flags;
829
830 STAP_RETVALUE[0] = '\0';
831 if (test_bit(SOCKWQ_ASYNC_NOSPACE, &flags))
832 strlcat(STAP_RETVALUE, "ASYNC_NOSPACE|", MAXSTRINGLEN);
833 if (test_bit(SOCKWQ_ASYNC_WAITDATA, &flags))
834 strlcat(STAP_RETVALUE, "ASYNC_WAITDATA|", MAXSTRINGLEN);
835 if (test_bit(SOCK_NOSPACE, &flags))
836 strlcat(STAP_RETVALUE, "NOSPACE|", MAXSTRINGLEN);
837 if (test_bit(SOCK_PASSCRED, &flags))
838 strlcat(STAP_RETVALUE, "PASSCRED|", MAXSTRINGLEN);
839 if (test_bit(SOCK_PASSSEC, &flags))
840 strlcat(STAP_RETVALUE, "PASSSEC|", MAXSTRINGLEN);
841 if (STAP_RETVALUE[0] != '\0')
842 STAP_RETVALUE[strlen(STAP_RETVALUE)-1] = '\0';
843 %}
844
845 ######### MESSAGE FLAGS HELPER FUNCTIONS #########
846
847 function msg_flags_num2str:string(flags:long)
848 %{ /* pure */
849 STAP_RETVALUE[0] = '\0';
850
851 if (STAP_ARG_flags & MSG_OOB)
852 strlcat(STAP_RETVALUE, "OOB|", MAXSTRINGLEN);
853 if (STAP_ARG_flags & MSG_PEEK)
854 strlcat(STAP_RETVALUE, "PEEK|", MAXSTRINGLEN);
855 if (STAP_ARG_flags & MSG_DONTROUTE)
856 strlcat(STAP_RETVALUE, "DONTROUTE|", MAXSTRINGLEN);
857 if (STAP_ARG_flags & MSG_TRYHARD)
858 strlcat(STAP_RETVALUE, "TRYHARD|", MAXSTRINGLEN);
859 if (STAP_ARG_flags & MSG_CTRUNC)
860 strlcat(STAP_RETVALUE, "CTRUNC|", MAXSTRINGLEN);
861 if (STAP_ARG_flags & MSG_PROBE)
862 strlcat(STAP_RETVALUE, "PROBE|", MAXSTRINGLEN);
863 if (STAP_ARG_flags & MSG_TRUNC)
864 strlcat(STAP_RETVALUE, "TRUNC|", MAXSTRINGLEN);
865 if (STAP_ARG_flags & MSG_DONTWAIT)
866 strlcat(STAP_RETVALUE, "DONTWAIT|", MAXSTRINGLEN);
867 if (STAP_ARG_flags & MSG_EOR)
868 strlcat(STAP_RETVALUE, "EOR|", MAXSTRINGLEN);
869 if (STAP_ARG_flags & MSG_WAITALL)
870 strlcat(STAP_RETVALUE, "WAITALL|", MAXSTRINGLEN);
871 if (STAP_ARG_flags & MSG_FIN)
872 strlcat(STAP_RETVALUE, "FIN|", MAXSTRINGLEN);
873 if (STAP_ARG_flags & MSG_SYN)
874 strlcat(STAP_RETVALUE, "SYN|", MAXSTRINGLEN);
875 if (STAP_ARG_flags & MSG_CONFIRM)
876 strlcat(STAP_RETVALUE, "CONFIRM|", MAXSTRINGLEN);
877 if (STAP_ARG_flags & MSG_RST)
878 strlcat(STAP_RETVALUE, "RST|", MAXSTRINGLEN);
879 if (STAP_ARG_flags & MSG_ERRQUEUE)
880 strlcat(STAP_RETVALUE, "ERRQUEUE|", MAXSTRINGLEN);
881 if (STAP_ARG_flags & MSG_NOSIGNAL)
882 strlcat(STAP_RETVALUE, "NOSIGNAL|", MAXSTRINGLEN);
883 if (STAP_ARG_flags & MSG_MORE)
884 strlcat(STAP_RETVALUE, "MORE|", MAXSTRINGLEN);
885
886 if (STAP_RETVALUE[0] != '\0')
887 STAP_RETVALUE[strlen(STAP_RETVALUE)-1] = '\0';
888 %}
889
890 ###########################
891 # INTERNAL MAPPING ARRAYS #
892 ###########################
893
894 @__private30 global _prot_num2str[138], _prot_str2num[138]
895 @__private30 global _fam_num2str[34], _fam_str2num[34]
896 @__private30 global _state_num2str[5], _state_str2num[5]
897 @__private30 global _type_num2str[11], _type_str2num[11]
898
899 probe init
900 {
901 /* From /etc/protocols.
902 * Many of these protocols aren't currently used over
903 * sockets, but are included for completeness
904 */
905 _prot_num2str[0] = "IP"
906 _prot_num2str[1] = "ICMP"
907 _prot_num2str[2] = "IGMP"
908 _prot_num2str[3] = "GGP"
909 _prot_num2str[4] = "IPENCAP"
910 _prot_num2str[5] = "ST"
911 _prot_num2str[6] = "TCP"
912 _prot_num2str[7] = "CBT"
913 _prot_num2str[8] = "EGP"
914 _prot_num2str[9] = "IGP"
915 _prot_num2str[10] = "BBN-RCC"
916 _prot_num2str[11] = "NVP"
917 _prot_num2str[12] = "PUP"
918 _prot_num2str[13] = "ARGUS"
919 _prot_num2str[14] = "EMCON"
920 _prot_num2str[15] = "XNET"
921 _prot_num2str[16] = "CHAOS"
922 _prot_num2str[17] = "UDP"
923 _prot_num2str[18] = "MUX"
924 _prot_num2str[19] = "DCN"
925 _prot_num2str[20] = "HMP"
926 _prot_num2str[21] = "PRM"
927 _prot_num2str[22] = "XNS-IDP"
928 _prot_num2str[23] = "TRUNK-1"
929 _prot_num2str[24] = "TRUNK-2"
930 _prot_num2str[25] = "LEAF-1"
931 _prot_num2str[26] = "LEAF-2"
932 _prot_num2str[27] = "RDP"
933 _prot_num2str[28] = "IRTP"
934 _prot_num2str[29] = "ISO-TP4"
935 _prot_num2str[30] = "NETBLT"
936 _prot_num2str[31] = "MFE-NSP"
937 _prot_num2str[32] = "MERIT-INP"
938 _prot_num2str[33] = "SEP"
939 _prot_num2str[34] = "3PC"
940 _prot_num2str[35] = "IDPR"
941 _prot_num2str[36] = "XTP"
942 _prot_num2str[37] = "DDP"
943 _prot_num2str[38] = "IDPR-CMTP"
944 _prot_num2str[39] = "TP++"
945 _prot_num2str[40] = "IL"
946 _prot_num2str[41] = "IPV6"
947 _prot_num2str[42] = "SDRP"
948 _prot_num2str[43] = "IPV6-ROUTE"
949 _prot_num2str[44] = "IPV6-FRAG"
950 _prot_num2str[45] = "IDRP"
951 _prot_num2str[46] = "RSVP"
952 _prot_num2str[47] = "GRE"
953 _prot_num2str[48] = "MHRP"
954 _prot_num2str[49] = "BNA"
955 _prot_num2str[50] = "IPV6-CRYPT"
956 _prot_num2str[51] = "IPV6-AUTH"
957 _prot_num2str[52] = "I-NLSP"
958 _prot_num2str[53] = "SWIPE"
959 _prot_num2str[54] = "NARP"
960 _prot_num2str[55] = "MOBILE"
961 _prot_num2str[56] = "TLSP"
962 _prot_num2str[57] = "SKIP"
963 _prot_num2str[58] = "IPV6-ICMP"
964 _prot_num2str[59] = "IPV6-NONXT"
965 _prot_num2str[60] = "IPV6-OPTS"
966 _prot_num2str[62] = "CFTP"
967 _prot_num2str[64] = "SAT-EXPAK"
968 _prot_num2str[65] = "KRYPTOLAN"
969 _prot_num2str[66] = "RVD"
970 _prot_num2str[67] = "IPPC"
971 _prot_num2str[69] = "SAT-MON"
972 _prot_num2str[70] = "VISA"
973 _prot_num2str[71] = "IPCV"
974 _prot_num2str[72] = "CPNX"
975 _prot_num2str[73] = "CPHB"
976 _prot_num2str[74] = "WSN"
977 _prot_num2str[75] = "PVP"
978 _prot_num2str[76] = "BR-SAT-MON"
979 _prot_num2str[77] = "SUN-ND"
980 _prot_num2str[78] = "WB-MON"
981 _prot_num2str[79] = "WB-EXPAK"
982 _prot_num2str[80] = "ISO-IP"
983 _prot_num2str[81] = "VMTP"
984 _prot_num2str[82] = "SECURE-VMTP"
985 _prot_num2str[83] = "VINES"
986 _prot_num2str[84] = "TTP"
987 _prot_num2str[85] = "NSFNET-IGP"
988 _prot_num2str[86] = "DGP"
989 _prot_num2str[87] = "TCF"
990 _prot_num2str[88] = "EIGRP"
991 _prot_num2str[89] = "OSPF"
992 _prot_num2str[90] = "SPRITE-RPC"
993 _prot_num2str[91] = "LARP"
994 _prot_num2str[92] = "MTP"
995 _prot_num2str[93] = "AX.25"
996 _prot_num2str[94] = "IPIP"
997 _prot_num2str[95] = "MICP"
998 _prot_num2str[96] = "SCC-SP"
999 _prot_num2str[97] = "ETHERIP"
1000 _prot_num2str[98] = "ENCAP"
1001 _prot_num2str[100] = "GMTP"
1002 _prot_num2str[101] = "IFMP"
1003 _prot_num2str[102] = "PNNI"
1004 _prot_num2str[103] = "PIM"
1005 _prot_num2str[104] = "ARIS"
1006 _prot_num2str[105] = "SCPS"
1007 _prot_num2str[106] = "QNX"
1008 _prot_num2str[107] = "A/N"
1009 _prot_num2str[108] = "IPCOMP"
1010 _prot_num2str[109] = "SNP"
1011 _prot_num2str[110] = "COMPAQ-PEER"
1012 _prot_num2str[111] = "IPX-IN-IP"
1013 _prot_num2str[112] = "VRRP"
1014 _prot_num2str[113] = "PGM"
1015 _prot_num2str[115] = "L2TP"
1016 _prot_num2str[116] = "DDX"
1017 _prot_num2str[117] = "IATP"
1018 _prot_num2str[118] = "STP"
1019 _prot_num2str[119] = "SRP"
1020 _prot_num2str[120] = "UTI"
1021 _prot_num2str[121] = "SMP"
1022 _prot_num2str[122] = "SM"
1023 _prot_num2str[123] = "PTP"
1024 _prot_num2str[124] = "ISIS"
1025 _prot_num2str[125] = "FIRE"
1026 _prot_num2str[126] = "CRTP"
1027 _prot_num2str[127] = "CRDUP"
1028 _prot_num2str[128] = "SSCOPMCE"
1029 _prot_num2str[129] = "IPLT"
1030 _prot_num2str[130] = "SPS"
1031 _prot_num2str[131] = "PIPE"
1032 _prot_num2str[132] = "SCTP"
1033 _prot_num2str[133] = "FC"
1034 _prot_num2str[134] = "RSVP-E2E-IGNORE"
1035 _prot_num2str[135] = "Mobility-Header"
1036 _prot_num2str[136] = "UDPLite"
1037 _prot_num2str[137] = "MPLS-IN-IP"
1038
1039 foreach (num in _prot_num2str)
1040 _prot_str2num[_prot_num2str[num]] = num
1041
1042 /* from include/linux/socket.h */
1043 _fam_num2str[0] = "UNSPEC"
1044 _fam_num2str[1] = "LOCAL"
1045 _fam_num2str[2] = "INET"
1046 _fam_num2str[3] = "AX25"
1047 _fam_num2str[4] = "IPX"
1048 _fam_num2str[5] = "APPLETALK"
1049 _fam_num2str[6] = "NETROM"
1050 _fam_num2str[7] = "BRIDGE"
1051 _fam_num2str[8] = "ATMPVC"
1052 _fam_num2str[9] = "X25"
1053 _fam_num2str[10] = "INET6"
1054 _fam_num2str[11] = "ROSE"
1055 _fam_num2str[12] = "DECNET"
1056 _fam_num2str[13] = "NETBEUI"
1057 _fam_num2str[14] = "SECURITY"
1058 _fam_num2str[15] = "KEY"
1059 _fam_num2str[16] = "NETLINK"
1060 _fam_num2str[17] = "PACKET"
1061 _fam_num2str[18] = "ASH"
1062 _fam_num2str[19] = "ECONET"
1063 _fam_num2str[20] = "ATMSVC"
1064 _fam_num2str[22] = "SNA"
1065 _fam_num2str[23] = "IRDA"
1066 _fam_num2str[24] = "PPPOX"
1067 _fam_num2str[25] = "WANPIPE"
1068 _fam_num2str[26] = "LLC"
1069 _fam_num2str[30] = "TIPC"
1070 _fam_num2str[31] = "BLUETOOTH"
1071 _fam_num2str[32] = "IUCV"
1072 _fam_num2str[33] = "RXRPC"
1073
1074 foreach (num in _fam_num2str)
1075 _fam_str2num[_fam_num2str[num]] = num
1076
1077 /* from include/linux/net.h */
1078 _state_num2str[0] = "FREE"
1079 _state_num2str[1] = "UNCONNECTED"
1080 _state_num2str[2] = "CONNECTING"
1081 _state_num2str[3] = "CONNECTED"
1082 _state_num2str[4] = "DISCONNECTING"
1083
1084 foreach (num in _state_num2str)
1085 _state_str2num[_state_num2str[num]] = num
1086
1087 /* from include/linux/net.h */
1088 _type_num2str[1] = "STREAM"
1089 _type_num2str[2] = "DGRAM"
1090 _type_num2str[3] = "RAW"
1091 _type_num2str[4] = "RDM"
1092 _type_num2str[5] = "SEQPACKET"
1093 _type_num2str[6] = "DCCP"
1094 _type_num2str[10] = "PACKET"
1095
1096 foreach (num in _type_num2str)
1097 _type_str2num[_type_num2str[num]] = num
1098 }
1099
1100 ######################
1101 # INTERNAL FUNCTIONS #
1102 ######################
1103
1104 @__private30 function _get_sock_addr:long(file:long)
1105 %{ /* pure */
1106 struct file *filep = (struct file *)(uintptr_t)(STAP_ARG_file);
1107 struct socket *sockp;
1108 if (filep) {
1109 #ifdef STAPCONF_DPATH_PATH
1110 struct dentry *dentry = kread(&(filep->f_path.dentry));
1111 #else
1112 struct dentry *dentry = kread(&(filep->f_dentry));
1113 #endif
1114 struct inode *inode = kread(&(dentry->d_inode));
1115 sockp = &container_of(inode, struct socket_alloc,
1116 vfs_inode)->socket;
1117 }
1118 else {
1119 sockp = NULL;
1120 }
1121 if (sockp == NULL)
1122 STAP_RETVALUE = -1;
1123 else
1124 STAP_RETVALUE = (long) sockp;
1125 CATCH_DEREF_FAULT();
1126 %}
1127
1128 @__private30 function _get_sock_size:long(iov:long, nr_segs:long)
1129 %{ /* pure */
1130 struct iovec *iovp = (struct iovec *)(uintptr_t)(STAP_ARG_iov);
1131 if (iovp == NULL)
1132 STAP_RETVALUE = -1;
1133 else {
1134 int i;
1135 STAP_RETVALUE = 0;
1136 for (i = 0 ; i < STAP_ARG_nr_segs ; i++)
1137 STAP_RETVALUE += kread(&(iovp[i].iov_len));
1138 }
1139 CATCH_DEREF_FAULT();
1140 %}
1141
1142 %( systemtap_v < "2.3" %?
1143 function _success_check:long(ret:long)
1144 {
1145 return @_sock_success_check(ret)
1146 }
1147
1148 function _sock_prot_num:long(sock:long)
1149 {
1150 return @_sock_prot_num(@cast(sock, "socket", "kernel"))
1151 }
1152
1153 function _sock_fam_num:long(sock:long)
1154 {
1155 return @_sock_fam_num(@cast(sock, "socket", "kernel"))
1156 }
1157
1158 function _sock_state_num:long(sock:long)
1159 {
1160 return @_sock_state_num(@cast(sock, "socket", "kernel"))
1161 }
1162
1163 function _sock_type_num:long(sock:long)
1164 {
1165 return @_sock_type_num(@cast(sock, "socket", "kernel"))
1166 }
1167
1168 function _sock_flags_num:long(sock:long)
1169 {
1170 return @_sock_flags_num(@cast(sock, "socket", "kernel"))
1171 }
1172 %)