#include "dns.h"
#include "gnunet_dns_service.h"
#include "gnunet_statistics_service.h"
-#include "tcpip_tun.h"
+#include "gnunet_tun_lib.h"
#ifndef IPVERSION
#define IPVERSION 4
#include "gnunet_mesh_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_constants.h"
-#include "tcpip_tun.h"
+#include "gnunet_tun_lib.h"
#include "exit.h"
/**
gnunet_time_lib.h \
gnunet_transport_service.h \
gnunet_transport_plugin.h \
+ gnunet_tun_lib.h \
gnunet_util_lib.h \
- gnunet_vpn_service.h \
- tcpip_tun.h
\ No newline at end of file
+ gnunet_vpn_service.h
--- /dev/null
+/*
+ This file is part of GNUnet.
+ (C) 2010, 2011, 2012 Christian Grothoff
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file include/gnunet_tun_lib.h
+ * @brief standard TCP/IP network structs and IP checksum calculations for TUN interaction
+ * @author Philipp Toelke
+ * @author Christian Grothoff
+ *
+ * TODO:
+ * - currently does not follow our naming conventions
+ */
+#ifndef TCPIP_TUN_H
+#define TCPIP_TUN_H
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+
+
+/* see http://www.iana.org/assignments/ethernet-numbers */
+#ifndef ETH_P_IPV4
+#define ETH_P_IPV4 0x0800
+#endif
+
+#ifndef ETH_P_IPV6
+#define ETH_P_IPV6 0x86DD
+#endif
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+/**
+ * Header from Linux TUN interface.
+ */
+struct tun_header
+{
+ /**
+ * Some flags (unused).
+ */
+ uint16_t flags;
+
+ /**
+ * Here we get an ETH_P_-number.
+ */
+ uint16_t proto;
+};
+
+
+/**
+ * Standard IPv4 header.
+ */
+struct ip4_header
+{
+ unsigned header_length:4 GNUNET_PACKED;
+ unsigned version:4 GNUNET_PACKED;
+ uint8_t diff_serv;
+ uint16_t total_length GNUNET_PACKED;
+ uint16_t identification GNUNET_PACKED;
+ unsigned flags:3 GNUNET_PACKED;
+ unsigned fragmentation_offset:13 GNUNET_PACKED;
+ uint8_t ttl;
+ uint8_t protocol;
+ uint16_t checksum GNUNET_PACKED;
+ struct in_addr source_address GNUNET_PACKED;
+ struct in_addr destination_address GNUNET_PACKED;
+};
+
+/**
+ * Standard IPv6 header.
+ */
+struct ip6_header
+{
+ unsigned traffic_class_h:4 GNUNET_PACKED;
+ unsigned version:4 GNUNET_PACKED;
+ unsigned traffic_class_l:4 GNUNET_PACKED;
+ unsigned flow_label:20 GNUNET_PACKED;
+ uint16_t payload_length GNUNET_PACKED;
+ uint8_t next_header;
+ uint8_t hop_limit;
+ struct in6_addr source_address GNUNET_PACKED;
+ struct in6_addr destination_address GNUNET_PACKED;
+};
+
+#define TCP_FLAG_SYN 2
+
+/**
+ * TCP packet header (FIXME: rename!)
+ */
+struct tcp_packet
+{
+ unsigned spt:16 GNUNET_PACKED;
+ unsigned dpt:16 GNUNET_PACKED;
+ unsigned seq:32 GNUNET_PACKED;
+ unsigned ack:32 GNUNET_PACKED;
+ unsigned off:4 GNUNET_PACKED;
+ unsigned rsv:4 GNUNET_PACKED;
+ unsigned flg:8 GNUNET_PACKED;
+ unsigned wsz:16 GNUNET_PACKED;
+ unsigned crc:16 GNUNET_PACKED;
+ unsigned urg:16 GNUNET_PACKED;
+};
+
+/**
+ * UDP packet header (FIXME: rename!)
+ */
+struct udp_packet
+{
+ uint16_t spt GNUNET_PACKED;
+ uint16_t dpt GNUNET_PACKED;
+ uint16_t len GNUNET_PACKED;
+ uint16_t crc GNUNET_PACKED;
+};
+
+/**
+ * DNS header.
+ */
+struct dns_header
+{
+ uint16_t id GNUNET_PACKED;
+ uint16_t flags GNUNET_PACKED;
+ uint16_t qdcount GNUNET_PACKED;
+ uint16_t ancount GNUNET_PACKED;
+ uint16_t nscount GNUNET_PACKED;
+ uint16_t arcount GNUNET_PACKED;
+};
+GNUNET_NETWORK_STRUCT_END
+
+
+
+
+
+
+
+
+#endif
+++ /dev/null
-/*
- This file is part of GNUnet.
- (C) 2010, 2011, 2012 Christian Grothoff
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file include/tcpip_tun.h
- * @brief standard TCP/IP network structs for TUN interaction
- * @author Philipp Toelke
- * @author Christian Grothoff
- *
- * TODO:
- * - currently does not follow our naming conventions
- */
-#ifndef TCPIP_TUN_H
-#define TCPIP_TUN_H
-
-#include "platform.h"
-#include "gnunet_util_lib.h"
-
-
-/* see http://www.iana.org/assignments/ethernet-numbers */
-#ifndef ETH_P_IPV4
-#define ETH_P_IPV4 0x0800
-#endif
-
-#ifndef ETH_P_IPV6
-#define ETH_P_IPV6 0x86DD
-#endif
-
-
-GNUNET_NETWORK_STRUCT_BEGIN
-/**
- * Header from Linux TUN interface.
- */
-struct tun_header
-{
- /**
- * Some flags (unused).
- */
- uint16_t flags;
-
- /**
- * Here we get an ETH_P_-number.
- */
- uint16_t proto;
-};
-
-
-/**
- * Standard IPv4 header.
- */
-struct ip4_header
-{
- unsigned header_length:4 GNUNET_PACKED;
- unsigned version:4 GNUNET_PACKED;
- uint8_t diff_serv;
- uint16_t total_length GNUNET_PACKED;
- uint16_t identification GNUNET_PACKED;
- unsigned flags:3 GNUNET_PACKED;
- unsigned fragmentation_offset:13 GNUNET_PACKED;
- uint8_t ttl;
- uint8_t protocol;
- uint16_t checksum GNUNET_PACKED;
- struct in_addr source_address GNUNET_PACKED;
- struct in_addr destination_address GNUNET_PACKED;
-};
-
-/**
- * Standard IPv6 header.
- */
-struct ip6_header
-{
- unsigned traffic_class_h:4 GNUNET_PACKED;
- unsigned version:4 GNUNET_PACKED;
- unsigned traffic_class_l:4 GNUNET_PACKED;
- unsigned flow_label:20 GNUNET_PACKED;
- uint16_t payload_length GNUNET_PACKED;
- uint8_t next_header;
- uint8_t hop_limit;
- struct in6_addr source_address GNUNET_PACKED;
- struct in6_addr destination_address GNUNET_PACKED;
-};
-
-#define TCP_FLAG_SYN 2
-
-/**
- * TCP packet header (FIXME: rename!)
- */
-struct tcp_packet
-{
- unsigned spt:16 GNUNET_PACKED;
- unsigned dpt:16 GNUNET_PACKED;
- unsigned seq:32 GNUNET_PACKED;
- unsigned ack:32 GNUNET_PACKED;
- unsigned off:4 GNUNET_PACKED;
- unsigned rsv:4 GNUNET_PACKED;
- unsigned flg:8 GNUNET_PACKED;
- unsigned wsz:16 GNUNET_PACKED;
- unsigned crc:16 GNUNET_PACKED;
- unsigned urg:16 GNUNET_PACKED;
-};
-
-/**
- * UDP packet header (FIXME: rename!)
- */
-struct udp_packet
-{
- uint16_t spt GNUNET_PACKED;
- uint16_t dpt GNUNET_PACKED;
- uint16_t len GNUNET_PACKED;
- uint16_t crc GNUNET_PACKED;
-};
-
-/**
- * DNS header.
- */
-struct dns_header
-{
- uint16_t id GNUNET_PACKED;
- uint16_t flags GNUNET_PACKED;
- uint16_t qdcount GNUNET_PACKED;
- uint16_t ancount GNUNET_PACKED;
- uint16_t nscount GNUNET_PACKED;
- uint16_t arcount GNUNET_PACKED;
-};
-GNUNET_NETWORK_STRUCT_END
-
-
-
-
-
-
-
-
-#endif
#include "gnunet_mesh_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_constants.h"
-#include "tcpip_tun.h"
+#include "gnunet_tun_lib.h"
#include "vpn.h"
#include "exit.h"
}
+/**
+ * Free resources associated with a tunnel state.
+ *
+ * @param ts state to free
+ */
+static void
+free_tunnel_state (struct TunnelState *ts)
+{
+ GNUNET_HashCode key;
+ struct TunnelMessageQueueEntry *tnq;
+ struct GNUNET_MESH_Tunnel *tunnel;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cleaning up tunnel state\n");
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# Active tunnels"),
+ -1, GNUNET_NO);
+ if (GNUNET_SCHEDULER_NO_TASK != ts->destroy_task)
+ {
+ GNUNET_SCHEDULER_cancel (ts->destroy_task);
+ ts->destroy_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ while (NULL != (tnq = ts->tmq_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (ts->tmq_head,
+ ts->tmq_tail,
+ tnq);
+ ts->tmq_length--;
+ GNUNET_free (tnq);
+ }
+ GNUNET_assert (0 == ts->tmq_length);
+ if (NULL != ts->client)
+ {
+ GNUNET_SERVER_client_drop (ts->client);
+ ts->client = NULL;
+ }
+ if (NULL != ts->th)
+ {
+ GNUNET_MESH_notify_transmit_ready_cancel (ts->th);
+ ts->th = NULL;
+ }
+ GNUNET_assert (NULL == ts->destination.heap_node);
+ if (NULL != (tunnel = ts->tunnel))
+ {
+ ts->tunnel = NULL;
+ GNUNET_MESH_tunnel_destroy (tunnel);
+ }
+ if (NULL != ts->heap_node)
+ {
+ GNUNET_CONTAINER_heap_remove_node (ts->heap_node);
+ ts->heap_node = NULL;
+ get_tunnel_key_from_ips (ts->af,
+ ts->protocol,
+ &ts->source_ip,
+ ts->source_port,
+ &ts->destination_ip,
+ ts->destination_port,
+ &key);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (tunnel_map,
+ &key,
+ ts));
+ }
+ if (NULL != ts->destination_container)
+ {
+ GNUNET_assert (ts == ts->destination_container->ts);
+ ts->destination_container->ts = NULL;
+ ts->destination_container = NULL;
+ }
+ GNUNET_free (ts);
+}
+
+
/**
* Destroy the mesh tunnel.
*
struct GNUNET_MESH_Tunnel *tunnel;
ts->destroy_task = GNUNET_SCHEDULER_NO_TASK;
- if (NULL == (tunnel = ts->tunnel))
- return;
+ GNUNET_assert (NULL != ts->tunnel);
+ tunnel = ts->tunnel;
ts->tunnel = NULL;
GNUNET_MESH_tunnel_destroy (tunnel);
+ free_tunnel_state (ts);
}
}
-/**
- * Free resources associated with a tunnel state.
- *
- * @param ts state to free
- */
-static void
-free_tunnel_state (struct TunnelState *ts)
-{
- GNUNET_HashCode key;
- struct TunnelMessageQueueEntry *tnq;
- struct GNUNET_MESH_Tunnel *tunnel;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Cleaning up tunnel state\n");
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Active tunnels"),
- -1, GNUNET_NO);
- if (GNUNET_SCHEDULER_NO_TASK != ts->destroy_task)
- {
- GNUNET_SCHEDULER_cancel (ts->destroy_task);
- ts->destroy_task = GNUNET_SCHEDULER_NO_TASK;
- }
- while (NULL != (tnq = ts->tmq_head))
- {
- GNUNET_CONTAINER_DLL_remove (ts->tmq_head,
- ts->tmq_tail,
- tnq);
- ts->tmq_length--;
- GNUNET_free (tnq);
- }
- GNUNET_assert (0 == ts->tmq_length);
- if (NULL != ts->client)
- {
- GNUNET_SERVER_client_drop (ts->client);
- ts->client = NULL;
- }
- if (NULL != ts->th)
- {
- GNUNET_MESH_notify_transmit_ready_cancel (ts->th);
- ts->th = NULL;
- }
- GNUNET_assert (NULL == ts->destination.heap_node);
- if (NULL != (tunnel = ts->tunnel))
- {
- ts->tunnel = NULL;
- GNUNET_MESH_tunnel_destroy (tunnel);
- }
- if (NULL != ts->heap_node)
- {
- GNUNET_CONTAINER_heap_remove_node (ts->heap_node);
- ts->heap_node = NULL;
- get_tunnel_key_from_ips (ts->af,
- ts->protocol,
- &ts->source_ip,
- ts->source_port,
- &ts->destination_ip,
- ts->destination_port,
- &key);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (tunnel_map,
- &key,
- ts));
- }
- if (NULL != ts->destination_container)
- {
- GNUNET_assert (ts == ts->destination_container->ts);
- ts->destination_container->ts = NULL;
- ts->destination_container = NULL;
- }
- GNUNET_free (ts);
-}
-
-
/**
* We have too many active tunnels. Clean up the oldest tunnel.
*