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_mdb.c 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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_mdb.h"
  14. #include "netlink.h"
  15. #include "xlat/mdb_flags.h"
  16. #include "xlat/mdb_states.h"
  17. #include "xlat/multicast_router_types.h"
  18. #include "xlat/rtnl_mdb_attrs.h"
  19. #include "xlat/rtnl_mdba_mdb_attrs.h"
  20. #include "xlat/rtnl_mdba_mdb_eattr_attrs.h"
  21. #include "xlat/rtnl_mdba_mdb_entry_attrs.h"
  22. #include "xlat/rtnl_mdba_router_attrs.h"
  23. #include "xlat/rtnl_mdba_router_pattr_attrs.h"
  24. static const nla_decoder_t mdba_mdb_eattr_nla_decoders[] = {
  25. [MDBA_MDB_EATTR_TIMER] = decode_nla_u32
  26. };
  27. static bool
  28. decode_mdba_mdb_entry_info(struct tcb *const tcp,
  29. const kernel_ulong_t addr,
  30. const unsigned int len,
  31. const void *const opaque_data)
  32. {
  33. struct_br_mdb_entry entry;
  34. if (len < sizeof(entry))
  35. return false;
  36. else if (!umove_or_printaddr(tcp, addr, &entry)) {
  37. PRINT_FIELD_IFINDEX("{", entry, ifindex);
  38. PRINT_FIELD_XVAL(", ", entry, state, mdb_states, "MDB_???");
  39. /*
  40. * Note that it's impossible to derive if flags/vid fields
  41. * are present on all architectures except m68k; as a side note,
  42. * v4.3-rc1~96^2~365 has introduced an ABI breakage on m68k.
  43. */
  44. PRINT_FIELD_FLAGS(", ", entry, flags,
  45. mdb_flags, "MDB_FLAGS_???");
  46. PRINT_FIELD_U(", ", entry, vid);
  47. const int proto = ntohs(entry.addr.proto);
  48. tprints(", addr={");
  49. print_inet_addr(proto, &entry.addr.u,
  50. sizeof(entry.addr.u), "u");
  51. tprints(", proto=htons(");
  52. printxval(addrfams, proto, "AF_???");
  53. tprints(")}}");
  54. }
  55. const size_t offset = NLMSG_ALIGN(sizeof(entry));
  56. if (len > offset) {
  57. tprints(", ");
  58. decode_nlattr(tcp, addr + offset, len - offset,
  59. rtnl_mdba_mdb_eattr_attrs, "MDBA_MDB_EATTR_???",
  60. mdba_mdb_eattr_nla_decoders,
  61. ARRAY_SIZE(mdba_mdb_eattr_nla_decoders), NULL);
  62. }
  63. return true;
  64. }
  65. static const nla_decoder_t mdba_mdb_entry_nla_decoders[] = {
  66. [MDBA_MDB_ENTRY_INFO] = decode_mdba_mdb_entry_info
  67. };
  68. static bool
  69. decode_mdba_mdb_entry(struct tcb *const tcp,
  70. const kernel_ulong_t addr,
  71. const unsigned int len,
  72. const void *const opaque_data)
  73. {
  74. decode_nlattr(tcp, addr, len, rtnl_mdba_mdb_entry_attrs,
  75. "MDBA_MDB_ENTRY_???", mdba_mdb_entry_nla_decoders,
  76. ARRAY_SIZE(mdba_mdb_entry_nla_decoders), NULL);
  77. return true;
  78. }
  79. static const nla_decoder_t mdba_mdb_nla_decoders[] = {
  80. [MDBA_MDB_ENTRY] = decode_mdba_mdb_entry
  81. };
  82. static bool
  83. decode_mdba_mdb(struct tcb *const tcp,
  84. const kernel_ulong_t addr,
  85. const unsigned int len,
  86. const void *const opaque_data)
  87. {
  88. decode_nlattr(tcp, addr, len, rtnl_mdba_mdb_attrs, "MDBA_MDB_???",
  89. mdba_mdb_nla_decoders,
  90. ARRAY_SIZE(mdba_mdb_nla_decoders), NULL);
  91. return true;
  92. }
  93. static bool
  94. decode_multicast_router_type(struct tcb *const tcp,
  95. const kernel_ulong_t addr,
  96. const unsigned int len,
  97. const void *const opaque_data)
  98. {
  99. uint8_t type;
  100. if (!umove_or_printaddr(tcp, addr, &type))
  101. printxval(multicast_router_types, type, "MDB_RTR_TYPE_???");
  102. return true;
  103. }
  104. static const nla_decoder_t mdba_router_pattr_nla_decoders[] = {
  105. [MDBA_ROUTER_PATTR_TIMER] = decode_nla_u32,
  106. [MDBA_ROUTER_PATTR_TYPE] = decode_multicast_router_type
  107. };
  108. static bool
  109. decode_mdba_router_port(struct tcb *const tcp,
  110. const kernel_ulong_t addr,
  111. const unsigned int len,
  112. const void *const opaque_data)
  113. {
  114. uint32_t ifindex;
  115. if (len < sizeof(ifindex))
  116. return false;
  117. else if (!umove_or_printaddr(tcp, addr, &ifindex))
  118. print_ifindex(ifindex);
  119. const size_t offset = NLMSG_ALIGN(sizeof(ifindex));
  120. if (len > offset) {
  121. tprints(", ");
  122. decode_nlattr(tcp, addr + offset, len - offset,
  123. rtnl_mdba_router_pattr_attrs,
  124. "MDBA_ROUTER_PATTR_???",
  125. mdba_router_pattr_nla_decoders,
  126. ARRAY_SIZE(mdba_router_pattr_nla_decoders), NULL);
  127. }
  128. return true;
  129. }
  130. static const nla_decoder_t mdba_router_nla_decoders[] = {
  131. [MDBA_ROUTER_PORT] = decode_mdba_router_port
  132. };
  133. static bool
  134. decode_mdba_router(struct tcb *const tcp,
  135. const kernel_ulong_t addr,
  136. const unsigned int len,
  137. const void *const opaque_data)
  138. {
  139. decode_nlattr(tcp, addr, len, rtnl_mdba_router_attrs, "MDBA_ROUTER_???",
  140. mdba_router_nla_decoders,
  141. ARRAY_SIZE(mdba_router_nla_decoders), NULL);
  142. return true;
  143. }
  144. static const nla_decoder_t br_port_msg_nla_decoders[] = {
  145. [MDBA_MDB] = decode_mdba_mdb,
  146. [MDBA_ROUTER] = decode_mdba_router
  147. };
  148. DECL_NETLINK_ROUTE_DECODER(decode_br_port_msg)
  149. {
  150. struct_br_port_msg bpm = { .family = family };
  151. size_t offset = sizeof(bpm.family);
  152. bool decode_nla = false;
  153. PRINT_FIELD_XVAL("{", bpm, family, addrfams, "AF_???");
  154. tprints(", ");
  155. if (len >= sizeof(bpm)) {
  156. if (!umoven_or_printaddr(tcp, addr + offset,
  157. sizeof(bpm) - offset,
  158. (char *) &bpm + offset)) {
  159. PRINT_FIELD_IFINDEX("", bpm, ifindex);
  160. decode_nla = true;
  161. }
  162. } else
  163. tprints("...");
  164. tprints("}");
  165. offset = NLMSG_ALIGN(sizeof(bpm));
  166. if (decode_nla && len > offset) {
  167. tprints(", ");
  168. decode_nlattr(tcp, addr + offset, len - offset,
  169. rtnl_mdb_attrs, "MDBA_???",
  170. br_port_msg_nla_decoders,
  171. ARRAY_SIZE(br_port_msg_nla_decoders), NULL);
  172. }
  173. }