diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/exit | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/exit')
-rw-r--r-- | src/exit/exit.h | 31 | ||||
-rw-r--r-- | src/exit/gnunet-daemon-exit.c | 4698 | ||||
-rw-r--r-- | src/exit/gnunet-helper-exit-windows.c | 1160 | ||||
-rw-r--r-- | src/exit/gnunet-helper-exit.c | 964 |
4 files changed, 3454 insertions, 3399 deletions
diff --git a/src/exit/exit.h b/src/exit/exit.h index 6214c230a..be4f042b6 100644 --- a/src/exit/exit.h +++ b/src/exit/exit.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file exit/exit.h | 22 | * @file exit/exit.h |
@@ -34,8 +34,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
34 | * Message send via cadet to an exit daemon to initiate forwarding of | 34 | * Message send via cadet to an exit daemon to initiate forwarding of |
35 | * TCP data to a local service. | 35 | * TCP data to a local service. |
36 | */ | 36 | */ |
37 | struct GNUNET_EXIT_TcpServiceStartMessage | 37 | struct GNUNET_EXIT_TcpServiceStartMessage { |
38 | { | ||
39 | /** | 38 | /** |
40 | * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START | 39 | * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START |
41 | */ | 40 | */ |
@@ -60,8 +59,7 @@ struct GNUNET_EXIT_TcpServiceStartMessage | |||
60 | * Message send via cadet to an exit daemon to initiate forwarding of | 59 | * Message send via cadet to an exit daemon to initiate forwarding of |
61 | * TCP data to the Internet. | 60 | * TCP data to the Internet. |
62 | */ | 61 | */ |
63 | struct GNUNET_EXIT_TcpInternetStartMessage | 62 | struct GNUNET_EXIT_TcpInternetStartMessage { |
64 | { | ||
65 | /** | 63 | /** |
66 | * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START | 64 | * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START |
67 | */ | 65 | */ |
@@ -91,8 +89,7 @@ struct GNUNET_EXIT_TcpInternetStartMessage | |||
91 | * format is used for both Internet-exits and service-exits and | 89 | * format is used for both Internet-exits and service-exits and |
92 | * in both directions (VPN to exit and exit to VPN). | 90 | * in both directions (VPN to exit and exit to VPN). |
93 | */ | 91 | */ |
94 | struct GNUNET_EXIT_TcpDataMessage | 92 | struct GNUNET_EXIT_TcpDataMessage { |
95 | { | ||
96 | /** | 93 | /** |
97 | * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_DATA | 94 | * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_DATA |
98 | */ | 95 | */ |
@@ -117,8 +114,7 @@ struct GNUNET_EXIT_TcpDataMessage | |||
117 | * Message send via cadet to an exit daemon to send | 114 | * Message send via cadet to an exit daemon to send |
118 | * UDP data to a local service. | 115 | * UDP data to a local service. |
119 | */ | 116 | */ |
120 | struct GNUNET_EXIT_UdpServiceMessage | 117 | struct GNUNET_EXIT_UdpServiceMessage { |
121 | { | ||
122 | /** | 118 | /** |
123 | * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE | 119 | * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE |
124 | */ | 120 | */ |
@@ -142,8 +138,7 @@ struct GNUNET_EXIT_UdpServiceMessage | |||
142 | * Message send via cadet to an exit daemon to forward | 138 | * Message send via cadet to an exit daemon to forward |
143 | * UDP data to the Internet. | 139 | * UDP data to the Internet. |
144 | */ | 140 | */ |
145 | struct GNUNET_EXIT_UdpInternetMessage | 141 | struct GNUNET_EXIT_UdpInternetMessage { |
146 | { | ||
147 | /** | 142 | /** |
148 | * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET | 143 | * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET |
149 | */ | 144 | */ |
@@ -175,8 +170,7 @@ struct GNUNET_EXIT_UdpInternetMessage | |||
175 | * Message send from exit daemon back to the UDP entry point | 170 | * Message send from exit daemon back to the UDP entry point |
176 | * (used for both Internet and Service exit replies). | 171 | * (used for both Internet and Service exit replies). |
177 | */ | 172 | */ |
178 | struct GNUNET_EXIT_UdpReplyMessage | 173 | struct GNUNET_EXIT_UdpReplyMessage { |
179 | { | ||
180 | /** | 174 | /** |
181 | * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY | 175 | * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY |
182 | */ | 176 | */ |
@@ -202,8 +196,7 @@ struct GNUNET_EXIT_UdpReplyMessage | |||
202 | * Message send via cadet to an exit daemon to send | 196 | * Message send via cadet to an exit daemon to send |
203 | * ICMP data to a local service. | 197 | * ICMP data to a local service. |
204 | */ | 198 | */ |
205 | struct GNUNET_EXIT_IcmpServiceMessage | 199 | struct GNUNET_EXIT_IcmpServiceMessage { |
206 | { | ||
207 | /** | 200 | /** |
208 | * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE | 201 | * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE |
209 | */ | 202 | */ |
@@ -233,8 +226,7 @@ struct GNUNET_EXIT_IcmpServiceMessage | |||
233 | * Message send via cadet to an exit daemon to forward | 226 | * Message send via cadet to an exit daemon to forward |
234 | * ICMP data to the Internet. | 227 | * ICMP data to the Internet. |
235 | */ | 228 | */ |
236 | struct GNUNET_EXIT_IcmpInternetMessage | 229 | struct GNUNET_EXIT_IcmpInternetMessage { |
237 | { | ||
238 | /** | 230 | /** |
239 | * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET | 231 | * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET |
240 | */ | 232 | */ |
@@ -268,8 +260,7 @@ struct GNUNET_EXIT_IcmpInternetMessage | |||
268 | * Message send via cadet to the vpn service to send | 260 | * Message send via cadet to the vpn service to send |
269 | * ICMP data to the VPN's TUN interface. | 261 | * ICMP data to the VPN's TUN interface. |
270 | */ | 262 | */ |
271 | struct GNUNET_EXIT_IcmpToVPNMessage | 263 | struct GNUNET_EXIT_IcmpToVPNMessage { |
272 | { | ||
273 | /** | 264 | /** |
274 | * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN | 265 | * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN |
275 | */ | 266 | */ |
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index 716a1ead0..f7cadbace 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file exit/gnunet-daemon-exit.c | 22 | * @file exit/gnunet-daemon-exit.c |
@@ -66,31 +66,30 @@ | |||
66 | /** | 66 | /** |
67 | * How frequently do we re-announce the regex for the exit? | 67 | * How frequently do we re-announce the regex for the exit? |
68 | */ | 68 | */ |
69 | #define REGEX_REFRESH_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) | 69 | #define REGEX_REFRESH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * How frequently do we re-announce the DNS exit in the DHT? | 72 | * How frequently do we re-announce the DNS exit in the DHT? |
73 | */ | 73 | */ |
74 | #define DHT_PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 74 | #define DHT_PUT_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * How long do we typically sign the DNS exit advertisement for? | 77 | * How long do we typically sign the DNS exit advertisement for? |
78 | */ | 78 | */ |
79 | #define DNS_ADVERTISEMENT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 3) | 79 | #define DNS_ADVERTISEMENT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 3) |
80 | 80 | ||
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Generic logging shorthand | 83 | * Generic logging shorthand |
84 | */ | 84 | */ |
85 | #define LOG(kind, ...) \ | 85 | #define LOG(kind, ...) \ |
86 | GNUNET_log_from (kind, "exit", __VA_ARGS__); | 86 | GNUNET_log_from(kind, "exit", __VA_ARGS__); |
87 | 87 | ||
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Information about an address. | 90 | * Information about an address. |
91 | */ | 91 | */ |
92 | struct SocketAddress | 92 | struct SocketAddress { |
93 | { | ||
94 | /** | 93 | /** |
95 | * AF_INET or AF_INET6. | 94 | * AF_INET or AF_INET6. |
96 | */ | 95 | */ |
@@ -99,8 +98,7 @@ struct SocketAddress | |||
99 | /** | 98 | /** |
100 | * Remote address information. | 99 | * Remote address information. |
101 | */ | 100 | */ |
102 | union | 101 | union { |
103 | { | ||
104 | /** | 102 | /** |
105 | * Address, if af is AF_INET. | 103 | * Address, if af is AF_INET. |
106 | */ | 104 | */ |
@@ -121,7 +119,6 @@ struct SocketAddress | |||
121 | * Remote port, in host byte order! | 119 | * Remote port, in host byte order! |
122 | */ | 120 | */ |
123 | uint16_t port; | 121 | uint16_t port; |
124 | |||
125 | }; | 122 | }; |
126 | 123 | ||
127 | 124 | ||
@@ -130,9 +127,7 @@ struct SocketAddress | |||
130 | * a service this peer is specifically offering an exit for | 127 | * a service this peer is specifically offering an exit for |
131 | * (for a specific domain name). | 128 | * (for a specific domain name). |
132 | */ | 129 | */ |
133 | struct LocalService | 130 | struct LocalService { |
134 | { | ||
135 | |||
136 | /** | 131 | /** |
137 | * Remote address to use for the service. | 132 | * Remote address to use for the service. |
138 | */ | 133 | */ |
@@ -157,7 +152,6 @@ struct LocalService | |||
157 | * #GNUNET_YES if this is a UDP service, otherwise TCP. | 152 | * #GNUNET_YES if this is a UDP service, otherwise TCP. |
158 | */ | 153 | */ |
159 | int16_t is_udp; | 154 | int16_t is_udp; |
160 | |||
161 | }; | 155 | }; |
162 | 156 | ||
163 | 157 | ||
@@ -166,9 +160,7 @@ struct LocalService | |||
166 | * IP-version, protocol, source-IP, destination-IP, source-port and | 160 | * IP-version, protocol, source-IP, destination-IP, source-port and |
167 | * destinatin-port. | 161 | * destinatin-port. |
168 | */ | 162 | */ |
169 | struct RedirectInformation | 163 | struct RedirectInformation { |
170 | { | ||
171 | |||
172 | /** | 164 | /** |
173 | * Address information for the other party (equivalent of the | 165 | * Address information for the other party (equivalent of the |
174 | * arguments one would give to "connect"). | 166 | * arguments one would give to "connect"). |
@@ -190,7 +182,7 @@ struct RedirectInformation | |||
190 | Note 2: we might also sometimes not match on all components | 182 | Note 2: we might also sometimes not match on all components |
191 | of the tuple, to support protocols where things do not always | 183 | of the tuple, to support protocols where things do not always |
192 | fully map. | 184 | fully map. |
193 | */ | 185 | */ |
194 | }; | 186 | }; |
195 | 187 | ||
196 | 188 | ||
@@ -200,8 +192,7 @@ struct RedirectInformation | |||
200 | * with the channel's closure so we can find it again for the next | 192 | * with the channel's closure so we can find it again for the next |
201 | * message from the channel. | 193 | * message from the channel. |
202 | */ | 194 | */ |
203 | struct ChannelState | 195 | struct ChannelState { |
204 | { | ||
205 | /** | 196 | /** |
206 | * Cadet channel that is used for this connection. | 197 | * Cadet channel that is used for this connection. |
207 | */ | 198 | */ |
@@ -220,11 +211,8 @@ struct ChannelState | |||
220 | */ | 211 | */ |
221 | int is_dns; | 212 | int is_dns; |
222 | 213 | ||
223 | union | 214 | union { |
224 | { | 215 | struct { |
225 | struct | ||
226 | { | ||
227 | |||
228 | /** | 216 | /** |
229 | * Heap node for this state in the connections_heap. | 217 | * Heap node for this state in the connections_heap. |
230 | */ | 218 | */ |
@@ -246,9 +234,7 @@ struct ChannelState | |||
246 | struct RedirectInformation ri; | 234 | struct RedirectInformation ri; |
247 | } tcp_udp; | 235 | } tcp_udp; |
248 | 236 | ||
249 | struct | 237 | struct { |
250 | { | ||
251 | |||
252 | /** | 238 | /** |
253 | * Socket we are using to transmit this request (must match if we receive | 239 | * Socket we are using to transmit this request (must match if we receive |
254 | * a response). | 240 | * a response). |
@@ -264,11 +250,8 @@ struct ChannelState | |||
264 | * DNS request ID that we used for forwarding. | 250 | * DNS request ID that we used for forwarding. |
265 | */ | 251 | */ |
266 | uint16_t my_id; | 252 | uint16_t my_id; |
267 | |||
268 | } dns; | 253 | } dns; |
269 | |||
270 | } specifics; | 254 | } specifics; |
271 | |||
272 | }; | 255 | }; |
273 | 256 | ||
274 | 257 | ||
@@ -435,8 +418,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
435 | /** | 418 | /** |
436 | * Message with a DNS response. | 419 | * Message with a DNS response. |
437 | */ | 420 | */ |
438 | struct DnsResponseMessage | 421 | struct DnsResponseMessage { |
439 | { | ||
440 | /** | 422 | /** |
441 | * GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET | 423 | * GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET |
442 | */ | 424 | */ |
@@ -462,35 +444,35 @@ GNUNET_NETWORK_STRUCT_END | |||
462 | * @param r number of bytes in @a dns | 444 | * @param r number of bytes in @a dns |
463 | */ | 445 | */ |
464 | static void | 446 | static void |
465 | process_dns_result (void *cls, | 447 | process_dns_result(void *cls, |
466 | const struct GNUNET_TUN_DnsHeader *dns, | 448 | const struct GNUNET_TUN_DnsHeader *dns, |
467 | size_t r) | 449 | size_t r) |
468 | { | 450 | { |
469 | struct ChannelState *ts; | 451 | struct ChannelState *ts; |
470 | struct GNUNET_MQ_Envelope *env; | 452 | struct GNUNET_MQ_Envelope *env; |
471 | struct DnsResponseMessage *resp; | 453 | struct DnsResponseMessage *resp; |
472 | 454 | ||
473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 455 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
474 | "Processing DNS result from stub resolver\n"); | 456 | "Processing DNS result from stub resolver\n"); |
475 | GNUNET_assert (NULL == cls); | 457 | GNUNET_assert(NULL == cls); |
476 | if (NULL == dns) | 458 | if (NULL == dns) |
477 | return; | 459 | return; |
478 | /* Handle case that this is a reply to a request from a CADET DNS channel */ | 460 | /* Handle case that this is a reply to a request from a CADET DNS channel */ |
479 | ts = channels[dns->id]; | 461 | ts = channels[dns->id]; |
480 | if (NULL == ts) | 462 | if (NULL == ts) |
481 | return; | 463 | return; |
482 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 464 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
483 | "Got a response from the stub resolver for DNS request received via CADET!\n"); | 465 | "Got a response from the stub resolver for DNS request received via CADET!\n"); |
484 | channels[dns->id] = NULL; | 466 | channels[dns->id] = NULL; |
485 | env = GNUNET_MQ_msg_extra (resp, | 467 | env = GNUNET_MQ_msg_extra(resp, |
486 | r - sizeof (struct GNUNET_TUN_DnsHeader), | 468 | r - sizeof(struct GNUNET_TUN_DnsHeader), |
487 | GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET); | 469 | GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET); |
488 | GNUNET_memcpy (&resp->dns, | 470 | GNUNET_memcpy(&resp->dns, |
489 | dns, | 471 | dns, |
490 | r); | 472 | r); |
491 | resp->dns.id = ts->specifics.dns.original_id; | 473 | resp->dns.id = ts->specifics.dns.original_id; |
492 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ts->channel), | 474 | GNUNET_MQ_send(GNUNET_CADET_get_mq(ts->channel), |
493 | env); | 475 | env); |
494 | } | 476 | } |
495 | 477 | ||
496 | 478 | ||
@@ -503,21 +485,21 @@ process_dns_result (void *cls, | |||
503 | * #GNUNET_SYSERR to close it (signal serious error) | 485 | * #GNUNET_SYSERR to close it (signal serious error) |
504 | */ | 486 | */ |
505 | static int | 487 | static int |
506 | check_dns_request (void *cls, | 488 | check_dns_request(void *cls, |
507 | const struct DnsResponseMessage *msg) | 489 | const struct DnsResponseMessage *msg) |
508 | { | 490 | { |
509 | struct ChannelState *ts = cls; | 491 | struct ChannelState *ts = cls; |
510 | 492 | ||
511 | if (NULL == dnsstub) | 493 | if (NULL == dnsstub) |
512 | { | 494 | { |
513 | GNUNET_break (0); | 495 | GNUNET_break(0); |
514 | return GNUNET_SYSERR; | 496 | return GNUNET_SYSERR; |
515 | } | 497 | } |
516 | if (GNUNET_NO == ts->is_dns) | 498 | if (GNUNET_NO == ts->is_dns) |
517 | { | 499 | { |
518 | GNUNET_break_op (0); | 500 | GNUNET_break_op(0); |
519 | return GNUNET_SYSERR; | 501 | return GNUNET_SYSERR; |
520 | } | 502 | } |
521 | return GNUNET_OK; | 503 | return GNUNET_OK; |
522 | } | 504 | } |
523 | 505 | ||
@@ -529,42 +511,42 @@ check_dns_request (void *cls, | |||
529 | * @param msg the actual message | 511 | * @param msg the actual message |
530 | */ | 512 | */ |
531 | static void | 513 | static void |
532 | handle_dns_request (void *cls, | 514 | handle_dns_request(void *cls, |
533 | const struct DnsResponseMessage *msg) | 515 | const struct DnsResponseMessage *msg) |
534 | { | 516 | { |
535 | struct ChannelState *ts = cls; | 517 | struct ChannelState *ts = cls; |
536 | size_t mlen = ntohs (msg->header.size); | 518 | size_t mlen = ntohs(msg->header.size); |
537 | size_t dlen = mlen - sizeof (struct GNUNET_MessageHeader); | 519 | size_t dlen = mlen - sizeof(struct GNUNET_MessageHeader); |
538 | char buf[dlen] GNUNET_ALIGN; | 520 | char buf[dlen] GNUNET_ALIGN; |
539 | struct GNUNET_TUN_DnsHeader *dout; | 521 | struct GNUNET_TUN_DnsHeader *dout; |
540 | 522 | ||
541 | if (GNUNET_SYSERR == ts->is_dns) | 523 | if (GNUNET_SYSERR == ts->is_dns) |
542 | { | 524 | { |
543 | /* channel is DNS from now on */ | 525 | /* channel is DNS from now on */ |
544 | ts->is_dns = GNUNET_YES; | 526 | ts->is_dns = GNUNET_YES; |
545 | } | 527 | } |
546 | ts->specifics.dns.original_id = msg->dns.id; | 528 | ts->specifics.dns.original_id = msg->dns.id; |
547 | if (channels[ts->specifics.dns.my_id] == ts) | 529 | if (channels[ts->specifics.dns.my_id] == ts) |
548 | channels[ts->specifics.dns.my_id] = NULL; | 530 | channels[ts->specifics.dns.my_id] = NULL; |
549 | ts->specifics.dns.my_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 531 | ts->specifics.dns.my_id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
550 | UINT16_MAX + 1); | 532 | UINT16_MAX + 1); |
551 | channels[ts->specifics.dns.my_id] = ts; | 533 | channels[ts->specifics.dns.my_id] = ts; |
552 | GNUNET_memcpy (buf, | 534 | GNUNET_memcpy(buf, |
553 | &msg->dns, | 535 | &msg->dns, |
554 | dlen); | 536 | dlen); |
555 | dout = (struct GNUNET_TUN_DnsHeader *) buf; | 537 | dout = (struct GNUNET_TUN_DnsHeader *)buf; |
556 | dout->id = ts->specifics.dns.my_id; | 538 | dout->id = ts->specifics.dns.my_id; |
557 | ts->specifics.dns.rs = GNUNET_DNSSTUB_resolve (dnsstub, | 539 | ts->specifics.dns.rs = GNUNET_DNSSTUB_resolve(dnsstub, |
558 | buf, | 540 | buf, |
559 | dlen, | 541 | dlen, |
560 | &process_dns_result, | 542 | &process_dns_result, |
561 | NULL); | 543 | NULL); |
562 | if (NULL == ts->specifics.dns.rs) | 544 | if (NULL == ts->specifics.dns.rs) |
563 | { | 545 | { |
564 | GNUNET_break_op (0); | 546 | GNUNET_break_op(0); |
565 | return; | 547 | return; |
566 | } | 548 | } |
567 | GNUNET_CADET_receive_done (ts->channel); | 549 | GNUNET_CADET_receive_done(ts->channel); |
568 | } | 550 | } |
569 | 551 | ||
570 | 552 | ||
@@ -576,62 +558,66 @@ handle_dns_request (void *cls, | |||
576 | * @param ri information about the connection | 558 | * @param ri information about the connection |
577 | */ | 559 | */ |
578 | static void | 560 | static void |
579 | hash_redirect_info (struct GNUNET_HashCode *hash, | 561 | hash_redirect_info(struct GNUNET_HashCode *hash, |
580 | const struct RedirectInformation *ri) | 562 | const struct RedirectInformation *ri) |
581 | { | 563 | { |
582 | char *off; | 564 | char *off; |
583 | 565 | ||
584 | memset (hash, | 566 | memset(hash, |
585 | 0, | 567 | 0, |
586 | sizeof (struct GNUNET_HashCode)); | 568 | sizeof(struct GNUNET_HashCode)); |
587 | /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, | 569 | /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, |
588 | so we put the IP address in there (and hope for few collisions) */ | 570 | so we put the IP address in there (and hope for few collisions) */ |
589 | off = (char*) hash; | 571 | off = (char*)hash; |
590 | switch (ri->remote_address.af) | 572 | switch (ri->remote_address.af) |
591 | { | 573 | { |
592 | case AF_INET: | 574 | case AF_INET: |
593 | GNUNET_memcpy (off, | 575 | GNUNET_memcpy(off, |
594 | &ri->remote_address.address.ipv4, | 576 | &ri->remote_address.address.ipv4, |
595 | sizeof (struct in_addr)); | 577 | sizeof(struct in_addr)); |
596 | off += sizeof (struct in_addr); | 578 | off += sizeof(struct in_addr); |
597 | break; | 579 | break; |
598 | case AF_INET6: | 580 | |
599 | GNUNET_memcpy (off, | 581 | case AF_INET6: |
600 | &ri->remote_address.address.ipv6, | 582 | GNUNET_memcpy(off, |
601 | sizeof (struct in6_addr)); | 583 | &ri->remote_address.address.ipv6, |
602 | off += sizeof (struct in_addr); | 584 | sizeof(struct in6_addr)); |
603 | break; | 585 | off += sizeof(struct in_addr); |
604 | default: | 586 | break; |
605 | GNUNET_assert (0); | 587 | |
606 | } | 588 | default: |
607 | GNUNET_memcpy (off, | 589 | GNUNET_assert(0); |
608 | &ri->remote_address.port, | 590 | } |
609 | sizeof (uint16_t)); | 591 | GNUNET_memcpy(off, |
610 | off += sizeof (uint16_t); | 592 | &ri->remote_address.port, |
593 | sizeof(uint16_t)); | ||
594 | off += sizeof(uint16_t); | ||
611 | switch (ri->local_address.af) | 595 | switch (ri->local_address.af) |
612 | { | 596 | { |
613 | case AF_INET: | 597 | case AF_INET: |
614 | GNUNET_memcpy (off, | 598 | GNUNET_memcpy(off, |
615 | &ri->local_address.address.ipv4, | 599 | &ri->local_address.address.ipv4, |
616 | sizeof (struct in_addr)); | 600 | sizeof(struct in_addr)); |
617 | off += sizeof (struct in_addr); | 601 | off += sizeof(struct in_addr); |
618 | break; | 602 | break; |
619 | case AF_INET6: | 603 | |
620 | GNUNET_memcpy (off, | 604 | case AF_INET6: |
621 | &ri->local_address.address.ipv6, | 605 | GNUNET_memcpy(off, |
622 | sizeof (struct in6_addr)); | 606 | &ri->local_address.address.ipv6, |
623 | off += sizeof (struct in_addr); | 607 | sizeof(struct in6_addr)); |
624 | break; | 608 | off += sizeof(struct in_addr); |
625 | default: | 609 | break; |
626 | GNUNET_assert (0); | 610 | |
627 | } | 611 | default: |
628 | GNUNET_memcpy (off, | 612 | GNUNET_assert(0); |
629 | &ri->local_address.port, | 613 | } |
630 | sizeof (uint16_t)); | 614 | GNUNET_memcpy(off, |
631 | off += sizeof (uint16_t); | 615 | &ri->local_address.port, |
632 | GNUNET_memcpy (off, | 616 | sizeof(uint16_t)); |
633 | &ri->remote_address.proto, | 617 | off += sizeof(uint16_t); |
634 | sizeof (uint8_t)); | 618 | GNUNET_memcpy(off, |
619 | &ri->remote_address.proto, | ||
620 | sizeof(uint8_t)); | ||
635 | /* off += sizeof (uint8_t); */ | 621 | /* off += sizeof (uint8_t); */ |
636 | } | 622 | } |
637 | 623 | ||
@@ -650,51 +636,51 @@ hash_redirect_info (struct GNUNET_HashCode *hash, | |||
650 | * @return NULL if we have no tracking information for this tuple | 636 | * @return NULL if we have no tracking information for this tuple |
651 | */ | 637 | */ |
652 | static struct ChannelState * | 638 | static struct ChannelState * |
653 | get_redirect_state (int af, | 639 | get_redirect_state(int af, |
654 | int protocol, | 640 | int protocol, |
655 | const void *destination_ip, | 641 | const void *destination_ip, |
656 | uint16_t destination_port, | 642 | uint16_t destination_port, |
657 | const void *local_ip, | 643 | const void *local_ip, |
658 | uint16_t local_port, | 644 | uint16_t local_port, |
659 | struct GNUNET_HashCode *state_key) | 645 | struct GNUNET_HashCode *state_key) |
660 | { | 646 | { |
661 | struct RedirectInformation ri; | 647 | struct RedirectInformation ri; |
662 | struct GNUNET_HashCode key; | 648 | struct GNUNET_HashCode key; |
663 | struct ChannelState *state; | 649 | struct ChannelState *state; |
664 | 650 | ||
665 | if ( ( (af == AF_INET) && (protocol == IPPROTO_ICMP) ) || | 651 | if (((af == AF_INET) && (protocol == IPPROTO_ICMP)) || |
666 | ( (af == AF_INET6) && (protocol == IPPROTO_ICMPV6) ) ) | 652 | ((af == AF_INET6) && (protocol == IPPROTO_ICMPV6))) |
667 | { | 653 | { |
668 | /* ignore ports */ | 654 | /* ignore ports */ |
669 | destination_port = 0; | 655 | destination_port = 0; |
670 | local_port = 0; | 656 | local_port = 0; |
671 | } | 657 | } |
672 | ri.remote_address.af = af; | 658 | ri.remote_address.af = af; |
673 | if (af == AF_INET) | 659 | if (af == AF_INET) |
674 | ri.remote_address.address.ipv4 = *((struct in_addr*) destination_ip); | 660 | ri.remote_address.address.ipv4 = *((struct in_addr*)destination_ip); |
675 | else | 661 | else |
676 | ri.remote_address.address.ipv6 = * ((struct in6_addr*) destination_ip); | 662 | ri.remote_address.address.ipv6 = *((struct in6_addr*)destination_ip); |
677 | ri.remote_address.port = destination_port; | 663 | ri.remote_address.port = destination_port; |
678 | ri.remote_address.proto = protocol; | 664 | ri.remote_address.proto = protocol; |
679 | ri.local_address.af = af; | 665 | ri.local_address.af = af; |
680 | if (af == AF_INET) | 666 | if (af == AF_INET) |
681 | ri.local_address.address.ipv4 = *((struct in_addr*) local_ip); | 667 | ri.local_address.address.ipv4 = *((struct in_addr*)local_ip); |
682 | else | 668 | else |
683 | ri.local_address.address.ipv6 = * ((struct in6_addr*) local_ip); | 669 | ri.local_address.address.ipv6 = *((struct in6_addr*)local_ip); |
684 | ri.local_address.port = local_port; | 670 | ri.local_address.port = local_port; |
685 | ri.local_address.proto = protocol; | 671 | ri.local_address.proto = protocol; |
686 | hash_redirect_info (&key, | 672 | hash_redirect_info(&key, |
687 | &ri); | 673 | &ri); |
688 | if (NULL != state_key) | 674 | if (NULL != state_key) |
689 | *state_key = key; | 675 | *state_key = key; |
690 | state = GNUNET_CONTAINER_multihashmap_get (connections_map, | 676 | state = GNUNET_CONTAINER_multihashmap_get(connections_map, |
691 | &key); | 677 | &key); |
692 | if (NULL == state) | 678 | if (NULL == state) |
693 | return NULL; | 679 | return NULL; |
694 | /* Mark this connection as freshly used */ | 680 | /* Mark this connection as freshly used */ |
695 | if (NULL == state_key) | 681 | if (NULL == state_key) |
696 | GNUNET_CONTAINER_heap_update_cost (state->specifics.tcp_udp.heap_node, | 682 | GNUNET_CONTAINER_heap_update_cost(state->specifics.tcp_udp.heap_node, |
697 | GNUNET_TIME_absolute_get ().abs_value_us); | 683 | GNUNET_TIME_absolute_get().abs_value_us); |
698 | return state; | 684 | return state; |
699 | } | 685 | } |
700 | 686 | ||
@@ -710,36 +696,36 @@ get_redirect_state (int af, | |||
710 | * #GNUNET_SYSERR to close it (signal serious error) | 696 | * #GNUNET_SYSERR to close it (signal serious error) |
711 | */ | 697 | */ |
712 | static int | 698 | static int |
713 | check_tcp_service (void *cls, | 699 | check_tcp_service(void *cls, |
714 | const struct GNUNET_EXIT_TcpServiceStartMessage *start) | 700 | const struct GNUNET_EXIT_TcpServiceStartMessage *start) |
715 | { | 701 | { |
716 | struct ChannelState *state = cls; | 702 | struct ChannelState *state = cls; |
717 | 703 | ||
718 | if (NULL == state) | 704 | if (NULL == state) |
719 | { | 705 | { |
720 | GNUNET_break_op (0); | 706 | GNUNET_break_op(0); |
721 | return GNUNET_SYSERR; | 707 | return GNUNET_SYSERR; |
722 | } | 708 | } |
723 | if (GNUNET_YES == state->is_dns) | 709 | if (GNUNET_YES == state->is_dns) |
724 | { | 710 | { |
725 | GNUNET_break_op (0); | 711 | GNUNET_break_op(0); |
726 | return GNUNET_SYSERR; | 712 | return GNUNET_SYSERR; |
727 | } | 713 | } |
728 | if (NULL == state->specifics.tcp_udp.serv) | 714 | if (NULL == state->specifics.tcp_udp.serv) |
729 | { | 715 | { |
730 | GNUNET_break_op (0); | 716 | GNUNET_break_op(0); |
731 | return GNUNET_SYSERR; | 717 | return GNUNET_SYSERR; |
732 | } | 718 | } |
733 | if (NULL != state->specifics.tcp_udp.heap_node) | 719 | if (NULL != state->specifics.tcp_udp.heap_node) |
734 | { | 720 | { |
735 | GNUNET_break_op (0); | 721 | GNUNET_break_op(0); |
736 | return GNUNET_SYSERR; | 722 | return GNUNET_SYSERR; |
737 | } | 723 | } |
738 | if (start->tcp_header.off * 4 < sizeof (struct GNUNET_TUN_TcpHeader)) | 724 | if (start->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) |
739 | { | 725 | { |
740 | GNUNET_break_op (0); | 726 | GNUNET_break_op(0); |
741 | return GNUNET_SYSERR; | 727 | return GNUNET_SYSERR; |
742 | } | 728 | } |
743 | return GNUNET_OK; | 729 | return GNUNET_OK; |
744 | } | 730 | } |
745 | 731 | ||
@@ -763,82 +749,86 @@ check_tcp_service (void *cls, | |||
763 | * AND the payload | 749 | * AND the payload |
764 | */ | 750 | */ |
765 | static void | 751 | static void |
766 | prepare_ipv4_packet (const void *payload, | 752 | prepare_ipv4_packet(const void *payload, |
767 | size_t payload_length, | 753 | size_t payload_length, |
768 | int protocol, | 754 | int protocol, |
769 | const struct GNUNET_TUN_TcpHeader *tcp_header, | 755 | const struct GNUNET_TUN_TcpHeader *tcp_header, |
770 | const struct SocketAddress *src_address, | 756 | const struct SocketAddress *src_address, |
771 | const struct SocketAddress *dst_address, | 757 | const struct SocketAddress *dst_address, |
772 | struct GNUNET_TUN_IPv4Header *pkt4) | 758 | struct GNUNET_TUN_IPv4Header *pkt4) |
773 | { | 759 | { |
774 | size_t len; | 760 | size_t len; |
775 | 761 | ||
776 | len = payload_length; | 762 | len = payload_length; |
777 | switch (protocol) | 763 | switch (protocol) |
778 | { | 764 | { |
779 | case IPPROTO_UDP: | 765 | case IPPROTO_UDP: |
780 | len += sizeof (struct GNUNET_TUN_UdpHeader); | 766 | len += sizeof(struct GNUNET_TUN_UdpHeader); |
781 | break; | 767 | break; |
782 | case IPPROTO_TCP: | ||
783 | len += sizeof (struct GNUNET_TUN_TcpHeader); | ||
784 | GNUNET_assert (NULL != tcp_header); | ||
785 | break; | ||
786 | default: | ||
787 | GNUNET_break (0); | ||
788 | return; | ||
789 | } | ||
790 | if (len + sizeof (struct GNUNET_TUN_IPv4Header) > UINT16_MAX) | ||
791 | { | ||
792 | GNUNET_break (0); | ||
793 | return; | ||
794 | } | ||
795 | 768 | ||
796 | GNUNET_TUN_initialize_ipv4_header (pkt4, | 769 | case IPPROTO_TCP: |
797 | protocol, | 770 | len += sizeof(struct GNUNET_TUN_TcpHeader); |
798 | len, | 771 | GNUNET_assert(NULL != tcp_header); |
799 | &src_address->address.ipv4, | 772 | break; |
800 | &dst_address->address.ipv4); | 773 | |
801 | switch (protocol) | 774 | default: |
802 | { | 775 | GNUNET_break(0); |
803 | case IPPROTO_UDP: | 776 | return; |
777 | } | ||
778 | if (len + sizeof(struct GNUNET_TUN_IPv4Header) > UINT16_MAX) | ||
804 | { | 779 | { |
805 | struct GNUNET_TUN_UdpHeader *pkt4_udp = (struct GNUNET_TUN_UdpHeader *) &pkt4[1]; | 780 | GNUNET_break(0); |
781 | return; | ||
782 | } | ||
806 | 783 | ||
807 | pkt4_udp->source_port = htons (src_address->port); | 784 | GNUNET_TUN_initialize_ipv4_header(pkt4, |
808 | pkt4_udp->destination_port = htons (dst_address->port); | 785 | protocol, |
809 | pkt4_udp->len = htons ((uint16_t) payload_length); | 786 | len, |
810 | GNUNET_TUN_calculate_udp4_checksum (pkt4, | 787 | &src_address->address.ipv4, |
811 | pkt4_udp, | 788 | &dst_address->address.ipv4); |
812 | payload, | 789 | switch (protocol) |
813 | payload_length); | 790 | { |
814 | GNUNET_memcpy (&pkt4_udp[1], | 791 | case IPPROTO_UDP: |
815 | payload, | 792 | { |
816 | payload_length); | 793 | struct GNUNET_TUN_UdpHeader *pkt4_udp = (struct GNUNET_TUN_UdpHeader *)&pkt4[1]; |
794 | |||
795 | pkt4_udp->source_port = htons(src_address->port); | ||
796 | pkt4_udp->destination_port = htons(dst_address->port); | ||
797 | pkt4_udp->len = htons((uint16_t)payload_length); | ||
798 | GNUNET_TUN_calculate_udp4_checksum(pkt4, | ||
799 | pkt4_udp, | ||
800 | payload, | ||
801 | payload_length); | ||
802 | GNUNET_memcpy(&pkt4_udp[1], | ||
803 | payload, | ||
804 | payload_length); | ||
817 | } | 805 | } |
818 | break; | 806 | break; |
819 | case IPPROTO_TCP: | 807 | |
808 | case IPPROTO_TCP: | ||
820 | { | 809 | { |
821 | struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct GNUNET_TUN_TcpHeader *) &pkt4[1]; | 810 | struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct GNUNET_TUN_TcpHeader *)&pkt4[1]; |
822 | 811 | ||
823 | *pkt4_tcp = *tcp_header; | 812 | *pkt4_tcp = *tcp_header; |
824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 813 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
825 | "Sending TCP packet from port %u to port %u\n", | 814 | "Sending TCP packet from port %u to port %u\n", |
826 | src_address->port, | 815 | src_address->port, |
827 | dst_address->port); | 816 | dst_address->port); |
828 | pkt4_tcp->source_port = htons (src_address->port); | 817 | pkt4_tcp->source_port = htons(src_address->port); |
829 | pkt4_tcp->destination_port = htons (dst_address->port); | 818 | pkt4_tcp->destination_port = htons(dst_address->port); |
830 | GNUNET_TUN_calculate_tcp4_checksum (pkt4, | 819 | GNUNET_TUN_calculate_tcp4_checksum(pkt4, |
831 | pkt4_tcp, | 820 | pkt4_tcp, |
832 | payload, | 821 | payload, |
833 | payload_length); | 822 | payload_length); |
834 | GNUNET_memcpy (&pkt4_tcp[1], | 823 | GNUNET_memcpy(&pkt4_tcp[1], |
835 | payload, | 824 | payload, |
836 | payload_length); | 825 | payload_length); |
837 | } | 826 | } |
838 | break; | 827 | break; |
839 | default: | 828 | |
840 | GNUNET_assert (0); | 829 | default: |
841 | } | 830 | GNUNET_assert(0); |
831 | } | ||
842 | } | 832 | } |
843 | 833 | ||
844 | 834 | ||
@@ -861,80 +851,84 @@ prepare_ipv4_packet (const void *payload, | |||
861 | * AND the payload | 851 | * AND the payload |
862 | */ | 852 | */ |
863 | static void | 853 | static void |
864 | prepare_ipv6_packet (const void *payload, | 854 | prepare_ipv6_packet(const void *payload, |
865 | size_t payload_length, | 855 | size_t payload_length, |
866 | int protocol, | 856 | int protocol, |
867 | const struct GNUNET_TUN_TcpHeader *tcp_header, | 857 | const struct GNUNET_TUN_TcpHeader *tcp_header, |
868 | const struct SocketAddress *src_address, | 858 | const struct SocketAddress *src_address, |
869 | const struct SocketAddress *dst_address, | 859 | const struct SocketAddress *dst_address, |
870 | struct GNUNET_TUN_IPv6Header *pkt6) | 860 | struct GNUNET_TUN_IPv6Header *pkt6) |
871 | { | 861 | { |
872 | size_t len; | 862 | size_t len; |
873 | 863 | ||
874 | len = payload_length; | 864 | len = payload_length; |
875 | switch (protocol) | 865 | switch (protocol) |
876 | { | 866 | { |
877 | case IPPROTO_UDP: | 867 | case IPPROTO_UDP: |
878 | len += sizeof (struct GNUNET_TUN_UdpHeader); | 868 | len += sizeof(struct GNUNET_TUN_UdpHeader); |
879 | break; | 869 | break; |
880 | case IPPROTO_TCP: | 870 | |
881 | len += sizeof (struct GNUNET_TUN_TcpHeader); | 871 | case IPPROTO_TCP: |
882 | break; | 872 | len += sizeof(struct GNUNET_TUN_TcpHeader); |
883 | default: | 873 | break; |
884 | GNUNET_break (0); | 874 | |
885 | return; | 875 | default: |
886 | } | 876 | GNUNET_break(0); |
877 | return; | ||
878 | } | ||
887 | if (len > UINT16_MAX) | 879 | if (len > UINT16_MAX) |
888 | { | 880 | { |
889 | GNUNET_break (0); | 881 | GNUNET_break(0); |
890 | return; | 882 | return; |
891 | } | 883 | } |
892 | 884 | ||
893 | GNUNET_TUN_initialize_ipv6_header (pkt6, | 885 | GNUNET_TUN_initialize_ipv6_header(pkt6, |
894 | protocol, | 886 | protocol, |
895 | len, | 887 | len, |
896 | &src_address->address.ipv6, | 888 | &src_address->address.ipv6, |
897 | &dst_address->address.ipv6); | 889 | &dst_address->address.ipv6); |
898 | 890 | ||
899 | switch (protocol) | 891 | switch (protocol) |
900 | { | ||
901 | case IPPROTO_UDP: | ||
902 | { | 892 | { |
903 | struct GNUNET_TUN_UdpHeader *pkt6_udp = (struct GNUNET_TUN_UdpHeader *) &pkt6[1]; | 893 | case IPPROTO_UDP: |
904 | 894 | { | |
905 | pkt6_udp->source_port = htons (src_address->port); | 895 | struct GNUNET_TUN_UdpHeader *pkt6_udp = (struct GNUNET_TUN_UdpHeader *)&pkt6[1]; |
906 | pkt6_udp->destination_port = htons (dst_address->port); | 896 | |
907 | pkt6_udp->len = htons ((uint16_t) payload_length); | 897 | pkt6_udp->source_port = htons(src_address->port); |
908 | GNUNET_TUN_calculate_udp6_checksum (pkt6, | 898 | pkt6_udp->destination_port = htons(dst_address->port); |
909 | pkt6_udp, | 899 | pkt6_udp->len = htons((uint16_t)payload_length); |
910 | payload, | 900 | GNUNET_TUN_calculate_udp6_checksum(pkt6, |
911 | payload_length); | 901 | pkt6_udp, |
912 | GNUNET_memcpy (&pkt6_udp[1], | 902 | payload, |
913 | payload, | 903 | payload_length); |
914 | payload_length); | 904 | GNUNET_memcpy(&pkt6_udp[1], |
905 | payload, | ||
906 | payload_length); | ||
915 | } | 907 | } |
916 | break; | 908 | break; |
917 | case IPPROTO_TCP: | 909 | |
910 | case IPPROTO_TCP: | ||
918 | { | 911 | { |
919 | struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct GNUNET_TUN_TcpHeader *) &pkt6[1]; | 912 | struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct GNUNET_TUN_TcpHeader *)&pkt6[1]; |
920 | 913 | ||
921 | /* GNUNET_memcpy first here as some TCP header fields are initialized this way! */ | 914 | /* GNUNET_memcpy first here as some TCP header fields are initialized this way! */ |
922 | *pkt6_tcp = *tcp_header; | 915 | *pkt6_tcp = *tcp_header; |
923 | pkt6_tcp->source_port = htons (src_address->port); | 916 | pkt6_tcp->source_port = htons(src_address->port); |
924 | pkt6_tcp->destination_port = htons (dst_address->port); | 917 | pkt6_tcp->destination_port = htons(dst_address->port); |
925 | GNUNET_TUN_calculate_tcp6_checksum (pkt6, | 918 | GNUNET_TUN_calculate_tcp6_checksum(pkt6, |
926 | pkt6_tcp, | 919 | pkt6_tcp, |
927 | payload, | 920 | payload, |
928 | payload_length); | 921 | payload_length); |
929 | GNUNET_memcpy (&pkt6_tcp[1], | 922 | GNUNET_memcpy(&pkt6_tcp[1], |
930 | payload, | 923 | payload, |
931 | payload_length); | 924 | payload_length); |
932 | } | 925 | } |
933 | break; | 926 | break; |
934 | default: | 927 | |
935 | GNUNET_assert (0); | 928 | default: |
936 | break; | 929 | GNUNET_assert(0); |
937 | } | 930 | break; |
931 | } | ||
938 | } | 932 | } |
939 | 933 | ||
940 | 934 | ||
@@ -948,93 +942,97 @@ prepare_ipv6_packet (const void *payload, | |||
948 | * @param payload_length number of bytes in @a payload | 942 | * @param payload_length number of bytes in @a payload |
949 | */ | 943 | */ |
950 | static void | 944 | static void |
951 | send_tcp_packet_via_tun (const struct SocketAddress *destination_address, | 945 | send_tcp_packet_via_tun(const struct SocketAddress *destination_address, |
952 | const struct SocketAddress *source_address, | 946 | const struct SocketAddress *source_address, |
953 | const struct GNUNET_TUN_TcpHeader *tcp_header, | 947 | const struct GNUNET_TUN_TcpHeader *tcp_header, |
954 | const void *payload, | 948 | const void *payload, |
955 | size_t payload_length) | 949 | size_t payload_length) |
956 | { | 950 | { |
957 | size_t len; | 951 | size_t len; |
958 | 952 | ||
959 | GNUNET_STATISTICS_update (stats, | 953 | GNUNET_STATISTICS_update(stats, |
960 | gettext_noop ("# TCP packets sent via TUN"), | 954 | gettext_noop("# TCP packets sent via TUN"), |
961 | 1, | 955 | 1, |
962 | GNUNET_NO); | 956 | GNUNET_NO); |
963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 957 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
964 | "Sending packet with %u bytes TCP payload via TUN\n", | 958 | "Sending packet with %u bytes TCP payload via TUN\n", |
965 | (unsigned int) payload_length); | 959 | (unsigned int)payload_length); |
966 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader); | 960 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_TUN_Layer2PacketHeader); |
967 | switch (source_address->af) | 961 | switch (source_address->af) |
968 | { | 962 | { |
969 | case AF_INET: | 963 | case AF_INET: |
970 | len += sizeof (struct GNUNET_TUN_IPv4Header); | 964 | len += sizeof(struct GNUNET_TUN_IPv4Header); |
971 | break; | 965 | break; |
972 | case AF_INET6: | 966 | |
973 | len += sizeof (struct GNUNET_TUN_IPv6Header); | 967 | case AF_INET6: |
974 | break; | 968 | len += sizeof(struct GNUNET_TUN_IPv6Header); |
975 | default: | 969 | break; |
976 | GNUNET_break (0); | 970 | |
977 | return; | 971 | default: |
978 | } | 972 | GNUNET_break(0); |
979 | len += sizeof (struct GNUNET_TUN_TcpHeader); | 973 | return; |
974 | } | ||
975 | len += sizeof(struct GNUNET_TUN_TcpHeader); | ||
980 | len += payload_length; | 976 | len += payload_length; |
981 | if (len >= GNUNET_MAX_MESSAGE_SIZE) | 977 | if (len >= GNUNET_MAX_MESSAGE_SIZE) |
982 | { | 978 | { |
983 | GNUNET_break (0); | 979 | GNUNET_break(0); |
984 | return; | 980 | return; |
985 | } | 981 | } |
986 | { | 982 | { |
987 | char buf[len] GNUNET_ALIGN; | 983 | char buf[len] GNUNET_ALIGN; |
988 | struct GNUNET_MessageHeader *hdr; | 984 | struct GNUNET_MessageHeader *hdr; |
989 | struct GNUNET_TUN_Layer2PacketHeader *tun; | 985 | struct GNUNET_TUN_Layer2PacketHeader *tun; |
990 | 986 | ||
991 | hdr = (struct GNUNET_MessageHeader *) buf; | 987 | hdr = (struct GNUNET_MessageHeader *)buf; |
992 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 988 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); |
993 | hdr->size = htons (len); | 989 | hdr->size = htons(len); |
994 | tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1]; | 990 | tun = (struct GNUNET_TUN_Layer2PacketHeader*)&hdr[1]; |
995 | tun->flags = htons (0); | 991 | tun->flags = htons(0); |
996 | switch (source_address->af) | 992 | switch (source_address->af) |
997 | { | ||
998 | case AF_INET: | ||
999 | { | 993 | { |
1000 | struct GNUNET_TUN_IPv4Header *ipv4 | 994 | case AF_INET: |
1001 | = (struct GNUNET_TUN_IPv4Header*) &tun[1]; | 995 | { |
1002 | 996 | struct GNUNET_TUN_IPv4Header *ipv4 | |
1003 | tun->proto = htons (ETH_P_IPV4); | 997 | = (struct GNUNET_TUN_IPv4Header*)&tun[1]; |
1004 | prepare_ipv4_packet (payload, | 998 | |
1005 | payload_length, | 999 | tun->proto = htons(ETH_P_IPV4); |
1006 | IPPROTO_TCP, | 1000 | prepare_ipv4_packet(payload, |
1007 | tcp_header, | 1001 | payload_length, |
1008 | source_address, | 1002 | IPPROTO_TCP, |
1009 | destination_address, | 1003 | tcp_header, |
1010 | ipv4); | 1004 | source_address, |
1005 | destination_address, | ||
1006 | ipv4); | ||
1011 | } | 1007 | } |
1012 | break; | 1008 | break; |
1013 | case AF_INET6: | 1009 | |
1010 | case AF_INET6: | ||
1014 | { | 1011 | { |
1015 | struct GNUNET_TUN_IPv6Header *ipv6 | 1012 | struct GNUNET_TUN_IPv6Header *ipv6 |
1016 | = (struct GNUNET_TUN_IPv6Header*) &tun[1]; | 1013 | = (struct GNUNET_TUN_IPv6Header*)&tun[1]; |
1017 | 1014 | ||
1018 | tun->proto = htons (ETH_P_IPV6); | 1015 | tun->proto = htons(ETH_P_IPV6); |
1019 | prepare_ipv6_packet (payload, | 1016 | prepare_ipv6_packet(payload, |
1020 | payload_length, | 1017 | payload_length, |
1021 | IPPROTO_TCP, | 1018 | IPPROTO_TCP, |
1022 | tcp_header, | 1019 | tcp_header, |
1023 | source_address, | 1020 | source_address, |
1024 | destination_address, | 1021 | destination_address, |
1025 | ipv6); | 1022 | ipv6); |
1026 | } | 1023 | } |
1027 | break; | 1024 | break; |
1028 | default: | 1025 | |
1029 | GNUNET_assert (0); | 1026 | default: |
1030 | break; | 1027 | GNUNET_assert(0); |
1031 | } | 1028 | break; |
1029 | } | ||
1032 | if (NULL != helper_handle) | 1030 | if (NULL != helper_handle) |
1033 | (void) GNUNET_HELPER_send (helper_handle, | 1031 | (void)GNUNET_HELPER_send(helper_handle, |
1034 | (const struct GNUNET_MessageHeader*) buf, | 1032 | (const struct GNUNET_MessageHeader*)buf, |
1035 | GNUNET_YES, | 1033 | GNUNET_YES, |
1036 | NULL, | 1034 | NULL, |
1037 | NULL); | 1035 | NULL); |
1038 | } | 1036 | } |
1039 | } | 1037 | } |
1040 | 1038 | ||
@@ -1049,94 +1047,98 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address, | |||
1049 | * @param payload_length number of bytes of data in @a payload | 1047 | * @param payload_length number of bytes of data in @a payload |
1050 | */ | 1048 | */ |
1051 | static void | 1049 | static void |
1052 | send_icmp_packet_via_tun (const struct SocketAddress *destination_address, | 1050 | send_icmp_packet_via_tun(const struct SocketAddress *destination_address, |
1053 | const struct SocketAddress *source_address, | 1051 | const struct SocketAddress *source_address, |
1054 | const struct GNUNET_TUN_IcmpHeader *icmp_header, | 1052 | const struct GNUNET_TUN_IcmpHeader *icmp_header, |
1055 | const void *payload, size_t payload_length) | 1053 | const void *payload, size_t payload_length) |
1056 | { | 1054 | { |
1057 | size_t len; | 1055 | size_t len; |
1058 | struct GNUNET_TUN_IcmpHeader *icmp; | 1056 | struct GNUNET_TUN_IcmpHeader *icmp; |
1059 | 1057 | ||
1060 | GNUNET_STATISTICS_update (stats, | 1058 | GNUNET_STATISTICS_update(stats, |
1061 | gettext_noop ("# ICMP packets sent via TUN"), | 1059 | gettext_noop("# ICMP packets sent via TUN"), |
1062 | 1, GNUNET_NO); | 1060 | 1, GNUNET_NO); |
1063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1061 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1064 | "Sending packet with %u bytes ICMP payload via TUN\n", | 1062 | "Sending packet with %u bytes ICMP payload via TUN\n", |
1065 | (unsigned int) payload_length); | 1063 | (unsigned int)payload_length); |
1066 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader); | 1064 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_TUN_Layer2PacketHeader); |
1067 | switch (destination_address->af) | 1065 | switch (destination_address->af) |
1068 | { | 1066 | { |
1069 | case AF_INET: | 1067 | case AF_INET: |
1070 | len += sizeof (struct GNUNET_TUN_IPv4Header); | 1068 | len += sizeof(struct GNUNET_TUN_IPv4Header); |
1071 | break; | 1069 | break; |
1072 | case AF_INET6: | 1070 | |
1073 | len += sizeof (struct GNUNET_TUN_IPv6Header); | 1071 | case AF_INET6: |
1074 | break; | 1072 | len += sizeof(struct GNUNET_TUN_IPv6Header); |
1075 | default: | 1073 | break; |
1076 | GNUNET_break (0); | 1074 | |
1077 | return; | 1075 | default: |
1078 | } | 1076 | GNUNET_break(0); |
1079 | len += sizeof (struct GNUNET_TUN_IcmpHeader); | 1077 | return; |
1078 | } | ||
1079 | len += sizeof(struct GNUNET_TUN_IcmpHeader); | ||
1080 | len += payload_length; | 1080 | len += payload_length; |
1081 | if (len >= GNUNET_MAX_MESSAGE_SIZE) | 1081 | if (len >= GNUNET_MAX_MESSAGE_SIZE) |
1082 | { | 1082 | { |
1083 | GNUNET_break (0); | 1083 | GNUNET_break(0); |
1084 | return; | 1084 | return; |
1085 | } | 1085 | } |
1086 | { | 1086 | { |
1087 | char buf[len] GNUNET_ALIGN; | 1087 | char buf[len] GNUNET_ALIGN; |
1088 | struct GNUNET_MessageHeader *hdr; | 1088 | struct GNUNET_MessageHeader *hdr; |
1089 | struct GNUNET_TUN_Layer2PacketHeader *tun; | 1089 | struct GNUNET_TUN_Layer2PacketHeader *tun; |
1090 | 1090 | ||
1091 | hdr= (struct GNUNET_MessageHeader *) buf; | 1091 | hdr = (struct GNUNET_MessageHeader *)buf; |
1092 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1092 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1093 | hdr->size = htons (len); | 1093 | hdr->size = htons(len); |
1094 | tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1]; | 1094 | tun = (struct GNUNET_TUN_Layer2PacketHeader*)&hdr[1]; |
1095 | tun->flags = htons (0); | 1095 | tun->flags = htons(0); |
1096 | switch (source_address->af) | 1096 | switch (source_address->af) |
1097 | { | ||
1098 | case AF_INET: | ||
1099 | { | 1097 | { |
1100 | struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1]; | 1098 | case AF_INET: |
1101 | 1099 | { | |
1102 | tun->proto = htons (ETH_P_IPV4); | 1100 | struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*)&tun[1]; |
1103 | GNUNET_TUN_initialize_ipv4_header (ipv4, | 1101 | |
1104 | IPPROTO_ICMP, | 1102 | tun->proto = htons(ETH_P_IPV4); |
1105 | sizeof (struct GNUNET_TUN_IcmpHeader) + payload_length, | 1103 | GNUNET_TUN_initialize_ipv4_header(ipv4, |
1106 | &source_address->address.ipv4, | 1104 | IPPROTO_ICMP, |
1107 | &destination_address->address.ipv4); | 1105 | sizeof(struct GNUNET_TUN_IcmpHeader) + payload_length, |
1108 | icmp = (struct GNUNET_TUN_IcmpHeader*) &ipv4[1]; | 1106 | &source_address->address.ipv4, |
1107 | &destination_address->address.ipv4); | ||
1108 | icmp = (struct GNUNET_TUN_IcmpHeader*)&ipv4[1]; | ||
1109 | } | 1109 | } |
1110 | break; | 1110 | break; |
1111 | case AF_INET6: | 1111 | |
1112 | case AF_INET6: | ||
1112 | { | 1113 | { |
1113 | struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1]; | 1114 | struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*)&tun[1]; |
1114 | 1115 | ||
1115 | tun->proto = htons (ETH_P_IPV6); | 1116 | tun->proto = htons(ETH_P_IPV6); |
1116 | GNUNET_TUN_initialize_ipv6_header (ipv6, | 1117 | GNUNET_TUN_initialize_ipv6_header(ipv6, |
1117 | IPPROTO_ICMPV6, | 1118 | IPPROTO_ICMPV6, |
1118 | sizeof (struct GNUNET_TUN_IcmpHeader) + payload_length, | 1119 | sizeof(struct GNUNET_TUN_IcmpHeader) + payload_length, |
1119 | &source_address->address.ipv6, | 1120 | &source_address->address.ipv6, |
1120 | &destination_address->address.ipv6); | 1121 | &destination_address->address.ipv6); |
1121 | icmp = (struct GNUNET_TUN_IcmpHeader*) &ipv6[1]; | 1122 | icmp = (struct GNUNET_TUN_IcmpHeader*)&ipv6[1]; |
1122 | } | 1123 | } |
1123 | break; | 1124 | break; |
1124 | default: | 1125 | |
1125 | GNUNET_assert (0); | 1126 | default: |
1126 | break; | 1127 | GNUNET_assert(0); |
1127 | } | 1128 | break; |
1129 | } | ||
1128 | *icmp = *icmp_header; | 1130 | *icmp = *icmp_header; |
1129 | GNUNET_memcpy (&icmp[1], | 1131 | GNUNET_memcpy(&icmp[1], |
1130 | payload, | 1132 | payload, |
1131 | payload_length); | 1133 | payload_length); |
1132 | GNUNET_TUN_calculate_icmp_checksum (icmp, | 1134 | GNUNET_TUN_calculate_icmp_checksum(icmp, |
1133 | payload, | 1135 | payload, |
1134 | payload_length); | 1136 | payload_length); |
1135 | if (NULL != helper_handle) | 1137 | if (NULL != helper_handle) |
1136 | (void) GNUNET_HELPER_send (helper_handle, | 1138 | (void)GNUNET_HELPER_send(helper_handle, |
1137 | (const struct GNUNET_MessageHeader*) buf, | 1139 | (const struct GNUNET_MessageHeader*)buf, |
1138 | GNUNET_YES, | 1140 | GNUNET_YES, |
1139 | NULL, NULL); | 1141 | NULL, NULL); |
1140 | } | 1142 | } |
1141 | } | 1143 | } |
1142 | 1144 | ||
@@ -1150,24 +1152,24 @@ send_icmp_packet_via_tun (const struct SocketAddress *destination_address, | |||
1150 | * @param local_address address to initialize | 1152 | * @param local_address address to initialize |
1151 | */ | 1153 | */ |
1152 | static void | 1154 | static void |
1153 | setup_fresh_address (int af, | 1155 | setup_fresh_address(int af, |
1154 | uint8_t proto, | 1156 | uint8_t proto, |
1155 | struct SocketAddress *local_address) | 1157 | struct SocketAddress *local_address) |
1156 | { | 1158 | { |
1157 | local_address->af = af; | 1159 | local_address->af = af; |
1158 | local_address->proto = (uint8_t) proto; | 1160 | local_address->proto = (uint8_t)proto; |
1159 | /* default "local" port range is often 32768--61000, | 1161 | /* default "local" port range is often 32768--61000, |
1160 | so we pick a random value in that range */ | 1162 | so we pick a random value in that range */ |
1161 | if ( ( (af == AF_INET) && (proto == IPPROTO_ICMP) ) || | 1163 | if (((af == AF_INET) && (proto == IPPROTO_ICMP)) || |
1162 | ( (af == AF_INET6) && (proto == IPPROTO_ICMPV6) ) ) | 1164 | ((af == AF_INET6) && (proto == IPPROTO_ICMPV6))) |
1163 | local_address->port = 0; | 1165 | local_address->port = 0; |
1164 | else | 1166 | else |
1165 | local_address->port | 1167 | local_address->port |
1166 | = (uint16_t) 32768 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1168 | = (uint16_t)32768 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1167 | 28232); | 1169 | 28232); |
1168 | switch (af) | 1170 | switch (af) |
1169 | { | 1171 | { |
1170 | case AF_INET: | 1172 | case AF_INET: |
1171 | { | 1173 | { |
1172 | struct in_addr addr; | 1174 | struct in_addr addr; |
1173 | struct in_addr mask; | 1175 | struct in_addr mask; |
@@ -1176,26 +1178,27 @@ setup_fresh_address (int af, | |||
1176 | addr = exit_ipv4addr; | 1178 | addr = exit_ipv4addr; |
1177 | mask = exit_ipv4mask; | 1179 | mask = exit_ipv4mask; |
1178 | if (0 == ~mask.s_addr) | 1180 | if (0 == ~mask.s_addr) |
1179 | { | 1181 | { |
1180 | /* only one valid IP anyway */ | 1182 | /* only one valid IP anyway */ |
1181 | local_address->address.ipv4 = addr; | 1183 | local_address->address.ipv4 = addr; |
1182 | return; | 1184 | return; |
1183 | } | 1185 | } |
1184 | /* Given 192.168.0.1/255.255.0.0, we want a mask | 1186 | /* Given 192.168.0.1/255.255.0.0, we want a mask |
1185 | of '192.168.255.255', thus: */ | 1187 | of '192.168.255.255', thus: */ |
1186 | mask.s_addr = addr.s_addr | ~mask.s_addr; | 1188 | mask.s_addr = addr.s_addr | ~mask.s_addr; |
1187 | /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ | 1189 | /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ |
1188 | do | 1190 | do |
1189 | { | 1191 | { |
1190 | rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1192 | rnd.s_addr = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1191 | UINT32_MAX); | 1193 | UINT32_MAX); |
1192 | local_address->address.ipv4.s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; | 1194 | local_address->address.ipv4.s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; |
1193 | } | 1195 | } |
1194 | while ( (local_address->address.ipv4.s_addr == addr.s_addr) || | 1196 | while ((local_address->address.ipv4.s_addr == addr.s_addr) || |
1195 | (local_address->address.ipv4.s_addr == mask.s_addr) ); | 1197 | (local_address->address.ipv4.s_addr == mask.s_addr)); |
1196 | } | 1198 | } |
1197 | break; | 1199 | break; |
1198 | case AF_INET6: | 1200 | |
1201 | case AF_INET6: | ||
1199 | { | 1202 | { |
1200 | struct in6_addr addr; | 1203 | struct in6_addr addr; |
1201 | struct in6_addr mask; | 1204 | struct in6_addr mask; |
@@ -1203,39 +1206,40 @@ setup_fresh_address (int af, | |||
1203 | int i; | 1206 | int i; |
1204 | 1207 | ||
1205 | addr = exit_ipv6addr; | 1208 | addr = exit_ipv6addr; |
1206 | GNUNET_assert (ipv6prefix < 128); | 1209 | GNUNET_assert(ipv6prefix < 128); |
1207 | if (ipv6prefix == 127) | 1210 | if (ipv6prefix == 127) |
1208 | { | 1211 | { |
1209 | /* only one valid IP anyway */ | 1212 | /* only one valid IP anyway */ |
1210 | local_address->address.ipv6 = addr; | 1213 | local_address->address.ipv6 = addr; |
1211 | return; | 1214 | return; |
1212 | } | 1215 | } |
1213 | /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, | 1216 | /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, |
1214 | thus: */ | 1217 | thus: */ |
1215 | mask = addr; | 1218 | mask = addr; |
1216 | for (i=127;i>=ipv6prefix;i--) | 1219 | for (i = 127; i >= ipv6prefix; i--) |
1217 | mask.s6_addr[i / 8] |= (1 << (i % 8)); | 1220 | mask.s6_addr[i / 8] |= (1 << (i % 8)); |
1218 | 1221 | ||
1219 | /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ | 1222 | /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ |
1220 | do | 1223 | do |
1221 | { | 1224 | { |
1222 | for (i=0;i<16;i++) | 1225 | for (i = 0; i < 16; i++) |
1223 | { | 1226 | { |
1224 | rnd.s6_addr[i] = (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1227 | rnd.s6_addr[i] = (unsigned char)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1225 | 256); | 1228 | 256); |
1226 | local_address->address.ipv6.s6_addr[i] | 1229 | local_address->address.ipv6.s6_addr[i] |
1227 | = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; | 1230 | = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; |
1228 | } | 1231 | } |
1229 | } | 1232 | } |
1230 | while ( (0 == GNUNET_memcmp (&local_address->address.ipv6, | 1233 | while ((0 == GNUNET_memcmp(&local_address->address.ipv6, |
1231 | &addr)) || | 1234 | &addr)) || |
1232 | (0 == GNUNET_memcmp (&local_address->address.ipv6, | 1235 | (0 == GNUNET_memcmp(&local_address->address.ipv6, |
1233 | &mask)) ); | 1236 | &mask))); |
1234 | } | 1237 | } |
1235 | break; | 1238 | break; |
1236 | default: | 1239 | |
1237 | GNUNET_assert (0); | 1240 | default: |
1238 | } | 1241 | GNUNET_assert(0); |
1242 | } | ||
1239 | } | 1243 | } |
1240 | 1244 | ||
1241 | 1245 | ||
@@ -1261,61 +1265,62 @@ setup_fresh_address (int af, | |||
1261 | * used to test if a state has been fully setup). | 1265 | * used to test if a state has been fully setup). |
1262 | */ | 1266 | */ |
1263 | static void | 1267 | static void |
1264 | setup_state_record (struct ChannelState *state) | 1268 | setup_state_record(struct ChannelState *state) |
1265 | { | 1269 | { |
1266 | struct GNUNET_HashCode key; | 1270 | struct GNUNET_HashCode key; |
1267 | struct ChannelState *s; | 1271 | struct ChannelState *s; |
1268 | 1272 | ||
1269 | /* generate fresh, unique address */ | 1273 | /* generate fresh, unique address */ |
1270 | do | 1274 | do |
1271 | { | 1275 | { |
1272 | if (NULL == state->specifics.tcp_udp.serv) | 1276 | if (NULL == state->specifics.tcp_udp.serv) |
1273 | setup_fresh_address (state->specifics.tcp_udp.ri.remote_address.af, | 1277 | setup_fresh_address(state->specifics.tcp_udp.ri.remote_address.af, |
1274 | state->specifics.tcp_udp.ri.remote_address.proto, | 1278 | state->specifics.tcp_udp.ri.remote_address.proto, |
1275 | &state->specifics.tcp_udp.ri.local_address); | 1279 | &state->specifics.tcp_udp.ri.local_address); |
1276 | else | 1280 | else |
1277 | setup_fresh_address (state->specifics.tcp_udp.serv->address.af, | 1281 | setup_fresh_address(state->specifics.tcp_udp.serv->address.af, |
1278 | state->specifics.tcp_udp.serv->address.proto, | 1282 | state->specifics.tcp_udp.serv->address.proto, |
1279 | &state->specifics.tcp_udp.ri.local_address); | 1283 | &state->specifics.tcp_udp.ri.local_address); |
1280 | } while (NULL != | 1284 | } |
1281 | get_redirect_state (state->specifics.tcp_udp.ri.remote_address.af, | 1285 | while (NULL != |
1282 | state->specifics.tcp_udp.ri.remote_address.proto, | 1286 | get_redirect_state(state->specifics.tcp_udp.ri.remote_address.af, |
1283 | &state->specifics.tcp_udp.ri.remote_address.address, | 1287 | state->specifics.tcp_udp.ri.remote_address.proto, |
1284 | state->specifics.tcp_udp.ri.remote_address.port, | 1288 | &state->specifics.tcp_udp.ri.remote_address.address, |
1285 | &state->specifics.tcp_udp.ri.local_address.address, | 1289 | state->specifics.tcp_udp.ri.remote_address.port, |
1286 | state->specifics.tcp_udp.ri.local_address.port, | 1290 | &state->specifics.tcp_udp.ri.local_address.address, |
1287 | &key)); | 1291 | state->specifics.tcp_udp.ri.local_address.port, |
1292 | &key)); | ||
1288 | { | 1293 | { |
1289 | char buf[INET6_ADDRSTRLEN]; | 1294 | char buf[INET6_ADDRSTRLEN]; |
1290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1291 | "Picked local address %s:%u for new connection\n", | 1296 | "Picked local address %s:%u for new connection\n", |
1292 | inet_ntop (state->specifics.tcp_udp.ri.local_address.af, | 1297 | inet_ntop(state->specifics.tcp_udp.ri.local_address.af, |
1293 | &state->specifics.tcp_udp.ri.local_address.address, | 1298 | &state->specifics.tcp_udp.ri.local_address.address, |
1294 | buf, | 1299 | buf, |
1295 | sizeof (buf)), | 1300 | sizeof(buf)), |
1296 | (unsigned int) state->specifics.tcp_udp.ri.local_address.port); | 1301 | (unsigned int)state->specifics.tcp_udp.ri.local_address.port); |
1297 | } | 1302 | } |
1298 | state->specifics.tcp_udp.state_key = key; | 1303 | state->specifics.tcp_udp.state_key = key; |
1299 | GNUNET_assert (GNUNET_OK == | 1304 | GNUNET_assert(GNUNET_OK == |
1300 | GNUNET_CONTAINER_multihashmap_put (connections_map, | 1305 | GNUNET_CONTAINER_multihashmap_put(connections_map, |
1301 | &key, state, | 1306 | &key, state, |
1302 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1307 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1303 | state->specifics.tcp_udp.heap_node | 1308 | state->specifics.tcp_udp.heap_node |
1304 | = GNUNET_CONTAINER_heap_insert (connections_heap, | 1309 | = GNUNET_CONTAINER_heap_insert(connections_heap, |
1305 | state, | 1310 | state, |
1306 | GNUNET_TIME_absolute_get ().abs_value_us); | 1311 | GNUNET_TIME_absolute_get().abs_value_us); |
1307 | while (GNUNET_CONTAINER_heap_get_size (connections_heap) > max_connections) | 1312 | while (GNUNET_CONTAINER_heap_get_size(connections_heap) > max_connections) |
1308 | { | 1313 | { |
1309 | s = GNUNET_CONTAINER_heap_remove_root (connections_heap); | 1314 | s = GNUNET_CONTAINER_heap_remove_root(connections_heap); |
1310 | GNUNET_assert (state != s); | 1315 | GNUNET_assert(state != s); |
1311 | s->specifics.tcp_udp.heap_node = NULL; | 1316 | s->specifics.tcp_udp.heap_node = NULL; |
1312 | GNUNET_CADET_channel_destroy (s->channel); | 1317 | GNUNET_CADET_channel_destroy(s->channel); |
1313 | GNUNET_assert (GNUNET_OK == | 1318 | GNUNET_assert(GNUNET_OK == |
1314 | GNUNET_CONTAINER_multihashmap_remove (connections_map, | 1319 | GNUNET_CONTAINER_multihashmap_remove(connections_map, |
1315 | &s->specifics.tcp_udp.state_key, | 1320 | &s->specifics.tcp_udp.state_key, |
1316 | s)); | 1321 | s)); |
1317 | GNUNET_free (s); | 1322 | GNUNET_free(s); |
1318 | } | 1323 | } |
1319 | } | 1324 | } |
1320 | 1325 | ||
1321 | 1326 | ||
@@ -1328,87 +1333,91 @@ setup_state_record (struct ChannelState *state) | |||
1328 | * @param payload_length number of bytes of data in @a payload | 1333 | * @param payload_length number of bytes of data in @a payload |
1329 | */ | 1334 | */ |
1330 | static void | 1335 | static void |
1331 | send_udp_packet_via_tun (const struct SocketAddress *destination_address, | 1336 | send_udp_packet_via_tun(const struct SocketAddress *destination_address, |
1332 | const struct SocketAddress *source_address, | 1337 | const struct SocketAddress *source_address, |
1333 | const void *payload, size_t payload_length) | 1338 | const void *payload, size_t payload_length) |
1334 | { | 1339 | { |
1335 | size_t len; | 1340 | size_t len; |
1336 | 1341 | ||
1337 | GNUNET_STATISTICS_update (stats, | 1342 | GNUNET_STATISTICS_update(stats, |
1338 | gettext_noop ("# UDP packets sent via TUN"), | 1343 | gettext_noop("# UDP packets sent via TUN"), |
1339 | 1, GNUNET_NO); | 1344 | 1, GNUNET_NO); |
1340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1345 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1341 | "Sending packet with %u bytes UDP payload via TUN\n", | 1346 | "Sending packet with %u bytes UDP payload via TUN\n", |
1342 | (unsigned int) payload_length); | 1347 | (unsigned int)payload_length); |
1343 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader); | 1348 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_TUN_Layer2PacketHeader); |
1344 | switch (source_address->af) | 1349 | switch (source_address->af) |
1345 | { | 1350 | { |
1346 | case AF_INET: | 1351 | case AF_INET: |
1347 | len += sizeof (struct GNUNET_TUN_IPv4Header); | 1352 | len += sizeof(struct GNUNET_TUN_IPv4Header); |
1348 | break; | 1353 | break; |
1349 | case AF_INET6: | 1354 | |
1350 | len += sizeof (struct GNUNET_TUN_IPv6Header); | 1355 | case AF_INET6: |
1351 | break; | 1356 | len += sizeof(struct GNUNET_TUN_IPv6Header); |
1352 | default: | 1357 | break; |
1353 | GNUNET_break (0); | 1358 | |
1354 | return; | 1359 | default: |
1355 | } | 1360 | GNUNET_break(0); |
1356 | len += sizeof (struct GNUNET_TUN_UdpHeader); | 1361 | return; |
1362 | } | ||
1363 | len += sizeof(struct GNUNET_TUN_UdpHeader); | ||
1357 | len += payload_length; | 1364 | len += payload_length; |
1358 | if (len >= GNUNET_MAX_MESSAGE_SIZE) | 1365 | if (len >= GNUNET_MAX_MESSAGE_SIZE) |
1359 | { | 1366 | { |
1360 | GNUNET_break (0); | 1367 | GNUNET_break(0); |
1361 | return; | 1368 | return; |
1362 | } | 1369 | } |
1363 | { | 1370 | { |
1364 | char buf[len] GNUNET_ALIGN; | 1371 | char buf[len] GNUNET_ALIGN; |
1365 | struct GNUNET_MessageHeader *hdr; | 1372 | struct GNUNET_MessageHeader *hdr; |
1366 | struct GNUNET_TUN_Layer2PacketHeader *tun; | 1373 | struct GNUNET_TUN_Layer2PacketHeader *tun; |
1367 | 1374 | ||
1368 | hdr= (struct GNUNET_MessageHeader *) buf; | 1375 | hdr = (struct GNUNET_MessageHeader *)buf; |
1369 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1376 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1370 | hdr->size = htons (len); | 1377 | hdr->size = htons(len); |
1371 | tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1]; | 1378 | tun = (struct GNUNET_TUN_Layer2PacketHeader*)&hdr[1]; |
1372 | tun->flags = htons (0); | 1379 | tun->flags = htons(0); |
1373 | switch (source_address->af) | 1380 | switch (source_address->af) |
1374 | { | ||
1375 | case AF_INET: | ||
1376 | { | 1381 | { |
1377 | struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1]; | 1382 | case AF_INET: |
1378 | 1383 | { | |
1379 | tun->proto = htons (ETH_P_IPV4); | 1384 | struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*)&tun[1]; |
1380 | prepare_ipv4_packet (payload, | 1385 | |
1381 | payload_length, | 1386 | tun->proto = htons(ETH_P_IPV4); |
1382 | IPPROTO_UDP, | 1387 | prepare_ipv4_packet(payload, |
1383 | NULL, | 1388 | payload_length, |
1384 | source_address, | 1389 | IPPROTO_UDP, |
1385 | destination_address, | 1390 | NULL, |
1386 | ipv4); | 1391 | source_address, |
1392 | destination_address, | ||
1393 | ipv4); | ||
1387 | } | 1394 | } |
1388 | break; | 1395 | break; |
1389 | case AF_INET6: | 1396 | |
1397 | case AF_INET6: | ||
1390 | { | 1398 | { |
1391 | struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1]; | 1399 | struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*)&tun[1]; |
1392 | 1400 | ||
1393 | tun->proto = htons (ETH_P_IPV6); | 1401 | tun->proto = htons(ETH_P_IPV6); |
1394 | prepare_ipv6_packet (payload, | 1402 | prepare_ipv6_packet(payload, |
1395 | payload_length, | 1403 | payload_length, |
1396 | IPPROTO_UDP, | 1404 | IPPROTO_UDP, |
1397 | NULL, | 1405 | NULL, |
1398 | source_address, | 1406 | source_address, |
1399 | destination_address, | 1407 | destination_address, |
1400 | ipv6); | 1408 | ipv6); |
1401 | } | 1409 | } |
1402 | break; | 1410 | break; |
1403 | default: | 1411 | |
1404 | GNUNET_assert (0); | 1412 | default: |
1405 | break; | 1413 | GNUNET_assert(0); |
1406 | } | 1414 | break; |
1415 | } | ||
1407 | if (NULL != helper_handle) | 1416 | if (NULL != helper_handle) |
1408 | (void) GNUNET_HELPER_send (helper_handle, | 1417 | (void)GNUNET_HELPER_send(helper_handle, |
1409 | (const struct GNUNET_MessageHeader*) buf, | 1418 | (const struct GNUNET_MessageHeader*)buf, |
1410 | GNUNET_YES, | 1419 | GNUNET_YES, |
1411 | NULL, NULL); | 1420 | NULL, NULL); |
1412 | } | 1421 | } |
1413 | } | 1422 | } |
1414 | 1423 | ||
@@ -1422,16 +1431,16 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address, | |||
1422 | * #GNUNET_SYSERR to close it (signal serious error) | 1431 | * #GNUNET_SYSERR to close it (signal serious error) |
1423 | */ | 1432 | */ |
1424 | static int | 1433 | static int |
1425 | check_udp_remote (void *cls, | 1434 | check_udp_remote(void *cls, |
1426 | const struct GNUNET_EXIT_UdpInternetMessage *msg) | 1435 | const struct GNUNET_EXIT_UdpInternetMessage *msg) |
1427 | { | 1436 | { |
1428 | struct ChannelState *state = cls; | 1437 | struct ChannelState *state = cls; |
1429 | 1438 | ||
1430 | if (GNUNET_YES == state->is_dns) | 1439 | if (GNUNET_YES == state->is_dns) |
1431 | { | 1440 | { |
1432 | GNUNET_break_op (0); | 1441 | GNUNET_break_op(0); |
1433 | return GNUNET_SYSERR; | 1442 | return GNUNET_SYSERR; |
1434 | } | 1443 | } |
1435 | return GNUNET_OK; | 1444 | return GNUNET_OK; |
1436 | } | 1445 | } |
1437 | 1446 | ||
@@ -1443,88 +1452,90 @@ check_udp_remote (void *cls, | |||
1443 | * @param msg the actual message | 1452 | * @param msg the actual message |
1444 | */ | 1453 | */ |
1445 | static void | 1454 | static void |
1446 | handle_udp_remote (void *cls, | 1455 | handle_udp_remote(void *cls, |
1447 | const struct GNUNET_EXIT_UdpInternetMessage *msg) | 1456 | const struct GNUNET_EXIT_UdpInternetMessage *msg) |
1448 | { | 1457 | { |
1449 | struct ChannelState *state = cls; | 1458 | struct ChannelState *state = cls; |
1450 | uint16_t pkt_len = ntohs (msg->header.size) - sizeof (struct GNUNET_EXIT_UdpInternetMessage); | 1459 | uint16_t pkt_len = ntohs(msg->header.size) - sizeof(struct GNUNET_EXIT_UdpInternetMessage); |
1451 | const struct in_addr *v4; | 1460 | const struct in_addr *v4; |
1452 | const struct in6_addr *v6; | 1461 | const struct in6_addr *v6; |
1453 | const void *payload; | 1462 | const void *payload; |
1454 | int af; | 1463 | int af; |
1455 | 1464 | ||
1456 | if (GNUNET_SYSERR == state->is_dns) | 1465 | if (GNUNET_SYSERR == state->is_dns) |
1457 | { | ||
1458 | /* channel is UDP/TCP from now on */ | ||
1459 | state->is_dns = GNUNET_NO; | ||
1460 | } | ||
1461 | GNUNET_STATISTICS_update (stats, | ||
1462 | gettext_noop ("# Bytes received from CADET"), | ||
1463 | pkt_len, GNUNET_NO); | ||
1464 | GNUNET_STATISTICS_update (stats, | ||
1465 | gettext_noop ("# UDP IP-exit requests received via cadet"), | ||
1466 | 1, GNUNET_NO); | ||
1467 | af = (int) ntohl (msg->af); | ||
1468 | state->specifics.tcp_udp.ri.remote_address.af = af; | ||
1469 | switch (af) | ||
1470 | { | ||
1471 | case AF_INET: | ||
1472 | if (pkt_len < sizeof (struct in_addr)) | ||
1473 | { | ||
1474 | GNUNET_break_op (0); | ||
1475 | return; | ||
1476 | } | ||
1477 | if (! ipv4_exit) | ||
1478 | { | 1466 | { |
1479 | GNUNET_break_op (0); | 1467 | /* channel is UDP/TCP from now on */ |
1480 | return; | 1468 | state->is_dns = GNUNET_NO; |
1481 | } | ||
1482 | v4 = (const struct in_addr*) &msg[1]; | ||
1483 | payload = &v4[1]; | ||
1484 | pkt_len -= sizeof (struct in_addr); | ||
1485 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | ||
1486 | break; | ||
1487 | case AF_INET6: | ||
1488 | if (pkt_len < sizeof (struct in6_addr)) | ||
1489 | { | ||
1490 | GNUNET_break_op (0); | ||
1491 | return; | ||
1492 | } | 1469 | } |
1493 | if (! ipv6_exit) | 1470 | GNUNET_STATISTICS_update(stats, |
1471 | gettext_noop("# Bytes received from CADET"), | ||
1472 | pkt_len, GNUNET_NO); | ||
1473 | GNUNET_STATISTICS_update(stats, | ||
1474 | gettext_noop("# UDP IP-exit requests received via cadet"), | ||
1475 | 1, GNUNET_NO); | ||
1476 | af = (int)ntohl(msg->af); | ||
1477 | state->specifics.tcp_udp.ri.remote_address.af = af; | ||
1478 | switch (af) | ||
1494 | { | 1479 | { |
1495 | GNUNET_break_op (0); | 1480 | case AF_INET: |
1481 | if (pkt_len < sizeof(struct in_addr)) | ||
1482 | { | ||
1483 | GNUNET_break_op(0); | ||
1484 | return; | ||
1485 | } | ||
1486 | if (!ipv4_exit) | ||
1487 | { | ||
1488 | GNUNET_break_op(0); | ||
1489 | return; | ||
1490 | } | ||
1491 | v4 = (const struct in_addr*)&msg[1]; | ||
1492 | payload = &v4[1]; | ||
1493 | pkt_len -= sizeof(struct in_addr); | ||
1494 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | ||
1495 | break; | ||
1496 | |||
1497 | case AF_INET6: | ||
1498 | if (pkt_len < sizeof(struct in6_addr)) | ||
1499 | { | ||
1500 | GNUNET_break_op(0); | ||
1501 | return; | ||
1502 | } | ||
1503 | if (!ipv6_exit) | ||
1504 | { | ||
1505 | GNUNET_break_op(0); | ||
1506 | return; | ||
1507 | } | ||
1508 | v6 = (const struct in6_addr*)&msg[1]; | ||
1509 | payload = &v6[1]; | ||
1510 | pkt_len -= sizeof(struct in6_addr); | ||
1511 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
1512 | break; | ||
1513 | |||
1514 | default: | ||
1515 | GNUNET_break_op(0); | ||
1496 | return; | 1516 | return; |
1497 | } | 1517 | } |
1498 | v6 = (const struct in6_addr*) &msg[1]; | ||
1499 | payload = &v6[1]; | ||
1500 | pkt_len -= sizeof (struct in6_addr); | ||
1501 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
1502 | break; | ||
1503 | default: | ||
1504 | GNUNET_break_op (0); | ||
1505 | return; | ||
1506 | } | ||
1507 | { | 1518 | { |
1508 | char buf[INET6_ADDRSTRLEN]; | 1519 | char buf[INET6_ADDRSTRLEN]; |
1509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1520 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1510 | "Received data from %s for forwarding to UDP %s:%u\n", | 1521 | "Received data from %s for forwarding to UDP %s:%u\n", |
1511 | GNUNET_i2s (&state->peer), | 1522 | GNUNET_i2s(&state->peer), |
1512 | inet_ntop (af, | 1523 | inet_ntop(af, |
1513 | &state->specifics.tcp_udp.ri.remote_address.address, | 1524 | &state->specifics.tcp_udp.ri.remote_address.address, |
1514 | buf, sizeof (buf)), | 1525 | buf, sizeof(buf)), |
1515 | (unsigned int) ntohs (msg->destination_port)); | 1526 | (unsigned int)ntohs(msg->destination_port)); |
1516 | } | 1527 | } |
1517 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_UDP; | 1528 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_UDP; |
1518 | state->specifics.tcp_udp.ri.remote_address.port = msg->destination_port; | 1529 | state->specifics.tcp_udp.ri.remote_address.port = msg->destination_port; |
1519 | if (NULL == state->specifics.tcp_udp.heap_node) | 1530 | if (NULL == state->specifics.tcp_udp.heap_node) |
1520 | setup_state_record (state); | 1531 | setup_state_record(state); |
1521 | if (0 != ntohs (msg->source_port)) | 1532 | if (0 != ntohs(msg->source_port)) |
1522 | state->specifics.tcp_udp.ri.local_address.port = msg->source_port; | 1533 | state->specifics.tcp_udp.ri.local_address.port = msg->source_port; |
1523 | send_udp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, | 1534 | send_udp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, |
1524 | &state->specifics.tcp_udp.ri.local_address, | 1535 | &state->specifics.tcp_udp.ri.local_address, |
1525 | payload, | 1536 | payload, |
1526 | pkt_len); | 1537 | pkt_len); |
1527 | GNUNET_CADET_receive_done (state->channel); | 1538 | GNUNET_CADET_receive_done(state->channel); |
1528 | } | 1539 | } |
1529 | 1540 | ||
1530 | 1541 | ||
@@ -1538,16 +1549,16 @@ handle_udp_remote (void *cls, | |||
1538 | * #GNUNET_SYSERR to close it (signal serious error) | 1549 | * #GNUNET_SYSERR to close it (signal serious error) |
1539 | */ | 1550 | */ |
1540 | static int | 1551 | static int |
1541 | check_udp_service (void *cls, | 1552 | check_udp_service(void *cls, |
1542 | const struct GNUNET_EXIT_UdpServiceMessage *msg) | 1553 | const struct GNUNET_EXIT_UdpServiceMessage *msg) |
1543 | { | 1554 | { |
1544 | struct ChannelState *state = cls; | 1555 | struct ChannelState *state = cls; |
1545 | 1556 | ||
1546 | if (NULL == state->specifics.tcp_udp.serv) | 1557 | if (NULL == state->specifics.tcp_udp.serv) |
1547 | { | 1558 | { |
1548 | GNUNET_break_op (0); | 1559 | GNUNET_break_op(0); |
1549 | return GNUNET_SYSERR; | 1560 | return GNUNET_SYSERR; |
1550 | } | 1561 | } |
1551 | return GNUNET_OK; | 1562 | return GNUNET_OK; |
1552 | } | 1563 | } |
1553 | 1564 | ||
@@ -1560,31 +1571,31 @@ check_udp_service (void *cls, | |||
1560 | * @param msg the actual message | 1571 | * @param msg the actual message |
1561 | */ | 1572 | */ |
1562 | static void | 1573 | static void |
1563 | handle_udp_service (void *cls, | 1574 | handle_udp_service(void *cls, |
1564 | const struct GNUNET_EXIT_UdpServiceMessage *msg) | 1575 | const struct GNUNET_EXIT_UdpServiceMessage *msg) |
1565 | { | 1576 | { |
1566 | struct ChannelState *state = cls; | 1577 | struct ChannelState *state = cls; |
1567 | uint16_t pkt_len = ntohs (msg->header.size) - sizeof (struct GNUNET_EXIT_UdpServiceMessage); | 1578 | uint16_t pkt_len = ntohs(msg->header.size) - sizeof(struct GNUNET_EXIT_UdpServiceMessage); |
1568 | 1579 | ||
1569 | GNUNET_STATISTICS_update (stats, | 1580 | GNUNET_STATISTICS_update(stats, |
1570 | gettext_noop ("# Bytes received from CADET"), | 1581 | gettext_noop("# Bytes received from CADET"), |
1571 | pkt_len, GNUNET_NO); | 1582 | pkt_len, GNUNET_NO); |
1572 | GNUNET_STATISTICS_update (stats, | 1583 | GNUNET_STATISTICS_update(stats, |
1573 | gettext_noop ("# UDP service requests received via cadet"), | 1584 | gettext_noop("# UDP service requests received via cadet"), |
1574 | 1, GNUNET_NO); | 1585 | 1, GNUNET_NO); |
1575 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1586 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1576 | "Received data from %s for forwarding to UDP service %s on port %u\n", | 1587 | "Received data from %s for forwarding to UDP service %s on port %u\n", |
1577 | GNUNET_i2s (&state->peer), | 1588 | GNUNET_i2s(&state->peer), |
1578 | GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor), | 1589 | GNUNET_h2s(&state->specifics.tcp_udp.serv->descriptor), |
1579 | (unsigned int) ntohs (msg->destination_port)); | 1590 | (unsigned int)ntohs(msg->destination_port)); |
1580 | setup_state_record (state); | 1591 | setup_state_record(state); |
1581 | if (0 != ntohs (msg->source_port)) | 1592 | if (0 != ntohs(msg->source_port)) |
1582 | state->specifics.tcp_udp.ri.local_address.port = msg->source_port; | 1593 | state->specifics.tcp_udp.ri.local_address.port = msg->source_port; |
1583 | send_udp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, | 1594 | send_udp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, |
1584 | &state->specifics.tcp_udp.ri.local_address, | 1595 | &state->specifics.tcp_udp.ri.local_address, |
1585 | &msg[1], | 1596 | &msg[1], |
1586 | pkt_len); | 1597 | pkt_len); |
1587 | GNUNET_CADET_receive_done (state->channel); | 1598 | GNUNET_CADET_receive_done(state->channel); |
1588 | } | 1599 | } |
1589 | 1600 | ||
1590 | 1601 | ||
@@ -1598,39 +1609,39 @@ handle_udp_service (void *cls, | |||
1598 | * #GNUNET_SYSERR to close it (signal serious error) | 1609 | * #GNUNET_SYSERR to close it (signal serious error) |
1599 | */ | 1610 | */ |
1600 | static void | 1611 | static void |
1601 | handle_tcp_service (void *cls, | 1612 | handle_tcp_service(void *cls, |
1602 | const struct GNUNET_EXIT_TcpServiceStartMessage *start) | 1613 | const struct GNUNET_EXIT_TcpServiceStartMessage *start) |
1603 | { | 1614 | { |
1604 | struct ChannelState *state = cls; | 1615 | struct ChannelState *state = cls; |
1605 | uint16_t pkt_len = ntohs (start->header.size) - sizeof (struct GNUNET_EXIT_TcpServiceStartMessage); | 1616 | uint16_t pkt_len = ntohs(start->header.size) - sizeof(struct GNUNET_EXIT_TcpServiceStartMessage); |
1606 | 1617 | ||
1607 | if (GNUNET_SYSERR == state->is_dns) | 1618 | if (GNUNET_SYSERR == state->is_dns) |
1608 | { | 1619 | { |
1609 | /* channel is UDP/TCP from now on */ | 1620 | /* channel is UDP/TCP from now on */ |
1610 | state->is_dns = GNUNET_NO; | 1621 | state->is_dns = GNUNET_NO; |
1611 | } | 1622 | } |
1612 | GNUNET_STATISTICS_update (stats, | 1623 | GNUNET_STATISTICS_update(stats, |
1613 | gettext_noop ("# TCP service creation requests received via cadet"), | 1624 | gettext_noop("# TCP service creation requests received via cadet"), |
1614 | 1, | 1625 | 1, |
1615 | GNUNET_NO); | 1626 | GNUNET_NO); |
1616 | GNUNET_STATISTICS_update (stats, | 1627 | GNUNET_STATISTICS_update(stats, |
1617 | gettext_noop ("# Bytes received from CADET"), | 1628 | gettext_noop("# Bytes received from CADET"), |
1618 | pkt_len, | 1629 | pkt_len, |
1619 | GNUNET_NO); | 1630 | GNUNET_NO); |
1620 | GNUNET_break_op (ntohl (start->reserved) == 0); | 1631 | GNUNET_break_op(ntohl(start->reserved) == 0); |
1621 | /* setup fresh connection */ | 1632 | /* setup fresh connection */ |
1622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1633 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1623 | "Received data from %s for forwarding to TCP service %s on port %u\n", | 1634 | "Received data from %s for forwarding to TCP service %s on port %u\n", |
1624 | GNUNET_i2s (&state->peer), | 1635 | GNUNET_i2s(&state->peer), |
1625 | GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor), | 1636 | GNUNET_h2s(&state->specifics.tcp_udp.serv->descriptor), |
1626 | (unsigned int) ntohs (start->tcp_header.destination_port)); | 1637 | (unsigned int)ntohs(start->tcp_header.destination_port)); |
1627 | setup_state_record (state); | 1638 | setup_state_record(state); |
1628 | send_tcp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, | 1639 | send_tcp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, |
1629 | &state->specifics.tcp_udp.ri.local_address, | 1640 | &state->specifics.tcp_udp.ri.local_address, |
1630 | &start->tcp_header, | 1641 | &start->tcp_header, |
1631 | &start[1], | 1642 | &start[1], |
1632 | pkt_len); | 1643 | pkt_len); |
1633 | GNUNET_CADET_receive_done (state->channel); | 1644 | GNUNET_CADET_receive_done(state->channel); |
1634 | } | 1645 | } |
1635 | 1646 | ||
1636 | 1647 | ||
@@ -1643,32 +1654,32 @@ handle_tcp_service (void *cls, | |||
1643 | * #GNUNET_SYSERR to close it (signal serious error) | 1654 | * #GNUNET_SYSERR to close it (signal serious error) |
1644 | */ | 1655 | */ |
1645 | static int | 1656 | static int |
1646 | check_tcp_remote (void *cls, | 1657 | check_tcp_remote(void *cls, |
1647 | const struct GNUNET_EXIT_TcpInternetStartMessage *start) | 1658 | const struct GNUNET_EXIT_TcpInternetStartMessage *start) |
1648 | { | 1659 | { |
1649 | struct ChannelState *state = cls; | 1660 | struct ChannelState *state = cls; |
1650 | 1661 | ||
1651 | if (NULL == state) | 1662 | if (NULL == state) |
1652 | { | 1663 | { |
1653 | GNUNET_break_op (0); | 1664 | GNUNET_break_op(0); |
1654 | return GNUNET_SYSERR; | 1665 | return GNUNET_SYSERR; |
1655 | } | 1666 | } |
1656 | if (GNUNET_YES == state->is_dns) | 1667 | if (GNUNET_YES == state->is_dns) |
1657 | { | 1668 | { |
1658 | GNUNET_break_op (0); | 1669 | GNUNET_break_op(0); |
1659 | return GNUNET_SYSERR; | 1670 | return GNUNET_SYSERR; |
1660 | } | 1671 | } |
1661 | if ( (NULL != state->specifics.tcp_udp.serv) || | 1672 | if ((NULL != state->specifics.tcp_udp.serv) || |
1662 | (NULL != state->specifics.tcp_udp.heap_node) ) | 1673 | (NULL != state->specifics.tcp_udp.heap_node)) |
1663 | { | 1674 | { |
1664 | GNUNET_break_op (0); | 1675 | GNUNET_break_op(0); |
1665 | return GNUNET_SYSERR; | 1676 | return GNUNET_SYSERR; |
1666 | } | 1677 | } |
1667 | if (start->tcp_header.off * 4 < sizeof (struct GNUNET_TUN_TcpHeader)) | 1678 | if (start->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) |
1668 | { | 1679 | { |
1669 | GNUNET_break_op (0); | 1680 | GNUNET_break_op(0); |
1670 | return GNUNET_SYSERR; | 1681 | return GNUNET_SYSERR; |
1671 | } | 1682 | } |
1672 | return GNUNET_OK; | 1683 | return GNUNET_OK; |
1673 | } | 1684 | } |
1674 | 1685 | ||
@@ -1680,86 +1691,88 @@ check_tcp_remote (void *cls, | |||
1680 | * @param start the actual message | 1691 | * @param start the actual message |
1681 | */ | 1692 | */ |
1682 | static void | 1693 | static void |
1683 | handle_tcp_remote (void *cls, | 1694 | handle_tcp_remote(void *cls, |
1684 | const struct GNUNET_EXIT_TcpInternetStartMessage *start) | 1695 | const struct GNUNET_EXIT_TcpInternetStartMessage *start) |
1685 | { | 1696 | { |
1686 | struct ChannelState *state = cls; | 1697 | struct ChannelState *state = cls; |
1687 | uint16_t pkt_len = ntohs (start->header.size) - sizeof (struct GNUNET_EXIT_TcpInternetStartMessage); | 1698 | uint16_t pkt_len = ntohs(start->header.size) - sizeof(struct GNUNET_EXIT_TcpInternetStartMessage); |
1688 | const struct in_addr *v4; | 1699 | const struct in_addr *v4; |
1689 | const struct in6_addr *v6; | 1700 | const struct in6_addr *v6; |
1690 | const void *payload; | 1701 | const void *payload; |
1691 | int af; | 1702 | int af; |
1692 | 1703 | ||
1693 | if (GNUNET_SYSERR == state->is_dns) | 1704 | if (GNUNET_SYSERR == state->is_dns) |
1694 | { | ||
1695 | /* channel is UDP/TCP from now on */ | ||
1696 | state->is_dns = GNUNET_NO; | ||
1697 | } | ||
1698 | GNUNET_STATISTICS_update (stats, | ||
1699 | gettext_noop ("# Bytes received from CADET"), | ||
1700 | pkt_len, GNUNET_NO); | ||
1701 | GNUNET_STATISTICS_update (stats, | ||
1702 | gettext_noop ("# TCP IP-exit creation requests received via cadet"), | ||
1703 | 1, GNUNET_NO); | ||
1704 | af = (int) ntohl (start->af); | ||
1705 | state->specifics.tcp_udp.ri.remote_address.af = af; | ||
1706 | switch (af) | ||
1707 | { | ||
1708 | case AF_INET: | ||
1709 | if (pkt_len < sizeof (struct in_addr)) | ||
1710 | { | ||
1711 | GNUNET_break_op (0); | ||
1712 | return; | ||
1713 | } | ||
1714 | if (! ipv4_exit) | ||
1715 | { | ||
1716 | GNUNET_break_op (0); | ||
1717 | return; | ||
1718 | } | ||
1719 | v4 = (const struct in_addr*) &start[1]; | ||
1720 | payload = &v4[1]; | ||
1721 | pkt_len -= sizeof (struct in_addr); | ||
1722 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | ||
1723 | break; | ||
1724 | case AF_INET6: | ||
1725 | if (pkt_len < sizeof (struct in6_addr)) | ||
1726 | { | 1705 | { |
1727 | GNUNET_break_op (0); | 1706 | /* channel is UDP/TCP from now on */ |
1728 | return; | 1707 | state->is_dns = GNUNET_NO; |
1729 | } | 1708 | } |
1730 | if (! ipv6_exit) | 1709 | GNUNET_STATISTICS_update(stats, |
1710 | gettext_noop("# Bytes received from CADET"), | ||
1711 | pkt_len, GNUNET_NO); | ||
1712 | GNUNET_STATISTICS_update(stats, | ||
1713 | gettext_noop("# TCP IP-exit creation requests received via cadet"), | ||
1714 | 1, GNUNET_NO); | ||
1715 | af = (int)ntohl(start->af); | ||
1716 | state->specifics.tcp_udp.ri.remote_address.af = af; | ||
1717 | switch (af) | ||
1731 | { | 1718 | { |
1732 | GNUNET_break_op (0); | 1719 | case AF_INET: |
1720 | if (pkt_len < sizeof(struct in_addr)) | ||
1721 | { | ||
1722 | GNUNET_break_op(0); | ||
1723 | return; | ||
1724 | } | ||
1725 | if (!ipv4_exit) | ||
1726 | { | ||
1727 | GNUNET_break_op(0); | ||
1728 | return; | ||
1729 | } | ||
1730 | v4 = (const struct in_addr*)&start[1]; | ||
1731 | payload = &v4[1]; | ||
1732 | pkt_len -= sizeof(struct in_addr); | ||
1733 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | ||
1734 | break; | ||
1735 | |||
1736 | case AF_INET6: | ||
1737 | if (pkt_len < sizeof(struct in6_addr)) | ||
1738 | { | ||
1739 | GNUNET_break_op(0); | ||
1740 | return; | ||
1741 | } | ||
1742 | if (!ipv6_exit) | ||
1743 | { | ||
1744 | GNUNET_break_op(0); | ||
1745 | return; | ||
1746 | } | ||
1747 | v6 = (const struct in6_addr*)&start[1]; | ||
1748 | payload = &v6[1]; | ||
1749 | pkt_len -= sizeof(struct in6_addr); | ||
1750 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
1751 | break; | ||
1752 | |||
1753 | default: | ||
1754 | GNUNET_break_op(0); | ||
1733 | return; | 1755 | return; |
1734 | } | 1756 | } |
1735 | v6 = (const struct in6_addr*) &start[1]; | ||
1736 | payload = &v6[1]; | ||
1737 | pkt_len -= sizeof (struct in6_addr); | ||
1738 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
1739 | break; | ||
1740 | default: | ||
1741 | GNUNET_break_op (0); | ||
1742 | return; | ||
1743 | } | ||
1744 | { | 1757 | { |
1745 | char buf[INET6_ADDRSTRLEN]; | 1758 | char buf[INET6_ADDRSTRLEN]; |
1746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1759 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1747 | "Received payload from %s for existing TCP stream to %s:%u\n", | 1760 | "Received payload from %s for existing TCP stream to %s:%u\n", |
1748 | GNUNET_i2s (&state->peer), | 1761 | GNUNET_i2s(&state->peer), |
1749 | inet_ntop (af, | 1762 | inet_ntop(af, |
1750 | &state->specifics.tcp_udp.ri.remote_address.address, | 1763 | &state->specifics.tcp_udp.ri.remote_address.address, |
1751 | buf, sizeof (buf)), | 1764 | buf, sizeof(buf)), |
1752 | (unsigned int) ntohs (start->tcp_header.destination_port)); | 1765 | (unsigned int)ntohs(start->tcp_header.destination_port)); |
1753 | } | 1766 | } |
1754 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_TCP; | 1767 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_TCP; |
1755 | state->specifics.tcp_udp.ri.remote_address.port = ntohs (start->tcp_header.destination_port); | 1768 | state->specifics.tcp_udp.ri.remote_address.port = ntohs(start->tcp_header.destination_port); |
1756 | setup_state_record (state); | 1769 | setup_state_record(state); |
1757 | send_tcp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, | 1770 | send_tcp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, |
1758 | &state->specifics.tcp_udp.ri.local_address, | 1771 | &state->specifics.tcp_udp.ri.local_address, |
1759 | &start->tcp_header, | 1772 | &start->tcp_header, |
1760 | payload, | 1773 | payload, |
1761 | pkt_len); | 1774 | pkt_len); |
1762 | GNUNET_CADET_receive_done (state->channel); | 1775 | GNUNET_CADET_receive_done(state->channel); |
1763 | } | 1776 | } |
1764 | 1777 | ||
1765 | 1778 | ||
@@ -1773,31 +1786,31 @@ handle_tcp_remote (void *cls, | |||
1773 | * #GNUNET_SYSERR to close it (signal serious error) | 1786 | * #GNUNET_SYSERR to close it (signal serious error) |
1774 | */ | 1787 | */ |
1775 | static int | 1788 | static int |
1776 | check_tcp_data (void *cls, | 1789 | check_tcp_data(void *cls, |
1777 | const struct GNUNET_EXIT_TcpDataMessage *data) | 1790 | const struct GNUNET_EXIT_TcpDataMessage *data) |
1778 | { | 1791 | { |
1779 | struct ChannelState *state = cls; | 1792 | struct ChannelState *state = cls; |
1780 | 1793 | ||
1781 | if ( (NULL == state) || | 1794 | if ((NULL == state) || |
1782 | (NULL == state->specifics.tcp_udp.heap_node) ) | 1795 | (NULL == state->specifics.tcp_udp.heap_node)) |
1783 | { | 1796 | { |
1784 | /* connection should have been up! */ | 1797 | /* connection should have been up! */ |
1785 | GNUNET_STATISTICS_update (stats, | 1798 | GNUNET_STATISTICS_update(stats, |
1786 | gettext_noop ("# TCP DATA requests dropped (no session)"), | 1799 | gettext_noop("# TCP DATA requests dropped (no session)"), |
1787 | 1, GNUNET_NO); | 1800 | 1, GNUNET_NO); |
1788 | GNUNET_break_op (0); | 1801 | GNUNET_break_op(0); |
1789 | return GNUNET_SYSERR; | 1802 | return GNUNET_SYSERR; |
1790 | } | 1803 | } |
1791 | if (data->tcp_header.off * 4 < sizeof (struct GNUNET_TUN_TcpHeader)) | 1804 | if (data->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) |
1792 | { | 1805 | { |
1793 | GNUNET_break_op (0); | 1806 | GNUNET_break_op(0); |
1794 | return GNUNET_SYSERR; | 1807 | return GNUNET_SYSERR; |
1795 | } | 1808 | } |
1796 | if (GNUNET_YES == state->is_dns) | 1809 | if (GNUNET_YES == state->is_dns) |
1797 | { | 1810 | { |
1798 | GNUNET_break_op (0); | 1811 | GNUNET_break_op(0); |
1799 | return GNUNET_SYSERR; | 1812 | return GNUNET_SYSERR; |
1800 | } | 1813 | } |
1801 | return GNUNET_OK; | 1814 | return GNUNET_OK; |
1802 | } | 1815 | } |
1803 | 1816 | ||
@@ -1810,42 +1823,42 @@ check_tcp_data (void *cls, | |||
1810 | * @param message the actual message | 1823 | * @param message the actual message |
1811 | */ | 1824 | */ |
1812 | static void | 1825 | static void |
1813 | handle_tcp_data (void *cls, | 1826 | handle_tcp_data(void *cls, |
1814 | const struct GNUNET_EXIT_TcpDataMessage *data) | 1827 | const struct GNUNET_EXIT_TcpDataMessage *data) |
1815 | { | 1828 | { |
1816 | struct ChannelState *state = cls; | 1829 | struct ChannelState *state = cls; |
1817 | uint16_t pkt_len = ntohs (data->header.size) - sizeof (struct GNUNET_EXIT_TcpDataMessage); | 1830 | uint16_t pkt_len = ntohs(data->header.size) - sizeof(struct GNUNET_EXIT_TcpDataMessage); |
1818 | 1831 | ||
1819 | GNUNET_STATISTICS_update (stats, | 1832 | GNUNET_STATISTICS_update(stats, |
1820 | gettext_noop ("# Bytes received from CADET"), | 1833 | gettext_noop("# Bytes received from CADET"), |
1821 | pkt_len, GNUNET_NO); | 1834 | pkt_len, GNUNET_NO); |
1822 | GNUNET_STATISTICS_update (stats, | 1835 | GNUNET_STATISTICS_update(stats, |
1823 | gettext_noop ("# TCP data requests received via cadet"), | 1836 | gettext_noop("# TCP data requests received via cadet"), |
1824 | 1, GNUNET_NO); | 1837 | 1, GNUNET_NO); |
1825 | if (GNUNET_SYSERR == state->is_dns) | 1838 | if (GNUNET_SYSERR == state->is_dns) |
1826 | { | 1839 | { |
1827 | /* channel is UDP/TCP from now on */ | 1840 | /* channel is UDP/TCP from now on */ |
1828 | state->is_dns = GNUNET_NO; | 1841 | state->is_dns = GNUNET_NO; |
1829 | } | 1842 | } |
1830 | 1843 | ||
1831 | GNUNET_break_op (ntohl (data->reserved) == 0); | 1844 | GNUNET_break_op(ntohl(data->reserved) == 0); |
1832 | { | 1845 | { |
1833 | char buf[INET6_ADDRSTRLEN]; | 1846 | char buf[INET6_ADDRSTRLEN]; |
1834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1847 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1835 | "Received additional %u bytes of data from %s for TCP stream to %s:%u\n", | 1848 | "Received additional %u bytes of data from %s for TCP stream to %s:%u\n", |
1836 | pkt_len, | 1849 | pkt_len, |
1837 | GNUNET_i2s (&state->peer), | 1850 | GNUNET_i2s(&state->peer), |
1838 | inet_ntop (state->specifics.tcp_udp.ri.remote_address.af, | 1851 | inet_ntop(state->specifics.tcp_udp.ri.remote_address.af, |
1839 | &state->specifics.tcp_udp.ri.remote_address.address, | 1852 | &state->specifics.tcp_udp.ri.remote_address.address, |
1840 | buf, sizeof (buf)), | 1853 | buf, sizeof(buf)), |
1841 | (unsigned int) state->specifics.tcp_udp.ri.remote_address.port); | 1854 | (unsigned int)state->specifics.tcp_udp.ri.remote_address.port); |
1842 | } | 1855 | } |
1843 | 1856 | ||
1844 | send_tcp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, | 1857 | send_tcp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, |
1845 | &state->specifics.tcp_udp.ri.local_address, | 1858 | &state->specifics.tcp_udp.ri.local_address, |
1846 | &data->tcp_header, | 1859 | &data->tcp_header, |
1847 | &data[1], pkt_len); | 1860 | &data[1], pkt_len); |
1848 | GNUNET_CADET_receive_done (state->channel); | 1861 | GNUNET_CADET_receive_done(state->channel); |
1849 | } | 1862 | } |
1850 | 1863 | ||
1851 | 1864 | ||
@@ -1859,19 +1872,19 @@ handle_tcp_data (void *cls, | |||
1859 | * also be the first 8 bytes of the TCP header | 1872 | * also be the first 8 bytes of the TCP header |
1860 | */ | 1873 | */ |
1861 | static void | 1874 | static void |
1862 | make_up_icmpv4_payload (struct ChannelState *state, | 1875 | make_up_icmpv4_payload(struct ChannelState *state, |
1863 | struct GNUNET_TUN_IPv4Header *ipp, | 1876 | struct GNUNET_TUN_IPv4Header *ipp, |
1864 | struct GNUNET_TUN_UdpHeader *udp) | 1877 | struct GNUNET_TUN_UdpHeader *udp) |
1865 | { | 1878 | { |
1866 | GNUNET_TUN_initialize_ipv4_header (ipp, | 1879 | GNUNET_TUN_initialize_ipv4_header(ipp, |
1867 | state->specifics.tcp_udp.ri.remote_address.proto, | 1880 | state->specifics.tcp_udp.ri.remote_address.proto, |
1868 | sizeof (struct GNUNET_TUN_TcpHeader), | 1881 | sizeof(struct GNUNET_TUN_TcpHeader), |
1869 | &state->specifics.tcp_udp.ri.remote_address.address.ipv4, | 1882 | &state->specifics.tcp_udp.ri.remote_address.address.ipv4, |
1870 | &state->specifics.tcp_udp.ri.local_address.address.ipv4); | 1883 | &state->specifics.tcp_udp.ri.local_address.address.ipv4); |
1871 | udp->source_port = htons (state->specifics.tcp_udp.ri.remote_address.port); | 1884 | udp->source_port = htons(state->specifics.tcp_udp.ri.remote_address.port); |
1872 | udp->destination_port = htons (state->specifics.tcp_udp.ri.local_address.port); | 1885 | udp->destination_port = htons(state->specifics.tcp_udp.ri.local_address.port); |
1873 | udp->len = htons (0); | 1886 | udp->len = htons(0); |
1874 | udp->crc = htons (0); | 1887 | udp->crc = htons(0); |
1875 | } | 1888 | } |
1876 | 1889 | ||
1877 | 1890 | ||
@@ -1885,19 +1898,19 @@ make_up_icmpv4_payload (struct ChannelState *state, | |||
1885 | * also be the first 8 bytes of the TCP header | 1898 | * also be the first 8 bytes of the TCP header |
1886 | */ | 1899 | */ |
1887 | static void | 1900 | static void |
1888 | make_up_icmpv6_payload (struct ChannelState *state, | 1901 | make_up_icmpv6_payload(struct ChannelState *state, |
1889 | struct GNUNET_TUN_IPv6Header *ipp, | 1902 | struct GNUNET_TUN_IPv6Header *ipp, |
1890 | struct GNUNET_TUN_UdpHeader *udp) | 1903 | struct GNUNET_TUN_UdpHeader *udp) |
1891 | { | 1904 | { |
1892 | GNUNET_TUN_initialize_ipv6_header (ipp, | 1905 | GNUNET_TUN_initialize_ipv6_header(ipp, |
1893 | state->specifics.tcp_udp.ri.remote_address.proto, | 1906 | state->specifics.tcp_udp.ri.remote_address.proto, |
1894 | sizeof (struct GNUNET_TUN_TcpHeader), | 1907 | sizeof(struct GNUNET_TUN_TcpHeader), |
1895 | &state->specifics.tcp_udp.ri.remote_address.address.ipv6, | 1908 | &state->specifics.tcp_udp.ri.remote_address.address.ipv6, |
1896 | &state->specifics.tcp_udp.ri.local_address.address.ipv6); | 1909 | &state->specifics.tcp_udp.ri.local_address.address.ipv6); |
1897 | udp->source_port = htons (state->specifics.tcp_udp.ri.remote_address.port); | 1910 | udp->source_port = htons(state->specifics.tcp_udp.ri.remote_address.port); |
1898 | udp->destination_port = htons (state->specifics.tcp_udp.ri.local_address.port); | 1911 | udp->destination_port = htons(state->specifics.tcp_udp.ri.local_address.port); |
1899 | udp->len = htons (0); | 1912 | udp->len = htons(0); |
1900 | udp->crc = htons (0); | 1913 | udp->crc = htons(0); |
1901 | } | 1914 | } |
1902 | 1915 | ||
1903 | 1916 | ||
@@ -1910,16 +1923,16 @@ make_up_icmpv6_payload (struct ChannelState *state, | |||
1910 | * #GNUNET_SYSERR to close it (signal serious error) | 1923 | * #GNUNET_SYSERR to close it (signal serious error) |
1911 | */ | 1924 | */ |
1912 | static int | 1925 | static int |
1913 | check_icmp_remote (void *cls, | 1926 | check_icmp_remote(void *cls, |
1914 | const struct GNUNET_EXIT_IcmpInternetMessage *msg) | 1927 | const struct GNUNET_EXIT_IcmpInternetMessage *msg) |
1915 | { | 1928 | { |
1916 | struct ChannelState *state = cls; | 1929 | struct ChannelState *state = cls; |
1917 | 1930 | ||
1918 | if (GNUNET_YES == state->is_dns) | 1931 | if (GNUNET_YES == state->is_dns) |
1919 | { | 1932 | { |
1920 | GNUNET_break_op (0); | 1933 | GNUNET_break_op(0); |
1921 | return GNUNET_SYSERR; | 1934 | return GNUNET_SYSERR; |
1922 | } | 1935 | } |
1923 | return GNUNET_OK; | 1936 | return GNUNET_OK; |
1924 | } | 1937 | } |
1925 | 1938 | ||
@@ -1931,177 +1944,183 @@ check_icmp_remote (void *cls, | |||
1931 | * @param msg the actual message | 1944 | * @param msg the actual message |
1932 | */ | 1945 | */ |
1933 | static void | 1946 | static void |
1934 | handle_icmp_remote (void *cls, | 1947 | handle_icmp_remote(void *cls, |
1935 | const struct GNUNET_EXIT_IcmpInternetMessage *msg) | 1948 | const struct GNUNET_EXIT_IcmpInternetMessage *msg) |
1936 | { | 1949 | { |
1937 | struct ChannelState *state = cls; | 1950 | struct ChannelState *state = cls; |
1938 | uint16_t pkt_len = ntohs (msg->header.size) - sizeof (struct GNUNET_EXIT_IcmpInternetMessage); | 1951 | uint16_t pkt_len = ntohs(msg->header.size) - sizeof(struct GNUNET_EXIT_IcmpInternetMessage); |
1939 | const struct in_addr *v4; | 1952 | const struct in_addr *v4; |
1940 | const struct in6_addr *v6; | 1953 | const struct in6_addr *v6; |
1941 | const void *payload; | 1954 | const void *payload; |
1942 | char buf[sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; | 1955 | char buf[sizeof(struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; |
1943 | int af; | 1956 | int af; |
1944 | 1957 | ||
1945 | if (GNUNET_SYSERR == state->is_dns) | 1958 | if (GNUNET_SYSERR == state->is_dns) |
1946 | { | ||
1947 | /* channel is UDP/TCP from now on */ | ||
1948 | state->is_dns = GNUNET_NO; | ||
1949 | } | ||
1950 | GNUNET_STATISTICS_update (stats, | ||
1951 | gettext_noop ("# Bytes received from CADET"), | ||
1952 | pkt_len, GNUNET_NO); | ||
1953 | GNUNET_STATISTICS_update (stats, | ||
1954 | gettext_noop ("# ICMP IP-exit requests received via cadet"), | ||
1955 | 1, GNUNET_NO); | ||
1956 | |||
1957 | af = (int) ntohl (msg->af); | ||
1958 | if ( (NULL != state->specifics.tcp_udp.heap_node) && | ||
1959 | (af != state->specifics.tcp_udp.ri.remote_address.af) ) | ||
1960 | { | ||
1961 | /* other peer switched AF on this channel; not allowed */ | ||
1962 | GNUNET_break_op (0); | ||
1963 | return; | ||
1964 | } | ||
1965 | |||
1966 | switch (af) | ||
1967 | { | ||
1968 | case AF_INET: | ||
1969 | if (pkt_len < sizeof (struct in_addr)) | ||
1970 | { | ||
1971 | GNUNET_break_op (0); | ||
1972 | return; | ||
1973 | } | ||
1974 | if (! ipv4_exit) | ||
1975 | { | 1959 | { |
1976 | GNUNET_break_op (0); | 1960 | /* channel is UDP/TCP from now on */ |
1977 | return; | 1961 | state->is_dns = GNUNET_NO; |
1978 | } | 1962 | } |
1979 | v4 = (const struct in_addr*) &msg[1]; | 1963 | GNUNET_STATISTICS_update(stats, |
1980 | payload = &v4[1]; | 1964 | gettext_noop("# Bytes received from CADET"), |
1981 | pkt_len -= sizeof (struct in_addr); | 1965 | pkt_len, GNUNET_NO); |
1982 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | 1966 | GNUNET_STATISTICS_update(stats, |
1983 | if (NULL == state->specifics.tcp_udp.heap_node) | 1967 | gettext_noop("# ICMP IP-exit requests received via cadet"), |
1968 | 1, GNUNET_NO); | ||
1969 | |||
1970 | af = (int)ntohl(msg->af); | ||
1971 | if ((NULL != state->specifics.tcp_udp.heap_node) && | ||
1972 | (af != state->specifics.tcp_udp.ri.remote_address.af)) | ||
1984 | { | 1973 | { |
1985 | state->specifics.tcp_udp.ri.remote_address.af = af; | 1974 | /* other peer switched AF on this channel; not allowed */ |
1986 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_ICMP; | 1975 | GNUNET_break_op(0); |
1987 | setup_state_record (state); | ||
1988 | } | ||
1989 | /* check that ICMP type is something we want to support | ||
1990 | and possibly make up payload! */ | ||
1991 | switch (msg->icmp_header.type) | ||
1992 | { | ||
1993 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
1994 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
1995 | break; | ||
1996 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
1997 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
1998 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
1999 | if (0 != pkt_len) | ||
2000 | { | ||
2001 | GNUNET_break_op (0); | ||
2002 | return; | ||
2003 | } | ||
2004 | /* make up payload */ | ||
2005 | { | ||
2006 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) buf; | ||
2007 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | ||
2008 | |||
2009 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); | ||
2010 | pkt_len = sizeof (struct GNUNET_TUN_IPv4Header) + 8; | ||
2011 | make_up_icmpv4_payload (state, | ||
2012 | ipp, | ||
2013 | udp); | ||
2014 | payload = ipp; | ||
2015 | } | ||
2016 | break; | ||
2017 | default: | ||
2018 | GNUNET_break_op (0); | ||
2019 | GNUNET_STATISTICS_update (stats, | ||
2020 | gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), | ||
2021 | 1, GNUNET_NO); | ||
2022 | return; | 1976 | return; |
2023 | } | 1977 | } |
2024 | /* end AF_INET */ | 1978 | |
2025 | break; | 1979 | switch (af) |
2026 | case AF_INET6: | ||
2027 | if (pkt_len < sizeof (struct in6_addr)) | ||
2028 | { | ||
2029 | GNUNET_break_op (0); | ||
2030 | return; | ||
2031 | } | ||
2032 | if (! ipv6_exit) | ||
2033 | { | ||
2034 | GNUNET_break_op (0); | ||
2035 | return; | ||
2036 | } | ||
2037 | v6 = (const struct in6_addr*) &msg[1]; | ||
2038 | payload = &v6[1]; | ||
2039 | pkt_len -= sizeof (struct in6_addr); | ||
2040 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
2041 | if (NULL == state->specifics.tcp_udp.heap_node) | ||
2042 | { | ||
2043 | state->specifics.tcp_udp.ri.remote_address.af = af; | ||
2044 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_ICMPV6; | ||
2045 | setup_state_record (state); | ||
2046 | } | ||
2047 | /* check that ICMP type is something we want to support | ||
2048 | and possibly make up payload! */ | ||
2049 | switch (msg->icmp_header.type) | ||
2050 | { | 1980 | { |
2051 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | 1981 | case AF_INET: |
2052 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | 1982 | if (pkt_len < sizeof(struct in_addr)) |
1983 | { | ||
1984 | GNUNET_break_op(0); | ||
1985 | return; | ||
1986 | } | ||
1987 | if (!ipv4_exit) | ||
1988 | { | ||
1989 | GNUNET_break_op(0); | ||
1990 | return; | ||
1991 | } | ||
1992 | v4 = (const struct in_addr*)&msg[1]; | ||
1993 | payload = &v4[1]; | ||
1994 | pkt_len -= sizeof(struct in_addr); | ||
1995 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | ||
1996 | if (NULL == state->specifics.tcp_udp.heap_node) | ||
1997 | { | ||
1998 | state->specifics.tcp_udp.ri.remote_address.af = af; | ||
1999 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_ICMP; | ||
2000 | setup_state_record(state); | ||
2001 | } | ||
2002 | /* check that ICMP type is something we want to support | ||
2003 | and possibly make up payload! */ | ||
2004 | switch (msg->icmp_header.type) | ||
2005 | { | ||
2006 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
2007 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
2008 | break; | ||
2009 | |||
2010 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
2011 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2012 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
2013 | if (0 != pkt_len) | ||
2014 | { | ||
2015 | GNUNET_break_op(0); | ||
2016 | return; | ||
2017 | } | ||
2018 | /* make up payload */ | ||
2019 | { | ||
2020 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *)buf; | ||
2021 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
2022 | |||
2023 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
2024 | pkt_len = sizeof(struct GNUNET_TUN_IPv4Header) + 8; | ||
2025 | make_up_icmpv4_payload(state, | ||
2026 | ipp, | ||
2027 | udp); | ||
2028 | payload = ipp; | ||
2029 | } | ||
2030 | break; | ||
2031 | |||
2032 | default: | ||
2033 | GNUNET_break_op(0); | ||
2034 | GNUNET_STATISTICS_update(stats, | ||
2035 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), | ||
2036 | 1, GNUNET_NO); | ||
2037 | return; | ||
2038 | } | ||
2039 | /* end AF_INET */ | ||
2053 | break; | 2040 | break; |
2054 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | 2041 | |
2055 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | 2042 | case AF_INET6: |
2056 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | 2043 | if (pkt_len < sizeof(struct in6_addr)) |
2057 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | 2044 | { |
2058 | if (0 != pkt_len) | 2045 | GNUNET_break_op(0); |
2059 | { | 2046 | return; |
2060 | GNUNET_break_op (0); | 2047 | } |
2061 | return; | 2048 | if (!ipv6_exit) |
2062 | } | 2049 | { |
2063 | /* make up payload */ | 2050 | GNUNET_break_op(0); |
2064 | { | 2051 | return; |
2065 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) buf; | 2052 | } |
2066 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | 2053 | v6 = (const struct in6_addr*)&msg[1]; |
2067 | 2054 | payload = &v6[1]; | |
2068 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); | 2055 | pkt_len -= sizeof(struct in6_addr); |
2069 | pkt_len = sizeof (struct GNUNET_TUN_IPv6Header) + 8; | 2056 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; |
2070 | make_up_icmpv6_payload (state, | 2057 | if (NULL == state->specifics.tcp_udp.heap_node) |
2071 | ipp, | 2058 | { |
2072 | udp); | 2059 | state->specifics.tcp_udp.ri.remote_address.af = af; |
2073 | payload = ipp; | 2060 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_ICMPV6; |
2074 | } | 2061 | setup_state_record(state); |
2062 | } | ||
2063 | /* check that ICMP type is something we want to support | ||
2064 | and possibly make up payload! */ | ||
2065 | switch (msg->icmp_header.type) | ||
2066 | { | ||
2067 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | ||
2068 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
2069 | break; | ||
2070 | |||
2071 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | ||
2072 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
2073 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
2074 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
2075 | if (0 != pkt_len) | ||
2076 | { | ||
2077 | GNUNET_break_op(0); | ||
2078 | return; | ||
2079 | } | ||
2080 | /* make up payload */ | ||
2081 | { | ||
2082 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *)buf; | ||
2083 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
2084 | |||
2085 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
2086 | pkt_len = sizeof(struct GNUNET_TUN_IPv6Header) + 8; | ||
2087 | make_up_icmpv6_payload(state, | ||
2088 | ipp, | ||
2089 | udp); | ||
2090 | payload = ipp; | ||
2091 | } | ||
2092 | break; | ||
2093 | |||
2094 | default: | ||
2095 | GNUNET_break_op(0); | ||
2096 | GNUNET_STATISTICS_update(stats, | ||
2097 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), | ||
2098 | 1, GNUNET_NO); | ||
2099 | return; | ||
2100 | } | ||
2101 | /* end AF_INET6 */ | ||
2075 | break; | 2102 | break; |
2103 | |||
2076 | default: | 2104 | default: |
2077 | GNUNET_break_op (0); | 2105 | /* bad AF */ |
2078 | GNUNET_STATISTICS_update (stats, | 2106 | GNUNET_break_op(0); |
2079 | gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), | ||
2080 | 1, GNUNET_NO); | ||
2081 | return; | 2107 | return; |
2082 | } | 2108 | } |
2083 | /* end AF_INET6 */ | ||
2084 | break; | ||
2085 | default: | ||
2086 | /* bad AF */ | ||
2087 | GNUNET_break_op (0); | ||
2088 | return; | ||
2089 | } | ||
2090 | 2109 | ||
2091 | { | 2110 | { |
2092 | char buf[INET6_ADDRSTRLEN]; | 2111 | char buf[INET6_ADDRSTRLEN]; |
2093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2112 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2094 | "Received ICMP data from %s for forwarding to %s\n", | 2113 | "Received ICMP data from %s for forwarding to %s\n", |
2095 | GNUNET_i2s (&state->peer), | 2114 | GNUNET_i2s(&state->peer), |
2096 | inet_ntop (af, | 2115 | inet_ntop(af, |
2097 | &state->specifics.tcp_udp.ri.remote_address.address, | 2116 | &state->specifics.tcp_udp.ri.remote_address.address, |
2098 | buf, sizeof (buf))); | 2117 | buf, sizeof(buf))); |
2099 | } | 2118 | } |
2100 | send_icmp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, | 2119 | send_icmp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, |
2101 | &state->specifics.tcp_udp.ri.local_address, | 2120 | &state->specifics.tcp_udp.ri.local_address, |
2102 | &msg->icmp_header, | 2121 | &msg->icmp_header, |
2103 | payload, pkt_len); | 2122 | payload, pkt_len); |
2104 | GNUNET_CADET_receive_done (state->channel); | 2123 | GNUNET_CADET_receive_done(state->channel); |
2105 | } | 2124 | } |
2106 | 2125 | ||
2107 | 2126 | ||
@@ -2115,42 +2134,44 @@ handle_icmp_remote (void *cls, | |||
2115 | * @return number of bytes of payload we created in buf | 2134 | * @return number of bytes of payload we created in buf |
2116 | */ | 2135 | */ |
2117 | static uint16_t | 2136 | static uint16_t |
2118 | make_up_icmp_service_payload (struct ChannelState *state, | 2137 | make_up_icmp_service_payload(struct ChannelState *state, |
2119 | char *buf) | 2138 | char *buf) |
2120 | { | 2139 | { |
2121 | switch (state->specifics.tcp_udp.serv->address.af) | 2140 | switch (state->specifics.tcp_udp.serv->address.af) |
2122 | { | 2141 | { |
2123 | case AF_INET: | 2142 | case AF_INET: |
2124 | { | 2143 | { |
2125 | struct GNUNET_TUN_IPv4Header *ipv4; | 2144 | struct GNUNET_TUN_IPv4Header *ipv4; |
2126 | struct GNUNET_TUN_UdpHeader *udp; | 2145 | struct GNUNET_TUN_UdpHeader *udp; |
2127 | 2146 | ||
2128 | ipv4 = (struct GNUNET_TUN_IPv4Header *)buf; | 2147 | ipv4 = (struct GNUNET_TUN_IPv4Header *)buf; |
2129 | udp = (struct GNUNET_TUN_UdpHeader *) &ipv4[1]; | 2148 | udp = (struct GNUNET_TUN_UdpHeader *)&ipv4[1]; |
2130 | make_up_icmpv4_payload (state, | 2149 | make_up_icmpv4_payload(state, |
2131 | ipv4, | 2150 | ipv4, |
2132 | udp); | 2151 | udp); |
2133 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); | 2152 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); |
2134 | return sizeof (struct GNUNET_TUN_IPv4Header) + 8; | 2153 | return sizeof(struct GNUNET_TUN_IPv4Header) + 8; |
2135 | } | 2154 | } |
2136 | break; | 2155 | break; |
2137 | case AF_INET6: | 2156 | |
2157 | case AF_INET6: | ||
2138 | { | 2158 | { |
2139 | struct GNUNET_TUN_IPv6Header *ipv6; | 2159 | struct GNUNET_TUN_IPv6Header *ipv6; |
2140 | struct GNUNET_TUN_UdpHeader *udp; | 2160 | struct GNUNET_TUN_UdpHeader *udp; |
2141 | 2161 | ||
2142 | ipv6 = (struct GNUNET_TUN_IPv6Header *)buf; | 2162 | ipv6 = (struct GNUNET_TUN_IPv6Header *)buf; |
2143 | udp = (struct GNUNET_TUN_UdpHeader *) &ipv6[1]; | 2163 | udp = (struct GNUNET_TUN_UdpHeader *)&ipv6[1]; |
2144 | make_up_icmpv6_payload (state, | 2164 | make_up_icmpv6_payload(state, |
2145 | ipv6, | 2165 | ipv6, |
2146 | udp); | 2166 | udp); |
2147 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); | 2167 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); |
2148 | return sizeof (struct GNUNET_TUN_IPv6Header) + 8; | 2168 | return sizeof(struct GNUNET_TUN_IPv6Header) + 8; |
2149 | } | 2169 | } |
2150 | break; | 2170 | break; |
2151 | default: | 2171 | |
2152 | GNUNET_break (0); | 2172 | default: |
2153 | } | 2173 | GNUNET_break(0); |
2174 | } | ||
2154 | return 0; | 2175 | return 0; |
2155 | } | 2176 | } |
2156 | 2177 | ||
@@ -2165,21 +2186,21 @@ make_up_icmp_service_payload (struct ChannelState *state, | |||
2165 | * #GNUNET_SYSERR to close it (signal serious error) | 2186 | * #GNUNET_SYSERR to close it (signal serious error) |
2166 | */ | 2187 | */ |
2167 | static int | 2188 | static int |
2168 | check_icmp_service (void *cls, | 2189 | check_icmp_service(void *cls, |
2169 | const struct GNUNET_EXIT_IcmpServiceMessage *msg) | 2190 | const struct GNUNET_EXIT_IcmpServiceMessage *msg) |
2170 | { | 2191 | { |
2171 | struct ChannelState *state = cls; | 2192 | struct ChannelState *state = cls; |
2172 | 2193 | ||
2173 | if (GNUNET_YES == state->is_dns) | 2194 | if (GNUNET_YES == state->is_dns) |
2174 | { | 2195 | { |
2175 | GNUNET_break_op (0); | 2196 | GNUNET_break_op(0); |
2176 | return GNUNET_SYSERR; | 2197 | return GNUNET_SYSERR; |
2177 | } | 2198 | } |
2178 | if (NULL == state->specifics.tcp_udp.serv) | 2199 | if (NULL == state->specifics.tcp_udp.serv) |
2179 | { | 2200 | { |
2180 | GNUNET_break_op (0); | 2201 | GNUNET_break_op(0); |
2181 | return GNUNET_SYSERR; | 2202 | return GNUNET_SYSERR; |
2182 | } | 2203 | } |
2183 | return GNUNET_OK; | 2204 | return GNUNET_OK; |
2184 | } | 2205 | } |
2185 | 2206 | ||
@@ -2192,164 +2213,176 @@ check_icmp_service (void *cls, | |||
2192 | * @param msg the actual message | 2213 | * @param msg the actual message |
2193 | */ | 2214 | */ |
2194 | static void | 2215 | static void |
2195 | handle_icmp_service (void *cls, | 2216 | handle_icmp_service(void *cls, |
2196 | const struct GNUNET_EXIT_IcmpServiceMessage *msg) | 2217 | const struct GNUNET_EXIT_IcmpServiceMessage *msg) |
2197 | { | 2218 | { |
2198 | struct ChannelState *state = cls; | 2219 | struct ChannelState *state = cls; |
2199 | uint16_t pkt_len = ntohs (msg->header.size) - sizeof (struct GNUNET_EXIT_IcmpServiceMessage); | 2220 | uint16_t pkt_len = ntohs(msg->header.size) - sizeof(struct GNUNET_EXIT_IcmpServiceMessage); |
2200 | struct GNUNET_TUN_IcmpHeader icmp; | 2221 | struct GNUNET_TUN_IcmpHeader icmp; |
2201 | char buf[sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; | 2222 | char buf[sizeof(struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; |
2202 | const void *payload; | 2223 | const void *payload; |
2203 | 2224 | ||
2204 | GNUNET_STATISTICS_update (stats, | 2225 | GNUNET_STATISTICS_update(stats, |
2205 | gettext_noop ("# Bytes received from CADET"), | 2226 | gettext_noop("# Bytes received from CADET"), |
2206 | pkt_len, GNUNET_NO); | 2227 | pkt_len, GNUNET_NO); |
2207 | GNUNET_STATISTICS_update (stats, | 2228 | GNUNET_STATISTICS_update(stats, |
2208 | gettext_noop ("# ICMP service requests received via cadet"), | 2229 | gettext_noop("# ICMP service requests received via cadet"), |
2209 | 1, GNUNET_NO); | 2230 | 1, GNUNET_NO); |
2210 | /* check that we got at least a valid header */ | 2231 | /* check that we got at least a valid header */ |
2211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2232 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2212 | "Received data from %s for forwarding to ICMP service %s\n", | 2233 | "Received data from %s for forwarding to ICMP service %s\n", |
2213 | GNUNET_i2s (&state->peer), | 2234 | GNUNET_i2s(&state->peer), |
2214 | GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor)); | 2235 | GNUNET_h2s(&state->specifics.tcp_udp.serv->descriptor)); |
2215 | icmp = msg->icmp_header; | 2236 | icmp = msg->icmp_header; |
2216 | payload = &msg[1]; | 2237 | payload = &msg[1]; |
2217 | state->specifics.tcp_udp.ri.remote_address | 2238 | state->specifics.tcp_udp.ri.remote_address |
2218 | = state->specifics.tcp_udp.serv->address; | 2239 | = state->specifics.tcp_udp.serv->address; |
2219 | setup_state_record (state); | 2240 | setup_state_record(state); |
2220 | 2241 | ||
2221 | /* check that ICMP type is something we want to support, | 2242 | /* check that ICMP type is something we want to support, |
2222 | perform ICMP PT if needed ans possibly make up payload */ | 2243 | perform ICMP PT if needed ans possibly make up payload */ |
2223 | switch (msg->af) | 2244 | switch (msg->af) |
2224 | { | ||
2225 | case AF_INET: | ||
2226 | switch (msg->icmp_header.type) | ||
2227 | { | ||
2228 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
2229 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2230 | icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; | ||
2231 | break; | ||
2232 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
2233 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2234 | icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; | ||
2235 | break; | ||
2236 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
2237 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2238 | icmp.type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; | ||
2239 | if (0 != pkt_len) | ||
2240 | { | ||
2241 | GNUNET_break_op (0); | ||
2242 | return; | ||
2243 | } | ||
2244 | payload = buf; | ||
2245 | pkt_len = make_up_icmp_service_payload (state, buf); | ||
2246 | break; | ||
2247 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
2248 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2249 | icmp.type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; | ||
2250 | if (0 != pkt_len) | ||
2251 | { | ||
2252 | GNUNET_break_op (0); | ||
2253 | return; | ||
2254 | } | ||
2255 | payload = buf; | ||
2256 | pkt_len = make_up_icmp_service_payload (state, buf); | ||
2257 | break; | ||
2258 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2259 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2260 | { | ||
2261 | GNUNET_STATISTICS_update (stats, | ||
2262 | gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), | ||
2263 | 1, GNUNET_NO); | ||
2264 | return; | ||
2265 | } | ||
2266 | if (0 != pkt_len) | ||
2267 | { | ||
2268 | GNUNET_break_op (0); | ||
2269 | return; | ||
2270 | } | ||
2271 | payload = buf; | ||
2272 | pkt_len = make_up_icmp_service_payload (state, buf); | ||
2273 | break; | ||
2274 | default: | ||
2275 | GNUNET_break_op (0); | ||
2276 | GNUNET_STATISTICS_update (stats, | ||
2277 | gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), | ||
2278 | 1, GNUNET_NO); | ||
2279 | return; | ||
2280 | } | ||
2281 | /* end of AF_INET */ | ||
2282 | break; | ||
2283 | case AF_INET6: | ||
2284 | switch (msg->icmp_header.type) | ||
2285 | { | 2245 | { |
2286 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | 2246 | case AF_INET: |
2287 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2247 | switch (msg->icmp_header.type) |
2288 | icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; | 2248 | { |
2289 | break; | 2249 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
2290 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | 2250 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2291 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2251 | icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; |
2292 | icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; | 2252 | break; |
2293 | break; | 2253 | |
2294 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | 2254 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: |
2295 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2255 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2296 | icmp.type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; | 2256 | icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; |
2297 | if (0 != pkt_len) | 2257 | break; |
2298 | { | 2258 | |
2299 | GNUNET_break_op (0); | 2259 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: |
2300 | return; | 2260 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2301 | } | 2261 | icmp.type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; |
2302 | payload = buf; | 2262 | if (0 != pkt_len) |
2303 | pkt_len = make_up_icmp_service_payload (state, buf); | 2263 | { |
2304 | break; | 2264 | GNUNET_break_op(0); |
2305 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | 2265 | return; |
2306 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2266 | } |
2307 | icmp.type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; | 2267 | payload = buf; |
2308 | if (0 != pkt_len) | 2268 | pkt_len = make_up_icmp_service_payload(state, buf); |
2309 | { | 2269 | break; |
2310 | GNUNET_break_op (0); | 2270 | |
2311 | return; | 2271 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
2312 | } | 2272 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2313 | payload = buf; | 2273 | icmp.type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; |
2314 | pkt_len = make_up_icmp_service_payload (state, buf); | 2274 | if (0 != pkt_len) |
2275 | { | ||
2276 | GNUNET_break_op(0); | ||
2277 | return; | ||
2278 | } | ||
2279 | payload = buf; | ||
2280 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2281 | break; | ||
2282 | |||
2283 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2284 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2285 | { | ||
2286 | GNUNET_STATISTICS_update(stats, | ||
2287 | gettext_noop("# ICMPv4 packets dropped (impossible PT to v6)"), | ||
2288 | 1, GNUNET_NO); | ||
2289 | return; | ||
2290 | } | ||
2291 | if (0 != pkt_len) | ||
2292 | { | ||
2293 | GNUNET_break_op(0); | ||
2294 | return; | ||
2295 | } | ||
2296 | payload = buf; | ||
2297 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2298 | break; | ||
2299 | |||
2300 | default: | ||
2301 | GNUNET_break_op(0); | ||
2302 | GNUNET_STATISTICS_update(stats, | ||
2303 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), | ||
2304 | 1, GNUNET_NO); | ||
2305 | return; | ||
2306 | } | ||
2307 | /* end of AF_INET */ | ||
2315 | break; | 2308 | break; |
2316 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | 2309 | |
2317 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | 2310 | case AF_INET6: |
2318 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2311 | switch (msg->icmp_header.type) |
2319 | { | 2312 | { |
2320 | GNUNET_STATISTICS_update (stats, | 2313 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: |
2321 | gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), | 2314 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) |
2322 | 1, GNUNET_NO); | 2315 | icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; |
2323 | return; | 2316 | break; |
2324 | } | 2317 | |
2325 | if (0 != pkt_len) | 2318 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: |
2326 | { | 2319 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) |
2327 | GNUNET_break_op (0); | 2320 | icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; |
2328 | return; | 2321 | break; |
2329 | } | 2322 | |
2330 | payload = buf; | 2323 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: |
2331 | pkt_len = make_up_icmp_service_payload (state, buf); | 2324 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) |
2325 | icmp.type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; | ||
2326 | if (0 != pkt_len) | ||
2327 | { | ||
2328 | GNUNET_break_op(0); | ||
2329 | return; | ||
2330 | } | ||
2331 | payload = buf; | ||
2332 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2333 | break; | ||
2334 | |||
2335 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
2336 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | ||
2337 | icmp.type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; | ||
2338 | if (0 != pkt_len) | ||
2339 | { | ||
2340 | GNUNET_break_op(0); | ||
2341 | return; | ||
2342 | } | ||
2343 | payload = buf; | ||
2344 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2345 | break; | ||
2346 | |||
2347 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
2348 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
2349 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | ||
2350 | { | ||
2351 | GNUNET_STATISTICS_update(stats, | ||
2352 | gettext_noop("# ICMPv6 packets dropped (impossible PT to v4)"), | ||
2353 | 1, GNUNET_NO); | ||
2354 | return; | ||
2355 | } | ||
2356 | if (0 != pkt_len) | ||
2357 | { | ||
2358 | GNUNET_break_op(0); | ||
2359 | return; | ||
2360 | } | ||
2361 | payload = buf; | ||
2362 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2363 | break; | ||
2364 | |||
2365 | default: | ||
2366 | GNUNET_break_op(0); | ||
2367 | GNUNET_STATISTICS_update(stats, | ||
2368 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), | ||
2369 | 1, GNUNET_NO); | ||
2370 | return; | ||
2371 | } | ||
2372 | /* end of AF_INET6 */ | ||
2332 | break; | 2373 | break; |
2374 | |||
2333 | default: | 2375 | default: |
2334 | GNUNET_break_op (0); | 2376 | GNUNET_break_op(0); |
2335 | GNUNET_STATISTICS_update (stats, | ||
2336 | gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), | ||
2337 | 1, GNUNET_NO); | ||
2338 | return; | 2377 | return; |
2339 | } | 2378 | } |
2340 | /* end of AF_INET6 */ | ||
2341 | break; | ||
2342 | default: | ||
2343 | GNUNET_break_op (0); | ||
2344 | return; | ||
2345 | } | ||
2346 | 2379 | ||
2347 | send_icmp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, | 2380 | send_icmp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, |
2348 | &state->specifics.tcp_udp.ri.local_address, | 2381 | &state->specifics.tcp_udp.ri.local_address, |
2349 | &icmp, | 2382 | &icmp, |
2350 | payload, | 2383 | payload, |
2351 | pkt_len); | 2384 | pkt_len); |
2352 | GNUNET_CADET_receive_done (state->channel); | 2385 | GNUNET_CADET_receive_done(state->channel); |
2353 | } | 2386 | } |
2354 | 2387 | ||
2355 | 2388 | ||
@@ -2362,19 +2395,19 @@ handle_icmp_service (void *cls, | |||
2362 | * @return #GNUNET_OK | 2395 | * @return #GNUNET_OK |
2363 | */ | 2396 | */ |
2364 | static int | 2397 | static int |
2365 | free_service_record (void *cls, | 2398 | free_service_record(void *cls, |
2366 | const struct GNUNET_HashCode *key, | 2399 | const struct GNUNET_HashCode *key, |
2367 | void *value) | 2400 | void *value) |
2368 | { | 2401 | { |
2369 | struct LocalService *service = value; | 2402 | struct LocalService *service = value; |
2370 | 2403 | ||
2371 | GNUNET_assert (GNUNET_YES == | 2404 | GNUNET_assert(GNUNET_YES == |
2372 | GNUNET_CONTAINER_multihashmap_remove (services, | 2405 | GNUNET_CONTAINER_multihashmap_remove(services, |
2373 | key, | 2406 | key, |
2374 | service)); | 2407 | service)); |
2375 | GNUNET_CADET_close_port (service->port); | 2408 | GNUNET_CADET_close_port(service->port); |
2376 | GNUNET_free_non_null (service->name); | 2409 | GNUNET_free_non_null(service->name); |
2377 | GNUNET_free (service); | 2410 | GNUNET_free(service); |
2378 | return GNUNET_OK; | 2411 | return GNUNET_OK; |
2379 | } | 2412 | } |
2380 | 2413 | ||
@@ -2388,21 +2421,21 @@ free_service_record (void *cls, | |||
2388 | * @return initial channel context for the channel | 2421 | * @return initial channel context for the channel |
2389 | */ | 2422 | */ |
2390 | static void * | 2423 | static void * |
2391 | new_service_channel (void *cls, | 2424 | new_service_channel(void *cls, |
2392 | struct GNUNET_CADET_Channel *channel, | 2425 | struct GNUNET_CADET_Channel *channel, |
2393 | const struct GNUNET_PeerIdentity *initiator) | 2426 | const struct GNUNET_PeerIdentity *initiator) |
2394 | { | 2427 | { |
2395 | struct LocalService *ls = cls; | 2428 | struct LocalService *ls = cls; |
2396 | struct ChannelState *s = GNUNET_new (struct ChannelState); | 2429 | struct ChannelState *s = GNUNET_new(struct ChannelState); |
2397 | 2430 | ||
2398 | s->peer = *initiator; | 2431 | s->peer = *initiator; |
2399 | GNUNET_STATISTICS_update (stats, | 2432 | GNUNET_STATISTICS_update(stats, |
2400 | gettext_noop ("# Inbound CADET channels created"), | 2433 | gettext_noop("# Inbound CADET channels created"), |
2401 | 1, | 2434 | 1, |
2402 | GNUNET_NO); | 2435 | GNUNET_NO); |
2403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2404 | "Received inbound channel from `%s'\n", | 2437 | "Received inbound channel from `%s'\n", |
2405 | GNUNET_i2s (initiator)); | 2438 | GNUNET_i2s(initiator)); |
2406 | s->channel = channel; | 2439 | s->channel = channel; |
2407 | s->specifics.tcp_udp.serv = ls; | 2440 | s->specifics.tcp_udp.serv = ls; |
2408 | s->specifics.tcp_udp.ri.remote_address = ls->address; | 2441 | s->specifics.tcp_udp.ri.remote_address = ls->address; |
@@ -2418,36 +2451,36 @@ new_service_channel (void *cls, | |||
2418 | * @param channel connection to the other end (henceforth invalid) | 2451 | * @param channel connection to the other end (henceforth invalid) |
2419 | */ | 2452 | */ |
2420 | static void | 2453 | static void |
2421 | clean_channel (void *cls, | 2454 | clean_channel(void *cls, |
2422 | const struct GNUNET_CADET_Channel *channel) | 2455 | const struct GNUNET_CADET_Channel *channel) |
2423 | { | 2456 | { |
2424 | struct ChannelState *s = cls; | 2457 | struct ChannelState *s = cls; |
2425 | 2458 | ||
2426 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2459 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2427 | "Channel destroyed\n"); | 2460 | "Channel destroyed\n"); |
2428 | if (GNUNET_SYSERR == s->is_dns) | 2461 | if (GNUNET_SYSERR == s->is_dns) |
2429 | { | 2462 | { |
2430 | GNUNET_free (s); | 2463 | GNUNET_free(s); |
2431 | return; | 2464 | return; |
2432 | } | 2465 | } |
2433 | if (GNUNET_YES == s->is_dns) | 2466 | if (GNUNET_YES == s->is_dns) |
2434 | { | 2467 | { |
2435 | if (channels[s->specifics.dns.my_id] == s) | 2468 | if (channels[s->specifics.dns.my_id] == s) |
2436 | channels[s->specifics.dns.my_id] = NULL; | 2469 | channels[s->specifics.dns.my_id] = NULL; |
2437 | } | 2470 | } |
2438 | else | 2471 | else |
2439 | { | ||
2440 | if (NULL != s->specifics.tcp_udp.heap_node) | ||
2441 | { | 2472 | { |
2442 | GNUNET_assert (GNUNET_YES == | 2473 | if (NULL != s->specifics.tcp_udp.heap_node) |
2443 | GNUNET_CONTAINER_multihashmap_remove (connections_map, | 2474 | { |
2444 | &s->specifics.tcp_udp.state_key, | 2475 | GNUNET_assert(GNUNET_YES == |
2445 | s)); | 2476 | GNUNET_CONTAINER_multihashmap_remove(connections_map, |
2446 | GNUNET_CONTAINER_heap_remove_node (s->specifics.tcp_udp.heap_node); | 2477 | &s->specifics.tcp_udp.state_key, |
2447 | s->specifics.tcp_udp.heap_node = NULL; | 2478 | s)); |
2479 | GNUNET_CONTAINER_heap_remove_node(s->specifics.tcp_udp.heap_node); | ||
2480 | s->specifics.tcp_udp.heap_node = NULL; | ||
2481 | } | ||
2448 | } | 2482 | } |
2449 | } | 2483 | GNUNET_free(s); |
2450 | GNUNET_free (s); | ||
2451 | } | 2484 | } |
2452 | 2485 | ||
2453 | 2486 | ||
@@ -2461,66 +2494,66 @@ clean_channel (void *cls, | |||
2461 | * @param service service information record to store (service->name will be set). | 2494 | * @param service service information record to store (service->name will be set). |
2462 | */ | 2495 | */ |
2463 | static void | 2496 | static void |
2464 | store_service (int proto, | 2497 | store_service(int proto, |
2465 | const char *name, | 2498 | const char *name, |
2466 | uint16_t destination_port, | 2499 | uint16_t destination_port, |
2467 | struct LocalService *service) | 2500 | struct LocalService *service) |
2468 | { | 2501 | { |
2469 | struct GNUNET_MQ_MessageHandler handlers[] = { | 2502 | struct GNUNET_MQ_MessageHandler handlers[] = { |
2470 | GNUNET_MQ_hd_var_size (icmp_service, | 2503 | GNUNET_MQ_hd_var_size(icmp_service, |
2471 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE, | 2504 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE, |
2472 | struct GNUNET_EXIT_IcmpServiceMessage, | 2505 | struct GNUNET_EXIT_IcmpServiceMessage, |
2473 | service), | 2506 | service), |
2474 | GNUNET_MQ_hd_var_size (udp_service, | 2507 | GNUNET_MQ_hd_var_size(udp_service, |
2475 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE, | 2508 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE, |
2476 | struct GNUNET_EXIT_UdpServiceMessage, | 2509 | struct GNUNET_EXIT_UdpServiceMessage, |
2477 | service), | 2510 | service), |
2478 | GNUNET_MQ_hd_var_size (tcp_service, | 2511 | GNUNET_MQ_hd_var_size(tcp_service, |
2479 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START, | 2512 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START, |
2480 | struct GNUNET_EXIT_TcpServiceStartMessage, | 2513 | struct GNUNET_EXIT_TcpServiceStartMessage, |
2481 | service), | 2514 | service), |
2482 | GNUNET_MQ_hd_var_size (tcp_data, | 2515 | GNUNET_MQ_hd_var_size(tcp_data, |
2483 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, | 2516 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, |
2484 | struct GNUNET_EXIT_TcpDataMessage, | 2517 | struct GNUNET_EXIT_TcpDataMessage, |
2485 | service), | 2518 | service), |
2486 | GNUNET_MQ_handler_end () | 2519 | GNUNET_MQ_handler_end() |
2487 | }; | 2520 | }; |
2488 | 2521 | ||
2489 | struct GNUNET_HashCode cadet_port; | 2522 | struct GNUNET_HashCode cadet_port; |
2490 | 2523 | ||
2491 | service->name = GNUNET_strdup (name); | 2524 | service->name = GNUNET_strdup(name); |
2492 | GNUNET_TUN_service_name_to_hash (name, | 2525 | GNUNET_TUN_service_name_to_hash(name, |
2493 | &service->descriptor); | 2526 | &service->descriptor); |
2494 | GNUNET_TUN_compute_service_cadet_port (&service->descriptor, | 2527 | GNUNET_TUN_compute_service_cadet_port(&service->descriptor, |
2495 | destination_port, | 2528 | destination_port, |
2496 | &cadet_port); | 2529 | &cadet_port); |
2497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2530 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2498 | "Opening CADET port %s for SERVICE exit %s on port %u\n", | 2531 | "Opening CADET port %s for SERVICE exit %s on port %u\n", |
2499 | GNUNET_h2s (&cadet_port), | 2532 | GNUNET_h2s(&cadet_port), |
2500 | name, | 2533 | name, |
2501 | (unsigned int) destination_port); | 2534 | (unsigned int)destination_port); |
2502 | service->port = GNUNET_CADET_open_port (cadet_handle, | 2535 | service->port = GNUNET_CADET_open_port(cadet_handle, |
2503 | &cadet_port, | 2536 | &cadet_port, |
2504 | &new_service_channel, | 2537 | &new_service_channel, |
2505 | service, | 2538 | service, |
2506 | NULL, | 2539 | NULL, |
2507 | &clean_channel, | 2540 | &clean_channel, |
2508 | handlers); | 2541 | handlers); |
2509 | service->is_udp = (IPPROTO_UDP == proto); | 2542 | service->is_udp = (IPPROTO_UDP == proto); |
2510 | if (GNUNET_OK != | 2543 | if (GNUNET_OK != |
2511 | GNUNET_CONTAINER_multihashmap_put (services, | 2544 | GNUNET_CONTAINER_multihashmap_put(services, |
2512 | &cadet_port, | 2545 | &cadet_port, |
2513 | service, | 2546 | service, |
2514 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 2547 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
2515 | { | 2548 | { |
2516 | GNUNET_CADET_close_port (service->port); | 2549 | GNUNET_CADET_close_port(service->port); |
2517 | GNUNET_free_non_null (service->name); | 2550 | GNUNET_free_non_null(service->name); |
2518 | GNUNET_free (service); | 2551 | GNUNET_free(service); |
2519 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2552 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2520 | _("Got duplicate service records for `%s:%u'\n"), | 2553 | _("Got duplicate service records for `%s:%u'\n"), |
2521 | name, | 2554 | name, |
2522 | (unsigned int) destination_port); | 2555 | (unsigned int)destination_port); |
2523 | } | 2556 | } |
2524 | } | 2557 | } |
2525 | 2558 | ||
2526 | 2559 | ||
@@ -2531,16 +2564,16 @@ store_service (int proto, | |||
2531 | * @param env message to queue | 2564 | * @param env message to queue |
2532 | */ | 2565 | */ |
2533 | static void | 2566 | static void |
2534 | send_packet_to_cadet_channel (struct ChannelState *s, | 2567 | send_packet_to_cadet_channel(struct ChannelState *s, |
2535 | struct GNUNET_MQ_Envelope *env) | 2568 | struct GNUNET_MQ_Envelope *env) |
2536 | { | 2569 | { |
2537 | GNUNET_assert (NULL != s); | 2570 | GNUNET_assert(NULL != s); |
2538 | GNUNET_STATISTICS_update (stats, | 2571 | GNUNET_STATISTICS_update(stats, |
2539 | gettext_noop ("# Messages transmitted via cadet channels"), | 2572 | gettext_noop("# Messages transmitted via cadet channels"), |
2540 | 1, | 2573 | 1, |
2541 | GNUNET_NO); | 2574 | GNUNET_NO); |
2542 | GNUNET_MQ_send (GNUNET_CADET_get_mq (s->channel), | 2575 | GNUNET_MQ_send(GNUNET_CADET_get_mq(s->channel), |
2543 | env); | 2576 | env); |
2544 | } | 2577 | } |
2545 | 2578 | ||
2546 | 2579 | ||
@@ -2556,11 +2589,11 @@ send_packet_to_cadet_channel (struct ChannelState *s, | |||
2556 | * be the original destination address) | 2589 | * be the original destination address) |
2557 | */ | 2590 | */ |
2558 | static void | 2591 | static void |
2559 | icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, | 2592 | icmp_from_helper(const struct GNUNET_TUN_IcmpHeader *icmp, |
2560 | size_t pktlen, | 2593 | size_t pktlen, |
2561 | int af, | 2594 | int af, |
2562 | const void *destination_ip, | 2595 | const void *destination_ip, |
2563 | const void *source_ip) | 2596 | const void *source_ip) |
2564 | { | 2597 | { |
2565 | struct ChannelState *state; | 2598 | struct ChannelState *state; |
2566 | struct GNUNET_MQ_Envelope *env; | 2599 | struct GNUNET_MQ_Envelope *env; |
@@ -2575,165 +2608,176 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, | |||
2575 | { | 2608 | { |
2576 | char sbuf[INET6_ADDRSTRLEN]; | 2609 | char sbuf[INET6_ADDRSTRLEN]; |
2577 | char dbuf[INET6_ADDRSTRLEN]; | 2610 | char dbuf[INET6_ADDRSTRLEN]; |
2578 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2611 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2579 | "Received ICMP packet going from %s to %s\n", | 2612 | "Received ICMP packet going from %s to %s\n", |
2580 | inet_ntop (af, | 2613 | inet_ntop(af, |
2581 | source_ip, | 2614 | source_ip, |
2582 | sbuf, sizeof (sbuf)), | 2615 | sbuf, sizeof(sbuf)), |
2583 | inet_ntop (af, | 2616 | inet_ntop(af, |
2584 | destination_ip, | 2617 | destination_ip, |
2585 | dbuf, sizeof (dbuf))); | 2618 | dbuf, sizeof(dbuf))); |
2586 | } | ||
2587 | if (pktlen < sizeof (struct GNUNET_TUN_IcmpHeader)) | ||
2588 | { | ||
2589 | /* blame kernel */ | ||
2590 | GNUNET_break (0); | ||
2591 | return; | ||
2592 | } | 2619 | } |
2593 | 2620 | ||
2621 | if (pktlen < sizeof(struct GNUNET_TUN_IcmpHeader)) | ||
2622 | { | ||
2623 | /* blame kernel */ | ||
2624 | GNUNET_break(0); | ||
2625 | return; | ||
2626 | } | ||
2627 | |||
2594 | /* Find out if this is an ICMP packet in response to an existing | 2628 | /* Find out if this is an ICMP packet in response to an existing |
2595 | TCP/UDP packet and if so, figure out ports / protocol of the | 2629 | TCP/UDP packet and if so, figure out ports / protocol of the |
2596 | existing session from the IP data in the ICMP payload */ | 2630 | existing session from the IP data in the ICMP payload */ |
2597 | source_port = 0; | 2631 | source_port = 0; |
2598 | destination_port = 0; | 2632 | destination_port = 0; |
2599 | switch (af) | 2633 | switch (af) |
2600 | { | 2634 | { |
2601 | case AF_INET: | 2635 | case AF_INET: |
2602 | protocol = IPPROTO_ICMP; | 2636 | protocol = IPPROTO_ICMP; |
2603 | switch (icmp->type) | 2637 | switch (icmp->type) |
2604 | { | 2638 | { |
2605 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | 2639 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
2606 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | 2640 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: |
2607 | break; | 2641 | break; |
2608 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | 2642 | |
2609 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | 2643 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: |
2610 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | 2644 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
2611 | if (pktlen < | 2645 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
2612 | sizeof (struct GNUNET_TUN_IcmpHeader) + | 2646 | if (pktlen < |
2613 | sizeof (struct GNUNET_TUN_IPv4Header) + 8) | 2647 | sizeof(struct GNUNET_TUN_IcmpHeader) + |
2614 | { | 2648 | sizeof(struct GNUNET_TUN_IPv4Header) + 8) |
2615 | /* blame kernel */ | 2649 | { |
2616 | GNUNET_break (0); | 2650 | /* blame kernel */ |
2617 | return; | 2651 | GNUNET_break(0); |
2618 | } | 2652 | return; |
2619 | ipv4 = (const struct GNUNET_TUN_IPv4Header *) &icmp[1]; | 2653 | } |
2620 | protocol = ipv4->protocol; | 2654 | ipv4 = (const struct GNUNET_TUN_IPv4Header *)&icmp[1]; |
2621 | /* could be TCP or UDP, but both have the ports in the right | 2655 | protocol = ipv4->protocol; |
2622 | place, so that doesn't matter here */ | 2656 | /* could be TCP or UDP, but both have the ports in the right |
2623 | udp = (const struct GNUNET_TUN_UdpHeader *) &ipv4[1]; | 2657 | place, so that doesn't matter here */ |
2624 | /* swap ports, as they are from the original message */ | 2658 | udp = (const struct GNUNET_TUN_UdpHeader *)&ipv4[1]; |
2625 | destination_port = ntohs (udp->source_port); | 2659 | /* swap ports, as they are from the original message */ |
2626 | source_port = ntohs (udp->destination_port); | 2660 | destination_port = ntohs(udp->source_port); |
2627 | /* throw away ICMP payload, won't be useful for the other side anyway */ | 2661 | source_port = ntohs(udp->destination_port); |
2628 | pktlen = sizeof (struct GNUNET_TUN_IcmpHeader); | 2662 | /* throw away ICMP payload, won't be useful for the other side anyway */ |
2629 | break; | 2663 | pktlen = sizeof(struct GNUNET_TUN_IcmpHeader); |
2630 | default: | 2664 | break; |
2631 | GNUNET_STATISTICS_update (stats, | 2665 | |
2632 | gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), | 2666 | default: |
2633 | 1, GNUNET_NO); | 2667 | GNUNET_STATISTICS_update(stats, |
2634 | return; | 2668 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), |
2635 | } | 2669 | 1, GNUNET_NO); |
2636 | break; | 2670 | return; |
2637 | case AF_INET6: | 2671 | } |
2638 | protocol = IPPROTO_ICMPV6; | 2672 | break; |
2639 | switch (icmp->type) | 2673 | |
2640 | { | 2674 | case AF_INET6: |
2641 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | 2675 | protocol = IPPROTO_ICMPV6; |
2642 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | 2676 | switch (icmp->type) |
2643 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | 2677 | { |
2644 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | 2678 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: |
2645 | if (pktlen < | 2679 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: |
2646 | sizeof (struct GNUNET_TUN_IcmpHeader) + | 2680 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: |
2647 | sizeof (struct GNUNET_TUN_IPv6Header) + 8) | 2681 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: |
2648 | { | 2682 | if (pktlen < |
2649 | /* blame kernel */ | 2683 | sizeof(struct GNUNET_TUN_IcmpHeader) + |
2650 | GNUNET_break (0); | 2684 | sizeof(struct GNUNET_TUN_IPv6Header) + 8) |
2651 | return; | 2685 | { |
2652 | } | 2686 | /* blame kernel */ |
2653 | ipv6 = (const struct GNUNET_TUN_IPv6Header *) &icmp[1]; | 2687 | GNUNET_break(0); |
2654 | protocol = ipv6->next_header; | 2688 | return; |
2655 | /* could be TCP or UDP, but both have the ports in the right | 2689 | } |
2656 | place, so that doesn't matter here */ | 2690 | ipv6 = (const struct GNUNET_TUN_IPv6Header *)&icmp[1]; |
2657 | udp = (const struct GNUNET_TUN_UdpHeader *) &ipv6[1]; | 2691 | protocol = ipv6->next_header; |
2658 | /* swap ports, as they are from the original message */ | 2692 | /* could be TCP or UDP, but both have the ports in the right |
2659 | destination_port = ntohs (udp->source_port); | 2693 | place, so that doesn't matter here */ |
2660 | source_port = ntohs (udp->destination_port); | 2694 | udp = (const struct GNUNET_TUN_UdpHeader *)&ipv6[1]; |
2661 | /* throw away ICMP payload, won't be useful for the other side anyway */ | 2695 | /* swap ports, as they are from the original message */ |
2662 | pktlen = sizeof (struct GNUNET_TUN_IcmpHeader); | 2696 | destination_port = ntohs(udp->source_port); |
2663 | break; | 2697 | source_port = ntohs(udp->destination_port); |
2664 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | 2698 | /* throw away ICMP payload, won't be useful for the other side anyway */ |
2665 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | 2699 | pktlen = sizeof(struct GNUNET_TUN_IcmpHeader); |
2666 | break; | 2700 | break; |
2667 | default: | 2701 | |
2668 | GNUNET_STATISTICS_update (stats, | 2702 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: |
2669 | gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), | 2703 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: |
2670 | 1, GNUNET_NO); | 2704 | break; |
2671 | return; | 2705 | |
2672 | } | 2706 | default: |
2673 | break; | 2707 | GNUNET_STATISTICS_update(stats, |
2674 | default: | 2708 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), |
2675 | GNUNET_assert (0); | 2709 | 1, GNUNET_NO); |
2676 | } | 2710 | return; |
2711 | } | ||
2712 | break; | ||
2713 | |||
2714 | default: | ||
2715 | GNUNET_assert(0); | ||
2716 | } | ||
2677 | switch (protocol) | 2717 | switch (protocol) |
2678 | { | 2718 | { |
2679 | case IPPROTO_ICMP: | 2719 | case IPPROTO_ICMP: |
2680 | state = get_redirect_state (af, | 2720 | state = get_redirect_state(af, |
2681 | IPPROTO_ICMP, | 2721 | IPPROTO_ICMP, |
2682 | source_ip, | 2722 | source_ip, |
2683 | 0, | 2723 | 0, |
2684 | destination_ip, | 2724 | destination_ip, |
2685 | 0, | 2725 | 0, |
2686 | NULL); | 2726 | NULL); |
2687 | break; | 2727 | break; |
2688 | case IPPROTO_ICMPV6: | 2728 | |
2689 | state = get_redirect_state (af, | 2729 | case IPPROTO_ICMPV6: |
2690 | IPPROTO_ICMPV6, | 2730 | state = get_redirect_state(af, |
2691 | source_ip, | 2731 | IPPROTO_ICMPV6, |
2692 | 0, | 2732 | source_ip, |
2693 | destination_ip, | 2733 | 0, |
2694 | 0, | 2734 | destination_ip, |
2695 | NULL); | 2735 | 0, |
2696 | break; | 2736 | NULL); |
2697 | case IPPROTO_UDP: | 2737 | break; |
2698 | state = get_redirect_state (af, | 2738 | |
2699 | IPPROTO_UDP, | 2739 | case IPPROTO_UDP: |
2700 | source_ip, | 2740 | state = get_redirect_state(af, |
2701 | source_port, | 2741 | IPPROTO_UDP, |
2702 | destination_ip, | 2742 | source_ip, |
2703 | destination_port, | 2743 | source_port, |
2704 | NULL); | 2744 | destination_ip, |
2705 | break; | 2745 | destination_port, |
2706 | case IPPROTO_TCP: | 2746 | NULL); |
2707 | state = get_redirect_state (af, | 2747 | break; |
2708 | IPPROTO_TCP, | 2748 | |
2709 | source_ip, | 2749 | case IPPROTO_TCP: |
2710 | source_port, | 2750 | state = get_redirect_state(af, |
2711 | destination_ip, | 2751 | IPPROTO_TCP, |
2712 | destination_port, | 2752 | source_ip, |
2713 | NULL); | 2753 | source_port, |
2714 | break; | 2754 | destination_ip, |
2715 | default: | 2755 | destination_port, |
2716 | GNUNET_STATISTICS_update (stats, | 2756 | NULL); |
2717 | gettext_noop ("# ICMP packets dropped (not allowed)"), | 2757 | break; |
2718 | 1, | 2758 | |
2719 | GNUNET_NO); | 2759 | default: |
2720 | return; | 2760 | GNUNET_STATISTICS_update(stats, |
2721 | } | 2761 | gettext_noop("# ICMP packets dropped (not allowed)"), |
2762 | 1, | ||
2763 | GNUNET_NO); | ||
2764 | return; | ||
2765 | } | ||
2722 | if (NULL == state) | 2766 | if (NULL == state) |
2723 | { | 2767 | { |
2724 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2768 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2725 | _("ICMP Packet dropped, have no matching connection information\n")); | 2769 | _("ICMP Packet dropped, have no matching connection information\n")); |
2726 | return; | 2770 | return; |
2727 | } | 2771 | } |
2728 | env = GNUNET_MQ_msg_extra (i2v, | 2772 | env = GNUNET_MQ_msg_extra(i2v, |
2729 | pktlen - sizeof (struct GNUNET_TUN_IcmpHeader), | 2773 | pktlen - sizeof(struct GNUNET_TUN_IcmpHeader), |
2730 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN); | 2774 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN); |
2731 | i2v->af = htonl (af); | 2775 | i2v->af = htonl(af); |
2732 | GNUNET_memcpy (&i2v->icmp_header, | 2776 | GNUNET_memcpy(&i2v->icmp_header, |
2733 | icmp, | 2777 | icmp, |
2734 | pktlen); | 2778 | pktlen); |
2735 | send_packet_to_cadet_channel (state, | 2779 | send_packet_to_cadet_channel(state, |
2736 | env); | 2780 | env); |
2737 | } | 2781 | } |
2738 | 2782 | ||
2739 | 2783 | ||
@@ -2749,11 +2793,11 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, | |||
2749 | * be the original destination address) | 2793 | * be the original destination address) |
2750 | */ | 2794 | */ |
2751 | static void | 2795 | static void |
2752 | udp_from_helper (const struct GNUNET_TUN_UdpHeader *udp, | 2796 | udp_from_helper(const struct GNUNET_TUN_UdpHeader *udp, |
2753 | size_t pktlen, | 2797 | size_t pktlen, |
2754 | int af, | 2798 | int af, |
2755 | const void *destination_ip, | 2799 | const void *destination_ip, |
2756 | const void *source_ip) | 2800 | const void *source_ip) |
2757 | { | 2801 | { |
2758 | struct ChannelState *state; | 2802 | struct ChannelState *state; |
2759 | struct GNUNET_MQ_Envelope *env; | 2803 | struct GNUNET_MQ_Envelope *env; |
@@ -2763,52 +2807,53 @@ udp_from_helper (const struct GNUNET_TUN_UdpHeader *udp, | |||
2763 | char sbuf[INET6_ADDRSTRLEN]; | 2807 | char sbuf[INET6_ADDRSTRLEN]; |
2764 | char dbuf[INET6_ADDRSTRLEN]; | 2808 | char dbuf[INET6_ADDRSTRLEN]; |
2765 | 2809 | ||
2766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2810 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2767 | "Received UDP packet going from %s:%u to %s:%u\n", | 2811 | "Received UDP packet going from %s:%u to %s:%u\n", |
2768 | inet_ntop (af, | 2812 | inet_ntop(af, |
2769 | source_ip, | 2813 | source_ip, |
2770 | sbuf, sizeof (sbuf)), | 2814 | sbuf, sizeof(sbuf)), |
2771 | (unsigned int) ntohs (udp->source_port), | 2815 | (unsigned int)ntohs(udp->source_port), |
2772 | inet_ntop (af, | 2816 | inet_ntop(af, |
2773 | destination_ip, | 2817 | destination_ip, |
2774 | dbuf, sizeof (dbuf)), | 2818 | dbuf, sizeof(dbuf)), |
2775 | (unsigned int) ntohs (udp->destination_port)); | 2819 | (unsigned int)ntohs(udp->destination_port)); |
2776 | } | ||
2777 | if (pktlen < sizeof (struct GNUNET_TUN_UdpHeader)) | ||
2778 | { | ||
2779 | /* blame kernel */ | ||
2780 | GNUNET_break (0); | ||
2781 | return; | ||
2782 | } | ||
2783 | if (pktlen != ntohs (udp->len)) | ||
2784 | { | ||
2785 | /* blame kernel */ | ||
2786 | GNUNET_break (0); | ||
2787 | return; | ||
2788 | } | 2820 | } |
2789 | state = get_redirect_state (af, | 2821 | |
2790 | IPPROTO_UDP, | 2822 | if (pktlen < sizeof(struct GNUNET_TUN_UdpHeader)) |
2791 | source_ip, | 2823 | { |
2792 | ntohs (udp->source_port), | 2824 | /* blame kernel */ |
2793 | destination_ip, | 2825 | GNUNET_break(0); |
2794 | ntohs (udp->destination_port), | 2826 | return; |
2795 | NULL); | 2827 | } |
2828 | if (pktlen != ntohs(udp->len)) | ||
2829 | { | ||
2830 | /* blame kernel */ | ||
2831 | GNUNET_break(0); | ||
2832 | return; | ||
2833 | } | ||
2834 | state = get_redirect_state(af, | ||
2835 | IPPROTO_UDP, | ||
2836 | source_ip, | ||
2837 | ntohs(udp->source_port), | ||
2838 | destination_ip, | ||
2839 | ntohs(udp->destination_port), | ||
2840 | NULL); | ||
2796 | if (NULL == state) | 2841 | if (NULL == state) |
2797 | { | 2842 | { |
2798 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2843 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2799 | _("UDP Packet dropped, have no matching connection information\n")); | 2844 | _("UDP Packet dropped, have no matching connection information\n")); |
2800 | return; | 2845 | return; |
2801 | } | 2846 | } |
2802 | env = GNUNET_MQ_msg_extra (urm, | 2847 | env = GNUNET_MQ_msg_extra(urm, |
2803 | pktlen - sizeof (struct GNUNET_TUN_UdpHeader), | 2848 | pktlen - sizeof(struct GNUNET_TUN_UdpHeader), |
2804 | GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY); | 2849 | GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY); |
2805 | urm->source_port = htons (0); | 2850 | urm->source_port = htons(0); |
2806 | urm->destination_port = htons (0); | 2851 | urm->destination_port = htons(0); |
2807 | GNUNET_memcpy (&urm[1], | 2852 | GNUNET_memcpy(&urm[1], |
2808 | &udp[1], | 2853 | &udp[1], |
2809 | pktlen - sizeof (struct GNUNET_TUN_UdpHeader)); | 2854 | pktlen - sizeof(struct GNUNET_TUN_UdpHeader)); |
2810 | send_packet_to_cadet_channel (state, | 2855 | send_packet_to_cadet_channel(state, |
2811 | env); | 2856 | env); |
2812 | } | 2857 | } |
2813 | 2858 | ||
2814 | 2859 | ||
@@ -2824,11 +2869,11 @@ udp_from_helper (const struct GNUNET_TUN_UdpHeader *udp, | |||
2824 | * be the original destination address) | 2869 | * be the original destination address) |
2825 | */ | 2870 | */ |
2826 | static void | 2871 | static void |
2827 | tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp, | 2872 | tcp_from_helper(const struct GNUNET_TUN_TcpHeader *tcp, |
2828 | size_t pktlen, | 2873 | size_t pktlen, |
2829 | int af, | 2874 | int af, |
2830 | const void *destination_ip, | 2875 | const void *destination_ip, |
2831 | const void *source_ip) | 2876 | const void *source_ip) |
2832 | { | 2877 | { |
2833 | struct ChannelState *state; | 2878 | struct ChannelState *state; |
2834 | char buf[pktlen] GNUNET_ALIGN; | 2879 | char buf[pktlen] GNUNET_ALIGN; |
@@ -2840,61 +2885,62 @@ tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp, | |||
2840 | { | 2885 | { |
2841 | char sbuf[INET6_ADDRSTRLEN]; | 2886 | char sbuf[INET6_ADDRSTRLEN]; |
2842 | char dbuf[INET6_ADDRSTRLEN]; | 2887 | char dbuf[INET6_ADDRSTRLEN]; |
2843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2888 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2844 | "Received TCP packet with %u bytes going from %s:%u to %s:%u\n", | 2889 | "Received TCP packet with %u bytes going from %s:%u to %s:%u\n", |
2845 | (unsigned int) (pktlen - sizeof (struct GNUNET_TUN_TcpHeader)), | 2890 | (unsigned int)(pktlen - sizeof(struct GNUNET_TUN_TcpHeader)), |
2846 | inet_ntop (af, | 2891 | inet_ntop(af, |
2847 | source_ip, | 2892 | source_ip, |
2848 | sbuf, sizeof (sbuf)), | 2893 | sbuf, sizeof(sbuf)), |
2849 | (unsigned int) ntohs (tcp->source_port), | 2894 | (unsigned int)ntohs(tcp->source_port), |
2850 | inet_ntop (af, | 2895 | inet_ntop(af, |
2851 | destination_ip, | 2896 | destination_ip, |
2852 | dbuf, sizeof (dbuf)), | 2897 | dbuf, sizeof(dbuf)), |
2853 | (unsigned int) ntohs (tcp->destination_port)); | 2898 | (unsigned int)ntohs(tcp->destination_port)); |
2854 | } | 2899 | } |
2855 | if (pktlen < sizeof (struct GNUNET_TUN_TcpHeader)) | 2900 | |
2856 | { | 2901 | if (pktlen < sizeof(struct GNUNET_TUN_TcpHeader)) |
2857 | /* blame kernel */ | 2902 | { |
2858 | GNUNET_break (0); | 2903 | /* blame kernel */ |
2859 | return; | 2904 | GNUNET_break(0); |
2860 | } | 2905 | return; |
2861 | state = get_redirect_state (af, | 2906 | } |
2862 | IPPROTO_TCP, | 2907 | state = get_redirect_state(af, |
2863 | source_ip, | 2908 | IPPROTO_TCP, |
2864 | ntohs (tcp->source_port), | 2909 | source_ip, |
2865 | destination_ip, | 2910 | ntohs(tcp->source_port), |
2866 | ntohs (tcp->destination_port), | 2911 | destination_ip, |
2867 | NULL); | 2912 | ntohs(tcp->destination_port), |
2913 | NULL); | ||
2868 | if (NULL == state) | 2914 | if (NULL == state) |
2869 | { | 2915 | { |
2870 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2916 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2871 | _("TCP Packet dropped, have no matching connection information\n")); | 2917 | _("TCP Packet dropped, have no matching connection information\n")); |
2872 | 2918 | ||
2873 | return; | 2919 | return; |
2874 | } | 2920 | } |
2875 | /* mug port numbers and crc to avoid information leakage; | 2921 | /* mug port numbers and crc to avoid information leakage; |
2876 | sender will need to lookup the correct values anyway */ | 2922 | sender will need to lookup the correct values anyway */ |
2877 | GNUNET_memcpy (buf, tcp, pktlen); | 2923 | GNUNET_memcpy(buf, tcp, pktlen); |
2878 | mtcp = (struct GNUNET_TUN_TcpHeader *) buf; | 2924 | mtcp = (struct GNUNET_TUN_TcpHeader *)buf; |
2879 | mtcp->source_port = 0; | 2925 | mtcp->source_port = 0; |
2880 | mtcp->destination_port = 0; | 2926 | mtcp->destination_port = 0; |
2881 | mtcp->crc = 0; | 2927 | mtcp->crc = 0; |
2882 | 2928 | ||
2883 | mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + (pktlen - sizeof (struct GNUNET_TUN_TcpHeader)); | 2929 | mlen = sizeof(struct GNUNET_EXIT_TcpDataMessage) + (pktlen - sizeof(struct GNUNET_TUN_TcpHeader)); |
2884 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | 2930 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) |
2885 | { | 2931 | { |
2886 | GNUNET_break (0); | 2932 | GNUNET_break(0); |
2887 | return; | 2933 | return; |
2888 | } | 2934 | } |
2889 | env = GNUNET_MQ_msg_extra (tdm, | 2935 | env = GNUNET_MQ_msg_extra(tdm, |
2890 | pktlen - sizeof (struct GNUNET_TUN_TcpHeader), | 2936 | pktlen - sizeof(struct GNUNET_TUN_TcpHeader), |
2891 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN); | 2937 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN); |
2892 | tdm->reserved = htonl (0); | 2938 | tdm->reserved = htonl(0); |
2893 | GNUNET_memcpy (&tdm->tcp_header, | 2939 | GNUNET_memcpy(&tdm->tcp_header, |
2894 | buf, | 2940 | buf, |
2895 | pktlen); | 2941 | pktlen); |
2896 | send_packet_to_cadet_channel (state, | 2942 | send_packet_to_cadet_channel(state, |
2897 | env); | 2943 | env); |
2898 | } | 2944 | } |
2899 | 2945 | ||
2900 | 2946 | ||
@@ -2905,142 +2951,150 @@ tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp, | |||
2905 | * @param message message received from helper | 2951 | * @param message message received from helper |
2906 | */ | 2952 | */ |
2907 | static int | 2953 | static int |
2908 | message_token (void *cls GNUNET_UNUSED, | 2954 | message_token(void *cls GNUNET_UNUSED, |
2909 | const struct GNUNET_MessageHeader *message) | 2955 | const struct GNUNET_MessageHeader *message) |
2910 | { | 2956 | { |
2911 | const struct GNUNET_TUN_Layer2PacketHeader *pkt_tun; | 2957 | const struct GNUNET_TUN_Layer2PacketHeader *pkt_tun; |
2912 | size_t size; | 2958 | size_t size; |
2913 | 2959 | ||
2914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2960 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2915 | "Got %u-byte message of type %u from gnunet-helper-exit\n", | 2961 | "Got %u-byte message of type %u from gnunet-helper-exit\n", |
2916 | ntohs (message->size), | 2962 | ntohs(message->size), |
2917 | ntohs (message->type)); | 2963 | ntohs(message->type)); |
2918 | GNUNET_STATISTICS_update (stats, | 2964 | GNUNET_STATISTICS_update(stats, |
2919 | gettext_noop ("# Packets received from TUN"), | 2965 | gettext_noop("# Packets received from TUN"), |
2920 | 1, GNUNET_NO); | 2966 | 1, GNUNET_NO); |
2921 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) | 2967 | if (ntohs(message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) |
2922 | { | 2968 | { |
2923 | GNUNET_break (0); | 2969 | GNUNET_break(0); |
2924 | return GNUNET_OK; | 2970 | return GNUNET_OK; |
2925 | } | 2971 | } |
2926 | size = ntohs (message->size); | 2972 | size = ntohs(message->size); |
2927 | if (size < sizeof (struct GNUNET_TUN_Layer2PacketHeader) + sizeof (struct GNUNET_MessageHeader)) | 2973 | if (size < sizeof(struct GNUNET_TUN_Layer2PacketHeader) + sizeof(struct GNUNET_MessageHeader)) |
2928 | { | 2974 | { |
2929 | GNUNET_break (0); | 2975 | GNUNET_break(0); |
2930 | return GNUNET_OK; | 2976 | return GNUNET_OK; |
2931 | } | 2977 | } |
2932 | GNUNET_STATISTICS_update (stats, | 2978 | GNUNET_STATISTICS_update(stats, |
2933 | gettext_noop ("# Bytes received from TUN"), | 2979 | gettext_noop("# Bytes received from TUN"), |
2934 | size, GNUNET_NO); | 2980 | size, GNUNET_NO); |
2935 | pkt_tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; | 2981 | pkt_tun = (const struct GNUNET_TUN_Layer2PacketHeader *)&message[1]; |
2936 | size -= sizeof (struct GNUNET_TUN_Layer2PacketHeader) + sizeof (struct GNUNET_MessageHeader); | 2982 | size -= sizeof(struct GNUNET_TUN_Layer2PacketHeader) + sizeof(struct GNUNET_MessageHeader); |
2937 | switch (ntohs (pkt_tun->proto)) | 2983 | switch (ntohs(pkt_tun->proto)) |
2938 | { | 2984 | { |
2939 | case ETH_P_IPV4: | 2985 | case ETH_P_IPV4: |
2940 | { | 2986 | { |
2941 | const struct GNUNET_TUN_IPv4Header *pkt4; | 2987 | const struct GNUNET_TUN_IPv4Header *pkt4; |
2942 | 2988 | ||
2943 | if (size < sizeof (struct GNUNET_TUN_IPv4Header)) | 2989 | if (size < sizeof(struct GNUNET_TUN_IPv4Header)) |
2944 | { | 2990 | { |
2945 | /* Kernel to blame? */ | 2991 | /* Kernel to blame? */ |
2946 | GNUNET_break (0); | 2992 | GNUNET_break(0); |
2947 | return GNUNET_OK; | 2993 | return GNUNET_OK; |
2948 | } | 2994 | } |
2949 | pkt4 = (const struct GNUNET_TUN_IPv4Header *) &pkt_tun[1]; | 2995 | pkt4 = (const struct GNUNET_TUN_IPv4Header *)&pkt_tun[1]; |
2950 | if (size != ntohs (pkt4->total_length)) | 2996 | if (size != ntohs(pkt4->total_length)) |
2951 | { | 2997 | { |
2952 | /* Kernel to blame? */ | 2998 | /* Kernel to blame? */ |
2953 | GNUNET_break (0); | 2999 | GNUNET_break(0); |
2954 | return GNUNET_OK; | 3000 | return GNUNET_OK; |
2955 | } | 3001 | } |
2956 | if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header)) | 3002 | if (pkt4->header_length * 4 != sizeof(struct GNUNET_TUN_IPv4Header)) |
2957 | { | 3003 | { |
2958 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3004 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2959 | _("IPv4 packet options received. Ignored.\n")); | 3005 | _("IPv4 packet options received. Ignored.\n")); |
2960 | return GNUNET_OK; | 3006 | return GNUNET_OK; |
2961 | } | 3007 | } |
2962 | 3008 | ||
2963 | size -= sizeof (struct GNUNET_TUN_IPv4Header); | 3009 | size -= sizeof(struct GNUNET_TUN_IPv4Header); |
2964 | switch (pkt4->protocol) | 3010 | switch (pkt4->protocol) |
2965 | { | 3011 | { |
2966 | case IPPROTO_UDP: | 3012 | case IPPROTO_UDP: |
2967 | udp_from_helper ((const struct GNUNET_TUN_UdpHeader *) &pkt4[1], size, | 3013 | udp_from_helper((const struct GNUNET_TUN_UdpHeader *)&pkt4[1], size, |
2968 | AF_INET, | 3014 | AF_INET, |
2969 | &pkt4->destination_address, | 3015 | &pkt4->destination_address, |
2970 | &pkt4->source_address); | 3016 | &pkt4->source_address); |
2971 | break; | 3017 | break; |
2972 | case IPPROTO_TCP: | 3018 | |
2973 | tcp_from_helper ((const struct GNUNET_TUN_TcpHeader *) &pkt4[1], size, | 3019 | case IPPROTO_TCP: |
2974 | AF_INET, | 3020 | tcp_from_helper((const struct GNUNET_TUN_TcpHeader *)&pkt4[1], size, |
2975 | &pkt4->destination_address, | 3021 | AF_INET, |
2976 | &pkt4->source_address); | 3022 | &pkt4->destination_address, |
2977 | break; | 3023 | &pkt4->source_address); |
2978 | case IPPROTO_ICMP: | 3024 | break; |
2979 | icmp_from_helper ((const struct GNUNET_TUN_IcmpHeader *) &pkt4[1], size, | 3025 | |
2980 | AF_INET, | 3026 | case IPPROTO_ICMP: |
2981 | &pkt4->destination_address, | 3027 | icmp_from_helper((const struct GNUNET_TUN_IcmpHeader *)&pkt4[1], size, |
2982 | &pkt4->source_address); | 3028 | AF_INET, |
2983 | break; | 3029 | &pkt4->destination_address, |
2984 | default: | 3030 | &pkt4->source_address); |
2985 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3031 | break; |
2986 | _("IPv4 packet with unsupported next header %u received. Ignored.\n"), | 3032 | |
2987 | (int) pkt4->protocol); | 3033 | default: |
2988 | return GNUNET_OK; | 3034 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2989 | } | 3035 | _("IPv4 packet with unsupported next header %u received. Ignored.\n"), |
3036 | (int)pkt4->protocol); | ||
3037 | return GNUNET_OK; | ||
3038 | } | ||
2990 | } | 3039 | } |
2991 | break; | 3040 | break; |
2992 | case ETH_P_IPV6: | 3041 | |
3042 | case ETH_P_IPV6: | ||
2993 | { | 3043 | { |
2994 | const struct GNUNET_TUN_IPv6Header *pkt6; | 3044 | const struct GNUNET_TUN_IPv6Header *pkt6; |
2995 | 3045 | ||
2996 | if (size < sizeof (struct GNUNET_TUN_IPv6Header)) | 3046 | if (size < sizeof(struct GNUNET_TUN_IPv6Header)) |
2997 | { | 3047 | { |
2998 | /* Kernel to blame? */ | 3048 | /* Kernel to blame? */ |
2999 | GNUNET_break (0); | 3049 | GNUNET_break(0); |
3000 | return GNUNET_OK; | 3050 | return GNUNET_OK; |
3001 | } | 3051 | } |
3002 | pkt6 = (struct GNUNET_TUN_IPv6Header *) &pkt_tun[1]; | 3052 | pkt6 = (struct GNUNET_TUN_IPv6Header *)&pkt_tun[1]; |
3003 | if (size != ntohs (pkt6->payload_length) + sizeof (struct GNUNET_TUN_IPv6Header)) | 3053 | if (size != ntohs(pkt6->payload_length) + sizeof(struct GNUNET_TUN_IPv6Header)) |
3004 | { | 3054 | { |
3005 | /* Kernel to blame? */ | 3055 | /* Kernel to blame? */ |
3006 | GNUNET_break (0); | 3056 | GNUNET_break(0); |
3007 | return GNUNET_OK; | 3057 | return GNUNET_OK; |
3008 | } | 3058 | } |
3009 | size -= sizeof (struct GNUNET_TUN_IPv6Header); | 3059 | size -= sizeof(struct GNUNET_TUN_IPv6Header); |
3010 | switch (pkt6->next_header) | 3060 | switch (pkt6->next_header) |
3011 | { | 3061 | { |
3012 | case IPPROTO_UDP: | 3062 | case IPPROTO_UDP: |
3013 | udp_from_helper ((const struct GNUNET_TUN_UdpHeader *) &pkt6[1], size, | 3063 | udp_from_helper((const struct GNUNET_TUN_UdpHeader *)&pkt6[1], size, |
3014 | AF_INET6, | 3064 | AF_INET6, |
3015 | &pkt6->destination_address, | 3065 | &pkt6->destination_address, |
3016 | &pkt6->source_address); | 3066 | &pkt6->source_address); |
3017 | break; | 3067 | break; |
3018 | case IPPROTO_TCP: | 3068 | |
3019 | tcp_from_helper ((const struct GNUNET_TUN_TcpHeader *) &pkt6[1], size, | 3069 | case IPPROTO_TCP: |
3020 | AF_INET6, | 3070 | tcp_from_helper((const struct GNUNET_TUN_TcpHeader *)&pkt6[1], size, |
3021 | &pkt6->destination_address, | 3071 | AF_INET6, |
3022 | &pkt6->source_address); | 3072 | &pkt6->destination_address, |
3023 | break; | 3073 | &pkt6->source_address); |
3024 | case IPPROTO_ICMPV6: | 3074 | break; |
3025 | icmp_from_helper ((const struct GNUNET_TUN_IcmpHeader *) &pkt6[1], size, | 3075 | |
3026 | AF_INET6, | 3076 | case IPPROTO_ICMPV6: |
3027 | &pkt6->destination_address, | 3077 | icmp_from_helper((const struct GNUNET_TUN_IcmpHeader *)&pkt6[1], size, |
3028 | &pkt6->source_address); | 3078 | AF_INET6, |
3029 | break; | 3079 | &pkt6->destination_address, |
3030 | default: | 3080 | &pkt6->source_address); |
3031 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3081 | break; |
3032 | _("IPv6 packet with unsupported next header %d received. Ignored.\n"), | 3082 | |
3033 | pkt6->next_header); | 3083 | default: |
3034 | return GNUNET_OK; | 3084 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3035 | } | 3085 | _("IPv6 packet with unsupported next header %d received. Ignored.\n"), |
3086 | pkt6->next_header); | ||
3087 | return GNUNET_OK; | ||
3088 | } | ||
3036 | } | 3089 | } |
3037 | break; | 3090 | break; |
3038 | default: | 3091 | |
3039 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3092 | default: |
3040 | _("Packet from unknown protocol %u received. Ignored.\n"), | 3093 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3041 | ntohs (pkt_tun->proto)); | 3094 | _("Packet from unknown protocol %u received. Ignored.\n"), |
3042 | break; | 3095 | ntohs(pkt_tun->proto)); |
3043 | } | 3096 | break; |
3097 | } | ||
3044 | return GNUNET_OK; | 3098 | return GNUNET_OK; |
3045 | } | 3099 | } |
3046 | 3100 | ||
@@ -3054,21 +3108,21 @@ message_token (void *cls GNUNET_UNUSED, | |||
3054 | * @return initial channel context for the channel | 3108 | * @return initial channel context for the channel |
3055 | */ | 3109 | */ |
3056 | static void * | 3110 | static void * |
3057 | new_channel (void *cls, | 3111 | new_channel(void *cls, |
3058 | struct GNUNET_CADET_Channel *channel, | 3112 | struct GNUNET_CADET_Channel *channel, |
3059 | const struct GNUNET_PeerIdentity *initiator) | 3113 | const struct GNUNET_PeerIdentity *initiator) |
3060 | { | 3114 | { |
3061 | struct ChannelState *s = GNUNET_new (struct ChannelState); | 3115 | struct ChannelState *s = GNUNET_new(struct ChannelState); |
3062 | 3116 | ||
3063 | s->is_dns = GNUNET_SYSERR; | 3117 | s->is_dns = GNUNET_SYSERR; |
3064 | s->peer = *initiator; | 3118 | s->peer = *initiator; |
3065 | GNUNET_STATISTICS_update (stats, | 3119 | GNUNET_STATISTICS_update(stats, |
3066 | gettext_noop ("# Inbound CADET channels created"), | 3120 | gettext_noop("# Inbound CADET channels created"), |
3067 | 1, | 3121 | 1, |
3068 | GNUNET_NO); | 3122 | GNUNET_NO); |
3069 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3123 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3070 | "Received inbound channel from `%s'\n", | 3124 | "Received inbound channel from `%s'\n", |
3071 | GNUNET_i2s (initiator)); | 3125 | GNUNET_i2s(initiator)); |
3072 | s->channel = channel; | 3126 | s->channel = channel; |
3073 | return s; | 3127 | return s; |
3074 | } | 3128 | } |
@@ -3082,11 +3136,11 @@ new_channel (void *cls, | |||
3082 | * @param value value to free | 3136 | * @param value value to free |
3083 | */ | 3137 | */ |
3084 | static int | 3138 | static int |
3085 | free_iterate (void *cls, | 3139 | free_iterate(void *cls, |
3086 | const struct GNUNET_HashCode * hash, | 3140 | const struct GNUNET_HashCode * hash, |
3087 | void *value) | 3141 | void *value) |
3088 | { | 3142 | { |
3089 | GNUNET_free (value); | 3143 | GNUNET_free(value); |
3090 | return GNUNET_YES; | 3144 | return GNUNET_YES; |
3091 | } | 3145 | } |
3092 | 3146 | ||
@@ -3101,7 +3155,7 @@ free_iterate (void *cls, | |||
3101 | * @param tc scheduler context | 3155 | * @param tc scheduler context |
3102 | */ | 3156 | */ |
3103 | static void | 3157 | static void |
3104 | dummy_task (void *cls) | 3158 | dummy_task(void *cls) |
3105 | { | 3159 | { |
3106 | /* just terminate */ | 3160 | /* just terminate */ |
3107 | } | 3161 | } |
@@ -3113,101 +3167,101 @@ dummy_task (void *cls) | |||
3113 | * @param cls NULL | 3167 | * @param cls NULL |
3114 | */ | 3168 | */ |
3115 | static void | 3169 | static void |
3116 | cleanup (void *cls) | 3170 | cleanup(void *cls) |
3117 | { | 3171 | { |
3118 | unsigned int i; | 3172 | unsigned int i; |
3119 | 3173 | ||
3120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3174 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3121 | "Exit service is shutting down now\n"); | 3175 | "Exit service is shutting down now\n"); |
3122 | 3176 | ||
3123 | if (NULL != helper_handle) | 3177 | if (NULL != helper_handle) |
3124 | { | 3178 | { |
3125 | GNUNET_HELPER_stop (helper_handle, GNUNET_NO); | 3179 | GNUNET_HELPER_stop(helper_handle, GNUNET_NO); |
3126 | helper_handle = NULL; | 3180 | helper_handle = NULL; |
3127 | } | 3181 | } |
3128 | if (NULL != regex4) | 3182 | if (NULL != regex4) |
3129 | { | 3183 | { |
3130 | GNUNET_REGEX_announce_cancel (regex4); | 3184 | GNUNET_REGEX_announce_cancel(regex4); |
3131 | regex4 = NULL; | 3185 | regex4 = NULL; |
3132 | } | 3186 | } |
3133 | if (NULL != regex6) | 3187 | if (NULL != regex6) |
3134 | { | 3188 | { |
3135 | GNUNET_REGEX_announce_cancel (regex6); | 3189 | GNUNET_REGEX_announce_cancel(regex6); |
3136 | regex6 = NULL; | 3190 | regex6 = NULL; |
3137 | } | 3191 | } |
3138 | if (NULL != services) | 3192 | if (NULL != services) |
3139 | { | 3193 | { |
3140 | GNUNET_CONTAINER_multihashmap_iterate (services, | 3194 | GNUNET_CONTAINER_multihashmap_iterate(services, |
3141 | &free_service_record, | 3195 | &free_service_record, |
3142 | NULL); | 3196 | NULL); |
3143 | GNUNET_CONTAINER_multihashmap_destroy (services); | 3197 | GNUNET_CONTAINER_multihashmap_destroy(services); |
3144 | } | 3198 | } |
3145 | if (NULL != dns_port) | 3199 | if (NULL != dns_port) |
3146 | { | 3200 | { |
3147 | GNUNET_CADET_close_port (dns_port); | 3201 | GNUNET_CADET_close_port(dns_port); |
3148 | dns_port = NULL; | 3202 | dns_port = NULL; |
3149 | } | 3203 | } |
3150 | if (NULL != cadet_port4) | 3204 | if (NULL != cadet_port4) |
3151 | { | 3205 | { |
3152 | GNUNET_CADET_close_port (cadet_port4); | 3206 | GNUNET_CADET_close_port(cadet_port4); |
3153 | cadet_port4 = NULL; | 3207 | cadet_port4 = NULL; |
3154 | } | 3208 | } |
3155 | if (NULL != cadet_port6) | 3209 | if (NULL != cadet_port6) |
3156 | { | 3210 | { |
3157 | GNUNET_CADET_close_port (cadet_port6); | 3211 | GNUNET_CADET_close_port(cadet_port6); |
3158 | cadet_port6 = NULL; | 3212 | cadet_port6 = NULL; |
3159 | } | 3213 | } |
3160 | if (NULL != cadet_handle) | 3214 | if (NULL != cadet_handle) |
3161 | { | 3215 | { |
3162 | GNUNET_CADET_disconnect (cadet_handle); | 3216 | GNUNET_CADET_disconnect(cadet_handle); |
3163 | cadet_handle = NULL; | 3217 | cadet_handle = NULL; |
3164 | } | 3218 | } |
3165 | if (NULL != connections_map) | 3219 | if (NULL != connections_map) |
3166 | { | 3220 | { |
3167 | GNUNET_CONTAINER_multihashmap_iterate (connections_map, | 3221 | GNUNET_CONTAINER_multihashmap_iterate(connections_map, |
3168 | &free_iterate, | 3222 | &free_iterate, |
3169 | NULL); | 3223 | NULL); |
3170 | GNUNET_CONTAINER_multihashmap_destroy (connections_map); | 3224 | GNUNET_CONTAINER_multihashmap_destroy(connections_map); |
3171 | connections_map = NULL; | 3225 | connections_map = NULL; |
3172 | } | 3226 | } |
3173 | if (NULL != connections_heap) | 3227 | if (NULL != connections_heap) |
3174 | { | 3228 | { |
3175 | GNUNET_CONTAINER_heap_destroy (connections_heap); | 3229 | GNUNET_CONTAINER_heap_destroy(connections_heap); |
3176 | connections_heap = NULL; | 3230 | connections_heap = NULL; |
3177 | } | 3231 | } |
3178 | if (NULL != dnsstub) | 3232 | if (NULL != dnsstub) |
3179 | { | 3233 | { |
3180 | GNUNET_DNSSTUB_stop (dnsstub); | 3234 | GNUNET_DNSSTUB_stop(dnsstub); |
3181 | dnsstub = NULL; | 3235 | dnsstub = NULL; |
3182 | } | 3236 | } |
3183 | if (NULL != peer_key) | 3237 | if (NULL != peer_key) |
3184 | { | 3238 | { |
3185 | GNUNET_free (peer_key); | 3239 | GNUNET_free(peer_key); |
3186 | peer_key = NULL; | 3240 | peer_key = NULL; |
3187 | } | 3241 | } |
3188 | if (NULL != dht_task) | 3242 | if (NULL != dht_task) |
3189 | { | 3243 | { |
3190 | GNUNET_SCHEDULER_cancel (dht_task); | 3244 | GNUNET_SCHEDULER_cancel(dht_task); |
3191 | dht_task = NULL; | 3245 | dht_task = NULL; |
3192 | } | 3246 | } |
3193 | if (NULL != dht_put) | 3247 | if (NULL != dht_put) |
3194 | { | 3248 | { |
3195 | GNUNET_DHT_put_cancel (dht_put); | 3249 | GNUNET_DHT_put_cancel(dht_put); |
3196 | dht_put = NULL; | 3250 | dht_put = NULL; |
3197 | } | 3251 | } |
3198 | if (NULL != dht) | 3252 | if (NULL != dht) |
3199 | { | 3253 | { |
3200 | GNUNET_DHT_disconnect (dht); | 3254 | GNUNET_DHT_disconnect(dht); |
3201 | dht = NULL; | 3255 | dht = NULL; |
3202 | } | 3256 | } |
3203 | if (NULL != stats) | 3257 | if (NULL != stats) |
3204 | { | 3258 | { |
3205 | GNUNET_STATISTICS_destroy (stats, | 3259 | GNUNET_STATISTICS_destroy(stats, |
3206 | GNUNET_NO); | 3260 | GNUNET_NO); |
3207 | stats = NULL; | 3261 | stats = NULL; |
3208 | } | 3262 | } |
3209 | for (i=0;i<8;i++) | 3263 | for (i = 0; i < 8; i++) |
3210 | GNUNET_free_non_null (exit_argv[i]); | 3264 | GNUNET_free_non_null(exit_argv[i]); |
3211 | } | 3265 | } |
3212 | 3266 | ||
3213 | 3267 | ||
@@ -3219,9 +3273,9 @@ cleanup (void *cls) | |||
3219 | * @param name DNS name of the service | 3273 | * @param name DNS name of the service |
3220 | */ | 3274 | */ |
3221 | static void | 3275 | static void |
3222 | add_services (int proto, | 3276 | add_services(int proto, |
3223 | char *cpy, | 3277 | char *cpy, |
3224 | const char *name) | 3278 | const char *name) |
3225 | { | 3279 | { |
3226 | char *redirect; | 3280 | char *redirect; |
3227 | char *hostname; | 3281 | char *hostname; |
@@ -3230,142 +3284,144 @@ add_services (int proto, | |||
3230 | char *n; | 3284 | char *n; |
3231 | size_t slen; | 3285 | size_t slen; |
3232 | 3286 | ||
3233 | slen = strlen (name); | 3287 | slen = strlen(name); |
3234 | GNUNET_assert (slen >= 8); | 3288 | GNUNET_assert(slen >= 8); |
3235 | n = GNUNET_strndup (name, slen - 8 /* remove .gnunet. */); | 3289 | n = GNUNET_strndup(name, slen - 8 /* remove .gnunet. */); |
3236 | 3290 | ||
3237 | for (redirect = strtok (cpy, " ;"); redirect != NULL; | 3291 | for (redirect = strtok(cpy, " ;"); redirect != NULL; |
3238 | redirect = strtok (NULL, " ;")) | 3292 | redirect = strtok(NULL, " ;")) |
3239 | { | ||
3240 | if (NULL == (hostname = strstr (redirect, ":"))) | ||
3241 | { | 3293 | { |
3242 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3294 | if (NULL == (hostname = strstr(redirect, ":"))) |
3243 | _("Option `%s' for domain `%s' is not formatted correctly!\n"), | 3295 | { |
3244 | redirect, | 3296 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3245 | name); | 3297 | _("Option `%s' for domain `%s' is not formatted correctly!\n"), |
3246 | continue; | 3298 | redirect, |
3247 | } | 3299 | name); |
3248 | hostname[0] = '\0'; | 3300 | continue; |
3249 | hostname++; | 3301 | } |
3250 | if (NULL == (hostport = strstr (hostname, ":"))) | 3302 | hostname[0] = '\0'; |
3251 | { | 3303 | hostname++; |
3252 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3304 | if (NULL == (hostport = strstr(hostname, ":"))) |
3253 | _("Option `%s' for domain `%s' is not formatted correctly!\n"), | 3305 | { |
3254 | redirect, | 3306 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3255 | name); | 3307 | _("Option `%s' for domain `%s' is not formatted correctly!\n"), |
3256 | continue; | 3308 | redirect, |
3257 | } | 3309 | name); |
3258 | hostport[0] = '\0'; | 3310 | continue; |
3259 | hostport++; | 3311 | } |
3260 | 3312 | hostport[0] = '\0'; | |
3261 | int local_port = atoi (redirect); | 3313 | hostport++; |
3262 | int remote_port = atoi (hostport); | 3314 | |
3263 | 3315 | int local_port = atoi(redirect); | |
3264 | if (! ((local_port > 0) && (local_port < 65536))) | 3316 | int remote_port = atoi(hostport); |
3265 | { | 3317 | |
3266 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3318 | if (!((local_port > 0) && (local_port < 65536))) |
3267 | _("`%s' is not a valid port number (for domain `%s')!"), | 3319 | { |
3268 | redirect, | 3320 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3269 | name); | 3321 | _("`%s' is not a valid port number (for domain `%s')!"), |
3270 | continue; | 3322 | redirect, |
3271 | } | 3323 | name); |
3272 | if (! ((remote_port > 0) && (remote_port < 65536))) | 3324 | continue; |
3273 | { | 3325 | } |
3274 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3326 | if (!((remote_port > 0) && (remote_port < 65536))) |
3275 | _("`%s' is not a valid port number (for domain `%s')!"), | 3327 | { |
3276 | hostport, | 3328 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3277 | name); | 3329 | _("`%s' is not a valid port number (for domain `%s')!"), |
3278 | continue; | 3330 | hostport, |
3279 | } | 3331 | name); |
3280 | 3332 | continue; | |
3281 | serv = GNUNET_new (struct LocalService); | 3333 | } |
3282 | serv->address.proto = proto; | 3334 | |
3283 | serv->address.port = remote_port; | 3335 | serv = GNUNET_new(struct LocalService); |
3284 | if (0 == strcmp ("localhost4", | 3336 | serv->address.proto = proto; |
3285 | hostname)) | 3337 | serv->address.port = remote_port; |
3286 | { | 3338 | if (0 == strcmp("localhost4", |
3287 | const char *ip4addr = exit_argv[5]; | 3339 | hostname)) |
3288 | 3340 | { | |
3289 | serv->address.af = AF_INET; | 3341 | const char *ip4addr = exit_argv[5]; |
3290 | GNUNET_assert (1 == inet_pton (AF_INET, | 3342 | |
3291 | ip4addr, | 3343 | serv->address.af = AF_INET; |
3292 | &serv->address.address.ipv4)); | 3344 | GNUNET_assert(1 == inet_pton(AF_INET, |
3293 | } | 3345 | ip4addr, |
3294 | else if (0 == strcmp ("localhost6", | 3346 | &serv->address.address.ipv4)); |
3295 | hostname)) | 3347 | } |
3296 | { | 3348 | else if (0 == strcmp("localhost6", |
3297 | const char *ip6addr = exit_argv[3]; | 3349 | hostname)) |
3298 | 3350 | { | |
3299 | serv->address.af = AF_INET6; | 3351 | const char *ip6addr = exit_argv[3]; |
3300 | GNUNET_assert (1 == inet_pton (AF_INET6, | 3352 | |
3301 | ip6addr, | 3353 | serv->address.af = AF_INET6; |
3302 | &serv->address.address.ipv6)); | 3354 | GNUNET_assert(1 == inet_pton(AF_INET6, |
3303 | } | 3355 | ip6addr, |
3304 | else | 3356 | &serv->address.address.ipv6)); |
3305 | { | 3357 | } |
3306 | struct addrinfo *res; | 3358 | else |
3307 | int ret; | 3359 | { |
3308 | 3360 | struct addrinfo *res; | |
3309 | ret = getaddrinfo (hostname, | 3361 | int ret; |
3310 | NULL, | 3362 | |
3311 | NULL, | 3363 | ret = getaddrinfo(hostname, |
3312 | &res); | 3364 | NULL, |
3313 | if ( (0 != ret) || (NULL == res) ) | 3365 | NULL, |
3314 | { | 3366 | &res); |
3315 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3367 | if ((0 != ret) || (NULL == res)) |
3316 | _("No addresses found for hostname `%s' of service `%s'!\n"), | 3368 | { |
3317 | hostname, | 3369 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3318 | n); | 3370 | _("No addresses found for hostname `%s' of service `%s'!\n"), |
3319 | GNUNET_free (serv); | 3371 | hostname, |
3320 | continue; | 3372 | n); |
3321 | } | 3373 | GNUNET_free(serv); |
3322 | 3374 | continue; | |
3323 | serv->address.af = res->ai_family; | 3375 | } |
3324 | switch (res->ai_family) | 3376 | |
3325 | { | 3377 | serv->address.af = res->ai_family; |
3326 | case AF_INET: | 3378 | switch (res->ai_family) |
3327 | if (! ipv4_enabled) | 3379 | { |
3328 | { | 3380 | case AF_INET: |
3329 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3381 | if (!ipv4_enabled) |
3330 | _("Service `%s' configured for IPv4, but IPv4 is disabled!\n"), | 3382 | { |
3331 | n); | 3383 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3332 | freeaddrinfo (res); | 3384 | _("Service `%s' configured for IPv4, but IPv4 is disabled!\n"), |
3333 | GNUNET_free (serv); | 3385 | n); |
3334 | continue; | 3386 | freeaddrinfo(res); |
3335 | } | 3387 | GNUNET_free(serv); |
3336 | serv->address.address.ipv4 | 3388 | continue; |
3337 | = ((struct sockaddr_in *) res->ai_addr)->sin_addr; | 3389 | } |
3338 | break; | 3390 | serv->address.address.ipv4 |
3339 | case AF_INET6: | 3391 | = ((struct sockaddr_in *)res->ai_addr)->sin_addr; |
3340 | if (! ipv6_enabled) | 3392 | break; |
3341 | { | 3393 | |
3342 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3394 | case AF_INET6: |
3343 | _("Service `%s' configured for IPv4, but IPv4 is disabled!\n"), | 3395 | if (!ipv6_enabled) |
3344 | n); | 3396 | { |
3345 | freeaddrinfo (res); | 3397 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3346 | GNUNET_free (serv); | 3398 | _("Service `%s' configured for IPv4, but IPv4 is disabled!\n"), |
3347 | continue; | 3399 | n); |
3348 | } | 3400 | freeaddrinfo(res); |
3349 | serv->address.address.ipv6 | 3401 | GNUNET_free(serv); |
3350 | = ((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; | 3402 | continue; |
3351 | break; | 3403 | } |
3352 | default: | 3404 | serv->address.address.ipv6 |
3353 | freeaddrinfo (res); | 3405 | = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; |
3354 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3406 | break; |
3355 | _("No IP addresses found for hostname `%s' of service `%s'!\n"), | 3407 | |
3356 | hostname, | 3408 | default: |
3357 | n); | 3409 | freeaddrinfo(res); |
3358 | GNUNET_free (serv); | 3410 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3359 | continue; | 3411 | _("No IP addresses found for hostname `%s' of service `%s'!\n"), |
3360 | } | 3412 | hostname, |
3361 | freeaddrinfo (res); | 3413 | n); |
3414 | GNUNET_free(serv); | ||
3415 | continue; | ||
3416 | } | ||
3417 | freeaddrinfo(res); | ||
3418 | } | ||
3419 | store_service(proto, | ||
3420 | n, | ||
3421 | local_port, | ||
3422 | serv); | ||
3362 | } | 3423 | } |
3363 | store_service (proto, | 3424 | GNUNET_free(n); |
3364 | n, | ||
3365 | local_port, | ||
3366 | serv); | ||
3367 | } | ||
3368 | GNUNET_free (n); | ||
3369 | } | 3425 | } |
3370 | 3426 | ||
3371 | 3427 | ||
@@ -3376,36 +3432,36 @@ add_services (int proto, | |||
3376 | * @param section name of section in config | 3432 | * @param section name of section in config |
3377 | */ | 3433 | */ |
3378 | static void | 3434 | static void |
3379 | read_service_conf (void *cls, | 3435 | read_service_conf(void *cls, |
3380 | const char *section) | 3436 | const char *section) |
3381 | { | 3437 | { |
3382 | char *cpy; | 3438 | char *cpy; |
3383 | 3439 | ||
3384 | if ((strlen (section) < 8) || | 3440 | if ((strlen(section) < 8) || |
3385 | (0 != strcmp (".gnunet.", section + (strlen (section) - 8)))) | 3441 | (0 != strcmp(".gnunet.", section + (strlen(section) - 8)))) |
3386 | return; | 3442 | return; |
3387 | if (GNUNET_OK == | 3443 | if (GNUNET_OK == |
3388 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3444 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3389 | section, | 3445 | section, |
3390 | "UDP_REDIRECTS", | 3446 | "UDP_REDIRECTS", |
3391 | &cpy)) | 3447 | &cpy)) |
3392 | { | 3448 | { |
3393 | add_services (IPPROTO_UDP, | 3449 | add_services(IPPROTO_UDP, |
3394 | cpy, | 3450 | cpy, |
3395 | section); | 3451 | section); |
3396 | GNUNET_free (cpy); | 3452 | GNUNET_free(cpy); |
3397 | } | 3453 | } |
3398 | if (GNUNET_OK == | 3454 | if (GNUNET_OK == |
3399 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3455 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3400 | section, | 3456 | section, |
3401 | "TCP_REDIRECTS", | 3457 | "TCP_REDIRECTS", |
3402 | &cpy)) | 3458 | &cpy)) |
3403 | { | 3459 | { |
3404 | add_services (IPPROTO_TCP, | 3460 | add_services(IPPROTO_TCP, |
3405 | cpy, | 3461 | cpy, |
3406 | section); | 3462 | section); |
3407 | GNUNET_free (cpy); | 3463 | GNUNET_free(cpy); |
3408 | } | 3464 | } |
3409 | } | 3465 | } |
3410 | 3466 | ||
3411 | 3467 | ||
@@ -3416,7 +3472,7 @@ read_service_conf (void *cls, | |||
3416 | * @param cls closure | 3472 | * @param cls closure |
3417 | */ | 3473 | */ |
3418 | static void | 3474 | static void |
3419 | do_dht_put (void *cls); | 3475 | do_dht_put(void *cls); |
3420 | 3476 | ||
3421 | 3477 | ||
3422 | /** | 3478 | /** |
@@ -3426,7 +3482,7 @@ do_dht_put (void *cls); | |||
3426 | * @param cls closure, NULL | 3482 | * @param cls closure, NULL |
3427 | */ | 3483 | */ |
3428 | static void | 3484 | static void |
3429 | dht_put_cont (void *cls) | 3485 | dht_put_cont(void *cls) |
3430 | { | 3486 | { |
3431 | dht_put = NULL; | 3487 | dht_put = NULL; |
3432 | } | 3488 | } |
@@ -3439,37 +3495,37 @@ dht_put_cont (void *cls) | |||
3439 | * @param cls closure | 3495 | * @param cls closure |
3440 | */ | 3496 | */ |
3441 | static void | 3497 | static void |
3442 | do_dht_put (void *cls) | 3498 | do_dht_put(void *cls) |
3443 | { | 3499 | { |
3444 | struct GNUNET_TIME_Absolute expiration; | 3500 | struct GNUNET_TIME_Absolute expiration; |
3445 | 3501 | ||
3446 | dht_task = GNUNET_SCHEDULER_add_delayed (DHT_PUT_FREQUENCY, | 3502 | dht_task = GNUNET_SCHEDULER_add_delayed(DHT_PUT_FREQUENCY, |
3447 | &do_dht_put, | 3503 | &do_dht_put, |
3448 | NULL); | 3504 | NULL); |
3449 | expiration = GNUNET_TIME_absolute_ntoh (dns_advertisement.expiration_time); | 3505 | expiration = GNUNET_TIME_absolute_ntoh(dns_advertisement.expiration_time); |
3450 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us < | 3506 | if (GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us < |
3451 | GNUNET_TIME_UNIT_HOURS.rel_value_us) | 3507 | GNUNET_TIME_UNIT_HOURS.rel_value_us) |
3452 | { | 3508 | { |
3453 | /* refresh advertisement */ | 3509 | /* refresh advertisement */ |
3454 | expiration = GNUNET_TIME_relative_to_absolute (DNS_ADVERTISEMENT_TIMEOUT); | 3510 | expiration = GNUNET_TIME_relative_to_absolute(DNS_ADVERTISEMENT_TIMEOUT); |
3455 | dns_advertisement.expiration_time = GNUNET_TIME_absolute_hton (expiration); | 3511 | dns_advertisement.expiration_time = GNUNET_TIME_absolute_hton(expiration); |
3456 | GNUNET_assert (GNUNET_OK == | 3512 | GNUNET_assert(GNUNET_OK == |
3457 | GNUNET_CRYPTO_eddsa_sign (peer_key, | 3513 | GNUNET_CRYPTO_eddsa_sign(peer_key, |
3458 | &dns_advertisement.purpose, | 3514 | &dns_advertisement.purpose, |
3459 | &dns_advertisement.signature)); | 3515 | &dns_advertisement.signature)); |
3460 | } | 3516 | } |
3461 | if (NULL != dht_put) | 3517 | if (NULL != dht_put) |
3462 | GNUNET_DHT_put_cancel (dht_put); | 3518 | GNUNET_DHT_put_cancel(dht_put); |
3463 | dht_put = GNUNET_DHT_put (dht, | 3519 | dht_put = GNUNET_DHT_put(dht, |
3464 | &dht_put_key, | 3520 | &dht_put_key, |
3465 | 1 /* replication */, | 3521 | 1 /* replication */, |
3466 | GNUNET_DHT_RO_NONE, | 3522 | GNUNET_DHT_RO_NONE, |
3467 | GNUNET_BLOCK_TYPE_DNS, | 3523 | GNUNET_BLOCK_TYPE_DNS, |
3468 | sizeof (struct GNUNET_DNS_Advertisement), | 3524 | sizeof(struct GNUNET_DNS_Advertisement), |
3469 | &dns_advertisement, | 3525 | &dns_advertisement, |
3470 | expiration, | 3526 | expiration, |
3471 | &dht_put_cont, | 3527 | &dht_put_cont, |
3472 | NULL); | 3528 | NULL); |
3473 | } | 3529 | } |
3474 | 3530 | ||
3475 | 3531 | ||
@@ -3478,48 +3534,48 @@ do_dht_put (void *cls) | |||
3478 | * are supported by the OS) according to our configuration. | 3534 | * are supported by the OS) according to our configuration. |
3479 | */ | 3535 | */ |
3480 | static void | 3536 | static void |
3481 | parse_ip_options () | 3537 | parse_ip_options() |
3482 | { | 3538 | { |
3483 | ipv4_exit = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 3539 | ipv4_exit = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
3484 | "exit", | 3540 | "exit", |
3485 | "EXIT_IPV4"); | 3541 | "EXIT_IPV4"); |
3486 | ipv6_exit = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 3542 | ipv6_exit = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
3487 | "exit", | 3543 | "exit", |
3488 | "EXIT_IPV6"); | 3544 | "EXIT_IPV6"); |
3489 | ipv4_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 3545 | ipv4_enabled = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
3490 | "exit", | 3546 | "exit", |
3491 | "ENABLE_IPV4"); | 3547 | "ENABLE_IPV4"); |
3492 | ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 3548 | ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
3493 | "exit", | 3549 | "exit", |
3494 | "ENABLE_IPV6"); | 3550 | "ENABLE_IPV6"); |
3495 | if ( (ipv4_exit || ipv4_enabled) && | 3551 | if ((ipv4_exit || ipv4_enabled) && |
3496 | GNUNET_OK != GNUNET_NETWORK_test_pf (PF_INET)) | 3552 | GNUNET_OK != GNUNET_NETWORK_test_pf(PF_INET)) |
3497 | { | 3553 | { |
3498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3554 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3499 | _("This system does not support IPv4, will disable IPv4 functions despite them being enabled in the configuration\n")); | 3555 | _("This system does not support IPv4, will disable IPv4 functions despite them being enabled in the configuration\n")); |
3500 | ipv4_exit = GNUNET_NO; | 3556 | ipv4_exit = GNUNET_NO; |
3501 | ipv4_enabled = GNUNET_NO; | 3557 | ipv4_enabled = GNUNET_NO; |
3502 | } | 3558 | } |
3503 | if ( (ipv6_exit || ipv6_enabled) && | 3559 | if ((ipv6_exit || ipv6_enabled) && |
3504 | GNUNET_OK != GNUNET_NETWORK_test_pf (PF_INET6)) | 3560 | GNUNET_OK != GNUNET_NETWORK_test_pf(PF_INET6)) |
3505 | { | 3561 | { |
3506 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3562 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3507 | _("This system does not support IPv6, will disable IPv6 functions despite them being enabled in the configuration\n")); | 3563 | _("This system does not support IPv6, will disable IPv6 functions despite them being enabled in the configuration\n")); |
3508 | ipv6_exit = GNUNET_NO; | 3564 | ipv6_exit = GNUNET_NO; |
3509 | ipv6_enabled = GNUNET_NO; | 3565 | ipv6_enabled = GNUNET_NO; |
3510 | } | 3566 | } |
3511 | if (ipv4_exit && (! ipv4_enabled)) | 3567 | if (ipv4_exit && (!ipv4_enabled)) |
3512 | { | 3568 | { |
3513 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3569 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3514 | _("Cannot enable IPv4 exit but disable IPv4 on TUN interface, will use ENABLE_IPv4=YES\n")); | 3570 | _("Cannot enable IPv4 exit but disable IPv4 on TUN interface, will use ENABLE_IPv4=YES\n")); |
3515 | ipv4_enabled = GNUNET_YES; | 3571 | ipv4_enabled = GNUNET_YES; |
3516 | } | 3572 | } |
3517 | if (ipv6_exit && (! ipv6_enabled)) | 3573 | if (ipv6_exit && (!ipv6_enabled)) |
3518 | { | 3574 | { |
3519 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3575 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3520 | _("Cannot enable IPv6 exit but disable IPv6 on TUN interface, will use ENABLE_IPv6=YES\n")); | 3576 | _("Cannot enable IPv6 exit but disable IPv6 on TUN interface, will use ENABLE_IPv6=YES\n")); |
3521 | ipv6_enabled = GNUNET_YES; | 3577 | ipv6_enabled = GNUNET_YES; |
3522 | } | 3578 | } |
3523 | } | 3579 | } |
3524 | 3580 | ||
3525 | 3581 | ||
@@ -3528,71 +3584,71 @@ parse_ip_options () | |||
3528 | * advertise the DNS exit (if applicable). | 3584 | * advertise the DNS exit (if applicable). |
3529 | */ | 3585 | */ |
3530 | static void | 3586 | static void |
3531 | advertise_dns_exit () | 3587 | advertise_dns_exit() |
3532 | { | 3588 | { |
3533 | struct GNUNET_MQ_MessageHandler handlers[] = { | 3589 | struct GNUNET_MQ_MessageHandler handlers[] = { |
3534 | GNUNET_MQ_hd_var_size (dns_request, | 3590 | GNUNET_MQ_hd_var_size(dns_request, |
3535 | GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET, | 3591 | GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET, |
3536 | struct DnsResponseMessage, | 3592 | struct DnsResponseMessage, |
3537 | NULL), | 3593 | NULL), |
3538 | GNUNET_MQ_handler_end () | 3594 | GNUNET_MQ_handler_end() |
3539 | }; | 3595 | }; |
3540 | char *dns_exit; | 3596 | char *dns_exit; |
3541 | struct GNUNET_HashCode port; | 3597 | struct GNUNET_HashCode port; |
3542 | 3598 | ||
3543 | if (GNUNET_YES != | 3599 | if (GNUNET_YES != |
3544 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | 3600 | GNUNET_CONFIGURATION_get_value_yesno(cfg, |
3545 | "exit", | 3601 | "exit", |
3546 | "EXIT_DNS")) | 3602 | "EXIT_DNS")) |
3547 | return; | 3603 | return; |
3548 | GNUNET_assert (NULL != (dnsstub = GNUNET_DNSSTUB_start (128))); | 3604 | GNUNET_assert(NULL != (dnsstub = GNUNET_DNSSTUB_start(128))); |
3549 | dns_exit = NULL; | 3605 | dns_exit = NULL; |
3550 | /* TODO: support using multiple DNS resolvers */ | 3606 | /* TODO: support using multiple DNS resolvers */ |
3551 | if ( (GNUNET_OK != | 3607 | if ((GNUNET_OK != |
3552 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3608 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3553 | "exit", | 3609 | "exit", |
3554 | "DNS_RESOLVER", | 3610 | "DNS_RESOLVER", |
3555 | &dns_exit)) || | 3611 | &dns_exit)) || |
3556 | (GNUNET_OK != | 3612 | (GNUNET_OK != |
3557 | GNUNET_DNSSTUB_add_dns_ip (dnsstub, | 3613 | GNUNET_DNSSTUB_add_dns_ip(dnsstub, |
3558 | dns_exit)) ) | 3614 | dns_exit))) |
3559 | { | 3615 | { |
3560 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 3616 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, |
3561 | "dns", | 3617 | "dns", |
3562 | "DNS_RESOLVER", | 3618 | "DNS_RESOLVER", |
3563 | _("need a valid IPv4 or IPv6 address\n")); | 3619 | _("need a valid IPv4 or IPv6 address\n")); |
3564 | GNUNET_free_non_null (dns_exit); | 3620 | GNUNET_free_non_null(dns_exit); |
3565 | return; | 3621 | return; |
3566 | } | 3622 | } |
3567 | /* open port */ | 3623 | /* open port */ |
3568 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, | 3624 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, |
3569 | strlen (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER), | 3625 | strlen(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER), |
3570 | &port); | 3626 | &port); |
3571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3627 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3572 | "Opening CADET port %s for DNS exit service\n", | 3628 | "Opening CADET port %s for DNS exit service\n", |
3573 | GNUNET_h2s (&port)); | 3629 | GNUNET_h2s(&port)); |
3574 | dns_port = GNUNET_CADET_open_port (cadet_handle, | 3630 | dns_port = GNUNET_CADET_open_port(cadet_handle, |
3575 | &port, | 3631 | &port, |
3576 | &new_channel, | 3632 | &new_channel, |
3577 | NULL, | 3633 | NULL, |
3578 | NULL, | 3634 | NULL, |
3579 | &clean_channel, | 3635 | &clean_channel, |
3580 | handlers); | 3636 | handlers); |
3581 | /* advertise exit */ | 3637 | /* advertise exit */ |
3582 | dht = GNUNET_DHT_connect (cfg, | 3638 | dht = GNUNET_DHT_connect(cfg, |
3583 | 1); | 3639 | 1); |
3584 | peer_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); | 3640 | peer_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); |
3585 | GNUNET_CRYPTO_eddsa_key_get_public (peer_key, | 3641 | GNUNET_CRYPTO_eddsa_key_get_public(peer_key, |
3586 | &dns_advertisement.peer.public_key); | 3642 | &dns_advertisement.peer.public_key); |
3587 | dns_advertisement.purpose.size = htonl (sizeof (struct GNUNET_DNS_Advertisement) - | 3643 | dns_advertisement.purpose.size = htonl(sizeof(struct GNUNET_DNS_Advertisement) - |
3588 | sizeof (struct GNUNET_CRYPTO_EddsaSignature)); | 3644 | sizeof(struct GNUNET_CRYPTO_EddsaSignature)); |
3589 | dns_advertisement.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD); | 3645 | dns_advertisement.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD); |
3590 | GNUNET_CRYPTO_hash ("dns", | 3646 | GNUNET_CRYPTO_hash("dns", |
3591 | strlen ("dns"), | 3647 | strlen("dns"), |
3592 | &dht_put_key); | 3648 | &dht_put_key); |
3593 | dht_task = GNUNET_SCHEDULER_add_now (&do_dht_put, | 3649 | dht_task = GNUNET_SCHEDULER_add_now(&do_dht_put, |
3594 | NULL); | 3650 | NULL); |
3595 | GNUNET_free (dns_exit); | 3651 | GNUNET_free(dns_exit); |
3596 | } | 3652 | } |
3597 | 3653 | ||
3598 | 3654 | ||
@@ -3602,7 +3658,7 @@ advertise_dns_exit () | |||
3602 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if we should shutdown | 3658 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if we should shutdown |
3603 | */ | 3659 | */ |
3604 | static int | 3660 | static int |
3605 | setup_exit_helper_args () | 3661 | setup_exit_helper_args() |
3606 | { | 3662 | { |
3607 | char *exit_ifname; | 3663 | char *exit_ifname; |
3608 | char *tun_ifname; | 3664 | char *tun_ifname; |
@@ -3611,133 +3667,133 @@ setup_exit_helper_args () | |||
3611 | char *ipv4addr; | 3667 | char *ipv4addr; |
3612 | char *ipv4mask; | 3668 | char *ipv4mask; |
3613 | 3669 | ||
3614 | exit_argv[0] = GNUNET_strdup ("exit-gnunet"); | 3670 | exit_argv[0] = GNUNET_strdup("exit-gnunet"); |
3615 | if (GNUNET_SYSERR == | 3671 | if (GNUNET_SYSERR == |
3616 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3672 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3617 | "exit", | 3673 | "exit", |
3618 | "TUN_IFNAME", | 3674 | "TUN_IFNAME", |
3619 | &tun_ifname)) | 3675 | &tun_ifname)) |
3620 | { | 3676 | { |
3621 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3677 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
3622 | "EXIT", | 3678 | "EXIT", |
3623 | "TUN_IFNAME"); | 3679 | "TUN_IFNAME"); |
3624 | return GNUNET_SYSERR; | 3680 | return GNUNET_SYSERR; |
3625 | } | 3681 | } |
3626 | exit_argv[1] = tun_ifname; | 3682 | exit_argv[1] = tun_ifname; |
3627 | if (ipv4_enabled) | 3683 | if (ipv4_enabled) |
3628 | { | 3684 | { |
3629 | if (GNUNET_SYSERR == | 3685 | if (GNUNET_SYSERR == |
3630 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3686 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3631 | "exit", | 3687 | "exit", |
3632 | "EXIT_IFNAME", | 3688 | "EXIT_IFNAME", |
3633 | &exit_ifname)) | 3689 | &exit_ifname)) |
3634 | { | 3690 | { |
3635 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3691 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
3636 | "EXIT", | 3692 | "EXIT", |
3637 | "EXIT_IFNAME"); | 3693 | "EXIT_IFNAME"); |
3638 | return GNUNET_SYSERR; | 3694 | return GNUNET_SYSERR; |
3695 | } | ||
3696 | exit_argv[2] = exit_ifname; | ||
3639 | } | 3697 | } |
3640 | exit_argv[2] = exit_ifname; | ||
3641 | } | ||
3642 | else | 3698 | else |
3643 | { | 3699 | { |
3644 | exit_argv[2] = GNUNET_strdup ("-"); | 3700 | exit_argv[2] = GNUNET_strdup("-"); |
3645 | } | 3701 | } |
3646 | 3702 | ||
3647 | if (GNUNET_YES == ipv6_enabled) | 3703 | if (GNUNET_YES == ipv6_enabled) |
3648 | { | 3704 | { |
3649 | ipv6addr = NULL; | 3705 | ipv6addr = NULL; |
3650 | if ( (GNUNET_SYSERR == | 3706 | if ((GNUNET_SYSERR == |
3651 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3707 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3652 | "exit", | 3708 | "exit", |
3653 | "IPV6ADDR", | 3709 | "IPV6ADDR", |
3654 | &ipv6addr) || | 3710 | &ipv6addr) || |
3655 | (1 != inet_pton (AF_INET6, | 3711 | (1 != inet_pton(AF_INET6, |
3656 | ipv6addr, | 3712 | ipv6addr, |
3657 | &exit_ipv6addr))) ) | 3713 | &exit_ipv6addr)))) |
3658 | { | 3714 | { |
3659 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3715 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
3660 | "EXIT", | 3716 | "EXIT", |
3661 | "IPV6ADDR"); | 3717 | "IPV6ADDR"); |
3662 | GNUNET_free_non_null (ipv6addr); | 3718 | GNUNET_free_non_null(ipv6addr); |
3663 | return GNUNET_SYSERR; | 3719 | return GNUNET_SYSERR; |
3664 | } | 3720 | } |
3665 | exit_argv[3] = ipv6addr; | 3721 | exit_argv[3] = ipv6addr; |
3666 | if (GNUNET_SYSERR == | 3722 | if (GNUNET_SYSERR == |
3667 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3723 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3668 | "exit", | 3724 | "exit", |
3669 | "IPV6PREFIX", | 3725 | "IPV6PREFIX", |
3670 | &ipv6prefix_s)) | 3726 | &ipv6prefix_s)) |
3671 | { | 3727 | { |
3672 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3728 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
3673 | "EXIT", | 3729 | "EXIT", |
3674 | "IPV6PREFIX"); | 3730 | "IPV6PREFIX"); |
3675 | return GNUNET_SYSERR; | 3731 | return GNUNET_SYSERR; |
3676 | } | 3732 | } |
3677 | exit_argv[4] = ipv6prefix_s; | 3733 | exit_argv[4] = ipv6prefix_s; |
3678 | if ( (GNUNET_OK != | 3734 | if ((GNUNET_OK != |
3679 | GNUNET_CONFIGURATION_get_value_number (cfg, | 3735 | GNUNET_CONFIGURATION_get_value_number(cfg, |
3680 | "exit", | 3736 | "exit", |
3681 | "IPV6PREFIX", | 3737 | "IPV6PREFIX", |
3682 | &ipv6prefix)) || | 3738 | &ipv6prefix)) || |
3683 | (ipv6prefix >= 127) ) | 3739 | (ipv6prefix >= 127)) |
3684 | { | 3740 | { |
3685 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 3741 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, |
3686 | "EXIT", | 3742 | "EXIT", |
3687 | "IPV6PREFIX", | 3743 | "IPV6PREFIX", |
3688 | _("Must be a number")); | 3744 | _("Must be a number")); |
3689 | return GNUNET_SYSERR; | 3745 | return GNUNET_SYSERR; |
3746 | } | ||
3690 | } | 3747 | } |
3691 | } | ||
3692 | else | 3748 | else |
3693 | { | 3749 | { |
3694 | /* IPv6 explicitly disabled */ | 3750 | /* IPv6 explicitly disabled */ |
3695 | exit_argv[3] = GNUNET_strdup ("-"); | 3751 | exit_argv[3] = GNUNET_strdup("-"); |
3696 | exit_argv[4] = GNUNET_strdup ("-"); | 3752 | exit_argv[4] = GNUNET_strdup("-"); |
3697 | } | 3753 | } |
3698 | if (GNUNET_YES == ipv4_enabled) | 3754 | if (GNUNET_YES == ipv4_enabled) |
3699 | { | 3755 | { |
3700 | ipv4addr = NULL; | 3756 | ipv4addr = NULL; |
3701 | if ( (GNUNET_SYSERR == | 3757 | if ((GNUNET_SYSERR == |
3702 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3758 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3703 | "exit", | 3759 | "exit", |
3704 | "IPV4ADDR", | 3760 | "IPV4ADDR", |
3705 | &ipv4addr) || | 3761 | &ipv4addr) || |
3706 | (1 != inet_pton (AF_INET, | 3762 | (1 != inet_pton(AF_INET, |
3707 | ipv4addr, | 3763 | ipv4addr, |
3708 | &exit_ipv4addr))) ) | 3764 | &exit_ipv4addr)))) |
3709 | { | 3765 | { |
3710 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3766 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
3711 | "EXIT", | 3767 | "EXIT", |
3712 | "IPV4ADDR"); | 3768 | "IPV4ADDR"); |
3713 | GNUNET_free_non_null (ipv4addr); | 3769 | GNUNET_free_non_null(ipv4addr); |
3714 | return GNUNET_SYSERR; | 3770 | return GNUNET_SYSERR; |
3715 | } | 3771 | } |
3716 | exit_argv[5] = ipv4addr; | 3772 | exit_argv[5] = ipv4addr; |
3717 | ipv4mask = NULL; | 3773 | ipv4mask = NULL; |
3718 | if ( (GNUNET_SYSERR == | 3774 | if ((GNUNET_SYSERR == |
3719 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3775 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3720 | "exit", | 3776 | "exit", |
3721 | "IPV4MASK", | 3777 | "IPV4MASK", |
3722 | &ipv4mask) || | 3778 | &ipv4mask) || |
3723 | (1 != inet_pton (AF_INET, | 3779 | (1 != inet_pton(AF_INET, |
3724 | ipv4mask, | 3780 | ipv4mask, |
3725 | &exit_ipv4mask))) ) | 3781 | &exit_ipv4mask)))) |
3726 | { | 3782 | { |
3727 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3783 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
3728 | "EXIT", | 3784 | "EXIT", |
3729 | "IPV4MASK"); | 3785 | "IPV4MASK"); |
3730 | GNUNET_free_non_null (ipv4mask); | 3786 | GNUNET_free_non_null(ipv4mask); |
3731 | return GNUNET_SYSERR; | 3787 | return GNUNET_SYSERR; |
3788 | } | ||
3789 | exit_argv[6] = ipv4mask; | ||
3732 | } | 3790 | } |
3733 | exit_argv[6] = ipv4mask; | ||
3734 | } | ||
3735 | else | 3791 | else |
3736 | { | 3792 | { |
3737 | /* IPv4 explicitly disabled */ | 3793 | /* IPv4 explicitly disabled */ |
3738 | exit_argv[5] = GNUNET_strdup ("-"); | 3794 | exit_argv[5] = GNUNET_strdup("-"); |
3739 | exit_argv[6] = GNUNET_strdup ("-"); | 3795 | exit_argv[6] = GNUNET_strdup("-"); |
3740 | } | 3796 | } |
3741 | exit_argv[7] = NULL; | 3797 | exit_argv[7] = NULL; |
3742 | return GNUNET_OK; | 3798 | return GNUNET_OK; |
3743 | } | 3799 | } |
@@ -3752,29 +3808,29 @@ setup_exit_helper_args () | |||
3752 | * @param cfg_ configuration | 3808 | * @param cfg_ configuration |
3753 | */ | 3809 | */ |
3754 | static void | 3810 | static void |
3755 | run (void *cls, | 3811 | run(void *cls, |
3756 | char *const *args, | 3812 | char *const *args, |
3757 | const char *cfgfile, | 3813 | const char *cfgfile, |
3758 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 3814 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
3759 | { | 3815 | { |
3760 | struct GNUNET_MQ_MessageHandler handlers[] = { | 3816 | struct GNUNET_MQ_MessageHandler handlers[] = { |
3761 | GNUNET_MQ_hd_var_size (icmp_remote, | 3817 | GNUNET_MQ_hd_var_size(icmp_remote, |
3762 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET, | 3818 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET, |
3763 | struct GNUNET_EXIT_IcmpInternetMessage, | 3819 | struct GNUNET_EXIT_IcmpInternetMessage, |
3764 | NULL), | 3820 | NULL), |
3765 | GNUNET_MQ_hd_var_size (udp_remote, | 3821 | GNUNET_MQ_hd_var_size(udp_remote, |
3766 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET, | 3822 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET, |
3767 | struct GNUNET_EXIT_UdpInternetMessage, | 3823 | struct GNUNET_EXIT_UdpInternetMessage, |
3768 | NULL), | 3824 | NULL), |
3769 | GNUNET_MQ_hd_var_size (tcp_remote, | 3825 | GNUNET_MQ_hd_var_size(tcp_remote, |
3770 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START, | 3826 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START, |
3771 | struct GNUNET_EXIT_TcpInternetStartMessage, | 3827 | struct GNUNET_EXIT_TcpInternetStartMessage, |
3772 | NULL), | 3828 | NULL), |
3773 | GNUNET_MQ_hd_var_size (tcp_data, | 3829 | GNUNET_MQ_hd_var_size(tcp_data, |
3774 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, | 3830 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, |
3775 | struct GNUNET_EXIT_TcpDataMessage, | 3831 | struct GNUNET_EXIT_TcpDataMessage, |
3776 | NULL), | 3832 | NULL), |
3777 | GNUNET_MQ_handler_end () | 3833 | GNUNET_MQ_handler_end() |
3778 | }; | 3834 | }; |
3779 | struct GNUNET_HashCode port; | 3835 | struct GNUNET_HashCode port; |
3780 | char *policy; | 3836 | char *policy; |
@@ -3784,157 +3840,157 @@ run (void *cls, | |||
3784 | 3840 | ||
3785 | cfg = cfg_; | 3841 | cfg = cfg_; |
3786 | if (GNUNET_OK != | 3842 | if (GNUNET_OK != |
3787 | GNUNET_CONFIGURATION_get_value_number (cfg, | 3843 | GNUNET_CONFIGURATION_get_value_number(cfg, |
3788 | "exit", | 3844 | "exit", |
3789 | "MAX_CONNECTIONS", | 3845 | "MAX_CONNECTIONS", |
3790 | &max_connections)) | 3846 | &max_connections)) |
3791 | max_connections = 1024; | 3847 | max_connections = 1024; |
3792 | parse_ip_options (); | 3848 | parse_ip_options(); |
3793 | binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-exit"); | 3849 | binary = GNUNET_OS_get_suid_binary_path(cfg, "gnunet-helper-exit"); |
3794 | if ( (ipv4_exit) || (ipv6_exit) ) | 3850 | if ((ipv4_exit) || (ipv6_exit)) |
3795 | { | 3851 | { |
3796 | if (GNUNET_YES != | 3852 | if (GNUNET_YES != |
3797 | GNUNET_OS_check_helper_binary (binary, | 3853 | GNUNET_OS_check_helper_binary(binary, |
3798 | GNUNET_YES, | 3854 | GNUNET_YES, |
3799 | "gnunet-vpn - - - 169.1.3.7 255.255.255.0")) //no nat, ipv4 only | 3855 | "gnunet-vpn - - - 169.1.3.7 255.255.255.0")) //no nat, ipv4 only |
3800 | { | 3856 | { |
3801 | GNUNET_free (binary); | 3857 | GNUNET_free(binary); |
3802 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3858 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3803 | _("`%s' is not SUID or the path is invalid, EXIT will not work\n"), | 3859 | _("`%s' is not SUID or the path is invalid, EXIT will not work\n"), |
3804 | "gnunet-helper-exit"); | 3860 | "gnunet-helper-exit"); |
3805 | GNUNET_SCHEDULER_add_shutdown (&dummy_task, | 3861 | GNUNET_SCHEDULER_add_shutdown(&dummy_task, |
3806 | NULL); | 3862 | NULL); |
3807 | global_ret = 1; | 3863 | global_ret = 1; |
3864 | return; | ||
3865 | } | ||
3866 | } | ||
3867 | if (!(ipv4_enabled || ipv6_enabled)) | ||
3868 | { | ||
3869 | GNUNET_free(binary); | ||
3870 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
3871 | _("No useful service enabled. Exiting.\n")); | ||
3872 | GNUNET_SCHEDULER_shutdown(); | ||
3808 | return; | 3873 | return; |
3809 | } | 3874 | } |
3810 | } | ||
3811 | if (! (ipv4_enabled || ipv6_enabled)) | ||
3812 | { | ||
3813 | GNUNET_free (binary); | ||
3814 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3815 | _("No useful service enabled. Exiting.\n")); | ||
3816 | GNUNET_SCHEDULER_shutdown (); | ||
3817 | return; | ||
3818 | } | ||
3819 | 3875 | ||
3820 | GNUNET_SCHEDULER_add_shutdown (&cleanup, | 3876 | GNUNET_SCHEDULER_add_shutdown(&cleanup, |
3821 | NULL); | 3877 | NULL); |
3822 | stats = GNUNET_STATISTICS_create ("exit", | 3878 | stats = GNUNET_STATISTICS_create("exit", |
3823 | cfg); | 3879 | cfg); |
3824 | cadet_handle = GNUNET_CADET_connect (cfg); | 3880 | cadet_handle = GNUNET_CADET_connect(cfg); |
3825 | if (NULL == cadet_handle) | 3881 | if (NULL == cadet_handle) |
3826 | { | 3882 | { |
3827 | GNUNET_free (binary); | 3883 | GNUNET_free(binary); |
3828 | GNUNET_SCHEDULER_shutdown (); | 3884 | GNUNET_SCHEDULER_shutdown(); |
3829 | return; | 3885 | return; |
3830 | } | 3886 | } |
3831 | advertise_dns_exit (); | 3887 | advertise_dns_exit(); |
3832 | if (GNUNET_OK != | 3888 | if (GNUNET_OK != |
3833 | setup_exit_helper_args ()) | 3889 | setup_exit_helper_args()) |
3834 | { | 3890 | { |
3835 | GNUNET_free (binary); | 3891 | GNUNET_free(binary); |
3836 | GNUNET_SCHEDULER_shutdown (); | 3892 | GNUNET_SCHEDULER_shutdown(); |
3837 | return; | 3893 | return; |
3838 | } | 3894 | } |
3839 | 3895 | ||
3840 | services = GNUNET_CONTAINER_multihashmap_create (65536, | 3896 | services = GNUNET_CONTAINER_multihashmap_create(65536, |
3841 | GNUNET_NO); | 3897 | GNUNET_NO); |
3842 | connections_map = GNUNET_CONTAINER_multihashmap_create (65536, | 3898 | connections_map = GNUNET_CONTAINER_multihashmap_create(65536, |
3843 | GNUNET_NO); | 3899 | GNUNET_NO); |
3844 | connections_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 3900 | connections_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
3845 | GNUNET_CONFIGURATION_iterate_sections (cfg, | 3901 | GNUNET_CONFIGURATION_iterate_sections(cfg, |
3846 | &read_service_conf, | 3902 | &read_service_conf, |
3847 | NULL); | 3903 | NULL); |
3848 | 3904 | ||
3849 | /* Cadet handle acquired, now open ports and announce regular | 3905 | /* Cadet handle acquired, now open ports and announce regular |
3850 | expressions matching our exit */ | 3906 | expressions matching our exit */ |
3851 | if ( (GNUNET_YES == ipv4_enabled) && | 3907 | if ((GNUNET_YES == ipv4_enabled) && |
3852 | (GNUNET_YES == ipv4_exit) ) | 3908 | (GNUNET_YES == ipv4_exit)) |
3853 | { | 3909 | { |
3854 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV4_GATEWAY, | 3910 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_IPV4_GATEWAY, |
3855 | strlen (GNUNET_APPLICATION_PORT_IPV4_GATEWAY), | 3911 | strlen(GNUNET_APPLICATION_PORT_IPV4_GATEWAY), |
3856 | &port); | 3912 | &port); |
3857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3913 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3858 | "Opening CADET port %s for IPv4 gateway service\n", | 3914 | "Opening CADET port %s for IPv4 gateway service\n", |
3859 | GNUNET_h2s (&port)); | 3915 | GNUNET_h2s(&port)); |
3860 | cadet_port4 = GNUNET_CADET_open_port (cadet_handle, | 3916 | cadet_port4 = GNUNET_CADET_open_port(cadet_handle, |
3861 | &port, | 3917 | &port, |
3862 | &new_channel, | 3918 | &new_channel, |
3863 | NULL, | 3919 | NULL, |
3864 | NULL, | 3920 | NULL, |
3865 | &clean_channel, | 3921 | &clean_channel, |
3866 | handlers); | 3922 | handlers); |
3867 | policy = NULL; | 3923 | policy = NULL; |
3868 | if (GNUNET_OK != | 3924 | if (GNUNET_OK != |
3869 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3925 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3870 | "exit", | 3926 | "exit", |
3871 | "EXIT_RANGE_IPV4_POLICY", | 3927 | "EXIT_RANGE_IPV4_POLICY", |
3872 | &policy)) | 3928 | &policy)) |
3873 | regex = NULL; | 3929 | regex = NULL; |
3874 | else | 3930 | else |
3875 | regex = GNUNET_TUN_ipv4policy2regex (policy); | 3931 | regex = GNUNET_TUN_ipv4policy2regex(policy); |
3876 | GNUNET_free_non_null (policy); | 3932 | GNUNET_free_non_null(policy); |
3877 | if (NULL != regex) | 3933 | if (NULL != regex) |
3878 | { | 3934 | { |
3879 | (void) GNUNET_asprintf (&prefixed_regex, | 3935 | (void)GNUNET_asprintf(&prefixed_regex, |
3880 | "%s%s", | 3936 | "%s%s", |
3881 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | 3937 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, |
3882 | regex); | 3938 | regex); |
3883 | regex4 = GNUNET_REGEX_announce (cfg, | 3939 | regex4 = GNUNET_REGEX_announce(cfg, |
3884 | prefixed_regex, | 3940 | prefixed_regex, |
3885 | REGEX_REFRESH_FREQUENCY, | 3941 | REGEX_REFRESH_FREQUENCY, |
3886 | REGEX_MAX_PATH_LEN_IPV4); | 3942 | REGEX_MAX_PATH_LEN_IPV4); |
3887 | GNUNET_free (regex); | 3943 | GNUNET_free(regex); |
3888 | GNUNET_free (prefixed_regex); | 3944 | GNUNET_free(prefixed_regex); |
3945 | } | ||
3889 | } | 3946 | } |
3890 | } | ||
3891 | 3947 | ||
3892 | if ( (GNUNET_YES == ipv6_enabled) && (GNUNET_YES == ipv6_exit) ) | 3948 | if ((GNUNET_YES == ipv6_enabled) && (GNUNET_YES == ipv6_exit)) |
3893 | { | 3949 | { |
3894 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV6_GATEWAY, | 3950 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_IPV6_GATEWAY, |
3895 | strlen (GNUNET_APPLICATION_PORT_IPV6_GATEWAY), | 3951 | strlen(GNUNET_APPLICATION_PORT_IPV6_GATEWAY), |
3896 | &port); | 3952 | &port); |
3897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3953 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3898 | "Opening CADET port %s for IPv6 gateway service\n", | 3954 | "Opening CADET port %s for IPv6 gateway service\n", |
3899 | GNUNET_h2s (&port)); | 3955 | GNUNET_h2s(&port)); |
3900 | cadet_port6 = GNUNET_CADET_open_port (cadet_handle, | 3956 | cadet_port6 = GNUNET_CADET_open_port(cadet_handle, |
3901 | &port, | 3957 | &port, |
3902 | &new_channel, | 3958 | &new_channel, |
3903 | NULL, | 3959 | NULL, |
3904 | NULL, | 3960 | NULL, |
3905 | &clean_channel, | 3961 | &clean_channel, |
3906 | handlers); | 3962 | handlers); |
3907 | policy = NULL; | 3963 | policy = NULL; |
3908 | if (GNUNET_OK != | 3964 | if (GNUNET_OK != |
3909 | GNUNET_CONFIGURATION_get_value_string (cfg, | 3965 | GNUNET_CONFIGURATION_get_value_string(cfg, |
3910 | "exit", | 3966 | "exit", |
3911 | "EXIT_RANGE_IPV6_POLICY", | 3967 | "EXIT_RANGE_IPV6_POLICY", |
3912 | &policy)) | 3968 | &policy)) |
3913 | regex = NULL; | 3969 | regex = NULL; |
3914 | else | 3970 | else |
3915 | regex = GNUNET_TUN_ipv6policy2regex (policy); | 3971 | regex = GNUNET_TUN_ipv6policy2regex(policy); |
3916 | GNUNET_free_non_null (policy); | 3972 | GNUNET_free_non_null(policy); |
3917 | if (NULL != regex) | 3973 | if (NULL != regex) |
3918 | { | 3974 | { |
3919 | (void) GNUNET_asprintf (&prefixed_regex, | 3975 | (void)GNUNET_asprintf(&prefixed_regex, |
3920 | "%s%s", | 3976 | "%s%s", |
3921 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | 3977 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, |
3922 | regex); | 3978 | regex); |
3923 | regex6 = GNUNET_REGEX_announce (cfg, | 3979 | regex6 = GNUNET_REGEX_announce(cfg, |
3924 | prefixed_regex, | 3980 | prefixed_regex, |
3925 | REGEX_REFRESH_FREQUENCY, | 3981 | REGEX_REFRESH_FREQUENCY, |
3926 | REGEX_MAX_PATH_LEN_IPV6); | 3982 | REGEX_MAX_PATH_LEN_IPV6); |
3927 | GNUNET_free (regex); | 3983 | GNUNET_free(regex); |
3928 | GNUNET_free (prefixed_regex); | 3984 | GNUNET_free(prefixed_regex); |
3985 | } | ||
3929 | } | 3986 | } |
3930 | } | 3987 | helper_handle = GNUNET_HELPER_start(GNUNET_NO, |
3931 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, | 3988 | binary, |
3932 | binary, | 3989 | exit_argv, |
3933 | exit_argv, | 3990 | &message_token, |
3934 | &message_token, | 3991 | NULL, |
3935 | NULL, | 3992 | NULL); |
3936 | NULL); | 3993 | GNUNET_free(binary); |
3937 | GNUNET_free (binary); | ||
3938 | } | 3994 | } |
3939 | 3995 | ||
3940 | 3996 | ||
@@ -3946,28 +4002,28 @@ run (void *cls, | |||
3946 | * @return 0 ok, 1 on error | 4002 | * @return 0 ok, 1 on error |
3947 | */ | 4003 | */ |
3948 | int | 4004 | int |
3949 | main (int argc, | 4005 | main(int argc, |
3950 | char *const *argv) | 4006 | char *const *argv) |
3951 | { | 4007 | { |
3952 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 4008 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
3953 | GNUNET_GETOPT_OPTION_END | 4009 | GNUNET_GETOPT_OPTION_END |
3954 | }; | 4010 | }; |
3955 | 4011 | ||
3956 | if (GNUNET_OK != | 4012 | if (GNUNET_OK != |
3957 | GNUNET_STRINGS_get_utf8_args (argc, | 4013 | GNUNET_STRINGS_get_utf8_args(argc, |
3958 | argv, | 4014 | argv, |
3959 | &argc, | 4015 | &argc, |
3960 | &argv)) | 4016 | &argv)) |
3961 | return 2; | 4017 | return 2; |
3962 | 4018 | ||
3963 | return (GNUNET_OK == | 4019 | return (GNUNET_OK == |
3964 | GNUNET_PROGRAM_run (argc, | 4020 | GNUNET_PROGRAM_run(argc, |
3965 | argv, | 4021 | argv, |
3966 | "gnunet-daemon-exit", | 4022 | "gnunet-daemon-exit", |
3967 | gettext_noop ("Daemon to run to provide an IP exit node for the VPN"), | 4023 | gettext_noop("Daemon to run to provide an IP exit node for the VPN"), |
3968 | options, | 4024 | options, |
3969 | &run, | 4025 | &run, |
3970 | NULL)) ? global_ret : 1; | 4026 | NULL)) ? global_ret : 1; |
3971 | } | 4027 | } |
3972 | 4028 | ||
3973 | 4029 | ||
diff --git a/src/exit/gnunet-helper-exit-windows.c b/src/exit/gnunet-helper-exit-windows.c index 8bae7ca86..0ffd28148 100644 --- a/src/exit/gnunet-helper-exit-windows.c +++ b/src/exit/gnunet-helper-exit-windows.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -66,7 +66,7 @@ | |||
66 | 66 | ||
67 | #if DEBUG | 67 | #if DEBUG |
68 | /* FIXME: define with varargs... */ | 68 | /* FIXME: define with varargs... */ |
69 | #define LOG_DEBUG(msg) fprintf (stderr, "%s", msg); | 69 | #define LOG_DEBUG(msg) fprintf(stderr, "%s", msg); |
70 | #else | 70 | #else |
71 | #define LOG_DEBUG(msg) do {} while (0) | 71 | #define LOG_DEBUG(msg) do {} while (0) |
72 | #endif | 72 | #endif |
@@ -162,9 +162,7 @@ static char device_guid[256]; | |||
162 | /** | 162 | /** |
163 | * Possible states of an IO facility. | 163 | * Possible states of an IO facility. |
164 | */ | 164 | */ |
165 | enum IO_State | 165 | enum IO_State { |
166 | { | ||
167 | |||
168 | /** | 166 | /** |
169 | * overlapped I/O is ready for work | 167 | * overlapped I/O is ready for work |
170 | */ | 168 | */ |
@@ -190,15 +188,13 @@ enum IO_State | |||
190 | * overlapped I/O has failed, stop processing | 188 | * overlapped I/O has failed, stop processing |
191 | */ | 189 | */ |
192 | IOSTATE_FAILED | 190 | IOSTATE_FAILED |
193 | |||
194 | }; | 191 | }; |
195 | 192 | ||
196 | 193 | ||
197 | /** | 194 | /** |
198 | * A IO Object + read/writebuffer + buffer-size for windows asynchronous IO handling | 195 | * A IO Object + read/writebuffer + buffer-size for windows asynchronous IO handling |
199 | */ | 196 | */ |
200 | struct io_facility | 197 | struct io_facility { |
201 | { | ||
202 | /** | 198 | /** |
203 | * The mode the state machine associated with this object is in. | 199 | * The mode the state machine associated with this object is in. |
204 | */ | 200 | */ |
@@ -243,12 +239,12 @@ struct io_facility | |||
243 | /** | 239 | /** |
244 | * ReOpenFile is only available as of XP SP2 and 2003 SP1 | 240 | * ReOpenFile is only available as of XP SP2 and 2003 SP1 |
245 | */ | 241 | */ |
246 | WINBASEAPI HANDLE WINAPI ReOpenFile (HANDLE, DWORD, DWORD, DWORD); | 242 | WINBASEAPI HANDLE WINAPI ReOpenFile(HANDLE, DWORD, DWORD, DWORD); |
247 | 243 | ||
248 | /** | 244 | /** |
249 | * IsWow64Process definition for our is_win64, as this is a kernel function | 245 | * IsWow64Process definition for our is_win64, as this is a kernel function |
250 | */ | 246 | */ |
251 | typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); | 247 | typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL); |
252 | 248 | ||
253 | 249 | ||
254 | /** | 250 | /** |
@@ -261,7 +257,7 @@ typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); | |||
261 | * @param n the length of the string to copy, including its terminating null | 257 | * @param n the length of the string to copy, including its terminating null |
262 | * byte | 258 | * byte |
263 | * @return the length of the string that was copied, excluding the terminating | 259 | * @return the length of the string that was copied, excluding the terminating |
264 | * null byte | 260 | * null byte |
265 | */ | 261 | */ |
266 | size_t | 262 | size_t |
267 | GNUNET_strlcpy(char *dst, const char *src, size_t n) | 263 | GNUNET_strlcpy(char *dst, const char *src, size_t n) |
@@ -269,9 +265,9 @@ GNUNET_strlcpy(char *dst, const char *src, size_t n) | |||
269 | size_t ret; | 265 | size_t ret; |
270 | size_t slen; | 266 | size_t slen; |
271 | 267 | ||
272 | GNUNET_assert (0 != n); | 268 | GNUNET_assert(0 != n); |
273 | slen = strnlen (src, n - 1); | 269 | slen = strnlen(src, n - 1); |
274 | memcpy (dst, src, slen); | 270 | memcpy(dst, src, slen); |
275 | dst[slen] = '\0'; | 271 | dst[slen] = '\0'; |
276 | return slen; | 272 | return slen; |
277 | } | 273 | } |
@@ -283,7 +279,7 @@ GNUNET_strlcpy(char *dst, const char *src, size_t n) | |||
283 | * @return true if | 279 | * @return true if |
284 | */ | 280 | */ |
285 | BOOL | 281 | BOOL |
286 | is_win64 () | 282 | is_win64() |
287 | { | 283 | { |
288 | #if defined(_WIN64) | 284 | #if defined(_WIN64) |
289 | //this is a win64 binary, | 285 | //this is a win64 binary, |
@@ -292,10 +288,10 @@ is_win64 () | |||
292 | //this is a 32bit binary, and we need to check if we are running in WOW64 | 288 | //this is a 32bit binary, and we need to check if we are running in WOW64 |
293 | BOOL success = FALSE; | 289 | BOOL success = FALSE; |
294 | BOOL on_wow64 = FALSE; | 290 | BOOL on_wow64 = FALSE; |
295 | LPFN_ISWOW64PROCESS IsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle ("kernel32"), "IsWow64Process"); | 291 | LPFN_ISWOW64PROCESS IsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process"); |
296 | 292 | ||
297 | if (NULL != IsWow64Process) | 293 | if (NULL != IsWow64Process) |
298 | success = IsWow64Process (GetCurrentProcess (), &on_wow64); | 294 | success = IsWow64Process(GetCurrentProcess(), &on_wow64); |
299 | 295 | ||
300 | return success && on_wow64; | 296 | return success && on_wow64; |
301 | #endif | 297 | #endif |
@@ -309,22 +305,22 @@ is_win64 () | |||
309 | * * EPIPE (could not read STDOUT) | 305 | * * EPIPE (could not read STDOUT) |
310 | */ | 306 | */ |
311 | static int | 307 | static int |
312 | execute_shellcommand (const char *command) | 308 | execute_shellcommand(const char *command) |
313 | { | 309 | { |
314 | FILE *pipe; | 310 | FILE *pipe; |
315 | 311 | ||
316 | if ( (NULL == command) || | 312 | if ((NULL == command) || |
317 | (NULL == (pipe = _popen (command, "rt"))) ) | 313 | (NULL == (pipe = _popen(command, "rt")))) |
318 | return EINVAL; | 314 | return EINVAL; |
319 | 315 | ||
320 | #if DEBUG | 316 | #if DEBUG |
321 | fprintf (stderr, "DEBUG: Command output: \n"); | 317 | fprintf(stderr, "DEBUG: Command output: \n"); |
322 | char output[LINE_LEN]; | 318 | char output[LINE_LEN]; |
323 | while (NULL != fgets (output, sizeof (output), pipe)) | 319 | while (NULL != fgets(output, sizeof(output), pipe)) |
324 | fprintf (stderr, "%s", output); | 320 | fprintf(stderr, "%s", output); |
325 | #endif | 321 | #endif |
326 | 322 | ||
327 | return _pclose (pipe); | 323 | return _pclose(pipe); |
328 | } | 324 | } |
329 | 325 | ||
330 | 326 | ||
@@ -335,7 +331,7 @@ execute_shellcommand (const char *command) | |||
335 | * @param prefix_len the length of the network-prefix | 331 | * @param prefix_len the length of the network-prefix |
336 | */ | 332 | */ |
337 | static int | 333 | static int |
338 | set_address6 (const char *address, unsigned long prefix_len) | 334 | set_address6(const char *address, unsigned long prefix_len) |
339 | { | 335 | { |
340 | int ret = EINVAL; | 336 | int ret = EINVAL; |
341 | char command[LINE_LEN]; | 337 | char command[LINE_LEN]; |
@@ -344,29 +340,29 @@ set_address6 (const char *address, unsigned long prefix_len) | |||
344 | /* | 340 | /* |
345 | * parse the new address | 341 | * parse the new address |
346 | */ | 342 | */ |
347 | memset (&sa6, 0, sizeof (struct sockaddr_in6)); | 343 | memset(&sa6, 0, sizeof(struct sockaddr_in6)); |
348 | sa6.sin6_family = AF_INET6; | 344 | sa6.sin6_family = AF_INET6; |
349 | if (1 != inet_pton (AF_INET6, address, &sa6.sin6_addr.s6_addr)) | 345 | if (1 != inet_pton(AF_INET6, address, &sa6.sin6_addr.s6_addr)) |
350 | { | 346 | { |
351 | fprintf (stderr, "ERROR: Failed to parse address `%s': %s\n", address, | 347 | fprintf(stderr, "ERROR: Failed to parse address `%s': %s\n", address, |
352 | strerror (errno)); | 348 | strerror(errno)); |
353 | return -1; | 349 | return -1; |
354 | } | 350 | } |
355 | 351 | ||
356 | /* | 352 | /* |
357 | * prepare the command | 353 | * prepare the command |
358 | */ | 354 | */ |
359 | snprintf (command, LINE_LEN, | 355 | snprintf(command, LINE_LEN, |
360 | "netsh interface ipv6 add address \"%s\" %s/%d store=active", | 356 | "netsh interface ipv6 add address \"%s\" %s/%d store=active", |
361 | device_visible_name, address, prefix_len); | 357 | device_visible_name, address, prefix_len); |
362 | /* | 358 | /* |
363 | * Set the address | 359 | * Set the address |
364 | */ | 360 | */ |
365 | ret = execute_shellcommand (command); | 361 | ret = execute_shellcommand(command); |
366 | 362 | ||
367 | /* Did it work?*/ | 363 | /* Did it work?*/ |
368 | if (0 != ret) | 364 | if (0 != ret) |
369 | fprintf (stderr, "FATAL: Setting IPv6 address failed: %s\n", strerror (ret)); | 365 | fprintf(stderr, "FATAL: Setting IPv6 address failed: %s\n", strerror(ret)); |
370 | return ret; | 366 | return ret; |
371 | } | 367 | } |
372 | 368 | ||
@@ -377,7 +373,7 @@ set_address6 (const char *address, unsigned long prefix_len) | |||
377 | * @param address the IPv4-Address | 373 | * @param address the IPv4-Address |
378 | */ | 374 | */ |
379 | static void | 375 | static void |
380 | remove_address6 (const char *address) | 376 | remove_address6(const char *address) |
381 | { | 377 | { |
382 | char command[LINE_LEN]; | 378 | char command[LINE_LEN]; |
383 | int ret = EINVAL; | 379 | int ret = EINVAL; |
@@ -386,17 +382,17 @@ remove_address6 (const char *address) | |||
386 | /* | 382 | /* |
387 | * prepare the command | 383 | * prepare the command |
388 | */ | 384 | */ |
389 | snprintf (command, LINE_LEN, | 385 | snprintf(command, LINE_LEN, |
390 | "netsh interface ipv6 delete address \"%s\" store=persistent", | 386 | "netsh interface ipv6 delete address \"%s\" store=persistent", |
391 | device_visible_name); | 387 | device_visible_name); |
392 | /* | 388 | /* |
393 | * Set the address | 389 | * Set the address |
394 | */ | 390 | */ |
395 | ret = execute_shellcommand (command); | 391 | ret = execute_shellcommand(command); |
396 | 392 | ||
397 | /* Did it work?*/ | 393 | /* Did it work?*/ |
398 | if (0 != ret) | 394 | if (0 != ret) |
399 | fprintf (stderr, "FATAL: removing IPv6 address failed: %s\n", strerror (ret)); | 395 | fprintf(stderr, "FATAL: removing IPv6 address failed: %s\n", strerror(ret)); |
400 | } | 396 | } |
401 | 397 | ||
402 | 398 | ||
@@ -407,21 +403,22 @@ remove_address6 (const char *address) | |||
407 | * @param mask the netmask | 403 | * @param mask the netmask |
408 | */ | 404 | */ |
409 | static int | 405 | static int |
410 | set_address4 (const char *address, const char *mask) | 406 | set_address4(const char *address, const char *mask) |
411 | { | 407 | { |
412 | int ret = EINVAL; | 408 | int ret = EINVAL; |
413 | char command[LINE_LEN]; | 409 | char command[LINE_LEN]; |
414 | 410 | ||
415 | struct sockaddr_in addr; | 411 | struct sockaddr_in addr; |
412 | |||
416 | addr.sin_family = AF_INET; | 413 | addr.sin_family = AF_INET; |
417 | 414 | ||
418 | /* | 415 | /* |
419 | * Parse the address | 416 | * Parse the address |
420 | */ | 417 | */ |
421 | if (1 != inet_pton (AF_INET, address, &addr.sin_addr.s_addr)) | 418 | if (1 != inet_pton(AF_INET, address, &addr.sin_addr.s_addr)) |
422 | { | 419 | { |
423 | fprintf (stderr, "ERROR: Failed to parse address `%s': %s\n", address, | 420 | fprintf(stderr, "ERROR: Failed to parse address `%s': %s\n", address, |
424 | strerror (errno)); | 421 | strerror(errno)); |
425 | return -1; | 422 | return -1; |
426 | } | 423 | } |
427 | // Set Device to Subnet-Mode? | 424 | // Set Device to Subnet-Mode? |
@@ -430,17 +427,17 @@ set_address4 (const char *address, const char *mask) | |||
430 | /* | 427 | /* |
431 | * prepare the command | 428 | * prepare the command |
432 | */ | 429 | */ |
433 | snprintf (command, LINE_LEN, | 430 | snprintf(command, LINE_LEN, |
434 | "netsh interface ipv4 add address \"%s\" %s %s store=active", | 431 | "netsh interface ipv4 add address \"%s\" %s %s store=active", |
435 | device_visible_name, address, mask); | 432 | device_visible_name, address, mask); |
436 | /* | 433 | /* |
437 | * Set the address | 434 | * Set the address |
438 | */ | 435 | */ |
439 | ret = execute_shellcommand (command); | 436 | ret = execute_shellcommand(command); |
440 | 437 | ||
441 | /* Did it work?*/ | 438 | /* Did it work?*/ |
442 | if (0 != ret) | 439 | if (0 != ret) |
443 | fprintf (stderr, "FATAL: Setting IPv4 address failed: %s\n", strerror (ret)); | 440 | fprintf(stderr, "FATAL: Setting IPv4 address failed: %s\n", strerror(ret)); |
444 | return ret; | 441 | return ret; |
445 | } | 442 | } |
446 | 443 | ||
@@ -451,7 +448,7 @@ set_address4 (const char *address, const char *mask) | |||
451 | * @param address the IPv4-Address | 448 | * @param address the IPv4-Address |
452 | */ | 449 | */ |
453 | static void | 450 | static void |
454 | remove_address4 (const char *address) | 451 | remove_address4(const char *address) |
455 | { | 452 | { |
456 | char command[LINE_LEN]; | 453 | char command[LINE_LEN]; |
457 | int ret = EINVAL; | 454 | int ret = EINVAL; |
@@ -461,17 +458,17 @@ remove_address4 (const char *address) | |||
461 | /* | 458 | /* |
462 | * prepare the command | 459 | * prepare the command |
463 | */ | 460 | */ |
464 | snprintf (command, LINE_LEN, | 461 | snprintf(command, LINE_LEN, |
465 | "netsh interface ipv4 delete address \"%s\" gateway=all store=persistent", | 462 | "netsh interface ipv4 delete address \"%s\" gateway=all store=persistent", |
466 | device_visible_name); | 463 | device_visible_name); |
467 | /* | 464 | /* |
468 | * Set the address | 465 | * Set the address |
469 | */ | 466 | */ |
470 | ret = execute_shellcommand (command); | 467 | ret = execute_shellcommand(command); |
471 | 468 | ||
472 | /* Did it work?*/ | 469 | /* Did it work?*/ |
473 | if (0 != ret) | 470 | if (0 != ret) |
474 | fprintf (stderr, "FATAL: removing IPv4 address failed: %s\n", strerror (ret)); | 471 | fprintf(stderr, "FATAL: removing IPv4 address failed: %s\n", strerror(ret)); |
475 | } | 472 | } |
476 | 473 | ||
477 | 474 | ||
@@ -481,7 +478,7 @@ remove_address4 (const char *address) | |||
481 | * @return: TRUE if setup was successful, else FALSE | 478 | * @return: TRUE if setup was successful, else FALSE |
482 | */ | 479 | */ |
483 | static BOOL | 480 | static BOOL |
484 | setup_interface () | 481 | setup_interface() |
485 | { | 482 | { |
486 | /* | 483 | /* |
487 | * where to find our inf-file. (+ the "full" path, after windows found") | 484 | * where to find our inf-file. (+ the "full" path, after windows found") |
@@ -500,20 +497,20 @@ setup_interface () | |||
500 | * Set the device's hardware ID and add it to a list. | 497 | * Set the device's hardware ID and add it to a list. |
501 | * This information will later on identify this device in registry. | 498 | * This information will later on identify this device in registry. |
502 | */ | 499 | */ |
503 | str_length = GNUNET_strlcpy (hwidlist, | 500 | str_length = GNUNET_strlcpy(hwidlist, |
504 | HARDWARE_ID, | 501 | HARDWARE_ID, |
505 | sizeof (hwidlist)) + 1; | 502 | sizeof(hwidlist)) + 1; |
506 | /** | 503 | /** |
507 | * this is kind of over-complicated, but allows keeps things independent of | 504 | * this is kind of over-complicated, but allows keeps things independent of |
508 | * how the openvpn-hwid is actually stored. | 505 | * how the openvpn-hwid is actually stored. |
509 | * | 506 | * |
510 | * A HWID list is double-\0 terminated and \0 separated | 507 | * A HWID list is double-\0 terminated and \0 separated |
511 | */ | 508 | */ |
512 | str_length = strlen (hwidlist) + 1; | 509 | str_length = strlen(hwidlist) + 1; |
513 | str_length += GNUNET_strlcpy (&hwidlist[str_length], | 510 | str_length += GNUNET_strlcpy(&hwidlist[str_length], |
514 | secondary_hwid, | 511 | secondary_hwid, |
515 | sizeof (hwidlist) - str_length) + 1; | 512 | sizeof(hwidlist) - str_length) + 1; |
516 | GNUNET_assert (str_length < sizeof (hwidlist)); | 513 | GNUNET_assert(str_length < sizeof(hwidlist)); |
517 | hwidlist[str_length] = '\0'; | 514 | hwidlist[str_length] = '\0'; |
518 | ++str_length; | 515 | ++str_length; |
519 | 516 | ||
@@ -522,62 +519,62 @@ setup_interface () | |||
522 | * find it. We need to pick the correct driver for win32/win64. | 519 | * find it. We need to pick the correct driver for win32/win64. |
523 | */ | 520 | */ |
524 | if (is_win64()) | 521 | if (is_win64()) |
525 | GetFullPathNameA (INF_FILE64, MAX_PATH, inf_file_path, &temp_inf_filename); | 522 | GetFullPathNameA(INF_FILE64, MAX_PATH, inf_file_path, &temp_inf_filename); |
526 | else | 523 | else |
527 | GetFullPathNameA (INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename); | 524 | GetFullPathNameA(INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename); |
528 | 525 | ||
529 | fprintf (stderr, "INFO: Located our driver's .inf file at %s\n", inf_file_path); | 526 | fprintf(stderr, "INFO: Located our driver's .inf file at %s\n", inf_file_path); |
530 | /** | 527 | /** |
531 | * Bootstrap our device info using the drivers inf-file | 528 | * Bootstrap our device info using the drivers inf-file |
532 | */ | 529 | */ |
533 | if ( ! SetupDiGetINFClassA (inf_file_path, | 530 | if (!SetupDiGetINFClassA(inf_file_path, |
534 | &class_guid, | 531 | &class_guid, |
535 | class_name, sizeof (class_name) / sizeof (char), | 532 | class_name, sizeof(class_name) / sizeof(char), |
536 | NULL)) | 533 | NULL)) |
537 | return FALSE; | 534 | return FALSE; |
538 | 535 | ||
539 | /** | 536 | /** |
540 | * Collect all the other needed information... | 537 | * Collect all the other needed information... |
541 | * let the system fill our this form | 538 | * let the system fill our this form |
542 | */ | 539 | */ |
543 | DeviceInfo = SetupDiCreateDeviceInfoList (&class_guid, NULL); | 540 | DeviceInfo = SetupDiCreateDeviceInfoList(&class_guid, NULL); |
544 | if (DeviceInfo == INVALID_HANDLE_VALUE) | 541 | if (DeviceInfo == INVALID_HANDLE_VALUE) |
545 | return FALSE; | 542 | return FALSE; |
546 | 543 | ||
547 | DeviceNode.cbSize = sizeof (SP_DEVINFO_DATA); | 544 | DeviceNode.cbSize = sizeof(SP_DEVINFO_DATA); |
548 | if ( ! SetupDiCreateDeviceInfoA (DeviceInfo, | 545 | if (!SetupDiCreateDeviceInfoA(DeviceInfo, |
549 | class_name, | 546 | class_name, |
550 | &class_guid, | 547 | &class_guid, |
551 | NULL, | 548 | NULL, |
552 | 0, | 549 | 0, |
553 | DICD_GENERATE_ID, | 550 | DICD_GENERATE_ID, |
554 | &DeviceNode)) | 551 | &DeviceNode)) |
555 | return FALSE; | 552 | return FALSE; |
556 | 553 | ||
557 | /* Deploy all the information collected into the registry */ | 554 | /* Deploy all the information collected into the registry */ |
558 | if ( ! SetupDiSetDeviceRegistryPropertyA (DeviceInfo, | 555 | if (!SetupDiSetDeviceRegistryPropertyA(DeviceInfo, |
559 | &DeviceNode, | 556 | &DeviceNode, |
560 | SPDRP_HARDWAREID, | 557 | SPDRP_HARDWAREID, |
561 | (LPBYTE) hwidlist, | 558 | (LPBYTE)hwidlist, |
562 | str_length * sizeof (char))) | 559 | str_length * sizeof(char))) |
563 | return FALSE; | 560 | return FALSE; |
564 | 561 | ||
565 | /* Install our new class(=device) into the system */ | 562 | /* Install our new class(=device) into the system */ |
566 | if ( ! SetupDiCallClassInstaller (DIF_REGISTERDEVICE, | 563 | if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, |
567 | DeviceInfo, | 564 | DeviceInfo, |
568 | &DeviceNode)) | 565 | &DeviceNode)) |
569 | return FALSE; | 566 | return FALSE; |
570 | 567 | ||
571 | /* This system call tends to take a while (several seconds!) on | 568 | /* This system call tends to take a while (several seconds!) on |
572 | "modern" Windoze systems */ | 569 | "modern" Windoze systems */ |
573 | if ( ! UpdateDriverForPlugAndPlayDevicesA (NULL, | 570 | if (!UpdateDriverForPlugAndPlayDevicesA(NULL, |
574 | secondary_hwid, | 571 | secondary_hwid, |
575 | inf_file_path, | 572 | inf_file_path, |
576 | INSTALLFLAG_FORCE | INSTALLFLAG_NONINTERACTIVE, | 573 | INSTALLFLAG_FORCE | INSTALLFLAG_NONINTERACTIVE, |
577 | NULL)) //reboot required? NEVER! | 574 | NULL)) //reboot required? NEVER! |
578 | return FALSE; | 575 | return FALSE; |
579 | 576 | ||
580 | fprintf (stderr, "DEBUG: successfully created a network device\n"); | 577 | fprintf(stderr, "DEBUG: successfully created a network device\n"); |
581 | return TRUE; | 578 | return TRUE; |
582 | } | 579 | } |
583 | 580 | ||
@@ -589,14 +586,14 @@ setup_interface () | |||
589 | * @return: TRUE if destruction was successful, else FALSE | 586 | * @return: TRUE if destruction was successful, else FALSE |
590 | */ | 587 | */ |
591 | static BOOL | 588 | static BOOL |
592 | remove_interface () | 589 | remove_interface() |
593 | { | 590 | { |
594 | SP_REMOVEDEVICE_PARAMS remove; | 591 | SP_REMOVEDEVICE_PARAMS remove; |
595 | 592 | ||
596 | if (INVALID_HANDLE_VALUE == DeviceInfo) | 593 | if (INVALID_HANDLE_VALUE == DeviceInfo) |
597 | return FALSE; | 594 | return FALSE; |
598 | 595 | ||
599 | remove.ClassInstallHeader.cbSize = sizeof (SP_CLASSINSTALL_HEADER); | 596 | remove.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); |
600 | remove.HwProfile = 0; | 597 | remove.HwProfile = 0; |
601 | remove.Scope = DI_REMOVEDEVICE_GLOBAL; | 598 | remove.Scope = DI_REMOVEDEVICE_GLOBAL; |
602 | remove.ClassInstallHeader.InstallFunction = DIF_REMOVE; | 599 | remove.ClassInstallHeader.InstallFunction = DIF_REMOVE; |
@@ -604,22 +601,22 @@ remove_interface () | |||
604 | * 1. Prepare our existing device information set, and place the | 601 | * 1. Prepare our existing device information set, and place the |
605 | * uninstall related information into the structure | 602 | * uninstall related information into the structure |
606 | */ | 603 | */ |
607 | if ( ! SetupDiSetClassInstallParamsA (DeviceInfo, | 604 | if (!SetupDiSetClassInstallParamsA(DeviceInfo, |
608 | (PSP_DEVINFO_DATA) & DeviceNode, | 605 | (PSP_DEVINFO_DATA)&DeviceNode, |
609 | &remove.ClassInstallHeader, | 606 | &remove.ClassInstallHeader, |
610 | sizeof (remove))) | 607 | sizeof(remove))) |
611 | return FALSE; | 608 | return FALSE; |
612 | /* | 609 | /* |
613 | * 2. Uninstall the virtual interface using the class installer | 610 | * 2. Uninstall the virtual interface using the class installer |
614 | */ | 611 | */ |
615 | if ( ! SetupDiCallClassInstaller (DIF_REMOVE, | 612 | if (!SetupDiCallClassInstaller(DIF_REMOVE, |
616 | DeviceInfo, | 613 | DeviceInfo, |
617 | (PSP_DEVINFO_DATA) & DeviceNode)) | 614 | (PSP_DEVINFO_DATA)&DeviceNode)) |
618 | return FALSE; | 615 | return FALSE; |
619 | 616 | ||
620 | SetupDiDestroyDeviceInfoList (DeviceInfo); | 617 | SetupDiDestroyDeviceInfoList(DeviceInfo); |
621 | 618 | ||
622 | fprintf (stderr, "DEBUG: removed interface successfully\n"); | 619 | fprintf(stderr, "DEBUG: removed interface successfully\n"); |
623 | 620 | ||
624 | return TRUE; | 621 | return TRUE; |
625 | } | 622 | } |
@@ -632,7 +629,7 @@ remove_interface () | |||
632 | * @return: TRUE if we were able to lookup the interface's name, else FALSE | 629 | * @return: TRUE if we were able to lookup the interface's name, else FALSE |
633 | */ | 630 | */ |
634 | static BOOL | 631 | static BOOL |
635 | resolve_interface_name () | 632 | resolve_interface_name() |
636 | { | 633 | { |
637 | SP_DEVINFO_LIST_DETAIL_DATA device_details; | 634 | SP_DEVINFO_LIST_DETAIL_DATA device_details; |
638 | char pnp_instance_id [MAX_DEVICE_ID_LEN]; | 635 | char pnp_instance_id [MAX_DEVICE_ID_LEN]; |
@@ -645,29 +642,29 @@ resolve_interface_name () | |||
645 | char adapter[] = INTERFACE_REGISTRY_LOCATION; | 642 | char adapter[] = INTERFACE_REGISTRY_LOCATION; |
646 | 643 | ||
647 | /* We can obtain the PNP instance ID from our setupapi handle */ | 644 | /* We can obtain the PNP instance ID from our setupapi handle */ |
648 | device_details.cbSize = sizeof (device_details); | 645 | device_details.cbSize = sizeof(device_details); |
649 | if (CR_SUCCESS != CM_Get_Device_ID_ExA (DeviceNode.DevInst, | 646 | if (CR_SUCCESS != CM_Get_Device_ID_ExA(DeviceNode.DevInst, |
650 | (PCHAR) pnp_instance_id, | 647 | (PCHAR)pnp_instance_id, |
651 | MAX_DEVICE_ID_LEN, | 648 | MAX_DEVICE_ID_LEN, |
652 | 0, //must be 0 | 649 | 0, //must be 0 |
653 | NULL)) //hMachine, we are local | 650 | NULL)) //hMachine, we are local |
654 | return FALSE; | 651 | return FALSE; |
655 | 652 | ||
656 | fprintf (stderr, "DEBUG: Resolving interface name for network device %s\n",pnp_instance_id); | 653 | fprintf(stderr, "DEBUG: Resolving interface name for network device %s\n", pnp_instance_id); |
657 | 654 | ||
658 | /* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */ | 655 | /* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */ |
659 | for (retrys = 0; retrys < 120 && !retval; retrys++) | 656 | for (retrys = 0; retrys < 120 && !retval; retrys++) |
660 | { | 657 | { |
661 | /* sleep for 250ms*/ | 658 | /* sleep for 250ms*/ |
662 | Sleep (250); | 659 | Sleep(250); |
663 | 660 | ||
664 | /* Now we can use this ID to locate the correct networks interface in registry */ | 661 | /* Now we can use this ID to locate the correct networks interface in registry */ |
665 | if (ERROR_SUCCESS != RegOpenKeyExA ( | 662 | if (ERROR_SUCCESS != RegOpenKeyExA( |
666 | HKEY_LOCAL_MACHINE, | 663 | HKEY_LOCAL_MACHINE, |
667 | adapter, | 664 | adapter, |
668 | 0, | 665 | 0, |
669 | KEY_READ, | 666 | KEY_READ, |
670 | &adapter_key_handle)) | 667 | &adapter_key_handle)) |
671 | return FALSE; | 668 | return FALSE; |
672 | 669 | ||
673 | /* Of course there is a multitude of entries here, with arbitrary names, | 670 | /* Of course there is a multitude of entries here, with arbitrary names, |
@@ -683,17 +680,17 @@ resolve_interface_name () | |||
683 | char adaptername_name[] = "Name"; | 680 | char adaptername_name[] = "Name"; |
684 | DWORD data_type; | 681 | DWORD data_type; |
685 | 682 | ||
686 | len = 256 * sizeof (char); | 683 | len = 256 * sizeof(char); |
687 | /* optain a subkey of {4D36E972-E325-11CE-BFC1-08002BE10318} */ | 684 | /* optain a subkey of {4D36E972-E325-11CE-BFC1-08002BE10318} */ |
688 | status = RegEnumKeyExA ( | 685 | status = RegEnumKeyExA( |
689 | adapter_key_handle, | 686 | adapter_key_handle, |
690 | i, | 687 | i, |
691 | instance_key, | 688 | instance_key, |
692 | &len, | 689 | &len, |
693 | NULL, | 690 | NULL, |
694 | NULL, | 691 | NULL, |
695 | NULL, | 692 | NULL, |
696 | NULL); | 693 | NULL); |
697 | 694 | ||
698 | /* this may fail due to one of two reasons: | 695 | /* this may fail due to one of two reasons: |
699 | * we are at the end of the list*/ | 696 | * we are at the end of the list*/ |
@@ -704,44 +701,44 @@ resolve_interface_name () | |||
704 | goto cleanup; | 701 | goto cleanup; |
705 | 702 | ||
706 | /* prepare our new query string: */ | 703 | /* prepare our new query string: */ |
707 | snprintf (query_key, 256, "%s\\%s\\Connection", | 704 | snprintf(query_key, 256, "%s\\%s\\Connection", |
708 | adapter, | 705 | adapter, |
709 | instance_key); | 706 | instance_key); |
710 | 707 | ||
711 | /* look inside instance_key\\Connection */ | 708 | /* look inside instance_key\\Connection */ |
712 | if (ERROR_SUCCESS != RegOpenKeyExA ( | 709 | if (ERROR_SUCCESS != RegOpenKeyExA( |
713 | HKEY_LOCAL_MACHINE, | 710 | HKEY_LOCAL_MACHINE, |
714 | query_key, | 711 | query_key, |
715 | 0, | 712 | 0, |
716 | KEY_READ, | 713 | KEY_READ, |
717 | &instance_key_handle)) | 714 | &instance_key_handle)) |
718 | goto cleanup; | 715 | goto cleanup; |
719 | 716 | ||
720 | /* now, read our PnpInstanceID */ | 717 | /* now, read our PnpInstanceID */ |
721 | len = sizeof (pnpinstanceid_value); | 718 | len = sizeof(pnpinstanceid_value); |
722 | status = RegQueryValueExA (instance_key_handle, | 719 | status = RegQueryValueExA(instance_key_handle, |
723 | pnpinstanceid_name, | 720 | pnpinstanceid_name, |
724 | NULL, //reserved, always NULL according to MSDN | 721 | NULL, //reserved, always NULL according to MSDN |
725 | &data_type, | 722 | &data_type, |
726 | (LPBYTE) pnpinstanceid_value, | 723 | (LPBYTE)pnpinstanceid_value, |
727 | &len); | 724 | &len); |
728 | 725 | ||
729 | if (status != ERROR_SUCCESS || data_type != REG_SZ) | 726 | if (status != ERROR_SUCCESS || data_type != REG_SZ) |
730 | goto cleanup; | 727 | goto cleanup; |
731 | 728 | ||
732 | /* compare the value we got to our devices PNPInstanceID*/ | 729 | /* compare the value we got to our devices PNPInstanceID*/ |
733 | if (0 != strncmp (pnpinstanceid_value, pnp_instance_id, | 730 | if (0 != strncmp(pnpinstanceid_value, pnp_instance_id, |
734 | sizeof (pnpinstanceid_value) / sizeof (char))) | 731 | sizeof(pnpinstanceid_value) / sizeof(char))) |
735 | goto cleanup; | 732 | goto cleanup; |
736 | 733 | ||
737 | len = sizeof (device_visible_name); | 734 | len = sizeof(device_visible_name); |
738 | status = RegQueryValueExA ( | 735 | status = RegQueryValueExA( |
739 | instance_key_handle, | 736 | instance_key_handle, |
740 | adaptername_name, | 737 | adaptername_name, |
741 | NULL, //reserved, always NULL according to MSDN | 738 | NULL, //reserved, always NULL according to MSDN |
742 | &data_type, | 739 | &data_type, |
743 | (LPBYTE) device_visible_name, | 740 | (LPBYTE)device_visible_name, |
744 | &len); | 741 | &len); |
745 | 742 | ||
746 | if (status != ERROR_SUCCESS || data_type != REG_SZ) | 743 | if (status != ERROR_SUCCESS || data_type != REG_SZ) |
747 | goto cleanup; | 744 | goto cleanup; |
@@ -750,17 +747,17 @@ resolve_interface_name () | |||
750 | * we have successfully found OUR instance, | 747 | * we have successfully found OUR instance, |
751 | * save the device GUID before exiting | 748 | * save the device GUID before exiting |
752 | */ | 749 | */ |
753 | GNUNET_strlcpy (device_guid, instance_key, sizeof (device_guid)); | 750 | GNUNET_strlcpy(device_guid, instance_key, sizeof(device_guid)); |
754 | retval = TRUE; | 751 | retval = TRUE; |
755 | fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid); | 752 | fprintf(stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid); |
756 | 753 | ||
757 | cleanup: | 754 | cleanup: |
758 | RegCloseKey (instance_key_handle); | 755 | RegCloseKey(instance_key_handle); |
759 | 756 | ||
760 | ++i; | 757 | ++i; |
761 | } | 758 | } |
762 | 759 | ||
763 | RegCloseKey (adapter_key_handle); | 760 | RegCloseKey(adapter_key_handle); |
764 | } | 761 | } |
765 | return retval; | 762 | return retval; |
766 | } | 763 | } |
@@ -773,25 +770,27 @@ cleanup: | |||
773 | * @return TRUE if the version is sufficient, else FALSE | 770 | * @return TRUE if the version is sufficient, else FALSE |
774 | */ | 771 | */ |
775 | static BOOL | 772 | static BOOL |
776 | check_tapw32_version (HANDLE handle) | 773 | check_tapw32_version(HANDLE handle) |
777 | { | 774 | { |
778 | ULONG version[3]; | 775 | ULONG version[3]; |
779 | DWORD len; | 776 | DWORD len; |
780 | memset (&(version), 0, sizeof (version)); | ||
781 | 777 | ||
782 | if (DeviceIoControl (handle, TAP_WIN_IOCTL_GET_VERSION, | 778 | memset(&(version), 0, sizeof(version)); |
783 | &version, sizeof (version), | 779 | |
784 | &version, sizeof (version), &len, NULL)) | 780 | if (DeviceIoControl(handle, TAP_WIN_IOCTL_GET_VERSION, |
785 | fprintf (stderr, "INFO: TAP-Windows Driver Version %d.%d %s\n", | 781 | &version, sizeof(version), |
786 | (int) version[0], | 782 | &version, sizeof(version), &len, NULL)) |
787 | (int) version[1], | 783 | fprintf(stderr, "INFO: TAP-Windows Driver Version %d.%d %s\n", |
788 | (version[2] ? "(DEBUG)" : "")); | 784 | (int)version[0], |
785 | (int)version[1], | ||
786 | (version[2] ? "(DEBUG)" : "")); | ||
789 | 787 | ||
790 | if ((version[0] != TAP_WIN_MIN_MAJOR) || | 788 | if ((version[0] != TAP_WIN_MIN_MAJOR) || |
791 | (version[1] < TAP_WIN_MIN_MINOR )){ | 789 | (version[1] < TAP_WIN_MIN_MINOR)) |
792 | fprintf (stderr, "FATAL: This version of gnunet requires a TAP-Windows driver that is at least version %d.%d\n", | 790 | { |
793 | TAP_WIN_MIN_MAJOR, | 791 | fprintf(stderr, "FATAL: This version of gnunet requires a TAP-Windows driver that is at least version %d.%d\n", |
794 | TAP_WIN_MIN_MINOR); | 792 | TAP_WIN_MIN_MAJOR, |
793 | TAP_WIN_MIN_MINOR); | ||
795 | return FALSE; | 794 | return FALSE; |
796 | } | 795 | } |
797 | 796 | ||
@@ -805,55 +804,55 @@ check_tapw32_version (HANDLE handle) | |||
805 | * @return the fd to the tun or -1 on error | 804 | * @return the fd to the tun or -1 on error |
806 | */ | 805 | */ |
807 | static HANDLE | 806 | static HANDLE |
808 | init_tun () | 807 | init_tun() |
809 | { | 808 | { |
810 | char device_path[256]; | 809 | char device_path[256]; |
811 | HANDLE handle; | 810 | HANDLE handle; |
812 | 811 | ||
813 | if (! setup_interface ()) | 812 | if (!setup_interface()) |
814 | { | 813 | { |
815 | errno = ENODEV; | 814 | errno = ENODEV; |
816 | return INVALID_HANDLE_VALUE; | 815 | return INVALID_HANDLE_VALUE; |
817 | } | 816 | } |
818 | 817 | ||
819 | if (! resolve_interface_name ()) | 818 | if (!resolve_interface_name()) |
820 | { | 819 | { |
821 | errno = ENODEV; | 820 | errno = ENODEV; |
822 | return INVALID_HANDLE_VALUE; | 821 | return INVALID_HANDLE_VALUE; |
823 | } | 822 | } |
824 | 823 | ||
825 | /* Open Windows TAP-Windows adapter */ | 824 | /* Open Windows TAP-Windows adapter */ |
826 | snprintf (device_path, sizeof (device_path), "%s%s%s", | 825 | snprintf(device_path, sizeof(device_path), "%s%s%s", |
827 | USERMODEDEVICEDIR, | 826 | USERMODEDEVICEDIR, |
828 | device_guid, | 827 | device_guid, |
829 | TAP_WIN_SUFFIX); | 828 | TAP_WIN_SUFFIX); |
830 | 829 | ||
831 | handle = CreateFile ( | 830 | handle = CreateFile( |
832 | device_path, | 831 | device_path, |
833 | GENERIC_READ | GENERIC_WRITE, | 832 | GENERIC_READ | GENERIC_WRITE, |
834 | 0, /* was: FILE_SHARE_READ */ | 833 | 0, /* was: FILE_SHARE_READ */ |
835 | 0, | 834 | 0, |
836 | OPEN_EXISTING, | 835 | OPEN_EXISTING, |
837 | FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, | 836 | FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, |
838 | 0 | 837 | 0 |
839 | ); | 838 | ); |
840 | 839 | ||
841 | if (INVALID_HANDLE_VALUE == handle) | 840 | if (INVALID_HANDLE_VALUE == handle) |
842 | { | 841 | { |
843 | fprintf (stderr, "FATAL: CreateFile failed on TAP device: %s\n", device_path); | 842 | fprintf(stderr, "FATAL: CreateFile failed on TAP device: %s\n", device_path); |
844 | return handle; | 843 | return handle; |
845 | } | 844 | } |
846 | 845 | ||
847 | /* get driver version info */ | 846 | /* get driver version info */ |
848 | if (! check_tapw32_version (handle)) | 847 | if (!check_tapw32_version(handle)) |
849 | { | 848 | { |
850 | CloseHandle (handle); | 849 | CloseHandle(handle); |
851 | return INVALID_HANDLE_VALUE; | 850 | return INVALID_HANDLE_VALUE; |
852 | } | 851 | } |
853 | 852 | ||
854 | /* TODO (opt?): get MTU-Size */ | 853 | /* TODO (opt?): get MTU-Size */ |
855 | 854 | ||
856 | fprintf (stderr, "DEBUG: successfully opened TAP device\n"); | 855 | fprintf(stderr, "DEBUG: successfully opened TAP device\n"); |
857 | return handle; | 856 | return handle; |
858 | } | 857 | } |
859 | 858 | ||
@@ -865,21 +864,22 @@ init_tun () | |||
865 | * @return True if the operation succeeded, else false | 864 | * @return True if the operation succeeded, else false |
866 | */ | 865 | */ |
867 | static BOOL | 866 | static BOOL |
868 | tun_up (HANDLE handle) | 867 | tun_up(HANDLE handle) |
869 | { | 868 | { |
870 | ULONG status = TRUE; | 869 | ULONG status = TRUE; |
871 | DWORD len; | 870 | DWORD len; |
872 | if (! DeviceIoControl (handle, TAP_WIN_IOCTL_SET_MEDIA_STATUS, | 871 | |
873 | &status, sizeof (status), | 872 | if (!DeviceIoControl(handle, TAP_WIN_IOCTL_SET_MEDIA_STATUS, |
874 | &status, sizeof (status), &len, NULL)) | 873 | &status, sizeof(status), |
874 | &status, sizeof(status), &len, NULL)) | ||
875 | { | 875 | { |
876 | fprintf (stderr, "FATAL: TAP driver ignored request to UP interface (DeviceIoControl call)\n"); | 876 | fprintf(stderr, "FATAL: TAP driver ignored request to UP interface (DeviceIoControl call)\n"); |
877 | return FALSE; | 877 | return FALSE; |
878 | } | 878 | } |
879 | 879 | ||
880 | /* Wait for the device to go UP, might take some time. */ | 880 | /* Wait for the device to go UP, might take some time. */ |
881 | Sleep (TAP32_POSTUP_WAITTIME * 1000); | 881 | Sleep(TAP32_POSTUP_WAITTIME * 1000); |
882 | fprintf (stderr, "DEBUG: successfully set TAP device to UP\n"); | 882 | fprintf(stderr, "DEBUG: successfully set TAP device to UP\n"); |
883 | 883 | ||
884 | return TRUE; | 884 | return TRUE; |
885 | } | 885 | } |
@@ -911,8 +911,8 @@ tun_up (HANDLE handle) | |||
911 | * @return false if an event reset was impossible (OS error), else true | 911 | * @return false if an event reset was impossible (OS error), else true |
912 | */ | 912 | */ |
913 | static BOOL | 913 | static BOOL |
914 | attempt_read_tap (struct io_facility * input_facility, | 914 | attempt_read_tap(struct io_facility * input_facility, |
915 | struct io_facility * output_facility) | 915 | struct io_facility * output_facility) |
916 | { | 916 | { |
917 | struct GNUNET_MessageHeader * hdr; | 917 | struct GNUNET_MessageHeader * hdr; |
918 | unsigned short size; | 918 | unsigned short size; |
@@ -920,137 +920,139 @@ attempt_read_tap (struct io_facility * input_facility, | |||
920 | switch (input_facility->facility_state) | 920 | switch (input_facility->facility_state) |
921 | { | 921 | { |
922 | case IOSTATE_READY: | 922 | case IOSTATE_READY: |
923 | { | 923 | { |
924 | if (! ResetEvent (input_facility->overlapped.hEvent)) | 924 | if (!ResetEvent(input_facility->overlapped.hEvent)) |
925 | { | 925 | { |
926 | return FALSE; | ||
927 | } | ||
928 | |||
929 | input_facility->buffer_size = 0; | ||
930 | |||
931 | /* Check how the task is handled */ | ||
932 | if (ReadFile(input_facility->handle, | ||
933 | input_facility->buffer, | ||
934 | sizeof(input_facility->buffer) - sizeof(struct GNUNET_MessageHeader), | ||
935 | &input_facility->buffer_size, | ||
936 | &input_facility->overlapped)) | ||
937 | { /* async event processed immediately*/ | ||
938 | /* reset event manually*/ | ||
939 | if (!SetEvent(input_facility->overlapped.hEvent)) | ||
926 | return FALSE; | 940 | return FALSE; |
927 | } | 941 | |
928 | 942 | fprintf(stderr, "DEBUG: tap read succeeded immediately\n"); | |
929 | input_facility->buffer_size = 0; | 943 | |
930 | 944 | /* we successfully read something from the TAP and now need to | |
931 | /* Check how the task is handled */ | 945 | * send it our via STDOUT. Is that possible at the moment? */ |
932 | if (ReadFile (input_facility->handle, | 946 | if ((IOSTATE_READY == output_facility->facility_state || |
933 | input_facility->buffer, | 947 | IOSTATE_WAITING == output_facility->facility_state) |
934 | sizeof (input_facility->buffer) - sizeof (struct GNUNET_MessageHeader), | 948 | && (0 < input_facility->buffer_size)) |
935 | &input_facility->buffer_size, | 949 | { /* hand over this buffers content and apply message header for gnunet */ |
936 | &input_facility->overlapped)) | 950 | hdr = (struct GNUNET_MessageHeader *)output_facility->buffer; |
937 | {/* async event processed immediately*/ | 951 | size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader); |
938 | 952 | ||
939 | /* reset event manually*/ | 953 | GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader), |
940 | if (! SetEvent (input_facility->overlapped.hEvent)) | 954 | input_facility->buffer, |
941 | return FALSE; | 955 | input_facility->buffer_size); |
942 | 956 | ||
943 | fprintf (stderr, "DEBUG: tap read succeeded immediately\n"); | 957 | output_facility->buffer_size = size; |
944 | 958 | hdr->size = htons(size); | |
945 | /* we successfully read something from the TAP and now need to | 959 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); |
946 | * send it our via STDOUT. Is that possible at the moment? */ | 960 | output_facility->facility_state = IOSTATE_READY; |
947 | if ((IOSTATE_READY == output_facility->facility_state || | 961 | } |
948 | IOSTATE_WAITING == output_facility->facility_state) | 962 | else if (0 < input_facility->buffer_size) |
949 | && (0 < input_facility->buffer_size)) | 963 | /* If we have have read our buffer, wait for our write-partner*/ |
950 | { /* hand over this buffers content and apply message header for gnunet */ | 964 | input_facility->facility_state = IOSTATE_WAITING; |
951 | hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; | 965 | } |
952 | size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); | 966 | else /* operation was either queued or failed*/ |
953 | 967 | { | |
954 | GNUNET_memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), | 968 | int err = GetLastError(); |
955 | input_facility->buffer, | 969 | if (ERROR_IO_PENDING == err) |
956 | input_facility->buffer_size); | 970 | { /* operation queued */ |
957 | 971 | input_facility->facility_state = IOSTATE_QUEUED; | |
958 | output_facility->buffer_size = size; | 972 | } |
959 | hdr->size = htons (size); | 973 | else |
960 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 974 | { /* error occurred, let the rest of the elements finish */ |
961 | output_facility->facility_state = IOSTATE_READY; | 975 | input_facility->path_open = FALSE; |
962 | } | 976 | input_facility->facility_state = IOSTATE_FAILED; |
963 | else if (0 < input_facility->buffer_size) | 977 | if (IOSTATE_WAITING == output_facility->facility_state) |
964 | /* If we have have read our buffer, wait for our write-partner*/ | 978 | output_facility->path_open = FALSE; |
965 | input_facility->facility_state = IOSTATE_WAITING; | 979 | |
966 | } | 980 | fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n"); |
967 | else /* operation was either queued or failed*/ | 981 | } |
968 | { | 982 | } |
969 | int err = GetLastError (); | 983 | } |
970 | if (ERROR_IO_PENDING == err) | ||
971 | { /* operation queued */ | ||
972 | input_facility->facility_state = IOSTATE_QUEUED; | ||
973 | } | ||
974 | else | ||
975 | { /* error occurred, let the rest of the elements finish */ | ||
976 | input_facility->path_open = FALSE; | ||
977 | input_facility->facility_state = IOSTATE_FAILED; | ||
978 | if (IOSTATE_WAITING == output_facility->facility_state) | ||
979 | output_facility->path_open = FALSE; | ||
980 | |||
981 | fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n"); | ||
982 | } | ||
983 | } | ||
984 | } | ||
985 | return TRUE; | 984 | return TRUE; |
986 | // We are queued and should check if the read has finished | 985 | |
986 | // We are queued and should check if the read has finished | ||
987 | case IOSTATE_QUEUED: | 987 | case IOSTATE_QUEUED: |
988 | { | 988 | { |
989 | // there was an operation going on already, check if that has completed now. | 989 | // there was an operation going on already, check if that has completed now. |
990 | 990 | ||
991 | if (GetOverlappedResult (input_facility->handle, | 991 | if (GetOverlappedResult(input_facility->handle, |
992 | &input_facility->overlapped, | 992 | &input_facility->overlapped, |
993 | &input_facility->buffer_size, | 993 | &input_facility->buffer_size, |
994 | FALSE)) | 994 | FALSE)) |
995 | {/* successful return for a queued operation */ | 995 | { /* successful return for a queued operation */ |
996 | if (! ResetEvent (input_facility->overlapped.hEvent)) | 996 | if (!ResetEvent(input_facility->overlapped.hEvent)) |
997 | return FALSE; | 997 | return FALSE; |
998 | 998 | ||
999 | fprintf (stderr, "DEBUG: tap read succeeded delayed\n"); | 999 | fprintf(stderr, "DEBUG: tap read succeeded delayed\n"); |
1000 | 1000 | ||
1001 | /* we successfully read something from the TAP and now need to | 1001 | /* we successfully read something from the TAP and now need to |
1002 | * send it our via STDOUT. Is that possible at the moment? */ | 1002 | * send it our via STDOUT. Is that possible at the moment? */ |
1003 | if ((IOSTATE_READY == output_facility->facility_state || | 1003 | if ((IOSTATE_READY == output_facility->facility_state || |
1004 | IOSTATE_WAITING == output_facility->facility_state) | 1004 | IOSTATE_WAITING == output_facility->facility_state) |
1005 | && 0 < input_facility->buffer_size) | 1005 | && 0 < input_facility->buffer_size) |
1006 | { /* hand over this buffers content and apply message header for gnunet */ | 1006 | { /* hand over this buffers content and apply message header for gnunet */ |
1007 | hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; | 1007 | hdr = (struct GNUNET_MessageHeader *)output_facility->buffer; |
1008 | size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); | 1008 | size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader); |
1009 | 1009 | ||
1010 | GNUNET_memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), | 1010 | GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader), |
1011 | input_facility->buffer, | 1011 | input_facility->buffer, |
1012 | input_facility->buffer_size); | 1012 | input_facility->buffer_size); |
1013 | 1013 | ||
1014 | output_facility->buffer_size = size; | 1014 | output_facility->buffer_size = size; |
1015 | hdr->size = htons(size); | 1015 | hdr->size = htons(size); |
1016 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1016 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1017 | output_facility->facility_state = IOSTATE_READY; | 1017 | output_facility->facility_state = IOSTATE_READY; |
1018 | input_facility->facility_state = IOSTATE_READY; | 1018 | input_facility->facility_state = IOSTATE_READY; |
1019 | } | 1019 | } |
1020 | else if (0 < input_facility->buffer_size) | 1020 | else if (0 < input_facility->buffer_size) |
1021 | { /* If we have have read our buffer, wait for our write-partner*/ | 1021 | { /* If we have have read our buffer, wait for our write-partner*/ |
1022 | input_facility->facility_state = IOSTATE_WAITING; | 1022 | input_facility->facility_state = IOSTATE_WAITING; |
1023 | // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish? | 1023 | // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish? |
1024 | } | 1024 | } |
1025 | } | 1025 | } |
1026 | else | 1026 | else |
1027 | { /* operation still pending/queued or failed? */ | 1027 | { /* operation still pending/queued or failed? */ |
1028 | int err = GetLastError (); | 1028 | int err = GetLastError(); |
1029 | if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err)) | 1029 | if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err)) |
1030 | { /* error occurred, let the rest of the elements finish */ | 1030 | { /* error occurred, let the rest of the elements finish */ |
1031 | input_facility->path_open = FALSE; | 1031 | input_facility->path_open = FALSE; |
1032 | input_facility->facility_state = IOSTATE_FAILED; | 1032 | input_facility->facility_state = IOSTATE_FAILED; |
1033 | if (IOSTATE_WAITING == output_facility->facility_state) | 1033 | if (IOSTATE_WAITING == output_facility->facility_state) |
1034 | output_facility->path_open = FALSE; | 1034 | output_facility->path_open = FALSE; |
1035 | fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n"); | 1035 | fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n"); |
1036 | } | 1036 | } |
1037 | } | 1037 | } |
1038 | } | 1038 | } |
1039 | return TRUE; | 1039 | return TRUE; |
1040 | |||
1040 | case IOSTATE_RESUME: | 1041 | case IOSTATE_RESUME: |
1041 | hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; | 1042 | hdr = (struct GNUNET_MessageHeader *)output_facility->buffer; |
1042 | size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); | 1043 | size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader); |
1043 | 1044 | ||
1044 | GNUNET_memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), | 1045 | GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader), |
1045 | input_facility->buffer, | 1046 | input_facility->buffer, |
1046 | input_facility->buffer_size); | 1047 | input_facility->buffer_size); |
1047 | 1048 | ||
1048 | output_facility->buffer_size = size; | 1049 | output_facility->buffer_size = size; |
1049 | hdr->size = htons (size); | 1050 | hdr->size = htons(size); |
1050 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1051 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1051 | output_facility->facility_state = IOSTATE_READY; | 1052 | output_facility->facility_state = IOSTATE_READY; |
1052 | input_facility->facility_state = IOSTATE_READY; | 1053 | input_facility->facility_state = IOSTATE_READY; |
1053 | return TRUE; | 1054 | return TRUE; |
1055 | |||
1054 | default: | 1056 | default: |
1055 | return TRUE; | 1057 | return TRUE; |
1056 | } | 1058 | } |
@@ -1084,154 +1086,157 @@ attempt_read_tap (struct io_facility * input_facility, | |||
1084 | * @return false if an event reset was impossible (OS error), else true | 1086 | * @return false if an event reset was impossible (OS error), else true |
1085 | */ | 1087 | */ |
1086 | static BOOL | 1088 | static BOOL |
1087 | attempt_read_stdin (struct io_facility * input_facility, | 1089 | attempt_read_stdin(struct io_facility * input_facility, |
1088 | struct io_facility * output_facility) | 1090 | struct io_facility * output_facility) |
1089 | { | 1091 | { |
1090 | struct GNUNET_MessageHeader * hdr; | 1092 | struct GNUNET_MessageHeader * hdr; |
1091 | 1093 | ||
1092 | switch (input_facility->facility_state) | 1094 | switch (input_facility->facility_state) |
1093 | { | 1095 | { |
1094 | case IOSTATE_READY: | 1096 | case IOSTATE_READY: |
1095 | { | 1097 | { |
1096 | input_facility->buffer_size = 0; | 1098 | input_facility->buffer_size = 0; |
1097 | 1099 | ||
1098 | partial_read_iostate_ready: | 1100 | partial_read_iostate_ready: |
1099 | if (! ResetEvent (input_facility->overlapped.hEvent)) | 1101 | if (!ResetEvent(input_facility->overlapped.hEvent)) |
1100 | return FALSE; | 1102 | return FALSE; |
1101 | 1103 | ||
1102 | /* Check how the task is handled */ | 1104 | /* Check how the task is handled */ |
1103 | if (ReadFile (input_facility->handle, | 1105 | if (ReadFile(input_facility->handle, |
1104 | input_facility->buffer + input_facility->buffer_size, | 1106 | input_facility->buffer + input_facility->buffer_size, |
1105 | sizeof (input_facility->buffer) - input_facility->buffer_size, | 1107 | sizeof(input_facility->buffer) - input_facility->buffer_size, |
1106 | &input_facility->buffer_size_processed, | 1108 | &input_facility->buffer_size_processed, |
1107 | &input_facility->overlapped)) | 1109 | &input_facility->overlapped)) |
1108 | {/* async event processed immediately*/ | 1110 | { /* async event processed immediately*/ |
1109 | hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; | 1111 | hdr = (struct GNUNET_MessageHeader *)input_facility->buffer; |
1110 | 1112 | ||
1111 | /* reset event manually*/ | 1113 | /* reset event manually*/ |
1112 | if (!SetEvent (input_facility->overlapped.hEvent)) | 1114 | if (!SetEvent(input_facility->overlapped.hEvent)) |
1113 | return FALSE; | 1115 | return FALSE; |
1114 | 1116 | ||
1115 | fprintf (stderr, "DEBUG: stdin read succeeded immediately\n"); | 1117 | fprintf(stderr, "DEBUG: stdin read succeeded immediately\n"); |
1116 | input_facility->buffer_size += input_facility->buffer_size_processed; | 1118 | input_facility->buffer_size += input_facility->buffer_size_processed; |
1117 | 1119 | ||
1118 | if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || | 1120 | if (ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || |
1119 | ntohs (hdr->size) > sizeof (input_facility->buffer)) | 1121 | ntohs(hdr->size) > sizeof(input_facility->buffer)) |
1120 | { | 1122 | { |
1121 | fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs (hdr->type), ntohs (hdr->size)); | 1123 | fprintf(stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs(hdr->type), ntohs(hdr->size)); |
1122 | input_facility->facility_state = IOSTATE_READY; | 1124 | input_facility->facility_state = IOSTATE_READY; |
1123 | return TRUE; | 1125 | return TRUE; |
1124 | } | 1126 | } |
1125 | /* we got the a part of a packet */ | 1127 | /* we got the a part of a packet */ |
1126 | if (ntohs (hdr->size) > input_facility->buffer_size) | 1128 | if (ntohs(hdr->size) > input_facility->buffer_size) |
1127 | goto partial_read_iostate_ready; | 1129 | goto partial_read_iostate_ready; |
1128 | 1130 | ||
1129 | /* have we read more than 0 bytes of payload? (sizeread > header)*/ | 1131 | /* have we read more than 0 bytes of payload? (sizeread > header)*/ |
1130 | if (input_facility->buffer_size > sizeof (struct GNUNET_MessageHeader) && | 1132 | if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader) && |
1131 | ((IOSTATE_READY == output_facility->facility_state) || | 1133 | ((IOSTATE_READY == output_facility->facility_state) || |
1132 | (IOSTATE_WAITING == output_facility->facility_state))) | 1134 | (IOSTATE_WAITING == output_facility->facility_state))) |
1133 | {/* we successfully read something from the TAP and now need to | 1135 | { /* we successfully read something from the TAP and now need to |
1134 | * send it our via STDOUT. Is that possible at the moment? */ | 1136 | * send it our via STDOUT. Is that possible at the moment? */ |
1135 | 1137 | /* hand over this buffers content and strip gnunet message header */ | |
1136 | /* hand over this buffers content and strip gnunet message header */ | 1138 | GNUNET_memcpy(output_facility->buffer, |
1137 | GNUNET_memcpy (output_facility->buffer, | 1139 | input_facility->buffer + sizeof(struct GNUNET_MessageHeader), |
1138 | input_facility->buffer + sizeof (struct GNUNET_MessageHeader), | 1140 | input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader)); |
1139 | input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader)); | 1141 | output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader); |
1140 | output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader); | 1142 | output_facility->facility_state = IOSTATE_READY; |
1141 | output_facility->facility_state = IOSTATE_READY; | ||
1142 | input_facility->facility_state = IOSTATE_READY; | ||
1143 | } | ||
1144 | else if (input_facility->buffer_size > sizeof (struct GNUNET_MessageHeader)) | ||
1145 | /* If we have have read our buffer, wait for our write-partner*/ | ||
1146 | input_facility->facility_state = IOSTATE_WAITING; | ||
1147 | else /* we read nothing */ | ||
1148 | input_facility->facility_state = IOSTATE_READY; | 1143 | input_facility->facility_state = IOSTATE_READY; |
1149 | } | 1144 | } |
1150 | else /* operation was either queued or failed*/ | 1145 | else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader)) |
1151 | { | 1146 | /* If we have have read our buffer, wait for our write-partner*/ |
1152 | int err = GetLastError (); | 1147 | input_facility->facility_state = IOSTATE_WAITING; |
1153 | if (ERROR_IO_PENDING == err) /* operation queued */ | 1148 | else /* we read nothing */ |
1154 | input_facility->facility_state = IOSTATE_QUEUED; | 1149 | input_facility->facility_state = IOSTATE_READY; |
1155 | else | 1150 | } |
1156 | { /* error occurred, let the rest of the elements finish */ | 1151 | else /* operation was either queued or failed*/ |
1157 | input_facility->path_open = FALSE; | 1152 | { |
1158 | input_facility->facility_state = IOSTATE_FAILED; | 1153 | int err = GetLastError(); |
1159 | if (IOSTATE_WAITING == output_facility->facility_state) | 1154 | if (ERROR_IO_PENDING == err) /* operation queued */ |
1160 | output_facility->path_open = FALSE; | 1155 | input_facility->facility_state = IOSTATE_QUEUED; |
1161 | 1156 | else | |
1162 | fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n"); | 1157 | { /* error occurred, let the rest of the elements finish */ |
1163 | } | 1158 | input_facility->path_open = FALSE; |
1164 | } | 1159 | input_facility->facility_state = IOSTATE_FAILED; |
1165 | } | 1160 | if (IOSTATE_WAITING == output_facility->facility_state) |
1161 | output_facility->path_open = FALSE; | ||
1162 | |||
1163 | fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n"); | ||
1164 | } | ||
1165 | } | ||
1166 | } | ||
1166 | return TRUE; | 1167 | return TRUE; |
1167 | // We are queued and should check if the read has finished | 1168 | |
1169 | // We are queued and should check if the read has finished | ||
1168 | case IOSTATE_QUEUED: | 1170 | case IOSTATE_QUEUED: |
1169 | { | 1171 | { |
1170 | // there was an operation going on already, check if that has completed now. | 1172 | // there was an operation going on already, check if that has completed now. |
1171 | if (GetOverlappedResult (input_facility->handle, | 1173 | if (GetOverlappedResult(input_facility->handle, |
1172 | &input_facility->overlapped, | 1174 | &input_facility->overlapped, |
1173 | &input_facility->buffer_size_processed, | 1175 | &input_facility->buffer_size_processed, |
1174 | FALSE)) | 1176 | FALSE)) |
1175 | {/* successful return for a queued operation */ | 1177 | { /* successful return for a queued operation */ |
1176 | hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; | 1178 | hdr = (struct GNUNET_MessageHeader *)input_facility->buffer; |
1177 | 1179 | ||
1178 | if (! ResetEvent (input_facility->overlapped.hEvent)) | 1180 | if (!ResetEvent(input_facility->overlapped.hEvent)) |
1179 | return FALSE; | 1181 | return FALSE; |
1180 | 1182 | ||
1181 | fprintf (stderr, "DEBUG: stdin read succeeded delayed\n"); | 1183 | fprintf(stderr, "DEBUG: stdin read succeeded delayed\n"); |
1182 | input_facility->buffer_size += input_facility->buffer_size_processed; | 1184 | input_facility->buffer_size += input_facility->buffer_size_processed; |
1183 | 1185 | ||
1184 | if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || | 1186 | if ((ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || |
1185 | (ntohs (hdr->size) > sizeof (input_facility->buffer))) | 1187 | (ntohs(hdr->size) > sizeof(input_facility->buffer))) |
1186 | { | 1188 | { |
1187 | fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs (hdr->type), ntohs (hdr->size)); | 1189 | fprintf(stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs(hdr->type), ntohs(hdr->size)); |
1188 | input_facility->facility_state = IOSTATE_READY; | ||
1189 | return TRUE; | ||
1190 | } | ||
1191 | /* we got the a part of a packet */ | ||
1192 | if (ntohs (hdr->size) > input_facility->buffer_size ); | ||
1193 | goto partial_read_iostate_ready; | ||
1194 | |||
1195 | /* we successfully read something from the TAP and now need to | ||
1196 | * send it our via STDOUT. Is that possible at the moment? */ | ||
1197 | if ((IOSTATE_READY == output_facility->facility_state || | ||
1198 | IOSTATE_WAITING == output_facility->facility_state) | ||
1199 | && input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader)) | ||
1200 | { /* hand over this buffers content and strip gnunet message header */ | ||
1201 | GNUNET_memcpy (output_facility->buffer, | ||
1202 | input_facility->buffer + sizeof(struct GNUNET_MessageHeader), | ||
1203 | input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader)); | ||
1204 | output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader); | ||
1205 | output_facility->facility_state = IOSTATE_READY; | ||
1206 | input_facility->facility_state = IOSTATE_READY; | ||
1207 | } | ||
1208 | else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader)) | ||
1209 | input_facility->facility_state = IOSTATE_WAITING; | ||
1210 | else | ||
1211 | input_facility->facility_state = IOSTATE_READY; | 1190 | input_facility->facility_state = IOSTATE_READY; |
1212 | } | 1191 | return TRUE; |
1213 | else | 1192 | } |
1214 | { /* operation still pending/queued or failed? */ | 1193 | /* we got the a part of a packet */ |
1215 | int err = GetLastError (); | 1194 | if (ntohs(hdr->size) > input_facility->buffer_size) |
1216 | if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err)) | 1195 | ; |
1217 | { /* error occurred, let the rest of the elements finish */ | 1196 | goto partial_read_iostate_ready; |
1218 | input_facility->path_open = FALSE; | 1197 | |
1219 | input_facility->facility_state = IOSTATE_FAILED; | 1198 | /* we successfully read something from the TAP and now need to |
1220 | if (IOSTATE_WAITING == output_facility->facility_state) | 1199 | * send it our via STDOUT. Is that possible at the moment? */ |
1221 | output_facility->path_open = FALSE; | 1200 | if ((IOSTATE_READY == output_facility->facility_state || |
1222 | fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n"); | 1201 | IOSTATE_WAITING == output_facility->facility_state) |
1223 | } | 1202 | && input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader)) |
1224 | } | 1203 | { /* hand over this buffers content and strip gnunet message header */ |
1225 | } | 1204 | GNUNET_memcpy(output_facility->buffer, |
1205 | input_facility->buffer + sizeof(struct GNUNET_MessageHeader), | ||
1206 | input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader)); | ||
1207 | output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader); | ||
1208 | output_facility->facility_state = IOSTATE_READY; | ||
1209 | input_facility->facility_state = IOSTATE_READY; | ||
1210 | } | ||
1211 | else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader)) | ||
1212 | input_facility->facility_state = IOSTATE_WAITING; | ||
1213 | else | ||
1214 | input_facility->facility_state = IOSTATE_READY; | ||
1215 | } | ||
1216 | else | ||
1217 | { /* operation still pending/queued or failed? */ | ||
1218 | int err = GetLastError(); | ||
1219 | if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err)) | ||
1220 | { /* error occurred, let the rest of the elements finish */ | ||
1221 | input_facility->path_open = FALSE; | ||
1222 | input_facility->facility_state = IOSTATE_FAILED; | ||
1223 | if (IOSTATE_WAITING == output_facility->facility_state) | ||
1224 | output_facility->path_open = FALSE; | ||
1225 | fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n"); | ||
1226 | } | ||
1227 | } | ||
1228 | } | ||
1226 | return TRUE; | 1229 | return TRUE; |
1230 | |||
1227 | case IOSTATE_RESUME: /* Our buffer was filled already but our write facility was busy. */ | 1231 | case IOSTATE_RESUME: /* Our buffer was filled already but our write facility was busy. */ |
1228 | GNUNET_memcpy (output_facility->buffer, | 1232 | GNUNET_memcpy(output_facility->buffer, |
1229 | input_facility->buffer + sizeof (struct GNUNET_MessageHeader), | 1233 | input_facility->buffer + sizeof(struct GNUNET_MessageHeader), |
1230 | input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader)); | 1234 | input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader)); |
1231 | output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader); | 1235 | output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader); |
1232 | output_facility->facility_state = IOSTATE_READY; | 1236 | output_facility->facility_state = IOSTATE_READY; |
1233 | input_facility->facility_state = IOSTATE_READY; | 1237 | input_facility->facility_state = IOSTATE_READY; |
1234 | return TRUE; | 1238 | return TRUE; |
1239 | |||
1235 | default: | 1240 | default: |
1236 | return TRUE; | 1241 | return TRUE; |
1237 | } | 1242 | } |
@@ -1248,8 +1253,8 @@ partial_read_iostate_ready: | |||
1248 | * @return false if an event reset was impossible (OS error), else true | 1253 | * @return false if an event reset was impossible (OS error), else true |
1249 | */ | 1254 | */ |
1250 | static BOOL | 1255 | static BOOL |
1251 | attempt_write (struct io_facility * output_facility, | 1256 | attempt_write(struct io_facility * output_facility, |
1252 | struct io_facility * input_facility) | 1257 | struct io_facility * input_facility) |
1253 | { | 1258 | { |
1254 | switch (output_facility->facility_state) | 1259 | switch (output_facility->facility_state) |
1255 | { | 1260 | { |
@@ -1257,22 +1262,21 @@ attempt_write (struct io_facility * output_facility, | |||
1257 | output_facility->buffer_size_written = 0; | 1262 | output_facility->buffer_size_written = 0; |
1258 | 1263 | ||
1259 | continue_partial_write: | 1264 | continue_partial_write: |
1260 | if (! ResetEvent (output_facility->overlapped.hEvent)) | 1265 | if (!ResetEvent(output_facility->overlapped.hEvent)) |
1261 | return FALSE; | 1266 | return FALSE; |
1262 | 1267 | ||
1263 | /* Check how the task was handled */ | 1268 | /* Check how the task was handled */ |
1264 | if (WriteFile (output_facility->handle, | 1269 | if (WriteFile(output_facility->handle, |
1265 | output_facility->buffer + output_facility->buffer_size_written, | 1270 | output_facility->buffer + output_facility->buffer_size_written, |
1266 | output_facility->buffer_size - output_facility->buffer_size_written, | 1271 | output_facility->buffer_size - output_facility->buffer_size_written, |
1267 | &output_facility->buffer_size_processed, | 1272 | &output_facility->buffer_size_processed, |
1268 | &output_facility->overlapped)) | 1273 | &output_facility->overlapped)) |
1269 | {/* async event processed immediately*/ | 1274 | {/* async event processed immediately*/ |
1270 | 1275 | fprintf(stderr, "DEBUG: write succeeded immediately\n"); | |
1271 | fprintf (stderr, "DEBUG: write succeeded immediately\n"); | ||
1272 | output_facility->buffer_size_written += output_facility->buffer_size_processed; | 1276 | output_facility->buffer_size_written += output_facility->buffer_size_processed; |
1273 | 1277 | ||
1274 | /* reset event manually*/ | 1278 | /* reset event manually*/ |
1275 | if (! SetEvent (output_facility->overlapped.hEvent)) | 1279 | if (!SetEvent(output_facility->overlapped.hEvent)) |
1276 | return FALSE; | 1280 | return FALSE; |
1277 | 1281 | ||
1278 | /* partial write */ | 1282 | /* partial write */ |
@@ -1290,7 +1294,7 @@ continue_partial_write: | |||
1290 | } | 1294 | } |
1291 | else /* operation was either queued or failed*/ | 1295 | else /* operation was either queued or failed*/ |
1292 | { | 1296 | { |
1293 | int err = GetLastError (); | 1297 | int err = GetLastError(); |
1294 | if (ERROR_IO_PENDING == err) | 1298 | if (ERROR_IO_PENDING == err) |
1295 | { /* operation queued */ | 1299 | { /* operation queued */ |
1296 | output_facility->facility_state = IOSTATE_QUEUED; | 1300 | output_facility->facility_state = IOSTATE_QUEUED; |
@@ -1299,22 +1303,23 @@ continue_partial_write: | |||
1299 | { /* error occurred, close this path */ | 1303 | { /* error occurred, close this path */ |
1300 | output_facility->path_open = FALSE; | 1304 | output_facility->path_open = FALSE; |
1301 | output_facility->facility_state = IOSTATE_FAILED; | 1305 | output_facility->facility_state = IOSTATE_FAILED; |
1302 | fprintf (stderr, "FATAL: Write to handle failed, exiting\n"); | 1306 | fprintf(stderr, "FATAL: Write to handle failed, exiting\n"); |
1303 | } | 1307 | } |
1304 | } | 1308 | } |
1305 | return TRUE; | 1309 | return TRUE; |
1310 | |||
1306 | case IOSTATE_QUEUED: | 1311 | case IOSTATE_QUEUED: |
1307 | // there was an operation going on already, check if that has completed now. | 1312 | // there was an operation going on already, check if that has completed now. |
1308 | 1313 | ||
1309 | if (GetOverlappedResult (output_facility->handle, | 1314 | if (GetOverlappedResult(output_facility->handle, |
1310 | &output_facility->overlapped, | 1315 | &output_facility->overlapped, |
1311 | &output_facility->buffer_size_processed, | 1316 | &output_facility->buffer_size_processed, |
1312 | FALSE)) | 1317 | FALSE)) |
1313 | {/* successful return for a queued operation */ | 1318 | {/* successful return for a queued operation */ |
1314 | if (! ResetEvent (output_facility->overlapped.hEvent)) | 1319 | if (!ResetEvent(output_facility->overlapped.hEvent)) |
1315 | return FALSE; | 1320 | return FALSE; |
1316 | 1321 | ||
1317 | fprintf (stderr, "DEBUG: write succeeded delayed\n"); | 1322 | fprintf(stderr, "DEBUG: write succeeded delayed\n"); |
1318 | output_facility->buffer_size_written += output_facility->buffer_size_processed; | 1323 | output_facility->buffer_size_written += output_facility->buffer_size_processed; |
1319 | 1324 | ||
1320 | /* partial write */ | 1325 | /* partial write */ |
@@ -1332,14 +1337,15 @@ continue_partial_write: | |||
1332 | } | 1337 | } |
1333 | else | 1338 | else |
1334 | { /* operation still pending/queued or failed? */ | 1339 | { /* operation still pending/queued or failed? */ |
1335 | int err = GetLastError (); | 1340 | int err = GetLastError(); |
1336 | if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err)) | 1341 | if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err)) |
1337 | { /* error occurred, close this path */ | 1342 | { /* error occurred, close this path */ |
1338 | output_facility->path_open = FALSE; | 1343 | output_facility->path_open = FALSE; |
1339 | output_facility->facility_state = IOSTATE_FAILED; | 1344 | output_facility->facility_state = IOSTATE_FAILED; |
1340 | fprintf (stderr, "FATAL: Write to handle failed, exiting\n"); | 1345 | fprintf(stderr, "FATAL: Write to handle failed, exiting\n"); |
1341 | } | 1346 | } |
1342 | } | 1347 | } |
1348 | |||
1343 | default: | 1349 | default: |
1344 | return TRUE; | 1350 | return TRUE; |
1345 | } | 1351 | } |
@@ -1355,15 +1361,15 @@ continue_partial_write: | |||
1355 | * @return true on success, else false | 1361 | * @return true on success, else false |
1356 | */ | 1362 | */ |
1357 | static BOOL | 1363 | static BOOL |
1358 | initialize_io_facility (struct io_facility * elem, | 1364 | initialize_io_facility(struct io_facility * elem, |
1359 | int initial_state, | 1365 | int initial_state, |
1360 | BOOL signaled) | 1366 | BOOL signaled) |
1361 | { | 1367 | { |
1362 | elem->path_open = TRUE; | 1368 | elem->path_open = TRUE; |
1363 | elem->handle = INVALID_HANDLE_VALUE; | 1369 | elem->handle = INVALID_HANDLE_VALUE; |
1364 | elem->facility_state = initial_state; | 1370 | elem->facility_state = initial_state; |
1365 | elem->buffer_size = 0; | 1371 | elem->buffer_size = 0; |
1366 | elem->overlapped.hEvent = CreateEvent (NULL, TRUE, signaled, NULL); | 1372 | elem->overlapped.hEvent = CreateEvent(NULL, TRUE, signaled, NULL); |
1367 | if (NULL == elem->overlapped.hEvent) | 1373 | if (NULL == elem->overlapped.hEvent) |
1368 | return FALSE; | 1374 | return FALSE; |
1369 | 1375 | ||
@@ -1377,7 +1383,7 @@ initialize_io_facility (struct io_facility * elem, | |||
1377 | * @param tap_handle device handle for interacting with the Virtual interface | 1383 | * @param tap_handle device handle for interacting with the Virtual interface |
1378 | */ | 1384 | */ |
1379 | static void | 1385 | static void |
1380 | run (HANDLE tap_handle) | 1386 | run(HANDLE tap_handle) |
1381 | { | 1387 | { |
1382 | /* IO-Facility for reading from our virtual interface */ | 1388 | /* IO-Facility for reading from our virtual interface */ |
1383 | struct io_facility tap_read; | 1389 | struct io_facility tap_read; |
@@ -1388,8 +1394,8 @@ run (HANDLE tap_handle) | |||
1388 | /* IO-Facility for writing to stdout */ | 1394 | /* IO-Facility for writing to stdout */ |
1389 | struct io_facility std_out; | 1395 | struct io_facility std_out; |
1390 | 1396 | ||
1391 | HANDLE parent_std_in_handle = GetStdHandle (STD_INPUT_HANDLE); | 1397 | HANDLE parent_std_in_handle = GetStdHandle(STD_INPUT_HANDLE); |
1392 | HANDLE parent_std_out_handle = GetStdHandle (STD_OUTPUT_HANDLE); | 1398 | HANDLE parent_std_out_handle = GetStdHandle(STD_OUTPUT_HANDLE); |
1393 | 1399 | ||
1394 | /* tun up: */ | 1400 | /* tun up: */ |
1395 | /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn | 1401 | /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn |
@@ -1398,14 +1404,14 @@ run (HANDLE tap_handle) | |||
1398 | * DHCP and such are all features we will never use in gnunet afaik. | 1404 | * DHCP and such are all features we will never use in gnunet afaik. |
1399 | * But for openvpn those are essential. | 1405 | * But for openvpn those are essential. |
1400 | */ | 1406 | */ |
1401 | if ((privilege_testing) || (! tun_up (tap_handle) )) | 1407 | if ((privilege_testing) || (!tun_up(tap_handle))) |
1402 | goto teardown_final; | 1408 | goto teardown_final; |
1403 | 1409 | ||
1404 | /* Initialize our overlapped IO structures*/ | 1410 | /* Initialize our overlapped IO structures*/ |
1405 | if (! (initialize_io_facility (&tap_read, IOSTATE_READY, FALSE) | 1411 | if (!(initialize_io_facility(&tap_read, IOSTATE_READY, FALSE) |
1406 | && initialize_io_facility (&tap_write, IOSTATE_WAITING, TRUE) | 1412 | && initialize_io_facility(&tap_write, IOSTATE_WAITING, TRUE) |
1407 | && initialize_io_facility (&std_in, IOSTATE_READY, FALSE) | 1413 | && initialize_io_facility(&std_in, IOSTATE_READY, FALSE) |
1408 | && initialize_io_facility (&std_out, IOSTATE_WAITING, TRUE))) | 1414 | && initialize_io_facility(&std_out, IOSTATE_WAITING, TRUE))) |
1409 | goto teardown_final; | 1415 | goto teardown_final; |
1410 | 1416 | ||
1411 | /* Handles for STDIN and STDOUT */ | 1417 | /* Handles for STDIN and STDOUT */ |
@@ -1416,75 +1422,74 @@ run (HANDLE tap_handle) | |||
1416 | /* Debug output to console STDIN/STDOUT*/ | 1422 | /* Debug output to console STDIN/STDOUT*/ |
1417 | std_in.handle = parent_std_in_handle; | 1423 | std_in.handle = parent_std_in_handle; |
1418 | std_out.handle = parent_std_out_handle; | 1424 | std_out.handle = parent_std_out_handle; |
1419 | |||
1420 | #else | 1425 | #else |
1421 | fprintf (stderr, "DEBUG: reopening stdin/out for overlapped IO\n"); | 1426 | fprintf(stderr, "DEBUG: reopening stdin/out for overlapped IO\n"); |
1422 | /* | 1427 | /* |
1423 | * Find out the types of our handles. | 1428 | * Find out the types of our handles. |
1424 | * This part is a problem, because in windows we need to handle files, | 1429 | * This part is a problem, because in windows we need to handle files, |
1425 | * pipes and the console differently. | 1430 | * pipes and the console differently. |
1426 | */ | 1431 | */ |
1427 | if ((FILE_TYPE_PIPE != GetFileType (parent_std_in_handle)) || | 1432 | if ((FILE_TYPE_PIPE != GetFileType(parent_std_in_handle)) || |
1428 | (FILE_TYPE_PIPE != GetFileType (parent_std_out_handle))) | 1433 | (FILE_TYPE_PIPE != GetFileType(parent_std_out_handle))) |
1429 | { | 1434 | { |
1430 | fprintf (stderr, "ERROR: stdin/stdout must be named pipes\n"); | 1435 | fprintf(stderr, "ERROR: stdin/stdout must be named pipes\n"); |
1431 | goto teardown; | 1436 | goto teardown; |
1432 | } | 1437 | } |
1433 | 1438 | ||
1434 | std_in.handle = ReOpenFile (parent_std_in_handle, | 1439 | std_in.handle = ReOpenFile(parent_std_in_handle, |
1435 | GENERIC_READ, | 1440 | GENERIC_READ, |
1436 | FILE_SHARE_WRITE | FILE_SHARE_READ, | 1441 | FILE_SHARE_WRITE | FILE_SHARE_READ, |
1437 | FILE_FLAG_OVERLAPPED); | 1442 | FILE_FLAG_OVERLAPPED); |
1438 | 1443 | ||
1439 | if (INVALID_HANDLE_VALUE == std_in.handle) | 1444 | if (INVALID_HANDLE_VALUE == std_in.handle) |
1440 | { | 1445 | { |
1441 | fprintf (stderr, "FATAL: Could not reopen stdin for in overlapped mode, has to be a named pipe\n"); | 1446 | fprintf(stderr, "FATAL: Could not reopen stdin for in overlapped mode, has to be a named pipe\n"); |
1442 | goto teardown; | 1447 | goto teardown; |
1443 | } | 1448 | } |
1444 | 1449 | ||
1445 | std_out.handle = ReOpenFile (parent_std_out_handle, | 1450 | std_out.handle = ReOpenFile(parent_std_out_handle, |
1446 | GENERIC_WRITE, | 1451 | GENERIC_WRITE, |
1447 | FILE_SHARE_READ, | 1452 | FILE_SHARE_READ, |
1448 | FILE_FLAG_OVERLAPPED); | 1453 | FILE_FLAG_OVERLAPPED); |
1449 | 1454 | ||
1450 | if (INVALID_HANDLE_VALUE == std_out.handle) | 1455 | if (INVALID_HANDLE_VALUE == std_out.handle) |
1451 | { | 1456 | { |
1452 | fprintf (stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe\n"); | 1457 | fprintf(stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe\n"); |
1453 | goto teardown; | 1458 | goto teardown; |
1454 | } | 1459 | } |
1455 | #endif | 1460 | #endif |
1456 | 1461 | ||
1457 | fprintf (stderr, "DEBUG: mainloop has begun\n"); | 1462 | fprintf(stderr, "DEBUG: mainloop has begun\n"); |
1458 | 1463 | ||
1459 | while (std_out.path_open || tap_write.path_open) | 1464 | while (std_out.path_open || tap_write.path_open) |
1460 | { | 1465 | { |
1461 | /* perform READ from stdin if possible */ | 1466 | /* perform READ from stdin if possible */ |
1462 | if (std_in.path_open && (! attempt_read_stdin (&std_in, &tap_write))) | 1467 | if (std_in.path_open && (!attempt_read_stdin(&std_in, &tap_write))) |
1463 | break; | 1468 | break; |
1464 | 1469 | ||
1465 | /* perform READ from tap if possible */ | 1470 | /* perform READ from tap if possible */ |
1466 | if (tap_read.path_open && (! attempt_read_tap (&tap_read, &std_out))) | 1471 | if (tap_read.path_open && (!attempt_read_tap(&tap_read, &std_out))) |
1467 | break; | 1472 | break; |
1468 | 1473 | ||
1469 | /* perform WRITE to tap if possible */ | 1474 | /* perform WRITE to tap if possible */ |
1470 | if (tap_write.path_open && (! attempt_write (&tap_write, &std_in))) | 1475 | if (tap_write.path_open && (!attempt_write(&tap_write, &std_in))) |
1471 | break; | 1476 | break; |
1472 | 1477 | ||
1473 | /* perform WRITE to STDOUT if possible */ | 1478 | /* perform WRITE to STDOUT if possible */ |
1474 | if (std_out.path_open && (! attempt_write (&std_out, &tap_read))) | 1479 | if (std_out.path_open && (!attempt_write(&std_out, &tap_read))) |
1475 | break; | 1480 | break; |
1476 | } | 1481 | } |
1477 | fprintf (stderr, "DEBUG: teardown initiated\n"); | 1482 | fprintf(stderr, "DEBUG: teardown initiated\n"); |
1478 | 1483 | ||
1479 | teardown: | 1484 | teardown: |
1480 | 1485 | ||
1481 | CancelIo (tap_handle); | 1486 | CancelIo(tap_handle); |
1482 | CancelIo (std_in.handle); | 1487 | CancelIo(std_in.handle); |
1483 | CancelIo (std_out.handle); | 1488 | CancelIo(std_out.handle); |
1484 | 1489 | ||
1485 | teardown_final: | 1490 | teardown_final: |
1486 | 1491 | ||
1487 | CloseHandle (tap_handle); | 1492 | CloseHandle(tap_handle); |
1488 | } | 1493 | } |
1489 | 1494 | ||
1490 | 1495 | ||
@@ -1501,7 +1506,7 @@ teardown_final: | |||
1501 | * 6: IPv4 netmask ("255.255.0.0") [ignored if #4 is "-"] | 1506 | * 6: IPv4 netmask ("255.255.0.0") [ignored if #4 is "-"] |
1502 | */ | 1507 | */ |
1503 | int | 1508 | int |
1504 | main (int argc, char **argv) | 1509 | main(int argc, char **argv) |
1505 | { | 1510 | { |
1506 | char hwid[LINE_LEN]; | 1511 | char hwid[LINE_LEN]; |
1507 | HANDLE handle; | 1512 | HANDLE handle; |
@@ -1511,99 +1516,100 @@ main (int argc, char **argv) | |||
1511 | BOOL have_ip6 = FALSE; | 1516 | BOOL have_ip6 = FALSE; |
1512 | BOOL have_nat44 = FALSE; | 1517 | BOOL have_nat44 = FALSE; |
1513 | 1518 | ||
1514 | if ( (1 < argc) && (0 != strcmp (argv[1], "-d"))){ | 1519 | if ((1 < argc) && (0 != strcmp(argv[1], "-d"))) |
1520 | { | ||
1515 | privilege_testing = TRUE; | 1521 | privilege_testing = TRUE; |
1516 | fprintf (stderr, | 1522 | fprintf(stderr, |
1517 | "%s", | 1523 | "%s", |
1518 | "DEBUG: Running binary in privilege testing mode."); | 1524 | "DEBUG: Running binary in privilege testing mode."); |
1519 | argv++; | 1525 | argv++; |
1520 | argc--; | 1526 | argc--; |
1521 | } | 1527 | } |
1522 | 1528 | ||
1523 | if (6 != argc) | 1529 | if (6 != argc) |
1524 | { | 1530 | { |
1525 | fprintf (stderr, | 1531 | fprintf(stderr, |
1526 | "%s", | 1532 | "%s", |
1527 | "FATAL: must supply 6 arguments\nUsage:\ngnunet-helper-exit [-d] <if name prefix> <uplink-interface name> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n"); | 1533 | "FATAL: must supply 6 arguments\nUsage:\ngnunet-helper-exit [-d] <if name prefix> <uplink-interface name> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n"); |
1528 | return 1; | 1534 | return 1; |
1529 | } | 1535 | } |
1530 | 1536 | ||
1531 | GNUNET_strlcpy (hwid, argv[1], sizeof (hwid)); | 1537 | GNUNET_strlcpy(hwid, argv[1], sizeof(hwid)); |
1532 | 1538 | ||
1533 | /* | 1539 | /* |
1534 | * We use our PID for finding/resolving the control-panel name of our virtual | 1540 | * We use our PID for finding/resolving the control-panel name of our virtual |
1535 | * device. PIDs are (of course) unique at runtime, thus we can safely use it | 1541 | * device. PIDs are (of course) unique at runtime, thus we can safely use it |
1536 | * as additional hardware-id for our device. | 1542 | * as additional hardware-id for our device. |
1537 | */ | 1543 | */ |
1538 | snprintf (secondary_hwid, LINE_LEN / 2, "%s-%d", | 1544 | snprintf(secondary_hwid, LINE_LEN / 2, "%s-%d", |
1539 | hwid, | 1545 | hwid, |
1540 | _getpid ()); | 1546 | _getpid()); |
1541 | 1547 | ||
1542 | if (INVALID_HANDLE_VALUE == (handle = init_tun ())) | 1548 | if (INVALID_HANDLE_VALUE == (handle = init_tun())) |
1543 | { | 1549 | { |
1544 | fprintf (stderr, "FATAL: could not initialize virtual-interface %s with IPv6 %s/%s and IPv4 %s/%s\n", | 1550 | fprintf(stderr, "FATAL: could not initialize virtual-interface %s with IPv6 %s/%s and IPv4 %s/%s\n", |
1545 | hwid, | 1551 | hwid, |
1546 | argv[3], | 1552 | argv[3], |
1547 | argv[4], | 1553 | argv[4], |
1548 | argv[5], | 1554 | argv[5], |
1549 | argv[6]); | 1555 | argv[6]); |
1550 | global_ret = -1; | 1556 | global_ret = -1; |
1551 | goto cleanup; | 1557 | goto cleanup; |
1552 | } | 1558 | } |
1553 | 1559 | ||
1554 | fprintf (stderr, "DEBUG: Setting IPs, if needed\n"); | 1560 | fprintf(stderr, "DEBUG: Setting IPs, if needed\n"); |
1555 | if (0 != strcmp (argv[3], "-")) | 1561 | if (0 != strcmp(argv[3], "-")) |
1556 | { | 1562 | { |
1557 | char command[LINE_LEN]; | 1563 | char command[LINE_LEN]; |
1558 | const char *address = argv[3]; | 1564 | const char *address = argv[3]; |
1559 | long prefix_len = atol (argv[4]); | 1565 | long prefix_len = atol(argv[4]); |
1560 | 1566 | ||
1561 | if ((prefix_len < 1) || (prefix_len > 127)) | 1567 | if ((prefix_len < 1) || (prefix_len > 127)) |
1562 | { | 1568 | { |
1563 | fprintf (stderr, "FATAL: ipv6 prefix_len out of range\n"); | 1569 | fprintf(stderr, "FATAL: ipv6 prefix_len out of range\n"); |
1564 | global_ret = -1; | 1570 | global_ret = -1; |
1565 | goto cleanup; | 1571 | goto cleanup; |
1566 | } | 1572 | } |
1567 | 1573 | ||
1568 | fprintf (stderr, "DEBUG: Setting IP6 address: %s/%d\n", address, prefix_len); | 1574 | fprintf(stderr, "DEBUG: Setting IP6 address: %s/%d\n", address, prefix_len); |
1569 | if (0 != (global_ret = set_address6 (address, prefix_len))) | 1575 | if (0 != (global_ret = set_address6(address, prefix_len))) |
1570 | goto cleanup; | 1576 | goto cleanup; |
1571 | 1577 | ||
1572 | have_ip6 = TRUE; | 1578 | have_ip6 = TRUE; |
1573 | 1579 | ||
1574 | /* install our the windows NAT module*/ | 1580 | /* install our the windows NAT module*/ |
1575 | fprintf (stderr, "DEBUG: Setting IPv6 Forwarding for internal and external interface.\n"); | 1581 | fprintf(stderr, "DEBUG: Setting IPv6 Forwarding for internal and external interface.\n"); |
1576 | /* outside interface (maybe that's already set) */ | 1582 | /* outside interface (maybe that's already set) */ |
1577 | snprintf (command, LINE_LEN, | 1583 | snprintf(command, LINE_LEN, |
1578 | "netsh interface ipv6 set interface interface=\"%s\" metric=1 forwarding=enabled store=active", | 1584 | "netsh interface ipv6 set interface interface=\"%s\" metric=1 forwarding=enabled store=active", |
1579 | argv[2]); | 1585 | argv[2]); |
1580 | local_ret = execute_shellcommand (command); | 1586 | local_ret = execute_shellcommand(command); |
1581 | if (0 != local_ret) | 1587 | if (0 != local_ret) |
1582 | { | 1588 | { |
1583 | fprintf (stderr, "FATAL: Could not enable forwarding via netsh: %s\n", strerror (local_ret)); | 1589 | fprintf(stderr, "FATAL: Could not enable forwarding via netsh: %s\n", strerror(local_ret)); |
1584 | goto cleanup; | 1590 | goto cleanup; |
1585 | } | 1591 | } |
1586 | /* internal interface */ | 1592 | /* internal interface */ |
1587 | snprintf (command, LINE_LEN, | 1593 | snprintf(command, LINE_LEN, |
1588 | "netsh interface ipv6 set interface interface=\"%s\" metric=1 forwarding=enabled advertise=enabled store=active", | 1594 | "netsh interface ipv6 set interface interface=\"%s\" metric=1 forwarding=enabled advertise=enabled store=active", |
1589 | device_visible_name); | 1595 | device_visible_name); |
1590 | local_ret = execute_shellcommand (command); | 1596 | local_ret = execute_shellcommand(command); |
1591 | if (0 != local_ret) | 1597 | if (0 != local_ret) |
1592 | { | 1598 | { |
1593 | fprintf (stderr, "FATAL: Could not enable forwarding via netsh: %s\n", strerror (local_ret)); | 1599 | fprintf(stderr, "FATAL: Could not enable forwarding via netsh: %s\n", strerror(local_ret)); |
1594 | goto cleanup; | 1600 | goto cleanup; |
1595 | } | 1601 | } |
1596 | /* we can keep IPv6 forwarding around, as all interfaces have | 1602 | /* we can keep IPv6 forwarding around, as all interfaces have |
1597 | * their forwarding mode reset to false at bootup. */ | 1603 | * their forwarding mode reset to false at bootup. */ |
1598 | } | 1604 | } |
1599 | 1605 | ||
1600 | if (0 != strcmp (argv[5], "-")) | 1606 | if (0 != strcmp(argv[5], "-")) |
1601 | { | 1607 | { |
1602 | const char *address = argv[5]; | 1608 | const char *address = argv[5]; |
1603 | const char *mask = argv[6]; | 1609 | const char *mask = argv[6]; |
1604 | 1610 | ||
1605 | fprintf (stderr, "DEBUG: Setting IP4 address: %s/%s\n", address, mask); | 1611 | fprintf(stderr, "DEBUG: Setting IP4 address: %s/%s\n", address, mask); |
1606 | if (0 != (global_ret = set_address4 (address, mask))) | 1612 | if (0 != (global_ret = set_address4(address, mask))) |
1607 | goto cleanup; | 1613 | goto cleanup; |
1608 | 1614 | ||
1609 | // setup NAPT, if possible | 1615 | // setup NAPT, if possible |
@@ -1620,36 +1626,36 @@ main (int argc, char **argv) | |||
1620 | * ... | 1626 | * ... |
1621 | */ | 1627 | */ |
1622 | have_ip4 = TRUE; | 1628 | have_ip4 = TRUE; |
1623 | if (0 != strcmp (argv[2], "-")) | 1629 | if (0 != strcmp(argv[2], "-")) |
1624 | { | 1630 | { |
1625 | char command[LINE_LEN]; | 1631 | char command[LINE_LEN]; |
1626 | 1632 | ||
1627 | /* install our the windows NAT module*/ | 1633 | /* install our the windows NAT module*/ |
1628 | fprintf (stderr, "DEBUG: Adding NAPT/Masquerading between external IF %s and mine.\n", argv[2]); | 1634 | fprintf(stderr, "DEBUG: Adding NAPT/Masquerading between external IF %s and mine.\n", argv[2]); |
1629 | local_ret = execute_shellcommand ("netsh routing ip nat install"); | 1635 | local_ret = execute_shellcommand("netsh routing ip nat install"); |
1630 | if (0 != local_ret) | 1636 | if (0 != local_ret) |
1631 | { | 1637 | { |
1632 | fprintf (stderr, "FATAL: Could not install NAPT support via Netsh: %s\n", strerror (local_ret)); | 1638 | fprintf(stderr, "FATAL: Could not install NAPT support via Netsh: %s\n", strerror(local_ret)); |
1633 | goto cleanup; | 1639 | goto cleanup; |
1634 | } | 1640 | } |
1635 | /* external IF */ | 1641 | /* external IF */ |
1636 | snprintf (command, LINE_LEN, | 1642 | snprintf(command, LINE_LEN, |
1637 | "netsh routing ip nat add interface \"%s\" full", /*full = NAPT (addr+port)*/ | 1643 | "netsh routing ip nat add interface \"%s\" full", /*full = NAPT (addr+port)*/ |
1638 | argv[2]); | 1644 | argv[2]); |
1639 | local_ret = execute_shellcommand (command); | 1645 | local_ret = execute_shellcommand(command); |
1640 | if (0 != local_ret) | 1646 | if (0 != local_ret) |
1641 | { | 1647 | { |
1642 | fprintf (stderr, "FATAL: IPv4-NAPT on external interface failed: %s\n", strerror (local_ret)); | 1648 | fprintf(stderr, "FATAL: IPv4-NAPT on external interface failed: %s\n", strerror(local_ret)); |
1643 | goto cleanup; | 1649 | goto cleanup; |
1644 | } | 1650 | } |
1645 | /* private/internal/virtual IF */ | 1651 | /* private/internal/virtual IF */ |
1646 | snprintf (command, LINE_LEN, | 1652 | snprintf(command, LINE_LEN, |
1647 | "netsh routing ip nat add interface \"%s\" private", | 1653 | "netsh routing ip nat add interface \"%s\" private", |
1648 | device_visible_name); | 1654 | device_visible_name); |
1649 | local_ret = execute_shellcommand (command); | 1655 | local_ret = execute_shellcommand(command); |
1650 | if (0 != local_ret) | 1656 | if (0 != local_ret) |
1651 | { | 1657 | { |
1652 | fprintf (stderr, "FATAL: IPv4-NAPT on internal interface failed: %s\n", strerror (local_ret)); | 1658 | fprintf(stderr, "FATAL: IPv4-NAPT on internal interface failed: %s\n", strerror(local_ret)); |
1653 | goto cleanup; | 1659 | goto cleanup; |
1654 | 1660 | ||
1655 | have_nat44 = TRUE; | 1661 | have_nat44 = TRUE; |
@@ -1657,12 +1663,14 @@ main (int argc, char **argv) | |||
1657 | } | 1663 | } |
1658 | } | 1664 | } |
1659 | 1665 | ||
1660 | run (handle); | 1666 | run(handle); |
1661 | cleanup: | 1667 | cleanup: |
1662 | 1668 | ||
1663 | if (have_ip4) { | 1669 | if (have_ip4) |
1670 | { | ||
1664 | const char *address = argv[5]; | 1671 | const char *address = argv[5]; |
1665 | if (have_nat44) { | 1672 | if (have_nat44) |
1673 | { | ||
1666 | char command[LINE_LEN]; | 1674 | char command[LINE_LEN]; |
1667 | fprintf(stderr, "DEBUG: removing IP4 NAPT from virtual interface \n"); | 1675 | fprintf(stderr, "DEBUG: removing IP4 NAPT from virtual interface \n"); |
1668 | snprintf(command, LINE_LEN, | 1676 | snprintf(command, LINE_LEN, |
@@ -1670,22 +1678,22 @@ cleanup: | |||
1670 | device_visible_name); | 1678 | device_visible_name); |
1671 | local_ret = execute_shellcommand(command); | 1679 | local_ret = execute_shellcommand(command); |
1672 | if (0 != local_ret) | 1680 | if (0 != local_ret) |
1673 | fprintf(stderr, "WARNING: Could not remove IPv4-NAPT from internal interface, hopefully this will have no effect in future runs: %s\n", strerror(local_ret)); | 1681 | fprintf(stderr, "WARNING: Could not remove IPv4-NAPT from internal interface, hopefully this will have no effect in future runs: %s\n", strerror(local_ret)); |
1674 | } | 1682 | } |
1675 | 1683 | ||
1676 | fprintf(stderr, "DEBUG: Removing IP4 address\n"); | 1684 | fprintf(stderr, "DEBUG: Removing IP4 address\n"); |
1677 | remove_address4 (address); | 1685 | remove_address4(address); |
1678 | } | 1686 | } |
1679 | if (have_ip6) | 1687 | if (have_ip6) |
1680 | { | 1688 | { |
1681 | const char *address = argv[3]; | 1689 | const char *address = argv[3]; |
1682 | fprintf (stderr, "DEBUG: Removing IP6 address\n"); | 1690 | fprintf(stderr, "DEBUG: Removing IP6 address\n"); |
1683 | remove_address6 (address); | 1691 | remove_address6(address); |
1684 | } | 1692 | } |
1685 | 1693 | ||
1686 | fprintf (stderr, "DEBUG: removing interface\n"); | 1694 | fprintf(stderr, "DEBUG: removing interface\n"); |
1687 | remove_interface (); | 1695 | remove_interface(); |
1688 | fprintf (stderr, "DEBUG: graceful exit completed\n"); | 1696 | fprintf(stderr, "DEBUG: graceful exit completed\n"); |
1689 | 1697 | ||
1690 | return global_ret; | 1698 | return global_ret; |
1691 | } | 1699 | } |
diff --git a/src/exit/gnunet-helper-exit.c b/src/exit/gnunet-helper-exit.c index cda38710f..297a17813 100644 --- a/src/exit/gnunet-helper-exit.c +++ b/src/exit/gnunet-helper-exit.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file exit/gnunet-helper-exit.c | 22 | * @file exit/gnunet-helper-exit.c |
@@ -81,8 +81,7 @@ static const char *sbin_iptables; | |||
81 | /** | 81 | /** |
82 | * This is in linux/include/net/ipv6.h, but not always exported... | 82 | * This is in linux/include/net/ipv6.h, but not always exported... |
83 | */ | 83 | */ |
84 | struct in6_ifreq | 84 | struct in6_ifreq { |
85 | { | ||
86 | struct in6_addr ifr6_addr; | 85 | struct in6_addr ifr6_addr; |
87 | uint32_t ifr6_prefixlen; /* __u32 in the original */ | 86 | uint32_t ifr6_prefixlen; /* __u32 in the original */ |
88 | int ifr6_ifindex; | 87 | int ifr6_ifindex; |
@@ -98,22 +97,22 @@ struct in6_ifreq | |||
98 | * @param flags open flags (O_RDONLY, O_WRONLY) | 97 | * @param flags open flags (O_RDONLY, O_WRONLY) |
99 | */ | 98 | */ |
100 | static void | 99 | static void |
101 | open_dev_null (int target_fd, | 100 | open_dev_null(int target_fd, |
102 | int flags) | 101 | int flags) |
103 | { | 102 | { |
104 | int fd; | 103 | int fd; |
105 | 104 | ||
106 | fd = open ("/dev/null", flags); | 105 | fd = open("/dev/null", flags); |
107 | if (-1 == fd) | 106 | if (-1 == fd) |
108 | abort (); | 107 | abort(); |
109 | if (fd == target_fd) | 108 | if (fd == target_fd) |
110 | return; | 109 | return; |
111 | if (-1 == dup2 (fd, target_fd)) | 110 | if (-1 == dup2(fd, target_fd)) |
112 | { | 111 | { |
113 | (void) close (fd); | 112 | (void)close(fd); |
114 | abort (); | 113 | abort(); |
115 | } | 114 | } |
116 | (void) close (fd); | 115 | (void)close(fd); |
117 | } | 116 | } |
118 | 117 | ||
119 | 118 | ||
@@ -125,49 +124,50 @@ open_dev_null (int target_fd, | |||
125 | * @return 0 on success, 1 on any error | 124 | * @return 0 on success, 1 on any error |
126 | */ | 125 | */ |
127 | static int | 126 | static int |
128 | fork_and_exec (const char *file, | 127 | fork_and_exec(const char *file, |
129 | char *const cmd[]) | 128 | char *const cmd[]) |
130 | { | 129 | { |
131 | int status; | 130 | int status; |
132 | pid_t pid; | 131 | pid_t pid; |
133 | pid_t ret; | 132 | pid_t ret; |
134 | 133 | ||
135 | pid = fork (); | 134 | pid = fork(); |
136 | if (-1 == pid) | 135 | if (-1 == pid) |
137 | { | 136 | { |
138 | fprintf (stderr, | 137 | fprintf(stderr, |
139 | "fork failed: %s\n", | 138 | "fork failed: %s\n", |
140 | strerror (errno)); | 139 | strerror(errno)); |
141 | return 1; | 140 | return 1; |
142 | } | 141 | } |
143 | if (0 == pid) | 142 | if (0 == pid) |
144 | { | 143 | { |
145 | /* we are the child process */ | 144 | /* we are the child process */ |
146 | /* close stdin/stdout to not cause interference | 145 | /* close stdin/stdout to not cause interference |
147 | with the helper's main protocol! */ | 146 | with the helper's main protocol! */ |
148 | (void) close (0); | 147 | (void)close(0); |
149 | open_dev_null (0, O_RDONLY); | 148 | open_dev_null(0, O_RDONLY); |
150 | (void) close (1); | 149 | (void)close(1); |
151 | open_dev_null (1, O_WRONLY); | 150 | open_dev_null(1, O_WRONLY); |
152 | (void) execv (file, cmd); | 151 | (void)execv(file, cmd); |
153 | /* can only get here on error */ | 152 | /* can only get here on error */ |
154 | fprintf (stderr, | 153 | fprintf(stderr, |
155 | "exec `%s' failed: %s\n", | 154 | "exec `%s' failed: %s\n", |
156 | file, | 155 | file, |
157 | strerror (errno)); | 156 | strerror(errno)); |
158 | _exit (1); | 157 | _exit(1); |
159 | } | 158 | } |
160 | /* keep running waitpid as long as the only error we get is 'EINTR' */ | 159 | /* keep running waitpid as long as the only error we get is 'EINTR' */ |
161 | while ( (-1 == (ret = waitpid (pid, &status, 0))) && | 160 | while ((-1 == (ret = waitpid(pid, &status, 0))) && |
162 | (errno == EINTR) ); | 161 | (errno == EINTR)) |
162 | ; | ||
163 | if (-1 == ret) | 163 | if (-1 == ret) |
164 | { | 164 | { |
165 | fprintf (stderr, | 165 | fprintf(stderr, |
166 | "waitpid failed: %s\n", | 166 | "waitpid failed: %s\n", |
167 | strerror (errno)); | 167 | strerror(errno)); |
168 | return 1; | 168 | return 1; |
169 | } | 169 | } |
170 | if (! (WIFEXITED (status) && (0 == WEXITSTATUS (status)))) | 170 | if (!(WIFEXITED(status) && (0 == WEXITSTATUS(status)))) |
171 | return 1; | 171 | return 1; |
172 | /* child process completed and returned success, we're happy */ | 172 | /* child process completed and returned success, we're happy */ |
173 | return 0; | 173 | return 0; |
@@ -182,46 +182,46 @@ fork_and_exec (const char *file, | |||
182 | * @return the fd to the tun or -1 on error | 182 | * @return the fd to the tun or -1 on error |
183 | */ | 183 | */ |
184 | static int | 184 | static int |
185 | init_tun (char *dev) | 185 | init_tun(char *dev) |
186 | { | 186 | { |
187 | struct ifreq ifr; | 187 | struct ifreq ifr; |
188 | int fd; | 188 | int fd; |
189 | 189 | ||
190 | if (NULL == dev) | 190 | if (NULL == dev) |
191 | { | 191 | { |
192 | errno = EINVAL; | 192 | errno = EINVAL; |
193 | return -1; | 193 | return -1; |
194 | } | 194 | } |
195 | 195 | ||
196 | if (-1 == (fd = open ("/dev/net/tun", O_RDWR))) | 196 | if (-1 == (fd = open("/dev/net/tun", O_RDWR))) |
197 | { | 197 | { |
198 | fprintf (stderr, "Error opening `%s': %s\n", "/dev/net/tun", | 198 | fprintf(stderr, "Error opening `%s': %s\n", "/dev/net/tun", |
199 | strerror (errno)); | 199 | strerror(errno)); |
200 | return -1; | 200 | return -1; |
201 | } | 201 | } |
202 | 202 | ||
203 | if (fd >= FD_SETSIZE) | 203 | if (fd >= FD_SETSIZE) |
204 | { | 204 | { |
205 | fprintf (stderr, "File descriptor to large: %d", fd); | 205 | fprintf(stderr, "File descriptor to large: %d", fd); |
206 | (void) close (fd); | 206 | (void)close(fd); |
207 | return -1; | 207 | return -1; |
208 | } | 208 | } |
209 | 209 | ||
210 | memset (&ifr, 0, sizeof (ifr)); | 210 | memset(&ifr, 0, sizeof(ifr)); |
211 | ifr.ifr_flags = IFF_TUN; | 211 | ifr.ifr_flags = IFF_TUN; |
212 | 212 | ||
213 | if ('\0' != *dev) | 213 | if ('\0' != *dev) |
214 | strncpy (ifr.ifr_name, dev, IFNAMSIZ); | 214 | strncpy(ifr.ifr_name, dev, IFNAMSIZ); |
215 | 215 | ||
216 | if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr)) | 216 | if (-1 == ioctl(fd, TUNSETIFF, (void *)&ifr)) |
217 | { | 217 | { |
218 | fprintf (stderr, | 218 | fprintf(stderr, |
219 | "Error with ioctl on `%s': %s\n", "/dev/net/tun", | 219 | "Error with ioctl on `%s': %s\n", "/dev/net/tun", |
220 | strerror (errno)); | 220 | strerror(errno)); |
221 | (void) close (fd); | 221 | (void)close(fd); |
222 | return -1; | 222 | return -1; |
223 | } | 223 | } |
224 | strcpy (dev, ifr.ifr_name); | 224 | strcpy(dev, ifr.ifr_name); |
225 | return fd; | 225 | return fd; |
226 | } | 226 | } |
227 | 227 | ||
@@ -234,7 +234,7 @@ init_tun (char *dev) | |||
234 | * @param prefix_len the length of the network-prefix | 234 | * @param prefix_len the length of the network-prefix |
235 | */ | 235 | */ |
236 | static void | 236 | static void |
237 | set_address6 (const char *dev, const char *address, unsigned long prefix_len) | 237 | set_address6(const char *dev, const char *address, unsigned long prefix_len) |
238 | { | 238 | { |
239 | struct ifreq ifr; | 239 | struct ifreq ifr; |
240 | struct sockaddr_in6 sa6; | 240 | struct sockaddr_in6 sa6; |
@@ -244,34 +244,34 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len) | |||
244 | /* | 244 | /* |
245 | * parse the new address | 245 | * parse the new address |
246 | */ | 246 | */ |
247 | memset (&sa6, 0, sizeof (struct sockaddr_in6)); | 247 | memset(&sa6, 0, sizeof(struct sockaddr_in6)); |
248 | sa6.sin6_family = AF_INET6; | 248 | sa6.sin6_family = AF_INET6; |
249 | if (1 != inet_pton (AF_INET6, address, &sa6.sin6_addr)) | 249 | if (1 != inet_pton(AF_INET6, address, &sa6.sin6_addr)) |
250 | { | 250 | { |
251 | fprintf (stderr, "Failed to parse address `%s': %s\n", address, | 251 | fprintf(stderr, "Failed to parse address `%s': %s\n", address, |
252 | strerror (errno)); | 252 | strerror(errno)); |
253 | exit (1); | 253 | exit(1); |
254 | } | 254 | } |
255 | 255 | ||
256 | if (-1 == (fd = socket (PF_INET6, SOCK_DGRAM, 0))) | 256 | if (-1 == (fd = socket(PF_INET6, SOCK_DGRAM, 0))) |
257 | { | 257 | { |
258 | fprintf (stderr, "Error creating socket: %s\n", strerror (errno)); | 258 | fprintf(stderr, "Error creating socket: %s\n", strerror(errno)); |
259 | exit (1); | 259 | exit(1); |
260 | } | 260 | } |
261 | 261 | ||
262 | memset (&ifr, 0, sizeof (struct ifreq)); | 262 | memset(&ifr, 0, sizeof(struct ifreq)); |
263 | /* | 263 | /* |
264 | * Get the index of the if | 264 | * Get the index of the if |
265 | */ | 265 | */ |
266 | strncpy (ifr.ifr_name, dev, IFNAMSIZ); | 266 | strncpy(ifr.ifr_name, dev, IFNAMSIZ); |
267 | if (-1 == ioctl (fd, SIOGIFINDEX, &ifr)) | 267 | if (-1 == ioctl(fd, SIOGIFINDEX, &ifr)) |
268 | { | 268 | { |
269 | fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno)); | 269 | fprintf(stderr, "ioctl failed at %d: %s\n", __LINE__, strerror(errno)); |
270 | (void) close (fd); | 270 | (void)close(fd); |
271 | exit (1); | 271 | exit(1); |
272 | } | 272 | } |
273 | 273 | ||
274 | memset (&ifr6, 0, sizeof (struct in6_ifreq)); | 274 | memset(&ifr6, 0, sizeof(struct in6_ifreq)); |
275 | ifr6.ifr6_addr = sa6.sin6_addr; | 275 | ifr6.ifr6_addr = sa6.sin6_addr; |
276 | ifr6.ifr6_ifindex = ifr.ifr_ifindex; | 276 | ifr6.ifr6_ifindex = ifr.ifr_ifindex; |
277 | ifr6.ifr6_prefixlen = prefix_len; | 277 | ifr6.ifr6_prefixlen = prefix_len; |
@@ -279,42 +279,42 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len) | |||
279 | /* | 279 | /* |
280 | * Set the address | 280 | * Set the address |
281 | */ | 281 | */ |
282 | if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6)) | 282 | if (-1 == ioctl(fd, SIOCSIFADDR, &ifr6)) |
283 | { | 283 | { |
284 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, | 284 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, |
285 | strerror (errno)); | 285 | strerror(errno)); |
286 | (void) close (fd); | 286 | (void)close(fd); |
287 | exit (1); | 287 | exit(1); |
288 | } | 288 | } |
289 | 289 | ||
290 | /* | 290 | /* |
291 | * Get the flags | 291 | * Get the flags |
292 | */ | 292 | */ |
293 | if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) | 293 | if (-1 == ioctl(fd, SIOCGIFFLAGS, &ifr)) |
294 | { | 294 | { |
295 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, | 295 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, |
296 | strerror (errno)); | 296 | strerror(errno)); |
297 | (void) close (fd); | 297 | (void)close(fd); |
298 | exit (1); | 298 | exit(1); |
299 | } | 299 | } |
300 | 300 | ||
301 | /* | 301 | /* |
302 | * Add the UP and RUNNING flags | 302 | * Add the UP and RUNNING flags |
303 | */ | 303 | */ |
304 | ifr.ifr_flags |= IFF_UP | IFF_RUNNING; | 304 | ifr.ifr_flags |= IFF_UP | IFF_RUNNING; |
305 | if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) | 305 | if (-1 == ioctl(fd, SIOCSIFFLAGS, &ifr)) |
306 | { | 306 | { |
307 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, | 307 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, |
308 | strerror (errno)); | 308 | strerror(errno)); |
309 | (void) close (fd); | 309 | (void)close(fd); |
310 | exit (1); | 310 | exit(1); |
311 | } | 311 | } |
312 | 312 | ||
313 | if (0 != close (fd)) | 313 | if (0 != close(fd)) |
314 | { | 314 | { |
315 | fprintf (stderr, "close failed: %s\n", strerror (errno)); | 315 | fprintf(stderr, "close failed: %s\n", strerror(errno)); |
316 | exit (1); | 316 | exit(1); |
317 | } | 317 | } |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
@@ -326,96 +326,96 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len) | |||
326 | * @param mask the netmask | 326 | * @param mask the netmask |
327 | */ | 327 | */ |
328 | static void | 328 | static void |
329 | set_address4 (const char *dev, const char *address, const char *mask) | 329 | set_address4(const char *dev, const char *address, const char *mask) |
330 | { | 330 | { |
331 | int fd; | 331 | int fd; |
332 | struct sockaddr_in *addr; | 332 | struct sockaddr_in *addr; |
333 | struct ifreq ifr; | 333 | struct ifreq ifr; |
334 | 334 | ||
335 | memset (&ifr, 0, sizeof (struct ifreq)); | 335 | memset(&ifr, 0, sizeof(struct ifreq)); |
336 | addr = (struct sockaddr_in *) &(ifr.ifr_addr); | 336 | addr = (struct sockaddr_in *)&(ifr.ifr_addr); |
337 | addr->sin_family = AF_INET; | 337 | addr->sin_family = AF_INET; |
338 | 338 | ||
339 | /* | 339 | /* |
340 | * Parse the address | 340 | * Parse the address |
341 | */ | 341 | */ |
342 | if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr)) | 342 | if (1 != inet_pton(AF_INET, address, &addr->sin_addr.s_addr)) |
343 | { | 343 | { |
344 | fprintf (stderr, "Failed to parse address `%s': %s\n", address, | 344 | fprintf(stderr, "Failed to parse address `%s': %s\n", address, |
345 | strerror (errno)); | 345 | strerror(errno)); |
346 | exit (1); | 346 | exit(1); |
347 | } | 347 | } |
348 | 348 | ||
349 | if (-1 == (fd = socket (PF_INET, SOCK_DGRAM, 0))) | 349 | if (-1 == (fd = socket(PF_INET, SOCK_DGRAM, 0))) |
350 | { | 350 | { |
351 | fprintf (stderr, "Error creating socket: %s\n", strerror (errno)); | 351 | fprintf(stderr, "Error creating socket: %s\n", strerror(errno)); |
352 | exit (1); | 352 | exit(1); |
353 | } | 353 | } |
354 | 354 | ||
355 | strncpy (ifr.ifr_name, dev, IFNAMSIZ); | 355 | strncpy(ifr.ifr_name, dev, IFNAMSIZ); |
356 | 356 | ||
357 | /* | 357 | /* |
358 | * Set the address | 358 | * Set the address |
359 | */ | 359 | */ |
360 | if (-1 == ioctl (fd, SIOCSIFADDR, &ifr)) | 360 | if (-1 == ioctl(fd, SIOCSIFADDR, &ifr)) |
361 | { | 361 | { |
362 | fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno)); | 362 | fprintf(stderr, "ioctl failed at %d: %s\n", __LINE__, strerror(errno)); |
363 | (void) close (fd); | 363 | (void)close(fd); |
364 | exit (1); | 364 | exit(1); |
365 | } | 365 | } |
366 | 366 | ||
367 | /* | 367 | /* |
368 | * Parse the netmask | 368 | * Parse the netmask |
369 | */ | 369 | */ |
370 | addr = (struct sockaddr_in *) &(ifr.ifr_netmask); | 370 | addr = (struct sockaddr_in *)&(ifr.ifr_netmask); |
371 | if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr)) | 371 | if (1 != inet_pton(AF_INET, mask, &addr->sin_addr.s_addr)) |
372 | { | 372 | { |
373 | fprintf (stderr, "Failed to parse address `%s': %s\n", mask, | 373 | fprintf(stderr, "Failed to parse address `%s': %s\n", mask, |
374 | strerror (errno)); | 374 | strerror(errno)); |
375 | (void) close (fd); | 375 | (void)close(fd); |
376 | exit (1); | 376 | exit(1); |
377 | } | 377 | } |
378 | 378 | ||
379 | /* | 379 | /* |
380 | * Set the netmask | 380 | * Set the netmask |
381 | */ | 381 | */ |
382 | if (-1 == ioctl (fd, SIOCSIFNETMASK, &ifr)) | 382 | if (-1 == ioctl(fd, SIOCSIFNETMASK, &ifr)) |
383 | { | 383 | { |
384 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, | 384 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, |
385 | strerror (errno)); | 385 | strerror(errno)); |
386 | (void) close (fd); | 386 | (void)close(fd); |
387 | exit (1); | 387 | exit(1); |
388 | } | 388 | } |
389 | 389 | ||
390 | /* | 390 | /* |
391 | * Get the flags | 391 | * Get the flags |
392 | */ | 392 | */ |
393 | if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) | 393 | if (-1 == ioctl(fd, SIOCGIFFLAGS, &ifr)) |
394 | { | 394 | { |
395 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, | 395 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, |
396 | strerror (errno)); | 396 | strerror(errno)); |
397 | (void) close (fd); | 397 | (void)close(fd); |
398 | exit (1); | 398 | exit(1); |
399 | } | 399 | } |
400 | 400 | ||
401 | /* | 401 | /* |
402 | * Add the UP and RUNNING flags | 402 | * Add the UP and RUNNING flags |
403 | */ | 403 | */ |
404 | ifr.ifr_flags |= IFF_UP | IFF_RUNNING; | 404 | ifr.ifr_flags |= IFF_UP | IFF_RUNNING; |
405 | if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) | 405 | if (-1 == ioctl(fd, SIOCSIFFLAGS, &ifr)) |
406 | { | 406 | { |
407 | fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__, | 407 | fprintf(stderr, "ioctl failed at line %d: %s\n", __LINE__, |
408 | strerror (errno)); | 408 | strerror(errno)); |
409 | (void) close (fd); | 409 | (void)close(fd); |
410 | exit (1); | 410 | exit(1); |
411 | } | 411 | } |
412 | 412 | ||
413 | if (0 != close (fd)) | 413 | if (0 != close(fd)) |
414 | { | 414 | { |
415 | fprintf (stderr, "close failed: %s\n", strerror (errno)); | 415 | fprintf(stderr, "close failed: %s\n", strerror(errno)); |
416 | (void) close (fd); | 416 | (void)close(fd); |
417 | exit (1); | 417 | exit(1); |
418 | } | 418 | } |
419 | } | 419 | } |
420 | 420 | ||
421 | 421 | ||
@@ -425,7 +425,7 @@ set_address4 (const char *dev, const char *address, const char *mask) | |||
425 | * @param fd_tun tunnel FD | 425 | * @param fd_tun tunnel FD |
426 | */ | 426 | */ |
427 | static void | 427 | static void |
428 | run (int fd_tun) | 428 | run(int fd_tun) |
429 | { | 429 | { |
430 | /* | 430 | /* |
431 | * The buffer filled by reading from fd_tun | 431 | * The buffer filled by reading from fd_tun |
@@ -452,188 +452,188 @@ run (int fd_tun) | |||
452 | int write_open = 1; | 452 | int write_open = 1; |
453 | 453 | ||
454 | while ((1 == read_open) && (1 == write_open)) | 454 | while ((1 == read_open) && (1 == write_open)) |
455 | { | 455 | { |
456 | FD_ZERO (&fds_w); | 456 | FD_ZERO(&fds_w); |
457 | FD_ZERO (&fds_r); | 457 | FD_ZERO(&fds_r); |
458 | 458 | ||
459 | /* | 459 | /* |
460 | * We are supposed to read and the buffer is empty | 460 | * We are supposed to read and the buffer is empty |
461 | * -> select on read from tun | 461 | * -> select on read from tun |
462 | */ | 462 | */ |
463 | if (read_open && (0 == buftun_size)) | 463 | if (read_open && (0 == buftun_size)) |
464 | FD_SET (fd_tun, &fds_r); | 464 | FD_SET(fd_tun, &fds_r); |
465 | 465 | ||
466 | /* | 466 | /* |
467 | * We are supposed to read and the buffer is not empty | 467 | * We are supposed to read and the buffer is not empty |
468 | * -> select on write to stdout | 468 | * -> select on write to stdout |
469 | */ | 469 | */ |
470 | if (read_open && (0 != buftun_size)) | 470 | if (read_open && (0 != buftun_size)) |
471 | FD_SET (1, &fds_w); | 471 | FD_SET(1, &fds_w); |
472 | 472 | ||
473 | /* | 473 | /* |
474 | * We are supposed to write and the buffer is empty | 474 | * We are supposed to write and the buffer is empty |
475 | * -> select on read from stdin | 475 | * -> select on read from stdin |
476 | */ | 476 | */ |
477 | if (write_open && (NULL == bufin_read)) | 477 | if (write_open && (NULL == bufin_read)) |
478 | FD_SET (0, &fds_r); | 478 | FD_SET(0, &fds_r); |
479 | 479 | ||
480 | /* | 480 | /* |
481 | * We are supposed to write and the buffer is not empty | 481 | * We are supposed to write and the buffer is not empty |
482 | * -> select on write to tun | 482 | * -> select on write to tun |
483 | */ | 483 | */ |
484 | if (write_open && (NULL != bufin_read)) | 484 | if (write_open && (NULL != bufin_read)) |
485 | FD_SET (fd_tun, &fds_w); | 485 | FD_SET(fd_tun, &fds_w); |
486 | 486 | ||
487 | int r = select (fd_tun + 1, &fds_r, &fds_w, NULL, NULL); | 487 | int r = select(fd_tun + 1, &fds_r, &fds_w, NULL, NULL); |
488 | 488 | ||
489 | if (-1 == r) | 489 | if (-1 == r) |
490 | { | ||
491 | if (EINTR == errno) | ||
492 | continue; | ||
493 | fprintf (stderr, "select failed: %s\n", strerror (errno)); | ||
494 | exit (1); | ||
495 | } | ||
496 | |||
497 | if (r > 0) | ||
498 | { | ||
499 | if (FD_ISSET (fd_tun, &fds_r)) | ||
500 | { | ||
501 | buftun_size = | ||
502 | read (fd_tun, buftun + sizeof (struct GNUNET_MessageHeader), | ||
503 | MAX_SIZE - sizeof (struct GNUNET_MessageHeader)); | ||
504 | if (-1 == buftun_size) | ||
505 | { | 490 | { |
506 | fprintf (stderr, | 491 | if (EINTR == errno) |
507 | "read-error: %s\n", | 492 | continue; |
508 | strerror (errno)); | 493 | fprintf(stderr, "select failed: %s\n", strerror(errno)); |
509 | shutdown (fd_tun, SHUT_RD); | 494 | exit(1); |
510 | shutdown (1, SHUT_WR); | ||
511 | read_open = 0; | ||
512 | buftun_size = 0; | ||
513 | } | 495 | } |
514 | else if (0 == buftun_size) | 496 | |
497 | if (r > 0) | ||
515 | { | 498 | { |
499 | if (FD_ISSET(fd_tun, &fds_r)) | ||
500 | { | ||
501 | buftun_size = | ||
502 | read(fd_tun, buftun + sizeof(struct GNUNET_MessageHeader), | ||
503 | MAX_SIZE - sizeof(struct GNUNET_MessageHeader)); | ||
504 | if (-1 == buftun_size) | ||
505 | { | ||
506 | fprintf(stderr, | ||
507 | "read-error: %s\n", | ||
508 | strerror(errno)); | ||
509 | shutdown(fd_tun, SHUT_RD); | ||
510 | shutdown(1, SHUT_WR); | ||
511 | read_open = 0; | ||
512 | buftun_size = 0; | ||
513 | } | ||
514 | else if (0 == buftun_size) | ||
515 | { | ||
516 | #if DEBUG | 516 | #if DEBUG |
517 | fprintf (stderr, "EOF on tun\n"); | 517 | fprintf(stderr, "EOF on tun\n"); |
518 | #endif | 518 | #endif |
519 | shutdown (fd_tun, SHUT_RD); | 519 | shutdown(fd_tun, SHUT_RD); |
520 | shutdown (1, SHUT_WR); | 520 | shutdown(1, SHUT_WR); |
521 | read_open = 0; | 521 | read_open = 0; |
522 | buftun_size = 0; | 522 | buftun_size = 0; |
523 | } | 523 | } |
524 | else | 524 | else |
525 | { | 525 | { |
526 | buftun_read = buftun; | 526 | buftun_read = buftun; |
527 | struct GNUNET_MessageHeader *hdr = | 527 | struct GNUNET_MessageHeader *hdr = |
528 | (struct GNUNET_MessageHeader *) buftun; | 528 | (struct GNUNET_MessageHeader *)buftun; |
529 | buftun_size += sizeof (struct GNUNET_MessageHeader); | 529 | buftun_size += sizeof(struct GNUNET_MessageHeader); |
530 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 530 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); |
531 | hdr->size = htons (buftun_size); | 531 | hdr->size = htons(buftun_size); |
532 | } | 532 | } |
533 | } | 533 | } |
534 | else if (FD_ISSET (1, &fds_w)) | 534 | else if (FD_ISSET(1, &fds_w)) |
535 | { | 535 | { |
536 | ssize_t written = write (1, buftun_read, buftun_size); | 536 | ssize_t written = write(1, buftun_read, buftun_size); |
537 | 537 | ||
538 | if (-1 == written) | 538 | if (-1 == written) |
539 | { | 539 | { |
540 | #if !DEBUG | 540 | #if !DEBUG |
541 | if (errno != EPIPE) | 541 | if (errno != EPIPE) |
542 | #endif | 542 | #endif |
543 | fprintf (stderr, | 543 | fprintf(stderr, |
544 | "write-error to stdout: %s\n", | 544 | "write-error to stdout: %s\n", |
545 | strerror (errno)); | 545 | strerror(errno)); |
546 | shutdown (fd_tun, SHUT_RD); | 546 | shutdown(fd_tun, SHUT_RD); |
547 | shutdown (1, SHUT_WR); | 547 | shutdown(1, SHUT_WR); |
548 | read_open = 0; | 548 | read_open = 0; |
549 | buftun_size = 0; | 549 | buftun_size = 0; |
550 | } | 550 | } |
551 | else if (0 == written) | 551 | else if (0 == written) |
552 | { | 552 | { |
553 | fprintf (stderr, "write returned 0!?\n"); | 553 | fprintf(stderr, "write returned 0!?\n"); |
554 | exit (1); | 554 | exit(1); |
555 | } | 555 | } |
556 | else | 556 | else |
557 | { | 557 | { |
558 | buftun_size -= written; | 558 | buftun_size -= written; |
559 | buftun_read += written; | 559 | buftun_read += written; |
560 | } | 560 | } |
561 | } | 561 | } |
562 | 562 | ||
563 | if (FD_ISSET (0, &fds_r)) | 563 | if (FD_ISSET(0, &fds_r)) |
564 | { | 564 | { |
565 | bufin_size = read (0, bufin + bufin_rpos, MAX_SIZE - bufin_rpos); | 565 | bufin_size = read(0, bufin + bufin_rpos, MAX_SIZE - bufin_rpos); |
566 | if (-1 == bufin_size) | 566 | if (-1 == bufin_size) |
567 | { | 567 | { |
568 | fprintf (stderr, "read-error: %s\n", strerror (errno)); | 568 | fprintf(stderr, "read-error: %s\n", strerror(errno)); |
569 | shutdown (0, SHUT_RD); | 569 | shutdown(0, SHUT_RD); |
570 | shutdown (fd_tun, SHUT_WR); | 570 | shutdown(fd_tun, SHUT_WR); |
571 | write_open = 0; | 571 | write_open = 0; |
572 | bufin_size = 0; | 572 | bufin_size = 0; |
573 | } | 573 | } |
574 | else if (0 == bufin_size) | 574 | else if (0 == bufin_size) |
575 | { | 575 | { |
576 | #if DEBUG | 576 | #if DEBUG |
577 | fprintf (stderr, "EOF on stdin\n"); | 577 | fprintf(stderr, "EOF on stdin\n"); |
578 | #endif | 578 | #endif |
579 | shutdown (0, SHUT_RD); | 579 | shutdown(0, SHUT_RD); |
580 | shutdown (fd_tun, SHUT_WR); | 580 | shutdown(fd_tun, SHUT_WR); |
581 | write_open = 0; | 581 | write_open = 0; |
582 | bufin_size = 0; | 582 | bufin_size = 0; |
583 | } | 583 | } |
584 | else | 584 | else |
585 | { | 585 | { |
586 | struct GNUNET_MessageHeader *hdr; | 586 | struct GNUNET_MessageHeader *hdr; |
587 | 587 | ||
588 | PROCESS_BUFFER: | 588 | PROCESS_BUFFER: |
589 | bufin_rpos += bufin_size; | 589 | bufin_rpos += bufin_size; |
590 | if (bufin_rpos < sizeof (struct GNUNET_MessageHeader)) | 590 | if (bufin_rpos < sizeof(struct GNUNET_MessageHeader)) |
591 | continue; | 591 | continue; |
592 | hdr = (struct GNUNET_MessageHeader *) bufin; | 592 | hdr = (struct GNUNET_MessageHeader *)bufin; |
593 | if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) | 593 | if (ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) |
594 | { | 594 | { |
595 | fprintf (stderr, "protocol violation!\n"); | 595 | fprintf(stderr, "protocol violation!\n"); |
596 | exit (1); | 596 | exit(1); |
597 | } | 597 | } |
598 | if (ntohs (hdr->size) > bufin_rpos) | 598 | if (ntohs(hdr->size) > bufin_rpos) |
599 | continue; | 599 | continue; |
600 | bufin_read = bufin + sizeof (struct GNUNET_MessageHeader); | 600 | bufin_read = bufin + sizeof(struct GNUNET_MessageHeader); |
601 | bufin_size = ntohs (hdr->size) - sizeof (struct GNUNET_MessageHeader); | 601 | bufin_size = ntohs(hdr->size) - sizeof(struct GNUNET_MessageHeader); |
602 | bufin_rpos -= bufin_size + sizeof (struct GNUNET_MessageHeader); | 602 | bufin_rpos -= bufin_size + sizeof(struct GNUNET_MessageHeader); |
603 | } | 603 | } |
604 | } | 604 | } |
605 | else if (FD_ISSET (fd_tun, &fds_w)) | 605 | else if (FD_ISSET(fd_tun, &fds_w)) |
606 | { | 606 | { |
607 | ssize_t written = write (fd_tun, bufin_read, bufin_size); | 607 | ssize_t written = write(fd_tun, bufin_read, bufin_size); |
608 | 608 | ||
609 | if (-1 == written) | 609 | if (-1 == written) |
610 | { | 610 | { |
611 | fprintf (stderr, "write-error to tun: %s\n", strerror (errno)); | 611 | fprintf(stderr, "write-error to tun: %s\n", strerror(errno)); |
612 | shutdown (0, SHUT_RD); | 612 | shutdown(0, SHUT_RD); |
613 | shutdown (fd_tun, SHUT_WR); | 613 | shutdown(fd_tun, SHUT_WR); |
614 | write_open = 0; | 614 | write_open = 0; |
615 | bufin_size = 0; | 615 | bufin_size = 0; |
616 | } | ||
617 | else if (0 == written) | ||
618 | { | ||
619 | fprintf(stderr, "write returned 0!?\n"); | ||
620 | exit(1); | ||
621 | } | ||
622 | else | ||
623 | { | ||
624 | bufin_size -= written; | ||
625 | bufin_read += written; | ||
626 | if (0 == bufin_size) | ||
627 | { | ||
628 | memmove(bufin, bufin_read, bufin_rpos); | ||
629 | bufin_read = NULL; /* start reading again */ | ||
630 | bufin_size = 0; | ||
631 | goto PROCESS_BUFFER; | ||
632 | } | ||
633 | } | ||
634 | } | ||
616 | } | 635 | } |
617 | else if (0 == written) | ||
618 | { | ||
619 | fprintf (stderr, "write returned 0!?\n"); | ||
620 | exit (1); | ||
621 | } | ||
622 | else | ||
623 | { | ||
624 | bufin_size -= written; | ||
625 | bufin_read += written; | ||
626 | if (0 == bufin_size) | ||
627 | { | ||
628 | memmove (bufin, bufin_read, bufin_rpos); | ||
629 | bufin_read = NULL; /* start reading again */ | ||
630 | bufin_size = 0; | ||
631 | goto PROCESS_BUFFER; | ||
632 | } | ||
633 | } | ||
634 | } | ||
635 | } | 636 | } |
636 | } | ||
637 | } | 637 | } |
638 | 638 | ||
639 | 639 | ||
@@ -651,166 +651,166 @@ PROCESS_BUFFER: | |||
651 | * 6: IPv4 netmask ("255.255.0.0") [ignored if #4 is "-"] | 651 | * 6: IPv4 netmask ("255.255.0.0") [ignored if #4 is "-"] |
652 | */ | 652 | */ |
653 | int | 653 | int |
654 | main (int argc, char **argv) | 654 | main(int argc, char **argv) |
655 | { | 655 | { |
656 | char dev[IFNAMSIZ]; | 656 | char dev[IFNAMSIZ]; |
657 | int fd_tun; | 657 | int fd_tun; |
658 | int global_ret; | 658 | int global_ret; |
659 | 659 | ||
660 | if (7 != argc) | 660 | if (7 != argc) |
661 | { | 661 | { |
662 | fprintf (stderr, "Fatal: must supply 6 arguments!\n"); | 662 | fprintf(stderr, "Fatal: must supply 6 arguments!\n"); |
663 | return 1; | ||
664 | } | ||
665 | if ( (0 == strcmp (argv[3], "-")) && | ||
666 | (0 == strcmp (argv[5], "-")) ) | ||
667 | { | ||
668 | fprintf (stderr, "Fatal: disabling both IPv4 and IPv6 makes no sense.\n"); | ||
669 | return 1; | ||
670 | } | ||
671 | if (0 != strcmp (argv[2], "-")) | ||
672 | { | ||
673 | #ifdef IPTABLES | ||
674 | if (0 == access (IPTABLES, X_OK)) | ||
675 | sbin_iptables = IPTABLES; | ||
676 | else | ||
677 | #endif | ||
678 | if (0 == access ("/sbin/iptables", X_OK)) | ||
679 | sbin_iptables = "/sbin/iptables"; | ||
680 | else if (0 == access ("/usr/sbin/iptables", X_OK)) | ||
681 | sbin_iptables = "/usr/sbin/iptables"; | ||
682 | else | ||
683 | { | ||
684 | fprintf (stderr, | ||
685 | "Fatal: executable iptables not found in approved directories: %s\n", | ||
686 | strerror (errno)); | ||
687 | return 1; | 663 | return 1; |
688 | } | 664 | } |
665 | if ((0 == strcmp(argv[3], "-")) && | ||
666 | (0 == strcmp(argv[5], "-"))) | ||
667 | { | ||
668 | fprintf(stderr, "Fatal: disabling both IPv4 and IPv6 makes no sense.\n"); | ||
669 | return 1; | ||
670 | } | ||
671 | if (0 != strcmp(argv[2], "-")) | ||
672 | { | ||
673 | #ifdef IPTABLES | ||
674 | if (0 == access(IPTABLES, X_OK)) | ||
675 | sbin_iptables = IPTABLES; | ||
676 | else | ||
677 | #endif | ||
678 | if (0 == access("/sbin/iptables", X_OK)) | ||
679 | sbin_iptables = "/sbin/iptables"; | ||
680 | else if (0 == access("/usr/sbin/iptables", X_OK)) | ||
681 | sbin_iptables = "/usr/sbin/iptables"; | ||
682 | else | ||
683 | { | ||
684 | fprintf(stderr, | ||
685 | "Fatal: executable iptables not found in approved directories: %s\n", | ||
686 | strerror(errno)); | ||
687 | return 1; | ||
688 | } | ||
689 | #ifdef SYSCTL | 689 | #ifdef SYSCTL |
690 | if (0 == access (SYSCTL, X_OK)) | 690 | if (0 == access(SYSCTL, X_OK)) |
691 | sbin_sysctl = SYSCTL; | 691 | sbin_sysctl = SYSCTL; |
692 | else | 692 | else |
693 | #endif | 693 | #endif |
694 | if (0 == access ("/sbin/sysctl", X_OK)) | 694 | if (0 == access("/sbin/sysctl", X_OK)) |
695 | sbin_sysctl = "/sbin/sysctl"; | 695 | sbin_sysctl = "/sbin/sysctl"; |
696 | else if (0 == access ("/usr/sbin/sysctl", X_OK)) | 696 | else if (0 == access("/usr/sbin/sysctl", X_OK)) |
697 | sbin_sysctl = "/usr/sbin/sysctl"; | 697 | sbin_sysctl = "/usr/sbin/sysctl"; |
698 | else | 698 | else |
699 | { | 699 | { |
700 | fprintf (stderr, | 700 | fprintf(stderr, |
701 | "Fatal: executable sysctl not found in approved directories: %s\n", | 701 | "Fatal: executable sysctl not found in approved directories: %s\n", |
702 | strerror (errno)); | 702 | strerror(errno)); |
703 | return 1; | 703 | return 1; |
704 | } | ||
704 | } | 705 | } |
705 | } | ||
706 | 706 | ||
707 | strncpy (dev, argv[1], IFNAMSIZ); | 707 | strncpy(dev, argv[1], IFNAMSIZ); |
708 | dev[IFNAMSIZ - 1] = '\0'; | 708 | dev[IFNAMSIZ - 1] = '\0'; |
709 | 709 | ||
710 | if (-1 == (fd_tun = init_tun (dev))) | 710 | if (-1 == (fd_tun = init_tun(dev))) |
711 | { | ||
712 | fprintf (stderr, | ||
713 | "Fatal: could not initialize tun-interface `%s' with IPv6 %s/%s and IPv4 %s/%s\n", | ||
714 | dev, | ||
715 | argv[3], | ||
716 | argv[4], | ||
717 | argv[5], | ||
718 | argv[6]); | ||
719 | return 1; | ||
720 | } | ||
721 | |||
722 | if (0 != strcmp (argv[3], "-")) | ||
723 | { | ||
724 | { | 711 | { |
725 | const char *address = argv[3]; | 712 | fprintf(stderr, |
726 | long prefix_len = atol (argv[4]); | 713 | "Fatal: could not initialize tun-interface `%s' with IPv6 %s/%s and IPv4 %s/%s\n", |
727 | 714 | dev, | |
728 | if ((prefix_len < 1) || (prefix_len > 127)) | 715 | argv[3], |
729 | { | 716 | argv[4], |
730 | fprintf (stderr, "Fatal: prefix_len out of range\n"); | 717 | argv[5], |
731 | return 1; | 718 | argv[6]); |
732 | } | 719 | return 1; |
733 | set_address6 (dev, address, prefix_len); | ||
734 | } | 720 | } |
735 | if (0 != strcmp (argv[2], "-")) | 721 | |
722 | if (0 != strcmp(argv[3], "-")) | ||
736 | { | 723 | { |
737 | char *const sysctl_args[] = | ||
738 | { | ||
739 | "sysctl", "-w", "net.ipv6.conf.all.forwarding=1", NULL | ||
740 | }; | ||
741 | if (0 != fork_and_exec (sbin_sysctl, | ||
742 | sysctl_args)) | ||
743 | { | 724 | { |
744 | fprintf (stderr, | 725 | const char *address = argv[3]; |
745 | "Failed to enable IPv6 forwarding. Will continue anyway.\n"); | 726 | long prefix_len = atol(argv[4]); |
727 | |||
728 | if ((prefix_len < 1) || (prefix_len > 127)) | ||
729 | { | ||
730 | fprintf(stderr, "Fatal: prefix_len out of range\n"); | ||
731 | return 1; | ||
732 | } | ||
733 | set_address6(dev, address, prefix_len); | ||
746 | } | 734 | } |
735 | if (0 != strcmp(argv[2], "-")) | ||
736 | { | ||
737 | char *const sysctl_args[] = | ||
738 | { | ||
739 | "sysctl", "-w", "net.ipv6.conf.all.forwarding=1", NULL | ||
740 | }; | ||
741 | if (0 != fork_and_exec(sbin_sysctl, | ||
742 | sysctl_args)) | ||
743 | { | ||
744 | fprintf(stderr, | ||
745 | "Failed to enable IPv6 forwarding. Will continue anyway.\n"); | ||
746 | } | ||
747 | } | ||
747 | } | 748 | } |
748 | } | ||
749 | 749 | ||
750 | if (0 != strcmp (argv[5], "-")) | 750 | if (0 != strcmp(argv[5], "-")) |
751 | { | ||
752 | { | ||
753 | const char *address = argv[5]; | ||
754 | const char *mask = argv[6]; | ||
755 | |||
756 | set_address4 (dev, address, mask); | ||
757 | } | ||
758 | if (0 != strcmp (argv[2], "-")) | ||
759 | { | 751 | { |
760 | { | 752 | { |
761 | char *const sysctl_args[] = | 753 | const char *address = argv[5]; |
762 | { | 754 | const char *mask = argv[6]; |
763 | "sysctl", "-w", "net.ipv4.ip_forward=1", NULL | 755 | |
764 | }; | 756 | set_address4(dev, address, mask); |
765 | if (0 != fork_and_exec (sbin_sysctl, | ||
766 | sysctl_args)) | ||
767 | { | ||
768 | fprintf (stderr, | ||
769 | "Failed to enable IPv4 forwarding. Will continue anyway.\n"); | ||
770 | } | ||
771 | } | 757 | } |
772 | { | 758 | if (0 != strcmp(argv[2], "-")) |
773 | char *const iptables_args[] = | ||
774 | { | ||
775 | "iptables", "-t", "nat", "-A", "POSTROUTING", "-o", argv[2], "-j", "MASQUERADE", NULL | ||
776 | }; | ||
777 | if (0 != fork_and_exec (sbin_iptables, | ||
778 | iptables_args)) | ||
779 | { | 759 | { |
780 | fprintf (stderr, | 760 | { |
781 | "Failed to enable IPv4 masquerading (NAT). Will continue anyway.\n"); | 761 | char *const sysctl_args[] = |
762 | { | ||
763 | "sysctl", "-w", "net.ipv4.ip_forward=1", NULL | ||
764 | }; | ||
765 | if (0 != fork_and_exec(sbin_sysctl, | ||
766 | sysctl_args)) | ||
767 | { | ||
768 | fprintf(stderr, | ||
769 | "Failed to enable IPv4 forwarding. Will continue anyway.\n"); | ||
770 | } | ||
771 | } | ||
772 | { | ||
773 | char *const iptables_args[] = | ||
774 | { | ||
775 | "iptables", "-t", "nat", "-A", "POSTROUTING", "-o", argv[2], "-j", "MASQUERADE", NULL | ||
776 | }; | ||
777 | if (0 != fork_and_exec(sbin_iptables, | ||
778 | iptables_args)) | ||
779 | { | ||
780 | fprintf(stderr, | ||
781 | "Failed to enable IPv4 masquerading (NAT). Will continue anyway.\n"); | ||
782 | } | ||
783 | } | ||
782 | } | 784 | } |
783 | } | ||
784 | } | 785 | } |
785 | } | ||
786 | 786 | ||
787 | uid_t uid = getuid (); | 787 | uid_t uid = getuid(); |
788 | #ifdef HAVE_SETRESUID | 788 | #ifdef HAVE_SETRESUID |
789 | if (0 != setresuid (uid, uid, uid)) | 789 | if (0 != setresuid(uid, uid, uid)) |
790 | { | 790 | { |
791 | fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); | 791 | fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno)); |
792 | global_ret = 2; | 792 | global_ret = 2; |
793 | goto cleanup; | 793 | goto cleanup; |
794 | } | 794 | } |
795 | #else | 795 | #else |
796 | if (0 != (setuid (uid) | seteuid (uid))) | 796 | if (0 != (setuid(uid) | seteuid(uid))) |
797 | { | 797 | { |
798 | fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); | 798 | fprintf(stderr, "Failed to setuid: %s\n", strerror(errno)); |
799 | global_ret = 2; | 799 | global_ret = 2; |
800 | goto cleanup; | 800 | goto cleanup; |
801 | } | 801 | } |
802 | #endif | 802 | #endif |
803 | 803 | ||
804 | if (SIG_ERR == signal (SIGPIPE, SIG_IGN)) | 804 | if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) |
805 | { | 805 | { |
806 | fprintf (stderr, "Failed to protect against SIGPIPE: %s\n", | 806 | fprintf(stderr, "Failed to protect against SIGPIPE: %s\n", |
807 | strerror (errno)); | 807 | strerror(errno)); |
808 | /* no exit, we might as well die with SIGPIPE should it ever happen */ | 808 | /* no exit, we might as well die with SIGPIPE should it ever happen */ |
809 | } | 809 | } |
810 | run (fd_tun); | 810 | run(fd_tun); |
811 | global_ret = 0; | 811 | global_ret = 0; |
812 | cleanup: | 812 | cleanup: |
813 | (void) close (fd_tun); | 813 | (void)close(fd_tun); |
814 | return global_ret; | 814 | return global_ret; |
815 | } | 815 | } |
816 | 816 | ||