gnunet_tun_lib.h 21 KB

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