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