Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rtnl_neightbl.c 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
  3. * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
  4. * Copyright (c) 2016-2020 The strace developers.
  5. * All rights reserved.
  6. *
  7. * SPDX-License-Identifier: LGPL-2.1-or-later
  8. */
  9. #include "defs.h"
  10. #include "netlink_route.h"
  11. #include "nlattr.h"
  12. #include "print_fields.h"
  13. #include "types/rtnl_neightbl.h"
  14. #include "xlat/rtnl_neightbl_attrs.h"
  15. #include "xlat/rtnl_neightbl_parms_attrs.h"
  16. static bool
  17. decode_ndt_config(struct tcb *const tcp,
  18. const kernel_ulong_t addr,
  19. const unsigned int len,
  20. const void *const opaque_data)
  21. {
  22. struct_ndt_config ndtc;
  23. if (len < sizeof(ndtc))
  24. return false;
  25. else if (!umove_or_printaddr(tcp, addr, &ndtc)) {
  26. PRINT_FIELD_U("{", ndtc, ndtc_key_len);
  27. PRINT_FIELD_U(", ", ndtc, ndtc_entry_size);
  28. PRINT_FIELD_U(", ", ndtc, ndtc_entries);
  29. PRINT_FIELD_U(", ", ndtc, ndtc_last_flush);
  30. PRINT_FIELD_U(", ", ndtc, ndtc_last_rand);
  31. PRINT_FIELD_U(", ", ndtc, ndtc_hash_rnd);
  32. PRINT_FIELD_0X(", ", ndtc, ndtc_hash_mask);
  33. PRINT_FIELD_U(", ", ndtc, ndtc_hash_chain_gc);
  34. PRINT_FIELD_U(", ", ndtc, ndtc_proxy_qlen);
  35. tprints("}");
  36. }
  37. return true;
  38. }
  39. static const nla_decoder_t ndt_parms_nla_decoders[] = {
  40. [NDTPA_IFINDEX] = decode_nla_ifindex,
  41. [NDTPA_REFCNT] = decode_nla_u32,
  42. [NDTPA_REACHABLE_TIME] = decode_nla_u64,
  43. [NDTPA_BASE_REACHABLE_TIME] = decode_nla_u64,
  44. [NDTPA_RETRANS_TIME] = decode_nla_u64,
  45. [NDTPA_GC_STALETIME] = decode_nla_u64,
  46. [NDTPA_DELAY_PROBE_TIME] = decode_nla_u64,
  47. [NDTPA_QUEUE_LEN] = decode_nla_u32,
  48. [NDTPA_APP_PROBES] = decode_nla_u32,
  49. [NDTPA_UCAST_PROBES] = decode_nla_u32,
  50. [NDTPA_MCAST_PROBES] = decode_nla_u32,
  51. [NDTPA_ANYCAST_DELAY] = decode_nla_u64,
  52. [NDTPA_PROXY_DELAY] = decode_nla_u64,
  53. [NDTPA_PROXY_QLEN] = decode_nla_u32,
  54. [NDTPA_LOCKTIME] = decode_nla_u64,
  55. [NDTPA_QUEUE_LENBYTES] = decode_nla_u32,
  56. [NDTPA_MCAST_REPROBES] = decode_nla_u32,
  57. [NDTPA_PAD] = NULL
  58. };
  59. static bool
  60. decode_ndta_parms(struct tcb *const tcp,
  61. const kernel_ulong_t addr,
  62. const unsigned int len,
  63. const void *const opaque_data)
  64. {
  65. decode_nlattr(tcp, addr, len, rtnl_neightbl_parms_attrs, "NDTPA_???",
  66. ndt_parms_nla_decoders,
  67. ARRAY_SIZE(ndt_parms_nla_decoders), opaque_data);
  68. return true;
  69. }
  70. static bool
  71. decode_ndt_stats(struct tcb *const tcp,
  72. const kernel_ulong_t addr,
  73. const unsigned int len,
  74. const void *const opaque_data)
  75. {
  76. struct_ndt_stats ndtst;
  77. const unsigned int min_size =
  78. offsetofend(struct ndt_stats, ndts_forced_gc_runs);
  79. const unsigned int def_size = sizeof(ndtst);
  80. const unsigned int size =
  81. (len >= def_size) ? def_size :
  82. ((len == min_size) ? min_size : 0);
  83. if (!size)
  84. return false;
  85. if (!umoven_or_printaddr(tcp, addr, size, &ndtst)) {
  86. PRINT_FIELD_U("{", ndtst, ndts_allocs);
  87. PRINT_FIELD_U(", ", ndtst, ndts_destroys);
  88. PRINT_FIELD_U(", ", ndtst, ndts_hash_grows);
  89. PRINT_FIELD_U(", ", ndtst, ndts_res_failed);
  90. PRINT_FIELD_U(", ", ndtst, ndts_lookups);
  91. PRINT_FIELD_U(", ", ndtst, ndts_hits);
  92. PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_mcast);
  93. PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_ucast);
  94. PRINT_FIELD_U(", ", ndtst, ndts_periodic_gc_runs);
  95. PRINT_FIELD_U(", ", ndtst, ndts_forced_gc_runs);
  96. if (len >= def_size)
  97. PRINT_FIELD_U(", ", ndtst, ndts_table_fulls);
  98. tprints("}");
  99. }
  100. return true;
  101. }
  102. static const nla_decoder_t ndtmsg_nla_decoders[] = {
  103. [NDTA_NAME] = decode_nla_str,
  104. [NDTA_THRESH1] = decode_nla_u32,
  105. [NDTA_THRESH2] = decode_nla_u32,
  106. [NDTA_THRESH3] = decode_nla_u32,
  107. [NDTA_CONFIG] = decode_ndt_config,
  108. [NDTA_PARMS] = decode_ndta_parms,
  109. [NDTA_STATS] = decode_ndt_stats,
  110. [NDTA_GC_INTERVAL] = decode_nla_u64,
  111. [NDTA_PAD] = NULL,
  112. };
  113. DECL_NETLINK_ROUTE_DECODER(decode_ndtmsg)
  114. {
  115. struct ndtmsg ndtmsg = { .ndtm_family = family };
  116. PRINT_FIELD_XVAL("{", ndtmsg, ndtm_family, addrfams, "AF_???");
  117. tprints("}");
  118. const size_t offset = NLMSG_ALIGN(sizeof(ndtmsg));
  119. if (len > offset) {
  120. tprints(", ");
  121. decode_nlattr(tcp, addr + offset, len - offset,
  122. rtnl_neightbl_attrs, "NDTA_???",
  123. ndtmsg_nla_decoders,
  124. ARRAY_SIZE(ndtmsg_nla_decoders), NULL);
  125. }
  126. }