GNUnet  0.11.x
Data Structures | Macros | Functions
TUN library

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_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...
 

Macros

#define ETH_P_IPV4   0x0800
 Number for IPv4. More...
 
#define ETH_P_IPV6   0x86DD
 Number for IPv6. More...
 
#define GNUNET_TUN_IPV4_REGEXLEN   16
 Maximum regex string length for use with GNUNET_TUN_ipv4toregexsearch. More...
 
#define GNUNET_TUN_IPV6_REGEXLEN   40
 Maximum regex string length for use with GNUNET_TUN_ipv6toregexsearch. More...
 
#define GNUNET_TUN_TCP_FLAGS_FIN   1
 TCP flags. More...
 
#define GNUNET_TUN_TCP_FLAGS_SYN   2
 
#define GNUNET_TUN_TCP_FLAGS_RST   4
 
#define GNUNET_TUN_TCP_FLAGS_PSH   8
 
#define GNUNET_TUN_TCP_FLAGS_ACK   16
 
#define GNUNET_TUN_TCP_FLAGS_URG   32
 
#define GNUNET_TUN_TCP_FLAGS_ECE   64
 
#define GNUNET_TUN_TCP_FLAGS_CWR   128
 
#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). More...
 
#define GNUNET_TUN_DNS_CLASS_CHAOS   3
 
#define GNUNET_TUN_DNS_CLASS_HESIOD   4
 
#define GNUNET_TUN_DNS_OPCODE_QUERY   0
 
#define GNUNET_TUN_DNS_OPCODE_INVERSE_QUERY   1
 
#define GNUNET_TUN_DNS_OPCODE_STATUS   2
 
#define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR   0
 RFC 1035 codes. More...
 
#define GNUNET_TUN_DNS_RETURN_CODE_FORMAT_ERROR   1
 
#define GNUNET_TUN_DNS_RETURN_CODE_SERVER_FAILURE   2
 
#define GNUNET_TUN_DNS_RETURN_CODE_NAME_ERROR   3
 
#define GNUNET_TUN_DNS_RETURN_CODE_NOT_IMPLEMENTED   4
 
#define GNUNET_TUN_DNS_RETURN_CODE_REFUSED   5
 
#define GNUNET_TUN_DNS_RETURN_CODE_YXDOMAIN   6
 RFC 2136 codes. More...
 
#define GNUNET_TUN_DNS_RETURN_CODE_YXRRSET   7
 
#define GNUNET_TUN_DNS_RETURN_CODE_NXRRSET   8
 
#define GNUNET_TUN_DNS_RETURN_CODE_NOT_AUTH   9
 
#define GNUNET_TUN_DNS_RETURN_CODE_NOT_ZONE   10
 
#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY   0
 
#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE   3
 
#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH   4
 
#define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE   5
 
#define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST   8
 
#define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT   9
 
#define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION   10
 
#define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED   11
 
#define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE   1
 
#define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG   2
 
#define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED   3
 
#define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM   4
 
#define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST   128
 
#define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY   129
 

Functions

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_ipv4toregexsearch (const struct in_addr *ip, uint16_t port, char *rxstr)
 Create a regex in rxstr from the given ip and port. More...
 
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. More...
 
char * GNUNET_TUN_ipv6policy2regex (const char *policy)
 Convert an exit policy to a regular expression. More...
 
char * GNUNET_TUN_ipv4policy2regex (const char *policy)
 Convert an exit policy to a regular expression. 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...
 

Detailed Description

Standard TCP/IP network structs and IP checksum calculations for TUN interaction.

Macro Definition Documentation

◆ ETH_P_IPV4

#define ETH_P_IPV4   0x0800

◆ ETH_P_IPV6

#define ETH_P_IPV6   0x86DD

◆ GNUNET_TUN_IPV4_REGEXLEN

#define GNUNET_TUN_IPV4_REGEXLEN   16

Maximum regex string length for use with GNUNET_TUN_ipv4toregexsearch.

8 bytes for IPv4, 4 bytes for port, 1 byte for "4", 2 bytes for "-", one byte for 0-termination.

Definition at line 64 of file gnunet_tun_lib.h.

Referenced by create_channel_to_destination(), and GNUNET_TUN_ipv4toregexsearch().

