Hello,
I hope you are well.
I encountered a strange performance degradation.
Simplified config (essentially, LAN routed to WAN, however, for specific DHCP pool default route is replaced with wireguard through separate routing table using routing rule)
# * by RouterOS 7.13
# model = CRS309-1G-8S+
/interface bridge add frame-types=admit-only-vlan-tagged name=bridge1 vlan-filtering=yes
/interface ethernet set [ find default-name=sfp-sfpplus1 ] l2mtu=10218
/interface ethernet set [ find default-name=sfp-sfpplus2 ] l2mtu=10218 mtu=10134
/interface wireguard add listen-port=56791 mtu=1420 name=wgCF private-key="*"
/interface vlan add interface=bridge1 mtu=10134 name=lan1 vlan-id=2
/interface vlan add interface=bridge1 name=wan1 vlan-id=3
/interface ethernet switch set 0 l3-hw-offloading=yes qos-hw-offloading=yes
/interface ethernet switch port set sfp-sfpplus1 l3-hw-offloading=no
/ip pool add name=dhcp_pool_lan_devices ranges=192.168.0.0/27
/ip pool add name=dhcp_pool_lan_cf ranges=192.168.0.32/27
/ip pool add name=dhcp_pool_lan_unknown ranges=192.168.0.96/27
/ip dhcp-server add address-pool=dhcp_pool_lan_unknown authoritative=yes interface=lan1 lease-time=1d name=dhcp_lan
/routing table add fib name=cf
/interface bridge port add bridge=bridge1 comment=WAN1 frame-types=admit-only-untagged-and-priority-tagged interface=sfp-sfpplus1 pvid=3
/interface bridge port add bridge=bridge1 comment=LAN1 edge=yes frame-types=admit-all interface=sfp-sfpplus2 pvid=2
/interface ethernet switch l3hw-settings set fasttrack-hw=yes ipv6-hw=yes
/ip settings set allow-fast-path=yes ip-forward=yes
/ipv6 settings set disable-ipv6=no forward=yes
/interface bridge vlan add bridge=bridge1 tagged=bridge1 vlan-ids=2
/interface bridge vlan add bridge=bridge1 tagged=bridge1 vlan-ids=3
/interface wireguard peers add allowed-address=0.0.0.0/0 endpoint-address=* endpoint-port=* interface=wgCF persistent-keepalive=25s public-key="*"
/ip address add address=192.168.0.1/24 interface=lan1 network=192.168.0.0
/ip address add address=172.16.0.2 interface=wgCF network=172.16.0.2
/ip dhcp-client add add-default-route=special-classless default-route-distance=10 interface=wan1 use-peer-dns=no use-peer-ntp=no
/ip dhcp-server lease add address=192.168.0.36 client-id=cf mac-address=* server=dhcp_lan
/ip dhcp-server lease add address=192.168.0.6 mac-address=* server=dhcp_lan
/ip dhcp-server network add address=192.168.0.0/24 comment=lan dns-server=1.1.1.1,1.0.0.1 gateway=192.168.0.1
/ip firewall filter add action=fasttrack-connection chain=forward connection-state=established,related hw-offload=yes
/ip firewall nat add action=masquerade chain=srcnat out-interface=wan1
/ip firewall nat add action=masquerade chain=srcnat out-interface=wgCF
/ip route add dst-address=0.0.0.0/0 gateway=wgCF routing-table=cf
/ip route add dst-address=104.16.123.96/32 gateway=wgCF pref-src=172.16.0.2
/routing rule add action=lookup min-prefix=0 table=main
/routing rule add action=lookup-only-in-table interface=lan1 src-address=192.168.0.32/27 table=cf
Note three most relevant parts
/ip dhcp-server lease add address=192.168.0.36 client-id=cf mac-address=* server=dhcp_lan
/ip dhcp-server lease add address=192.168.0.6 mac-address=* server=dhcp_lan
/ip firewall filter add action=fasttrack-connection chain=forward connection-state=established,related hw-offload=yes
/ip route add dst-address=104.16.123.96/32 gateway=wgCF pref-src=172.16.0.2
Test is being done from macOS device connected to sfp-sfpplus2 using the following commands
curl --resolve www.cloudflare.com:443:104.16.123.96 'https://www.cloudflare.com/cdn-cgi/trace' -v --trace-time
curl --resolve www.cloudflare.com:443:104.16.124.96 'https://www.cloudflare.com/cdn-cgi/trace' -v --trace-time
If the client does not fill client-id, it receives 192.168.0.6 IP. Both curl commands execute instantaneously, and the first result signifies traffic has been through the wireguard interface, the second - not.
If the client sets client-id=cf, it receives 192.168.0.36 IP. The first curl command executes instantaneously, the second curl commands executes with a ~1.5-second delay (see log below) usually during TLS handshake but sometimes before response. Both results signify traffic has been through the wireguard interface.
Deleting the route to 104.16.123.96 adds the delay to execution of the first command. Removing the firewall fasttrack-connection rule removes the delay from both.
Adding either out-interface=!wgCF or src-address=!192.168.0.32/27 to the firewall fasttrack-connection rule does NOT remove the delay.
What could be the problem?
P. S. TLS handshake delay is reproducible with any website that is routed through the separate routing table (e. g. opening a website in browser is delayed, and then images on it are delayed after the website is shown, as new connections with new TLS handshakes need to be established).
14:48:38.984210 * Added www.cloudflare.com:443:104.16.124.96 to DNS cache
14:48:38.984529 * Hostname www.cloudflare.com was found in DNS cache
14:48:38.984641 * Trying 104.16.124.96:443...
14:48:38.988348 * Connected to www.cloudflare.com (104.16.124.96) port 443
14:48:38.990355 * ALPN: curl offers h2,http/1.1
14:48:38.990609 * TLSv1.3 (OUT), TLS handshake, Client hello (1):
14:48:39.001550 * CAfile: /opt/local/share/curl/curl-ca-bundle.crt
14:48:39.001577 * CApath: none
14:48:39.018492 * TLSv1.3 (IN), TLS handshake, Server hello (2):
14:48:39.018921 * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
14:48:39.018962 * TLSv1.3 (IN), TLS handshake, Certificate (11):
14:48:39.022113 * TLSv1.3 (IN), TLS handshake, CERT verify (15):
14:48:39.022339 * TLSv1.3 (IN), TLS handshake, Finished (20):
14:48:39.022407 * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
14:48:39.022464 * TLSv1.3 (OUT), TLS handshake, Finished (20):
14:48:39.022539 * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / x25519 / id-ecPublicKey
14:48:39.022568 * ALPN: server accepted h2
14:48:39.022595 * Server certificate:
14:48:39.022627 * subject: CN=www.cloudflare.com
14:48:39.022656 * start date: Apr 25 21:43:30 2024 GMT
14:48:39.022684 * expire date: Jul 24 21:43:29 2024 GMT
14:48:39.022715 * subjectAltName: host "www.cloudflare.com" matched cert's "www.cloudflare.com"
14:48:39.022744 * issuer: C=US; O=Let's Encrypt; CN=E1
14:48:39.022770 * SSL certificate verify ok.
14:48:39.022800 * Certificate level 0: Public key type EC/prime256v1 (256/128 Bits/secBits), signed using ecdsa-with-SHA384
14:48:39.022828 * Certificate level 1: Public key type EC/secp384r1 (384/192 Bits/secBits), signed using ecdsa-with-SHA384
14:48:39.022855 * Certificate level 2: Public key type EC/secp384r1 (384/192 Bits/secBits), signed using ecdsa-with-SHA384
14:48:39.022957 * using HTTP/2
14:48:39.023015 * [HTTP/2] [1] OPENED stream for https://www.cloudflare.com/cdn-cgi/trace
14:48:39.023042 * [HTTP/2] [1] [:method: GET]
14:48:39.023068 * [HTTP/2] [1] [:scheme: https]
14:48:39.023094 * [HTTP/2] [1] [:authority: www.cloudflare.com]
14:48:39.023119 * [HTTP/2] [1] [:path: /cdn-cgi/trace]
14:48:39.023146 * [HTTP/2] [1] [user-agent: curl/8.6.0]
14:48:39.023172 * [HTTP/2] [1] [accept: */*]
14:48:39.023219 > GET /cdn-cgi/trace HTTP/2
14:48:39.023219 > Host: www.cloudflare.com
14:48:39.023219 > User-Agent: curl/8.6.0
14:48:39.023219 > Accept: */*
14:48:39.023219 >
14:48:40.292474 * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
14:48:40.292692 * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
14:48:40.292770 * old SSL session ID is stale, removing
14:48:40.295692 < HTTP/2 200
14:48:40.295761 < date: Mon, 20 May 2024 11:48:39 GMT
14:48:40.295813 < content-type: text/plain
14:48:40.295863 < access-control-allow-origin: *
14:48:40.295912 < server: cloudflare
14:48:40.295961 < cf-ray: 886c1954ece52de7-DME
14:48:40.296017 < x-frame-options: DENY
14:48:40.296066 < x-content-type-options: nosniff
14:48:40.296121 < expires: Thu, 01 Jan 1970 00:00:01 GMT
14:48:40.296171 < cache-control: no-cache
14:48:40.296253 <
14:48:40.296413 * Connection #0 to host www.cloudflare.com left intact