From patchwork Wed Nov 22 01:00:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi-Hung Wei X-Patchwork-Id: 840238 X-Patchwork-Delegate: jpettit@nicira.com 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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mu7fWb96"; dkim-atps=neutral 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 3yhPNk3Y83z9sDB for ; Wed, 22 Nov 2017 12:04:06 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id F2037BD0; Wed, 22 Nov 2017 01:01:55 +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 AAD87BC6 for ; Wed, 22 Nov 2017 01:01:54 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4634513B for ; Wed, 22 Nov 2017 01:01:54 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id z184so11593585pgd.13 for ; Tue, 21 Nov 2017 17:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gfOpYF5ArsdGWHGuIXPk1HNoOgCIqnvWlmc5YnUzays=; b=mu7fWb96boTq2JWSBg0LZaSOihhB8yZ63MiDi5R1U+seQdAqPYHmto+vj3PHo29ecM wSLsNNenEyb8Pf6UP0IpYdwtg+OrdZITpQC5aIrXhV4F1vIlmr2DcIiwtyzQUefZzPz3 Clqgzq+lxIvypVdud08bxKFGm0mIqytq8DZpTqvOAgtZ22xl6mFibHq+kU4W61rH0/gJ MndGFyjS1qV7X1MuJbR98uuHSQ9YMFqSdgoxUcbV8rtPSmxBIXbaXDaB+dumo7rYobfo cT2Ijn1G0VQcSLkt9vqTr86XLALBU44y2bDO5KUueoUAeJF4l3B5NIAwvr/CAHCBbZwT kAWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gfOpYF5ArsdGWHGuIXPk1HNoOgCIqnvWlmc5YnUzays=; b=MN/Jh7FC2uvgJV6/xkR83YMk3EhgTUhSNHyWeq6EkaMSSTqC2lENRYjYuAWqx0tAr9 RRXMarW0VdERh2cAfUwEHKcx2Jkfl91M2jShaQGDl5UvyRO88+AvRw3lZkTPva41d2B6 3t/4m+o7WsL4JmYk2FW3mUzvV3zZ067pi4Jhrj7w9sfixhFTTmL0319jQBqfjstqwNDu oUQdsdPUiXxFu4aCKI/VexbLIJ4iCoP+Acl81nIBkkPE5L0DT6TPRpjHWYiYIUjmR+3Q wF49YlfrMYfilSrPIoog/kH13Ba2aWdHUORtqx9f9x1y82PvZEClyn35kpq3HqJe0hNE k30g== X-Gm-Message-State: AJaThX7hfmsFNjZFCxMAWqTyJyDQ7wMHggEu1+AiM/FhxcfR6fC4eiYv IR6sg7F2M0I4KMLxo3alepa5kf2f X-Google-Smtp-Source: AGs4zMbHCJGwH35GJkbAISjD4fSrFk0bPlfUNmidRqjp35qenI1xmfQEaajKzLNVnWpcMAfKGm09Dw== X-Received: by 10.99.53.3 with SMTP id c3mr18006386pga.194.1511312513537; Tue, 21 Nov 2017 17:01:53 -0800 (PST) Received: from sc9-mailhost2.vmware.com ([208.91.2.2]) by smtp.gmail.com with ESMTPSA id w3sm22105172pge.59.2017.11.21.17.01.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Nov 2017 17:01:53 -0800 (PST) From: Yi-Hung Wei To: dev@openvswitch.org Date: Tue, 21 Nov 2017 17:00:54 -0800 Message-Id: <1511312455-7733-3-git-send-email-yihung.wei@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511312455-7733-1-git-send-email-yihung.wei@gmail.com> References: <1511312455-7733-1-git-send-email-yihung.wei@gmail.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 v2 2/3] conntrack: Support conntrack flush by ct 5-tuple 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 This patch adds support of flushing a conntrack entry specified by the conntrack 5-tuple in dpif-netdev. Signed-off-by: Yi-Hung Wei --- lib/conntrack.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/conntrack.h | 3 +++ lib/dpif-netdev.c | 2 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index f5a3aa9fab34..c9077c07042c 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -2335,6 +2335,18 @@ ct_endpoint_to_ct_dpif_inet_addr(const struct ct_addr *a, } static void +ct_dpif_inet_addr_to_ct_endpoint(const union ct_dpif_inet_addr *a, + struct ct_addr *b, + const uint16_t l3_type) +{ + if (l3_type == AF_INET) { + b->ipv4_aligned = a->ip; + } else if (l3_type == AF_INET6) { + b->ipv6_aligned = a->in6; + } +} + +static void conn_key_to_tuple(const struct conn_key *key, struct ct_dpif_tuple *tuple) { if (key->dl_type == htons(ETH_TYPE_IP)) { @@ -2359,6 +2371,35 @@ conn_key_to_tuple(const struct conn_key *key, struct ct_dpif_tuple *tuple) } static void +tuple_to_conn_key(const struct ct_dpif_tuple *tuple, uint16_t zone, + struct conn_key *key) +{ + if (tuple->l3_type == AF_INET) { + key->dl_type = htons(ETH_TYPE_IP); + } else if (tuple->l3_type == AF_INET6) { + key->dl_type = htons(ETH_TYPE_IPV6); + } + key->nw_proto = tuple->ip_proto; + ct_dpif_inet_addr_to_ct_endpoint(&tuple->src, &key->src.addr, + tuple->l3_type); + ct_dpif_inet_addr_to_ct_endpoint(&tuple->dst, &key->dst.addr, + tuple->l3_type); + + if (tuple->ip_proto == IPPROTO_ICMP || tuple->ip_proto == IPPROTO_ICMPV6) { + key->src.icmp_id = tuple->icmp_id; + key->src.icmp_type = tuple->icmp_type; + key->src.icmp_code = tuple->icmp_code; + key->dst.icmp_id = tuple->icmp_id; + key->dst.icmp_type = reverse_icmp_type(tuple->icmp_type); + key->dst.icmp_code = tuple->icmp_code; + } else { + key->src.port = tuple->src_port; + key->dst.port = tuple->dst_port; + } + key->zone = zone; +} + +static void conn_to_ct_dpif_entry(const struct conn *conn, struct ct_dpif_entry *entry, long long now, int bkt) { @@ -2485,6 +2526,29 @@ conntrack_flush(struct conntrack *ct, const uint16_t *zone) return 0; } +int +conntrack_flush_tuple(struct conntrack *ct, const struct ct_dpif_tuple *tuple, + uint16_t zone) +{ + struct conn_lookup_ctx ctx; + int error = 0; + + memset(&ctx, 0, sizeof(ctx)); + tuple_to_conn_key(tuple, zone, &ctx.key); + ctx.hash = conn_key_hash(&ctx.key, ct->hash_basis); + unsigned bucket = hash_to_bucket(ctx.hash); + + ct_lock_lock(&ct->buckets[bucket].lock); + conn_key_lookup(&ct->buckets[bucket], &ctx, time_msec()); + if (ctx.conn) { + conn_clean(ct, ctx.conn, &ct->buckets[bucket]); + } else { + error = ENOENT; + } + ct_lock_unlock(&ct->buckets[bucket].lock); + return error; +} + /* This function must be called with the ct->resources read lock taken. */ static struct alg_exp_node * expectation_lookup(struct hmap *alg_expectations, diff --git a/lib/conntrack.h b/lib/conntrack.h index fbeef1c4754e..b5b26dd96e00 100644 --- a/lib/conntrack.h +++ b/lib/conntrack.h @@ -107,6 +107,7 @@ struct conntrack_dump { }; struct ct_dpif_entry; +struct ct_dpif_tuple; int conntrack_dump_start(struct conntrack *, struct conntrack_dump *, const uint16_t *pzone, int *); @@ -114,6 +115,8 @@ int conntrack_dump_next(struct conntrack_dump *, struct ct_dpif_entry *); int conntrack_dump_done(struct conntrack_dump *); int conntrack_flush(struct conntrack *, const uint16_t *zone); +int conntrack_flush_tuple(struct conntrack *, const struct ct_dpif_tuple *, + uint16_t zone); /* 'struct ct_lock' is a wrapper for an adaptive mutex. It's useful to try * different types of locks (e.g. spinlocks) */ diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index b1ef9a6a5992..527442ebfc2a 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -5740,7 +5740,7 @@ dpif_netdev_ct_flush(struct dpif *dpif, const uint16_t *zone, struct dp_netdev *dp = get_dp_netdev(dpif); if (tuple) { - return EOPNOTSUPP; + return conntrack_flush_tuple(&dp->conntrack, tuple, zone ? *zone : 0); } return conntrack_flush(&dp->conntrack, zone); }