◆ GNUNET_TUN_IPV6_REGEXLEN

#define GNUNET_TUN_IPV6_REGEXLEN   40

Maximum regex string length for use with GNUNET_TUN_ipv6toregexsearch.

32 bytes for IPv4, 4 bytes for port, 1 byte for "4", 2 bytes for "-", one byte for 0-termination.

Definition at line 73 of file gnunet_tun_lib.h.

Referenced by create_channel_to_destination(), and GNUNET_TUN_ipv6toregexsearch().

◆ GNUNET_TUN_TCP_FLAGS_FIN

#define GNUNET_TUN_TCP_FLAGS_FIN   1

TCP flags.

Definition at line 199 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_TCP_FLAGS_SYN

#define GNUNET_TUN_TCP_FLAGS_SYN   2

Definition at line 200 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_TCP_FLAGS_RST

#define GNUNET_TUN_TCP_FLAGS_RST   4

Definition at line 201 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_TCP_FLAGS_PSH

#define GNUNET_TUN_TCP_FLAGS_PSH   8

Definition at line 202 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_TCP_FLAGS_ACK

#define GNUNET_TUN_TCP_FLAGS_ACK   16

Definition at line 203 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_TCP_FLAGS_URG

#define GNUNET_TUN_TCP_FLAGS_URG   32

Definition at line 204 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_TCP_FLAGS_ECE

#define GNUNET_TUN_TCP_FLAGS_ECE   64

Definition at line 205 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_TCP_FLAGS_CWR

#define GNUNET_TUN_TCP_FLAGS_CWR   128

Definition at line 206 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_CLASS_INTERNET

#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 307 of file gnunet_tun_lib.h.

Referenced by add_host(), build_dns_query(), get_class(), pack(), queue(), recursive_dns_resolution(), reply_to_dns(), and result_processor().

◆ GNUNET_TUN_DNS_CLASS_CHAOS

#define GNUNET_TUN_DNS_CLASS_CHAOS   3

Definition at line 308 of file gnunet_tun_lib.h.

Referenced by get_class().

◆ GNUNET_TUN_DNS_CLASS_HESIOD

#define GNUNET_TUN_DNS_CLASS_HESIOD   4

Definition at line 309 of file gnunet_tun_lib.h.

Referenced by get_class().

◆ GNUNET_TUN_DNS_OPCODE_QUERY

#define GNUNET_TUN_DNS_OPCODE_QUERY   0

Definition at line 311 of file gnunet_tun_lib.h.

Referenced by recursive_dns_resolution().

◆ GNUNET_TUN_DNS_OPCODE_INVERSE_QUERY

#define GNUNET_TUN_DNS_OPCODE_INVERSE_QUERY   1

Definition at line 312 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_OPCODE_STATUS

#define GNUNET_TUN_DNS_OPCODE_STATUS   2

Definition at line 313 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR

#define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR   0

RFC 1035 codes.

Definition at line 319 of file gnunet_tun_lib.h.

Referenced by reply_to_dns(), and result_processor().

◆ GNUNET_TUN_DNS_RETURN_CODE_FORMAT_ERROR

#define GNUNET_TUN_DNS_RETURN_CODE_FORMAT_ERROR   1

Definition at line 320 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_SERVER_FAILURE

#define GNUNET_TUN_DNS_RETURN_CODE_SERVER_FAILURE   2

Definition at line 321 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_NAME_ERROR

#define GNUNET_TUN_DNS_RETURN_CODE_NAME_ERROR   3

Definition at line 322 of file gnunet_tun_lib.h.

Referenced by reply_to_dns().

◆ GNUNET_TUN_DNS_RETURN_CODE_NOT_IMPLEMENTED

#define GNUNET_TUN_DNS_RETURN_CODE_NOT_IMPLEMENTED   4

Definition at line 323 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_REFUSED

#define GNUNET_TUN_DNS_RETURN_CODE_REFUSED   5

Definition at line 324 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_YXDOMAIN

#define GNUNET_TUN_DNS_RETURN_CODE_YXDOMAIN   6

RFC 2136 codes.

Definition at line 329 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_YXRRSET

#define GNUNET_TUN_DNS_RETURN_CODE_YXRRSET   7

Definition at line 330 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_NXRRSET

#define GNUNET_TUN_DNS_RETURN_CODE_NXRRSET   8

