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