Standard TCP/IP network structs and IP checksum calculations for TUN interaction. More...
Data Structures | |
struct | GNUNET_TUN_Layer2PacketHeader |
Header from Linux TUN interface. More... | |
struct | GNUNET_TUN_IPv4Header |
Standard IPv4 header. More... | |
struct | GNUNET_TUN_IPv6Header |
Standard IPv6 header. More... | |
struct | GNUNET_TUN_TcpHeader |
TCP packet header. More... | |
struct | GNUNET_TUN_UdpHeader |
UDP packet header. More... | |
struct | GNUNET_TUN_DnsFlags |
DNS flags (largely RFC 1035 / RFC 2136). More... | |
struct | GNUNET_TUN_DnsHeader |
DNS header. More... | |
struct | GNUNET_TUN_DnsSoaRecord |
Payload of DNS SOA record (header). More... | |
struct | GNUNET_TUN_DnsSrvRecord |
Payload of DNS SRV record (header). More... | |
struct | GNUNET_TUN_DnsUriRecord |
Payload of DNS URI record (header). More... | |
struct | GNUNET_TUN_DnsCertRecord |
Payload of DNS CERT record. More... | |
struct | GNUNET_TUN_DnsTlsaRecord |
Payload of DNSSEC TLSA record. More... | |
struct | GNUNET_TUN_GnsVpnRecord |
Payload of GNS VPN record. More... | |
struct | GNUNET_TUN_DnsQueryLine |
DNS query prefix. More... | |
struct | GNUNET_TUN_DnsRecordLine |
General DNS record prefix. More... | |
struct | GNUNET_TUN_IcmpHeader |
ICMP header. More... | |
Functions | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, const void *payload, uint16_t payload_length) |
Calculate ICMP checksum. More... | |
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 the network. More... | |
int | GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa, const struct sockaddr *sb, int include_port) |
Check if two sockaddrs are equal. More... | |
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 a TCP/UDP port ip_port. More... | |
Variables | |
struct GNUNET_TUN_IPv4Header | GNUNET_GCC_STRUCT_LAYOUT |
Standard TCP/IP network structs and IP checksum calculations for TUN interaction.
#define ETH_P_IPV4 0x0800 |
Number for IPv4.
Definition at line 50 of file gnunet_tun_lib.h.
#define ETH_P_IPV6 0x86DD |
Number for IPv6.
Definition at line 57 of file gnunet_tun_lib.h.
#define GNUNET_TUN_IPV4_REGEXLEN 16 |
Maximum regex string length for use with GNUNET_REGEX_ipv4toregexsearch.
8 bytes for IPv4, 4 bytes for port, 1 byte for "4", 2 bytes for "-", one byte for 0-termination.
Definition at line 68 of file gnunet_tun_lib.h.
#define GNUNET_TUN_IPV6_REGEXLEN 40 |
Maximum regex string length for use with GNUNET_REGEX_ipv6toregexsearch.
32 bytes for IPv4, 4 bytes for port, 1 byte for "4", 2 bytes for "-", one byte for 0-termination.
Definition at line 77 of file gnunet_tun_lib.h.
#define GNUNET_TUN_TCP_FLAGS_FIN 1 |
TCP flags.
Definition at line 203 of file gnunet_tun_lib.h.
#define GNUNET_TUN_TCP_FLAGS_SYN 2 |
Definition at line 204 of file gnunet_tun_lib.h.
#define GNUNET_TUN_TCP_FLAGS_RST 4 |
Definition at line 205 of file gnunet_tun_lib.h.
#define GNUNET_TUN_TCP_FLAGS_PSH 8 |
Definition at line 206 of file gnunet_tun_lib.h.
#define GNUNET_TUN_TCP_FLAGS_ACK 16 |
Definition at line 207 of file gnunet_tun_lib.h.
#define GNUNET_TUN_TCP_FLAGS_URG 32 |
Definition at line 208 of file gnunet_tun_lib.h.
#define GNUNET_TUN_TCP_FLAGS_ECE 64 |
Definition at line 209 of file gnunet_tun_lib.h.
#define GNUNET_TUN_TCP_FLAGS_CWR 128 |
Definition at line 210 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_CLASS_INTERNET 1 |
A few common DNS classes (ok, only one is common, but I list a couple more to make it clear what we're talking about here).
Definition at line 311 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_CLASS_CHAOS 3 |
Definition at line 312 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_CLASS_HESIOD 4 |
Definition at line 313 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_OPCODE_QUERY 0 |
Definition at line 315 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_OPCODE_INVERSE_QUERY 1 |
Definition at line 316 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_OPCODE_STATUS 2 |
Definition at line 317 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR 0 |
RFC 1035 codes.
Definition at line 323 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_FORMAT_ERROR 1 |
Definition at line 324 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_SERVER_FAILURE 2 |
Definition at line 325 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_NAME_ERROR 3 |
Definition at line 326 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_NOT_IMPLEMENTED 4 |
Definition at line 327 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_REFUSED 5 |
Definition at line 328 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_YXDOMAIN 6 |
RFC 2136 codes.
Definition at line 333 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_YXRRSET 7 |
Definition at line 334 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_NXRRSET 8 |
Definition at line 335 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_NOT_AUTH 9 |
Definition at line 336 of file gnunet_tun_lib.h.
#define GNUNET_TUN_DNS_RETURN_CODE_NOT_ZONE 10 |
Definition at line 337 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0 |
Definition at line 708 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3 |
Definition at line 709 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4 |
Definition at line 710 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5 |
Definition at line 711 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8 |
Definition at line 712 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9 |
Definition at line 713 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10 |
Definition at line 714 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11 |
Definition at line 715 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1 |
Definition at line 717 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2 |
Definition at line 718 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3 |
Definition at line 719 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4 |
Definition at line 720 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128 |
Definition at line 721 of file gnunet_tun_lib.h.
#define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129 |
Definition at line 722 of file gnunet_tun_lib.h.
struct GNUNET_TUN_DnsFlags GNUNET_GCC_STRUCT_LAYOUT |
gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields
Definition at line 243 of file gnunet_common.h.
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.
ip | header to initialize |
protocol | protocol to use (e.g. IPPROTO_UDP) |
payload_length | number of bytes of payload that follow (excluding IPv4 header) |
src | source IP address to use |
dst | destination IP address to use |
Definition at line 80 of file tun.c.
References GNUNET_TUN_IPv4Header::checksum, GNUNET_TUN_IPv4Header::destination_address, FRESH_TTL, GNUNET_assert, GNUNET_CRYPTO_crc16_n(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_TUN_IPv4Header::header_length, GNUNET_TUN_IPv4Header::identification, GNUNET_TUN_IPv4Header::protocol, GNUNET_TUN_IPv4Header::source_address, GNUNET_TUN_IPv4Header::total_length, GNUNET_TUN_IPv4Header::ttl, and GNUNET_TUN_IPv4Header::version.
Referenced by handle_icmp_back(), handle_tcp_back(), handle_udp_back(), make_up_icmpv4_payload(), prepare_ipv4_packet(), request_done(), and send_icmp_packet_via_tun().
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.
ip | header to initialize |
protocol | protocol to use (e.g. IPPROTO_UDP) |
payload_length | number of bytes of payload that follow (excluding IPv4 header) |
src | source IP address to use |
dst | destination IP address to use |
ip | header to initialize |
protocol | protocol to use (e.g. IPPROTO_UDP), technically "next_header" for IPv6 |
payload_length | number of bytes of payload that follow (excluding IPv6 header) |
src | source IP address to use |
dst | destination IP address to use |
Definition at line 115 of file tun.c.
References GNUNET_TUN_IPv6Header::destination_address, FRESH_TTL, GNUNET_assert, GNUNET_TUN_IPv6Header::hop_limit, GNUNET_TUN_IPv6Header::next_header, GNUNET_TUN_IPv6Header::payload_length, GNUNET_TUN_IPv4Header::protocol, GNUNET_TUN_IPv6Header::source_address, and GNUNET_TUN_IPv6Header::version.
Referenced by handle_icmp_back(), handle_tcp_back(), handle_udp_back(), make_up_icmpv6_payload(), prepare_ipv6_packet(), request_done(), and send_icmp_packet_via_tun().
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.
ip | ipv4 header fully initialized |
tcp | TCP header (initialized except for CRC) |
payload | the TCP payload |
payload_length | number of bytes of TCP payload |
Definition at line 135 of file tun.c.
References GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), payload, GNUNET_TUN_IPv4Header::protocol, GNUNET_TUN_IPv4Header::source_address, consensus-simulation::sum, tcp, and GNUNET_TUN_IPv4Header::total_length.
Referenced by handle_tcp_back(), and prepare_ipv4_packet().
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.
ip | ipv6 header fully initialized |
tcp | TCP header (initialized except for CRC) |
payload | the TCP payload |
payload_length | number of bytes of TCP payload |
Definition at line 165 of file tun.c.
References GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), GNUNET_TUN_IPv6Header::next_header, payload, GNUNET_TUN_IPv6Header::payload_length, GNUNET_TUN_IPv6Header::source_address, consensus-simulation::sum, and tcp.
Referenced by handle_tcp_back(), and prepare_ipv6_packet().
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.
ip | ipv4 header fully initialized |
udp | UDP header (initialized except for CRC) |
payload | the UDP payload |
payload_length | number of bytes of UDP payload |
Definition at line 193 of file tun.c.
References GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), payload, GNUNET_TUN_IPv4Header::protocol, GNUNET_TUN_IPv4Header::source_address, consensus-simulation::sum, GNUNET_TUN_IPv4Header::total_length, and udp.
Referenced by handle_udp_back(), prepare_ipv4_packet(), and request_done().
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.
ip | ipv6 header fully initialized |
udp | UDP header (initialized except for CRC) |
payload | the UDP payload |
payload_length | number of bytes of payload |
Definition at line 224 of file tun.c.
References GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), GNUNET_TUN_IPv6Header::next_header, payload, GNUNET_TUN_IPv6Header::payload_length, GNUNET_TUN_IPv6Header::source_address, consensus-simulation::sum, and udp.
Referenced by handle_udp_back(), prepare_ipv6_packet(), and request_done().
void GNUNET_TUN_calculate_icmp_checksum | ( | struct GNUNET_TUN_IcmpHeader * | icmp, |
const void * | payload, | ||
uint16_t | payload_length | ||
) |
Calculate ICMP checksum.
icmp | IMCP header (initialized except for CRC) |
payload | the ICMP payload |
payload_length | number of bytes of payload |
Definition at line 255 of file tun.c.
References GNUNET_TUN_IcmpHeader::crc, GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), payload, and consensus-simulation::sum.
Referenced by handle_icmp_back(), and send_icmp_packet_via_tun().
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 the network.
service_name | a string | |
[out] | hc | corresponding hash |
Definition at line 38 of file tun.c.
References GNUNET_CRYPTO_hash(), and service_name.
Referenced by result_processor(), run(), and store_service().
int GNUNET_TUN_sockaddr_cmp | ( | const struct sockaddr * | sa, |
const struct sockaddr * | sb, | ||
int | include_port | ||
) |
Check if two sockaddrs are equal.
sa | one address |
sb | another address |
include_port | also check ports |
Definition at line 279 of file tun.c.
References GNUNET_break, GNUNET_NO, and GNUNET_SYSERR.
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 a TCP/UDP port ip_port.
desc | service shared secret | |
ip_port | TCP/UDP port, use 0 for ICMP | |
[out] | cadet_port | CADET port to use |
Definition at line 57 of file tun.c.
References cadet_port, and GNUNET_memcpy.
Referenced by create_channel_to_destination(), and store_service().
struct GNUNET_TUN_DnsFlags GNUNET_GCC_STRUCT_LAYOUT |