1.\" $OpenBSD: relayd.conf.5,v 1.211 2024/10/28 19:56:18 tb 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 28 2024 $ 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.Op Ic pflog 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. 544The optional 545.Ic pflog 546keyword will add 547.Cm log 548to the rule. 549The logged packets are sent to 550.Xr pflog 4 . 551.It Xo 552.Op Ic match 553.Ic pftag Ar name 554.Xc 555Automatically tag packets passing through the 556.Xr pf 4 557rdr-to rule with the name supplied. 558This allows simpler filter rules. 559The optional 560.Ic match 561keyword will change the default rule action from 562.Ql pass in quick 563to 564.Ql match in 565to allow further evaluation in the pf ruleset using the 566.Cm tagged Ar name 567rule option. 568.It Xo 569.Ic route to 570.Pf < Ar table Ns > 571.Op Ic port Ar number 572.Ar options ... 573.Xc 574Like the 575.Ic forward to 576directive, but directly routes the packets to the target host without 577modifying the target address using a 578.Xr pf 4 579route-to rule. 580This can be used for 581.Dq direct server return 582to force the target host to respond via a different gateway. 583Note that hosts have to accept sessions for the same address as 584the gateway, which is typically done by configuring a loopback 585interface on the host with this address. 586.It Ic session timeout Ar seconds 587Specify the inactivity timeout in seconds for established redirections. 588The default timeout is 600 seconds (10 minutes). 589The maximum is 2147483647 seconds (68 years). 590.It Ic sticky-address 591This has the same effect as specifying sticky-address 592for an rdr-to rule in 593.Xr pf.conf 5 . 594It will ensure that multiple connections from the same source are 595mapped to the same redirection address. 596.El 597.Sh RELAYS 598Relays will forward traffic between a client and a target server. 599In contrast to redirections and IP forwarding in the network stack, a 600relay will accept incoming connections from remote clients as a 601server, open an outgoing connection to a target host, and forward 602any traffic between the target host and the remote client, 603operating on layer 7. 604A relay is also called an application layer gateway or layer 7 proxy. 605.Pp 606The main purpose of a relay is to provide advanced load balancing 607functionality based on specified protocol characteristics, such as 608HTTP headers, to provide TLS acceleration and to allow 609basic handling of the underlying application protocol. 610.Pp 611The 612.Ic relay 613configuration directives are described below: 614.Bl -tag -width Ds 615.It Ic disable 616Start the relay but immediately close any accepted connections. 617.It Xo 618.Op Ic transparent 619.Ic forward 620.Op Ic with tls 621.Ic to 622.Ar address 623.Op Ic port Ar port 624.Ar options ... 625.Xc 626Specify the address and port of the target host to connect to. 627If the 628.Ic port 629option is not specified, the port from the 630.Ic listen on 631directive will be used. 632Use the 633.Ic transparent 634keyword to enable fully-transparent mode; the source address of the 635client will be retained in this case. 636.Pp 637The 638.Ic with tls 639directive enables client-side TLS mode to connect to the remote host. 640Verification of server certificates can be enabled by setting the 641.Ic ca file 642option in the protocol section. 643.Pp 644The following options may be specified for forward directives: 645.Bl -tag -width Ds 646.It Ic inet 647If the requested destination is an IPv6 address, 648.Xr relayd 8 649will forward the connection to an IPv4 address which is determined by 650the last 4 octets of the original IPv6 destination. 651For example, if the original IPv6 destination address is 6522001:db8:7395:ffff::a01:101, the session is relayed to the IPv4 653address 10.1.1.1 (a01:101). 654.It Ic inet6 Ar address-prefix 655If the requested destination is an IPv4 address, 656.Xr relayd 8 657will forward the connection to an IPv6 address which is determined by 658setting the last 4 octets of the specified IPv6 659.Ar address-prefix 660to the 4 octets of the original IPv4 destination. 661For example, if the original IPv4 destination address is 10.1.1.1 and 662the specified address prefix is 2001:db8:7395:ffff::, the session is 663relayed to the IPv6 address 2001:db8:7395:ffff::a01:101. 664.It Ic retry Ar number 665The optional host 666.Ic retry 667option will be used as a tolerance for failed 668host connections; the connection will be retried for 669.Ar number 670more times. 671.El 672.It Xo 673.Ic forward to 674.Pf < Ar table Ns > 675.Op Ic port Ar port 676.Ar options ... 677.Xc 678Like the previous directive, but connect to a host from the specified 679table; see the 680.Sx TABLES 681section above for information about table options. 682This directive can be specified multiple times \(en subsequent entries 683will be used as the backup table if all hosts in the previous table 684are down. 685At least one entry for the main table is mandatory. 686As above, use the 687.Ic with tls 688directive to enable client-side TLS mode when connecting to the remote host. 689.It Xo 690.Ic forward to 691.Ic destination 692.Ar options ... 693.Xc 694When redirecting connections with a divert-to rule in 695.Xr pf.conf 5 696to a relay listening on localhost, this directive will 697look up the real destination address of the intended target host, 698allowing the relay to be run as a transparent proxy. 699If an additional 700.Ic forward to 701directive to a specified address or table is present, 702it will be used as a backup if the lookup failed. 703As above, use the 704.Ic with tls 705directive to enable client-side TLS mode when connecting to the remote host. 706.It Xo 707.Ic forward to 708.Ic nat lookup 709.Ar options ... 710.Xc 711Like the previous directive, but for redirections with rdr-to in 712.Xr pf.conf 5 . 713.It Xo 714.Ic listen on Ar address Ic port Ar port 715.Op Ic tls 716.Xc 717Specify the address and port for the relay to listen on. 718The relay will accept incoming connections to the specified address. 719If the 720.Ic tls 721keyword is present, the relay will accept connections using the 722encrypted TLS protocol. 723.It Ic protocol Ar name 724Use the specified protocol definition for the relay. 725The generic TCP protocol options will be used by default; 726see the 727.Sx PROTOCOLS 728section below. 729.It Ic session timeout Ar seconds 730Specify the inactivity timeout in seconds for accepted sessions. 731The default timeout is 600 seconds (10 minutes). 732The maximum is 2147483647 seconds (68 years). 733.El 734.Sh TLS RELAYS 735In addition to plain TCP, 736.Xr relayd 8 737supports the Transport Layer Security (TLS) cryptographic protocol for 738authenticated and encrypted relays. 739.Xr relayd 8 740can operate as a TLS client or server to offer a variety of options 741for different use cases related to TLS. 742.Bl -tag -width Ds 743.It Ic TLS client 744When configuring the relay 745.Ic forward 746statements with the 747.Ic with tls 748directive, 749.Xr relayd 8 750will enable client-side TLS to connect to the remote host. 751This is commonly used for TLS tunneling and transparent encapsulation 752of plain TCP connections. 753See the 754.Ic forward to 755description in the 756.Sx RELAYS 757section for more details. 758.It Ic TLS server 759When specifying the 760.Ic tls 761keyword in the relay 762.Ic listen 763statements, 764.Xr relayd 8 765will accept connections from clients as a TLS server. 766This mode is also known as 767.Dq TLS acceleration . 768See the 769.Ic listen on 770description in the 771.Sx RELAYS 772section for more details. 773.It Ic TLS client and server 774When combining both modes, TLS server and client, 775.Xr relayd 8 776can filter TLS connections as a man-in-the-middle. 777This combined mode is also called 778.Dq TLS inspection . 779The configuration requires additional X.509 certificate settings; 780see the 781.Ic ca key 782description in the 783.Sx PROTOCOLS 784section for more details. 785.El 786.Pp 787When configured for 788.Dq TLS inspection 789mode, 790.Xr relayd 8 791will listen for incoming connections which have been diverted to the 792local socket by PF. 793Before accepting and negotiating the incoming TLS connection as a 794server, it will look up the original destination address on the 795diverted socket, and pre-connect to the target server as a TLS client 796to obtain the remote TLS certificate. 797It will update or patch the obtained TLS certificate by replacing the 798included public key with its local server key because it doesn't have 799the private key of the remote server certificate. 800It also updates the X.509 issuer name to the local CA subject name and 801signs the certificate with its local CA key. 802This way it keeps all the other X.509 attributes that are already 803present in the server certificate, including the "green bar" extended 804validation attributes. 805Now it finally accepts the TLS connection from the diverted client 806using the updated certificate and continues to handle the connection 807and to connect to the remote server. 808.Sh PROTOCOLS 809Protocols are templates defining settings and rules for relays. 810They allow setting generic TCP options, TLS settings, and rules 811for the selected application layer protocol. 812.Pp 813The protocol directive is available for a number of different 814application layer protocols. 815There is no generic handler for UDP-based protocols because it is a 816stateless datagram-based protocol which has to look into the 817application layer protocol to find any possible state information. 818.Bl -tag -width Ds 819.It Ic dns protocol 820(UDP) 821Domain Name System (DNS) protocol. 822The requested IDs in the DNS header will be used to match the state. 823.Xr relayd 8 824replaces these IDs with random values to compensate for 825predictable values generated by some hosts. 826.It Ic http protocol 827Handle the HyperText Transfer Protocol 828(HTTP, or "HTTPS" if encapsulated in a TLS tunnel). 829.It Xo 830.Op Ic tcp 831.Ic protocol 832.Xc 833Generic handler for TCP-based protocols. 834This is the default. 835.El 836.Pp 837The available configuration directives are described below: 838.Bl -tag -width Ds 839.It Xo 840.Pq Ic block Ns | Ns Ic pass Ns | Ns Ic match 841.Op Ar rule 842.Xc 843Specify one or more rules to filter connections based on their 844network or application layer headers; 845see the 846.Sx FILTER RULES 847section for more details. 848.It Ic return error Op Ar option 849Return an error response to the client if an internal operation or the 850forward connection to the client failed. 851By default, the connection will be silently dropped. 852The effect of this option depends on the protocol: HTTP will send an 853error header and page to the client before closing the connection. 854Additional valid options are: 855.Bl -tag -width Ds 856.It Ic style Ar string 857Specify a Cascading Style Sheet (CSS) to be used for the returned 858HTTP error pages, for example: 859.Bd -literal -offset indent 860body { background: #a00000; color: white; } 861.Ed 862.El 863.It Ic tcp Ar option 864Enable or disable the specified TCP/IP options; see 865.Xr tcp 4 866and 867.Xr ip 4 868for more information about the options. 869Valid options are: 870.Bl -tag -width Ds 871.It Ic backlog Ar number 872Set the maximum length the queue of pending connections may grow to. 873The backlog option is 10 by default, is limited to 512 and capped by the 874.Ic kern.somaxconn 875.Xr sysctl 8 876variable. 877.It Ic ip minttl Ar number 878This option for the underlying IP connection may be used to discard packets 879with a TTL lower than the specified value. 880This can be used to implement the 881Generalized TTL Security Mechanism (GTSM) 882according to RFC 5082. 883.It Ic ip ttl Ar number 884Change the default time-to-live value in the IP headers. 885.It Ic nodelay 886Enable the TCP NODELAY option for this connection. 887This is recommended to avoid delays in the relayed data stream, 888e.g. for SSH connections. 889The default is 890.Ic no nodelay . 891.It Ic no splice 892Disable socket splicing for zero-copy data transfer. 893The default is to enable socket splicing. 894.It Ic sack 895Use selective acknowledgements for this connection. 896The default is 897.Ic no sack . 898.It Ic socket buffer Ar number 899Set the socket-level buffer size for input and output for this 900connection. 901This will affect the TCP window size. 902.El 903.It Ic tls Ar option 904Set the TLS options and session settings. 905This is only used if TLS is enabled in the relay. 906Valid options are: 907.Bl -tag -width Ds 908.It Ic ca cert Ar path 909Specify a CA certificate for TLS inspection. 910For more information, see the 911.Ic ca key 912option below. 913.It Ic ca file Ar path 914This option enables CA verification in TLS client mode. 915The daemon will load the CA (Certificate Authority) certificates from 916the specified path to verify the server certificates. 917.Ox 918provides a default CA bundle in 919.Pa /etc/ssl/cert.pem . 920.It Ic ca key Ar path Ic password Ar password 921Specify a CA key for TLS inspection. 922The 923.Ar password 924argument will specify the password to decrypt the CA key 925(typically an RSA key). 926This option will enable TLS inspection if the following conditions 927are true: 928.Pp 929.Bl -bullet -compact -offset indent 930.It 931TLS server mode is enabled by the 932.Ic listen 933directive: 934.Ic listen on ... tls . 935.It 936TLS client mode and divert lookups are enabled by the 937.Ic forward 938directive: 939.Ic forward with tls to destination . 940.It 941The 942.Ic ca cert 943option is specified. 944.It 945The 946.Ic ca key 947option is specified. 948.El 949.It Ic ciphers Ar string 950Set the string defining the TLS cipher suite. 951If not specified, the default value 952.Ql HIGH:!aNULL 953will be used (strong crypto cipher suites without anonymous DH). 954See the CIPHERS section of 955.Xr openssl 1 956for information about TLS cipher suites and preference lists. 957.It Ic client ca Ar path 958Require TLS client certificates that can be verified against the CA 959certificates in the specified file. 960.It Ic client-renegotiation 961Allow client-initiated renegotiation. 962To mitigate a potential DoS risk, 963the default is 964.Ic no client-renegotiation . 965.It Ic ecdhe Ar curves 966Specify a comma separated list of elliptic curves to use for ECDHE cipher 967suites, in order of preference. 968The special value of "default" will use the default curves; see 969.Xr tls_config_set_ecdhecurves 3 970for further details. 971.It Ic edh Op Ic params Pq Ic none Ns | Ns Ic auto Ns | Ns Ic legacy 972Enable EDH-based cipher suites with Perfect Forward Secrecy (PFS) for 973older clients that do not support ECDHE. 974In 975.Ic auto 976mode, the key size of the ephemeral key is automatically selected 977based on the size of the private key used for signing. 978In 979.Ic legacy 980mode, a 1024 bit ephemeral key is used. 981If 982.Ic params 983is omitted, 984.Ic auto 985is used. 986The default is 987.Ic no edh . 988.It Ic keypair Ar name 989The relay will attempt to look up a private key in 990.Pa /etc/ssl/private/name:port.key 991and a public certificate in 992.Pa /etc/ssl/name:port.crt , 993where 994.Ar port 995is the specified port that the relay listens on. 996If these files are not present, the relay will continue to look in 997.Pa /etc/ssl/private/name.key 998and 999.Pa /etc/ssl/name.crt . 1000This option can be specified multiple times for TLS Server Name Indication. 1001If not specified, 1002a keypair will be loaded using the specified IP address of the relay as 1003.Ar name . 1004See 1005.Xr ssl 8 1006for details about TLS server certificates. 1007.Pp 1008An optional OCSP staple file will be used during TLS handshakes with 1009this server if it is found as a non-empty file in 1010.Pa /etc/ssl/name:port.ocsp 1011or 1012.Pa /etc/ssl/name.ocsp . 1013The file should contain a DER-format OCSP response retrieved from an 1014OCSP server for the certificate in use, and can be created using 1015.Xr ocspcheck 8 . 1016.It Ic no cipher-server-preference 1017Prefer the client's cipher list over the server's preferences when 1018choosing a cipher for the connection. 1019The default is to prefer the server's cipher list. 1020.It Ic session tickets 1021Enable TLS session tickets. 1022.Xr relayd 8 1023supports stateless TLS session tickets (RFC 5077) to implement TLS session 1024resumption for connections not using TLSv1.3. 1025The default is to disable session tickets. 1026.It Ic no tlsv1.3 1027Disable the TLSv1.3 protocol. 1028The default is to enable TLSv1.3. 1029.It Ic no tlsv1.2 1030Disable the TLSv1.2 protocol. 1031The default is to enable TLSv1.2. 1032.It Ic sslv3 1033Is deprecated and does nothing. 1034.It Ic tlsv1 1035Enable all TLSv1 protocols. 1036This is an alias that currently includes 1037.Ic tlsv1.2 , 1038and 1039.Ic tlsv1.3 . 1040The default is 1041.Ic no tlsv1 . 1042.It Ic tlsv1.0 1043Is deprecated and does nothing. 1044.It Ic tlsv1.1 1045Is deprecated and does nothing. 1046.El 1047.It Ic http Ar option 1048Set the HTTP options and session settings. 1049This is only used if HTTP is enabled in the relay. 1050Valid options are: 1051.Bl -tag -width Ds 1052.It Ic headerlen Ar number 1053Set the maximum size of all HTTP headers in bytes. 1054The default value is 8192 and it is limited to a maximum of 131072. 1055.It Ic websockets 1056Allow connection upgrade to websocket protocol. 1057The default is 1058.Ic no websockets . 1059.El 1060.El 1061.Sh FILTER RULES 1062Relays have the ability to filter connections based 1063on their network or application layer headers. 1064Filter rules apply options to connections based on the specified 1065filter parameters. 1066.Pp 1067For each connection that is processed by a relay, the filter rules are 1068evaluated in sequential order, from first to last. 1069For 1070.Ic block 1071and 1072.Ic pass , 1073the last matching rule decides what action is taken; 1074if no rule matches the connection, the default action is to establish 1075the connection without any additional action. 1076For 1077.Ic match , 1078rules are evaluated every time they match; 1079the pass/block state of a connection remains unchanged. 1080.Pp 1081The filter action may be one of the following: 1082.Bl -tag -width Ds 1083.It Ic block 1084The connection is blocked. 1085If a 1086.Ic block 1087rule matches a new connection attempt, it will not be established. 1088.Ic block 1089rules can also trigger for existing connections after evaluating 1090application layer parameters; 1091any connection of the relay session will be instantly dropped. 1092.It Ic match 1093The connection is matched. 1094This action does not alter the connection state, but allows 1095additional parameters to the connection. 1096.It Ic pass 1097The connection is passed; 1098.Xr relayd 8 1099will continue to process the relay session normally. 1100.El 1101.Pp 1102These filter parameters can be used in the rules: 1103.Bl -tag -width Ds 1104.It Ic request No or Ic response 1105A relay session always consists of two connections: 1106the 1107.Ic request , 1108a client initiating a new connection to a server via the relay, 1109and the 1110.Ic response , 1111the server accepting the connection. 1112Depending on the protocol, 1113an established session can be purely request/response-based (like 1114HTTP), exchange data in a bidirectional way (like arbitrary TCP 1115sessions), or just contain a single datagram and an optional response 1116(like UDP-based protocols). 1117But the client always 1118.Em requests 1119to communicate with a remote peer; the server. 1120.It Ic quick 1121If a connection is matched by a rule with the 1122.Ic quick 1123option set, 1124the rule is considered to be the last matching rule and any further 1125evaluation is skipped. 1126.It Ic inet No or Ic inet6 1127Only match connections with the specified address family, 1128either of type IPv4 or IPv6. 1129.It Ic from Ar address Ns Oo Li / Ns Ar prefix Oc 1130This rule only matches for connections from the specified source. 1131.It Ic to Ar address Ns Oo Li / Ns Ar prefix Oc 1132This rule only matches for connections to the specified destination. 1133The destination is the address the client was connecting to, 1134typically the relay's listen address in non-transparent mode, 1135not the address of the forwarded backend connection. 1136.It Ic forward to Pf < Ar table Ns > 1137Forward the request to a server in the specified table. 1138With this option, requests can be passed to specific backend servers. 1139A corresponding 1140.Ic forward to 1141declaration in the 1142.Sx RELAYS 1143section is required. 1144.It Ic label Ar string 1145The label will be printed as part of the error message if the 1146.Ic return error 1147option is set and may contain HTML tags, for example: 1148.Bd -literal -offset indent 1149block request url digest 5c1e03f58f8ce0b457474ffb371fd1ef \e 1150 label "<a href='http://example.com/adv.pl?id=7359'>\e 1151 Advisory provided by example.com</a>" 1152.Ed 1153.It Ic no Ar parameter 1154Reset a sticky parameter that was previously set by a matching rule. 1155The 1156.Ar parameter 1157is a keyword that can be either 1158.Ic label 1159or 1160.Ic tag . 1161.It Ic tag Ar string 1162Add a "sticky" tag to connections matching this filter rule. 1163Tags can be used to filter the connection by further rules using the 1164.Ic tagged 1165option. 1166Only one tag is assigned per connection; 1167the tag will be replaced if the connection is already tagged. 1168.It Ic tagged Ar string 1169Match the connection if it is already tagged with a given tag by a 1170previous rule. 1171.El 1172.Pp 1173The following parameters are available when using the 1174.Ic http 1175protocol: 1176.Bl -tag -width Ds 1177.It Ic method Ar name 1178Match the HTTP request method. 1179The method is specified by 1180.Ar name 1181and can be either 1182.Ic ACL , 1183.Ic BASELINE-CONTROL , 1184.Ic CHECKIN , 1185.Ic CHECKOUT , 1186.Ic CONNECT , 1187.Ic COPY , 1188.Ic DELETE , 1189.Ic GET , 1190.Ic HEAD , 1191.Ic LABEL , 1192.Ic LOCK , 1193.Ic MERGE , 1194.Ic MKACTIVITY , 1195.Ic MKCOL , 1196.Ic MKREDIRECTREF , 1197.Ic MKWORKSPACE , 1198.Ic MOVE , 1199.Ic OPTIONS , 1200.Ic ORDERPATCH , 1201.Ic PATCH , 1202.Ic POST , 1203.Ic PROPFIND , 1204.Ic PROPPATCH , 1205.Ic PUT , 1206.Ic REPORT , 1207.Ic SEARCH , 1208.Ic TRACE , 1209.Ic UNCHECKOUT , 1210.Ic UNLOCK , 1211.Ic UPDATE , 1212.Ic UPDATEREDIRECTREF , 1213or 1214.Ic VERSION-CONTROL . 1215.It Xo 1216.Ar type option 1217.Oo Oo Ic digest Oc 1218.Pq Ar key Ns | Ns Ic file Ar path 1219.Oo Ic value Ar value Oc Oc 1220.Xc 1221Match a specified HTTP header entity and an optional 1222.Ic key 1223and 1224.Ic value . 1225An 1226.Ic option 1227can be specified to modify the matched entity or to trigger an event. 1228The entity is extracted from the HTTP request or response header and 1229can be either of 1230.Ar type 1231.Ic cookie , 1232.Ic header , 1233.Ic path , 1234.Ic query , 1235or 1236.Ic url . 1237.Pp 1238Instead of a single 1239.Ar key , 1240multiple keys can be loaded from a 1241.Ic file 1242specified by 1243.Ar path 1244that contains one key per line. 1245Lines will be stripped at the first whitespace or newline character 1246and any empty lines or lines beginning with a hash mark 1247.Pq Ql # 1248will be ignored. 1249.Pp 1250If the 1251.Ic digest 1252keyword is specified, 1253compare the message digest of the key against the defined string. 1254The algorithm used is determined by the string length of the 1255.Ar key 1256argument, either SHA1 (40 characters) or MD5 (32 characters). 1257To compute the digest, 1258for example for a 1259.Ic url , 1260use this simple command: 1261.Bd -literal -offset indent 1262$ echo -n "example.com/path/?args" | sha1 1263.Ed 1264.El 1265.Pp 1266.Bq Ar type 1267may be one of: 1268.Bl -tag -width Ds 1269.It Ic cookie Ar option Oo Ar key Oo Ic value Ar value Oc Oc 1270Look up the entity as a value in the Cookie header. 1271This type is only available with the direction 1272.Ic request . 1273.It Ic header Ar option Oo Ar key Oo Ic value Ar value Oc Oc 1274Look up the entity in the application protocol headers, like HTTP 1275headers in 1276.Ic http 1277mode. 1278.It Ic path Ar option Oo Ar key Oo Ic value Ar value Oc Oc 1279Look up the entity as a value in the URL path when using the 1280.Ic http 1281protocol. 1282This type is only available with the direction 1283.Ic request . 1284The 1285.Ar key 1286will match the path of the requested URL without the hostname 1287and query and the value will match the complete query, 1288for example: 1289.Bd -literal -offset indent 1290block path "/index.html" 1291block path "/cgi-bin/t.cgi" value "foo=bar*" 1292.Ed 1293.It Ic path strip Ar number 1294Strip 1295.Ar number 1296path components from the beginning of the path of the requested URL 1297when using the 1298.Ic http 1299protocol. 1300This type is only available with the direction 1301.Ic request . 1302.It Ic query Ar option Oo Ar key Oo Ic value Ar value Oc Oc 1303Look up the entity as a query variable in the URL when using the 1304.Ic http 1305protocol. 1306This type is only available with the direction 1307.Ic request , 1308for example: 1309.Bd -literal -offset indent 1310# Will match /cgi-bin/example.pl?foo=bar&ok=yes 1311pass request query "foo" value "bar" 1312.Ed 1313.It Ic url Ar option Oo Oo Ic digest Oc Ar key Oo Ic value Ar value Oc Oc 1314Look up the entity as a URL suffix/prefix expression consisting of a 1315canonicalized hostname without port or suffix and a path name or 1316prefix when using the 1317.Ic http 1318protocol. 1319This type is only available with the direction 1320.Ic request , 1321for example: 1322.Bd -literal -offset indent 1323block url "example.com/index.html" 1324block url "example.com/test.cgi?val=1" 1325.Ed 1326.Pp 1327.Xr relayd 8 1328will match the full URL and different possible suffix/prefix 1329combinations by stripping subdomains and path components (up to 5 1330levels), and the query string. 1331For example, the following 1332lookups will be done for 1333http://www.example.com:81/1/2/3/4/5.html?query=yes: 1334.Bd -literal -offset indent 1335www.example.com/1/2/3/4/5.html?query=yes 1336www.example.com/1/2/3/4/5.html 1337www.example.com/ 1338www.example.com/1/ 1339www.example.com/1/2/ 1340www.example.com/1/2/3/ 1341example.com/1/2/3/4/5.html?query=yes 1342example.com/1/2/3/4/5.html 1343example.com/ 1344example.com/1/ 1345example.com/1/2/ 1346example.com/1/2/3/ 1347.Ed 1348.El 1349.Pp 1350.Bq Ar option 1351may be one of: 1352.Bl -tag -width Ds 1353.It Ic append 1354Append the specified 1355.Ar value 1356to a protocol entity with the selected 1357.Ar key 1358name. 1359If it does not exist, it will be created with the new value. 1360.Pp 1361The value string may contain predefined macros that will be expanded 1362at runtime: 1363.Pp 1364.Bl -tag -width $SERVER_ADDR -offset indent -compact 1365.It Ic $HOST 1366The Host header's value of the relay. 1367.It Ic $REMOTE_ADDR 1368The IP address of the connected client. 1369.It Ic $REMOTE_PORT 1370The TCP source port of the connected client. 1371.It Ic $SERVER_ADDR 1372The configured IP address of the relay. 1373.It Ic $SERVER_PORT 1374The configured TCP server port of the relay. 1375.It Ic $SERVER_NAME 1376The server software name of 1377.Xr relayd 8 . 1378.It Ic $TIMEOUT 1379The configured session timeout of the relay. 1380.El 1381.It Ic hash 1382Feed the 1383.Ar value 1384of the selected entity into the load balancing hash to select the 1385target host. 1386See the 1387.Ic table 1388keyword in the 1389.Sx RELAYS 1390section above. 1391.It Ic log 1392Log the 1393.Ar key 1394name and the 1395.Ar value 1396of the entity. 1397.It Ic remove 1398Remove the entity with the selected 1399.Ar key 1400name. 1401.It Ic set 1402Like the 1403.Ic append 1404directive above, but change the contents of the specified entity. 1405If 1406.Ar key 1407does not exist in the request, it will be created with the new 1408.Ar value . 1409.Pp 1410The 1411.Ar value 1412string 1413may contain predefined macros that will be expanded at runtime, 1414as detailed for the 1415.Ic append 1416directive above. 1417.El 1418.Sh ROUTERS 1419Routers represent routing table entries in the kernel forwarding 1420database, see 1421.Xr route 4 , 1422and a table of associated gateways. 1423They are used to dynamically insert or remove routes with gateways 1424based on their availability and health-check results. 1425A router can include multiple network statements and a single forward 1426statement with a table of one or more gateways. 1427All entries in a single router directive must match the same address 1428family, either IPv4 or IPv6. 1429.Pp 1430The kernel supports multipath routing when multiple gateways exist to 1431the same destination address. 1432The multipath routing behaviour can be changed globally using the 1433.Xr sysctl 8 1434variables 1435.Va net.inet.ip.multipath 1436and 1437.Va net.inet6.ip6.multipath . 1438With the default setting of 0, 1439the first route selected will be used for subsequent packets to that 1440destination regardless of source. 1441Setting it to 1 will enable load balancing based on the packet source 1442address across gateways; multiple routes with the same priority are 1443used equally. 1444The kernel will also check the link state of the related network 1445interface and try a different route if it is not active. 1446.Pp 1447The configuration directives that are valid in the 1448.Ic routers 1449context are described below: 1450.Bl -tag -width Ds 1451.It Xo 1452.Ic forward to 1453.Pf < Ar table Ns > 1454.Ic port Ar number 1455.Ar options ... 1456.Xc 1457Specify the table of target gateways to be used; see the 1458.Sx TABLES 1459section above for information about table options. 1460This entry is mandatory and must be specified once. 1461.It Xo 1462.Ic route 1463.Ar address Ns Li / Ns Ar prefix 1464.Xc 1465Specify the network address and prefix length of a route destination 1466that is reachable via the active gateways. 1467This entry must be specified at least once in a router directive. 1468.It Ic rtable Ar id 1469Add the routes to the kernel routing table with the specified 1470.Ar id . 1471.It Ic rtlabel Ar label 1472Add the routes with the specified 1473.Ar label 1474to the kernel routing table. 1475.El 1476.Sh FILES 1477.Bl -tag -width Ds -compact 1478.It Pa /etc/relayd.conf 1479.Xr relayd 8 1480configuration file. 1481.Pp 1482.It Pa /etc/examples/relayd.conf 1483Example configuration file. 1484.Pp 1485.It Pa /etc/services 1486Service name database. 1487.Pp 1488.It Pa /etc/ssl/address.crt 1489.It Pa /etc/ssl/address:port.crt 1490.It Pa /etc/ssl/private/address.key 1491.It Pa /etc/ssl/private/address:port.key 1492Location of the relay TLS server certificates, where 1493.Ar address 1494is the configured IP address 1495and 1496.Ar port 1497is the configured port number of the relay. 1498.Pp 1499.It Pa /etc/ssl/cert.pem 1500Default location of the CA bundle that can be used with 1501.Xr relayd 8 . 1502.El 1503.Sh EXAMPLES 1504This configuration file would create a redirection service 1505.Dq www 1506which load balances four hosts 1507and falls back to one host containing a 1508.Dq sorry page : 1509.Bd -literal -offset indent 1510www1=front-www1.private.example.com 1511www2=front-www2.private.example.com 1512www3=front-www3.private.example.com 1513www4=front-www4.private.example.com 1514 1515interval 5 1516 1517table <phphosts> { $www1, $www2, $www3, $www4 } 1518table <sorryhost> disable { sorryhost.private.example.com } 1519 1520redirect "www" { 1521 listen on www.example.com port 8080 interface trunk0 1522 listen on www6.example.com port 80 interface trunk0 1523 1524 pftag REDIRECTED 1525 1526 forward to <phphosts> port 8080 timeout 300 \e 1527 check http "/" digest "630aa3c2f..." 1528 forward to <sorryhost> port 8080 timeout 300 check icmp 1529} 1530.Ed 1531.Pp 1532It is possible to specify multiple listen directives with different IP 1533protocols in a single redirection configuration: 1534.Bd -literal -offset indent 1535redirect "dns" { 1536 listen on dns.example.com tcp port 53 1537 listen on dns.example.com udp port 53 1538 1539 forward to <dnshosts> port 53 check tcp 1540} 1541.Ed 1542.Pp 1543To load balance an IP address over multiple backend servers using a 1544.Xr pf 4 1545.Cm route-to 1546directive: 1547.Bd -literal -offset indent 1548table <backends> { 10.100.42.71 10.100.42.72 10.100.42.73 } 1549 1550redirect "xmpp" { 1551 listen on 10.100.42.2 tcp port 5222 1552 1553 route to <backends> port 5222 check tcp interface em0 1554} 1555.Ed 1556.Pp 1557The following configuration would add a relay to forward 1558secure HTTPS connections to a pool of HTTP webservers 1559using the 1560.Ic loadbalance 1561mode (TLS acceleration and layer 7 load balancing). 1562The HTTP protocol definition will add two HTTP headers containing 1563address information of the client and the server, set the 1564.Dq Keep-Alive 1565header value to the configured session timeout, 1566and include the 1567.Dq sessid 1568variable in the hash to calculate the target host: 1569.Bd -literal -offset indent 1570http protocol "https" { 1571 match header set "X-Forwarded-For" \e 1572 value "$REMOTE_ADDR" 1573 match header set "X-Forwarded-By" \e 1574 value "$SERVER_ADDR:$SERVER_PORT" 1575 match header set "Keep-Alive" value "$TIMEOUT" 1576 1577 match query hash "sessid" 1578 1579 pass 1580 block path "/cgi-bin/index.cgi" value "*command=*" 1581 1582 tls { no tlsv1.0, ciphers "HIGH" } 1583} 1584 1585relay "tlsaccel" { 1586 listen on www.example.com port 443 tls 1587 protocol "https" 1588 forward to <phphosts> port 8080 mode loadbalance check tcp 1589} 1590.Ed 1591.Pp 1592The second relay example will accept incoming connections to port 15932222 and forward them to a remote SSH server. 1594The TCP 1595.Ic nodelay 1596option will allow a 1597.Dq smooth 1598SSH session without delays between keystrokes or displayed output on 1599the terminal: 1600.Bd -literal -offset indent 1601protocol "myssh" { 1602 tcp { nodelay, socket buffer 65536 } 1603} 1604 1605relay "sshforward" { 1606 listen on www.example.com port 2222 1607 protocol "myssh" 1608 forward to shell.example.com port 22 1609} 1610.Ed 1611.Pp 1612The following relay example will configure 1613.Dq TLS inspection 1614as described in the 1615.Sx TLS RELAYS 1616section. 1617To start, first generate a new local CA key and certificate: 1618.Bd -literal -offset indent 1619# openssl req -x509 -days 365 -newkey rsa:2048 \e 1620 -keyout /etc/ssl/private/ca.key -out /etc/ssl/ca.crt 1621.Ed 1622.Pp 1623A TLS server key and self-signed cert for 127.0.0.1 are also required; 1624see 1625.Ic listen on 1626in the 1627.Sx RELAYS 1628section for more details about certificate locations. 1629Configure the packet filter with a matching divert rule in 1630.Xr pf.conf 5 : 1631.Bd -literal -offset indent 1632# Divert incoming HTTPS traffic to relayd 1633pass in on vlan1 inet proto tcp to port 443 \e 1634 divert-to localhost port 8443 1635.Ed 1636.Pp 1637And finally configure the TLS inspection in 1638.Nm : 1639.Bd -literal -offset indent 1640http protocol httpfilter { 1641 return error 1642 1643 pass 1644 match label "Prohibited!" 1645 block url "social.network.example.com/" 1646 1647 # New configuration directives for TLS Interception 1648 tls ca key "/etc/ssl/private/ca.key" password "password123" 1649 tls ca cert "/etc/ssl/ca.crt" 1650} 1651 1652relay tlsinspect { 1653 listen on 127.0.0.1 port 8443 tls 1654 protocol httpfilter 1655 forward with tls to destination 1656} 1657.Ed 1658.Pp 1659The next simple router configuration example can be used to run 1660redundant, health-checked WAN links: 1661.Bd -literal -offset indent 1662table <gateways> { $gw1 ip ttl 1, $gw2 ip ttl 1 } 1663router "uplinks" { 1664 route 0.0.0.0/0 1665 forward to <gateways> check icmp 1666} 1667.Ed 1668.Sh SEE ALSO 1669.Xr ocspcheck 8 , 1670.Xr relayctl 8 , 1671.Xr relayd 8 , 1672.Xr ssl 8 1673.Sh HISTORY 1674The 1675.Nm 1676file format, formerly known as 1677.Ic hoststated.conf , 1678first appeared in 1679.Ox 4.1 . 1680It was renamed to 1681.Nm 1682in 1683.Ox 4.3 . 1684.Sh AUTHORS 1685.An -nosplit 1686The 1687.Xr relayd 8 1688program was written by 1689.An Pierre-Yves Ritschard Aq Mt pyr@openbsd.org 1690and 1691.An Reyk Floeter Aq Mt reyk@openbsd.org . 1692.Sh CAVEATS 1693.Xr relayd 8 1694verification of TLS server certificates is based on a static CA bundle 1695and 1696.Xr relayd 8 1697currently does not support CRLs (Certificate Revocation Lists). 1698