gnunet_tun_lib.h 20 KB

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