diff options
Diffstat (limited to 'src/include/gnunet_tun_lib.h')
-rw-r--r-- | src/include/gnunet_tun_lib.h | 152 |
1 files changed, 64 insertions, 88 deletions
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h index c01e641c1..941f394aa 100644 --- a/src/include/gnunet_tun_lib.h +++ b/src/include/gnunet_tun_lib.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Philipp Toelke | 22 | * @author Philipp Toelke |
@@ -78,8 +78,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
78 | /** | 78 | /** |
79 | * Header from Linux TUN interface. | 79 | * Header from Linux TUN interface. |
80 | */ | 80 | */ |
81 | struct GNUNET_TUN_Layer2PacketHeader | 81 | struct GNUNET_TUN_Layer2PacketHeader { |
82 | { | ||
83 | /** | 82 | /** |
84 | * Some flags (unused). | 83 | * Some flags (unused). |
85 | */ | 84 | */ |
@@ -95,8 +94,7 @@ struct GNUNET_TUN_Layer2PacketHeader | |||
95 | /** | 94 | /** |
96 | * Standard IPv4 header. | 95 | * Standard IPv4 header. |
97 | */ | 96 | */ |
98 | struct GNUNET_TUN_IPv4Header | 97 | struct GNUNET_TUN_IPv4Header { |
99 | { | ||
100 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 98 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
101 | unsigned int header_length : 4 GNUNET_PACKED; | 99 | unsigned int header_length : 4 GNUNET_PACKED; |
102 | unsigned int version : 4 GNUNET_PACKED; | 100 | unsigned int version : 4 GNUNET_PACKED; |
@@ -152,8 +150,7 @@ struct GNUNET_TUN_IPv4Header | |||
152 | /** | 150 | /** |
153 | * Standard IPv6 header. | 151 | * Standard IPv6 header. |
154 | */ | 152 | */ |
155 | struct GNUNET_TUN_IPv6Header | 153 | struct GNUNET_TUN_IPv6Header { |
156 | { | ||
157 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 154 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
158 | unsigned int traffic_class_h : 4 GNUNET_PACKED; | 155 | unsigned int traffic_class_h : 4 GNUNET_PACKED; |
159 | unsigned int version : 4 GNUNET_PACKED; | 156 | unsigned int version : 4 GNUNET_PACKED; |
@@ -208,8 +205,7 @@ struct GNUNET_TUN_IPv6Header | |||
208 | /** | 205 | /** |
209 | * TCP packet header. | 206 | * TCP packet header. |
210 | */ | 207 | */ |
211 | struct GNUNET_TUN_TcpHeader | 208 | struct GNUNET_TUN_TcpHeader { |
212 | { | ||
213 | /** | 209 | /** |
214 | * Source port (in NBO). | 210 | * Source port (in NBO). |
215 | */ | 211 | */ |
@@ -276,8 +272,7 @@ struct GNUNET_TUN_TcpHeader | |||
276 | /** | 272 | /** |
277 | * UDP packet header. | 273 | * UDP packet header. |
278 | */ | 274 | */ |
279 | struct GNUNET_TUN_UdpHeader | 275 | struct GNUNET_TUN_UdpHeader { |
280 | { | ||
281 | /** | 276 | /** |
282 | * Source port (in NBO). | 277 | * Source port (in NBO). |
283 | */ | 278 | */ |
@@ -336,8 +331,7 @@ struct GNUNET_TUN_UdpHeader | |||
336 | /** | 331 | /** |
337 | * DNS flags (largely RFC 1035 / RFC 2136). | 332 | * DNS flags (largely RFC 1035 / RFC 2136). |
338 | */ | 333 | */ |
339 | struct GNUNET_TUN_DnsFlags | 334 | struct GNUNET_TUN_DnsFlags { |
340 | { | ||
341 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 335 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
342 | /** | 336 | /** |
343 | * Set to 1 if recursion is desired (client -> server) | 337 | * Set to 1 if recursion is desired (client -> server) |
@@ -389,7 +383,6 @@ struct GNUNET_TUN_DnsFlags | |||
389 | */ | 383 | */ |
390 | unsigned int recursion_available : 1 GNUNET_PACKED; | 384 | unsigned int recursion_available : 1 GNUNET_PACKED; |
391 | #elif __BYTE_ORDER == __BIG_ENDIAN | 385 | #elif __BYTE_ORDER == __BIG_ENDIAN |
392 | |||
393 | /** | 386 | /** |
394 | * query:0, response:1 | 387 | * query:0, response:1 |
395 | */ | 388 | */ |
@@ -443,15 +436,13 @@ struct GNUNET_TUN_DnsFlags | |||
443 | #else | 436 | #else |
444 | #error byteorder undefined | 437 | #error byteorder undefined |
445 | #endif | 438 | #endif |
446 | |||
447 | } GNUNET_GCC_STRUCT_LAYOUT; | 439 | } GNUNET_GCC_STRUCT_LAYOUT; |
448 | 440 | ||
449 | 441 | ||
450 | /** | 442 | /** |
451 | * DNS header. | 443 | * DNS header. |
452 | */ | 444 | */ |
453 | struct GNUNET_TUN_DnsHeader | 445 | struct GNUNET_TUN_DnsHeader { |
454 | { | ||
455 | /** | 446 | /** |
456 | * Unique identifier for the request/response. | 447 | * Unique identifier for the request/response. |
457 | */ | 448 | */ |
@@ -487,8 +478,7 @@ struct GNUNET_TUN_DnsHeader | |||
487 | /** | 478 | /** |
488 | * Payload of DNS SOA record (header). | 479 | * Payload of DNS SOA record (header). |
489 | */ | 480 | */ |
490 | struct GNUNET_TUN_DnsSoaRecord | 481 | struct GNUNET_TUN_DnsSoaRecord { |
491 | { | ||
492 | /** | 482 | /** |
493 | * The version number of the original copy of the zone. (NBO) | 483 | * The version number of the original copy of the zone. (NBO) |
494 | */ | 484 | */ |
@@ -522,9 +512,7 @@ struct GNUNET_TUN_DnsSoaRecord | |||
522 | /** | 512 | /** |
523 | * Payload of DNS SRV record (header). | 513 | * Payload of DNS SRV record (header). |
524 | */ | 514 | */ |
525 | struct GNUNET_TUN_DnsSrvRecord | 515 | struct GNUNET_TUN_DnsSrvRecord { |
526 | { | ||
527 | |||
528 | /** | 516 | /** |
529 | * Preference for this entry (lower value is higher preference). Clients | 517 | * Preference for this entry (lower value is higher preference). Clients |
530 | * will contact hosts from the lowest-priority group first and fall back | 518 | * will contact hosts from the lowest-priority group first and fall back |
@@ -551,9 +539,7 @@ struct GNUNET_TUN_DnsSrvRecord | |||
551 | /** | 539 | /** |
552 | * Payload of DNS CERT record. | 540 | * Payload of DNS CERT record. |
553 | */ | 541 | */ |
554 | struct GNUNET_TUN_DnsCertRecord | 542 | struct GNUNET_TUN_DnsCertRecord { |
555 | { | ||
556 | |||
557 | /** | 543 | /** |
558 | * Certificate type | 544 | * Certificate type |
559 | */ | 545 | */ |
@@ -577,9 +563,7 @@ struct GNUNET_TUN_DnsCertRecord | |||
577 | * Payload of DNSSEC TLSA record. | 563 | * Payload of DNSSEC TLSA record. |
578 | * http://datatracker.ietf.org/doc/draft-ietf-dane-protocol/ | 564 | * http://datatracker.ietf.org/doc/draft-ietf-dane-protocol/ |
579 | */ | 565 | */ |
580 | struct GNUNET_TUN_DnsTlsaRecord | 566 | struct GNUNET_TUN_DnsTlsaRecord { |
581 | { | ||
582 | |||
583 | /** | 567 | /** |
584 | * Certificate usage | 568 | * Certificate usage |
585 | * 0: CA cert | 569 | * 0: CA cert |
@@ -623,8 +607,7 @@ struct GNUNET_TUN_DnsTlsaRecord | |||
623 | /** | 607 | /** |
624 | * Payload of GNS VPN record | 608 | * Payload of GNS VPN record |
625 | */ | 609 | */ |
626 | struct GNUNET_TUN_GnsVpnRecord | 610 | struct GNUNET_TUN_GnsVpnRecord { |
627 | { | ||
628 | /** | 611 | /** |
629 | * The peer to contact | 612 | * The peer to contact |
630 | */ | 613 | */ |
@@ -642,8 +625,7 @@ struct GNUNET_TUN_GnsVpnRecord | |||
642 | /** | 625 | /** |
643 | * DNS query prefix. | 626 | * DNS query prefix. |
644 | */ | 627 | */ |
645 | struct GNUNET_TUN_DnsQueryLine | 628 | struct GNUNET_TUN_DnsQueryLine { |
646 | { | ||
647 | /** | 629 | /** |
648 | * Desired type (GNUNET_DNSPARSER_TYPE_XXX). (NBO) | 630 | * Desired type (GNUNET_DNSPARSER_TYPE_XXX). (NBO) |
649 | */ | 631 | */ |
@@ -659,8 +641,7 @@ struct GNUNET_TUN_DnsQueryLine | |||
659 | /** | 641 | /** |
660 | * General DNS record prefix. | 642 | * General DNS record prefix. |
661 | */ | 643 | */ |
662 | struct GNUNET_TUN_DnsRecordLine | 644 | struct GNUNET_TUN_DnsRecordLine { |
663 | { | ||
664 | /** | 645 | /** |
665 | * Record type (GNUNET_DNSPARSER_TYPE_XXX). (NBO) | 646 | * Record type (GNUNET_DNSPARSER_TYPE_XXX). (NBO) |
666 | */ | 647 | */ |
@@ -703,19 +684,16 @@ struct GNUNET_TUN_DnsRecordLine | |||
703 | /** | 684 | /** |
704 | * ICMP header. | 685 | * ICMP header. |
705 | */ | 686 | */ |
706 | struct GNUNET_TUN_IcmpHeader | 687 | struct GNUNET_TUN_IcmpHeader { |
707 | { | ||
708 | uint8_t type; | 688 | uint8_t type; |
709 | uint8_t code; | 689 | uint8_t code; |
710 | uint16_t crc GNUNET_PACKED; | 690 | uint16_t crc GNUNET_PACKED; |
711 | 691 | ||
712 | union | 692 | union { |
713 | { | ||
714 | /** | 693 | /** |
715 | * ICMP Echo (request/reply) | 694 | * ICMP Echo (request/reply) |
716 | */ | 695 | */ |
717 | struct | 696 | struct { |
718 | { | ||
719 | uint16_t identifier GNUNET_PACKED; | 697 | uint16_t identifier GNUNET_PACKED; |
720 | uint16_t sequence_number GNUNET_PACKED; | 698 | uint16_t sequence_number GNUNET_PACKED; |
721 | } echo; | 699 | } echo; |
@@ -723,8 +701,7 @@ struct GNUNET_TUN_IcmpHeader | |||
723 | /** | 701 | /** |
724 | * ICMP Destination Unreachable (RFC 1191) | 702 | * ICMP Destination Unreachable (RFC 1191) |
725 | */ | 703 | */ |
726 | struct ih_pmtu | 704 | struct ih_pmtu { |
727 | { | ||
728 | uint16_t empty GNUNET_PACKED; | 705 | uint16_t empty GNUNET_PACKED; |
729 | uint16_t next_hop_mtu GNUNET_PACKED; | 706 | uint16_t next_hop_mtu GNUNET_PACKED; |
730 | /* followed by original IP header + first 8 bytes of original IP datagram | 707 | /* followed by original IP header + first 8 bytes of original IP datagram |
@@ -740,7 +717,6 @@ struct GNUNET_TUN_IcmpHeader | |||
740 | * MTU for packets that are too big (IPv6). | 717 | * MTU for packets that are too big (IPv6). |
741 | */ | 718 | */ |
742 | uint32_t packet_too_big_mtu GNUNET_PACKED; | 719 | uint32_t packet_too_big_mtu GNUNET_PACKED; |
743 | |||
744 | } quench; | 720 | } quench; |
745 | }; | 721 | }; |
746 | 722 | ||
@@ -759,11 +735,11 @@ GNUNET_NETWORK_STRUCT_END | |||
759 | * @param dst destination IP address to use | 735 | * @param dst destination IP address to use |
760 | */ | 736 | */ |
761 | void | 737 | void |
762 | GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, | 738 | GNUNET_TUN_initialize_ipv4_header(struct GNUNET_TUN_IPv4Header *ip, |
763 | uint8_t protocol, | 739 | uint8_t protocol, |
764 | uint16_t payload_length, | 740 | uint16_t payload_length, |
765 | const struct in_addr *src, | 741 | const struct in_addr *src, |
766 | const struct in_addr *dst); | 742 | const struct in_addr *dst); |
767 | 743 | ||
768 | 744 | ||
769 | /** | 745 | /** |
@@ -777,11 +753,11 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, | |||
777 | * @param dst destination IP address to use | 753 | * @param dst destination IP address to use |
778 | */ | 754 | */ |
779 | void | 755 | void |
780 | GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, | 756 | GNUNET_TUN_initialize_ipv6_header(struct GNUNET_TUN_IPv6Header *ip, |
781 | uint8_t protocol, | 757 | uint8_t protocol, |
782 | uint16_t payload_length, | 758 | uint16_t payload_length, |
783 | const struct in6_addr *src, | 759 | const struct in6_addr *src, |
784 | const struct in6_addr *dst); | 760 | const struct in6_addr *dst); |
785 | 761 | ||
786 | /** | 762 | /** |
787 | * Calculate IPv4 TCP checksum. | 763 | * Calculate IPv4 TCP checksum. |
@@ -792,10 +768,10 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, | |||
792 | * @param payload_length number of bytes of TCP @a payload | 768 | * @param payload_length number of bytes of TCP @a payload |
793 | */ | 769 | */ |
794 | void | 770 | void |
795 | GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | 771 | GNUNET_TUN_calculate_tcp4_checksum(const struct GNUNET_TUN_IPv4Header *ip, |
796 | struct GNUNET_TUN_TcpHeader *tcp, | 772 | struct GNUNET_TUN_TcpHeader *tcp, |
797 | const void *payload, | 773 | const void *payload, |
798 | uint16_t payload_length); | 774 | uint16_t payload_length); |
799 | 775 | ||
800 | /** | 776 | /** |
801 | * Calculate IPv6 TCP checksum. | 777 | * Calculate IPv6 TCP checksum. |
@@ -806,10 +782,10 @@ GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | |||
806 | * @param payload_length number of bytes of TCP payload | 782 | * @param payload_length number of bytes of TCP payload |
807 | */ | 783 | */ |
808 | void | 784 | void |
809 | GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | 785 | GNUNET_TUN_calculate_tcp6_checksum(const struct GNUNET_TUN_IPv6Header *ip, |
810 | struct GNUNET_TUN_TcpHeader *tcp, | 786 | struct GNUNET_TUN_TcpHeader *tcp, |
811 | const void *payload, | 787 | const void *payload, |
812 | uint16_t payload_length); | 788 | uint16_t payload_length); |
813 | 789 | ||
814 | /** | 790 | /** |
815 | * Calculate IPv4 UDP checksum. | 791 | * Calculate IPv4 UDP checksum. |
@@ -820,10 +796,10 @@ GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | |||
820 | * @param payload_length number of bytes of UDP @a payload | 796 | * @param payload_length number of bytes of UDP @a payload |
821 | */ | 797 | */ |
822 | void | 798 | void |
823 | GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | 799 | GNUNET_TUN_calculate_udp4_checksum(const struct GNUNET_TUN_IPv4Header *ip, |
824 | struct GNUNET_TUN_UdpHeader *udp, | 800 | struct GNUNET_TUN_UdpHeader *udp, |
825 | const void *payload, | 801 | const void *payload, |
826 | uint16_t payload_length); | 802 | uint16_t payload_length); |
827 | 803 | ||
828 | 804 | ||
829 | /** | 805 | /** |
@@ -835,10 +811,10 @@ GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | |||
835 | * @param payload_length number of bytes of @a payload | 811 | * @param payload_length number of bytes of @a payload |
836 | */ | 812 | */ |
837 | void | 813 | void |
838 | GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | 814 | GNUNET_TUN_calculate_udp6_checksum(const struct GNUNET_TUN_IPv6Header *ip, |
839 | struct GNUNET_TUN_UdpHeader *udp, | 815 | struct GNUNET_TUN_UdpHeader *udp, |
840 | const void *payload, | 816 | const void *payload, |
841 | uint16_t payload_length); | 817 | uint16_t payload_length); |
842 | 818 | ||
843 | 819 | ||
844 | /** | 820 | /** |
@@ -849,9 +825,9 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | |||
849 | * @param payload_length number of bytes of @a payload | 825 | * @param payload_length number of bytes of @a payload |
850 | */ | 826 | */ |
851 | void | 827 | void |
852 | GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, | 828 | GNUNET_TUN_calculate_icmp_checksum(struct GNUNET_TUN_IcmpHeader *icmp, |
853 | const void *payload, | 829 | const void *payload, |
854 | uint16_t payload_length); | 830 | uint16_t payload_length); |
855 | 831 | ||
856 | 832 | ||
857 | /** | 833 | /** |
@@ -863,9 +839,9 @@ GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, | |||
863 | * bytes long. | 839 | * bytes long. |
864 | */ | 840 | */ |
865 | void | 841 | void |
866 | GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip, | 842 | GNUNET_TUN_ipv4toregexsearch(const struct in_addr *ip, |
867 | uint16_t port, | 843 | uint16_t port, |
868 | char *rxstr); | 844 | char *rxstr); |
869 | 845 | ||
870 | 846 | ||
871 | /** | 847 | /** |
@@ -877,9 +853,9 @@ GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip, | |||
877 | * bytes long. | 853 | * bytes long. |
878 | */ | 854 | */ |
879 | void | 855 | void |
880 | GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6, | 856 | GNUNET_TUN_ipv6toregexsearch(const struct in6_addr *ipv6, |
881 | uint16_t port, | 857 | uint16_t port, |
882 | char *rxstr); | 858 | char *rxstr); |
883 | 859 | ||
884 | 860 | ||
885 | /** | 861 | /** |
@@ -892,7 +868,7 @@ GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6, | |||
892 | * @return regular expression, NULL on error | 868 | * @return regular expression, NULL on error |
893 | */ | 869 | */ |
894 | char * | 870 | char * |
895 | GNUNET_TUN_ipv6policy2regex (const char *policy); | 871 | GNUNET_TUN_ipv6policy2regex(const char *policy); |
896 | 872 | ||
897 | 873 | ||
898 | /** | 874 | /** |
@@ -905,7 +881,7 @@ GNUNET_TUN_ipv6policy2regex (const char *policy); | |||
905 | * @return regular expression, NULL on error | 881 | * @return regular expression, NULL on error |
906 | */ | 882 | */ |
907 | char * | 883 | char * |
908 | GNUNET_TUN_ipv4policy2regex (const char *policy); | 884 | GNUNET_TUN_ipv4policy2regex(const char *policy); |
909 | 885 | ||
910 | 886 | ||
911 | /** | 887 | /** |
@@ -917,8 +893,8 @@ GNUNET_TUN_ipv4policy2regex (const char *policy); | |||
917 | * @param[out] hc corresponding hash | 893 | * @param[out] hc corresponding hash |
918 | */ | 894 | */ |
919 | void | 895 | void |
920 | GNUNET_TUN_service_name_to_hash (const char *service_name, | 896 | GNUNET_TUN_service_name_to_hash(const char *service_name, |
921 | struct GNUNET_HashCode *hc); | 897 | struct GNUNET_HashCode *hc); |
922 | 898 | ||
923 | 899 | ||
924 | /** | 900 | /** |
@@ -930,9 +906,9 @@ GNUNET_TUN_service_name_to_hash (const char *service_name, | |||
930 | * @return #GNUNET_YES if they are equal | 906 | * @return #GNUNET_YES if they are equal |
931 | */ | 907 | */ |
932 | int | 908 | int |
933 | GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa, | 909 | GNUNET_TUN_sockaddr_cmp(const struct sockaddr *sa, |
934 | const struct sockaddr *sb, | 910 | const struct sockaddr *sb, |
935 | int include_port); | 911 | int include_port); |
936 | 912 | ||
937 | 913 | ||
938 | /** | 914 | /** |
@@ -945,9 +921,9 @@ GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa, | |||
945 | * @param[out] cadet_port CADET port to use | 921 | * @param[out] cadet_port CADET port to use |
946 | */ | 922 | */ |
947 | void | 923 | void |
948 | GNUNET_TUN_compute_service_cadet_port (const struct GNUNET_HashCode *desc, | 924 | GNUNET_TUN_compute_service_cadet_port(const struct GNUNET_HashCode *desc, |
949 | uint16_t ip_port, | 925 | uint16_t ip_port, |
950 | struct GNUNET_HashCode *cadet_port); | 926 | struct GNUNET_HashCode *cadet_port); |
951 | 927 | ||
952 | #endif | 928 | #endif |
953 | 929 | ||