gnunet-android

GNUnet for Android
Log | Files | Refs | README

gnunet_tun_lib.h (20785B)


      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 
     25 /**
     26  * @addtogroup vpn_suite  VPN services and libraries
     27  * @{
     28  *
     29  * @author Philipp Toelke
     30  * @author Christian Grothoff
     31  *
     32  * @file
     33  * Standard TCP/IP network structs and IP checksum calculations for TUN
     34  * interaction
     35  *
     36  * @defgroup tun  TUN library
     37  * Standard TCP/IP network structs and IP checksum calculations for TUN
     38  * interaction
     39  * @{
     40  */
     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
     47 /**
     48  * Number for IPv4
     49  */
     50 #define ETH_P_IPV4 0x0800
     51 #endif
     52 
     53 #ifndef ETH_P_IPV6
     54 /**
     55  * Number for IPv6
     56  */
     57 #define ETH_P_IPV6 0x86DD
     58 #endif
     59 
     60 
     61 /**
     62  * Maximum regex string length for use with #GNUNET_REGEX_ipv4toregexsearch.
     63  *
     64  * 8 bytes for IPv4, 4 bytes for port, 1 byte for "4", 2 bytes for "-",
     65  * one byte for 0-termination.
     66  */
     67 
     68 #define GNUNET_TUN_IPV4_REGEXLEN 16
     69 
     70 
     71 /**
     72  * Maximum regex string length for use with #GNUNET_REGEX_ipv6toregexsearch
     73  *
     74  * 32 bytes for IPv4, 4 bytes for port, 1 byte for "4", 2 bytes for "-",
     75  * one byte for 0-termination.
     76  */
     77 #define GNUNET_TUN_IPV6_REGEXLEN 40
     78 
     79 
     80 GNUNET_NETWORK_STRUCT_BEGIN
     81 
     82 /**
     83  * Header from Linux TUN interface.
     84  */
     85 struct GNUNET_TUN_Layer2PacketHeader
     86 {
     87   /**
     88    * Some flags (unused).
     89    */
     90   uint16_t flags GNUNET_PACKED;
     91 
     92   /**
     93    * Here we get an ETH_P_-number.
     94    */
     95   uint16_t proto GNUNET_PACKED;
     96 };
     97 
     98 
     99 /**
    100  * Standard IPv4 header.
    101  */
    102 struct GNUNET_TUN_IPv4Header
    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 
    115   /**
    116    * Length of the packet, including this header.
    117    */
    118   uint16_t total_length GNUNET_PACKED;
    119 
    120   /**
    121    * Unique random ID for matching up fragments.
    122    */
    123   uint16_t identification GNUNET_PACKED;
    124 
    125   unsigned int flags : 3 GNUNET_PACKED;
    126 
    127   unsigned int fragmentation_offset : 13 GNUNET_PACKED;
    128 
    129   /**
    130    * How many more hops can this packet be forwarded?
    131    */
    132   uint8_t ttl;
    133 
    134   /**
    135    * L4-protocol, for example, IPPROTO_UDP or IPPROTO_TCP.
    136    */
    137   uint8_t protocol;
    138 
    139   /**
    140    * Checksum.
    141    */
    142   uint16_t checksum GNUNET_PACKED;
    143 
    144   /**
    145    * Origin of the packet.
    146    */
    147   struct in_addr source_address;
    148 
    149   /**
    150    * Destination of the packet.
    151    */
    152   struct in_addr destination_address;
    153 } GNUNET_GCC_STRUCT_LAYOUT;
    154 
    155 
    156 /**
    157  * Standard IPv6 header.
    158  */
    159 struct GNUNET_TUN_IPv6Header
    160 {
    161 #if __BYTE_ORDER == __LITTLE_ENDIAN
    162   unsigned int traffic_class_h : 4 GNUNET_PACKED;
    163   unsigned int version : 4 GNUNET_PACKED;
    164   unsigned int traffic_class_l : 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
    173   /**
    174    * Length of the payload, excluding this header.
    175    */
    176   uint16_t payload_length GNUNET_PACKED;
    177 
    178   /**
    179    * For example, IPPROTO_UDP or IPPROTO_TCP.
    180    */
    181   uint8_t next_header;
    182 
    183   /**
    184    * How many more hops can this packet be forwarded?
    185    */
    186   uint8_t hop_limit;
    187 
    188   /**
    189    * Origin of the packet.
    190    */
    191   struct in6_addr source_address GNUNET_PACKED;
    192 
    193   /**
    194    * Destination of the packet.
    195    */
    196   struct in6_addr destination_address GNUNET_PACKED;
    197 } GNUNET_GCC_STRUCT_LAYOUT;
    198 
    199 
    200 /**
    201  * TCP flags.
    202  */
    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 
    212 /**
    213  * TCP packet header.
    214  */
    215 struct GNUNET_TUN_TcpHeader
    216 {
    217   /**
    218    * Source port (in NBO).
    219    */
    220   uint16_t source_port GNUNET_PACKED;
    221 
    222   /**
    223    * Destination port (in NBO).
    224    */
    225   uint16_t destination_port GNUNET_PACKED;
    226 
    227   /**
    228    * Sequence number.
    229    */
    230   uint32_t seq GNUNET_PACKED;
    231 
    232   /**
    233    * Acknowledgement number.
    234    */
    235   uint32_t ack GNUNET_PACKED;
    236 #if __BYTE_ORDER == __LITTLE_ENDIAN
    237   /**
    238    * Reserved.  Must be zero.
    239    */
    240   unsigned int reserved : 4 GNUNET_PACKED;
    241   /**
    242    * Number of 32-bit words in TCP header.
    243    */
    244   unsigned int off : 4 GNUNET_PACKED;
    245 #elif __BYTE_ORDER == __BIG_ENDIAN
    246   /**
    247    * Number of 32-bit words in TCP header.
    248    */
    249   unsigned int off : 4 GNUNET_PACKED;
    250   /**
    251    * Reserved.  Must be zero.
    252    */
    253   unsigned int reserved : 4 GNUNET_PACKED;
    254 #else
    255 #error byteorder undefined
    256 #endif
    257 
    258   /**
    259    * Flags (SYN, FIN, ACK, etc.)
    260    */
    261   uint8_t flags;
    262 
    263   /**
    264    * Window size.
    265    */
    266   uint16_t window_size GNUNET_PACKED;
    267 
    268   /**
    269    * Checksum.
    270    */
    271   uint16_t crc GNUNET_PACKED;
    272 
    273   /**
    274    * Urgent pointer.
    275    */
    276   uint16_t urgent_pointer GNUNET_PACKED;
    277 } GNUNET_GCC_STRUCT_LAYOUT;
    278 
    279 
    280 /**
    281  * UDP packet header.
    282  */
    283 struct GNUNET_TUN_UdpHeader
    284 {
    285   /**
    286    * Source port (in NBO).
    287    */
    288   uint16_t source_port GNUNET_PACKED;
    289 
    290   /**
    291    * Destination port (in NBO).
    292    */
    293   uint16_t destination_port GNUNET_PACKED;
    294 
    295   /**
    296    * Number of bytes of payload.
    297    */
    298   uint16_t len GNUNET_PACKED;
    299 
    300   /**
    301    * Checksum.
    302    */
    303   uint16_t crc GNUNET_PACKED;
    304 };
    305 
    306 
    307 /**
    308  * A few common DNS classes (ok, only one is common, but I list a
    309  * couple more to make it clear what we're talking about here).
    310  */
    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 
    320 /**
    321  * RFC 1035 codes.
    322  */
    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 
    330 /**
    331  * RFC 2136 codes
    332  */
    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 
    340 /**
    341  * DNS flags (largely RFC 1035 / RFC 2136).
    342  */
    343 struct GNUNET_TUN_DnsFlags
    344 {
    345 #if __BYTE_ORDER == __LITTLE_ENDIAN
    346   /**
    347    * Set to 1 if recursion is desired (client -> server)
    348    */
    349   unsigned int recursion_desired : 1 GNUNET_PACKED;
    350 
    351   /**
    352    * Set to 1 if message is truncated
    353    */
    354   unsigned int message_truncated : 1 GNUNET_PACKED;
    355 
    356   /**
    357    * Set to 1 if this is an authoritative answer
    358    */
    359   unsigned int authoritative_answer : 1 GNUNET_PACKED;
    360 
    361   /**
    362    * See GNUNET_TUN_DNS_OPCODE_ defines.
    363    */
    364   unsigned int opcode : 4 GNUNET_PACKED;
    365 
    366   /**
    367    * query:0, response:1
    368    */
    369   unsigned int query_or_response : 1 GNUNET_PACKED;
    370 
    371   /**
    372    * See GNUNET_TUN_DNS_RETURN_CODE_ defines.
    373    */
    374   unsigned int return_code : 4 GNUNET_PACKED;
    375 
    376   /**
    377    * See RFC 4035.
    378    */
    379   unsigned int checking_disabled : 1 GNUNET_PACKED;
    380 
    381   /**
    382    * Response has been cryptographically verified, RFC 4035.
    383    */
    384   unsigned int authenticated_data : 1 GNUNET_PACKED;
    385 
    386   /**
    387    * Always zero.
    388    */
    389   unsigned int zero : 1 GNUNET_PACKED;
    390 
    391   /**
    392    * Set to 1 if recursion is available (server -> client)
    393    */
    394   unsigned int recursion_available : 1 GNUNET_PACKED;
    395 #elif __BYTE_ORDER == __BIG_ENDIAN
    396   /**
    397    * query:0, response:1
    398    */
    399   unsigned int query_or_response : 1 GNUNET_PACKED;
    400 
    401   /**
    402    * See GNUNET_TUN_DNS_OPCODE_ defines.
    403    */
    404   unsigned int opcode : 4 GNUNET_PACKED;
    405 
    406   /**
    407    * Set to 1 if this is an authoritative answer
    408    */
    409   unsigned int authoritative_answer : 1 GNUNET_PACKED;
    410 
    411   /**
    412    * Set to 1 if message is truncated
    413    */
    414   unsigned int message_truncated : 1 GNUNET_PACKED;
    415 
    416   /**
    417    * Set to 1 if recursion is desired (client -> server)
    418    */
    419   unsigned int recursion_desired : 1 GNUNET_PACKED;
    420 
    421 
    422   /**
    423    * Set to 1 if recursion is available (server -> client)
    424    */
    425   unsigned int recursion_available : 1 GNUNET_PACKED;
    426 
    427   /**
    428    * Always zero.
    429    */
    430   unsigned int zero : 1 GNUNET_PACKED;
    431 
    432   /**
    433    * Response has been cryptographically verified, RFC 4035.
    434    */
    435   unsigned int authenticated_data : 1 GNUNET_PACKED;
    436 
    437   /**
    438    * See RFC 4035.
    439    */
    440   unsigned int checking_disabled : 1 GNUNET_PACKED;
    441 
    442   /**
    443    * See GNUNET_TUN_DNS_RETURN_CODE_ defines.
    444    */
    445   unsigned int return_code : 4 GNUNET_PACKED;
    446 #else
    447 #error byteorder undefined
    448 #endif
    449 } GNUNET_GCC_STRUCT_LAYOUT;
    450 
    451 
    452 /**
    453  * DNS header.
    454  */
    455 struct GNUNET_TUN_DnsHeader
    456 {
    457   /**
    458    * Unique identifier for the request/response.
    459    */
    460   uint16_t id GNUNET_PACKED;
    461 
    462   /**
    463    * Flags.
    464    */
    465   struct GNUNET_TUN_DnsFlags flags;
    466 
    467   /**
    468    * Number of queries.
    469    */
    470   uint16_t query_count GNUNET_PACKED;
    471 
    472   /**
    473    * Number of answers.
    474    */
    475   uint16_t answer_rcount GNUNET_PACKED;
    476 
    477   /**
    478    * Number of authoritative answers.
    479    */
    480   uint16_t authority_rcount GNUNET_PACKED;
    481 
    482   /**
    483    * Number of additional records.
    484    */
    485   uint16_t additional_rcount GNUNET_PACKED;
    486 };
    487 
    488 
    489 /**
    490  * Payload of DNS SOA record (header).
    491  */
    492 struct GNUNET_TUN_DnsSoaRecord
    493 {
    494   /**
    495    * The version number of the original copy of the zone.   (NBO)
    496    */
    497   uint32_t serial GNUNET_PACKED;
    498 
    499   /**
    500    * Time interval before the zone should be refreshed. (NBO)
    501    */
    502   uint32_t refresh GNUNET_PACKED;
    503 
    504   /**
    505    * Time interval that should elapse before a failed refresh should
    506    * be retried. (NBO)
    507    */
    508   uint32_t retry GNUNET_PACKED;
    509 
    510   /**
    511    * Time value that specifies the upper limit on the time interval
    512    * that can elapse before the zone is no longer authoritative. (NBO)
    513    */
    514   uint32_t expire GNUNET_PACKED;
    515 
    516   /**
    517    * The bit minimum TTL field that should be exported with any RR
    518    * from this zone. (NBO)
    519    */
    520   uint32_t minimum GNUNET_PACKED;
    521 };
    522 
    523 
    524 /**
    525  * Payload of DNS SRV record (header).
    526  */
    527 struct GNUNET_TUN_DnsSrvRecord
    528 {
    529   /**
    530    * Preference for this entry (lower value is higher preference).  Clients
    531    * will contact hosts from the lowest-priority group first and fall back
    532    * to higher priorities if the low-priority entries are unavailable. (NBO)
    533    */
    534   uint16_t prio GNUNET_PACKED;
    535 
    536   /**
    537    * Relative weight for records with the same priority.  Clients will use
    538    * the hosts of the same (lowest) priority with a probability proportional
    539    * to the weight given. (NBO)
    540    */
    541   uint16_t weight GNUNET_PACKED;
    542 
    543   /**
    544    * TCP or UDP port of the service. (NBO)
    545    */
    546   uint16_t port GNUNET_PACKED;
    547 
    548   /* followed by 'target' name */
    549 };
    550 
    551 
    552 /**
    553  * Payload of DNS URI record (header).
    554  */
    555 struct GNUNET_TUN_DnsUriRecord
    556 {
    557   /**
    558    * Preference for this entry (lower value is higher preference).  Clients
    559    * will contact hosts from the lowest-priority group first and fall back
    560    * to higher priorities if the low-priority entries are unavailable. (NBO)
    561    */
    562   uint16_t prio GNUNET_PACKED;
    563 
    564   /**
    565    * Relative weight for records with the same priority.  Clients will use
    566    * the hosts of the same (lowest) priority with a probability proportional
    567    * to the weight given. (NBO)
    568    */
    569   uint16_t weight GNUNET_PACKED;
    570 
    571   /* followed by 'target' name */
    572 };
    573 
    574 
    575 /**
    576  * Payload of DNS CERT record.
    577  */
    578 struct GNUNET_TUN_DnsCertRecord
    579 {
    580   /**
    581    * Certificate type
    582    */
    583   uint16_t cert_type;
    584 
    585   /**
    586    * Certificate KeyTag
    587    */
    588   uint16_t cert_tag;
    589 
    590   /**
    591    * Algorithm
    592    */
    593   uint8_t algorithm;
    594 
    595   /* Followed by the certificate */
    596 };
    597 
    598 
    599 /**
    600  * Payload of DNSSEC TLSA record.
    601  * http://datatracker.ietf.org/doc/draft-ietf-dane-protocol/
    602  */
    603 struct GNUNET_TUN_DnsTlsaRecord
    604 {
    605   /**
    606    * Certificate usage
    607    * 0: CA cert
    608    * 1: Entity cert
    609    * 2: Trust anchor
    610    * 3: domain-issued cert
    611    */
    612   uint8_t usage;
    613 
    614   /**
    615    * Selector
    616    * What part will be matched against the cert
    617    * presented by server
    618    * 0: Full cert (in binary)
    619    * 1: Full cert (in DER)
    620    */
    621   uint8_t selector;
    622 
    623   /**
    624    * Matching type (of selected content)
    625    * 0: exact match
    626    * 1: SHA-256 hash
    627    * 2: SHA-512 hash
    628    */
    629   uint8_t matching_type;
    630 
    631   /**
    632    * followed by certificate association data
    633    * The "certificate association data" to be matched.
    634    * These bytes are either raw data (that is, the full certificate or
    635    * its SubjectPublicKeyInfo, depending on the selector) for matching
    636    * type 0, or the hash of the raw data for matching types 1 and 2.
    637    * The data refers to the certificate in the association, not to the
    638    * TLS ASN.1 Certificate object.
    639    *
    640    * The data is represented as a string of hex chars
    641    */
    642 };
    643 
    644 
    645 /**
    646  * Payload of GNS VPN record
    647  */
    648 struct GNUNET_TUN_GnsVpnRecord
    649 {
    650   /**
    651    * The peer to contact
    652    */
    653   struct GNUNET_PeerIdentity peer;
    654 
    655   /**
    656    * The protocol to use
    657    */
    658   uint16_t proto;
    659 
    660   /* followed by the servicename */
    661 };
    662 
    663 
    664 /**
    665  * DNS query prefix.
    666  */
    667 struct GNUNET_TUN_DnsQueryLine
    668 {
    669   /**
    670    * Desired type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
    671    */
    672   uint16_t type GNUNET_PACKED;
    673 
    674   /**
    675    * Desired class (usually GNUNET_TUN_DNS_CLASS_INTERNET). (NBO)
    676    */
    677   uint16_t dns_traffic_class GNUNET_PACKED;
    678 };
    679 
    680 
    681 /**
    682  * General DNS record prefix.
    683  */
    684 struct GNUNET_TUN_DnsRecordLine
    685 {
    686   /**
    687    * Record type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
    688    */
    689   uint16_t type GNUNET_PACKED;
    690 
    691   /**
    692    * Record class (usually GNUNET_TUN_DNS_CLASS_INTERNET). (NBO)
    693    */
    694   uint16_t dns_traffic_class GNUNET_PACKED;
    695 
    696   /**
    697    * Expiration for the record (in seconds). (NBO)
    698    */
    699   uint32_t ttl GNUNET_PACKED;
    700 
    701   /**
    702    * Number of bytes of data that follow. (NBO)
    703    */
    704   uint16_t data_len GNUNET_PACKED;
    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 
    725 /**
    726  * ICMP header.
    727  */
    728 struct GNUNET_TUN_IcmpHeader
    729 {
    730   uint8_t type;
    731   uint8_t code;
    732   uint16_t crc GNUNET_PACKED;
    733 
    734   union
    735   {
    736     /**
    737      * ICMP Echo (request/reply)
    738      */
    739     struct
    740     {
    741       uint16_t identifier GNUNET_PACKED;
    742       uint16_t sequence_number GNUNET_PACKED;
    743     } echo;
    744 
    745     /**
    746      * ICMP Destination Unreachable (RFC 1191)
    747      */
    748     struct ih_pmtu
    749     {
    750       uint16_t empty GNUNET_PACKED;
    751       uint16_t next_hop_mtu GNUNET_PACKED;
    752       /* followed by original IP header + first 8 bytes of original IP datagram
    753        */
    754     } destination_unreachable;
    755 
    756     /**
    757      * ICMP Redirect
    758      */
    759     struct in_addr redirect_gateway_address;
    760 
    761     /**
    762      * MTU for packets that are too big (IPv6).
    763      */
    764     uint32_t packet_too_big_mtu GNUNET_PACKED;
    765   } quench;
    766 };
    767 
    768 
    769 GNUNET_NETWORK_STRUCT_END
    770 
    771 
    772 /**
    773  * Initialize an IPv4 header.
    774  *
    775  * @param ip header to initialize
    776  * @param protocol protocol to use (e.g. IPPROTO_UDP)
    777  * @param payload_length number of bytes of payload that follow (excluding IPv4
    778  * header)
    779  * @param src source IP address to use
    780  * @param dst destination IP address to use
    781  */
    782 void
    783 GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
    784                                    uint8_t protocol,
    785                                    uint16_t payload_length,
    786                                    const struct in_addr *src,
    787                                    const struct in_addr *dst);
    788 
    789 
    790 /**
    791  * Initialize an IPv6 header.
    792  *
    793  * @param ip header to initialize
    794  * @param protocol protocol to use (e.g. IPPROTO_UDP)
    795  * @param payload_length number of bytes of payload that follow (excluding IPv4
    796  * header)
    797  * @param src source IP address to use
    798  * @param dst destination IP address to use
    799  */
    800 void
    801 GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
    802                                    uint8_t protocol,
    803                                    uint16_t payload_length,
    804                                    const struct in6_addr *src,
    805                                    const struct in6_addr *dst);
    806 
    807 /**
    808  * Calculate IPv4 TCP checksum.
    809  *
    810  * @param ip ipv4 header fully initialized
    811  * @param tcp TCP header (initialized except for CRC)
    812  * @param payload the TCP payload
    813  * @param payload_length number of bytes of TCP @a payload
    814  */
    815 void
    816 GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
    817                                     struct GNUNET_TUN_TcpHeader *tcp,
    818                                     const void *payload,
    819                                     uint16_t payload_length);
    820 
    821 /**
    822  * Calculate IPv6 TCP checksum.
    823  *
    824  * @param ip ipv6 header fully initialized
    825  * @param tcp TCP header (initialized except for CRC)
    826  * @param payload the TCP payload
    827  * @param payload_length number of bytes of TCP payload
    828  */
    829 void
    830 GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
    831                                     struct GNUNET_TUN_TcpHeader *tcp,
    832                                     const void *payload,
    833                                     uint16_t payload_length);
    834 
    835 /**
    836  * Calculate IPv4 UDP checksum.
    837  *
    838  * @param ip ipv4 header fully initialized
    839  * @param udp UDP header (initialized except for CRC)
    840  * @param payload the UDP payload
    841  * @param payload_length number of bytes of UDP @a payload
    842  */
    843 void
    844 GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
    845                                     struct GNUNET_TUN_UdpHeader *udp,
    846                                     const void *payload,
    847                                     uint16_t payload_length);
    848 
    849 
    850 /**
    851  * Calculate IPv6 UDP checksum.
    852  *
    853  * @param ip ipv6 header fully initialized
    854  * @param udp UDP header (initialized except for CRC)
    855  * @param payload the UDP payload
    856  * @param payload_length number of bytes of @a payload
    857  */
    858 void
    859 GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
    860                                     struct GNUNET_TUN_UdpHeader *udp,
    861                                     const void *payload,
    862                                     uint16_t payload_length);
    863 
    864 
    865 /**
    866  * Calculate ICMP checksum.
    867  *
    868  * @param icmp IMCP header (initialized except for CRC)
    869  * @param payload the ICMP payload
    870  * @param payload_length number of bytes of @a payload
    871  */
    872 void
    873 GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
    874                                     const void *payload,
    875                                     uint16_t payload_length);
    876 
    877 
    878 /**
    879  * Hash the service name of a hosted service to the
    880  * hash code that is used to identify the service on
    881  * the network.
    882  *
    883  * @param service_name a string
    884  * @param[out] hc corresponding hash
    885  */
    886 void
    887 GNUNET_TUN_service_name_to_hash (const char *service_name,
    888                                  struct GNUNET_HashCode *hc);
    889 
    890 
    891 /**
    892  * Check if two sockaddrs are equal.
    893  *
    894  * @param sa one address
    895  * @param sb another address
    896  * @param include_port also check ports
    897  * @return #GNUNET_YES if they are equal
    898  */
    899 int
    900 GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa,
    901                          const struct sockaddr *sb,
    902                          int include_port);
    903 
    904 
    905 /**
    906  * Compute the CADET port given a service descriptor
    907  * (returned from #GNUNET_TUN_service_name_to_hash) and
    908  * a TCP/UDP port @a ip_port.
    909  *
    910  * @param desc service shared secret
    911  * @param ip_port TCP/UDP port, use 0 for ICMP
    912  * @param[out] cadet_port CADET port to use
    913  */
    914 void
    915 GNUNET_TUN_compute_service_cadet_port (const struct GNUNET_HashCode *desc,
    916                                        uint16_t ip_port,
    917                                        struct GNUNET_HashCode *cadet_port);
    918 
    919 #endif
    920 
    921 /** @} */ /* end of group */
    922 
    923 /** @} */ /* end of group addition */