From patchwork Wed Apr 4 15:06:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 895022 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 40GTqP6MLjz9s08 for ; Thu, 5 Apr 2018 01:08:17 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 779E6950; Wed, 4 Apr 2018 15:06:54 +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 878BD84B for ; Wed, 4 Apr 2018 15:06:52 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A241C418 for ; Wed, 4 Apr 2018 15:06:51 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id r131so43421628wmb.2 for ; Wed, 04 Apr 2018 08:06: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; bh=MO/W5reJor9mxzpbyYfXGMOwx+olozjQBwp3p1fCp14=; b=cli25wKar4rxLgfknzSxm7oLdDcRN4h+RToGpWj5vhEiPcZKxOful0WsiXaI0BeG1x Dlj3K+4jJzrwHAgwM8JTlbjT/d6Pb7JRshR1KqHNKDND7ZSzxhyxcyklzy7oU1GSFqg8 MW0Q+qLP5EFTFJrBnWqmZf61hlC8/W3waXCRxtvKvD7YTMW0Ff8ZdmB8L45adD4IXlNz yfxWV4gLLob/0mPVpJNqGT75ua7HaY7MUatlRf641Y9Yof8WzfERhhsZF2x8fCsxl34v DW+doZI4nhG+NAbnlzFW6gsemSUBeqoPxm6s+B91HqWZhsWT8DYksgE5SXqvKcwQMsLP qm6A== X-Gm-Message-State: ALQs6tC27boIoNcGCbVNb02PKUWnXRnsxfb9bppatF4XtTeYCHO+MIYU /USJgfHpC9Ut4aqC2EwfPQcBu2KbLBU= X-Google-Smtp-Source: AIpwx49eavF1gvOMS/pZqn/OcHKEyUB8+SUUo1IQ17KyGTvMl2fDw9YTQxcjd3sfQuEFubl0cNWqHQ== X-Received: by 10.28.106.5 with SMTP id f5mr3241289wmc.84.1522854409891; Wed, 04 Apr 2018 08:06: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 z9sm8888717wrz.4.2018.04.04.08.06.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Apr 2018 08:06:49 -0700 (PDT) From: Lorenzo Bianconi To: dev@openvswitch.org Date: Wed, 4 Apr 2018 17:06:37 +0200 Message-Id: <13396a4c549d425aada79fc19307f93e58249271.1522853801.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.14.3 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] [PATCH 2/2] OVN: add tcp_reset action to ovn acl reject support 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 by a TCP segment send back a TCP RST packet to close the connection using the tcp_reset action. Moreover add add tcp_reset test case to 'ACL reject rule test' Signed-off-by: Lorenzo Bianconi --- ovn/northd/ovn-northd.c | 30 ++++++++++++++++++++++++------ ovn/ovn-nb.xml | 1 - tests/ovn.at | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 396381049..07896be84 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -2905,9 +2905,11 @@ build_pre_acls(struct ovn_datapath *od, struct hmap *lflows) * Not to do conntrack on ND and ICMP destination * unreachable packets. */ ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_ACL, 110, - "nd || nd_rs || nd_ra || icmp4.type == 3", "next;"); + "nd || nd_rs || nd_ra || icmp4.type == 3 || " + "(tcp && tcp.flags == 4)", "next;"); ovn_lflow_add(lflows, od, S_SWITCH_OUT_PRE_ACL, 110, - "nd || nd_rs || nd_ra || icmp4.type == 3", "next;"); + "nd || nd_rs || nd_ra || icmp4.type == 3 || " + "(tcp && tcp.flags == 4)", "next;"); /* Ingress and Egress Pre-ACL Table (Priority 100). * @@ -3097,14 +3099,30 @@ build_reject_acl_rules(struct ovn_datapath *od, struct hmap *lflows, struct ds actions = DS_EMPTY_INITIALIZER; bool ingress = (stage == S_SWITCH_IN_ACL); - /* XXX: Treat TCP connections as "drop;" for now */ + /* TCP */ build_acl_log(&actions, acl); if (extra_match->length > 0) { ds_put_format(&match, "(%s) && ", extra_match->string); } - ds_put_format(&match, "ip && tcp && (%s)", acl->match); - ds_put_cstr(&actions, "/* drop */"); - ovn_lflow_add(lflows, od, stage, acl->priority + OVN_ACL_PRI_OFFSET, + ds_put_format(&match, "ip4 && tcp && (%s)", acl->match); + ds_put_format(&actions, "reg0 = 0; " + "eth.dst <-> eth.src; ip4.dst <-> ip4.src; " + "tcp_reset { outport <-> inport; %s };", + ingress ? "output;" : "next(pipeline=ingress,table=0);"); + ovn_lflow_add(lflows, od, stage, acl->priority + OVN_ACL_PRI_OFFSET + 10, + ds_cstr(&match), ds_cstr(&actions)); + ds_clear(&match); + ds_clear(&actions); + build_acl_log(&actions, acl); + if (extra_match->length > 0) { + ds_put_format(&match, "(%s) && ", extra_match->string); + } + ds_put_format(&match, "ip6 && tcp && (%s)", acl->match); + ds_put_format(&actions, "reg0 = 0; " + "eth.dst <-> eth.src; ip6.dst <-> ip6.src; " + "tcp_reset { outport <-> inport; %s };", + ingress ? "output;" : "next(pipeline=ingress,table=0);"); + ovn_lflow_add(lflows, od, stage, acl->priority + OVN_ACL_PRI_OFFSET + 10, ds_cstr(&match), ds_cstr(&actions)); /* IPv4 traffic */ diff --git a/ovn/ovn-nb.xml b/ovn/ovn-nb.xml index 6bb93dedd..2ebaac561 100644 --- a/ovn/ovn-nb.xml +++ b/ovn/ovn-nb.xml @@ -1062,7 +1062,6 @@
  • reject: Drop the packet, replying with a RST for TCP or ICMP unreachable message for other IP-based protocols. - Not implemented--currently treated as drop
  • diff --git a/tests/ovn.at b/tests/ovn.at index 4cd3bbf9b..0f37b8892 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -9386,6 +9386,34 @@ test_ip_packet() { as hv$hv ovs-appctl netdev-dummy/receive vif$inport $packet } +# test_tcp_syn_packet INPORT HV ETH_SRC ETH_DST IPV4_SRC IPV4_DST IP_CHKSUM TCP_SPORT TCP_DPORT TCP_CHKSUM EXP_IP_CHKSUM EXP_TCP_RST_CHKSUM +# +# Causes a packet to be received on INPORT of the hypervisor HV. The packet is an TCP syn segment with +# ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_CHKSUM, TCP_SPORT, TCP_DPORT, TCP_CHKSUM as specified. +# EXP_IP_CHKSUM and EXP_TCP_RST_CHKSUM are the ip and tcp checksums of the tcp reset segment generated from ACL rule hit +# +# INPORT is an lport number, e.g. 11 for vif11. +# HV is an hypervisor number +# ETH_SRC and ETH_DST are each 12 hex digits. +# IPV4_SRC and IPV4_DST are each 8 hex digits. +# TCP_SPORT and TCP_DPORT are 4 hex digits. +# IP_CHKSUM, TCP_CHKSUM, EXP_IP_CHSUM and EXP_TCP_RST_CHKSUM are each 4 hex digits +test_tcp_syn_packet() { + local inport=$1 hv=$2 eth_src=$3 eth_dst=$4 ipv4_src=$5 ipv4_dst=$6 ip_chksum=$7 + local tcp_sport=$8 tcp_dport=$9 tcp_chksum=${10} + local exp_ip_chksum=${11} exp_tcp_rst_chksum=${12} + shift 12 + + local ip_ttl=ff + local packet=${eth_dst}${eth_src}08004500002800004000${ip_ttl}06${ip_chksum}${ipv4_src}${ipv4_dst}${tcp_sport}${tcp_dport}000000010000000050027210${tcp_chksum}0000 + + local tcp_rst_ttl=ff + local reply=${eth_src}${eth_dst}08004500002800004000${tcp_rst_ttl}06${exp_ip_chksum}${ipv4_dst}${ipv4_src}${tcp_dport}${tcp_sport}000000000000000150040000${exp_tcp_rst_chksum}0000 + echo $reply >> vif$inport.expected + + as hv$hv ovs-appctl netdev-dummy/receive vif$inport $packet +} + # Create hypervisors hv[123]. # Add vif1[123] to hv1, vif2[123] to hv2, vif3[123] to hv3. # Add all of the vifs to a single logical switch sw0. @@ -9432,6 +9460,10 @@ test_ip_packet 11 1 000000000011 000000000021 $(ip_to_hex 192 168 1 11) $(ip_to_ test_ip_packet 21 2 000000000021 000000000011 $(ip_to_hex 192 168 1 21) $(ip_to_hex 192 168 1 11) 0000 7d8d fcfe test_ip_packet 31 3 000000000031 000000000012 $(ip_to_hex 192 168 1 31) $(ip_to_hex 192 168 1 12) 0000 7d82 fcfe +test_tcp_syn_packet 11 1 000000000011 000000000021 $(ip_to_hex 192 168 1 11) $(ip_to_hex 192 168 1 21) 0000 8b40 3039 0000 7d8d 4486 +test_tcp_syn_packet 21 2 000000000021 000000000011 $(ip_to_hex 192 168 1 21) $(ip_to_hex 192 168 1 11) 0000 8b40 3039 0000 7d8d 4486 +test_tcp_syn_packet 31 3 000000000031 000000000012 $(ip_to_hex 192 168 1 31) $(ip_to_hex 192 168 1 12) 0000 8b40 3039 0000 7d82 4486 + for i in 1 2 3; do OVN_CHECK_PACKETS([hv$i/vif${i}1-tx.pcap], [vif${i}1.expected]) done