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_addr.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "defs.h"
  30. #include "netlink_route.h"
  31. #include "nlattr.h"
  32. #include "print_fields.h"
  33. #include "netlink.h"
  34. #include <linux/rtnetlink.h>
  35. #ifdef HAVE_LINUX_IF_ADDR_H
  36. # include <linux/if_addr.h>
  37. #endif
  38. #include "xlat/ifaddrflags.h"
  39. #include "xlat/routing_scopes.h"
  40. #include "xlat/rtnl_addr_attrs.h"
  41. static bool
  42. decode_ifa_address(struct tcb *const tcp,
  43. const kernel_ulong_t addr,
  44. const unsigned int len,
  45. const void *const opaque_data)
  46. {
  47. const struct ifaddrmsg *const ifaddr = opaque_data;
  48. decode_inet_addr(tcp, addr, len, ifaddr->ifa_family, NULL);
  49. return true;
  50. }
  51. static bool
  52. decode_ifa_cacheinfo(struct tcb *const tcp,
  53. const kernel_ulong_t addr,
  54. const unsigned int len,
  55. const void *const opaque_data)
  56. {
  57. struct ifa_cacheinfo ci;
  58. if (len < sizeof(ci))
  59. return false;
  60. else if (!umove_or_printaddr(tcp, addr, &ci)) {
  61. PRINT_FIELD_U("{", ci, ifa_prefered);
  62. PRINT_FIELD_U(", ", ci, ifa_valid);
  63. PRINT_FIELD_U(", ", ci, cstamp);
  64. PRINT_FIELD_U(", ", ci, tstamp);
  65. tprintf("}");
  66. }
  67. return true;
  68. }
  69. static bool
  70. decode_ifa_flags(struct tcb *const tcp,
  71. const kernel_ulong_t addr,
  72. const unsigned int len,
  73. const void *const opaque_data)
  74. {
  75. uint32_t ifa_flags;
  76. if (len < sizeof(ifa_flags))
  77. return false;
  78. else if (!umove_or_printaddr(tcp, addr, &ifa_flags))
  79. printflags(ifaddrflags, ifa_flags, "IFA_F_???");
  80. return true;
  81. }
  82. static const nla_decoder_t ifaddrmsg_nla_decoders[] = {
  83. [IFA_ADDRESS] = decode_ifa_address,
  84. [IFA_LOCAL] = decode_ifa_address,
  85. [IFA_LABEL] = decode_nla_str,
  86. [IFA_BROADCAST] = decode_ifa_address,
  87. [IFA_ANYCAST] = decode_ifa_address,
  88. [IFA_CACHEINFO] = decode_ifa_cacheinfo,
  89. [IFA_MULTICAST] = decode_ifa_address,
  90. [IFA_FLAGS] = decode_ifa_flags
  91. };
  92. DECL_NETLINK_ROUTE_DECODER(decode_ifaddrmsg)
  93. {
  94. struct ifaddrmsg ifaddr = { .ifa_family = family };
  95. size_t offset = sizeof(ifaddr.ifa_family);
  96. bool decode_nla = false;
  97. PRINT_FIELD_XVAL("{", ifaddr, ifa_family, addrfams, "AF_???");
  98. tprints(", ");
  99. if (len >= sizeof(ifaddr)) {
  100. if (!umoven_or_printaddr(tcp, addr + offset,
  101. sizeof(ifaddr) - offset,
  102. (char *) &ifaddr + offset)) {
  103. PRINT_FIELD_U("", ifaddr, ifa_prefixlen);
  104. PRINT_FIELD_FLAGS(", ", ifaddr, ifa_flags,
  105. ifaddrflags, "IFA_F_???");
  106. PRINT_FIELD_XVAL(", ", ifaddr, ifa_scope,
  107. routing_scopes, NULL);
  108. PRINT_FIELD_IFINDEX(", ", ifaddr, ifa_index);
  109. decode_nla = true;
  110. }
  111. } else
  112. tprints("...");
  113. tprints("}");
  114. offset = NLMSG_ALIGN(sizeof(ifaddr));
  115. if (decode_nla && len > offset) {
  116. tprints(", ");
  117. decode_nlattr(tcp, addr + offset, len - offset,
  118. rtnl_addr_attrs, "IFA_???",
  119. ifaddrmsg_nla_decoders,
  120. ARRAY_SIZE(ifaddrmsg_nla_decoders), &ifaddr);
  121. }
  122. }