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