Blob


1 .\" $OpenBSD: relayd.conf.5,v 1.218 2026/05/19 05:06:41 rsadowski Exp $
2 .\"
3 .\" Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org>
4 .\" Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
5 .\"
6 .\" Permission to use, copy, modify, and distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
9 .\"
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 .\"
18 .Dd $Mdocdate: May 19 2026 $
19 .Dt RELAYD.CONF 5
20 .Os
21 .Sh NAME
22 .Nm relayd.conf
23 .Nd relay daemon configuration file
24 .Sh DESCRIPTION
25 .Nm
26 is the configuration file for the relay daemon,
27 .Xr relayd 8 .
28 .Pp
29 .Nm
30 is divided into the following main sections:
31 .Bl -tag -width xxxx
32 .It Sx Macros
33 Definitions of variables that can be used later, simplifying the
34 configuration file.
35 .It Sx Global configuration
36 Global settings for
37 .Xr relayd 8 .
38 Do note that the config file allows global settings to be added after
39 defining tables in the config file, but those tables will use the
40 built-in defaults instead of the global settings below them.
41 .It Sx Tables
42 Table definitions describe a list of hosts,
43 in a similar fashion to
44 .Xr pf 4
45 tables.
46 They are used for relay, redirection, and router target selection with
47 the described options and health checking on the host they contain.
48 .It Sx Redirections
49 Redirections are translated to
50 .Xr pf 4
51 rdr-to rules for stateful forwarding to a target host from a
52 health-checked table on layer 3.
53 .It Sx Relays
54 Relays allow application layer load balancing, TLS acceleration, and
55 general purpose TCP proxying on layer 7.
56 .It Sx Protocols
57 Protocols are predefined settings and filter rules for relays.
58 .It Sx Routers
59 Routers are used to insert routes with health-checked gateways for
60 (WAN) link balancing.
61 .El
62 .Pp
63 Within the sections,
64 a host
65 .Ar address
66 can be specified by IPv4 address, IPv6 address, interface name,
67 interface group, or DNS hostname.
68 If the address is an interface name,
69 .Xr relayd 8
70 will look up the first IPv4 address and any other IPv4 and IPv6
71 addresses of the specified network interface.
72 A
73 .Ar port
74 can be specified by number or name.
75 The port name to number mappings are found in the file
76 .Pa /etc/services ;
77 see
78 .Xr services 5
79 for details.
80 .Pp
81 The current line can be extended over multiple lines using a backslash
82 .Pq Sq \e .
83 Comments can be put anywhere in the file using a hash mark
84 .Pq Sq # ,
85 and extend to the end of the current line.
86 Care should be taken when commenting out multi-line text:
87 the comment is effective until the end of the entire block.
88 .Pp
89 Arguments not beginning with a letter, digit, or underscore
90 must be quoted.
91 .Pp
92 Additional configuration files can be included with the
93 .Ic include
94 keyword, for example:
95 .Bd -literal -offset indent
96 include "/etc/relayd.conf.local"
97 .Ed
98 .Ss Macros
99 A macro is defined with a command of the form
100 .Ar name Ns = Ns Ar value .
101 The macro
102 .Ar name
103 can contain letters, digits, and underscores and cannot be a reserved word
104 (for example,
105 .Ic table ,
106 .Ic relay ,
107 or
108 .Ic timeout ) .
109 Within unquoted arguments, the string
110 .Pf $ Ar name
111 is later expanded to
112 .Ar value .
113 .Pp
114 For example:
115 .Bd -literal -offset indent
116 www1="10.0.0.1"
117 www2="10.0.0.2"
118 table <webhosts> {
119 $www1
120 $www2
122 .Ed
123 .Ss Global configuration
124 Here are the settings that can be set globally:
125 .Bl -tag -width Ds
126 .It Ic agentx Oo Ic context Ar context Oc Oo Ic path Ar path Oc
127 Export
128 .Xr relayd 8
129 metrics via an agentx compatible
130 .Pq snmp
131 daemon by connecting to
132 .Ar path .
133 Metrics can be found under the relaydMIBObjects subtree
134 .Pq enterprises.30155.3 .
135 If
136 .Ar path
137 is omitted, it will default to
138 .Pa /var/agentx/master .
139 .Ar Context
140 is the SNMPv3 context and can usually be omitted.
141 .It Ic interval Ar number
142 Set the interval in seconds at which the hosts will be checked.
143 The default interval is 10 seconds.
144 .It Xo
145 .Ic log
146 .Pq Ic state changes Ns | Ns Ic host checks
147 .Xc
148 Log host checks:
149 Either log only the
150 .Ic state changes
151 of hosts or log all
152 .Ic host checks
153 that were run, even if the state didn't change.
154 The host state can be
155 .Dq up
156 (the health check completed successfully),
157 .Dq down
158 (the host is down or didn't match the check criteria),
159 or
160 .Dq unknown
161 (the host is disabled or has not been checked yet).
162 .It Xo
163 .Ic log connection Op Ic errors
164 .Xc
165 When using relays, log all TCP connections.
166 Optionally log only
167 .Ic connection errors .
168 .It Ic prefork Ar number
169 When using relays, run the specified number of processes to handle
170 relayed connections.
171 This increases the performance and prevents delays when connecting
172 to a relay.
173 .Xr relayd 8
174 runs 3 relay processes by default and every process will handle
175 all configured relays.
176 .It Ic socket Qo Ar path Qc
177 Create a control socket at
178 .Ar path .
179 By default
180 .Pa /var/run/relayd.sock
181 is used.
182 .It Ic timeout Ar number
183 Set the global timeout in milliseconds for checks.
184 This can be overridden by the timeout value in the table definitions.
185 The default timeout is 200 milliseconds and it must not exceed the
186 global interval.
187 The default value is optimized for checks within the
188 same collision domain \(en use a higher timeout, such as 1000 milliseconds,
189 for checks of hosts in other subnets.
190 If this option is to be set, it should be placed before overrides in tables.
191 .El
192 .Ss Tables
193 Tables are used to group a set of hosts as the target for redirections
194 or relays; they will be mapped to a
195 .Xr pf 4
196 table for redirections.
197 Tables may be defined with the following attribute:
198 .Bl -tag -width disable
199 .It Ic disable
200 Start the table disabled \(en no hosts will be checked in this table.
201 The table can be later enabled through
202 .Xr relayctl 8 .
203 .El
204 .Pp
205 Each table must contain at least one host
206 .Ar address ;
207 multiple hosts are separated by newline, comma, or whitespace.
208 Host entries may be defined with the following attributes:
209 .Bl -tag -width retry
210 .It Ic ip ttl Ar number
211 Change the default time-to-live value in the IP headers for host checks.
212 .It Ic parent Ar number
213 The optional parent option inherits the state from a parent
214 host with the specified identifier.
215 The check will be skipped for this host and copied from the parent host.
216 This can be used to prevent multiple checks on hosts with multiple IP
217 addresses for the same service.
218 The host identifiers are sequentially assigned to the configured hosts
219 starting with 1; it can be shown with the
220 .Xr relayctl 8
221 .Ic show summary
222 commands.
223 .It Ic priority Ar number
224 Change the route priority used when adding a route.
225 If not specified, the kernel will set a priority of 8
226 .Pq Dv RTP_STATIC .
227 In ordinary use, a fallback route should be added statically with a very
228 high (e.g. 52) priority.
229 Unused in all other modes.
230 .It Ic retry Ar number
231 The optional retry option adds a tolerance for failed host checks;
232 the check will be retried for
233 .Ar number
234 more times before setting the host state to down.
235 If this table is used by a relay, it will also specify the number of
236 retries for outgoing connection attempts.
237 .El
238 .Pp
239 For example:
240 .Bd -literal -offset indent
241 table <service> { 192.168.1.1, 192.168.1.2, 192.168.2.3 }
242 table <fallback> disable { 10.1.5.1 retry 2 }
244 redirect "www" {
245 listen on www.example.com port 80
246 forward to <service> check http "/" code 200
247 forward to <fallback> check http "/" code 200
249 .Ed
250 .Pp
251 Tables are used by
252 .Ic forward to
253 directives in redirections or relays with a set of general options,
254 health-checking rules, and timings;
255 see the
256 .Sx Redirections
257 and
258 .Sx Relays
259 sections for more information about the forward context.
260 Table specific configuration directives are described below.
261 Multiple options can be appended to
262 .Ic forward to
263 directives, separated by whitespaces.
264 .Pp
265 The following options will configure the health-checking method for
266 the table, and is mandatory for redirections:
267 .Bl -tag -width Ds
268 .It Xo
269 .Ic check http Ar path
270 .Op Ic host Ar hostname
271 .Ic code Ar number
272 .Xc
273 For each host in the table, verify that retrieving the URL
274 .Ar path
275 gives the HTTP return code
276 .Ar number .
277 If
278 .Ar hostname
279 is specified, it is used as the
280 .Dq Host:
281 header to query a specific hostname at the target host.
282 To validate the HTTP return code, use this shell command:
283 .Bd -literal -offset indent
284 $ echo -n "HEAD <path> HTTP/1.0\er\en\er\en" | \e
285 nc <host> <port> | head -n1
286 .Ed
287 .Pp
288 This prints the status header including the actual return code:
289 .Bd -literal -offset indent
290 HTTP/1.1 200 OK
291 .Ed
292 .It Xo
293 .Ic check https Ar path
294 .Op Ic host Ar hostname
295 .Ic code Ar number
296 .Xc
297 This has the same effect as above but wraps the HTTP request in TLS.
298 .It Xo
299 .Ic check http Ar path
300 .Op Ic host Ar hostname
301 .Ic digest Ar string
302 .Xc
303 For each host in the table, verify that retrieving the URL
304 .Ar path
305 produces non-binary content whose message digest matches the defined string.
306 The algorithm used is determined by the string length of the
307 .Ar digest
308 argument, either SHA1 (40 characters) or MD5 (32 characters).
309 If
310 .Ar hostname
311 is specified, it is used as the
312 .Dq Host:
313 header to query a specific hostname at the target host.
314 The digest does not take the HTTP headers into account.
315 Do not specify a binary object (such as a graphic) as the target of the
316 request, as
317 .Nm
318 expects the data returned to be a string.
319 To compute the digest, use this simple command:
320 .Bd -literal -offset indent
321 $ ftp -o - http://host[:port]/path | sha1
322 .Ed
323 .Pp
324 This gives a digest that can be used as-is in a digest statement:
325 .Bd -literal -offset indent
326 a9993e36476816aba3e25717850c26c9cd0d89d
327 .Ed
328 .It Xo
329 .Ic check https Ar path
330 .Op Ic host Ar hostname
331 .Ic digest Ar string
332 .Xc
333 This has the same effect as above but wraps the HTTP request in TLS.
334 .It Ic check icmp
335 Ping hosts in this table to determine whether they are up or not.
336 This method will automatically use ICMP or ICMPV6 depending on the
337 address family of each host.
338 .It Ic check script Ar path
339 Execute an external program to check the host state.
340 The program will be executed for each host by specifying the hostname
341 on the command line:
342 .Bd -literal -offset indent
343 /usr/local/bin/checkload.pl front-www1.private.example.com
344 .Ed
345 .Pp
346 .Xr relayd 8
347 expects a positive return value on success and zero on failure.
348 Note that the script will be executed with the privileges of the
349 .Qq _relayd
350 user and terminated after
351 .Ar timeout
352 milliseconds.
353 .It Xo
354 .Ic check send
355 .Ar data
356 .Ic expect
357 .Ar pattern
358 .Op Ic tls
359 .Xc
360 For each host in the table, a TCP connection is established on the
361 port specified, then
362 .Ar data
363 is sent.
364 Incoming data is then read and is expected to match against
365 .Ar pattern
366 using shell globbing rules.
367 If
368 .Ar data
369 is an empty string or
370 .Ic nothing
371 then nothing is sent on the connection and data is immediately
372 read.
373 This can be useful with protocols that output a banner like
374 SMTP, NNTP, and FTP.
375 If the
376 .Ic tls
377 keyword is present,
378 the transaction will occur in a TLS tunnel.
379 .It Xo
380 .Ic check binary send
381 .Ar data
382 .Ic expect
383 .Ar data
384 .Op Ic tls
385 .Xc
386 For each host in the table, a TCP connection is established on the
387 port specified, then the
388 .Ic send
389 .Ar data
390 is converted into binary and sent.
391 Incoming (binary)
392 data is then read and is expected to match against a binary
393 conversion of the
394 .Ic expect
395 .Ar data
396 using
397 .Xr memcmp 3 .
398 .Ar data
399 must be populated with a string containing an even number of hexadecimal
400 single-byte characters and must not be empty.
401 This can be useful with binary protocols such as LDAP and SNMP.
402 If the
403 .Ic tls
404 keyword is present,
405 the transaction will occur in a TLS tunnel.
406 .It Ic check tcp
407 Use a simple TCP connect to check that hosts are up.
408 .It Ic check tls
409 Perform a complete TLS handshake with each host to check their availability.
410 .El
411 .Pp
412 The following general table options are available:
413 .Bl -tag -width Ds
414 .It Ic demote Ar group
415 Enable the per-table
416 .Xr carp 4
417 demotion option.
418 This will increment the carp demotion counter for the
419 specified interface group if all hosts in the table are down.
420 For more information on interface groups,
421 see the
422 .Ic group
423 keyword in
424 .Xr ifconfig 8 .
425 .It Ic interval Ar number
426 Override the global interval and specify one for this table.
427 It must be a multiple of the global interval.
428 .It Ic timeout Ar number
429 Set the timeout in milliseconds for each host that is checked using
430 TCP as the transport.
431 This will override the global timeout, which is 200 milliseconds by default.
432 .El
433 .Pp
434 The following options will set the scheduling algorithm to select a
435 host from the specified table:
436 .Bl -tag -width Ds
437 .It Ic mode hash Op Ar key
438 Balances the outgoing connections across the active hosts based on the
439 .Ar key ,
440 IP address and port of the relay.
441 Additional input can be fed into the
442 hash by looking at HTTP headers and GET variables;
443 see the
444 .Sx Protocols
445 section below.
446 This mode is only supported by relays.
447 .It Ic mode least-states
448 Forward each outgoing connection to the active host with the least
449 active
450 .Xr pf 4
451 states.
452 This mode is only supported by redirections.
453 .It Ic mode loadbalance Op Ar key
454 Balances the outgoing connections across the active hosts based on the
455 .Ar key ,
456 the source IP address of the client, and the IP address and port of the relay.
457 This mode is only supported by relays.
458 .It Ic mode random
459 Distributes the outgoing connections randomly through all active hosts.
460 This mode is supported by redirections and relays.
461 .It Ic mode roundrobin
462 Distributes the outgoing connections using a round-robin scheduler
463 through all active hosts.
464 This is the default mode and will be used if no option has been specified.
465 This mode is supported by redirections and relays.
466 .It Ic mode source-hash Op Ar key
467 Balances the outgoing connections across the active hosts based on the
468 .Ar key
469 and the source IP address of the client.
470 This mode is supported by redirections and relays.
471 .El
472 .Pp
473 The optional
474 .Ar key
475 argument can be specified for the
476 .Ic hash ,
477 .Ic loadbalance ,
478 and
479 .Ic source-hash
480 modes as either a hex value with a leading
481 .Ql 0x
482 or as a string.
483 If omitted,
484 .Xr relayd 8
485 generates a random key when the configuration is loaded.
486 .Ss Redirections
487 Redirections represent a
488 .Xr pf 4
489 rdr-to rule.
490 They are used for stateful redirections to the hosts in the specified
491 tables.
492 .Xr pf 4
493 rewrites the target IP addresses and ports of the incoming
494 connections, operating on layer 3.
495 The configuration directives that are valid in the
496 .Ic redirect
497 context are described below:
498 .Bl -tag -width Ds
499 .It Ic disable
500 The redirection is initially disabled.
501 It can be later enabled through
502 .Xr relayctl 8 .
503 .It Xo
504 .Ic forward to
505 .Pf < Ar table Ns >
506 .Op Ic port Ar number
507 .Ar options ...
508 .Xc
509 Specify the tables of target hosts to be used; see the
510 .Sx Tables
511 section above for information about table options.
512 If the
513 .Ic port
514 option is not specified, the first port from the
515 .Ic listen on
516 directive will be used.
517 This directive can be specified twice \(en the second entry will be used
518 as the backup table if all hosts in the main table are down.
519 At least one entry for the main table is mandatory.
520 .It Xo
521 .Ic listen on Ar address
522 .Op ip-proto
523 .Ic port Ar port
524 .Op Ic interface Ar name
525 .Op Ic pflog
526 .Xc
527 Specify an
528 .Ar address
529 and a
530 .Ar port
531 to listen on.
532 .Xr pf 4
533 will redirect incoming connections for the specified target to the
534 hosts in the main or backup table.
535 The
536 .Ar port
537 argument can optionally specify a port range instead of a single port;
538 the format is
539 .Ar min-port : Ns Ar max-port .
540 The optional argument
541 .Ar ip-proto
542 can be used to specify an IP protocol like
543 .Cm tcp
544 or
545 .Cm udp ;
546 it defaults to
547 .Cm tcp .
548 The rule can be optionally restricted to a given interface name.
549 The optional
550 .Ic pflog
551 keyword will add
552 .Cm log
553 to the rule.
554 The logged packets are sent to
555 .Xr pflog 4 .
556 .It Xo
557 .Op Ic match
558 .Ic pftag Ar name
559 .Xc
560 Automatically tag packets passing through the
561 .Xr pf 4
562 rdr-to rule with the name supplied.
563 This allows simpler filter rules.
564 The optional
565 .Ic match
566 keyword will change the default rule action from
567 .Ql pass in quick
568 to
569 .Ql match in
570 to allow further evaluation in the pf ruleset using the
571 .Cm tagged Ar name
572 rule option.
573 .It Xo
574 .Ic route to
575 .Pf < Ar table Ns >
576 .Op Ic port Ar number
577 .Ar options ...
578 .Xc
579 Like the
580 .Ic forward to
581 directive, but directly routes the packets to the target host without
582 modifying the target address using a
583 .Xr pf 4
584 route-to rule.
585 This can be used for
586 .Dq direct server return
587 to force the target host to respond via a different gateway.
588 Note that hosts have to accept sessions for the same address as
589 the gateway, which is typically done by configuring a loopback
590 interface on the host with this address.
591 .It Ic session timeout Ar seconds
592 Specify the inactivity timeout in seconds for established redirections.
593 The default timeout is 600 seconds (10 minutes).
594 The maximum is 2147483647 seconds (68 years).
595 .It Ic sticky-address
596 This has the same effect as specifying sticky-address
597 for an rdr-to rule in
598 .Xr pf.conf 5 .
599 It will ensure that multiple connections from the same source are
600 mapped to the same redirection address.
601 .El
602 .Ss Relays
603 Relays will forward traffic between a client and a target server.
604 In contrast to redirections and IP forwarding in the network stack, a
605 relay will accept incoming connections from remote clients as a
606 server, open an outgoing connection to a target host, and forward
607 any traffic between the target host and the remote client,
608 operating on layer 7.
609 A relay is also called an application layer gateway or layer 7 proxy.
610 .Pp
611 The main purpose of a relay is to provide advanced load balancing
612 functionality based on specified protocol characteristics, such as
613 HTTP headers, to provide TLS acceleration and to allow
614 basic handling of the underlying application protocol.
615 .Pp
616 The
617 .Ic relay
618 configuration directives are described below:
619 .Bl -tag -width Ds
620 .It Ic disable
621 Start the relay but immediately close any accepted connections.
622 .It Xo
623 .Op Ic transparent
624 .Ic forward
625 .Op Ic with tls
626 .Ic to
627 .Ar address
628 .Op Ic port Ar port
629 .Ar options ...
630 .Xc
631 Specify the address and port of the target host to connect to.
632 If the
633 .Ic port
634 option is not specified, the port from the
635 .Ic listen on
636 directive will be used.
637 Use the
638 .Ic transparent
639 keyword to enable fully-transparent mode; the source address of the
640 client will be retained in this case.
641 .Pp
642 The
643 .Ic with tls
644 directive enables client-side TLS mode to connect to the remote host.
645 Verification of server certificates can be enabled by setting the
646 .Ic ca file
647 option in the protocol section.
648 .Pp
649 The following options may be specified for forward directives:
650 .Bl -tag -width Ds
651 .It Ic inet
652 If the requested destination is an IPv6 address,
653 .Xr relayd 8
654 will forward the connection to an IPv4 address which is determined by
655 the last 4 octets of the original IPv6 destination.
656 For example, if the original IPv6 destination address is
657 2001:db8:7395:ffff::a01:101, the session is relayed to the IPv4
658 address 10.1.1.1 (a01:101).
659 .It Ic inet6 Ar address-prefix
660 If the requested destination is an IPv4 address,
661 .Xr relayd 8
662 will forward the connection to an IPv6 address which is determined by
663 setting the last 4 octets of the specified IPv6
664 .Ar address-prefix
665 to the 4 octets of the original IPv4 destination.
666 For example, if the original IPv4 destination address is 10.1.1.1 and
667 the specified address prefix is 2001:db8:7395:ffff::, the session is
668 relayed to the IPv6 address 2001:db8:7395:ffff::a01:101.
669 .It Ic retry Ar number
670 The optional host
671 .Ic retry
672 option will be used as a tolerance for failed
673 host connections; the connection will be retried for
674 .Ar number
675 more times.
676 .It Ic proxy-protocol Pq Ic v1 Ns | Ns Ic v2
677 Upon connection to the destination,
678 .Xr relayd 8
679 will prepend a PROXY protocol header of the specified version to the relayed
680 data, with the IP address and port of the remote host as well as the
681 .Xr relayd 8
682 server.
683 .El
684 .It Xo
685 .Ic forward to
686 .Pf < Ar table Ns >
687 .Op Ic port Ar port
688 .Ar options ...
689 .Xc
690 Like the previous directive, but connect to a host from the specified
691 table; see the
692 .Sx Tables
693 section above for information about table options.
694 This directive can be specified multiple times \(en subsequent entries
695 will be used as the backup table if all hosts in the previous table
696 are down.
697 At least one entry for the main table is mandatory.
698 As above, use the
699 .Ic with tls
700 directive to enable client-side TLS mode when connecting to the remote host.
701 .It Xo
702 .Ic forward to
703 .Ic destination
704 .Ar options ...
705 .Xc
706 When redirecting connections with a divert-to rule in
707 .Xr pf.conf 5
708 to a relay listening on localhost, this directive will
709 look up the real destination address of the intended target host,
710 allowing the relay to be run as a transparent proxy.
711 If an additional
712 .Ic forward to
713 directive to a specified address or table is present,
714 it will be used as a backup if the lookup failed.
715 As above, use the
716 .Ic with tls
717 directive to enable client-side TLS mode when connecting to the remote host.
718 .It Xo
719 .Ic forward to
720 .Ic nat lookup
721 .Ar options ...
722 .Xc
723 Like the previous directive, but for redirections with rdr-to in
724 .Xr pf.conf 5 .
725 .It Xo
726 .Ic listen on Ar address Ic port Ar port
727 .Op Ic tls
728 .Xc
729 Specify the address and port for the relay to listen on.
730 The relay will accept incoming connections to the specified address or
731 addresses.
732 If
733 .Ar address
734 resolves to multiple IPv4 or IPv6 addresses, such as an interface
735 name, interface group, or DNS hostname,
736 .Xr relayd 8
737 will create a listener for each local address.
738 For DNS hostnames, all resolved IPv4 and IPv6 addresses are considered,
739 but only addresses configured on a local interface are used.
740 Addresses that are not configured on a local interface are ignored.
741 If none of the resolved addresses are local, the configuration is
742 invalid.
743 If the
744 .Ic tls
745 keyword is present, the relay will accept connections using the
746 encrypted TLS protocol.
747 .It Ic protocol Ar name
748 Use the specified protocol definition for the relay.
749 The generic TCP protocol options will be used by default;
750 see the
751 .Sx Protocols
752 section below.
753 .It Ic session timeout Ar seconds
754 Specify the inactivity timeout in seconds for accepted sessions.
755 The default timeout is 600 seconds (10 minutes).
756 The maximum is 2147483647 seconds (68 years).
757 .El
758 .Ss TLS relays
759 In addition to plain TCP,
760 .Xr relayd 8
761 supports the Transport Layer Security (TLS) cryptographic protocol for
762 authenticated and encrypted relays.
763 .Xr relayd 8
764 can operate as a TLS client or server to offer a variety of options
765 for different use cases related to TLS.
766 .Bl -tag -width Ds
767 .It Ic TLS client
768 When configuring the relay
769 .Ic forward
770 statements with the
771 .Ic with tls
772 directive,
773 .Xr relayd 8
774 will enable client-side TLS to connect to the remote host.
775 This is commonly used for TLS tunneling and transparent encapsulation
776 of plain TCP connections.
777 See the
778 .Ic forward to
779 description in the
780 .Sx Relays
781 section for more details.
782 .It Ic TLS server
783 When specifying the
784 .Ic tls
785 keyword in the relay
786 .Ic listen
787 statements,
788 .Xr relayd 8
789 will accept connections from clients as a TLS server.
790 This mode is also known as
791 .Dq TLS acceleration .
792 See the
793 .Ic listen on
794 description in the
795 .Sx Relays
796 section for more details.
797 .It Ic TLS client and server
798 When combining both modes, TLS server and client,
799 .Xr relayd 8
800 can filter TLS connections as a man-in-the-middle.
801 This combined mode is also called
802 .Dq TLS inspection .
803 The configuration requires additional X.509 certificate settings;
804 see the
805 .Ic ca key
806 description in the
807 .Sx Protocols
808 section for more details.
809 .El
810 .Pp
811 When configured for
812 .Dq TLS inspection
813 mode,
814 .Xr relayd 8
815 will listen for incoming connections which have been diverted to the
816 local socket by PF.
817 Before accepting and negotiating the incoming TLS connection as a
818 server, it will look up the original destination address on the
819 diverted socket, and pre-connect to the target server as a TLS client
820 to obtain the remote TLS certificate.
821 It will update or patch the obtained TLS certificate by replacing the
822 included public key with its local server key because it doesn't have
823 the private key of the remote server certificate.
824 It also updates the X.509 issuer name to the local CA subject name and
825 signs the certificate with its local CA key.
826 This way it keeps all the other X.509 attributes that are already
827 present in the server certificate, including the "green bar" extended
828 validation attributes.
829 Now it finally accepts the TLS connection from the diverted client
830 using the updated certificate and continues to handle the connection
831 and to connect to the remote server.
832 .Ss Protocols
833 Protocols are templates defining settings and rules for relays.
834 They allow setting generic TCP options, TLS settings, and rules
835 for the selected application layer protocol.
836 .Pp
837 The protocol directive is available for a number of different
838 application layer protocols.
839 There is no generic handler for UDP-based protocols because it is a
840 stateless datagram-based protocol which has to look into the
841 application layer protocol to find any possible state information.
842 .Bl -tag -width Ds
843 .It Ic dns protocol
844 (UDP)
845 Domain Name System (DNS) protocol.
846 The requested IDs in the DNS header will be used to match the state.
847 .Xr relayd 8
848 replaces these IDs with random values to compensate for
849 predictable values generated by some hosts.
850 .It Ic http protocol
851 Handle the HyperText Transfer Protocol
852 (HTTP, or "HTTPS" if encapsulated in a TLS tunnel).
853 .It Xo
854 .Op Ic tcp
855 .Ic protocol
856 .Xc
857 Generic handler for TCP-based protocols.
858 This is the default.
859 .El
860 .Pp
861 The available configuration directives are described below:
862 .Bl -tag -width Ds
863 .It Xo
864 .Pq Ic block Ns | Ns Ic pass Ns | Ns Ic match
865 .Op Ar rule
866 .Xc
867 Specify one or more rules to filter connections based on their
868 network or application layer headers;
869 see the
870 .Sx Filter rules
871 section for more details.
872 .It Ic return error Op Ar option
873 Return an error response to the client if an internal operation or the
874 forward connection to the client failed.
875 By default, the connection will be silently dropped.
876 The effect of this option depends on the protocol: HTTP will send an
877 error header and page to the client before closing the connection.
878 Additional valid options are:
879 .Bl -tag -width Ds
880 .It Ic style Ar string
881 Specify a Cascading Style Sheet (CSS) to be used for the returned
882 HTTP error pages, for example:
883 .Bd -literal -offset indent
884 body { background: #a00000; color: white; }
885 .Ed
886 .El
887 .It Ic tcp Ar option
888 Enable or disable the specified TCP/IP options; see
889 .Xr tcp 4
890 and
891 .Xr ip 4
892 for more information about the options.
893 Valid options are:
894 .Bl -tag -width Ds
895 .It Ic backlog Ar number
896 Set the maximum length the queue of pending connections may grow to.
897 The backlog option is 10 by default, is limited to 512 and capped by the
898 .Ic kern.somaxconn
899 .Xr sysctl 8
900 variable.
901 .It Ic ip minttl Ar number
902 This option for the underlying IP connection may be used to discard packets
903 with a TTL lower than the specified value.
904 This can be used to implement the
905 Generalized TTL Security Mechanism (GTSM)
906 according to RFC 5082.
907 .It Ic ip ttl Ar number
908 Change the default time-to-live value in the IP headers.
909 .It Ic nodelay
910 Enable the TCP NODELAY option for this connection.
911 This is recommended to avoid delays in the relayed data stream,
912 e.g. for SSH connections.
913 The default is
914 .Ic no nodelay .
915 .It Ic no splice
916 Disable socket splicing for zero-copy data transfer.
917 The default is to enable socket splicing.
918 .It Ic sack
919 Use selective acknowledgements for this connection.
920 The default is
921 .Ic no sack .
922 .It Ic socket buffer Ar number
923 Set the socket-level buffer size for input and output for this
924 connection.
925 This will affect the TCP window size.
926 .El
927 .It Ic tls Ar option
928 Set the TLS options and session settings.
929 This is only used if TLS is enabled in the relay.
930 Valid options are:
931 .Bl -tag -width Ds
932 .It Ic ca cert Ar path
933 Specify a CA certificate for TLS inspection.
934 For more information, see the
935 .Ic ca key
936 option below.
937 .It Ic ca file Ar path
938 This option enables CA verification in TLS client mode.
939 The daemon will load the CA (Certificate Authority) certificates from
940 the specified path to verify the server certificates.
941 .Ox
942 provides a default CA bundle in
943 .Pa /etc/ssl/cert.pem .
944 .It Ic ca key Ar path Ic password Ar password
945 Specify a CA key for TLS inspection.
946 The
947 .Ar password
948 argument will specify the password to decrypt the CA key
949 (typically an RSA key).
950 This option will enable TLS inspection if the following conditions
951 are true:
952 .Pp
953 .Bl -bullet -compact -offset indent
954 .It
955 TLS server mode is enabled by the
956 .Ic listen
957 directive:
958 .Ic listen on ... tls .
959 .It
960 TLS client mode and divert lookups are enabled by the
961 .Ic forward
962 directive:
963 .Ic forward with tls to destination .
964 .It
965 The
966 .Ic ca cert
967 option is specified.
968 .It
969 The
970 .Ic ca key
971 option is specified.
972 .El
973 .It Ic ciphers Ar string
974 Set the string defining the TLS cipher suite.
975 If not specified, the default value
976 .Ql HIGH:!aNULL
977 will be used (strong crypto cipher suites without anonymous DH).
978 See the CIPHERS section of
979 .Xr openssl 1
980 for information about TLS cipher suites and preference lists.
981 .It Ic client ca Ar path
982 Require TLS client certificates that can be verified against the CA
983 certificates in the specified file.
984 .It Ic client-renegotiation
985 Allow client-initiated renegotiation.
986 To mitigate a potential DoS risk,
987 the default is
988 .Ic no client-renegotiation .
989 .It Ic ecdhe Ar curves
990 Specify a comma separated list of elliptic curves to use for ECDHE cipher
991 suites, in order of preference.
992 The special value of "default" will use the default curves; see
993 .Xr tls_config_set_ecdhecurves 3
994 for further details.
995 .It Ic edh Op Ic params Pq Ic none Ns | Ns Ic auto Ns | Ns Ic legacy
996 Enable EDH-based cipher suites with Perfect Forward Secrecy (PFS) for
997 older clients that do not support ECDHE.
998 In
999 .Ic auto
1000 mode, the key size of the ephemeral key is automatically selected
1001 based on the size of the private key used for signing.
1003 .Ic legacy
1004 mode, a 1024 bit ephemeral key is used.
1006 .Ic params
1007 is omitted,
1008 .Ic auto
1009 is used.
1010 The default is
1011 .Ic no edh .
1012 .It Ic keypair Ar name
1013 .It Ic keypair Ar name Op Ic cert Ar "path"
1014 .It Ic keypair Ar name Op Ic key Ar "path"
1015 .It Ic keypair Ar name Op Ic ocsp Ar "path"
1016 The relay will attempt to look up the TLS assets associated with
1017 .Ar name .
1018 The optional
1019 .Ar path
1020 arguments must be enclosed in double quotes and specify the absolute path to
1021 the respective file.
1022 By default, it searches for a private key in
1023 .Pa /etc/ssl/private/name:port.key
1024 and a public certificate in
1025 .Pa /etc/ssl/name:port.crt ,
1026 where
1027 .Ar port
1028 is the specified port that the relay listens on.
1029 If these files are not present, the relay will continue to look in
1030 .Pa /etc/ssl/private/name.key
1031 and
1032 .Pa /etc/ssl/name.crt .
1033 .Pp
1034 If the
1035 .Ic cert ,
1036 .Ic key ,
1038 .Ic ocsp
1039 keywords are followed by an explicit
1040 .Ar path ,
1041 that file will be used instead of the default location.
1042 .Pp
1043 This option can be specified multiple times for TLS Server Name Indication.
1044 If not specified,
1045 a keypair will be loaded using the specified IP address of the relay as
1046 .Ar name .
1047 See
1048 .Xr ssl 8
1049 for details about TLS server certificates.
1050 .Pp
1051 An optional OCSP staple file will be used during TLS handshakes.
1052 If no explicit
1053 .Ic ocsp Ar path
1054 is given, it will be searched as a non-empty file in
1055 .Pa /etc/ssl/name:port.ocsp
1057 .Pa /etc/ssl/name.ocsp .
1058 The file should contain a DER-format OCSP response retrieved from an
1059 OCSP server for the certificate in use, and can be created using
1060 .Xr ocspcheck 8 .
1061 .It Ic no cipher-server-preference
1062 Prefer the client's cipher list over the server's preferences when
1063 choosing a cipher for the connection.
1064 The default is to prefer the server's cipher list.
1065 .It Ic session tickets
1066 Enable TLS session tickets.
1067 .Xr relayd 8
1068 supports stateless TLS session tickets (RFC 5077) to implement TLS session
1069 resumption for connections not using TLSv1.3.
1070 The default is to disable session tickets.
1071 .It Ic no tlsv1.3
1072 Disable the TLSv1.3 protocol.
1073 The default is to enable TLSv1.3.
1074 .It Ic no tlsv1.2
1075 Disable the TLSv1.2 protocol.
1076 The default is to enable TLSv1.2.
1077 .It Ic sslv3
1078 Is deprecated and does nothing.
1079 .It Ic tlsv1
1080 Enable all TLSv1 protocols.
1081 This is an alias that currently includes
1082 .Ic tlsv1.2 ,
1083 and
1084 .Ic tlsv1.3 .
1085 The default is
1086 .Ic no tlsv1 .
1087 .It Ic tlsv1.0
1088 Is deprecated and does nothing.
1089 .It Ic tlsv1.1
1090 Is deprecated and does nothing.
1091 .El
1092 .It Ic http Ar option
1093 Set the HTTP options and session settings.
1094 This is only used if HTTP is enabled in the relay.
1095 Valid options are:
1096 .Bl -tag -width Ds
1097 .It Ic headerlen Ar number
1098 Set the maximum size of all HTTP headers in bytes.
1099 The default value is 8192 and it is limited to a maximum of 131072.
1100 .It Ic websockets
1101 Allow connection upgrade to websocket protocol.
1102 The default is
1103 .Ic no websockets .
1104 .El
1105 .El
1106 .Ss Filter rules
1107 Relays have the ability to filter connections based
1108 on their network or application layer headers.
1109 Filter rules apply options to connections based on the specified
1110 filter parameters.
1111 .Pp
1112 For each connection that is processed by a relay, the filter rules are
1113 evaluated in sequential order, from first to last.
1114 For
1115 .Ic block
1116 and
1117 .Ic pass ,
1118 the last matching rule decides what action is taken;
1119 if no rule matches the connection, the default action is to establish
1120 the connection without any additional action.
1121 For
1122 .Ic match ,
1123 rules are evaluated every time they match;
1124 the pass/block state of a connection remains unchanged.
1125 .Pp
1126 The filter action may be one of the following:
1127 .Bl -tag -width Ds
1128 .It Ic block
1129 The connection is blocked.
1130 If a
1131 .Ic block
1132 rule matches a new connection attempt, it will not be established.
1133 .Ic block
1134 rules can also trigger for existing connections after evaluating
1135 application layer parameters;
1136 any connection of the relay session will be instantly dropped.
1137 .It Ic match
1138 The connection is matched.
1139 This action does not alter the connection state, but allows
1140 additional parameters to the connection.
1141 .It Ic pass
1142 The connection is passed;
1143 .Xr relayd 8
1144 will continue to process the relay session normally.
1145 .El
1146 .Pp
1147 These filter parameters can be used in the rules:
1148 .Bl -tag -width Ds
1149 .It Ic request No or Ic response
1150 A relay session always consists of two connections:
1151 the
1152 .Ic request ,
1153 a client initiating a new connection to a server via the relay,
1154 and the
1155 .Ic response ,
1156 the server accepting the connection.
1157 Depending on the protocol,
1158 an established session can be purely request/response-based (like
1159 HTTP), exchange data in a bidirectional way (like arbitrary TCP
1160 sessions), or just contain a single datagram and an optional response
1161 (like UDP-based protocols).
1162 But the client always
1163 .Em requests
1164 to communicate with a remote peer; the server.
1165 .It Ic quick
1166 If a connection is matched by a rule with the
1167 .Ic quick
1168 option set,
1169 the rule is considered to be the last matching rule and any further
1170 evaluation is skipped.
1171 .It Ic inet No or Ic inet6
1172 Only match connections with the specified address family,
1173 either of type IPv4 or IPv6.
1174 .It Ic from Ar address Ns Oo Li / Ns Ar prefix Oc
1175 This rule only matches for connections from the specified source.
1176 .It Ic to Ar address Ns Oo Li / Ns Ar prefix Oc
1177 This rule only matches for connections to the specified destination.
1178 The destination is the address the client was connecting to,
1179 typically the relay's listen address in non-transparent mode,
1180 not the address of the forwarded backend connection.
1181 .It Ic forward to Pf < Ar table Ns >
1182 Forward the request to a server in the specified table.
1183 With this option, requests can be passed to specific backend servers.
1184 A corresponding
1185 .Ic forward to
1186 declaration in the
1187 .Sx Relays
1188 section is required.
1189 .It Ic label Ar string
1190 The label will be printed as part of the error message if the
1191 .Ic return error
1192 option is set and may contain HTML tags, for example:
1193 .Bd -literal -offset indent
1194 block request url digest 5c1e03f58f8ce0b457474ffb371fd1ef \e
1195 label "<a href='http://example.com/adv.pl?id=7359'>\e
1196 Advisory provided by example.com</a>"
1197 .Ed
1198 .It Ic no Ar parameter
1199 Reset a sticky parameter that was previously set by a matching rule.
1200 The
1201 .Ar parameter
1202 is a keyword that can be either
1203 .Ic label
1205 .Ic tag .
1206 .It Ic tag Ar string
1207 Add a "sticky" tag to connections matching this filter rule.
1208 Tags can be used to filter the connection by further rules using the
1209 .Ic tagged
1210 option.
1211 Only one tag is assigned per connection;
1212 the tag will be replaced if the connection is already tagged.
1213 .It Ic tagged Ar string
1214 Match the connection if it is already tagged with a given tag by a
1215 previous rule.
1216 .El
1217 .Pp
1218 The following parameters are available when using the
1219 .Ic http
1220 protocol:
1221 .Bl -tag -width Ds
1222 .It Ic method Ar name
1223 Match the HTTP request method.
1224 The method is specified by
1225 .Ar name
1226 and can be either
1227 .Ic ACL ,
1228 .Ic BASELINE-CONTROL ,
1229 .Ic CHECKIN ,
1230 .Ic CHECKOUT ,
1231 .Ic CONNECT ,
1232 .Ic COPY ,
1233 .Ic DELETE ,
1234 .Ic GET ,
1235 .Ic HEAD ,
1236 .Ic LABEL ,
1237 .Ic LOCK ,
1238 .Ic MERGE ,
1239 .Ic MKACTIVITY ,
1240 .Ic MKCALENDAR ,
1241 .Ic MKCOL ,
1242 .Ic MKREDIRECTREF ,
1243 .Ic MKWORKSPACE ,
1244 .Ic MOVE ,
1245 .Ic OPTIONS ,
1246 .Ic ORDERPATCH ,
1247 .Ic PATCH ,
1248 .Ic POST ,
1249 .Ic PROPFIND ,
1250 .Ic PROPPATCH ,
1251 .Ic PUT ,
1252 .Ic REPORT ,
1253 .Ic SEARCH ,
1254 .Ic TRACE ,
1255 .Ic UNCHECKOUT ,
1256 .Ic UNLOCK ,
1257 .Ic UPDATE ,
1258 .Ic UPDATEREDIRECTREF ,
1260 .Ic VERSION-CONTROL .
1261 .It Xo
1262 .Ar type option
1263 .Oo Oo Ic digest Oc
1264 .Pq Ar key Ns | Ns Ic file Ar path
1265 .Oo Ic value Ar value Oc Oc
1266 .Xc
1267 Match a specified HTTP header entity and an optional
1268 .Ic key
1269 and
1270 .Ic value .
1272 .Ic option
1273 can be specified to modify the matched entity or to trigger an event.
1274 The entity is extracted from the HTTP request or response header and
1275 can be either of
1276 .Ar type
1277 .Ic cookie ,
1278 .Ic header ,
1279 .Ic path ,
1280 .Ic query ,
1282 .Ic url .
1283 .Pp
1284 Instead of a single
1285 .Ar key ,
1286 multiple keys can be loaded from a
1287 .Ic file
1288 specified by
1289 .Ar path
1290 that contains one key per line.
1291 Lines will be stripped at the first whitespace or newline character
1292 and any empty lines or lines beginning with a hash mark
1293 .Pq Ql #
1294 will be ignored.
1295 .Pp
1296 If the
1297 .Ic digest
1298 keyword is specified,
1299 compare the message digest of the key against the defined string.
1300 The algorithm used is determined by the string length of the
1301 .Ar key
1302 argument, either SHA1 (40 characters) or MD5 (32 characters).
1303 To compute the digest,
1304 for example for a
1305 .Ic url ,
1306 use this simple command:
1307 .Bd -literal -offset indent
1308 $ echo -n "example.com/path/?args" | sha1
1309 .Ed
1310 .El
1311 .Pp
1312 .Bq Ar type
1313 may be one of:
1314 .Bl -tag -width Ds
1315 .It Ic cookie Ar option Oo Ar key Oo Ic value Ar value Oc Oc
1316 Look up the entity as a value in the Cookie header.
1317 This type is only available with the direction
1318 .Ic request .
1319 .It Ic header Ar option Oo Ar key Oo Ic value Ar value Oc Oc
1320 Look up the entity in the application protocol headers, like HTTP
1321 headers in
1322 .Ic http
1323 mode.
1324 .It Ic path Ar option Oo Ar key Oo Ic value Ar value Oc Oc
1325 Look up the entity as a value in the URL path when using the
1326 .Ic http
1327 protocol.
1328 This type is only available with the direction
1329 .Ic request .
1330 The
1331 .Ar key
1332 will match the path of the requested URL without the hostname
1333 and query and the value will match the complete query,
1334 for example:
1335 .Bd -literal -offset indent
1336 block path "/index.html"
1337 block path "/cgi-bin/t.cgi" value "foo=bar*"
1338 .Ed
1339 .It Ic path strip Ar number
1340 Strip
1341 .Ar number
1342 path components from the beginning of the path of the requested URL
1343 when using the
1344 .Ic http
1345 protocol.
1346 This type is only available with the direction
1347 .Ic request .
1348 .It Ic query Ar option Oo Ar key Oo Ic value Ar value Oc Oc
1349 Look up the entity as a query variable in the URL when using the
1350 .Ic http
1351 protocol.
1352 This type is only available with the direction
1353 .Ic request ,
1354 for example:
1355 .Bd -literal -offset indent
1356 # Will match /cgi-bin/example.pl?foo=bar&ok=yes
1357 pass request query "foo" value "bar"
1358 .Ed
1359 .It Ic url Ar option Oo Oo Ic digest Oc Ar key Oo Ic value Ar value Oc Oc
1360 Look up the entity as a URL suffix/prefix expression consisting of a
1361 canonicalized hostname without port or suffix and a path name or
1362 prefix when using the
1363 .Ic http
1364 protocol.
1365 This type is only available with the direction
1366 .Ic request ,
1367 for example:
1368 .Bd -literal -offset indent
1369 block url "example.com/index.html"
1370 block url "example.com/test.cgi?val=1"
1371 .Ed
1372 .Pp
1373 .Xr relayd 8
1374 will match the full URL and different possible suffix/prefix
1375 combinations by stripping subdomains and path components (up to 5
1376 levels), and the query string.
1377 For example, the following
1378 lookups will be done for
1379 http://www.example.com:81/1/2/3/4/5.html?query=yes:
1380 .Bd -literal -offset indent
1381 www.example.com/1/2/3/4/5.html?query=yes
1382 www.example.com/1/2/3/4/5.html
1383 www.example.com/
1384 www.example.com/1/
1385 www.example.com/1/2/
1386 www.example.com/1/2/3/
1387 example.com/1/2/3/4/5.html?query=yes
1388 example.com/1/2/3/4/5.html
1389 example.com/
1390 example.com/1/
1391 example.com/1/2/
1392 example.com/1/2/3/
1393 .Ed
1394 .El
1395 .Pp
1396 .Bq Ar option
1397 may be one of:
1398 .Bl -tag -width Ds
1399 .It Ic append
1400 Append the specified
1401 .Ar value
1402 to a protocol entity with the selected
1403 .Ar key
1404 name.
1405 If it does not exist, it will be created with the new value.
1406 .Pp
1407 The value string may contain predefined macros that will be expanded
1408 at runtime:
1409 .Pp
1410 .Bl -tag -width $SERVER_ADDR -offset indent -compact
1411 .It Ic $HOST
1412 The Host header's value of the relay.
1413 .It Ic $REMOTE_ADDR
1414 The IP address of the connected client.
1415 .It Ic $REMOTE_PORT
1416 The TCP source port of the connected client.
1417 .It Ic $SERVER_ADDR
1418 The configured IP address of the relay.
1419 .It Ic $SERVER_PORT
1420 The configured TCP server port of the relay.
1421 .It Ic $SERVER_NAME
1422 The server software name of
1423 .Xr relayd 8 .
1424 .It Ic $TIMEOUT
1425 The configured session timeout of the relay.
1426 .El
1427 .It Ic hash
1428 Feed the
1429 .Ar value
1430 of the selected entity into the load balancing hash to select the
1431 target host.
1432 See the
1433 .Ic table
1434 keyword in the
1435 .Sx Relays
1436 section above.
1437 .It Ic log
1438 Log the
1439 .Ar key
1440 name and the
1441 .Ar value
1442 of the entity.
1443 .It Ic remove
1444 Remove the entity with the selected
1445 .Ar key
1446 name.
1447 .It Ic set
1448 Like the
1449 .Ic append
1450 directive above, but change the contents of the specified entity.
1452 .Ar key
1453 does not exist in the request, it will be created with the new
1454 .Ar value .
1455 .Pp
1456 The
1457 .Ar value
1458 string
1459 may contain predefined macros that will be expanded at runtime,
1460 as detailed for the
1461 .Ic append
1462 directive above.
1463 .El
1464 .Ss Routers
1465 Routers represent routing table entries in the kernel forwarding
1466 database, see
1467 .Xr route 4 ,
1468 and a table of associated gateways.
1469 They are used to dynamically insert or remove routes with gateways
1470 based on their availability and health-check results.
1471 A router can include multiple network statements and a single forward
1472 statement with a table of one or more gateways.
1473 All entries in a single router directive must match the same address
1474 family, either IPv4 or IPv6.
1475 .Pp
1476 The kernel supports multipath routing when multiple gateways exist to
1477 the same destination address.
1478 The multipath routing behaviour can be changed globally using the
1479 .Xr sysctl 8
1480 variables
1481 .Va net.inet.ip.multipath
1482 and
1483 .Va net.inet6.ip6.multipath .
1484 With the default setting of 0,
1485 the first route selected will be used for subsequent packets to that
1486 destination regardless of source.
1487 Setting it to 1 will enable load balancing based on the packet source
1488 address across gateways; multiple routes with the same priority are
1489 used equally.
1490 The kernel will also check the link state of the related network
1491 interface and try a different route if it is not active.
1492 .Pp
1493 The configuration directives that are valid in the
1494 .Ic routers
1495 context are described below:
1496 .Bl -tag -width Ds
1497 .It Xo
1498 .Ic forward to
1499 .Pf < Ar table Ns >
1500 .Ic port Ar number
1501 .Ar options ...
1502 .Xc
1503 Specify the table of target gateways to be used; see the
1504 .Sx Tables
1505 section above for information about table options.
1506 This entry is mandatory and must be specified once.
1507 .It Xo
1508 .Ic route
1509 .Ar address Ns Li / Ns Ar prefix
1510 .Xc
1511 Specify the network address and prefix length of a route destination
1512 that is reachable via the active gateways.
1513 This entry must be specified at least once in a router directive.
1514 .It Ic rtable Ar id
1515 Add the routes to the kernel routing table with the specified
1516 .Ar id .
1517 .It Ic rtlabel Ar label
1518 Add the routes with the specified
1519 .Ar label
1520 to the kernel routing table.
1521 .El
1522 .Sh FILES
1523 .Bl -tag -width Ds -compact
1524 .It Pa /etc/relayd.conf
1525 .Xr relayd 8
1526 configuration file.
1527 .Pp
1528 .It Pa /etc/examples/relayd.conf
1529 Example configuration file.
1530 .Pp
1531 .It Pa /etc/services
1532 Service name database.
1533 .Pp
1534 .It Pa /etc/ssl/address.crt
1535 .It Pa /etc/ssl/address:port.crt
1536 .It Pa /etc/ssl/private/address.key
1537 .It Pa /etc/ssl/private/address:port.key
1538 Location of the relay TLS server certificates, where
1539 .Ar address
1540 is the configured IP address
1541 and
1542 .Ar port
1543 is the configured port number of the relay.
1544 .Pp
1545 .It Pa /etc/ssl/cert.pem
1546 Default location of the CA bundle that can be used with
1547 .Xr relayd 8 .
1548 .El
1549 .Sh EXAMPLES
1550 This configuration file would create a redirection service
1551 .Dq www
1552 which load balances four hosts
1553 and falls back to one host containing a
1554 .Dq sorry page :
1555 .Bd -literal -offset indent
1556 www1=front-www1.private.example.com
1557 www2=front-www2.private.example.com
1558 www3=front-www3.private.example.com
1559 www4=front-www4.private.example.com
1561 interval 5
1563 table <phphosts> { $www1, $www2, $www3, $www4 }
1564 table <sorryhost> disable { sorryhost.private.example.com }
1566 redirect "www" {
1567 listen on www.example.com port 8080 interface trunk0
1568 listen on www6.example.com port 80 interface trunk0
1570 pftag REDIRECTED
1572 forward to <phphosts> port 8080 timeout 300 \e
1573 check http "/" digest "630aa3c2f..."
1574 forward to <sorryhost> port 8080 timeout 300 check icmp
1576 .Ed
1577 .Pp
1578 It is possible to specify multiple listen directives with different IP
1579 protocols in a single redirection configuration:
1580 .Bd -literal -offset indent
1581 redirect "dns" {
1582 listen on dns.example.com tcp port 53
1583 listen on dns.example.com udp port 53
1585 forward to <dnshosts> port 53 check tcp
1587 .Ed
1588 .Pp
1589 To load balance an IP address over multiple backend servers using a
1590 .Xr pf 4
1591 .Cm route-to
1592 directive:
1593 .Bd -literal -offset indent
1594 table <backends> { 10.100.42.71 10.100.42.72 10.100.42.73 }
1596 redirect "xmpp" {
1597 listen on 10.100.42.2 tcp port 5222
1599 route to <backends> port 5222 check tcp interface em0
1601 .Ed
1602 .Pp
1603 The following configuration would add a relay to forward
1604 secure HTTPS connections to a pool of HTTP webservers
1605 using the
1606 .Ic loadbalance
1607 mode (TLS acceleration and layer 7 load balancing).
1608 The HTTP protocol definition will add two HTTP headers containing
1609 address information of the client and the server, set the
1610 .Dq Keep-Alive
1611 header value to the configured session timeout,
1612 and include the
1613 .Dq sessid
1614 variable in the hash to calculate the target host:
1615 .Bd -literal -offset indent
1616 http protocol "https" {
1617 match header set "X-Forwarded-For" \e
1618 value "$REMOTE_ADDR"
1619 match header set "X-Forwarded-By" \e
1620 value "$SERVER_ADDR:$SERVER_PORT"
1621 match header set "Keep-Alive" value "$TIMEOUT"
1623 match query hash "sessid"
1625 pass
1626 block path "/cgi-bin/index.cgi" value "*command=*"
1628 tls { no tlsv1.0, ciphers "HIGH" }
1631 relay "tlsaccel" {
1632 listen on www.example.com port 443 tls
1633 protocol "https"
1634 forward to <phphosts> port 8080 mode loadbalance check tcp
1636 .Ed
1637 .Pp
1638 The second relay example will accept incoming connections to port
1639 2222 and forward them to a remote SSH server.
1640 The TCP
1641 .Ic nodelay
1642 option will allow a
1643 .Dq smooth
1644 SSH session without delays between keystrokes or displayed output on
1645 the terminal:
1646 .Bd -literal -offset indent
1647 protocol "myssh" {
1648 tcp { nodelay, socket buffer 65536 }
1651 relay "sshforward" {
1652 listen on www.example.com port 2222
1653 protocol "myssh"
1654 forward to shell.example.com port 22
1656 .Ed
1657 .Pp
1658 The following relay example will configure
1659 .Dq TLS inspection
1660 as described in the
1661 .Sx TLS relays
1662 section.
1663 To start, first generate a new local CA key and certificate:
1664 .Bd -literal -offset indent
1665 # openssl req -x509 -days 365 -newkey rsa:2048 \e
1666 -keyout /etc/ssl/private/ca.key -out /etc/ssl/ca.crt
1667 .Ed
1668 .Pp
1669 A TLS server key and self-signed cert for 127.0.0.1 are also required;
1670 see
1671 .Ic listen on
1672 in the
1673 .Sx Relays
1674 section for more details about certificate locations.
1675 Configure the packet filter with a matching divert rule in
1676 .Xr pf.conf 5 :
1677 .Bd -literal -offset indent
1678 # Divert incoming HTTPS traffic to relayd
1679 pass in on vlan1 inet proto tcp to port 443 \e
1680 divert-to localhost port 8443
1681 .Ed
1682 .Pp
1683 And finally configure the TLS inspection in
1684 .Nm :
1685 .Bd -literal -offset indent
1686 http protocol httpfilter {
1687 return error
1689 pass
1690 match label "Prohibited!"
1691 block url "social.network.example.com/"
1693 # New configuration directives for TLS Interception
1694 tls ca key "/etc/ssl/private/ca.key" password "password123"
1695 tls ca cert "/etc/ssl/ca.crt"
1698 relay tlsinspect {
1699 listen on 127.0.0.1 port 8443 tls
1700 protocol httpfilter
1701 forward with tls to destination
1703 .Ed
1704 .Pp
1705 The next simple router configuration example can be used to run
1706 redundant, health-checked WAN links:
1707 .Bd -literal -offset indent
1708 table <gateways> { $gw1 ip ttl 1, $gw2 ip ttl 1 }
1709 router "uplinks" {
1710 route 0.0.0.0/0
1711 forward to <gateways> check icmp
1713 .Ed
1714 .Sh SEE ALSO
1715 .Xr ocspcheck 8 ,
1716 .Xr relayctl 8 ,
1717 .Xr relayd 8 ,
1718 .Xr ssl 8
1719 .Sh HISTORY
1720 The
1721 .Nm
1722 file format, formerly known as
1723 .Ic hoststated.conf ,
1724 first appeared in
1725 .Ox 4.1 .
1726 It was renamed to
1727 .Nm
1729 .Ox 4.3 .
1730 .Sh AUTHORS
1731 .An -nosplit
1732 The
1733 .Xr relayd 8
1734 program was written by
1735 .An Pierre-Yves Ritschard Aq Mt pyr@openbsd.org
1736 and
1737 .An Reyk Floeter Aq Mt reyk@openbsd.org .
1738 .Sh CAVEATS
1739 .Xr relayd 8
1740 verification of TLS server certificates is based on a static CA bundle
1741 and
1742 .Xr relayd 8
1743 currently does not support CRLs (Certificate Revocation Lists).