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