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.4KB

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