slight update
[rrq/rrqnet.git] / rrqnet.8.adoc
1 rrqnet(8)
2 =========
3 :doctype: manpage
4 :revdate: {sys:date "+%Y-%m-%d %H:%M:%S"}
5 :COLON: :
6 :EQUALS: =
7
8 NAME
9 ----
10 rrqnet - Packet tunneling over UDP, multiple channels
11
12 SYNOPSIS
13 --------
14 *rrqnet* [ OPTIONS ] _port_ ( _remote_ [*-i* _mac_]* )*
15
16 DESCRIPTION
17 -----------
18 *rrqnet* is a bi-directional networking plug that channels Ethernet
19 packets between a UDP port and either a tap interface or standard
20 input/output. It is configured on the command line by declarations of
21 the remotes it may communicate with.
22
23 OPTIONS
24 -------
25
26 Note that any options must be given in the fixed order:
27
28     [-v] [-4] [-B n] [-T n] [-m mcast] [-t tap]
29
30 *-v*::
31
32 This tells *rrqnet* to log its operation on +stderr+. Use *-vv* to
33 also see logs about connections and messaging, or *-vvv* for *rrqnet*
34 to be insanely verbose on +stderr+ about virtually everything.
35
36 *-4*::
37
38 This directs *rrqnet* to use an ipv4-only socket for its UDP. By
39 default it opens a dual ipv4/ipv6 socket and internally it then uses
40 address mapping for ipv4 (i.e. the ::ffff/96 prefix).
41
42 *-B* _n_::
43
44 This sets the number of receive buffers *rrqnet* should use. The
45 default is computed to be twice the number of dispatch threads (see
46 *-T* below). Receive buffers are pre-allocated and recycled.
47
48 *-T* _n_::
49
50 This sets the number of dispatch threads *rrqnet* should use. The
51 default is 5. The (additional) main thread handles packet reception,
52 where it immediately puts received packets into the buffer queue which
53 is serviced by the dispatch threads for optional decryption, dispatch
54 decision, optional encryption and delivery.
55
56 *-m* _mcast_::
57
58 This tells *rrqnet* to open an ipv4 UDP multicast channel as an
59 additional remote channel.
60
61 *-t* _tap_::
62
63 This tells *rrqnet* to open the nominated tap (the _tap_ interface
64 name) as local channel.
65
66 * When a tap is used, stdin and stdout are closed, but stderr remains
67 open.
68
69 * Without a *-t* argument, *rrqnet* will merely operate as a virtual
70 switch among its channels.
71
72 * With "*-*" as tap name, *rrqnet* will use stdin/stdout as local
73 networking channel in a format compatible with VDE plugs.
74
75 _address-block[:port][=cryptfile]_ [ *-i* _mac_[,_mac_]* ]::
76
77 Remotes are declared as +ipv4+ or +ipv6+ network address blocks
78 optionally with port and transport encryption key file pathname, and
79 optionally with specific MAC addresses (in a comma separated list) to
80 ignore. Note that an ipv6 address block might need surrounding square
81 brackets, to avoid confusion with the port number.
82
83 DETAILED DESCRIPTION
84 --------------------
85
86 The intended use of *rrqnet* is to provide VPN (virtual private
87 network) connectivity between hosts. Each VPN host runs its own
88 *rrqnet* daemon to channel the traffic to/from tap interfaces on the
89 hosts via UDP messaging between the hosts.
90
91 *rrqnet* is prepared for almost any network layout, even including a
92 collection of fully connected hosts, although the more common is a
93 "star' formation. See the EXAMPLES section for inspiration.
94
95 *rrqnet* includes logic aiming to protect against broadcast cycles.
96 Howewer it does not have the more advanced spanning tree logic that is
97 offered by bridge interfaces. In general it's best to avoid cycles and
98 rather run several *rrqnet* on a host with their local taps connected
99 in a bridge interface.
100
101 By default *rrqnet* opens an +ipv6+ socket on the given port. This
102 mode handles both +ipv6+ and +ipv4+ remotes with +ipv4+ remotes
103 handled by means of ipv6-mapped address translations. If *-4* is
104 given, *rrqnet* opens an +ipv4+ socket instead, and it cannot then
105 have +ipv6+ remotes.
106
107 A *rrqnet* daemon delivers the packets received from the local end,
108 i.e., the _tap_ or _stdio_, to known remote ends according the
109 targeted MAC addresses and established remote channels. Likewise,
110 packets from remotes are delivered to the local end or to other
111 remotes according to the targeted MAC addresses. If a packet is an
112 Ethernet broadcast, it is delivered to all (known) channels except the
113 one it came from.
114
115 If *rrqnet* is started without *-t* option it will operate like an
116 Ethernet switch that provides connectivity among its +UDP+ channels
117 without involving the host network other than for the tunneling.
118
119
120 REMOTE DECLARATIONS
121 ~~~~~~~~~~~~~~~~~~~
122
123 .ipv4 address block
124
125 This format declares remotes by +ipv4+ address, with optional network
126 prefix length (0-32), optional port (1-65535) and/or optional key file
127 pathname. *rrqnet* will accept packets from sources that match. If the
128 network prefix length, +n+, is omitted or given as 32, and a port is
129 given, then the remote is taken as an _uplink_.
130
131 .matching ipv4 uplink and downlink
132 ====
133 ----
134 [1.2.3.4]# rrqnet -t vpn0 2300 5.6.7.1:2300=/sec/vpn0.key
135 [5.6.7.1]# rrqnet -t vpn0 2300 1.2.3.0/24:2300=/sec/vpn0.key
136 ----
137 ====
138
139 .plain ipv6 address block
140
141 This format declares remotes by ipv6 address, with optional network
142 prefix length (0-128) and/or optional key file pathname. *rrqnet* will
143 accept packets from sources that match. This format (without square
144 brackets) is without port number part, and it thus only declares a
145 prefix mask for allowed sender hosts.
146
147 .ipv6 address block within square brackets
148
149 This format declares remotes by ipv6 address, with optional network
150 prefix length (0-128) within square brackets, then optionally a port
151 number and/or an optional key file pathname. *rrqnet* will accept
152 packets from sources that match. If the network prefix length, +n+, is
153 omitted, or given as 128, and a port number is given, then it declares
154 an _uplink_.
155
156 .matching ipv6 uplink and downlink
157 ====
158 ----
159 [fd::4]# rrqnet -t vpn0 2300 '[fe::1:4]:2300=/sec/vpn0.key'
160 [fe::1:4]# rrqnet -t vpn0 2300 '[fd::/120]:2300=/sec/vpn0.key'
161 ----
162 ====
163
164 Remotes are declarations to match the source IP addresses for UDP
165 traffic. It is either a full host and port address, or an address
166 block with or without port number. A full network address and port
167 (e.g +[fe::1:4]:2300+ of example 2) declares an _uplink_ that the
168 declaring *rrqnet* daemon will establish and maintain by means of
169 regular heartbeat messaging. An address block declaration defines the
170 mask for allowed incoming connections, aka _downlinks_, that teh
171 declaring dameon expects are maintained as uplinks by the remote
172 *rrqnet* daemons.
173
174 The *-i* option, if used for a remote declaration, is followed by a
175 comma separated list of the MAC addresses to ignore on the associated
176 channel. The *rrqnet* daemon will then just drop any packet with those
177 MAC addresses (whether source or destination) on the remotes of the
178 channel.
179
180 MULTICAST CHANNEL
181 -----------------
182
183 With the *-m* option, the *rrqnet* daemon also listens for packets on
184 the declared ipv4 multicast address. It is then treated as a separate,
185 persistent remote channel.
186
187 A multicast channel is declared using the format:
188 *ipv4:port{=keyfile}*. I.e. it includes the multicast ipv4 address,
189 the port number (1-65535), and optionally a key file pathname. The
190 multicast channel is an additional communication channel, but anything
191 received on it will be treated as being from the multicast IP rather
192 than the actual source IP.
193
194 .multicast example without other remotes
195 ====
196 ----
197 # rrqnet -m 244.0.2.1:2000 -t vpn0
198 ----
199 ====
200
201 The multicast channel is compatible with QEMU multicast socket.
202
203 TRANSPORT ENCRYPTION
204 --------------------
205
206 Transport encryption is added to a channel by menas of using a shared
207 key. This is a sizable file, say 1 Mb, of binary data that is used for
208 scrambling the network packets. For example, 1 Mb random data is fine.
209
210 .preparing 1 Mb key file with random content
211 ====
212 ----
213 dd if=/dev/random of=/sec/keyfile bs=1M count=1
214 ----
215 ====
216
217 The key file needs to be copied to all hosts.
218
219 A channel that has a key file is declared by appending it to the
220 channel declaration, as in the following example.
221
222 .another example of a downlink with encryption
223 ====
224 ----
225 [10.0.0.1]# rrqnet -v -t tap0 1400 10.2.0.0/16:1400=/sec/keyfile
226 ----
227 ====
228
229 That declaration says that all channels with hosts of ipv4 address
230 +10.2.0.0/16+, port 1400, use the file +/sec/keyfile+ for transport
231 encryption.
232
233
234 FURTHER EXAMPLES
235 ----------------
236
237 Simple rrqnet set up (ipv6)
238 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
239 This is an example set up for connecting two hosts with *rrqnet*,
240 without transport encryption. We pretend these hosts are mutually
241 reachable with ipv6 addresses +fe::2+ and +fe::1:3+ respectively, and
242 we want to use the ipv6 network +fd::1000:0/120+ over *rrqnet*. A
243 nominal set up might then be as follows:
244
245 .simple rrqnet set up (ipv6)
246 ====
247 ----
248 [fe::2]# ip tuntap add tap0 mode tap
249 [fe::2]# ifconfig tap0 fd::1000:10/120 up
250 [fe::2]# rrqnet -v -t tap0 1400 '[fe::1:3]:1400' &
251 --
252 [fe::1:3]# ip tuntap add tap0 mode tap
253 [fe::1:3]# ifconfig tap0 fd::1000:20/120 up
254 [fe::1:3]# rrqnet -v -t tap0 1400 '[fe::2]:1400' &
255 ----
256 ====
257
258 Thus, the host +fe::2+ is set up with a tap, +tap0+, having +ipv6+
259 address and net +fd::1000:10/120+, and a *rrqnet* daemon for the tap
260 and UDP port +1400+ that uplinks to a remote *rrqnet* at +fe::1:3+
261 port +1400+. Similarly, the host +fe::1:3+ is set up with a tap
262 +tap0+, having +ipv6+ address and net +fd::1000:20/120+, and a *rrqnet*
263 daemon for the tap and UDP port +1400+ that uplinks to a remote
264 *rrqnet* at +fe::2+ port +1400+.
265
266 This example also needs ipv6 address resolution set up, which uses the
267 MAC addresses of the two taps. Let's say it's +02:00:00:00:00:02+ for
268 +tap0+ on +fe::2+ and +04:00:00:00:00:04+ for +tap0+ on +fe::1:3+.
269 Then address resolution is established with the following:
270
271 .example of ipv6 address resolution set up
272 ====
273 ----
274 [fe::2]# ip neigh add fd::1000:20 dev tap0 lladdr 04:00:00:00:00:04
275 --
276 [fe::1:3]# ip neigh add fd::1000:10 dev tap0 lladdr 02:00:00:00:00:02
277 ----
278 ====
279
280 Simple rrqnet set up (ipv4)
281 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
282
283 This is an example set up for connecting two hosts with *rrqnet*,
284 without transport encryption. We pretend these hosts are mutually
285 reachable with ipv4 addresses +10.0.0.1+ and +192.168.0.1+
286 respectively, and we want to use the ipv4 network +10.100.100.0/24+
287 over *rrqnet*. A nominal set up might be as follows:
288
289 .Simple rrqnet set up (ipv4)
290 ====
291 ----
292 [10.0.0.1]# ip tuntap add tap0 mode tap
293 [10.0.0.1]# ifconfig tap0 10.100.100.1/24 up
294 [10.0.0.1]# rrqnet -v -t tap0 1400 192.168.0.1:1400 &
295 --
296 [192.168.0.1]# ip tuntap add tap0 mode tap
297 [192.168.0.1]# ifconfig tap0 10.100.100.2/24 up
298 [192.168.0.1]# rrqnet -v -t tap0 1400 10.0.0.1:1400 &
299 ----
300 ====
301
302 Thus, the host +10.0.0.1+ is set up with a tap, +tap0+, having ipv4
303 address and net +10.100.100.1/24+, and a *rrqnet* daemon for the tap
304 and UDP port +1400+ that uplinks to a remote *rrqnet* at +192.168.0.1+
305 port +1400+. Similarly, the host +192.168.0.1+ is set up with a tap
306 +tap0+, having +ipv4+ address and net +10.100.100.2/24+, and a
307 *rrqnet* daemon for the tap and UDP port +1400+ that uplinks to a
308 remote *rrqnet* at +10.0.0.1+ port 1400.
309
310 The kernel automagically performs ipv4 address resolution to learn the
311 MAC addresses associated with the remote ipv4 addresses through the
312 taps.
313
314 rrqnet set up through NAT
315 ~~~~~~~~~~~~~~~~~~~~~~~~~
316
317 If one of the hosts, say +192.168.0.1+ is behind a NAT router with
318 different IP, say, a dynamic IP on the net +10.2.0.0/16+, we need a
319 different set up. In this scenario, the first host would be set up as
320 a "server" and the second a client that would utilize the router's NAT
321 function for return traffic. The set up would be as follows:
322
323 .rrqnet set up through NAT
324 ====
325 ----
326 [10.0.0.1]# ip tuntap add tap0 mode tap
327 [10.0.0.1]# ifconfig tap0 10.100.100.1 up
328 [10.0.0.1]# rrqnet -v -t tap0 1400 10.2.0.0/16:1400 &
329 --
330 [192.168.0.1]# ip tuntap add tap0 mode tap
331 [192.168.0.1]# ifconfig tap0 10.100.100.2 up
332 [192.168.0.1]# rrqnet -v -t tap0 1400 10.0.0.1:1400 &
333 ----
334 ====
335
336 Thus, the "server" is set up to allow connections from any host on the
337 network +10.2.0.0/16+, port 1400, while the "client" is set up the
338 same way as in the simple example above. The client will establish and
339 uphold the connection by virtue of its 30 second "heart beat", and
340 return traffic will be channeled via the router's NAT function.
341
342 Note that the server sees the _external_ IP of the client and not its
343 _internal_ IP. The server's *rrqnet* therefor has a remote declaration
344 to allow messages from that external IP, and in the example case, even
345 an address block of a 16 bit common prefix (the choice of a 16 bit
346 prefix is merely for the sake of this example).
347
348 Multiple client hosts
349 ~~~~~~~~~~~~~~~~~~~~~
350
351 In a "client-server" set up, there can be any number of "client"
352 hosts. However, the "clients" behind a common NAT router must then use
353 distinct ports as otherwise the router will be confused about the
354 return traffic.
355
356 With multiple remote channels, a *rrqnet* daemon serves as a network
357 switch that forwards traffic in between the channels as well as to and
358 from the "server" tap. The daemon also forwards Ethernet broadcasts
359 out on all established channels in support of ARP messaging.
360
361 Further, a *rrqnet* daemon may be both a "server" with down-link
362 channels, and a "client" with one or more up-link channels, all at the
363 same time. Such a daemon forwards traffic between all established
364 channels by means of the Ethernet addresses, as well as broadcasts
365 onto all channels
366
367 Stdio network
368 ~~~~~~~~~~~~~
369 The *rrqnet* daemon may be set up to use standard input/output rather
370 than a tap for local network traffic. This operation mode has some
371 rare use cases, such as linking two *rrqnet* daemons, or connecting to
372 a VDE network. For example:
373
374 .stdio network between two rrqnet plugs
375 ====
376 ----
377 # dpipe rrqnet 1400 0.0.0.0/0=keyfile0 = rrqnet 1401 0.0.0.0/0=keyfile1 &
378 ----
379 ====
380
381 That example set up would make a connection between the two "server"
382 daemons operating at different UDP ports, accepting messages from any
383 ipv4 host, where port +1400+ has +keyfile0+ for transport encryption,
384 and +1401+ has +keyfile1+ for transport encryption.
385
386 Another example would be for connecting the *rrqnet* traffic to a VDE
387 network via a +vde_plug+ as in the following example:
388
389 .stdio network to a vde_plug
390 ====
391 ----
392 # dpipe rrqnet 1400 0.0.0.0/0 = vde_plug /tmp/vde1.ctl &
393 ----
394 ====
395
396 Note that *rrqnet* and +vde_plug+ use compatible stdio packet
397 representation.
398
399 NOTES
400 -----
401
402 The UDP receiver in *rrqnet* accepts packets from the specified remote
403 ends only, but it doesn't perform any payload verification. Messages
404 smaller than 12 bytes are taken as "heartbeats", and larger messages
405 are first decrypted as applicable, then treated as Ethernet messages
406 and delivered according to their destination MAC addresses. *rrqnet*
407 versions after 0.2.3 adds some data to the Ethernet packet in the UDP
408 communication.
409
410 *rrqnet* bridges its connections, and forwards Ethernet broadcasts to
411 all known end-points except the incoming one. The input logic takes
412 care of avoiding broadcast cycles.
413
414 *rrqnet* does not have Spanning Tree Logic (STL), but some simple
415 timing logic based on binding MAC addresses to remotes. That binding
416 is sticky for a short time: 6s for broadcast and 20s for unicast. Any
417 packet received during that time from the same MAC address via another
418 remote is dropped. Also, a downlink without incoming traffic for 3
419 minutes is considered stale.
420
421 *rrqnet* sends a "heartbeat" of an empty UDP message on its uplinks
422 every 30 seconds. This is done in order to maintain the channel with
423 the remote end without actually binding any MAC address.
424
425 When the local input is a tap, *rrqnet* closes standard input and
426 standard output, but not standard error, before entering the packet
427 handling loop.
428
429 Using +-t -+ for stdin/stdout packet traffic is compatible with
430 +vde_plug+.
431
432 SEE ALSO
433 --------
434 *rrqnet-cron.sh(8)* - Management script to uphold a *rrqnet* plug.
435
436 *vde_plug(1)* - Virtual Distributed Ethernet plug.
437
438 AUTHOR
439 ------
440 Ralph Rönnquist <ralph.ronnquist@gmail.com>