aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-03-05 11:17:07 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-03-05 11:17:07 +0000
commit400de3aa78c110aeca65609af3571b1a65eaf4bf (patch)
treec591a0a3979814f67daf4b0a2b42d1ada46a8d38 /src/vpn
parent2a16fa8a3584bc001b757885449bc189e2cea1e3 (diff)
downloadgnunet-400de3aa78c110aeca65609af3571b1a65eaf4bf.tar.gz
gnunet-400de3aa78c110aeca65609af3571b1a65eaf4bf.zip
Allow the use of all ports and not just 4 per connection
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c2
-rw-r--r--src/vpn/gnunet-daemon-vpn.c78
-rw-r--r--src/vpn/gnunet-daemon-vpn.h27
3 files changed, 92 insertions, 15 deletions
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 9df2a8cc0..7d9eb7d6e 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -230,7 +230,7 @@ message_token(void *cls,
230 GNUNET_free(key); 230 GNUNET_free(key);
231 if (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP) && 231 if (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP) &&
232 (port_in_ports(me->desc.ports, pkt6_udp->udp_hdr.dpt) || 232 (port_in_ports(me->desc.ports, pkt6_udp->udp_hdr.dpt) ||
233 port_in_ports(me->additional_ports, pkt6_udp->udp_hdr.dpt))) 233 testBit(me->additional_ports, ntohs(pkt6_udp->udp_hdr.dpt))))
234 { 234 {
235 size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + sizeof(GNUNET_HashCode) + ntohs(pkt6_udp->udp_hdr.len); 235 size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + sizeof(GNUNET_HashCode) + ntohs(pkt6_udp->udp_hdr.len);
236 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc(size); 236 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc(size);
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 */
357void
358setBit (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 */
374void
375clearBit (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 */
392int
393testBit (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 */
351static void 412static void
352add_additional_port (struct map_entry *me, uint16_t port) 413add_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
366static int 418static 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;
diff --git a/src/vpn/gnunet-daemon-vpn.h b/src/vpn/gnunet-daemon-vpn.h
index 36f3dcbe7..e0e688f99 100644
--- a/src/vpn/gnunet-daemon-vpn.h
+++ b/src/vpn/gnunet-daemon-vpn.h
@@ -72,10 +72,35 @@ struct map_entry {
72 struct GNUNET_vpn_service_descriptor desc; 72 struct GNUNET_vpn_service_descriptor desc;
73 struct GNUNET_MESH_Tunnel *tunnel; 73 struct GNUNET_MESH_Tunnel *tunnel;
74 uint16_t namelen; 74 uint16_t namelen;
75 uint64_t additional_ports; 75 char additional_ports[8192];
76 /** 76 /**
77 * After this struct the name is located in DNS-Format! 77 * After this struct the name is located in DNS-Format!
78 */ 78 */
79}; 79};
80 80
81/**
82 * Sets a bit active in a bitArray.
83 *
84 * @param bitArray memory area to set the bit in
85 * @param bitIdx which bit to set
86 */
87void setBit (char *bitArray, unsigned int bitIdx);
88
89/**
90 * Clears a bit from bitArray.
91 *
92 * @param bitArray memory area to set the bit in
93 * @param bitIdx which bit to unset
94 */
95void clearBit (char *bitArray, unsigned int bitIdx);
96
97/**
98 * Checks if a bit is active in the bitArray
99 *
100 * @param bitArray memory area to set the bit in
101 * @param bitIdx which bit to test
102 * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
103 */
104int testBit (char *bitArray, unsigned int bitIdx);
105
81#endif /* end of include guard: GNUNET-DAEMON-VPN_H */ 106#endif /* end of include guard: GNUNET-DAEMON-VPN_H */