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