mirror of
https://github.com/FRRouting/frr.git
synced 2025-04-30 13:37:17 +02:00
lib: libyang2 add missed conversion
Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
parent
ea9aa70547
commit
af1b88e990
16
.travis.yml
16
.travis.yml
|
@ -5,14 +5,14 @@ services:
|
||||||
- docker
|
- docker
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
# - script:
|
- script:
|
||||||
# - docker/centos-7/build.sh
|
- docker/centos-7/build.sh
|
||||||
# - docker images
|
- docker images
|
||||||
# name: centos7
|
name: centos7
|
||||||
# - script:
|
- script:
|
||||||
# - docker/centos-8/build.sh
|
- docker/centos-8/build.sh
|
||||||
# - docker images
|
- docker images
|
||||||
# name: centos8
|
name: centos8
|
||||||
- script:
|
- script:
|
||||||
- sudo apt install -y linux-modules-extra-$(uname -r)
|
- sudo apt install -y linux-modules-extra-$(uname -r)
|
||||||
- docker build -t frr-ubuntu18:latest -f docker/ubuntu18-ci/Dockerfile .
|
- docker build -t frr-ubuntu18:latest -f docker/ubuntu18-ci/Dockerfile .
|
||||||
|
|
|
@ -11,6 +11,11 @@ AM_CFLAGS = \
|
||||||
$(SAN_FLAGS) \
|
$(SAN_FLAGS) \
|
||||||
$(WERROR) \
|
$(WERROR) \
|
||||||
# end
|
# end
|
||||||
|
AM_CXXFLAGS = \
|
||||||
|
$(AC_CXXFLAGS) \
|
||||||
|
$(LIBYANG_CFLAGS) \
|
||||||
|
$(WERROR) \
|
||||||
|
# end
|
||||||
|
|
||||||
# CPPFLAGS_BASE does not contain the include path for overriding assert.h,
|
# CPPFLAGS_BASE does not contain the include path for overriding assert.h,
|
||||||
# therefore should be used in tools that do *not* link libfrr or do not want
|
# therefore should be used in tools that do *not* link libfrr or do not want
|
||||||
|
|
|
@ -10,7 +10,7 @@ The FRR project builds some binary ``libyang`` packages.
|
||||||
RPM packages are at our `RPM repository <https://rpm.frrouting.org>`_.
|
RPM packages are at our `RPM repository <https://rpm.frrouting.org>`_.
|
||||||
|
|
||||||
DEB packages are available as CI artifacts `here
|
DEB packages are available as CI artifacts `here
|
||||||
<https://ci1.netdef.org/browse/LIBYANG-LIBYANG-V2/latestSuccessful/artifact>`_.
|
<https://ci1.netdef.org/browse/LIBYANG-LIBYANGV2/latestSuccessful/artifact>`_.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ RUN yum install -y rpm-build autoconf automake libtool make \
|
||||||
readline-devel texinfo net-snmp-devel groff pkgconfig \
|
readline-devel texinfo net-snmp-devel groff pkgconfig \
|
||||||
json-c-devel pam-devel bison flex pytest c-ares-devel \
|
json-c-devel pam-devel bison flex pytest c-ares-devel \
|
||||||
python3-devel python3-sphinx systemd-devel libcap-devel \
|
python3-devel python3-sphinx systemd-devel libcap-devel \
|
||||||
https://ci1.netdef.org/artifact/LIBYANG-LY1REL/shared/build-4/CentOS-7-x86_64-Packages/libyang1-1.0.184-0.x86_64.rpm \
|
https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-7-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el7.x86_64.rpm \
|
||||||
https://ci1.netdef.org/artifact/LIBYANG-LY1REL/shared/build-4/CentOS-7-x86_64-Packages/libyang-devel-1.0.184-0.x86_64.rpm \
|
https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-7-x86_64-Packages/libyang2-devel-2.0.0.10.g2eb910e4-1.el7.x86_64.rpm \
|
||||||
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm \
|
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm \
|
||||||
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-devel-0.7.0-1.el7.centos.x86_64.rpm
|
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-devel-0.7.0-1.el7.centos.x86_64.rpm
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ RUN echo '%_smp_mflags %( echo "-j$(/usr/bin/getconf _NPROCESSORS_ONLN)"; )' >>
|
||||||
# This stage installs frr from the rpm
|
# This stage installs frr from the rpm
|
||||||
FROM centos:centos7
|
FROM centos:centos7
|
||||||
RUN mkdir -p /pkgs/rpm \
|
RUN mkdir -p /pkgs/rpm \
|
||||||
&& yum install -y https://ci1.netdef.org/artifact/LIBYANG-LY1REL/shared/build-4/CentOS-7-x86_64-Packages/libyang1-1.0.184-0.x86_64.rpm \
|
&& yum install -y https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-7-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el7.x86_64.rpm \
|
||||||
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm
|
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm
|
||||||
|
|
||||||
COPY --from=centos-7-builder /rpmbuild/RPMS/ /pkgs/rpm/
|
COPY --from=centos-7-builder /rpmbuild/RPMS/ /pkgs/rpm/
|
||||||
|
|
|
@ -5,8 +5,8 @@ RUN dnf install --enablerepo=powertools -y rpm-build git autoconf pcre-devel \
|
||||||
automake libtool make readline-devel texinfo net-snmp-devel pkgconfig \
|
automake libtool make readline-devel texinfo net-snmp-devel pkgconfig \
|
||||||
groff pkgconfig json-c-devel pam-devel bison flex python3-pytest \
|
groff pkgconfig json-c-devel pam-devel bison flex python3-pytest \
|
||||||
c-ares-devel python3-devel python3-sphinx systemd-devel libcap-devel platform-python-devel \
|
c-ares-devel python3-devel python3-sphinx systemd-devel libcap-devel platform-python-devel \
|
||||||
https://ci1.netdef.org/artifact/LIBYANG-LY1REL/shared/build-4/CentOS-8-x86_64-Packages/libyang1-1.0.184-0.x86_64.rpm \
|
https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \
|
||||||
https://ci1.netdef.org/artifact/LIBYANG-LY1REL/shared/build-4/CentOS-8-x86_64-Packages/libyang-devel-1.0.184-0.x86_64.rpm \
|
https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-devel-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \
|
||||||
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm \
|
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm \
|
||||||
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-devel-0.7.0-1.el7.centos.x86_64.rpm
|
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-devel-0.7.0-1.el7.centos.x86_64.rpm
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ RUN echo '%_smp_mflags %( echo "-j$(/usr/bin/getconf _NPROCESSORS_ONLN)"; )' >>
|
||||||
# This stage installs frr from the rpm
|
# This stage installs frr from the rpm
|
||||||
FROM centos:centos8
|
FROM centos:centos8
|
||||||
RUN mkdir -p /pkgs/rpm \
|
RUN mkdir -p /pkgs/rpm \
|
||||||
&& yum install -y https://ci1.netdef.org/artifact/LIBYANG-LY1REL/shared/build-4/CentOS-8-x86_64-Packages/libyang1-1.0.184-0.x86_64.rpm \
|
&& yum install -y https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \
|
||||||
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm
|
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-110/CentOS-7-x86_64-Packages/librtr-0.7.0-1.el7.centos.x86_64.rpm
|
||||||
|
|
||||||
COPY --from=centos-8-builder /rpmbuild/RPMS/ /pkgs/rpm/
|
COPY --from=centos-8-builder /rpmbuild/RPMS/ /pkgs/rpm/
|
||||||
|
|
|
@ -87,9 +87,12 @@ int nb_db_transaction_save(const struct nb_transaction *transaction,
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
client_name = nb_client_name(transaction->context->client);
|
client_name = nb_client_name(transaction->context->client);
|
||||||
/* Always record configurations in the XML format. */
|
/*
|
||||||
|
* Always record configurations in the XML format, save the default
|
||||||
|
* values too, as this covers the case where defaults may change.
|
||||||
|
*/
|
||||||
if (lyd_print_mem(&config_str, transaction->config->dnode, LYD_XML,
|
if (lyd_print_mem(&config_str, transaction->config->dnode, LYD_XML,
|
||||||
LYP_FORMAT | LYP_WITHSIBLINGS)
|
LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL)
|
||||||
!= 0)
|
!= 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
@ -149,6 +152,7 @@ struct nb_config *nb_db_transaction_load(uint32_t transaction_id)
|
||||||
struct lyd_node *dnode;
|
struct lyd_node *dnode;
|
||||||
const char *config_str;
|
const char *config_str;
|
||||||
struct sqlite3_stmt *ss;
|
struct sqlite3_stmt *ss;
|
||||||
|
LY_ERR err;
|
||||||
|
|
||||||
ss = db_prepare(
|
ss = db_prepare(
|
||||||
"SELECT\n"
|
"SELECT\n"
|
||||||
|
@ -169,10 +173,11 @@ struct nb_config *nb_db_transaction_load(uint32_t transaction_id)
|
||||||
if (db_loadf(ss, "%s", &config_str) != 0)
|
if (db_loadf(ss, "%s", &config_str) != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
dnode = lyd_parse_mem(ly_native_ctx, config_str, LYD_XML,
|
err = lyd_parse_data_mem(ly_native_ctx, config_str, LYD_XML,
|
||||||
LYD_OPT_CONFIG);
|
LYD_PARSE_STRICT | LYD_PARSE_NO_STATE,
|
||||||
if (!dnode)
|
LYD_VALIDATE_NO_STATE, &dnode);
|
||||||
flog_warn(EC_LIB_LIBYANG, "%s: lyd_parse_mem() failed",
|
if (err || !dnode)
|
||||||
|
flog_warn(EC_LIB_LIBYANG, "%s: lyd_parse_data_mem() failed",
|
||||||
__func__);
|
__func__);
|
||||||
else
|
else
|
||||||
config = nb_config_new(dnode);
|
config = nb_config_new(dnode);
|
||||||
|
|
|
@ -199,9 +199,8 @@ class NorthboundImpl
|
||||||
auto m = tag->response.add_supported_modules();
|
auto m = tag->response.add_supported_modules();
|
||||||
|
|
||||||
m->set_name(module->name);
|
m->set_name(module->name);
|
||||||
if (module->info->rev_size)
|
if (module->info->revision)
|
||||||
m->set_revision(
|
m->set_revision(module->info->revision);
|
||||||
module->info->rev[0].date);
|
|
||||||
m->set_organization(module->info->org);
|
m->set_organization(module->info->org);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1068,14 +1067,13 @@ class NorthboundImpl
|
||||||
const std::string &path,
|
const std::string &path,
|
||||||
const std::string &value)
|
const std::string &value)
|
||||||
{
|
{
|
||||||
ly_errno = LY_SUCCESS;
|
LY_ERR err = lyd_new_path(dnode, ly_native_ctx, path.c_str(),
|
||||||
dnode = lyd_new_path(dnode, ly_native_ctx, path.c_str(),
|
value.c_str(), LYD_NEW_PATH_UPDATE,
|
||||||
(void *)value.c_str(),
|
&dnode);
|
||||||
(LYD_ANYDATA_VALUETYPE)0,
|
if (err != LY_SUCCESS) {
|
||||||
LYD_PATH_OPT_UPDATE);
|
flog_warn(EC_LIB_LIBYANG,
|
||||||
if (!dnode && ly_errno != LY_SUCCESS) {
|
"%s: lyd_new_path() failed: %s", __func__,
|
||||||
flog_warn(EC_LIB_LIBYANG, "%s: lyd_new_path() failed",
|
ly_errmsg(ly_native_ctx));
|
||||||
__func__);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1089,7 +1087,7 @@ class NorthboundImpl
|
||||||
if (!dnode)
|
if (!dnode)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
lyd_free(dnode);
|
lyd_free_tree(dnode);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1132,7 +1130,7 @@ class NorthboundImpl
|
||||||
std::string(date), std::string(comment)));
|
std::string(date), std::string(comment)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int data_tree_from_dnode(frr::DataTree *dt,
|
static LY_ERR data_tree_from_dnode(frr::DataTree *dt,
|
||||||
const struct lyd_node *dnode,
|
const struct lyd_node *dnode,
|
||||||
LYD_FORMAT lyd_format,
|
LYD_FORMAT lyd_format,
|
||||||
bool with_defaults)
|
bool with_defaults)
|
||||||
|
@ -1140,38 +1138,45 @@ class NorthboundImpl
|
||||||
char *strp;
|
char *strp;
|
||||||
int options = 0;
|
int options = 0;
|
||||||
|
|
||||||
SET_FLAG(options, LYP_FORMAT | LYP_WITHSIBLINGS);
|
SET_FLAG(options, LYD_PRINT_WITHSIBLINGS);
|
||||||
if (with_defaults)
|
if (with_defaults)
|
||||||
SET_FLAG(options, LYP_WD_ALL);
|
SET_FLAG(options, LYD_PRINT_WD_ALL);
|
||||||
else
|
else
|
||||||
SET_FLAG(options, LYP_WD_TRIM);
|
SET_FLAG(options, LYD_PRINT_WD_TRIM);
|
||||||
|
|
||||||
if (lyd_print_mem(&strp, dnode, lyd_format, options) == 0) {
|
LY_ERR err = lyd_print_mem(&strp, dnode, lyd_format, options);
|
||||||
|
if (err == LY_SUCCESS) {
|
||||||
if (strp) {
|
if (strp) {
|
||||||
dt->set_data(strp);
|
dt->set_data(strp);
|
||||||
free(strp);
|
free(strp);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return err;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct lyd_node *dnode_from_data_tree(const frr::DataTree *dt,
|
static struct lyd_node *dnode_from_data_tree(const frr::DataTree *dt,
|
||||||
bool config_only)
|
bool config_only)
|
||||||
{
|
{
|
||||||
struct lyd_node *dnode;
|
struct lyd_node *dnode;
|
||||||
int options;
|
int options, opt2;
|
||||||
|
LY_ERR err;
|
||||||
|
|
||||||
if (config_only)
|
if (config_only) {
|
||||||
options = LYD_OPT_CONFIG;
|
options = LYD_PARSE_STRICT | LYD_PARSE_NO_STATE;
|
||||||
else
|
opt2 = LYD_VALIDATE_NO_STATE;
|
||||||
options = LYD_OPT_DATA | LYD_OPT_DATA_NO_YANGLIB;
|
} else {
|
||||||
|
options = LYD_PARSE_STRICT;
|
||||||
|
opt2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
dnode = lyd_parse_mem(ly_native_ctx, dt->data().c_str(),
|
err = lyd_parse_data_mem(ly_native_ctx, dt->data().c_str(),
|
||||||
encoding2lyd_format(dt->encoding()),
|
encoding2lyd_format(dt->encoding()),
|
||||||
options);
|
options, opt2, &dnode);
|
||||||
|
if (err != LY_SUCCESS) {
|
||||||
|
flog_warn(EC_LIB_LIBYANG,
|
||||||
|
"%s: lyd_parse_mem() failed: %s", __func__,
|
||||||
|
ly_errmsg(ly_native_ctx));
|
||||||
|
}
|
||||||
return dnode;
|
return dnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1239,14 +1244,15 @@ class NorthboundImpl
|
||||||
// Combine configuration and state data into a single
|
// Combine configuration and state data into a single
|
||||||
// dnode.
|
// dnode.
|
||||||
//
|
//
|
||||||
if (lyd_merge(dnode_state, dnode_config,
|
if (lyd_merge_tree(&dnode_state, dnode_config,
|
||||||
LYD_OPT_EXPLICIT)
|
LYD_MERGE_DESTRUCT)
|
||||||
!= 0) {
|
!= LY_SUCCESS) {
|
||||||
yang_dnode_free(dnode_state);
|
yang_dnode_free(dnode_state);
|
||||||
yang_dnode_free(dnode_config);
|
yang_dnode_free(dnode_config);
|
||||||
return grpc::Status(
|
return grpc::Status(
|
||||||
grpc::StatusCode::INTERNAL,
|
grpc::StatusCode::INTERNAL,
|
||||||
"Failed to merge configuration and state data");
|
"Failed to merge configuration and state data",
|
||||||
|
ly_errmsg(ly_native_ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
dnode_final = dnode_state;
|
dnode_final = dnode_state;
|
||||||
|
@ -1262,19 +1268,25 @@ class NorthboundImpl
|
||||||
// Validate data to create implicit default nodes if necessary.
|
// Validate data to create implicit default nodes if necessary.
|
||||||
int validate_opts = 0;
|
int validate_opts = 0;
|
||||||
if (type == frr::GetRequest_DataType_CONFIG)
|
if (type == frr::GetRequest_DataType_CONFIG)
|
||||||
validate_opts = LYD_OPT_CONFIG;
|
validate_opts = LYD_VALIDATE_NO_STATE;
|
||||||
else
|
else
|
||||||
validate_opts = LYD_OPT_DATA | LYD_OPT_DATA_NO_YANGLIB;
|
validate_opts = 0;
|
||||||
lyd_validate(&dnode_final, validate_opts, ly_native_ctx);
|
|
||||||
|
|
||||||
|
LY_ERR err = lyd_validate_all(&dnode_final, ly_native_ctx,
|
||||||
|
validate_opts, NULL);
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
flog_warn(EC_LIB_LIBYANG,
|
||||||
|
"%s: lyd_validate_all() failed: %s", __func__,
|
||||||
|
ly_errmsg(ly_native_ctx));
|
||||||
// Dump data using the requested format.
|
// Dump data using the requested format.
|
||||||
int ret = data_tree_from_dnode(dt, dnode_final, lyd_format,
|
if (!err)
|
||||||
|
err = data_tree_from_dnode(dt, dnode_final, lyd_format,
|
||||||
with_defaults);
|
with_defaults);
|
||||||
yang_dnode_free(dnode_final);
|
yang_dnode_free(dnode_final);
|
||||||
if (ret != 0)
|
if (err)
|
||||||
return grpc::Status(grpc::StatusCode::INTERNAL,
|
return grpc::Status(grpc::StatusCode::INTERNAL,
|
||||||
"Failed to dump data");
|
"Failed to dump data");
|
||||||
|
|
||||||
return grpc::Status::OK;
|
return grpc::Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,7 @@ extern const struct xref * const __stop_xref_array[1] DSO_LOCAL;
|
||||||
static void __attribute__((used, _CONSTRUCTOR(1100))) \
|
static void __attribute__((used, _CONSTRUCTOR(1100))) \
|
||||||
_xref_init(void) { \
|
_xref_init(void) { \
|
||||||
static struct xref_block _xref_block = { \
|
static struct xref_block _xref_block = { \
|
||||||
|
.next = NULL, \
|
||||||
.start = __start_xref_array, \
|
.start = __start_xref_array, \
|
||||||
.stop = __stop_xref_array, \
|
.stop = __stop_xref_array, \
|
||||||
}; \
|
}; \
|
||||||
|
|
Loading…
Reference in a new issue