From patchwork Tue Aug 27 15:25:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1153919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Ht5V720xz9sN4 for ; Wed, 28 Aug 2019 01:26:54 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8C49F17ED; Tue, 27 Aug 2019 15:26:53 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 7D78F17E1 for ; Tue, 27 Aug 2019 15:26:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 1A943710 for ; Tue, 27 Aug 2019 15:26:52 +0000 (UTC) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 697F02A09D2 for ; Tue, 27 Aug 2019 15:26:51 +0000 (UTC) Received: by mail-wr1-f71.google.com with SMTP id k14so11584043wrv.2 for ; Tue, 27 Aug 2019 08:26:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=37YUTuxLyZAW78GgQtAcpfadyilkWN5JVDFUCliukGI=; b=oz6gcBlwGmmpRSmwl9LQf6A0lvqUg/2ft1u/dJi0Z336BnhLbaCBqdCa4ZLfqRqT2t fnLaDp6u/snnXr61q4IS1URFtZ/0zdsQc+r8F9hP1gAaHolfVbv0o7qPLieiuVW5KFfv g/Gt1SAF7kLLT32rYKlVM6K1F8/F5XQ1TAfQYwkjjh/TWkamI3jgTvBPKrUdR+3tJfrc tDACn3CZCUgleVc1O0Un8+ow3FW3F8l0gjK34K9NOwQvqOr6oHuRGXGbMnRX3lXn9hKS KJNmHfXdFWbCaKlx6ymn73cEc8HxYSAvwZ+DTlp4nugl9VhXFeNcKmyB0A4QgjRcbEph 1aKg== X-Gm-Message-State: APjAAAWFfnWvCbc+4Y/9sIdu6VyAwHU2buebw0F+C2tzQHT6otdipLB7 NxVcJANifoH9DXG7RF/eDdwvzRRTTv+QusVzG+M531NSY8Gyhda1Uio19zMCdD7ad1P+b3+eijE eeWAvxDni2yg+6i7Amg== X-Received: by 2002:a5d:698d:: with SMTP id g13mr1619764wru.338.1566919609896; Tue, 27 Aug 2019 08:26:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJPyb3dZ1bZcAbcYnjVSmWVf0RsgnZPjQCfClFZAz6gBC/wh+B7zaRJtRox/X5sJ6ss4h01g== X-Received: by 2002:a5d:698d:: with SMTP id g13mr1619734wru.338.1566919609676; Tue, 27 Aug 2019 08:26:49 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id 4sm30050834wro.78.2019.08.27.08.26.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2019 08:26:49 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Tue, 27 Aug 2019 17:25:21 +0200 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH ovn 1/2] northd: introduce build_empty_lb_event_flow routine X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Introduce build_empty_lb_event_flow routine and remove open code Signed-off-by: Lorenzo Bianconi --- northd/ovn-northd.c | 63 ++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index ca128c996..9db8b43e2 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -4001,6 +4001,41 @@ ls_has_dns_records(const struct nbrec_logical_switch *nbs) return false; } +static void +build_empty_lb_event_flow(struct ovn_datapath *od, struct hmap *lflows, + struct smap_node *node, char *ip_address, + struct nbrec_load_balancer *lb, uint16_t port, + int addr_family, int pl) +{ + if (!controller_event_en || node->value[0]) { + return; + } + + struct ds match = DS_EMPTY_INITIALIZER; + char *action; + + if (addr_family == AF_INET) { + ds_put_format(&match, "ip4.dst == %s && %s", + ip_address, lb->protocol); + } else { + ds_put_format(&match, "ip6.dst == %s && %s", + ip_address, lb->protocol); + } + if (port) { + ds_put_format(&match, " && %s.dst == %u", lb->protocol, + port); + } + action = xasprintf("trigger_event(event = \"%s\", " + "vip = \"%s\", protocol = \"%s\", " + "load_balancer = \"" UUID_FMT "\");", + event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS), + node->key, lb->protocol, + UUID_ARGS(&lb->header_.uuid)); + ovn_lflow_add(lflows, od, pl, 130, ds_cstr(&match), action); + ds_destroy(&match); + free(action); +} + static void build_pre_lb(struct ovn_datapath *od, struct hmap *lflows) { @@ -4038,32 +4073,8 @@ build_pre_lb(struct ovn_datapath *od, struct hmap *lflows) sset_add(&all_ips, ip_address); } - if (controller_event_en && !node->value[0]) { - struct ds match = DS_EMPTY_INITIALIZER; - char *action; - - if (addr_family == AF_INET) { - ds_put_format(&match, "ip4.dst == %s && %s", - ip_address, lb->protocol); - } else { - ds_put_format(&match, "ip6.dst == %s && %s", - ip_address, lb->protocol); - } - if (port) { - ds_put_format(&match, " && %s.dst == %u", lb->protocol, - port); - } - action = xasprintf("trigger_event(event = \"%s\", " - "vip = \"%s\", protocol = \"%s\", " - "load_balancer = \"" UUID_FMT "\");", - event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS), - node->key, lb->protocol, - UUID_ARGS(&lb->header_.uuid)); - ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB, 120, - ds_cstr(&match), action); - ds_destroy(&match); - free(action); - } + build_empty_lb_event_flow(od, lflows, node, ip_address, lb, + port, addr_family, S_SWITCH_IN_PRE_LB); free(ip_address);