From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2EC4FA00C2; Fri, 24 Apr 2020 22:59:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 42D6C1D147; Fri, 24 Apr 2020 22:59:36 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 3BE271B53 for ; Fri, 24 Apr 2020 22:59:34 +0200 (CEST) IronPort-SDR: Ll5yJC6AKx/ezPYsRgrT1cLoK4fXekta1/jrN9KJ64gxB3d94m64gUZSU4fElcjmtmcDE1LD13 YrQbnu4EodhA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2020 13:59:33 -0700 IronPort-SDR: ISBbOItcXyztXxozBcrGHavh+8W8qhNo543iCZMfFVoaECbT8bsMmOK47XZ2B67tTtroibo7gd xJG4lau7LYEA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,313,1583222400"; d="scan'208";a="301678728" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 24 Apr 2020 13:59:33 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 24 Apr 2020 13:59:24 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Fri, 24 Apr 2020 13:59:23 -0700 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Fri, 24 Apr 2020 13:59:23 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.103) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 24 Apr 2020 13:59:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bd5IIOP08w30eCFOxCloWrjZksJGJf5cjYzatF8SmPZaYUHW089fh4Lr2p45SfJ5d9yZvbJ8Jv/Zio8JDSG9cSei1gbVl45V/tT9FtKzmuCu11it0w7Leu2l3r7VJ0hzRywyW8O3iumD0BDsbsNAsCRV/rdt7gXi90Z3Tbm+JnTt1sT7spDzgFAQcN1xOk0+xipmTLLNOaRwMCg20fiKfJZF6zPKYkVbkopl5ZsYvxMSeoNI31zk20o9W9Orj9XqsS7j5aABaBQ6GnZp4DvorG3+N4wkO+MtTQBb9chn8fEHzXzMffdv8sNXaCTYqUI8qyN9d3wGXv3c/lkHDzVRqA== 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-SenderADCheck; bh=H7NkW3I4M2OD482ef/SHTtsIvsgTpPG0lIoYu0hgyt8=; b=LsFQP8mPogMKnqSy6Agw0WV9pWbfVhrsu7lpnzDR4uRLiJPztrNiWc8fj6DPTfPPe7jtkq9TEGEe03FSQvxRQ1nJBugC4+UUyadyFLwyqKPufQJZeSXaZyhYAlN9ftPT8//3PvPKbDbiW4jj1kcgzYe/fhjkVr3tkwkqYfGSPggGP7fnVvJZYU0RHJsXzpAbe1HkhzrSUJzBdFLfkNh0QPi46FiCf5MNNWLJ95TW2Qx311iMLZ7PMsGVunVf2ZoRvx0GtRRculKIlDKS8I67rUaPAj7ZW2xW7euvuATLEDbOmfn+Xo/nDhrb7zMltieZCPxjw3+oFPdph1mEi+Pjzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H7NkW3I4M2OD482ef/SHTtsIvsgTpPG0lIoYu0hgyt8=; b=nifJzBNYfotMsFgtrk2+UEHQbKK0cfZCesc2ervXfCNbM86xlXrylOW953+VZM5KjnqYihqWxMQqNNKd/C64WtFoBiag8qKqVIUz0Uqw69Dq/kZEKjDyr7XcF2MCrjjwegypCe3Z4peN7aKBV0OFz+mHtEFHgEgrnhe+ClhGfB8= Received: from DM6PR11MB4593.namprd11.prod.outlook.com (2603:10b6:5:2a3::8) by DM6PR11MB4204.namprd11.prod.outlook.com (2603:10b6:5:206::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Fri, 24 Apr 2020 20:59:18 +0000 Received: from DM6PR11MB4593.namprd11.prod.outlook.com ([fe80::acee:4fa2:2a9e:7cd6]) by DM6PR11MB4593.namprd11.prod.outlook.com ([fe80::acee:4fa2:2a9e:7cd6%3]) with mapi id 15.20.2937.020; Fri, 24 Apr 2020 20:59:18 +0000 From: "Wiles, Keith" To: "Power, Ciara" CC: dev , "Laatz, Kevin" , "Pattan, Reshma" , "jerinjacobk@gmail.com" , "david.marchand@redhat.com" , "mb@smartsharesystems.com" , "thomas@monjalon.net" Thread-Topic: [PATCH v4 13/18] telemetry: introduce telemetry backward compatibility Thread-Index: AQHWGjizXFJw5pCKjUCOc7RVLeHqh6iIwf2A Date: Fri, 24 Apr 2020 20:59:18 +0000 Message-ID: <7874FF63-D512-4583-8101-44A7CF98A630@intel.com> References: <20200319171907.60891-1-ciara.power@intel.com> <20200424124159.45989-1-ciara.power@intel.com> <20200424124159.45989-14-ciara.power@intel.com> In-Reply-To: <20200424124159.45989-14-ciara.power@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=keith.wiles@intel.com; x-originating-ip: [47.24.6.94] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: dc1a842d-1730-47c7-d16e-08d7e8925ae3 x-ms-traffictypediagnostic: DM6PR11MB4204: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-forefront-prvs: 03838E948C x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4593.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(376002)(396003)(136003)(39860400002)(366004)(346002)(71200400001)(66556008)(186003)(36756003)(316002)(2616005)(6862004)(91956017)(30864003)(26005)(81156014)(76116006)(66476007)(478600001)(53546011)(66946007)(86362001)(37006003)(64756008)(8676002)(54906003)(8936002)(33656002)(66446008)(6486002)(6506007)(6636002)(2906002)(4326008)(6512007)(5660300002); DIR:OUT; SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: UGqdofk4Hoxre8OEalCGVC27mdrk2iSVVGKRChdQ34Hur07Ou6ELU+H2MhLDAUwmKi+PztqznvYYCGVkMN52kSO1gD+T5Gv1RJTC+nYGZUVQqCy78HZNxi59qH17jk8UXWvEfzj+yNmrSrdVUkQV0mFDZ2bDNaflUmIq5gmZB2WYfT5VGc92X4RkFsszaIspF0tKM65hepCehsgjaYw0BMCXW4F+0I5qwXRikn1JjQn7BE40kj7wpaHEUgacL4ESca/1N1vlPbqAz3RZi5me6iyT7hzRnfbl5t35O6b8Hs54X6bJCkQC/iUk/Qi1ymo7QvD5UvwqRv7Q7ljHSD+CnWjUM+SGz6WMCsMRJmGXrxG5LBoclAgKjYxX5jWZ1CsSyNVgL/vlfGkRoVGh1buKEGkq0hoVYGt5LzttDnPl4jQlTskcdv+T2Rb5HvE+qo0j x-ms-exchange-antispam-messagedata: AcoE/QlyaFYq5vzng4oOMltdHvsyrZwrd+dBHBzDoUCgzIBy209w3Vsdb/eda1TGTn3/HU0Ix5VMnuspmM6PKTWzaw4z5320HZzRFJWqUxXOvc3In/rUQapE/7hxd6pObGHcHD+WBv+rXgL3A99if1x8Yb9rqSJgxo6R+x7MQPdx6utlZOfASvhthKBxVMLI3+D4xXL1uhZ9qUHJZHkZ88/txDdzh0y9Z+rdBmJQkNxdul+M9G1up3RWDRUNZVcvyN8d2n+38JuPnmi72yIEf6NcwRTiNdJsRU9N7l1hAJA5BB5NVp75lvfjAdcjPr/HEW+tCQDJNFPfQuVeBtg8QE8H1ijeHPiyxpG0kTcREx9eaQOisefRVilmQnsnuFmd0e/bwBlAT6Ui9Uvk9KLMUd9fwFCgrWDsAV8GV3c4ZOG4LhNBEIA4pg7wucP46i2IHiAFj6jKfx1eQA/bceAECT6Vp+twevaFsQMNQlvIZe2VSmDtHsBagBoT6aRyyXG4I18MKEgnA5imhbCG2BDwuoU9io1lLH2SI6CDdk/W8s8s8AAtm6VA8yZtf8V5W1akB9kxsP8ry5sUaGj2zPa/jBXcmco10S2BiliP9+M+q8L4IEHf37bZecnHqXmU11k82EY6Px0ntlTLfJmIAUoYh4mL81rtOh27bZ8uobL+w83NUxdp8ziV/jUywjFPIdMSF44E475Ars2tdbSPS1W763g1BP5VhiXoc3oezfpp9MF8X1+31dP5vOa7X3FggfT4aEwqlowOJ/MI7M1I6GEfXnRiXpJ6dtX33/2x3W88c90= Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: dc1a842d-1730-47c7-d16e-08d7e8925ae3 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Apr 2020 20:59:18.2211 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: U5zxR4/knqD4vHHTXTBwxDjvUOyIu8iqEdPl3feuuuwBbpts0KdcuSWLaFq47WaH0L7XAFJxwMzUNjN2Oc/psg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4204 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v4 13/18] telemetry: introduce telemetry backward compatibility X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > On Apr 24, 2020, at 7:41 AM, Power, Ciara wrote: >=20 > The new telemetry will now open a socket using the old telemetry path, > to ensure backward compatibility. This is not yet initialised, as it > would clash with the existing telemetry, to be removed in a later patch. > This means that both old and new telemetry socket interfaces are > handled in a common way. >=20 > Signed-off-by: Ciara Power >=20 > --- > v4: Added legacy callback typedef > --- > lib/librte_metrics/rte_metrics_telemetry.c | 113 +++++++++ > lib/librte_telemetry/Makefile | 1 + > lib/librte_telemetry/meson.build | 2 +- > lib/librte_telemetry/rte_telemetry_legacy.h | 87 +++++++ > .../rte_telemetry_version.map | 2 + > lib/librte_telemetry/telemetry.c | 31 +++ > lib/librte_telemetry/telemetry_legacy.c | 227 ++++++++++++++++++ > 7 files changed, 462 insertions(+), 1 deletion(-) > create mode 100644 lib/librte_telemetry/rte_telemetry_legacy.h > create mode 100644 lib/librte_telemetry/telemetry_legacy.c >=20 > diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metr= ics/rte_metrics_telemetry.c > index 31d505551b..49de9d74b5 100644 > --- a/lib/librte_metrics/rte_metrics_telemetry.c > +++ b/lib/librte_metrics/rte_metrics_telemetry.c > @@ -8,6 +8,7 @@ > #include > #ifdef RTE_LIBRTE_TELEMETRY > #include > +#include > #endif >=20 > #include "rte_metrics.h" > @@ -417,6 +418,112 @@ rte_metrics_tel_extract_data(struct telemetry_encod= e_param *ep, json_t *data) > return 0; > } >=20 > +static int > +rte_metrics_tel_initial_metrics_setup(void) > +{ > + int ret; > + rte_metrics_init(rte_socket_id()); > + > + if (!tel_met_data.metrics_register_done) { > + ret =3D rte_metrics_tel_reg_all_ethdev( > + &tel_met_data.metrics_register_done, > + tel_met_data.reg_index); > + if (ret < 0) > + return ret; > + } > + return 0; > +} > + > +static int > +handle_ports_all_stats_values(const char *cmd __rte_unused, > + const char *params __rte_unused, > + char *buffer, int buf_len) > +{ > + struct telemetry_encode_param ep; > + int ret, used =3D 0; > + char *json_buffer =3D NULL; > + > + ret =3D rte_metrics_tel_initial_metrics_setup(); > + if (ret < 0) > + return ret; > + > + memset(&ep, 0, sizeof(ep)); > + ret =3D rte_metrics_tel_get_port_stats_ids(&ep); > + if (ret < 0) > + return ret; > + > + ret =3D rte_metrics_tel_get_ports_stats_json(&ep, tel_met_data.reg_inde= x, > + &json_buffer); > + if (ret < 0) > + return ret; > + > + used +=3D strlcpy(buffer, json_buffer, buf_len); > + return used; > +} > + > +static int > +handle_global_stats_values(const char *cmd __rte_unused, > + const char *params __rte_unused, > + char *buffer, int buf_len) > +{ > + char *json_buffer =3D NULL; > + struct telemetry_encode_param ep =3D { .type =3D GLOBAL_STATS }; > + int ret, used =3D 0; > + > + ret =3D rte_metrics_tel_initial_metrics_setup(); > + if (ret < 0) > + return ret; > + > + ret =3D rte_metrics_tel_encode_json_format(&ep, &json_buffer); > + if (ret < 0) { > + METRICS_LOG_ERR("JSON encode function failed"); > + return ret; > + } > + used +=3D strlcpy(buffer, json_buffer, buf_len); > + return used; > +} > + > +static int > +handle_ports_stats_values_by_name(const char *cmd __rte_unused, > + const char *params, > + char *buffer, int buf_len) > +{ > + char *json_buffer =3D NULL; > + struct telemetry_encode_param ep; > + int ret, used =3D 0; > + json_t *data; > + json_error_t error; > + > + ret =3D rte_metrics_tel_initial_metrics_setup(); > + if (ret < 0) > + return ret; > + > + data =3D json_loads(params, 0, &error); > + if (!data) { > + METRICS_LOG_WARN("Could not load JSON object from data passed in : %s"= , > + error.text); > + return -EPERM; > + } else if (!json_is_object(data)) { > + METRICS_LOG_WARN("JSON Request data is not a JSON object"); > + json_decref(data); > + return -EINVAL; > + } > + > + ret =3D rte_metrics_tel_extract_data(&ep, data); > + if (ret < 0) { > + METRICS_LOG_ERR("Extract data function failed"); > + return ret; > + } > + > + ret =3D rte_metrics_tel_encode_json_format(&ep, &json_buffer); > + if (ret < 0) { > + METRICS_LOG_ERR("JSON encode function failed"); > + return ret; > + } > + used +=3D strlcpy(buffer, json_buffer, buf_len); > + return used; > +} > + > RTE_INIT(metrics_ctor) > { > #ifdef RTE_LIBRTE_TELEMETRY > @@ -428,6 +535,12 @@ RTE_INIT(metrics_ctor) > .extract_data =3D rte_metrics_tel_extract_data > }; > rte_telemetry_set_metrics_fns(&fns); /* assign them to telemetry lib */ > + rte_telemetry_legacy_register("ports_all_stat_values", DATA_NOT_REQ, > + handle_ports_all_stats_values); > + rte_telemetry_legacy_register("global_stat_values", DATA_NOT_REQ, > + handle_global_stats_values); > + rte_telemetry_legacy_register("ports_stats_values_by_name", DATA_REQ, > + handle_ports_stats_values_by_name); > #endif > metrics_log_level =3D rte_log_register("lib.metrics"); > if (metrics_log_level >=3D 0) > diff --git a/lib/librte_telemetry/Makefile b/lib/librte_telemetry/Makefil= e > index 5457d1ed4f..260dce3e3d 100644 > --- a/lib/librte_telemetry/Makefile > +++ b/lib/librte_telemetry/Makefile > @@ -25,6 +25,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) +=3D rte_telemetry_= parser.c > SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) +=3D rte_telemetry_parser_test.c > SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) +=3D telemetry.c > SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) +=3D telemetry_data.c > +SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) +=3D telemetry_legacy.c >=20 > # export include files > SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include :=3D rte_telemetry.h > diff --git a/lib/librte_telemetry/meson.build b/lib/librte_telemetry/meso= n.build > index 80926936a5..5bcef6c81f 100644 > --- a/lib/librte_telemetry/meson.build > +++ b/lib/librte_telemetry/meson.build > @@ -4,7 +4,7 @@ > includes =3D [global_inc] >=20 > sources =3D files('rte_telemetry.c', 'rte_telemetry_parser.c', 'rte_telem= etry_parser_test.c', > - 'telemetry.c', 'telemetry_data.c') > + 'telemetry.c', 'telemetry_data.c', 'telemetry_legacy.c') > headers =3D files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_tel= emetry_parser.h') > includes +=3D include_directories('../librte_metrics') >=20 > diff --git a/lib/librte_telemetry/rte_telemetry_legacy.h b/lib/librte_tel= emetry/rte_telemetry_legacy.h > new file mode 100644 > index 0000000000..c83f9a8d90 > --- /dev/null > +++ b/lib/librte_telemetry/rte_telemetry_legacy.h > @@ -0,0 +1,87 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2020 Intel Corporation > + */ > + > +#ifndef _RTE_TELEMETRY_LEGACY_H_ > +#define _RTE_TELEMETRY_LEGACY_H_ > + > +#include > +#include "rte_telemetry.h" > + > +/** > + * @internal > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice > + > + * @file > + * RTE Telemetry Legacy > + * > + ***/ > + > +/** > + * @internal > + * Value representing if data is required for the command > + */ > +enum rte_telemetry_legacy_data_req { > + DATA_NOT_REQ =3D 0, > + DATA_REQ > +}; > + > +/** > + * This telemetry callback is used when registering a legacy telemetry c= ommand. > + * It handles getting and formatting stats to be returned to telemetry w= hen > + * requested. Stats up to buf_len in length are put in the buffer. > + * > + * @param cmd > + * The cmd that was requested by the client. > + * @param params > + * Contains data required by the callback function. > + * @param buffer > + * A buffer to hold the formatted response. > + * @param buf_len > + * Length of the buffer. > + * > + * @return > + * Length of buffer used on success. > + * @return > + * Negative integer on error. > + */ > +typedef int (*telemetry_legacy_cb)(const char *cmd, const char *params, > + char *buffer, int buf_len); > + > +/** > + * @internal > + * Counter for the number of registered legacy callbacks > + */ > +extern int num_legacy_callbacks; > + > +/** > + * @internal > + * Used for handling data received over the legacy telemetry socket. > + * > + * @return > + * Void. > + */ > +void * > +legacy_client_handler(void *sock_id); > + > +/** > + * @internal > + * > + * Used when registering a command and callback function with > + * telemetry legacy support. > + * > + * @return > + * 0 on success. > + * @return > + * -EINVAL for invalid parameters failure. > + * @return > + * -ENOENT if max callbacks limit has been reached. > + */ > +__rte_experimental > +int > +rte_telemetry_legacy_register(const char *cmd, > + enum rte_telemetry_legacy_data_req data_req, > + telemetry_legacy_cb fn); > + > +#endif > diff --git a/lib/librte_telemetry/rte_telemetry_version.map b/lib/librte_= telemetry/rte_telemetry_version.map > index e433ce58b7..36eac75c4e 100644 > --- a/lib/librte_telemetry/rte_telemetry_version.map > +++ b/lib/librte_telemetry/rte_telemetry_version.map > @@ -17,6 +17,8 @@ EXPERIMENTAL { > rte_tel_data_start_array; > rte_tel_data_start_dict; > rte_tel_data_string; > + rte_telemetry_legacy_init; > + rte_telemetry_legacy_register; >=20 > local: *; > }; > diff --git a/lib/librte_telemetry/telemetry.c b/lib/librte_telemetry/tele= metry.c > index 63986378d8..f7e51be07c 100644 > --- a/lib/librte_telemetry/telemetry.c > +++ b/lib/librte_telemetry/telemetry.c > @@ -18,6 +18,7 @@ > #include "rte_telemetry.h" > #include "telemetry_json.h" > #include "telemetry_data.h" > +#include "rte_telemetry_legacy.h" >=20 > #define MAX_CMD_LEN 56 > #define MAX_HELP_LEN 64 > @@ -38,6 +39,7 @@ struct socket { > handler fn; > }; > static struct socket v2_socket; /* socket for v2 telemetry */ > +static struct socket v1_socket; /* socket for v1 telemetry */ > static char telemetry_log_error[1024]; /* Will contain error on init fail= ure */ > /* list of command callbacks, with one command registered by default */ > static struct cmd_callback callbacks[TELEMETRY_MAX_CALLBACKS]; > @@ -298,6 +300,8 @@ unlink_sockets(void) > { > if (v2_socket.path[0]) > unlink(v2_socket.path); > + if (v1_socket.path[0]) > + unlink(v1_socket.path); > } >=20 > static int > @@ -337,6 +341,33 @@ create_socket(char *path) > return -1; > } >=20 > +static int __rte_unused /* will be used in future commit */ > +telemetry_legacy_init(const char *runtime_dir) > +{ > + pthread_t t_old; > + > + if (num_legacy_callbacks =3D=3D 1) { > + snprintf(telemetry_log_error, sizeof(telemetry_log_error), > + "No legacy callbacks, legacy socket not created"); > + return -1; > + } > + > + v1_socket.fn =3D legacy_client_handler; > + if ((size_t) snprintf(v1_socket.path, sizeof(v1_socket.path), > + "%s/telemetry", runtime_dir) > + >=3D sizeof(v1_socket.path)) { > + snprintf(telemetry_log_error, sizeof(telemetry_log_error), > + "Error with socket binding, path too long"); > + return -1; > + } > + v1_socket.sock =3D create_socket(v1_socket.path); > + if (v1_socket.sock < 0) > + return -1; > + pthread_create(&t_old, NULL, socket_listener, &v1_socket); > + > + return 0; > +} > + > static int > telemetry_v2_init(const char *runtime_dir) > { > diff --git a/lib/librte_telemetry/telemetry_legacy.c b/lib/librte_telemet= ry/telemetry_legacy.c > new file mode 100644 > index 0000000000..bdf7492cda > --- /dev/null > +++ b/lib/librte_telemetry/telemetry_legacy.c > @@ -0,0 +1,227 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2020 Intel Corporation > + */ > + > +#include > +#include > +#include > +#include > + > +/* we won't link against libbsd, so just always use DPDKs-specific strlc= py */ > +#undef RTE_USE_LIBBSD > +#include > +#include > +#include > + > +#include "rte_telemetry_legacy.h" > + > +#define MAX_LEN 128 > +#define BUF_SIZE 1024 > +#define CLIENTS_UNREG_ACTION "\"action\":2" > +#define CLIENTS_CMD "\"command\":\"clients\"" > +#define CLIENTS_DATA "\"data\":{\"client_path\":\"" > +#define STATS_ACTION "\"action\":0" > +#define DATA_REQ_LABEL "\"data\":" > +#define TELEMETRY_LEGACY_MAX_CALLBACKS 4 > + > + > +static int > +register_client(const char *cmd __rte_unused, > + const char *params __rte_unused, > + char *buffer, int buf_len); > + > +struct json_command { > + char action[MAX_LEN]; > + char cmd[MAX_LEN]; > + char data[MAX_LEN]; > + telemetry_legacy_cb fn; > + > +}; > + > +struct json_command callbacks[TELEMETRY_LEGACY_MAX_CALLBACKS] =3D { > + { > + .action =3D "\"action\":1", > + .cmd =3D CLIENTS_CMD, > + .data =3D CLIENTS_DATA, > + .fn =3D register_client > + } > +}; > +int num_legacy_callbacks =3D 1; > +static rte_spinlock_t callback_sl =3D RTE_SPINLOCK_INITIALIZER; > + > +int > +rte_telemetry_legacy_register(const char *cmd, > + enum rte_telemetry_legacy_data_req data_req, > + telemetry_legacy_cb fn) > +{ > + if (fn =3D=3D NULL) > + return -EINVAL; > + if (num_legacy_callbacks >=3D (int) RTE_DIM(callbacks)) > + return -ENOENT; > + > + rte_spinlock_lock(&callback_sl); > + strlcpy(callbacks[num_legacy_callbacks].action, STATS_ACTION, MAX_LEN); > + snprintf(callbacks[num_legacy_callbacks].cmd, MAX_LEN, > + "\"command\":\"%s\"", cmd); > + snprintf(callbacks[num_legacy_callbacks].data, MAX_LEN, > + data_req ? "%s{\"" : "%snull", > + DATA_REQ_LABEL); > + callbacks[num_legacy_callbacks].fn =3D fn; > + num_legacy_callbacks++; > + rte_spinlock_unlock(&callback_sl); > + > + return 0; > +} > + > +static int > +register_client(const char *cmd __rte_unused, const char *params, > + char *buffer __rte_unused, int buf_len __rte_unused) > +{ > + pthread_t th; > + char data[BUF_SIZE]; > + int fd; > + struct sockaddr_un addrs; > + > + strlcpy(data, strchr(params, ':'), sizeof(data)); > + memcpy(data, &data[strlen(":\"")], strlen(data)); > + *strchr(data, '\"') =3D 0; > + > + fd =3D socket(AF_UNIX, SOCK_SEQPACKET, 0); > + addrs.sun_family =3D AF_UNIX; > + strlcpy(addrs.sun_path, data, sizeof(addrs.sun_path)); > + > + if (connect(fd, (struct sockaddr *)&addrs, sizeof(addrs)) =3D=3D -1) { > + perror("\nClient connection error\n"); > + return -1; > + } > + pthread_create(&th, NULL, &legacy_client_handler, > + (void *)(uintptr_t)fd); > + return 0; > +} > + > +static int > +send_error_response(int s, int err) > +{ > + const char *desc; > + char out_buf[100000]; > + > + switch (err) { > + case -ENOMEM: > + desc =3D "Memory Allocation Error"; > + break; > + case -EINVAL: > + desc =3D "Invalid Argument 404"; > + break; > + case -EPERM: > + desc =3D "Unknown"; > + break; > + default: > + /* Default case keeps behaviour of Telemetry library */ > + printf("\nInvalid error type: %d\n", err); > + return -EINVAL; > + } > + int used =3D snprintf(out_buf, sizeof(out_buf), "{\"status_code\": " > + "\"Status Error: %s\", \"data\": null}", desc); > + if (write(s, out_buf, used) < 0) { > + perror("Error writing to socket"); > + return -1; > + } > + return 0; > +} > + > +static void > +perform_command(telemetry_legacy_cb fn, const char *param, int s) > +{ > + char out_buf[100000]; > + int ret, used =3D 0; > + > + ret =3D fn("", param, out_buf, sizeof(out_buf)); > + if (ret < 0) { > + ret =3D send_error_response(s, ret); > + if (ret < 0) > + printf("\nCould not send error response\n"); > + return; > + } > + used +=3D ret; > + if (write(s, out_buf, used) < 0) > + perror("Error writing to socket"); > +} > + > +static int > +parse_client_request(char *buffer, int buf_len, int s) > +{ > + int i; > + char *data =3D buffer + buf_len; > + telemetry_legacy_cb fn =3D NULL; > + const char *valid_sep =3D ",}"; > + if (buffer[0] !=3D '{' || buffer[buf_len - 1] !=3D '}') > + return -EPERM; > + > + if (strstr(buffer, CLIENTS_UNREG_ACTION) && strstr(buffer, CLIENTS_CMD) > + && strstr(buffer, CLIENTS_DATA)) > + return 0; > + > + for (i =3D 0; i < num_legacy_callbacks; i++) { > + char *action_ptr =3D strstr(buffer, callbacks[i].action); > + char *cmd_ptr =3D strstr(buffer, callbacks[i].cmd); > + char *data_ptr =3D strstr(buffer, callbacks[i].data); > + if (!action_ptr || !cmd_ptr || !data_ptr) > + continue; > + > + char action_sep =3D action_ptr[strlen(callbacks[i].action)]; > + char cmd_sep =3D cmd_ptr[strlen(callbacks[i].cmd)]; > + if (!(strchr(valid_sep, action_sep) && strchr(valid_sep, > + cmd_sep))) > + return -EPERM; > + char data_sep; > + > + if (!strchr(data_ptr, '{')) > + data_sep =3D data_ptr[strlen(callbacks[i].data)]; > + else { > + char *data_end =3D strchr(data_ptr, '}'); > + data =3D data_ptr + strlen(DATA_REQ_LABEL); > + data_sep =3D data_end[1]; > + data_end[1] =3D 0; > + } > + if (!strchr(valid_sep, data_sep)) > + return -EPERM; > + fn =3D callbacks[i].fn; > + break; > + } > + > + if (!fn) > + return -EINVAL; > + perform_command(fn, data, s); > + return 0; > +} > + > +void * > +legacy_client_handler(void *sock_id) > +{ > + int s =3D (int)(uintptr_t)sock_id; > + int ret; > + char buffer_recv[BUF_SIZE]; > + /* receive data is not null terminated */ > + int bytes =3D read(s, buffer_recv, sizeof(buffer_recv)); > + buffer_recv[bytes] =3D 0; Same here bytes could be negative. > + > + while (bytes > 0) { > + int i, j; > + char buffer[BUF_SIZE]; > + for (i =3D 0, j =3D 0; buffer_recv[i] !=3D '\0'; i++) { > + buffer[j] =3D buffer_recv[i]; > + j +=3D !isspace(buffer_recv[i]); > + } > + buffer[j] =3D 0; > + ret =3D parse_client_request(buffer, j, s); > + if (ret < 0) { > + ret =3D send_error_response(s, ret); > + if (ret < 0) > + printf("\nCould not send error response\n"); > + } > + bytes =3D read(s, buffer_recv, sizeof(buffer_recv)); > + buffer_recv[bytes] =3D 0; Same here negative return value. > + } > + close(s); > + return NULL; > +} > --=20 > 2.17.1 >=20