More W32 resolver workarounds
[oweals/gnunet.git] / src / include / gnunet_tun_lib.h
1 /*
2      This file is part of GNUnet.
3      (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 packet header.
189  */
190 struct GNUNET_TUN_TcpHeader
191 {
192   /**
193    * Source port (in NBO).
194    */
195   uint16_t source_port GNUNET_PACKED;
196
197   /**
198    * Destination port (in NBO).
199    */
200   uint16_t destination_port GNUNET_PACKED;
201
202   /**
203    * Sequence number.
204    */
205   uint32_t seq GNUNET_PACKED;
206
207   /**
208    * Acknowledgement number.
209    */
210   uint32_t ack GNUNET_PACKED;
211 #if __BYTE_ORDER == __LITTLE_ENDIAN
212   /**
213    * Reserved.  Must be zero.
214    */
215   unsigned int reserved : 4 GNUNET_PACKED;
216   /**
217    * Number of 32-bit words in TCP header.
218    */
219   unsigned int off : 4 GNUNET_PACKED;
220 #elif __BYTE_ORDER == __BIG_ENDIAN
221   /**
222    * Number of 32-bit words in TCP header.
223    */
224   unsigned int off : 4 GNUNET_PACKED;
225   /**
226    * Reserved.  Must be zero.
227    */
228   unsigned int reserved : 4 GNUNET_PACKED;
229 #else
230   #error byteorder undefined
231 #endif
232
233   /**
234    * Flags (SYN, FIN, ACK, etc.)
235    */
236   uint8_t flags;
237
238   /**
239    * Window size.
240    */
241   uint16_t window_size GNUNET_PACKED;
242
243   /**
244    * Checksum.
245    */
246   uint16_t crc GNUNET_PACKED;
247
248   /**
249    * Urgent pointer.
250    */
251   uint16_t urgent_pointer GNUNET_PACKED;
252 } GNUNET_GCC_STRUCT_LAYOUT;
253
254
255 /**
256  * UDP packet header.
257  */
258 struct GNUNET_TUN_UdpHeader
259 {
260   /**
261    * Source port (in NBO).
262    */
263   uint16_t source_port GNUNET_PACKED;
264
265   /**
266    * Destination port (in NBO).
267    */
268   uint16_t destination_port GNUNET_PACKED;
269
270   /**
271    * Number of bytes of payload.
272    */
273   uint16_t len GNUNET_PACKED;
274
275   /**
276    * Checksum.
277    */
278   uint16_t crc GNUNET_PACKED;
279 };
280
281
282
283 /**
284  * A few common DNS classes (ok, only one is common, but I list a
285  * couple more to make it clear what we're talking about here).
286  */
287 #define GNUNET_TUN_DNS_CLASS_INTERNET 1
288 #define GNUNET_TUN_DNS_CLASS_CHAOS 3
289 #define GNUNET_TUN_DNS_CLASS_HESIOD 4
290
291 #define GNUNET_TUN_DNS_OPCODE_QUERY 0
292 #define GNUNET_TUN_DNS_OPCODE_INVERSE_QUERY 1
293 #define GNUNET_TUN_DNS_OPCODE_STATUS 2
294
295
296 /**
297  * RFC 1035 codes.
298  */
299 #define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR 0
300 #define GNUNET_TUN_DNS_RETURN_CODE_FORMAT_ERROR 1
301 #define GNUNET_TUN_DNS_RETURN_CODE_SERVER_FAILURE 2
302 #define GNUNET_TUN_DNS_RETURN_CODE_NAME_ERROR 3
303 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_IMPLEMENTED 4
304 #define GNUNET_TUN_DNS_RETURN_CODE_REFUSED 5
305
306 /**
307  * RFC 2136 codes
308  */
309 #define GNUNET_TUN_DNS_RETURN_CODE_YXDOMAIN 6
310 #define GNUNET_TUN_DNS_RETURN_CODE_YXRRSET 7
311 #define GNUNET_TUN_DNS_RETURN_CODE_NXRRSET 8
312 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_AUTH 9
313 #define GNUNET_TUN_DNS_RETURN_CODE_NOT_ZONE 10
314
315
316 /**
317  * DNS flags (largely RFC 1035 / RFC 2136).
318  */
319 struct GNUNET_TUN_DnsFlags
320 {
321 #if __BYTE_ORDER == __LITTLE_ENDIAN
322   /**
323    * Set to 1 if recursion is desired (client -> server)
324    */
325   unsigned int recursion_desired    : 1 GNUNET_PACKED;
326
327   /**
328    * Set to 1 if message is truncated
329    */
330   unsigned int message_truncated    : 1 GNUNET_PACKED;
331
332   /**
333    * Set to 1 if this is an authoritative answer
334    */
335   unsigned int authoritative_answer : 1 GNUNET_PACKED;
336
337   /**
338    * See GNUNET_TUN_DNS_OPCODE_ defines.
339    */
340   unsigned int opcode               : 4 GNUNET_PACKED;
341
342   /**
343    * query:0, response:1
344    */
345   unsigned int query_or_response    : 1 GNUNET_PACKED;
346
347   /**
348    * See GNUNET_TUN_DNS_RETURN_CODE_ defines.
349    */
350   unsigned int return_code          : 4 GNUNET_PACKED;
351
352   /**
353    * See RFC 4035.
354    */
355   unsigned int checking_disabled    : 1 GNUNET_PACKED;
356
357   /**
358    * Response has been cryptographically verified, RFC 4035.
359    */
360   unsigned int authenticated_data   : 1 GNUNET_PACKED;
361
362   /**
363    * Always zero.
364    */
365   unsigned int zero                 : 1 GNUNET_PACKED;
366
367   /**
368    * Set to 1 if recursion is available (server -> client)
369    */
370   unsigned int recursion_available  : 1 GNUNET_PACKED;
371 #elif __BYTE_ORDER == __BIG_ENDIAN
372
373   /**
374    * query:0, response:1
375    */
376   unsigned int query_or_response    : 1 GNUNET_PACKED;
377
378   /**
379    * See GNUNET_TUN_DNS_OPCODE_ defines.
380    */
381   unsigned int opcode               : 4 GNUNET_PACKED;
382
383   /**
384    * Set to 1 if this is an authoritative answer
385    */
386   unsigned int authoritative_answer : 1 GNUNET_PACKED;
387
388   /**
389    * Set to 1 if message is truncated
390    */
391   unsigned int message_truncated    : 1 GNUNET_PACKED;
392
393   /**
394    * Set to 1 if recursion is desired (client -> server)
395    */
396   unsigned int recursion_desired    : 1 GNUNET_PACKED;
397
398
399   /**
400    * Set to 1 if recursion is available (server -> client)
401    */
402   unsigned int recursion_available  : 1 GNUNET_PACKED;
403
404   /**
405    * Always zero.
406    */
407   unsigned int zero                 : 1 GNUNET_PACKED;
408
409   /**
410    * Response has been cryptographically verified, RFC 4035.
411    */
412   unsigned int authenticated_data   : 1 GNUNET_PACKED;
413
414   /**
415    * See RFC 4035.
416    */
417   unsigned int checking_disabled    : 1 GNUNET_PACKED;
418
419   /**
420    * See GNUNET_TUN_DNS_RETURN_CODE_ defines.
421    */
422   unsigned int return_code          : 4 GNUNET_PACKED;
423 #else
424   #error byteorder undefined
425 #endif
426
427 } GNUNET_GCC_STRUCT_LAYOUT;
428
429
430
431 /**
432  * DNS header.
433  */
434 struct GNUNET_TUN_DnsHeader
435 {
436   /**
437    * Unique identifier for the request/response.
438    */
439   uint16_t id GNUNET_PACKED;
440
441   /**
442    * Flags.
443    */
444   struct GNUNET_TUN_DnsFlags flags;
445
446   /**
447    * Number of queries.
448    */
449   uint16_t query_count GNUNET_PACKED;
450
451   /**
452    * Number of answers.
453    */
454   uint16_t answer_rcount GNUNET_PACKED;
455
456   /**
457    * Number of authoritative answers.
458    */
459   uint16_t authority_rcount GNUNET_PACKED;
460
461   /**
462    * Number of additional records.
463    */
464   uint16_t additional_rcount GNUNET_PACKED;
465 };
466
467
468 /**
469  * Payload of DNS SOA record (header).
470  */
471 struct GNUNET_TUN_DnsSoaRecord
472 {
473   /**
474    * The version number of the original copy of the zone.   (NBO)
475    */
476   uint32_t serial GNUNET_PACKED;
477
478   /**
479    * Time interval before the zone should be refreshed. (NBO)
480    */
481   uint32_t refresh GNUNET_PACKED;
482
483   /**
484    * Time interval that should elapse before a failed refresh should
485    * be retried. (NBO)
486    */
487   uint32_t retry GNUNET_PACKED;
488
489   /**
490    * Time value that specifies the upper limit on the time interval
491    * that can elapse before the zone is no longer authoritative. (NBO)
492    */
493   uint32_t expire GNUNET_PACKED;
494
495   /**
496    * The bit minimum TTL field that should be exported with any RR
497    * from this zone. (NBO)
498    */
499   uint32_t minimum GNUNET_PACKED;
500 };
501
502
503 /**
504  * Payload of DNS SRV record (header).
505  */
506 struct GNUNET_TUN_DnsSrvRecord
507 {
508
509   /**
510    * Preference for this entry (lower value is higher preference).  Clients
511    * will contact hosts from the lowest-priority group first and fall back
512    * to higher priorities if the low-priority entries are unavailable. (NBO)
513    */
514   uint16_t prio GNUNET_PACKED;
515
516   /**
517    * Relative weight for records with the same priority.  Clients will use
518    * the hosts of the same (lowest) priority with a probability proportional
519    * to the weight given. (NBO)
520    */
521   uint16_t weight GNUNET_PACKED;
522
523   /**
524    * TCP or UDP port of the service. (NBO)
525    */
526   uint16_t port GNUNET_PACKED;
527
528   /* followed by 'target' name */
529 };
530
531
532 /**
533  * Payload of DNS CERT record.
534  */
535 struct GNUNET_TUN_DnsCertRecord
536 {
537
538   /**
539    * Certificate type
540    */
541   uint16_t cert_type;
542
543   /**
544    * Certificate KeyTag
545    */
546   uint16_t cert_tag;
547
548   /**
549    * Algorithm
550    */
551   uint8_t algorithm;
552
553   /* Followed by the certificate */
554 };
555
556
557 /**
558  * Payload of DNSSEC TLSA record.
559  * http://datatracker.ietf.org/doc/draft-ietf-dane-protocol/
560  */
561 struct GNUNET_TUN_DnsTlsaRecord
562 {
563
564   /**
565    * Certificate usage
566    * 0: CA cert
567    * 1: Entity cert
568    * 2: Trust anchor
569    * 3: domain-issued cert
570    */
571   uint8_t usage;
572
573   /**
574    * Selector
575    * What part will be matched against the cert
576    * presented by server
577    * 0: Full cert (in binary)
578    * 1: Full cert (in DER)
579    */
580   uint8_t selector;
581
582   /**
583    * Matching type (of selected content)
584    * 0: exact match
585    * 1: SHA-256 hash
586    * 2: SHA-512 hash
587    */
588   uint8_t matching_type;
589
590   /**
591    * followed by certificate association data
592    * The "certificate association data" to be matched.
593    * These bytes are either raw data (that is, the full certificate or
594    * its SubjectPublicKeyInfo, depending on the selector) for matching
595    * type 0, or the hash of the raw data for matching types 1 and 2.
596    * The data refers to the certificate in the association, not to the
597    * TLS ASN.1 Certificate object.
598    *
599    * The data is represented as a string of hex chars
600    */
601 };
602
603
604 /**
605  * Payload of GNS VPN record
606  */
607 struct GNUNET_TUN_GnsVpnRecord
608 {
609   /**
610    * The peer to contact
611    */
612   struct GNUNET_PeerIdentity peer;
613
614   /**
615    * The protocol to use
616    */
617   uint16_t proto;
618
619   /* followed by the servicename */
620 };
621
622
623 /**
624  * DNS query prefix.
625  */
626 struct GNUNET_TUN_DnsQueryLine
627 {
628   /**
629    * Desired type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
630    */
631   uint16_t type GNUNET_PACKED;
632
633   /**
634    * Desired class (usually GNUNET_TUN_DNS_CLASS_INTERNET). (NBO)
635    */
636   uint16_t dns_traffic_class GNUNET_PACKED;
637 };
638
639
640 /**
641  * General DNS record prefix.
642  */
643 struct GNUNET_TUN_DnsRecordLine
644 {
645   /**
646    * Record type (GNUNET_DNSPARSER_TYPE_XXX). (NBO)
647    */
648   uint16_t type GNUNET_PACKED;
649
650   /**
651    * Record class (usually GNUNET_TUN_DNS_CLASS_INTERNET). (NBO)
652    */
653   uint16_t dns_traffic_class GNUNET_PACKED;
654
655   /**
656    * Expiration for the record (in seconds). (NBO)
657    */
658   uint32_t ttl GNUNET_PACKED;
659
660   /**
661    * Number of bytes of data that follow. (NBO)
662    */
663   uint16_t data_len GNUNET_PACKED;
664 };
665
666
667 #define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0
668 #define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3
669 #define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4
670 #define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5
671 #define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8
672 #define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9
673 #define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10
674 #define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11
675
676 #define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1
677 #define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2
678 #define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3
679 #define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4
680 #define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128
681 #define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129
682
683
684 /**
685  * ICMP header.
686  */
687 struct GNUNET_TUN_IcmpHeader
688 {
689   uint8_t type;
690   uint8_t code;
691   uint16_t crc GNUNET_PACKED;
692
693   union
694   {
695     /**
696      * ICMP Echo (request/reply)
697      */
698     struct
699     {
700       uint16_t  identifier GNUNET_PACKED;
701       uint16_t  sequence_number GNUNET_PACKED;
702     } echo;
703
704     /**
705      * ICMP Destination Unreachable (RFC 1191)
706      */
707     struct ih_pmtu
708     {
709       uint16_t empty GNUNET_PACKED;
710       uint16_t next_hop_mtu GNUNET_PACKED;
711       /* followed by original IP header + first 8 bytes of original IP datagram */
712     } destination_unreachable;
713
714     /**
715      * ICMP Redirect
716      */
717     struct in_addr redirect_gateway_address GNUNET_PACKED;
718
719     /**
720      * MTU for packets that are too big (IPv6).
721      */
722     uint32_t packet_too_big_mtu GNUNET_PACKED;
723
724   } quench;
725
726 };
727
728
729 GNUNET_NETWORK_STRUCT_END
730
731
732 /**
733  * Initialize an IPv4 header.
734  *
735  * @param ip header to initialize
736  * @param protocol protocol to use (i.e. IPPROTO_UDP)
737  * @param payload_length number of bytes of payload that follow (excluding IPv4 header)
738  * @param src source IP address to use
739  * @param dst destination IP address to use
740  */
741 void
742 GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
743                                    uint8_t protocol,
744                                    uint16_t payload_length,
745                                    const struct in_addr *src,
746                                    const struct in_addr *dst);
747
748
749 /**
750  * Initialize an IPv6 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_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
760                                    uint8_t protocol,
761                                    uint16_t payload_length,
762                                    const struct in6_addr *src,
763                                    const struct in6_addr *dst);
764
765 /**
766  * Calculate IPv4 TCP checksum.
767  *
768  * @param ip ipv4 header fully initialized
769  * @param tcp TCP header (initialized except for CRC)
770  * @param payload the TCP payload
771  * @param payload_length number of bytes of TCP @a payload
772  */
773 void
774 GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
775                                     struct GNUNET_TUN_TcpHeader *tcp,
776                                     const void *payload,
777                                     uint16_t payload_length);
778
779 /**
780  * Calculate IPv6 TCP checksum.
781  *
782  * @param ip ipv6 header fully initialized
783  * @param tcp TCP header (initialized except for CRC)
784  * @param payload the TCP payload
785  * @param payload_length number of bytes of TCP payload
786  */
787 void
788 GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
789                                     struct GNUNET_TUN_TcpHeader *tcp,
790                                     const void *payload,
791                                     uint16_t payload_length);
792
793 /**
794  * Calculate IPv4 UDP checksum.
795  *
796  * @param ip ipv4 header fully initialized
797  * @param udp UDP header (initialized except for CRC)
798  * @param payload the UDP payload
799  * @param payload_length number of bytes of UDP @a payload
800  */
801 void
802 GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
803                                     struct GNUNET_TUN_UdpHeader *udp,
804                                     const void *payload,
805                                     uint16_t payload_length);
806
807
808 /**
809  * Calculate IPv6 UDP checksum.
810  *
811  * @param ip ipv6 header fully initialized
812  * @param udp UDP header (initialized except for CRC)
813  * @param payload the UDP payload
814  * @param payload_length number of bytes of @a payload
815  */
816 void
817 GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
818                                     struct GNUNET_TUN_UdpHeader *udp,
819                                     const void *payload,
820                                     uint16_t payload_length);
821
822
823 /**
824  * Calculate ICMP checksum.
825  *
826  * @param icmp IMCP header (initialized except for CRC)
827  * @param payload the ICMP payload
828  * @param payload_length number of bytes of @a payload
829  */
830 void
831 GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
832                                     const void *payload,
833                                     uint16_t payload_length);
834
835
836 /**
837  * Create a regex in @a rxstr from the given @a ip and @a port.
838  *
839  * @param ip IPv4 representation.
840  * @param port destination port
841  * @param rxstr generated regex, must be at least #GNUNET_TUN_IPV4_REGEXLEN
842  *              bytes long.
843  */
844 void
845 GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip,
846                               uint16_t port,
847                               char *rxstr);
848
849
850 /**
851  * Create a regex in @a rxstr from the given @a ipv6 and @a port.
852  *
853  * @param ipv6 IPv6 representation.
854  * @param port destination port
855  * @param rxstr generated regex, must be at least #GNUNET_TUN_IPV6_REGEXLEN
856  *              bytes long.
857  */
858 void
859 GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6,
860                               uint16_t port,
861                               char *rxstr);
862
863
864 /**
865  * Convert an exit policy to a regular expression.  The exit policy
866  * specifies a set of subnets this peer is willing to serve as an
867  * exit for; the resulting regular expression will match the
868  * IPv6 address strings as returned by #GNUNET_TUN_ipv6toregexsearch.
869  *
870  * @param policy exit policy specification
871  * @return regular expression, NULL on error
872  */
873 char *
874 GNUNET_TUN_ipv6policy2regex (const char *policy);
875
876
877 /**
878  * Convert an exit policy to a regular expression.  The exit policy
879  * specifies a set of subnets this peer is willing to serve as an
880  * exit for; the resulting regular expression will match the
881  * IPv4 address strings as returned by #GNUNET_TUN_ipv4toregexsearch.
882  *
883  * @param policy exit policy specification
884  * @return regular expression, NULL on error
885  */
886 char *
887 GNUNET_TUN_ipv4policy2regex (const char *policy);
888
889
890 /**
891  * Hash the service name of a hosted service to the
892  * hash code that is used to identify the service on
893  * the network.
894  *
895  * @param service_name a string
896  * @param hc corresponding hash
897  */
898 void
899 GNUNET_TUN_service_name_to_hash (const char *service_name,
900                                  struct GNUNET_HashCode *hc);
901
902 #endif