您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

67 行
1.6KB

  1. #include "linux/kprobes.h"
  2. #include <linux/inet_diag.h>
  3. #include <net/tcp.h>
  4. /* Include the struct of the ROCCET congestion control algorithm. */
  5. #include "tcp_roccet.h"
  6. // Handler for the pre-call probe
  7. static int handler_pre(struct kprobe *p, struct pt_regs *regs)
  8. {
  9. /* System V ABI for x86_64 Linux:
  10. * arg0: di,
  11. * arg1: si,
  12. * arg2: dx,
  13. * ...
  14. */
  15. /* Get the first argument of the probed function */
  16. struct sock *sk = (struct sock *)regs->di;
  17. struct roccettcp *ca = inet_csk_ca(sk);
  18. u32 ack = (u32)regs->si;
  19. u32 acked = (u32)regs->dx;
  20. /* Use `trace_printk` to print debug information to the
  21. * `/sys/kernel/tracing/trace buffer`.
  22. * This buffer can be read using the debug trace interface of the kernel.
  23. */
  24. trace_printk(
  25. "roccettcp_cong_avoid: sk=%p ca=%p cnt=%u last_max_cwnd=%u, "
  26. "last_congestion_event=%u\n",
  27. sk, ca, ca->cnt, ca->last_max_cwnd,
  28. ca->roccet_last_event_time_us);
  29. trace_printk("ack: %u acked: %u\n", ack, acked);
  30. return 0;
  31. }
  32. static struct kprobe kp = {
  33. /* Define which function to probe. */
  34. .symbol_name = "roccettcp_cong_avoid",
  35. .pre_handler = handler_pre, /* Runs before the probed function. */
  36. .post_handler = NULL, /* Runs after the probed function. */
  37. };
  38. static int __init kprobe_init(void)
  39. {
  40. return register_kprobe(&kp);
  41. }
  42. static void __exit kprobe_exit(void)
  43. {
  44. unregister_kprobe(&kp);
  45. }
  46. module_init(kprobe_init);
  47. module_exit(kprobe_exit);
  48. MODULE_LICENSE("GPL");
  49. MODULE_DESCRIPTION("Makes it possible to probe the ROCCET Congestion "
  50. "Control Algrithm with kprobes. This enabled Debugging via a "
  51. "loadable kernel module.");
  52. MODULE_AUTHOR("Tim Füchsel");
  53. MODULE_VERSION("0.1");