From patchwork Wed Jan 10 17:59:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 858458 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=) 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 3zGxdk639Bz9ryQ for ; Thu, 11 Jan 2018 05:01:14 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8C8F01008; Wed, 10 Jan 2018 17:59:29 +0000 (UTC) X-Original-To: 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 B7109FE9 for ; Wed, 10 Jan 2018 17:59:27 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 13EEF18A for ; Wed, 10 Jan 2018 17:59:27 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id f140so642911wmd.2 for ; Wed, 10 Jan 2018 09:59:26 -0800 (PST) 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; bh=cpJWSLYatemyhDpkpCsrIQSg+EUM7YVHYZtAtYzy26U=; b=Vk7CHB8CnZFHZG0lKwbCJA9MTRv950bqn44pQ4qBTcnOs6AbzhyLwuG7o7xaTGuWWP dKHIdzXHSuhGb8cOdGqyP3GkK0oAaDL4DGrSUXAZ3qqGwzYK8y8XK6cGtQ2H7nYFrkhf mj8A1vOvdV3wOmOpS4p6Pq5H/J6qzLMNxE6L/9mcs/NvCNW2mKGIEQKpgOqQgmeam8kB eAMV3wUVBgn6+44c8V0nWqd8fmt7poio6p7VO+qzsUbhl7WjjV971AYqhIl1c7sJ7TaH acgbFF1puHUz5BUrCyh4bp5HoURZjanDw7Pw9uzb2lnlCyq6WJyUUoappur75pZSu82z ysgA== X-Gm-Message-State: AKGB3mKq1R5uHfoGBpNCDa8hrQm75UiPHrTqwWS7J+FMqIvrDw4cMX6R KjRAcYlFZF37BcW16YdRCTFUMF3HP+s= X-Google-Smtp-Source: ACJfBosJcoRcT9ciZkgQ4ALVESRtR7d6YuWO/qKskUClnSLlEM1qBQkMuo1b77+zN8KPWbqjyx9BTA== X-Received: by 10.28.134.143 with SMTP id i137mr17075852wmd.2.1515607165473; Wed, 10 Jan 2018 09:59:25 -0800 (PST) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id 187sm23591636wmu.19.2018.01.10.09.59.24 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jan 2018 09:59:25 -0800 (PST) From: Lorenzo Bianconi To: dev@openvswitch.org Date: Wed, 10 Jan 2018 18:59:01 +0100 Message-Id: X-Mailer: git-send-email 2.13.6 In-Reply-To: References: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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] [RFC 3/3] OVN: add acl reject rule support using icmp4 action 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Whenever the acl reject rule is hit send back an ICMPv4 destination unreachable packet and do not handle reject rule as drop one Signed-off-by: Lorenzo Bianconi --- ovn/northd/ovn-northd.c | 76 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 63ed97efb..9b7063f45 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -2890,13 +2890,18 @@ build_pre_acls(struct ovn_datapath *od, struct hmap *lflows) /* Ingress and Egress Pre-ACL Table (Priority 110). * - * Not to do conntrack on ND packets. */ + * Not to do conntrack on ND and ICMP destination + * unreachable packets. */ ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_ACL, 110, "nd", "next;"); ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_ACL, 110, "(nd_rs || nd_ra)", "next;"); + ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_ACL, 110, + "ip4 && icmp4.type == 3", "next;"); ovn_lflow_add(lflows, od, S_SWITCH_OUT_PRE_ACL, 110, "nd", "next;"); ovn_lflow_add(lflows, od, S_SWITCH_OUT_PRE_ACL, 110, "(nd_rs || nd_ra)", "next;"); + ovn_lflow_add(lflows, od, S_SWITCH_OUT_PRE_ACL, 110, + "ip4 && icmp4.type == 3", "next;"); /* Ingress and Egress Pre-ACL Table (Priority 100). * @@ -3256,28 +3261,30 @@ build_acls(struct ovn_datapath *od, struct hmap *lflows) struct ds match = DS_EMPTY_INITIALIZER; struct ds actions = DS_EMPTY_INITIALIZER; - /* XXX Need to support "reject", treat it as "drop;" for now. */ - if (!strcmp(acl->action, "reject")) { - VLOG_INFO("reject is not a supported action"); - } - /* The implementation of "drop" differs if stateful ACLs are in * use for this datapath. In that case, the actions differ * depending on whether the connection was previously committed * to the connection tracker with ct_commit. */ if (has_stateful) { /* If the packet is not part of an established connection, then - * we can simply drop it. */ + * we can simply reject/drop it. */ ds_put_format(&match, "(!ct.est || (ct.est && ct_label.blocked == 1)) " "&& (%s)", acl->match); build_acl_log(&actions, acl); - ds_put_cstr(&actions, "/* drop */"); - ovn_lflow_add_with_hint(lflows, od, stage, - acl->priority + OVN_ACL_PRI_OFFSET, - ds_cstr(&match), ds_cstr(&actions), - stage_hint); + if (!strcmp(acl->action, "reject")) { + ds_put_format(&actions, "reg0 = 0; " + "eth.dst <-> eth.src; ip4.dst <-> ip4.src; " + "icmp4 { outport <-> inport; %s };", + ingress ? "output;" + : "next(pipeline=ingress,table=0);"); + } else { + ds_put_cstr(&actions, "/* drop */"); + } + ovn_lflow_add(lflows, od, stage, + acl->priority + OVN_ACL_PRI_OFFSET, + ds_cstr(&match), ds_cstr(&actions)); /* For an existing connection without ct_label set, we've * encountered a policy change. ACLs previously allowed @@ -3288,7 +3295,8 @@ build_acls(struct ovn_datapath *od, struct hmap *lflows) * specifying "next;", we implicitly drop the packet after * updating conntrack state. We would normally defer * ct_commit() to the "stateful" stage, but since we're - * dropping the packet, we go ahead and do it here. */ + * rejecting/dropping the packet, we go ahead and do it here. + */ ds_clear(&match); ds_clear(&actions); ds_put_format(&match, @@ -3296,22 +3304,38 @@ build_acls(struct ovn_datapath *od, struct hmap *lflows) acl->match); ds_put_cstr(&actions, "ct_commit(ct_label=1/1); "); build_acl_log(&actions, acl); - ds_put_cstr(&actions, "/* drop */"); - ovn_lflow_add_with_hint(lflows, od, stage, - acl->priority + OVN_ACL_PRI_OFFSET, - ds_cstr(&match), ds_cstr(&actions), - stage_hint); - + if (!strcmp(acl->action, "reject")) { + ds_put_format(&match, " && ip4"); + ds_put_format(&actions, "reg0 = 0; " + "eth.dst <-> eth.src; ip4.dst <-> ip4.src; " + "icmp4 { outport <-> inport; %s };", + ingress ? "output;" + : "next(pipeline=ingress,table=0);"); + } else { + ds_put_cstr(&actions, "/* drop */"); + } + ovn_lflow_add(lflows, od, stage, + acl->priority + OVN_ACL_PRI_OFFSET, + ds_cstr(&match), ds_cstr(&actions)); } else { /* There are no stateful ACLs in use on this datapath, - * so a "drop" ACL is simply the "drop" logical flow action - * in all cases. */ + * so a "reject/drop" ACL is simply the "reject/drop" + * logical flow action in all cases. */ build_acl_log(&actions, acl); - ds_put_cstr(&actions, "/* drop */"); - ovn_lflow_add_with_hint(lflows, od, stage, - acl->priority + OVN_ACL_PRI_OFFSET, - acl->match, ds_cstr(&actions), - stage_hint); + if (!strcmp(acl->action, "reject")) { + ds_put_format(&match, "(%s) && ip4", acl->match); + ds_put_format(&actions, + "eth.dst <-> eth.src; ip4.dst <-> ip4.src; " + "icmp4 { outport <-> inport; %s };", + ingress ? "output;" + : "next(pipeline=ingress,table=0);"); + } else { + ds_put_cstr(&match, acl->match); + ds_put_cstr(&actions, "/* drop */"); + } + ovn_lflow_add(lflows, od, stage, + acl->priority + OVN_ACL_PRI_OFFSET, + ds_cstr(&match), ds_cstr(&actions)); } ds_destroy(&match); ds_destroy(&actions);