PROTOCOL 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. This is the protocol documentation for tinc, a Virtual Private Network daemon.
  2. Copyright 2000-2006 Guus Sliepen <guus@tinc-vpn.org>,
  3. 2000-2005 Ivo Timmmermans
  4. Permission is granted to make and distribute verbatim copies of
  5. this documentation provided the copyright notice and this
  6. permission notice are preserved on all copies.
  7. Permission is granted to copy and distribute modified versions of
  8. this documentation under the conditions for verbatim copying,
  9. provided that the entire resulting derived work is distributed
  10. under the terms of a permission notice identical to this one.
  11. 1. Protocols used in tinc
  12. -------------------------
  13. tinc uses several protocols to function correctly. To enter the
  14. network of tinc daemons that make up the virtual private network, tinc
  15. makes TCP connections to other tinc daemons. It uses the "meta
  16. protocol" for these connections. To exchange packets on the virtual
  17. network, UDP connections are made and the "packet protocol" is used.
  18. Tinc also needs to exchange network packets with the kernel. This is
  19. done using the ethertap device or the universal TUN/TAP device that
  20. can be found in various UNIX flavours.
  21. 2. Packet protocol
  22. ------------------
  23. Normal packets are sent without any state information, so the layout
  24. is pretty basic.
  25. A data packet can only be sent if the encryption key, cipher and digest are
  26. known to both parties, and the connection is activated. If the encryption key
  27. is not known, a request is sent to the destination using the meta connection to
  28. retreive it.
  29. 0 1 2 3 4 5 6 7 ... 97 98 99 100
  30. | seqno | data | MAC |
  31. \____________________________________/\_______________/
  32. | |
  33. encrypted using symmetric cipher digest
  34. The sequence number prevents replay attacks, the message authentication code
  35. prevents altered packets from being accepted.
  36. 3. Meta protocol
  37. ----------------
  38. The meta protocol is used to tie all tinc daemons together, and
  39. exchange information about which tinc daemon serves which virtual
  40. subnet.
  41. The meta protocol consists of requests that can be sent to the other
  42. side. Each request has a unique number and several parameters. All
  43. requests are represented in the standard ASCII character set. It is
  44. possible to use tools such as telnet or netcat to connect to a tinc
  45. daemon and to read and write requests by hand, provided that one
  46. understands the numeric codes sent.
  47. The authentication scheme is described in the SECURITY2 file. After a
  48. succesful authentication, the server and the client will exchange all the
  49. information about other tinc daemons and subnets they know of, so that both
  50. sides (and all the other tinc daemons behind them) have their information
  51. synchronised.
  52. daemon message
  53. --------------------------------------------------------------------------
  54. origin ADD_EDGE node1 node2 21.32.43.54 655 222 0
  55. | | | | | +-> options
  56. | | | | +----> weight
  57. | | | +--------> UDP port of node2
  58. | | +----------------> real address of node2
  59. | +-------------------------> name of destination node
  60. +-------------------------------> name of source node
  61. origin ADD_SUBNET node 192.168.1.0/24
  62. | | +--> prefixlength
  63. | +--------> network address
  64. +------------------> owner of this subnet
  65. --------------------------------------------------------------------------
  66. The ADD_EDGE messages are to inform other tinc daemons that a connection between
  67. two nodes exist. The address of the destination node is available so that
  68. VPN packets can be sent directly to that node.
  69. The ADD_SUBNET messages inform other tinc daemons that certain subnets belong
  70. to certain nodes. tinc will use it to determine to which node a VPN packet has
  71. to be sent.
  72. message
  73. ------------------------------------------------------------------
  74. DEL_EDGE node1 node2
  75. | +----> name of destination node
  76. +----------> name of source node
  77. DEL_SUBNET node 192.168.1.0/24
  78. | | +--> prefixlength
  79. | +--------> network address
  80. +------------------> owner of this subnet
  81. ------------------------------------------------------------------
  82. In case a connection between two daemons is closed or broken, DEL_EDGE messages
  83. are sent to inform the other daemons of that fact. Each daemon will calculate a
  84. new route to the the daemons, or mark them unreachable if there isn't any.
  85. message
  86. ------------------------------------------------------------------
  87. REQ_KEY origin destination
  88. | +--> name of the tinc daemon it wants the key from
  89. +----------> name of the daemon that wants the key
  90. ANS_KEY origin destination 4ae0b0a82d6e0078 91 64 4
  91. | | \______________/ | | +--> MAC length
  92. | | | | +-----> digest algorithm
  93. | | | +--------> cipher algorithm
  94. | | +--> 128 bits key
  95. | +--> name of the daemon that wants the key
  96. +----------> name of the daemon that uses this key
  97. KEY_CHANGED origin
  98. +--> daemon that has changed it's packet key
  99. --------------------------------------------------------------------------
  100. The keys used to encrypt VPN packets are not sent out directly. This is
  101. because it would generate a lot of traffic on VPNs with many daemons, and
  102. chances are that not every tinc daemon will ever send a packet to every
  103. other daemon. Instead, if a daemon needs a key it sends a request for it
  104. via the meta connection of the nearest hop in the direction of the
  105. destination. If any hop on the way has already learned the key, it will
  106. act as a proxy and forward its copy back to the requestor.
  107. daemon message
  108. --------------------------------------------------------------------------
  109. origin PING
  110. dest. PONG
  111. --------------------------------------------------------------------------
  112. There is also a mechanism to check if hosts are still alive. Since network
  113. failures or a crash can cause a daemon to be killed without properly
  114. shutting down the TCP connection, this is necessary to keep an up to date
  115. connection list. Pings are sent at regular intervals, except when there
  116. is also some other traffic. A little bit of salt (random data) is added
  117. with each PING and PONG message, to make sure that long sequences of PING/PONG
  118. messages without any other traffic won't result in known plaintext.
  119. This basically covers everything that is sent over the meta connection by
  120. tinc.