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_sock_diag.c 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
  3. * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
  4. * Copyright (c) 2017-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.h"
  11. #include "netlink_sock_diag.h"
  12. #define XLAT_MACROS_ONLY
  13. #include "xlat/addrfams.h"
  14. #undef XLAT_MACROS_ONLY
  15. static void
  16. decode_family(struct tcb *const tcp, const uint8_t family,
  17. const kernel_ulong_t addr, const unsigned int len)
  18. {
  19. tprints("{family=");
  20. printxval(addrfams, family, "AF_???");
  21. if (len > sizeof(family)) {
  22. tprints(", ");
  23. printstr_ex(tcp, addr + sizeof(family),
  24. len - sizeof(family), QUOTE_FORCE_HEX);
  25. }
  26. tprints("}");
  27. }
  28. typedef DECL_NETLINK_DIAG_DECODER((*netlink_diag_decoder_t));
  29. static const struct {
  30. const netlink_diag_decoder_t request, response;
  31. } diag_decoders[] = {
  32. [AF_UNIX] = { decode_unix_diag_req, decode_unix_diag_msg },
  33. [AF_INET] = { decode_inet_diag_req, decode_inet_diag_msg },
  34. [AF_INET6] = { decode_inet_diag_req, decode_inet_diag_msg },
  35. [AF_NETLINK] = { decode_netlink_diag_req, decode_netlink_diag_msg },
  36. [AF_PACKET] = { decode_packet_diag_req, decode_packet_diag_msg },
  37. [AF_SMC] = { decode_smc_diag_req, decode_smc_diag_msg },
  38. };
  39. bool
  40. decode_netlink_sock_diag(struct tcb *const tcp,
  41. const struct nlmsghdr *const nlmsghdr,
  42. const kernel_ulong_t addr,
  43. const unsigned int len)
  44. {
  45. uint8_t family;
  46. if (nlmsghdr->nlmsg_type == NLMSG_DONE)
  47. return false;
  48. if (!umove_or_printaddr(tcp, addr, &family)) {
  49. if (family < ARRAY_SIZE(diag_decoders)
  50. && len > sizeof(family)) {
  51. const netlink_diag_decoder_t decoder =
  52. (nlmsghdr->nlmsg_flags & NLM_F_REQUEST)
  53. ? diag_decoders[family].request
  54. : diag_decoders[family].response;
  55. if (decoder) {
  56. decoder(tcp, nlmsghdr, family, addr, len);
  57. return true;
  58. }
  59. }
  60. decode_family(tcp, family, addr, len);
  61. }
  62. return true;
  63. }