gsliepen / tinc

a VPN daemon
http://tinc-vpn.org/
Other
1.87k stars 280 forks source link

Which routing protocol does Tinc use in router mode? #444

Closed marek22k closed 4 months ago

marek22k commented 6 months ago

Hello,

I would like to know which routing protocol Tinc uses in router mode? As far as I understand it, this is a specially developed loop-free protocol. Is that correct? If so, what kind of protocol is it (path-vector routing protocol, link-state routing protocol, distance-vector routing protocol, ...)?

gsliepen commented 6 months ago

There might be some confusion here; "router mode" has nothing to do with the routing protocol that tinc uses internally to route packets between nodes. The same routing protocol is also used in switch and hub modes. What Mode does is change the way how tinc decides the destination node based in the header of the packet received from the tun/tap device. In router mode, it uses a routing table, the same as you see when you type ip route show or netstat -r. You can see this routing table by giving the command tinc -n $NETNAME dump subnets.

Tinc tries to send packets directly to the destination node. Only if that is not possible will it try to route it via intermediate nodes. The routing protocol used for that is a link-state routing protocol. From the link state it derives the shortest paths using Dijkstra's algorithm, and a minimum spanning tree using Kruskal's algorithm. The latter is used to handle broadcast packets.

marek22k commented 6 months ago

Many thanks for the answer!

I have one more question (I hope it's not too stupid): If a routing protocol is used, why is it necessary to specify Subnet = in the host configuration files?

gsliepen commented 6 months ago

Because tinc doesn't know how your network interfaces are configured. This is done on purpose: it simplifies the code, and it actually makes tinc much more flexible. The Subnet statements indicate which subnets belong to which nodes. That information is exchanged between nodes, so that if one node receives a packet from its local tun/tap interface, it can look at the desination IP address, and find out which node owns the Subnet that best matches that address, and then send the packet to it. Note also that you can have multiple Subnet statements in a given host configuration file.

marek22k commented 4 months ago

Thanks for the further answer! I took another look at Tinc today and apparently had a misunderstanding. I thought each node had to manually configure the subnets from every other node it is connected to. However, you only have to configure the subnet for your own node.