[PATCH 0/9] Add conf.d support and restructure settings
Jussi Laakkonen <[email protected]> Wed, 20 May 2026 16:47:04 +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,
.check_str_cb = NULL,
.parse_list_strs_cb = NULL,
.parse_list_uint_cb = NULL,
.parse_list_item_cb = NULL,
.parse_hashtable_cb = NULL,
.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
check_str_cb Callback for checking string value: CONF_TYPE_STR
parse_list_strs_cb Callback for parsing a string list: CONF_TYPE_STRARR
parse_list_uint_cb Callback for parsing int list: CONF_TYPE_UINTARR
parse_list_item_cb Callback to handle of strings separate: CONF_TYPE_STRARR
parse_hashtable_cb Callback for parsing 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 both parse_list_strs_cb and parse_list_item_cb are missing the string list
is saved as is to configuration. The special case of parse_list_item_cb
handling is to not to create a string list but to handle items separately,
for example, using different concatenation to form a one value. 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:
https://github.com/LaakkonenJussi/connman_ng/pull/4
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 | 1574 +++++++++++++++++++++++++++++++++++++++++
src/shared/util.c | 179 +++++
src/shared/util.h | 7 +
src/wispr.c | 4 +-
unit/test-setting.c | 1103 +++++++++++++++++++++++++++++
vpn/main.c | 15 +-
vpn/vpn-settings.c | 83 ++-
vpn/vpn.h | 4 +-
13 files changed, 3051 insertions(+), 1022 deletions(-)
create mode 100644 src/setting.c
create mode 100644 unit/test-setting.c
--
2.47.3