From 400de3aa78c110aeca65609af3571b1a65eaf4bf Mon Sep 17 00:00:00 2001 From: Philipp Tölke Date: Sat, 5 Mar 2011 11:17:07 +0000 Subject: Allow the use of all ports and not just 4 per connection --- src/vpn/gnunet-daemon-vpn-helper.c | 2 +- src/vpn/gnunet-daemon-vpn.c | 78 +++++++++++++++++++++++++++++++------- src/vpn/gnunet-daemon-vpn.h | 27 ++++++++++++- 3 files changed, 92 insertions(+), 15 deletions(-) (limited to 'src/vpn') 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, GNUNET_free(key); if (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP) && (port_in_ports(me->desc.ports, pkt6_udp->udp_hdr.dpt) || - port_in_ports(me->additional_ports, pkt6_udp->udp_hdr.dpt))) + testBit(me->additional_ports, ntohs(pkt6_udp->udp_hdr.dpt)))) { size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + sizeof(GNUNET_HashCode) + ntohs(pkt6_udp->udp_hdr.len); 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) { memcpy(&value->desc, &pkt->service_descr, sizeof(struct GNUNET_vpn_service_descriptor)); - value->additional_ports = 0; + memset(value->additional_ports, 0, 8192); if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (hashmap, &key)) @@ -348,19 +348,71 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { return; } +/** + * Sets a bit active in a bitArray. + * + * @param bitArray memory area to set the bit in + * @param bitIdx which bit to set + */ +void +setBit (char *bitArray, unsigned int bitIdx) +{ + size_t arraySlot; + unsigned int targetBit; + + arraySlot = bitIdx / 8; + targetBit = (1L << (bitIdx % 8)); + bitArray[arraySlot] |= targetBit; +} + +/** + * Clears a bit from bitArray. + * + * @param bitArray memory area to set the bit in + * @param bitIdx which bit to unset + */ +void +clearBit (char *bitArray, unsigned int bitIdx) +{ + size_t slot; + unsigned int targetBit; + + slot = bitIdx / 8; + targetBit = (1L << (bitIdx % 8)); + bitArray[slot] = bitArray[slot] & (~targetBit); +} + +/** + * Checks if a bit is active in the bitArray + * + * @param bitArray memory area to set the bit in + * @param bitIdx which bit to test + * @return GNUNET_YES if the bit is set, GNUNET_NO if not. + */ +int +testBit (char *bitArray, unsigned int bitIdx) +{ + size_t slot; + unsigned int targetBit; + + slot = bitIdx / 8; + targetBit = (1L << (bitIdx % 8)); + if (bitArray[slot] & targetBit) + return GNUNET_YES; + else + return GNUNET_NO; +} + +/** + * @brief Add the port to the list of additional ports in the map_entry + * + * @param me the map_entry + * @param port the port in host-byte-order + */ static void add_additional_port (struct map_entry *me, uint16_t port) { - uint16_t *ps = (uint16_t *) & me->additional_ports; - unsigned int i; - for (i = 0; i < 4; i++) - { - if (ps[i] == 0) - { - ps[i] = port; - break; - } - } + setBit(me->additional_ports, port); } static int @@ -415,8 +467,8 @@ receive_udp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel, GNUNET_assert (me != NULL); GNUNET_assert (me->desc.service_type & htonl(GNUNET_DNS_SERVICE_TYPE_UDP)); if (!port_in_ports(me->desc.ports, pkt6->udp_hdr.spt) && - !port_in_ports(me->additional_ports, pkt6->udp_hdr.spt)) { - add_additional_port(me, pkt6->udp_hdr.spt); + !testBit(me->additional_ports, ntohs(pkt6->udp_hdr.spt))) { + add_additional_port(me, ntohs(pkt6->udp_hdr.spt)); } 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 { struct GNUNET_vpn_service_descriptor desc; struct GNUNET_MESH_Tunnel *tunnel; uint16_t namelen; - uint64_t additional_ports; + char additional_ports[8192]; /** * After this struct the name is located in DNS-Format! */ }; +/** + * Sets a bit active in a bitArray. + * + * @param bitArray memory area to set the bit in + * @param bitIdx which bit to set + */ +void setBit (char *bitArray, unsigned int bitIdx); + +/** + * Clears a bit from bitArray. + * + * @param bitArray memory area to set the bit in + * @param bitIdx which bit to unset + */ +void clearBit (char *bitArray, unsigned int bitIdx); + +/** + * Checks if a bit is active in the bitArray + * + * @param bitArray memory area to set the bit in + * @param bitIdx which bit to test + * @return GNUNET_YES if the bit is set, GNUNET_NO if not. + */ +int testBit (char *bitArray, unsigned int bitIdx); + #endif /* end of include guard: GNUNET-DAEMON-VPN_H */ -- cgit v1.2.3