summaryrefslogtreecommitdiffstats
path: root/lib/yang_translator.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* lib: add flag to have libyang load internal ietf-yang-library moduleChristian Hopps2024-10-071-2/+2
| | | | | | | | | | | | | | | | | | | | Mgmtd makes use of libyang's internal ietf-yang-library module to add support for said module to FRR management. Previously, mgmtd was loading this module explicitly; however, that required that libyang's `ietf-yang-library.yang` module definition file be co-located with FRR's yang files so that it (and ietf-datastore.yang) would be found when searched for by libyang using FRRs search path. This isn't always the case depending on how the user compiles and installs libyang so mgmtd was failing to run in some cases. Instead of doing it the above way we simply tell libyang to load it's internal version of ietf-yang-library when we initialize the libyang context. This required adding a boolean to a couple of the init functions which is why so many files are touched (although all the changes are minimal). Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: all: remove './' from xpath 22% speedupChristian Hopps2023-11-291-4/+4
| | | | | | fixes #8299 Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: add and use new yang function for finding schema nodesChristian Hopps2023-04-171-5/+4
| | | | | | | | | | | | | | | Add a wrapper around lys_find_xpath which has an unfortunate API returning an allocated set of schema nodes when we only ever expect and want one. Another libyang function `lys_find_path` returns a single node; however, that function can assert/abort on invalid path values so is unsuitable for user input. Replace previous uses of `lys_find_path` with new API when dealing with possible invalid path values (i.e., from a user). Signed-off-by: Christian Hopps <chopps@labn.net>
* Merge pull request #12780 from opensourcerouting/spdx-license-idDonald Sharp2023-02-171-14/+1
|\ | | | | *: convert to SPDX License identifiers
| * *: auto-convert to SPDX License IDsDavid Lamparter2023-02-091-14/+1
| | | | | | | | | | | | Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* | lib: Free dnode before returning if YANG translator model is already loadedDonatas Abraitis2023-02-091-0/+1
| | | | | | | | | | | | Seems just a missed one because at `goto error` we release dnode. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
* | lib: Release memory of YANG translation module on errorDonatas Abraitis2023-02-091-6/+7
|/ | | | Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
* *: no-warn pragmas for non-const format stringsDavid Lamparter2023-01-271-0/+8
| | | | | | | | We do use non-constant/literal format strings in a few places for more or less valid reasons; put `ignored "-Wformat-nonliteral"` around those so we can have the warning enabled for everywhere else. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: adapt to version 2 of libyangChristian Hopps2021-05-131-62/+67
| | | | | | | | | Compile with v2.0.0 tag of `libyang2` branch of: https://github.com/CESNET/libyang staticd init load time of 10k routes now 6s vs ly1 time of 150s Signed-off-by: Christian Hopps <chopps@labn.net>
* *: require semicolon after DEFINE_MTYPE & coDavid Lamparter2021-03-171-3/+3
| | | | | | | | | | | | | | | | | Back when I put this together in 2015, ISO C11 was still reasonably new and we couldn't require it just yet. Without ISO C11, there is no "good" way (only bad hacks) to require a semicolon after a macro that ends with a function definition. And if you added one anyway, you'd get "spurious semicolon" warnings on some compilers... With C11, `_Static_assert()` at the end of a macro will make it so that the semicolon is properly required, consumed, and not warned about. Consistently requiring semicolons after "file-level" macros matches Linux kernel coding style and helps some editors against mis-syntax'ing these macros. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: combine two YANG schema iteration functions into oneRenato Westphal2020-10-231-11/+11
| | | | | | | | | | Combine yang_snodes_iterate_module() and yang_snodes_iterate_all() into an unified yang_snodes_iterate() function, where the first "module" parameter is optional. There's no point in having two separate YANG schema iteration functions anymore now that they are too similar. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib, tools: silence harmless warnings in the northbound toolsRenato Westphal2020-04-041-2/+2
| | | | | | | | | | | | | | | Our two northbound tools don't have embedded YANG modules like the other FRR binaries. As such, ly_ctx_set_module_imp_clb() shouldn't be called when the YANG subsystem it being initialized by a northbound tool. To make that possible, add a new "embedded_modules" parameter to the yang_init() function to control whether libyang should look for embedded modules or not. With this fix, "gen_northbound_callbacks" and "gen_yang_deviations" won't emit "YANG model X not embedded, trying external file" warnings anymore. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: hashing functions should take const argumentsQuentin Young2019-05-141-1/+1
| | | | | | | | | | It doesn't make much sense for a hash function to modify its argument, so const the hash input. BGP does it in a couple places, those cast away the const. Not great but not any worse than it was. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: remove str_replace functionQuentin Young2019-05-071-32/+19
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: strncpy -> strlcpy | memcpyQuentin Young2019-02-261-1/+1
| | | | | | strncpy is a byte copy function not a string copy function Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: yang: use common yang_ctx_new_setup()David Lamparter2019-02-191-4/+2
| | | | | | | | | | | | After creating a libyang context, we need to hook up our callback to use embedded built-in modules. I hadn't added this to the yang translator code. Also, ly_ctx_new fails if the search directory doesn't exist. Since that's not a hard error for us, work around that and ignore inaccessible YANG_MODELS_DIR. (This is needed for snap packages.) Signed-off-by: David Lamparter <equinox@diac24.net>
* Merge pull request #3342 from opensourcerouting/nb-operational-dataRuss White2018-11-291-22/+32
|\ | | | | Northbound: improved support for YANG-modeled operational data
| * lib: rework the yang schema node iteration functionsRenato Westphal2018-11-261-21/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | * Rename yang_snodes_iterate() to yang_snodes_iterate_subtree() and expose it in the public API. * Rename yang_module_snodes_iterate() to yang_snodes_iterate_module(). * Rename yang_all_snodes_iterate() to yang_snodes_iterate_all(). * Make it possible to stop the iteration at any time by returning YANG_ITER_STOP in the iteration callbacks. * Make the iteration callbacks accept only one user argument and not two. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
| * lib: make it possible to create YANG data nodes containing state dataRenato Westphal2018-11-261-1/+1
| | | | | | | | | | | | | | | | | | By default the data nodes created by yang_dnode_new() could contain only configuration data (LYD_OPT_CONFIG). Add a 'config_only' option to yang_dnode_new() so that it can create data nodes containing both configuration and state data. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* | lib: set YANG search directory when creating libyang contextRenato Westphal2018-11-261-4/+4
|/ | | | | | Minor code simplification. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: introduce new northbound APIRenato Westphal2018-10-271-0/+545
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>