Routing, DNAT and load balancing

Summary

A routing profile changes the upstream destination after a policy match. It can replace the destination address, replace the destination port, distribute connections across resolved addresses and rewrite an exact outbound TLS SNI value.

Use it for controlled service redirection or simple upstream distribution. It is not a health-checking load balancer: candidate selection does not probe application health or retry failed targets.

Minimal DNAT example

Define target objects:

address_objects = {
    backend_a = { type = "cidr"; value = "192.0.2.20/32"; };
};

port_objects = {
    backend_tls = { start = 8443; end = 8443; };
};

Create a routing profile:

routing = {
    internal_tls = {
        dnat_address = [ "backend_a" ];
        dnat_port = [ "backend_tls" ];
        dnat_lb_method = "round-robin";
    };
};

Reference it from a policy:

policy = (
  {
    name = "route lab service";
    proto = "tcp";
    src = [ "lab" ];
    sport = [ "all" ];
    dst = [ "service_vip" ];
    dport = [ "https" ];
    action = "accept";
    nat = "auto";
    routing = "internal_tls";
  }
);

Routing profile fields

Field Type Behavior
dnat_address array of address-object names expands candidates for the connection address family
dnat_port array of port-object names uses the first referenced object and its first port
dnat_lb_method string round-robin, sticky-l3 or sticky-l4
rewrite_sni string exact client SNI value to match
rewrite_sni_to string outbound replacement SNI

If a port object contains a range, only its first port is used. There is no port-range balancing.

Candidate expansion

Address objects are expanded separately for IPv4 and IPv6. A connection selects candidates matching its current target address family. Candidate lists are refreshed at most once per five seconds, which allows FQDN-backed objects to follow DNS changes without resolving on every connection.

If no candidate exists for the relevant family, the address is not replaced. Always provide both families explicitly when dual-stack routing is required.

Distribution methods

round-robin

Uses a per-profile counter modulo the number of candidates. The counter advances when the profile is updated for a routing request. It does not account for active connection count, latency or failures.

sticky-l3

Calculates CRC32 over:

source IP + original destination IP

The result selects a candidate by modulo. Connections with the same L3 tuple remain on the same candidate while the ordered candidate set is unchanged.

sticky-l4

Calculates CRC32 over:

source IP + original destination IP + original destination port

The client source port is not part of this implementation. This is destination-service stickiness, not per-flow five-tuple hashing.

Candidate-set changes can remap existing keys because selection uses modulo; this is not consistent hashing.

Outbound SNI rewrite

Both fields must be non-empty:

routing = {
    sni_route = {
        rewrite_sni = "public.example";
        rewrite_sni_to = "backend.internal";
    };
};

The match is exact. SNI rewrite changes the outbound TLS name; it does not by itself change DNS resolution or the upstream IP. Combine it with dnat_address when the replacement name is served at a different target.

Diagnostics

diag proxy policy list
diag proxy session list 7 tls ips
show event list

Verify the matched policy, original destination, selected upstream address/port and observed outbound SNI. Test every address family and every candidate. A successful round-robin test does not establish stickiness behavior.