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.

netlink_smc_diag.c 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
  3. * Copyright (c) 2017-2018 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #include "defs.h"
  9. #include <sys/socket.h>
  10. #ifndef AF_SMC
  11. # define XLAT_MACROS_ONLY
  12. # include "xlat/addrfams.h"
  13. # undef XLAT_MACROS_ONLY
  14. #endif
  15. #include "netlink.h"
  16. #include "netlink_sock_diag.h"
  17. #include "nlattr.h"
  18. #include "print_fields.h"
  19. #include <arpa/inet.h>
  20. #include <linux/smc_diag.h>
  21. #include "xlat/smc_decl_codes.h"
  22. #include "xlat/smc_diag_attrs.h"
  23. #include "xlat/smc_diag_extended_flags.h"
  24. #include "xlat/smc_diag_mode.h"
  25. #include "xlat/smc_link_group_roles.h"
  26. #include "xlat/smc_states.h"
  27. #include "xlat/sock_shutdown_flags.h"
  28. DECL_NETLINK_DIAG_DECODER(decode_smc_diag_req)
  29. {
  30. struct smc_diag_req req = { .diag_family = family };
  31. const size_t offset = sizeof(req.diag_family);
  32. PRINT_FIELD_XVAL("{", req, diag_family, addrfams, "AF_???");
  33. tprints(", ");
  34. if (len >= sizeof(req)) {
  35. if (!umoven_or_printaddr(tcp, addr + offset,
  36. sizeof(req) - offset,
  37. (void *) &req + offset)) {
  38. PRINT_FIELD_FLAGS("", req, diag_ext,
  39. smc_diag_extended_flags,
  40. "1<<SMC_DIAG_\?\?\?-1");
  41. /*
  42. * AF_SMC protocol family socket handler
  43. * keeping the AF_INET sock address.
  44. */
  45. PRINT_FIELD_INET_DIAG_SOCKID(", ", req, id, AF_INET);
  46. }
  47. } else
  48. tprints("...");
  49. tprints("}");
  50. }
  51. static void
  52. print_smc_diag_cursor(const struct smc_diag_cursor *const cursor)
  53. {
  54. PRINT_FIELD_U("{", *cursor, reserved);
  55. PRINT_FIELD_U(", ", *cursor, wrap);
  56. PRINT_FIELD_U(", ", *cursor, count);
  57. tprints("}");
  58. }
  59. #define PRINT_FIELD_SMC_DIAG_CURSOR(prefix_, where_, field_) \
  60. do { \
  61. tprintf("%s%s=", (prefix_), #field_); \
  62. print_smc_diag_cursor(&(where_).field_); \
  63. } while (0)
  64. static bool
  65. decode_smc_diag_conninfo(struct tcb *const tcp,
  66. const kernel_ulong_t addr,
  67. const unsigned int len,
  68. const void *const opaque_data)
  69. {
  70. struct smc_diag_conninfo cinfo;
  71. if (len < sizeof(cinfo))
  72. return false;
  73. if (umove_or_printaddr(tcp, addr, &cinfo))
  74. return true;
  75. PRINT_FIELD_U("{", cinfo, token);
  76. PRINT_FIELD_U(", ", cinfo, sndbuf_size);
  77. PRINT_FIELD_U(", ", cinfo, rmbe_size);
  78. PRINT_FIELD_U(", ", cinfo, peer_rmbe_size);
  79. PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, rx_prod);
  80. PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, rx_cons);
  81. PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_prod);
  82. PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_cons);
  83. PRINT_FIELD_0X(", ", cinfo, rx_prod_flags);
  84. PRINT_FIELD_0X(", ", cinfo, rx_conn_state_flags);
  85. PRINT_FIELD_0X(", ", cinfo, tx_prod_flags);
  86. PRINT_FIELD_0X(", ", cinfo, tx_conn_state_flags);
  87. PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_prep);
  88. PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_sent);
  89. PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_fin);
  90. tprints("}");
  91. return true;
  92. }
  93. static bool
  94. decode_smc_diag_lgrinfo(struct tcb *const tcp,
  95. const kernel_ulong_t addr,
  96. const unsigned int len,
  97. const void *const opaque_data)
  98. {
  99. struct smc_diag_lgrinfo linfo;
  100. if (len < sizeof(linfo))
  101. return false;
  102. if (umove_or_printaddr(tcp, addr, &linfo))
  103. return true;
  104. tprints("{lnk[0]={");
  105. PRINT_FIELD_U("", linfo.lnk[0], link_id);
  106. PRINT_FIELD_CSTRING(", ", linfo.lnk[0], ibname);
  107. PRINT_FIELD_U(", ", linfo.lnk[0], ibport);
  108. PRINT_FIELD_CSTRING(", ", linfo.lnk[0], gid);
  109. PRINT_FIELD_CSTRING(", ", linfo.lnk[0], peer_gid);
  110. PRINT_FIELD_XVAL("}, ", linfo, role, smc_link_group_roles, "SMC_???");
  111. tprints("}");
  112. return true;
  113. }
  114. static bool
  115. decode_smc_diag_shutdown(struct tcb *const tcp,
  116. const kernel_ulong_t addr,
  117. const unsigned int len,
  118. const void *const opaque_data)
  119. {
  120. const struct decode_nla_xlat_opts opts = {
  121. sock_shutdown_flags, "???_SHUTDOWN",
  122. .size = 1,
  123. };
  124. return decode_nla_flags(tcp, addr, len, &opts);
  125. }
  126. static bool
  127. decode_smc_diag_dmbinfo(struct tcb *const tcp,
  128. const kernel_ulong_t addr,
  129. const unsigned int len,
  130. const void *const opaque_data)
  131. {
  132. struct smcd_diag_dmbinfo dinfo;
  133. if (len < sizeof(dinfo))
  134. return false;
  135. if (umove_or_printaddr(tcp, addr, &dinfo))
  136. return true;
  137. PRINT_FIELD_U("{", dinfo, linkid);
  138. PRINT_FIELD_X(", ", dinfo, peer_gid);
  139. PRINT_FIELD_X(", ", dinfo, my_gid);
  140. PRINT_FIELD_X(", ", dinfo, token);
  141. PRINT_FIELD_X(", ", dinfo, peer_token);
  142. tprints("}");
  143. return true;
  144. }
  145. static bool
  146. decode_smc_diag_fallback(struct tcb *const tcp,
  147. const kernel_ulong_t addr,
  148. const unsigned int len,
  149. const void *const opaque_data)
  150. {
  151. struct smc_diag_fallback fb;
  152. if (len < sizeof(fb))
  153. return false;
  154. if (umove_or_printaddr(tcp, addr, &fb))
  155. return true;
  156. /*
  157. * We print them verbose since they are defined in a non-UAPI header,
  158. * net/smc/smc_clc.h
  159. */
  160. tprints("{reason=");
  161. printxval_ex(smc_decl_codes, fb.reason, "SMC_CLC_DECL_???",
  162. XLAT_STYLE_VERBOSE);
  163. tprints(", peer_diagnosis=");
  164. printxval_ex(smc_decl_codes, fb.peer_diagnosis, "SMC_CLC_DECL_???",
  165. XLAT_STYLE_VERBOSE);
  166. tprints("}");
  167. return true;
  168. }
  169. static const nla_decoder_t smc_diag_msg_nla_decoders[] = {
  170. [SMC_DIAG_CONNINFO] = decode_smc_diag_conninfo,
  171. [SMC_DIAG_LGRINFO] = decode_smc_diag_lgrinfo,
  172. [SMC_DIAG_SHUTDOWN] = decode_smc_diag_shutdown,
  173. [SMC_DIAG_DMBINFO] = decode_smc_diag_dmbinfo,
  174. [SMC_DIAG_FALLBACK] = decode_smc_diag_fallback,
  175. };
  176. DECL_NETLINK_DIAG_DECODER(decode_smc_diag_msg)
  177. {
  178. struct smc_diag_msg msg = { .diag_family = family };
  179. size_t offset = sizeof(msg.diag_family);
  180. bool decode_nla = false;
  181. PRINT_FIELD_XVAL("{", msg, diag_family, addrfams, "AF_???");
  182. tprints(", ");
  183. if (len >= sizeof(msg)) {
  184. if (!umoven_or_printaddr(tcp, addr + offset,
  185. sizeof(msg) - offset,
  186. (void *) &msg + offset)) {
  187. PRINT_FIELD_XVAL("", msg, diag_state,
  188. smc_states, "SMC_???");
  189. PRINT_FIELD_XVAL(", ", msg, diag_fallback,
  190. smc_diag_mode, "SMC_DIAG_MODE_???");
  191. PRINT_FIELD_U(", ", msg, diag_shutdown);
  192. /*
  193. * AF_SMC protocol family socket handler
  194. * keeping the AF_INET sock address.
  195. */
  196. PRINT_FIELD_INET_DIAG_SOCKID(", ", msg, id, AF_INET);
  197. PRINT_FIELD_U(", ", msg, diag_uid);
  198. PRINT_FIELD_U(", ", msg, diag_inode);
  199. decode_nla = true;
  200. }
  201. } else
  202. tprints("...");
  203. tprints("}");
  204. offset = NLMSG_ALIGN(sizeof(msg));
  205. if (decode_nla && len > offset) {
  206. tprints(", ");
  207. decode_nlattr(tcp, addr + offset, len - offset,
  208. smc_diag_attrs, "SMC_DIAG_???",
  209. smc_diag_msg_nla_decoders,
  210. ARRAY_SIZE(smc_diag_msg_nla_decoders), NULL);
  211. }
  212. }