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_netfilter.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2018 Chen Jingpiao <chenjingpiao@gmail.com>
  3. * Copyright (c) 2018 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #include "defs.h"
  9. #ifdef HAVE_LINUX_NETFILTER_NFNETLINK_H
  10. # include "print_fields.h"
  11. # include "nlattr.h"
  12. # include <netinet/in.h>
  13. # include <arpa/inet.h>
  14. # include "netlink.h"
  15. # include <linux/netfilter/nfnetlink.h>
  16. # include "xlat/netfilter_versions.h"
  17. # include "xlat/nl_netfilter_msg_types.h"
  18. # include "xlat/nl_netfilter_subsys_ids.h"
  19. bool
  20. decode_netlink_netfilter(struct tcb *const tcp,
  21. const struct nlmsghdr *const nlmsghdr,
  22. const kernel_ulong_t addr,
  23. const unsigned int len)
  24. {
  25. if (nlmsghdr->nlmsg_type == NLMSG_DONE)
  26. return false;
  27. struct nfgenmsg nfmsg;
  28. if (len < sizeof(nfmsg))
  29. printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
  30. else if (!umove_or_printaddr(tcp, addr, &nfmsg)) {
  31. const uint8_t subsys_id = (uint8_t) (nlmsghdr->nlmsg_type >> 8);
  32. uint16_t res_id = ntohs(nfmsg.res_id);
  33. PRINT_FIELD_XVAL("{", nfmsg, nfgen_family, addrfams, "AF_???");
  34. PRINT_FIELD_XVAL(", ", nfmsg, version, netfilter_versions,
  35. "NFNETLINK_???");
  36. /*
  37. * Work around wrong endianness in res_id field,
  38. * see linux commit v4.3-rc1~28^2~47^2~1
  39. */
  40. tprints(", res_id=");
  41. if (subsys_id == NFNL_SUBSYS_NFTABLES
  42. && res_id == NFNL_SUBSYS_NFTABLES) {
  43. print_xlat_ex(nfmsg.res_id,
  44. "htons(NFNL_SUBSYS_NFTABLES)",
  45. XLAT_STYLE_DEFAULT);
  46. } else if (subsys_id == NFNL_SUBSYS_NFTABLES
  47. && nfmsg.res_id == NFNL_SUBSYS_NFTABLES) {
  48. print_xlat_ex(nfmsg.res_id, "NFNL_SUBSYS_NFTABLES",
  49. XLAT_STYLE_DEFAULT);
  50. } else {
  51. tprintf("htons(%d)", res_id);
  52. }
  53. const size_t offset = NLMSG_ALIGN(sizeof(nfmsg));
  54. if (len > offset) {
  55. tprints(", ");
  56. if ((nlmsghdr->nlmsg_type >= NFNL_MSG_BATCH_BEGIN
  57. && nlmsghdr->nlmsg_type <= NFNL_MSG_BATCH_END)
  58. || nlmsghdr->nlmsg_type < NLMSG_MIN_TYPE)
  59. printstr_ex(tcp, addr + offset,
  60. len - offset, QUOTE_FORCE_HEX);
  61. else
  62. decode_nlattr(tcp, addr + offset, len - offset,
  63. NULL, NULL, NULL, 0, NULL);
  64. }
  65. }
  66. return true;
  67. }
  68. #endif /* HAVE_LINUX_NETFILTER_NFNETLINK_H */