From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail04.ics.ntt-tx.co.jp (mail05.ics.ntt-tx.co.jp [210.232.35.69]) by dpdk.org (Postfix) with ESMTP id 314581B1A7 for ; Thu, 28 Dec 2017 05:56:15 +0100 (CET) Received: from gwchk03.silk.ntt-tx.co.jp (gwchk03.silk.ntt-tx.co.jp [10.107.0.111]) by mail04.ics.ntt-tx.co.jp (unknown) with ESMTP id vBS4uEj7025321 for unknown; Thu, 28 Dec 2017 13:56:14 +0900 Received: (from root@localhost) by gwchk03.silk.ntt-tx.co.jp (unknown) id vBS4uAG3027498 for unknown; Thu, 28 Dec 2017 13:56:10 +0900 Received: from gwchk.silk.ntt-tx.co.jp [10.107.0.110] by gwchk03.silk.ntt-tx.co.jp with ESMTP id PAA27495; Thu, 28 Dec 2017 13:56:10 +0900 Received: from imss03.silk.ntt-tx.co.jp (localhost [127.0.0.1]) by imss03.silk.ntt-tx.co.jp (unknown) with ESMTP id vBS4u96h011241 for unknown; Thu, 28 Dec 2017 13:56:10 +0900 Received: from mgate01.silk.ntt-tx.co.jp (smtp02.silk.ntt-tx.co.jp [10.107.0.37]) by imss03.silk.ntt-tx.co.jp (unknown) with ESMTP id vBS4u9Qj011233 for unknown; Thu, 28 Dec 2017 13:56:09 +0900 Message-Id: <201712280456.vBS4u9Qj011233@imss03.silk.ntt-tx.co.jp> Received: from localhost by mgate01.silk.ntt-tx.co.jp (unknown) id vBS4u4b3025622 ; Thu, 28 Dec 2017 13:56:06 +0900 From: x-fn-spp@sl.ntt-tx.co.jp To: spp@dpdk.org Date: Thu, 28 Dec 2017 13:55:36 +0900 X-Mailer: git-send-email 1.9.1 In-Reply-To: <4aae78ff-3b6c-cdfe-a8b7-24ec08b73935@lab.ntt.co.jp> References: <4aae78ff-3b6c-cdfe-a8b7-24ec08b73935@lab.ntt.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-MML: No Subject: [spp] [PATCH 29/57] spp_vf: replace unsupported jansson api X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Dec 2017 04:56:17 -0000 From: Hiroyuki Nakamura * Stop using the json_path_get function and replace it with our own spp_config_get_path_obj function. * The json_path_get function is only available at branch of Jansson project, and it can not be provided in most of the pkgs(deb,rpm). This change made for build convenience. Signed-off-by: Kentaro Watanabe Signed-off-by: Yasufum Ogawa --- src/vf/spp_config.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++------- src/vf/spp_config.h | 9 +++++++ 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/vf/spp_config.c b/src/vf/spp_config.c index 4ad4f87..6d8e380 100644 --- a/src/vf/spp_config.c +++ b/src/vf/spp_config.c @@ -25,13 +25,63 @@ #define JSONPATH_TX_TABLE "$.tx_port_table" /* + * Instead of json_path_get + */ +json_t * +spp_config_get_path_obj(const json_t *json, const char *path) +{ + const json_t *obj, *array_obj; + json_t *new_obj = NULL; + char buf[SPP_CONFIG_PATH_LEN]; + char *str, *token, *bracket, *endptr; + int index = 0; + + if (unlikely(path[0] != '$') || unlikely(path[1] != '.') || + unlikely(strlen(path) >= SPP_CONFIG_PATH_LEN)) + return NULL; + + strcpy(buf, path); + obj = json; + str = buf+1; + while(str != NULL) { + token = str+1; + str = strpbrk(token, "."); + if (str != NULL) + *str = '\0'; + + bracket = strpbrk(token, "["); + if (bracket != NULL) + *bracket = '\0'; + + new_obj = json_object_get(obj, token); + if (new_obj == NULL) + return NULL; + + if (bracket != NULL) { + index = strtol(bracket+1, &endptr, 0); + if (unlikely(str == endptr) || unlikely(*endptr != ']')) + return NULL; + + array_obj = new_obj; + new_obj = json_array_get(array_obj, index); + if (new_obj == NULL) + return NULL; + } + + obj = new_obj; + } + + return new_obj; +} + +/* * Get integer data from config */ static int config_get_int_value(const json_t *obj, const char *path, int *value) { /* 指定パラメータのJsonオブジェクト取得 */ - json_t *tmp_obj = json_path_get(obj, path); + json_t *tmp_obj = spp_config_get_path_obj(obj, path); if (unlikely(tmp_obj == NULL)) { /* 必須でないデータを取得する場合を考慮し、DEBUGログとする。 */ RTE_LOG(DEBUG, APP, "No parameter. (path = %s)\n", path); @@ -58,7 +108,7 @@ static int config_get_str_value(const json_t *obj, const char *path, char *value) { /* 指定パラメータのJsonオブジェクト取得 */ - json_t *tmp_obj = json_path_get(obj, path); + json_t *tmp_obj = spp_config_get_path_obj(obj, path); if (unlikely(tmp_obj == NULL)) { RTE_LOG(DEBUG, APP, "No parameter. (path = %s)\n", path); return -1; @@ -204,7 +254,7 @@ config_load_classifier_table(const json_t *obj, struct spp_config_classifier_table *classifier_table) { /* classifier_table用オブジェクト取得 */ - json_t *classifier_obj = json_path_get(obj, JSONPATH_CLASSIFIER_TABLE); + json_t *classifier_obj = spp_config_get_path_obj(obj, JSONPATH_CLASSIFIER_TABLE); if (unlikely(classifier_obj == NULL)) { RTE_LOG(INFO, APP, "No classifier table.\n"); return 0; @@ -219,7 +269,7 @@ config_load_classifier_table(const json_t *obj, } /* table用オブジェクト取得 */ - json_t *array_obj = json_path_get(classifier_obj, JSONPATH_TABLE); + json_t *array_obj = spp_config_get_path_obj(classifier_obj, JSONPATH_TABLE); if (unlikely(!array_obj)) { RTE_LOG(ERR, APP, "Json object get failed. (path = %s)\n", JSONPATH_TABLE); @@ -338,7 +388,7 @@ config_set_rx_port(enum spp_core_type type, json_t *obj, if (type == SPP_CONFIG_MERGE) { /* Merge */ /* 受信ポート用オブジェクト取得 */ - json_t *array_obj = json_path_get(obj, JSONPATH_RX_PORT); + json_t *array_obj = spp_config_get_path_obj(obj, JSONPATH_RX_PORT); if (unlikely(!array_obj)) { RTE_LOG(ERR, APP, "Json object get failed. (path = %s, route = merge)\n", JSONPATH_RX_PORT); @@ -454,7 +504,7 @@ config_set_tx_port(enum spp_core_type type, json_t *obj, } } else { /* Classifier */ - json_t *table_obj = json_path_get(obj, JSONPATH_TX_TABLE); + json_t *table_obj = spp_config_get_path_obj(obj, JSONPATH_TX_TABLE); if (unlikely(table_obj != NULL)) { /* Classifier Tableから取得 */ functions->num_tx_port = classifier_table->num_table; @@ -473,7 +523,7 @@ config_set_tx_port(enum spp_core_type type, json_t *obj, { /* tx_portパラメータより取得 */ /* 送信ポート用オブジェクト取得 */ - json_t *array_obj = json_path_get(obj, JSONPATH_TX_PORT); + json_t *array_obj = spp_config_get_path_obj(obj, JSONPATH_TX_PORT); if (unlikely(array_obj == NULL)) { RTE_LOG(ERR, APP, "Json object get failed. (path = %s, route = classifier)\n", JSONPATH_TX_PORT); @@ -545,7 +595,7 @@ config_load_proc_info(const json_t *obj, int node_id, struct spp_config_area *co struct spp_config_classifier_table *classifier_table = &config->classifier_table; /* proc_table用オブジェクト取得 */ - json_t *proc_table_obj = json_path_get(obj, JSONPATH_PROC_TABLE); + json_t *proc_table_obj = spp_config_get_path_obj(obj, JSONPATH_PROC_TABLE); if (unlikely(proc_table_obj == NULL)) { RTE_LOG(ERR, APP, "Json object get failed. (path = %s)\n", JSONPATH_PROC_TABLE); @@ -599,7 +649,7 @@ config_load_proc_info(const json_t *obj, int node_id, struct spp_config_area *co } /* functions用オブジェクト取得 */ - json_t *array_obj = json_path_get(proc_obj, JSONPATH_FUNCTIONS); + json_t *array_obj = spp_config_get_path_obj(proc_obj, JSONPATH_FUNCTIONS); if (unlikely(!array_obj)) { RTE_LOG(ERR, APP, "Json object get failed. (path = %s)\n", JSONPATH_FUNCTIONS); diff --git a/src/vf/spp_config.h b/src/vf/spp_config.h index 37414cf..7945807 100644 --- a/src/vf/spp_config.h +++ b/src/vf/spp_config.h @@ -1,6 +1,7 @@ #ifndef __SPP_CONFIG_H__ #define __SPP_CONFIG_H__ +#include #include "common.h" #define SPP_CONFIG_FILE_PATH "/usr/local/etc/spp/spp.json" @@ -12,6 +13,7 @@ #define SPP_CONFIG_STR_LEN 32 #define SPP_CONFIG_MAC_TABLE_MAX 16 #define SPP_CONFIG_CORE_MAX 64 +#define SPP_CONFIG_PATH_LEN 1024 /* * Process type for each CORE @@ -81,6 +83,13 @@ struct spp_config_area { }; /* + * Instead of json_path_get + * OK : Json object address + * NG : NULL + */ +json_t *spp_config_get_path_obj(const json_t *json, const char *path); + +/* * Change mac address string to int64 * OK : int64 that store mac address * NG : -1 -- 1.9.1