From: Loke Berne <[email protected]> A logical switch with DNS records gets a datapath-wide flow in the ls_in_dns_lookup stage matching "udp.dst == 53" and applying the dns_lookup() action. Any UDP packet to port 53 entering the logical switch, including unsolicited ones coming from the outside through a router port (e.g. from the internet to a NAT'ed address), is thus handed to ovn-controller, where it is parsed, before any ACL is evaluated. An ACL can't stop this traffic, and a flood of such packets can saturate ovn-controller and ovs-vswitchd on the chassis hosting the targeted logical port.
Add a priority 200 logical flow for each router port of a logical switch with DNS records, matching on "inport" and advancing the packet to the next stage without any lookup. The priority 100 lookup flow is unchanged, so the packets entering through any other port are handled as before, and the number of added logical flows only depends on the number of router ports of the logical switch, not on its number of ports. Signed-off-by: Loke Berne <[email protected]> --- Documentation/ref/ovn-logical-flows.7.rst | 7 +++ northd/northd.c | 26 +++++++- tests/ovn-northd.at | 77 +++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/Documentation/ref/ovn-logical-flows.7.rst b/Documentation/ref/ovn-logical-flows.7.rst index 913ebbc83..4692c17cc 100644 --- a/Documentation/ref/ovn-logical-flows.7.rst +++ b/Documentation/ref/ovn-logical-flows.7.rst @@ -1390,6 +1390,13 @@ Ingress Table 30 DNS Lookup This table looks up and resolves the DNS names to the corresponding configured IP address(es). +- For each logical switch port ``P`` of type ``router`` of a logical switch + that is configured with DNS records, a priority-200 logical flow which + matches packets with ``inport`` == ``P`` and advances them to the next table + without any DNS lookup. Packets coming from the routed side of the logical + switch, e.g. from the internet, are thus never handed to ``ovn-controller`` + and are subject to the ACLs like any other UDP traffic. + - A priority-100 logical flow for each logical switch datapath if it is configured with DNS records, which matches the IPv4 and IPv6 packets with ``udp.dst`` = 53 and applies the action ``dns_lookup`` and advances the packet diff --git a/northd/northd.c b/northd/northd.c index 7585767c9..a858a313c 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -11568,7 +11568,11 @@ build_lswitch_dhcp_and_dns_defaults(struct ovn_datapath *od, /* Logical switch ingress table 22 and 23: DNS lookup and response * priority 100 flows. -*/ +* +* Packets entering the logical switch through a router port come from +* outside of the switch (e.g. from the internet through a NAT'ed address) and +* must not be handed to ovn-controller: see +* build_lswitch_dns_lookup_skip_router_port(). */ static void build_lswitch_dns_lookup_and_response(struct ovn_datapath *od, struct lflow_table *lflows, @@ -11598,6 +11602,25 @@ build_lswitch_dns_lookup_and_response(struct ovn_datapath *od, dns_match, dns_action, lflow_ref); } +/* Table 22: DNS lookup, priority 200 flow that skips the lookup for the + * packets entering the logical switch through a router port, so that + * unsolicited DNS traffic coming from the routed side never reaches + * ovn-controller, and is subject to the ACLs like any other UDP traffic. */ +static void +build_lswitch_dns_lookup_skip_router_port(struct ovn_port *op, + struct lflow_table *lflows, + struct ds *match) +{ + ovs_assert(op->nbsp); + if (!lsp_is_router(op->nbsp) || !ls_has_dns_records(op->od->nbs)) { + return; + } + ds_clear(match); + ds_put_format(match, "inport == %s", op->json_key); + ovn_lflow_add(lflows, op->od, S_SWITCH_IN_DNS_LOOKUP, 200, + ds_cstr(match), "next;", op->lflow_ref); +} + /* Table 24: External port. Drop ARP request for router ips from * external ports on chassis not binding those ports. * This makes the router pipeline to be run only on the chassis @@ -20772,6 +20795,7 @@ build_lswitch_and_lrouter_iterate_by_lsp(struct ovn_port *op, build_lswitch_arp_nd_responder_known_ips(op, lflows, ls_ports, meter_groups, actions, match); build_lswitch_dhcp_options_and_response(op, lflows, meter_groups); + build_lswitch_dns_lookup_skip_router_port(op, lflows, match); build_lswitch_external_port(op, lflows); build_lswitch_icmp_packet_toobig_admin_flows(op, lflows, match, actions); build_lswitch_ip_unicast_lookup(op, lflows, actions, diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index e2b8424d2..de5241841 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -13101,6 +13101,83 @@ check ovn-nbctl clear Logical_Switch sw0 dns_records check ovn-nbctl --wait=sb sync wait_row_count sb:DNS 0 +OVN_CLEANUP_NORTHD +AT_CLEANUP +]) + +OVN_FOR_EACH_NORTHD_NO_HV([ +AT_SETUP([DNS lookup skipped for packets entering through router ports]) +ovn_start + +check ovn-nbctl lr-add lr0 +check ovn-nbctl lrp-add lr0 lrp0 00:00:00:00:00:01 10.0.0.1/24 +check ovn-nbctl lrp-add lr0 lrp1 00:00:00:00:00:02 10.0.0.2/24 + +check ovn-nbctl ls-add sw0 +check ovn-nbctl lsp-add sw0 sw0-vm1 +check ovn-nbctl lsp-set-addresses sw0-vm1 "00:00:00:00:00:11 10.0.0.11" +check ovn-nbctl lsp-add sw0 sw0-lr0 +check ovn-nbctl lsp-set-type sw0-lr0 router +check ovn-nbctl lsp-set-addresses sw0-lr0 router +check ovn-nbctl lsp-set-options sw0-lr0 router-port=lrp0 + +dns_uuid=$(ovn-nbctl create DNS records={}) +check ovn-nbctl set DNS $dns_uuid records:vm1.ovn.org="10.0.0.11" + +dns_lookup_flows() { + ovn-sbctl dump-flows sw0 | grep -w "ls_in_dns_lookup" | ovn_strip_lflows | sort +} + +# Without DNS records, there is no lookup flow. +check ovn-nbctl --wait=sb sync +AT_CHECK([dns_lookup_flows], [0], [dnl + table=??(ls_in_dns_lookup ), priority=0 , match=(1), action=(next;) +]) + +# With DNS records, packets entering through the router port skip the lookup, +# all the others are looked up, whatever the number of ports. +check ovn-nbctl set Logical_Switch sw0 dns_records="$dns_uuid" +check ovn-nbctl --wait=sb sync +AT_CHECK([dns_lookup_flows], [0], [dnl + table=??(ls_in_dns_lookup ), priority=0 , match=(1), action=(next;) + table=??(ls_in_dns_lookup ), priority=100 , match=(udp.dst == 53), action=(reg0[[4]] = dns_lookup(); next;) + table=??(ls_in_dns_lookup ), priority=200 , match=(inport == "sw0-lr0"), action=(next;) +]) + +# Adding VIF ports does not add lookup flows. +for i in 2 3 4; do + check ovn-nbctl lsp-add sw0 sw0-vm$i + check ovn-nbctl lsp-set-addresses sw0-vm$i "00:00:00:00:00:1$i 10.0.0.1$i" +done +check ovn-nbctl --wait=sb sync +AT_CHECK([dns_lookup_flows | wc -l], [0], [3 +]) + +# A second router port gets its own skip flow, and loses it when removed. +check ovn-nbctl lsp-add sw0 sw0-lr1 +check ovn-nbctl lsp-set-type sw0-lr1 router +check ovn-nbctl lsp-set-addresses sw0-lr1 router +check ovn-nbctl lsp-set-options sw0-lr1 router-port=lrp1 +check ovn-nbctl --wait=sb sync +AT_CHECK([dns_lookup_flows | grep -c 'priority=200'], [0], [2 +]) +check ovn-nbctl lsp-del sw0-lr1 +check ovn-nbctl --wait=sb sync +AT_CHECK([dns_lookup_flows | grep -c 'priority=200'], [0], [1 +]) + +# The DNS response flows are unchanged. +AT_CHECK([ovn-sbctl dump-flows sw0 | grep -w "ls_in_dns_response" | grep -c "udp.dst == 53"], [0], [2 +]) + +# Clearing the DNS records removes every lookup flow again. +check ovn-nbctl clear Logical_Switch sw0 dns_records +check ovn-nbctl --wait=sb sync +AT_CHECK([dns_lookup_flows], [0], [dnl + table=??(ls_in_dns_lookup ), priority=0 , match=(1), action=(next;) +]) + +OVN_CLEANUP_NORTHD AT_CLEANUP ]) -- 2.54.0 (Apple Git-157) _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
