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_neigh.c 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include "netlink_route.h"
  11. #include "nlattr.h"
  12. #include "print_fields.h"
  13. #include "netlink.h"
  14. #include <linux/rtnetlink.h>
  15. #ifdef HAVE_LINUX_NEIGHBOUR_H
  16. # include <linux/neighbour.h>
  17. #endif
  18. #include "xlat/neighbor_cache_entry_flags.h"
  19. #include "xlat/neighbor_cache_entry_states.h"
  20. #include "xlat/rtnl_neigh_attrs.h"
  21. static bool
  22. decode_neigh_addr(struct tcb *const tcp,
  23. const kernel_ulong_t addr,
  24. const unsigned int len,
  25. const void *const opaque_data)
  26. {
  27. const struct ndmsg *const ndmsg = opaque_data;
  28. decode_inet_addr(tcp, addr, len, ndmsg->ndm_family, NULL);
  29. return true;
  30. }
  31. static bool
  32. decode_nda_cacheinfo(struct tcb *const tcp,
  33. const kernel_ulong_t addr,
  34. const unsigned int len,
  35. const void *const opaque_data)
  36. {
  37. struct nda_cacheinfo ci;
  38. if (len < sizeof(ci))
  39. return false;
  40. else if (!umove_or_printaddr(tcp, addr, &ci)) {
  41. PRINT_FIELD_U("{", ci, ndm_confirmed);
  42. PRINT_FIELD_U(", ", ci, ndm_used);
  43. PRINT_FIELD_U(", ", ci, ndm_updated);
  44. PRINT_FIELD_U(", ", ci, ndm_refcnt);
  45. tprints("}");
  46. }
  47. return true;
  48. }
  49. static const nla_decoder_t ndmsg_nla_decoders[] = {
  50. [NDA_DST] = decode_neigh_addr,
  51. [NDA_LLADDR] = decode_neigh_addr,
  52. [NDA_CACHEINFO] = decode_nda_cacheinfo,
  53. [NDA_PROBES] = decode_nla_u32,
  54. [NDA_VLAN] = decode_nla_u16,
  55. [NDA_PORT] = decode_nla_be16,
  56. [NDA_VNI] = decode_nla_u32,
  57. [NDA_IFINDEX] = decode_nla_ifindex,
  58. [NDA_MASTER] = decode_nla_ifindex,
  59. [NDA_LINK_NETNSID] = decode_nla_u32,
  60. [NDA_SRC_VNI] = NULL,
  61. [NDA_PROTOCOL] = decode_nla_u8,
  62. };
  63. DECL_NETLINK_ROUTE_DECODER(decode_ndmsg)
  64. {
  65. struct ndmsg ndmsg = { .ndm_family = family };
  66. size_t offset = sizeof(ndmsg.ndm_family);
  67. bool decode_nla = false;
  68. PRINT_FIELD_XVAL("{", ndmsg, ndm_family, addrfams, "AF_???");
  69. tprints(", ");
  70. if (len >= sizeof(ndmsg)) {
  71. if (!umoven_or_printaddr(tcp, addr + offset,
  72. sizeof(ndmsg) - offset,
  73. (char *) &ndmsg + offset)) {
  74. PRINT_FIELD_IFINDEX("", ndmsg, ndm_ifindex);
  75. PRINT_FIELD_FLAGS(", ", ndmsg, ndm_state,
  76. neighbor_cache_entry_states,
  77. "NUD_???");
  78. PRINT_FIELD_FLAGS(", ", ndmsg, ndm_flags,
  79. neighbor_cache_entry_flags,
  80. "NTF_???");
  81. PRINT_FIELD_XVAL(", ", ndmsg, ndm_type,
  82. routing_types, "RTN_???");
  83. decode_nla = true;
  84. }
  85. } else
  86. tprints("...");
  87. tprints("}");
  88. offset = NLMSG_ALIGN(sizeof(ndmsg));
  89. if (decode_nla && len > offset) {
  90. tprints(", ");
  91. decode_nlattr(tcp, addr + offset, len - offset,
  92. rtnl_neigh_attrs, "NDA_???",
  93. ndmsg_nla_decoders,
  94. ARRAY_SIZE(ndmsg_nla_decoders), &ndmsg);
  95. }
  96. }
  97. DECL_NETLINK_ROUTE_DECODER(decode_rtm_getneigh)
  98. {
  99. if (family == AF_BRIDGE)
  100. decode_ifinfomsg(tcp, nlmsghdr, family, addr, len);
  101. else
  102. decode_ndmsg(tcp, nlmsghdr, family, addr, len);
  103. }