Skip to content

Commit 1df2bbe

Browse files
trozethzhou8
authored andcommitted
northd: Skip UNSNAT for force-SNAT load balancer VIPs.
Northd adds a priority-120 UNSNAT bypass when a load balancer VIP also appears as a NAT external IP. This prevents packets for the VIP from repeatedly entering an SNAT zone lookup that never commits the pre-DNAT tuple. Such packets remain ct.new and cannot be offloaded. Gateway routers using lb_force_snat_ip=router_ip may use a router port IP as the VIP while their NAT external IP is a different masquerade address. Northd then omits the bypass even though it creates an UNSNAT flow for the router port IP. Generate the bypass when a port-specific VIP also matches a DNAT or load balancer force-SNAT address, or a router port address selected by lb_force_snat_ip=router_ip. Do not extend the bypass to port-less VIPs in the new force-SNAT cases. Such a flow would match replies sent to the force-SNAT address and shadow the flow that reverses SNAT. Keep the existing NAT external-IP behavior unchanged. Add coverage using port-specific and port-less VIPs with a different masquerade SNAT address. A single-stream OVN-Kubernetes DPU test with the port-specific NodePort VIP improved from 8.8 Gbit/s to 19.8 Gbit/s. Reported-at: ovn-kubernetes/ovn-kubernetes#6422 Assisted-by: GPT-5, OpenAI Codex Signed-off-by: Tim Rozet <trozet@nvidia.com> Signed-off-by: Han Zhou <hzhou@ovn.org> (cherry picked from commit 45831b7)
1 parent c643458 commit 1df2bbe

2 files changed

Lines changed: 71 additions & 8 deletions

File tree

northd/northd.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13761,6 +13761,28 @@ build_gw_lrouter_nat_flows_for_lb(struct lrouter_nat_lb_flows_ctx *ctx,
1376113761
bitmap_free(dp_non_meter);
1376213762
}
1376313763

13764+
static bool
13765+
lrouter_lb_vip_is_unsnat_ip(const struct ovn_datapath *od,
13766+
const struct lr_nat_record *lrnat_rec,
13767+
const struct ovn_lb_vip *lb_vip)
13768+
{
13769+
const char *vip = lb_vip->vip_str;
13770+
13771+
if (sset_contains(&lrnat_rec->external_ips, vip)) {
13772+
return true;
13773+
}
13774+
13775+
/* A port-less bypass would also match replies sent to a force-SNAT
13776+
* address and prevent them from reaching the UNSNAT flow. */
13777+
return lb_vip->port_str
13778+
&& (lport_addresses_contains_ip(
13779+
&lrnat_rec->dnat_force_snat_addrs, 1, vip)
13780+
|| lport_addresses_contains_ip(
13781+
&lrnat_rec->lb_force_snat_addrs, 1, vip)
13782+
|| (lrnat_rec->lb_force_snat_router_ip
13783+
&& sset_contains(&od->router_ips, vip)));
13784+
}
13785+
1376413786
static void
1376513787
build_lrouter_nat_flows_for_lb(
1376613788
struct ovn_lb_vip *lb_vip,
@@ -13910,16 +13932,15 @@ build_lrouter_nat_flows_for_lb(
1391013932
bitmap_set1(aff_dp_bitmap[type], index);
1391113933
}
1391213934

13913-
if (sset_contains(&lrnat_rec->external_ips, lb_vip->vip_str)) {
13914-
/* The load balancer vip is also present in the NAT entries.
13915-
* So add a high priority lflow to advance the the packet
13916-
* destined to the vip (and the vip port if defined)
13917-
* in the S_ROUTER_IN_UNSNAT stage.
13935+
if (lrouter_lb_vip_is_unsnat_ip(od, lrnat_rec, lb_vip)) {
13936+
/* The load balancer VIP is also present in an UNSNAT flow.
13937+
* Add a high priority lflow to advance packets destined to the
13938+
* VIP (and the VIP port if defined) in S_ROUTER_IN_UNSNAT.
1391813939
* There seems to be an issue with ovs-vswitchd. When the new
13919-
* connection packet destined for the lb vip is received,
13920-
* it is dnat'ed in the S_ROUTER_IN_DNAT stage in the dnat
13940+
* connection packet destined for the LB VIP is received,
13941+
* it is DNATed in the S_ROUTER_IN_DNAT stage in the DNAT
1392113942
* conntrack zone. For the next packet, if it goes through
13922-
* unsnat stage, the conntrack flags are not set properly, and
13943+
* UNSNAT stage, the conntrack flags are not set properly, and
1392313944
* it doesn't hit the established state flows in
1392413945
* S_ROUTER_IN_DNAT stage. */
1392513946
ovn_lflow_add(lflows, od, S_ROUTER_IN_UNSNAT, 120,

tests/ovn-northd.at

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,48 @@ OVN_CLEANUP_NORTHD
18821882
AT_CLEANUP
18831883
])
18841884

1885+
OVN_FOR_EACH_NORTHD_NO_HV([
1886+
AT_SETUP([Load balancer VIP in force-SNAT addresses])
1887+
ovn_start
1888+
1889+
check ovn-nbctl ls-add public
1890+
check ovn-nbctl lr-add lr0
1891+
check ovn-nbctl set logical_router lr0 options:chassis=ch1
1892+
check ovn-nbctl lrp-add lr0 lr0-public 00:00:00:00:00:01 \
1893+
192.0.2.1/24
1894+
check ovn-nbctl lsp-add-router-port public public-lr0 lr0-public
1895+
1896+
check ovn-nbctl lb-add lb0 192.0.2.1:30663 198.51.100.10:5201
1897+
check ovn-nbctl lb-add lb1 192.0.2.1 198.51.100.11
1898+
check ovn-nbctl lr-lb-add lr0 lb0
1899+
check ovn-nbctl lr-lb-add lr0 lb1
1900+
check ovn-nbctl lr-nat-add lr0 snat 169.254.0.47 198.51.100.0/24
1901+
check ovn-nbctl --wait=sb sync
1902+
1903+
ovn-sbctl dump-flows lr0 > sbflows
1904+
AT_CAPTURE_FILE([sbflows])
1905+
AT_CHECK([grep "lr_in_unsnat.*priority=120" sbflows], [1])
1906+
1907+
check ovn-nbctl --wait=sb set logical_router lr0 \
1908+
options:lb_force_snat_ip=192.0.2.1
1909+
1910+
AT_CHECK([ovn-sbctl dump-flows lr0 | \
1911+
grep "lr_in_unsnat.*priority=120" | ovn_strip_lflows], [0], [dnl
1912+
table=??(lr_in_unsnat ), priority=120 , match=(ip4 && ip4.dst == 192.0.2.1 && tcp && tcp.dst == 30663), action=(next;)
1913+
])
1914+
1915+
check ovn-nbctl --wait=sb set logical_router lr0 \
1916+
options:lb_force_snat_ip=router_ip
1917+
1918+
AT_CHECK([ovn-sbctl dump-flows lr0 | \
1919+
grep "lr_in_unsnat.*priority=120" | ovn_strip_lflows], [0], [dnl
1920+
table=??(lr_in_unsnat ), priority=120 , match=(ip4 && ip4.dst == 192.0.2.1 && tcp && tcp.dst == 30663), action=(next;)
1921+
])
1922+
1923+
OVN_CLEANUP_NORTHD
1924+
AT_CLEANUP
1925+
])
1926+
18851927
OVN_FOR_EACH_NORTHD_NO_HV([
18861928
AT_SETUP([LRP same IP as VIP or SNAT])
18871929
ovn_start

0 commit comments

Comments
 (0)