From patchwork Wed Jan 27 06:23:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1432035 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQYTf2Lbwz9sSs for ; Wed, 27 Jan 2021 17:24:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id BC93F870C6; Wed, 27 Jan 2021 06:24:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2mRBLy2D5-Bx; Wed, 27 Jan 2021 06:24:03 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 09AF78715A; Wed, 27 Jan 2021 06:24:03 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EED39C0FA7; Wed, 27 Jan 2021 06:24:02 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1A6F1C013A for ; Wed, 27 Jan 2021 06:24:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 10DE585A37 for ; Wed, 27 Jan 2021 06:24:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JB0kDxC6yyRq for ; Wed, 27 Jan 2021 06:24:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by fraxinus.osuosl.org (Postfix) with ESMTP id DC1C2851C2 for ; Wed, 27 Jan 2021 06:24:00 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from cmi@nvidia.com) with SMTP; 27 Jan 2021 08:23:56 +0200 Received: from dev-r630-03.mtbc.labs.mlnx (dev-r630-03.mtbc.labs.mlnx [10.75.205.13]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 10R6NkMJ004930; Wed, 27 Jan 2021 08:23:55 +0200 From: Chris Mi To: dev@openvswitch.org Date: Wed, 27 Jan 2021 14:23:36 +0800 Message-Id: <20210127062344.194230-4-cmi@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210127062344.194230-1-cmi@nvidia.com> References: <20210127062344.194230-1-cmi@nvidia.com> MIME-Version: 1.0 Cc: elibr@nvidia.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v12 03/11] dpif: Introduce register sFlow upcall callback API X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When offloading sample action to TC, psample sends the sampled packets to userspace by a netlink message. The thread polling psample socket will translate the psample netlink message to an sFlow format and call the sFlow upcall callback to send the sFlow packet to right monitoring host. Introduce register sFlow upcall callback API. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein --- lib/dpif-netdev.c | 1 + lib/dpif-netlink.c | 1 + lib/dpif-provider.h | 10 ++++++++++ lib/dpif.c | 8 ++++++++ lib/dpif.h | 23 +++++++++++++++++++++++ 5 files changed, 43 insertions(+) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index e3fd0a07f..deb95c780 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -8469,6 +8469,7 @@ const struct dpif_class dpif_netdev_class = { dpif_netdev_register_upcall_cb, dpif_netdev_enable_upcall, dpif_netdev_disable_upcall, + NULL, /* register_sflow_upcall_cb */ dpif_netdev_get_datapath_version, dpif_netdev_ct_dump_start, dpif_netdev_ct_dump_next, diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index ceb56c685..3dcad757a 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -3983,6 +3983,7 @@ const struct dpif_class dpif_netlink_class = { NULL, /* register_upcall_cb */ NULL, /* enable_upcall */ NULL, /* disable_upcall */ + NULL, /* register_sflow_upcall_cb */ dpif_netlink_get_datapath_version, /* get_datapath_version */ dpif_netlink_ct_dump_start, dpif_netlink_ct_dump_next, diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index b817fceac..589f11be4 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -427,6 +427,16 @@ struct dpif_class { /* Disables upcalls if 'dpif' directly executes upcall functions. */ void (*disable_upcall)(struct dpif *); + /* When offloading sample action, psample sends the sampled packets to + * userspace by a netlink message. The thread polling psample socket + * will translate the psample netlink message to an sFlow format and call + * the sFlow upcall callback to send the sFlow packet to right monitoring + * host. + * + * Registers an upcall callback to process sFlow packet. + */ + void (*register_sflow_upcall_cb)(struct dpif *, sflow_upcall_callback *); + /* Get datapath version. Caller is responsible for freeing the string * returned. */ char *(*get_datapath_version)(void); diff --git a/lib/dpif.c b/lib/dpif.c index 56d0b4a65..c03ad6a31 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1520,6 +1520,14 @@ dpif_disable_upcall(struct dpif *dpif) } } +void +dpif_register_sflow_upcall_cb(struct dpif *dpif, sflow_upcall_callback *cb) +{ + if (dpif->dpif_class->register_sflow_upcall_cb) { + dpif->dpif_class->register_sflow_upcall_cb(dpif, cb); + } +} + void dpif_print_packet(struct dpif *dpif, struct dpif_upcall *upcall) { diff --git a/lib/dpif.h b/lib/dpif.h index ecda896c7..aac0c2b46 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -871,6 +871,29 @@ typedef int upcall_callback(const struct dp_packet *packet, void dpif_register_upcall_cb(struct dpif *, upcall_callback *, void *aux); +/* When offloading sample action, userspace creates a unique ID to map + * sFlow action and tunnel info and passes this ID to datapath instead + * of the sFlow info. Datapath will send this ID and sampled packet to + * userspace. Using the ID, userspace can recover the sFlow info and send + * sampled packet to the right sFlow monitoring host. + */ +struct dpif_sflow_attr { + const struct nlattr *sflow; /* sFlow action */ + void *userdata; /* struct user_action_cookie */ + size_t userdata_len; /* struct user_action_cookie length */ + struct flow_tnl *tunnel; /* Tunnel info */ +}; + +/* A sampled packet passed up from datapath to userspace. */ +struct dpif_upcall_sflow { + struct dp_packet packet; /* packet data */ + uint32_t iifindex; /* input ifindex */ + const struct dpif_sflow_attr *sflow_attr; +}; + +typedef int sflow_upcall_callback(struct dpif_upcall_sflow *dupcall); +void dpif_register_sflow_upcall_cb(struct dpif *, sflow_upcall_callback *); + int dpif_recv_set(struct dpif *, bool enable); int dpif_handlers_set(struct dpif *, uint32_t n_handlers); int dpif_set_config(struct dpif *, const struct smap *cfg);