Merge branch 'master' of black:tinc
[tinc] / doc / NETWORKING
1 This is the network infrastructure documentation for tinc, a Virtual Private
2 Network daemon.
3
4    Copyright 2001-2006 Guus Sliepen <guus@tinc-vpn.org>
5
6    Permission is granted to make and distribute verbatim copies of
7    this documentation provided the copyright notice and this
8    permission notice are preserved on all copies.
9
10    Permission is granted to copy and distribute modified versions of
11    this documentation under the conditions for verbatim copying,
12    provided that the entire resulting derived work is distributed
13    under the terms of a permission notice identical to this one.
14
15 1. Packet flow
16 ==============
17
18 There are two directions for packets. There are packets received from the tap
19 device that have to be sent out to other tinc daemon, and there are packets
20 that are received from other tinc daemons which have to be send to the tap
21 device. The first direction will be called the outgoing direction, while the
22 latter will be called the incoming direction.
23
24 1.1 Outgoing flow
25 -----------------
26
27         handle_tap_input()
28                 |
29                 |
30                 V
31          route_outgoing()
32                 |
33                 |
34                 V
35           send_packet()         ----
36           /           \        /    \
37          /             \      |   queue
38         V               V     V     /
39 send_tcppacket()  send_udppacket()--
40
41 Packets are read from the tap device by handle_tap_input(). The packets will be
42 marked as coming from ourself, and are then handled by route_outgoing(). This
43 function will determine the destination tinc daemon this packet has to be sent
44 to, and in the future it may also determine if this packet has to be broadcast
45 or multicast. route_outgoing() will call send_packet() (in case of
46 broad/multicast several times). send_packet() will check the destination
47 connection_t entry to see if it is a valid destination, and whether it has to
48 be sent via TCP or UDP. It will then either call send_tcppacket() or
49 send_udppacket(). Since a different key is used for UDP packets, which might
50 not be available at that time, send_udppacket() might put the packet in a queue
51 and send a REQ_KEY to the destination tinc daemon. If the key has been retrieved,
52 the packet will be fed to send_udppacket() again.
53
54 1.2 Incoming flow
55 -----------------
56
57                handle_vpn_input()
58                         |
59                         |
60                         V
61 tcppacket_h()  receive_udppacket()
62         \              /
63          \            /
64           V          V
65         receive_packet()
66                |
67                |
68                V
69         route_incoming()
70                |
71                |
72                V
73         accept_packet()
74
75 Packets from other tinc daemons can be received by tcppacket_h(), for TCP
76 packets, and receive_udppacket() via handle_vpn_input() for UDP packets.
77 receive_packet() actually does not have to do much, except logging and calling
78 route_incoming(), but it's there for symmetry with the scheme for the outgoing
79 flow. route_incoming() will change the MAC header of the packet if necessary to
80 let the kernel accept the packet after it has been sent to the tap device by
81 accept_packet().