1 : /*
2 : * teredo.h - Common Teredo protocol typedefs
3 : * $Id: teredo.h 1771 2006-10-04 19:12:17Z remi $
4 : *
5 : * See "Teredo: Tunneling IPv6 over UDP through NATs"
6 : * for more information
7 : */
8 :
9 : /***********************************************************************
10 : * Copyright © 2004-2006 Rémi Denis-Courmont. *
11 : * This program is free software; you can redistribute and/or modify *
12 : * it under the terms of the GNU General Public License as published *
13 : * by the Free Software Foundation; version 2 of the license. *
14 : * *
15 : * This program is distributed in the hope that it will be useful, *
16 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
18 : * See the GNU General Public License for more details. *
19 : * *
20 : * You should have received a copy of the GNU General Public License *
21 : * along with this program; if not, you can get it from: *
22 : * http://www.gnu.org/copyleft/gpl.html *
23 : ***********************************************************************/
24 :
25 : #ifndef MIREDO_INCLUDE_TEREDO_H
26 : # define MIREDO_INCLUDE_TEREDO_H
27 :
28 : # if __STDC_VERSION__ < 199901L
29 : # ifndef inline
30 : # define inline
31 : # endif
32 : # endif
33 :
34 : /* UDP Teredo port number */
35 : #define IPPORT_TEREDO 3544
36 :
37 : /* Multicast IPv4 discovery address */
38 : #define TEREDO_DISCOVERY_IPV4 0xe00000fd
39 :
40 : /*
41 : * Teredo addresses
42 : */
43 : extern const struct in6_addr teredo_restrict;
44 : extern const struct in6_addr teredo_cone;
45 :
46 : #define TEREDO_PREFIX 0x20010000
47 : #define TEREDO_PREFIX_OBSOLETE 0x3ffe831f
48 :
49 : union teredo_addr
50 : {
51 : struct in6_addr ip6;
52 : struct
53 : {
54 : uint32_t prefix;
55 : uint32_t server_ip;
56 : uint16_t flags;
57 : uint16_t client_port;
58 : uint32_t client_ip;
59 : } teredo;
60 : uint32_t t6_addr32[4];
61 : };
62 :
63 : #define TEREDO_FLAG_CONE 0x8000
64 :
65 : /* The following two flags should never be set */
66 : #define TEREDO_FLAG_MULTICAST 0x0200
67 : #define TEREDO_FLAG_GLOBAL 0x0100
68 :
69 : /* Non-standard flags (taken from draft-ietf-ngtrans-shipworm-07) */
70 : #define TEREDO_FLAG_RANDOM 0x4000
71 : #define TEREDO_RANDOM_MASK 0xc3ff
72 :
73 : #define ip6_teredo( ip6 ) (((union teredo_addr *)ip6)->teredo)
74 :
75 : /* NOTE: these macros expect 4-byte aligned addresses structs */
76 : #define IN6_IS_TEREDO_ADDR_CONE( ip6 ) \
77 : (((const union teredo_addr *)(ip6))->teredo.flags \
78 : & htons (TEREDO_FLAG_CONE))
79 :
80 : #define IN6_TEREDO_PREFIX( ip6 ) \
81 : (((const union teredo_addr *)ip6)->teredo.prefix)
82 : #define IN6_TEREDO_SERVER( ip6 ) \
83 : (((const union teredo_addr *)ip6)->teredo.server_ip)
84 : #define IN6_TEREDO_IPV4( ip6 ) \
85 : (((const union teredo_addr *)ip6)->teredo.client_ip ^ 0xffffffff)
86 : #define IN6_TEREDO_PORT( ip6 ) \
87 : (((const union teredo_addr *)ip6)->teredo.client_port ^ 0xffff)
88 :
89 : #define IN6_MATCHES_TEREDO_CLIENT( ip6, ip4, port ) \
90 : in6_matches_teredo_client ((const union teredo_addr *)ip6, ip4, port)
91 :
92 : #define IN6_MATCHES_TEREDO_SYMMETRIC( ip6, ip4, port ) \
93 : in6_matches_teredo_symmetric ((const union teredo_addr *)ip6, ip4, port)
94 :
95 : static inline int
96 : in6_matches_teredo_client (const union teredo_addr *ip6,
97 : uint32_t ip, uint16_t port)
98 0 : {
99 0 : return (ip == IN6_TEREDO_IPV4 (ip6)) && (port == IN6_TEREDO_PORT (ip6));
100 : }
101 :
102 : static inline int
103 : in6_matches_teredo_symmetric (const union teredo_addr *ip6,
104 : uint32_t ip, uint16_t port)
105 0 : {
106 0 : return (ip == IN6_TEREDO_IPV4 (ip6))
107 : && ((port == IN6_TEREDO_PORT (ip6)
108 : || (ip6->teredo.flags & TEREDO_RANDOM_MASK)));
109 : }
110 :
111 : /*
112 : * Returns true if prefix can be used as a Teredo prefix.
113 : * As per RFC3513, anything could be used for Teredo (unicast)
114 : * except the multicast range (ff00::/8).
115 : */
116 : #define is_valid_teredo_prefix( prefix ) \
117 : ((prefix & 0xff000000) != 0xff000000)
118 :
119 : /*
120 : * Teredo headers
121 : */
122 : enum
123 : {
124 : teredo_orig_ind=0,
125 : teredo_auth_hdr
126 : };
127 :
128 : struct teredo_hdr_common
129 : {
130 : uint8_t zero;
131 : uint8_t code;
132 : };
133 :
134 : struct teredo_orig_ind /* code == 1 */
135 : {
136 : struct teredo_hdr_common hdr;
137 : uint16_t orig_port; /* obfuscated port number in network byte order */
138 : uint32_t orig_addr; /* obfuscated IPv4 address in network byte order */
139 : };
140 :
141 : struct teredo_auth_hdr
142 : {
143 : struct teredo_hdr_common hdr;
144 : uint8_t id_len;
145 : uint8_t au_len;
146 : /* client id and auth value follows */
147 : };
148 :
149 : /*
150 : * Minimal Teredo auth header
151 : * BIG FAT WARNING:
152 : * This structure will probably break alignement in your Teredo packets.
153 : */
154 : struct teredo_simple_auth
155 : {
156 : struct teredo_auth_hdr hdr;
157 : uint8_t nonce[8];
158 : uint8_t confirmation;
159 : };
160 :
161 : #endif /* ifndef MIREDO_INCLUDE_TEREDO_H */
162 :
|