From: Jaygue Lee <[email protected]> The lr_out_snat priority of a NAT entry without a custom match is prefix_len + 1, shifted up by NAT_PRIORITY_DGP_OFFSET on routers with distributed gateway ports, and some of its flows add up to 5 to that. The flows that consume flags.force_snat_for_dnat, flags.force_snat_for_lb and flags.skip_snat_for_lb use fixed priorities from 100 to 120, shifted the same way on routers with distributed gateway ports. That keeps them above every IPv4 NAT entry, but an IPv6 SNAT entry with a long enough prefix, a /128 for example, outranks them. The load balanced traffic is then SNATed by that entry, and skip_snat and lb_force_snat_ip, including lb_force_snat_ip=router_ip, are ignored.
Derive the priorities of these consumers from MAX_PREFIX_LEN, the same way ROUTE_PRIO_BASE_SHIFT does for routes, so that they sit above every NAT entry without a custom match regardless of its prefix length. Their relative order is unchanged, and a build time assertion checks that they stay below the NAT entries with a custom match, as they already are for IPv4. Update the documentation of the gateway router flows accordingly. The new system test checks, on a gateway router with an SNAT entry for the client's /128, that skip_snat, lb_force_snat_ip=router_ip and an explicit lb_force_snat_ip address are all honored. Reported-by: Dumitru Ceara <[email protected]> Fixes: 719f586e4d38 ("northd: Add lflows for IPv6 NAT.") Fixes: c6e21a23bd8c ("northd: Provide the Gateway router option 'lb_force_snat_ip' to take router port ips.") Fixes: c337d0bbf42a ("northd: introduce per-lb lb_skip_snat option") Assisted-by: Claude Opus 5, Claude Code Signed-off-by: Jaygue Lee <[email protected]> --- Documentation/ref/ovn-logical-flows.7.rst | 14 +- northd/northd.c | 65 ++++-- tests/ovn-northd.at | 231 +++++++++++++++------- tests/system-ovn.at | 143 ++++++++++++++ 4 files changed, 356 insertions(+), 97 deletions(-) diff --git a/Documentation/ref/ovn-logical-flows.7.rst b/Documentation/ref/ovn-logical-flows.7.rst index 15e6e73..c2c2e54 100644 --- a/Documentation/ref/ovn-logical-flows.7.rst +++ b/Documentation/ref/ovn-logical-flows.7.rst @@ -3870,19 +3870,19 @@ based on the configuration in the OVN Northbound database. **Egress Table 3: SNAT on Gateway Routers** - If the Gateway router in the OVN Northbound database has been configured to - force SNAT a packet (that has been previously DNATted) to *B*, a priority-100 + force SNAT a packet (that has been previously DNATted) to *B*, a priority-135 flow matches ``flags.force_snat_for_dnat == 1 && ip`` with an action ``ct_snat(B);``. - If a load balancer configured to skip snat has been applied to the Gateway - router pipeline, a priority-120 flow matches ``flags.skip_snat_for_lb == 1 && + router pipeline, a priority-155 flow matches ``flags.skip_snat_for_lb == 1 && ip`` with an action ``next;``. - If the Gateway router in the OVN Northbound database has been configured to force SNAT a packet (that has been previously load-balanced) using router IP (i.e ``options``:lb_force_snat_ip=router_ip), then for each logical router port *P* attached to the Gateway router, and for each network configured for - this port, a priority-110 flow matches ``flags.force_snat_for_lb == 1`` && + this port, a priority-145 flow matches ``flags.force_snat_for_lb == 1`` && ``ip4`` && ``flags.network_id == N`` && ``outport == P``, where *N* is the network index, with an action ``ct_snat(R);`` where *R* is the IP configured on the router port. A similar flow is created for IPv6, with ``ip6`` instead @@ -3894,7 +3894,7 @@ based on the configuration in the OVN Northbound database. networks configured, the lexicographically first IP will be considered for SNAT for networks 17 and up. -- A priority-105 flow matches the old behavior for if northd is upgraded before +- A priority-140 flow matches the old behavior for if northd is upgraded before controller and ``flags.network_id`` is not recognized. It is only added if there's at least one network configured (excluding LLA for IPv6). It matches on: ``flags.force_snat_for_lb == 1`` && ``ip4`` && ``outport == P``, with @@ -3903,7 +3903,7 @@ based on the configuration in the OVN Northbound database. - If the Gateway router in the OVN Northbound database has been configured to force SNAT a packet (that has been previously load-balanced) to *B*, a - priority-100 flow matches ``flags.force_snat_for_lb == 1 && ip`` with an + priority-135 flow matches ``flags.force_snat_for_lb == 1 && ip`` with an action ``ct_snat(B);``. - For each configuration in the OVN Northbound database, that asks to change the @@ -3911,7 +3911,9 @@ based on the configuration in the OVN Northbound database. source IP address of a packet that belongs to network *A* to *B*, a flow matches ``ip && ip4.src == A && (!ct.trk || !ct.rpl)`` with an action ``ct_snat(B);``. The priority of the flow is calculated based on the mask of - *A*, with matches having larger masks getting higher priorities. If the NAT + *A*, with matches having larger masks getting higher priorities, at most + 134. The flows above that match on the force and skip SNAT flags have higher + priorities, so they take precedence regardless of the mask of *A*. If the NAT rule is of type dnat_and_snat and has ``stateless=true`` in the options, then the action would be ``ip4/6.src=(B)``. diff --git a/northd/northd.c b/northd/northd.c index e4acb11..6136f87 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -14224,6 +14224,36 @@ build_lrouter_allow_vip_traffic_template(struct lflow_table *lflows, * fixed ordering relative to the NAT flows must apply the same offset. */ #define NAT_PRIORITY_DGP_OFFSET 128 +/* Highest lr_out_snat priority of a NAT flow without a custom match, before + * NAT_PRIORITY_DGP_OFFSET is applied: prefix_len + 1, plus at most 5 for the + * dnat_and_snat CT zone flow. */ +#define NAT_PRIORITY_NO_MATCH_MAX (MAX_PREFIX_LEN + 1 + 5) + +/* The flows that consume flags.force_snat_for_dnat, flags.force_snat_for_lb + * and flags.skip_snat_for_lb must take precedence over every NAT flow + * without a custom match, regardless of the prefix length of its + * logical_ip. Otherwise an IPv6 SNAT entry with a long enough prefix is hit + * first and the flag is ignored. */ +#define NAT_PRIORITY_SNAT_FLAGS_BASE (NAT_PRIORITY_NO_MATCH_MAX + 1) + +/* Returns the lr_out_snat priority of a flow that consumes one of the force + * or skip SNAT flags. 'offset' orders these flows among themselves: + * + * 0: force SNAT to a configured address. + * 5: force SNAT to the router port address, compatibility flow. + * 10: force SNAT to the router port address, per network. + * 20: skip SNAT. */ +static uint16_t +lrouter_snat_flags_get_priority(const struct ovn_datapath *od, + uint16_t offset) +{ + uint16_t priority = NAT_PRIORITY_SNAT_FLAGS_BASE + offset; + if (!od->is_gw_router && !vector_is_empty(&od->l3dgw_ports)) { + priority += NAT_PRIORITY_DGP_OFFSET; + } + return priority; +} + static void build_lrouter_flows_for_lb(struct ovn_lb_datapaths *lb_dps, struct lflow_table *lflows, @@ -14276,10 +14306,7 @@ build_lrouter_flows_for_lb(struct ovn_lb_datapaths *lb_dps, DYNAMIC_BITMAP_FOR_EACH_1 (index, &lb_dps->nb_lr_map) { struct ovn_datapath *od = sparse_array_get(&lr_datapaths->dps, index); - uint16_t prio = 120; - if (!od->is_gw_router && !vector_is_empty(&od->l3dgw_ports)) { - prio += NAT_PRIORITY_DGP_OFFSET; - } + uint16_t prio = lrouter_snat_flags_get_priority(od, 20); ovn_lflow_add(lflows, od, S_ROUTER_OUT_SNAT, prio, "flags.skip_snat_for_lb == 1 && ip", "next;", lb_dps->lflow_ref); @@ -14386,6 +14413,11 @@ lrouter_dnat_and_snat_is_stateless(const struct ovn_nat *nat) #define NAT_PRIORITY_MATCH_OFFSET 300 +/* The SNAT flag consumers must stay below the NAT flows with a custom match, + * also on routers with distributed gateway ports. */ +BUILD_ASSERT_DECL(NAT_PRIORITY_SNAT_FLAGS_BASE + 20 + + NAT_PRIORITY_DGP_OFFSET < NAT_PRIORITY_MATCH_OFFSET); + static inline uint16_t lrouter_nat_get_priority(const struct ovn_datapath *od, const struct nbrec_nat *nat, bool is_dnat, @@ -14784,24 +14816,17 @@ build_lrouter_force_snat_flows(struct lflow_table *lflows, ds_clear(&match); ds_put_format(&match, "flags.force_snat_for_%s == 1 && ip%s", context, ip_version); - uint16_t snat_prio = 100; if (l3dgw_port) { /* Distributed router: force SNAT is applied on the chassis * where the gateway port is resident, consistent with how - * regular SNAT entries are handled for such routers. - * - * The NAT flows of such a router are shifted up by - * NAT_PRIORITY_DGP_OFFSET, so shift this flow as well to keep the - * same ordering it has on a gateway router. Without the shift - * even a plain subnet SNAT entry would outrank it and the forced - * SNAT would never be applied. */ + * regular SNAT entries are handled for such routers. */ ds_put_format(&match, " && outport == %s && is_chassis_resident(" "\"%s\")", l3dgw_port->json_key, l3dgw_port->cr_port->key); - snat_prio += NAT_PRIORITY_DGP_OFFSET; } ds_put_format(&actions, "ct_snat(%s);", ip_addr); - ovn_lflow_add(lflows, od, S_ROUTER_OUT_SNAT, snat_prio, + ovn_lflow_add(lflows, od, S_ROUTER_OUT_SNAT, + lrouter_snat_flags_get_priority(od, 0), ds_cstr(&match), ds_cstr(&actions), lflow_ref); @@ -14940,7 +14965,8 @@ build_lrouter_force_snat_flows_op(struct ovn_port *op, "outport == %s", network_id, op->json_key); ds_put_format(actions, "ct_snat(%s);", op->lrp_networks.ipv4_addrs[network_id].addr_s); - ovn_lflow_add(lflows, op->od, S_ROUTER_OUT_SNAT, 110, + ovn_lflow_add(lflows, op->od, S_ROUTER_OUT_SNAT, + lrouter_snat_flags_get_priority(op->od, 10), ds_cstr(match), ds_cstr(actions), lflow_ref); } @@ -14980,7 +15006,8 @@ build_lrouter_force_snat_flows_op(struct ovn_port *op, "outport == %s", network_id, op->json_key); ds_put_format(actions, "ct_snat(%s);", op->lrp_networks.ipv6_addrs[network_id].addr_s); - ovn_lflow_add(lflows, op->od, S_ROUTER_OUT_SNAT, 110, + ovn_lflow_add(lflows, op->od, S_ROUTER_OUT_SNAT, + lrouter_snat_flags_get_priority(op->od, 10), ds_cstr(match), ds_cstr(actions), lflow_ref); } @@ -14994,7 +15021,8 @@ build_lrouter_force_snat_flows_op(struct ovn_port *op, "outport == %s", op->json_key); ds_put_format(actions, "ct_snat(%s);", op->lrp_networks.ipv4_addrs[0].addr_s); - ovn_lflow_add(lflows, op->od, S_ROUTER_OUT_SNAT, 105, + ovn_lflow_add(lflows, op->od, S_ROUTER_OUT_SNAT, + lrouter_snat_flags_get_priority(op->od, 5), ds_cstr(match), ds_cstr(actions), lflow_ref); } @@ -15007,7 +15035,8 @@ build_lrouter_force_snat_flows_op(struct ovn_port *op, "outport == %s", op->json_key); ds_put_format(actions, "ct_snat(%s);", op->lrp_networks.ipv6_addrs[0].addr_s); - ovn_lflow_add(lflows, op->od, S_ROUTER_OUT_SNAT, 105, + ovn_lflow_add(lflows, op->od, S_ROUTER_OUT_SNAT, + lrouter_snat_flags_get_priority(op->od, 5), ds_cstr(match), ds_cstr(actions), lflow_ref); } } diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index f1e88b4..3645fd8 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -5204,9 +5204,9 @@ AT_CHECK([grep "lr_in_dnat" lr0flows | ovn_strip_lflows], [0], [dnl AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl table=??(lr_out_snat ), priority=0 , match=(1), action=(next;) - table=??(lr_out_snat ), priority=100 , match=(flags.force_snat_for_lb == 1 && ip4), action=(ct_snat(20.0.0.4);) - table=??(lr_out_snat ), priority=100 , match=(flags.force_snat_for_lb == 1 && ip6), action=(ct_snat(aef0::4);) table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) + table=??(lr_out_snat ), priority=135 , match=(flags.force_snat_for_lb == 1 && ip4), action=(ct_snat(20.0.0.4);) + table=??(lr_out_snat ), priority=135 , match=(flags.force_snat_for_lb == 1 && ip6), action=(ct_snat(aef0::4);) ]) AT_CHECK([grep "lr_out_undnat" lr0flows | ovn_strip_lflows], [0], [dnl @@ -5255,13 +5255,13 @@ AT_CHECK([grep "lr_in_dnat" lr0flows | ovn_strip_lflows], [0], [dnl AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl table=??(lr_out_snat ), priority=0 , match=(1), action=(next;) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw1"), action=(ct_snat(20.0.0.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw1"), action=(ct_snat(20.0.0.1);) table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw1"), action=(ct_snat(20.0.0.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw1"), action=(ct_snat(20.0.0.1);) ]) AT_CHECK([grep "lr_out_undnat" lr0flows | ovn_strip_lflows], [0], [dnl @@ -5323,15 +5323,15 @@ AT_CHECK([grep "lr_in_dnat" lr0flows | ovn_strip_lflows], [0], [dnl AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl table=??(lr_out_snat ), priority=0 , match=(1), action=(next;) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw1"), action=(ct_snat(20.0.0.1);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-sw1"), action=(ct_snat(bef0::1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw1"), action=(ct_snat(20.0.0.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lr0-sw1"), action=(ct_snat(bef0::1);) table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw1"), action=(ct_snat(20.0.0.1);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-sw1"), action=(ct_snat(bef0::1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw1"), action=(ct_snat(20.0.0.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lr0-sw1"), action=(ct_snat(bef0::1);) ]) AT_CHECK([grep "lr_out_undnat" lr0flows | ovn_strip_lflows], [0], [dnl @@ -5372,7 +5372,7 @@ AT_CHECK([grep "lr_in_dnat" lr0flows | grep skip_snat_for_lb | ovn_strip_lflows] ]) AT_CHECK([grep "lr_out_snat" lr0flows | grep skip_snat_for_lb | ovn_strip_lflows], [0], [dnl - table=??(lr_out_snat ), priority=120 , match=(flags.skip_snat_for_lb == 1 && ip), action=(next;) + table=??(lr_out_snat ), priority=155 , match=(flags.skip_snat_for_lb == 1 && ip), action=(next;) ]) AT_CHECK([grep "lr_out_undnat" lr0flows | ovn_strip_lflows], [0], [dnl @@ -5444,8 +5444,8 @@ AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) table=??(lr_out_snat ), priority=153 , match=(ip && ip4.dst == 10.0.0.0/24 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public") && (!ct.trk || !ct.rpl)), action=(ct_snat;) table=??(lr_out_snat ), priority=153 , match=(ip && ip4.src == 10.0.0.0/24 && outport == "lr0-public" && is_chassis_resident("cr-lr0-public") && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.100);) - table=??(lr_out_snat ), priority=228 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat(172.168.0.4);) - table=??(lr_out_snat ), priority=228 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat(aef0::4);) + table=??(lr_out_snat ), priority=263 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat(172.168.0.4);) + table=??(lr_out_snat ), priority=263 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat(aef0::4);) ]) # The producer and the consumer must both be present: the load balancer @@ -5475,7 +5475,7 @@ AT_CHECK([grep "lr_out_undnat" lr0flows | ovn_strip_lflows], [0], [dnl ]) AT_CHECK([grep "lr_out_snat" lr0flows | grep skip_snat | ovn_strip_lflows], [0], [dnl - table=??(lr_out_snat ), priority=248 , match=(flags.skip_snat_for_lb == 1 && ip), action=(next;) + table=??(lr_out_snat ), priority=283 , match=(flags.skip_snat_for_lb == 1 && ip), action=(next;) ]) check ovn-nbctl --wait=sb remove load_balancer lb1 options skip_snat @@ -5493,6 +5493,91 @@ OVN_CLEANUP_NORTHD AT_CLEANUP ]) +OVN_FOR_EACH_NORTHD_NO_HV([ +AT_SETUP([Load Balancers and SNAT flags with an IPv6 /128 SNAT entry]) +ovn_start + +# The lr_out_snat priority of a NAT entry without a custom match is +# prefix_len + 1, so an IPv6 /128 entry gets 129 on a gateway router and 257 +# on a router with a distributed gateway port. The flows that consume the +# force and skip SNAT flags must still be hit first. + +# Gateway router. +check ovn-nbctl ls-add sw0 +check ovn-nbctl ls-add public0 +check ovn-nbctl lr-add lr0 -- set logical_router lr0 options:chassis=ch1 +check ovn-nbctl lrp-add lr0 lr0-sw0 00:00:00:00:ff:01 10.0.0.1/24 aef0::1/64 +check ovn-nbctl lsp-add-router-port sw0 sw0-lr0 lr0-sw0 +check ovn-nbctl lrp-add lr0 lr0-public 00:00:20:20:12:13 172.168.0.100/24 def0::10/64 +check ovn-nbctl lsp-add-router-port public0 public0-lr0 lr0-public +check ovn-nbctl lb-add lb0 aef0::100 aef0::2 +check ovn-nbctl lr-lb-add lr0 lb0 +check ovn-nbctl lr-nat-add lr0 snat def0::100 aef0::2 + +# Router with a distributed gateway port. +check ovn-nbctl ls-add sw1 +check ovn-nbctl ls-add public1 +check ovn-nbctl lr-add lr1 +check ovn-nbctl lrp-add lr1 lr1-sw1 00:00:00:00:ff:02 10.0.1.1/24 aef1::1/64 +check ovn-nbctl lsp-add-router-port sw1 sw1-lr1 lr1-sw1 +check ovn-nbctl lrp-add lr1 lr1-public 00:00:20:20:12:14 172.168.1.100/24 def1::10/64 +check ovn-nbctl lsp-add-router-port public1 public1-lr1 lr1-public +check ovn-nbctl lrp-set-gateway-chassis lr1-public ch1 +check ovn-nbctl lb-add lb1 aef1::100 aef1::2 +check ovn-nbctl lr-lb-add lr1 lb1 +check ovn-nbctl lr-nat-add lr1 snat def1::100 aef1::2 + +check ovn-nbctl set logical_router lr0 options:lb_force_snat_ip=def0::4 \ + options:dnat_force_snat_ip=def0::5 +check ovn-nbctl set logical_router lr1 options:lb_force_snat_ip=def1::4 +check ovn-nbctl set load_balancer lb0 options:skip_snat=true +check ovn-nbctl set load_balancer lb1 options:skip_snat=true +check ovn-nbctl --wait=sb sync + +ovn-sbctl dump-flows lr0 > lr0flows +AT_CAPTURE_FILE([lr0flows]) +ovn-sbctl dump-flows lr1 > lr1flows +AT_CAPTURE_FILE([lr1flows]) + +AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl + table=??(lr_out_snat ), priority=0 , match=(1), action=(next;) + table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) + table=??(lr_out_snat ), priority=129 , match=(ip && ip6.src == aef0::2 && (!ct.trk || !ct.rpl)), action=(ct_snat(def0::100);) + table=??(lr_out_snat ), priority=135 , match=(flags.force_snat_for_dnat == 1 && ip6), action=(ct_snat(def0::5);) + table=??(lr_out_snat ), priority=135 , match=(flags.force_snat_for_lb == 1 && ip6), action=(ct_snat(def0::4);) + table=??(lr_out_snat ), priority=155 , match=(flags.skip_snat_for_lb == 1 && ip), action=(next;) +]) + +AT_CHECK([grep "lr_out_snat" lr1flows | ovn_strip_lflows], [0], [dnl + table=??(lr_out_snat ), priority=0 , match=(1), action=(next;) + table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) + table=??(lr_out_snat ), priority=257 , match=(ip && ip6.dst == aef1::2 && inport == "lr1-public" && is_chassis_resident("cr-lr1-public") && (!ct.trk || !ct.rpl)), action=(ct_snat;) + table=??(lr_out_snat ), priority=257 , match=(ip && ip6.src == aef1::2 && outport == "lr1-public" && is_chassis_resident("cr-lr1-public") && (!ct.trk || !ct.rpl)), action=(ct_snat(def1::100);) + table=??(lr_out_snat ), priority=263 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr1-public" && is_chassis_resident("cr-lr1-public")), action=(ct_snat(def1::4);) + table=??(lr_out_snat ), priority=283 , match=(flags.skip_snat_for_lb == 1 && ip), action=(next;) +]) + +# lb_force_snat_ip=router_ip is only supported on gateway routers. +check ovn-nbctl --wait=sb set logical_router lr0 options:lb_force_snat_ip=router_ip + +ovn-sbctl dump-flows lr0 > lr0flows +AT_CAPTURE_FILE([lr0flows]) + +AT_CHECK([grep "lr_out_snat" lr0flows | grep force_snat_for_lb | ovn_strip_lflows], [0], [dnl + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-public"), action=(ct_snat(def0::10);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-sw0"), action=(ct_snat(aef0::1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.100);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lr0-public"), action=(ct_snat(def0::10);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lr0-sw0"), action=(ct_snat(aef0::1);) +]) + +OVN_CLEANUP_NORTHD +AT_CLEANUP +]) + OVN_FOR_EACH_NORTHD_NO_HV([ AT_SETUP([HA chassis group cleanup for external port ]) ovn_start @@ -7342,11 +7427,11 @@ AT_CHECK([grep "lr_out_post_undnat" lr0flows | ovn_strip_lflows], [0], [dnl AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl table=??(lr_out_snat ), priority=0 , match=(1), action=(next;) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) table=??(lr_out_snat ), priority=25 , match=(ip && ip4.src == 10.0.0.0/24 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.10);) table=??(lr_out_snat ), priority=33 , match=(ip && ip4.src == 10.0.0.10 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.30);) table=??(lr_out_snat ), priority=33 , match=(ip && ip4.src == 10.0.0.3 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.20);) @@ -7411,11 +7496,11 @@ AT_CHECK([grep "lr_out_post_undnat" lr0flows | ovn_strip_lflows], [0], [dnl AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl table=??(lr_out_snat ), priority=0 , match=(1), action=(next;) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) table=??(lr_out_snat ), priority=25 , match=(ip && ip4.src == 10.0.0.0/24 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.10);) table=??(lr_out_snat ), priority=33 , match=(ip && ip4.src == 10.0.0.10 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.30);) table=??(lr_out_snat ), priority=33 , match=(ip && ip4.src == 10.0.0.3 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.20);) @@ -7492,15 +7577,15 @@ AT_CHECK([grep "lr_out_post_undnat" lr0flows | ovn_strip_lflows], [0], [dnl AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl table=??(lr_out_snat ), priority=0 , match=(1), action=(next;) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-public"), action=(ct_snat(def0::10);) - table=??(lr_out_snat ), priority=105 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-sw0"), action=(ct_snat(aef0::1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lr0-public"), action=(ct_snat(def0::10);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lr0-sw0"), action=(ct_snat(aef0::1);) table=??(lr_out_snat ), priority=120 , match=(nd_ns), action=(next;) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-public"), action=(ct_snat(def0::10);) + table=??(lr_out_snat ), priority=140 , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-sw0"), action=(ct_snat(aef0::1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-public"), action=(ct_snat(172.168.0.10);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lr0-sw0"), action=(ct_snat(10.0.0.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lr0-public"), action=(ct_snat(def0::10);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lr0-sw0"), action=(ct_snat(aef0::1);) table=??(lr_out_snat ), priority=25 , match=(ip && ip4.src == 10.0.0.0/24 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.10);) table=??(lr_out_snat ), priority=33 , match=(ip && ip4.src == 10.0.0.10 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.30);) table=??(lr_out_snat ), priority=33 , match=(ip && ip4.src == 10.0.0.3 && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.20);) @@ -17390,7 +17475,7 @@ check_snat_flows() { AT_CAPTURE_FILE([snatflows]) for family in 4 6; do AT_CHECK([grep lr_in_unsnat snatflows | grep "inport == \"$2\"" | grep -q "ip$family.dst"], [$3]) - for priority in 105 110; do + for priority in 140 145; do AT_CHECK([grep lr_out_snat snatflows | grep "priority=$priority " | grep "outport == \"$2\"" | grep -q "&& ip$family"], [$3]) done done @@ -21050,40 +21135,40 @@ AT_CHECK([grep -E flags.network_id lrflows | ovn_strip_lflows], [0], [dnl table=??(lr_in_network_id ), priority=110 , match=(outport == "lrp-server" && ip6 && xxreg0 == ff01::d/128), action=(flags.network_id = 11; next;) table=??(lr_in_network_id ), priority=110 , match=(outport == "lrp-server" && ip6 && xxreg0 == ff01::e/128), action=(flags.network_id = 12; next;) table=??(lr_in_network_id ), priority=110 , match=(outport == "lrp-server" && ip6 && xxreg0 == ff01::f/128), action=(flags.network_id = 13; next;) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lrp-client"), action=(ct_snat(1.1.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lrp-server"), action=(ct_snat(1.1.2.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lrp-client"), action=(ct_snat(ff01::1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::2);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 1 && ip4 && outport == "lrp-server"), action=(ct_snat(1.2.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 1 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::3);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 10 && ip4 && outport == "lrp-server"), action=(ct_snat(6.6.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 10 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::c);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 11 && ip4 && outport == "lrp-server"), action=(ct_snat(6.6.6.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 11 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::d);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 12 && ip4 && outport == "lrp-server"), action=(ct_snat(6.7.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 12 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::e);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 13 && ip4 && outport == "lrp-server"), action=(ct_snat(6.8.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 13 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::f);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 14 && ip4 && outport == "lrp-server"), action=(ct_snat(6.9.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 14 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::a1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 15 && ip4 && outport == "lrp-server"), action=(ct_snat(7.2.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 15 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::a2);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 2 && ip4 && outport == "lrp-server"), action=(ct_snat(1.2.2.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 2 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::4);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 3 && ip4 && outport == "lrp-server"), action=(ct_snat(3.3.3.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 3 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::5);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 4 && ip4 && outport == "lrp-server"), action=(ct_snat(4.4.4.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 4 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::6);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 5 && ip4 && outport == "lrp-server"), action=(ct_snat(5.5.5.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 5 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::7);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 6 && ip4 && outport == "lrp-server"), action=(ct_snat(6.2.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 6 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::8);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 7 && ip4 && outport == "lrp-server"), action=(ct_snat(6.3.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 7 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::9);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 8 && ip4 && outport == "lrp-server"), action=(ct_snat(6.4.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 8 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::a);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 9 && ip4 && outport == "lrp-server"), action=(ct_snat(6.5.1.1);) - table=??(lr_out_snat ), priority=110 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 9 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::b);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lrp-client"), action=(ct_snat(1.1.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip4 && outport == "lrp-server"), action=(ct_snat(1.1.2.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lrp-client"), action=(ct_snat(ff01::1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 0 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::2);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 1 && ip4 && outport == "lrp-server"), action=(ct_snat(1.2.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 1 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::3);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 10 && ip4 && outport == "lrp-server"), action=(ct_snat(6.6.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 10 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::c);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 11 && ip4 && outport == "lrp-server"), action=(ct_snat(6.6.6.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 11 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::d);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 12 && ip4 && outport == "lrp-server"), action=(ct_snat(6.7.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 12 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::e);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 13 && ip4 && outport == "lrp-server"), action=(ct_snat(6.8.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 13 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::f);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 14 && ip4 && outport == "lrp-server"), action=(ct_snat(6.9.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 14 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::a1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 15 && ip4 && outport == "lrp-server"), action=(ct_snat(7.2.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 15 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::a2);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 2 && ip4 && outport == "lrp-server"), action=(ct_snat(1.2.2.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 2 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::4);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 3 && ip4 && outport == "lrp-server"), action=(ct_snat(3.3.3.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 3 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::5);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 4 && ip4 && outport == "lrp-server"), action=(ct_snat(4.4.4.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 4 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::6);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 5 && ip4 && outport == "lrp-server"), action=(ct_snat(5.5.5.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 5 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::7);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 6 && ip4 && outport == "lrp-server"), action=(ct_snat(6.2.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 6 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::8);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 7 && ip4 && outport == "lrp-server"), action=(ct_snat(6.3.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 7 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::9);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 8 && ip4 && outport == "lrp-server"), action=(ct_snat(6.4.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 8 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::a);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 9 && ip4 && outport == "lrp-server"), action=(ct_snat(6.5.1.1);) + table=??(lr_out_snat ), priority=145 , match=(flags.force_snat_for_lb == 1 && flags.network_id == 9 && ip6 && outport == "lrp-server"), action=(ct_snat(ff01::b);) ]) OVN_CLEANUP_NORTHD AT_CLEANUP @@ -21103,13 +21188,13 @@ check ovn-nbctl --wait=sb sync ovn-sbctl dump-flows lr0 > lrflows AT_CAPTURE_FILE([lrflows]) -AT_CHECK([! ovn_strip_lflows < lrflows | grep priority=105 | grep -q "flags.force_snat_for_lb == 1"], [0], [], [ignore]) +AT_CHECK([! ovn_strip_lflows < lrflows | grep priority=140 | grep -q "flags.force_snat_for_lb == 1"], [0], [], [ignore]) check ovn-nbctl lrp-del lrp0 -- lrp-add lr0 lrp0 02:00:00:00:00:01 4242::4242/64 check ovn-nbctl --wait=sb sync ovn-sbctl dump-flows lr0 > lrflows AT_CAPTURE_FILE([lrflows]) -AT_CHECK([ovn_strip_lflows < lrflows | grep priority=105 | grep -c "flags.force_snat_for_lb == 1"], [0], [dnl +AT_CHECK([ovn_strip_lflows < lrflows | grep priority=140 | grep -c "flags.force_snat_for_lb == 1"], [0], [dnl 1 ]) diff --git a/tests/system-ovn.at b/tests/system-ovn.at index 28914a9..f4d21d4 100644 --- a/tests/system-ovn.at +++ b/tests/system-ovn.at @@ -2908,6 +2908,149 @@ OVS_TRAFFIC_VSWITCHD_STOP(["/failed to query port patch-.*/d AT_CLEANUP ]) +OVN_FOR_EACH_NORTHD([ +AT_SETUP([load balancing with SNAT flags and an IPv6 /128 SNAT entry]) +AT_KEYWORDS([ovnlb]) + +CHECK_CONNTRACK() +CHECK_CONNTRACK_NAT() +ovn_start +OVS_TRAFFIC_VSWITCHD_START() +ADD_BR([br-int]) + +# Set external-ids in br-int needed for ovn-controller. +check ovs-vsctl \ + -- set Open_vSwitch . external-ids:system-id=hv1 \ + -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \ + -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \ + -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \ + -- set bridge br-int fail-mode=secure other-config:disable-in-band=true + +# Start ovn-controller. +start_daemon ovn-controller + +# Logical network: +# +# foo -- R1 -- join -- R2 -- alice +# +# R2 is a gateway router with a load balancer whose backend sits on "alice". +# It also has an SNAT entry for the client's /128. The lr_out_snat priority +# of that entry is 129, so it competes with the flows that consume the skip +# and force SNAT flags for the load balanced traffic. + +check_uuid ovn-nbctl create Logical_Router name=R1 +check_uuid ovn-nbctl create Logical_Router name=R2 options:chassis=hv1 + +check ovn-nbctl ls-add foo +check ovn-nbctl ls-add alice +check ovn-nbctl ls-add join + +# Connect foo to R1. +check ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 fd11::1/64 +check ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo \ + type=router options:router-port=foo addresses=\"00:00:01:01:02:03\" + +# Connect alice to R2. +check ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 fd72::1/64 +check ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \ + type=router options:router-port=alice addresses=\"00:00:02:01:02:03\" + +# Connect R1 to join. +check ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 fd20::1/64 +check ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \ + type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"' + +# Connect R2 to join. +check ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 fd20::2/64 +check ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \ + type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"' + +# Static routes. +check ovn-nbctl lr-route-add R1 fd30::/64 fd20::2 +check ovn-nbctl lr-route-add R1 fd72::/64 fd20::2 +check ovn-nbctl lr-route-add R2 fd11::/64 fd20::1 + +# Logical port 'foo1' in switch 'foo'. This is the client. +ADD_NAMESPACES(foo1) +ADD_VETH(foo1, foo1, br-int, "fd11::2/64", "f0:00:00:01:02:03", \ + "fd11::1") +check ovn-nbctl lsp-add foo foo1 \ +-- lsp-set-addresses foo1 "f0:00:00:01:02:03 fd11::2" + +# Logical port 'alice1' in switch 'alice'. This is the backend. +ADD_NAMESPACES(alice1) +ADD_VETH(alice1, alice1, br-int, "fd72::2/64", "f0:00:00:01:02:04", \ + "fd72::1") +check ovn-nbctl lsp-add alice alice1 \ +-- lsp-set-addresses alice1 "f0:00:00:01:02:04 fd72::2" + +uuid=`ovn-nbctl create load_balancer vips:'"[[fd30::1]]:8000"'='"@<:@fd72::2@:>@:80"'` +check ovn-nbctl set logical_router R2 load_balancer=$uuid + +check ovn-nbctl lr-nat-add R2 snat fd30::99 fd11::2 + +check ovn-nbctl set load_balancer $uuid options:skip_snat=true +check ovn-nbctl --wait=hv sync +OVS_WAIT_UNTIL([ovs-ofctl -O OpenFlow13 dump-groups br-int | \ +grep 'nat(dst=\[[fd72::2\]]:80)']) + +# Start a webserver on the backend. +OVS_START_L7([alice1], [http6]) + +dnl With skip_snat the load balanced traffic must not be SNATed, in +dnl particular not by the /128 SNAT entry. +check ovs-appctl dpctl/flush-conntrack +NS_CHECK_EXEC([foo1], [wget http://[[fd30::1]]:8000 -t 5 -T 1 --retry-connrefused -v -o wget-skip.log]) + +AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(fd30::1) | grep -v fe80 | \ + sed -e 's/zone=[[0-9]]*/zone=<cleared>/' -e 's/mark=[[0-9]]*/mark=<cleared>/'], [0], [dnl +tcp,orig=(src=fd11::2,dst=fd30::1,sport=<cleared>,dport=<cleared>),reply=(src=fd72::2,dst=fd11::2,sport=<cleared>,dport=<cleared>),zone=<cleared>,mark=<cleared>,protoinfo=(state=<cleared>) +]) + +AT_CHECK([ovs-appctl dpctl/dump-conntrack | grep -c "fd30::99"], [1], [0 +]) + +dnl With lb_force_snat_ip=router_ip the load balanced traffic must be SNATed +dnl to the IP of the router port it leaves through, not by the /128 entry. +check ovn-nbctl remove load_balancer $uuid options skip_snat +check ovn-nbctl --wait=hv set logical_router R2 options:lb_force_snat_ip=router_ip + +check ovs-appctl dpctl/flush-conntrack +NS_CHECK_EXEC([foo1], [wget http://[[fd30::1]]:8000 -t 5 -T 1 --retry-connrefused -v -o wget-router-ip.log]) + +AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(fd72::1) | grep -v fe80 | \ + sed -e 's/zone=[[0-9]]*/zone=<cleared>/'], [0], [dnl +tcp,orig=(src=fd11::2,dst=fd72::2,sport=<cleared>,dport=<cleared>),reply=(src=fd72::2,dst=fd72::1,sport=<cleared>,dport=<cleared>),zone=<cleared>,protoinfo=(state=<cleared>) +]) + +AT_CHECK([ovs-appctl dpctl/dump-conntrack | grep -c "fd30::99"], [1], [0 +]) + +dnl Same with an explicit lb_force_snat_ip address. +check ovn-nbctl --wait=hv set logical_router R2 options:lb_force_snat_ip=fd30::98 + +check ovs-appctl dpctl/flush-conntrack +NS_CHECK_EXEC([foo1], [wget http://[[fd30::1]]:8000 -t 5 -T 1 --retry-connrefused -v -o wget-force-ip.log]) + +AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(fd30::98) | grep -v fe80 | \ + sed -e 's/zone=[[0-9]]*/zone=<cleared>/'], [0], [dnl +tcp,orig=(src=fd11::2,dst=fd72::2,sport=<cleared>,dport=<cleared>),reply=(src=fd72::2,dst=fd30::98,sport=<cleared>,dport=<cleared>),zone=<cleared>,protoinfo=(state=<cleared>) +]) + +AT_CHECK([ovs-appctl dpctl/dump-conntrack | grep -c "fd30::99"], [1], [0 +]) + +OVN_CLEANUP_CONTROLLER([hv1]) + +OVN_CLEANUP_NORTHD + +as +OVS_TRAFFIC_VSWITCHD_STOP(["/failed to query port patch-.*/d +/Failed to acquire.*/d +/connection dropped.*/d"]) +AT_CLEANUP +]) + OVN_FOR_EACH_NORTHD([ AT_SETUP([load balancing in gateway router - IPv6]) AT_KEYWORDS([ovnlb]) -- 2.43.0 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
