or.h 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330
  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 "common/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 "common/crypto.h"
  61. #include "common/crypto_format.h"
  62. #include "common/crypto_dh.h"
  63. #include "common/crypto_hkdf.h"
  64. #include "common/tortls.h"
  65. #include "common/torlog.h"
  66. #include "common/container.h"
  67. #include "common/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 "common/crypto_curve25519.h"
  74. #include "common/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. /** Amount to increment a stream window when we get a stream SENDME. */
  814. #define STREAMWINDOW_INCREMENT 50
  815. /** Maximum number of queued cells on a circuit for which we are the
  816. * midpoint before we give up and kill it. This must be >= circwindow
  817. * to avoid killing innocent circuits, and >= circwindow*2 to give
  818. * leaky-pipe a chance of working someday. The ORCIRC_MAX_MIDDLE_KILL_THRESH
  819. * ratio controls the margin of error between emitting a warning and
  820. * killing the circuit.
  821. */
  822. #define ORCIRC_MAX_MIDDLE_CELLS (CIRCWINDOW_START_MAX*2)
  823. /** Ratio of hard (circuit kill) to soft (warning) thresholds for the
  824. * ORCIRC_MAX_MIDDLE_CELLS tests.
  825. */
  826. #define ORCIRC_MAX_MIDDLE_KILL_THRESH (1.1f)
  827. /* Cell commands. These values are defined in tor-spec.txt. */
  828. #define CELL_PADDING 0
  829. #define CELL_CREATE 1
  830. #define CELL_CREATED 2
  831. #define CELL_RELAY 3
  832. #define CELL_DESTROY 4
  833. #define CELL_CREATE_FAST 5
  834. #define CELL_CREATED_FAST 6
  835. #define CELL_VERSIONS 7
  836. #define CELL_NETINFO 8
  837. #define CELL_RELAY_EARLY 9
  838. #define CELL_CREATE2 10
  839. #define CELL_CREATED2 11
  840. #define CELL_PADDING_NEGOTIATE 12
  841. #define CELL_VPADDING 128
  842. #define CELL_CERTS 129
  843. #define CELL_AUTH_CHALLENGE 130
  844. #define CELL_AUTHENTICATE 131
  845. #define CELL_AUTHORIZE 132
  846. #define CELL_COMMAND_MAX_ 132
  847. /** How long to test reachability before complaining to the user. */
  848. #define TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT (20*60)
  849. /** Legal characters in a nickname. */
  850. #define LEGAL_NICKNAME_CHARACTERS \
  851. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  852. /** Name to use in client TLS certificates if no nickname is given. Once
  853. * Tor 0.1.2.x is obsolete, we can remove this. */
  854. #define DEFAULT_CLIENT_NICKNAME "client"
  855. /** Name chosen by routers that don't configure nicknames */
  856. #define UNNAMED_ROUTER_NICKNAME "Unnamed"
  857. /** Number of bytes in a SOCKS4 header. */
  858. #define SOCKS4_NETWORK_LEN 8
  859. /*
  860. * Relay payload:
  861. * Relay command [1 byte]
  862. * Recognized [2 bytes]
  863. * Stream ID [2 bytes]
  864. * Partial SHA-1 [4 bytes]
  865. * Length [2 bytes]
  866. * Relay payload [498 bytes]
  867. */
  868. /** Number of bytes in a cell, minus cell header. */
  869. #define CELL_PAYLOAD_SIZE 509
  870. /** Number of bytes in a cell transmitted over the network, in the longest
  871. * form */
  872. #define CELL_MAX_NETWORK_SIZE 514
  873. /** Maximum length of a header on a variable-length cell. */
  874. #define VAR_CELL_MAX_HEADER_SIZE 7
  875. static int get_cell_network_size(int wide_circ_ids);
  876. static inline int get_cell_network_size(int wide_circ_ids)
  877. {
  878. return wide_circ_ids ? CELL_MAX_NETWORK_SIZE : CELL_MAX_NETWORK_SIZE - 2;
  879. }
  880. static int get_var_cell_header_size(int wide_circ_ids);
  881. static inline int get_var_cell_header_size(int wide_circ_ids)
  882. {
  883. return wide_circ_ids ? VAR_CELL_MAX_HEADER_SIZE :
  884. VAR_CELL_MAX_HEADER_SIZE - 2;
  885. }
  886. static int get_circ_id_size(int wide_circ_ids);
  887. static inline int get_circ_id_size(int wide_circ_ids)
  888. {
  889. return wide_circ_ids ? 4 : 2;
  890. }
  891. /** Number of bytes in a relay cell's header (not including general cell
  892. * header). */
  893. #define RELAY_HEADER_SIZE (1+2+2+4+2)
  894. /** Largest number of bytes that can fit in a relay cell payload. */
  895. #define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE)
  896. /** Identifies a circuit on an or_connection */
  897. typedef uint32_t circid_t;
  898. /** Identifies a stream on a circuit */
  899. typedef uint16_t streamid_t;
  900. /* channel_t typedef; struct channel_s is in channel.h */
  901. typedef struct channel_s channel_t;
  902. /* channel_listener_t typedef; struct channel_listener_s is in channel.h */
  903. typedef struct channel_listener_s channel_listener_t;
  904. /* channel states for channel_t */
  905. typedef enum {
  906. /*
  907. * Closed state - channel is inactive
  908. *
  909. * Permitted transitions from:
  910. * - CHANNEL_STATE_CLOSING
  911. * Permitted transitions to:
  912. * - CHANNEL_STATE_OPENING
  913. */
  914. CHANNEL_STATE_CLOSED = 0,
  915. /*
  916. * Opening state - channel is trying to connect
  917. *
  918. * Permitted transitions from:
  919. * - CHANNEL_STATE_CLOSED
  920. * Permitted transitions to:
  921. * - CHANNEL_STATE_CLOSING
  922. * - CHANNEL_STATE_ERROR
  923. * - CHANNEL_STATE_OPEN
  924. */
  925. CHANNEL_STATE_OPENING,
  926. /*
  927. * Open state - channel is active and ready for use
  928. *
  929. * Permitted transitions from:
  930. * - CHANNEL_STATE_MAINT
  931. * - CHANNEL_STATE_OPENING
  932. * Permitted transitions to:
  933. * - CHANNEL_STATE_CLOSING
  934. * - CHANNEL_STATE_ERROR
  935. * - CHANNEL_STATE_MAINT
  936. */
  937. CHANNEL_STATE_OPEN,
  938. /*
  939. * Maintenance state - channel is temporarily offline for subclass specific
  940. * maintenance activities such as TLS renegotiation.
  941. *
  942. * Permitted transitions from:
  943. * - CHANNEL_STATE_OPEN
  944. * Permitted transitions to:
  945. * - CHANNEL_STATE_CLOSING
  946. * - CHANNEL_STATE_ERROR
  947. * - CHANNEL_STATE_OPEN
  948. */
  949. CHANNEL_STATE_MAINT,
  950. /*
  951. * Closing state - channel is shutting down
  952. *
  953. * Permitted transitions from:
  954. * - CHANNEL_STATE_MAINT
  955. * - CHANNEL_STATE_OPEN
  956. * Permitted transitions to:
  957. * - CHANNEL_STATE_CLOSED,
  958. * - CHANNEL_STATE_ERROR
  959. */
  960. CHANNEL_STATE_CLOSING,
  961. /*
  962. * Error state - channel has experienced a permanent error
  963. *
  964. * Permitted transitions from:
  965. * - CHANNEL_STATE_CLOSING
  966. * - CHANNEL_STATE_MAINT
  967. * - CHANNEL_STATE_OPENING
  968. * - CHANNEL_STATE_OPEN
  969. * Permitted transitions to:
  970. * - None
  971. */
  972. CHANNEL_STATE_ERROR,
  973. /*
  974. * Placeholder for maximum state value
  975. */
  976. CHANNEL_STATE_LAST
  977. } channel_state_t;
  978. /* channel listener states for channel_listener_t */
  979. typedef enum {
  980. /*
  981. * Closed state - channel listener is inactive
  982. *
  983. * Permitted transitions from:
  984. * - CHANNEL_LISTENER_STATE_CLOSING
  985. * Permitted transitions to:
  986. * - CHANNEL_LISTENER_STATE_LISTENING
  987. */
  988. CHANNEL_LISTENER_STATE_CLOSED = 0,
  989. /*
  990. * Listening state - channel listener is listening for incoming
  991. * connections
  992. *
  993. * Permitted transitions from:
  994. * - CHANNEL_LISTENER_STATE_CLOSED
  995. * Permitted transitions to:
  996. * - CHANNEL_LISTENER_STATE_CLOSING
  997. * - CHANNEL_LISTENER_STATE_ERROR
  998. */
  999. CHANNEL_LISTENER_STATE_LISTENING,
  1000. /*
  1001. * Closing state - channel listener is shutting down
  1002. *
  1003. * Permitted transitions from:
  1004. * - CHANNEL_LISTENER_STATE_LISTENING
  1005. * Permitted transitions to:
  1006. * - CHANNEL_LISTENER_STATE_CLOSED,
  1007. * - CHANNEL_LISTENER_STATE_ERROR
  1008. */
  1009. CHANNEL_LISTENER_STATE_CLOSING,
  1010. /*
  1011. * Error state - channel listener has experienced a permanent error
  1012. *
  1013. * Permitted transitions from:
  1014. * - CHANNEL_STATE_CLOSING
  1015. * - CHANNEL_STATE_LISTENING
  1016. * Permitted transitions to:
  1017. * - None
  1018. */
  1019. CHANNEL_LISTENER_STATE_ERROR,
  1020. /*
  1021. * Placeholder for maximum state value
  1022. */
  1023. CHANNEL_LISTENER_STATE_LAST
  1024. } channel_listener_state_t;
  1025. /* TLS channel stuff */
  1026. typedef struct channel_tls_s channel_tls_t;
  1027. /* circuitmux_t typedef; struct circuitmux_s is in circuitmux.h */
  1028. typedef struct circuitmux_s circuitmux_t;
  1029. typedef struct cell_t cell_t;
  1030. typedef struct var_cell_t var_cell_t;
  1031. typedef struct packed_cell_t packed_cell_t;
  1032. typedef struct cell_queue_t cell_queue_t;
  1033. typedef struct destroy_cell_t destroy_cell_t;
  1034. typedef struct destroy_cell_queue_t destroy_cell_queue_t;
  1035. /** A parsed Extended ORPort message. */
  1036. typedef struct ext_or_cmd_t {
  1037. uint16_t cmd; /** Command type */
  1038. uint16_t len; /** Body length */
  1039. char body[FLEXIBLE_ARRAY_MEMBER]; /** Message body */
  1040. } ext_or_cmd_t;
  1041. /** Beginning of a RELAY cell payload. */
  1042. typedef struct {
  1043. uint8_t command; /**< The end-to-end relay command. */
  1044. uint16_t recognized; /**< Used to tell whether cell is for us. */
  1045. streamid_t stream_id; /**< Which stream is this cell associated with? */
  1046. char integrity[4]; /**< Used to tell whether cell is corrupted. */
  1047. uint16_t length; /**< How long is the payload body? */
  1048. } relay_header_t;
  1049. typedef struct socks_request_t socks_request_t;
  1050. typedef struct entry_port_cfg_t entry_port_cfg_t;
  1051. typedef struct server_port_cfg_t server_port_cfg_t;
  1052. /* Values for connection_t.magic: used to make sure that downcasts (casts from
  1053. * connection_t to foo_connection_t) are safe. */
  1054. #define BASE_CONNECTION_MAGIC 0x7C3C304Eu
  1055. #define OR_CONNECTION_MAGIC 0x7D31FF03u
  1056. #define EDGE_CONNECTION_MAGIC 0xF0374013u
  1057. #define ENTRY_CONNECTION_MAGIC 0xbb4a5703
  1058. #define DIR_CONNECTION_MAGIC 0x9988ffeeu
  1059. #define CONTROL_CONNECTION_MAGIC 0x8abc765du
  1060. #define LISTENER_CONNECTION_MAGIC 0x1a1ac741u
  1061. /** Minimum length of the random part of an AUTH_CHALLENGE cell. */
  1062. #define OR_AUTH_CHALLENGE_LEN 32
  1063. /**
  1064. * @name Certificate types for CERTS cells.
  1065. *
  1066. * These values are defined by the protocol, and affect how an X509
  1067. * certificate in a CERTS cell is interpreted and used.
  1068. *
  1069. * @{ */
  1070. /** A certificate that authenticates a TLS link key. The subject key
  1071. * must match the key used in the TLS handshake; it must be signed by
  1072. * the identity key. */
  1073. #define OR_CERT_TYPE_TLS_LINK 1
  1074. /** A self-signed identity certificate. The subject key must be a
  1075. * 1024-bit RSA key. */
  1076. #define OR_CERT_TYPE_ID_1024 2
  1077. /** A certificate that authenticates a key used in an AUTHENTICATE cell
  1078. * in the v3 handshake. The subject key must be a 1024-bit RSA key; it
  1079. * must be signed by the identity key */
  1080. #define OR_CERT_TYPE_AUTH_1024 3
  1081. /* DOCDOC */
  1082. #define OR_CERT_TYPE_RSA_ED_CROSSCERT 7
  1083. /**@}*/
  1084. /** The first supported type of AUTHENTICATE cell. It contains
  1085. * a bunch of structures signed with an RSA1024 key. The signed
  1086. * structures include a HMAC using negotiated TLS secrets, and a digest
  1087. * of all cells sent or received before the AUTHENTICATE cell (including
  1088. * the random server-generated AUTH_CHALLENGE cell).
  1089. */
  1090. #define AUTHTYPE_RSA_SHA256_TLSSECRET 1
  1091. /** As AUTHTYPE_RSA_SHA256_TLSSECRET, but instead of using the
  1092. * negotiated TLS secrets, uses exported keying material from the TLS
  1093. * session as described in RFC 5705.
  1094. *
  1095. * Not used by today's tors, since everything that supports this
  1096. * also supports ED25519_SHA256_5705, which is better.
  1097. **/
  1098. #define AUTHTYPE_RSA_SHA256_RFC5705 2
  1099. /** As AUTHTYPE_RSA_SHA256_RFC5705, but uses an Ed25519 identity key to
  1100. * authenticate. */
  1101. #define AUTHTYPE_ED25519_SHA256_RFC5705 3
  1102. /*
  1103. * NOTE: authchallenge_type_is_better() relies on these AUTHTYPE codes
  1104. * being sorted in order of preference. If we someday add one with
  1105. * a higher numerical value that we don't like as much, we should revise
  1106. * authchallenge_type_is_better().
  1107. */
  1108. /** The length of the part of the AUTHENTICATE cell body that the client and
  1109. * server can generate independently (when using RSA_SHA256_TLSSECRET). It
  1110. * contains everything except the client's timestamp, the client's randomly
  1111. * generated nonce, and the signature. */
  1112. #define V3_AUTH_FIXED_PART_LEN (8+(32*6))
  1113. /** The length of the part of the AUTHENTICATE cell body that the client
  1114. * signs. */
  1115. #define V3_AUTH_BODY_LEN (V3_AUTH_FIXED_PART_LEN + 8 + 16)
  1116. typedef struct or_handshake_certs_t or_handshake_certs_t;
  1117. typedef struct or_handshake_state_t or_handshake_state_t;
  1118. /** Length of Extended ORPort connection identifier. */
  1119. #define EXT_OR_CONN_ID_LEN DIGEST_LEN /* 20 */
  1120. /*
  1121. * OR_CONN_HIGHWATER and OR_CONN_LOWWATER moved from connection_or.c so
  1122. * channeltls.c can see them too.
  1123. */
  1124. /** When adding cells to an OR connection's outbuf, keep adding until the
  1125. * outbuf is at least this long, or we run out of cells. */
  1126. #define OR_CONN_HIGHWATER (32*1024)
  1127. /** Add cells to an OR connection's outbuf whenever the outbuf's data length
  1128. * drops below this size. */
  1129. #define OR_CONN_LOWWATER (16*1024)
  1130. typedef struct connection_t connection_t;
  1131. typedef struct control_connection_t control_connection_t;
  1132. typedef struct dir_connection_t dir_connection_t;
  1133. typedef struct edge_connection_t edge_connection_t;
  1134. typedef struct entry_connection_t entry_connection_t;
  1135. typedef struct listener_connection_t listener_connection_t;
  1136. typedef struct or_connection_t or_connection_t;
  1137. /** Cast a connection_t subtype pointer to a connection_t **/
  1138. #define TO_CONN(c) (&(((c)->base_)))
  1139. /** Cast a entry_connection_t subtype pointer to a connection_t **/
  1140. #define ENTRY_TO_CONN(c) (TO_CONN(ENTRY_TO_EDGE_CONN(c)))
  1141. /** What action type does an address policy indicate: accept or reject? */
  1142. typedef enum {
  1143. ADDR_POLICY_ACCEPT=1,
  1144. ADDR_POLICY_REJECT=2,
  1145. } addr_policy_action_t;
  1146. #define addr_policy_action_bitfield_t ENUM_BF(addr_policy_action_t)
  1147. /** A reference-counted address policy rule. */
  1148. typedef struct addr_policy_t {
  1149. int refcnt; /**< Reference count */
  1150. /** What to do when the policy matches.*/
  1151. addr_policy_action_bitfield_t policy_type:2;
  1152. unsigned int is_private:1; /**< True iff this is the pseudo-address,
  1153. * "private". */
  1154. unsigned int is_canonical:1; /**< True iff this policy is the canonical
  1155. * copy (stored in a hash table to avoid
  1156. * duplication of common policies) */
  1157. maskbits_t maskbits; /**< Accept/reject all addresses <b>a</b> such that the
  1158. * first <b>maskbits</b> bits of <b>a</b> match
  1159. * <b>addr</b>. */
  1160. /** Base address to accept or reject.
  1161. *
  1162. * Note that wildcards are treated
  1163. * differntly depending on address family. An AF_UNSPEC address means
  1164. * "All addresses, IPv4 or IPv6." An AF_INET address with maskbits==0 means
  1165. * "All IPv4 addresses" and an AF_INET6 address with maskbits == 0 means
  1166. * "All IPv6 addresses".
  1167. **/
  1168. tor_addr_t addr;
  1169. uint16_t prt_min; /**< Lowest port number to accept/reject. */
  1170. uint16_t prt_max; /**< Highest port number to accept/reject. */
  1171. } addr_policy_t;
  1172. typedef struct cached_dir_t cached_dir_t;
  1173. /** Enum used to remember where a signed_descriptor_t is stored and how to
  1174. * manage the memory for signed_descriptor_body. */
  1175. typedef enum {
  1176. /** The descriptor isn't stored on disk at all: the copy in memory is
  1177. * canonical; the saved_offset field is meaningless. */
  1178. SAVED_NOWHERE=0,
  1179. /** The descriptor is stored in the cached_routers file: the
  1180. * signed_descriptor_body is meaningless; the signed_descriptor_len and
  1181. * saved_offset are used to index into the mmaped cache file. */
  1182. SAVED_IN_CACHE,
  1183. /** The descriptor is stored in the cached_routers.new file: the
  1184. * signed_descriptor_body and saved_offset fields are both set. */
  1185. /* FFFF (We could also mmap the file and grow the mmap as needed, or
  1186. * lazy-load the descriptor text by using seek and read. We don't, for
  1187. * now.)
  1188. */
  1189. SAVED_IN_JOURNAL
  1190. } saved_location_t;
  1191. #define saved_location_bitfield_t ENUM_BF(saved_location_t)
  1192. /** Enumeration: what directory object is being downloaded?
  1193. * This determines which schedule is selected to perform the download. */
  1194. typedef enum {
  1195. DL_SCHED_GENERIC = 0,
  1196. DL_SCHED_CONSENSUS = 1,
  1197. DL_SCHED_BRIDGE = 2,
  1198. } download_schedule_t;
  1199. #define download_schedule_bitfield_t ENUM_BF(download_schedule_t)
  1200. /** Enumeration: is the download schedule for downloading from an authority,
  1201. * or from any available directory mirror?
  1202. * During bootstrap, "any" means a fallback (or an authority, if there
  1203. * are no fallbacks).
  1204. * When we have a valid consensus, "any" means any directory server. */
  1205. typedef enum {
  1206. DL_WANT_ANY_DIRSERVER = 0,
  1207. DL_WANT_AUTHORITY = 1,
  1208. } download_want_authority_t;
  1209. #define download_want_authority_bitfield_t \
  1210. ENUM_BF(download_want_authority_t)
  1211. /** Enumeration: do we want to increment the schedule position each time a
  1212. * connection is attempted (these attempts can be concurrent), or do we want
  1213. * to increment the schedule position after a connection fails? */
  1214. typedef enum {
  1215. DL_SCHED_INCREMENT_FAILURE = 0,
  1216. DL_SCHED_INCREMENT_ATTEMPT = 1,
  1217. } download_schedule_increment_t;
  1218. #define download_schedule_increment_bitfield_t \
  1219. ENUM_BF(download_schedule_increment_t)
  1220. typedef struct download_status_t download_status_t;
  1221. /** If n_download_failures is this high, the download can never happen. */
  1222. #define IMPOSSIBLE_TO_DOWNLOAD 255
  1223. /** The max size we expect router descriptor annotations we create to
  1224. * be. We'll accept larger ones if we see them on disk, but we won't
  1225. * create any that are larger than this. */
  1226. #define ROUTER_ANNOTATION_BUF_LEN 256
  1227. typedef struct signed_descriptor_t signed_descriptor_t;
  1228. /** A signed integer representing a country code. */
  1229. typedef int16_t country_t;
  1230. /** Flags used to summarize the declared protocol versions of a relay,
  1231. * so we don't need to parse them again and again. */
  1232. typedef struct protover_summary_flags_t {
  1233. /** True iff we have a proto line for this router, or a versions line
  1234. * from which we could infer the protocols. */
  1235. unsigned int protocols_known:1;
  1236. /** True iff this router has a version or protocol list that allows it to
  1237. * accept EXTEND2 cells. This requires Relay=2. */
  1238. unsigned int supports_extend2_cells:1;
  1239. /** True iff this router has a protocol list that allows it to negotiate
  1240. * ed25519 identity keys on a link handshake with us. This
  1241. * requires LinkAuth=3. */
  1242. unsigned int supports_ed25519_link_handshake_compat:1;
  1243. /** True iff this router has a protocol list that allows it to negotiate
  1244. * ed25519 identity keys on a link handshake, at all. This requires some
  1245. * LinkAuth=X for X >= 3. */
  1246. unsigned int supports_ed25519_link_handshake_any:1;
  1247. /** True iff this router has a protocol list that allows it to be an
  1248. * introduction point supporting ed25519 authentication key which is part of
  1249. * the v3 protocol detailed in proposal 224. This requires HSIntro=4. */
  1250. unsigned int supports_ed25519_hs_intro : 1;
  1251. /** True iff this router has a protocol list that allows it to be an hidden
  1252. * service directory supporting version 3 as seen in proposal 224. This
  1253. * requires HSDir=2. */
  1254. unsigned int supports_v3_hsdir : 1;
  1255. /** True iff this router has a protocol list that allows it to be an hidden
  1256. * service rendezvous point supporting version 3 as seen in proposal 224.
  1257. * This requires HSRend=2. */
  1258. unsigned int supports_v3_rendezvous_point: 1;
  1259. } protover_summary_flags_t;
  1260. typedef struct routerinfo_t routerinfo_t;
  1261. typedef struct extrainfo_t extrainfo_t;
  1262. typedef struct routerstatus_t routerstatus_t;
  1263. /** A single entry in a parsed policy summary, describing a range of ports. */
  1264. typedef struct short_policy_entry_t {
  1265. uint16_t min_port, max_port;
  1266. } short_policy_entry_t;
  1267. /** A short_poliy_t is the parsed version of a policy summary. */
  1268. typedef struct short_policy_t {
  1269. /** True if the members of 'entries' are port ranges to accept; false if
  1270. * they are port ranges to reject */
  1271. unsigned int is_accept : 1;
  1272. /** The actual number of values in 'entries'. */
  1273. unsigned int n_entries : 31;
  1274. /** An array of 0 or more short_policy_entry_t values, each describing a
  1275. * range of ports that this policy accepts or rejects (depending on the
  1276. * value of is_accept).
  1277. */
  1278. short_policy_entry_t entries[FLEXIBLE_ARRAY_MEMBER];
  1279. } short_policy_t;
  1280. typedef struct microdesc_t microdesc_t;
  1281. typedef struct node_t node_t;
  1282. typedef struct vote_microdesc_hash_t vote_microdesc_hash_t;
  1283. typedef struct vote_routerstatus_t vote_routerstatus_t;
  1284. typedef struct document_signature_t document_signature_t;
  1285. typedef struct networkstatus_voter_info_t networkstatus_voter_info_t;
  1286. typedef struct networkstatus_sr_info_t networkstatus_sr_info_t;
  1287. /** Enumerates the possible seriousness values of a networkstatus document. */
  1288. typedef enum {
  1289. NS_TYPE_VOTE,
  1290. NS_TYPE_CONSENSUS,
  1291. NS_TYPE_OPINION,
  1292. } networkstatus_type_t;
  1293. /** Enumerates recognized flavors of a consensus networkstatus document. All
  1294. * flavors of a consensus are generated from the same set of votes, but they
  1295. * present different types information to different versions of Tor. */
  1296. typedef enum {
  1297. FLAV_NS = 0,
  1298. FLAV_MICRODESC = 1,
  1299. } consensus_flavor_t;
  1300. /** How many different consensus flavors are there? */
  1301. #define N_CONSENSUS_FLAVORS ((int)(FLAV_MICRODESC)+1)
  1302. typedef struct networkstatus_t networkstatus_t;
  1303. typedef struct ns_detached_signatures_t ns_detached_signatures_t;
  1304. /** Allowable types of desc_store_t. */
  1305. typedef enum store_type_t {
  1306. ROUTER_STORE = 0,
  1307. EXTRAINFO_STORE = 1
  1308. } store_type_t;
  1309. typedef struct desc_store_t desc_store_t;
  1310. typedef struct routerlist_t routerlist_t;
  1311. typedef struct extend_info_t extend_info_t;
  1312. typedef struct authority_cert_t authority_cert_t;
  1313. /** Bitfield enum type listing types of information that directory authorities
  1314. * can be authoritative about, and that directory caches may or may not cache.
  1315. *
  1316. * Note that the granularity here is based on authority granularity and on
  1317. * cache capabilities. Thus, one particular bit may correspond in practice to
  1318. * a few types of directory info, so long as every authority that pronounces
  1319. * officially about one of the types prounounces officially about all of them,
  1320. * and so long as every cache that caches one of them caches all of them.
  1321. */
  1322. typedef enum {
  1323. NO_DIRINFO = 0,
  1324. /** Serves/signs v3 directory information: votes, consensuses, certs */
  1325. V3_DIRINFO = 1 << 2,
  1326. /** Serves bridge descriptors. */
  1327. BRIDGE_DIRINFO = 1 << 4,
  1328. /** Serves extrainfo documents. */
  1329. EXTRAINFO_DIRINFO=1 << 5,
  1330. /** Serves microdescriptors. */
  1331. MICRODESC_DIRINFO=1 << 6,
  1332. } dirinfo_type_t;
  1333. #define ALL_DIRINFO ((dirinfo_type_t)((1<<7)-1))
  1334. #define CRYPT_PATH_MAGIC 0x70127012u
  1335. struct fast_handshake_state_t;
  1336. struct ntor_handshake_state_t;
  1337. #define ONION_HANDSHAKE_TYPE_TAP 0x0000
  1338. #define ONION_HANDSHAKE_TYPE_FAST 0x0001
  1339. #define ONION_HANDSHAKE_TYPE_NTOR 0x0002
  1340. #define MAX_ONION_HANDSHAKE_TYPE 0x0002
  1341. typedef struct {
  1342. uint16_t tag;
  1343. union {
  1344. struct fast_handshake_state_t *fast;
  1345. crypto_dh_t *tap;
  1346. struct ntor_handshake_state_t *ntor;
  1347. } u;
  1348. } onion_handshake_state_t;
  1349. typedef struct relay_crypto_t relay_crypto_t;
  1350. typedef struct crypt_path_t crypt_path_t;
  1351. typedef struct crypt_path_reference_t crypt_path_reference_t;
  1352. #define CPATH_KEY_MATERIAL_LEN (20*2+16*2)
  1353. #define DH_KEY_LEN DH_BYTES
  1354. typedef struct cpath_build_state_t cpath_build_state_t;
  1355. /** "magic" value for an origin_circuit_t */
  1356. #define ORIGIN_CIRCUIT_MAGIC 0x35315243u
  1357. /** "magic" value for an or_circuit_t */
  1358. #define OR_CIRCUIT_MAGIC 0x98ABC04Fu
  1359. /** "magic" value for a circuit that would have been freed by circuit_free,
  1360. * but which we're keeping around until a cpuworker reply arrives. See
  1361. * circuit_free() for more documentation. */
  1362. #define DEAD_CIRCUIT_MAGIC 0xdeadc14c
  1363. struct create_cell_t;
  1364. /** Entry in the cell stats list of a circuit; used only if CELL_STATS
  1365. * events are enabled. */
  1366. typedef struct testing_cell_stats_entry_t {
  1367. uint8_t command; /**< cell command number. */
  1368. /** Waiting time in centiseconds if this event is for a removed cell,
  1369. * or 0 if this event is for adding a cell to the queue. 22 bits can
  1370. * store more than 11 hours, enough to assume that a circuit with this
  1371. * delay would long have been closed. */
  1372. unsigned int waiting_time:22;
  1373. unsigned int removed:1; /**< 0 for added to, 1 for removed from queue. */
  1374. unsigned int exitward:1; /**< 0 for app-ward, 1 for exit-ward. */
  1375. } testing_cell_stats_entry_t;
  1376. typedef struct circuit_t circuit_t;
  1377. typedef struct origin_circuit_t origin_circuit_t;
  1378. typedef struct or_circuit_t or_circuit_t;
  1379. /** Largest number of relay_early cells that we can send on a given
  1380. * circuit. */
  1381. #define MAX_RELAY_EARLY_CELLS_PER_CIRCUIT 8
  1382. /**
  1383. * Describes the circuit building process in simplified terms based
  1384. * on the path bias accounting state for a circuit.
  1385. *
  1386. * NOTE: These state values are enumerated in the order for which we
  1387. * expect circuits to transition through them. If you add states,
  1388. * you need to preserve this overall ordering. The various pathbias
  1389. * state transition and accounting functions (pathbias_mark_* and
  1390. * pathbias_count_*) contain ordinal comparisons to enforce proper
  1391. * state transitions for corrections.
  1392. *
  1393. * This state machine and the associated logic was created to prevent
  1394. * miscounting due to unknown cases of circuit reuse. See also tickets
  1395. * #6475 and #7802.
  1396. */
  1397. typedef enum {
  1398. /** This circuit is "new". It has not yet completed a first hop
  1399. * or been counted by the path bias code. */
  1400. PATH_STATE_NEW_CIRC = 0,
  1401. /** This circuit has completed one/two hops, and has been counted by
  1402. * the path bias logic. */
  1403. PATH_STATE_BUILD_ATTEMPTED = 1,
  1404. /** This circuit has been completely built */
  1405. PATH_STATE_BUILD_SUCCEEDED = 2,
  1406. /** Did we try to attach any SOCKS streams or hidserv introductions to
  1407. * this circuit?
  1408. *
  1409. * Note: If we ever implement end-to-end stream timing through test
  1410. * stream probes (#5707), we must *not* set this for those probes
  1411. * (or any other automatic streams) because the adversary could
  1412. * just tag at a later point.
  1413. */
  1414. PATH_STATE_USE_ATTEMPTED = 3,
  1415. /** Did any SOCKS streams or hidserv introductions actually succeed on
  1416. * this circuit?
  1417. *
  1418. * If any streams detatch/fail from this circuit, the code transitions
  1419. * the circuit back to PATH_STATE_USE_ATTEMPTED to ensure we probe. See
  1420. * pathbias_mark_use_rollback() for that.
  1421. */
  1422. PATH_STATE_USE_SUCCEEDED = 4,
  1423. /**
  1424. * This is a special state to indicate that we got a corrupted
  1425. * relay cell on a circuit and we don't intend to probe it.
  1426. */
  1427. PATH_STATE_USE_FAILED = 5,
  1428. /**
  1429. * This is a special state to indicate that we already counted
  1430. * the circuit. Used to guard against potential state machine
  1431. * violations.
  1432. */
  1433. PATH_STATE_ALREADY_COUNTED = 6,
  1434. } path_state_t;
  1435. #define path_state_bitfield_t ENUM_BF(path_state_t)
  1436. #if REND_COOKIE_LEN != DIGEST_LEN
  1437. #error "The REND_TOKEN_LEN macro assumes REND_COOKIE_LEN == DIGEST_LEN"
  1438. #endif
  1439. #define REND_TOKEN_LEN DIGEST_LEN
  1440. /** Convert a circuit subtype to a circuit_t. */
  1441. #define TO_CIRCUIT(x) (&((x)->base_))
  1442. /* limits for TCP send and recv buffer size used for constrained sockets */
  1443. #define MIN_CONSTRAINED_TCP_BUFFER 2048
  1444. #define MAX_CONSTRAINED_TCP_BUFFER 262144 /* 256k */
  1445. /** @name Isolation flags
  1446. Ways to isolate client streams
  1447. @{
  1448. */
  1449. /** Isolate based on destination port */
  1450. #define ISO_DESTPORT (1u<<0)
  1451. /** Isolate based on destination address */
  1452. #define ISO_DESTADDR (1u<<1)
  1453. /** Isolate based on SOCKS authentication */
  1454. #define ISO_SOCKSAUTH (1u<<2)
  1455. /** Isolate based on client protocol choice */
  1456. #define ISO_CLIENTPROTO (1u<<3)
  1457. /** Isolate based on client address */
  1458. #define ISO_CLIENTADDR (1u<<4)
  1459. /** Isolate based on session group (always on). */
  1460. #define ISO_SESSIONGRP (1u<<5)
  1461. /** Isolate based on newnym epoch (always on). */
  1462. #define ISO_NYM_EPOCH (1u<<6)
  1463. /** Isolate all streams (Internal only). */
  1464. #define ISO_STREAM (1u<<7)
  1465. /**@}*/
  1466. /** Default isolation level for ports. */
  1467. #define ISO_DEFAULT (ISO_CLIENTADDR|ISO_SOCKSAUTH|ISO_SESSIONGRP|ISO_NYM_EPOCH)
  1468. /** Indicates that we haven't yet set a session group on a port_cfg_t. */
  1469. #define SESSION_GROUP_UNSET -1
  1470. /** Session group reserved for directory connections */
  1471. #define SESSION_GROUP_DIRCONN -2
  1472. /** Session group reserved for resolve requests launched by a controller */
  1473. #define SESSION_GROUP_CONTROL_RESOLVE -3
  1474. /** First automatically allocated session group number */
  1475. #define SESSION_GROUP_FIRST_AUTO -4
  1476. typedef struct port_cfg_t port_cfg_t;
  1477. typedef struct routerset_t routerset_t;
  1478. /** A magic value for the (Socks|OR|...)Port options below, telling Tor
  1479. * to pick its own port. */
  1480. #define CFG_AUTO_PORT 0xc4005e
  1481. /** Enumeration of outbound address configuration types:
  1482. * Exit-only, OR-only, or both */
  1483. typedef enum {OUTBOUND_ADDR_EXIT, OUTBOUND_ADDR_OR,
  1484. OUTBOUND_ADDR_EXIT_AND_OR,
  1485. OUTBOUND_ADDR_MAX} outbound_addr_t;
  1486. /** Configuration options for a Tor process. */
  1487. typedef struct {
  1488. uint32_t magic_;
  1489. /** What should the tor process actually do? */
  1490. enum {
  1491. CMD_RUN_TOR=0, CMD_LIST_FINGERPRINT, CMD_HASH_PASSWORD,
  1492. CMD_VERIFY_CONFIG, CMD_RUN_UNITTESTS, CMD_DUMP_CONFIG,
  1493. CMD_KEYGEN,
  1494. CMD_KEY_EXPIRATION,
  1495. } command;
  1496. char *command_arg; /**< Argument for command-line option. */
  1497. config_line_t *Logs; /**< New-style list of configuration lines
  1498. * for logs */
  1499. int LogTimeGranularity; /**< Log resolution in milliseconds. */
  1500. int LogMessageDomains; /**< Boolean: Should we log the domain(s) in which
  1501. * each log message occurs? */
  1502. int TruncateLogFile; /**< Boolean: Should we truncate the log file
  1503. before we start writing? */
  1504. char *SyslogIdentityTag; /**< Identity tag to add for syslog logging. */
  1505. char *AndroidIdentityTag; /**< Identity tag to add for Android logging. */
  1506. char *DebugLogFile; /**< Where to send verbose log messages. */
  1507. char *DataDirectory_option; /**< Where to store long-term data, as
  1508. * configured by the user. */
  1509. char *DataDirectory; /**< Where to store long-term data, as modified. */
  1510. int DataDirectoryGroupReadable; /**< Boolean: Is the DataDirectory g+r? */
  1511. char *KeyDirectory_option; /**< Where to store keys, as
  1512. * configured by the user. */
  1513. char *KeyDirectory; /**< Where to store keys data, as modified. */
  1514. int KeyDirectoryGroupReadable; /**< Boolean: Is the KeyDirectory g+r? */
  1515. char *CacheDirectory_option; /**< Where to store cached data, as
  1516. * configured by the user. */
  1517. char *CacheDirectory; /**< Where to store cached data, as modified. */
  1518. int CacheDirectoryGroupReadable; /**< Boolean: Is the CacheDirectory g+r? */
  1519. char *Nickname; /**< OR only: nickname of this onion router. */
  1520. char *Address; /**< OR only: configured address for this onion router. */
  1521. char *PidFile; /**< Where to store PID of Tor process. */
  1522. routerset_t *ExitNodes; /**< Structure containing nicknames, digests,
  1523. * country codes and IP address patterns of ORs to
  1524. * consider as exits. */
  1525. routerset_t *EntryNodes;/**< Structure containing nicknames, digests,
  1526. * country codes and IP address patterns of ORs to
  1527. * consider as entry points. */
  1528. int StrictNodes; /**< Boolean: When none of our EntryNodes or ExitNodes
  1529. * are up, or we need to access a node in ExcludeNodes,
  1530. * do we just fail instead? */
  1531. routerset_t *ExcludeNodes;/**< Structure containing nicknames, digests,
  1532. * country codes and IP address patterns of ORs
  1533. * not to use in circuits. But see StrictNodes
  1534. * above. */
  1535. routerset_t *ExcludeExitNodes;/**< Structure containing nicknames, digests,
  1536. * country codes and IP address patterns of
  1537. * ORs not to consider as exits. */
  1538. /** Union of ExcludeNodes and ExcludeExitNodes */
  1539. routerset_t *ExcludeExitNodesUnion_;
  1540. int DisableAllSwap; /**< Boolean: Attempt to call mlockall() on our
  1541. * process for all current and future memory. */
  1542. config_line_t *ExitPolicy; /**< Lists of exit policy components. */
  1543. int ExitPolicyRejectPrivate; /**< Should we not exit to reserved private
  1544. * addresses, and our own published addresses?
  1545. */
  1546. int ExitPolicyRejectLocalInterfaces; /**< Should we not exit to local
  1547. * interface addresses?
  1548. * Includes OutboundBindAddresses and
  1549. * configured ports. */
  1550. int ReducedExitPolicy; /**<Should we use the Reduced Exit Policy? */
  1551. config_line_t *SocksPolicy; /**< Lists of socks policy components */
  1552. config_line_t *DirPolicy; /**< Lists of dir policy components */
  1553. /** Local address to bind outbound sockets */
  1554. config_line_t *OutboundBindAddress;
  1555. /** Local address to bind outbound relay sockets */
  1556. config_line_t *OutboundBindAddressOR;
  1557. /** Local address to bind outbound exit sockets */
  1558. config_line_t *OutboundBindAddressExit;
  1559. /** Addresses derived from the various OutboundBindAddress lines.
  1560. * [][0] is IPv4, [][1] is IPv6
  1561. */
  1562. tor_addr_t OutboundBindAddresses[OUTBOUND_ADDR_MAX][2];
  1563. /** Directory server only: which versions of
  1564. * Tor should we tell users to run? */
  1565. config_line_t *RecommendedVersions;
  1566. config_line_t *RecommendedClientVersions;
  1567. config_line_t *RecommendedServerVersions;
  1568. config_line_t *RecommendedPackages;
  1569. /** Whether dirservers allow router descriptors with private IPs. */
  1570. int DirAllowPrivateAddresses;
  1571. /** Whether routers accept EXTEND cells to routers with private IPs. */
  1572. int ExtendAllowPrivateAddresses;
  1573. char *User; /**< Name of user to run Tor as. */
  1574. config_line_t *ORPort_lines; /**< Ports to listen on for OR connections. */
  1575. /** Ports to listen on for extended OR connections. */
  1576. config_line_t *ExtORPort_lines;
  1577. /** Ports to listen on for SOCKS connections. */
  1578. config_line_t *SocksPort_lines;
  1579. /** Ports to listen on for transparent pf/netfilter connections. */
  1580. config_line_t *TransPort_lines;
  1581. char *TransProxyType; /**< What kind of transparent proxy
  1582. * implementation are we using? */
  1583. /** Parsed value of TransProxyType. */
  1584. enum {
  1585. TPT_DEFAULT,
  1586. TPT_PF_DIVERT,
  1587. TPT_IPFW,
  1588. TPT_TPROXY,
  1589. } TransProxyType_parsed;
  1590. config_line_t *NATDPort_lines; /**< Ports to listen on for transparent natd
  1591. * connections. */
  1592. /** Ports to listen on for HTTP Tunnel connections. */
  1593. config_line_t *HTTPTunnelPort_lines;
  1594. config_line_t *ControlPort_lines; /**< Ports to listen on for control
  1595. * connections. */
  1596. config_line_t *ControlSocket; /**< List of Unix Domain Sockets to listen on
  1597. * for control connections. */
  1598. int ControlSocketsGroupWritable; /**< Boolean: Are control sockets g+rw? */
  1599. int UnixSocksGroupWritable; /**< Boolean: Are SOCKS Unix sockets g+rw? */
  1600. /** Ports to listen on for directory connections. */
  1601. config_line_t *DirPort_lines;
  1602. config_line_t *DNSPort_lines; /**< Ports to listen on for DNS requests. */
  1603. /* MaxMemInQueues value as input by the user. We clean this up to be
  1604. * MaxMemInQueues. */
  1605. uint64_t MaxMemInQueues_raw;
  1606. uint64_t MaxMemInQueues;/**< If we have more memory than this allocated
  1607. * for queues and buffers, run the OOM handler */
  1608. /** Above this value, consider ourselves low on RAM. */
  1609. uint64_t MaxMemInQueues_low_threshold;
  1610. /** @name port booleans
  1611. *
  1612. * Derived booleans: For server ports and ControlPort, true iff there is a
  1613. * non-listener port on an AF_INET or AF_INET6 address of the given type
  1614. * configured in one of the _lines options above.
  1615. * For client ports, also true if there is a unix socket configured.
  1616. * If you are checking for client ports, you may want to use:
  1617. * SocksPort_set || TransPort_set || NATDPort_set || DNSPort_set ||
  1618. * HTTPTunnelPort_set
  1619. * rather than SocksPort_set.
  1620. *
  1621. * @{
  1622. */
  1623. unsigned int ORPort_set : 1;
  1624. unsigned int SocksPort_set : 1;
  1625. unsigned int TransPort_set : 1;
  1626. unsigned int NATDPort_set : 1;
  1627. unsigned int ControlPort_set : 1;
  1628. unsigned int DirPort_set : 1;
  1629. unsigned int DNSPort_set : 1;
  1630. unsigned int ExtORPort_set : 1;
  1631. unsigned int HTTPTunnelPort_set : 1;
  1632. /**@}*/
  1633. int AssumeReachable; /**< Whether to publish our descriptor regardless. */
  1634. int AuthoritativeDir; /**< Boolean: is this an authoritative directory? */
  1635. int V3AuthoritativeDir; /**< Boolean: is this an authoritative directory
  1636. * for version 3 directories? */
  1637. int VersioningAuthoritativeDir; /**< Boolean: is this an authoritative
  1638. * directory that's willing to recommend
  1639. * versions? */
  1640. int BridgeAuthoritativeDir; /**< Boolean: is this an authoritative directory
  1641. * that aggregates bridge descriptors? */
  1642. /** If set on a bridge relay, it will include this value on a new
  1643. * "bridge-distribution-request" line in its bridge descriptor. */
  1644. char *BridgeDistribution;
  1645. /** If set on a bridge authority, it will answer requests on its dirport
  1646. * for bridge statuses -- but only if the requests use this password. */
  1647. char *BridgePassword;
  1648. /** If BridgePassword is set, this is a SHA256 digest of the basic http
  1649. * authenticator for it. Used so we can do a time-independent comparison. */
  1650. char *BridgePassword_AuthDigest_;
  1651. int UseBridges; /**< Boolean: should we start all circuits with a bridge? */
  1652. config_line_t *Bridges; /**< List of bootstrap bridge addresses. */
  1653. config_line_t *ClientTransportPlugin; /**< List of client
  1654. transport plugins. */
  1655. config_line_t *ServerTransportPlugin; /**< List of client
  1656. transport plugins. */
  1657. /** List of TCP/IP addresses that transports should listen at. */
  1658. config_line_t *ServerTransportListenAddr;
  1659. /** List of options that must be passed to pluggable transports. */
  1660. config_line_t *ServerTransportOptions;
  1661. int BridgeRelay; /**< Boolean: are we acting as a bridge relay? We make
  1662. * this explicit so we can change how we behave in the
  1663. * future. */
  1664. /** Boolean: if we know the bridge's digest, should we get new
  1665. * descriptors from the bridge authorities or from the bridge itself? */
  1666. int UpdateBridgesFromAuthority;
  1667. int AvoidDiskWrites; /**< Boolean: should we never cache things to disk?
  1668. * Not used yet. */
  1669. int ClientOnly; /**< Boolean: should we never evolve into a server role? */
  1670. int ReducedConnectionPadding; /**< Boolean: Should we try to keep connections
  1671. open shorter and pad them less against
  1672. connection-level traffic analysis? */
  1673. /** Autobool: if auto, then connection padding will be negotiated by client
  1674. * and server. If 0, it will be fully disabled. If 1, the client will still
  1675. * pad to the server regardless of server support. */
  1676. int ConnectionPadding;
  1677. /** To what authority types do we publish our descriptor? Choices are
  1678. * "v1", "v2", "v3", "bridge", or "". */
  1679. smartlist_t *PublishServerDescriptor;
  1680. /** A bitfield of authority types, derived from PublishServerDescriptor. */
  1681. dirinfo_type_t PublishServerDescriptor_;
  1682. /** Boolean: do we publish hidden service descriptors to the HS auths? */
  1683. int PublishHidServDescriptors;
  1684. int FetchServerDescriptors; /**< Do we fetch server descriptors as normal? */
  1685. int FetchHidServDescriptors; /**< and hidden service descriptors? */
  1686. int MinUptimeHidServDirectoryV2; /**< As directory authority, accept hidden
  1687. * service directories after what time? */
  1688. int FetchUselessDescriptors; /**< Do we fetch non-running descriptors too? */
  1689. int AllDirActionsPrivate; /**< Should every directory action be sent
  1690. * through a Tor circuit? */
  1691. /** Run in 'tor2web mode'? (I.e. only make client connections to hidden
  1692. * services, and use a single hop for all hidden-service-related
  1693. * circuits.) */
  1694. int Tor2webMode;
  1695. /** A routerset that should be used when picking RPs for HS circuits. */
  1696. routerset_t *Tor2webRendezvousPoints;
  1697. /** A routerset that should be used when picking middle nodes for HS
  1698. * circuits. */
  1699. routerset_t *HSLayer2Nodes;
  1700. /** A routerset that should be used when picking third-hop nodes for HS
  1701. * circuits. */
  1702. routerset_t *HSLayer3Nodes;
  1703. /** Onion Services in HiddenServiceSingleHopMode make one-hop (direct)
  1704. * circuits between the onion service server, and the introduction and
  1705. * rendezvous points. (Onion service descriptors are still posted using
  1706. * 3-hop paths, to avoid onion service directories blocking the service.)
  1707. * This option makes every hidden service instance hosted by
  1708. * this tor instance a Single Onion Service.
  1709. * HiddenServiceSingleHopMode requires HiddenServiceNonAnonymousMode to be
  1710. * set to 1.
  1711. * Use rend_service_allow_non_anonymous_connection() or
  1712. * rend_service_reveal_startup_time() instead of using this option directly.
  1713. */
  1714. int HiddenServiceSingleHopMode;
  1715. /* Makes hidden service clients and servers non-anonymous on this tor
  1716. * instance. Allows the non-anonymous HiddenServiceSingleHopMode. Enables
  1717. * non-anonymous behaviour in the hidden service protocol.
  1718. * Use rend_service_non_anonymous_mode_enabled() instead of using this option
  1719. * directly.
  1720. */
  1721. int HiddenServiceNonAnonymousMode;
  1722. int ConnLimit; /**< Demanded minimum number of simultaneous connections. */
  1723. int ConnLimit_; /**< Maximum allowed number of simultaneous connections. */
  1724. int ConnLimit_high_thresh; /**< start trying to lower socket usage if we
  1725. * have this many. */
  1726. int ConnLimit_low_thresh; /**< try to get down to here after socket
  1727. * exhaustion. */
  1728. int RunAsDaemon; /**< If true, run in the background. (Unix only) */
  1729. int FascistFirewall; /**< Whether to prefer ORs reachable on open ports. */
  1730. smartlist_t *FirewallPorts; /**< Which ports our firewall allows
  1731. * (strings). */
  1732. config_line_t *ReachableAddresses; /**< IP:ports our firewall allows. */
  1733. config_line_t *ReachableORAddresses; /**< IP:ports for OR conns. */
  1734. config_line_t *ReachableDirAddresses; /**< IP:ports for Dir conns. */
  1735. int ConstrainedSockets; /**< Shrink xmit and recv socket buffers. */
  1736. uint64_t ConstrainedSockSize; /**< Size of constrained buffers. */
  1737. /** Whether we should drop exit streams from Tors that we don't know are
  1738. * relays. One of "0" (never refuse), "1" (always refuse), or "-1" (do
  1739. * what the consensus says, defaulting to 'refuse' if the consensus says
  1740. * nothing). */
  1741. int RefuseUnknownExits;
  1742. /** Application ports that require all nodes in circ to have sufficient
  1743. * uptime. */
  1744. smartlist_t *LongLivedPorts;
  1745. /** Application ports that are likely to be unencrypted and
  1746. * unauthenticated; we reject requests for them to prevent the
  1747. * user from screwing up and leaking plaintext secrets to an
  1748. * observer somewhere on the Internet. */
  1749. smartlist_t *RejectPlaintextPorts;
  1750. /** Related to RejectPlaintextPorts above, except this config option
  1751. * controls whether we warn (in the log and via a controller status
  1752. * event) every time a risky connection is attempted. */
  1753. smartlist_t *WarnPlaintextPorts;
  1754. /** Should we try to reuse the same exit node for a given host */
  1755. smartlist_t *TrackHostExits;
  1756. int TrackHostExitsExpire; /**< Number of seconds until we expire an
  1757. * addressmap */
  1758. config_line_t *AddressMap; /**< List of address map directives. */
  1759. int AutomapHostsOnResolve; /**< If true, when we get a resolve request for a
  1760. * hostname ending with one of the suffixes in
  1761. * <b>AutomapHostsSuffixes</b>, map it to a
  1762. * virtual address. */
  1763. /** List of suffixes for <b>AutomapHostsOnResolve</b>. The special value
  1764. * "." means "match everything." */
  1765. smartlist_t *AutomapHostsSuffixes;
  1766. int RendPostPeriod; /**< How often do we post each rendezvous service
  1767. * descriptor? Remember to publish them independently. */
  1768. int KeepalivePeriod; /**< How often do we send padding cells to keep
  1769. * connections alive? */
  1770. int SocksTimeout; /**< How long do we let a socks connection wait
  1771. * unattached before we fail it? */
  1772. int LearnCircuitBuildTimeout; /**< If non-zero, we attempt to learn a value
  1773. * for CircuitBuildTimeout based on timeout
  1774. * history. Use circuit_build_times_disabled()
  1775. * rather than checking this value directly. */
  1776. int CircuitBuildTimeout; /**< Cull non-open circuits that were born at
  1777. * least this many seconds ago. Used until
  1778. * adaptive algorithm learns a new value. */
  1779. int CircuitsAvailableTimeout; /**< Try to have an open circuit for at
  1780. least this long after last activity */
  1781. int CircuitStreamTimeout; /**< If non-zero, detach streams from circuits
  1782. * and try a new circuit if the stream has been
  1783. * waiting for this many seconds. If zero, use
  1784. * our default internal timeout schedule. */
  1785. int MaxOnionQueueDelay; /*< DOCDOC */
  1786. int NewCircuitPeriod; /**< How long do we use a circuit before building
  1787. * a new one? */
  1788. int MaxCircuitDirtiness; /**< Never use circs that were first used more than
  1789. this interval ago. */
  1790. uint64_t BandwidthRate; /**< How much bandwidth, on average, are we willing
  1791. * to use in a second? */
  1792. uint64_t BandwidthBurst; /**< How much bandwidth, at maximum, are we willing
  1793. * to use in a second? */
  1794. uint64_t MaxAdvertisedBandwidth; /**< How much bandwidth are we willing to
  1795. * tell other nodes we have? */
  1796. uint64_t RelayBandwidthRate; /**< How much bandwidth, on average, are we
  1797. * willing to use for all relayed conns? */
  1798. uint64_t RelayBandwidthBurst; /**< How much bandwidth, at maximum, will we
  1799. * use in a second for all relayed conns? */
  1800. uint64_t PerConnBWRate; /**< Long-term bw on a single TLS conn, if set. */
  1801. uint64_t PerConnBWBurst; /**< Allowed burst on a single TLS conn, if set. */
  1802. int NumCPUs; /**< How many CPUs should we try to use? */
  1803. config_line_t *RendConfigLines; /**< List of configuration lines
  1804. * for rendezvous services. */
  1805. config_line_t *HidServAuth; /**< List of configuration lines for client-side
  1806. * authorizations for hidden services */
  1807. char *ContactInfo; /**< Contact info to be published in the directory. */
  1808. int HeartbeatPeriod; /**< Log heartbeat messages after this many seconds
  1809. * have passed. */
  1810. int MainloopStats; /**< Log main loop statistics as part of the
  1811. * heartbeat messages. */
  1812. char *HTTPProxy; /**< hostname[:port] to use as http proxy, if any. */
  1813. tor_addr_t HTTPProxyAddr; /**< Parsed IPv4 addr for http proxy, if any. */
  1814. uint16_t HTTPProxyPort; /**< Parsed port for http proxy, if any. */
  1815. char *HTTPProxyAuthenticator; /**< username:password string, if any. */
  1816. char *HTTPSProxy; /**< hostname[:port] to use as https proxy, if any. */
  1817. tor_addr_t HTTPSProxyAddr; /**< Parsed addr for https proxy, if any. */
  1818. uint16_t HTTPSProxyPort; /**< Parsed port for https proxy, if any. */
  1819. char *HTTPSProxyAuthenticator; /**< username:password string, if any. */
  1820. char *Socks4Proxy; /**< hostname:port to use as a SOCKS4 proxy, if any. */
  1821. tor_addr_t Socks4ProxyAddr; /**< Derived from Socks4Proxy. */
  1822. uint16_t Socks4ProxyPort; /**< Derived from Socks4Proxy. */
  1823. char *Socks5Proxy; /**< hostname:port to use as a SOCKS5 proxy, if any. */
  1824. tor_addr_t Socks5ProxyAddr; /**< Derived from Sock5Proxy. */
  1825. uint16_t Socks5ProxyPort; /**< Derived from Socks5Proxy. */
  1826. char *Socks5ProxyUsername; /**< Username for SOCKS5 authentication, if any */
  1827. char *Socks5ProxyPassword; /**< Password for SOCKS5 authentication, if any */
  1828. /** List of configuration lines for replacement directory authorities.
  1829. * If you just want to replace one class of authority at a time,
  1830. * use the "Alternate*Authority" options below instead. */
  1831. config_line_t *DirAuthorities;
  1832. /** List of fallback directory servers */
  1833. config_line_t *FallbackDir;
  1834. /** Whether to use the default hard-coded FallbackDirs */
  1835. int UseDefaultFallbackDirs;
  1836. /** Weight to apply to all directory authority rates if considering them
  1837. * along with fallbackdirs */
  1838. double DirAuthorityFallbackRate;
  1839. /** If set, use these main (currently v3) directory authorities and
  1840. * not the default ones. */
  1841. config_line_t *AlternateDirAuthority;
  1842. /** If set, use these bridge authorities and not the default one. */
  1843. config_line_t *AlternateBridgeAuthority;
  1844. config_line_t *MyFamily_lines; /**< Declared family for this OR. */
  1845. config_line_t *MyFamily; /**< Declared family for this OR, normalized */
  1846. config_line_t *NodeFamilies; /**< List of config lines for
  1847. * node families */
  1848. smartlist_t *NodeFamilySets; /**< List of parsed NodeFamilies values. */
  1849. config_line_t *AuthDirBadExit; /**< Address policy for descriptors to
  1850. * mark as bad exits. */
  1851. config_line_t *AuthDirReject; /**< Address policy for descriptors to
  1852. * reject. */
  1853. config_line_t *AuthDirInvalid; /**< Address policy for descriptors to
  1854. * never mark as valid. */
  1855. /** @name AuthDir...CC
  1856. *
  1857. * Lists of country codes to mark as BadExit, or Invalid, or to
  1858. * reject entirely.
  1859. *
  1860. * @{
  1861. */
  1862. smartlist_t *AuthDirBadExitCCs;
  1863. smartlist_t *AuthDirInvalidCCs;
  1864. smartlist_t *AuthDirRejectCCs;
  1865. /**@}*/
  1866. int AuthDirListBadExits; /**< True iff we should list bad exits,
  1867. * and vote for all other exits as good. */
  1868. int AuthDirMaxServersPerAddr; /**< Do not permit more than this
  1869. * number of servers per IP address. */
  1870. int AuthDirHasIPv6Connectivity; /**< Boolean: are we on IPv6? */
  1871. int AuthDirPinKeys; /**< Boolean: Do we enforce key-pinning? */
  1872. /** If non-zero, always vote the Fast flag for any relay advertising
  1873. * this amount of capacity or more. */
  1874. uint64_t AuthDirFastGuarantee;
  1875. /** If non-zero, this advertised capacity or more is always sufficient
  1876. * to satisfy the bandwidth requirement for the Guard flag. */
  1877. uint64_t AuthDirGuardBWGuarantee;
  1878. char *AccountingStart; /**< How long is the accounting interval, and when
  1879. * does it start? */
  1880. uint64_t AccountingMax; /**< How many bytes do we allow per accounting
  1881. * interval before hibernation? 0 for "never
  1882. * hibernate." */
  1883. /** How do we determine when our AccountingMax has been reached?
  1884. * "max" for when in or out reaches AccountingMax
  1885. * "sum" for when in plus out reaches AccountingMax
  1886. * "in" for when in reaches AccountingMax
  1887. * "out" for when out reaches AccountingMax */
  1888. char *AccountingRule_option;
  1889. enum { ACCT_MAX, ACCT_SUM, ACCT_IN, ACCT_OUT } AccountingRule;
  1890. /** Base64-encoded hash of accepted passwords for the control system. */
  1891. config_line_t *HashedControlPassword;
  1892. /** As HashedControlPassword, but not saved. */
  1893. config_line_t *HashedControlSessionPassword;
  1894. int CookieAuthentication; /**< Boolean: do we enable cookie-based auth for
  1895. * the control system? */
  1896. char *CookieAuthFile; /**< Filesystem location of a ControlPort
  1897. * authentication cookie. */
  1898. char *ExtORPortCookieAuthFile; /**< Filesystem location of Extended
  1899. * ORPort authentication cookie. */
  1900. int CookieAuthFileGroupReadable; /**< Boolean: Is the CookieAuthFile g+r? */
  1901. int ExtORPortCookieAuthFileGroupReadable; /**< Boolean: Is the
  1902. * ExtORPortCookieAuthFile g+r? */
  1903. int LeaveStreamsUnattached; /**< Boolean: Does Tor attach new streams to
  1904. * circuits itself (0), or does it expect a controller
  1905. * to cope? (1) */
  1906. int DisablePredictedCircuits; /**< Boolean: does Tor preemptively
  1907. * make circuits in the background (0),
  1908. * or not (1)? */
  1909. /** Process specifier for a controller that ‘owns’ this Tor
  1910. * instance. Tor will terminate if its owning controller does. */
  1911. char *OwningControllerProcess;
  1912. /** FD specifier for a controller that owns this Tor instance. */
  1913. int OwningControllerFD;
  1914. int ShutdownWaitLength; /**< When we get a SIGINT and we're a server, how
  1915. * long do we wait before exiting? */
  1916. char *SafeLogging; /**< Contains "relay", "1", "0" (meaning no scrubbing). */
  1917. /* Derived from SafeLogging */
  1918. enum {
  1919. SAFELOG_SCRUB_ALL, SAFELOG_SCRUB_RELAY, SAFELOG_SCRUB_NONE
  1920. } SafeLogging_;
  1921. int Sandbox; /**< Boolean: should sandboxing be enabled? */
  1922. int SafeSocks; /**< Boolean: should we outright refuse application
  1923. * connections that use socks4 or socks5-with-local-dns? */
  1924. int ProtocolWarnings; /**< Boolean: when other parties screw up the Tor
  1925. * protocol, is it a warn or an info in our logs? */
  1926. int TestSocks; /**< Boolean: when we get a socks connection, do we loudly
  1927. * log whether it was DNS-leaking or not? */
  1928. int HardwareAccel; /**< Boolean: Should we enable OpenSSL hardware
  1929. * acceleration where available? */
  1930. /** Token Bucket Refill resolution in milliseconds. */
  1931. int TokenBucketRefillInterval;
  1932. char *AccelName; /**< Optional hardware acceleration engine name. */
  1933. char *AccelDir; /**< Optional hardware acceleration engine search dir. */
  1934. /** Boolean: Do we try to enter from a smallish number
  1935. * of fixed nodes? */
  1936. int UseEntryGuards_option;
  1937. /** Internal variable to remember whether we're actually acting on
  1938. * UseEntryGuards_option -- when we're a non-anonymous Tor2web client or
  1939. * Single Onion Service, it is always false, otherwise we use the value of
  1940. * UseEntryGuards_option. */
  1941. int UseEntryGuards;
  1942. int NumEntryGuards; /**< How many entry guards do we try to establish? */
  1943. /** If 1, we use any guardfraction information we see in the
  1944. * consensus. If 0, we don't. If -1, let the consensus parameter
  1945. * decide. */
  1946. int UseGuardFraction;
  1947. int NumDirectoryGuards; /**< How many dir guards do we try to establish?
  1948. * If 0, use value from NumEntryGuards. */
  1949. int NumPrimaryGuards; /**< How many primary guards do we want? */
  1950. int RephistTrackTime; /**< How many seconds do we keep rephist info? */
  1951. /** Should we always fetch our dir info on the mirror schedule (which
  1952. * means directly from the authorities) no matter our other config? */
  1953. int FetchDirInfoEarly;
  1954. /** Should we fetch our dir info at the start of the consensus period? */
  1955. int FetchDirInfoExtraEarly;
  1956. int DirCache; /**< Cache all directory documents and accept requests via
  1957. * tunnelled dir conns from clients. If 1, enabled (default);
  1958. * If 0, disabled. */
  1959. char *VirtualAddrNetworkIPv4; /**< Address and mask to hand out for virtual
  1960. * MAPADDRESS requests for IPv4 addresses */
  1961. char *VirtualAddrNetworkIPv6; /**< Address and mask to hand out for virtual
  1962. * MAPADDRESS requests for IPv6 addresses */
  1963. int ServerDNSSearchDomains; /**< Boolean: If set, we don't force exit
  1964. * addresses to be FQDNs, but rather search for them in
  1965. * the local domains. */
  1966. int ServerDNSDetectHijacking; /**< Boolean: If true, check for DNS failure
  1967. * hijacking. */
  1968. int ServerDNSRandomizeCase; /**< Boolean: Use the 0x20-hack to prevent
  1969. * DNS poisoning attacks. */
  1970. char *ServerDNSResolvConfFile; /**< If provided, we configure our internal
  1971. * resolver from the file here rather than from
  1972. * /etc/resolv.conf (Unix) or the registry (Windows). */
  1973. char *DirPortFrontPage; /**< This is a full path to a file with an html
  1974. disclaimer. This allows a server administrator to show
  1975. that they're running Tor and anyone visiting their server
  1976. will know this without any specialized knowledge. */
  1977. int DisableDebuggerAttachment; /**< Currently Linux only specific attempt to
  1978. disable ptrace; needs BSD testing. */
  1979. /** Boolean: if set, we start even if our resolv.conf file is missing
  1980. * or broken. */
  1981. int ServerDNSAllowBrokenConfig;
  1982. /** Boolean: if set, then even connections to private addresses will get
  1983. * rate-limited. */
  1984. int CountPrivateBandwidth;
  1985. smartlist_t *ServerDNSTestAddresses; /**< A list of addresses that definitely
  1986. * should be resolvable. Used for
  1987. * testing our DNS server. */
  1988. int EnforceDistinctSubnets; /**< If true, don't allow multiple routers in the
  1989. * same network zone in the same circuit. */
  1990. int AllowNonRFC953Hostnames; /**< If true, we allow connections to hostnames
  1991. * with weird characters. */
  1992. /** If true, we try resolving hostnames with weird characters. */
  1993. int ServerDNSAllowNonRFC953Hostnames;
  1994. /** If true, we try to download extra-info documents (and we serve them,
  1995. * if we are a cache). For authorities, this is always true. */
  1996. int DownloadExtraInfo;
  1997. /** If true, we're configured to collect statistics on clients
  1998. * requesting network statuses from us as directory. */
  1999. int DirReqStatistics_option;
  2000. /** Internal variable to remember whether we're actually acting on
  2001. * DirReqStatistics_option -- yes if it's set and we're a server, else no. */
  2002. int DirReqStatistics;
  2003. /** If true, the user wants us to collect statistics on port usage. */
  2004. int ExitPortStatistics;
  2005. /** If true, the user wants us to collect connection statistics. */
  2006. int ConnDirectionStatistics;
  2007. /** If true, the user wants us to collect cell statistics. */
  2008. int CellStatistics;
  2009. /** If true, the user wants us to collect padding statistics. */
  2010. int PaddingStatistics;
  2011. /** If true, the user wants us to collect statistics as entry node. */
  2012. int EntryStatistics;
  2013. /** If true, the user wants us to collect statistics as hidden service
  2014. * directory, introduction point, or rendezvous point. */
  2015. int HiddenServiceStatistics_option;
  2016. /** Internal variable to remember whether we're actually acting on
  2017. * HiddenServiceStatistics_option -- yes if it's set and we're a server,
  2018. * else no. */
  2019. int HiddenServiceStatistics;
  2020. /** If true, include statistics file contents in extra-info documents. */
  2021. int ExtraInfoStatistics;
  2022. /** If true, do not believe anybody who tells us that a domain resolves
  2023. * to an internal address, or that an internal address has a PTR mapping.
  2024. * Helps avoid some cross-site attacks. */
  2025. int ClientDNSRejectInternalAddresses;
  2026. /** If true, do not accept any requests to connect to internal addresses
  2027. * over randomly chosen exits. */
  2028. int ClientRejectInternalAddresses;
  2029. /** If true, clients may connect over IPv4. If false, they will avoid
  2030. * connecting over IPv4. We enforce this for OR and Dir connections. */
  2031. int ClientUseIPv4;
  2032. /** If true, clients may connect over IPv6. If false, they will avoid
  2033. * connecting over IPv4. We enforce this for OR and Dir connections.
  2034. * Use fascist_firewall_use_ipv6() instead of accessing this value
  2035. * directly. */
  2036. int ClientUseIPv6;
  2037. /** If true, prefer an IPv6 OR port over an IPv4 one for entry node
  2038. * connections. If auto, bridge clients prefer IPv6, and other clients
  2039. * prefer IPv4. Use node_ipv6_or_preferred() instead of accessing this value
  2040. * directly. */
  2041. int ClientPreferIPv6ORPort;
  2042. /** If true, prefer an IPv6 directory port over an IPv4 one for direct
  2043. * directory connections. If auto, bridge clients prefer IPv6, and other
  2044. * clients prefer IPv4. Use fascist_firewall_prefer_ipv6_dirport() instead of
  2045. * accessing this value directly. */
  2046. int ClientPreferIPv6DirPort;
  2047. /** The length of time that we think a consensus should be fresh. */
  2048. int V3AuthVotingInterval;
  2049. /** The length of time we think it will take to distribute votes. */
  2050. int V3AuthVoteDelay;
  2051. /** The length of time we think it will take to distribute signatures. */
  2052. int V3AuthDistDelay;
  2053. /** The number of intervals we think a consensus should be valid. */
  2054. int V3AuthNIntervalsValid;
  2055. /** Should advertise and sign consensuses with a legacy key, for key
  2056. * migration purposes? */
  2057. int V3AuthUseLegacyKey;
  2058. /** Location of bandwidth measurement file */
  2059. char *V3BandwidthsFile;
  2060. /** Location of guardfraction file */
  2061. char *GuardfractionFile;
  2062. /** Authority only: key=value pairs that we add to our networkstatus
  2063. * consensus vote on the 'params' line. */
  2064. char *ConsensusParams;
  2065. /** Authority only: minimum number of measured bandwidths we must see
  2066. * before we only believe measured bandwidths to assign flags. */
  2067. int MinMeasuredBWsForAuthToIgnoreAdvertised;
  2068. /** The length of time that we think an initial consensus should be fresh.
  2069. * Only altered on testing networks. */
  2070. int TestingV3AuthInitialVotingInterval;
  2071. /** The length of time we think it will take to distribute initial votes.
  2072. * Only altered on testing networks. */
  2073. int TestingV3AuthInitialVoteDelay;
  2074. /** The length of time we think it will take to distribute initial
  2075. * signatures. Only altered on testing networks.*/
  2076. int TestingV3AuthInitialDistDelay;
  2077. /** Offset in seconds added to the starting time for consensus
  2078. voting. Only altered on testing networks. */
  2079. int TestingV3AuthVotingStartOffset;
  2080. /** If an authority has been around for less than this amount of time, it
  2081. * does not believe its reachability information is accurate. Only
  2082. * altered on testing networks. */
  2083. int TestingAuthDirTimeToLearnReachability;
  2084. /** Clients don't download any descriptor this recent, since it will
  2085. * probably not have propagated to enough caches. Only altered on testing
  2086. * networks. */
  2087. int TestingEstimatedDescriptorPropagationTime;
  2088. /** Schedule for when servers should download things in general. Only
  2089. * altered on testing networks. */
  2090. int TestingServerDownloadInitialDelay;
  2091. /** Schedule for when clients should download things in general. Only
  2092. * altered on testing networks. */
  2093. int TestingClientDownloadInitialDelay;
  2094. /** Schedule for when servers should download consensuses. Only altered
  2095. * on testing networks. */
  2096. int TestingServerConsensusDownloadInitialDelay;
  2097. /** Schedule for when clients should download consensuses. Only altered
  2098. * on testing networks. */
  2099. int TestingClientConsensusDownloadInitialDelay;
  2100. /** Schedule for when clients should download consensuses from authorities
  2101. * if they are bootstrapping (that is, they don't have a usable, reasonably
  2102. * live consensus). Only used by clients fetching from a list of fallback
  2103. * directory mirrors.
  2104. *
  2105. * This schedule is incremented by (potentially concurrent) connection
  2106. * attempts, unlike other schedules, which are incremented by connection
  2107. * failures. Only altered on testing networks. */
  2108. int ClientBootstrapConsensusAuthorityDownloadInitialDelay;
  2109. /** Schedule for when clients should download consensuses from fallback
  2110. * directory mirrors if they are bootstrapping (that is, they don't have a
  2111. * usable, reasonably live consensus). Only used by clients fetching from a
  2112. * list of fallback directory mirrors.
  2113. *
  2114. * This schedule is incremented by (potentially concurrent) connection
  2115. * attempts, unlike other schedules, which are incremented by connection
  2116. * failures. Only altered on testing networks. */
  2117. int ClientBootstrapConsensusFallbackDownloadInitialDelay;
  2118. /** Schedule for when clients should download consensuses from authorities
  2119. * if they are bootstrapping (that is, they don't have a usable, reasonably
  2120. * live consensus). Only used by clients which don't have or won't fetch
  2121. * from a list of fallback directory mirrors.
  2122. *
  2123. * This schedule is incremented by (potentially concurrent) connection
  2124. * attempts, unlike other schedules, which are incremented by connection
  2125. * failures. Only altered on testing networks. */
  2126. int ClientBootstrapConsensusAuthorityOnlyDownloadInitialDelay;
  2127. /** Schedule for when clients should download bridge descriptors. Only
  2128. * altered on testing networks. */
  2129. int TestingBridgeDownloadInitialDelay;
  2130. /** Schedule for when clients should download bridge descriptors when they
  2131. * have no running bridges. Only altered on testing networks. */
  2132. int TestingBridgeBootstrapDownloadInitialDelay;
  2133. /** When directory clients have only a few descriptors to request, they
  2134. * batch them until they have more, or until this amount of time has
  2135. * passed. Only altered on testing networks. */
  2136. int TestingClientMaxIntervalWithoutRequest;
  2137. /** How long do we let a directory connection stall before expiring
  2138. * it? Only altered on testing networks. */
  2139. int TestingDirConnectionMaxStall;
  2140. /** How many simultaneous in-progress connections will we make when trying
  2141. * to fetch a consensus before we wait for one to complete, timeout, or
  2142. * error out? Only altered on testing networks. */
  2143. int ClientBootstrapConsensusMaxInProgressTries;
  2144. /** If true, we take part in a testing network. Change the defaults of a
  2145. * couple of other configuration options and allow to change the values
  2146. * of certain configuration options. */
  2147. int TestingTorNetwork;
  2148. /** Minimum value for the Exit flag threshold on testing networks. */
  2149. uint64_t TestingMinExitFlagThreshold;
  2150. /** Minimum value for the Fast flag threshold on testing networks. */
  2151. uint64_t TestingMinFastFlagThreshold;
  2152. /** Relays in a testing network which should be voted Exit
  2153. * regardless of exit policy. */
  2154. routerset_t *TestingDirAuthVoteExit;
  2155. int TestingDirAuthVoteExitIsStrict;
  2156. /** Relays in a testing network which should be voted Guard
  2157. * regardless of uptime and bandwidth. */
  2158. routerset_t *TestingDirAuthVoteGuard;
  2159. int TestingDirAuthVoteGuardIsStrict;
  2160. /** Relays in a testing network which should be voted HSDir
  2161. * regardless of uptime and DirPort. */
  2162. routerset_t *TestingDirAuthVoteHSDir;
  2163. int TestingDirAuthVoteHSDirIsStrict;
  2164. /** Enable CONN_BW events. Only altered on testing networks. */
  2165. int TestingEnableConnBwEvent;
  2166. /** Enable CELL_STATS events. Only altered on testing networks. */
  2167. int TestingEnableCellStatsEvent;
  2168. /** If true, and we have GeoIP data, and we're a bridge, keep a per-country
  2169. * count of how many client addresses have contacted us so that we can help
  2170. * the bridge authority guess which countries have blocked access to us. */
  2171. int BridgeRecordUsageByCountry;
  2172. /** Optionally, IPv4 and IPv6 GeoIP data. */
  2173. char *GeoIPFile;
  2174. char *GeoIPv6File;
  2175. /** Autobool: if auto, then any attempt to Exclude{Exit,}Nodes a particular
  2176. * country code will exclude all nodes in ?? and A1. If true, all nodes in
  2177. * ?? and A1 are excluded. Has no effect if we don't know any GeoIP data. */
  2178. int GeoIPExcludeUnknown;
  2179. /** If true, SIGHUP should reload the torrc. Sometimes controllers want
  2180. * to make this false. */
  2181. int ReloadTorrcOnSIGHUP;
  2182. /* The main parameter for picking circuits within a connection.
  2183. *
  2184. * If this value is positive, when picking a cell to relay on a connection,
  2185. * we always relay from the circuit whose weighted cell count is lowest.
  2186. * Cells are weighted exponentially such that if one cell is sent
  2187. * 'CircuitPriorityHalflife' seconds before another, it counts for half as
  2188. * much.
  2189. *
  2190. * If this value is zero, we're disabling the cell-EWMA algorithm.
  2191. *
  2192. * If this value is negative, we're using the default approach
  2193. * according to either Tor or a parameter set in the consensus.
  2194. */
  2195. double CircuitPriorityHalflife;
  2196. /** Set to true if the TestingTorNetwork configuration option is set.
  2197. * This is used so that options_validate() has a chance to realize that
  2198. * the defaults have changed. */
  2199. int UsingTestNetworkDefaults_;
  2200. /** If 1, we try to use microdescriptors to build circuits. If 0, we don't.
  2201. * If -1, Tor decides. */
  2202. int UseMicrodescriptors;
  2203. /** File where we should write the ControlPort. */
  2204. char *ControlPortWriteToFile;
  2205. /** Should that file be group-readable? */
  2206. int ControlPortFileGroupReadable;
  2207. #define MAX_MAX_CLIENT_CIRCUITS_PENDING 1024
  2208. /** Maximum number of non-open general-purpose origin circuits to allow at
  2209. * once. */
  2210. int MaxClientCircuitsPending;
  2211. /** If 1, we always send optimistic data when it's supported. If 0, we
  2212. * never use it. If -1, we do what the consensus says. */
  2213. int OptimisticData;
  2214. /** If 1, we accept and launch no external network connections, except on
  2215. * control ports. */
  2216. int DisableNetwork;
  2217. /**
  2218. * Parameters for path-bias detection.
  2219. * @{
  2220. * These options override the default behavior of Tor's (**currently
  2221. * experimental**) path bias detection algorithm. To try to find broken or
  2222. * misbehaving guard nodes, Tor looks for nodes where more than a certain
  2223. * fraction of circuits through that guard fail to get built.
  2224. *
  2225. * The PathBiasCircThreshold option controls how many circuits we need to
  2226. * build through a guard before we make these checks. The
  2227. * PathBiasNoticeRate, PathBiasWarnRate and PathBiasExtremeRate options
  2228. * control what fraction of circuits must succeed through a guard so we
  2229. * won't write log messages. If less than PathBiasExtremeRate circuits
  2230. * succeed *and* PathBiasDropGuards is set to 1, we disable use of that
  2231. * guard.
  2232. *
  2233. * When we have seen more than PathBiasScaleThreshold circuits through a
  2234. * guard, we scale our observations by 0.5 (governed by the consensus) so
  2235. * that new observations don't get swamped by old ones.
  2236. *
  2237. * By default, or if a negative value is provided for one of these options,
  2238. * Tor uses reasonable defaults from the networkstatus consensus document.
  2239. * If no defaults are available there, these options default to 150, .70,
  2240. * .50, .30, 0, and 300 respectively.
  2241. */
  2242. int PathBiasCircThreshold;
  2243. double PathBiasNoticeRate;
  2244. double PathBiasWarnRate;
  2245. double PathBiasExtremeRate;
  2246. int PathBiasDropGuards;
  2247. int PathBiasScaleThreshold;
  2248. /** @} */
  2249. /**
  2250. * Parameters for path-bias use detection
  2251. * @{
  2252. * Similar to the above options, these options override the default behavior
  2253. * of Tor's (**currently experimental**) path use bias detection algorithm.
  2254. *
  2255. * Where as the path bias parameters govern thresholds for successfully
  2256. * building circuits, these four path use bias parameters govern thresholds
  2257. * only for circuit usage. Circuits which receive no stream usage are not
  2258. * counted by this detection algorithm. A used circuit is considered
  2259. * successful if it is capable of carrying streams or otherwise receiving
  2260. * well-formed responses to RELAY cells.
  2261. *
  2262. * By default, or if a negative value is provided for one of these options,
  2263. * Tor uses reasonable defaults from the networkstatus consensus document.
  2264. * If no defaults are available there, these options default to 20, .80,
  2265. * .60, and 100, respectively.
  2266. */
  2267. int PathBiasUseThreshold;
  2268. double PathBiasNoticeUseRate;
  2269. double PathBiasExtremeUseRate;
  2270. int PathBiasScaleUseThreshold;
  2271. /** @} */
  2272. int IPv6Exit; /**< Do we support exiting to IPv6 addresses? */
  2273. /** Fraction: */
  2274. double PathsNeededToBuildCircuits;
  2275. /** What expiry time shall we place on our SSL certs? "0" means we
  2276. * should guess a suitable value. */
  2277. int SSLKeyLifetime;
  2278. /** How long (seconds) do we keep a guard before picking a new one? */
  2279. int GuardLifetime;
  2280. /** Is this an exit node? This is a tristate, where "1" means "yes, and use
  2281. * the default exit policy if none is given" and "0" means "no; exit policy
  2282. * is 'reject *'" and "auto" (-1) means "same as 1, but warn the user."
  2283. *
  2284. * XXXX Eventually, the default will be 0. */
  2285. int ExitRelay;
  2286. /** For how long (seconds) do we declare our signing keys to be valid? */
  2287. int SigningKeyLifetime;
  2288. /** For how long (seconds) do we declare our link keys to be valid? */
  2289. int TestingLinkCertLifetime;
  2290. /** For how long (seconds) do we declare our auth keys to be valid? */
  2291. int TestingAuthKeyLifetime;
  2292. /** How long before signing keys expire will we try to make a new one? */
  2293. int TestingSigningKeySlop;
  2294. /** How long before link keys expire will we try to make a new one? */
  2295. int TestingLinkKeySlop;
  2296. /** How long before auth keys expire will we try to make a new one? */
  2297. int TestingAuthKeySlop;
  2298. /** Force use of offline master key features: never generate a master
  2299. * ed25519 identity key except from tor --keygen */
  2300. int OfflineMasterKey;
  2301. enum {
  2302. FORCE_PASSPHRASE_AUTO=0,
  2303. FORCE_PASSPHRASE_ON,
  2304. FORCE_PASSPHRASE_OFF
  2305. } keygen_force_passphrase;
  2306. int use_keygen_passphrase_fd;
  2307. int keygen_passphrase_fd;
  2308. int change_key_passphrase;
  2309. char *master_key_fname;
  2310. /** Autobool: Do we try to retain capabilities if we can? */
  2311. int KeepBindCapabilities;
  2312. /** Maximum total size of unparseable descriptors to log during the
  2313. * lifetime of this Tor process.
  2314. */
  2315. uint64_t MaxUnparseableDescSizeToLog;
  2316. /** Bool (default: 1): Switch for the shared random protocol. Only
  2317. * relevant to a directory authority. If off, the authority won't
  2318. * participate in the protocol. If on (default), a flag is added to the
  2319. * vote indicating participation. */
  2320. int AuthDirSharedRandomness;
  2321. /** If 1, we skip all OOS checks. */
  2322. int DisableOOSCheck;
  2323. /** Autobool: Should we include Ed25519 identities in extend2 cells?
  2324. * If -1, we should do whatever the consensus parameter says. */
  2325. int ExtendByEd25519ID;
  2326. /** Bool (default: 1): When testing routerinfos as a directory authority,
  2327. * do we enforce Ed25519 identity match? */
  2328. /* NOTE: remove this option someday. */
  2329. int AuthDirTestEd25519LinkKeys;
  2330. /** Bool (default: 0): Tells if a %include was used on torrc */
  2331. int IncludeUsed;
  2332. /** The seconds after expiration which we as a relay should keep old
  2333. * consensuses around so that we can generate diffs from them. If 0,
  2334. * use the default. */
  2335. int MaxConsensusAgeForDiffs;
  2336. /** Bool (default: 0). Tells Tor to never try to exec another program.
  2337. */
  2338. int NoExec;
  2339. /** Have the KIST scheduler run every X milliseconds. If less than zero, do
  2340. * not use the KIST scheduler but use the old vanilla scheduler instead. If
  2341. * zero, do what the consensus says and fall back to using KIST as if this is
  2342. * set to "10 msec" if the consensus doesn't say anything. */
  2343. int KISTSchedRunInterval;
  2344. /** A multiplier for the KIST per-socket limit calculation. */
  2345. double KISTSockBufSizeFactor;
  2346. /** The list of scheduler type string ordered by priority that is first one
  2347. * has to be tried first. Default: KIST,KISTLite,Vanilla */
  2348. smartlist_t *Schedulers;
  2349. /* An ordered list of scheduler_types mapped from Schedulers. */
  2350. smartlist_t *SchedulerTypes_;
  2351. /** List of files that were opened by %include in torrc and torrc-defaults */
  2352. smartlist_t *FilesOpenedByIncludes;
  2353. /** If true, Tor shouldn't install any posix signal handlers, since it is
  2354. * running embedded inside another process.
  2355. */
  2356. int DisableSignalHandlers;
  2357. /** Autobool: Is the circuit creation DoS mitigation subsystem enabled? */
  2358. int DoSCircuitCreationEnabled;
  2359. /** Minimum concurrent connection needed from one single address before any
  2360. * defense is used. */
  2361. int DoSCircuitCreationMinConnections;
  2362. /** Circuit rate used to refill the token bucket. */
  2363. int DoSCircuitCreationRate;
  2364. /** Maximum allowed burst of circuits. Reaching that value, the address is
  2365. * detected as malicious and a defense might be used. */
  2366. int DoSCircuitCreationBurst;
  2367. /** When an address is marked as malicous, what defense should be used
  2368. * against it. See the dos_cc_defense_type_t enum. */
  2369. int DoSCircuitCreationDefenseType;
  2370. /** For how much time (in seconds) the defense is applicable for a malicious
  2371. * address. A random time delta is added to the defense time of an address
  2372. * which will be between 1 second and half of this value. */
  2373. int DoSCircuitCreationDefenseTimePeriod;
  2374. /** Autobool: Is the DoS connection mitigation subsystem enabled? */
  2375. int DoSConnectionEnabled;
  2376. /** Maximum concurrent connection allowed per address. */
  2377. int DoSConnectionMaxConcurrentCount;
  2378. /** When an address is reaches the maximum count, what defense should be
  2379. * used against it. See the dos_conn_defense_type_t enum. */
  2380. int DoSConnectionDefenseType;
  2381. /** Autobool: Do we refuse single hop client rendezvous? */
  2382. int DoSRefuseSingleHopClientRendezvous;
  2383. } or_options_t;
  2384. #define LOG_PROTOCOL_WARN (get_protocol_warning_severity_level())
  2385. /** Persistent state for an onion router, as saved to disk. */
  2386. typedef struct {
  2387. uint32_t magic_;
  2388. /** The time at which we next plan to write the state to the disk. Equal to
  2389. * TIME_MAX if there are no savable changes, 0 if there are changes that
  2390. * should be saved right away. */
  2391. time_t next_write;
  2392. /** When was the state last written to disk? */
  2393. time_t LastWritten;
  2394. /** Fields for accounting bandwidth use. */
  2395. time_t AccountingIntervalStart;
  2396. uint64_t AccountingBytesReadInInterval;
  2397. uint64_t AccountingBytesWrittenInInterval;
  2398. int AccountingSecondsActive;
  2399. int AccountingSecondsToReachSoftLimit;
  2400. time_t AccountingSoftLimitHitAt;
  2401. uint64_t AccountingBytesAtSoftLimit;
  2402. uint64_t AccountingExpectedUsage;
  2403. /** A list of Entry Guard-related configuration lines. (pre-prop271) */
  2404. config_line_t *EntryGuards;
  2405. /** A list of guard-related configuration lines. (post-prop271) */
  2406. config_line_t *Guard;
  2407. config_line_t *TransportProxies;
  2408. /** Cached revision counters for active hidden services on this host */
  2409. config_line_t *HidServRevCounter;
  2410. /** These fields hold information on the history of bandwidth usage for
  2411. * servers. The "Ends" fields hold the time when we last updated the
  2412. * bandwidth usage. The "Interval" fields hold the granularity, in seconds,
  2413. * of the entries of Values. The "Values" lists hold decimal string
  2414. * representations of the number of bytes read or written in each
  2415. * interval. The "Maxima" list holds decimal strings describing the highest
  2416. * rate achieved during the interval.
  2417. */
  2418. time_t BWHistoryReadEnds;
  2419. int BWHistoryReadInterval;
  2420. smartlist_t *BWHistoryReadValues;
  2421. smartlist_t *BWHistoryReadMaxima;
  2422. time_t BWHistoryWriteEnds;
  2423. int BWHistoryWriteInterval;
  2424. smartlist_t *BWHistoryWriteValues;
  2425. smartlist_t *BWHistoryWriteMaxima;
  2426. time_t BWHistoryDirReadEnds;
  2427. int BWHistoryDirReadInterval;
  2428. smartlist_t *BWHistoryDirReadValues;
  2429. smartlist_t *BWHistoryDirReadMaxima;
  2430. time_t BWHistoryDirWriteEnds;
  2431. int BWHistoryDirWriteInterval;
  2432. smartlist_t *BWHistoryDirWriteValues;
  2433. smartlist_t *BWHistoryDirWriteMaxima;
  2434. /** Build time histogram */
  2435. config_line_t * BuildtimeHistogram;
  2436. int TotalBuildTimes;
  2437. int CircuitBuildAbandonedCount;
  2438. /** What version of Tor wrote this state file? */
  2439. char *TorVersion;
  2440. /** Holds any unrecognized values we found in the state file, in the order
  2441. * in which we found them. */
  2442. config_line_t *ExtraLines;
  2443. /** When did we last rotate our onion key? "0" for 'no idea'. */
  2444. time_t LastRotatedOnionKey;
  2445. } or_state_t;
  2446. #define MAX_SOCKS_REPLY_LEN 1024
  2447. #define MAX_SOCKS_ADDR_LEN 256
  2448. #define SOCKS_NO_AUTH 0x00
  2449. #define SOCKS_USER_PASS 0x02
  2450. /** Please open a TCP connection to this addr:port. */
  2451. #define SOCKS_COMMAND_CONNECT 0x01
  2452. /** Please turn this FQDN into an IP address, privately. */
  2453. #define SOCKS_COMMAND_RESOLVE 0xF0
  2454. /** Please turn this IP address into an FQDN, privately. */
  2455. #define SOCKS_COMMAND_RESOLVE_PTR 0xF1
  2456. /* || 0 is for -Wparentheses-equality (-Wall?) appeasement under clang */
  2457. #define SOCKS_COMMAND_IS_CONNECT(c) (((c)==SOCKS_COMMAND_CONNECT) || 0)
  2458. #define SOCKS_COMMAND_IS_RESOLVE(c) ((c)==SOCKS_COMMAND_RESOLVE || \
  2459. (c)==SOCKS_COMMAND_RESOLVE_PTR)
  2460. /********************************* circuitbuild.c **********************/
  2461. /** How many hops does a general-purpose circuit have by default? */
  2462. #define DEFAULT_ROUTE_LEN 3
  2463. /* Circuit Build Timeout "public" structures. */
  2464. /** Precision multiplier for the Bw weights */
  2465. #define BW_WEIGHT_SCALE 10000
  2466. #define BW_MIN_WEIGHT_SCALE 1
  2467. #define BW_MAX_WEIGHT_SCALE INT32_MAX
  2468. /** Total size of the circuit timeout history to accumulate.
  2469. * 1000 is approx 2.5 days worth of continual-use circuits. */
  2470. #define CBT_NCIRCUITS_TO_OBSERVE 1000
  2471. /** Width of the histogram bins in milliseconds */
  2472. #define CBT_BIN_WIDTH ((build_time_t)50)
  2473. /** Number of modes to use in the weighted-avg computation of Xm */
  2474. #define CBT_DEFAULT_NUM_XM_MODES 3
  2475. #define CBT_MIN_NUM_XM_MODES 1
  2476. #define CBT_MAX_NUM_XM_MODES 20
  2477. /** A build_time_t is milliseconds */
  2478. typedef uint32_t build_time_t;
  2479. /**
  2480. * CBT_BUILD_ABANDONED is our flag value to represent a force-closed
  2481. * circuit (Aka a 'right-censored' pareto value).
  2482. */
  2483. #define CBT_BUILD_ABANDONED ((build_time_t)(INT32_MAX-1))
  2484. #define CBT_BUILD_TIME_MAX ((build_time_t)(INT32_MAX))
  2485. /** Save state every 10 circuits */
  2486. #define CBT_SAVE_STATE_EVERY 10
  2487. /* Circuit build times consensus parameters */
  2488. /**
  2489. * How long to wait before actually closing circuits that take too long to
  2490. * build in terms of CDF quantile.
  2491. */
  2492. #define CBT_DEFAULT_CLOSE_QUANTILE 95
  2493. #define CBT_MIN_CLOSE_QUANTILE CBT_MIN_QUANTILE_CUTOFF
  2494. #define CBT_MAX_CLOSE_QUANTILE CBT_MAX_QUANTILE_CUTOFF
  2495. /**
  2496. * How many circuits count as recent when considering if the
  2497. * connection has gone gimpy or changed.
  2498. */
  2499. #define CBT_DEFAULT_RECENT_CIRCUITS 20
  2500. #define CBT_MIN_RECENT_CIRCUITS 3
  2501. #define CBT_MAX_RECENT_CIRCUITS 1000
  2502. /**
  2503. * Maximum count of timeouts that finish the first hop in the past
  2504. * RECENT_CIRCUITS before calculating a new timeout.
  2505. *
  2506. * This tells us whether to abandon timeout history and set
  2507. * the timeout back to whatever circuit_build_times_get_initial_timeout()
  2508. * gives us.
  2509. */
  2510. #define CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT (CBT_DEFAULT_RECENT_CIRCUITS*9/10)
  2511. #define CBT_MIN_MAX_RECENT_TIMEOUT_COUNT 3
  2512. #define CBT_MAX_MAX_RECENT_TIMEOUT_COUNT 10000
  2513. /** Minimum circuits before estimating a timeout */
  2514. #define CBT_DEFAULT_MIN_CIRCUITS_TO_OBSERVE 100
  2515. #define CBT_MIN_MIN_CIRCUITS_TO_OBSERVE 1
  2516. #define CBT_MAX_MIN_CIRCUITS_TO_OBSERVE 10000
  2517. /** Cutoff percentile on the CDF for our timeout estimation. */
  2518. #define CBT_DEFAULT_QUANTILE_CUTOFF 80
  2519. #define CBT_MIN_QUANTILE_CUTOFF 10
  2520. #define CBT_MAX_QUANTILE_CUTOFF 99
  2521. double circuit_build_times_quantile_cutoff(void);
  2522. /** How often in seconds should we build a test circuit */
  2523. #define CBT_DEFAULT_TEST_FREQUENCY 10
  2524. #define CBT_MIN_TEST_FREQUENCY 1
  2525. #define CBT_MAX_TEST_FREQUENCY INT32_MAX
  2526. /** Lowest allowable value for CircuitBuildTimeout in milliseconds */
  2527. #define CBT_DEFAULT_TIMEOUT_MIN_VALUE (1500)
  2528. #define CBT_MIN_TIMEOUT_MIN_VALUE 500
  2529. #define CBT_MAX_TIMEOUT_MIN_VALUE INT32_MAX
  2530. /** Initial circuit build timeout in milliseconds */
  2531. #define CBT_DEFAULT_TIMEOUT_INITIAL_VALUE (60*1000)
  2532. #define CBT_MIN_TIMEOUT_INITIAL_VALUE CBT_MIN_TIMEOUT_MIN_VALUE
  2533. #define CBT_MAX_TIMEOUT_INITIAL_VALUE INT32_MAX
  2534. int32_t circuit_build_times_initial_timeout(void);
  2535. #if CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT < CBT_MIN_MAX_RECENT_TIMEOUT_COUNT
  2536. #error "RECENT_CIRCUITS is set too low."
  2537. #endif
  2538. typedef struct circuit_build_times_s circuit_build_times_t;
  2539. /********************************* config.c ***************************/
  2540. /** An error from options_trial_assign() or options_init_from_string(). */
  2541. typedef enum setopt_err_t {
  2542. SETOPT_OK = 0,
  2543. SETOPT_ERR_MISC = -1,
  2544. SETOPT_ERR_PARSE = -2,
  2545. SETOPT_ERR_TRANSITION = -3,
  2546. SETOPT_ERR_SETTING = -4,
  2547. } setopt_err_t;
  2548. /********************************* connection_edge.c *************************/
  2549. /** Enumerates possible origins of a client-side address mapping. */
  2550. typedef enum {
  2551. /** We're remapping this address because the controller told us to. */
  2552. ADDRMAPSRC_CONTROLLER,
  2553. /** We're remapping this address because of an AutomapHostsOnResolve
  2554. * configuration. */
  2555. ADDRMAPSRC_AUTOMAP,
  2556. /** We're remapping this address because our configuration (via torrc, the
  2557. * command line, or a SETCONF command) told us to. */
  2558. ADDRMAPSRC_TORRC,
  2559. /** We're remapping this address because we have TrackHostExit configured,
  2560. * and we want to remember to use the same exit next time. */
  2561. ADDRMAPSRC_TRACKEXIT,
  2562. /** We're remapping this address because we got a DNS resolution from a
  2563. * Tor server that told us what its value was. */
  2564. ADDRMAPSRC_DNS,
  2565. /** No remapping has occurred. This isn't a possible value for an
  2566. * addrmap_entry_t; it's used as a null value when we need to answer "Why
  2567. * did this remapping happen." */
  2568. ADDRMAPSRC_NONE
  2569. } addressmap_entry_source_t;
  2570. #define addressmap_entry_source_bitfield_t ENUM_BF(addressmap_entry_source_t)
  2571. /********************************* control.c ***************************/
  2572. /** Used to indicate the type of a circuit event passed to the controller.
  2573. * The various types are defined in control-spec.txt */
  2574. typedef enum circuit_status_event_t {
  2575. CIRC_EVENT_LAUNCHED = 0,
  2576. CIRC_EVENT_BUILT = 1,
  2577. CIRC_EVENT_EXTENDED = 2,
  2578. CIRC_EVENT_FAILED = 3,
  2579. CIRC_EVENT_CLOSED = 4,
  2580. } circuit_status_event_t;
  2581. /** Used to indicate the type of a CIRC_MINOR event passed to the controller.
  2582. * The various types are defined in control-spec.txt . */
  2583. typedef enum circuit_status_minor_event_t {
  2584. CIRC_MINOR_EVENT_PURPOSE_CHANGED,
  2585. CIRC_MINOR_EVENT_CANNIBALIZED,
  2586. } circuit_status_minor_event_t;
  2587. /** Used to indicate the type of a stream event passed to the controller.
  2588. * The various types are defined in control-spec.txt */
  2589. typedef enum stream_status_event_t {
  2590. STREAM_EVENT_SENT_CONNECT = 0,
  2591. STREAM_EVENT_SENT_RESOLVE = 1,
  2592. STREAM_EVENT_SUCCEEDED = 2,
  2593. STREAM_EVENT_FAILED = 3,
  2594. STREAM_EVENT_CLOSED = 4,
  2595. STREAM_EVENT_NEW = 5,
  2596. STREAM_EVENT_NEW_RESOLVE = 6,
  2597. STREAM_EVENT_FAILED_RETRIABLE = 7,
  2598. STREAM_EVENT_REMAP = 8
  2599. } stream_status_event_t;
  2600. /** Used to indicate the type of an OR connection event passed to the
  2601. * controller. The various types are defined in control-spec.txt */
  2602. typedef enum or_conn_status_event_t {
  2603. OR_CONN_EVENT_LAUNCHED = 0,
  2604. OR_CONN_EVENT_CONNECTED = 1,
  2605. OR_CONN_EVENT_FAILED = 2,
  2606. OR_CONN_EVENT_CLOSED = 3,
  2607. OR_CONN_EVENT_NEW = 4,
  2608. } or_conn_status_event_t;
  2609. /** Used to indicate the type of a buildtime event */
  2610. typedef enum buildtimeout_set_event_t {
  2611. BUILDTIMEOUT_SET_EVENT_COMPUTED = 0,
  2612. BUILDTIMEOUT_SET_EVENT_RESET = 1,
  2613. BUILDTIMEOUT_SET_EVENT_SUSPENDED = 2,
  2614. BUILDTIMEOUT_SET_EVENT_DISCARD = 3,
  2615. BUILDTIMEOUT_SET_EVENT_RESUME = 4
  2616. } buildtimeout_set_event_t;
  2617. /** Execute the statement <b>stmt</b>, which may log events concerning the
  2618. * connection <b>conn</b>. To prevent infinite loops, disable log messages
  2619. * being sent to controllers if <b>conn</b> is a control connection.
  2620. *
  2621. * Stmt must not contain any return or goto statements.
  2622. */
  2623. #define CONN_LOG_PROTECT(conn, stmt) \
  2624. STMT_BEGIN \
  2625. int _log_conn_is_control; \
  2626. tor_assert(conn); \
  2627. _log_conn_is_control = (conn->type == CONN_TYPE_CONTROL); \
  2628. if (_log_conn_is_control) \
  2629. disable_control_logging(); \
  2630. STMT_BEGIN stmt; STMT_END; \
  2631. if (_log_conn_is_control) \
  2632. enable_control_logging(); \
  2633. STMT_END
  2634. /** Enum describing various stages of bootstrapping, for use with controller
  2635. * bootstrap status events. The values range from 0 to 100. */
  2636. typedef enum {
  2637. BOOTSTRAP_STATUS_UNDEF=-1,
  2638. BOOTSTRAP_STATUS_STARTING=0,
  2639. BOOTSTRAP_STATUS_CONN_DIR=5,
  2640. BOOTSTRAP_STATUS_HANDSHAKE=-2,
  2641. BOOTSTRAP_STATUS_HANDSHAKE_DIR=10,
  2642. BOOTSTRAP_STATUS_ONEHOP_CREATE=15,
  2643. BOOTSTRAP_STATUS_REQUESTING_STATUS=20,
  2644. BOOTSTRAP_STATUS_LOADING_STATUS=25,
  2645. BOOTSTRAP_STATUS_LOADING_KEYS=40,
  2646. BOOTSTRAP_STATUS_REQUESTING_DESCRIPTORS=45,
  2647. BOOTSTRAP_STATUS_LOADING_DESCRIPTORS=50,
  2648. BOOTSTRAP_STATUS_CONN_OR=80,
  2649. BOOTSTRAP_STATUS_HANDSHAKE_OR=85,
  2650. BOOTSTRAP_STATUS_CIRCUIT_CREATE=90,
  2651. BOOTSTRAP_STATUS_DONE=100
  2652. } bootstrap_status_t;
  2653. /********************************* dirserv.c ***************************/
  2654. /** An enum to describe what format we're generating a routerstatus line in.
  2655. */
  2656. typedef enum {
  2657. /** For use in a v2 opinion */
  2658. NS_V2,
  2659. /** For use in a consensus networkstatus document (ns flavor) */
  2660. NS_V3_CONSENSUS,
  2661. /** For use in a vote networkstatus document */
  2662. NS_V3_VOTE,
  2663. /** For passing to the controlport in response to a GETINFO request */
  2664. NS_CONTROL_PORT,
  2665. /** For use in a consensus networkstatus document (microdesc flavor) */
  2666. NS_V3_CONSENSUS_MICRODESC
  2667. } routerstatus_format_type_t;
  2668. /********************************* dirvote.c ************************/
  2669. typedef struct vote_timing_t vote_timing_t;
  2670. /********************************* geoip.c **************************/
  2671. /** Indicates an action that we might be noting geoip statistics on.
  2672. * Note that if we're noticing CONNECT, we're a bridge, and if we're noticing
  2673. * the others, we're not.
  2674. */
  2675. typedef enum {
  2676. /** We've noticed a connection as a bridge relay or entry guard. */
  2677. GEOIP_CLIENT_CONNECT = 0,
  2678. /** We've served a networkstatus consensus as a directory server. */
  2679. GEOIP_CLIENT_NETWORKSTATUS = 1,
  2680. } geoip_client_action_t;
  2681. /** Indicates either a positive reply or a reason for rejectng a network
  2682. * status request that will be included in geoip statistics. */
  2683. typedef enum {
  2684. /** Request is answered successfully. */
  2685. GEOIP_SUCCESS = 0,
  2686. /** V3 network status is not signed by a sufficient number of requested
  2687. * authorities. */
  2688. GEOIP_REJECT_NOT_ENOUGH_SIGS = 1,
  2689. /** Requested network status object is unavailable. */
  2690. GEOIP_REJECT_UNAVAILABLE = 2,
  2691. /** Requested network status not found. */
  2692. GEOIP_REJECT_NOT_FOUND = 3,
  2693. /** Network status has not been modified since If-Modified-Since time. */
  2694. GEOIP_REJECT_NOT_MODIFIED = 4,
  2695. /** Directory is busy. */
  2696. GEOIP_REJECT_BUSY = 5,
  2697. } geoip_ns_response_t;
  2698. #define GEOIP_NS_RESPONSE_NUM 6
  2699. /** Directory requests that we are measuring can be either direct or
  2700. * tunneled. */
  2701. typedef enum {
  2702. DIRREQ_DIRECT = 0,
  2703. DIRREQ_TUNNELED = 1,
  2704. } dirreq_type_t;
  2705. /** Possible states for either direct or tunneled directory requests that
  2706. * are relevant for determining network status download times. */
  2707. typedef enum {
  2708. /** Found that the client requests a network status; applies to both
  2709. * direct and tunneled requests; initial state of a request that we are
  2710. * measuring. */
  2711. DIRREQ_IS_FOR_NETWORK_STATUS = 0,
  2712. /** Finished writing a network status to the directory connection;
  2713. * applies to both direct and tunneled requests; completes a direct
  2714. * request. */
  2715. DIRREQ_FLUSHING_DIR_CONN_FINISHED = 1,
  2716. /** END cell sent to circuit that initiated a tunneled request. */
  2717. DIRREQ_END_CELL_SENT = 2,
  2718. /** Flushed last cell from queue of the circuit that initiated a
  2719. * tunneled request to the outbuf of the OR connection. */
  2720. DIRREQ_CIRC_QUEUE_FLUSHED = 3,
  2721. /** Flushed last byte from buffer of the channel belonging to the
  2722. * circuit that initiated a tunneled request; completes a tunneled
  2723. * request. */
  2724. DIRREQ_CHANNEL_BUFFER_FLUSHED = 4
  2725. } dirreq_state_t;
  2726. #define WRITE_STATS_INTERVAL (24*60*60)
  2727. /********************************* microdesc.c *************************/
  2728. typedef struct microdesc_cache_t microdesc_cache_t;
  2729. /********************************* networkstatus.c *********************/
  2730. /** Possible statuses of a version of Tor, given opinions from the directory
  2731. * servers. */
  2732. typedef enum version_status_t {
  2733. VS_RECOMMENDED=0, /**< This version is listed as recommended. */
  2734. VS_OLD=1, /**< This version is older than any recommended version. */
  2735. VS_NEW=2, /**< This version is newer than any recommended version. */
  2736. VS_NEW_IN_SERIES=3, /**< This version is newer than any recommended version
  2737. * in its series, but later recommended versions exist.
  2738. */
  2739. VS_UNRECOMMENDED=4, /**< This version is not recommended (general case). */
  2740. VS_EMPTY=5, /**< The version list was empty; no agreed-on versions. */
  2741. VS_UNKNOWN, /**< We have no idea. */
  2742. } version_status_t;
  2743. /********************************* policies.c ************************/
  2744. /** Outcome of applying an address policy to an address. */
  2745. typedef enum {
  2746. /** The address was accepted */
  2747. ADDR_POLICY_ACCEPTED=0,
  2748. /** The address was rejected */
  2749. ADDR_POLICY_REJECTED=-1,
  2750. /** Part of the address was unknown, but as far as we can tell, it was
  2751. * accepted. */
  2752. ADDR_POLICY_PROBABLY_ACCEPTED=1,
  2753. /** Part of the address was unknown, but as far as we can tell, it was
  2754. * rejected. */
  2755. ADDR_POLICY_PROBABLY_REJECTED=2,
  2756. } addr_policy_result_t;
  2757. /********************************* rephist.c ***************************/
  2758. /** Possible public/private key operations in Tor: used to keep track of where
  2759. * we're spending our time. */
  2760. typedef enum {
  2761. SIGN_DIR, SIGN_RTR,
  2762. VERIFY_DIR, VERIFY_RTR,
  2763. ENC_ONIONSKIN, DEC_ONIONSKIN,
  2764. TLS_HANDSHAKE_C, TLS_HANDSHAKE_S,
  2765. REND_CLIENT, REND_MID, REND_SERVER,
  2766. } pk_op_t;
  2767. /********************************* rendcommon.c ***************************/
  2768. typedef struct rend_authorized_client_t rend_authorized_client_t;
  2769. typedef struct rend_encoded_v2_service_descriptor_t
  2770. rend_encoded_v2_service_descriptor_t;
  2771. /** The maximum number of non-circuit-build-timeout failures a hidden
  2772. * service client will tolerate while trying to build a circuit to an
  2773. * introduction point. See also rend_intro_point_t.unreachable_count. */
  2774. #define MAX_INTRO_POINT_REACHABILITY_FAILURES 5
  2775. /** The minimum and maximum number of distinct INTRODUCE2 cells which a
  2776. * hidden service's introduction point will receive before it begins to
  2777. * expire. */
  2778. #define INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS 16384
  2779. /* Double the minimum value so the interval is [min, min * 2]. */
  2780. #define INTRO_POINT_MAX_LIFETIME_INTRODUCTIONS \
  2781. (INTRO_POINT_MIN_LIFETIME_INTRODUCTIONS * 2)
  2782. /** The minimum number of seconds that an introduction point will last
  2783. * before expiring due to old age. (If it receives
  2784. * INTRO_POINT_LIFETIME_INTRODUCTIONS INTRODUCE2 cells, it may expire
  2785. * sooner.)
  2786. *
  2787. * XXX Should this be configurable? */
  2788. #define INTRO_POINT_LIFETIME_MIN_SECONDS (18*60*60)
  2789. /** The maximum number of seconds that an introduction point will last
  2790. * before expiring due to old age.
  2791. *
  2792. * XXX Should this be configurable? */
  2793. #define INTRO_POINT_LIFETIME_MAX_SECONDS (24*60*60)
  2794. /** The maximum number of circuit creation retry we do to an intro point
  2795. * before giving up. We try to reuse intro point that fails during their
  2796. * lifetime so this is a hard limit on the amount of time we do that. */
  2797. #define MAX_INTRO_POINT_CIRCUIT_RETRIES 3
  2798. typedef struct rend_intro_point_t rend_intro_point_t;
  2799. typedef struct rend_service_descriptor_t rend_service_descriptor_t;
  2800. /********************************* routerlist.c ***************************/
  2801. typedef struct dir_server_t dir_server_t;
  2802. #define RELAY_REQUIRED_MIN_BANDWIDTH (75*1024)
  2803. #define BRIDGE_REQUIRED_MIN_BANDWIDTH (50*1024)
  2804. #define ROUTER_MAX_DECLARED_BANDWIDTH INT32_MAX
  2805. /* Flags for pick_directory_server() and pick_trusteddirserver(). */
  2806. /** Flag to indicate that we should not automatically be willing to use
  2807. * ourself to answer a directory request.
  2808. * Passed to router_pick_directory_server (et al).*/
  2809. #define PDS_ALLOW_SELF (1<<0)
  2810. /** Flag to indicate that if no servers seem to be up, we should mark all
  2811. * directory servers as up and try again.
  2812. * Passed to router_pick_directory_server (et al).*/
  2813. #define PDS_RETRY_IF_NO_SERVERS (1<<1)
  2814. /** Flag to indicate that we should not exclude directory servers that
  2815. * our ReachableAddress settings would exclude. This usually means that
  2816. * we're going to connect to the server over Tor, and so we don't need to
  2817. * worry about our firewall telling us we can't.
  2818. * Passed to router_pick_directory_server (et al).*/
  2819. #define PDS_IGNORE_FASCISTFIREWALL (1<<2)
  2820. /** Flag to indicate that we should not use any directory authority to which
  2821. * we have an existing directory connection for downloading server descriptors
  2822. * or extrainfo documents.
  2823. *
  2824. * Passed to router_pick_directory_server (et al)
  2825. */
  2826. #define PDS_NO_EXISTING_SERVERDESC_FETCH (1<<3)
  2827. /** Flag to indicate that we should not use any directory authority to which
  2828. * we have an existing directory connection for downloading microdescs.
  2829. *
  2830. * Passed to router_pick_directory_server (et al)
  2831. */
  2832. #define PDS_NO_EXISTING_MICRODESC_FETCH (1<<4)
  2833. /** Possible ways to weight routers when choosing one randomly. See
  2834. * routerlist_sl_choose_by_bandwidth() for more information.*/
  2835. typedef enum bandwidth_weight_rule_t {
  2836. NO_WEIGHTING, WEIGHT_FOR_EXIT, WEIGHT_FOR_MID, WEIGHT_FOR_GUARD,
  2837. WEIGHT_FOR_DIR
  2838. } bandwidth_weight_rule_t;
  2839. /** Flags to be passed to control router_choose_random_node() to indicate what
  2840. * kind of nodes to pick according to what algorithm. */
  2841. typedef enum {
  2842. CRN_NEED_UPTIME = 1<<0,
  2843. CRN_NEED_CAPACITY = 1<<1,
  2844. CRN_NEED_GUARD = 1<<2,
  2845. /* XXXX not used, apparently. */
  2846. CRN_WEIGHT_AS_EXIT = 1<<5,
  2847. CRN_NEED_DESC = 1<<6,
  2848. /* On clients, only provide nodes that satisfy ClientPreferIPv6OR */
  2849. CRN_PREF_ADDR = 1<<7,
  2850. /* On clients, only provide nodes that we can connect to directly, based on
  2851. * our firewall rules */
  2852. CRN_DIRECT_CONN = 1<<8,
  2853. /* On clients, only provide nodes with HSRend >= 2 protocol version which
  2854. * is required for hidden service version >= 3. */
  2855. CRN_RENDEZVOUS_V3 = 1<<9,
  2856. } router_crn_flags_t;
  2857. /** Return value for router_add_to_routerlist() and dirserv_add_descriptor() */
  2858. typedef enum was_router_added_t {
  2859. /* Router was added successfully. */
  2860. ROUTER_ADDED_SUCCESSFULLY = 1,
  2861. /* Extrainfo document was rejected because no corresponding router
  2862. * descriptor was found OR router descriptor was rejected because
  2863. * it was incompatible with its extrainfo document. */
  2864. ROUTER_BAD_EI = -1,
  2865. /* Router descriptor was rejected because it is already known. */
  2866. ROUTER_IS_ALREADY_KNOWN = -2,
  2867. /* General purpose router was rejected, because it was not listed
  2868. * in consensus. */
  2869. ROUTER_NOT_IN_CONSENSUS = -3,
  2870. /* Router was neither in directory consensus nor in any of
  2871. * networkstatus documents. Caching it to access later.
  2872. * (Applies to fetched descriptors only.) */
  2873. ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS = -4,
  2874. /* Router was rejected by directory authority. */
  2875. ROUTER_AUTHDIR_REJECTS = -5,
  2876. /* Bridge descriptor was rejected because such bridge was not one
  2877. * of the bridges we have listed in our configuration. */
  2878. ROUTER_WAS_NOT_WANTED = -6,
  2879. /* Router descriptor was rejected because it was older than
  2880. * OLD_ROUTER_DESC_MAX_AGE. */
  2881. ROUTER_WAS_TOO_OLD = -7, /* note contrast with 'NOT_NEW' */
  2882. /* DOCDOC */
  2883. ROUTER_CERTS_EXPIRED = -8
  2884. } was_router_added_t;
  2885. typedef struct tor_version_t tor_version_t;
  2886. #endif /* !defined(TOR_OR_H) */