Definition at line 331 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_NOT_AUTH

#define GNUNET_TUN_DNS_RETURN_CODE_NOT_AUTH   9

Definition at line 332 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_DNS_RETURN_CODE_NOT_ZONE

#define GNUNET_TUN_DNS_RETURN_CODE_NOT_ZONE   10

Definition at line 333 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_ICMPTYPE_ECHO_REPLY

#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY   0

◆ GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE

#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE   3

◆ GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH

#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH   4

◆ GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE

#define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE   5

Definition at line 684 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_ICMPTYPE_ECHO_REQUEST

#define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST   8

◆ GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT

#define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT   9

Definition at line 686 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION

#define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION   10

Definition at line 687 of file gnunet_tun_lib.h.

◆ GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED

#define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED   11

◆ GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE

#define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE   1

◆ GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG

#define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG   2

◆ GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED

#define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED   3

◆ GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM

#define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM   4

◆ GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST

#define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST   128

◆ GNUNET_TUN_ICMPTYPE6_ECHO_REPLY

#define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY   129

Function Documentation

◆ GNUNET_TUN_initialize_ipv4_header()

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.

Parameters
ipheader to initialize
protocolprotocol to use (i.e. IPPROTO_UDP)
payload_lengthnumber of bytes of payload that follow (excluding IPv4 header)
srcsource IP address to use
dstdestination IP address to use

Definition at line 46 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().

51 {
52  GNUNET_assert (20 == sizeof(struct GNUNET_TUN_IPv4Header));
53  GNUNET_assert (payload_length <=
54  UINT16_MAX - sizeof(struct GNUNET_TUN_IPv4Header));
55  memset (ip, 0, sizeof(struct GNUNET_TUN_IPv4Header));
56  ip->header_length = sizeof(struct GNUNET_TUN_IPv4Header) / 4;
57  ip->version = 4;
58  ip->total_length =
59  htons (sizeof(struct GNUNET_TUN_IPv4Header) + payload_length);
60  ip->identification =
62  ip->ttl = FRESH_TTL;
63  ip->protocol = protocol;
64  ip->source_address = *src;
65  ip->destination_address = *dst;
66  ip->checksum =
67  GNUNET_CRYPTO_crc16_n (ip, sizeof(struct GNUNET_TUN_IPv4Header));
68 }
uint16_t identification
Unique random ID for matching up fragments.
unsigned int header_length
uint16_t GNUNET_CRYPTO_crc16_n(const void *buf, size_t len)
Calculate the checksum of a buffer in one step.
Definition: crypto_crc.c:161
uint8_t ttl
How many more hops can this packet be forwarded?
struct in_addr destination_address
Destination of the packet.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Standard IPv4 header.
#define FRESH_TTL
IP TTL we use for packets that we assemble (8 bit unsigned integer)
Definition: tun.c:33
uint8_t protocol
L4-protocol, for example, IPPROTO_UDP or IPPROTO_TCP.
struct in_addr source_address
Origin of the packet.
uint16_t checksum
Checksum.
uint16_t total_length
Length of the packet, including this header.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_initialize_ipv6_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.

Parameters
ipheader to initialize
protocolprotocol to use (i.e. IPPROTO_UDP)
payload_lengthnumber of bytes of payload that follow (excluding IPv4 header)
srcsource IP address to use
dstdestination IP address to use
ipheader to initialize
protocolprotocol to use (i.e. IPPROTO_UDP), technically "next_header" for IPv6
payload_lengthnumber of bytes of payload that follow (excluding IPv6 header)
srcsource IP address to use
dstdestination IP address to use

Definition at line 81 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().

