From patchwork Wed Sep 9 13:04:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1360623 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bmj0860crz9sTN for ; Wed, 9 Sep 2020 23:04:24 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 478678721F; Wed, 9 Sep 2020 13:04:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tw12Ai1ose6W; Wed, 9 Sep 2020 13:04:21 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 94C7A8717A; Wed, 9 Sep 2020 13:04:21 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 76A5EC0859; Wed, 9 Sep 2020 13:04:21 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 24495C0051 for ; Wed, 9 Sep 2020 13:04:20 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 140968703D for ; Wed, 9 Sep 2020 13:04:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pg1fpji-HVWa for ; Wed, 9 Sep 2020 13:04:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.kot-begemot.co.uk (ivanoab7.miniserver.com [37.128.132.42]) by fraxinus.osuosl.org (Postfix) with ESMTPS id C5CDF87026 for ; Wed, 9 Sep 2020 13:04:18 +0000 (UTC) Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFzln-0007KD-Fw; Wed, 09 Sep 2020 13:04:15 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1kFzli-0006Je-JG; Wed, 09 Sep 2020 14:04:12 +0100 From: anton.ivanov@cambridgegreys.com To: dev@openvswitch.org Date: Wed, 9 Sep 2020 14:04:08 +0100 Message-Id: <20200909130408.24235-1-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett Cc: i.maximets@ovn.org, Anton Ivanov Subject: [ovs-dev] [PATCH ovn v2] ovn-northd: Replace ds_put_* evaluating to constant expressions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Anton Ivanov Replaces ds_put_cstr and ds_put_format which evaluate to constant expressions with string constants This version also removes invocations of ds_clear() which are no longer required as per comments by I. Maximets on the first version. It also covers one more case which was missed in the first version. Signed-off-by: Anton Ivanov --- northd/ovn-northd.c | 68 +++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 3de71612b..71815d9e7 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -6947,28 +6947,20 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports, continue; } - struct ds action = DS_EMPTY_INITIALIZER; - - ds_clear(&match); - ds_put_cstr(&match, "udp.dst == 53"); - ds_put_format(&action, - REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;"); ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100, - ds_cstr(&match), ds_cstr(&action)); - ds_clear(&action); - ds_put_cstr(&match, " && "REGBIT_DNS_LOOKUP_RESULT); - ds_put_format(&action, "eth.dst <-> eth.src; ip4.src <-> ip4.dst; " + "udp.dst == 53", + REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;"); + const char *dns_action = "eth.dst <-> eth.src; ip4.src <-> ip4.dst; " "udp.dst = udp.src; udp.src = 53; outport = inport; " - "flags.loopback = 1; output;"); + "flags.loopback = 1; output;"; + const char *dns_match = "udp.dst == 53 && "REGBIT_DNS_LOOKUP_RESULT; ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100, - ds_cstr(&match), ds_cstr(&action)); - ds_clear(&action); - ds_put_format(&action, "eth.dst <-> eth.src; ip6.src <-> ip6.dst; " + dns_match, dns_action); + dns_action = "eth.dst <-> eth.src; ip6.src <-> ip6.dst; " "udp.dst = udp.src; udp.src = 53; outport = inport; " - "flags.loopback = 1; output;"); + "flags.loopback = 1; output;"; ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100, - ds_cstr(&match), ds_cstr(&action)); - ds_destroy(&action); + dns_match, dns_action); } /* Ingress table 14 and 15: DHCP options and response, by default goto @@ -7838,11 +7830,10 @@ add_ecmp_symmetric_reply_flows(struct hmap *lflows, ds_cstr(&ecmp_reply), "next;", &st_route->header_); - ds_clear(&actions); - ds_put_cstr(&actions, "eth.dst = ct_label.ecmp_reply_eth; next;"); + const char *action = "eth.dst = ct_label.ecmp_reply_eth; next;"; ovn_lflow_add_with_hint(lflows, od, S_ROUTER_IN_ARP_RESOLVE, 200, ds_cstr(&ecmp_reply), - ds_cstr(&actions), &st_route->header_); + action, &st_route->header_); } static void @@ -8733,10 +8724,8 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, "eth.bcast", "drop;"); /* TTL discard */ - ds_clear(&match); - ds_put_cstr(&match, "ip4 && ip.ttl == {0, 1}"); ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_INPUT, 30, - ds_cstr(&match), "drop;"); + "ip4 && ip.ttl == {0, 1}", "drop;"); /* Pass other traffic not already handled to the next table for * routing. */ @@ -8777,15 +8766,13 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, op_put_v4_networks(&match, op, false); ds_put_cstr(&match, " && icmp4.type == 8 && icmp4.code == 0"); - ds_clear(&actions); - ds_put_format(&actions, - "ip4.dst <-> ip4.src; " - "ip.ttl = 255; " - "icmp4.type = 0; " - "flags.loopback = 1; " - "next; "); + const char * icmp_actions = "ip4.dst <-> ip4.src; " + "ip.ttl = 255; " + "icmp4.type = 0; " + "flags.loopback = 1; " + "next; "; ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90, - ds_cstr(&match), ds_cstr(&actions), + ds_cstr(&match), icmp_actions, &op->nbrp->header_); } @@ -9152,14 +9139,13 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, } for (size_t i = 0; i < op->lrp_networks.n_ipv6_addrs; i++) { - ds_clear(&actions); ds_clear(&match); ds_put_format(&match, "ip6.dst == %s && udp.src == 547 &&" " udp.dst == 546", op->lrp_networks.ipv6_addrs[i].addr_s); - ds_put_format(&actions, "reg0 = 0; handle_dhcpv6_reply;"); ovn_lflow_add(lflows, op->od, S_ROUTER_IN_IP_INPUT, 100, - ds_cstr(&match), ds_cstr(&actions)); + ds_cstr(&match), + "reg0 = 0; handle_dhcpv6_reply;"); } } @@ -9183,15 +9169,14 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, op_put_v6_networks(&match, op); ds_put_cstr(&match, " && icmp6.type == 128 && icmp6.code == 0"); - ds_clear(&actions); - ds_put_cstr(&actions, + const char *lrp_actions = "ip6.dst <-> ip6.src; " "ip.ttl = 255; " "icmp6.type = 129; " "flags.loopback = 1; " - "next; "); + "next; "; ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90, - ds_cstr(&match), ds_cstr(&actions), + ds_cstr(&match), lrp_actions, &op->nbrp->header_); } @@ -10449,13 +10434,12 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, REG_NEXT_HOP_IPV4 " == %s", peer->json_key, vip); - ds_clear(&actions); - ds_put_format(&actions, - "eth.dst = 00:00:00:00:00:00; next;"); + const char *arp_actions = + "eth.dst = 00:00:00:00:00:00; next;"; ovn_lflow_add_with_hint(lflows, peer->od, S_ROUTER_IN_ARP_RESOLVE, 100, ds_cstr(&match), - ds_cstr(&actions), + arp_actions, &op->nbsp->header_); break; }