aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_tun_lib.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-15 10:52:06 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-15 10:52:06 +0000
commit3288af4a4651156c01bdf6ffe1b20c6fbedf4bd8 (patch)
treeed49951102400f7086f4db23846fb7aaf32e5eb1 /src/include/gnunet_tun_lib.h
parent9e94c69b299f74ac88b14f92b7a01bba0c33a776 (diff)
downloadgnunet-3288af4a4651156c01bdf6ffe1b20c6fbedf4bd8.tar.gz
gnunet-3288af4a4651156c01bdf6ffe1b20c6fbedf4bd8.zip
-eliminating duplicate struct definitions
Diffstat (limited to 'src/include/gnunet_tun_lib.h')
-rw-r--r--src/include/gnunet_tun_lib.h396
1 files changed, 382 insertions, 14 deletions
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h
index 1b0bb716d..683910d93 100644
--- a/src/include/gnunet_tun_lib.h
+++ b/src/include/gnunet_tun_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010, 2011, 2012 Christian Grothoff 3 (C) 2010-2013 Christian Grothoff
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -183,7 +183,14 @@ struct GNUNET_TUN_IPv6Header
183 */ 183 */
184struct GNUNET_TUN_TcpHeader 184struct GNUNET_TUN_TcpHeader
185{ 185{
186 /**
187 * Source port (in NBO).
188 */
186 uint16_t source_port GNUNET_PACKED; 189 uint16_t source_port GNUNET_PACKED;
190
191 /**
192 * Destination port (in NBO).
193 */
187 uint16_t destination_port GNUNET_PACKED; 194 uint16_t destination_port GNUNET_PACKED;
188 195
189 /** 196 /**
@@ -244,26 +251,387 @@ struct GNUNET_TUN_TcpHeader
244 */ 251 */
245struct GNUNET_TUN_UdpHeader 252struct GNUNET_TUN_UdpHeader
246{ 253{
254 /**
255 * Source port (in NBO).
256 */
247 uint16_t source_port GNUNET_PACKED; 257 uint16_t source_port GNUNET_PACKED;
258
259 /**
260 * Destination port (in NBO).
261 */
248 uint16_t destination_port GNUNET_PACKED; 262 uint16_t destination_port GNUNET_PACKED;
263
264 /**
265 * Number of bytes of payload.
266 */
249 uint16_t len GNUNET_PACKED; 267 uint16_t len GNUNET_PACKED;
268
269 /**
270 * Checksum.
271 */
250 uint16_t crc GNUNET_PACKED; 272 uint16_t crc GNUNET_PACKED;
251}; 273};
252 274
253 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 */
313struct 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
254/** 425/**
255 * DNS header. 426 * DNS header.
256 */ 427 */
257struct GNUNET_TUN_DnsHeader 428struct GNUNET_TUN_DnsHeader
258{ 429{
430 /**
431 * Unique identifier for the request/response.
432 */
259 uint16_t id GNUNET_PACKED; 433 uint16_t id GNUNET_PACKED;
260 uint16_t flags GNUNET_PACKED; 434
261 uint16_t qdcount GNUNET_PACKED; 435 /**
262 uint16_t ancount GNUNET_PACKED; 436 * Flags.
263 uint16_t nscount GNUNET_PACKED; 437 */
264 uint16_t arcount GNUNET_PACKED; 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 */
465struct 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;
265}; 494};
266 495
496
497/**
498 * Payload of DNS SRV record (header).
499 */
500struct 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 */
530struct 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 */
576struct GNUNET_TUN_GnsVpnRecord
577{
578 /**
579 * The peer to contact
580 */
581 struct GNUNET_HashCode 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 */
594struct 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 class GNUNET_PACKED;
605};
606
607
608/**
609 * General DNS record prefix.
610 */
611struct 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 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
267#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0 635#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0
268#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3 636#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3
269#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4 637#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4
@@ -364,7 +732,7 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
364 * @param ip ipv4 header fully initialized 732 * @param ip ipv4 header fully initialized
365 * @param tcp TCP header (initialized except for CRC) 733 * @param tcp TCP header (initialized except for CRC)
366 * @param payload the TCP payload 734 * @param payload the TCP payload
367 * @param payload_length number of bytes of TCP payload 735 * @param payload_length number of bytes of TCP @a payload
368 */ 736 */
369void 737void
370GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, 738GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
@@ -392,7 +760,7 @@ GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
392 * @param ip ipv4 header fully initialized 760 * @param ip ipv4 header fully initialized
393 * @param udp UDP header (initialized except for CRC) 761 * @param udp UDP header (initialized except for CRC)
394 * @param payload the UDP payload 762 * @param payload the UDP payload
395 * @param payload_length number of bytes of UDP payload 763 * @param payload_length number of bytes of UDP @a payload
396 */ 764 */
397void 765void
398GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, 766GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
@@ -430,11 +798,11 @@ GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
430 798
431 799
432/** 800/**
433 * Create a regex in 'rxstr' from the given 'ip' and 'netmask'. 801 * Create a regex in @a rxstr from the given @a ip and @a netmask.
434 * 802 *
435 * @param ip IPv4 representation. 803 * @param ip IPv4 representation.
436 * @param netmask netmask for the ip. 804 * @param netmask netmask for the ip.
437 * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN 805 * @param rxstr generated regex, must be at least #GNUNET_REGEX_IPV4_REGEXLEN
438 * bytes long. 806 * bytes long.
439 */ 807 */
440void 808void
@@ -443,11 +811,11 @@ GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip, const char *netmask,
443 811
444 812
445/** 813/**
446 * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'. 814 * Create a regex in @a rxstr from the given @a ipv6 and @a prefixlen.
447 * 815 *
448 * @param ipv6 IPv6 representation. 816 * @param ipv6 IPv6 representation.
449 * @param prefixlen length of the ipv6 prefix. 817 * @param prefixlen length of the ipv6 prefix.
450 * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN 818 * @param rxstr generated regex, must be at least #GNUNET_REGEX_IPV6_REGEXLEN
451 * bytes long. 819 * bytes long.
452 */ 820 */
453void 821void
@@ -459,7 +827,7 @@ GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6,
459 * Convert an exit policy to a regular expression. The exit policy 827 * Convert an exit policy to a regular expression. The exit policy
460 * specifies a set of subnets this peer is willing to serve as an 828 * specifies a set of subnets this peer is willing to serve as an
461 * exit for; the resulting regular expression will match the 829 * exit for; the resulting regular expression will match the
462 * IPv6 address strings as returned by 'GNUNET_TUN_ipv6toregexsearch'. 830 * IPv6 address strings as returned by #GNUNET_TUN_ipv6toregexsearch.
463 * 831 *
464 * @param policy exit policy specification 832 * @param policy exit policy specification
465 * @return regular expression, NULL on error 833 * @return regular expression, NULL on error
@@ -472,7 +840,7 @@ GNUNET_TUN_ipv6policy2regex (const char *policy);
472 * Convert an exit policy to a regular expression. The exit policy 840 * Convert an exit policy to a regular expression. The exit policy
473 * specifies a set of subnets this peer is willing to serve as an 841 * specifies a set of subnets this peer is willing to serve as an
474 * exit for; the resulting regular expression will match the 842 * exit for; the resulting regular expression will match the
475 * IPv4 address strings as returned by 'GNUNET_TUN_ipv4toregexsearch'. 843 * IPv4 address strings as returned by #GNUNET_TUN_ipv4toregexsearch.
476 * 844 *
477 * @param policy exit policy specification 845 * @param policy exit policy specification
478 * @return regular expression, NULL on error 846 * @return regular expression, NULL on error