or.h 133 KB

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