Skip to content

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Oct 9, 2025

Note that this PR is continuing the work started on #68127. Most of the commits come directly from that PR, couple of latest ones are new as they add settings db support.

Executive summary of how the PR works:

  • create yaml file describing the network configuration
  • at built time, create a const C struct from this yaml data and compile it to application
  • at runtime, allow user to tweak the configuration and store changes to settings db
  • at boot, apply the default and user changed configuration to network subsystem

More detailed description follows:

This PR adds support to autoconfigure the network sub-system when the device boots. It is mainly meant to be used when there are multiple network interfaces in the system. In that case Kconfig based network configure parameters cannot be used easily as the system will only apply the configuration to one of the network interfaces.

This is related to old enhancement #29750 request. There it was pondered to use devicetree to configuring network stack. As DT is only meant to describe hardware configuration some other way of configuration is needed.

This PR uses yaml file to describe network stack configuration. The configuration data in yaml file is not restricted to network configuration but any subsystem configuration could be done via it. I concentrated to network configuration as we need this multi network interface autoconfiguration in networking.

The PR provides minimal infrastructure to validate a user supplied yaml file and then generate a C configuration data file from it. So we do not import the yaml file directly to the zephyr image, but we use a generator script to generate C header file that is then included by the network config library. When the device boots, the network configurator reads the configuration stored in ROM, and applies the configuration to each network interface found in the system. When the user creates the yaml file, she/he should know the network configuration in order to map the yaml file to the device in use. The configuration from ROM is used as a default read-only configuration.

The user supplied yaml file can be stored outside of zephyr. When building the network application, the location of the yaml file is given so the build system can then utilize it.

At runtime, user is able to adjust the configuration values stored in ROM. The changes will be stored in settings database, currently using NVS backend. The changes to the network configuration can be done via net_config_get/set() API or via a net config shell which provides commands (view/set/remove) to adjust the values in the network configuration. When the device boots, the default configuration in ROM is used as a base and user updated configuration values from settings db are applied on top of that.

This PR is still work in progress, more testing is needed and documentation needs more work if this is to be merged.

Add a way to convert a user supplied yaml file to a configuration
file. For networking, a C header file is generated which can then
be included to the application.

Add a cmake function that calls the generate config macros with
suitable values for networking needs.

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar added the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label Oct 9, 2025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: We're moving away from pykwalify in favour of jsonschema see #90272 and #90261

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info, I will look into converting the code.

@jukkar
Copy link
Member Author

jukkar commented Oct 10, 2025

  • Converted the schema to jsonschema

jukkar added 15 commits October 13, 2025 09:16
This contains rules to validate network configuration in yaml format.

Signed-off-by: Jukka Rissanen <[email protected]>
Add a python script that converts a user supplied network configuration
yaml file to a valid network configuration C header file.

Signed-off-by: Jukka Rissanen <[email protected]>
If CONFIG_NET_CONFIG_SETTINGS is enabled, then the network
configuration library will check if a yaml file net-init-config.yaml
is found in the application directory and use it to generate
network initial configuration that is then applied when the device
boots. If the yaml file is not there, then the relevant Kconfig options
are used to create initial network configuration.

Signed-off-by: Jukka Rissanen <[email protected]>
User can set NET_INIT_CONFIG_FILE to override the name of the
default configuration file name which is net-init-config.yaml
This way a substitute yaml config file can be used instead of
the default one.

Signed-off-by: Jukka Rissanen <[email protected]>
Example networking yaml configuration file. This contains
more complex network setup that can be used to see what
can be done.

Signed-off-by: Jukka Rissanen <[email protected]>
Add documentation about the network stack initialization using
a yaml file.

Signed-off-by: Jukka Rissanen <[email protected]>
If user is not interested in the mask length, the value can be set to
NULL so that it is not been returned to the caller.

Signed-off-by: Jukka Rissanen <[email protected]>
If user has supplied a yaml file, it is used as configuration
data that is applied to network configuration. In this case
the CONFIG_NET_CONFIG_* Kconfig variables used for configuration
are ignored.

Signed-off-by: Jukka Rissanen <[email protected]>
Add simple unit tests that verify that options specified
in yaml file can be used to configure network stack.

Signed-off-by: Jukka Rissanen <[email protected]>
The hash value is used to detect if the yaml format file has
changed so that we know that the data format is changed and
the previous configuration in settings should be abandoned.

Signed-off-by: Jukka Rissanen <[email protected]>
Add __xxx_changed boolean flag to the strcut definition so that
we know if the value was changed by the user.

Signed-off-by: Jukka Rissanen <[email protected]>
Add set and get functions that return/set either the default
settings or if user has changed them, the user adjusted value.
Make these two functions to use settings API.

Signed-off-by: Jukka Rissanen <[email protected]>
Add "net config" command to view the current configuration
and modify or remove the configuration data.

Signed-off-by: Jukka Rissanen <[email protected]>
Convert network configuration schema in pykwalify format to
jsonschema format because pykwalify is being deprecated in
zephyr and jsonschema is used in the future.

Signed-off-by: Jukka Rissanen <[email protected]>
As pykwalify is no longer used in zephyr, the yaml schema format
is changed to jsonschema format. This requires changes to
python script that generates C struct configuration definitions.

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar force-pushed the devel/net-config-overhaul branch from 435dd17 to 871eae7 Compare October 13, 2025 10:47
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants