ipv6.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef TINC_IPV6_H
  2. #define TINC_IPV6_H
  3. /*
  4. ipv6.h -- missing IPv6 related definitions
  5. Copyright (C) 2005 Ivo Timmermans
  6. 2006-2012 Guus Sliepen <guus@tinc-vpn.org>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License along
  16. with this program; if not, write to the Free Software Foundation, Inc.,
  17. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #ifndef AF_INET6
  20. #define AF_INET6 10
  21. #endif
  22. #ifndef IPPROTO_ICMPV6
  23. #define IPPROTO_ICMPV6 58
  24. #endif
  25. #ifndef HAVE_STRUCT_IN6_ADDR
  26. struct in6_addr {
  27. union {
  28. uint8_t u6_addr8[16];
  29. uint16_t u6_addr16[8];
  30. uint32_t u6_addr32[4];
  31. } in6_u;
  32. } __attribute__((__packed__));
  33. #define s6_addr in6_u.u6_addr8
  34. #define s6_addr16 in6_u.u6_addr16
  35. #define s6_addr32 in6_u.u6_addr32
  36. #endif
  37. #ifndef HAVE_STRUCT_SOCKADDR_IN6
  38. struct sockaddr_in6 {
  39. uint16_t sin6_family;
  40. uint16_t sin6_port;
  41. uint32_t sin6_flowinfo;
  42. struct in6_addr sin6_addr;
  43. uint32_t sin6_scope_id;
  44. } __attribute__((__packed__));
  45. #endif
  46. #ifndef IN6_IS_ADDR_V4MAPPED
  47. #define IN6_IS_ADDR_V4MAPPED(a) \
  48. ((((const uint32_t *) (a))[0] == 0) \
  49. && (((const uint32_t *) (a))[1] == 0) \
  50. && (((const uint32_t *) (a))[2] == htonl (0xffff)))
  51. #endif
  52. #ifndef HAVE_STRUCT_IP6_HDR
  53. struct ip6_hdr {
  54. union {
  55. struct ip6_hdrctl {
  56. uint32_t ip6_un1_flow;
  57. uint16_t ip6_un1_plen;
  58. uint8_t ip6_un1_nxt;
  59. uint8_t ip6_un1_hlim;
  60. } ip6_un1;
  61. uint8_t ip6_un2_vfc;
  62. } ip6_ctlun;
  63. struct in6_addr ip6_src;
  64. struct in6_addr ip6_dst;
  65. } __attribute__((__packed__));
  66. #define ip6_vfc ip6_ctlun.ip6_un2_vfc
  67. #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
  68. #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
  69. #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
  70. #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
  71. #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
  72. #endif
  73. #ifndef HAVE_STRUCT_ICMP6_HDR
  74. struct icmp6_hdr {
  75. uint8_t icmp6_type;
  76. uint8_t icmp6_code;
  77. uint16_t icmp6_cksum;
  78. union {
  79. uint32_t icmp6_un_data32[1];
  80. uint16_t icmp6_un_data16[2];
  81. uint8_t icmp6_un_data8[4];
  82. } icmp6_dataun;
  83. } __attribute__((__packed__));
  84. #define ICMP6_DST_UNREACH_NOROUTE 0
  85. #define ICMP6_DST_UNREACH 1
  86. #define ICMP6_PACKET_TOO_BIG 2
  87. #define ICMP6_TIME_EXCEEDED 3
  88. #define ICMP6_DST_UNREACH_ADMIN 1
  89. #define ICMP6_DST_UNREACH_ADDR 3
  90. #define ICMP6_TIME_EXCEED_TRANSIT 0
  91. #define ND_NEIGHBOR_SOLICIT 135
  92. #define ND_NEIGHBOR_ADVERT 136
  93. #define icmp6_data32 icmp6_dataun.icmp6_un_data32
  94. #define icmp6_data16 icmp6_dataun.icmp6_un_data16
  95. #define icmp6_data8 icmp6_dataun.icmp6_un_data8
  96. #define icmp6_mtu icmp6_data32[0]
  97. #endif
  98. #ifndef HAVE_STRUCT_ND_NEIGHBOR_SOLICIT
  99. struct nd_neighbor_solicit {
  100. struct icmp6_hdr nd_ns_hdr;
  101. struct in6_addr nd_ns_target;
  102. } __attribute__((__packed__));
  103. #define ND_OPT_SOURCE_LINKADDR 1
  104. #define ND_OPT_TARGET_LINKADDR 2
  105. #define nd_ns_type nd_ns_hdr.icmp6_type
  106. #define nd_ns_code nd_ns_hdr.icmp6_code
  107. #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
  108. #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
  109. #endif
  110. #ifndef HAVE_STRUCT_ND_OPT_HDR
  111. struct nd_opt_hdr {
  112. uint8_t nd_opt_type;
  113. uint8_t nd_opt_len;
  114. } __attribute__((__packed__));
  115. #endif
  116. #endif