This is the documentation for the latest (main) development branch of Zephyr. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

Network Configuration Library

Overview

The network configuration library sets up networking devices in a semi-automatic way during the system boot, based on user-supplied Kconfig options.

The following Kconfig options affect how configuration library will setup the system:

Kconfig options for network configuration library

Option name

Description

:kconfig:`CONFIG_NET_CONFIG_SETTINGS`

This option controls whether the network system is configured or initialized at all. If not set, then the config library is not used for initialization and the application needs to do all the network related configuration itself. If this option is set, then the user can optionally configure static IP addresses to be set to the first network interface in the system. Typically setting static IP addresses is only usable in testing and should not be used in production code. See the config library Kconfig file subsys/net/lib/config/Kconfig for specific options to set the static IP addresses.

:kconfig:`CONFIG_NET_CONFIG_AUTO_INIT`

The networking system is automatically configured when the device is started.

:kconfig:`CONFIG_NET_CONFIG_INIT_TIMEOUT`

This tells how long to wait for the networking to be ready and available. If for example IPv4 address from DHCPv4 is not received within this limit, then a call to net_config_init() will return error during the device startup.

:kconfig:`CONFIG_NET_CONFIG_NEED_IPV4`

The network application needs IPv4 support to function properly. This option makes sure the network application is initialized properly in order to use IPv4. If :kconfig:`CONFIG_NET_IPV4` is not enabled, then setting this option will automatically enable IPv4.

:kconfig:`CONFIG_NET_CONFIG_NEED_IPV6`

The network application needs IPv6 support to function properly. This option makes sure the network application is initialized properly in order to use IPv6. If :kconfig:`CONFIG_NET_IPV6` is not enabled, then setting this option will automatically enable IPv6.

:kconfig:`CONFIG_NET_CONFIG_NEED_IPV6_ROUTER`

If IPv6 is enabled, then this option tells that the network application needs IPv6 router to exists before continuing. This means in practice that the application wants to wait until it receives IPv6 router advertisement message before continuing.

:kconfig:`CONFIG_NET_CONFIG_BT_NODE`

Enables application to operate in Bluetooth node mode which requires GATT service to be registered and start advertising as peripheral.

Sample usage

If :kconfig:`CONFIG_NET_CONFIG_AUTO_INIT` is set, then the configuration library is automatically enabled and run during the device boot. In this case, the library will call net_config_init() automatically and the application does not need to do any network configuration.

If you want to use the network configuration library but without automatic initialization, you can call net_config_init() manually. The flags parameter can be used to give hints to the library about what kind of functionality the application wishes to have before the actual application starts.

API Reference

group net_config

Network configuration library.

Defines

NET_CONFIG_NEED_ROUTER

Application needs routers to be set so that connectivity to remote network is possible. For IPv6 networks, this means that the device should receive IPv6 router advertisement message before continuing.

NET_CONFIG_NEED_IPV6

Application needs IPv6 subsystem configured and initialized. Typically this means that the device has IPv6 address set.

NET_CONFIG_NEED_IPV4

Application needs IPv4 subsystem configured and initialized. Typically this means that the device has IPv4 address set.

Functions

int net_config_init(const char *app_info, uint32_t flags, int32_t timeout)

Initialize this network application.

This will call net_config_init_by_iface() with NULL network interface.

Parameters
  • app_info – String describing this application.

  • flags – Flags related to services needed by the client.

  • timeout – How long to wait the network setup before continuing the startup.

Returns

0 if ok, <0 if error.

int net_config_init_by_iface(struct net_if *iface, const char *app_info, uint32_t flags, int32_t timeout)

Initialize this network application using a specific network interface.

If network interface is set to NULL, then the default one is used in the configuration.

Parameters
  • iface – Initialize networking using this network interface.

  • app_info – String describing this application.

  • flags – Flags related to services needed by the client.

  • timeout – How long to wait the network setup before continuing the startup.

Returns

0 if ok, <0 if error.

int net_config_init_app(const struct device *dev, const char *app_info)

Initialize this network application.

If CONFIG_NET_CONFIG_AUTO_INIT is set, then this function is called automatically when the device boots. If that is not desired, unset the config option and call the function manually when the application starts.

Parameters
  • dev – Network device to use. The function will figure out what network interface to use based on the device. If the device is NULL, then default network interface is used by the function.

  • app_info – String describing this application.

Returns

0 if ok, <0 if error.