GNUnet  0.17.6
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 
37 #ifndef GNUNET_TUN_LIB_H
38 #define GNUNET_TUN_LIB_H
39 
40 #include "gnunet_common.h"
41 #include "gnunet_crypto_lib.h"
42 
43 
44 /* see http://www.iana.org/assignments/ethernet-numbers */
45 #ifndef ETH_P_IPV4
49 #define ETH_P_IPV4 0x0800
50 #endif
51 
52 #ifndef ETH_P_IPV6
56 #define ETH_P_IPV6 0x86DD
57 #endif
58 
59 
67 #define GNUNET_TUN_IPV4_REGEXLEN 16
68 
69 
76 #define GNUNET_TUN_IPV6_REGEXLEN 40
77 
78 
80 
85 {
89  uint16_t flags GNUNET_PACKED;
90 
94  uint16_t proto GNUNET_PACKED;
95 };
96 
97 
102 {
103 #if __BYTE_ORDER == __LITTLE_ENDIAN
104  unsigned int header_length : 4 GNUNET_PACKED;
105  unsigned int version : 4 GNUNET_PACKED;
106 #elif __BYTE_ORDER == __BIG_ENDIAN
107  unsigned int version : 4 GNUNET_PACKED;
108  unsigned int header_length : 4 GNUNET_PACKED;
109 #else
110 #error byteorder undefined
111 #endif
112  uint8_t diff_serv;
113 
118 
123 
124  unsigned int flags : 3 GNUNET_PACKED;
125 
127 
131  uint8_t ttl;
132 
136  uint8_t protocol;
137 
142 
146  struct in_addr source_address;
147 
151  struct in_addr destination_address;
153 
154 
159 {
160 #if __BYTE_ORDER == __LITTLE_ENDIAN
161  unsigned int traffic_class_h : 4 GNUNET_PACKED;
162  unsigned int version : 4 GNUNET_PACKED;
163  unsigned int traffic_class_l : 4 GNUNET_PACKED;
164  unsigned int flow_label : 20 GNUNET_PACKED;
165 #elif __BYTE_ORDER == __BIG_ENDIAN
166  unsigned int version : 4 GNUNET_PACKED;
167  unsigned int traffic_class : 8 GNUNET_PACKED;
168  unsigned int flow_label : 20 GNUNET_PACKED;
169 #else
170 #error byteorder undefined
171 #endif
176 
180  uint8_t next_header;
181 
185  uint8_t hop_limit;
186 
190  struct in6_addr source_address GNUNET_PACKED;
191 
195  struct in6_addr destination_address GNUNET_PACKED;
197 
198 
202 #define GNUNET_TUN_TCP_FLAGS_FIN 1
203 #define GNUNET_TUN_TCP_FLAGS_SYN 2
204 #define GNUNET_TUN_TCP_FLAGS_RST 4
205 #define GNUNET_TUN_TCP_FLAGS_PSH 8
206 #define GNUNET_TUN_TCP_FLAGS_ACK 16
207 #define GNUNET_TUN_TCP_FLAGS_URG 32
208 #define GNUNET_TUN_TCP_FLAGS_ECE 64
209 #define GNUNET_TUN_TCP_FLAGS_CWR 128
210 
215 {
220 
225 
229  uint32_t seq GNUNET_PACKED;
230 
234  uint32_t ack GNUNET_PACKED;
235 #if __BYTE_ORDER == __LITTLE_ENDIAN
239  unsigned int reserved : 4 GNUNET_PACKED;
243  unsigned int off : 4 GNUNET_PACKED;
244 #elif __BYTE_ORDER == __BIG_ENDIAN
248  unsigned int off : 4 GNUNET_PACKED;
252  unsigned int reserved : 4 GNUNET_PACKED;
253 #else
254 #error byteorder undefined
255 #endif
256 
260  uint8_t flags;
261 
266 
270  uint16_t crc GNUNET_PACKED;
271 
277 
278 
283 {
288 
293 
297  uint16_t len GNUNET_PACKED;
298 
302  uint16_t crc GNUNET_PACKED;
303 };
304 
305 
310 #define GNUNET_TUN_DNS_CLASS_INTERNET 1
311 #define GNUNET_TUN_DNS_CLASS_CHAOS 3
312 #define GNUNET_TUN_DNS_CLASS_HESIOD 4
313 
314 #define GNUNET_TUN_DNS_OPCODE_QUERY 0
315 #define GNUNET_TUN_DNS_OPCODE_INVERSE_QUERY 1
316 #define GNUNET_TUN_DNS_OPCODE_STATUS 2
317 
318 
322 #define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR 0
323 #define GNUNET_TUN_DNS_RETURN_CODE_FORMAT_ERROR 1
324 #define GNUNET_TUN_DNS_RETURN_CODE_SERVER_FAILURE 2
325 #define GNUNET_TUN_DNS_RETURN_CODE_NAME_ERROR 3
326 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_IMPLEMENTED 4
327 #define GNUNET_TUN_DNS_RETURN_CODE_REFUSED 5
328 
332 #define GNUNET_TUN_DNS_RETURN_CODE_YXDOMAIN 6
333 #define GNUNET_TUN_DNS_RETURN_CODE_YXRRSET 7
334 #define GNUNET_TUN_DNS_RETURN_CODE_NXRRSET 8
335 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_AUTH 9
336 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_ZONE 10
337 
338 
343 {
344 #if __BYTE_ORDER == __LITTLE_ENDIAN
349 
354 
359 
363  unsigned int opcode : 4 GNUNET_PACKED;
364 
369 
373  unsigned int return_code : 4 GNUNET_PACKED;
374 
379 
384 
388  unsigned int zero : 1 GNUNET_PACKED;
389 
394 #elif __BYTE_ORDER == __BIG_ENDIAN
398  unsigned int query_or_response : 1 GNUNET_PACKED;
399 
403  unsigned int opcode : 4 GNUNET_PACKED;
404 
408  unsigned int authoritative_answer : 1 GNUNET_PACKED;
409 
413  unsigned int message_truncated : 1 GNUNET_PACKED;
414 
418  unsigned int recursion_desired : 1 GNUNET_PACKED;
419 
420 
424  unsigned int recursion_available : 1 GNUNET_PACKED;
425 
429  unsigned int zero : 1 GNUNET_PACKED;
430 
434  unsigned int authenticated_data : 1 GNUNET_PACKED;
435 
439  unsigned int checking_disabled : 1 GNUNET_PACKED;
440 
444  unsigned int return_code : 4 GNUNET_PACKED;
445 #else
446 #error byteorder undefined
447 #endif
449 
450 
455 {
459  uint16_t id GNUNET_PACKED;
460 
464  struct GNUNET_TUN_DnsFlags flags;
465 
470 
475 
480 
485 };
486 
487 
492 {
497 
502 
508 
514 
520 };
521 
522 
527 {
533  uint16_t prio GNUNET_PACKED;
534 
541 
545  uint16_t port GNUNET_PACKED;
546 
547  /* followed by 'target' name */
548 };
549 
550 
555 {
559  uint16_t cert_type;
560 
564  uint16_t cert_tag;
565 
569  uint8_t algorithm;
570 
571  /* Followed by the certificate */
572 };
573 
574 
580 {
588  uint8_t usage;
589 
597  uint8_t selector;
598 
605  uint8_t matching_type;
606 
618 };
619 
620 
625 {
629  struct GNUNET_PeerIdentity peer;
630 
634  uint16_t proto;
635 
636  /* followed by the servicename */
637 };
638 
639 
644 {
648  uint16_t type GNUNET_PACKED;
649 
654 };
655 
656 
661 {
665  uint16_t type GNUNET_PACKED;
666 
671 
675  uint32_t ttl GNUNET_PACKED;
676 
681 };
682 
683 
684 #define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0
685 #define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3
686 #define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4
687 #define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5
688 #define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8
689 #define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9
690 #define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10
691 #define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11
692 
693 #define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1
694 #define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2
695 #define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3
696 #define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4
697 #define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128
698 #define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129
699 
700 
705 {
706  uint8_t type;
707  uint8_t code;
708  uint16_t crc GNUNET_PACKED;
709 
710  union
711  {
715  struct
716  {
719  } echo;
720 
724  struct ih_pmtu
725  {
728  /* followed by original IP header + first 8 bytes of original IP datagram
729  */
731 
735  struct in_addr redirect_gateway_address;
736 
742 };
743 
744 
746 
747 
758 void
760  uint8_t protocol,
761  uint16_t payload_length,
762  const struct in_addr *src,
763  const struct in_addr *dst);
764 
765 
776 void
778  uint8_t protocol,
779  uint16_t payload_length,
780  const struct in6_addr *src,
781  const struct in6_addr *dst);
782 
791 void
793  struct GNUNET_TUN_TcpHeader *tcp,
794  const void *payload,
795  uint16_t payload_length);
796 
805 void
807  struct GNUNET_TUN_TcpHeader *tcp,
808  const void *payload,
809  uint16_t payload_length);
810 
819 void
821  struct GNUNET_TUN_UdpHeader *udp,
822  const void *payload,
823  uint16_t payload_length);
824 
825 
834 void
836  struct GNUNET_TUN_UdpHeader *udp,
837  const void *payload,
838  uint16_t payload_length);
839 
840 
848 void
850  const void *payload,
851  uint16_t payload_length);
852 
853 
862 void
863 GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip,
864  uint16_t port,
865  char *rxstr);
866 
867 
876 void
877 GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6,
878  uint16_t port,
879  char *rxstr);
880 
881 
891 char *
892 GNUNET_TUN_ipv6policy2regex (const char *policy);
893 
894 
904 char *
905 GNUNET_TUN_ipv4policy2regex (const char *policy);
906 
907 
916 void
918  struct GNUNET_HashCode *hc);
919 
920 
929 int
930 GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa,
931  const struct sockaddr *sb,
932  int include_port);
933 
934 
944 void
946  uint16_t ip_port,
947  struct GNUNET_HashCode *cadet_port);
948 
949 #endif
950  /* end of group */
952  /* end of group addition */
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static unsigned long long payload
How much data are we currently storing in the database?
static struct GNUNET_CADET_Port * cadet_port
Listen port for incoming requests.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
static int udp
Option -u: UDP requested.
Definition: gnunet-vpn.c:76
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:66
static int tcp
Option -t: TCP requested.
Definition: gnunet-vpn.c:71
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
cryptographic primitives for GNUnet
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_GCC_STRUCT_LAYOUT
gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
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
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
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
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
char * GNUNET_TUN_ipv4policy2regex(const char *policy)
Convert an exit policy to a regular expression.
Definition: regex.c:707
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:833
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
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_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:814
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
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
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
char * GNUNET_TUN_ipv6policy2regex(const char *policy)
Convert an exit policy to a regular expression.
Definition: regex.c:759
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
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
Payload of DNS CERT record.
uint16_t cert_type
Certificate type.
uint16_t cert_tag
Certificate KeyTag.
uint8_t algorithm
Algorithm.
DNS flags (largely RFC 1035 / RFC 2136).
unsigned int checking_disabled
See RFC 4035.
unsigned int zero
Always zero.
unsigned int message_truncated
Set to 1 if message is truncated.
unsigned int query_or_response
query:0, response:1
unsigned int return_code
See GNUNET_TUN_DNS_RETURN_CODE_ defines.
unsigned int recursion_available
Set to 1 if recursion is available (server -> client)
unsigned int opcode
See GNUNET_TUN_DNS_OPCODE_ defines.
unsigned int recursion_desired
Set to 1 if recursion is desired (client -> server)
unsigned int authenticated_data
Response has been cryptographically verified, RFC 4035.
unsigned int authoritative_answer
Set to 1 if this is an authoritative answer.
struct GNUNET_TUN_DnsFlags flags
Flags.
uint16_t query_count
Number of queries.
uint16_t authority_rcount
Number of authoritative answers.
uint16_t additional_rcount
Number of additional records.
uint16_t answer_rcount
Number of answers.
DNS query prefix.
uint16_t type
Desired type (GNUNET_DNSPARSER_TYPE_XXX).
uint16_t dns_traffic_class
Desired class (usually GNUNET_TUN_DNS_CLASS_INTERNET).
General DNS record prefix.
uint32_t ttl
Expiration for the record (in seconds).
uint16_t dns_traffic_class
Record class (usually GNUNET_TUN_DNS_CLASS_INTERNET).
uint16_t type
Record type (GNUNET_DNSPARSER_TYPE_XXX).
uint16_t data_len
Number of bytes of data that follow.
Payload of DNS SOA record (header).
uint32_t minimum
The bit minimum TTL field that should be exported with any RR from this zone.
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
uint32_t refresh
Time interval before the zone should be refreshed.
uint32_t serial
The version number of the original copy of the zone.
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
Payload of DNS SRV record (header).
uint16_t prio
Preference for this entry (lower value is higher preference).
uint16_t weight
Relative weight for records with the same priority.
uint16_t port
TCP or UDP port of the service.
Payload of DNSSEC TLSA record.
uint8_t selector
Selector What part will be matched against the cert presented by server 0: Full cert (in binary) 1: F...
uint8_t matching_type
Matching type (of selected content) 0: exact match 1: SHA-256 hash 2: SHA-512 hash.
uint8_t usage
Certificate usage 0: CA cert 1: Entity cert 2: Trust anchor 3: domain-issued cert.
Payload of GNS VPN record.
struct GNUNET_PeerIdentity peer
The peer to contact.
uint16_t proto
The protocol to use.
Standard IPv4 header.
uint16_t total_length
Length of the packet, including this header.
uint8_t ttl
How many more hops can this packet be forwarded?
uint8_t protocol
L4-protocol, for example, IPPROTO_UDP or IPPROTO_TCP.
uint16_t checksum
Checksum.
uint16_t identification
Unique random ID for matching up fragments.
unsigned int fragmentation_offset
struct in_addr source_address
Origin of the packet.
struct in_addr destination_address
Destination of the packet.
unsigned int header_length
Standard IPv6 header.
unsigned int traffic_class_h
struct in6_addr source_address
Origin of the packet.
unsigned int traffic_class_l
uint8_t next_header
For example, IPPROTO_UDP or IPPROTO_TCP.
uint8_t hop_limit
How many more hops can this packet be forwarded?
struct in6_addr destination_address
Destination of the packet.
uint16_t payload_length
Length of the payload, excluding this header.
union GNUNET_TUN_IcmpHeader::@50 quench
uint32_t packet_too_big_mtu
MTU for packets that are too big (IPv6).
struct in_addr redirect_gateway_address
ICMP Redirect.
struct GNUNET_TUN_IcmpHeader::@50::ih_pmtu destination_unreachable
struct GNUNET_TUN_IcmpHeader::@50::@51 echo
ICMP Echo (request/reply)
Header from Linux TUN interface.
uint16_t proto
Here we get an ETH_P_-number.
uint16_t flags
Some flags (unused).
TCP packet header.
uint32_t seq
Sequence number.
uint16_t source_port
Source port (in NBO).
unsigned int reserved
Reserved.
uint16_t window_size
Window size.
uint16_t crc
Checksum.
uint32_t ack
Acknowledgement number.
uint16_t urgent_pointer
Urgent pointer.
unsigned int off
Number of 32-bit words in TCP header.
uint16_t destination_port
Destination port (in NBO).
uint8_t flags
Flags (SYN, FIN, ACK, etc.)
UDP packet header.
uint16_t len
Number of bytes of payload.
uint16_t crc
Checksum.
uint16_t destination_port
Destination port (in NBO).
uint16_t source_port
Source port (in NBO).