diff options
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn.c')
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 78 |
1 files changed, 65 insertions, 13 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index fa5b1058f..50c9d14b1 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -264,7 +264,7 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { | |||
264 | 264 | ||
265 | memcpy(&value->desc, &pkt->service_descr, sizeof(struct GNUNET_vpn_service_descriptor)); | 265 | memcpy(&value->desc, &pkt->service_descr, sizeof(struct GNUNET_vpn_service_descriptor)); |
266 | 266 | ||
267 | value->additional_ports = 0; | 267 | memset(value->additional_ports, 0, 8192); |
268 | 268 | ||
269 | if (GNUNET_NO == | 269 | if (GNUNET_NO == |
270 | GNUNET_CONTAINER_multihashmap_contains (hashmap, &key)) | 270 | GNUNET_CONTAINER_multihashmap_contains (hashmap, &key)) |
@@ -348,19 +348,71 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { | |||
348 | return; | 348 | return; |
349 | } | 349 | } |
350 | 350 | ||
351 | /** | ||
352 | * Sets a bit active in a bitArray. | ||
353 | * | ||
354 | * @param bitArray memory area to set the bit in | ||
355 | * @param bitIdx which bit to set | ||
356 | */ | ||
357 | void | ||
358 | setBit (char *bitArray, unsigned int bitIdx) | ||
359 | { | ||
360 | size_t arraySlot; | ||
361 | unsigned int targetBit; | ||
362 | |||
363 | arraySlot = bitIdx / 8; | ||
364 | targetBit = (1L << (bitIdx % 8)); | ||
365 | bitArray[arraySlot] |= targetBit; | ||
366 | } | ||
367 | |||
368 | /** | ||
369 | * Clears a bit from bitArray. | ||
370 | * | ||
371 | * @param bitArray memory area to set the bit in | ||
372 | * @param bitIdx which bit to unset | ||
373 | */ | ||
374 | void | ||
375 | clearBit (char *bitArray, unsigned int bitIdx) | ||
376 | { | ||
377 | size_t slot; | ||
378 | unsigned int targetBit; | ||
379 | |||
380 | slot = bitIdx / 8; | ||
381 | targetBit = (1L << (bitIdx % 8)); | ||
382 | bitArray[slot] = bitArray[slot] & (~targetBit); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * Checks if a bit is active in the bitArray | ||
387 | * | ||
388 | * @param bitArray memory area to set the bit in | ||
389 | * @param bitIdx which bit to test | ||
390 | * @return GNUNET_YES if the bit is set, GNUNET_NO if not. | ||
391 | */ | ||
392 | int | ||
393 | testBit (char *bitArray, unsigned int bitIdx) | ||
394 | { | ||
395 | size_t slot; | ||
396 | unsigned int targetBit; | ||
397 | |||
398 | slot = bitIdx / 8; | ||
399 | targetBit = (1L << (bitIdx % 8)); | ||
400 | if (bitArray[slot] & targetBit) | ||
401 | return GNUNET_YES; | ||
402 | else | ||
403 | return GNUNET_NO; | ||
404 | } | ||
405 | |||
406 | /** | ||
407 | * @brief Add the port to the list of additional ports in the map_entry | ||
408 | * | ||
409 | * @param me the map_entry | ||
410 | * @param port the port in host-byte-order | ||
411 | */ | ||
351 | static void | 412 | static void |
352 | add_additional_port (struct map_entry *me, uint16_t port) | 413 | add_additional_port (struct map_entry *me, uint16_t port) |
353 | { | 414 | { |
354 | uint16_t *ps = (uint16_t *) & me->additional_ports; | 415 | setBit(me->additional_ports, port); |
355 | unsigned int i; | ||
356 | for (i = 0; i < 4; i++) | ||
357 | { | ||
358 | if (ps[i] == 0) | ||
359 | { | ||
360 | ps[i] = port; | ||
361 | break; | ||
362 | } | ||
363 | } | ||
364 | } | 416 | } |
365 | 417 | ||
366 | static int | 418 | static int |
@@ -415,8 +467,8 @@ receive_udp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel, | |||
415 | GNUNET_assert (me != NULL); | 467 | GNUNET_assert (me != NULL); |
416 | GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP)); | 468 | GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP)); |
417 | if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) && | 469 | if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) && |
418 | !port_in_ports(me->additional_ports, pkt6->udp_hdr.spt)) { | 470 | !testBit(me->additional_ports, ntohs(pkt6->udp_hdr.spt))) { |
419 | add_additional_port(me, pkt6->udp_hdr.spt); | 471 | add_additional_port(me, ntohs(pkt6->udp_hdr.spt)); |
420 | } | 472 | } |
421 | 473 | ||
422 | pkt6->udp_hdr.crc = 0; | 474 | pkt6->udp_hdr.crc = 0; |