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_route.c 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.h"
  11. #include "netlink_route.h"
  12. #include <linux/rtnetlink.h>
  13. #include "xlat/nl_route_types.h"
  14. static void
  15. decode_family(struct tcb *const tcp, const uint8_t family,
  16. const kernel_ulong_t addr, const unsigned int len)
  17. {
  18. tprints("{family=");
  19. printxval(addrfams, family, "AF_???");
  20. if (len > sizeof(family)) {
  21. tprints(", ");
  22. printstr_ex(tcp, addr + sizeof(family),
  23. len - sizeof(family), QUOTE_FORCE_HEX);
  24. }
  25. tprints("}");
  26. }
  27. typedef DECL_NETLINK_ROUTE_DECODER((*netlink_route_decoder_t));
  28. static const netlink_route_decoder_t route_decoders[] = {
  29. [RTM_DELLINK - RTM_BASE] = decode_ifinfomsg,
  30. [RTM_GETLINK - RTM_BASE] = decode_ifinfomsg,
  31. [RTM_NEWLINK - RTM_BASE] = decode_ifinfomsg,
  32. [RTM_SETLINK - RTM_BASE] = decode_ifinfomsg,
  33. [RTM_DELADDR - RTM_BASE] = decode_ifaddrmsg,
  34. [RTM_GETADDR - RTM_BASE] = decode_ifaddrmsg,
  35. [RTM_GETANYCAST - RTM_BASE] = decode_ifaddrmsg,
  36. [RTM_GETMULTICAST - RTM_BASE] = decode_ifaddrmsg,
  37. [RTM_NEWADDR - RTM_BASE] = decode_ifaddrmsg,
  38. [RTM_DELROUTE - RTM_BASE] = decode_rtmsg,
  39. [RTM_GETROUTE - RTM_BASE] = decode_rtmsg,
  40. [RTM_NEWROUTE - RTM_BASE] = decode_rtmsg,
  41. [RTM_DELRULE - RTM_BASE] = decode_fib_rule_hdr,
  42. [RTM_GETRULE - RTM_BASE] = decode_fib_rule_hdr,
  43. [RTM_NEWRULE - RTM_BASE] = decode_fib_rule_hdr,
  44. [RTM_DELNEIGH - RTM_BASE] = decode_ndmsg,
  45. [RTM_GETNEIGH - RTM_BASE] = decode_rtm_getneigh,
  46. [RTM_NEWNEIGH - RTM_BASE] = decode_ndmsg,
  47. [RTM_GETNEIGHTBL - RTM_BASE] = decode_ndtmsg,
  48. [RTM_NEWNEIGHTBL - RTM_BASE] = decode_ndtmsg,
  49. [RTM_SETNEIGHTBL - RTM_BASE] = decode_ndtmsg,
  50. [RTM_DELQDISC - RTM_BASE] = decode_tcmsg,
  51. [RTM_GETQDISC - RTM_BASE] = decode_tcmsg,
  52. [RTM_NEWQDISC - RTM_BASE] = decode_tcmsg,
  53. [RTM_DELTCLASS - RTM_BASE] = decode_tcmsg,
  54. [RTM_GETTCLASS - RTM_BASE] = decode_tcmsg,
  55. [RTM_NEWTCLASS - RTM_BASE] = decode_tcmsg,
  56. [RTM_DELTFILTER - RTM_BASE] = decode_tcmsg,
  57. [RTM_GETTFILTER - RTM_BASE] = decode_tcmsg,
  58. [RTM_NEWTFILTER - RTM_BASE] = decode_tcmsg,
  59. [RTM_DELACTION - RTM_BASE] = decode_tcamsg,
  60. [RTM_GETACTION - RTM_BASE] = decode_tcamsg,
  61. [RTM_NEWACTION - RTM_BASE] = decode_tcamsg,
  62. #ifdef HAVE_STRUCT_IFADDRLBLMSG
  63. [RTM_DELADDRLABEL - RTM_BASE] = decode_ifaddrlblmsg,
  64. [RTM_GETADDRLABEL - RTM_BASE] = decode_ifaddrlblmsg,
  65. [RTM_NEWADDRLABEL - RTM_BASE] = decode_ifaddrlblmsg,
  66. #endif
  67. #ifdef HAVE_STRUCT_DCBMSG
  68. [RTM_GETDCB - RTM_BASE] = decode_dcbmsg,
  69. [RTM_SETDCB - RTM_BASE] = decode_dcbmsg,
  70. #endif
  71. #ifdef HAVE_STRUCT_NETCONFMSG
  72. [RTM_DELNETCONF - RTM_BASE] = decode_netconfmsg,
  73. [RTM_GETNETCONF - RTM_BASE] = decode_netconfmsg,
  74. [RTM_NEWNETCONF - RTM_BASE] = decode_netconfmsg,
  75. #endif
  76. #ifdef HAVE_STRUCT_BR_PORT_MSG
  77. [RTM_DELMDB - RTM_BASE] = decode_br_port_msg,
  78. [RTM_GETMDB - RTM_BASE] = decode_br_port_msg,
  79. [RTM_NEWMDB - RTM_BASE] = decode_br_port_msg,
  80. #endif
  81. [RTM_DELNSID - RTM_BASE] = decode_rtgenmsg,
  82. [RTM_GETNSID - RTM_BASE] = decode_rtgenmsg,
  83. [RTM_NEWNSID - RTM_BASE] = decode_rtgenmsg
  84. };
  85. bool
  86. decode_netlink_route(struct tcb *const tcp,
  87. const struct nlmsghdr *const nlmsghdr,
  88. const kernel_ulong_t addr,
  89. const unsigned int len)
  90. {
  91. uint8_t family;
  92. if (nlmsghdr->nlmsg_type == NLMSG_DONE)
  93. return false;
  94. if (!umove_or_printaddr(tcp, addr, &family)) {
  95. const unsigned int index = nlmsghdr->nlmsg_type - RTM_BASE;
  96. if (index < ARRAY_SIZE(route_decoders)
  97. && route_decoders[index]) {
  98. route_decoders[index](tcp, nlmsghdr, family, addr, len);
  99. } else {
  100. decode_family(tcp, family, addr, len);
  101. }
  102. }
  103. return true;
  104. }