From 1e403bf195b3328952616e05e33ccb526597e187 Mon Sep 17 00:00:00 2001 From: haozi007 Date: Fri, 3 Jul 2020 15:41:24 +0800 Subject: [PATCH] keep all residual values of cni 1. can keep undefined keys and values in cni conf 2. so we can support extend configs of cni conf 3. in theory we can support all third party plugins of cni, such as calico, flannel and so on Signed-off-by: haozi007 --- src/api.c | 4 ++-- src/conf.c | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/api.c b/src/api.c index 0a70e62..abb3791 100644 --- a/src/api.c +++ b/src/api.c @@ -142,7 +142,7 @@ free_out: static int do_generate_cni_net_conf_json(const struct network_config *orig, char **result, char **err) { - struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; + struct parser_context ctx = { OPT_PARSE_FULLKEY | OPT_GEN_SIMPLIFY, 0 }; parser_error jerr = NULL; int ret = 0; @@ -270,7 +270,7 @@ free_out: static int do_check_generate_cni_net_conf_json(char **full_conf_bytes, struct network_config *pnet, char **err) { - struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; + struct parser_context ctx = { OPT_PARSE_FULLKEY | OPT_GEN_SIMPLIFY, 0 }; parser_error serr = NULL; int ret = 0; diff --git a/src/conf.c b/src/conf.c index b99d95f..0aabf5b 100644 --- a/src/conf.c +++ b/src/conf.c @@ -38,8 +38,9 @@ static int do_conf_from_bytes(const char *conf_str, struct network_config *confi { int ret = 0; parser_error jerr = NULL; + struct parser_context ctx = { OPT_PARSE_FULLKEY | OPT_GEN_SIMPLIFY, 0 }; - config->network = cni_net_conf_parse_data(conf_str, NULL, &jerr); + config->network = cni_net_conf_parse_data(conf_str, &ctx, &jerr); if (config->network == NULL) { ret = asprintf(err, "Error parsing configuration: %s", jerr); if (ret < 0) { @@ -197,6 +198,7 @@ int conflist_from_bytes(const char *json_str, struct network_config_list **list, int ret = -1; parser_error jerr = NULL; cni_net_conf_list *tmp_list = NULL; + struct parser_context ctx = { OPT_PARSE_FULLKEY | OPT_GEN_SIMPLIFY, 0 }; if (check_conflist_from_bytes_args(list, err)) { ERROR("Invalid arguments"); @@ -213,7 +215,7 @@ int conflist_from_bytes(const char *json_str, struct network_config_list **list, ERROR("Out of memory"); goto free_out; } - tmp_list = cni_net_conf_list_parse_data(json_str, NULL, &jerr); + tmp_list = cni_net_conf_list_parse_data(json_str, &ctx, &jerr); if (tmp_list == NULL) { ret = asprintf(err, "Error parsing configuration list: %s", jerr); if (ret < 0) { @@ -523,7 +525,7 @@ free_out: static int generate_new_conflist(const cni_net_conf_list *list, struct network_config_list **conf_list, char **err) { - struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 }; + struct parser_context ctx = { OPT_PARSE_FULLKEY | OPT_GEN_SIMPLIFY, 0 }; parser_error jerr = NULL; char *cni_net_conf_json_str = NULL; int ret = -1; -- GitLab