86 {
87  GNUNET_assert (40 == sizeof(struct GNUNET_TUN_IPv6Header));
88  GNUNET_assert (payload_length <=
89  UINT16_MAX - sizeof(struct GNUNET_TUN_IPv6Header));
90  memset (ip, 0, sizeof(struct GNUNET_TUN_IPv6Header));
91  ip->version = 6;
92  ip->next_header = protocol;
93  ip->payload_length = htons ((uint16_t) payload_length);
94  ip->hop_limit = FRESH_TTL;
95  ip->destination_address = *dst;
96  ip->source_address = *src;
97 }
struct in6_addr source_address
Origin of the packet.
struct in6_addr destination_address
Destination of the packet.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint8_t hop_limit
How many more hops can this packet be forwarded?
#define FRESH_TTL
IP TTL we use for packets that we assemble (8 bit unsigned integer)
Definition: tun.c:33
uint8_t next_header
For example, IPPROTO_UDP or IPPROTO_TCP.
Standard IPv6 header.
uint8_t protocol
L4-protocol, for example, IPPROTO_UDP or IPPROTO_TCP.
uint16_t payload_length
Length of the payload, excluding this header.
Here is the caller graph for this function:

◆ GNUNET_TUN_calculate_tcp4_checksum()

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.

Parameters
ipipv4 header fully initialized
tcpTCP header (initialized except for CRC)
payloadthe TCP payload
payload_lengthnumber of bytes of TCP payload
ipipv4 header fully initialized
tcpTCP header (initialized except for CRC)
payloadthe TCP payload
payload_lengthnumber of bytes of TCP payload

Definition at line 109 of file tun.c.

References GNUNET_TUN_TcpHeader::crc, GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), GNUNET_TUN_IPv4Header::protocol, GNUNET_TUN_IPv4Header::source_address, and GNUNET_TUN_IPv4Header::total_length.

Referenced by handle_tcp_back(), and prepare_ipv4_packet().

113 {
114  uint32_t sum;
115  uint16_t tmp;
116 
117  GNUNET_assert (20 == sizeof(struct GNUNET_TUN_TcpHeader));
118  GNUNET_assert (payload_length + sizeof(struct GNUNET_TUN_IPv4Header)
119  + sizeof(struct GNUNET_TUN_TcpHeader) ==
120  ntohs (ip->total_length));
121  GNUNET_assert (IPPROTO_TCP == ip->protocol);
122 
123  tcp->crc = 0;
124  sum = GNUNET_CRYPTO_crc16_step (0,
125  &ip->source_address,
126  sizeof(struct in_addr) * 2);
127  tmp = htons (IPPROTO_TCP);
128  sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof(uint16_t));
129  tmp = htons (payload_length + sizeof(struct GNUNET_TUN_TcpHeader));
130  sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof(uint16_t));
131  sum =
132  GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof(struct GNUNET_TUN_TcpHeader));
133  sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
134  tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
135 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Standard IPv4 header.
uint16_t GNUNET_CRYPTO_crc16_finish(uint32_t sum)
Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
Definition: crypto_crc.c:144
uint32_t GNUNET_CRYPTO_crc16_step(uint32_t sum, const void *buf, size_t len)
Perform an incremental step in a CRC16 (for TCP/IP) calculation.
Definition: crypto_crc.c:125
TCP packet header.
static unsigned long long payload
How much data are we currently storing in the database?
uint8_t protocol
L4-protocol, for example, IPPROTO_UDP or IPPROTO_TCP.
struct in_addr source_address
Origin of the packet.
uint16_t total_length
Length of the packet, including this header.
uint16_t crc
Checksum.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_calculate_tcp6_checksum()

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.

Parameters
ipipv6 header fully initialized
tcpTCP header (initialized except for CRC)
payloadthe TCP payload
payload_lengthnumber of bytes of TCP payload
ipipv6 header fully initialized
tcpheader (initialized except for CRC)
payloadthe TCP payload
payload_lengthnumber of bytes of TCP payload

Definition at line 147 of file tun.c.

References GNUNET_TUN_TcpHeader::crc, GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), GNUNET_TUN_IPv6Header::next_header, GNUNET_TUN_IPv6Header::payload_length, and GNUNET_TUN_IPv6Header::source_address.

Referenced by handle_tcp_back(), and prepare_ipv6_packet().

