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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
  3. * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
  4. * Copyright (c) 2016-2018 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 "netlink.h"
  14. #include <linux/rtnetlink.h>
  15. #ifdef HAVE_LINUX_NEIGHBOUR_H
  16. # include <linux/neighbour.h>
  17. #endif
  18. #include "xlat/rtnl_neightbl_attrs.h"
  19. #include "xlat/rtnl_neightbl_parms_attrs.h"
  20. typedef struct {
  21. uint16_t ndtc_key_len;
  22. uint16_t ndtc_entry_size;
  23. uint32_t ndtc_entries;
  24. uint32_t ndtc_last_flush;
  25. uint32_t ndtc_last_rand;
  26. uint32_t ndtc_hash_rnd;
  27. uint32_t ndtc_hash_mask;
  28. uint32_t ndtc_hash_chain_gc;
  29. uint32_t ndtc_proxy_qlen;
  30. } struct_ndt_config;
  31. typedef struct {
  32. uint64_t ndts_allocs;
  33. uint64_t ndts_destroys;
  34. uint64_t ndts_hash_grows;
  35. uint64_t ndts_res_failed;
  36. uint64_t ndts_lookups;
  37. uint64_t ndts_hits;
  38. uint64_t ndts_rcv_probes_mcast;
  39. uint64_t ndts_rcv_probes_ucast;
  40. uint64_t ndts_periodic_gc_runs;
  41. uint64_t ndts_forced_gc_runs;
  42. uint64_t ndts_table_fulls; /**< Added by v4.3-rc1~96^2~202 */
  43. } struct_ndt_stats;
  44. # ifdef HAVE_STRUCT_NDT_CONFIG
  45. static_assert(sizeof(struct ndt_config) == sizeof(struct_ndt_config),
  46. "Unexpected struct ndt_config size, please update the decoder");
  47. # endif
  48. # ifdef HAVE_STRUCT_NDT_STATS
  49. static_assert(sizeof(struct ndt_stats) <= sizeof(struct_ndt_stats),
  50. "Unexpected struct ndt_stats size, please update the decoder");
  51. # endif
  52. static bool
  53. decode_ndt_config(struct tcb *const tcp,
  54. const kernel_ulong_t addr,
  55. const unsigned int len,
  56. const void *const opaque_data)
  57. {
  58. struct_ndt_config ndtc;
  59. if (len < sizeof(ndtc))
  60. return false;
  61. else if (!umove_or_printaddr(tcp, addr, &ndtc)) {
  62. PRINT_FIELD_U("{", ndtc, ndtc_key_len);
  63. PRINT_FIELD_U(", ", ndtc, ndtc_entry_size);
  64. PRINT_FIELD_U(", ", ndtc, ndtc_entries);
  65. PRINT_FIELD_U(", ", ndtc, ndtc_last_flush);
  66. PRINT_FIELD_U(", ", ndtc, ndtc_last_rand);
  67. PRINT_FIELD_U(", ", ndtc, ndtc_hash_rnd);
  68. PRINT_FIELD_0X(", ", ndtc, ndtc_hash_mask);
  69. PRINT_FIELD_U(", ", ndtc, ndtc_hash_chain_gc);
  70. PRINT_FIELD_U(", ", ndtc, ndtc_proxy_qlen);
  71. tprints("}");
  72. }
  73. return true;
  74. }
  75. static const nla_decoder_t ndt_parms_nla_decoders[] = {
  76. [NDTPA_IFINDEX] = decode_nla_ifindex,
  77. [NDTPA_REFCNT] = decode_nla_u32,
  78. [NDTPA_REACHABLE_TIME] = decode_nla_u64,
  79. [NDTPA_BASE_REACHABLE_TIME] = decode_nla_u64,
  80. [NDTPA_RETRANS_TIME] = decode_nla_u64,
  81. [NDTPA_GC_STALETIME] = decode_nla_u64,
  82. [NDTPA_DELAY_PROBE_TIME] = decode_nla_u64,
  83. [NDTPA_QUEUE_LEN] = decode_nla_u32,
  84. [NDTPA_APP_PROBES] = decode_nla_u32,
  85. [NDTPA_UCAST_PROBES] = decode_nla_u32,
  86. [NDTPA_MCAST_PROBES] = decode_nla_u32,
  87. [NDTPA_ANYCAST_DELAY] = decode_nla_u64,
  88. [NDTPA_PROXY_DELAY] = decode_nla_u64,
  89. [NDTPA_PROXY_QLEN] = decode_nla_u32,
  90. [NDTPA_LOCKTIME] = decode_nla_u64,
  91. [NDTPA_QUEUE_LENBYTES] = decode_nla_u32,
  92. [NDTPA_MCAST_REPROBES] = decode_nla_u32,
  93. [NDTPA_PAD] = NULL
  94. };
  95. static bool
  96. decode_ndta_parms(struct tcb *const tcp,
  97. const kernel_ulong_t addr,
  98. const unsigned int len,
  99. const void *const opaque_data)
  100. {
  101. decode_nlattr(tcp, addr, len, rtnl_neightbl_parms_attrs, "NDTPA_???",
  102. ndt_parms_nla_decoders,
  103. ARRAY_SIZE(ndt_parms_nla_decoders), opaque_data);
  104. return true;
  105. }
  106. static bool
  107. decode_ndt_stats(struct tcb *const tcp,
  108. const kernel_ulong_t addr,
  109. const unsigned int len,
  110. const void *const opaque_data)
  111. {
  112. struct_ndt_stats ndtst;
  113. const unsigned int min_size =
  114. offsetofend(struct ndt_stats, ndts_forced_gc_runs);
  115. const unsigned int def_size = sizeof(ndtst);
  116. const unsigned int size =
  117. (len >= def_size) ? def_size :
  118. ((len == min_size) ? min_size : 0);
  119. if (!size)
  120. return false;
  121. if (!umoven_or_printaddr(tcp, addr, size, &ndtst)) {
  122. PRINT_FIELD_U("{", ndtst, ndts_allocs);
  123. PRINT_FIELD_U(", ", ndtst, ndts_destroys);
  124. PRINT_FIELD_U(", ", ndtst, ndts_hash_grows);
  125. PRINT_FIELD_U(", ", ndtst, ndts_res_failed);
  126. PRINT_FIELD_U(", ", ndtst, ndts_lookups);
  127. PRINT_FIELD_U(", ", ndtst, ndts_hits);
  128. PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_mcast);
  129. PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_ucast);
  130. PRINT_FIELD_U(", ", ndtst, ndts_periodic_gc_runs);
  131. PRINT_FIELD_U(", ", ndtst, ndts_forced_gc_runs);
  132. if (len >= def_size)
  133. PRINT_FIELD_U(", ", ndtst, ndts_table_fulls);
  134. tprints("}");
  135. }
  136. return true;
  137. }
  138. static const nla_decoder_t ndtmsg_nla_decoders[] = {
  139. [NDTA_NAME] = decode_nla_str,
  140. [NDTA_THRESH1] = decode_nla_u32,
  141. [NDTA_THRESH2] = decode_nla_u32,
  142. [NDTA_THRESH3] = decode_nla_u32,
  143. [NDTA_CONFIG] = decode_ndt_config,
  144. [NDTA_PARMS] = decode_ndta_parms,
  145. [NDTA_STATS] = decode_ndt_stats,
  146. [NDTA_GC_INTERVAL] = decode_nla_u64,
  147. [NDTA_PAD] = NULL,
  148. };
  149. DECL_NETLINK_ROUTE_DECODER(decode_ndtmsg)
  150. {
  151. struct ndtmsg ndtmsg = { .ndtm_family = family };
  152. PRINT_FIELD_XVAL("{", ndtmsg, ndtm_family, addrfams, "AF_???");
  153. tprints("}");
  154. const size_t offset = NLMSG_ALIGN(sizeof(ndtmsg));
  155. if (len > offset) {
  156. tprints(", ");
  157. decode_nlattr(tcp, addr + offset, len - offset,
  158. rtnl_neightbl_attrs, "NDTA_???",
  159. ndtmsg_nla_decoders,
  160. ARRAY_SIZE(ndtmsg_nla_decoders), NULL);
  161. }
  162. }