From patchwork Fri Nov 6 03:12:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Di Proietto X-Patchwork-Id: 540798 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 36AE01402D7 for ; Fri, 6 Nov 2015 14:13:49 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 5881722C3BE; Thu, 5 Nov 2015 19:12:53 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 8083F22C386 for ; Thu, 5 Nov 2015 19:12:49 -0800 (PST) Received: from bar2.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 904B21E026D for ; Thu, 5 Nov 2015 20:12:48 -0700 (MST) X-ASG-Debug-ID: 1446779567-03dc5331bb5c730001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar2.cudamail.com with ESMTP id ate7bL3Xi2EvDzpz (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 05 Nov 2015 20:12:47 -0700 (MST) X-Barracuda-Envelope-From: diproiettod@vmware.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO smtp-outbound-2.vmware.com) (208.91.2.13) by mx1-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 6 Nov 2015 03:12:47 -0000 Received-SPF: error (mx1-pf1.cudamail.com: error in processing during lookup of vmware.com: DNS problem) X-Barracuda-Apparent-Source-IP: 208.91.2.13 X-Barracuda-RBL-IP: 208.91.2.13 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id BC24F2844A for ; Thu, 5 Nov 2015 19:12:46 -0800 (PST) Received: from diproiettod-dev.localdomain (unknown [10.33.74.202]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id BE21240250; Thu, 5 Nov 2015 19:12:46 -0800 (PST) X-CudaMail-Envelope-Sender: diproiettod@vmware.com From: Daniele Di Proietto To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-1104112887 X-CudaMail-DTE: 110515 X-CudaMail-Originating-IP: 208.91.2.13 Date: Thu, 5 Nov 2015 19:12:34 -0800 X-ASG-Orig-Subj: [##CM-E1-1104112887##][PATCH v2 03/11] ct-dpif: Add ct_dpif_dump_{start, next, done}(). Message-Id: <1446779562-3837-4-git-send-email-diproiettod@vmware.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1446779562-3837-1-git-send-email-diproiettod@vmware.com> References: <1446779562-3837-1-git-send-email-diproiettod@vmware.com> X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1446779567 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-ASG-Whitelist: EmailCat (corporate) Subject: [ovs-dev] [PATCH v2 03/11] ct-dpif: Add ct_dpif_dump_{start, next, done}(). X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" These function can be used to dump conntrack entries from a datapath. They simply call a function pointer in the dpif_class. No dpif currently implements the interface. The next commits will provide an implementation in dpif-netlink. Signed-off-by: Daniele Di Proietto --- lib/ct-dpif.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/ct-dpif.h | 10 +++++++++ lib/dpif-netdev.c | 3 +++ lib/dpif-netlink.c | 3 +++ lib/dpif-provider.h | 25 ++++++++++++++++++++++ 5 files changed, 102 insertions(+) diff --git a/lib/ct-dpif.c b/lib/ct-dpif.c index db1f831..84e6488 100644 --- a/lib/ct-dpif.c +++ b/lib/ct-dpif.c @@ -20,6 +20,8 @@ #include "ct-dpif.h" +#include "dpif-provider.h" + /* Declarations for conntrack entry formatting. */ struct flags { uint32_t flag; @@ -46,6 +48,65 @@ static const struct flags ct_dpif_status_flags[] = { { 0, NULL } /* End marker. */ }; +/* Dumping */ + +/* Start dumping the entries from the connection tracker used by 'dpif'. + * + * 'dump' must be the address of a pointer to a struct ct_dpif_dump_state, + * which should be passed (unaltered) to ct_dpif_dump_{next,done}(). + * + * If 'zone' is not NULL, it should point to an integer identifing a + * conntrack zone to which the dump will be limited. + * + * If there has been a problem the function returns a non-zero value + * that represents the error. Otherwise it returns zero. */ +int +ct_dpif_dump_start(struct dpif *dpif, struct ct_dpif_dump_state **dump, + const uint16_t *zone) +{ + int err; + + err = (dpif->dpif_class->ct_dump_start + ? dpif->dpif_class->ct_dump_start(dpif, dump, zone) + : EOPNOTSUPP); + + if (!err) { + (*dump)->dpif = dpif; + } + + return err; +} + +/* Dump one connection from a tracker, and put it in 'entry'. + * + * 'dump' should have been initialized by ct_dpif_dump_start(). + * + * The function returns 0, if an entry has been dumped succesfully. + * Otherwise it returns a non-zero value which can be: + * - EOF: meaning that there are no more entries to dump. + * - an error value. + * In both cases, the user should call ct_dpif_dump_done(). */ +int +ct_dpif_dump_next(struct ct_dpif_dump_state *dump, struct ct_dpif_entry *entry) +{ + struct dpif *dpif = dump->dpif; + + return (dpif->dpif_class->ct_dump_next + ? dpif->dpif_class->ct_dump_next(dpif, dump, entry) + : EOPNOTSUPP); +} + +/* Free resources used by 'dump' */ +int +ct_dpif_dump_done(struct ct_dpif_dump_state *dump) +{ + struct dpif *dpif = dump->dpif; + + return (dpif->dpif_class->ct_dump_done + ? dpif->dpif_class->ct_dump_done(dpif, dump) + : EOPNOTSUPP); +} + /* Free memory held by 'entry'. */ void ct_dpif_entry_uninit(struct ct_dpif_entry *entry) diff --git a/lib/ct-dpif.h b/lib/ct-dpif.h index 5127ec2..03f1c20 100644 --- a/lib/ct-dpif.h +++ b/lib/ct-dpif.h @@ -165,6 +165,16 @@ struct ct_dpif_entry { uint32_t mark; }; +struct dpif; + +struct ct_dpif_dump_state { + struct dpif *dpif; +}; + +int ct_dpif_dump_start(struct dpif *, struct ct_dpif_dump_state **, + const uint16_t *zone); +int ct_dpif_dump_next(struct ct_dpif_dump_state *, struct ct_dpif_entry *); +int ct_dpif_dump_done(struct ct_dpif_dump_state *); void ct_dpif_entry_uninit(struct ct_dpif_entry *); void ct_dpif_format_entry(const struct ct_dpif_entry *, struct ds *, bool verbose, bool print_stats); diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 47fa9e2..0f76249 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -3687,6 +3687,9 @@ const struct dpif_class dpif_netdev_class = { dpif_netdev_enable_upcall, dpif_netdev_disable_upcall, dpif_netdev_get_datapath_version, + NULL, /* ct_dump_start */ + NULL, /* ct_dump_next */ + NULL, /* ct_dump_done */ }; static void diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index c195042..bf81e61 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -2319,6 +2319,9 @@ const struct dpif_class dpif_netlink_class = { NULL, /* enable_upcall */ NULL, /* disable_upcall */ dpif_netlink_get_datapath_version, /* get_datapath_version */ + NULL, /* ct_dump_start */ + NULL, /* ct_dump_next */ + NULL, /* ct_dump_done */ }; static int diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index 5415897..f00e635 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -73,6 +73,9 @@ dpif_flow_dump_thread_init(struct dpif_flow_dump_thread *thread, thread->dpif = dump->dpif; } +struct ct_dpif_dump_state; +struct ct_dpif_entry; + /* Datapath interface class structure, to be defined by each implementation of * a datapath interface. * @@ -390,6 +393,28 @@ struct dpif_class { /* Get datapath version. Caller is responsible for freeing the string * returned. */ char *(*get_datapath_version)(void); + + /* Conntrack entry dumping interface. + * + * These functions are used by ct-dpif.c to provide a datapath-agnostic + * dumping interface to the connection trackes provided by the + * datapaths. + * + * ct_dump_start() should put in '*state' a pointer to a newly allocated + * stucture that will be passed by the caller to ct_dump_next() and + * ct_dump_done(). If 'zone' is not NULL, only the entries in '*zone' + * should be dumped. + * + * ct_dump_next() should fill 'entry' with information from a connection + * and prepare to dump the next one on a subsequest invocation. + * + * ct_dump_done should perform any cleanup necessary (including + * deallocating the 'state' structure, if applicable). */ + int (*ct_dump_start)(struct dpif *, struct ct_dpif_dump_state **state, + const uint16_t *zone); + int (*ct_dump_next)(struct dpif *, struct ct_dpif_dump_state *, + struct ct_dpif_entry *entry); + int (*ct_dump_done)(struct dpif *, struct ct_dpif_dump_state *state); }; extern const struct dpif_class dpif_netlink_class;