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