diff --git a/doc/apidoc/inc-netdef.md b/doc/apidoc/inc-netdef.md new file mode 100644 index 000000000..25d315be2 --- /dev/null +++ b/doc/apidoc/inc-netdef.md @@ -0,0 +1,4 @@ +# netdef.h + +```{autodoxygenfile} include/netdef.h +``` diff --git a/doc/apidoc/index.md b/doc/apidoc/index.md index e424b43e0..2949f2a61 100644 --- a/doc/apidoc/index.md +++ b/doc/apidoc/index.md @@ -1,13 +1,14 @@ # Reference: libnetplan API ## Public headers + ```{toctree} --- maxdepth: 1 --- -inc-netplan +inc-parse ``` -> ```{autodoxygenfile} include/netplan.h +> ```{autodoxygenfile} include/parse.h > :sections: briefdescription > ``` @@ -25,9 +26,9 @@ inc-parse-nm --- maxdepth: 1 --- -inc-parse +inc-netplan ``` -> ```{autodoxygenfile} include/parse.h +> ```{autodoxygenfile} include/netplan.h > :sections: briefdescription > ``` @@ -35,9 +36,9 @@ inc-parse --- maxdepth: 1 --- -inc-types +inc-netdef ``` -> ```{autodoxygenfile} include/types.h +> ```{autodoxygenfile} include/netdef.h > :sections: briefdescription > ``` @@ -50,3 +51,13 @@ inc-util > ```{autodoxygenfile} include/util.h > :sections: briefdescription > ``` + +```{toctree} +--- +maxdepth: 1 +--- +inc-types +``` +> ```{autodoxygenfile} include/types.h +> :sections: briefdescription +> ``` diff --git a/doc/conf.py b/doc/conf.py index 197a9e172..3137bfe0d 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -195,19 +195,20 @@ # https://breathe.readthedocs.io/en/latest/directives.html # breathe_projects = {"Netplan": "../doxyxml/"} breathe_projects_source = {"auto-apidoc": ("../", [ + "include/netdef.h", "include/netplan.h", "include/parse-nm.h", "include/parse.h", "include/types.h", "include/util.h", - "src/error.c", - "src/names.c", - "src/netplan.c", - "src/parse-nm.c", - "src/parse.c", - "src/types.c", - "src/util.c", - "src/validation.c", + #"src/error.c", + #"src/names.c", + #"src/netplan.c", + #"src/parse-nm.c", + #"src/parse.c", + #"src/types.c", + #"src/util.c", + #"src/validation.c", ])} breathe_doxygen_config_options = { diff --git a/include/meson.build b/include/meson.build index 79ecd595a..f867ee78e 100644 --- a/include/meson.build +++ b/include/meson.build @@ -1,2 +1,2 @@ -install_headers('netplan.h', 'parse.h', 'parse-nm.h', 'util.h', 'types.h', +install_headers('netdef.h', 'netplan.h', 'parse.h', 'parse-nm.h', 'util.h', 'types.h', subdir: 'netplan') diff --git a/include/netdef.h b/include/netdef.h new file mode 100644 index 000000000..ea9dbd2e3 --- /dev/null +++ b/include/netdef.h @@ -0,0 +1,195 @@ + +/* + * Copyright (C) 2024 Canonical, Ltd. + * Author: Lukas Märdian + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file netdef.h + * @brief Functions for manipulating @ref NetplanNetDefinition objects. + */ + +#pragma once +#include +#include "types.h" + +/** + * @brief Get the full path that a @ref NetplanNetDefinition will be written to by its backend renderer. + * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the + * buffer is too small its content will not be `NUL`-terminated. + * @note Used by the NetworkManager YAML backend but also applicable to the systemd-networkd renderer. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @param[in] ssid Wi-Fi SSID of this connection, or `NULL` + * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller + * @param[in] out_buf_size The maximum size (in bytes) available for @p out_buffer + * @return The size of the copied string, including the final `NUL` character. + * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. + */ +NETPLAN_PUBLIC ssize_t +netplan_netdef_get_output_filename(const NetplanNetDefinition* netdef, const char* ssid, char* out_buffer, size_t out_buf_size); + +/** + * @brief Get the origin filepath of a given @ref NetplanNetDefinition. + * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the + * buffer is too small its content will not be `NUL`-terminated. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller + * @param[in] out_buffer_size The maximum size (in bytes) available for @p out_buffer + * @return The size of the copied string, including the final `NUL` character. + * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. + */ +NETPLAN_PUBLIC ssize_t +netplan_netdef_get_filepath(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buffer_size); + +/** + * @brief Get the specific @ref NetplanBackend defined for this @ref NetplanNetDefinition. + * @param[in] np_state The @ref NetplanState to query + * @return Enumeration value, specifiying the @ref NetplanBackend + */ +NETPLAN_PUBLIC NetplanBackend +netplan_netdef_get_backend(const NetplanNetDefinition* netdef); + +/** + * @brief Get the interface type for a given @ref NetplanNetDefinition. + * @param[in] np_state The @ref NetplanState to query + * @return Enumeration value of @ref NetplanDefType, specifiying the interface type + */ +NETPLAN_PUBLIC NetplanDefType +netplan_netdef_get_type(const NetplanNetDefinition* netdef); + +/** + * @brief Get the Netplan ID of a given @ref NetplanNetDefinition. + * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the + * buffer is too small its content will not be `NUL`-terminated. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller + * @param[in] out_buffer_size The maximum size (in bytes) available for @p out_buffer + * @return The size of the copied string, including the final `NUL` character. + * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. + */ +NETPLAN_PUBLIC ssize_t +netplan_netdef_get_id(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buffer_size); + +/** + * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. + * @details This defines the parent-child relationship between bridged interfaces. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @return Reference to the parent of @p netdef + */ +NETPLAN_PUBLIC NetplanNetDefinition* +netplan_netdef_get_bridge_link(const NetplanNetDefinition* netdef); + +/** + * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. + * @details This defines the parent-child relationship between bonded interfaces. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @return Reference to the parent of @p netdef + */ +NETPLAN_PUBLIC NetplanNetDefinition* +netplan_netdef_get_bond_link(const NetplanNetDefinition* netdef); + +/** + * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. + * @details This defines the peer relationship between veth or Open vSwitch interfaces. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @return Reference to the peer of @p netdef + */ +NETPLAN_PUBLIC NetplanNetDefinition* +netplan_netdef_get_peer_link(const NetplanNetDefinition* netdef); + +/** + * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. + * @details This defines the parent-child relationship of VLAN interfaces. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @return Reference to the parent of @p netdef + */ +NETPLAN_PUBLIC NetplanNetDefinition* +netplan_netdef_get_vlan_link(const NetplanNetDefinition* netdef); + +/** + * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. + * @details This defines the parent-child relationship of SR-IOV virtual functions. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @return Reference to the physical function of @p netdef + */ +NETPLAN_PUBLIC NetplanNetDefinition* +netplan_netdef_get_sriov_link(const NetplanNetDefinition* netdef); + +/** + * @brief Get the `set-name` setting of a given @ref NetplanNetDefinition. + * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the + * buffer is too small its content will not be `NUL`-terminated. + * @note This is unrelated to the `match.name` setting. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller + * @param[in] out_buffer_size The maximum size (in bytes) available for @p out_buffer + * @return The size of the copied string, including the final `NUL` character. + * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. + */ +NETPLAN_PUBLIC ssize_t +netplan_netdef_get_set_name(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buffer_size); + +/** + * @brief Query a @ref NetplanNetDefinition for a `match` stanza in its configuration. + * @details In the absence of a `match` stanza, the Netplan ID + can be considered to be the interface name of a single interface. Otherwise, it could match multiple interfaces. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @return Indication if @p netdef uses custom interface matching rules + */ +NETPLAN_PUBLIC gboolean +netplan_netdef_has_match(const NetplanNetDefinition* netdef); + +/** + * @brief Gheck if a @ref NetplanNetDefinition matches on given interface parameters. + * @details If defined in @p netdef calculate if it would match on given @p mac AND @p name AND @p driver_name parameters. + * @note Matching a single driver out of a list given in the YAML configuration is enough to satisfy the condition. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @param[in] name The interface name match, optionally using shell wildcard patterns (`fnmatch()`) + * @param[in] mac The exact, case insensitive match on the interface MAC address + * @param[in] driver_name The driver match, optionally using shell wildcard patterns (`fnmatch()`) + * @return Indication if @p netdef uses custom interface matching rules + */ +NETPLAN_PUBLIC gboolean +netplan_netdef_match_interface(const NetplanNetDefinition* netdef, const char* name, const char* mac, const char* driver_name); + +/** + * @brief Query a @ref NetplanNetDefinition for the value of its `dhcp4` setting. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @return Indication if @p netdef is configured to enable DHCP for IPv4 + */ +NETPLAN_PUBLIC gboolean +netplan_netdef_get_dhcp4(const NetplanNetDefinition* netdef); + +/** + * @brief Query a @ref NetplanNetDefinition for the value of its `dhcp6` setting. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @return Indication if @p netdef is configured to enable DHCP for IPv6 + */ +NETPLAN_PUBLIC gboolean +netplan_netdef_get_dhcp6(const NetplanNetDefinition* netdef); + +/** + * @brief Get the `macaddress` setting of a given @ref NetplanNetDefinition. + * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the + * buffer is too small its content will not be `NUL`-terminated. + * @note This is unrelated to the `match.macaddress` setting. + * @param[in] netdef The @ref NetplanNetDefinition to query + * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller + * @param[in] out_buffer_size The maximum size (in bytes) available for @p out_buffer + * @return The size of the copied string, including the final `NUL` character. + * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. + */ +NETPLAN_PUBLIC ssize_t +netplan_netdef_get_macaddress(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buffer_size); diff --git a/include/netplan.h b/include/netplan.h index c06dceb7e..7cb908b0a 100644 --- a/include/netplan.h +++ b/include/netplan.h @@ -17,12 +17,13 @@ /** * @file netplan.h - * @brief Functions for manipulating @ref NetplanState and @ref NetplanNetDefinition objects. + * @brief Functions for manipulating @ref NetplanState objects. */ #pragma once #include #include "types.h" +#include "netdef.h" // API compat with NetworkManager YAML backend /** * @brief Allocate and initialize a new @ref NetplanState object. @@ -49,13 +50,15 @@ NETPLAN_PUBLIC void netplan_state_clear(NetplanState** np_state); /** - * @brief Get the global @ref NetplanBackend defined in this @ref NetplanState. - * @note This will be the default fallback backend to render any contained @ref NetplanNetDefinition on, if not otherwise specified. - * @param[in] np_state The @ref NetplanState to query - * @return Enumeration value, specifiying the @ref NetplanBackend + * @brief Validate pre-parsed Netplan configuration data inside a @ref NetplanParser and import them into a @ref NetplanState. + * @details This will transfer ownership of the contained data from @p npp to @p np_state and clean up by calling @ref netplan_parser_reset. + * @param[in] np_state The @ref NetplanState to be filled with validated Netplan configuration from @p npp + * @param[in] npp The @ref NetplanParser containing unvalidated Netplan configuration from raw inputs + * @param[out] error Will be filled with a @ref NetplanError in case of failure + * @return Indication of success or failure */ -NETPLAN_PUBLIC NetplanBackend -netplan_state_get_backend(const NetplanState* np_state); +NETPLAN_PUBLIC gboolean +netplan_state_import_parser_results(NetplanState* np_state, NetplanParser* npp, NetplanError** error); /** * @brief Get the number of @ref NetplanNetDefinition configurations stored in this @ref NetplanState @@ -76,46 +79,13 @@ NETPLAN_PUBLIC NetplanNetDefinition* netplan_state_get_netdef(const NetplanState* np_state, const char* id); /** - * @brief Write generic NetworkManager configuration to disk. - * @details This configures global settings, independent of @ref NetplanNetDefinition data, like udev blocklisting to make NetworkManager ignore certain interfaces using `[device].managed=false` or `NM_MANAGED=0`. - * @param[in] np_state The @ref NetplanState to read settings from - * @param[in] rootdir If not `NULL`, generate configuration in this root directory (useful for testing) - * @param[out] error Will be filled with a @ref NetplanError in case of failure - * @return Indication of success or failure - */ -NETPLAN_PUBLIC gboolean -netplan_state_finish_nm_write( - const NetplanState* np_state, - const char* rootdir, - NetplanError** error); - -/** - * @brief Write generic Open vSwitch configuration to disk. - * @details This configures global settings, independent of @ref NetplanNetDefinition data, like patch ports, SSL configuration or the `netplan-ovs-cleanup.service` unit. - * @param[in] np_state The @ref NetplanState to read settings from - * @param[in] rootdir If not `NULL`, generate configuration in this root directory (useful for testing) - * @param[out] error Will be filled with a @ref NetplanError in case of failure - * @return Indication of success or failure - */ -NETPLAN_PUBLIC gboolean -netplan_state_finish_ovs_write( - const NetplanState* np_state, - const char* rootdir, - NetplanError** error); - -/** - * @brief Write generic SR-IOV configuration to disk. - * @details This configures global settings, independent of @ref NetplanNetDefinition data, like udev rules or the `netplan-sriov-rebind.service` unit. - * @param[in] np_state The @ref NetplanState to read settings from - * @param[in] rootdir If not `NULL`, generate configuration in this root directory (useful for testing) - * @param[out] error Will be filled with a @ref NetplanError in case of failure - * @return Indication of success or failure + * @brief Get the global @ref NetplanBackend defined in this @ref NetplanState. + * @note This will be the default fallback backend to render any contained @ref NetplanNetDefinition on, if not otherwise specified. + * @param[in] np_state The @ref NetplanState to query + * @return Enumeration value, specifiying the @ref NetplanBackend */ -NETPLAN_PUBLIC gboolean -netplan_state_finish_sriov_write( - const NetplanState* np_state, - const char* rootdir, - NetplanError** error); +NETPLAN_PUBLIC NetplanBackend +netplan_state_get_backend(const NetplanState* np_state); /** * @brief Write the selected YAML file, filtered to the data relevant to this file. @@ -181,155 +151,67 @@ netplan_netdef_write_yaml( NetplanError** error); /** - * @brief Get the origin filepath of a given @ref NetplanNetDefinition. - * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the - * buffer is too small its content will not be `NUL`-terminated. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller - * @param[in] out_buffer_size The maximum size (in bytes) available for @p out_buffer - * @return The size of the copied string, including the final `NUL` character. - * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. - */ -NETPLAN_PUBLIC ssize_t -netplan_netdef_get_filepath(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buffer_size); - -/** - * @brief Get the specific @ref NetplanBackend defined for this @ref NetplanNetDefinition. - * @param[in] np_state The @ref NetplanState to query - * @return Enumeration value, specifiying the @ref NetplanBackend - */ -NETPLAN_PUBLIC NetplanBackend -netplan_netdef_get_backend(const NetplanNetDefinition* netdef); - -/** - * @brief Get the interface type for a given @ref NetplanNetDefinition. - * @param[in] np_state The @ref NetplanState to query - * @return Enumeration value of @ref NetplanDefType, specifiying the interface type - */ -NETPLAN_PUBLIC NetplanDefType -netplan_netdef_get_type(const NetplanNetDefinition* netdef); - -/** - * @brief Get the Netplan ID of a given @ref NetplanNetDefinition. - * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the - * buffer is too small its content will not be `NUL`-terminated. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller - * @param[in] out_buffer_size The maximum size (in bytes) available for @p out_buffer - * @return The size of the copied string, including the final `NUL` character. - * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. - */ -NETPLAN_PUBLIC ssize_t -netplan_netdef_get_id(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buffer_size); - -/** - * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. - * @details This defines the parent-child relationship between bridged interfaces. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @return Reference to the parent of @p netdef - */ -NETPLAN_PUBLIC NetplanNetDefinition* -netplan_netdef_get_bridge_link(const NetplanNetDefinition* netdef); - -/** - * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. - * @details This defines the parent-child relationship between bonded interfaces. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @return Reference to the parent of @p netdef - */ -NETPLAN_PUBLIC NetplanNetDefinition* -netplan_netdef_get_bond_link(const NetplanNetDefinition* netdef); - -/** - * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. - * @details This defines the peer relationship between veth or Open vSwitch interfaces. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @return Reference to the peer of @p netdef - */ -NETPLAN_PUBLIC NetplanNetDefinition* -netplan_netdef_get_peer_link(const NetplanNetDefinition* netdef); - -/** - * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. - * @details This defines the parent-child relationship of VLAN interfaces. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @return Reference to the parent of @p netdef + * @brief Initialize a @ref NetplanStateIterator for walking through a list of @ref NetplanNetDefinition inside @p np_state. + * @param[in] np_state The @ref NetplanState to query + * @param[in,out] iter A @ref NetplanStateIterator structure to be initialized */ -NETPLAN_PUBLIC NetplanNetDefinition* -netplan_netdef_get_vlan_link(const NetplanNetDefinition* netdef); +NETPLAN_PUBLIC void +netplan_state_iterator_init(const NetplanState* np_state, NetplanStateIterator* iter); /** - * @brief Get a reference to a linked @ref NetplanNetDefinition for a given @p netdef. - * @details This defines the parent-child relationship of SR-IOV virtual functions. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @return Reference to the physical function of @p netdef + * @brief Get the next @ref NetplanNetDefinition in the list of a @ref NetplanState object. + * @param[in,out] iter A @ref NetplanStateIterator to work with + * @return The next @ref NetplanNetDefinition or `NULL` */ NETPLAN_PUBLIC NetplanNetDefinition* -netplan_netdef_get_sriov_link(const NetplanNetDefinition* netdef); - -/** - * @brief Get the `set-name` setting of a given @ref NetplanNetDefinition. - * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the - * buffer is too small its content will not be `NUL`-terminated. - * @note This is unrelated to the `match.name` setting. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller - * @param[in] out_buffer_size The maximum size (in bytes) available for @p out_buffer - * @return The size of the copied string, including the final `NUL` character. - * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. - */ -NETPLAN_PUBLIC ssize_t -netplan_netdef_get_set_name(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buffer_size); +netplan_state_iterator_next(NetplanStateIterator* iter); /** - * @brief Query a @ref NetplanNetDefinition for a `match` stanza in its configuration. - * @details In the absence of a `match` stanza, the Netplan ID - can be considered to be the interface name of a single interface. Otherwise, it could match multiple interfaces. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @return Indication if @p netdef uses custom interface matching rules + * @brief Check if there is any next @ref NetplanNetDefinition in the list of a @ref NetplanState object. + * @param[in,out] iter A @ref NetplanStateIterator to work with + * @return Indication if this @ref NetplanStateIterator contains any further @ref NetplanNetDefinition */ NETPLAN_PUBLIC gboolean -netplan_netdef_has_match(const NetplanNetDefinition* netdef); +netplan_state_iterator_has_next(const NetplanStateIterator* iter); /** - * @brief Gheck if a @ref NetplanNetDefinition matches on given interface parameters. - * @details If defined in @p netdef calculate if it would match on given @p mac AND @p name AND @p driver_name parameters. - * @note Matching a single driver out of a list given in the YAML configuration is enough to satisfy the condition. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @param[in] name The interface name match, optionally using shell wildcard patterns (`fnmatch()`) - * @param[in] mac The exact, case insensitive match on the interface MAC address - * @param[in] driver_name The driver match, optionally using shell wildcard patterns (`fnmatch()`) - * @return Indication if @p netdef uses custom interface matching rules + * @brief Write generic NetworkManager configuration to disk. + * @details This configures global settings, independent of @ref NetplanNetDefinition data, like udev blocklisting to make NetworkManager ignore certain interfaces using `[device].managed=false` or `NM_MANAGED=0`. + * @param[in] np_state The @ref NetplanState to read settings from + * @param[in] rootdir If not `NULL`, generate configuration in this root directory (useful for testing) + * @param[out] error Will be filled with a @ref NetplanError in case of failure + * @return Indication of success or failure */ NETPLAN_PUBLIC gboolean -netplan_netdef_match_interface(const NetplanNetDefinition* netdef, const char* name, const char* mac, const char* driver_name); +netplan_state_finish_nm_write( + const NetplanState* np_state, + const char* rootdir, + NetplanError** error); /** - * @brief Query a @ref NetplanNetDefinition for the value of its `dhcp4` setting. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @return Indication if @p netdef is configured to enable DHCP for IPv4 + * @brief Write generic Open vSwitch configuration to disk. + * @details This configures global settings, independent of @ref NetplanNetDefinition data, like patch ports, SSL configuration or the `netplan-ovs-cleanup.service` unit. + * @param[in] np_state The @ref NetplanState to read settings from + * @param[in] rootdir If not `NULL`, generate configuration in this root directory (useful for testing) + * @param[out] error Will be filled with a @ref NetplanError in case of failure + * @return Indication of success or failure */ NETPLAN_PUBLIC gboolean -netplan_netdef_get_dhcp4(const NetplanNetDefinition* netdef); +netplan_state_finish_ovs_write( + const NetplanState* np_state, + const char* rootdir, + NetplanError** error); /** - * @brief Query a @ref NetplanNetDefinition for the value of its `dhcp6` setting. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @return Indication if @p netdef is configured to enable DHCP for IPv6 + * @brief Write generic SR-IOV configuration to disk. + * @details This configures global settings, independent of @ref NetplanNetDefinition data, like udev rules or the `netplan-sriov-rebind.service` unit. + * @param[in] np_state The @ref NetplanState to read settings from + * @param[in] rootdir If not `NULL`, generate configuration in this root directory (useful for testing) + * @param[out] error Will be filled with a @ref NetplanError in case of failure + * @return Indication of success or failure */ NETPLAN_PUBLIC gboolean -netplan_netdef_get_dhcp6(const NetplanNetDefinition* netdef); - -/** - * @brief Get the `macaddress` setting of a given @ref NetplanNetDefinition. - * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the - * buffer is too small its content will not be `NUL`-terminated. - * @note This is unrelated to the `match.macaddress` setting. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller - * @param[in] out_buffer_size The maximum size (in bytes) available for @p out_buffer - * @return The size of the copied string, including the final `NUL` character. - * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. - */ -NETPLAN_PUBLIC ssize_t -netplan_netdef_get_macaddress(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buffer_size); +netplan_state_finish_sriov_write( + const NetplanState* np_state, + const char* rootdir, + NetplanError** error); diff --git a/include/parse.h b/include/parse.h index a4626371b..d70ef740b 100644 --- a/include/parse.h +++ b/include/parse.h @@ -116,14 +116,3 @@ netplan_parser_load_nullable_fields(NetplanParser* npp, int input_fd, NetplanErr NETPLAN_PUBLIC gboolean netplan_parser_load_nullable_overrides( NetplanParser* npp, int input_fd, const char* constraint, NetplanError** error); - -/** - * @brief Validate pre-parsed Netplan configuration data inside a @ref NetplanParser and import them into a @ref NetplanState. - * @details This will transfer ownership of the contained data from @p npp to @p np_state and clean up by calling @ref netplan_parser_reset. - * @param[in] np_state The @ref NetplanState to be filled with validated Netplan configuration from @p npp - * @param[in] npp The @ref NetplanParser containing unvalidated Netplan configuration from raw inputs - * @param[out] error Will be filled with a @ref NetplanError in case of failure - * @return Indication of success or failure - */ -NETPLAN_PUBLIC gboolean -netplan_state_import_parser_results(NetplanState* np_state, NetplanParser* npp, NetplanError** error); diff --git a/include/util.h b/include/util.h index e8b9f75f8..e604319d0 100644 --- a/include/util.h +++ b/include/util.h @@ -55,21 +55,6 @@ netplan_delete_connection(const char* id, const char* rootdir); NETPLAN_PUBLIC ssize_t netplan_get_id_from_nm_filepath(const char* filename, const char* ssid, char* out_buffer, size_t out_buf_size); -/** - * @brief Get the full path that a @ref NetplanNetDefinition will be written to by its backend renderer. - * @details Copies a `NUL`-terminated string into a sized @p out_buffer. If the - * buffer is too small its content will not be `NUL`-terminated. - * @note Used by the NetworkManager YAML backend but also applicable to the systemd-networkd renderer. - * @param[in] netdef The @ref NetplanNetDefinition to query - * @param[in] ssid Wi-Fi SSID of this connection, or `NULL` - * @param[out] out_buffer A pre-allocated buffer to write the output string into, owned by the caller - * @param[in] out_buf_size The maximum size (in bytes) available for @p out_buffer - * @return The size of the copied string, including the final `NUL` character. - * If the buffer is too small, returns @ref NETPLAN_BUFFER_TOO_SMALL instead. - */ -NETPLAN_PUBLIC ssize_t -netplan_netdef_get_output_filename(const NetplanNetDefinition* netdef, const char* ssid, char* out_buffer, size_t out_buf_size); - /** * @brief Free a @ref NetplanError, including any dynamically allocated data. * @details Free @p error and set `*error` to `NULL`. @@ -106,30 +91,6 @@ netplan_error_message(NetplanError* error, char* buf, size_t buf_size); NETPLAN_PUBLIC uint64_t netplan_error_code(NetplanError* error); -/** - * @brief Initialize a @ref NetplanStateIterator for walking through a list of @ref NetplanNetDefinition inside @p np_state. - * @param[in] np_state The @ref NetplanState to query - * @param[in,out] iter A @ref NetplanStateIterator structure to be initialized - */ -NETPLAN_PUBLIC void -netplan_state_iterator_init(const NetplanState* np_state, NetplanStateIterator* iter); - -/** - * @brief Get the next @ref NetplanNetDefinition in the list of a @ref NetplanState object. - * @param[in,out] iter A @ref NetplanStateIterator to work with - * @return The next @ref NetplanNetDefinition or `NULL` - */ -NETPLAN_PUBLIC NetplanNetDefinition* -netplan_state_iterator_next(NetplanStateIterator* iter); - -/** - * @brief Check if there is any next @ref NetplanNetDefinition in the list of a @ref NetplanState object. - * @param[in,out] iter A @ref NetplanStateIterator to work with - * @return Indication if this @ref NetplanStateIterator contains any further @ref NetplanNetDefinition - */ -NETPLAN_PUBLIC gboolean -netplan_state_iterator_has_next(const NetplanStateIterator* iter); - /** * @brief Create a YAML document from a "netplan-set expression". * @details A "set expression" here consists of a path formed of `TAB`-separated