2 This file is part of GNUnet.
3 (C) 2010, 2011, 2012 Christian Grothoff
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_tun_lib.h
23 * @brief standard TCP/IP network structs and IP checksum calculations for TUN interaction
24 * @author Philipp Toelke
25 * @author Christian Grothoff
27 #ifndef GNUNET_TUN_LIB_H
28 #define GNUNET_TUN_LIB_H
30 #include "gnunet_util_lib.h"
33 /* see http://www.iana.org/assignments/ethernet-numbers */
38 #define ETH_P_IPV4 0x0800
45 #define ETH_P_IPV6 0x86DD
49 GNUNET_NETWORK_STRUCT_BEGIN
52 * Header from Linux TUN interface.
54 struct GNUNET_TUN_Layer2PacketHeader
57 * Some flags (unused).
62 * Here we get an ETH_P_-number.
69 * Standard IPv4 header.
71 struct GNUNET_TUN_IPv4Header
73 unsigned header_length:4 GNUNET_PACKED;
74 unsigned version:4 GNUNET_PACKED;
76 uint16_t total_length GNUNET_PACKED;
77 uint16_t identification GNUNET_PACKED;
78 unsigned flags:3 GNUNET_PACKED;
79 unsigned fragmentation_offset:13 GNUNET_PACKED;
82 uint16_t checksum GNUNET_PACKED;
83 struct in_addr source_address GNUNET_PACKED;
84 struct in_addr destination_address GNUNET_PACKED;
89 * Standard IPv6 header.
91 struct GNUNET_TUN_IPv6Header
93 unsigned traffic_class_h:4 GNUNET_PACKED;
94 unsigned version:4 GNUNET_PACKED;
95 unsigned traffic_class_l:4 GNUNET_PACKED;
96 unsigned flow_label:20 GNUNET_PACKED;
97 uint16_t payload_length GNUNET_PACKED;
100 struct in6_addr source_address GNUNET_PACKED;
101 struct in6_addr destination_address GNUNET_PACKED;
106 * TCP packet header (FIXME: rename!)
108 struct GNUNET_TUN_TcpHeader
110 unsigned spt:16 GNUNET_PACKED;
111 unsigned dpt:16 GNUNET_PACKED;
112 unsigned seq:32 GNUNET_PACKED;
113 unsigned ack:32 GNUNET_PACKED;
114 unsigned off:4 GNUNET_PACKED;
115 unsigned rsv:4 GNUNET_PACKED;
116 unsigned flg:8 GNUNET_PACKED;
117 unsigned wsz:16 GNUNET_PACKED;
118 unsigned crc:16 GNUNET_PACKED;
119 unsigned urg:16 GNUNET_PACKED;
124 * UDP packet header (FIXME: rename!)
126 struct GNUNET_TUN_UdpHeader
128 uint16_t spt GNUNET_PACKED;
129 uint16_t dpt GNUNET_PACKED;
130 uint16_t len GNUNET_PACKED;
131 uint16_t crc GNUNET_PACKED;
138 struct GNUNET_TUN_DnsHeader
140 uint16_t id GNUNET_PACKED;
141 uint16_t flags GNUNET_PACKED;
142 uint16_t qdcount GNUNET_PACKED;
143 uint16_t ancount GNUNET_PACKED;
144 uint16_t nscount GNUNET_PACKED;
145 uint16_t arcount GNUNET_PACKED;
148 GNUNET_NETWORK_STRUCT_END
152 * Initialize an IPv4 header.
154 * @param ip header to initialize
155 * @param protocol protocol to use (i.e. IPPROTO_UDP)
156 * @param payload_length number of bytes of payload that follow (excluding IPv4 header)
157 * @param src source IP address to use
158 * @param dst destination IP address to use
161 GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
163 uint16_t payload_length,
164 const struct in_addr *src,
165 const struct in_addr *dst);
169 * Initialize an IPv6 header.
171 * @param ip header to initialize
172 * @param protocol protocol to use (i.e. IPPROTO_UDP)
173 * @param payload_length number of bytes of payload that follow (excluding IPv4 header)
174 * @param src source IP address to use
175 * @param dst destination IP address to use
178 GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
180 uint16_t payload_length,
181 const struct in6_addr *src,
182 const struct in6_addr *dst);