From: Christian Grothoff Date: Tue, 17 Jan 2012 18:59:02 +0000 (+0000) Subject: -rename header X-Git-Tag: initial-import-from-subversion-38251~15254 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4d899684274d4d5d0ce68c897acafc3d6d5ea3ab;p=oweals%2Fgnunet.git -rename header --- diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index 764ede782..76beaaf5c 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c @@ -30,7 +30,7 @@ #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 diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index 3909d4a70..3dce69a3e 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c @@ -44,7 +44,7 @@ #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" /** diff --git a/src/include/Makefile.am b/src/include/Makefile.am index d0cd70d01..85c9f7d4f 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -72,6 +72,6 @@ gnunetinclude_HEADERS = \ 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 diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h new file mode 100644 index 000000000..ca521db3b --- /dev/null +++ b/src/include/gnunet_tun_lib.h @@ -0,0 +1,151 @@ +/* + 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 diff --git a/src/include/tcpip_tun.h b/src/include/tcpip_tun.h deleted file mode 100644 index 80419aae5..000000000 --- a/src/include/tcpip_tun.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - 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 diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 381cdb7c8..9c0fb1667 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c @@ -45,7 +45,7 @@ #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" @@ -499,6 +499,79 @@ send_client_reply (struct GNUNET_SERVER_Client *client, } +/** + * 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. * @@ -513,10 +586,11 @@ destroy_tunnel_task (void *cls, 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); } @@ -763,79 +837,6 @@ create_tunnel_to_destination (struct DestinationEntry *de, } -/** - * 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. *