or.h 133 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file or.h
  8. * \brief Master header file for Tor-specific functionality.
  9. **/
  10. #ifndef TOR_OR_H
  11. #define TOR_OR_H
  12. #include "orconfig.h"
  13. #ifdef HAVE_UNISTD_H
  14. #include <unistd.h>
  15. #endif
  16. #ifdef HAVE_SIGNAL_H
  17. #include <signal.h>
  18. #endif
  19. #ifdef HAVE_NETDB_H
  20. #include <netdb.h>
  21. #endif
  22. #ifdef HAVE_SYS_PARAM_H
  23. #include <sys/param.h> /* FreeBSD needs this to know what version it is */
  24. #endif
  25. #include "lib/cc/torint.h"
  26. #ifdef HAVE_SYS_FCNTL_H
  27. #include <sys/fcntl.h>
  28. #endif
  29. #ifdef HAVE_FCNTL_H
  30. #include <fcntl.h>
  31. #endif
  32. #ifdef HAVE_SYS_IOCTL_H
  33. #include <sys/ioctl.h>
  34. #endif
  35. #ifdef HAVE_SYS_UN_H
  36. #include <sys/un.h>
  37. #endif
  38. #ifdef HAVE_SYS_STAT_H
  39. #include <sys/stat.h>
  40. #endif
  41. #ifdef HAVE_NETINET_IN_H
  42. #include <netinet/in.h>
  43. #endif
  44. #ifdef HAVE_ARPA_INET_H
  45. #include <arpa/inet.h>
  46. #endif
  47. #ifdef HAVE_ERRNO_H
  48. #include <errno.h>
  49. #endif
  50. #ifdef HAVE_TIME_H
  51. #include <time.h>
  52. #endif
  53. #ifdef _WIN32
  54. #include <winsock2.h>
  55. #include <io.h>
  56. #include <process.h>
  57. #include <direct.h>
  58. #include <windows.h>
  59. #endif /* defined(_WIN32) */
  60. #include "lib/crypt_ops/crypto.h"
  61. #include "lib/crypt_ops/crypto_format.h"
  62. #include "lib/crypt_ops/crypto_dh.h"
  63. #include "lib/crypt_ops/crypto_hkdf.h"
  64. #include "lib/tls/tortls.h"
  65. #include "common/torlog.h"
  66. #include "common/container.h"
  67. #include "lib/compress/compress.h"
  68. #include "common/address.h"
  69. #include "common/compat_libevent.h"
  70. #include "ht.h"
  71. #include "common/confline.h"
  72. #include "or/replaycache.h"
  73. #include "lib/crypt_ops/crypto_curve25519.h"
  74. #include "lib/crypt_ops/crypto_ed25519.h"
  75. #include "tor_queue.h"
  76. #include "common/token_bucket.h"
  77. #include "common/util_format.h"
  78. #include "or/hs_circuitmap.h"
  79. // These, more than other includes, are for keeping the other struct
  80. // definitions working. We should remove them when we minimize our includes.
  81. #include "or/entry_port_cfg_st.h"
  82. /* These signals are defined to help handle_control_signal work.
  83. */
  84. #ifndef SIGHUP
  85. #define SIGHUP 1
  86. #endif
  87. #ifndef SIGINT
  88. #define SIGINT 2
  89. #endif
  90. #ifndef SIGUSR1
  91. #define SIGUSR1 10
  92. #endif
  93. #ifndef SIGUSR2
  94. #define SIGUSR2 12
  95. #endif
  96. #ifndef SIGTERM
  97. #define SIGTERM 15
  98. #endif
  99. /* Controller signals start at a high number so we don't
  100. * conflict with system-defined signals. */
  101. #define SIGNEWNYM 129
  102. #define SIGCLEARDNSCACHE 130
  103. #define SIGHEARTBEAT 131
  104. #if (SIZEOF_CELL_T != 0)
  105. /* On Irix, stdlib.h defines a cell_t type, so we need to make sure
  106. * that our stuff always calls cell_t something different. */
  107. #define cell_t tor_cell_t
  108. #endif
  109. #ifdef ENABLE_TOR2WEB_MODE
  110. #define NON_ANONYMOUS_MODE_ENABLED 1
  111. #endif
  112. /** Helper macro: Given a pointer to to.base_, of type from*, return &to. */
  113. #define DOWNCAST(to, ptr) ((to*)SUBTYPE_P(ptr, to, base_))
  114. /** Length of longest allowable configured nickname. */
  115. #define MAX_NICKNAME_LEN 19
  116. /** Length of a router identity encoded as a hexadecimal digest, plus
  117. * possible dollar sign. */
  118. #define MAX_HEX_NICKNAME_LEN (HEX_DIGEST_LEN+1)
  119. /** Maximum length of verbose router identifier: dollar sign, hex ID digest,
  120. * equal sign or tilde, nickname. */
  121. #define MAX_VERBOSE_NICKNAME_LEN (1+HEX_DIGEST_LEN+1+MAX_NICKNAME_LEN)
  122. /** Maximum size, in bytes, for resized buffers. */
  123. #define MAX_BUF_SIZE ((1<<24)-1) /* 16MB-1 */
  124. /** Maximum size, in bytes, for any directory object that we've downloaded. */
  125. #define MAX_DIR_DL_SIZE MAX_BUF_SIZE
  126. /** For HTTP parsing: Maximum number of bytes we'll accept in the headers
  127. * of an HTTP request or response. */
  128. #define MAX_HEADERS_SIZE 50000
  129. /** Maximum size, in bytes, for any directory object that we're accepting
  130. * as an upload. */
  131. #define MAX_DIR_UL_SIZE MAX_BUF_SIZE
  132. /** Maximum size, in bytes, of a single router descriptor uploaded to us
  133. * as a directory authority. Caches and clients fetch whatever descriptors
  134. * the authorities tell them to fetch, and don't care about size. */
  135. #define MAX_DESCRIPTOR_UPLOAD_SIZE 20000
  136. /** Maximum size of a single extrainfo document, as above. */
  137. #define MAX_EXTRAINFO_UPLOAD_SIZE 50000
  138. /** Minimum lifetime for an onion key in days. */
  139. #define MIN_ONION_KEY_LIFETIME_DAYS (1)
  140. /** Maximum lifetime for an onion key in days. */
  141. #define MAX_ONION_KEY_LIFETIME_DAYS (90)
  142. /** Default lifetime for an onion key in days. */
  143. #define DEFAULT_ONION_KEY_LIFETIME_DAYS (28)
  144. /** Minimum grace period for acceptance of an onion key in days.
  145. * The maximum value is defined in proposal #274 as being the current network
  146. * consensus parameter for "onion-key-rotation-days". */
  147. #define MIN_ONION_KEY_GRACE_PERIOD_DAYS (1)
  148. /** Default grace period for acceptance of an onion key in days. */
  149. #define DEFAULT_ONION_KEY_GRACE_PERIOD_DAYS (7)
  150. /** How often we should check the network consensus if it is time to rotate or
  151. * expire onion keys. */
  152. #define ONION_KEY_CONSENSUS_CHECK_INTERVAL (60*60)
  153. /** How often do we rotate TLS contexts? */
  154. #define MAX_SSL_KEY_LIFETIME_INTERNAL (2*60*60)
  155. /** How old do we allow a router to get before removing it
  156. * from the router list? In seconds. */
  157. #define ROUTER_MAX_AGE (60*60*48)
  158. /** How old can a router get before we (as a server) will no longer
  159. * consider it live? In seconds. */
  160. #define ROUTER_MAX_AGE_TO_PUBLISH (60*60*24)
  161. /** How old do we let a saved descriptor get before force-removing it? */
  162. #define OLD_ROUTER_DESC_MAX_AGE (60*60*24*5)
  163. /** Possible rules for generating circuit IDs on an OR connection. */
  164. typedef enum {
  165. CIRC_ID_TYPE_LOWER=0, /**< Pick from 0..1<<15-1. */
  166. CIRC_ID_TYPE_HIGHER=1, /**< Pick from 1<<15..1<<16-1. */
  167. /** The other side of a connection is an OP: never create circuits to it,
  168. * and let it use any circuit ID it wants. */
  169. CIRC_ID_TYPE_NEITHER=2
  170. } circ_id_type_t;
  171. #define circ_id_type_bitfield_t ENUM_BF(circ_id_type_t)
  172. #define CONN_TYPE_MIN_ 3
  173. /** Type for sockets listening for OR connections. */
  174. #define CONN_TYPE_OR_LISTENER 3
  175. /** A bidirectional TLS connection transmitting a sequence of cells.
  176. * May be from an OR to an OR, or from an OP to an OR. */
  177. #define CONN_TYPE_OR 4
  178. /** A TCP connection from an onion router to a stream's destination. */
  179. #define CONN_TYPE_EXIT 5
  180. /** Type for sockets listening for SOCKS connections. */
  181. #define CONN_TYPE_AP_LISTENER 6
  182. /** A SOCKS proxy connection from the user application to the onion
  183. * proxy. */
  184. #define CONN_TYPE_AP 7
  185. /** Type for sockets listening for HTTP connections to the directory server. */
  186. #define CONN_TYPE_DIR_LISTENER 8
  187. /** Type for HTTP connections to the directory server. */
  188. #define CONN_TYPE_DIR 9
  189. /* Type 10 is unused. */
  190. /** Type for listening for connections from user interface process. */
  191. #define CONN_TYPE_CONTROL_LISTENER 11
  192. /** Type for connections from user interface process. */
  193. #define CONN_TYPE_CONTROL 12
  194. /** Type for sockets listening for transparent connections redirected by pf or
  195. * netfilter. */
  196. #define CONN_TYPE_AP_TRANS_LISTENER 13
  197. /** Type for sockets listening for transparent connections redirected by
  198. * natd. */
  199. #define CONN_TYPE_AP_NATD_LISTENER 14
  200. /** Type for sockets listening for DNS requests. */
  201. #define CONN_TYPE_AP_DNS_LISTENER 15
  202. /** Type for connections from the Extended ORPort. */
  203. #define CONN_TYPE_EXT_OR 16
  204. /** Type for sockets listening for Extended ORPort connections. */
  205. #define CONN_TYPE_EXT_OR_LISTENER 17
  206. /** Type for sockets listening for HTTP CONNECT tunnel connections. */
  207. #define CONN_TYPE_AP_HTTP_CONNECT_LISTENER 18
  208. #define CONN_TYPE_MAX_ 19
  209. /* !!!! If _CONN_TYPE_MAX is ever over 31, we must grow the type field in
  210. * connection_t. */
  211. /* Proxy client types */
  212. #define PROXY_NONE 0
  213. #define PROXY_CONNECT 1
  214. #define PROXY_SOCKS4 2
  215. #define PROXY_SOCKS5 3
  216. /* !!!! If there is ever a PROXY_* type over 3, we must grow the proxy_type
  217. * field in or_connection_t */
  218. /* Pluggable transport proxy type. Don't use this in or_connection_t,
  219. * instead use the actual underlying proxy type (see above). */
  220. #define PROXY_PLUGGABLE 4
  221. /* Proxy client handshake states */
  222. /* We use a proxy but we haven't even connected to it yet. */
  223. #define PROXY_INFANT 1
  224. /* We use an HTTP proxy and we've sent the CONNECT command. */
  225. #define PROXY_HTTPS_WANT_CONNECT_OK 2
  226. /* We use a SOCKS4 proxy and we've sent the CONNECT command. */
  227. #define PROXY_SOCKS4_WANT_CONNECT_OK 3
  228. /* We use a SOCKS5 proxy and we try to negotiate without
  229. any authentication . */
  230. #define PROXY_SOCKS5_WANT_AUTH_METHOD_NONE 4
  231. /* We use a SOCKS5 proxy and we try to negotiate with
  232. Username/Password authentication . */
  233. #define PROXY_SOCKS5_WANT_AUTH_METHOD_RFC1929 5
  234. /* We use a SOCKS5 proxy and we just sent our credentials. */
  235. #define PROXY_SOCKS5_WANT_AUTH_RFC1929_OK 6
  236. /* We use a SOCKS5 proxy and we just sent our CONNECT command. */
  237. #define PROXY_SOCKS5_WANT_CONNECT_OK 7
  238. /* We use a proxy and we CONNECTed successfully!. */
  239. #define PROXY_CONNECTED 8
  240. /** True iff <b>x</b> is an edge connection. */
  241. #define CONN_IS_EDGE(x) \
  242. ((x)->type == CONN_TYPE_EXIT || (x)->type == CONN_TYPE_AP)
  243. /** State for any listener connection. */
  244. #define LISTENER_STATE_READY 0
  245. #define OR_CONN_STATE_MIN_ 1
  246. /** State for a connection to an OR: waiting for connect() to finish. */
  247. #define OR_CONN_STATE_CONNECTING 1
  248. /** State for a connection to an OR: waiting for proxy handshake to complete */
  249. #define OR_CONN_STATE_PROXY_HANDSHAKING 2
  250. /** State for an OR connection client: SSL is handshaking, not done
  251. * yet. */
  252. #define OR_CONN_STATE_TLS_HANDSHAKING 3
  253. /** State for a connection to an OR: We're doing a second SSL handshake for
  254. * renegotiation purposes. (V2 handshake only.) */
  255. #define OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING 4
  256. /** State for a connection at an OR: We're waiting for the client to
  257. * renegotiate (to indicate a v2 handshake) or send a versions cell (to
  258. * indicate a v3 handshake) */
  259. #define OR_CONN_STATE_TLS_SERVER_RENEGOTIATING 5
  260. /** State for an OR connection: We're done with our SSL handshake, we've done
  261. * renegotiation, but we haven't yet negotiated link protocol versions and
  262. * sent a netinfo cell. */
  263. #define OR_CONN_STATE_OR_HANDSHAKING_V2 6
  264. /** State for an OR connection: We're done with our SSL handshake, but we
  265. * haven't yet negotiated link protocol versions, done a V3 handshake, and
  266. * sent a netinfo cell. */
  267. #define OR_CONN_STATE_OR_HANDSHAKING_V3 7
  268. /** State for an OR connection: Ready to send/receive cells. */
  269. #define OR_CONN_STATE_OPEN 8
  270. #define OR_CONN_STATE_MAX_ 8
  271. /** States of the Extended ORPort protocol. Be careful before changing
  272. * the numbers: they matter. */
  273. #define EXT_OR_CONN_STATE_MIN_ 1
  274. /** Extended ORPort authentication is waiting for the authentication
  275. * type selected by the client. */
  276. #define EXT_OR_CONN_STATE_AUTH_WAIT_AUTH_TYPE 1
  277. /** Extended ORPort authentication is waiting for the client nonce. */
  278. #define EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_NONCE 2
  279. /** Extended ORPort authentication is waiting for the client hash. */
  280. #define EXT_OR_CONN_STATE_AUTH_WAIT_CLIENT_HASH 3
  281. #define EXT_OR_CONN_STATE_AUTH_MAX 3
  282. /** Authentication finished and the Extended ORPort is now accepting
  283. * traffic. */
  284. #define EXT_OR_CONN_STATE_OPEN 4
  285. /** Extended ORPort is flushing its last messages and preparing to
  286. * start accepting OR connections. */
  287. #define EXT_OR_CONN_STATE_FLUSHING 5
  288. #define EXT_OR_CONN_STATE_MAX_ 5
  289. #define EXIT_CONN_STATE_MIN_ 1
  290. /** State for an exit connection: waiting for response from DNS farm. */
  291. #define EXIT_CONN_STATE_RESOLVING 1
  292. /** State for an exit connection: waiting for connect() to finish. */
  293. #define EXIT_CONN_STATE_CONNECTING 2
  294. /** State for an exit connection: open and ready to transmit data. */
  295. #define EXIT_CONN_STATE_OPEN 3
  296. /** State for an exit connection: waiting to be removed. */
  297. #define EXIT_CONN_STATE_RESOLVEFAILED 4
  298. #define EXIT_CONN_STATE_MAX_ 4
  299. /* The AP state values must be disjoint from the EXIT state values. */
  300. #define AP_CONN_STATE_MIN_ 5
  301. /** State for a SOCKS connection: waiting for SOCKS request. */
  302. #define AP_CONN_STATE_SOCKS_WAIT 5
  303. /** State for a SOCKS connection: got a y.onion URL; waiting to receive
  304. * rendezvous descriptor. */
  305. #define AP_CONN_STATE_RENDDESC_WAIT 6
  306. /** The controller will attach this connection to a circuit; it isn't our
  307. * job to do so. */
  308. #define AP_CONN_STATE_CONTROLLER_WAIT 7
  309. /** State for a SOCKS connection: waiting for a completed circuit. */
  310. #define AP_CONN_STATE_CIRCUIT_WAIT 8
  311. /** State for a SOCKS connection: sent BEGIN, waiting for CONNECTED. */
  312. #define AP_CONN_STATE_CONNECT_WAIT 9
  313. /** State for a SOCKS connection: sent RESOLVE, waiting for RESOLVED. */
  314. #define AP_CONN_STATE_RESOLVE_WAIT 10
  315. /** State for a SOCKS connection: ready to send and receive. */
  316. #define AP_CONN_STATE_OPEN 11
  317. /** State for a transparent natd connection: waiting for original
  318. * destination. */
  319. #define AP_CONN_STATE_NATD_WAIT 12
  320. /** State for an HTTP tunnel: waiting for an HTTP CONNECT command. */
  321. #define AP_CONN_STATE_HTTP_CONNECT_WAIT 13
  322. #define AP_CONN_STATE_MAX_ 13
  323. /** True iff the AP_CONN_STATE_* value <b>s</b> means that the corresponding
  324. * edge connection is not attached to any circuit. */
  325. #define AP_CONN_STATE_IS_UNATTACHED(s) \
  326. ((s) <= AP_CONN_STATE_CIRCUIT_WAIT || (s) == AP_CONN_STATE_NATD_WAIT)
  327. #define DIR_CONN_STATE_MIN_ 1
  328. /** State for connection to directory server: waiting for connect(). */
  329. #define DIR_CONN_STATE_CONNECTING 1
  330. /** State for connection to directory server: sending HTTP request. */
  331. #define DIR_CONN_STATE_CLIENT_SENDING 2
  332. /** State for connection to directory server: reading HTTP response. */
  333. #define DIR_CONN_STATE_CLIENT_READING 3
  334. /** State for connection to directory server: happy and finished. */
  335. #define DIR_CONN_STATE_CLIENT_FINISHED 4
  336. /** State for connection at directory server: waiting for HTTP request. */
  337. #define DIR_CONN_STATE_SERVER_COMMAND_WAIT 5
  338. /** State for connection at directory server: sending HTTP response. */
  339. #define DIR_CONN_STATE_SERVER_WRITING 6
  340. #define DIR_CONN_STATE_MAX_ 6
  341. /** True iff the purpose of <b>conn</b> means that it's a server-side
  342. * directory connection. */
  343. #define DIR_CONN_IS_SERVER(conn) ((conn)->purpose == DIR_PURPOSE_SERVER)
  344. #define CONTROL_CONN_STATE_MIN_ 1
  345. /** State for a control connection: Authenticated and accepting v1 commands. */
  346. #define CONTROL_CONN_STATE_OPEN 1
  347. /** State for a control connection: Waiting for authentication; speaking
  348. * protocol v1. */
  349. #define CONTROL_CONN_STATE_NEEDAUTH 2
  350. #define CONTROL_CONN_STATE_MAX_ 2
  351. #define DIR_PURPOSE_MIN_ 4
  352. /** A connection to a directory server: set after a v2 rendezvous
  353. * descriptor is downloaded. */
  354. #define DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2 4
  355. /** A connection to a directory server: download one or more server
  356. * descriptors. */
  357. #define DIR_PURPOSE_FETCH_SERVERDESC 6
  358. /** A connection to a directory server: download one or more extra-info
  359. * documents. */
  360. #define DIR_PURPOSE_FETCH_EXTRAINFO 7
  361. /** A connection to a directory server: upload a server descriptor. */
  362. #define DIR_PURPOSE_UPLOAD_DIR 8
  363. /** A connection to a directory server: upload a v3 networkstatus vote. */
  364. #define DIR_PURPOSE_UPLOAD_VOTE 10
  365. /** A connection to a directory server: upload a v3 consensus signature */
  366. #define DIR_PURPOSE_UPLOAD_SIGNATURES 11
  367. /** A connection to a directory server: download one or more v3 networkstatus
  368. * votes. */
  369. #define DIR_PURPOSE_FETCH_STATUS_VOTE 12
  370. /** A connection to a directory server: download a v3 detached signatures
  371. * object for a consensus. */
  372. #define DIR_PURPOSE_FETCH_DETACHED_SIGNATURES 13
  373. /** A connection to a directory server: download a v3 networkstatus
  374. * consensus. */
  375. #define DIR_PURPOSE_FETCH_CONSENSUS 14
  376. /** A connection to a directory server: download one or more directory
  377. * authority certificates. */
  378. #define DIR_PURPOSE_FETCH_CERTIFICATE 15
  379. /** Purpose for connection at a directory server. */
  380. #define DIR_PURPOSE_SERVER 16
  381. /** A connection to a hidden service directory server: upload a v2 rendezvous
  382. * descriptor. */
  383. #define DIR_PURPOSE_UPLOAD_RENDDESC_V2 17
  384. /** A connection to a hidden service directory server: download a v2 rendezvous
  385. * descriptor. */
  386. #define DIR_PURPOSE_FETCH_RENDDESC_V2 18
  387. /** A connection to a directory server: download a microdescriptor. */
  388. #define DIR_PURPOSE_FETCH_MICRODESC 19
  389. /** A connection to a hidden service directory: upload a v3 descriptor. */
  390. #define DIR_PURPOSE_UPLOAD_HSDESC 20
  391. /** A connection to a hidden service directory: fetch a v3 descriptor. */
  392. #define DIR_PURPOSE_FETCH_HSDESC 21
  393. /** A connection to a directory server: set after a hidden service descriptor
  394. * is downloaded. */
  395. #define DIR_PURPOSE_HAS_FETCHED_HSDESC 22
  396. #define DIR_PURPOSE_MAX_ 22
  397. /** True iff <b>p</b> is a purpose corresponding to uploading
  398. * data to a directory server. */
  399. #define DIR_PURPOSE_IS_UPLOAD(p) \
  400. ((p)==DIR_PURPOSE_UPLOAD_DIR || \
  401. (p)==DIR_PURPOSE_UPLOAD_VOTE || \
  402. (p)==DIR_PURPOSE_UPLOAD_SIGNATURES || \
  403. (p)==DIR_PURPOSE_UPLOAD_RENDDESC_V2 || \
  404. (p)==DIR_PURPOSE_UPLOAD_HSDESC)
  405. #define EXIT_PURPOSE_MIN_ 1
  406. /** This exit stream wants to do an ordinary connect. */
  407. #define EXIT_PURPOSE_CONNECT 1
  408. /** This exit stream wants to do a resolve (either normal or reverse). */
  409. #define EXIT_PURPOSE_RESOLVE 2
  410. #define EXIT_PURPOSE_MAX_ 2
  411. /* !!!! If any connection purpose is ever over 31, we must grow the type
  412. * field in connection_t. */
  413. /** Circuit state: I'm the origin, still haven't done all my handshakes. */
  414. #define CIRCUIT_STATE_BUILDING 0
  415. /** Circuit state: Waiting to process the onionskin. */
  416. #define CIRCUIT_STATE_ONIONSKIN_PENDING 1
  417. /** Circuit state: I'd like to deliver a create, but my n_chan is still
  418. * connecting. */
  419. #define CIRCUIT_STATE_CHAN_WAIT 2
  420. /** Circuit state: the circuit is open but we don't want to actually use it
  421. * until we find out if a better guard will be available.
  422. */
  423. #define CIRCUIT_STATE_GUARD_WAIT 3
  424. /** Circuit state: onionskin(s) processed, ready to send/receive cells. */
  425. #define CIRCUIT_STATE_OPEN 4
  426. #define CIRCUIT_PURPOSE_MIN_ 1
  427. /* these circuits were initiated elsewhere */
  428. #define CIRCUIT_PURPOSE_OR_MIN_ 1
  429. /** OR-side circuit purpose: normal circuit, at OR. */
  430. #define CIRCUIT_PURPOSE_OR 1
  431. /** OR-side circuit purpose: At OR, from the service, waiting for intro from
  432. * clients. */
  433. #define CIRCUIT_PURPOSE_INTRO_POINT 2
  434. /** OR-side circuit purpose: At OR, from the client, waiting for the service.
  435. */
  436. #define CIRCUIT_PURPOSE_REND_POINT_WAITING 3
  437. /** OR-side circuit purpose: At OR, both circuits have this purpose. */
  438. #define CIRCUIT_PURPOSE_REND_ESTABLISHED 4
  439. #define CIRCUIT_PURPOSE_OR_MAX_ 4
  440. /* these circuits originate at this node */
  441. /* here's how circ client-side purposes work:
  442. * normal circuits are C_GENERAL.
  443. * circuits that are c_introducing are either on their way to
  444. * becoming open, or they are open and waiting for a
  445. * suitable rendcirc before they send the intro.
  446. * circuits that are c_introduce_ack_wait have sent the intro,
  447. * but haven't gotten a response yet.
  448. * circuits that are c_establish_rend are either on their way
  449. * to becoming open, or they are open and have sent the
  450. * establish_rendezvous cell but haven't received an ack.
  451. * circuits that are c_rend_ready are open and have received a
  452. * rend ack, but haven't heard from the service yet. if they have a
  453. * buildstate->pending_final_cpath then they're expecting a
  454. * cell from the service, else they're not.
  455. * circuits that are c_rend_ready_intro_acked are open, and
  456. * some intro circ has sent its intro and received an ack.
  457. * circuits that are c_rend_joined are open, have heard from
  458. * the service, and are talking to it.
  459. */
  460. /** Client-side circuit purpose: Normal circuit, with cpath. */
  461. #define CIRCUIT_PURPOSE_C_GENERAL 5
  462. #define CIRCUIT_PURPOSE_C_HS_MIN_ 6
  463. /** Client-side circuit purpose: at the client, connecting to intro point. */
  464. #define CIRCUIT_PURPOSE_C_INTRODUCING 6
  465. /** Client-side circuit purpose: at the client, sent INTRODUCE1 to intro point,
  466. * waiting for ACK/NAK. */
  467. #define CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT 7
  468. /** Client-side circuit purpose: at the client, introduced and acked, closing.
  469. */
  470. #define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED 8
  471. /** Client-side circuit purpose: at the client, waiting for ack. */
  472. #define CIRCUIT_PURPOSE_C_ESTABLISH_REND 9
  473. /** Client-side circuit purpose: at the client, waiting for the service. */
  474. #define CIRCUIT_PURPOSE_C_REND_READY 10
  475. /** Client-side circuit purpose: at the client, waiting for the service,
  476. * INTRODUCE has been acknowledged. */
  477. #define CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED 11
  478. /** Client-side circuit purpose: at the client, rendezvous established. */
  479. #define CIRCUIT_PURPOSE_C_REND_JOINED 12
  480. /** This circuit is used for getting hsdirs */
  481. #define CIRCUIT_PURPOSE_C_HSDIR_GET 13
  482. #define CIRCUIT_PURPOSE_C_HS_MAX_ 13
  483. /** This circuit is used for build time measurement only */
  484. #define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT 14
  485. #define CIRCUIT_PURPOSE_C_MAX_ 14
  486. #define CIRCUIT_PURPOSE_S_HS_MIN_ 15
  487. /** Hidden-service-side circuit purpose: at the service, waiting for
  488. * introductions. */
  489. #define CIRCUIT_PURPOSE_S_ESTABLISH_INTRO 15
  490. /** Hidden-service-side circuit purpose: at the service, successfully
  491. * established intro. */
  492. #define CIRCUIT_PURPOSE_S_INTRO 16
  493. /** Hidden-service-side circuit purpose: at the service, connecting to rend
  494. * point. */
  495. #define CIRCUIT_PURPOSE_S_CONNECT_REND 17
  496. /** Hidden-service-side circuit purpose: at the service, rendezvous
  497. * established. */
  498. #define CIRCUIT_PURPOSE_S_REND_JOINED 18
  499. /** This circuit is used for uploading hsdirs */
  500. #define CIRCUIT_PURPOSE_S_HSDIR_POST 19
  501. #define CIRCUIT_PURPOSE_S_HS_MAX_ 19
  502. /** A testing circuit; not meant to be used for actual traffic. */
  503. #define CIRCUIT_PURPOSE_TESTING 20
  504. /** A controller made this circuit and Tor should not use it. */
  505. #define CIRCUIT_PURPOSE_CONTROLLER 21
  506. /** This circuit is used for path bias probing only */
  507. #define CIRCUIT_PURPOSE_PATH_BIAS_TESTING 22
  508. /** This circuit is used for vanguards/restricted paths.
  509. *
  510. * This type of circuit is *only* created preemptively and never
  511. * on-demand. When an HS operation needs to take place (e.g. connect to an
  512. * intro point), these circuits are then cannibalized and repurposed to the
  513. * actual needed HS purpose. */
  514. #define CIRCUIT_PURPOSE_HS_VANGUARDS 23
  515. #define CIRCUIT_PURPOSE_MAX_ 23
  516. /** A catch-all for unrecognized purposes. Currently we don't expect
  517. * to make or see any circuits with this purpose. */
  518. #define CIRCUIT_PURPOSE_UNKNOWN 255
  519. /** True iff the circuit purpose <b>p</b> is for a circuit that
  520. * originated at this node. */
  521. #define CIRCUIT_PURPOSE_IS_ORIGIN(p) ((p)>CIRCUIT_PURPOSE_OR_MAX_)
  522. /** True iff the circuit purpose <b>p</b> is for a circuit that originated
  523. * here to serve as a client. (Hidden services don't count here.) */
  524. #define CIRCUIT_PURPOSE_IS_CLIENT(p) \
  525. ((p)> CIRCUIT_PURPOSE_OR_MAX_ && \
  526. (p)<=CIRCUIT_PURPOSE_C_MAX_)
  527. /** True iff the circuit_t <b>c</b> is actually an origin_circuit_t. */
  528. #define CIRCUIT_IS_ORIGIN(c) (CIRCUIT_PURPOSE_IS_ORIGIN((c)->purpose))
  529. /** True iff the circuit purpose <b>p</b> is for an established rendezvous
  530. * circuit. */
  531. #define CIRCUIT_PURPOSE_IS_ESTABLISHED_REND(p) \
  532. ((p) == CIRCUIT_PURPOSE_C_REND_JOINED || \
  533. (p) == CIRCUIT_PURPOSE_S_REND_JOINED)
  534. /** True iff the circuit_t c is actually an or_circuit_t */
  535. #define CIRCUIT_IS_ORCIRC(c) (((circuit_t *)(c))->magic == OR_CIRCUIT_MAGIC)
  536. /** True iff this circuit purpose should count towards the global
  537. * pending rate limit (set by MaxClientCircuitsPending). We count all
  538. * general purpose circuits, as well as the first step of client onion
  539. * service connections (HSDir gets). */
  540. #define CIRCUIT_PURPOSE_COUNTS_TOWARDS_MAXPENDING(p) \
  541. ((p) == CIRCUIT_PURPOSE_C_GENERAL || \
  542. (p) == CIRCUIT_PURPOSE_C_HSDIR_GET)
  543. /** How many circuits do we want simultaneously in-progress to handle
  544. * a given stream? */
  545. #define MIN_CIRCUITS_HANDLING_STREAM 2
  546. /* These RELAY_COMMAND constants define values for relay cell commands, and
  547. * must match those defined in tor-spec.txt. */
  548. #define RELAY_COMMAND_BEGIN 1
  549. #define RELAY_COMMAND_DATA 2
  550. #define RELAY_COMMAND_END 3
  551. #define RELAY_COMMAND_CONNECTED 4
  552. #define RELAY_COMMAND_SENDME 5
  553. #define RELAY_COMMAND_EXTEND 6
  554. #define RELAY_COMMAND_EXTENDED 7
  555. #define RELAY_COMMAND_TRUNCATE 8
  556. #define RELAY_COMMAND_TRUNCATED 9
  557. #define RELAY_COMMAND_DROP 10
  558. #define RELAY_COMMAND_RESOLVE 11
  559. #define RELAY_COMMAND_RESOLVED 12
  560. #define RELAY_COMMAND_BEGIN_DIR 13
  561. #define RELAY_COMMAND_EXTEND2 14
  562. #define RELAY_COMMAND_EXTENDED2 15
  563. #define RELAY_COMMAND_ESTABLISH_INTRO 32
  564. #define RELAY_COMMAND_ESTABLISH_RENDEZVOUS 33
  565. #define RELAY_COMMAND_INTRODUCE1 34
  566. #define RELAY_COMMAND_INTRODUCE2 35
  567. #define RELAY_COMMAND_RENDEZVOUS1 36
  568. #define RELAY_COMMAND_RENDEZVOUS2 37
  569. #define RELAY_COMMAND_INTRO_ESTABLISHED 38
  570. #define RELAY_COMMAND_RENDEZVOUS_ESTABLISHED 39
  571. #define RELAY_COMMAND_INTRODUCE_ACK 40
  572. /* Reasons why an OR connection is closed. */
  573. #define END_OR_CONN_REASON_DONE 1
  574. #define END_OR_CONN_REASON_REFUSED 2 /* connection refused */
  575. #define END_OR_CONN_REASON_OR_IDENTITY 3
  576. #define END_OR_CONN_REASON_CONNRESET 4 /* connection reset by peer */
  577. #define END_OR_CONN_REASON_TIMEOUT 5
  578. #define END_OR_CONN_REASON_NO_ROUTE 6 /* no route to host/net */
  579. #define END_OR_CONN_REASON_IO_ERROR 7 /* read/write error */
  580. #define END_OR_CONN_REASON_RESOURCE_LIMIT 8 /* sockets, buffers, etc */
  581. #define END_OR_CONN_REASON_PT_MISSING 9 /* PT failed or not available */
  582. #define END_OR_CONN_REASON_MISC 10
  583. /* Reasons why we (or a remote OR) might close a stream. See tor-spec.txt for
  584. * documentation of these. The values must match. */
  585. #define END_STREAM_REASON_MISC 1
  586. #define END_STREAM_REASON_RESOLVEFAILED 2
  587. #define END_STREAM_REASON_CONNECTREFUSED 3
  588. #define END_STREAM_REASON_EXITPOLICY 4
  589. #define END_STREAM_REASON_DESTROY 5
  590. #define END_STREAM_REASON_DONE 6
  591. #define END_STREAM_REASON_TIMEOUT 7
  592. #define END_STREAM_REASON_NOROUTE 8
  593. #define END_STREAM_REASON_HIBERNATING 9
  594. #define END_STREAM_REASON_INTERNAL 10
  595. #define END_STREAM_REASON_RESOURCELIMIT 11
  596. #define END_STREAM_REASON_CONNRESET 12
  597. #define END_STREAM_REASON_TORPROTOCOL 13
  598. #define END_STREAM_REASON_NOTDIRECTORY 14
  599. #define END_STREAM_REASON_ENTRYPOLICY 15
  600. /* These high-numbered end reasons are not part of the official spec,
  601. * and are not intended to be put in relay end cells. They are here
  602. * to be more informative when sending back socks replies to the
  603. * application. */
  604. /* XXXX 256 is no longer used; feel free to reuse it. */
  605. /** We were unable to attach the connection to any circuit at all. */
  606. /* XXXX the ways we use this one don't make a lot of sense. */
  607. #define END_STREAM_REASON_CANT_ATTACH 257
  608. /** We can't connect to any directories at all, so we killed our streams
  609. * before they can time out. */
  610. #define END_STREAM_REASON_NET_UNREACHABLE 258
  611. /** This is a SOCKS connection, and the client used (or misused) the SOCKS
  612. * protocol in a way we couldn't handle. */
  613. #define END_STREAM_REASON_SOCKSPROTOCOL 259
  614. /** This is a transparent proxy connection, but we can't extract the original
  615. * target address:port. */
  616. #define END_STREAM_REASON_CANT_FETCH_ORIG_DEST 260
  617. /** This is a connection on the NATD port, and the destination IP:Port was
  618. * either ill-formed or out-of-range. */
  619. #define END_STREAM_REASON_INVALID_NATD_DEST 261
  620. /** The target address is in a private network (like 127.0.0.1 or 10.0.0.1);
  621. * you don't want to do that over a randomly chosen exit */
  622. #define END_STREAM_REASON_PRIVATE_ADDR 262
  623. /** This is an HTTP tunnel connection and the client used or misused HTTP in a
  624. * way we can't handle.
  625. */
  626. #define END_STREAM_REASON_HTTPPROTOCOL 263
  627. /** Bitwise-and this value with endreason to mask out all flags. */
  628. #define END_STREAM_REASON_MASK 511
  629. /** Bitwise-or this with the argument to control_event_stream_status
  630. * to indicate that the reason came from an END cell. */
  631. #define END_STREAM_REASON_FLAG_REMOTE 512
  632. /** Bitwise-or this with the argument to control_event_stream_status
  633. * to indicate that we already sent a CLOSED stream event. */
  634. #define END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED 1024
  635. /** Bitwise-or this with endreason to indicate that we already sent
  636. * a socks reply, and no further reply needs to be sent from
  637. * connection_mark_unattached_ap(). */
  638. #define END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED 2048
  639. /** Reason for remapping an AP connection's address: we have a cached
  640. * answer. */
  641. #define REMAP_STREAM_SOURCE_CACHE 1
  642. /** Reason for remapping an AP connection's address: the exit node told us an
  643. * answer. */
  644. #define REMAP_STREAM_SOURCE_EXIT 2
  645. /* 'type' values to use in RESOLVED cells. Specified in tor-spec.txt. */
  646. #define RESOLVED_TYPE_HOSTNAME 0
  647. #define RESOLVED_TYPE_IPV4 4
  648. #define RESOLVED_TYPE_IPV6 6
  649. #define RESOLVED_TYPE_ERROR_TRANSIENT 0xF0
  650. #define RESOLVED_TYPE_ERROR 0xF1
  651. /* Negative reasons are internal: we never send them in a DESTROY or TRUNCATE
  652. * call; they only go to the controller for tracking */
  653. /* Closing introduction point that were opened in parallel. */
  654. #define END_CIRC_REASON_IP_NOW_REDUNDANT -4
  655. /** Our post-timeout circuit time measurement period expired.
  656. * We must give up now */
  657. #define END_CIRC_REASON_MEASUREMENT_EXPIRED -3
  658. /** We couldn't build a path for this circuit. */
  659. #define END_CIRC_REASON_NOPATH -2
  660. /** Catch-all "other" reason for closing origin circuits. */
  661. #define END_CIRC_AT_ORIGIN -1
  662. /* Reasons why we (or a remote OR) might close a circuit. See tor-spec.txt
  663. * section 5.4 for documentation of these. */
  664. #define END_CIRC_REASON_MIN_ 0
  665. #define END_CIRC_REASON_NONE 0
  666. #define END_CIRC_REASON_TORPROTOCOL 1
  667. #define END_CIRC_REASON_INTERNAL 2
  668. #define END_CIRC_REASON_REQUESTED 3
  669. #define END_CIRC_REASON_HIBERNATING 4
  670. #define END_CIRC_REASON_RESOURCELIMIT 5
  671. #define END_CIRC_REASON_CONNECTFAILED 6
  672. #define END_CIRC_REASON_OR_IDENTITY 7
  673. #define END_CIRC_REASON_CHANNEL_CLOSED 8
  674. #define END_CIRC_REASON_FINISHED 9
  675. #define END_CIRC_REASON_TIMEOUT 10
  676. #define END_CIRC_REASON_DESTROYED 11
  677. #define END_CIRC_REASON_NOSUCHSERVICE 12
  678. #define END_CIRC_REASON_MAX_ 12
  679. /** Bitwise-OR this with the argument to circuit_mark_for_close() or
  680. * control_event_circuit_status() to indicate that the reason was
  681. * passed through from a destroy or truncate cell. */
  682. #define END_CIRC_REASON_FLAG_REMOTE 512
  683. /** Length of 'y' portion of 'y.onion' URL. */
  684. #define REND_SERVICE_ID_LEN_BASE32 16
  685. /** Length of 'y.onion' including '.onion' URL. */
  686. #define REND_SERVICE_ADDRESS_LEN (16+1+5)
  687. /** Length of a binary-encoded rendezvous service ID. */
  688. #define REND_SERVICE_ID_LEN 10
  689. /** Time period for which a v2 descriptor will be valid. */
  690. #define REND_TIME_PERIOD_V2_DESC_VALIDITY (24*60*60)
  691. /** Time period within which two sets of v2 descriptors will be uploaded in
  692. * parallel. */
  693. #define REND_TIME_PERIOD_OVERLAPPING_V2_DESCS (60*60)
  694. /** Number of non-consecutive replicas (i.e. distributed somewhere
  695. * in the ring) for a descriptor. */
  696. #define REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS 2
  697. /** Number of consecutive replicas for a descriptor. */
  698. #define REND_NUMBER_OF_CONSECUTIVE_REPLICAS 3
  699. /** Length of v2 descriptor ID (32 base32 chars = 160 bits). */
  700. #define REND_DESC_ID_V2_LEN_BASE32 BASE32_DIGEST_LEN
  701. /** Length of the base32-encoded secret ID part of versioned hidden service
  702. * descriptors. */
  703. #define REND_SECRET_ID_PART_LEN_BASE32 BASE32_DIGEST_LEN
  704. /** Length of the base32-encoded hash of an introduction point's
  705. * identity key. */
  706. #define REND_INTRO_POINT_ID_LEN_BASE32 BASE32_DIGEST_LEN
  707. /** Length of the descriptor cookie that is used for client authorization
  708. * to hidden services. */
  709. #define REND_DESC_COOKIE_LEN 16
  710. /** Length of the base64-encoded descriptor cookie that is used for
  711. * exchanging client authorization between hidden service and client. */
  712. #define REND_DESC_COOKIE_LEN_BASE64 22
  713. /** Length of client identifier in encrypted introduction points for hidden
  714. * service authorization type 'basic'. */
  715. #define REND_BASIC_AUTH_CLIENT_ID_LEN 4
  716. /** Multiple of the number of clients to which the real number of clients
  717. * is padded with fake clients for hidden service authorization type
  718. * 'basic'. */
  719. #define REND_BASIC_AUTH_CLIENT_MULTIPLE 16
  720. /** Length of client entry consisting of client identifier and encrypted
  721. * session key for hidden service authorization type 'basic'. */
  722. #define REND_BASIC_AUTH_CLIENT_ENTRY_LEN (REND_BASIC_AUTH_CLIENT_ID_LEN \
  723. + CIPHER_KEY_LEN)
  724. /** Maximum size of v2 hidden service descriptors. */
  725. #define REND_DESC_MAX_SIZE (20 * 1024)
  726. /** Legal characters for use in authorized client names for a hidden
  727. * service. */
  728. #define REND_LEGAL_CLIENTNAME_CHARACTERS \
  729. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_"
  730. /** Maximum length of authorized client names for a hidden service. */
  731. #define REND_CLIENTNAME_MAX_LEN 16
  732. /** Length of the rendezvous cookie that is used to connect circuits at the
  733. * rendezvous point. */
  734. #define REND_COOKIE_LEN DIGEST_LEN
  735. /** Client authorization type that a hidden service performs. */
  736. typedef enum rend_auth_type_t {
  737. REND_NO_AUTH = 0,
  738. REND_BASIC_AUTH = 1,
  739. REND_STEALTH_AUTH = 2,
  740. } rend_auth_type_t;
  741. /** Client-side configuration of authorization for a hidden service. */
  742. typedef struct rend_service_authorization_t {
  743. uint8_t descriptor_cookie[REND_DESC_COOKIE_LEN];
  744. char onion_address[REND_SERVICE_ADDRESS_LEN+1];
  745. rend_auth_type_t auth_type;
  746. } rend_service_authorization_t;
  747. /** Client- and server-side data that is used for hidden service connection
  748. * establishment. Not all fields contain data depending on where this struct
  749. * is used. */
  750. typedef struct rend_data_t {
  751. /* Hidden service protocol version of this base object. */
  752. uint32_t version;
  753. /** List of HSDir fingerprints on which this request has been sent to. This
  754. * contains binary identity digest of the directory of size DIGEST_LEN. */
  755. smartlist_t *hsdirs_fp;
  756. /** Rendezvous cookie used by both, client and service. */
  757. char rend_cookie[REND_COOKIE_LEN];
  758. /** Number of streams associated with this rendezvous circuit. */
  759. int nr_streams;
  760. } rend_data_t;
  761. typedef struct rend_data_v2_t {
  762. /* Rendezvous base data. */
  763. rend_data_t base_;
  764. /** Onion address (without the .onion part) that a client requests. */
  765. char onion_address[REND_SERVICE_ID_LEN_BASE32+1];
  766. /** Descriptor ID for each replicas computed from the onion address. If
  767. * the onion address is empty, this array MUST be empty. We keep them so
  768. * we know when to purge our entry in the last hsdir request table. */
  769. char descriptor_id[REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS][DIGEST_LEN];
  770. /** (Optional) descriptor cookie that is used by a client. */
  771. char descriptor_cookie[REND_DESC_COOKIE_LEN];
  772. /** Authorization type for accessing a service used by a client. */
  773. rend_auth_type_t auth_type;
  774. /** Descriptor ID for a client request. The control port command HSFETCH
  775. * uses this. It's set if the descriptor query should only use this
  776. * descriptor ID. */
  777. char desc_id_fetch[DIGEST_LEN];
  778. /** Hash of the hidden service's PK used by a service. */
  779. char rend_pk_digest[DIGEST_LEN];
  780. } rend_data_v2_t;
  781. /* From a base rend_data_t object <b>d</d>, return the v2 object. */
  782. static inline
  783. rend_data_v2_t *TO_REND_DATA_V2(const rend_data_t *d)
  784. {
  785. tor_assert(d);
  786. tor_assert(d->version == 2);
  787. return DOWNCAST(rend_data_v2_t, d);
  788. }
  789. /* Stub because we can't include hs_ident.h. */
  790. struct hs_ident_edge_conn_t;
  791. struct hs_ident_dir_conn_t;
  792. struct hs_ident_circuit_t;
  793. typedef struct hsdir_index_t hsdir_index_t;
  794. /** Time interval for tracking replays of DH public keys received in
  795. * INTRODUCE2 cells. Used only to avoid launching multiple
  796. * simultaneous attempts to connect to the same rendezvous point. */
  797. #define REND_REPLAY_TIME_INTERVAL (5 * 60)
  798. /** Used to indicate which way a cell is going on a circuit. */
  799. typedef enum {
  800. CELL_DIRECTION_IN=1, /**< The cell is moving towards the origin. */
  801. CELL_DIRECTION_OUT=2, /**< The cell is moving away from the origin. */
  802. } cell_direction_t;
  803. /** Initial value for both sides of a circuit transmission window when the
  804. * circuit is initialized. Measured in cells. */
  805. #define CIRCWINDOW_START 1000
  806. #define CIRCWINDOW_START_MIN 100
  807. #define CIRCWINDOW_START_MAX 1000
  808. /** Amount to increment a circuit window when we get a circuit SENDME. */
  809. #define CIRCWINDOW_INCREMENT 100
  810. /** Initial value on both sides of a stream transmission window when the
  811. * stream is initialized. Measured in cells. */
  812. #define STREAMWINDOW_START 500
  813. #define STREAMWINDOW_START_MAX 500
  814. /** Amount to increment a stream window when we get a stream SENDME. */
  815. #define STREAMWINDOW_INCREMENT 50
  816. /** Maximum number of queued cells on a circuit for which we are the
  817. * midpoint before we give up and kill it. This must be >= circwindow
  818. * to avoid killing innocent circuits, and >= circwindow*2 to give
  819. * leaky-pipe a chance of working someday. The ORCIRC_MAX_MIDDLE_KILL_THRESH
  820. * ratio controls the margin of error between emitting a warning and
  821. * killing the circuit.
  822. */
  823. #define ORCIRC_MAX_MIDDLE_CELLS (CIRCWINDOW_START_MAX*2)
  824. /** Ratio of hard (circuit kill) to soft (warning) thresholds for the
  825. * ORCIRC_MAX_MIDDLE_CELLS tests.
  826. */
  827. #define ORCIRC_MAX_MIDDLE_KILL_THRESH (1.1f)
  828. /* Cell commands. These values are defined in tor-spec.txt. */
  829. #define CELL_PADDING 0
  830. #define CELL_CREATE 1
  831. #define CELL_CREATED 2
  832. #define CELL_RELAY 3
  833. #define CELL_DESTROY 4
  834. #define CELL_CREATE_FAST 5
  835. #define CELL_CREATED_FAST 6
  836. #define CELL_VERSIONS 7
  837. #define CELL_NETINFO 8
  838. #define CELL_RELAY_EARLY 9
  839. #define CELL_CREATE2 10
  840. #define CELL_CREATED2 11
  841. #define CELL_PADDING_NEGOTIATE 12
  842. #define CELL_VPADDING 128
  843. #define CELL_CERTS 129
  844. #define CELL_AUTH_CHALLENGE 130
  845. #define CELL_AUTHENTICATE 131
  846. #define CELL_AUTHORIZE 132
  847. #define CELL_COMMAND_MAX_ 132
  848. /** How long to test reachability before complaining to the user. */
  849. #define TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT (20*60)
  850. /** Legal characters in a nickname. */
  851. #define LEGAL_NICKNAME_CHARACTERS \
  852. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  853. /** Name to use in client TLS certificates if no nickname is given. Once
  854. * Tor 0.1.2.x is obsolete, we can remove this. */
  855. #define DEFAULT_CLIENT_NICKNAME "client"
  856. /** Name chosen by routers that don't configure nicknames */
  857. #define UNNAMED_ROUTER_NICKNAME "Unnamed"
  858. /** Number of bytes in a SOCKS4 header. */
  859. #define SOCKS4_NETWORK_LEN 8
  860. /*
  861. * Relay payload:
  862. * Relay command [1 byte]
  863. * Recognized [2 bytes]
  864. * Stream ID [2 bytes]
  865. * Partial SHA-1 [4 bytes]
  866. * Length [2 bytes]
  867. * Relay payload [498 bytes]
  868. */
  869. /** Number of bytes in a cell, minus cell header. */
  870. #define CELL_PAYLOAD_SIZE 509
  871. /** Number of bytes in a cell transmitted over the network, in the longest
  872. * form */
  873. #define CELL_MAX_NETWORK_SIZE 514
  874. /** Maximum length of a header on a variable-length cell. */
  875. #define VAR_CELL_MAX_HEADER_SIZE 7
  876. static int get_cell_network_size(int wide_circ_ids);
  877. static inline int get_cell_network_size(int wide_circ_ids)
  878. {
  879. return wide_circ_ids ? CELL_MAX_NETWORK_SIZE : CELL_MAX_NETWORK_SIZE - 2;
  880. }
  881. static int get_var_cell_header_size(int wide_circ_ids);
  882. static inline int get_var_cell_header_size(int wide_circ_ids)
  883. {
  884. return wide_circ_ids ? VAR_CELL_MAX_HEADER_SIZE :
  885. VAR_CELL_MAX_HEADER_SIZE - 2;
  886. }
  887. static int get_circ_id_size(int wide_circ_ids);
  888. static inline int get_circ_id_size(int wide_circ_ids)
  889. {
  890. return wide_circ_ids ? 4 : 2;
  891. }
  892. /** Number of bytes in a relay cell's header (not including general cell
  893. * header). */
  894. #define RELAY_HEADER_SIZE (1+2+2+4+2)
  895. /** Largest number of bytes that can fit in a relay cell payload. */
  896. #define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE)
  897. /** Identifies a circuit on an or_connection */
  898. typedef uint32_t circid_t;
  899. /** Identifies a stream on a circuit */
  900. typedef uint16_t streamid_t;
  901. /* channel_t typedef; struct channel_s is in channel.h */
  902. typedef struct channel_s channel_t;
  903. /* channel_listener_t typedef; struct channel_listener_s is in channel.h */
  904. typedef struct channel_listener_s channel_listener_t;
  905. /* channel states for channel_t */
  906. typedef enum {
  907. /*
  908. * Closed state - channel is inactive
  909. *
  910. * Permitted transitions from:
  911. * - CHANNEL_STATE_CLOSING
  912. * Permitted transitions to:
  913. * - CHANNEL_STATE_OPENING
  914. */
  915. CHANNEL_STATE_CLOSED = 0,
  916. /*
  917. * Opening state - channel is trying to connect
  918. *
  919. * Permitted transitions from:
  920. * - CHANNEL_STATE_CLOSED
  921. * Permitted transitions to:
  922. * - CHANNEL_STATE_CLOSING
  923. * - CHANNEL_STATE_ERROR
  924. * - CHANNEL_STATE_OPEN
  925. */
  926. CHANNEL_STATE_OPENING,
  927. /*
  928. * Open state - channel is active and ready for use
  929. *
  930. * Permitted transitions from:
  931. * - CHANNEL_STATE_MAINT
  932. * - CHANNEL_STATE_OPENING
  933. * Permitted transitions to:
  934. * - CHANNEL_STATE_CLOSING
  935. * - CHANNEL_STATE_ERROR
  936. * - CHANNEL_STATE_MAINT
  937. */
  938. CHANNEL_STATE_OPEN,
  939. /*
  940. * Maintenance state - channel is temporarily offline for subclass specific
  941. * maintenance activities such as TLS renegotiation.
  942. *
  943. * Permitted transitions from:
  944. * - CHANNEL_STATE_OPEN
  945. * Permitted transitions to:
  946. * - CHANNEL_STATE_CLOSING
  947. * - CHANNEL_STATE_ERROR
  948. * - CHANNEL_STATE_OPEN
  949. */
  950. CHANNEL_STATE_MAINT,
  951. /*
  952. * Closing state - channel is shutting down
  953. *
  954. * Permitted transitions from:
  955. * - CHANNEL_STATE_MAINT
  956. * - CHANNEL_STATE_OPEN
  957. * Permitted transitions to:
  958. * - CHANNEL_STATE_CLOSED,
  959. * - CHANNEL_STATE_ERROR
  960. */
  961. CHANNEL_STATE_CLOSING,
  962. /*
  963. * Error state - channel has experienced a permanent error
  964. *
  965. * Permitted transitions from:
  966. * - CHANNEL_STATE_CLOSING
  967. * - CHANNEL_STATE_MAINT
  968. * - CHANNEL_STATE_OPENING
  969. * - CHANNEL_STATE_OPEN
  970. * Permitted transitions to:
  971. * - None
  972. */
  973. CHANNEL_STATE_ERROR,
  974. /*
  975. * Placeholder for maximum state value
  976. */
  977. CHANNEL_STATE_LAST
  978. } channel_state_t;
  979. /* channel listener states for channel_listener_t */
  980. typedef enum {
  981. /*
  982. * Closed state - channel listener is inactive
  983. *
  984. * Permitted transitions from:
  985. * - CHANNEL_LISTENER_STATE_CLOSING
  986. * Permitted transitions to:
  987. * - CHANNEL_LISTENER_STATE_LISTENING
  988. */
  989. CHANNEL_LISTENER_STATE_CLOSED = 0,
  990. /*
  991. * Listening state - channel listener is listening for incoming
  992. * connections
  993. *
  994. * Permitted transitions from:
  995. * - CHANNEL_LISTENER_STATE_CLOSED
  996. * Permitted transitions to:
  997. * - CHANNEL_LISTENER_STATE_CLOSING
  998. * - CHANNEL_LISTENER_STATE_ERROR
  999. */
  1000. CHANNEL_LISTENER_STATE_LISTENING,
  1001. /*
  1002. * Closing state - channel listener is shutting down
  1003. *
  1004. * Permitted transitions from:
  1005. * - CHANNEL_LISTENER_STATE_LISTENING
  1006. * Permitted transitions to:
  1007. * - CHANNEL_LISTENER_STATE_CLOSED,
  1008. * - CHANNEL_LISTENER_STATE_ERROR
  1009. */
  1010. CHANNEL_LISTENER_STATE_CLOSING,
  1011. /*
  1012. * Error state - channel listener has experienced a permanent error
  1013. *
  1014. * Permitted transitions from:
  1015. * - CHANNEL_STATE_CLOSING
  1016. * - CHANNEL_STATE_LISTENING
  1017. * Permitted transitions to:
  1018. * - None
  1019. */
  1020. CHANNEL_LISTENER_STATE_ERROR,
  1021. /*
  1022. * Placeholder for maximum state value
  1023. */
  1024. CHANNEL_LISTENER_STATE_LAST
  1025. } channel_listener_state_t;
  1026. /* TLS channel stuff */
  1027. typedef struct channel_tls_s channel_tls_t;
  1028. /* circuitmux_t typedef; struct circuitmux_s is in circuitmux.h */
  1029. typedef struct circuitmux_s circuitmux_t;
  1030. typedef struct cell_t cell_t;
  1031. typedef struct var_cell_t var_cell_t;
  1032. typedef struct packed_cell_t packed_cell_t;
  1033. typedef struct cell_queue_t cell_queue_t;
  1034. typedef struct destroy_cell_t destroy_cell_t;
  1035. typedef struct destroy_cell_queue_t destroy_cell_queue_t;
  1036. /** A parsed Extended ORPort message. */
  1037. typedef struct ext_or_cmd_t {
  1038. uint16_t cmd; /** Command type */
  1039. uint16_t len; /** Body length */
  1040. char body[FLEXIBLE_ARRAY_MEMBER]; /** Message body */
  1041. } ext_or_cmd_t;
  1042. /** Beginning of a RELAY cell payload. */
  1043. typedef struct {
  1044. uint8_t command; /**< The end-to-end relay command. */
  1045. uint16_t recognized; /**< Used to tell whether cell is for us. */
  1046. streamid_t stream_id; /**< Which stream is this cell associated with? */
  1047. char integrity[4]; /**< Used to tell whether cell is corrupted. */
  1048. uint16_t length; /**< How long is the payload body? */
  1049. } relay_header_t;
  1050. typedef struct socks_request_t socks_request_t;
  1051. typedef struct entry_port_cfg_t entry_port_cfg_t;
  1052. typedef struct server_port_cfg_t server_port_cfg_t;
  1053. /* Values for connection_t.magic: used to make sure that downcasts (casts from
  1054. * connection_t to foo_connection_t) are safe. */
  1055. #define BASE_CONNECTION_MAGIC 0x7C3C304Eu
  1056. #define OR_CONNECTION_MAGIC 0x7D31FF03u
  1057. #define EDGE_CONNECTION_MAGIC 0xF0374013u
  1058. #define ENTRY_CONNECTION_MAGIC 0xbb4a5703
  1059. #define DIR_CONNECTION_MAGIC 0x9988ffeeu
  1060. #define CONTROL_CONNECTION_MAGIC 0x8abc765du
  1061. #define LISTENER_CONNECTION_MAGIC 0x1a1ac741u
  1062. /** Minimum length of the random part of an AUTH_CHALLENGE cell. */
  1063. #define OR_AUTH_CHALLENGE_LEN 32
  1064. /**
  1065. * @name Certificate types for CERTS cells.
  1066. *
  1067. * These values are defined by the protocol, and affect how an X509
  1068. * certificate in a CERTS cell is interpreted and used.
  1069. *
  1070. * @{ */
  1071. /** A certificate that authenticates a TLS link key. The subject key
  1072. * must match the key used in the TLS handshake; it must be signed by
  1073. * the identity key. */
  1074. #define OR_CERT_TYPE_TLS_LINK 1
  1075. /** A self-signed identity certificate. The subject key must be a
  1076. * 1024-bit RSA key. */
  1077. #define OR_CERT_TYPE_ID_1024 2
  1078. /** A certificate that authenticates a key used in an AUTHENTICATE cell
  1079. * in the v3 handshake. The subject key must be a 1024-bit RSA key; it
  1080. * must be signed by the identity key */
  1081. #define OR_CERT_TYPE_AUTH_1024 3
  1082. /* DOCDOC */
  1083. #define OR_CERT_TYPE_RSA_ED_CROSSCERT 7
  1084. /**@}*/
  1085. /** The first supported type of AUTHENTICATE cell. It contains
  1086. * a bunch of structures signed with an RSA1024 key. The signed
  1087. * structures include a HMAC using negotiated TLS secrets, and a digest
  1088. * of all cells sent or received before the AUTHENTICATE cell (including
  1089. * the random server-generated AUTH_CHALLENGE cell).
  1090. */
  1091. #define AUTHTYPE_RSA_SHA256_TLSSECRET 1
  1092. /** As AUTHTYPE_RSA_SHA256_TLSSECRET, but instead of using the
  1093. * negotiated TLS secrets, uses exported keying material from the TLS
  1094. * session as described in RFC 5705.
  1095. *
  1096. * Not used by today's tors, since everything that supports this
  1097. * also supports ED25519_SHA256_5705, which is better.
  1098. **/
  1099. #define AUTHTYPE_RSA_SHA256_RFC5705 2
  1100. /** As AUTHTYPE_RSA_SHA256_RFC5705, but uses an Ed25519 identity key to
  1101. * authenticate. */
  1102. #define AUTHTYPE_ED25519_SHA256_RFC5705 3
  1103. /*
  1104. * NOTE: authchallenge_type_is_better() relies on these AUTHTYPE codes
  1105. * being sorted in order of preference. If we someday add one with
  1106. * a higher numerical value that we don't like as much, we should revise
  1107. * authchallenge_type_is_better().
  1108. */
  1109. /** The length of the part of the AUTHENTICATE cell body that the client and
  1110. * server can generate independently (when using RSA_SHA256_TLSSECRET). It
  1111. * contains everything except the client's timestamp, the client's randomly
  1112. * generated nonce, and the signature. */
  1113. #define V3_AUTH_FIXED_PART_LEN (8+(32*6))
  1114. /** The length of the part of the AUTHENTICATE cell body that the client
  1115. * signs. */
  1116. #define V3_AUTH_BODY_LEN (V3_AUTH_FIXED_PART_LEN + 8 + 16)
  1117. typedef struct or_handshake_certs_t or_handshake_certs_t;
  1118. typedef struct or_handshake_state_t or_handshake_state_t;
  1119. /** Length of Extended ORPort connection identifier. */
  1120. #define EXT_OR_CONN_ID_LEN DIGEST_LEN /* 20 */
  1121. /*
  1122. * OR_CONN_HIGHWATER and OR_CONN_LOWWATER moved from connection_or.c so
  1123. * channeltls.c can see them too.
  1124. */
  1125. /** When adding cells to an OR connection's outbuf, keep adding until the
  1126. * outbuf is at least this long, or we run out of cells. */
  1127. #define OR_CONN_HIGHWATER (32*1024)
  1128. /** Add cells to an OR connection's outbuf whenever the outbuf's data length
  1129. * drops below this size. */
  1130. #define OR_CONN_LOWWATER (16*1024)
  1131. typedef struct connection_t connection_t;
  1132. typedef struct control_connection_t control_connection_t;
  1133. typedef struct dir_connection_t dir_connection_t;
  1134. typedef struct edge_connection_t edge_connection_t;
  1135. typedef struct entry_connection_t entry_connection_t;
  1136. typedef struct listener_connection_t listener_connection_t;
  1137. typedef struct or_connection_t or_connection_t;
  1138. /** Cast a connection_t subtype pointer to a connection_t **/
  1139. #define TO_CONN(c) (&(((c)->base_)))
  1140. /** Cast a entry_connection_t subtype pointer to a connection_t **/
  1141. #define ENTRY_TO_CONN(c) (TO_CONN(ENTRY_TO_EDGE_CONN(c)))
  1142. /** What action type does an address policy indicate: accept or reject? */
  1143. typedef enum {
  1144. ADDR_POLICY_ACCEPT=1,
  1145. ADDR_POLICY_REJECT=2,
  1146. } addr_policy_action_t;
  1147. #define addr_policy_action_bitfield_t ENUM_BF(addr_policy_action_t)
  1148. /** A reference-counted address policy rule. */
  1149. typedef struct addr_policy_t {
  1150. int refcnt; /**< Reference count */
  1151. /** What to do when the policy matches.*/
  1152. addr_policy_action_bitfield_t policy_type:2;
  1153. unsigned int is_private:1; /**< True iff this is the pseudo-address,
  1154. * "private". */
  1155. unsigned int is_canonical:1; /**< True iff this policy is the canonical
  1156. * copy (stored in a hash table to avoid
  1157. * duplication of common policies) */
  1158. maskbits_t maskbits; /**< Accept/reject all addresses <b>a</b> such that the
  1159. * first <b>maskbits</b> bits of <b>a</b> match
  1160. * <b>addr</b>. */
  1161. /** Base address to accept or reject.
  1162. *
  1163. * Note that wildcards are treated
  1164. * differntly depending on address family. An AF_UNSPEC address means
  1165. * "All addresses, IPv4 or IPv6." An AF_INET address with maskbits==0 means
  1166. * "All IPv4 addresses" and an AF_INET6 address with maskbits == 0 means
  1167. * "All IPv6 addresses".
  1168. **/
  1169. tor_addr_t addr;
  1170. uint16_t prt_min; /**< Lowest port number to accept/reject. */
  1171. uint16_t prt_max; /**< Highest port number to accept/reject. */
  1172. } addr_policy_t;
  1173. typedef struct cached_dir_t cached_dir_t;
  1174. /** Enum used to remember where a signed_descriptor_t is stored and how to
  1175. * manage the memory for signed_descriptor_body. */
  1176. typedef enum {
  1177. /** The descriptor isn't stored on disk at all: the copy in memory is
  1178. * canonical; the saved_offset field is meaningless. */
  1179. SAVED_NOWHERE=0,
  1180. /** The descriptor is stored in the cached_routers file: the
  1181. * signed_descriptor_body is meaningless; the signed_descriptor_len and
  1182. * saved_offset are used to index into the mmaped cache file. */
  1183. SAVED_IN_CACHE,
  1184. /** The descriptor is stored in the cached_routers.new file: the
  1185. * signed_descriptor_body and saved_offset fields are both set. */
  1186. /* FFFF (We could also mmap the file and grow the mmap as needed, or
  1187. * lazy-load the descriptor text by using seek and read. We don't, for
  1188. * now.)
  1189. */
  1190. SAVED_IN_JOURNAL
  1191. } saved_location_t;
  1192. #define saved_location_bitfield_t ENUM_BF(saved_location_t)
  1193. /** Enumeration: what directory object is being downloaded?
  1194. * This determines which schedule is selected to perform the download. */
  1195. typedef enum {
  1196. DL_SCHED_GENERIC = 0,
  1197. DL_SCHED_CONSENSUS = 1,
  1198. DL_SCHED_BRIDGE = 2,
  1199. } download_schedule_t;
  1200. #define download_schedule_bitfield_t ENUM_BF(download_schedule_t)
  1201. /** Enumeration: is the download schedule for downloading from an authority,
  1202. * or from any available directory mirror?
  1203. * During bootstrap, "any" means a fallback (or an authority, if there
  1204. * are no fallbacks).
  1205. * When we have a valid consensus, "any" means any directory server. */
  1206. typedef enum {
  1207. DL_WANT_ANY_DIRSERVER = 0,
  1208. DL_WANT_AUTHORITY = 1,
  1209. } download_want_authority_t;
  1210. #define download_want_authority_bitfield_t \
  1211. ENUM_BF(download_want_authority_t)
  1212. /** Enumeration: do we want to increment the schedule position each time a
  1213. * connection is attempted (these attempts can be concurrent), or do we want
  1214. * to increment the schedule position after a connection fails? */
  1215. typedef enum {
  1216. DL_SCHED_INCREMENT_FAILURE = 0,
  1217. DL_SCHED_INCREMENT_ATTEMPT = 1,
  1218. } download_schedule_increment_t;
  1219. #define download_schedule_increment_bitfield_t \
  1220. ENUM_BF(download_schedule_increment_t)
  1221. typedef struct download_status_t download_status_t;
  1222. /** If n_download_failures is this high, the download can never happen. */
  1223. #define IMPOSSIBLE_TO_DOWNLOAD 255
  1224. /** The max size we expect router descriptor annotations we create to
  1225. * be. We'll accept larger ones if we see them on disk, but we won't
  1226. * create any that are larger than this. */
  1227. #define ROUTER_ANNOTATION_BUF_LEN 256
  1228. typedef struct signed_descriptor_t signed_descriptor_t;
  1229. /** A signed integer representing a country code. */
  1230. typedef int16_t country_t;
  1231. /** Flags used to summarize the declared protocol versions of a relay,
  1232. * so we don't need to parse them again and again. */
  1233. typedef struct protover_summary_flags_t {
  1234. /** True iff we have a proto line for this router, or a versions line
  1235. * from which we could infer the protocols. */
  1236. unsigned int protocols_known:1;
  1237. /** True iff this router has a version or protocol list that allows it to
  1238. * accept EXTEND2 cells. This requires Relay=2. */
  1239. unsigned int supports_extend2_cells:1;
  1240. /** True iff this router has a protocol list that allows it to negotiate
  1241. * ed25519 identity keys on a link handshake with us. This
  1242. * requires LinkAuth=3. */
  1243. unsigned int supports_ed25519_link_handshake_compat:1;
  1244. /** True iff this router has a protocol list that allows it to negotiate
  1245. * ed25519 identity keys on a link handshake, at all. This requires some
  1246. * LinkAuth=X for X >= 3. */
  1247. unsigned int supports_ed25519_link_handshake_any:1;
  1248. /** True iff this router has a protocol list that allows it to be an
  1249. * introduction point supporting ed25519 authentication key which is part of
  1250. * the v3 protocol detailed in proposal 224. This requires HSIntro=4. */
  1251. unsigned int supports_ed25519_hs_intro : 1;
  1252. /** True iff this router has a protocol list that allows it to be an hidden
  1253. * service directory supporting version 3 as seen in proposal 224. This
  1254. * requires HSDir=2. */
  1255. unsigned int supports_v3_hsdir : 1;
  1256. /** True iff this router has a protocol list that allows it to be an hidden
  1257. * service rendezvous point supporting version 3 as seen in proposal 224.
  1258. * This requires HSRend=2. */
  1259. unsigned int supports_v3_rendezvous_point: 1;
  1260. } protover_summary_flags_t;
  1261. typedef struct routerinfo_t routerinfo_t;
  1262. typedef struct extrainfo_t extrainfo_t;
  1263. typedef struct routerstatus_t routerstatus_t;
  1264. /** A single entry in a parsed policy summary, describing a range of ports. */
  1265. typedef struct short_policy_entry_t {
  1266. uint16_t min_port, max_port;
  1267. } short_policy_entry_t;
  1268. /** A short_poliy_t is the parsed version of a policy summary. */
  1269. typedef struct short_policy_t {
  1270. /** True if the members of 'entries' are port ranges to accept; false if
  1271. * they are port ranges to reject */
  1272. unsigned int is_accept : 1;
  1273. /** The actual number of values in 'entries'. */
  1274. unsigned int n_entries : 31;
  1275. /** An array of 0 or more short_policy_entry_t values, each describing a
  1276. * range of ports that this policy accepts or rejects (depending on the
  1277. * value of is_accept).
  1278. */
  1279. short_policy_entry_t entries[FLEXIBLE_ARRAY_MEMBER];
  1280. } short_policy_t;
  1281. typedef struct microdesc_t microdesc_t;
  1282. typedef struct node_t node_t;
  1283. typedef struct vote_microdesc_hash_t vote_microdesc_hash_t;
  1284. typedef struct vote_routerstatus_t vote_routerstatus_t;
  1285. typedef struct document_signature_t document_signature_t;
  1286. typedef struct networkstatus_voter_info_t networkstatus_voter_info_t;
  1287. typedef struct networkstatus_sr_info_t networkstatus_sr_info_t;
  1288. /** Enumerates the possible seriousness values of a networkstatus document. */
  1289. typedef enum {
  1290. NS_TYPE_VOTE,
  1291. NS_TYPE_CONSENSUS,
  1292. NS_TYPE_OPINION,
  1293. } networkstatus_type_t;
  1294. /** Enumerates recognized flavors of a consensus networkstatus document. All
  1295. * flavors of a consensus are generated from the same set of votes, but they
  1296. * present different types information to different versions of Tor. */
  1297. typedef enum {
  1298. FLAV_NS = 0,
  1299. FLAV_MICRODESC = 1,
  1300. } consensus_flavor_t;
  1301. /** How many different consensus flavors are there? */
  1302. #define N_CONSENSUS_FLAVORS ((int)(FLAV_MICRODESC)+1)
  1303. typedef struct networkstatus_t networkstatus_t;
  1304. typedef struct ns_detached_signatures_t ns_detached_signatures_t;
  1305. /** Allowable types of desc_store_t. */
  1306. typedef enum store_type_t {
  1307. ROUTER_STORE = 0,
  1308. EXTRAINFO_STORE = 1
  1309. } store_type_t;
  1310. typedef struct desc_store_t desc_store_t;
  1311. typedef struct routerlist_t routerlist_t;
  1312. typedef struct extend_info_t extend_info_t;
  1313. typedef struct authority_cert_t authority_cert_t;
  1314. /** Bitfield enum type listing types of information that directory authorities
  1315. * can be authoritative about, and that directory caches may or may not cache.
  1316. *
  1317. * Note that the granularity here is based on authority granularity and on
  1318. * cache capabilities. Thus, one particular bit may correspond in practice to
  1319. * a few types of directory info, so long as every authority that pronounces
  1320. * officially about one of the types prounounces officially about all of them,
  1321. * and so long as every cache that caches one of them caches all of them.
  1322. */
  1323. typedef enum {
  1324. NO_DIRINFO = 0,
  1325. /** Serves/signs v3 directory information: votes, consensuses, certs */
  1326. V3_DIRINFO = 1 << 2,
  1327. /** Serves bridge descriptors. */
  1328. BRIDGE_DIRINFO = 1 << 4,
  1329. /** Serves extrainfo documents. */
  1330. EXTRAINFO_DIRINFO=1 << 5,
  1331. /** Serves microdescriptors. */
  1332. MICRODESC_DIRINFO=1 << 6,
  1333. } dirinfo_type_t;
  1334. #define ALL_DIRINFO ((dirinfo_type_t)((1<<7)-1))
  1335. #define CRYPT_PATH_MAGIC 0x70127012u
  1336. struct fast_handshake_state_t;
  1337. struct ntor_handshake_state_t;
  1338. #define ONION_HANDSHAKE_TYPE_TAP 0x0000
  1339. #define ONION_HANDSHAKE_TYPE_FAST 0x0001
  1340. #define ONION_HANDSHAKE_TYPE_NTOR 0x0002
  1341. #define MAX_ONION_HANDSHAKE_TYPE 0x0002
  1342. typedef struct {
  1343. uint16_t tag;
  1344. union {
  1345. struct fast_handshake_state_t *fast;
  1346. crypto_dh_t *tap;
  1347. struct ntor_handshake_state_t *ntor;
  1348. } u;
  1349. } onion_handshake_state_t;
  1350. typedef struct relay_crypto_t relay_crypto_t;
  1351. typedef struct crypt_path_t crypt_path_t;
  1352. typedef struct crypt_path_reference_t crypt_path_reference_t;
  1353. #define CPATH_KEY_MATERIAL_LEN (20*2+16*2)
  1354. #define DH_KEY_LEN DH_BYTES
  1355. typedef struct cpath_build_state_t cpath_build_state_t;
  1356. /** "magic" value for an origin_circuit_t */
  1357. #define ORIGIN_CIRCUIT_MAGIC 0x35315243u
  1358. /** "magic" value for an or_circuit_t */
  1359. #define OR_CIRCUIT_MAGIC 0x98ABC04Fu
  1360. /** "magic" value for a circuit that would have been freed by circuit_free,
  1361. * but which we're keeping around until a cpuworker reply arrives. See
  1362. * circuit_free() for more documentation. */
  1363. #define DEAD_CIRCUIT_MAGIC 0xdeadc14c
  1364. struct create_cell_t;
  1365. /** Entry in the cell stats list of a circuit; used only if CELL_STATS
  1366. * events are enabled. */
  1367. typedef struct testing_cell_stats_entry_t {
  1368. uint8_t command; /**< cell command number. */
  1369. /** Waiting time in centiseconds if this event is for a removed cell,
  1370. * or 0 if this event is for adding a cell to the queue. 22 bits can
  1371. * store more than 11 hours, enough to assume that a circuit with this
  1372. * delay would long have been closed. */
  1373. unsigned int waiting_time:22;
  1374. unsigned int removed:1; /**< 0 for added to, 1 for removed from queue. */
  1375. unsigned int exitward:1; /**< 0 for app-ward, 1 for exit-ward. */
  1376. } testing_cell_stats_entry_t;
  1377. typedef struct circuit_t circuit_t;
  1378. typedef struct origin_circuit_t origin_circuit_t;
  1379. typedef struct or_circuit_t or_circuit_t;
  1380. /** Largest number of relay_early cells that we can send on a given
  1381. * circuit. */
  1382. #define MAX_RELAY_EARLY_CELLS_PER_CIRCUIT 8
  1383. /**
  1384. * Describes the circuit building process in simplified terms based
  1385. * on the path bias accounting state for a circuit.
  1386. *
  1387. * NOTE: These state values are enumerated in the order for which we
  1388. * expect circuits to transition through them. If you add states,
  1389. * you need to preserve this overall ordering. The various pathbias
  1390. * state transition and accounting functions (pathbias_mark_* and
  1391. * pathbias_count_*) contain ordinal comparisons to enforce proper
  1392. * state transitions for corrections.
  1393. *
  1394. * This state machine and the associated logic was created to prevent
  1395. * miscounting due to unknown cases of circuit reuse. See also tickets
  1396. * #6475 and #7802.
  1397. */
  1398. typedef enum {
  1399. /** This circuit is "new". It has not yet completed a first hop
  1400. * or been counted by the path bias code. */
  1401. PATH_STATE_NEW_CIRC = 0,
  1402. /** This circuit has completed one/two hops, and has been counted by
  1403. * the path bias logic. */
  1404. PATH_STATE_BUILD_ATTEMPTED = 1,
  1405. /** This circuit has been completely built */
  1406. PATH_STATE_BUILD_SUCCEEDED = 2,
  1407. /** Did we try to attach any SOCKS streams or hidserv introductions to
  1408. * this circuit?
  1409. *
  1410. * Note: If we ever implement end-to-end stream timing through test
  1411. * stream probes (#5707), we must *not* set this for those probes
  1412. * (or any other automatic streams) because the adversary could
  1413. * just tag at a later point.
  1414. */
  1415. PATH_STATE_USE_ATTEMPTED = 3,
  1416. /** Did any SOCKS streams or hidserv introductions actually succeed on
  1417. * this circuit?
  1418. *
  1419. * If any streams detatch/fail from this circuit, the code transitions
  1420. * the circuit back to PATH_STATE_USE_ATTEMPTED to ensure we probe. See
  1421. * pathbias_mark_use_rollback() for that.
  1422. */
  1423. PATH_STATE_USE_SUCCEEDED = 4,
  1424. /**
  1425. * This is a special state to indicate that we got a corrupted
  1426. * relay cell on a circuit and we don't intend to probe it.
  1427. */
  1428. PATH_STATE_USE_FAILED = 5,
  1429. /**
  1430. * This is a special state to indicate that we already counted
  1431. * the circuit. Used to guard against potential state machine
  1432. * violations.
  1433. */
  1434. PATH_STATE_ALREADY_COUNTED = 6,
  1435. } path_state_t;
  1436. #define path_state_bitfield_t ENUM_BF(path_state_t)
  1437. #if REND_COOKIE_LEN != DIGEST_LEN
  1438. #error "The REND_TOKEN_LEN macro assumes REND_COOKIE_LEN == DIGEST_LEN"
  1439. #endif
  1440. #define REND_TOKEN_LEN DIGEST_LEN
  1441. /** Convert a circuit subtype to a circuit_t. */
  1442. #define TO_CIRCUIT(x) (&((x)->base_))
  1443. /* limits for TCP send and recv buffer size used for constrained sockets */
  1444. #define MIN_CONSTRAINED_TCP_BUFFER 2048
  1445. #define MAX_CONSTRAINED_TCP_BUFFER 262144 /* 256k */
  1446. /** @name Isolation flags
  1447. Ways to isolate client streams
  1448. @{
  1449. */
  1450. /** Isolate based on destination port */
  1451. #define ISO_DESTPORT (1u<<0)
  1452. /** Isolate based on destination address */
  1453. #define ISO_DESTADDR (1u<<1)
  1454. /** Isolate based on SOCKS authentication */
  1455. #define ISO_SOCKSAUTH (1u<<2)
  1456. /** Isolate based on client protocol choice */
  1457. #define ISO_CLIENTPROTO (1u<<3)
  1458. /** Isolate based on client address */
  1459. #define ISO_CLIENTADDR (1u<<4)
  1460. /** Isolate based on session group (always on). */
  1461. #define ISO_SESSIONGRP (1u<<5)
  1462. /** Isolate based on newnym epoch (always on). */
  1463. #define ISO_NYM_EPOCH (1u<<6)
  1464. /** Isolate all streams (Internal only). */
  1465. #define ISO_STREAM (1u<<7)
  1466. /**@}*/
  1467. /** Default isolation level for ports. */
  1468. #define ISO_DEFAULT (ISO_CLIENTADDR|ISO_SOCKSAUTH|ISO_SESSIONGRP|ISO_NYM_EPOCH)
  1469. /** Indicates that we haven't yet set a session group on a port_cfg_t. */
  1470. #define SESSION_GROUP_UNSET -1
  1471. /** Session group reserved for directory connections */
  1472. #define SESSION_GROUP_DIRCONN -2
  1473. /** Session group reserved for resolve requests launched by a controller */
  1474. #define SESSION_GROUP_CONTROL_RESOLVE -3
  1475. /** First automatically allocated session group number */
  1476. #define SESSION_GROUP_FIRST_AUTO -4
  1477. typedef struct port_cfg_t port_cfg_t;
  1478. typedef struct routerset_t routerset_t;
  1479. /** A magic value for the (Socks|OR|...)Port options below, telling Tor
  1480. * to pick its own port. */
  1481. #define CFG_AUTO_PORT 0xc4005e
  1482. /** Enumeration of outbound address configuration types:
  1483. * Exit-only, OR-only, or both */
  1484. typedef enum {OUTBOUND_ADDR_EXIT, OUTBOUND_ADDR_OR,
  1485. OUTBOUND_ADDR_EXIT_AND_OR,
  1486. OUTBOUND_ADDR_MAX} outbound_addr_t;
  1487. /** Configuration options for a Tor process. */
  1488. typedef struct {
  1489. uint32_t magic_;
  1490. /** What should the tor process actually do? */
  1491. enum {
  1492. CMD_RUN_TOR=0, CMD_LIST_FINGERPRINT, CMD_HASH_PASSWORD,
  1493. CMD_VERIFY_CONFIG, CMD_RUN_UNITTESTS, CMD_DUMP_CONFIG,
  1494. CMD_KEYGEN,
  1495. CMD_KEY_EXPIRATION,
  1496. } command;
  1497. char *command_arg; /**< Argument for command-line option. */
  1498. config_line_t *Logs; /**< New-style list of configuration lines
  1499. * for logs */
  1500. int LogTimeGranularity; /**< Log resolution in milliseconds. */
  1501. int LogMessageDomains; /**< Boolean: Should we log the domain(s) in which
  1502. * each log message occurs? */
  1503. int TruncateLogFile; /**< Boolean: Should we truncate the log file
  1504. before we start writing? */
  1505. char *SyslogIdentityTag; /**< Identity tag to add for syslog logging. */
  1506. char *AndroidIdentityTag; /**< Identity tag to add for Android logging. */
  1507. char *DebugLogFile; /**< Where to send verbose log messages. */
  1508. char *DataDirectory_option; /**< Where to store long-term data, as
  1509. * configured by the user. */
  1510. char *DataDirectory; /**< Where to store long-term data, as modified. */
  1511. int DataDirectoryGroupReadable; /**< Boolean: Is the DataDirectory g+r? */
  1512. char *KeyDirectory_option; /**< Where to store keys, as
  1513. * configured by the user. */
  1514. char *KeyDirectory; /**< Where to store keys data, as modified. */
  1515. int KeyDirectoryGroupReadable; /**< Boolean: Is the KeyDirectory g+r? */
  1516. char *CacheDirectory_option; /**< Where to store cached data, as
  1517. * configured by the user. */
  1518. char *CacheDirectory; /**< Where to store cached data, as modified. */
  1519. int CacheDirectoryGroupReadable; /**< Boolean: Is the CacheDirectory g+r? */
  1520. char *Nickname; /**< OR only: nickname of this onion router. */
  1521. char *Address; /**< OR only: configured address for this onion router. */
  1522. char *PidFile; /**< Where to store PID of Tor process. */
  1523. routerset_t *ExitNodes; /**< Structure containing nicknames, digests,
  1524. * country codes and IP address patterns of ORs to
  1525. * consider as exits. */
  1526. routerset_t *EntryNodes;/**< Structure containing nicknames, digests,
  1527. * country codes and IP address patterns of ORs to
  1528. * consider as entry points. */
  1529. int StrictNodes; /**< Boolean: When none of our EntryNodes or ExitNodes
  1530. * are up, or we need to access a node in ExcludeNodes,
  1531. * do we just fail instead? */
  1532. routerset_t *ExcludeNodes;/**< Structure containing nicknames, digests,
  1533. * country codes and IP address patterns of ORs
  1534. * not to use in circuits. But see StrictNodes
  1535. * above. */
  1536. routerset_t *ExcludeExitNodes;/**< Structure containing nicknames, digests,
  1537. * country codes and IP address patterns of
  1538. * ORs not to consider as exits. */
  1539. /** Union of ExcludeNodes and ExcludeExitNodes */
  1540. routerset_t *ExcludeExitNodesUnion_;
  1541. int DisableAllSwap; /**< Boolean: Attempt to call mlockall() on our
  1542. * process for all current and future memory. */
  1543. config_line_t *ExitPolicy; /**< Lists of exit policy components. */
  1544. int ExitPolicyRejectPrivate; /**< Should we not exit to reserved private
  1545. * addresses, and our own published addresses?
  1546. */
  1547. int ExitPolicyRejectLocalInterfaces; /**< Should we not exit to local
  1548. * interface addresses?
  1549. * Includes OutboundBindAddresses and
  1550. * configured ports. */
  1551. int ReducedExitPolicy; /**<Should we use the Reduced Exit Policy? */
  1552. config_line_t *SocksPolicy; /**< Lists of socks policy components */
  1553. config_line_t *DirPolicy; /**< Lists of dir policy components */
  1554. /** Local address to bind outbound sockets */
  1555. config_line_t *OutboundBindAddress;
  1556. /** Local address to bind outbound relay sockets */
  1557. config_line_t *OutboundBindAddressOR;
  1558. /** Local address to bind outbound exit sockets */
  1559. config_line_t *OutboundBindAddressExit;
  1560. /** Addresses derived from the various OutboundBindAddress lines.
  1561. * [][0] is IPv4, [][1] is IPv6
  1562. */
  1563. tor_addr_t OutboundBindAddresses[OUTBOUND_ADDR_MAX][2];
  1564. /** Directory server only: which versions of
  1565. * Tor should we tell users to run? */
  1566. config_line_t *RecommendedVersions;
  1567. config_line_t *RecommendedClientVersions;
  1568. config_line_t *RecommendedServerVersions;
  1569. config_line_t *RecommendedPackages;
  1570. /** Whether dirservers allow router descriptors with private IPs. */
  1571. int DirAllowPrivateAddresses;
  1572. /** Whether routers accept EXTEND cells to routers with private IPs. */
  1573. int ExtendAllowPrivateAddresses;
  1574. char *User; /**< Name of user to run Tor as. */
  1575. config_line_t *ORPort_lines; /**< Ports to listen on for OR connections. */
  1576. /** Ports to listen on for extended OR connections. */
  1577. config_line_t *ExtORPort_lines;
  1578. /** Ports to listen on for SOCKS connections. */
  1579. config_line_t *SocksPort_lines;
  1580. /** Ports to listen on for transparent pf/netfilter connections. */
  1581. config_line_t *TransPort_lines;
  1582. char *TransProxyType; /**< What kind of transparent proxy
  1583. * implementation are we using? */
  1584. /** Parsed value of TransProxyType. */
  1585. enum {
  1586. TPT_DEFAULT,
  1587. TPT_PF_DIVERT,
  1588. TPT_IPFW,
  1589. TPT_TPROXY,
  1590. } TransProxyType_parsed;
  1591. config_line_t *NATDPort_lines; /**< Ports to listen on for transparent natd
  1592. * connections. */
  1593. /** Ports to listen on for HTTP Tunnel connections. */
  1594. config_line_t *HTTPTunnelPort_lines;
  1595. config_line_t *ControlPort_lines; /**< Ports to listen on for control
  1596. * connections. */
  1597. config_line_t *ControlSocket; /**< List of Unix Domain Sockets to listen on
  1598. * for control connections. */
  1599. int ControlSocketsGroupWritable; /**< Boolean: Are control sockets g+rw? */
  1600. int UnixSocksGroupWritable; /**< Boolean: Are SOCKS Unix sockets g+rw? */
  1601. /** Ports to listen on for directory connections. */
  1602. config_line_t *DirPort_lines;
  1603. config_line_t *DNSPort_lines; /**< Ports to listen on for DNS requests. */
  1604. /* MaxMemInQueues value as input by the user. We clean this up to be
  1605. * MaxMemInQueues. */
  1606. uint64_t MaxMemInQueues_raw;
  1607. uint64_t MaxMemInQueues;/**< If we have more memory than this allocated
  1608. * for queues and buffers, run the OOM handler */
  1609. /** Above this value, consider ourselves low on RAM. */
  1610. uint64_t MaxMemInQueues_low_threshold;
  1611. /** @name port booleans
  1612. *
  1613. * Derived booleans: For server ports and ControlPort, true iff there is a
  1614. * non-listener port on an AF_INET or AF_INET6 address of the given type
  1615. * configured in one of the _lines options above.
  1616. * For client ports, also true if there is a unix socket configured.
  1617. * If you are checking for client ports, you may want to use:
  1618. * SocksPort_set || TransPort_set || NATDPort_set || DNSPort_set ||
  1619. * HTTPTunnelPort_set
  1620. * rather than SocksPort_set.
  1621. *
  1622. * @{
  1623. */
  1624. unsigned int ORPort_set : 1;
  1625. unsigned int SocksPort_set : 1;
  1626. unsigned int TransPort_set : 1;
  1627. unsigned int NATDPort_set : 1;
  1628. unsigned int ControlPort_set : 1;
  1629. unsigned int DirPort_set : 1;
  1630. unsigned int DNSPort_set : 1;
  1631. unsigned int ExtORPort_set : 1;
  1632. unsigned int HTTPTunnelPort_set : 1;
  1633. /**@}*/
  1634. int AssumeReachable; /**< Whether to publish our descriptor regardless. */
  1635. int AuthoritativeDir; /**< Boolean: is this an authoritative directory? */
  1636. int V3AuthoritativeDir; /**< Boolean: is this an authoritative directory
  1637. * for version 3 directories? */
  1638. int VersioningAuthoritativeDir; /**< Boolean: is this an authoritative
  1639. * directory that's willing to recommend
  1640. * versions? */
  1641. int BridgeAuthoritativeDir; /**< Boolean: is this an authoritative directory
  1642. * that aggregates bridge descriptors? */
  1643. /** If set on a bridge relay, it will include this value on a new
  1644. * "bridge-distribution-request" line in its bridge descriptor. */
  1645. char *BridgeDistribution;
  1646. /** If set on a bridge authority, it will answer requests on its dirport
  1647. * for bridge statuses -- but only if the requests use this password. */
  1648. char *BridgePassword;
  1649. /** If BridgePassword is set, this is a SHA256 digest of the basic http
  1650. * authenticator for it. Used so we can do a time-independent comparison. */
  1651. char *BridgePassword_AuthDigest_;
  1652. int UseBridges; /**< Boolean: should we start all circuits with a bridge? */
  1653. config_line_t *Bridges; /**< List of bootstrap bridge addresses. */
  1654. config_line_t *ClientTransportPlugin; /**< List of client
  1655. transport plugins. */
  1656. config_line_t *ServerTransportPlugin; /**< List of client
  1657. transport plugins. */
  1658. /** List of TCP/IP addresses that transports should listen at. */
  1659. config_line_t *ServerTransportListenAddr;
  1660. /** List of options that must be passed to pluggable transports. */
  1661. config_line_t *ServerTransportOptions;
  1662. int BridgeRelay; /**< Boolean: are we acting as a bridge relay? We make
  1663. * this explicit so we can change how we behave in the
  1664. * future. */
  1665. /** Boolean: if we know the bridge's digest, should we get new
  1666. * descriptors from the bridge authorities or from the bridge itself? */
  1667. int UpdateBridgesFromAuthority;
  1668. int AvoidDiskWrites; /**< Boolean: should we never cache things to disk?
  1669. * Not used yet. */
  1670. int ClientOnly; /**< Boolean: should we never evolve into a server role? */
  1671. int ReducedConnectionPadding; /**< Boolean: Should we try to keep connections
  1672. open shorter and pad them less against
  1673. connection-level traffic analysis? */
  1674. /** Autobool: if auto, then connection padding will be negotiated by client
  1675. * and server. If 0, it will be fully disabled. If 1, the client will still
  1676. * pad to the server regardless of server support. */
  1677. int ConnectionPadding;
  1678. /** To what authority types do we publish our descriptor? Choices are
  1679. * "v1", "v2", "v3", "bridge", or "". */
  1680. smartlist_t *PublishServerDescriptor;
  1681. /** A bitfield of authority types, derived from PublishServerDescriptor. */
  1682. dirinfo_type_t PublishServerDescriptor_;
  1683. /** Boolean: do we publish hidden service descriptors to the HS auths? */
  1684. int PublishHidServDescriptors;
  1685. int FetchServerDescriptors; /**< Do we fetch server descriptors as normal? */
  1686. int FetchHidServDescriptors; /**< and hidden service descriptors? */
  1687. int MinUptimeHidServDirectoryV2; /**< As directory authority, accept hidden
  1688. * service directories after what time? */
  1689. int FetchUselessDescriptors; /**< Do we fetch non-running descriptors too? */
  1690. int AllDirActionsPrivate; /**< Should every directory action be sent
  1691. * through a Tor circuit? */
  1692. /** Run in 'tor2web mode'? (I.e. only make client connections to hidden
  1693. * services, and use a single hop for all hidden-service-related
  1694. * circuits.) */
  1695. int Tor2webMode;
  1696. /** A routerset that should be used when picking RPs for HS circuits. */
  1697. routerset_t *Tor2webRendezvousPoints;
  1698. /** A routerset that should be used when picking middle nodes for HS
  1699. * circuits. */
  1700. routerset_t *HSLayer2Nodes;
  1701. /** A routerset that should be used when picking third-hop nodes for HS
  1702. * circuits. */
  1703. routerset_t *HSLayer3Nodes;
  1704. /** Onion Services in HiddenServiceSingleHopMode make one-hop (direct)
  1705. * circuits between the onion service server, and the introduction and
  1706. * rendezvous points. (Onion service descriptors are still posted using
  1707. * 3-hop paths, to avoid onion service directories blocking the service.)
  1708. * This option makes every hidden service instance hosted by
  1709. * this tor instance a Single Onion Service.
  1710. * HiddenServiceSingleHopMode requires HiddenServiceNonAnonymousMode to be
  1711. * set to 1.
  1712. * Use rend_service_allow_non_anonymous_connection() or
  1713. * rend_service_reveal_startup_time() instead of using this option directly.
  1714. */
  1715. int HiddenServiceSingleHopMode;
  1716. /* Makes hidden service clients and servers non-anonymous on this tor
  1717. * instance. Allows the non-anonymous HiddenServiceSingleHopMode. Enables
  1718. * non-anonymous behaviour in the hidden service protocol.
  1719. * Use rend_service_non_anonymous_mode_enabled() instead of using this option
  1720. * directly.
  1721. */
  1722. int HiddenServiceNonAnonymousMode;
  1723. int ConnLimit; /**< Demanded minimum number of simultaneous connections. */
  1724. int ConnLimit_; /**< Maximum allowed number of simultaneous connections. */
  1725. int ConnLimit_high_thresh; /**< start trying to lower socket usage if we
  1726. * have this many. */
  1727. int ConnLimit_low_thresh; /**< try to get down to here after socket
  1728. * exhaustion. */
  1729. int RunAsDaemon; /**< If true, run in the background. (Unix only) */
  1730. int FascistFirewall; /**< Whether to prefer ORs reachable on open ports. */
  1731. smartlist_t *FirewallPorts; /**< Which ports our firewall allows
  1732. * (strings). */
  1733. config_line_t *ReachableAddresses; /**< IP:ports our firewall allows. */
  1734. config_line_t *ReachableORAddresses; /**< IP:ports for OR conns. */
  1735. config_line_t *ReachableDirAddresses; /**< IP:ports for Dir conns. */
  1736. int ConstrainedSockets; /**< Shrink xmit and recv socket buffers. */
  1737. uint64_t ConstrainedSockSize; /**< Size of constrained buffers. */
  1738. /** Whether we should drop exit streams from Tors that we don't know are
  1739. * relays. One of "0" (never refuse), "1" (always refuse), or "-1" (do
  1740. * what the consensus says, defaulting to 'refuse' if the consensus says
  1741. * nothing). */
  1742. int RefuseUnknownExits;
  1743. /** Application ports that require all nodes in circ to have sufficient
  1744. * uptime. */
  1745. smartlist_t *LongLivedPorts;
  1746. /** Application ports that are likely to be unencrypted and
  1747. * unauthenticated; we reject requests for them to prevent the
  1748. * user from screwing up and leaking plaintext secrets to an
  1749. * observer somewhere on the Internet. */
  1750. smartlist_t *RejectPlaintextPorts;
  1751. /** Related to RejectPlaintextPorts above, except this config option
  1752. * controls whether we warn (in the log and via a controller status
  1753. * event) every time a risky connection is attempted. */
  1754. smartlist_t *WarnPlaintextPorts;
  1755. /** Should we try to reuse the same exit node for a given host */
  1756. smartlist_t *TrackHostExits;
  1757. int TrackHostExitsExpire; /**< Number of seconds until we expire an
  1758. * addressmap */
  1759. config_line_t *AddressMap; /**< List of address map directives. */
  1760. int AutomapHostsOnResolve; /**< If true, when we get a resolve request for a
  1761. * hostname ending with one of the suffixes in
  1762. * <b>AutomapHostsSuffixes</b>, map it to a
  1763. * virtual address. */
  1764. /** List of suffixes for <b>AutomapHostsOnResolve</b>. The special value
  1765. * "." means "match everything." */
  1766. smartlist_t *AutomapHostsSuffixes;
  1767. int RendPostPeriod; /**< How often do we post each rendezvous service
  1768. * descriptor? Remember to publish them independently. */
  1769. int KeepalivePeriod; /**< How often do we send padding cells to keep
  1770. * connections alive? */
  1771. int SocksTimeout; /**< How long do we let a socks connection wait
  1772. * unattached before we fail it? */
  1773. int LearnCircuitBuildTimeout; /**< If non-zero, we attempt to learn a value
  1774. * for CircuitBuildTimeout based on timeout
  1775. * history. Use circuit_build_times_disabled()
  1776. * rather than checking this value directly. */
  1777. int CircuitBuildTimeout; /**< Cull non-open circuits that were born at
  1778. * least this many seconds ago. Used until
  1779. * adaptive algorithm learns a new value. */
  1780. int CircuitsAvailableTimeout; /**< Try to have an open circuit for at
  1781. least this long after last activity */
  1782. int CircuitStreamTimeout; /**< If non-zero, detach streams from circuits
  1783. * and try a new circuit if the stream has been
  1784. * waiting for this many seconds. If zero, use
  1785. * our default internal timeout schedule. */
  1786. int MaxOnionQueueDelay; /*< DOCDOC */
  1787. int NewCircuitPeriod; /**< How long do we use a circuit before building
  1788. * a new one? */
  1789. int MaxCircuitDirtiness; /**< Never use circs that were first used more than
  1790. this interval ago. */
  1791. uint64_t BandwidthRate; /**< How much bandwidth, on average, are we willing
  1792. * to use in a second? */
  1793. uint64_t BandwidthBurst; /**< How much bandwidth, at maximum, are we willing
  1794. * to use in a second? */
  1795. uint64_t MaxAdvertisedBandwidth; /**< How much bandwidth are we willing to
  1796. * tell other nodes we have? */
  1797. uint64_t RelayBandwidthRate; /**< How much bandwidth, on average, are we
  1798. * willing to use for all relayed conns? */
  1799. uint64_t RelayBandwidthBurst; /**< How much bandwidth, at maximum, will we
  1800. * use in a second for all relayed conns? */
  1801. uint64_t PerConnBWRate; /**< Long-term bw on a single TLS conn, if set. */
  1802. uint64_t PerConnBWBurst; /**< Allowed burst on a single TLS conn, if set. */
  1803. int NumCPUs; /**< How many CPUs should we try to use? */
  1804. config_line_t *RendConfigLines; /**< List of configuration lines
  1805. * for rendezvous services. */
  1806. config_line_t *HidServAuth; /**< List of configuration lines for client-side
  1807. * authorizations for hidden services */
  1808. char *ContactInfo; /**< Contact info to be published in the directory. */
  1809. int HeartbeatPeriod; /**< Log heartbeat messages after this many seconds
  1810. * have passed. */
  1811. int MainloopStats; /**< Log main loop statistics as part of the
  1812. * heartbeat messages. */
  1813. char *HTTPProxy; /**< hostname[:port] to use as http proxy, if any. */
  1814. tor_addr_t HTTPProxyAddr; /**< Parsed IPv4 addr for http proxy, if any. */
  1815. uint16_t HTTPProxyPort; /**< Parsed port for http proxy, if any. */
  1816. char *HTTPProxyAuthenticator; /**< username:password string, if any. */
  1817. char *HTTPSProxy; /**< hostname[:port] to use as https proxy, if any. */
  1818. tor_addr_t HTTPSProxyAddr; /**< Parsed addr for https proxy, if any. */
  1819. uint16_t HTTPSProxyPort; /**< Parsed port for https proxy, if any. */
  1820. char *HTTPSProxyAuthenticator; /**< username:password string, if any. */
  1821. char *Socks4Proxy; /**< hostname:port to use as a SOCKS4 proxy, if any. */
  1822. tor_addr_t Socks4ProxyAddr; /**< Derived from Socks4Proxy. */
  1823. uint16_t Socks4ProxyPort; /**< Derived from Socks4Proxy. */
  1824. char *Socks5Proxy; /**< hostname:port to use as a SOCKS5 proxy, if any. */
  1825. tor_addr_t Socks5ProxyAddr; /**< Derived from Sock5Proxy. */
  1826. uint16_t Socks5ProxyPort; /**< Derived from Socks5Proxy. */
  1827. char *Socks5ProxyUsername; /**< Username for SOCKS5 authentication, if any */
  1828. char *Socks5ProxyPassword; /**< Password for SOCKS5 authentication, if any */
  1829. /** List of configuration lines for replacement directory authorities.
  1830. * If you just want to replace one class of authority at a time,
  1831. * use the "Alternate*Authority" options below instead. */
  1832. config_line_t *DirAuthorities;
  1833. /** List of fallback directory servers */
  1834. config_line_t *FallbackDir;
  1835. /** Whether to use the default hard-coded FallbackDirs */
  1836. int UseDefaultFallbackDirs;
  1837. /** Weight to apply to all directory authority rates if considering them
  1838. * along with fallbackdirs */
  1839. double DirAuthorityFallbackRate;
  1840. /** If set, use these main (currently v3) directory authorities and
  1841. * not the default ones. */
  1842. config_line_t *AlternateDirAuthority;
  1843. /** If set, use these bridge authorities and not the default one. */
  1844. config_line_t *AlternateBridgeAuthority;
  1845. config_line_t *MyFamily_lines; /**< Declared family for this OR. */
  1846. config_line_t *MyFamily; /**< Declared family for this OR, normalized */
  1847. config_line_t *NodeFamilies; /**< List of config lines for
  1848. * node families */
  1849. smartlist_t *NodeFamilySets; /**< List of parsed NodeFamilies values. */
  1850. config_line_t *AuthDirBadExit; /**< Address policy for descriptors to
  1851. * mark as bad exits. */
  1852. config_line_t *AuthDirReject; /**< Address policy for descriptors to
  1853. * reject. */
  1854. config_line_t *AuthDirInvalid; /**< Address policy for descriptors to
  1855. * never mark as valid. */
  1856. /** @name AuthDir...CC
  1857. *
  1858. * Lists of country codes to mark as BadExit, or Invalid, or to
  1859. * reject entirely.
  1860. *
  1861. * @{
  1862. */
  1863. smartlist_t *AuthDirBadExitCCs;
  1864. smartlist_t *AuthDirInvalidCCs;
  1865. smartlist_t *AuthDirRejectCCs;
  1866. /**@}*/
  1867. int AuthDirListBadExits; /**< True iff we should list bad exits,
  1868. * and vote for all other exits as good. */
  1869. int AuthDirMaxServersPerAddr; /**< Do not permit more than this
  1870. * number of servers per IP address. */
  1871. int AuthDirHasIPv6Connectivity; /**< Boolean: are we on IPv6? */
  1872. int AuthDirPinKeys; /**< Boolean: Do we enforce key-pinning? */
  1873. /** If non-zero, always vote the Fast flag for any relay advertising
  1874. * this amount of capacity or more. */
  1875. uint64_t AuthDirFastGuarantee;
  1876. /** If non-zero, this advertised capacity or more is always sufficient
  1877. * to satisfy the bandwidth requirement for the Guard flag. */
  1878. uint64_t AuthDirGuardBWGuarantee;
  1879. char *AccountingStart; /**< How long is the accounting interval, and when
  1880. * does it start? */
  1881. uint64_t AccountingMax; /**< How many bytes do we allow per accounting
  1882. * interval before hibernation? 0 for "never
  1883. * hibernate." */
  1884. /** How do we determine when our AccountingMax has been reached?
  1885. * "max" for when in or out reaches AccountingMax
  1886. * "sum" for when in plus out reaches AccountingMax
  1887. * "in" for when in reaches AccountingMax
  1888. * "out" for when out reaches AccountingMax */
  1889. char *AccountingRule_option;
  1890. enum { ACCT_MAX, ACCT_SUM, ACCT_IN, ACCT_OUT } AccountingRule;
  1891. /** Base64-encoded hash of accepted passwords for the control system. */
  1892. config_line_t *HashedControlPassword;
  1893. /** As HashedControlPassword, but not saved. */
  1894. config_line_t *HashedControlSessionPassword;
  1895. int CookieAuthentication; /**< Boolean: do we enable cookie-based auth for
  1896. * the control system? */
  1897. char *CookieAuthFile; /**< Filesystem location of a ControlPort
  1898. * authentication cookie. */
  1899. char *ExtORPortCookieAuthFile; /**< Filesystem location of Extended
  1900. * ORPort authentication cookie. */
  1901. int CookieAuthFileGroupReadable; /**< Boolean: Is the CookieAuthFile g+r? */
  1902. int ExtORPortCookieAuthFileGroupReadable; /**< Boolean: Is the
  1903. * ExtORPortCookieAuthFile g+r? */
  1904. int LeaveStreamsUnattached; /**< Boolean: Does Tor attach new streams to
  1905. * circuits itself (0), or does it expect a controller
  1906. * to cope? (1) */
  1907. int DisablePredictedCircuits; /**< Boolean: does Tor preemptively
  1908. * make circuits in the background (0),
  1909. * or not (1)? */
  1910. /** Process specifier for a controller that ‘owns’ this Tor
  1911. * instance. Tor will terminate if its owning controller does. */
  1912. char *OwningControllerProcess;
  1913. /** FD specifier for a controller that owns this Tor instance. */
  1914. int OwningControllerFD;
  1915. int ShutdownWaitLength; /**< When we get a SIGINT and we're a server, how
  1916. * long do we wait before exiting? */
  1917. char *SafeLogging; /**< Contains "relay", "1", "0" (meaning no scrubbing). */
  1918. /* Derived from SafeLogging */
  1919. enum {
  1920. SAFELOG_SCRUB_ALL, SAFELOG_SCRUB_RELAY, SAFELOG_SCRUB_NONE
  1921. } SafeLogging_;
  1922. int Sandbox; /**< Boolean: should sandboxing be enabled? */
  1923. int SafeSocks; /**< Boolean: should we outright refuse application
  1924. * connections that use socks4 or socks5-with-local-dns? */
  1925. int ProtocolWarnings; /**< Boolean: when other parties screw up the Tor
  1926. * protocol, is it a warn or an info in our logs? */
  1927. int TestSocks; /**< Boolean: when we get a socks connection, do we loudly
  1928. * log whether it was DNS-leaking or not? */
  1929. int HardwareAccel; /**< Boolean: Should we enable OpenSSL hardware
  1930. * acceleration where available? */
  1931. /** Token Bucket Refill resolution in milliseconds. */
  1932. int TokenBucketRefillInterval;
  1933. char *AccelName; /**< Optional hardware acceleration engine name. */
  1934. char *AccelDir; /**< Optional hardware acceleration engine search dir. */
  1935. /** Boolean: Do we try to enter from a smallish number
  1936. * of fixed nodes? */
  1937. int UseEntryGuards_option;
  1938. /** Internal variable to remember whether we're actually acting on
  1939. * UseEntryGuards_option -- when we're a non-anonymous Tor2web client or
  1940. * Single Onion Service, it is always false, otherwise we use the value of
  1941. * UseEntryGuards_option. */
  1942. int UseEntryGuards;
  1943. int NumEntryGuards; /**< How many entry guards do we try to establish? */
  1944. /** If 1, we use any guardfraction information we see in the
  1945. * consensus. If 0, we don't. If -1, let the consensus parameter
  1946. * decide. */
  1947. int UseGuardFraction;
  1948. int NumDirectoryGuards; /**< How many dir guards do we try to establish?
  1949. * If 0, use value from NumEntryGuards. */
  1950. int NumPrimaryGuards; /**< How many primary guards do we want? */
  1951. int RephistTrackTime; /**< How many seconds do we keep rephist info? */
  1952. /** Should we always fetch our dir info on the mirror schedule (which
  1953. * means directly from the authorities) no matter our other config? */
  1954. int FetchDirInfoEarly;
  1955. /** Should we fetch our dir info at the start of the consensus period? */
  1956. int FetchDirInfoExtraEarly;
  1957. int DirCache; /**< Cache all directory documents and accept requests via
  1958. * tunnelled dir conns from clients. If 1, enabled (default);
  1959. * If 0, disabled. */
  1960. char *VirtualAddrNetworkIPv4; /**< Address and mask to hand out for virtual
  1961. * MAPADDRESS requests for IPv4 addresses */
  1962. char *VirtualAddrNetworkIPv6; /**< Address and mask to hand out for virtual
  1963. * MAPADDRESS requests for IPv6 addresses */
  1964. int ServerDNSSearchDomains; /**< Boolean: If set, we don't force exit
  1965. * addresses to be FQDNs, but rather search for them in
  1966. * the local domains. */
  1967. int ServerDNSDetectHijacking; /**< Boolean: If true, check for DNS failure
  1968. * hijacking. */
  1969. int ServerDNSRandomizeCase; /**< Boolean: Use the 0x20-hack to prevent
  1970. * DNS poisoning attacks. */
  1971. char *ServerDNSResolvConfFile; /**< If provided, we configure our internal
  1972. * resolver from the file here rather than from
  1973. * /etc/resolv.conf (Unix) or the registry (Windows). */
  1974. char *DirPortFrontPage; /**< This is a full path to a file with an html
  1975. disclaimer. This allows a server administrator to show
  1976. that they're running Tor and anyone visiting their server
  1977. will know this without any specialized knowledge. */
  1978. int DisableDebuggerAttachment; /**< Currently Linux only specific attempt to
  1979. disable ptrace; needs BSD testing. */
  1980. /** Boolean: if set, we start even if our resolv.conf file is missing
  1981. * or broken. */
  1982. int ServerDNSAllowBrokenConfig;
  1983. /** Boolean: if set, then even connections to private addresses will get
  1984. * rate-limited. */
  1985. int CountPrivateBandwidth;
  1986. smartlist_t *ServerDNSTestAddresses; /**< A list of addresses that definitely
  1987. * should be resolvable. Used for
  1988. * testing our DNS server. */
  1989. int EnforceDistinctSubnets; /**< If true, don't allow multiple routers in the
  1990. * same network zone in the same circuit. */
  1991. int AllowNonRFC953Hostnames; /**< If true, we allow connections to hostnames
  1992. * with weird characters. */
  1993. /** If true, we try resolving hostnames with weird characters. */
  1994. int ServerDNSAllowNonRFC953Hostnames;
  1995. /** If true, we try to download extra-info documents (and we serve them,
  1996. * if we are a cache). For authorities, this is always true. */
  1997. int DownloadExtraInfo;
  1998. /** If true, we're configured to collect statistics on clients
  1999. * requesting network statuses from us as directory. */
  2000. int DirReqStatistics_option;
  2001. /** Internal variable to remember whether we're actually acting on
  2002. * DirReqStatistics_option -- yes if it's set and we're a server, else no. */
  2003. int DirReqStatistics;
  2004. /** If true, the user wants us to collect statistics on port usage. */
  2005. int ExitPortStatistics;
  2006. /** If true, the user wants us to collect connection statistics. */
  2007. int ConnDirectionStatistics;
  2008. /** If true, the user wants us to collect cell statistics. */
  2009. int CellStatistics;
  2010. /** If true, the user wants us to collect padding statistics. */
  2011. int PaddingStatistics;
  2012. /** If true, the user wants us to collect statistics as entry node. */
  2013. int EntryStatistics;
  2014. /** If true, the user wants us to collect statistics as hidden service
  2015. * directory, introduction point, or rendezvous point. */
  2016. int HiddenServiceStatistics_option;
  2017. /** Internal variable to remember whether we're actually acting on
  2018. * HiddenServiceStatistics_option -- yes if it's set and we're a server,
  2019. * else no. */
  2020. int HiddenServiceStatistics;
  2021. /** If true, include statistics file contents in extra-info documents. */
  2022. int ExtraInfoStatistics;
  2023. /** If true, do not believe anybody who tells us that a domain resolves
  2024. * to an internal address, or that an internal address has a PTR mapping.
  2025. * Helps avoid some cross-site attacks. */
  2026. int ClientDNSRejectInternalAddresses;
  2027. /** If true, do not accept any requests to connect to internal addresses
  2028. * over randomly chosen exits. */
  2029. int ClientRejectInternalAddresses;
  2030. /** If true, clients may connect over IPv4. If false, they will avoid
  2031. * connecting over IPv4. We enforce this for OR and Dir connections. */
  2032. int ClientUseIPv4;
  2033. /** If true, clients may connect over IPv6. If false, they will avoid
  2034. * connecting over IPv4. We enforce this for OR and Dir connections.
  2035. * Use fascist_firewall_use_ipv6() instead of accessing this value
  2036. * directly. */
  2037. int ClientUseIPv6;
  2038. /** If true, prefer an IPv6 OR port over an IPv4 one for entry node
  2039. * connections. If auto, bridge clients prefer IPv6, and other clients
  2040. * prefer IPv4. Use node_ipv6_or_preferred() instead of accessing this value
  2041. * directly. */
  2042. int ClientPreferIPv6ORPort;
  2043. /** If true, prefer an IPv6 directory port over an IPv4 one for direct
  2044. * directory connections. If auto, bridge clients prefer IPv6, and other
  2045. * clients prefer IPv4. Use fascist_firewall_prefer_ipv6_dirport() instead of
  2046. * accessing this value directly. */
  2047. int ClientPreferIPv6DirPort;
  2048. /** The length of time that we think a consensus should be fresh. */
  2049. int V3AuthVotingInterval;
  2050. /** The length of time we think it will take to distribute votes. */
  2051. int V3AuthVoteDelay;
  2052. /** The length of time we think it will take to distribute signatures. */
  2053. int V3AuthDistDelay;
  2054. /** The number of intervals we think a consensus should be valid. */
  2055. int V3AuthNIntervalsValid;
  2056. /** Should advertise and sign consensuses with a legacy key, for key
  2057. * migration purposes? */
  2058. int V3AuthUseLegacyKey;
  2059. /** Location of bandwidth measurement file */
  2060. char *V3BandwidthsFile;
  2061. /** Location of guardfraction file */
  2062. char *GuardfractionFile;
  2063. /** Authority only: key=value pairs that we add to our networkstatus
  2064. * consensus vote on the 'params' line. */
  2065. char *ConsensusParams;
  2066. /** Authority only: minimum number of measured bandwidths we must see
  2067. * before we only believe measured bandwidths to assign flags. */
  2068. int MinMeasuredBWsForAuthToIgnoreAdvertised;
  2069. /** The length of time that we think an initial consensus should be fresh.
  2070. * Only altered on testing networks. */
  2071. int TestingV3AuthInitialVotingInterval;
  2072. /** The length of time we think it will take to distribute initial votes.
  2073. * Only altered on testing networks. */
  2074. int TestingV3AuthInitialVoteDelay;
  2075. /** The length of time we think it will take to distribute initial
  2076. * signatures. Only altered on testing networks.*/
  2077. int TestingV3AuthInitialDistDelay;
  2078. /** Offset in seconds added to the starting time for consensus
  2079. voting. Only altered on testing networks. */
  2080. int TestingV3AuthVotingStartOffset;
  2081. /** If an authority has been around for less than this amount of time, it
  2082. * does not believe its reachability information is accurate. Only
  2083. * altered on testing networks. */
  2084. int TestingAuthDirTimeToLearnReachability;
  2085. /** Clients don't download any descriptor this recent, since it will
  2086. * probably not have propagated to enough caches. Only altered on testing
  2087. * networks. */
  2088. int TestingEstimatedDescriptorPropagationTime;
  2089. /** Schedule for when servers should download things in general. Only
  2090. * altered on testing networks. */
  2091. int TestingServerDownloadInitialDelay;
  2092. /** Schedule for when clients should download things in general. Only
  2093. * altered on testing networks. */
  2094. int TestingClientDownloadInitialDelay;
  2095. /** Schedule for when servers should download consensuses. Only altered
  2096. * on testing networks. */
  2097. int TestingServerConsensusDownloadInitialDelay;
  2098. /** Schedule for when clients should download consensuses. Only altered
  2099. * on testing networks. */
  2100. int TestingClientConsensusDownloadInitialDelay;
  2101. /** Schedule for when clients should download consensuses from authorities
  2102. * if they are bootstrapping (that is, they don't have a usable, reasonably
  2103. * live consensus). Only used by clients fetching from a list of fallback
  2104. * directory mirrors.
  2105. *
  2106. * This schedule is incremented by (potentially concurrent) connection
  2107. * attempts, unlike other schedules, which are incremented by connection
  2108. * failures. Only altered on testing networks. */
  2109. int ClientBootstrapConsensusAuthorityDownloadInitialDelay;
  2110. /** Schedule for when clients should download consensuses from fallback
  2111. * directory mirrors if they are bootstrapping (that is, they don't have a
  2112. * usable, reasonably live consensus). Only used by clients fetching from a
  2113. * list of fallback directory mirrors.
  2114. *
  2115. * This schedule is incremented by (potentially concurrent) connection
  2116. * attempts, unlike other schedules, which are incremented by connection
  2117. * failures. Only altered on testing networks. */
  2118. int ClientBootstrapConsensusFallbackDownloadInitialDelay;
  2119. /** Schedule for when clients should download consensuses from authorities
  2120. * if they are bootstrapping (that is, they don't have a usable, reasonably
  2121. * live consensus). Only used by clients which don't have or won't fetch
  2122. * from a list of fallback directory mirrors.
  2123. *
  2124. * This schedule is incremented by (potentially concurrent) connection
  2125. * attempts, unlike other schedules, which are incremented by connection
  2126. * failures. Only altered on testing networks. */
  2127. int ClientBootstrapConsensusAuthorityOnlyDownloadInitialDelay;
  2128. /** Schedule for when clients should download bridge descriptors. Only
  2129. * altered on testing networks. */
  2130. int TestingBridgeDownloadInitialDelay;
  2131. /** Schedule for when clients should download bridge descriptors when they
  2132. * have no running bridges. Only altered on testing networks. */
  2133. int TestingBridgeBootstrapDownloadInitialDelay;
  2134. /** When directory clients have only a few descriptors to request, they
  2135. * batch them until they have more, or until this amount of time has
  2136. * passed. Only altered on testing networks. */
  2137. int TestingClientMaxIntervalWithoutRequest;
  2138. /** How long do we let a directory connection stall before expiring
  2139. * it? Only altered on testing networks. */
  2140. int TestingDirConnectionMaxStall;
  2141. /** How many simultaneous in-progress connections will we make when trying
  2142. * to fetch a consensus before we wait for one to complete, timeout, or
  2143. * error out? Only altered on testing networks. */
  2144. int ClientBootstrapConsensusMaxInProgressTries;
  2145. /** If true, we take part in a testing network. Change the defaults of a
  2146. * couple of other configuration options and allow to change the values
  2147. * of certain configuration options. */
  2148. int TestingTorNetwork;
  2149. /** Minimum value for the Exit flag threshold on testing networks. */
  2150. uint64_t TestingMinExitFlagThreshold;
  2151. /** Minimum value for the Fast flag threshold on testing networks. */
  2152. uint64_t TestingMinFastFlagThreshold;
  2153. /** Relays in a testing network which should be voted Exit
  2154. * regardless of exit policy. */
  2155. routerset_t *TestingDirAuthVoteExit;
  2156. int TestingDirAuthVoteExitIsStrict;
  2157. /** Relays in a testing network which should be voted Guard
  2158. * regardless of uptime and bandwidth. */
  2159. routerset_t *TestingDirAuthVoteGuard;
  2160. int TestingDirAuthVoteGuardIsStrict;
  2161. /** Relays in a testing network which should be voted HSDir
  2162. * regardless of uptime and DirPort. */
  2163. routerset_t *TestingDirAuthVoteHSDir;
  2164. int TestingDirAuthVoteHSDirIsStrict;
  2165. /** Enable CONN_BW events. Only altered on testing networks. */
  2166. int TestingEnableConnBwEvent;
  2167. /** Enable CELL_STATS events. Only altered on testing networks. */
  2168. int TestingEnableCellStatsEvent;
  2169. /** If true, and we have GeoIP data, and we're a bridge, keep a per-country
  2170. * count of how many client addresses have contacted us so that we can help
  2171. * the bridge authority guess which countries have blocked access to us. */
  2172. int BridgeRecordUsageByCountry;
  2173. /** Optionally, IPv4 and IPv6 GeoIP data. */
  2174. char *GeoIPFile;
  2175. char *GeoIPv6File;
  2176. /** Autobool: if auto, then any attempt to Exclude{Exit,}Nodes a particular
  2177. * country code will exclude all nodes in ?? and A1. If true, all nodes in
  2178. * ?? and A1 are excluded. Has no effect if we don't know any GeoIP data. */
  2179. int GeoIPExcludeUnknown;
  2180. /** If true, SIGHUP should reload the torrc. Sometimes controllers want
  2181. * to make this false. */
  2182. int ReloadTorrcOnSIGHUP;
  2183. /* The main parameter for picking circuits within a connection.
  2184. *
  2185. * If this value is positive, when picking a cell to relay on a connection,
  2186. * we always relay from the circuit whose weighted cell count is lowest.
  2187. * Cells are weighted exponentially such that if one cell is sent
  2188. * 'CircuitPriorityHalflife' seconds before another, it counts for half as
  2189. * much.
  2190. *
  2191. * If this value is zero, we're disabling the cell-EWMA algorithm.
  2192. *
  2193. * If this value is negative, we're using the default approach
  2194. * according to either Tor or a parameter set in the consensus.
  2195. */
  2196. double CircuitPriorityHalflife;
  2197. /** Set to true if the TestingTorNetwork configuration option is set.
  2198. * This is used so that options_validate() has a chance to realize that
  2199. * the defaults have changed. */
  2200. int UsingTestNetworkDefaults_;
  2201. /** If 1, we try to use microdescriptors to build circuits. If 0, we don't.
  2202. * If -1, Tor decides. */
  2203. int UseMicrodescriptors;
  2204. /** File where we should write the ControlPort. */
  2205. char *ControlPortWriteToFile;
  2206. /** Should that file be group-readable? */
  2207. int ControlPortFileGroupReadable;
  2208. #define MAX_MAX_CLIENT_CIRCUITS_PENDING 1024
  2209. /** Maximum number of non-open general-purpose origin circuits to allow at
  2210. * once. */
  2211. int MaxClientCircuitsPending;
  2212. /** If 1, we always send optimistic data when it's supported. If 0, we
  2213. * never use it. If -1, we do what the consensus says. */
  2214. int OptimisticData;
  2215. /** If 1, we accept and launch no external network connections, except on
  2216. * control ports. */
  2217. int DisableNetwork;
  2218. /**
  2219. * Parameters for path-bias detection.
  2220. * @{
  2221. * These options override the default behavior of Tor's (**currently
  2222. * experimental**) path bias detection algorithm. To try to find broken or
  2223. * misbehaving guard nodes, Tor looks for nodes where more than a certain
  2224. * fraction of circuits through that guard fail to get built.
  2225. *
  2226. * The PathBiasCircThreshold option controls how many circuits we need to
  2227. * build through a guard before we make these checks. The
  2228. * PathBiasNoticeRate, PathBiasWarnRate and PathBiasExtremeRate options
  2229. * control what fraction of circuits must succeed through a guard so we
  2230. * won't write log messages. If less than PathBiasExtremeRate circuits
  2231. * succeed *and* PathBiasDropGuards is set to 1, we disable use of that
  2232. * guard.
  2233. *
  2234. * When we have seen more than PathBiasScaleThreshold circuits through a
  2235. * guard, we scale our observations by 0.5 (governed by the consensus) so
  2236. * that new observations don't get swamped by old ones.
  2237. *
  2238. * By default, or if a negative value is provided for one of these options,
  2239. * Tor uses reasonable defaults from the networkstatus consensus document.
  2240. * If no defaults are available there, these options default to 150, .70,
  2241. * .50, .30, 0, and 300 respectively.
  2242. */
  2243. int PathBiasCircThreshold;
  2244. double PathBiasNoticeRate;
  2245. double PathBiasWarnRate;
  2246. double PathBiasExtremeRate;
  2247. int PathBiasDropGuards;
  2248. int PathBiasScaleThreshold;
  2249. /** @} */
  2250. /**
  2251. * Parameters for path-bias use detection
  2252. * @{
  2253. * Similar to the above options, these options override the default behavior
  2254. * of Tor's (**currently experimental**) path use bias detection algorithm.
  2255. *
  2256. * Where as the path bias parameters govern thresholds for successfully
  2257. * building circuits, these four path use bias parameters govern thresholds
  2258. * only for circuit usage. Circuits which receive no stream usage are not
  2259. * counted by this detection algorithm. A used circuit is considered
  2260. * successful if it is capable of carrying streams or otherwise receiving
  2261. * well-formed responses to RELAY cells.
  2262. *
  2263. * By default, or if a negative value is provided for one of these options,
  2264. * Tor uses reasonable defaults from the networkstatus consensus document.
  2265. * If no defaults are available there, these options default to 20, .80,
  2266. * .60, and 100, respectively.
  2267. */
  2268. int PathBiasUseThreshold;
  2269. double PathBiasNoticeUseRate;
  2270. double PathBiasExtremeUseRate;
  2271. int PathBiasScaleUseThreshold;
  2272. /** @} */
  2273. int IPv6Exit; /**< Do we support exiting to IPv6 addresses? */
  2274. /** Fraction: */
  2275. double PathsNeededToBuildCircuits;
  2276. /** What expiry time shall we place on our SSL certs? "0" means we
  2277. * should guess a suitable value. */
  2278. int SSLKeyLifetime;
  2279. /** How long (seconds) do we keep a guard before picking a new one? */
  2280. int GuardLifetime;
  2281. /** Is this an exit node? This is a tristate, where "1" means "yes, and use
  2282. * the default exit policy if none is given" and "0" means "no; exit policy
  2283. * is 'reject *'" and "auto" (-1) means "same as 1, but warn the user."
  2284. *
  2285. * XXXX Eventually, the default will be 0. */
  2286. int ExitRelay;
  2287. /** For how long (seconds) do we declare our signing keys to be valid? */
  2288. int SigningKeyLifetime;
  2289. /** For how long (seconds) do we declare our link keys to be valid? */
  2290. int TestingLinkCertLifetime;
  2291. /** For how long (seconds) do we declare our auth keys to be valid? */
  2292. int TestingAuthKeyLifetime;
  2293. /** How long before signing keys expire will we try to make a new one? */
  2294. int TestingSigningKeySlop;
  2295. /** How long before link keys expire will we try to make a new one? */
  2296. int TestingLinkKeySlop;
  2297. /** How long before auth keys expire will we try to make a new one? */
  2298. int TestingAuthKeySlop;
  2299. /** Force use of offline master key features: never generate a master
  2300. * ed25519 identity key except from tor --keygen */
  2301. int OfflineMasterKey;
  2302. enum {
  2303. FORCE_PASSPHRASE_AUTO=0,
  2304. FORCE_PASSPHRASE_ON,
  2305. FORCE_PASSPHRASE_OFF
  2306. } keygen_force_passphrase;
  2307. int use_keygen_passphrase_fd;
  2308. int keygen_passphrase_fd;
  2309. int change_key_passphrase;
  2310. char *master_key_fname;
  2311. /** Autobool: Do we try to retain capabilities if we can? */
  2312. int KeepBindCapabilities;
  2313. /** Maximum total size of unparseable descriptors to log during the
  2314. * lifetime of this Tor process.
  2315. */
  2316. uint64_t MaxUnparseableDescSizeToLog;
  2317. /** Bool (default: 1): Switch for the shared random protocol. Only
  2318. * relevant to a directory authority. If off, the authority won't
  2319. * participate in the protocol. If on (default), a flag is added to the
  2320. * vote indicating participation. */
  2321. int AuthDirSharedRandomness;
  2322. /** If 1, we skip all OOS checks. */
  2323. int DisableOOSCheck;
  2324. /** Autobool: Should we include Ed25519 identities in extend2 cells?
  2325. * If -1, we should do whatever the consensus parameter says. */
  2326. int ExtendByEd25519ID;
  2327. /** Bool (default: 1): When testing routerinfos as a directory authority,
  2328. * do we enforce Ed25519 identity match? */
  2329. /* NOTE: remove this option someday. */
  2330. int AuthDirTestEd25519LinkKeys;
  2331. /** Bool (default: 0): Tells if a %include was used on torrc */
  2332. int IncludeUsed;
  2333. /** The seconds after expiration which we as a relay should keep old
  2334. * consensuses around so that we can generate diffs from them. If 0,
  2335. * use the default. */
  2336. int MaxConsensusAgeForDiffs;
  2337. /** Bool (default: 0). Tells Tor to never try to exec another program.
  2338. */
  2339. int NoExec;
  2340. /** Have the KIST scheduler run every X milliseconds. If less than zero, do
  2341. * not use the KIST scheduler but use the old vanilla scheduler instead. If
  2342. * zero, do what the consensus says and fall back to using KIST as if this is
  2343. * set to "10 msec" if the consensus doesn't say anything. */
  2344. int KISTSchedRunInterval;
  2345. /** A multiplier for the KIST per-socket limit calculation. */
  2346. double KISTSockBufSizeFactor;
  2347. /** The list of scheduler type string ordered by priority that is first one
  2348. * has to be tried first. Default: KIST,KISTLite,Vanilla */
  2349. smartlist_t *Schedulers;
  2350. /* An ordered list of scheduler_types mapped from Schedulers. */
  2351. smartlist_t *SchedulerTypes_;
  2352. /** List of files that were opened by %include in torrc and torrc-defaults */
  2353. smartlist_t *FilesOpenedByIncludes;
  2354. /** If true, Tor shouldn't install any posix signal handlers, since it is
  2355. * running embedded inside another process.
  2356. */
  2357. int DisableSignalHandlers;
  2358. /** Autobool: Is the circuit creation DoS mitigation subsystem enabled? */
  2359. int DoSCircuitCreationEnabled;
  2360. /** Minimum concurrent connection needed from one single address before any
  2361. * defense is used. */
  2362. int DoSCircuitCreationMinConnections;
  2363. /** Circuit rate used to refill the token bucket. */
  2364. int DoSCircuitCreationRate;
  2365. /** Maximum allowed burst of circuits. Reaching that value, the address is
  2366. * detected as malicious and a defense might be used. */
  2367. int DoSCircuitCreationBurst;
  2368. /** When an address is marked as malicous, what defense should be used
  2369. * against it. See the dos_cc_defense_type_t enum. */
  2370. int DoSCircuitCreationDefenseType;
  2371. /** For how much time (in seconds) the defense is applicable for a malicious
  2372. * address. A random time delta is added to the defense time of an address
  2373. * which will be between 1 second and half of this value. */
  2374. int DoSCircuitCreationDefenseTimePeriod;
  2375. /** Autobool: Is the DoS connection mitigation subsystem enabled? */
  2376. int DoSConnectionEnabled;
  2377. /** Maximum concurrent connection allowed per address. */
  2378. int DoSConnectionMaxConcurrentCount;
  2379. /** When an address is reaches the maximum count, what defense should be
  2380. * used against it. See the dos_conn_defense_type_t enum. */
  2381. int DoSConnectionDefenseType;
  2382. /** Autobool: Do we refuse single hop client rendezvous? */
  2383. int DoSRefuseSingleHopClientRendezvous;
  2384. } or_options_t;
  2385. #define LOG_PROTOCOL_WARN (get_protocol_warning_severity_level())
  2386. /** Persistent state for an onion router, as saved to disk. */
  2387. typedef struct {
  2388. uint32_t magic_;
  2389. /** The time at which we next plan to write the state to the disk. Equal to
  2390. * TIME_MAX if there are no savable changes, 0 if there are changes that
  2391. * should be saved right away. */
  2392. time_t next_write;
  2393. /** When was the state last written to disk? */
  2394. time_t LastWritten;
  2395. /** Fields for accounting bandwidth use. */
  2396. time_t AccountingIntervalStart;
  2397. uint64_t AccountingBytesReadInInterval;
  2398. uint64_t AccountingBytesWrittenInInterval;
  2399. int AccountingSecondsActive;
  2400. int AccountingSecondsToReachSoftLimit;
  2401. time_t AccountingSoftLimitHitAt;
  2402. uint64_t AccountingBytesAtSoftLimit;
  2403. uint64_t AccountingExpectedUsage;
  2404. /** A list of Entry Guard-related configuration lines. (pre-prop271) */
  2405. config_line_t *EntryGuards;
  2406. /** A list of guard-related configuration lines. (post-prop271) */
  2407. config_line_t *Guard;
  2408. config_line_t *TransportProxies;
  2409. /** Cached revision counters for active hidden services on this host */
  2410. config_line_t *HidServRevCounter;
  2411. /** These fields hold information on the history of bandwidth usage for
  2412. * servers. The "Ends" fields hold the time when we last updated the
  2413. * bandwidth usage. The "Interval" fields hold the granularity, in seconds,
  2414. * of the entries of Values. The "Values" lists hold decimal string
  2415. * representations of the number of bytes read or written in each
  2416. * interval. The "Maxima" list holds decimal strings describing the highest
  2417. * rate achieved during the interval.
  2418. */
  2419. time_t BWHistoryReadEnds;
  2420. int BWHistoryReadInterval;
  2421. smartlist_t *BWHistoryReadValues;
  2422. smartlist_t *BWHistoryReadMaxima;
  2423. time_t BWHistoryWriteEnds;
  2424. int BWHistoryWriteInterval;
  2425. smartlist_t *BWHistoryWriteValues;
  2426. smartlist_t *BWHistoryWriteMaxima;
  2427. time_t BWHistoryDirReadEnds;
  2428. int BWHistoryDirReadInterval;
  2429. smartlist_t *BWHistoryDirReadValues;
  2430. smartlist_t *BWHistoryDirReadMaxima;
  2431. time_t BWHistoryDirWriteEnds;
  2432. int BWHistoryDirWriteInterval;
  2433. smartlist_t *BWHistoryDirWriteValues;
  2434. smartlist_t *BWHistoryDirWriteMaxima;
  2435. /** Build time histogram */
  2436. config_line_t * BuildtimeHistogram;
  2437. int TotalBuildTimes;
  2438. int CircuitBuildAbandonedCount;
  2439. /** What version of Tor wrote this state file? */
  2440. char *TorVersion;
  2441. /** Holds any unrecognized values we found in the state file, in the order
  2442. * in which we found them. */
  2443. config_line_t *ExtraLines;
  2444. /** When did we last rotate our onion key? "0" for 'no idea'. */
  2445. time_t LastRotatedOnionKey;
  2446. } or_state_t;
  2447. #define MAX_SOCKS_REPLY_LEN 1024
  2448. #define MAX_SOCKS_ADDR_LEN 256
  2449. #define SOCKS_NO_AUTH 0x00
  2450. #define SOCKS_USER_PASS 0x02
  2451. /** Please open a TCP connection to this addr:port. */
  2452. #define SOCKS_COMMAND_CONNECT 0x01
  2453. /** Please turn this FQDN into an IP address, privately. */
  2454. #define SOCKS_COMMAND_RESOLVE 0xF0
  2455. /** Please turn this IP address into an FQDN, privately. */
  2456. #define SOCKS_COMMAND_RESOLVE_PTR 0xF1
  2457. /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
  2458. #define SOCKS_COMMAND_IS_CONNECT(c) (((c)==SOCKS_COMMAND_CONNECT) || 0)
  2459. #define SOCKS_COMMAND_IS_RESOLVE(c) ((c)==SOCKS_COMMAND_RESOLVE || \
  2460. (c)==SOCKS_COMMAND_RESOLVE_PTR)
  2461. /********************************* circuitbuild.c **********************/
  2462. /** How many hops does a general-purpose circuit have by default? */
  2463. #define DEFAULT_ROUTE_LEN 3
  2464. /* Circuit Build Timeout "public" structures. */
  2465. /** Precision multiplier for the Bw weights */
  2466. #define BW_WEIGHT_SCALE 10000
  2467. #define BW_MIN_WEIGHT_SCALE 1
  2468. #define BW_MAX_WEIGHT_SCALE INT32_MAX
  2469. /** Total size of the circuit timeout history to accumulate.
  2470. * 1000 is approx 2.5 days worth of continual-use circuits. */
  2471. #define CBT_NCIRCUITS_TO_OBSERVE 1000
  2472. /** Width of the histogram bins in milliseconds */
  2473. #define CBT_BIN_WIDTH ((build_time_t)50)
  2474. /** Number of modes to use in the weighted-avg computation of Xm */
  2475. #define CBT_DEFAULT_NUM_XM_MODES 3
  2476. #define CBT_MIN_NUM_XM_MODES 1
  2477. #define CBT_MAX_NUM_XM_MODES 20
  2478. /** A build_time_t is milliseconds */
  2479. typedef uint32_t build_time_t;
  2480. /**
  2481. * CBT_BUILD_ABANDONED is our flag value to represent a force-closed
  2482. * circuit (Aka a 'right-censored' pareto value).
  2483. */
  2484. #define CBT_BUILD_ABANDONED ((build_time_t)(INT32_MAX-1))
  2485. #define CBT_BUILD_TIME_MAX ((build_time_t)(INT32_MAX))
  2486. /** Save state every 10 circuits */
  2487. #define CBT_SAVE_STATE_EVERY 10
  2488. /* Circuit build times consensus parameters */
  2489. /**
  2490. * How long to wait before actually closing circuits that take too long to
  2491. * build in terms of CDF quantile.
  2492. */
  2493. #define CBT_DEFAULT_CLOSE_QUANTILE 95
  2494. #define CBT_MIN_CLOSE_QUANTILE CBT_MIN_QUANTILE_CUTOFF
  2495. #define CBT_MAX_CLOSE_QUANTILE CBT_MAX_QUANTILE_CUTOFF
  2496. /**
  2497. * How many circuits count as recent when considering if the
  2498. * connection has gone gimpy or changed.
  2499. */
  2500. #define CBT_DEFAULT_RECENT_CIRCUITS 20
  2501. #define CBT_MIN_RECENT_CIRCUITS 3
  2502. #define CBT_MAX_RECENT_CIRCUITS 1000
  2503. /**
  2504. * Maximum count of timeouts that finish the first hop in the past
  2505. * RECENT_CIRCUITS before calculating a new timeout.
  2506. *
  2507. * This tells us whether to abandon timeout history and set
  2508. * the timeout back to whatever circuit_build_times_get_initial_timeout()
  2509. * gives us.
  2510. */
  2511. #define CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT (CBT_DEFAULT_RECENT_CIRCUITS*9/10)
  2512. #define CBT_MIN_MAX_RECENT_TIMEOUT_COUNT 3
  2513. #define CBT_MAX_MAX_RECENT_TIMEOUT_COUNT 10000
  2514. /** Minimum circuits before estimating a timeout */
  2515. #define CBT_DEFAULT_MIN_CIRCUITS_TO_OBSERVE 100
  2516. #define CBT_MIN_MIN_CIRCUITS_TO_OBSERVE 1
  2517. #define CBT_MAX_MIN_CIRCUITS_TO_OBSERVE 10000
  2518. /** Cutoff percentile on the CDF for our timeout estimation. */
  2519. #define CBT_DEFAULT_QUANTILE_CUTOFF 80
  2520. #define CBT_MIN_QUANTILE_CUTOFF 10
  2521. #define CBT_MAX_QUANTILE_CUTOFF 99
  2522. double circuit_build_times_quantile_cutoff(void);
  2523. /** How often in seconds should we build a test circuit */
  2524. #define CBT_DEFAULT_TEST_FREQUENCY 10
  2525. #define CBT_MIN_TEST_FREQUENCY 1
  2526. #define CBT_MAX_TEST_FREQUENCY INT32_MAX
  2527. /** Lowest allowable value for CircuitBuildTimeout in milliseconds */
  2528. #define CBT_DEFAULT_TIMEOUT_MIN_VALUE (1500)
  2529. #define CBT_MIN_TIMEOUT_MIN_VALUE 500
  2530. #define CBT_MAX_TIMEOUT_MIN_VALUE INT32_MAX
  2531. /** Initial circuit build timeout in milliseconds */
  2532. #define CBT_DEFAULT_TIMEOUT_INITIAL_VALUE (60*1000)
  2533. #define CBT_MIN_TIMEOUT_INITIAL_VALUE CBT_MIN_TIMEOUT_MIN_VALUE
  2534. #define CBT_MAX_TIMEOUT_INITIAL_VALUE INT32_MAX
  2535. int32_t circuit_build_times_initial_timeout(void);
  2536. #if CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT < CBT_MIN_MAX_RECENT_TIMEOUT_COUNT
  2537. #error "RECENT_CIRCUITS is set too low."
  2538. #endif
  2539. typedef struct circuit_build_times_s circuit_build_times_t;
  2540. /********************************* config.c ***************************/
  2541. /** An error from options_trial_assign() or options_init_from_string(). */
  2542. typedef enum setopt_err_t {
  2543. SETOPT_OK = 0,
  2544. SETOPT_ERR_MISC = -1,
  2545. SETOPT_ERR_PARSE = -2,
  2546. SETOPT_ERR_TRANSITION = -3,
  2547. SETOPT_ERR_SETTING = -4,
  2548. } setopt_err_t;
  2549. /********************************* connection_edge.c *************************/
  2550. /** Enumerates possible origins of a client-side address mapping. */
  2551. typedef enum {
  2552. /** We're remapping this address because the controller told us to. */
  2553. ADDRMAPSRC_CONTROLLER,
  2554. /** We're remapping this address because of an AutomapHostsOnResolve
  2555. * configuration. */
  2556. ADDRMAPSRC_AUTOMAP,
  2557. /** We're remapping this address because our configuration (via torrc, the
  2558. * command line, or a SETCONF command) told us to. */
  2559. ADDRMAPSRC_TORRC,
  2560. /** We're remapping this address because we have TrackHostExit configured,
  2561. * and we want to remember to use the same exit next time. */
  2562. ADDRMAPSRC_TRACKEXIT,
  2563. /** We're remapping this address because we got a DNS resolution from a
  2564. * Tor server that told us what its value was. */
  2565. ADDRMAPSRC_DNS,
  2566. /** No remapping has occurred. This isn't a possible value for an
  2567. * addrmap_entry_t; it's used as a null value when we need to answer "Why
  2568. * did this remapping happen." */
  2569. ADDRMAPSRC_NONE
  2570. } addressmap_entry_source_t;
  2571. #define addressmap_entry_source_bitfield_t ENUM_BF(addressmap_entry_source_t)
  2572. /********************************* control.c ***************************/
  2573. /** Used to indicate the type of a circuit event passed to the controller.
  2574. * The various types are defined in control-spec.txt */
  2575. typedef enum circuit_status_event_t {
  2576. CIRC_EVENT_LAUNCHED = 0,
  2577. CIRC_EVENT_BUILT = 1,
  2578. CIRC_EVENT_EXTENDED = 2,
  2579. CIRC_EVENT_FAILED = 3,
  2580. CIRC_EVENT_CLOSED = 4,
  2581. } circuit_status_event_t;
  2582. /** Used to indicate the type of a CIRC_MINOR event passed to the controller.
  2583. * The various types are defined in control-spec.txt . */
  2584. typedef enum circuit_status_minor_event_t {
  2585. CIRC_MINOR_EVENT_PURPOSE_CHANGED,
  2586. CIRC_MINOR_EVENT_CANNIBALIZED,
  2587. } circuit_status_minor_event_t;
  2588. /** Used to indicate the type of a stream event passed to the controller.
  2589. * The various types are defined in control-spec.txt */
  2590. typedef enum stream_status_event_t {
  2591. STREAM_EVENT_SENT_CONNECT = 0,
  2592. STREAM_EVENT_SENT_RESOLVE = 1,
  2593. STREAM_EVENT_SUCCEEDED = 2,
  2594. STREAM_EVENT_FAILED = 3,
  2595. STREAM_EVENT_CLOSED = 4,
  2596. STREAM_EVENT_NEW = 5,
  2597. STREAM_EVENT_NEW_RESOLVE = 6,
  2598. STREAM_EVENT_FAILED_RETRIABLE = 7,
  2599. STREAM_EVENT_REMAP = 8
  2600. } stream_status_event_t;
  2601. /** Used to indicate the type of an OR connection event passed to the
  2602. * controller. The various types are defined in control-spec.txt */
  2603. typedef enum or_conn_status_event_t {
  2604. OR_CONN_EVENT_LAUNCHED = 0,
  2605. OR_CONN_EVENT_CONNECTED = 1,
  2606. OR_CONN_EVENT_FAILED = 2,
  2607. OR_CONN_EVENT_CLOSED = 3,
  2608. OR_CONN_EVENT_NEW = 4,
  2609. } or_conn_status_event_t;
  2610. /** Used to indicate the type of a buildtime event */
  2611. typedef enum buildtimeout_set_event_t {
  2612. BUILDTIMEOUT_SET_EVENT_COMPUTED = 0,
  2613. BUILDTIMEOUT_SET_EVENT_RESET = 1,
  2614. BUILDTIMEOUT_SET_EVENT_SUSPENDED = 2,
  2615. BUILDTIMEOUT_SET_EVENT_DISCARD = 3,
  2616. BUILDTIMEOUT_SET_EVENT_RESUME = 4
  2617. } buildtimeout_set_event_t;
  2618. /** Execute the statement <b>stmt</b>, which may log events concerning the
  2619. * connection <b>conn</b>. To prevent infinite loops, disable log messages
  2620. * being sent to controllers if <b>conn</b> is a control connection.
  2621. *
  2622. * Stmt must not contain any return or goto statements.
  2623. */
  2624. #define CONN_LOG_PROTECT(conn, stmt) \
  2625. STMT_BEGIN \
  2626. int _log_conn_is_control; \
  2627. tor_assert(conn); \
  2628. _log_conn_is_control = (conn->type == CONN_TYPE_CONTROL); \
  2629. if (_log_conn_is_control) \
  2630. disable_control_logging(); \
  2631. STMT_BEGIN stmt; STMT_END; \
  2632. if (_log_conn_is_control) \
  2633. enable_control_logging(); \
  2634. STMT_END
  2635. /** Enum describing various stages of bootstrapping, for use with controller
  2636. * bootstrap status events. The values range from 0 to 100. */
  2637. typedef enum {
  2638. BOOTSTRAP_STATUS_UNDEF=-1,
  2639. BOOTSTRAP_STATUS_STARTING=0,
  2640. BOOTSTRAP_STATUS_CONN_DIR=5,
  2641. BOOTSTRAP_STATUS_HANDSHAKE=-2,
  2642. BOOTSTRAP_STATUS_HANDSHAKE_DIR=10,
  2643. BOOTSTRAP_STATUS_ONEHOP_CREATE=15,
  2644. BOOTSTRAP_STATUS_REQUESTING_STATUS=20,
  2645. BOOTSTRAP_STATUS_LOADING_STATUS=25,
  2646. BOOTSTRAP_STATUS_LOADING_KEYS=40,
  2647. BOOTSTRAP_STATUS_REQUESTING_DESCRIPTORS=45,
  2648. BOOTSTRAP_STATUS_LOADING_DESCRIPTORS=50,
  2649. BOOTSTRAP_STATUS_CONN_OR=80,
  2650. BOOTSTRAP_STATUS_HANDSHAKE_OR=85,
  2651. BOOTSTRAP_STATUS_CIRCUIT_CREATE=90,
  2652. BOOTSTRAP_STATUS_DONE=100
  2653. } bootstrap_status_t;
  2654. /********************************* dirserv.c ***************************/
  2655. /** An enum to describe what format we're generating a routerstatus line in.
  2656. */
  2657. typedef enum {
  2658. /** For use in a v2 opinion */
  2659. NS_V2,
  2660. /** For use in a consensus networkstatus document (ns flavor) */
  2661. NS_V3_CONSENSUS,
  2662. /** For use in a vote networkstatus document */
  2663. NS_V3_VOTE,
  2664. /** For passing to the controlport in response to a GETINFO request */
  2665. NS_CONTROL_PORT,
  2666. /** For use in a consensus networkstatus document (microdesc flavor) */
  2667. NS_V3_CONSENSUS_MICRODESC
  2668. } routerstatus_format_type_t;
  2669. /********************************* dirvote.c ************************/
  2670. typedef struct vote_timing_t vote_timing_t;
  2671. /********************************* geoip.c **************************/
  2672. /** Indicates an action that we might be noting geoip statistics on.
  2673. * Note that if we're noticing CONNECT, we're a bridge, and if we're noticing
  2674. * the others, we're not.
  2675. */
  2676. typedef enum {
  2677. /** We've noticed a connection as a bridge relay or entry guard. */
  2678. GEOIP_CLIENT_CONNECT = 0,
  2679. /** We've served a networkstatus consensus as a directory server. */
  2680. GEOIP_CLIENT_NETWORKSTATUS = 1,
  2681. } geoip_client_action_t;
  2682. /** Indicates either a positive reply or a reason for rejectng a network
  2683. * status request that will be included in geoip statistics. */
  2684. typedef enum {
  2685. /** Request is answered successfully. */
  2686. GEOIP_SUCCESS = 0,
  2687. /** V3 network status is not signed by a sufficient number of requested
  2688. * authorities. */
  2689. GEOIP_REJECT_NOT_ENOUGH_SIGS = 1,
  2690. /** Requested network status object is unavailable. */
  2691. GEOIP_REJECT_UNAVAILABLE = 2,
  2692. /** Requested network status not found. */
  2693. GEOIP_REJECT_NOT_FOUND = 3,
  2694. /** Network status has not been modified since If-Modified-Since time. */
  2695. GEOIP_REJECT_NOT_MODIFIED = 4,
  2696. /** Directory is busy. */
  2697. GEOIP_REJECT_BUSY = 5,
  2698. } geoip_ns_response_t;
  2699. #define GEOIP_NS_RESPONSE_NUM 6
  2700. /** Directory requests that we are measuring can be either direct or
  2701. * tunneled. */
  2702. typedef enum {
  2703. DIRREQ_DIRECT = 0,
  2704. DIRREQ_TUNNELED = 1,
  2705. } dirreq_type_t;
  2706. /** Possible states for either direct or tunneled directory requests that
  2707. * are relevant for determining network status download times. */
  2708. typedef enum {
  2709. /** Found that the client requests a network status; applies to both
  2710. * direct and tunneled requests; initial state of a request that we are
  2711. * measuring. */
  2712. DIRREQ_IS_FOR_NETWORK_STATUS = 0,
  2713. /** Finished writing a network status to the directory connection;
  2714. * applies to both direct and tunneled requests; completes a direct
  2715. * request. */
  2716. DIRREQ_FLUSHING_DIR_CONN_FINISHED = 1,
  2717. /** END cell sent to circuit that initiated a tunneled request. */
  2718. DIRREQ_END_CELL_SENT = 2,
  2719. /** Flushed last cell from queue of the circuit that initiated a
  2720. * tunneled request to the outbuf of the OR connection. */
  2721. DIRREQ_CIRC_QUEUE_FLUSHED = 3,
  2722. /** Flushed last byte from buffer of the channel belonging to the
  2723. * circuit that initiated a tunneled request; completes a tunneled
  2724. * request. */
  2725. DIRREQ_CHANNEL_BUFFER_FLUSHED = 4
  2726. } dirreq_state_t;
  2727. #define WRITE_STATS_INTERVAL (24*60*60)
  2728. /********************************* microdesc.c *************************/
  2729. typedef struct microdesc_cache_t microdesc_cache_t;
  2730. /********************************* networkstatus.c *********************/
  2731. /** Possible statuses of a version of Tor, given opinions from the directory
  2732. * servers. */
  2733. typedef enum version_status_t {
  2734. VS_RECOMMENDED=0, /**< This version is listed as recommended. */
  2735. VS_OLD=1, /**< This version is older than any recommended version. */
  2736. VS_NEW=2, /**< This version is newer than any recommended version. */
  2737. VS_NEW_IN_SERIES=3, /**< This version is newer than any recommended version
  2738. * in its series, but later recommended versions exist.
  2739. */
  2740. VS_UNRECOMMENDED=4, /**< This version is not recommended (general case). */
  2741. VS_EMPTY=5, /**< The version list was empty; no agreed-on versions. */
  2742. VS_UNKNOWN, /**< We have no idea. */
  2743. } version_status_t;
  2744. /********************************* policies.c ************************/
  2745. /** Outcome of applying an address policy to an address. */
  2746. typedef enum {
  2747. /** The address was accepted */
  2748. ADDR_POLICY_ACCEPTED=0,
  2749. /** The address was rejected */
  2750. ADDR_POLICY_REJECTED=-1,
  2751. /** Part of the address was unknown, but as far as we can tell, it was
  2752. * accepted. */
  2753. ADDR_POLICY_PROBABLY_ACCEPTED=1,
  2754. /** Part of the address was unknown, but as far as we can tell, it was
  2755. * rejected. */
  2756. ADDR_POLICY_PROBABLY_REJECTED=2,
  2757. } addr_policy_result_t;
  2758. /********************************* rephist.c ***************************/
  2759. /** Possible public/private key operations in Tor: used to keep track of where
  2760. * we're spending our time. */
  2761. typedef enum {
  2762. SIGN_DIR, SIGN_RTR,
  2763. VERIFY_DIR, VERIFY_RTR,
  2764. ENC_ONIONSKIN, DEC_ONIONSKIN,
  2765. TLS_HANDSHAKE_C, TLS_HANDSHAKE_S,
  2766. REND_CLIENT, REND_MID, REND_SERVER,
  2767. } pk_op_t;
  2768. /********************************* rendcommon.c ***************************/
  2769. typedef struct rend_authorized_client_t rend_authorized_client_t;
  2770. typedef struct rend_encoded_v2_service_descriptor_t
  2771. rend_encoded_v2_service_descriptor_t;
  2772. /** The maximum number of non-circuit-build-timeout failures a hidden
  2773. * service client will tolerate while trying to build a circuit to an
  2774. * introduction point. See also rend_intro_point_t.unreachable_count. */
  2775. #define MAX_INTRO_POINT_REACHABILITY_FAILURES 5
  2776. /** The minimum and maximum number of distinct INTRODUCE2 cells which a
  2777. * hidden service's introduction point will receive before it begins to
  2778. * expire. */
  2779. #define INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS 16384
  2780. /* Double the minimum value so the interval is [min, min * 2]. */
  2781. #define INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS \
  2782. (INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS * 2)
  2783. /** The minimum number of seconds that an introduction point will last
  2784. * before expiring due to old age. (If it receives
  2785. * INTRO_POINT_LIFETIME_INTRODUCTIONS INTRODUCE2 cells, it may expire
  2786. * sooner.)
  2787. *
  2788. * XXX Should this be configurable? */
  2789. #define INTRO_POINT_LIFETIME_MIN_SECONDS (18*60*60)
  2790. /** The maximum number of seconds that an introduction point will last
  2791. * before expiring due to old age.
  2792. *
  2793. * XXX Should this be configurable? */
  2794. #define INTRO_POINT_LIFETIME_MAX_SECONDS (24*60*60)
  2795. /** The maximum number of circuit creation retry we do to an intro point
  2796. * before giving up. We try to reuse intro point that fails during their
  2797. * lifetime so this is a hard limit on the amount of time we do that. */
  2798. #define MAX_INTRO_POINT_CIRCUIT_RETRIES 3
  2799. typedef struct rend_intro_point_t rend_intro_point_t;
  2800. typedef struct rend_service_descriptor_t rend_service_descriptor_t;
  2801. /********************************* routerlist.c ***************************/
  2802. typedef struct dir_server_t dir_server_t;
  2803. #define RELAY_REQUIRED_MIN_BANDWIDTH (75*1024)
  2804. #define BRIDGE_REQUIRED_MIN_BANDWIDTH (50*1024)
  2805. #define ROUTER_MAX_DECLARED_BANDWIDTH INT32_MAX
  2806. /* Flags for pick_directory_server() and pick_trusteddirserver(). */
  2807. /** Flag to indicate that we should not automatically be willing to use
  2808. * ourself to answer a directory request.
  2809. * Passed to router_pick_directory_server (et al).*/
  2810. #define PDS_ALLOW_SELF (1<<0)
  2811. /** Flag to indicate that if no servers seem to be up, we should mark all
  2812. * directory servers as up and try again.
  2813. * Passed to router_pick_directory_server (et al).*/
  2814. #define PDS_RETRY_IF_NO_SERVERS (1<<1)
  2815. /** Flag to indicate that we should not exclude directory servers that
  2816. * our ReachableAddress settings would exclude. This usually means that
  2817. * we're going to connect to the server over Tor, and so we don't need to
  2818. * worry about our firewall telling us we can't.
  2819. * Passed to router_pick_directory_server (et al).*/
  2820. #define PDS_IGNORE_FASCISTFIREWALL (1<<2)
  2821. /** Flag to indicate that we should not use any directory authority to which
  2822. * we have an existing directory connection for downloading server descriptors
  2823. * or extrainfo documents.
  2824. *
  2825. * Passed to router_pick_directory_server (et al)
  2826. */
  2827. #define PDS_NO_EXISTING_SERVERDESC_FETCH (1<<3)
  2828. /** Flag to indicate that we should not use any directory authority to which
  2829. * we have an existing directory connection for downloading microdescs.
  2830. *
  2831. * Passed to router_pick_directory_server (et al)
  2832. */
  2833. #define PDS_NO_EXISTING_MICRODESC_FETCH (1<<4)
  2834. /** Possible ways to weight routers when choosing one randomly. See
  2835. * routerlist_sl_choose_by_bandwidth() for more information.*/
  2836. typedef enum bandwidth_weight_rule_t {
  2837. NO_WEIGHTING, WEIGHT_FOR_EXIT, WEIGHT_FOR_MID, WEIGHT_FOR_GUARD,
  2838. WEIGHT_FOR_DIR
  2839. } bandwidth_weight_rule_t;
  2840. /** Flags to be passed to control router_choose_random_node() to indicate what
  2841. * kind of nodes to pick according to what algorithm. */
  2842. typedef enum {
  2843. CRN_NEED_UPTIME = 1<<0,
  2844. CRN_NEED_CAPACITY = 1<<1,
  2845. CRN_NEED_GUARD = 1<<2,
  2846. /* XXXX not used, apparently. */
  2847. CRN_WEIGHT_AS_EXIT = 1<<5,
  2848. CRN_NEED_DESC = 1<<6,
  2849. /* On clients, only provide nodes that satisfy ClientPreferIPv6OR */
  2850. CRN_PREF_ADDR = 1<<7,
  2851. /* On clients, only provide nodes that we can connect to directly, based on
  2852. * our firewall rules */
  2853. CRN_DIRECT_CONN = 1<<8,
  2854. /* On clients, only provide nodes with HSRend >= 2 protocol version which
  2855. * is required for hidden service version >= 3. */
  2856. CRN_RENDEZVOUS_V3 = 1<<9,
  2857. } router_crn_flags_t;
  2858. /** Return value for router_add_to_routerlist() and dirserv_add_descriptor() */
  2859. typedef enum was_router_added_t {
  2860. /* Router was added successfully. */
  2861. ROUTER_ADDED_SUCCESSFULLY = 1,
  2862. /* Extrainfo document was rejected because no corresponding router
  2863. * descriptor was found OR router descriptor was rejected because
  2864. * it was incompatible with its extrainfo document. */
  2865. ROUTER_BAD_EI = -1,
  2866. /* Router descriptor was rejected because it is already known. */
  2867. ROUTER_IS_ALREADY_KNOWN = -2,
  2868. /* General purpose router was rejected, because it was not listed
  2869. * in consensus. */
  2870. ROUTER_NOT_IN_CONSENSUS = -3,
  2871. /* Router was neither in directory consensus nor in any of
  2872. * networkstatus documents. Caching it to access later.
  2873. * (Applies to fetched descriptors only.) */
  2874. ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS = -4,
  2875. /* Router was rejected by directory authority. */
  2876. ROUTER_AUTHDIR_REJECTS = -5,
  2877. /* Bridge descriptor was rejected because such bridge was not one
  2878. * of the bridges we have listed in our configuration. */
  2879. ROUTER_WAS_NOT_WANTED = -6,
  2880. /* Router descriptor was rejected because it was older than
  2881. * OLD_ROUTER_DESC_MAX_AGE. */
  2882. ROUTER_WAS_TOO_OLD = -7, /* note contrast with 'NOT_NEW' */
  2883. /* DOCDOC */
  2884. ROUTER_CERTS_EXPIRED = -8
  2885. } was_router_added_t;
  2886. typedef struct tor_version_t tor_version_t;
  2887. #endif /* !defined(TOR_OR_H) */