summaryrefslogtreecommitdiff
path: root/src/exit
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-08-22 14:50:04 +0000
committerChristian Grothoff <christian@grothoff.org>2016-08-22 14:50:04 +0000
commit6ee9d185c22d09d0e7e9da44522b33b03c5fa30b (patch)
tree898c1d392c3a8b871117570a1590aa6edea1bcd4 /src/exit
parent7b0c53a6b28bb3cedd44cb5dd396329f62aeab90 (diff)
downloadgnunet-6ee9d185c22d09d0e7e9da44522b33b03c5fa30b.tar.gz
gnunet-6ee9d185c22d09d0e7e9da44522b33b03c5fa30b.zip
fix exit CADET port binding for services, remove redundant service/port descriptor transmission from packets
Diffstat (limited to 'src/exit')
-rw-r--r--src/exit/exit.h33
-rw-r--r--src/exit/gnunet-daemon-exit.c419
2 files changed, 255 insertions, 197 deletions
diff --git a/src/exit/exit.h b/src/exit/exit.h
index 7b803f0cd..530d92125 100644
--- a/src/exit/exit.h
+++ b/src/exit/exit.h
@@ -37,7 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
37struct GNUNET_EXIT_TcpServiceStartMessage 37struct GNUNET_EXIT_TcpServiceStartMessage
38{ 38{
39 /** 39 /**
40 * Type is GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START 40 * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START
41 */ 41 */
42 struct GNUNET_MessageHeader header; 42 struct GNUNET_MessageHeader header;
43 43
@@ -47,11 +47,6 @@ struct GNUNET_EXIT_TcpServiceStartMessage
47 uint32_t reserved GNUNET_PACKED; 47 uint32_t reserved GNUNET_PACKED;
48 48
49 /** 49 /**
50 * Identification for the desired service.
51 */
52 struct GNUNET_HashCode service_descriptor;
53
54 /**
55 * Skeleton of the TCP header to send. Port numbers are to 50 * Skeleton of the TCP header to send. Port numbers are to
56 * be replaced and the checksum may be updated as necessary. 51 * be replaced and the checksum may be updated as necessary.
57 */ 52 */
@@ -68,7 +63,7 @@ struct GNUNET_EXIT_TcpServiceStartMessage
68struct GNUNET_EXIT_TcpInternetStartMessage 63struct GNUNET_EXIT_TcpInternetStartMessage
69{ 64{
70 /** 65 /**
71 * Type is GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START 66 * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START
72 */ 67 */
73 struct GNUNET_MessageHeader header; 68 struct GNUNET_MessageHeader header;
74 69
@@ -99,7 +94,7 @@ struct GNUNET_EXIT_TcpInternetStartMessage
99struct GNUNET_EXIT_TcpDataMessage 94struct GNUNET_EXIT_TcpDataMessage
100{ 95{
101 /** 96 /**
102 * Type is GNUNET_MESSAGE_TYPE_VPN_TCP_DATA 97 * Type is #GNUNET_MESSAGE_TYPE_VPN_TCP_DATA
103 */ 98 */
104 struct GNUNET_MessageHeader header; 99 struct GNUNET_MessageHeader header;
105 100
@@ -125,7 +120,7 @@ struct GNUNET_EXIT_TcpDataMessage
125struct GNUNET_EXIT_UdpServiceMessage 120struct GNUNET_EXIT_UdpServiceMessage
126{ 121{
127 /** 122 /**
128 * Type is GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE 123 * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE
129 */ 124 */
130 struct GNUNET_MessageHeader header; 125 struct GNUNET_MessageHeader header;
131 126
@@ -139,11 +134,6 @@ struct GNUNET_EXIT_UdpServiceMessage
139 */ 134 */
140 uint16_t destination_port GNUNET_PACKED; 135 uint16_t destination_port GNUNET_PACKED;
141 136
142 /**
143 * Identification for the desired service.
144 */
145 struct GNUNET_HashCode service_descriptor;
146
147 /* followed by UDP payload */ 137 /* followed by UDP payload */
148}; 138};
149 139
@@ -155,7 +145,7 @@ struct GNUNET_EXIT_UdpServiceMessage
155struct GNUNET_EXIT_UdpInternetMessage 145struct GNUNET_EXIT_UdpInternetMessage
156{ 146{
157 /** 147 /**
158 * Type is GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET 148 * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET
159 */ 149 */
160 struct GNUNET_MessageHeader header; 150 struct GNUNET_MessageHeader header;
161 151
@@ -188,7 +178,7 @@ struct GNUNET_EXIT_UdpInternetMessage
188struct GNUNET_EXIT_UdpReplyMessage 178struct GNUNET_EXIT_UdpReplyMessage
189{ 179{
190 /** 180 /**
191 * Type is GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY 181 * Type is #GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY
192 */ 182 */
193 struct GNUNET_MessageHeader header; 183 struct GNUNET_MessageHeader header;
194 184
@@ -215,7 +205,7 @@ struct GNUNET_EXIT_UdpReplyMessage
215struct GNUNET_EXIT_IcmpServiceMessage 205struct GNUNET_EXIT_IcmpServiceMessage
216{ 206{
217 /** 207 /**
218 * Type is GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE 208 * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE
219 */ 209 */
220 struct GNUNET_MessageHeader header; 210 struct GNUNET_MessageHeader header;
221 211
@@ -228,11 +218,6 @@ struct GNUNET_EXIT_IcmpServiceMessage
228 int32_t af GNUNET_PACKED; 218 int32_t af GNUNET_PACKED;
229 219
230 /** 220 /**
231 * Identification for the desired service.
232 */
233 struct GNUNET_HashCode service_descriptor;
234
235 /**
236 * ICMP header to use. 221 * ICMP header to use.
237 */ 222 */
238 struct GNUNET_TUN_IcmpHeader icmp_header; 223 struct GNUNET_TUN_IcmpHeader icmp_header;
@@ -251,7 +236,7 @@ struct GNUNET_EXIT_IcmpServiceMessage
251struct GNUNET_EXIT_IcmpInternetMessage 236struct GNUNET_EXIT_IcmpInternetMessage
252{ 237{
253 /** 238 /**
254 * Type is GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET 239 * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET
255 */ 240 */
256 struct GNUNET_MessageHeader header; 241 struct GNUNET_MessageHeader header;
257 242
@@ -286,7 +271,7 @@ struct GNUNET_EXIT_IcmpInternetMessage
286struct GNUNET_EXIT_IcmpToVPNMessage 271struct GNUNET_EXIT_IcmpToVPNMessage
287{ 272{
288 /** 273 /**
289 * Type is GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN 274 * Type is #GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN
290 */ 275 */
291 struct GNUNET_MessageHeader header; 276 struct GNUNET_MessageHeader header;
292 277
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index c8a2e85ef..e555e8638 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -124,6 +124,7 @@ struct SocketAddress
124 124
125}; 125};
126 126
127
127/** 128/**
128 * This struct is saved into the services-hashmap to represent 129 * This struct is saved into the services-hashmap to represent
129 * a service this peer is specifically offering an exit for 130 * a service this peer is specifically offering an exit for
@@ -138,16 +139,31 @@ struct LocalService
138 struct SocketAddress address; 139 struct SocketAddress address;
139 140
140 /** 141 /**
142 * Descriptor for the service (CADET port).
143 */
144 struct GNUNET_HashCode descriptor;
145
146 /**
141 * DNS name of the service. 147 * DNS name of the service.
142 */ 148 */
143 char *name; 149 char *name;
144 150
145 /** 151 /**
152 * Open port with CADET.
153 */
154 struct GNUNET_CADET_Port *port;
155
156 /**
146 * Port I am listening on within GNUnet for this service, in host 157 * Port I am listening on within GNUnet for this service, in host
147 * byte order. (as we may redirect ports). 158 * byte order. (as we may redirect ports).
148 */ 159 */
149 uint16_t my_port; 160 uint16_t my_port;
150 161
162 /**
163 * #GNUNET_YES if this is a UDP service, otherwise TCP.
164 */
165 int16_t is_udp;
166
151}; 167};
152 168
153/** 169/**
@@ -204,14 +220,14 @@ struct ChannelMessageQueue
204 const void *payload; 220 const void *payload;
205 221
206 /** 222 /**
207 * Number of bytes in 'payload'. 223 * Number of bytes in @e payload.
208 */ 224 */
209 size_t len; 225 size_t len;
210}; 226};
211 227
212 228
213/** 229/**
214 * This struct is saved into connections_map to allow finding the 230 * This struct is saved into #connections_map to allow finding the
215 * right channel given an IP packet from TUN. It is also associated 231 * right channel given an IP packet from TUN. It is also associated
216 * with the channel's closure so we can find it again for the next 232 * with the channel's closure so we can find it again for the next
217 * message from the channel. 233 * message from the channel.
@@ -252,7 +268,7 @@ struct ChannelState
252 struct GNUNET_CONTAINER_HeapNode *heap_node; 268 struct GNUNET_CONTAINER_HeapNode *heap_node;
253 269
254 /** 270 /**
255 * Key this state has in the connections_map. 271 * Key this state has in the #connections_map.
256 */ 272 */
257 struct GNUNET_HashCode state_key; 273 struct GNUNET_HashCode state_key;
258 274
@@ -390,14 +406,9 @@ static struct GNUNET_CONTAINER_Heap *connections_heap;
390static unsigned long long max_connections; 406static unsigned long long max_connections;
391 407
392/** 408/**
393 * This hashmaps saves interesting things about the configured UDP services 409 * This hashmaps saves interesting things about the configured services
394 */ 410 */
395static struct GNUNET_CONTAINER_MultiHashMap *udp_services; 411static struct GNUNET_CONTAINER_MultiHashMap *services;
396
397/**
398 * This hashmaps saves interesting things about the configured TCP services
399 */
400static struct GNUNET_CONTAINER_MultiHashMap *tcp_services;
401 412
402/** 413/**
403 * Array of all open DNS requests from channels. 414 * Array of all open DNS requests from channels.
@@ -465,10 +476,10 @@ static int ipv6_enabled;
465 * We got a reply from DNS for a request of a CADET channel. Send it 476 * We got a reply from DNS for a request of a CADET channel. Send it
466 * via the channel (after changing the request ID back). 477 * via the channel (after changing the request ID back).
467 * 478 *
468 * @param cls the 'struct ChannelState' 479 * @param cls the `struct ChannelState`
469 * @param size number of bytes available in buf 480 * @param size number of bytes available in @a buf
470 * @param buf where to copy the reply 481 * @param buf where to copy the reply
471 * @return number of bytes written to buf 482 * @return number of bytes written to @a buf
472 */ 483 */
473static size_t 484static size_t
474transmit_reply_to_cadet (void *cls, 485transmit_reply_to_cadet (void *cls,
@@ -629,41 +640,57 @@ hash_redirect_info (struct GNUNET_HashCode *hash,
629{ 640{
630 char *off; 641 char *off;
631 642
632 memset (hash, 0, sizeof (struct GNUNET_HashCode)); 643 memset (hash,
644 0,
645 sizeof (struct GNUNET_HashCode));
633 /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, 646 /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash,
634 so we put the IP address in there (and hope for few collisions) */ 647 so we put the IP address in there (and hope for few collisions) */
635 off = (char*) hash; 648 off = (char*) hash;
636 switch (ri->remote_address.af) 649 switch (ri->remote_address.af)
637 { 650 {
638 case AF_INET: 651 case AF_INET:
639 GNUNET_memcpy (off, &ri->remote_address.address.ipv4, sizeof (struct in_addr)); 652 GNUNET_memcpy (off,
653 &ri->remote_address.address.ipv4,
654 sizeof (struct in_addr));
640 off += sizeof (struct in_addr); 655 off += sizeof (struct in_addr);
641 break; 656 break;
642 case AF_INET6: 657 case AF_INET6:
643 GNUNET_memcpy (off, &ri->remote_address.address.ipv6, sizeof (struct in6_addr)); 658 GNUNET_memcpy (off,
659 &ri->remote_address.address.ipv6,
660 sizeof (struct in6_addr));
644 off += sizeof (struct in_addr); 661 off += sizeof (struct in_addr);
645 break; 662 break;
646 default: 663 default:
647 GNUNET_assert (0); 664 GNUNET_assert (0);
648 } 665 }
649 GNUNET_memcpy (off, &ri->remote_address.port, sizeof (uint16_t)); 666 GNUNET_memcpy (off,
667 &ri->remote_address.port,
668 sizeof (uint16_t));
650 off += sizeof (uint16_t); 669 off += sizeof (uint16_t);
651 switch (ri->local_address.af) 670 switch (ri->local_address.af)
652 { 671 {
653 case AF_INET: 672 case AF_INET:
654 GNUNET_memcpy (off, &ri->local_address.address.ipv4, sizeof (struct in_addr)); 673 GNUNET_memcpy (off,
674 &ri->local_address.address.ipv4,
675 sizeof (struct in_addr));
655 off += sizeof (struct in_addr); 676 off += sizeof (struct in_addr);
656 break; 677 break;
657 case AF_INET6: 678 case AF_INET6:
658 GNUNET_memcpy (off, &ri->local_address.address.ipv6, sizeof (struct in6_addr)); 679 GNUNET_memcpy (off,
680 &ri->local_address.address.ipv6,
681 sizeof (struct in6_addr));
659 off += sizeof (struct in_addr); 682 off += sizeof (struct in_addr);
660 break; 683 break;
661 default: 684 default:
662 GNUNET_assert (0); 685 GNUNET_assert (0);
663 } 686 }
664 GNUNET_memcpy (off, &ri->local_address.port, sizeof (uint16_t)); 687 GNUNET_memcpy (off,
688 &ri->local_address.port,
689 sizeof (uint16_t));
665 off += sizeof (uint16_t); 690 off += sizeof (uint16_t);
666 GNUNET_memcpy (off, &ri->remote_address.proto, sizeof (uint8_t)); 691 GNUNET_memcpy (off,
692 &ri->remote_address.proto,
693 sizeof (uint8_t));
667 /* off += sizeof (uint8_t); */ 694 /* off += sizeof (uint8_t); */
668} 695}
669 696
@@ -731,35 +758,12 @@ get_redirect_state (int af,
731 758
732 759
733/** 760/**
734 * Given a service descriptor and a destination port, find the
735 * respective service entry.
736 *
737 * @param service_map map of services (TCP or UDP)
738 * @param desc service descriptor
739 * @param destination_port destination port
740 * @return NULL if we are not aware of such a service
741 */
742static struct LocalService *
743find_service (struct GNUNET_CONTAINER_MultiHashMap *service_map,
744 const struct GNUNET_HashCode *desc,
745 uint16_t destination_port)
746{
747 char key[sizeof (struct GNUNET_HashCode) + sizeof (uint16_t)];
748
749 GNUNET_memcpy (&key[0], &destination_port, sizeof (uint16_t));
750 GNUNET_memcpy (&key[sizeof(uint16_t)], desc, sizeof (struct GNUNET_HashCode));
751 return GNUNET_CONTAINER_multihashmap_get (service_map,
752 (struct GNUNET_HashCode *) key);
753}
754
755
756/**
757 * Free memory associated with a service record. 761 * Free memory associated with a service record.
758 * 762 *
759 * @param cls unused 763 * @param cls unused
760 * @param key service descriptor 764 * @param key service descriptor
761 * @param value service record to free 765 * @param value service record to free
762 * @return GNUNET_OK 766 * @return #GNUNET_OK
763 */ 767 */
764static int 768static int
765free_service_record (void *cls, 769free_service_record (void *cls,
@@ -768,6 +772,11 @@ free_service_record (void *cls,
768{ 772{
769 struct LocalService *service = value; 773 struct LocalService *service = value;
770 774
775 GNUNET_assert (GNUNET_YES ==
776 GNUNET_CONTAINER_multihashmap_remove (services,
777 key,
778 service));
779 GNUNET_CADET_close_port (service->port);
771 GNUNET_free_non_null (service->name); 780 GNUNET_free_non_null (service->name);
772 GNUNET_free (service); 781 GNUNET_free (service);
773 return GNUNET_OK; 782 return GNUNET_OK;
@@ -775,34 +784,80 @@ free_service_record (void *cls,
775 784
776 785
777/** 786/**
787 * Callback from CADET for new channels.
788 *
789 * @param cls closure
790 * @param channel new handle to the channel
791 * @param initiator peer that started the channel
792 * @param port destination port
793 * @param options channel options flags
794 * @return initial channel context for the channel
795 */
796static void *
797new_service_channel (void *cls,
798 struct GNUNET_CADET_Channel *channel,
799 const struct GNUNET_PeerIdentity *initiator,
800 const struct GNUNET_HashCode *port,
801 enum GNUNET_CADET_ChannelOption options)
802{
803 struct LocalService *ls = cls;
804 struct ChannelState *s = GNUNET_new (struct ChannelState);
805
806 s->peer = *initiator;
807 GNUNET_STATISTICS_update (stats,
808 gettext_noop ("# Inbound CADET channels created"),
809 1,
810 GNUNET_NO);
811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
812 "Received inbound channel from `%s'\n",
813 GNUNET_i2s (initiator));
814 s->channel = channel;
815 s->specifics.tcp_udp.serv = ls;
816 s->specifics.tcp_udp.ri.remote_address = ls->address;
817 return s;
818}
819
820
821/**
778 * Given a service descriptor and a destination port, find the 822 * Given a service descriptor and a destination port, find the
779 * respective service entry. 823 * respective service entry.
780 * 824 *
781 * @param service_map map of services (TCP or UDP) 825 * @param proto IPPROTO_TCP or IPPROTO_UDP
782 * @param name name of the service 826 * @param name name of the service
783 * @param destination_port destination port 827 * @param destination_port destination port
784 * @param service service information record to store (service->name will be set). 828 * @param service service information record to store (service->name will be set).
785 */ 829 */
786static void 830static void
787store_service (struct GNUNET_CONTAINER_MultiHashMap *service_map, 831store_service (int proto,
788 const char *name, 832 const char *name,
789 uint16_t destination_port, 833 uint16_t destination_port,
790 struct LocalService *service) 834 struct LocalService *service)
791{ 835{
792 char key[sizeof (struct GNUNET_HashCode) + sizeof (uint16_t)]; 836 char key[sizeof (struct GNUNET_HashCode) + sizeof (uint16_t)];
793 struct GNUNET_HashCode desc;
794 837
795 GNUNET_TUN_service_name_to_hash (name, &desc); 838 GNUNET_TUN_service_name_to_hash (name,
839 &service->descriptor);
796 service->name = GNUNET_strdup (name); 840 service->name = GNUNET_strdup (name);
797 GNUNET_memcpy (&key[0], &destination_port, sizeof (uint16_t)); 841 GNUNET_memcpy (&key[0],
798 GNUNET_memcpy (&key[sizeof(uint16_t)], &desc, sizeof (struct GNUNET_HashCode)); 842 &destination_port,
843 sizeof (uint16_t));
844 GNUNET_memcpy (&key[sizeof(uint16_t)],
845 &service->descriptor,
846 sizeof (struct GNUNET_HashCode));
847 service->port = GNUNET_CADET_open_port (cadet_handle,
848 &service->descriptor,
849 &new_service_channel,
850 service);
851 service->is_udp = (IPPROTO_UDP == proto);
799 if (GNUNET_OK != 852 if (GNUNET_OK !=
800 GNUNET_CONTAINER_multihashmap_put (service_map, 853 GNUNET_CONTAINER_multihashmap_put (services,
801 (struct GNUNET_HashCode *) key, 854 (struct GNUNET_HashCode *) key,
802 service, 855 service,
803 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 856 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
804 { 857 {
805 free_service_record (NULL, (struct GNUNET_HashCode *) key, service); 858 free_service_record (NULL,
859 (struct GNUNET_HashCode *) key,
860 service);
806 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 861 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
807 _("Got duplicate service records for `%s:%u'\n"), 862 _("Got duplicate service records for `%s:%u'\n"),
808 name, 863 name,
@@ -814,13 +869,15 @@ store_service (struct GNUNET_CONTAINER_MultiHashMap *service_map,
814/** 869/**
815 * CADET is ready to receive a message for the channel. Transmit it. 870 * CADET is ready to receive a message for the channel. Transmit it.
816 * 871 *
817 * @param cls the 'struct ChannelState'. 872 * @param cls the `struct ChannelState`.
818 * @param size number of bytes available in buf 873 * @param size number of bytes available in @a buf
819 * @param buf where to copy the message 874 * @param buf where to copy the message
820 * @return number of bytes copied to buf 875 * @return number of bytes copied to @a buf
821 */ 876 */
822static size_t 877static size_t
823send_to_peer_notify_callback (void *cls, size_t size, void *buf) 878send_to_peer_notify_callback (void *cls,
879 size_t size,
880 void *buf)
824{ 881{
825 struct ChannelState *s = cls; 882 struct ChannelState *s = cls;
826 struct GNUNET_CADET_Channel *channel = s->channel; 883 struct GNUNET_CADET_Channel *channel = s->channel;
@@ -875,7 +932,9 @@ send_packet_to_cadet_channel (struct ChannelState *s,
875 932
876 cadet_channel = s->channel; 933 cadet_channel = s->channel;
877 GNUNET_assert (NULL != s); 934 GNUNET_assert (NULL != s);
878 GNUNET_CONTAINER_DLL_insert_tail (s->specifics.tcp_udp.head, s->specifics.tcp_udp.tail, tnq); 935 GNUNET_CONTAINER_DLL_insert_tail (s->specifics.tcp_udp.head,
936 s->specifics.tcp_udp.tail,
937 tnq);
879 if (NULL == s->th) 938 if (NULL == s->th)
880 s->th = GNUNET_CADET_notify_transmit_ready (cadet_channel, 939 s->th = GNUNET_CADET_notify_transmit_ready (cadet_channel,
881 GNUNET_NO /* cork */, 940 GNUNET_NO /* cork */,
@@ -890,7 +949,7 @@ send_packet_to_cadet_channel (struct ChannelState *s,
890 * @brief Handles an ICMP packet received from the helper. 949 * @brief Handles an ICMP packet received from the helper.
891 * 950 *
892 * @param icmp A pointer to the Packet 951 * @param icmp A pointer to the Packet
893 * @param pktlen number of bytes in 'icmp' 952 * @param pktlen number of bytes in @a icmp
894 * @param af address family (AFINET or AF_INET6) 953 * @param af address family (AFINET or AF_INET6)
895 * @param destination_ip destination IP-address of the IP packet (should 954 * @param destination_ip destination IP-address of the IP packet (should
896 * be our local address) 955 * be our local address)
@@ -1547,9 +1606,10 @@ setup_state_record (struct ChannelState *state)
1547 GNUNET_CONTAINER_multihashmap_put (connections_map, 1606 GNUNET_CONTAINER_multihashmap_put (connections_map,
1548 &key, state, 1607 &key, state,
1549 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1608 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1550 state->specifics.tcp_udp.heap_node = GNUNET_CONTAINER_heap_insert (connections_heap, 1609 state->specifics.tcp_udp.heap_node
1551 state, 1610 = GNUNET_CONTAINER_heap_insert (connections_heap,
1552 GNUNET_TIME_absolute_get ().abs_value_us); 1611 state,
1612 GNUNET_TIME_absolute_get ().abs_value_us);
1553 while (GNUNET_CONTAINER_heap_get_size (connections_heap) > max_connections) 1613 while (GNUNET_CONTAINER_heap_get_size (connections_heap) > max_connections)
1554 { 1614 {
1555 s = GNUNET_CONTAINER_heap_remove_root (connections_heap); 1615 s = GNUNET_CONTAINER_heap_remove_root (connections_heap);
@@ -1574,7 +1634,7 @@ setup_state_record (struct ChannelState *state)
1574 * 1634 *
1575 * @param payload payload of the packet (starting with UDP payload or 1635 * @param payload payload of the packet (starting with UDP payload or
1576 * TCP header, depending on protocol) 1636 * TCP header, depending on protocol)
1577 * @param payload_length number of bytes in 'payload' 1637 * @param payload_length number of bytes in @a payload
1578 * @param protocol IPPROTO_UDP or IPPROTO_TCP 1638 * @param protocol IPPROTO_UDP or IPPROTO_TCP
1579 * @param tcp_header skeleton of the TCP header, NULL for UDP 1639 * @param tcp_header skeleton of the TCP header, NULL for UDP
1580 * @param src_address source address to use (IP and port) 1640 * @param src_address source address to use (IP and port)
@@ -1584,7 +1644,8 @@ setup_state_record (struct ChannelState *state)
1584 * AND the payload 1644 * AND the payload
1585 */ 1645 */
1586static void 1646static void
1587prepare_ipv4_packet (const void *payload, size_t payload_length, 1647prepare_ipv4_packet (const void *payload,
1648 size_t payload_length,
1588 int protocol, 1649 int protocol,
1589 const struct GNUNET_TUN_TcpHeader *tcp_header, 1650 const struct GNUNET_TUN_TcpHeader *tcp_header,
1590 const struct SocketAddress *src_address, 1651 const struct SocketAddress *src_address,
@@ -1629,8 +1690,11 @@ prepare_ipv4_packet (const void *payload, size_t payload_length,
1629 pkt4_udp->len = htons ((uint16_t) payload_length); 1690 pkt4_udp->len = htons ((uint16_t) payload_length);
1630 GNUNET_TUN_calculate_udp4_checksum (pkt4, 1691 GNUNET_TUN_calculate_udp4_checksum (pkt4,
1631 pkt4_udp, 1692 pkt4_udp,
1632 payload, payload_length); 1693 payload,
1633 GNUNET_memcpy (&pkt4_udp[1], payload, payload_length); 1694 payload_length);
1695 GNUNET_memcpy (&pkt4_udp[1],
1696 payload,
1697 payload_length);
1634 } 1698 }
1635 break; 1699 break;
1636 case IPPROTO_TCP: 1700 case IPPROTO_TCP:
@@ -1638,13 +1702,19 @@ prepare_ipv4_packet (const void *payload, size_t payload_length,
1638 struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct GNUNET_TUN_TcpHeader *) &pkt4[1]; 1702 struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct GNUNET_TUN_TcpHeader *) &pkt4[1];
1639 1703
1640 *pkt4_tcp = *tcp_header; 1704 *pkt4_tcp = *tcp_header;
1705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1706 "Sending TCP packet from port %u to port %u\n",
1707 src_address->port,
1708 dst_address->port);
1641 pkt4_tcp->source_port = htons (src_address->port); 1709 pkt4_tcp->source_port = htons (src_address->port);
1642 pkt4_tcp->destination_port = htons (dst_address->port); 1710 pkt4_tcp->destination_port = htons (dst_address->port);
1643 GNUNET_TUN_calculate_tcp4_checksum (pkt4, 1711 GNUNET_TUN_calculate_tcp4_checksum (pkt4,
1644 pkt4_tcp, 1712 pkt4_tcp,
1645 payload, 1713 payload,
1646 payload_length); 1714 payload_length);
1647 GNUNET_memcpy (&pkt4_tcp[1], payload, payload_length); 1715 GNUNET_memcpy (&pkt4_tcp[1],
1716 payload,
1717 payload_length);
1648 } 1718 }
1649 break; 1719 break;
1650 default: 1720 default:
@@ -1662,7 +1732,7 @@ prepare_ipv4_packet (const void *payload, size_t payload_length,
1662 * 1732 *
1663 * @param payload payload of the packet (starting with UDP payload or 1733 * @param payload payload of the packet (starting with UDP payload or
1664 * TCP header, depending on protocol) 1734 * TCP header, depending on protocol)
1665 * @param payload_length number of bytes in 'payload' 1735 * @param payload_length number of bytes in @a payload
1666 * @param protocol IPPROTO_UDP or IPPROTO_TCP 1736 * @param protocol IPPROTO_UDP or IPPROTO_TCP
1667 * @param tcp_header skeleton TCP header data to send, NULL for UDP 1737 * @param tcp_header skeleton TCP header data to send, NULL for UDP
1668 * @param src_address source address to use (IP and port) 1738 * @param src_address source address to use (IP and port)
@@ -1672,7 +1742,8 @@ prepare_ipv4_packet (const void *payload, size_t payload_length,
1672 * AND the payload 1742 * AND the payload
1673 */ 1743 */
1674static void 1744static void
1675prepare_ipv6_packet (const void *payload, size_t payload_length, 1745prepare_ipv6_packet (const void *payload,
1746 size_t payload_length,
1676 int protocol, 1747 int protocol,
1677 const struct GNUNET_TUN_TcpHeader *tcp_header, 1748 const struct GNUNET_TUN_TcpHeader *tcp_header,
1678 const struct SocketAddress *src_address, 1749 const struct SocketAddress *src_address,
@@ -1757,13 +1828,15 @@ static void
1757send_tcp_packet_via_tun (const struct SocketAddress *destination_address, 1828send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1758 const struct SocketAddress *source_address, 1829 const struct SocketAddress *source_address,
1759 const struct GNUNET_TUN_TcpHeader *tcp_header, 1830 const struct GNUNET_TUN_TcpHeader *tcp_header,
1760 const void *payload, size_t payload_length) 1831 const void *payload,
1832 size_t payload_length)
1761{ 1833{
1762 size_t len; 1834 size_t len;
1763 1835
1764 GNUNET_STATISTICS_update (stats, 1836 GNUNET_STATISTICS_update (stats,
1765 gettext_noop ("# TCP packets sent via TUN"), 1837 gettext_noop ("# TCP packets sent via TUN"),
1766 1, GNUNET_NO); 1838 1,
1839 GNUNET_NO);
1767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1768 "Sending packet with %u bytes TCP payload via TUN\n", 1841 "Sending packet with %u bytes TCP payload via TUN\n",
1769 (unsigned int) payload_length); 1842 (unsigned int) payload_length);
@@ -1801,10 +1874,12 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1801 { 1874 {
1802 case AF_INET: 1875 case AF_INET:
1803 { 1876 {
1804 struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1]; 1877 struct GNUNET_TUN_IPv4Header *ipv4
1878 = (struct GNUNET_TUN_IPv4Header*) &tun[1];
1805 1879
1806 tun->proto = htons (ETH_P_IPV4); 1880 tun->proto = htons (ETH_P_IPV4);
1807 prepare_ipv4_packet (payload, payload_length, 1881 prepare_ipv4_packet (payload,
1882 payload_length,
1808 IPPROTO_TCP, 1883 IPPROTO_TCP,
1809 tcp_header, 1884 tcp_header,
1810 source_address, 1885 source_address,
@@ -1814,10 +1889,12 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1814 break; 1889 break;
1815 case AF_INET6: 1890 case AF_INET6:
1816 { 1891 {
1817 struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1]; 1892 struct GNUNET_TUN_IPv6Header *ipv6
1893 = (struct GNUNET_TUN_IPv6Header*) &tun[1];
1818 1894
1819 tun->proto = htons (ETH_P_IPV6); 1895 tun->proto = htons (ETH_P_IPV6);
1820 prepare_ipv6_packet (payload, payload_length, 1896 prepare_ipv6_packet (payload,
1897 payload_length,
1821 IPPROTO_TCP, 1898 IPPROTO_TCP,
1822 tcp_header, 1899 tcp_header,
1823 source_address, 1900 source_address,
@@ -1833,7 +1910,8 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
1833 (void) GNUNET_HELPER_send (helper_handle, 1910 (void) GNUNET_HELPER_send (helper_handle,
1834 (const struct GNUNET_MessageHeader*) buf, 1911 (const struct GNUNET_MessageHeader*) buf,
1835 GNUNET_YES, 1912 GNUNET_YES,
1836 NULL, NULL); 1913 NULL,
1914 NULL);
1837 } 1915 }
1838} 1916}
1839 1917
@@ -1869,6 +1947,11 @@ receive_tcp_service (void *cls,
1869 GNUNET_break_op (0); 1947 GNUNET_break_op (0);
1870 return GNUNET_SYSERR; 1948 return GNUNET_SYSERR;
1871 } 1949 }
1950 if (NULL == state->specifics.tcp_udp.serv)
1951 {
1952 GNUNET_break_op (0);
1953 return GNUNET_SYSERR;
1954 }
1872 if (GNUNET_SYSERR == state->is_dns) 1955 if (GNUNET_SYSERR == state->is_dns)
1873 { 1956 {
1874 /* channel is UDP/TCP from now on */ 1957 /* channel is UDP/TCP from now on */
@@ -1876,10 +1959,12 @@ receive_tcp_service (void *cls,
1876 } 1959 }
1877 GNUNET_STATISTICS_update (stats, 1960 GNUNET_STATISTICS_update (stats,
1878 gettext_noop ("# TCP service creation requests received via cadet"), 1961 gettext_noop ("# TCP service creation requests received via cadet"),
1879 1, GNUNET_NO); 1962 1,
1963 GNUNET_NO);
1880 GNUNET_STATISTICS_update (stats, 1964 GNUNET_STATISTICS_update (stats,
1881 gettext_noop ("# Bytes received from CADET"), 1965 gettext_noop ("# Bytes received from CADET"),
1882 pkt_len, GNUNET_NO); 1966 pkt_len,
1967 GNUNET_NO);
1883 /* check that we got at least a valid header */ 1968 /* check that we got at least a valid header */
1884 if (pkt_len < sizeof (struct GNUNET_EXIT_TcpServiceStartMessage)) 1969 if (pkt_len < sizeof (struct GNUNET_EXIT_TcpServiceStartMessage))
1885 { 1970 {
@@ -1888,8 +1973,7 @@ receive_tcp_service (void *cls,
1888 } 1973 }
1889 start = (const struct GNUNET_EXIT_TcpServiceStartMessage*) message; 1974 start = (const struct GNUNET_EXIT_TcpServiceStartMessage*) message;
1890 pkt_len -= sizeof (struct GNUNET_EXIT_TcpServiceStartMessage); 1975 pkt_len -= sizeof (struct GNUNET_EXIT_TcpServiceStartMessage);
1891 if ( (NULL != state->specifics.tcp_udp.serv) || 1976 if (NULL != state->specifics.tcp_udp.heap_node)
1892 (NULL != state->specifics.tcp_udp.heap_node) )
1893 { 1977 {
1894 GNUNET_break_op (0); 1978 GNUNET_break_op (0);
1895 return GNUNET_SYSERR; 1979 return GNUNET_SYSERR;
@@ -1904,29 +1988,14 @@ receive_tcp_service (void *cls,
1904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1905 "Received data from %s for forwarding to TCP service %s on port %u\n", 1989 "Received data from %s for forwarding to TCP service %s on port %u\n",
1906 GNUNET_i2s (&state->peer), 1990 GNUNET_i2s (&state->peer),
1907 GNUNET_h2s (&start->service_descriptor), 1991 GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor),
1908 (unsigned int) ntohs (start->tcp_header.destination_port)); 1992 (unsigned int) ntohs (start->tcp_header.destination_port));
1909 if (NULL == (state->specifics.tcp_udp.serv =
1910 find_service (tcp_services,
1911 &start->service_descriptor,
1912 ntohs (start->tcp_header.destination_port))))
1913 {
1914 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1915 _("No service %s found for %s on port %d!\n"),
1916 GNUNET_h2s (&start->service_descriptor),
1917 "TCP",
1918 ntohs (start->tcp_header.destination_port));
1919 GNUNET_STATISTICS_update (stats,
1920 gettext_noop ("# TCP requests dropped (no such service)"),
1921 1, GNUNET_NO);
1922 return GNUNET_SYSERR;
1923 }
1924 state->specifics.tcp_udp.ri.remote_address = state->specifics.tcp_udp.serv->address;
1925 setup_state_record (state); 1993 setup_state_record (state);
1926 send_tcp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, 1994 send_tcp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address,
1927 &state->specifics.tcp_udp.ri.local_address, 1995 &state->specifics.tcp_udp.ri.local_address,
1928 &start->tcp_header, 1996 &start->tcp_header,
1929 &start[1], pkt_len); 1997 &start[1],
1998 pkt_len);
1930 GNUNET_CADET_receive_done (channel); 1999 GNUNET_CADET_receive_done (channel);
1931 return GNUNET_YES; 2000 return GNUNET_YES;
1932} 2001}
@@ -2573,10 +2642,10 @@ receive_icmp_service (void *cls,
2573 GNUNET_break_op (0); 2642 GNUNET_break_op (0);
2574 return GNUNET_SYSERR; 2643 return GNUNET_SYSERR;
2575 } 2644 }
2576 if (GNUNET_SYSERR == state->is_dns) 2645 if (NULL == state->specifics.tcp_udp.serv)
2577 { 2646 {
2578 /* channel is UDP/TCP from now on */ 2647 GNUNET_break_op (0);
2579 state->is_dns = GNUNET_NO; 2648 return GNUNET_SYSERR;
2580 } 2649 }
2581 GNUNET_STATISTICS_update (stats, 2650 GNUNET_STATISTICS_update (stats,
2582 gettext_noop ("# Bytes received from CADET"), 2651 gettext_noop ("# Bytes received from CADET"),
@@ -2595,16 +2664,11 @@ receive_icmp_service (void *cls,
2595 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2596 "Received data from %s for forwarding to ICMP service %s\n", 2665 "Received data from %s for forwarding to ICMP service %s\n",
2597 GNUNET_i2s (&state->peer), 2666 GNUNET_i2s (&state->peer),
2598 GNUNET_h2s (&msg->service_descriptor)); 2667 GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor));
2599 if (NULL == state->specifics.tcp_udp.serv)
2600 {
2601 /* first packet to service must not be ICMP (cannot determine service!) */
2602 GNUNET_break_op (0);
2603 return GNUNET_SYSERR;
2604 }
2605 icmp = msg->icmp_header; 2668 icmp = msg->icmp_header;
2606 payload = &msg[1]; 2669 payload = &msg[1];
2607 state->specifics.tcp_udp.ri.remote_address = state->specifics.tcp_udp.serv->address; 2670 state->specifics.tcp_udp.ri.remote_address
2671 = state->specifics.tcp_udp.serv->address;
2608 setup_state_record (state); 2672 setup_state_record (state);
2609 2673
2610 /* check that ICMP type is something we want to support, 2674 /* check that ICMP type is something we want to support,
@@ -2800,7 +2864,8 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
2800 struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1]; 2864 struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1];
2801 2865
2802 tun->proto = htons (ETH_P_IPV4); 2866 tun->proto = htons (ETH_P_IPV4);
2803 prepare_ipv4_packet (payload, payload_length, 2867 prepare_ipv4_packet (payload,
2868 payload_length,
2804 IPPROTO_UDP, 2869 IPPROTO_UDP,
2805 NULL, 2870 NULL,
2806 source_address, 2871 source_address,
@@ -2813,7 +2878,8 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
2813 struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1]; 2878 struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1];
2814 2879
2815 tun->proto = htons (ETH_P_IPV6); 2880 tun->proto = htons (ETH_P_IPV6);
2816 prepare_ipv6_packet (payload, payload_length, 2881 prepare_ipv6_packet (payload,
2882 payload_length,
2817 IPPROTO_UDP, 2883 IPPROTO_UDP,
2818 NULL, 2884 NULL,
2819 source_address, 2885 source_address,
@@ -2966,16 +3032,11 @@ receive_udp_service (void *cls,
2966 const struct GNUNET_EXIT_UdpServiceMessage *msg; 3032 const struct GNUNET_EXIT_UdpServiceMessage *msg;
2967 uint16_t pkt_len = ntohs (message->size); 3033 uint16_t pkt_len = ntohs (message->size);
2968 3034
2969 if (GNUNET_YES == state->is_dns) 3035 if (NULL == state->specifics.tcp_udp.serv)
2970 { 3036 {
2971 GNUNET_break_op (0); 3037 GNUNET_break_op (0);
2972 return GNUNET_SYSERR; 3038 return GNUNET_SYSERR;
2973 } 3039 }
2974 if (GNUNET_SYSERR == state->is_dns)
2975 {
2976 /* channel is UDP/TCP from now on */
2977 state->is_dns = GNUNET_NO;
2978 }
2979 GNUNET_STATISTICS_update (stats, 3040 GNUNET_STATISTICS_update (stats,
2980 gettext_noop ("# Bytes received from CADET"), 3041 gettext_noop ("# Bytes received from CADET"),
2981 pkt_len, GNUNET_NO); 3042 pkt_len, GNUNET_NO);
@@ -2993,30 +3054,15 @@ receive_udp_service (void *cls,
2993 LOG (GNUNET_ERROR_TYPE_DEBUG, 3054 LOG (GNUNET_ERROR_TYPE_DEBUG,
2994 "Received data from %s for forwarding to UDP service %s on port %u\n", 3055 "Received data from %s for forwarding to UDP service %s on port %u\n",
2995 GNUNET_i2s (&state->peer), 3056 GNUNET_i2s (&state->peer),
2996 GNUNET_h2s (&msg->service_descriptor), 3057 GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor),
2997 (unsigned int) ntohs (msg->destination_port)); 3058 (unsigned int) ntohs (msg->destination_port));
2998 if (NULL == (state->specifics.tcp_udp.serv =
2999 find_service (udp_services,
3000 &msg->service_descriptor,
3001 ntohs (msg->destination_port))))
3002 {
3003 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3004 _("No service %s found for %s on port %d!\n"),
3005 GNUNET_h2s (&msg->service_descriptor),
3006 "UDP",
3007 ntohs (msg->destination_port));
3008 GNUNET_STATISTICS_update (stats,
3009 gettext_noop ("# UDP requests dropped (no such service)"),
3010 1, GNUNET_NO);
3011 return GNUNET_SYSERR;
3012 }
3013 state->specifics.tcp_udp.ri.remote_address = state->specifics.tcp_udp.serv->address;
3014 setup_state_record (state); 3059 setup_state_record (state);
3015 if (0 != ntohs (msg->source_port)) 3060 if (0 != ntohs (msg->source_port))
3016 state->specifics.tcp_udp.ri.local_address.port = msg->source_port; 3061 state->specifics.tcp_udp.ri.local_address.port = msg->source_port;
3017 send_udp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, 3062 send_udp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address,
3018 &state->specifics.tcp_udp.ri.local_address, 3063 &state->specifics.tcp_udp.ri.local_address,
3019 &msg[1], pkt_len); 3064 &msg[1],
3065 pkt_len);
3020 GNUNET_CADET_receive_done (channel); 3066 GNUNET_CADET_receive_done (channel);
3021 return GNUNET_YES; 3067 return GNUNET_YES;
3022} 3068}
@@ -3065,8 +3111,8 @@ new_channel (void *cls,
3065 */ 3111 */
3066static void 3112static void
3067clean_channel (void *cls, 3113clean_channel (void *cls,
3068 const struct GNUNET_CADET_Channel *channel, 3114 const struct GNUNET_CADET_Channel *channel,
3069 void *channel_ctx) 3115 void *channel_ctx)
3070{ 3116{
3071 struct ChannelState *s = channel_ctx; 3117 struct ChannelState *s = channel_ctx;
3072 struct ChannelMessageQueue *tnq; 3118 struct ChannelMessageQueue *tnq;
@@ -3173,6 +3219,13 @@ cleanup (void *cls)
3173 GNUNET_REGEX_announce_cancel (regex6); 3219 GNUNET_REGEX_announce_cancel (regex6);
3174 regex6 = NULL; 3220 regex6 = NULL;
3175 } 3221 }
3222 if (NULL != services)
3223 {
3224 GNUNET_CONTAINER_multihashmap_iterate (services,
3225 &free_service_record,
3226 NULL);
3227 GNUNET_CONTAINER_multihashmap_destroy (services);
3228 }
3176 if (NULL != cadet_handle) 3229 if (NULL != cadet_handle)
3177 { 3230 {
3178 GNUNET_CADET_disconnect (cadet_handle); 3231 GNUNET_CADET_disconnect (cadet_handle);
@@ -3180,7 +3233,9 @@ cleanup (void *cls)
3180 } 3233 }
3181 if (NULL != connections_map) 3234 if (NULL != connections_map)
3182 { 3235 {
3183 GNUNET_CONTAINER_multihashmap_iterate (connections_map, &free_iterate, NULL); 3236 GNUNET_CONTAINER_multihashmap_iterate (connections_map,
3237 &free_iterate,
3238 NULL);
3184 GNUNET_CONTAINER_multihashmap_destroy (connections_map); 3239 GNUNET_CONTAINER_multihashmap_destroy (connections_map);
3185 connections_map = NULL; 3240 connections_map = NULL;
3186 } 3241 }
@@ -3189,18 +3244,6 @@ cleanup (void *cls)
3189 GNUNET_CONTAINER_heap_destroy (connections_heap); 3244 GNUNET_CONTAINER_heap_destroy (connections_heap);
3190 connections_heap = NULL; 3245 connections_heap = NULL;
3191 } 3246 }
3192 if (NULL != tcp_services)
3193 {
3194 GNUNET_CONTAINER_multihashmap_iterate (tcp_services, &free_service_record, NULL);
3195 GNUNET_CONTAINER_multihashmap_destroy (tcp_services);
3196 tcp_services = NULL;
3197 }
3198 if (NULL != udp_services)
3199 {
3200 GNUNET_CONTAINER_multihashmap_iterate (udp_services, &free_service_record, NULL);
3201 GNUNET_CONTAINER_multihashmap_destroy (udp_services);
3202 udp_services = NULL;
3203 }
3204 if (NULL != dnsstub) 3247 if (NULL != dnsstub)
3205 { 3248 {
3206 GNUNET_DNSSTUB_stop (dnsstub); 3249 GNUNET_DNSSTUB_stop (dnsstub);
@@ -3286,7 +3329,7 @@ add_services (int proto,
3286 int local_port = atoi (redirect); 3329 int local_port = atoi (redirect);
3287 int remote_port = atoi (hostport); 3330 int remote_port = atoi (hostport);
3288 3331
3289 if (!((local_port > 0) && (local_port < 65536))) 3332 if (! ((local_port > 0) && (local_port < 65536)))
3290 { 3333 {
3291 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3334 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3292 _("`%s' is not a valid port number (for domain `%s')!"), 3335 _("`%s' is not a valid port number (for domain `%s')!"),
@@ -3294,7 +3337,7 @@ add_services (int proto,
3294 name); 3337 name);
3295 continue; 3338 continue;
3296 } 3339 }
3297 if (!((remote_port > 0) && (remote_port < 65536))) 3340 if (! ((remote_port > 0) && (remote_port < 65536)))
3298 { 3341 {
3299 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3342 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3300 _("`%s' is not a valid port number (for domain `%s')!"), 3343 _("`%s' is not a valid port number (for domain `%s')!"),
@@ -3307,27 +3350,36 @@ add_services (int proto,
3307 serv->address.proto = proto; 3350 serv->address.proto = proto;
3308 serv->my_port = (uint16_t) local_port; 3351 serv->my_port = (uint16_t) local_port;
3309 serv->address.port = remote_port; 3352 serv->address.port = remote_port;
3310 if (0 == strcmp ("localhost4", hostname)) 3353 if (0 == strcmp ("localhost4",
3354 hostname))
3311 { 3355 {
3312 const char *ip4addr = exit_argv[5]; 3356 const char *ip4addr = exit_argv[5];
3313 3357
3314 serv->address.af = AF_INET; 3358 serv->address.af = AF_INET;
3315 GNUNET_assert (1 == inet_pton (AF_INET, ip4addr, &serv->address.address.ipv4)); 3359 GNUNET_assert (1 == inet_pton (AF_INET,
3360 ip4addr,
3361 &serv->address.address.ipv4));
3316 } 3362 }
3317 else if (0 == strcmp ("localhost6", hostname)) 3363 else if (0 == strcmp ("localhost6",
3364 hostname))
3318 { 3365 {
3319 const char *ip6addr = exit_argv[3]; 3366 const char *ip6addr = exit_argv[3];
3320 3367
3321 serv->address.af = AF_INET6; 3368 serv->address.af = AF_INET6;
3322 GNUNET_assert (1 == inet_pton (AF_INET6, ip6addr, &serv->address.address.ipv6)); 3369 GNUNET_assert (1 == inet_pton (AF_INET6,
3370 ip6addr,
3371 &serv->address.address.ipv6));
3323 } 3372 }
3324 else 3373 else
3325 { 3374 {
3326 struct addrinfo *res; 3375 struct addrinfo *res;
3327 int ret; 3376 int ret;
3328 3377
3329 ret = getaddrinfo (hostname, NULL, NULL, &res); 3378 ret = getaddrinfo (hostname,
3330 if ( (ret != 0) || (res == NULL) ) 3379 NULL,
3380 NULL,
3381 &res);
3382 if ( (0 != ret) || (NULL == res) )
3331 { 3383 {
3332 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3384 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3333 _("No addresses found for hostname `%s' of service `%s'!\n"), 3385 _("No addresses found for hostname `%s' of service `%s'!\n"),
@@ -3350,7 +3402,8 @@ add_services (int proto,
3350 GNUNET_free (serv); 3402 GNUNET_free (serv);
3351 continue; 3403 continue;
3352 } 3404 }
3353 serv->address.address.ipv4 = ((struct sockaddr_in *) res->ai_addr)->sin_addr; 3405 serv->address.address.ipv4
3406 = ((struct sockaddr_in *) res->ai_addr)->sin_addr;
3354 break; 3407 break;
3355 case AF_INET6: 3408 case AF_INET6:
3356 if (! ipv6_enabled) 3409 if (! ipv6_enabled)
@@ -3362,7 +3415,8 @@ add_services (int proto,
3362 GNUNET_free (serv); 3415 GNUNET_free (serv);
3363 continue; 3416 continue;
3364 } 3417 }
3365 serv->address.address.ipv6 = ((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; 3418 serv->address.address.ipv6
3419 = ((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
3366 break; 3420 break;
3367 default: 3421 default:
3368 freeaddrinfo (res); 3422 freeaddrinfo (res);
@@ -3375,7 +3429,7 @@ add_services (int proto,
3375 } 3429 }
3376 freeaddrinfo (res); 3430 freeaddrinfo (res);
3377 } 3431 }
3378 store_service ((IPPROTO_UDP == proto) ? udp_services : tcp_services, 3432 store_service (proto,
3379 n, 3433 n,
3380 local_port, 3434 local_port,
3381 serv); 3435 serv);
@@ -3405,7 +3459,9 @@ read_service_conf (void *cls,
3405 "UDP_REDIRECTS", 3459 "UDP_REDIRECTS",
3406 &cpy)) 3460 &cpy))
3407 { 3461 {
3408 add_services (IPPROTO_UDP, cpy, section); 3462 add_services (IPPROTO_UDP,
3463 cpy,
3464 section);
3409 GNUNET_free (cpy); 3465 GNUNET_free (cpy);
3410 } 3466 }
3411 if (GNUNET_OK == 3467 if (GNUNET_OK ==
@@ -3414,7 +3470,9 @@ read_service_conf (void *cls,
3414 "TCP_REDIRECTS", 3470 "TCP_REDIRECTS",
3415 &cpy)) 3471 &cpy))
3416 { 3472 {
3417 add_services (IPPROTO_TCP, cpy, section); 3473 add_services (IPPROTO_TCP,
3474 cpy,
3475 section);
3418 GNUNET_free (cpy); 3476 GNUNET_free (cpy);
3419 } 3477 }
3420} 3478}
@@ -3574,6 +3632,9 @@ advertise_dns_exit ()
3574 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, 3632 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER,
3575 strlen (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER), 3633 strlen (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER),
3576 &port); 3634 &port);
3635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3636 "Opening CADET port %s for DNS exit service\n",
3637 GNUNET_h2s (&port));
3577 GNUNET_CADET_open_port (cadet_handle, 3638 GNUNET_CADET_open_port (cadet_handle,
3578 &port, 3639 &port,
3579 &new_channel, 3640 &new_channel,
@@ -3830,10 +3891,8 @@ run (void *cls,
3830 return; 3891 return;
3831 } 3892 }
3832 3893
3833 udp_services = GNUNET_CONTAINER_multihashmap_create (65536, 3894 services = GNUNET_CONTAINER_multihashmap_create (65536,
3834 GNUNET_NO); 3895 GNUNET_NO);
3835 tcp_services = GNUNET_CONTAINER_multihashmap_create (65536,
3836 GNUNET_NO);
3837 connections_map = GNUNET_CONTAINER_multihashmap_create (65536, 3896 connections_map = GNUNET_CONTAINER_multihashmap_create (65536,
3838 GNUNET_NO); 3897 GNUNET_NO);
3839 connections_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 3898 connections_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
@@ -3848,6 +3907,9 @@ run (void *cls,
3848 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV4_GATEWAY, 3907 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV4_GATEWAY,
3849 strlen (GNUNET_APPLICATION_PORT_IPV4_GATEWAY), 3908 strlen (GNUNET_APPLICATION_PORT_IPV4_GATEWAY),
3850 &port); 3909 &port);
3910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3911 "Opening CADET port %s for IPv4 gateway service\n",
3912 GNUNET_h2s (&port));
3851 GNUNET_CADET_open_port (cadet_handle, 3913 GNUNET_CADET_open_port (cadet_handle,
3852 &port, 3914 &port,
3853 &new_channel, 3915 &new_channel,
@@ -3882,6 +3944,9 @@ run (void *cls,
3882 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV6_GATEWAY, 3944 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV6_GATEWAY,
3883 strlen (GNUNET_APPLICATION_PORT_IPV6_GATEWAY), 3945 strlen (GNUNET_APPLICATION_PORT_IPV6_GATEWAY),
3884 &port); 3946 &port);
3947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3948 "Opening CADET port %s for IPv6 gateway service\n",
3949 GNUNET_h2s (&port));
3885 GNUNET_CADET_open_port (cadet_handle, 3950 GNUNET_CADET_open_port (cadet_handle,
3886 &port, 3951 &port,
3887 &new_channel, 3952 &new_channel,
@@ -3927,20 +3992,28 @@ run (void *cls,
3927 * @return 0 ok, 1 on error 3992 * @return 0 ok, 1 on error
3928 */ 3993 */
3929int 3994int
3930main (int argc, char *const *argv) 3995main (int argc,
3996 char *const *argv)
3931{ 3997{
3932 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 3998 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
3933 GNUNET_GETOPT_OPTION_END 3999 GNUNET_GETOPT_OPTION_END
3934 }; 4000 };
3935 4001
3936 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 4002 if (GNUNET_OK !=
4003 GNUNET_STRINGS_get_utf8_args (argc,
4004 argv,
4005 &argc,
4006 &argv))
3937 return 2; 4007 return 2;
3938 4008
3939 return (GNUNET_OK == 4009 return (GNUNET_OK ==
3940 GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit", 4010 GNUNET_PROGRAM_run (argc,
3941 gettext_noop 4011 argv,
3942 ("Daemon to run to provide an IP exit node for the VPN"), 4012 "gnunet-daemon-exit",
3943 options, &run, NULL)) ? global_ret : 1; 4013 gettext_noop ("Daemon to run to provide an IP exit node for the VPN"),
4014 options,
4015 &run,
4016 NULL)) ? global_ret : 1;
3944} 4017}
3945 4018
3946 4019