GNUnet 0.22.2
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
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
41#ifndef GNUNET_TUN_LIB_H
42#define GNUNET_TUN_LIB_H
43
44
45/* see http://www.iana.org/assignments/ethernet-numbers */
46#ifndef ETH_P_IPV4
50#define ETH_P_IPV4 0x0800
51#endif
52
53#ifndef ETH_P_IPV6
57#define ETH_P_IPV6 0x86DD
58#endif
59
60
68#define GNUNET_TUN_IPV4_REGEXLEN 16
69
70
77#define GNUNET_TUN_IPV6_REGEXLEN 40
78
79
81
86{
91
96};
97
98
103{
104#if __BYTE_ORDER == __LITTLE_ENDIAN
105 unsigned int header_length : 4 GNUNET_PACKED;
106 unsigned int version : 4 GNUNET_PACKED;
107#elif __BYTE_ORDER == __BIG_ENDIAN
108 unsigned int version : 4 GNUNET_PACKED;
109 unsigned int header_length : 4 GNUNET_PACKED;
110#else
111#error byteorder undefined
112#endif
113 uint8_t diff_serv;
114
119
124
125 unsigned int flags : 3 GNUNET_PACKED;
126
128
132 uint8_t ttl;
133
137 uint8_t protocol;
138
143
147 struct in_addr source_address;
148
152 struct in_addr destination_address;
154
155
160{
161#if __BYTE_ORDER == __LITTLE_ENDIAN
163 unsigned int version : 4 GNUNET_PACKED;
165 unsigned int flow_label : 20 GNUNET_PACKED;
166#elif __BYTE_ORDER == __BIG_ENDIAN
167 unsigned int version : 4 GNUNET_PACKED;
168 unsigned int traffic_class : 8 GNUNET_PACKED;
169 unsigned int flow_label : 20 GNUNET_PACKED;
170#else
171#error byteorder undefined
172#endif
177
181 uint8_t next_header;
182
186 uint8_t hop_limit;
187
192
198
199
203#define GNUNET_TUN_TCP_FLAGS_FIN 1
204#define GNUNET_TUN_TCP_FLAGS_SYN 2
205#define GNUNET_TUN_TCP_FLAGS_RST 4
206#define GNUNET_TUN_TCP_FLAGS_PSH 8
207#define GNUNET_TUN_TCP_FLAGS_ACK 16
208#define GNUNET_TUN_TCP_FLAGS_URG 32
209#define GNUNET_TUN_TCP_FLAGS_ECE 64
210#define GNUNET_TUN_TCP_FLAGS_CWR 128
211
216{
221
226
231
236#if __BYTE_ORDER == __LITTLE_ENDIAN
240 unsigned int reserved : 4 GNUNET_PACKED;
244 unsigned int off : 4 GNUNET_PACKED;
245#elif __BYTE_ORDER == __BIG_ENDIAN
249 unsigned int off : 4 GNUNET_PACKED;
253 unsigned int reserved : 4 GNUNET_PACKED;
254#else
255#error byteorder undefined
256#endif
257
261 uint8_t flags;
262
267
272
278
279
284{
289
294
299
304};
305
306
311#define GNUNET_TUN_DNS_CLASS_INTERNET 1
312#define GNUNET_TUN_DNS_CLASS_CHAOS 3
313#define GNUNET_TUN_DNS_CLASS_HESIOD 4
314
315#define GNUNET_TUN_DNS_OPCODE_QUERY 0
316#define GNUNET_TUN_DNS_OPCODE_INVERSE_QUERY 1
317#define GNUNET_TUN_DNS_OPCODE_STATUS 2
318
319
323#define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR 0
324#define GNUNET_TUN_DNS_RETURN_CODE_FORMAT_ERROR 1
325#define GNUNET_TUN_DNS_RETURN_CODE_SERVER_FAILURE 2
326#define GNUNET_TUN_DNS_RETURN_CODE_NAME_ERROR 3
327#define GNUNET_TUN_DNS_RETURN_CODE_NOT_IMPLEMENTED 4
328#define GNUNET_TUN_DNS_RETURN_CODE_REFUSED 5
329
333#define GNUNET_TUN_DNS_RETURN_CODE_YXDOMAIN 6
334#define GNUNET_TUN_DNS_RETURN_CODE_YXRRSET 7
335#define GNUNET_TUN_DNS_RETURN_CODE_NXRRSET 8
336#define GNUNET_TUN_DNS_RETURN_CODE_NOT_AUTH 9
337#define GNUNET_TUN_DNS_RETURN_CODE_NOT_ZONE 10
338
339
344{
345#if __BYTE_ORDER == __LITTLE_ENDIAN
350
355
360
364 unsigned int opcode : 4 GNUNET_PACKED;
365
370
374 unsigned int return_code : 4 GNUNET_PACKED;
375
380
385
389 unsigned int zero : 1 GNUNET_PACKED;
390
395#elif __BYTE_ORDER == __BIG_ENDIAN
399 unsigned int query_or_response : 1 GNUNET_PACKED;
400
404 unsigned int opcode : 4 GNUNET_PACKED;
405
409 unsigned int authoritative_answer : 1 GNUNET_PACKED;
410
414 unsigned int message_truncated : 1 GNUNET_PACKED;
415
419 unsigned int recursion_desired : 1 GNUNET_PACKED;
420
421
425 unsigned int recursion_available : 1 GNUNET_PACKED;
426
430 unsigned int zero : 1 GNUNET_PACKED;
431
435 unsigned int authenticated_data : 1 GNUNET_PACKED;
436
440 unsigned int checking_disabled : 1 GNUNET_PACKED;
441
445 unsigned int return_code : 4 GNUNET_PACKED;
446#else
447#error byteorder undefined
448#endif
450
451
456{
460 uint16_t id GNUNET_PACKED;
461
466
471
476
481
486};
487
488
493{
498
503
509
515
521};
522
523
528{
535
542
547
548 /* followed by 'target' name */
549};
550
551
556{
563
570
571 /* followed by 'target' name */
572};
573
574
579{
583 uint16_t cert_type;
584
588 uint16_t cert_tag;
589
593 uint8_t algorithm;
594
595 /* Followed by the certificate */
596};
597
598
604{
612 uint8_t usage;
613
621 uint8_t selector;
622
630
642};
643
644
649{
654
658 uint16_t proto;
659
660 /* followed by the servicename */
661};
662
663
668{
673
678};
679
680
685{
690
695
700
705};
706
707
708#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0
709#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3
710#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4
711#define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5
712#define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8
713#define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9
714#define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10
715#define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11
716
717#define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1
718#define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2
719#define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3
720#define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4
721#define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128
722#define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129
723
724
729{
730 uint8_t type;
731 uint8_t code;
733
734 union
735 {
739 struct
740 {
744
748 struct ih_pmtu
749 {
752 /* followed by original IP header + first 8 bytes of original IP datagram
753 */
755
760
766};
767
768
770
771
782void
784 uint8_t protocol,
785 uint16_t payload_length,
786 const struct in_addr *src,
787 const struct in_addr *dst);
788
789
800void
802 uint8_t protocol,
803 uint16_t payload_length,
804 const struct in6_addr *src,
805 const struct in6_addr *dst);
806
815void
818 const void *payload,
819 uint16_t payload_length);
820
829void
832 const void *payload,
833 uint16_t payload_length);
834
843void
846 const void *payload,
847 uint16_t payload_length);
848
849
858void
861 const void *payload,
862 uint16_t payload_length);
863
864
872void
874 const void *payload,
875 uint16_t payload_length);
876
877
886void
888 struct GNUNET_HashCode *hc);
889
890
899int
900GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa,
901 const struct sockaddr *sb,
902 int include_port);
903
904
914void
916 uint16_t ip_port,
918
919#endif
920 /* end of group */
922 /* end of group addition */
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:50
static int udp
Option -u: UDP requested.
Definition: gnunet-vpn.c:75
static int tcp
Option -t: TCP requested.
Definition: gnunet-vpn.c:70
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#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:115
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:193
GNUNET_NETWORK_STRUCT_END 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:80
void GNUNET_TUN_calculate_icmp_checksum(struct GNUNET_TUN_IcmpHeader *icmp, const void *payload, uint16_t payload_length)
Calculate ICMP checksum.
Definition: tun.c:255
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: tun.c:57
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:165
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: tun.c:38
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:279
struct GNUNET_TUN_IPv4Header GNUNET_GCC_STRUCT_LAYOUT
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:135
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:224
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 DNS URI 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.
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::@33 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::@33::ih_pmtu destination_unreachable
struct GNUNET_TUN_IcmpHeader::@33::@34 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).