PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/ipv6.h

https://bitbucket.org/mbent/tinc
C Header | 130 lines | 100 code | 11 blank | 19 comment | 5 complexity | 2a89d95feea38f7d19bc9281f867c127 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /*
  2. ipv6.h -- missing IPv6 related definitions
  3. Copyright (C) 2005 Ivo Timmermans
  4. 2006-2012 Guus Sliepen <guus@tinc-vpn.org>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #ifndef __TINC_IPV6_H__
  18. #define __TINC_IPV6_H__
  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 /* __TINC_IPV6_H__ */