151 {
152  uint32_t sum;
153  uint32_t tmp;
154 
155  GNUNET_assert (20 == sizeof(struct GNUNET_TUN_TcpHeader));
156  GNUNET_assert (payload_length + sizeof(struct GNUNET_TUN_TcpHeader) ==
157  ntohs (ip->payload_length));
158  GNUNET_assert (IPPROTO_TCP == ip->next_header);
159  tcp->crc = 0;
160  sum = GNUNET_CRYPTO_crc16_step (0,
161  &ip->source_address,
162  2 * sizeof(struct in6_addr));
163  tmp = htonl (sizeof(struct GNUNET_TUN_TcpHeader) + payload_length);
164  sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof(uint32_t));
165  tmp = htonl (IPPROTO_TCP);
166  sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof(uint32_t));
167  sum =
168  GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof(struct GNUNET_TUN_TcpHeader));
169  sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
170  tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
171 }
struct in6_addr source_address
Origin of the packet.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t GNUNET_CRYPTO_crc16_finish(uint32_t sum)
Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
Definition: crypto_crc.c:144
uint8_t next_header
For example, IPPROTO_UDP or IPPROTO_TCP.
uint32_t GNUNET_CRYPTO_crc16_step(uint32_t sum, const void *buf, size_t len)
Perform an incremental step in a CRC16 (for TCP/IP) calculation.
Definition: crypto_crc.c:125
TCP packet header.
static unsigned long long payload
How much data are we currently storing in the database?
uint16_t payload_length
Length of the payload, excluding this header.
uint16_t crc
Checksum.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_calculate_udp4_checksum()

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.

Parameters
ipipv4 header fully initialized
udpUDP header (initialized except for CRC)
payloadthe UDP payload
payload_lengthnumber of bytes of UDP payload
ipipv4 header fully initialized
udpUDP header (initialized except for CRC)
payloadthe UDP payload
payload_lengthnumber of bytes of UDP payload

Definition at line 183 of file tun.c.

References GNUNET_TUN_UdpHeader::crc, GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), GNUNET_TUN_IPv4Header::protocol, GNUNET_TUN_IPv4Header::source_address, and GNUNET_TUN_IPv4Header::total_length.

Referenced by handle_udp_back(), prepare_ipv4_packet(), and request_done().

187 {
188  uint32_t sum;
189  uint16_t tmp;
190 
191  GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader));
192  GNUNET_assert (payload_length + sizeof(struct GNUNET_TUN_IPv4Header)
193  + sizeof(struct GNUNET_TUN_UdpHeader) ==
194  ntohs (ip->total_length));
195  GNUNET_assert (IPPROTO_UDP == ip->protocol);
196 
197  udp->crc =
198  0; /* technically optional, but we calculate it anyway, just to be sure */
199  sum = GNUNET_CRYPTO_crc16_step (0,
200  &ip->source_address,
201  sizeof(struct in_addr) * 2);
202  tmp = htons (IPPROTO_UDP);
203  sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof(uint16_t));
204  tmp = htons (sizeof(struct GNUNET_TUN_UdpHeader) + payload_length);
205  sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof(uint16_t));
206  sum =
207  GNUNET_CRYPTO_crc16_step (sum, udp, sizeof(struct GNUNET_TUN_UdpHeader));
208  sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
209  udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
210 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
UDP packet header.
Standard IPv4 header.
uint16_t GNUNET_CRYPTO_crc16_finish(uint32_t sum)
Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
Definition: crypto_crc.c:144
uint32_t GNUNET_CRYPTO_crc16_step(uint32_t sum, const void *buf, size_t len)
Perform an incremental step in a CRC16 (for TCP/IP) calculation.
Definition: crypto_crc.c:125
static unsigned long long payload
How much data are we currently storing in the database?
uint16_t crc
Checksum.
uint8_t protocol
L4-protocol, for example, IPPROTO_UDP or IPPROTO_TCP.
struct in_addr source_address
Origin of the packet.
uint16_t total_length
Length of the packet, including this header.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_calculate_udp6_checksum()

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.

Parameters
ipipv6 header fully initialized
udpUDP header (initialized except for CRC)
payloadthe UDP payload
payload_lengthnumber of bytes of payload
ipipv6 header fully initialized
udpUDP header (initialized except for CRC)
payloadthe UDP payload
payload_lengthnumber of bytes of UDP payload

Definition at line 222 of file tun.c.

References GNUNET_TUN_UdpHeader::crc, GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), GNUNET_CRYPTO_crc16_step(), GNUNET_TUN_UdpHeader::len, GNUNET_TUN_IPv6Header::next_header, GNUNET_TUN_IPv6Header::payload_length, and GNUNET_TUN_IPv6Header::source_address.

Referenced by handle_udp_back(), prepare_ipv6_packet(), and request_done().

