diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-20 23:18:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-20 23:18:49 +0000 |
commit | 5e442d9cf826adb58d4595722c7dd7b2532096c9 (patch) | |
tree | 8102eea776e7a14294f89c7e8a9b009f488b3548 /src | |
parent | bd6dc9683d63356d34d0b0d1c3cea4c1b6d67769 (diff) | |
download | gnunet-5e442d9cf826adb58d4595722c7dd7b2532096c9.tar.gz gnunet-5e442d9cf826adb58d4595722c7dd7b2532096c9.zip |
-adding ICMP support to TUN library
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_tun_lib.h | 70 | ||||
-rw-r--r-- | src/tun/tun.c | 23 |
2 files changed, 93 insertions, 0 deletions
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h index 5fddf70b2..01358299d 100644 --- a/src/include/gnunet_tun_lib.h +++ b/src/include/gnunet_tun_lib.h | |||
@@ -145,6 +145,63 @@ struct GNUNET_TUN_DnsHeader | |||
145 | uint16_t arcount GNUNET_PACKED; | 145 | uint16_t arcount GNUNET_PACKED; |
146 | }; | 146 | }; |
147 | 147 | ||
148 | #define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0 | ||
149 | #define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3 | ||
150 | #define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4 | ||
151 | #define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5 | ||
152 | #define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8 | ||
153 | #define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9 | ||
154 | #define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10 | ||
155 | #define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11 | ||
156 | |||
157 | #define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1 | ||
158 | #define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2 | ||
159 | #define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3 | ||
160 | #define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4 | ||
161 | #define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128 | ||
162 | #define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129 | ||
163 | |||
164 | /** | ||
165 | * ICMP header. | ||
166 | */ | ||
167 | struct GNUNET_TUN_IcmpHeader { | ||
168 | uint8_t type; | ||
169 | uint8_t code; | ||
170 | uint16_t crc; | ||
171 | |||
172 | union { | ||
173 | /** | ||
174 | * ICMP Echo (request/reply) | ||
175 | */ | ||
176 | struct { | ||
177 | uint16_t identifier; | ||
178 | uint16_t sequence_number; | ||
179 | } echo; | ||
180 | |||
181 | /** | ||
182 | * ICMP Destination Unreachable (RFC 1191) | ||
183 | */ | ||
184 | struct ih_pmtu { | ||
185 | uint16_t empty; | ||
186 | uint16_t next_hop_mtu; | ||
187 | /* followed by original IP header + first 8 bytes of original IP datagram */ | ||
188 | } destination_unreachable; | ||
189 | |||
190 | /** | ||
191 | * ICMP Redirect | ||
192 | */ | ||
193 | struct in_addr redirect_gateway_address; | ||
194 | |||
195 | /** | ||
196 | * Placeholder. | ||
197 | */ | ||
198 | int32_t present; | ||
199 | |||
200 | } quench; | ||
201 | |||
202 | }; | ||
203 | |||
204 | |||
148 | GNUNET_NETWORK_STRUCT_END | 205 | GNUNET_NETWORK_STRUCT_END |
149 | 206 | ||
150 | 207 | ||
@@ -239,4 +296,17 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | |||
239 | uint16_t payload_length); | 296 | uint16_t payload_length); |
240 | 297 | ||
241 | 298 | ||
299 | /** | ||
300 | * Calculate ICMP checksum. | ||
301 | * | ||
302 | * @param icmp IMCP header (initialized except for CRC) | ||
303 | * @param payload the ICMP payload | ||
304 | * @param payload_length number of bytes of ICMP payload | ||
305 | */ | ||
306 | void | ||
307 | GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, | ||
308 | const void *payload, | ||
309 | uint16_t payload_length); | ||
310 | |||
311 | |||
242 | #endif | 312 | #endif |
diff --git a/src/tun/tun.c b/src/tun/tun.c index 009fdd952..4c2ddf07a 100644 --- a/src/tun/tun.c +++ b/src/tun/tun.c | |||
@@ -242,4 +242,27 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | |||
242 | } | 242 | } |
243 | 243 | ||
244 | 244 | ||
245 | /** | ||
246 | * Calculate ICMP checksum. | ||
247 | * | ||
248 | * @param icmp IMCP header (initialized except for CRC) | ||
249 | * @param payload the ICMP payload | ||
250 | * @param payload_length number of bytes of ICMP payload | ||
251 | */ | ||
252 | void | ||
253 | GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, | ||
254 | const void *payload, | ||
255 | uint16_t payload_length) | ||
256 | { | ||
257 | uint32_t sum; | ||
258 | |||
259 | icmp->crc = 0; | ||
260 | sum = GNUNET_CRYPTO_crc16_step (0, | ||
261 | icmp, | ||
262 | sizeof (struct GNUNET_TUN_IcmpHeader)); | ||
263 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | ||
264 | icmp->crc = GNUNET_CRYPTO_crc16_finish (sum); | ||
265 | } | ||
266 | |||
267 | |||
245 | /* end of tun.c */ | 268 | /* end of tun.c */ |