GNUnet  0.10.x
gnunet_tun_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010-2013 Christian Grothoff
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 
34 #ifndef GNUNET_TUN_LIB_H
35 #define GNUNET_TUN_LIB_H
36 
37 #include "gnunet_common.h"
38 #include "gnunet_crypto_lib.h"
39 
40 
41 /* see http://www.iana.org/assignments/ethernet-numbers */
42 #ifndef ETH_P_IPV4
43 
46 #define ETH_P_IPV4 0x0800
47 #endif
48 
49 #ifndef ETH_P_IPV6
50 
53 #define ETH_P_IPV6 0x86DD
54 #endif
55 
56 
64 #define GNUNET_TUN_IPV4_REGEXLEN 16
65 
66 
73 #define GNUNET_TUN_IPV6_REGEXLEN 40
74 
75 
77 
82 {
86  uint16_t flags GNUNET_PACKED;
87 
91  uint16_t proto GNUNET_PACKED;
92 };
93 
94 
99 {
100 #if __BYTE_ORDER == __LITTLE_ENDIAN
101  unsigned int header_length : 4 GNUNET_PACKED;
102  unsigned int version : 4 GNUNET_PACKED;
103 #elif __BYTE_ORDER == __BIG_ENDIAN
104  unsigned int version : 4 GNUNET_PACKED;
105  unsigned int header_length : 4 GNUNET_PACKED;
106 #else
107 #error byteorder undefined
108 #endif
109  uint8_t diff_serv;
110 
114  uint16_t total_length GNUNET_PACKED;
115 
119  uint16_t identification GNUNET_PACKED;
120 
121  unsigned int flags : 3 GNUNET_PACKED;
122 
124 
128  uint8_t ttl;
129 
133  uint8_t protocol;
134 
138  uint16_t checksum GNUNET_PACKED;
139 
143  struct in_addr source_address;
144 
148  struct in_addr destination_address;
150 
151 
156 {
157 #if __BYTE_ORDER == __LITTLE_ENDIAN
158  unsigned int traffic_class_h : 4 GNUNET_PACKED;
159  unsigned int version : 4 GNUNET_PACKED;
160  unsigned int traffic_class_l : 4 GNUNET_PACKED;
161  unsigned int flow_label : 20 GNUNET_PACKED;
162 #elif __BYTE_ORDER == __BIG_ENDIAN
163  unsigned int version : 4 GNUNET_PACKED;
164  unsigned int traffic_class : 8 GNUNET_PACKED;
165  unsigned int flow_label : 20 GNUNET_PACKED;
166 #else
167 #error byteorder undefined
168 #endif
169 
172  uint16_t payload_length GNUNET_PACKED;
173 
177  uint8_t next_header;
178 
182  uint8_t hop_limit;
183 
187  struct in6_addr source_address GNUNET_PACKED;
188 
192  struct in6_addr destination_address GNUNET_PACKED;
194 
195 
199 #define GNUNET_TUN_TCP_FLAGS_FIN 1
200 #define GNUNET_TUN_TCP_FLAGS_SYN 2
201 #define GNUNET_TUN_TCP_FLAGS_RST 4
202 #define GNUNET_TUN_TCP_FLAGS_PSH 8
203 #define GNUNET_TUN_TCP_FLAGS_ACK 16
204 #define GNUNET_TUN_TCP_FLAGS_URG 32
205 #define GNUNET_TUN_TCP_FLAGS_ECE 64
206 #define GNUNET_TUN_TCP_FLAGS_CWR 128
207 
212 {
216  uint16_t source_port GNUNET_PACKED;
217 
221  uint16_t destination_port GNUNET_PACKED;
222 
226  uint32_t seq GNUNET_PACKED;
227 
231  uint32_t ack GNUNET_PACKED;
232 #if __BYTE_ORDER == __LITTLE_ENDIAN
233 
236  unsigned int reserved : 4 GNUNET_PACKED;
240  unsigned int off : 4 GNUNET_PACKED;
241 #elif __BYTE_ORDER == __BIG_ENDIAN
242 
245  unsigned int off : 4 GNUNET_PACKED;
249  unsigned int reserved : 4 GNUNET_PACKED;
250 #else
251 #error byteorder undefined
252 #endif
253 
257  uint8_t flags;
258 
262  uint16_t window_size GNUNET_PACKED;
263 
267  uint16_t crc GNUNET_PACKED;
268 
272  uint16_t urgent_pointer GNUNET_PACKED;
274 
275 
280 {
284  uint16_t source_port GNUNET_PACKED;
285 
289  uint16_t destination_port GNUNET_PACKED;
290 
294  uint16_t len GNUNET_PACKED;
295 
299  uint16_t crc GNUNET_PACKED;
300 };
301 
302 
307 #define GNUNET_TUN_DNS_CLASS_INTERNET 1
308 #define GNUNET_TUN_DNS_CLASS_CHAOS 3
309 #define GNUNET_TUN_DNS_CLASS_HESIOD 4
310 
311 #define GNUNET_TUN_DNS_OPCODE_QUERY 0
312 #define GNUNET_TUN_DNS_OPCODE_INVERSE_QUERY 1
313 #define GNUNET_TUN_DNS_OPCODE_STATUS 2
314 
315 
319 #define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR 0
320 #define GNUNET_TUN_DNS_RETURN_CODE_FORMAT_ERROR 1
321 #define GNUNET_TUN_DNS_RETURN_CODE_SERVER_FAILURE 2
322 #define GNUNET_TUN_DNS_RETURN_CODE_NAME_ERROR 3
323 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_IMPLEMENTED 4
324 #define GNUNET_TUN_DNS_RETURN_CODE_REFUSED 5
325 
329 #define GNUNET_TUN_DNS_RETURN_CODE_YXDOMAIN 6
330 #define GNUNET_TUN_DNS_RETURN_CODE_YXRRSET 7
331 #define GNUNET_TUN_DNS_RETURN_CODE_NXRRSET 8
332 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_AUTH 9
333 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_ZONE 10
334 
335 
340 {
341 #if __BYTE_ORDER == __LITTLE_ENDIAN
342 
346 
351 
356 
360  unsigned int opcode : 4 GNUNET_PACKED;
361 
366 
370  unsigned int return_code : 4 GNUNET_PACKED;
371 
376 
381 
385  unsigned int zero : 1 GNUNET_PACKED;
386 
391 #elif __BYTE_ORDER == __BIG_ENDIAN
392 
396  unsigned int query_or_response : 1 GNUNET_PACKED;
397 
401  unsigned int opcode : 4 GNUNET_PACKED;
402 
406  unsigned int authoritative_answer : 1 GNUNET_PACKED;
407 
411  unsigned int message_truncated : 1 GNUNET_PACKED;
412 
416  unsigned int recursion_desired : 1 GNUNET_PACKED;
417 
418 
422  unsigned int recursion_available : 1 GNUNET_PACKED;
423 
427  unsigned int zero : 1 GNUNET_PACKED;
428 
432  unsigned int authenticated_data : 1 GNUNET_PACKED;
433 
437  unsigned int checking_disabled : 1 GNUNET_PACKED;
438 
442  unsigned int return_code : 4 GNUNET_PACKED;
443 #else
444 #error byteorder undefined
445 #endif
446 
448 
449 
454 {
458  uint16_t id GNUNET_PACKED;
459 
464 
468  uint16_t query_count GNUNET_PACKED;
469 
473  uint16_t answer_rcount GNUNET_PACKED;
474 
478  uint16_t authority_rcount GNUNET_PACKED;
479 
483  uint16_t additional_rcount GNUNET_PACKED;
484 };
485 
486 
491 {
495  uint32_t serial GNUNET_PACKED;
496 
500  uint32_t refresh GNUNET_PACKED;
501 
506  uint32_t retry GNUNET_PACKED;
507 
513 
518  uint32_t minimum GNUNET_PACKED;
519 };
520 
521 
526 {
527 
533  uint16_t prio GNUNET_PACKED;
534 
540  uint16_t weight GNUNET_PACKED;
541 
545  uint16_t port GNUNET_PACKED;
546 
547  /* followed by 'target' name */
548 };
549 
550 
555 {
556 
560  uint16_t cert_type;
561 
565  uint16_t cert_tag;
566 
570  uint8_t algorithm;
571 
572  /* Followed by the certificate */
573 };
574 
575 
581 {
582 
590  uint8_t usage;
591 
599  uint8_t selector;
600 
607  uint8_t matching_type;
608 
620 };
621 
622 
627 {
632 
636  uint16_t proto;
637 
638  /* followed by the servicename */
639 };
640 
641 
646 {
650  uint16_t type GNUNET_PACKED;
651 
655  uint16_t dns_traffic_class GNUNET_PACKED;
656 };
657 
658 
663 {
667  uint16_t type GNUNET_PACKED;
668 
672  uint16_t dns_traffic_class GNUNET_PACKED;
673 
677  uint32_t ttl GNUNET_PACKED;
678 
682  uint16_t data_len GNUNET_PACKED;
683 };
684 
685 
686 #define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0
687 #define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3
688 #define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4
689 #define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5
690 #define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8
691 #define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9
692 #define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10
693 #define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11
694 
695 #define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1
696 #define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2
697 #define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3
698 #define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4
699 #define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128
700 #define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129
701 
702 
707 {
708  uint8_t type;
709  uint8_t code;
710  uint16_t crc GNUNET_PACKED;
711 
712  union
713  {
717  struct
718  {
719  uint16_t identifier GNUNET_PACKED;
720  uint16_t sequence_number GNUNET_PACKED;
721  } echo;
722 
726  struct ih_pmtu
727  {
728  uint16_t empty GNUNET_PACKED;
729  uint16_t next_hop_mtu GNUNET_PACKED;
730  /* followed by original IP header + first 8 bytes of original IP datagram
731  */
732  } destination_unreachable;
733 
737  struct in_addr redirect_gateway_address;
738 
742  uint32_t packet_too_big_mtu GNUNET_PACKED;
743 
744  } quench;
745 };
746 
747 
749 
750 
761 void
763  uint8_t protocol,
764  uint16_t payload_length,
765  const struct in_addr *src,
766  const struct in_addr *dst);
767 
768 
779 void
781  uint8_t protocol,
782  uint16_t payload_length,
783  const struct in6_addr *src,
784  const struct in6_addr *dst);
785 
794 void
796  struct GNUNET_TUN_TcpHeader *tcp,
797  const void *payload,
798  uint16_t payload_length);
799 
808 void
810  struct GNUNET_TUN_TcpHeader *tcp,
811  const void *payload,
812  uint16_t payload_length);
813 
822 void
824  struct GNUNET_TUN_UdpHeader *udp,
825  const void *payload,
826  uint16_t payload_length);
827 
828 
837 void
839  struct GNUNET_TUN_UdpHeader *udp,
840  const void *payload,
841  uint16_t payload_length);
842 
843 
851 void
853  const void *payload,
854  uint16_t payload_length);
855 
856 
865 void
866 GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip,
867  uint16_t port,
868  char *rxstr);
869 
870 
879 void
880 GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6,
881  uint16_t port,
882  char *rxstr);
883 
884 
894 char *
895 GNUNET_TUN_ipv6policy2regex (const char *policy);
896 
897 
907 char *
908 GNUNET_TUN_ipv4policy2regex (const char *policy);
909 
910 
919 void
921  struct GNUNET_HashCode *hc);
922 
923 
932 int
933 GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa,
934  const struct sockaddr *sb,
935  int include_port);
936 
937 
947 void
949  uint16_t ip_port,
950  struct GNUNET_HashCode *cadet_port);
951 
952 #endif
953  /* end of group */
static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero
Public key of all zeros.
unsigned int header_length
unsigned int zero
Always zero.
Payload of GNS VPN record.
static int udp
Option -u: UDP requested.
Definition: gnunet-vpn.c:76
#define GNUNET_GCC_STRUCT_LAYOUT
gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields
DNS flags (largely RFC 1035 / RFC 2136).
unsigned int traffic_class_l
char * GNUNET_TUN_ipv4policy2regex(const char *policy)
Convert an exit policy to a regular expression.
Definition: regex.c:699
uint16_t proto
Here we get an ETH_P_-number.
uint8_t flags
Flags (SYN, FIN, ACK, etc.)
uint8_t ttl
How many more hops can this packet be forwarded?
unsigned int return_code
See GNUNET_TUN_DNS_RETURN_CODE_ defines.
static void expire(void *cls)
Expire a PooledConnection object.
static int echo
Request echo service.
Definition: gnunet-cadet.c:67
void GNUNET_TUN_ipv4toregexsearch(const struct in_addr *ip, uint16_t port, char *rxstr)
Create a regex in rxstr from the given ip and port.
Definition: regex.c:45
DNS query prefix.
UDP packet header.
Standard IPv4 header.
Payload of DNS CERT record.
uint8_t usage
Certificate usage 0: CA cert 1: Entity cert 2: Trust anchor 3: domain-issued cert.
uint16_t flags
Some flags (unused).
void GNUNET_TUN_calculate_udp4_checksum(const struct GNUNET_TUN_IPv4Header *ip, struct GNUNET_TUN_UdpHeader *udp, const void *payload, uint16_t payload_length)
Calculate IPv4 UDP checksum.
Definition: tun.c:183
uint8_t hop_limit
How many more hops can this packet be forwarded?
void GNUNET_TUN_calculate_tcp6_checksum(const struct GNUNET_TUN_IPv6Header *ip, struct GNUNET_TUN_TcpHeader *tcp, const void *payload, uint16_t payload_length)
Calculate IPv6 TCP checksum.
Definition: tun.c:147
unsigned int recursion_available
Set to 1 if recursion is available (server -> client)
void GNUNET_TUN_initialize_ipv4_header(struct GNUNET_TUN_IPv4Header *ip, uint8_t protocol, uint16_t payload_length, const struct in_addr *src, const struct in_addr *dst)
Initialize an IPv4 header.
Definition: tun.c:46
void GNUNET_TUN_calculate_udp6_checksum(const struct GNUNET_TUN_IPv6Header *ip, struct GNUNET_TUN_UdpHeader *udp, const void *payload, uint16_t payload_length)
Calculate IPv6 UDP checksum.
Definition: tun.c:222
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
unsigned int authoritative_answer
Set to 1 if this is an authoritative answer.
General DNS record prefix.
cryptographic primitives for GNUnet
unsigned int authenticated_data
Response has been cryptographically verified, RFC 4035.
unsigned int query_or_response
query:0, response:1
void GNUNET_TUN_calculate_tcp4_checksum(const struct GNUNET_TUN_IPv4Header *ip, struct GNUNET_TUN_TcpHeader *tcp, const void *payload, uint16_t payload_length)
Calculate IPv4 TCP checksum.
Definition: tun.c:109
uint16_t cert_tag
Certificate KeyTag.
uint8_t algorithm
Algorithm.
Payload of DNSSEC TLSA record.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
unsigned int fragmentation_offset
unsigned int recursion_desired
Set to 1 if recursion is desired (client -> server)
void GNUNET_TUN_service_name_to_hash(const char *service_name, struct GNUNET_HashCode *hc)
Hash the service name of a hosted service to the hash code that is used to identify the service on th...
Definition: regex.c:804
unsigned int message_truncated
Set to 1 if message is truncated.
unsigned int opcode
See GNUNET_TUN_DNS_OPCODE_ defines.
A 512-bit hashcode.
Header from Linux TUN interface.
uint8_t next_header
For example, IPPROTO_UDP or IPPROTO_TCP.
void GNUNET_TUN_ipv6toregexsearch(const struct in6_addr *ipv6, uint16_t port, char *rxstr)
Create a regex in rxstr from the given ipv6 and port.
Definition: regex.c:66
int GNUNET_TUN_sockaddr_cmp(const struct sockaddr *sa, const struct sockaddr *sb, int include_port)
Check if two sockaddrs are equal.
Definition: tun.c:284
unsigned int reserved
Reserved.
void GNUNET_TUN_compute_service_cadet_port(const struct GNUNET_HashCode *desc, uint16_t ip_port, struct GNUNET_HashCode *cadet_port)
Compute the CADET port given a service descriptor (returned from GNUNET_TUN_service_name_to_hash) and...
Definition: regex.c:823
uint16_t proto
The protocol to use.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
uint16_t cert_type
Certificate type.
uint8_t matching_type
Matching type (of selected content) 0: exact match 1: SHA-256 hash 2: SHA-512 hash.
void GNUNET_TUN_calculate_icmp_checksum(struct GNUNET_TUN_IcmpHeader *icmp, const void *payload, uint16_t payload_length)
Calculate ICMP checksum.
Definition: tun.c:260
TCP packet header.
static unsigned long long payload
How much data are we currently storing in the database?
static int tcp
Option -t: TCP requested.
Definition: gnunet-vpn.c:71
Standard IPv6 header.
uint8_t protocol
L4-protocol, for example, IPPROTO_UDP or IPPROTO_TCP.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
uint8_t selector
Selector What part will be matched against the cert presented by server 0: Full cert (in binary) 1: F...
Payload of DNS SRV record (header).
The identity of the host (wraps the signing key of the peer).
#define GNUNET_PACKED
gcc-ism to get packed structs.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
unsigned int traffic_class_h
char * GNUNET_TUN_ipv6policy2regex(const char *policy)
Convert an exit policy to a regular expression.
Definition: regex.c:751
static struct GNUNET_CADET_Port * cadet_port
Listen port for incoming requests.
Payload of DNS SOA record (header).
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
static unsigned long long reserved
How much space have we currently reserved?
unsigned int off
Number of 32-bit words in TCP header.
void GNUNET_TUN_initialize_ipv6_header(struct GNUNET_TUN_IPv6Header *ip, uint8_t protocol, uint16_t payload_length, const struct in6_addr *src, const struct in6_addr *dst)
Initialize an IPv6 header.
Definition: tun.c:81
unsigned int checking_disabled
See RFC 4035.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:66