226 {
227  uint32_t sum;
228  uint32_t tmp;
229 
230  GNUNET_assert (payload_length + sizeof(struct GNUNET_TUN_UdpHeader) ==
231  ntohs (ip->payload_length));
232  GNUNET_assert (payload_length + sizeof(struct GNUNET_TUN_UdpHeader) ==
233  ntohs (udp->len));
234  GNUNET_assert (IPPROTO_UDP == ip->next_header);
235 
236  udp->crc = 0;
237  sum = GNUNET_CRYPTO_crc16_step (0,
238  &ip->source_address,
239  sizeof(struct in6_addr) * 2);
240  tmp = htons (sizeof(struct GNUNET_TUN_UdpHeader)
241  + payload_length); /* aka udp->len */
242  sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof(uint32_t));
243  tmp = htons (ip->next_header);
244  sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof(uint32_t));
245  sum =
246  GNUNET_CRYPTO_crc16_step (sum, udp, sizeof(struct GNUNET_TUN_UdpHeader));
247  sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
248  udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
249 }
struct in6_addr source_address
Origin of the packet.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
UDP packet header.
uint16_t len
Number of bytes of payload.
uint16_t GNUNET_CRYPTO_crc16_finish(uint32_t sum)
Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
Definition: crypto_crc.c:144
uint8_t next_header
For example, IPPROTO_UDP or IPPROTO_TCP.
uint32_t GNUNET_CRYPTO_crc16_step(uint32_t sum, const void *buf, size_t len)
Perform an incremental step in a CRC16 (for TCP/IP) calculation.
Definition: crypto_crc.c:125
static unsigned long long payload
How much data are we currently storing in the database?
uint16_t crc
Checksum.
uint16_t payload_length
Length of the payload, excluding this header.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_calculate_icmp_checksum()

void GNUNET_TUN_calculate_icmp_checksum ( struct GNUNET_TUN_IcmpHeader icmp,
const void *  payload,
uint16_t  payload_length 
)

Calculate ICMP checksum.

Parameters
icmpIMCP header (initialized except for CRC)
payloadthe ICMP payload
payload_lengthnumber of bytes of payload
icmpIMCP header (initialized except for CRC)
payloadthe ICMP payload
payload_lengthnumber of bytes of ICMP payload

Definition at line 260 of file tun.c.

References GNUNET_TUN_IcmpHeader::crc, GNUNET_assert, GNUNET_CRYPTO_crc16_finish(), and GNUNET_CRYPTO_crc16_step().

Referenced by handle_icmp_back(), and send_icmp_packet_via_tun().

