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