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