263 {
264  uint32_t sum;
265 
266  GNUNET_assert (8 == sizeof(struct GNUNET_TUN_IcmpHeader));
267  icmp->crc = 0;
268  sum =
269  GNUNET_CRYPTO_crc16_step (0, icmp, sizeof(struct GNUNET_TUN_IcmpHeader));
270  sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
271  icmp->crc = GNUNET_CRYPTO_crc16_finish (sum);
272 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t GNUNET_CRYPTO_crc16_finish(uint32_t sum)
Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
Definition: crypto_crc.c:144
uint32_t GNUNET_CRYPTO_crc16_step(uint32_t sum, const void *buf, size_t len)
Perform an incremental step in a CRC16 (for TCP/IP) calculation.
Definition: crypto_crc.c:125
static unsigned long long payload
How much data are we currently storing in the database?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_ipv4toregexsearch()

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.

Parameters
ipIPv4 representation.
portdestination port
rxstrgenerated regex, must be at least GNUNET_TUN_IPV4_REGEXLEN bytes long.

Create a regex in rxstr from the given ip and port.

Parameters
ipIPv4 representation.
portdestination port
rxstrgenerated regex, must be at least GNUNET_TUN_IPV4_REGEXLEN bytes long.

Definition at line 45 of file regex.c.

References GNUNET_snprintf(), and GNUNET_TUN_IPV4_REGEXLEN.

Referenced by create_channel_to_destination().

48 {
49  GNUNET_snprintf (rxstr,
51  "4-%04X-%08X",
52  (unsigned int) port,
53  ntohl (ip->s_addr));
54 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_TUN_IPV4_REGEXLEN
Maximum regex string length for use with GNUNET_TUN_ipv4toregexsearch.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_ipv6toregexsearch()

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.

Parameters
ipv6IPv6 representation.
portdestination port
rxstrgenerated regex, must be at least GNUNET_TUN_IPV6_REGEXLEN bytes long.

Create a regex in rxstr from the given ipv6 and port.

Parameters
ipv6IPv6 representation.
portdestination port
rxstrgenerated regex, must be at least GNUNET_TUN_IPV6_REGEXLEN bytes long.

Definition at line 66 of file regex.c.

References GNUNET_snprintf(), and GNUNET_TUN_IPV6_REGEXLEN.

Referenced by create_channel_to_destination().

69 {
70  const uint32_t *addr;
71 
72  addr = (const uint32_t *) ipv6;
73  GNUNET_snprintf (rxstr,
75  "6-%04X-%08X%08X%08X%08X",
76  (unsigned int) port,
77  ntohl (addr[0]),
78  ntohl (addr[1]),
79  ntohl (addr[2]),
80  ntohl (addr[3]));
81 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
#define GNUNET_TUN_IPV6_REGEXLEN
Maximum regex string length for use with GNUNET_TUN_ipv6toregexsearch.
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_ipv6policy2regex()

char* GNUNET_TUN_ipv6policy2regex ( const char *  policy)

Convert an exit policy to a regular expression.

The exit policy specifies a set of subnets this peer is willing to serve as an exit for; the resulting regular expression will match the IPv6 address strings as returned by GNUNET_TUN_ipv6toregexsearch.

Parameters
policyexit policy specification
Returns
regular expression, NULL on error

The exit policy specifies a set of subnets this peer is willing to serve as an exit for; the resulting regular expression will match the IPv6 address strings as returned by GNUNET_TUN_ipv6toregexsearch().

Parameters
policyexit policy specification
Returns
regular expression, NULL on error

Definition at line 759 of file regex.c.

References GNUNET_asprintf(), GNUNET_free, GNUNET_free_non_null, GNUNET_STRINGS_parse_ipv6_policy(), ipv6_to_regex(), line, and GNUNET_STRINGS_IPv6NetworkPolicy::network.

Referenced by run().

760 {
761  struct in6_addr zero;
763  char *reg;
764  char *tmp;
765  char *line;
766  unsigned int i;
767 
768  np = GNUNET_STRINGS_parse_ipv6_policy (policy);
769  if (NULL == np)
770  return NULL;
771  reg = NULL;
772  memset (&zero, 0, sizeof(struct in6_addr));
773  for (i = 0; (0 == i) || (0 != memcmp (&zero, &np[i].network, sizeof(struct
774  in6_addr)));
775  i++)
776  {
777  line = ipv6_to_regex (&np[i]);
778  if (NULL == line)
779  {
780  GNUNET_free_non_null (reg);
781  GNUNET_free (np);
782  return NULL;
783  }
784  if (NULL == reg)
785  {
786  reg = line;
787  }
788  else
789  {
790  GNUNET_asprintf (&tmp,
791  "%s|(%s)",
792  reg, line);
793  GNUNET_free (reg);
794  GNUNET_free (line);
795  reg = tmp;
796  }
797  if (0 == memcmp (&zero, &np[i].network, sizeof(struct in6_addr)))
798  break;
799  }
800  GNUNET_free (np);
801  return reg;
802 }
static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero
Public key of all zeros.
static char * ipv6_to_regex(const struct GNUNET_STRINGS_IPv6NetworkPolicy *v6)
Convert a single line of an IPv4 policy to a regular expression.
Definition: regex.c:671
struct GNUNET_STRINGS_IPv6NetworkPolicy * GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX)
Parse an IPv6 network policy.
Definition: strings.c:1710
network in CIDR notation for IPV6.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char * line
Desired phone line (string to be converted to a hash).
struct in6_addr network
IPv6 address.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_ipv4policy2regex()

char* GNUNET_TUN_ipv4policy2regex ( const char *  policy)

Convert an exit policy to a regular expression.

The exit policy specifies a set of subnets this peer is willing to serve as an exit for; the resulting regular expression will match the IPv4 address strings as returned by GNUNET_TUN_ipv4toregexsearch.

Parameters
policyexit policy specification
Returns
regular expression, NULL on error

The exit policy specifies a set of subnets this peer is willing to serve as an exit for; the resulting regular expression will match the IPv4 address strings as returned by GNUNET_TUN_ipv4toregexsearch().

Parameters
policyexit policy specification
Returns
regular expression, NULL on error

Definition at line 707 of file regex.c.

References GNUNET_asprintf(), GNUNET_free, GNUNET_free_non_null, GNUNET_STRINGS_parse_ipv4_policy(), ipv4_to_regex(), line, and GNUNET_STRINGS_IPv4NetworkPolicy::network.

Referenced by run().

708 {
710  char *reg;
711  char *tmp;
712  char *line;
713  unsigned int i;
714 
715  np = GNUNET_STRINGS_parse_ipv4_policy (policy);
716  if (NULL == np)
717  return NULL;
718  reg = NULL;
719  for (i = 0; (0 == i) || (0 != np[i].network.s_addr); i++)
720  {
721  line = ipv4_to_regex (&np[i]);
722  if (NULL == line)
723  {
724  GNUNET_free_non_null (reg);
725  GNUNET_free (np);
726  return NULL;
727  }
728  if (NULL == reg)
729  {
730  reg = line;
731  }
732  else
733  {
734  GNUNET_asprintf (&tmp,
735  "%s|(%s)",
736  reg, line);
737  GNUNET_free (reg);
738  GNUNET_free (line);
739  reg = tmp;
740  }
741  if (0 == np[i].network.s_addr)
742  break;
743  }
744  GNUNET_free (np);
745  return reg;
746 }
struct GNUNET_STRINGS_IPv4NetworkPolicy * GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX)
Parse an IPv4 network policy.
Definition: strings.c:1518
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct in_addr network
IPv4 address.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char * line
Desired phone line (string to be converted to a hash).
IPV4 network in CIDR notation.
static char * ipv4_to_regex(const struct GNUNET_STRINGS_IPv4NetworkPolicy *v4)
Convert a single line of an IPv4 policy to a regular expression.
Definition: regex.c:638
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_service_name_to_hash()

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.

Parameters
service_namea string
[out]hccorresponding hash
service_namea string
hccorresponding hash

Definition at line 814 of file regex.c.

References GNUNET_CRYPTO_hash().

Referenced by handle_gns_resolution_result(), run(), and store_service().

816 {
818  strlen (service_name),
819  hc);
820 }
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TUN_sockaddr_cmp()

