[PATCHv2 0/9] Add conf.d support and restructure settings
Jussi Laakkonen <[email protected]> Wed, 29 Jul 2026 15:48:14 +0300
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
This set of patches brings conf.d support to ConnMan so main.conf can be
overridden fully or partially by adding new configuration files under
main.conf.d. The files are processed in alphabetical order and the last value
is dominant, following the common approach with conf.d support in general.
This patch set requires the other, previously sent set named as
"[PATCH 0/3] Allow to specify a type for devices that have no uevent file/info"
as a pre-requisite. A full set of patches can be also sent containing both
changes.
Both connmand and vpnd use the same approach for reading configuration files.
The basic version of this has been in Sailfish OS in use for over an year, also
in production release (5.0). The hash table addition to make things cleaner and
easier to add new options is a newer feature backed up with the unit test to
ensure there is no regression.
In order to achieve this, and to make the code reusable, all settings are
moved to setting.c, which has same getters as in main.c had before. The setting
system has been completely reworked and adding of new configuration file
options happens now through a struct in which the name, type and callbacks etc.
can be defined. For example, for BackgroundScanning the entry is:
{
.opt_key = CONF_BG_SCAN,
.opt_value = CONF_BG_SCAN_VAL,
.opt_type = CONF_TYPE_BOOL,
.opt_return_type = CONF_TYPE_BOOL,
.default_val.bool_val = true,
.error_cb = NULL,
.multiplier = 0
},
The key needs to be added to setting.h, the value needs to be added to the
setting.c option_val enum. The fields are detailed as follows:
opt_key Option name, used for searching in getters
opt_value enum value for the option
opt_type Option type, see enum option_type
opt_return_type The type of this option returns, supported: str -> uint
default_val Default value as union option, must match opt_type
parser Union for parser callbacks, contains:
parse_str_cb Check string value: CONF_TYPE_STR
parse_list_cb Parse a string list: CONF_TYPE_STRARR
parse_uint_list_cb Parse int list: CONF_TYPE_UINTARR
parse_hashtable_cb Parse a hash table: CONF_TYPE_HASHTABLE
error_cb Error callback when check_str_cb fails
multiplier For CONF_TYPE_UINT and CONF_TYPE_DOUBLE for correlation
The types that are currently supported for settings are: uint (CONF_TYPE_UINT),
uint* (CONF_TYPE_UINTARR), char* (CONF_TYPE_STR), char** (CONF_TYPE_STRARR),
bool (CONF_TYPE_BOOL), double/real (CONF_TYPE_DOUBLE) and GHashTable
(CONF_TYPE_HASHTABLE). The types, except uint* and GHashTable, are read with
their corresponding reading functions - the GHashTable and uint* are parsed
from char** with the defined callbacks (parse_hashtable_cb, parse_list_uint_cb).
If parse_list_strs_cb is missing the string list is saved as is to
configuration. The error_cb is useful in cases where the value needs a
complicated setup, e.g, with online check mode.
The alternative return type, opt_return_type, can be used to define a
conversion type value for a string. Currently accepted conversions are STR ->
UINT and DOUBLE -> UINT only.
The default_val can be used to define the config option default value. All
regular values (BOOL, INT, DOUBLE) will get the value copied to current_val.
STR will get copied only when it is converted to INT at return. Any INTARR,
STRARR or HASHTABLE opt_type needs to be initialized in
initialize_default_values(), and free'd in __connman_settings_cleanup().
The work for making these patches available for ConnMan upstream has been
funded by NLnet foundation grant NGI0 Commons Fund:
https://nlnet.nl/commonsfund.
The NLnet project website is available at:
https://nlnet.nl/project/ConnMan/.
The changes are also available at:
v1 the original: https://github.com/LaakkonenJussi/connman_ng/pull/4
v2 additions: https://github.com/LaakkonenJussi/connman_ng/pull/5
Changes in v2:
Patch 0:
- Updated the description after changes.
Patch 6: setting.c
- Moved all parser callbacks into an union, a new opt needs to define
only one cb. Dropped the list item callback.
- Fixed memory usage issues potentially causing leaked memory.
Allocating options is now more consistent and less complex.
- Fixed the service type and nameserver list parsing to not to clear
the list if the new list read from config is invalid.
- Removed the unnecessary enum for each config option.
- Improved the commit message.
Patch 8: test-setting.c
- Added invalid config test for checking lists with invalid separators.
Jussi Laakkonen (9):
util: Add conf.d support for connmand and vpnd
main: Support main.conf.d/ files for overriding configs
vpn-settings: Add callback for processing configs, support conf.d
vpn: Use util conf.d to read additional configs
main: Reformat processing of configuration values
setting: Move settings from main to setting with hash table support
wispr: Change online check urls to const char*
unit: Add basic unit test for setting
doc: Document conf.d support
Makefile.am | 14 +-
doc/connman.conf.5.in | 7 +
include/setting.h | 45 +-
src/connman.h | 7 +
src/main.c | 1031 ++-----------------------------
src/setting.c | 1339 +++++++++++++++++++++++++++++++++++++++++
src/shared/util.c | 179 ++++++
src/shared/util.h | 7 +
src/wispr.c | 4 +-
unit/test-setting.c | 1147 +++++++++++++++++++++++++++++++++++
vpn/main.c | 15 +-
vpn/vpn-settings.c | 83 ++-
vpn/vpn.h | 4 +-
13 files changed, 2860 insertions(+), 1022 deletions(-)
create mode 100644 src/setting.c
create mode 100644 unit/test-setting.c
--
2.47.3