SNAT and DNAT are committed in separate conntrack zones, and the reply direction looks a connection up in both. NIC hardware offload cannot serve the cross-zone lookup, so a router that both SNATs and DNATs drops to software on offloaded deployments. By default the operator has to set use_common_zone and remove gateway_mtu to recover the offload.
Detect hardware offload and do this automatically. ovn-controller now reports whether Open vSwitch has other_config:hw-offload enabled as a new hw-offload chassis feature, and northd ANDs it across every chassis like the other feature flags. When every chassis offloads, northd uses the common zone for the SNAT and DNAT of a router and stops emitting the check_pkt_larger action that gateway_mtu programs (it is not offloadable). A router that merges a load balancer with a NAT rule that performs SNAT (a snat or a dnat_and_snat floating IP) is kept on the separate zones: conntrack cannot reverse both an SNAT and a DNAT on the same packet in a single zone, which this combination requires. Reported-at: https://bugs.launchpad.net/ubuntu/+source/ovn/+bug/2175605 Signed-off-by: MJ Ponsonby <[email protected]> Assisted-by: DeepSeek V4 Pro, OpenCode --- NEWS | 8 ++++ controller/chassis.c | 14 +++++++ include/ovn/features.h | 1 + northd/en-global-config.c | 10 +++++ northd/en-global-config.h | 1 + northd/inc-proc-northd.c | 2 + northd/northd.c | 41 +++++++++++++++++-- ovn-nb.xml | 15 +++++-- tests/ovn-northd.at | 86 +++++++++++++++++++++++++++++++++++++++ 9 files changed, 172 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 628d894a3..b80c64676 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,14 @@ Post v26.09.0 message if a priority, match, or chain is provided as the input, but no router policies are actually deleted. This message is suppressed and ovn-nbctl will return 0 if "--if-exists" is supplied. + - When every chassis in the cluster has hardware offload enabled + (other_config:hw-offload=true in the Chassis record), ovn-northd now + uses a single common conntrack zone for the SNAT and DNAT of a router + and skips the non-offloadable check_pkt_larger action, unless the router + combines a load balancer with a NAT rule that performs SNAT (snat or + dnat_and_snat, i.e. a floating IP). Such routers require the separate + zones because conntrack cannot reverse both an SNAT and a DNAT on the + same packet in a single zone, and they continue to use them. - Router policies that used the deprecated "nexthop" column used to always be skipped and not applied. Now these router policies are only skipped if their action is "reroute". Router policies of type diff --git a/controller/chassis.c b/controller/chassis.c index a6feca5cb..dbf8c4d42 100644 --- a/controller/chassis.c +++ b/controller/chassis.c @@ -74,6 +74,8 @@ struct ovs_chassis_cfg { bool sample_with_regs; /* Does OVS support flushing CT zones using label/mark? */ bool ct_label_flush; + /* Is hardware offload (other_config:hw-offload) enabled? */ + bool hw_offload; }; enum chassis_update_status { @@ -382,6 +384,8 @@ chassis_parse_ovs_config(const struct ovsrec_open_vswitch_table *ovs_table, ovs_feature_is_supported(OVS_SAMPLE_REG_SUPPORT); ovs_cfg->ct_label_flush = ovs_feature_is_supported(OVS_CT_LABEL_FLUSH_SUPPORT); + ovs_cfg->hw_offload = smap_get_bool(&cfg->other_config, "hw-offload", + false); return true; } @@ -421,6 +425,8 @@ chassis_build_other_config(const struct ovs_chassis_cfg *ovs_cfg, smap_replace(config, OVN_FEATURE_CT_LABEL_FLUSH, ovs_cfg->ct_label_flush ? "true" :"false"); smap_replace(config, OVN_FEATURE_CT_STATE_SAVE, "true"); + smap_replace(config, OVN_FEATURE_HW_OFFLOAD, + ovs_cfg->hw_offload ? "true" : "false"); } /* @@ -594,6 +600,13 @@ chassis_other_config_changed(const struct ovs_chassis_cfg *ovs_cfg, return true; } + bool chassis_hw_offload = + smap_get_bool(&chassis_rec->other_config, OVN_FEATURE_HW_OFFLOAD, + false); + if (chassis_hw_offload != ovs_cfg->hw_offload) { + return true; + } + return false; } @@ -776,6 +789,7 @@ update_supported_sset(struct sset *supported) sset_add(supported, OVN_FEATURE_CT_NEXT_ZONE); sset_add(supported, OVN_FEATURE_CT_LABEL_FLUSH); sset_add(supported, OVN_FEATURE_CT_STATE_SAVE); + sset_add(supported, OVN_FEATURE_HW_OFFLOAD); } static void diff --git a/include/ovn/features.h b/include/ovn/features.h index 7207da67f..2f5daea83 100644 --- a/include/ovn/features.h +++ b/include/ovn/features.h @@ -27,6 +27,7 @@ #define OVN_FEATURE_CT_NEXT_ZONE "ct-next-zone" #define OVN_FEATURE_CT_LABEL_FLUSH "ct-label-flush" #define OVN_FEATURE_CT_STATE_SAVE "ct-state-save" +#define OVN_FEATURE_HW_OFFLOAD "hw-offload" /* DEPRECATED: The following features can be removed * after the next LTS version release. */ diff --git a/northd/en-global-config.c b/northd/en-global-config.c index 2558f5955..e84653a6c 100644 --- a/northd/en-global-config.c +++ b/northd/en-global-config.c @@ -520,6 +520,7 @@ northd_enable_all_features(struct ed_type_global_config *data) .ct_next_zone = true, .ct_label_flush = true, .ct_state_save = true, + .hw_offload = true, }; } @@ -596,6 +597,15 @@ build_chassis_features(const struct sbrec_chassis_table *sbrec_chassis_table, chassis_features->ct_state_save) { chassis_features->ct_state_save = false; } + + bool hw_offload = + smap_get_bool(&chassis->other_config, + OVN_FEATURE_HW_OFFLOAD, + false); + if (!hw_offload && + chassis_features->hw_offload) { + chassis_features->hw_offload = false; + } } } diff --git a/northd/en-global-config.h b/northd/en-global-config.h index 5a7b7ecda..1c7cf2497 100644 --- a/northd/en-global-config.h +++ b/northd/en-global-config.h @@ -20,6 +20,7 @@ struct chassis_features { bool ct_next_zone; bool ct_label_flush; bool ct_state_save; + bool hw_offload; }; struct global_config_tracked_data { diff --git a/northd/inc-proc-northd.c b/northd/inc-proc-northd.c index 49348e42f..6659d136c 100644 --- a/northd/inc-proc-northd.c +++ b/northd/inc-proc-northd.c @@ -714,6 +714,8 @@ chassis_features_list(struct unixctl_conn *conn, int argc OVS_UNUSED, features->ct_label_flush ? "true" : "false"); ds_put_format(&ds, "ct_state_save: %s\n", features->ct_state_save ? "true" : "false"); + ds_put_format(&ds, "hw_offload: %s\n", + features->hw_offload ? "true" : "false"); unixctl_command_reply(conn, ds_cstr(&ds)); ds_destroy(&ds); diff --git a/northd/northd.c b/northd/northd.c index a960da3ce..fe69ceda1 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -85,6 +85,12 @@ static bool install_ls_lb_from_router; /* Use common zone for SNAT and DNAT if this option is set to "true". */ static bool use_common_zone = false; +/* True if every chassis in the topology has hardware offload enabled. + * When set, northd auto-enables the common NAT zone and skips the + * non-offloadable check_pkt_larger action unless the router configuration + * is incompatible with a common zone (see lrouter_use_common_zone()). */ +static bool hw_offload = false; + /* If this option is 'true' northd will make use of ct.inv match fields. * Otherwise, it will avoid using it. The default is true. */ static bool use_ct_inv_match = true; @@ -13560,10 +13566,38 @@ struct lrouter_nat_lb_flows_ctx { const struct shash *meter_groups; }; +static bool +lr_has_snat(const struct ovn_datapath *od) +{ + for (size_t i = 0; i < od->nbr->n_nat; i++) { + const char *type = od->nbr->nat[i]->type; + /* Both a plain SNAT rule and a dnat_and_snat (floating IP) rule + * perform SNAT, so a load balancer combined with either can require + * reversing an SNAT and a DNAT on the same packet. */ + if (!strcmp(type, "snat") || !strcmp(type, "dnat_and_snat")) { + return true; + } + } + return false; +} + static inline bool lrouter_use_common_zone(const struct ovn_datapath *od) { - return !od->is_gw_router && use_common_zone; + if (od->is_gw_router) { + return false; + } + + if (use_common_zone) { + return true; + } + + /* Hardware offload requires the SNAT and DNAT of a connection to share + * a single conntrack zone, but conntrack cannot reverse both an SNAT and + * a DNAT on the same packet in one zone. A router that performs both + * (a load balancer plus an SNAT rule) must stay on the separate zones, + * so fall back for those routers. */ + return hw_offload && !(od_has_lb_vip(od) && lr_has_snat(od)); } static void @@ -15173,7 +15207,7 @@ build_gateway_mtu_flow(struct lflow_table *lflows, struct ovn_port *op, va_start(extra_actions_args, extra_actions_fmt); ds_clear(actions); - if (gw_mtu > 0) { + if (gw_mtu > 0 && !hw_offload) { int l2_hdr_size = build_gateway_get_l2_hdr_size(op); ds_put_format(actions, REGBIT_PKT_LARGER" = check_pkt_larger(%d); ", gw_mtu + l2_hdr_size); @@ -15183,7 +15217,7 @@ build_gateway_mtu_flow(struct lflow_table *lflows, struct ovn_port *op, ovn_lflow_add(lflows, op->od, stage, prio_low, ds_cstr(match), ds_cstr(actions), lflow_ref, WITH_HINT(hint)); - if (gw_mtu > 0) { + if (gw_mtu > 0 && !hw_offload) { ds_clear(actions); ds_put_format_valist(actions, extra_actions_fmt, extra_actions_args); @@ -22011,6 +22045,7 @@ ovnnb_db_run(struct northd_input *input_data, false); use_common_zone = smap_get_bool(input_data->nb_options, "use_common_zone", false); + hw_offload = input_data->features->hw_offload; vxlan_mode = input_data->vxlan_mode; diff --git a/ovn-nb.xml b/ovn-nb.xml index 8b74ed84e..543ab2849 100644 --- a/ovn-nb.xml +++ b/ovn-nb.xml @@ -393,11 +393,20 @@ <column name="options" key="use_common_zone" type='{"type": "boolean"}'> Default value is <code>false</code>. If set to <code>true</code> - the SNAT and DNAT happens in common zone, instead of happening in + the SNAT and DNAT happens in a common zone, instead of happening in separate zones, depending on the configuration. However, this option breaks traffic when there is configuration of DGP + LB + SNAT on - this LR. The value <code>true</code> should be used only in case - of HWOL compatibility with GDP. + this LR. + + When this option is not set, ovn-northd enables the common zone + automatically for routers that do not combine a load balancer with a + NAT rule that performs SNAT (an <code>snat</code> or + <code>dnat_and_snat</code> rule), if every chassis in the topology has + hardware offload enabled. A chassis advertises hardware offload by + setting <code>hw-offload</code> to <code>true</code> in its + <ref table="Chassis" db="OVN_Southbound" column="other_config"/>. + Routers that perform both SNAT and load-balancer DNAT keep using the + separate zones. </column> <column name="options" key="northd-backoff-interval-ms"> diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index b459b3a7b..a3dd463d0 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -7730,6 +7730,92 @@ OVN_CLEANUP_NORTHD AT_CLEANUP ]) +OVN_FOR_EACH_NORTHD_NO_HV_PARALLELIZATION([ +AT_SETUP([ovn -- hardware offload common zone]) +ovn_start + +check ovn-nbctl ls-add sw0 +check ovn-nbctl lr-add lr0 +check ovn-nbctl lrp-add lr0 lr0-sw0 00:00:00:00:ff:01 10.0.0.1/24 +check ovn-nbctl lsp-add-router-port sw0 sw0-lr0 lr0-sw0 + +check ovn-nbctl ls-add public +check ovn-nbctl lrp-add lr0 lr0-public 00:00:00:00:ff:02 172.168.0.10/24 +check ovn-nbctl lsp-add-router-port public public-lr0 lr0-public + +check ovn-nbctl lr-nat-add lr0 snat 172.168.0.10 10.0.0.0/24 + +# A chassis with hardware offload enabled, but without the ct-state-save +# feature so the flows use the plain 'next;' action. +check ovn-sbctl chassis-add gw1 geneve 127.0.0.1 \ + -- set chassis gw1 other_config:hw-offload="true" + +check ovn-nbctl --wait=sb lrp-set-gateway-chassis lr0-public gw1 + +ovn-sbctl dump-flows lr0 > lr0flows +AT_CAPTURE_FILE([lr0flows]) + +# Hardware offload forces the common SNAT/DNAT zone. +AT_CHECK([grep "lr_in_unsnat" lr0flows | ovn_strip_lflows], [0], [dnl + table=??(lr_in_unsnat ), priority=0 , match=(1), action=(next;) + table=??(lr_in_unsnat ), priority=100 , match=(ip && ip4.dst == 172.168.0.10 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public") && flags.loopback == 0), action=(ct_snat_in_czone;) + table=??(lr_in_unsnat ), priority=100 , match=(ip && ip4.dst == 172.168.0.10 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public") && flags.loopback == 1 && flags.use_snat_zone == 1), action=(ct_snat;) +]) + +# The gateway MTU check_pkt_larger action is not offloadable, so it is +# skipped while every chassis is offloading. +check ovn-nbctl --wait=sb set logical_router_port lr0-public options:gateway_mtu=1500 +ovn-sbctl dump-flows lr0 > lr0flows +AT_CAPTURE_FILE([lr0flows]) + +AT_CHECK([grep -E "lr_in_chk_pkt_len" lr0flows | ovn_strip_lflows], [0], [dnl + table=??(lr_in_chk_pkt_len ), priority=0 , match=(1), action=(next;) + table=??(lr_in_chk_pkt_len ), priority=50 , match=(outport == "lr0-public"), action=(next;) +]) +AT_CHECK([grep -E "check_pkt_larger" lr0flows], [1]) + +# A chassis that is not offloading disables the common zone for the whole +# topology (the feature is ANDed across every chassis). +check ovn-sbctl chassis-add gw2 geneve 127.0.0.2 +check ovn-nbctl --wait=sb sync +ovn-sbctl dump-flows lr0 > lr0flows +AT_CAPTURE_FILE([lr0flows]) + +AT_CHECK([grep "lr_in_unsnat" lr0flows | ovn_strip_lflows], [0], [dnl + table=??(lr_in_unsnat ), priority=0 , match=(1), action=(next;) + table=??(lr_in_unsnat ), priority=100 , match=(ip && ip4.dst == 172.168.0.10 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat;) +]) + +check ovn-sbctl chassis-del gw2 +check ovn-nbctl --wait=sb sync + +# A router that also has a load balancer must stay on the separate zones. +check ovn-nbctl --wait=sb lb-add lb0 172.168.0.100:8082 "10.0.0.50:82" +check ovn-nbctl --wait=sb lr-lb-add lr0 lb0 +ovn-sbctl dump-flows lr0 > lr0flows +AT_CAPTURE_FILE([lr0flows]) + +AT_CHECK([grep "lr_in_unsnat" lr0flows | ovn_strip_lflows], [0], [dnl + table=??(lr_in_unsnat ), priority=0 , match=(1), action=(next;) + table=??(lr_in_unsnat ), priority=100 , match=(ip && ip4.dst == 172.168.0.10 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat;) +]) + +# A floating IP (dnat_and_snat) also performs SNAT, so an LB plus a floating +# IP must stay on the separate zones too. +check ovn-nbctl --wait=sb lr-nat-del lr0 snat +check ovn-nbctl --wait=sb lr-nat-add lr0 dnat_and_snat 172.168.0.20 10.0.0.3 +ovn-sbctl dump-flows lr0 > lr0flows +AT_CAPTURE_FILE([lr0flows]) + +AT_CHECK([grep "lr_in_unsnat" lr0flows | ovn_strip_lflows], [0], [dnl + table=??(lr_in_unsnat ), priority=0 , match=(1), action=(next;) + table=??(lr_in_unsnat ), priority=100 , match=(ip && ip4.dst == 172.168.0.20 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat;) +]) + +OVN_CLEANUP_NORTHD +AT_CLEANUP +]) + OVN_FOR_EACH_NORTHD_NO_HV_PARALLELIZATION([ AT_SETUP([Load Balancer SB duplicates]) ovn_start -- 2.43.0 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