int GNUNET_TUN_sockaddr_cmp ( const struct sockaddr *  sa,
const struct sockaddr *  sb,
int  include_port 
)

Check if two sockaddrs are equal.

Parameters
saone address
sbanother address
include_portalso check ports
Returns
GNUNET_YES if they are equal

Definition at line 284 of file tun.c.

References GNUNET_break, GNUNET_NO, and GNUNET_SYSERR.

287 {
288  if (sa->sa_family != sb->sa_family)
289  return GNUNET_NO;
290 
291  switch (sa->sa_family)
292  {
293  case AF_INET: {
294  const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa;
295  const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb;
296  if ((include_port) && (sa4->sin_port != sb4->sin_port))
297  return GNUNET_NO;
298  return(sa4->sin_addr.s_addr == sb4->sin_addr.s_addr);
299  }
300 
301  case AF_INET6: {
302  const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa;
303  const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb;
304 
305  if ((include_port) && (sa6->sin6_port != sb6->sin6_port))
306  return GNUNET_NO;
307  return(
308  0 == memcmp (&sa6->sin6_addr, &sb6->sin6_addr, sizeof(struct
309  in6_addr)));
310  }
311 
312  default:
313  GNUNET_break (0);
314  return GNUNET_SYSERR;
315  }
316 }
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76

◆ GNUNET_TUN_compute_service_cadet_port()

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.

Parameters
descservice shared secret
ip_portTCP/UDP port, use 0 for ICMP
[out]cadet_portCADET port to use

Definition at line 833 of file regex.c.

References GNUNET_memcpy.

Referenced by create_channel_to_destination(), and store_service().

836 {
837  uint16_t be_port = htons (ip_port);
838 
839  *cadet_port = *desc;
840  GNUNET_memcpy (cadet_port,
841  &be_port,
842  sizeof(uint16_t));
843 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
Here is the caller graph for this function: