diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/vpn/gnunet-service-dns.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/vpn/gnunet-service-dns.c')
-rw-r--r-- | src/vpn/gnunet-service-dns.c | 1434 |
1 files changed, 750 insertions, 684 deletions
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index fca21ee4d..9959e9564 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c | |||
@@ -83,31 +83,33 @@ static struct answer_packet_list *tail; | |||
83 | * = 17 MiB on 64 bit. | 83 | * = 17 MiB on 64 bit. |
84 | * = 11 MiB on 32 bit. | 84 | * = 11 MiB on 32 bit. |
85 | */ | 85 | */ |
86 | static struct { | 86 | static struct |
87 | unsigned valid:1; | 87 | { |
88 | struct GNUNET_SERVER_Client* client; | 88 | unsigned valid:1; |
89 | struct GNUNET_MESH_Tunnel *tunnel; | 89 | struct GNUNET_SERVER_Client *client; |
90 | uint32_t local_ip; | 90 | struct GNUNET_MESH_Tunnel *tunnel; |
91 | uint32_t remote_ip; | 91 | uint32_t local_ip; |
92 | uint16_t local_port; | 92 | uint32_t remote_ip; |
93 | char* name; | 93 | uint16_t local_port; |
94 | uint8_t namelen; | 94 | char *name; |
95 | uint8_t namelen; | ||
95 | } query_states[UINT16_MAX]; | 96 | } query_states[UINT16_MAX]; |
96 | 97 | ||
97 | /** | 98 | /** |
98 | * A struct used to give more than one value as | 99 | * A struct used to give more than one value as |
99 | * closure to receive_dht | 100 | * closure to receive_dht |
100 | */ | 101 | */ |
101 | struct receive_dht_cls { | 102 | struct receive_dht_cls |
102 | uint16_t id; | 103 | { |
103 | struct GNUNET_DHT_GetHandle* handle; | 104 | uint16_t id; |
105 | struct GNUNET_DHT_GetHandle *handle; | ||
104 | }; | 106 | }; |
105 | 107 | ||
106 | struct tunnel_notify_queue | 108 | struct tunnel_notify_queue |
107 | { | 109 | { |
108 | struct tunnel_notify_queue* next; | 110 | struct tunnel_notify_queue *next; |
109 | struct tunnel_notify_queue* prev; | 111 | struct tunnel_notify_queue *prev; |
110 | void* cls; | 112 | void *cls; |
111 | size_t len; | 113 | size_t len; |
112 | GNUNET_CONNECTION_TransmitReadyNotify cb; | 114 | GNUNET_CONNECTION_TransmitReadyNotify cb; |
113 | }; | 115 | }; |
@@ -116,30 +118,31 @@ struct tunnel_notify_queue | |||
116 | * Hijack all outgoing DNS-Traffic but for traffic leaving "our" port. | 118 | * Hijack all outgoing DNS-Traffic but for traffic leaving "our" port. |
117 | */ | 119 | */ |
118 | static void | 120 | static void |
119 | hijack (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext *tc) | 121 | hijack (void *cls |
122 | __attribute__ ((unused)), const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
120 | { | 123 | { |
121 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 124 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
122 | return; | 125 | return; |
123 | 126 | ||
124 | if (0 == dnsoutport) | 127 | if (0 == dnsoutport) |
125 | { | 128 | { |
126 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Delaying the hijacking, port is still %d!\n", dnsoutport); | 129 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
127 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, hijack, NULL); | 130 | "Delaying the hijacking, port is still %d!\n", dnsoutport); |
128 | return; | 131 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL); |
129 | } | 132 | return; |
133 | } | ||
130 | 134 | ||
131 | char port_s[6]; | 135 | char port_s[6]; |
132 | char *virt_dns; | 136 | char *virt_dns; |
133 | struct GNUNET_OS_Process *proc; | 137 | struct GNUNET_OS_Process *proc; |
134 | 138 | ||
135 | if (GNUNET_SYSERR == | 139 | if (GNUNET_SYSERR == |
136 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", | 140 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns)) |
137 | &virt_dns)) | 141 | { |
138 | { | 142 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 143 | "No entry 'VIRTDNS' in configuration!\n"); |
140 | "No entry 'VIRTDNS' in configuration!\n"); | 144 | exit (1); |
141 | exit (1); | 145 | } |
142 | } | ||
143 | 146 | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport); | 147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport); |
145 | snprintf (port_s, 6, "%d", dnsoutport); | 148 | snprintf (port_s, 6, "%d", dnsoutport); |
@@ -163,13 +166,12 @@ unhijack (unsigned short port) | |||
163 | struct GNUNET_OS_Process *proc; | 166 | struct GNUNET_OS_Process *proc; |
164 | 167 | ||
165 | if (GNUNET_SYSERR == | 168 | if (GNUNET_SYSERR == |
166 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", | 169 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns)) |
167 | &virt_dns)) | 170 | { |
168 | { | 171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
169 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 172 | "No entry 'VIRTDNS' in configuration!\n"); |
170 | "No entry 'VIRTDNS' in configuration!\n"); | 173 | exit (1); |
171 | exit (1); | 174 | } |
172 | } | ||
173 | 175 | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port); | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port); |
175 | snprintf (port_s, 6, "%d", port); | 177 | snprintf (port_s, 6, "%d", port); |
@@ -187,33 +189,34 @@ unhijack (unsigned short port) | |||
187 | * system. | 189 | * system. |
188 | */ | 190 | */ |
189 | static size_t | 191 | static size_t |
190 | send_answer(void* cls, size_t size, void* buf) { | 192 | send_answer (void *cls, size_t size, void *buf) |
191 | struct answer_packet_list* query = head; | 193 | { |
192 | size_t len = ntohs(query->pkt.hdr.size); | 194 | struct answer_packet_list *query = head; |
195 | size_t len = ntohs (query->pkt.hdr.size); | ||
193 | 196 | ||
194 | GNUNET_assert(len <= size); | 197 | GNUNET_assert (len <= size); |
195 | 198 | ||
196 | memcpy(buf, &query->pkt.hdr, len); | 199 | memcpy (buf, &query->pkt.hdr, len); |
197 | 200 | ||
198 | GNUNET_CONTAINER_DLL_remove (head, tail, query); | 201 | GNUNET_CONTAINER_DLL_remove (head, tail, query); |
199 | 202 | ||
200 | GNUNET_free(query); | 203 | GNUNET_free (query); |
201 | 204 | ||
202 | /* When more data is to be sent, reschedule */ | 205 | /* When more data is to be sent, reschedule */ |
203 | if (head != NULL) | 206 | if (head != NULL) |
204 | GNUNET_SERVER_notify_transmit_ready(cls, | 207 | GNUNET_SERVER_notify_transmit_ready (cls, |
205 | ntohs(head->pkt.hdr.size), | 208 | ntohs (head->pkt.hdr.size), |
206 | GNUNET_TIME_UNIT_FOREVER_REL, | 209 | GNUNET_TIME_UNIT_FOREVER_REL, |
207 | &send_answer, | 210 | &send_answer, cls); |
208 | cls); | ||
209 | 211 | ||
210 | return len; | 212 | return len; |
211 | } | 213 | } |
212 | 214 | ||
213 | struct tunnel_cls { | 215 | struct tunnel_cls |
214 | struct GNUNET_MESH_Tunnel *tunnel GNUNET_PACKED; | 216 | { |
215 | struct GNUNET_MessageHeader hdr; | 217 | struct GNUNET_MESH_Tunnel *tunnel GNUNET_PACKED; |
216 | struct dns_pkt dns; | 218 | struct GNUNET_MessageHeader hdr; |
219 | struct dns_pkt dns; | ||
217 | }; | 220 | }; |
218 | 221 | ||
219 | struct tunnel_cls *remote_pending[UINT16_MAX]; | 222 | struct tunnel_cls *remote_pending[UINT16_MAX]; |
@@ -224,8 +227,9 @@ mesh_send_response (void *cls, size_t size, void *buf) | |||
224 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 227 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); |
225 | struct GNUNET_MessageHeader *hdr = buf; | 228 | struct GNUNET_MessageHeader *hdr = buf; |
226 | uint32_t *sz = cls; | 229 | uint32_t *sz = cls; |
227 | struct GNUNET_MESH_Tunnel **tunnel = (struct GNUNET_MESH_Tunnel**)(sz+1); | 230 | struct GNUNET_MESH_Tunnel **tunnel = (struct GNUNET_MESH_Tunnel **) (sz + 1); |
228 | struct dns_pkt *dns = (struct dns_pkt *) (tunnel + 1); | 231 | struct dns_pkt *dns = (struct dns_pkt *) (tunnel + 1); |
232 | |||
229 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_ANSWER_DNS); | 233 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_REMOTE_ANSWER_DNS); |
230 | hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader)); | 234 | hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader)); |
231 | 235 | ||
@@ -237,27 +241,29 @@ mesh_send_response (void *cls, size_t size, void *buf) | |||
237 | 241 | ||
238 | memcpy (hdr + 1, dns, *sz); | 242 | memcpy (hdr + 1, dns, *sz); |
239 | 243 | ||
240 | if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel)) | 244 | if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel)) |
241 | { | 245 | { |
242 | struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(*tunnel); | 246 | struct tunnel_notify_queue *element = GNUNET_MESH_tunnel_get_head (*tunnel); |
243 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel); | 247 | struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel); |
244 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel); | 248 | struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel); |
245 | 249 | ||
246 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | 250 | GNUNET_CONTAINER_DLL_remove (head, tail, element); |
247 | 251 | ||
248 | GNUNET_MESH_tunnel_set_head(*tunnel, head); | 252 | GNUNET_MESH_tunnel_set_head (*tunnel, head); |
249 | GNUNET_MESH_tunnel_set_tail(*tunnel, tail); | 253 | GNUNET_MESH_tunnel_set_tail (*tunnel, tail); |
250 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel, | 254 | struct GNUNET_MESH_TransmitHandle *th = |
251 | GNUNET_NO, | 255 | GNUNET_MESH_notify_transmit_ready (*tunnel, |
252 | 42, | 256 | GNUNET_NO, |
253 | GNUNET_TIME_relative_divide | 257 | 42, |
254 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 258 | GNUNET_TIME_relative_divide |
255 | (const struct GNUNET_PeerIdentity *) | 259 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
256 | NULL, element->len, | 260 | (const struct GNUNET_PeerIdentity *) |
257 | element->cb, element->cls); | 261 | NULL, element->len, |
258 | /* save the handle */ | 262 | element->cb, element->cls); |
259 | GNUNET_MESH_tunnel_set_data(*tunnel, th); | 263 | |
260 | } | 264 | /* save the handle */ |
265 | GNUNET_MESH_tunnel_set_data (*tunnel, th); | ||
266 | } | ||
261 | 267 | ||
262 | GNUNET_free (cls); | 268 | GNUNET_free (cls); |
263 | 269 | ||
@@ -268,37 +274,43 @@ static size_t | |||
268 | mesh_send (void *cls, size_t size, void *buf) | 274 | mesh_send (void *cls, size_t size, void *buf) |
269 | { | 275 | { |
270 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; | 276 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; |
271 | GNUNET_MESH_tunnel_set_data(cls_->tunnel, NULL); | ||
272 | 277 | ||
273 | GNUNET_assert(cls_->hdr.size <= size); | 278 | GNUNET_MESH_tunnel_set_data (cls_->tunnel, NULL); |
279 | |||
280 | GNUNET_assert (cls_->hdr.size <= size); | ||
274 | 281 | ||
275 | size = cls_->hdr.size; | 282 | size = cls_->hdr.size; |
276 | cls_->hdr.size = htons(cls_->hdr.size); | 283 | cls_->hdr.size = htons (cls_->hdr.size); |
277 | 284 | ||
278 | memcpy(buf, &cls_->hdr, size); | 285 | memcpy (buf, &cls_->hdr, size); |
279 | 286 | ||
280 | if (NULL != GNUNET_MESH_tunnel_get_head(cls_->tunnel)) | 287 | if (NULL != GNUNET_MESH_tunnel_get_head (cls_->tunnel)) |
281 | { | 288 | { |
282 | struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(cls_->tunnel); | 289 | struct tunnel_notify_queue *element = |
283 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(cls_->tunnel); | 290 | GNUNET_MESH_tunnel_get_head (cls_->tunnel); |
284 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(cls_->tunnel); | 291 | struct tunnel_notify_queue *head = |
285 | 292 | GNUNET_MESH_tunnel_get_head (cls_->tunnel); | |
286 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | 293 | struct tunnel_notify_queue *tail = |
287 | 294 | GNUNET_MESH_tunnel_get_tail (cls_->tunnel); | |
288 | GNUNET_MESH_tunnel_set_head(cls_->tunnel, head); | 295 | |
289 | GNUNET_MESH_tunnel_set_tail(cls_->tunnel, tail); | 296 | GNUNET_CONTAINER_DLL_remove (head, tail, element); |
290 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (cls_->tunnel, | 297 | |
291 | GNUNET_NO, | 298 | GNUNET_MESH_tunnel_set_head (cls_->tunnel, head); |
292 | 42, | 299 | GNUNET_MESH_tunnel_set_tail (cls_->tunnel, tail); |
293 | GNUNET_TIME_relative_divide | 300 | struct GNUNET_MESH_TransmitHandle *th = |
294 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 301 | GNUNET_MESH_notify_transmit_ready (cls_->tunnel, |
295 | (const struct GNUNET_PeerIdentity *) | 302 | GNUNET_NO, |
296 | NULL, element->len, | 303 | 42, |
297 | element->cb, element->cls); | 304 | GNUNET_TIME_relative_divide |
298 | /* save the handle */ | 305 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
299 | GNUNET_MESH_tunnel_set_data(cls_->tunnel, th); | 306 | (const struct GNUNET_PeerIdentity *) |
300 | GNUNET_free(element); | 307 | NULL, element->len, |
301 | } | 308 | element->cb, element->cls); |
309 | |||
310 | /* save the handle */ | ||
311 | GNUNET_MESH_tunnel_set_data (cls_->tunnel, th); | ||
312 | GNUNET_free (element); | ||
313 | } | ||
302 | 314 | ||
303 | return size; | 315 | return size; |
304 | } | 316 | } |
@@ -312,13 +324,14 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
312 | if (NULL == peer) | 324 | if (NULL == peer) |
313 | return; | 325 | return; |
314 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; | 326 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; |
327 | |||
315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
316 | "Connected to peer %s, %x, sending query with id %d\n", | 329 | "Connected to peer %s, %x, sending query with id %d\n", |
317 | GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id)); | 330 | GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id)); |
318 | 331 | ||
319 | if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel)) | 332 | if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel)) |
320 | { | 333 | { |
321 | struct GNUNET_MESH_TransmitHandle *th = | 334 | struct GNUNET_MESH_TransmitHandle *th = |
322 | GNUNET_MESH_notify_transmit_ready (cls_->tunnel, | 335 | GNUNET_MESH_notify_transmit_ready (cls_->tunnel, |
323 | GNUNET_YES, | 336 | GNUNET_YES, |
324 | 42, | 337 | 42, |
@@ -328,22 +341,25 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
328 | mesh_send, | 341 | mesh_send, |
329 | cls); | 342 | cls); |
330 | 343 | ||
331 | GNUNET_MESH_tunnel_set_data (cls_->tunnel, th); | 344 | GNUNET_MESH_tunnel_set_data (cls_->tunnel, th); |
332 | } | 345 | } |
333 | else | 346 | else |
334 | { | 347 | { |
335 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(cls_->tunnel); | 348 | struct tunnel_notify_queue *head = |
336 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(cls_->tunnel); | 349 | GNUNET_MESH_tunnel_get_head (cls_->tunnel); |
337 | 350 | struct tunnel_notify_queue *tail = | |
338 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue)); | 351 | GNUNET_MESH_tunnel_get_tail (cls_->tunnel); |
339 | element->cls = cls; | 352 | |
340 | element->len = cls_->hdr.size; | 353 | struct tunnel_notify_queue *element = |
341 | element->cb = mesh_send; | 354 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); |
342 | 355 | element->cls = cls; | |
343 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | 356 | element->len = cls_->hdr.size; |
344 | GNUNET_MESH_tunnel_set_head(cls_->tunnel, head); | 357 | element->cb = mesh_send; |
345 | GNUNET_MESH_tunnel_set_tail(cls_->tunnel, tail); | 358 | |
346 | } | 359 | GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); |
360 | GNUNET_MESH_tunnel_set_head (cls_->tunnel, head); | ||
361 | GNUNET_MESH_tunnel_set_tail (cls_->tunnel, tail); | ||
362 | } | ||
347 | } | 363 | } |
348 | 364 | ||
349 | 365 | ||
@@ -353,54 +369,58 @@ send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
353 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 369 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
354 | return; | 370 | return; |
355 | 371 | ||
356 | struct tunnel_cls *cls_ = (struct tunnel_cls*)cls; | 372 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; |
357 | 373 | ||
358 | cls_->tunnel = GNUNET_MESH_peer_request_connect_by_type(mesh_handle, | 374 | cls_->tunnel = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, |
359 | GNUNET_TIME_UNIT_HOURS, | 375 | GNUNET_TIME_UNIT_HOURS, |
360 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, | 376 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, |
361 | mesh_connect, | 377 | mesh_connect, |
362 | NULL, | 378 | NULL, cls_); |
363 | cls_); | ||
364 | 379 | ||
365 | remote_pending[cls_->dns.s.id] = cls_; | 380 | remote_pending[cls_->dns.s.id] = cls_; |
366 | } | 381 | } |
367 | 382 | ||
368 | static int | 383 | static int |
369 | receive_mesh_query (void *cls __attribute__((unused)), | 384 | receive_mesh_query (void *cls __attribute__ ((unused)), |
370 | struct GNUNET_MESH_Tunnel *tunnel, | 385 | struct GNUNET_MESH_Tunnel *tunnel, |
371 | void **ctx __attribute__((unused)), | 386 | void **ctx __attribute__ ((unused)), |
372 | const struct GNUNET_PeerIdentity *sender __attribute__((unused)), | 387 | const struct GNUNET_PeerIdentity *sender |
388 | __attribute__ ((unused)), | ||
373 | const struct GNUNET_MessageHeader *message, | 389 | const struct GNUNET_MessageHeader *message, |
374 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) | 390 | const struct GNUNET_TRANSPORT_ATS_Information *atsi |
391 | __attribute__ ((unused))) | ||
375 | { | 392 | { |
376 | struct dns_pkt *dns = (struct dns_pkt*)(message + 1); | 393 | struct dns_pkt *dns = (struct dns_pkt *) (message + 1); |
377 | 394 | ||
378 | struct sockaddr_in dest; | 395 | struct sockaddr_in dest; |
379 | memset(&dest, 0, sizeof dest); | 396 | |
380 | dest.sin_port = htons(53); | 397 | memset (&dest, 0, sizeof dest); |
398 | dest.sin_port = htons (53); | ||
381 | /* TODO: read from config */ | 399 | /* TODO: read from config */ |
382 | inet_pton(AF_INET, "8.8.8.8", &dest.sin_addr); | 400 | inet_pton (AF_INET, "8.8.8.8", &dest.sin_addr); |
383 | 401 | ||
384 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Querying for remote, id=%d\n", ntohs(dns->s.id)); | 402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Querying for remote, id=%d\n", |
403 | ntohs (dns->s.id)); | ||
385 | query_states[dns->s.id].tunnel = tunnel; | 404 | query_states[dns->s.id].tunnel = tunnel; |
386 | query_states[dns->s.id].valid = GNUNET_YES; | 405 | query_states[dns->s.id].valid = GNUNET_YES; |
387 | 406 | ||
388 | GNUNET_NETWORK_socket_sendto(dnsout, | 407 | GNUNET_NETWORK_socket_sendto (dnsout, |
389 | dns, | 408 | dns, |
390 | ntohs(message->size) - sizeof(struct GNUNET_MessageHeader), | 409 | ntohs (message->size) - |
391 | (struct sockaddr*) &dest, | 410 | sizeof (struct GNUNET_MessageHeader), |
392 | sizeof dest); | 411 | (struct sockaddr *) &dest, sizeof dest); |
393 | 412 | ||
394 | return GNUNET_SYSERR; | 413 | return GNUNET_SYSERR; |
395 | } | 414 | } |
396 | 415 | ||
397 | static int | 416 | static int |
398 | receive_mesh_answer (void *cls __attribute__((unused)), | 417 | receive_mesh_answer (void *cls __attribute__ ((unused)), |
399 | struct GNUNET_MESH_Tunnel *tunnel, | 418 | struct GNUNET_MESH_Tunnel *tunnel, |
400 | void **ctx __attribute__((unused)), | 419 | void **ctx __attribute__ ((unused)), |
401 | const struct GNUNET_PeerIdentity *sender, | 420 | const struct GNUNET_PeerIdentity *sender, |
402 | const struct GNUNET_MessageHeader *message, | 421 | const struct GNUNET_MessageHeader *message, |
403 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) | 422 | const struct GNUNET_TRANSPORT_ATS_Information *atsi |
423 | __attribute__ ((unused))) | ||
404 | { | 424 | { |
405 | /* TODo: size check */ | 425 | /* TODo: size check */ |
406 | struct dns_pkt *dns = (struct dns_pkt *) (message + 1); | 426 | struct dns_pkt *dns = (struct dns_pkt *) (message + 1); |
@@ -410,37 +430,42 @@ receive_mesh_answer (void *cls __attribute__((unused)), | |||
410 | || remote_pending[dns->s.id]->tunnel != tunnel) | 430 | || remote_pending[dns->s.id]->tunnel != tunnel) |
411 | return GNUNET_OK; | 431 | return GNUNET_OK; |
412 | 432 | ||
413 | GNUNET_free(remote_pending[dns->s.id]); | 433 | GNUNET_free (remote_pending[dns->s.id]); |
414 | remote_pending[dns->s.id] = NULL; | 434 | remote_pending[dns->s.id] = NULL; |
415 | 435 | ||
416 | if (query_states[dns->s.id].valid != GNUNET_YES) | 436 | if (query_states[dns->s.id].valid != GNUNET_YES) |
417 | return GNUNET_SYSERR; | 437 | return GNUNET_SYSERR; |
418 | query_states[dns->s.id].valid = GNUNET_NO; | 438 | query_states[dns->s.id].valid = GNUNET_NO; |
419 | 439 | ||
420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received answer from peer %s, dns-id %d\n", GNUNET_i2s(sender), ntohs(dns->s.id)); | 440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
441 | "Received answer from peer %s, dns-id %d\n", GNUNET_i2s (sender), | ||
442 | ntohs (dns->s.id)); | ||
421 | 443 | ||
422 | size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + query_states[dns->s.id].namelen + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as defined in RFC1035) to the name */ | 444 | size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + query_states[dns->s.id].namelen + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as defined in RFC1035) to the name */ |
423 | + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ | 445 | + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ |
424 | 446 | ||
425 | struct answer_packet_list *answer = | 447 | struct answer_packet_list *answer = |
426 | GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *)); | 448 | GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *)); |
427 | memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *)); | 449 | memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *)); |
428 | 450 | ||
429 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | 451 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); |
430 | answer->pkt.hdr.size = htons (len); | 452 | answer->pkt.hdr.size = htons (len); |
431 | 453 | ||
432 | struct dns_pkt_parsed* pdns = parse_dns_packet(dns); | 454 | struct dns_pkt_parsed *pdns = parse_dns_packet (dns); |
433 | 455 | ||
434 | if (ntohs(pdns->s.ancount) < 1) | 456 | if (ntohs (pdns->s.ancount) < 1) |
435 | { | 457 | { |
436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer only contains %d answers.\n", ntohs(pdns->s.ancount)); | 458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer only contains %d answers.\n", |
437 | free_parsed_dns_packet(pdns); | 459 | ntohs (pdns->s.ancount)); |
438 | return GNUNET_OK; | 460 | free_parsed_dns_packet (pdns); |
439 | } | 461 | return GNUNET_OK; |
462 | } | ||
440 | 463 | ||
441 | answer->pkt.addrsize = ntohs(pdns->answers[0]->data_len); | 464 | answer->pkt.addrsize = ntohs (pdns->answers[0]->data_len); |
442 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "The first answer has the addrlen %d\n", answer->pkt.addrsize); | 465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "The first answer has the addrlen %d\n", |
443 | memcpy(answer->pkt.addr, pdns->answers[0]->data, ntohs(pdns->answers[0]->data_len)); | 466 | answer->pkt.addrsize); |
467 | memcpy (answer->pkt.addr, pdns->answers[0]->data, | ||
468 | ntohs (pdns->answers[0]->data_len)); | ||
444 | 469 | ||
445 | answer->pkt.from = query_states[dns->s.id].remote_ip; | 470 | answer->pkt.from = query_states[dns->s.id].remote_ip; |
446 | 471 | ||
@@ -462,32 +487,32 @@ receive_mesh_answer (void *cls __attribute__((unused)), | |||
462 | query_states[dns->s.id].name = NULL; | 487 | query_states[dns->s.id].name = NULL; |
463 | 488 | ||
464 | struct dns_query_line *dque = | 489 | struct dns_query_line *dque = |
465 | (struct dns_query_line *) (dpkt->data + | 490 | (struct dns_query_line *) (dpkt->data + |
466 | (query_states[dns->s.id].namelen)); | 491 | (query_states[dns->s.id].namelen)); |
467 | 492 | ||
468 | struct dns_record_line *drec_data = | 493 | struct dns_record_line *drec_data = |
469 | (struct dns_record_line *) (dpkt->data + | 494 | (struct dns_record_line *) (dpkt->data + |
470 | (query_states[dns->s.id].namelen) + | 495 | (query_states[dns->s.id].namelen) + |
471 | sizeof (struct dns_query_line) + 2); | 496 | sizeof (struct dns_query_line) + 2); |
472 | if (16 == answer->pkt.addrsize) | 497 | if (16 == answer->pkt.addrsize) |
473 | { | 498 | { |
474 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA; | 499 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA; |
475 | dque->type = htons (28); /* AAAA */ | 500 | dque->type = htons (28); /* AAAA */ |
476 | drec_data->type = htons (28); /* AAAA */ | 501 | drec_data->type = htons (28); /* AAAA */ |
477 | drec_data->data_len = htons (16); | 502 | drec_data->data_len = htons (16); |
478 | } | 503 | } |
479 | else | 504 | else |
480 | { | 505 | { |
481 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A; | 506 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A; |
482 | dque->type = htons (1); /* A */ | 507 | dque->type = htons (1); /* A */ |
483 | drec_data->type = htons (1); /* A*/ | 508 | drec_data->type = htons (1); /* A */ |
484 | drec_data->data_len = htons (4); | 509 | drec_data->data_len = htons (4); |
485 | } | 510 | } |
486 | dque->class = htons (1); /* IN */ | 511 | dque->class = htons (1); /* IN */ |
487 | 512 | ||
488 | char *anname = | 513 | char *anname = |
489 | (char *) (dpkt->data + (query_states[dns->s.id].namelen) + | 514 | (char *) (dpkt->data + (query_states[dns->s.id].namelen) + |
490 | sizeof (struct dns_query_line)); | 515 | sizeof (struct dns_query_line)); |
491 | memcpy (anname, "\xc0\x0c", 2); | 516 | memcpy (anname, "\xc0\x0c", 2); |
492 | drec_data->class = htons (1); /* IN */ | 517 | drec_data->class = htons (1); /* IN */ |
493 | 518 | ||
@@ -496,8 +521,8 @@ receive_mesh_answer (void *cls __attribute__((unused)), | |||
496 | /* Calculate at which offset in the packet the IPv6-Address belongs, it is | 521 | /* Calculate at which offset in the packet the IPv6-Address belongs, it is |
497 | * filled in by the daemon-vpn */ | 522 | * filled in by the daemon-vpn */ |
498 | answer->pkt.addroffset = | 523 | answer->pkt.addroffset = |
499 | htons ((unsigned short) ((unsigned long) (&drec_data->data) - | 524 | htons ((unsigned short) ((unsigned long) (&drec_data->data) - |
500 | (unsigned long) (&answer->pkt))); | 525 | (unsigned long) (&answer->pkt))); |
501 | 526 | ||
502 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); | 527 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); |
503 | 528 | ||
@@ -507,378 +532,408 @@ receive_mesh_answer (void *cls __attribute__((unused)), | |||
507 | &send_answer, | 532 | &send_answer, |
508 | query_states[dns->s.id].client); | 533 | query_states[dns->s.id].client); |
509 | 534 | ||
510 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sent answer of length %d on to client, addroffset = %d\n", len, answer->pkt.addroffset); | 535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
536 | "Sent answer of length %d on to client, addroffset = %d\n", len, | ||
537 | answer->pkt.addroffset); | ||
511 | 538 | ||
512 | free_parsed_dns_packet(pdns); | 539 | free_parsed_dns_packet (pdns); |
513 | return GNUNET_OK; | 540 | return GNUNET_OK; |
514 | } | 541 | } |
515 | 542 | ||
516 | 543 | ||
517 | static void | 544 | static void |
518 | send_rev_query(void * cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { | 545 | send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
519 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 546 | { |
520 | return; | 547 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
521 | 548 | return; | |
522 | struct dns_pkt_parsed* pdns = (struct dns_pkt_parsed*) cls; | ||
523 | 549 | ||
524 | unsigned short id = pdns->s.id; | 550 | struct dns_pkt_parsed *pdns = (struct dns_pkt_parsed *) cls; |
525 | 551 | ||
526 | free_parsed_dns_packet(pdns); | 552 | unsigned short id = pdns->s.id; |
527 | 553 | ||
528 | if (query_states[id].valid != GNUNET_YES) return; | 554 | free_parsed_dns_packet (pdns); |
529 | query_states[id].valid = GNUNET_NO; | ||
530 | 555 | ||
531 | GNUNET_assert(query_states[id].namelen == 74); | 556 | if (query_states[id].valid != GNUNET_YES) |
557 | return; | ||
558 | query_states[id].valid = GNUNET_NO; | ||
532 | 559 | ||
533 | size_t len = sizeof(struct answer_packet) - 1 \ | 560 | GNUNET_assert (query_states[id].namelen == 74); |
534 | + sizeof(struct dns_static) \ | ||
535 | + 74 /* this is the length of a reverse ipv6-lookup */ \ | ||
536 | + sizeof(struct dns_query_line) \ | ||
537 | + 2 /* To hold the pointer (as defined in RFC1035) to the name */ \ | ||
538 | + sizeof(struct dns_record_line) - 1 \ | ||
539 | - 2 /* We do not know the lenght of the answer yet*/; | ||
540 | 561 | ||
541 | struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct answer_packet_list*)); | 562 | size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + 74 /* this is the length of a reverse ipv6-lookup */ |
542 | memset(answer, 0, len + 2*sizeof(struct answer_packet_list*)); | 563 | + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as defined in RFC1035) to the name */ |
564 | + sizeof (struct dns_record_line) - 1 | ||
565 | - 2 /* We do not know the lenght of the answer yet */ ; | ||
543 | 566 | ||
544 | answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | 567 | struct answer_packet_list *answer = |
545 | answer->pkt.hdr.size = htons(len); | 568 | GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *)); |
546 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV; | 569 | memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *)); |
547 | 570 | ||
548 | answer->pkt.from = query_states[id].remote_ip; | 571 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); |
572 | answer->pkt.hdr.size = htons (len); | ||
573 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV; | ||
549 | 574 | ||
550 | answer->pkt.to = query_states[id].local_ip; | 575 | answer->pkt.from = query_states[id].remote_ip; |
551 | answer->pkt.dst_port = query_states[id].local_port; | ||
552 | 576 | ||
553 | struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data; | 577 | answer->pkt.to = query_states[id].local_ip; |
578 | answer->pkt.dst_port = query_states[id].local_port; | ||
554 | 579 | ||
555 | dpkt->s.id = id; | 580 | struct dns_pkt *dpkt = (struct dns_pkt *) answer->pkt.data; |
556 | dpkt->s.aa = 1; | ||
557 | dpkt->s.qr = 1; | ||
558 | dpkt->s.ra = 1; | ||
559 | dpkt->s.qdcount = htons(1); | ||
560 | dpkt->s.ancount = htons(1); | ||
561 | 581 | ||
562 | memcpy(dpkt->data, query_states[id].name, query_states[id].namelen); | 582 | dpkt->s.id = id; |
563 | GNUNET_free(query_states[id].name); | 583 | dpkt->s.aa = 1; |
584 | dpkt->s.qr = 1; | ||
585 | dpkt->s.ra = 1; | ||
586 | dpkt->s.qdcount = htons (1); | ||
587 | dpkt->s.ancount = htons (1); | ||
564 | 588 | ||
565 | struct dns_query_line* dque = (struct dns_query_line*)(dpkt->data+(query_states[id].namelen)); | 589 | memcpy (dpkt->data, query_states[id].name, query_states[id].namelen); |
566 | dque->type = htons(12); /* PTR */ | 590 | GNUNET_free (query_states[id].name); |
567 | dque->class = htons(1); /* IN */ | ||
568 | 591 | ||
569 | char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)); | 592 | struct dns_query_line *dque = |
570 | memcpy(anname, "\xc0\x0c", 2); | 593 | (struct dns_query_line *) (dpkt->data + (query_states[id].namelen)); |
594 | dque->type = htons (12); /* PTR */ | ||
595 | dque->class = htons (1); /* IN */ | ||
571 | 596 | ||
572 | struct dns_record_line *drec_data = (struct dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)+2); | 597 | char *anname = |
573 | drec_data->type = htons(12); /* AAAA */ | 598 | (char *) (dpkt->data + (query_states[id].namelen) + |
574 | drec_data->class = htons(1); /* IN */ | 599 | sizeof (struct dns_query_line)); |
575 | /* FIXME: read the TTL from block: | 600 | memcpy (anname, "\xc0\x0c", 2); |
576 | * GNUNET_TIME_absolute_get_remaining(rec->expiration_time) | ||
577 | * | ||
578 | * But how to get the seconds out of this? | ||
579 | */ | ||
580 | drec_data->ttl = htonl(3600); | ||
581 | 601 | ||
582 | /* Calculate at which offset in the packet the length of the name and the | 602 | struct dns_record_line *drec_data = |
583 | * name, it is filled in by the daemon-vpn */ | 603 | (struct dns_record_line *) (dpkt->data + (query_states[id].namelen) + |
584 | answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data_len)-(unsigned long)(&answer->pkt))); | 604 | sizeof (struct dns_query_line) + 2); |
605 | drec_data->type = htons (12); /* AAAA */ | ||
606 | drec_data->class = htons (1); /* IN */ | ||
607 | /* FIXME: read the TTL from block: | ||
608 | * GNUNET_TIME_absolute_get_remaining(rec->expiration_time) | ||
609 | * | ||
610 | * But how to get the seconds out of this? | ||
611 | */ | ||
612 | drec_data->ttl = htonl (3600); | ||
613 | |||
614 | /* Calculate at which offset in the packet the length of the name and the | ||
615 | * name, it is filled in by the daemon-vpn */ | ||
616 | answer->pkt.addroffset = | ||
617 | htons ((unsigned short) ((unsigned long) (&drec_data->data_len) - | ||
618 | (unsigned long) (&answer->pkt))); | ||
585 | 619 | ||
586 | GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer); | 620 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); |
587 | 621 | ||
588 | GNUNET_SERVER_notify_transmit_ready(query_states[id].client, | 622 | GNUNET_SERVER_notify_transmit_ready (query_states[id].client, |
589 | len, | 623 | len, |
590 | GNUNET_TIME_UNIT_FOREVER_REL, | 624 | GNUNET_TIME_UNIT_FOREVER_REL, |
591 | &send_answer, | 625 | &send_answer, query_states[id].client); |
592 | query_states[id].client); | ||
593 | } | 626 | } |
594 | 627 | ||
595 | /** | 628 | /** |
596 | * Receive a block from the dht. | 629 | * Receive a block from the dht. |
597 | */ | 630 | */ |
598 | static void | 631 | static void |
599 | receive_dht(void *cls, | 632 | receive_dht (void *cls, |
600 | struct GNUNET_TIME_Absolute exp __attribute__((unused)), | 633 | struct GNUNET_TIME_Absolute exp __attribute__ ((unused)), |
601 | const GNUNET_HashCode *key __attribute__((unused)), | 634 | const GNUNET_HashCode * key __attribute__ ((unused)), |
602 | const struct GNUNET_PeerIdentity *const *get_path __attribute__((unused)), | 635 | const struct GNUNET_PeerIdentity *const *get_path |
603 | const struct GNUNET_PeerIdentity *const *put_path __attribute__((unused)), | 636 | __attribute__ ((unused)), |
604 | enum GNUNET_BLOCK_Type type, | 637 | const struct GNUNET_PeerIdentity *const *put_path |
605 | size_t size, | 638 | __attribute__ ((unused)), enum GNUNET_BLOCK_Type type, size_t size, |
606 | const void *data) { | 639 | const void *data) |
607 | 640 | { | |
608 | unsigned short id = ((struct receive_dht_cls*)cls)->id; | 641 | |
609 | struct GNUNET_DHT_GetHandle* handle = ((struct receive_dht_cls*)cls)->handle; | 642 | unsigned short id = ((struct receive_dht_cls *) cls)->id; |
610 | GNUNET_free(cls); | 643 | struct GNUNET_DHT_GetHandle *handle = |
611 | 644 | ((struct receive_dht_cls *) cls)->handle; | |
612 | GNUNET_assert(type == GNUNET_BLOCK_TYPE_DNS); | 645 | GNUNET_free (cls); |
613 | 646 | ||
614 | /* If no query with this id is pending, ignore the block */ | 647 | GNUNET_assert (type == GNUNET_BLOCK_TYPE_DNS); |
615 | if (query_states[id].valid != GNUNET_YES) return; | 648 | |
616 | query_states[id].valid = GNUNET_NO; | 649 | /* If no query with this id is pending, ignore the block */ |
617 | 650 | if (query_states[id].valid != GNUNET_YES) | |
618 | const struct GNUNET_DNS_Record* rec = data; | 651 | return; |
619 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 652 | query_states[id].valid = GNUNET_NO; |
620 | "Got block of size %d, peer: %08x, desc: %08x\n", | 653 | |
621 | size, | 654 | const struct GNUNET_DNS_Record *rec = data; |
622 | *((unsigned int*)&rec->peer), | 655 | |
623 | *((unsigned int*)&rec->service_descriptor)); | 656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
624 | 657 | "Got block of size %d, peer: %08x, desc: %08x\n", | |
625 | size_t len = sizeof(struct answer_packet) - 1 \ | 658 | size, |
626 | + sizeof(struct dns_static) \ | 659 | *((unsigned int *) &rec->peer), |
627 | + query_states[id].namelen \ | 660 | *((unsigned int *) &rec->service_descriptor)); |
628 | + sizeof(struct dns_query_line) \ | 661 | |
629 | + 2 /* To hold the pointer (as defined in RFC1035) to the name */ \ | 662 | size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + query_states[id].namelen + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as defined in RFC1035) to the name */ |
630 | + sizeof(struct dns_record_line) - 1 \ | 663 | + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ |
631 | + 16; /* To hold the IPv6-Address */ | ||
632 | |||
633 | struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct answer_packet_list*)); | ||
634 | memset(answer, 0, len + 2*sizeof(struct answer_packet_list*)); | ||
635 | |||
636 | answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | ||
637 | answer->pkt.hdr.size = htons(len); | ||
638 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_SERVICE; | ||
639 | |||
640 | GNUNET_CRYPTO_hash(&rec->peer, | ||
641 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
642 | &answer->pkt.service_descr.peer); | ||
643 | |||
644 | memcpy(&answer->pkt.service_descr.service_descriptor, | ||
645 | &rec->service_descriptor, | ||
646 | sizeof(GNUNET_HashCode)); | ||
647 | memcpy(&answer->pkt.service_descr.service_type, | ||
648 | &rec->service_type, | ||
649 | sizeof(answer->pkt.service_descr.service_type)); | ||
650 | memcpy(&answer->pkt.service_descr.ports, &rec->ports, sizeof(answer->pkt.service_descr.ports)); | ||
651 | |||
652 | answer->pkt.from = query_states[id].remote_ip; | ||
653 | |||
654 | answer->pkt.to = query_states[id].local_ip; | ||
655 | answer->pkt.dst_port = query_states[id].local_port; | ||
656 | |||
657 | struct dns_pkt *dpkt = (struct dns_pkt*)answer->pkt.data; | ||
658 | |||
659 | dpkt->s.id = id; | ||
660 | dpkt->s.aa = 1; | ||
661 | dpkt->s.qr = 1; | ||
662 | dpkt->s.ra = 1; | ||
663 | dpkt->s.qdcount = htons(1); | ||
664 | dpkt->s.ancount = htons(1); | ||
665 | |||
666 | memcpy(dpkt->data, query_states[id].name, query_states[id].namelen); | ||
667 | GNUNET_free(query_states[id].name); | ||
668 | |||
669 | struct dns_query_line* dque = (struct dns_query_line*)(dpkt->data+(query_states[id].namelen)); | ||
670 | dque->type = htons(28); /* AAAA */ | ||
671 | dque->class = htons(1); /* IN */ | ||
672 | |||
673 | char* anname = (char*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)); | ||
674 | memcpy(anname, "\xc0\x0c", 2); | ||
675 | |||
676 | struct dns_record_line *drec_data = (struct dns_record_line*)(dpkt->data+(query_states[id].namelen)+sizeof(struct dns_query_line)+2); | ||
677 | drec_data->type = htons(28); /* AAAA */ | ||
678 | drec_data->class = htons(1); /* IN */ | ||
679 | |||
680 | /* FIXME: read the TTL from block: | ||
681 | * GNUNET_TIME_absolute_get_remaining(rec->expiration_time) | ||
682 | * | ||
683 | * But how to get the seconds out of this? | ||
684 | */ | ||
685 | drec_data->ttl = htonl(3600); | ||
686 | drec_data->data_len = htons(16); | ||
687 | 664 | ||
688 | /* Calculate at which offset in the packet the IPv6-Address belongs, it is | 665 | struct answer_packet_list *answer = |
689 | * filled in by the daemon-vpn */ | 666 | GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *)); |
690 | answer->pkt.addroffset = htons((unsigned short)((unsigned long)(&drec_data->data)-(unsigned long)(&answer->pkt))); | 667 | memset (answer, 0, len + 2 * sizeof (struct answer_packet_list *)); |
668 | |||
669 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | ||
670 | answer->pkt.hdr.size = htons (len); | ||
671 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_SERVICE; | ||
672 | |||
673 | GNUNET_CRYPTO_hash (&rec->peer, | ||
674 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
675 | &answer->pkt.service_descr.peer); | ||
676 | |||
677 | memcpy (&answer->pkt.service_descr.service_descriptor, | ||
678 | &rec->service_descriptor, sizeof (GNUNET_HashCode)); | ||
679 | memcpy (&answer->pkt.service_descr.service_type, | ||
680 | &rec->service_type, sizeof (answer->pkt.service_descr.service_type)); | ||
681 | memcpy (&answer->pkt.service_descr.ports, &rec->ports, | ||
682 | sizeof (answer->pkt.service_descr.ports)); | ||
683 | |||
684 | answer->pkt.from = query_states[id].remote_ip; | ||
685 | |||
686 | answer->pkt.to = query_states[id].local_ip; | ||
687 | answer->pkt.dst_port = query_states[id].local_port; | ||
688 | |||
689 | struct dns_pkt *dpkt = (struct dns_pkt *) answer->pkt.data; | ||
690 | |||
691 | dpkt->s.id = id; | ||
692 | dpkt->s.aa = 1; | ||
693 | dpkt->s.qr = 1; | ||
694 | dpkt->s.ra = 1; | ||
695 | dpkt->s.qdcount = htons (1); | ||
696 | dpkt->s.ancount = htons (1); | ||
691 | 697 | ||
692 | GNUNET_CONTAINER_DLL_insert_after(head, tail, tail, answer); | 698 | memcpy (dpkt->data, query_states[id].name, query_states[id].namelen); |
699 | GNUNET_free (query_states[id].name); | ||
693 | 700 | ||
694 | GNUNET_SERVER_notify_transmit_ready(query_states[id].client, | 701 | struct dns_query_line *dque = |
695 | len, | 702 | (struct dns_query_line *) (dpkt->data + (query_states[id].namelen)); |
696 | GNUNET_TIME_UNIT_FOREVER_REL, | 703 | dque->type = htons (28); /* AAAA */ |
697 | &send_answer, | 704 | dque->class = htons (1); /* IN */ |
698 | query_states[id].client); | 705 | |
706 | char *anname = | ||
707 | (char *) (dpkt->data + (query_states[id].namelen) + | ||
708 | sizeof (struct dns_query_line)); | ||
709 | memcpy (anname, "\xc0\x0c", 2); | ||
710 | |||
711 | struct dns_record_line *drec_data = | ||
712 | (struct dns_record_line *) (dpkt->data + (query_states[id].namelen) + | ||
713 | sizeof (struct dns_query_line) + 2); | ||
714 | drec_data->type = htons (28); /* AAAA */ | ||
715 | drec_data->class = htons (1); /* IN */ | ||
716 | |||
717 | /* FIXME: read the TTL from block: | ||
718 | * GNUNET_TIME_absolute_get_remaining(rec->expiration_time) | ||
719 | * | ||
720 | * But how to get the seconds out of this? | ||
721 | */ | ||
722 | drec_data->ttl = htonl (3600); | ||
723 | drec_data->data_len = htons (16); | ||
724 | |||
725 | /* Calculate at which offset in the packet the IPv6-Address belongs, it is | ||
726 | * filled in by the daemon-vpn */ | ||
727 | answer->pkt.addroffset = | ||
728 | htons ((unsigned short) ((unsigned long) (&drec_data->data) - | ||
729 | (unsigned long) (&answer->pkt))); | ||
730 | |||
731 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); | ||
732 | |||
733 | GNUNET_SERVER_notify_transmit_ready (query_states[id].client, | ||
734 | len, | ||
735 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
736 | &send_answer, query_states[id].client); | ||
699 | 737 | ||
700 | GNUNET_DHT_get_stop(handle); | 738 | GNUNET_DHT_get_stop (handle); |
701 | } | 739 | } |
702 | 740 | ||
703 | /** | 741 | /** |
704 | * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS | 742 | * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS |
705 | */ | 743 | */ |
706 | static void | 744 | static void |
707 | rehijack(void *cls __attribute__((unused)), | 745 | rehijack (void *cls __attribute__ ((unused)), |
708 | struct GNUNET_SERVER_Client *client, | 746 | struct GNUNET_SERVER_Client *client, |
709 | const struct GNUNET_MessageHeader *message __attribute__((unused))) { | 747 | const struct GNUNET_MessageHeader *message __attribute__ ((unused))) |
710 | unhijack(dnsoutport); | 748 | { |
711 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, hijack, NULL); | 749 | unhijack (dnsoutport); |
750 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL); | ||
712 | 751 | ||
713 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 752 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
714 | } | 753 | } |
715 | 754 | ||
716 | /** | 755 | /** |
717 | * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket | 756 | * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket |
718 | */ | 757 | */ |
719 | static void | 758 | static void |
720 | receive_query(void *cls __attribute__((unused)), | 759 | receive_query (void *cls __attribute__ ((unused)), |
721 | struct GNUNET_SERVER_Client *client, | 760 | struct GNUNET_SERVER_Client *client, |
722 | const struct GNUNET_MessageHeader *message) { | 761 | const struct GNUNET_MessageHeader *message) |
723 | struct query_packet* pkt = (struct query_packet*)message; | 762 | { |
724 | struct dns_pkt* dns = (struct dns_pkt*)pkt->data; | 763 | struct query_packet *pkt = (struct query_packet *) message; |
725 | struct dns_pkt_parsed* pdns = parse_dns_packet(dns); | 764 | struct dns_pkt *dns = (struct dns_pkt *) pkt->data; |
726 | 765 | struct dns_pkt_parsed *pdns = parse_dns_packet (dns); | |
727 | query_states[dns->s.id].valid = GNUNET_YES; | ||
728 | query_states[dns->s.id].client = client; | ||
729 | query_states[dns->s.id].local_ip = pkt->orig_from; | ||
730 | query_states[dns->s.id].local_port = pkt->src_port; | ||
731 | query_states[dns->s.id].remote_ip = pkt->orig_to; | ||
732 | query_states[dns->s.id].namelen = strlen((char*)dns->data) + 1; | ||
733 | if (query_states[dns->s.id].name != NULL) | ||
734 | GNUNET_free(query_states[dns->s.id].name); | ||
735 | query_states[dns->s.id].name = GNUNET_malloc(query_states[dns->s.id].namelen); | ||
736 | memcpy(query_states[dns->s.id].name, dns->data, query_states[dns->s.id].namelen); | ||
737 | |||
738 | /* The query is for a .gnunet-address */ | ||
739 | if (pdns->queries[0]->namelen > 9 && | ||
740 | 0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - 9), ".gnunet.", 9)) | ||
741 | { | ||
742 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n"); | ||
743 | GNUNET_HashCode key; | ||
744 | GNUNET_CRYPTO_hash(pdns->queries[0]->name, pdns->queries[0]->namelen, &key); | ||
745 | |||
746 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
747 | "Getting with key %08x, len is %d\n", | ||
748 | *((unsigned int*)&key), | ||
749 | pdns->queries[0]->namelen); | ||
750 | |||
751 | struct receive_dht_cls* cls = GNUNET_malloc(sizeof(struct receive_dht_cls)); | ||
752 | cls->id = dns->s.id; | ||
753 | |||
754 | cls->handle = GNUNET_DHT_get_start(dht, | ||
755 | GNUNET_TIME_UNIT_MINUTES, | ||
756 | GNUNET_BLOCK_TYPE_DNS, | ||
757 | &key, | ||
758 | DEFAULT_GET_REPLICATION, | ||
759 | GNUNET_DHT_RO_NONE, | ||
760 | NULL, | ||
761 | 0, | ||
762 | NULL, | ||
763 | 0, | ||
764 | receive_dht, | ||
765 | cls); | ||
766 | |||
767 | goto outfree; | ||
768 | } | ||
769 | 766 | ||
770 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for '%s'; namelen=%d\n", pdns->queries[0]->name, pdns->queries[0]->namelen); | 767 | query_states[dns->s.id].valid = GNUNET_YES; |
768 | query_states[dns->s.id].client = client; | ||
769 | query_states[dns->s.id].local_ip = pkt->orig_from; | ||
770 | query_states[dns->s.id].local_port = pkt->src_port; | ||
771 | query_states[dns->s.id].remote_ip = pkt->orig_to; | ||
772 | query_states[dns->s.id].namelen = strlen ((char *) dns->data) + 1; | ||
773 | if (query_states[dns->s.id].name != NULL) | ||
774 | GNUNET_free (query_states[dns->s.id].name); | ||
775 | query_states[dns->s.id].name = | ||
776 | GNUNET_malloc (query_states[dns->s.id].namelen); | ||
777 | memcpy (query_states[dns->s.id].name, dns->data, | ||
778 | query_states[dns->s.id].namelen); | ||
771 | 779 | ||
772 | /* This is a PTR-Query. Check if it is for "our" network */ | 780 | /* The query is for a .gnunet-address */ |
773 | if (htons(pdns->queries[0]->qtype) == 12 && | 781 | if (pdns->queries[0]->namelen > 9 && |
774 | 74 == pdns->queries[0]->namelen) | 782 | 0 == strncmp (pdns->queries[0]->name + (pdns->queries[0]->namelen - 9), |
775 | { | 783 | ".gnunet.", 9)) |
776 | char* ipv6addr; | 784 | { |
777 | char ipv6[16]; | 785 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n"); |
778 | char ipv6rev[74] = "X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.ip6.arpa."; | 786 | GNUNET_HashCode key; |
779 | unsigned int i; | ||
780 | unsigned long long ipv6prefix; | ||
781 | unsigned int comparelen; | ||
782 | |||
783 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "vpn", "IPV6ADDR", &ipv6addr)); | ||
784 | inet_pton (AF_INET6, ipv6addr, ipv6); | ||
785 | GNUNET_free(ipv6addr); | ||
786 | |||
787 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "vpn", "IPV6PREFIX", &ipv6prefix)); | ||
788 | GNUNET_assert(ipv6prefix < 127); | ||
789 | ipv6prefix = (ipv6prefix + 7)/8; | ||
790 | |||
791 | for (i = ipv6prefix; i < 16; i++) | ||
792 | ipv6[i] = 0; | ||
793 | |||
794 | for (i = 0; i < 16; i++) | ||
795 | { | ||
796 | unsigned char c1 = ipv6[i] >> 4; | ||
797 | unsigned char c2 = ipv6[i] & 0xf; | ||
798 | |||
799 | if (c1 <= 9) | ||
800 | ipv6rev[62-(4*i)] = c1 + '0'; | ||
801 | else | ||
802 | ipv6rev[62-(4*i)] = c1 + 87; /* 87 is the difference between 'a' and 10 */ | ||
803 | |||
804 | if (c2 <= 9) | ||
805 | ipv6rev[62-((4*i)+2)] = c2 + '0'; | ||
806 | else | ||
807 | ipv6rev[62-((4*i)+2)] = c2 + 87; | ||
808 | } | ||
809 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "My network is %s'.\n", ipv6rev); | ||
810 | comparelen = 10 + 4*ipv6prefix; | ||
811 | if(0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - comparelen), | ||
812 | ipv6rev + (74 - comparelen), | ||
813 | comparelen)) | ||
814 | { | ||
815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Reverse-Query for .gnunet!\n"); | ||
816 | |||
817 | GNUNET_SCHEDULER_add_now(send_rev_query, pdns); | ||
818 | |||
819 | goto out; | ||
820 | } | ||
821 | } | ||
822 | 787 | ||
823 | char* virt_dns; | 788 | GNUNET_CRYPTO_hash (pdns->queries[0]->name, pdns->queries[0]->namelen, |
824 | unsigned int virt_dns_bytes; | 789 | &key); |
825 | if (GNUNET_SYSERR == | ||
826 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", | ||
827 | &virt_dns)) | ||
828 | { | ||
829 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
830 | "No entry 'VIRTDNS' in configuration!\n"); | ||
831 | exit (1); | ||
832 | } | ||
833 | 790 | ||
834 | if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) | 791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
835 | { | 792 | "Getting with key %08x, len is %d\n", |
836 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 793 | *((unsigned int *) &key), pdns->queries[0]->namelen); |
837 | "Error parsing 'VIRTDNS': %s; %m!\n", virt_dns); | ||
838 | exit(1); | ||
839 | } | ||
840 | 794 | ||
841 | GNUNET_free(virt_dns); | 795 | struct receive_dht_cls *cls = |
796 | GNUNET_malloc (sizeof (struct receive_dht_cls)); | ||
797 | cls->id = dns->s.id; | ||
842 | 798 | ||
843 | if (virt_dns_bytes == pkt->orig_to) | 799 | cls->handle = GNUNET_DHT_get_start (dht, |
844 | { | 800 | GNUNET_TIME_UNIT_MINUTES, |
845 | /* This is a packet that was sent directly to the virtual dns-server | 801 | GNUNET_BLOCK_TYPE_DNS, |
846 | * | 802 | &key, |
847 | * This means we have to send this query over gnunet | 803 | DEFAULT_GET_REPLICATION, |
848 | */ | 804 | GNUNET_DHT_RO_NONE, |
805 | NULL, 0, NULL, 0, receive_dht, cls); | ||
849 | 806 | ||
850 | size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + (ntohs(message->size) - sizeof(struct query_packet) + 1); | 807 | goto outfree; |
851 | struct tunnel_cls *cls_ = GNUNET_malloc(size); | 808 | } |
852 | cls_->hdr.size = size - sizeof(struct GNUNET_MESH_Tunnel*); | ||
853 | 809 | ||
854 | cls_->hdr.type = ntohs(GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS); | 810 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Query for '%s'; namelen=%d\n", |
855 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size); | 811 | pdns->queries[0]->name, pdns->queries[0]->namelen); |
856 | 812 | ||
857 | memcpy(&cls_->dns, dns, cls_->hdr.size - sizeof(struct GNUNET_MessageHeader)); | 813 | /* This is a PTR-Query. Check if it is for "our" network */ |
858 | GNUNET_SCHEDULER_add_now(send_mesh_query, cls_); | 814 | if (htons (pdns->queries[0]->qtype) == 12 && 74 == pdns->queries[0]->namelen) |
815 | { | ||
816 | char *ipv6addr; | ||
817 | char ipv6[16]; | ||
818 | char ipv6rev[74] = | ||
819 | "X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.X.ip6.arpa."; | ||
820 | unsigned int i; | ||
821 | unsigned long long ipv6prefix; | ||
822 | unsigned int comparelen; | ||
823 | |||
824 | GNUNET_assert (GNUNET_OK == | ||
825 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", | ||
826 | "IPV6ADDR", | ||
827 | &ipv6addr)); | ||
828 | inet_pton (AF_INET6, ipv6addr, ipv6); | ||
829 | GNUNET_free (ipv6addr); | ||
830 | |||
831 | GNUNET_assert (GNUNET_OK == | ||
832 | GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", | ||
833 | "IPV6PREFIX", | ||
834 | &ipv6prefix)); | ||
835 | GNUNET_assert (ipv6prefix < 127); | ||
836 | ipv6prefix = (ipv6prefix + 7) / 8; | ||
837 | |||
838 | for (i = ipv6prefix; i < 16; i++) | ||
839 | ipv6[i] = 0; | ||
840 | |||
841 | for (i = 0; i < 16; i++) | ||
842 | { | ||
843 | unsigned char c1 = ipv6[i] >> 4; | ||
844 | unsigned char c2 = ipv6[i] & 0xf; | ||
845 | |||
846 | if (c1 <= 9) | ||
847 | ipv6rev[62 - (4 * i)] = c1 + '0'; | ||
848 | else | ||
849 | ipv6rev[62 - (4 * i)] = c1 + 87; /* 87 is the difference between 'a' and 10 */ | ||
850 | |||
851 | if (c2 <= 9) | ||
852 | ipv6rev[62 - ((4 * i) + 2)] = c2 + '0'; | ||
853 | else | ||
854 | ipv6rev[62 - ((4 * i) + 2)] = c2 + 87; | ||
855 | } | ||
856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "My network is %s'.\n", ipv6rev); | ||
857 | comparelen = 10 + 4 * ipv6prefix; | ||
858 | if (0 == | ||
859 | strncmp (pdns->queries[0]->name + | ||
860 | (pdns->queries[0]->namelen - comparelen), | ||
861 | ipv6rev + (74 - comparelen), comparelen)) | ||
862 | { | ||
863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reverse-Query for .gnunet!\n"); | ||
859 | 864 | ||
860 | goto outfree; | 865 | GNUNET_SCHEDULER_add_now (send_rev_query, pdns); |
861 | } | ||
862 | 866 | ||
867 | goto out; | ||
868 | } | ||
869 | } | ||
863 | 870 | ||
864 | /* The query should be sent to the network */ | 871 | char *virt_dns; |
872 | unsigned int virt_dns_bytes; | ||
865 | 873 | ||
866 | struct sockaddr_in dest; | 874 | if (GNUNET_SYSERR == |
867 | memset(&dest, 0, sizeof dest); | 875 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns)) |
868 | dest.sin_port = htons(53); | 876 | { |
869 | dest.sin_addr.s_addr = pkt->orig_to; | 877 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
878 | "No entry 'VIRTDNS' in configuration!\n"); | ||
879 | exit (1); | ||
880 | } | ||
870 | 881 | ||
871 | GNUNET_NETWORK_socket_sendto(dnsout, | 882 | if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) |
872 | dns, | 883 | { |
873 | ntohs(pkt->hdr.size) - sizeof(struct query_packet) + 1, | 884 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
874 | (struct sockaddr*) &dest, | 885 | "Error parsing 'VIRTDNS': %s; %m!\n", virt_dns); |
875 | sizeof dest); | 886 | exit (1); |
887 | } | ||
888 | |||
889 | GNUNET_free (virt_dns); | ||
890 | |||
891 | if (virt_dns_bytes == pkt->orig_to) | ||
892 | { | ||
893 | /* This is a packet that was sent directly to the virtual dns-server | ||
894 | * | ||
895 | * This means we have to send this query over gnunet | ||
896 | */ | ||
897 | |||
898 | size_t size = | ||
899 | sizeof (struct GNUNET_MESH_Tunnel *) + | ||
900 | sizeof (struct GNUNET_MessageHeader) + (ntohs (message->size) - | ||
901 | sizeof (struct query_packet) + | ||
902 | 1); | ||
903 | struct tunnel_cls *cls_ = GNUNET_malloc (size); | ||
904 | |||
905 | cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *); | ||
906 | |||
907 | cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS); | ||
908 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size); | ||
909 | |||
910 | memcpy (&cls_->dns, dns, | ||
911 | cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); | ||
912 | GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); | ||
913 | |||
914 | goto outfree; | ||
915 | } | ||
916 | |||
917 | |||
918 | /* The query should be sent to the network */ | ||
919 | |||
920 | struct sockaddr_in dest; | ||
921 | |||
922 | memset (&dest, 0, sizeof dest); | ||
923 | dest.sin_port = htons (53); | ||
924 | dest.sin_addr.s_addr = pkt->orig_to; | ||
925 | |||
926 | GNUNET_NETWORK_socket_sendto (dnsout, | ||
927 | dns, | ||
928 | ntohs (pkt->hdr.size) - | ||
929 | sizeof (struct query_packet) + 1, | ||
930 | (struct sockaddr *) &dest, sizeof dest); | ||
876 | 931 | ||
877 | outfree: | 932 | outfree: |
878 | free_parsed_dns_packet(pdns); | 933 | free_parsed_dns_packet (pdns); |
879 | pdns = NULL; | 934 | pdns = NULL; |
880 | out: | 935 | out: |
881 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 936 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
882 | } | 937 | } |
883 | 938 | ||
884 | static void read_response (void *cls, | 939 | static void read_response (void *cls, |
@@ -900,14 +955,14 @@ open_port () | |||
900 | sizeof (struct sockaddr_in)); | 955 | sizeof (struct sockaddr_in)); |
901 | 956 | ||
902 | if (err != GNUNET_OK) | 957 | if (err != GNUNET_OK) |
903 | { | 958 | { |
904 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 959 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not bind a port: %m\n"); |
905 | "Could not bind a port: %m\n"); | 960 | return GNUNET_SYSERR; |
906 | return GNUNET_SYSERR; | 961 | } |
907 | } | ||
908 | 962 | ||
909 | /* Read the port we bound to */ | 963 | /* Read the port we bound to */ |
910 | socklen_t addrlen = sizeof (struct sockaddr_in); | 964 | socklen_t addrlen = sizeof (struct sockaddr_in); |
965 | |||
911 | err = getsockname (GNUNET_NETWORK_get_fd (dnsout), | 966 | err = getsockname (GNUNET_NETWORK_get_fd (dnsout), |
912 | (struct sockaddr *) &addr, &addrlen); | 967 | (struct sockaddr *) &addr, &addrlen); |
913 | 968 | ||
@@ -941,12 +996,12 @@ read_response (void *cls | |||
941 | 996 | ||
942 | #ifndef MINGW | 997 | #ifndef MINGW |
943 | if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len)) | 998 | if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len)) |
944 | { | 999 | { |
945 | unhijack (dnsoutport); | 1000 | unhijack (dnsoutport); |
946 | if (GNUNET_YES == open_port ()) | 1001 | if (GNUNET_YES == open_port ()) |
947 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL); | 1002 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL); |
948 | return; | 1003 | return; |
949 | } | 1004 | } |
950 | #else | 1005 | #else |
951 | /* port the code above? */ | 1006 | /* port the code above? */ |
952 | len = 65536; | 1007 | len = 65536; |
@@ -961,83 +1016,90 @@ read_response (void *cls | |||
961 | (struct sockaddr *) &addr, &addrlen); | 1016 | (struct sockaddr *) &addr, &addrlen); |
962 | 1017 | ||
963 | if (r < 0) | 1018 | if (r < 0) |
964 | { | 1019 | { |
965 | unhijack (dnsoutport); | 1020 | unhijack (dnsoutport); |
966 | if (GNUNET_YES == open_port ()) | 1021 | if (GNUNET_YES == open_port ()) |
967 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL); | 1022 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL); |
968 | return; | 1023 | return; |
969 | } | 1024 | } |
970 | 1025 | ||
971 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n", ntohs(dns->s.id)); | 1026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n", |
1027 | ntohs (dns->s.id)); | ||
972 | 1028 | ||
973 | if (query_states[dns->s.id].valid == GNUNET_YES) | 1029 | if (query_states[dns->s.id].valid == GNUNET_YES) |
1030 | { | ||
1031 | if (query_states[dns->s.id].tunnel != NULL) | ||
974 | { | 1032 | { |
975 | if (query_states[dns->s.id].tunnel != NULL) | 1033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
976 | { | 1034 | "Answer to query %d for a remote peer!\n", |
977 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d for a remote peer!\n", ntohs(dns->s.id)); | 1035 | ntohs (dns->s.id)); |
978 | /* This response should go through a tunnel */ | 1036 | /* This response should go through a tunnel */ |
979 | uint32_t *c = GNUNET_malloc (4 + sizeof(struct GNUNET_MESH_Tunnel*) + r); | 1037 | uint32_t *c = |
980 | *c = r; | 1038 | GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r); |
981 | struct GNUNET_MESH_Tunnel** t = (struct GNUNET_MESH_Tunnel**)(c + 1); | 1039 | *c = r; |
982 | *t = query_states[dns->s.id].tunnel; | 1040 | struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1); |
983 | memcpy (t + 1, dns, r); | 1041 | |
984 | if (NULL == | 1042 | *t = query_states[dns->s.id].tunnel; |
985 | GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel)) | 1043 | memcpy (t + 1, dns, r); |
986 | { | 1044 | if (NULL == |
987 | struct GNUNET_MESH_TransmitHandle *th = | 1045 | GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel)) |
988 | GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, | 1046 | { |
989 | GNUNET_YES, | 1047 | struct GNUNET_MESH_TransmitHandle *th = |
990 | 32, | 1048 | GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, |
991 | GNUNET_TIME_UNIT_MINUTES, | 1049 | GNUNET_YES, |
992 | NULL, | 1050 | 32, |
993 | r + | 1051 | GNUNET_TIME_UNIT_MINUTES, |
994 | sizeof (struct | 1052 | NULL, |
995 | GNUNET_MessageHeader), | 1053 | r + |
996 | mesh_send_response, c); | 1054 | sizeof (struct |
997 | GNUNET_MESH_tunnel_set_data (query_states[dns->s.id].tunnel, | 1055 | GNUNET_MessageHeader), |
998 | th); | 1056 | mesh_send_response, c); |
999 | } | 1057 | |
1000 | else | 1058 | GNUNET_MESH_tunnel_set_data (query_states[dns->s.id].tunnel, th); |
1001 | { | 1059 | } |
1002 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(query_states[dns->s.id].tunnel); | ||
1003 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(query_states[dns->s.id].tunnel); | ||
1004 | |||
1005 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue)); | ||
1006 | element->cls = c; | ||
1007 | element->len = r+sizeof(struct GNUNET_MessageHeader); | ||
1008 | element->cb = mesh_send_response; | ||
1009 | |||
1010 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | ||
1011 | GNUNET_MESH_tunnel_set_head(query_states[dns->s.id].tunnel, head); | ||
1012 | GNUNET_MESH_tunnel_set_tail(query_states[dns->s.id].tunnel, tail); | ||
1013 | } | ||
1014 | } | ||
1015 | else | 1060 | else |
1016 | { | 1061 | { |
1017 | query_states[dns->s.id].valid = GNUNET_NO; | 1062 | struct tunnel_notify_queue *head = |
1018 | 1063 | GNUNET_MESH_tunnel_get_head (query_states[dns->s.id].tunnel); | |
1019 | size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */ | 1064 | struct tunnel_notify_queue *tail = |
1020 | struct answer_packet_list *answer = | 1065 | GNUNET_MESH_tunnel_get_tail (query_states[dns->s.id].tunnel); |
1021 | GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *)); | 1066 | |
1022 | answer->pkt.hdr.type = | 1067 | struct tunnel_notify_queue *element = |
1023 | htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | 1068 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); |
1024 | answer->pkt.hdr.size = htons (len); | 1069 | element->cls = c; |
1025 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP; | 1070 | element->len = r + sizeof (struct GNUNET_MessageHeader); |
1026 | answer->pkt.from = addr.sin_addr.s_addr; | 1071 | element->cb = mesh_send_response; |
1027 | answer->pkt.to = query_states[dns->s.id].local_ip; | 1072 | |
1028 | answer->pkt.dst_port = query_states[dns->s.id].local_port; | 1073 | GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); |
1029 | memcpy (answer->pkt.data, buf, r); | 1074 | GNUNET_MESH_tunnel_set_head (query_states[dns->s.id].tunnel, head); |
1030 | 1075 | GNUNET_MESH_tunnel_set_tail (query_states[dns->s.id].tunnel, tail); | |
1031 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); | 1076 | } |
1032 | 1077 | } | |
1033 | GNUNET_SERVER_notify_transmit_ready (query_states | 1078 | else |
1034 | [dns->s.id].client, len, | 1079 | { |
1035 | GNUNET_TIME_UNIT_FOREVER_REL, | 1080 | query_states[dns->s.id].valid = GNUNET_NO; |
1036 | &send_answer, | 1081 | |
1037 | query_states[dns->s. | 1082 | size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */ |
1038 | id].client); | 1083 | struct answer_packet_list *answer = |
1039 | } | 1084 | GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *)); |
1085 | answer->pkt.hdr.type = | ||
1086 | htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | ||
1087 | answer->pkt.hdr.size = htons (len); | ||
1088 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP; | ||
1089 | answer->pkt.from = addr.sin_addr.s_addr; | ||
1090 | answer->pkt.to = query_states[dns->s.id].local_ip; | ||
1091 | answer->pkt.dst_port = query_states[dns->s.id].local_port; | ||
1092 | memcpy (answer->pkt.data, buf, r); | ||
1093 | |||
1094 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); | ||
1095 | |||
1096 | GNUNET_SERVER_notify_transmit_ready (query_states | ||
1097 | [dns->s.id].client, len, | ||
1098 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1099 | &send_answer, | ||
1100 | query_states[dns->s.id].client); | ||
1040 | } | 1101 | } |
1102 | } | ||
1041 | } | 1103 | } |
1042 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1104 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1043 | dnsout, &read_response, NULL); | 1105 | dnsout, &read_response, NULL); |
@@ -1051,14 +1113,14 @@ read_response (void *cls | |||
1051 | * @param tc unused | 1113 | * @param tc unused |
1052 | */ | 1114 | */ |
1053 | static void | 1115 | static void |
1054 | cleanup_task (void *cls __attribute__((unused)), | 1116 | cleanup_task (void *cls __attribute__ ((unused)), |
1055 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1117 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1056 | { | 1118 | { |
1057 | GNUNET_assert(0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); | 1119 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); |
1058 | 1120 | ||
1059 | unhijack(dnsoutport); | 1121 | unhijack (dnsoutport); |
1060 | GNUNET_DHT_disconnect(dht); | 1122 | GNUNET_DHT_disconnect (dht); |
1061 | GNUNET_MESH_disconnect(mesh_handle); | 1123 | GNUNET_MESH_disconnect (mesh_handle); |
1062 | } | 1124 | } |
1063 | 1125 | ||
1064 | /** | 1126 | /** |
@@ -1073,70 +1135,78 @@ uint64_t | |||
1073 | get_port_from_redirects (const char *udp_redirects, const char *tcp_redirects) | 1135 | get_port_from_redirects (const char *udp_redirects, const char *tcp_redirects) |
1074 | { | 1136 | { |
1075 | uint64_t ret = 0; | 1137 | uint64_t ret = 0; |
1076 | char* cpy, *hostname, *redirect; | 1138 | char *cpy, *hostname, *redirect; |
1077 | int local_port, count = 0; | 1139 | int local_port, count = 0; |
1078 | 1140 | ||
1079 | if (NULL != udp_redirects) | 1141 | if (NULL != udp_redirects) |
1142 | { | ||
1143 | cpy = GNUNET_strdup (udp_redirects); | ||
1144 | for (redirect = strtok (cpy, " "); redirect != NULL; | ||
1145 | redirect = strtok (NULL, " ")) | ||
1080 | { | 1146 | { |
1081 | cpy = GNUNET_strdup (udp_redirects); | 1147 | if (NULL == (hostname = strstr (redirect, ":"))) |
1082 | for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " ")) | 1148 | { |
1083 | { | 1149 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1084 | if (NULL == (hostname = strstr (redirect, ":"))) | 1150 | "Warning: option %s is not formatted correctly!\n", |
1085 | { | 1151 | redirect); |
1086 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", redirect); | 1152 | continue; |
1087 | continue; | 1153 | } |
1088 | } | 1154 | hostname[0] = '\0'; |
1089 | hostname[0] = '\0'; | 1155 | local_port = atoi (redirect); |
1090 | local_port = atoi (redirect); | 1156 | if (!((local_port > 0) && (local_port < 65536))) |
1091 | if (!((local_port > 0) && (local_port < 65536))) | 1157 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1092 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.", redirect); | 1158 | "Warning: %s is not a correct port.", redirect); |
1093 | 1159 | ||
1094 | ret |= (0xFFFF & htons(local_port)); | 1160 | ret |= (0xFFFF & htons (local_port)); |
1095 | ret <<= 16; | 1161 | ret <<= 16; |
1096 | count ++; | 1162 | count++; |
1097 | 1163 | ||
1098 | if(count > 4) | 1164 | if (count > 4) |
1099 | { | 1165 | { |
1100 | ret = 0; | 1166 | ret = 0; |
1101 | goto out; | 1167 | goto out; |
1102 | } | 1168 | } |
1103 | } | ||
1104 | GNUNET_free(cpy); | ||
1105 | cpy = NULL; | ||
1106 | } | 1169 | } |
1170 | GNUNET_free (cpy); | ||
1171 | cpy = NULL; | ||
1172 | } | ||
1107 | 1173 | ||
1108 | if (NULL != tcp_redirects) | 1174 | if (NULL != tcp_redirects) |
1175 | { | ||
1176 | cpy = GNUNET_strdup (tcp_redirects); | ||
1177 | for (redirect = strtok (cpy, " "); redirect != NULL; | ||
1178 | redirect = strtok (NULL, " ")) | ||
1109 | { | 1179 | { |
1110 | cpy = GNUNET_strdup (tcp_redirects); | 1180 | if (NULL == (hostname = strstr (redirect, ":"))) |
1111 | for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok (NULL, " ")) | 1181 | { |
1112 | { | 1182 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1113 | if (NULL == (hostname = strstr (redirect, ":"))) | 1183 | "Warning: option %s is not formatted correctly!\n", |
1114 | { | 1184 | redirect); |
1115 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", redirect); | 1185 | continue; |
1116 | continue; | 1186 | } |
1117 | } | 1187 | hostname[0] = '\0'; |
1118 | hostname[0] = '\0'; | 1188 | local_port = atoi (redirect); |
1119 | local_port = atoi (redirect); | 1189 | if (!((local_port > 0) && (local_port < 65536))) |
1120 | if (!((local_port > 0) && (local_port < 65536))) | 1190 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1121 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.", redirect); | 1191 | "Warning: %s is not a correct port.", redirect); |
1122 | 1192 | ||
1123 | ret |= (0xFFFF & htons(local_port)); | 1193 | ret |= (0xFFFF & htons (local_port)); |
1124 | ret <<= 16; | 1194 | ret <<= 16; |
1125 | count ++; | 1195 | count++; |
1126 | 1196 | ||
1127 | if(count > 4) | 1197 | if (count > 4) |
1128 | { | 1198 | { |
1129 | ret = 0; | 1199 | ret = 0; |
1130 | goto out; | 1200 | goto out; |
1131 | } | 1201 | } |
1132 | } | ||
1133 | GNUNET_free(cpy); | ||
1134 | cpy = NULL; | ||
1135 | } | 1202 | } |
1203 | GNUNET_free (cpy); | ||
1204 | cpy = NULL; | ||
1205 | } | ||
1136 | 1206 | ||
1137 | out: | 1207 | out: |
1138 | if (NULL != cpy) | 1208 | if (NULL != cpy) |
1139 | GNUNET_free(cpy); | 1209 | GNUNET_free (cpy); |
1140 | return ret; | 1210 | return ret; |
1141 | } | 1211 | } |
1142 | 1212 | ||
@@ -1146,10 +1216,10 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, | |||
1146 | { | 1216 | { |
1147 | size_t size = sizeof (struct GNUNET_DNS_Record); | 1217 | size_t size = sizeof (struct GNUNET_DNS_Record); |
1148 | struct GNUNET_DNS_Record data; | 1218 | struct GNUNET_DNS_Record data; |
1219 | |||
1149 | memset (&data, 0, size); | 1220 | memset (&data, 0, size); |
1150 | 1221 | ||
1151 | data.purpose.size = | 1222 | data.purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
1152 | htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature)); | ||
1153 | data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD; | 1223 | data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD; |
1154 | 1224 | ||
1155 | GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor); | 1225 | GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor); |
@@ -1162,15 +1232,16 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, | |||
1162 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer); | 1232 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer); |
1163 | 1233 | ||
1164 | data.expiration_time = | 1234 | data.expiration_time = |
1165 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 2)); | 1235 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply |
1236 | (GNUNET_TIME_UNIT_HOURS, 2)); | ||
1166 | 1237 | ||
1167 | /* Sign the block */ | 1238 | /* Sign the block */ |
1168 | if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key, | 1239 | if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key, |
1169 | &data.purpose, &data.signature)) | 1240 | &data.purpose, &data.signature)) |
1170 | { | 1241 | { |
1171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); | 1242 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); |
1172 | return; | 1243 | return; |
1173 | } | 1244 | } |
1174 | 1245 | ||
1175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1176 | "Putting with key %08x, size = %d\n", | 1247 | "Putting with key %08x, size = %d\n", |
@@ -1194,15 +1265,16 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, | |||
1194 | * @param section the current section | 1265 | * @param section the current section |
1195 | */ | 1266 | */ |
1196 | void | 1267 | void |
1197 | publish_iterate (void *cls __attribute__((unused)), const char *section) | 1268 | publish_iterate (void *cls __attribute__ ((unused)), const char *section) |
1198 | { | 1269 | { |
1199 | if ((strlen(section) < 8) || (0 != strcmp (".gnunet.", section + (strlen(section) - 8)))) | 1270 | if ((strlen (section) < 8) || |
1271 | (0 != strcmp (".gnunet.", section + (strlen (section) - 8)))) | ||
1200 | return; | 1272 | return; |
1201 | 1273 | ||
1202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %s\n", section); | 1274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %s\n", section); |
1203 | 1275 | ||
1204 | char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name, | 1276 | char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name, |
1205 | *keyfile; | 1277 | *keyfile; |
1206 | 1278 | ||
1207 | GNUNET_CONFIGURATION_get_value_string (cfg, section, | 1279 | GNUNET_CONFIGURATION_get_value_string (cfg, section, |
1208 | "UDP_REDIRECTS", &udp_redirects); | 1280 | "UDP_REDIRECTS", &udp_redirects); |
@@ -1212,15 +1284,15 @@ publish_iterate (void *cls __attribute__((unused)), const char *section) | |||
1212 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", | 1284 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", |
1213 | "HOSTKEY", | 1285 | "HOSTKEY", |
1214 | &keyfile)) | 1286 | &keyfile)) |
1215 | { | 1287 | { |
1216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n"); | 1288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n"); |
1217 | if (keyfile != NULL) | 1289 | if (keyfile != NULL) |
1218 | GNUNET_free (keyfile); | 1290 | GNUNET_free (keyfile); |
1219 | return; | 1291 | return; |
1220 | } | 1292 | } |
1221 | 1293 | ||
1222 | struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key = | 1294 | struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key = |
1223 | GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 1295 | GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
1224 | GNUNET_free (keyfile); | 1296 | GNUNET_free (keyfile); |
1225 | GNUNET_assert (my_private_key != NULL); | 1297 | GNUNET_assert (my_private_key != NULL); |
1226 | 1298 | ||
@@ -1243,17 +1315,17 @@ publish_iterate (void *cls __attribute__((unused)), const char *section) | |||
1243 | &alternative_names); | 1315 | &alternative_names); |
1244 | for (alternative_name = strtok (alternative_names, " "); | 1316 | for (alternative_name = strtok (alternative_names, " "); |
1245 | alternative_name != NULL; alternative_name = strtok (NULL, " ")) | 1317 | alternative_name != NULL; alternative_name = strtok (NULL, " ")) |
1246 | { | 1318 | { |
1247 | char *altname = | 1319 | char *altname = |
1248 | alloca (strlen (alternative_name) + strlen (section) + 1 + 1); | 1320 | alloca (strlen (alternative_name) + strlen (section) + 1 + 1); |
1249 | strcpy (altname, alternative_name); | 1321 | strcpy (altname, alternative_name); |
1250 | strcpy (altname + strlen (alternative_name) + 1, section); | 1322 | strcpy (altname + strlen (alternative_name) + 1, section); |
1251 | altname[strlen (alternative_name)] = '.'; | 1323 | altname[strlen (alternative_name)] = '.'; |
1252 | 1324 | ||
1253 | publish_name (altname, ports, service_type, my_private_key); | 1325 | publish_name (altname, ports, service_type, my_private_key); |
1254 | } | 1326 | } |
1255 | 1327 | ||
1256 | GNUNET_free_non_null(alternative_names); | 1328 | GNUNET_free_non_null (alternative_names); |
1257 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | 1329 | GNUNET_CRYPTO_rsa_key_free (my_private_key); |
1258 | GNUNET_free_non_null (udp_redirects); | 1330 | GNUNET_free_non_null (udp_redirects); |
1259 | GNUNET_free_non_null (tcp_redirects); | 1331 | GNUNET_free_non_null (tcp_redirects); |
@@ -1263,16 +1335,15 @@ publish_iterate (void *cls __attribute__((unused)), const char *section) | |||
1263 | * Publish a DNS-record in the DHT. | 1335 | * Publish a DNS-record in the DHT. |
1264 | */ | 1336 | */ |
1265 | static void | 1337 | static void |
1266 | publish_names (void *cls __attribute__((unused)), | 1338 | publish_names (void *cls __attribute__ ((unused)), |
1267 | const struct GNUNET_SCHEDULER_TaskContext *tc) { | 1339 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1268 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1340 | { |
1269 | return; | 1341 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1342 | return; | ||
1270 | 1343 | ||
1271 | GNUNET_CONFIGURATION_iterate_sections(cfg, publish_iterate, NULL); | 1344 | GNUNET_CONFIGURATION_iterate_sections (cfg, publish_iterate, NULL); |
1272 | 1345 | ||
1273 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_HOURS, | 1346 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_HOURS, publish_names, NULL); |
1274 | publish_names, | ||
1275 | NULL); | ||
1276 | } | 1347 | } |
1277 | 1348 | ||
1278 | /** | 1349 | /** |
@@ -1299,35 +1370,31 @@ run (void *cls, | |||
1299 | {NULL, 0, 0} | 1370 | {NULL, 0, 0} |
1300 | }; | 1371 | }; |
1301 | 1372 | ||
1302 | static GNUNET_MESH_ApplicationType *apptypes; | 1373 | static GNUNET_MESH_ApplicationType apptypes[] = { |
1374 | GNUNET_APPLICATION_TYPE_END, | ||
1375 | GNUNET_APPLICATION_TYPE_END | ||
1376 | }; | ||
1377 | |||
1303 | 1378 | ||
1304 | if (GNUNET_YES != open_port ()) | 1379 | if (GNUNET_YES != open_port ()) |
1305 | { | 1380 | { |
1306 | GNUNET_SCHEDULER_shutdown(); | 1381 | GNUNET_SCHEDULER_shutdown (); |
1307 | return; | 1382 | return; |
1308 | } | 1383 | } |
1309 | 1384 | ||
1310 | if (GNUNET_YES == | 1385 | if (GNUNET_YES == |
1311 | GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) | 1386 | GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) |
1312 | apptypes = (GNUNET_MESH_ApplicationType[]) | 1387 | apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER; |
1313 | { | 1388 | mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers, apptypes); |
1314 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, | ||
1315 | GNUNET_APPLICATION_TYPE_END}; | ||
1316 | else | ||
1317 | apptypes = (GNUNET_MESH_ApplicationType[]) | ||
1318 | { | ||
1319 | GNUNET_APPLICATION_TYPE_END}; | ||
1320 | |||
1321 | mesh_handle = | ||
1322 | GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers, apptypes); | ||
1323 | 1389 | ||
1324 | cfg = cfg_; | 1390 | cfg = cfg_; |
1325 | 1391 | ||
1326 | unsigned int i; | 1392 | unsigned int i; |
1393 | |||
1327 | for (i = 0; i < 65536; i++) | 1394 | for (i = 0; i < 65536; i++) |
1328 | { | 1395 | { |
1329 | query_states[i].valid = GNUNET_NO; | 1396 | query_states[i].valid = GNUNET_NO; |
1330 | } | 1397 | } |
1331 | 1398 | ||
1332 | dht = GNUNET_DHT_connect (cfg, 1024); | 1399 | dht = GNUNET_DHT_connect (cfg, 1024); |
1333 | 1400 | ||
@@ -1349,9 +1416,8 @@ int | |||
1349 | main (int argc, char *const *argv) | 1416 | main (int argc, char *const *argv) |
1350 | { | 1417 | { |
1351 | return (GNUNET_OK == | 1418 | return (GNUNET_OK == |
1352 | GNUNET_SERVICE_run (argc, | 1419 | GNUNET_SERVICE_run (argc, |
1353 | argv, | 1420 | argv, |
1354 | "dns", | 1421 | "dns", |
1355 | GNUNET_SERVICE_OPTION_NONE, | 1422 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
1356 | &run, NULL)) ? 0 : 1; | ||
1357 | } | 1423 | } |