From patchwork Wed Mar 29 07:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1762602 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=WaONQJ2z; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PmdKK0sKHz1yYr for ; Wed, 29 Mar 2023 18:21:57 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id D9C0F41DE5; Wed, 29 Mar 2023 07:21:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org D9C0F41DE5 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=WaONQJ2z X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dD1Zt_yui4NW; Wed, 29 Mar 2023 07:21:50 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id F0B3141DCB; Wed, 29 Mar 2023 07:21:48 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org F0B3141DCB Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BADB2C008A; Wed, 29 Mar 2023 07:21:48 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 23207C0091 for ; Wed, 29 Mar 2023 07:21:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id E86A084094 for ; Wed, 29 Mar 2023 07:21:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org E86A084094 Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=WaONQJ2z X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q-xcNpvaRAq6 for ; Wed, 29 Mar 2023 07:21:39 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org B0BC884062 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2062f.outbound.protection.outlook.com [IPv6:2a01:111:f400:7ea9::62f]) by smtp1.osuosl.org (Postfix) with ESMTPS id B0BC884062 for ; Wed, 29 Mar 2023 07:21:39 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lIqAGZBbTCbYB6n3En52GUbHbVNlUVjOCAUDV/AhNzHQyy7eruQgXkB0FU62z/a9/jwdc6l3nyFh02Gipx/LeTnly6e9VQYyLZl30pkxKgpVef113chsHb1nTrtLbiQj9pplMq+kipVJ2TPlzVzTbCScXBR/KZDwu+DVOQzwIn3TCrNv7Tdi0K7c+WKB6+u+VvK2M51LjHM6oK/zspraEDEMbYLUZBX0xE759mmDd8AxM0w8DlO6JqOkqWmx4FIm42o3UGqB9JabwQILlFqADjI4XSnNwwYmWUz188AUxgyZQLpMEFb5PDz+Q24HDrlXpA8iqwkkupFxpoIv4yg0Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xUNVn8elQtZ7Q9j48qtTxnYhAjqrs8uZCFYXZ3h9LcU=; b=Yr4JndCAHfuCjOZHgNl13uO3mjkb1fgBkDyGSFrifIsinpwHgXGtEkKOCDiJ6DOwb2kvstJrJ/52MQ/zmP8LKB4Ct7NmkH5V4zHjsisth4YMw1U1hVUHlPnEmEYpSgWFZVIfEhaIL66pV/70rqeuw5x+5zKR/VcwjSIXKQX2zH3sx31S4k7LqaJfYhDXN/ur6QK3yOrPt+ZgjdSOncPto6BerwSrpVvAoo6D1PwvDxradNe9t9Aj7ZmrwSqNNyCQYZCY9tv7hJKeEKuCgFU7vApQAEb/eRPBo+sXWarx9z4QvR3/DgWqOV/Dsw2PNF9kfSMOYUFew2f92cXdzyNz3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=openvswitch.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xUNVn8elQtZ7Q9j48qtTxnYhAjqrs8uZCFYXZ3h9LcU=; b=WaONQJ2z3P7xVIVpzASZg5SSc4kKb//9rPICwVEc/O9GrFWD6hgy0RUMV6EdmTU0vubIqaszQWxq9x+BmwsRodyjlezoYgac0Od4DymJ55aHyzrUO0q6owNAoBGmSurT/YJSPjjwBwolqLHZt48PeuVBrIgvlYZWjCNUtloHJPc/93B4mewtZpEwAdiP4aQz+GURQSMFl45FUPU6A9hD4Cr6gvePRN2sJpppdrlz4js808OTgGThoCwoE1SJkkTKyiYRrhIAibi0by5eQYaHSJyUaD7yQfXhD+VISwBiNPzyzy895s/ToyHg+R4G2Zexg9FEWT/ZMHBeZK6efKusaw== Received: from BL1PR13CA0344.namprd13.prod.outlook.com (2603:10b6:208:2c6::19) by PH0PR12MB5435.namprd12.prod.outlook.com (2603:10b6:510:ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.33; Wed, 29 Mar 2023 07:21:36 +0000 Received: from BL02EPF000100D0.namprd05.prod.outlook.com (2603:10b6:208:2c6:cafe::1a) by BL1PR13CA0344.outlook.office365.com (2603:10b6:208:2c6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.20 via Frontend Transport; Wed, 29 Mar 2023 07:21:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF000100D0.mail.protection.outlook.com (10.167.241.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.30 via Frontend Transport; Wed, 29 Mar 2023 07:21:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 29 Mar 2023 00:21:19 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 29 Mar 2023 00:21:19 -0700 Received: from c-237-115-60-065.mtl.labs.mlnx (10.127.8.10) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 29 Mar 2023 00:21:16 -0700 To: Date: Wed, 29 Mar 2023 10:20:55 +0300 Message-ID: <20230329072059.78569-5-cmi@nvidia.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20230329072059.78569-1-cmi@nvidia.com> References: <20230329072059.78569-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000100D0:EE_|PH0PR12MB5435:EE_ X-MS-Office365-Filtering-Correlation-Id: 04601c43-2ba1-4dba-9759-08db30263b53 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K/1IStTcRZhP6CDCf4ivCmq146QEH4d0qklKtStl5YnUG6x8ffbF/igiaOFaTAInvYyAvS+EkUGFxHoKlFQVaZ7HQ9Djmcv7Jfn1LZJ6rfhDDzkAErjHi4Lzdqw32qsffYl9KQNE5jdePeA84kB+U50Bz8ChBkaGUHa6aAtD/XSmyUdRUOU9iqRlwGY8HV5UiV0r8imRL7HrPyRrgbb7BqOIQLUaOxY5PXYvV4R0bbr/0hDa0jTnePXE92OG4JIwwyMwhZqj8vUmRUMaB8vHRpzfoHnhgXJVqGIqRi0jKs+RwR8jBOwKxxQyn1qlFE6Ng7ddOFc0nDKlq6SFfo5xGmYJkGrdkfoA0bP89k9OPMK4Cb/3ud9Hd5KSMR7sdO9z6tWXvyP02tKfvdJimtXvsLGUnJKId6v+TXGqzuOad+43B7R+HJ6WIlXGu+iqXxzjXy/F+cUlj5r1dMdFHcJCsS74U3RGBlZq01B8H6qcABhppracm1EwmisePwVZeW1Bl/0Z0U4WDDwOP+9vTjzTuJgBmuuOHI/9ecHkAuI/gL8275NKVTkPIDmirGnfJulCSU4kUUgmgpid6A8IHGR2nYQvKBWPjzWHjZyWr8EakZmEUyMlxtoJtvy+XP0qrMkoQkgFf582acERHgFuIXGHFc7/zS+W8rgCjXxnE5yjs1SlMJ0YGZRQyRbNkInkjd49NQoLWxhO/bFwNo2Pi1HR6zHI2y3sCH0NRFE2yJzMPetH6reLWMBJlnHXTeee/oHk X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230028)(4636009)(136003)(376002)(396003)(346002)(39860400002)(451199021)(36840700001)(46966006)(40470700004)(82310400005)(82740400003)(356005)(5660300002)(2906002)(8936002)(41300700001)(316002)(478600001)(47076005)(6916009)(70206006)(8676002)(70586007)(4326008)(54906003)(26005)(36756003)(83380400001)(107886003)(1076003)(186003)(6666004)(2616005)(336012)(426003)(36860700001)(7636003)(40460700003)(86362001)(40480700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2023 07:21:36.3406 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04601c43-2ba1-4dba-9759-08db30263b53 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF000100D0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5435 Cc: elibr@nvidia.com, simon.horman@corigine.com, roniba@nvidia.com, i.maximets@ovn.org, konguyen@redhat.com, majd@nvidia.com, maord@nvidia.com Subject: [ovs-dev] [PATCH v25 4/8] netdev-offload-tc: Add sample offload API for TC 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Initialize psample socket. Add sample recv API to receive sampled packets from psample socket. Add sample recv wait API to add psample socket fd to poll list. Signed-off-by: Chris Mi Reviewed-by: Roi Dayan --- lib/dpif.h | 6 +- lib/netdev-offload-provider.h | 17 +++ lib/netdev-offload-tc.c | 192 ++++++++++++++++++++++++++++++++++ lib/netdev-offload.c | 3 +- 4 files changed, 215 insertions(+), 3 deletions(-) diff --git a/lib/dpif.h b/lib/dpif.h index 129cbf6a1..5b094ce68 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -834,8 +834,10 @@ struct dpif_upcall { /* DPIF_UC_ACTION only. */ struct nlattr *userdata; /* Argument to OVS_ACTION_ATTR_USERSPACE. */ - struct nlattr *out_tun_key; /* Output tunnel key. */ - struct nlattr *actions; /* Argument to OVS_ACTION_ATTR_USERSPACE. */ + struct nlattr *out_tun_key; /* Output tunnel key. */ + struct nlattr *actions; /* Argument to OVS_ACTION_ATTR_USERSPACE. */ + struct flow flow; /* Caller provide 'flow' if 'key' is not + available. */ }; /* A callback to notify higher layer of dpif about to be purged, so that diff --git a/lib/netdev-offload-provider.h b/lib/netdev-offload-provider.h index 9108856d1..b3bf433d0 100644 --- a/lib/netdev-offload-provider.h +++ b/lib/netdev-offload-provider.h @@ -28,6 +28,8 @@ extern "C" { #endif +struct dpif_upcall; + struct netdev_flow_api { char *type; /* Flush all offloaded flows from a netdev. @@ -121,6 +123,21 @@ struct netdev_flow_api { int (*meter_del)(ofproto_meter_id meter_id, struct ofputil_meter_stats *stats); + /* Polls for sample offload packets for an upcall handler. If successful, + * stores the upcall into '*upcall', using 'buf' for storage. + * + * Return 0 if successful, otherwise returns a positive errno value. + * + * This function must not block. If no upcall is pending when it is + * called, it should return EAGAIN without blocking. */ + int (*recv)(struct dpif_upcall *upcall, struct ofpbuf *buf, + uint32_t handler_id); + + /* Arranges for the poll loop for an upcall handler to wake up when + * sample socket has a message queued to be received with the recv + * member functions. */ + void (*recv_wait)(uint32_t handler_id); + /* Initializies the netdev flow api. * Return 0 if successful, otherwise returns a positive errno value. */ int (*init_flow_api)(struct netdev *); diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 6ac40b663..8fa6e731b 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -18,6 +18,8 @@ #include #include +#include +#include #include "dpif.h" #include "hash.h" @@ -124,6 +126,9 @@ struct sgid_node { struct offload_sample sample; }; +static struct nl_sock *psample_sock; +static int psample_family; + static struct ovs_mutex sgid_lock = OVS_MUTEX_INITIALIZER; static struct cmap sgid_map = CMAP_INITIALIZER; static struct id_pool *sample_group_ids OVS_GUARDED_BY(sgid_lock); @@ -148,6 +153,14 @@ sgid_find(uint32_t id) return node ? CONTAINER_OF(node, struct sgid_node, id_node) : NULL; } +static struct offload_sample * +sample_find(uint32_t id) +{ + struct sgid_node *node = sgid_find(id); + + return node ? &node->sample: NULL; +} + static void offload_sample_clone(struct offload_sample *new, const struct offload_sample *old) @@ -2930,6 +2943,55 @@ tc_cleanup_policer_actions(struct id_pool *police_ids, hmap_destroy(&map); } +static void +psample_init(void) +{ + unsigned int psample_mcgroup; + int err; + + if (!netdev_is_flow_api_enabled()) { + VLOG_DBG("Flow API is not enabled"); + return; + } + + if (psample_sock) { + VLOG_DBG("Psample socket is already initialized"); + return; + } + + err = nl_lookup_genl_family(PSAMPLE_GENL_NAME, + &psample_family); + if (err) { + VLOG_INFO("Generic Netlink family '%s' does not exist: %s\n" + "Please make sure the kernel module psample is loaded", + PSAMPLE_GENL_NAME, ovs_strerror(err)); + return; + } + + err = nl_lookup_genl_mcgroup(PSAMPLE_GENL_NAME, + PSAMPLE_NL_MCGRP_SAMPLE_NAME, + &psample_mcgroup); + if (err) { + VLOG_INFO("Failed to join Netlink multicast group '%s': %s", + PSAMPLE_NL_MCGRP_SAMPLE_NAME, ovs_strerror(err)); + return; + } + + err = nl_sock_create(NETLINK_GENERIC, &psample_sock); + if (err) { + VLOG_INFO("Failed to create psample socket: %s", ovs_strerror(err)); + return; + } + + err = nl_sock_join_mcgroup(psample_sock, psample_mcgroup); + if (err) { + VLOG_INFO("Failed to join psample mcgroup: %s", ovs_strerror(err)); + nl_sock_destroy(psample_sock); + psample_sock = NULL; + return; + } +} + static int netdev_tc_init_flow_api(struct netdev *netdev) { @@ -2989,6 +3051,7 @@ netdev_tc_init_flow_api(struct netdev *netdev) ovs_mutex_lock(&sgid_lock); sample_group_ids = id_pool_create(1, UINT32_MAX - 1); ovs_mutex_unlock(&sgid_lock); + psample_init(); ovsthread_once_done(&once); } @@ -3205,6 +3268,133 @@ meter_tc_del_policer(ofproto_meter_id meter_id, return err; } +struct offload_psample { + struct nlattr *packet; /* Packet data. */ + uint32_t group_id; /* Mapping id for sample offload. */ + uint16_t iifindex; /* Input ifindex. */ +}; + +static int +nl_parse_psample(struct offload_psample *psample, struct ofpbuf *buf) +{ + static const struct nl_policy ovs_psample_policy[] = { + [PSAMPLE_ATTR_IIFINDEX] = { .type = NL_A_U16, .optional = true, }, + [PSAMPLE_ATTR_SAMPLE_GROUP] = { .type = NL_A_U32 }, + [PSAMPLE_ATTR_GROUP_SEQ] = { .type = NL_A_U32 }, + [PSAMPLE_ATTR_DATA] = { .type = NL_A_UNSPEC }, + }; + struct nlattr *a[ARRAY_SIZE(ovs_psample_policy)]; + struct genlmsghdr *genl; + struct nlmsghdr *nlmsg; + struct ofpbuf b; + + b = ofpbuf_const_initializer(buf->data, buf->size); + nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg); + genl = ofpbuf_try_pull(&b, sizeof *genl); + if (!nlmsg || !genl || nlmsg->nlmsg_type != psample_family + || !nl_policy_parse(&b, 0, ovs_psample_policy, a, + ARRAY_SIZE(ovs_psample_policy))) { + return EINVAL; + } + + if (a[PSAMPLE_ATTR_IIFINDEX]) { + psample->iifindex = nl_attr_get_u16(a[PSAMPLE_ATTR_IIFINDEX]); + } + psample->group_id = nl_attr_get_u32(a[PSAMPLE_ATTR_SAMPLE_GROUP]); + psample->packet = a[PSAMPLE_ATTR_DATA]; + + return 0; +} + +static int +psample_parse_packet(struct offload_psample *psample, + struct dpif_upcall *upcall) +{ + struct flow *flow = &upcall->flow; + struct offload_sample *sample; + + memset(upcall, 0, sizeof *upcall); + dp_packet_use_const(&upcall->packet, + nl_attr_get(psample->packet), + nl_attr_get_size(psample->packet)); + + sample = sample_find(psample->group_id); + if (!sample) { + VLOG_ERR_RL(&error_rl, "failed to get sample info via group id: %d", + psample->group_id); + return ENOENT; + } + + upcall->userdata = sample->userdata; + if (sample->tunnel) { + memcpy(&flow->tunnel, sample->tunnel, sizeof flow->tunnel); + } + if (sample->actions) { + upcall->actions = sample->actions; + } + if (psample->iifindex) { + flow->in_port.odp_port = netdev_ifindex_to_odp_port(psample->iifindex); + } + upcall->type = DPIF_UC_ACTION; + + return 0; +} + +static int +netdev_tc_recv(struct dpif_upcall *upcall, struct ofpbuf *buf, + uint32_t handler_id) +{ + int read_tries = 0; + + if (handler_id) { + return EAGAIN; + } + + if (!psample_sock) { + return EAGAIN; + } + + for (;;) { + struct offload_psample psample; + int error; + + if (++read_tries > 50) { + return EAGAIN; + } + + error = nl_sock_recv(psample_sock, buf, NULL, false); + if (error == ENOBUFS) { + continue; + } + + if (error) { + if (error == EAGAIN) { + break; + } + return error; + } + + memset(&psample, 0, sizeof psample); + error = nl_parse_psample(&psample, buf); + + return error ? error : psample_parse_packet(&psample, upcall); + } + + return EAGAIN; +} + +static void +netdev_tc_recv_wait(uint32_t handler_id) +{ + if (handler_id) { + return; + } + + if (psample_sock) { + nl_sock_wait(psample_sock, POLLIN); + } +} + const struct netdev_flow_api netdev_offload_tc = { .type = "linux_tc", .flow_flush = netdev_tc_flow_flush, @@ -3218,5 +3408,7 @@ const struct netdev_flow_api netdev_offload_tc = { .meter_set = meter_tc_set_policer, .meter_get = meter_tc_get_policer, .meter_del = meter_tc_del_policer, + .recv = netdev_tc_recv, + .recv_wait = netdev_tc_recv_wait, .init_flow_api = netdev_tc_init_flow_api, }; diff --git a/lib/netdev-offload.c b/lib/netdev-offload.c index 4592262bd..84503ec8b 100644 --- a/lib/netdev-offload.c +++ b/lib/netdev-offload.c @@ -38,6 +38,7 @@ #include "netdev-provider.h" #include "netdev-vport.h" #include "odp-netlink.h" +#include "odp-util.h" #include "openflow/openflow.h" #include "packets.h" #include "openvswitch/ofp-print.h" @@ -820,7 +821,7 @@ odp_port_t netdev_ifindex_to_odp_port(int ifindex) { struct port_to_netdev_data *data; - odp_port_t ret = 0; + odp_port_t ret = ODPP_NONE; ovs_rwlock_rdlock(&netdev_hmap_rwlock); HMAP_FOR_EACH_WITH_HASH (data, ifindex_node, ifindex, &ifindex_to_port) {