Network Interface

Overview

The network interface is a nexus that ties the network device drivers and the upper part of the network stack together. All the sent and received data is transferred via a network interface. The network interfaces cannot be created at runtime. A special linker section will contain information about them and that section is populated at linking time.

Network interfaces are created by NET_DEVICE_INIT() macro. For Ethernet network, a macro called ETH_NET_DEVICE_INIT() should be used instead as it will create VLAN interfaces automatically if CONFIG_NET_VLAN is enabled. These macros are typically used in network device driver source code.

The network interface can be turned ON by calling net_if_up() and OFF by calling net_if_down(). When the device is powered ON, the network interface is also turned ON by default.

The network interfaces can be referenced either by a struct net_if * pointer or by a network interface index. The network interface can be resolved from its index by calling net_if_get_by_index() and from interface pointer by calling net_if_get_by_iface().

The IP address for network devices must be set for them to be connectable. In a typical dynamic network environment, IP addresses are set automatically by DHCPv4, for example. If needed though, the application can set a device’s IP address manually. See the API documentation below for functions such as net_if_ipv4_addr_add() that do that.

The net_if_get_default() returns a default network interface. What this default interface means can be configured via options like CONFIG_NET_DEFAULT_IF_FIRST and CONFIG_NET_DEFAULT_IF_ETHERNET. See Kconfig file subsys/net/ip/Kconfig what options are available for selecting the default network interface.

The transmitted and received network packets can be classified via a network packet priority. This is typically done in Ethernet networks when virtual LANs (VLANs) are used. Higher priority packets can be sent or received earlier than lower priority packets. The traffic class setup can be configured by CONFIG_NET_TC_TX_COUNT and CONFIG_NET_TC_RX_COUNT options.

If the CONFIG_NET_PROMISCUOUS_MODE is enabled and if the underlaying network technology supports promiscuous mode, then it is possible to receive all the network packets that the network device driver is able to receive. See Promiscuous Mode API for more details.

API Reference

group net_if

Network Interface abstraction layer.

Defines

NET_DEVICE_INIT(dev_name, drv_name, init_fn, pm_control_fn, data, cfg, prio, api, l2, l2_ctx_type, mtu)

Create a network interface and bind it to network device.

Parameters
  • dev_name: Network device name.

  • drv_name: The name this instance of the driver exposes to the system.

  • init_fn: Address to the init function of the driver.

  • pm_control_fn: Pointer to device_pm_control function. Can be empty function (device_pm_control_nop) if not implemented.

  • data: Pointer to the device’s private data.

  • cfg: The address to the structure containing the configuration information for this instance of the driver.

  • prio: The initialization level at which configuration occurs.

  • api: Provides an initial pointer to the API function struct used by the driver. Can be NULL.

  • l2: Network L2 layer for this network interface.

  • l2_ctx_type: Type of L2 context data.

  • mtu: Maximum transfer unit in bytes for this network interface.

NET_DEVICE_DT_DEFINE(node_id, init_fn, pm_control_fn, data, cfg, prio, api, l2, l2_ctx_type, mtu)

Like NET_DEVICE_INIT but taking metadata from a devicetree node. Create a network interface and bind it to network device.

Parameters
  • node_id: The devicetree node identifier.

  • init_fn: Address to the init function of the driver.

  • pm_control_fn: Pointer to device_pm_control function. Can be empty function (device_pm_control_nop) if not implemented.

  • data: Pointer to the device’s private data.

  • cfg: The address to the structure containing the configuration information for this instance of the driver.

  • prio: The initialization level at which configuration occurs.

  • api: Provides an initial pointer to the API function struct used by the driver. Can be NULL.

  • l2: Network L2 layer for this network interface.

  • l2_ctx_type: Type of L2 context data.

  • mtu: Maximum transfer unit in bytes for this network interface.

NET_DEVICE_DT_INST_DEFINE(inst, ...)

Like NET_DEVICE_DT_DEFINE for an instance of a DT_DRV_COMPAT compatible.

Parameters
  • inst: instance number. This is replaced by DT_DRV_COMPAT(inst) in the call to NET_DEVICE_DT_DEFINE.

  • ...: other parameters as expected by NET_DEVICE_DT_DEFINE.

NET_DEVICE_INIT_INSTANCE(dev_name, drv_name, instance, init_fn, pm_control_fn, data, cfg, prio, api, l2, l2_ctx_type, mtu)

Create multiple network interfaces and bind them to network device. If your network device needs more than one instance of a network interface, use this macro below and provide a different instance suffix each time (0, 1, 2, … or a, b, c … whatever works for you)

Parameters
  • dev_name: Network device name.

  • drv_name: The name this instance of the driver exposes to the system.

  • instance: Instance identifier.

  • init_fn: Address to the init function of the driver.

  • pm_control_fn: Pointer to device_pm_control function. Can be empty function (device_pm_control_nop) if not implemented.

  • data: Pointer to the device’s private data.

  • cfg: The address to the structure containing the configuration information for this instance of the driver.

  • prio: The initialization level at which configuration occurs.

  • api: Provides an initial pointer to the API function struct used by the driver. Can be NULL.

  • l2: Network L2 layer for this network interface.

  • l2_ctx_type: Type of L2 context data.

  • mtu: Maximum transfer unit in bytes for this network interface.

NET_DEVICE_DT_DEFINE_INSTANCE(node_id, instance, init_fn, pm_control_fn, data, cfg, prio, api, l2, l2_ctx_type, mtu)

Like NET_DEVICE_OFFLOAD_INIT but taking metadata from a devicetree. Create multiple network interfaces and bind them to network device. If your network device needs more than one instance of a network interface, use this macro below and provide a different instance suffix each time (0, 1, 2, … or a, b, c … whatever works for you)

Parameters
  • node_id: The devicetree node identifier.

  • instance: Instance identifier.

  • init_fn: Address to the init function of the driver.

  • pm_control_fn: Pointer to device_pm_control function. Can be empty function (device_pm_control_nop) if not implemented.

  • data: Pointer to the device’s private data.

  • cfg: The address to the structure containing the configuration information for this instance of the driver.

  • prio: The initialization level at which configuration occurs.

  • api: Provides an initial pointer to the API function struct used by the driver. Can be NULL.

  • l2: Network L2 layer for this network interface.

  • l2_ctx_type: Type of L2 context data.

  • mtu: Maximum transfer unit in bytes for this network interface.

NET_DEVICE_DT_INST_DEFINE_INSTANCE(inst, ...)

Like NET_DEVICE_DT_DEFINE_INSTANCE for an instance of a DT_DRV_COMPAT compatible.

Parameters
  • inst: instance number. This is replaced by DT_DRV_COMPAT(inst) in the call to NET_DEVICE_DT_DEFINE_INSTANCE.

  • ...: other parameters as expected by NET_DEVICE_DT_DEFINE_INSTANCE.

NET_DEVICE_OFFLOAD_INIT(dev_name, drv_name, init_fn, pm_control_fn, data, cfg, prio, api, mtu)

Create a offloaded network interface and bind it to network device. The offloaded network interface is implemented by a device vendor HAL or similar.

Parameters
  • dev_name: Network device name.

  • drv_name: The name this instance of the driver exposes to the system.

  • init_fn: Address to the init function of the driver.

  • pm_control_fn: Pointer to device_pm_control function. Can be empty function (device_pm_control_nop) if not implemented.

  • data: Pointer to the device’s private data.

  • cfg: The address to the structure containing the configuration information for this instance of the driver.

  • prio: The initialization level at which configuration occurs.

  • api: Provides an initial pointer to the API function struct used by the driver. Can be NULL.

  • mtu: Maximum transfer unit in bytes for this network interface.

NET_DEVICE_DT_OFFLOAD_DEFINE(node_id, init_fn, pm_control_fn, data, cfg, prio, api, mtu)

Like NET_DEVICE_OFFLOAD_INIT but taking metadata from a devicetree node. Create a offloaded network interface and bind it to network device. The offloaded network interface is implemented by a device vendor HAL or similar.

Parameters
  • node_id: The devicetree node identifier.

  • init_fn: Address to the init function of the driver.

  • pm_control_fn: Pointer to device_pm_control function. Can be empty function (device_pm_control_nop) if not implemented.

  • data: Pointer to the device’s private data.

  • cfg: The address to the structure containing the configuration information for this instance of the driver.

  • prio: The initialization level at which configuration occurs.

  • api: Provides an initial pointer to the API function struct used by the driver. Can be NULL.

  • mtu: Maximum transfer unit in bytes for this network interface.

NET_DEVICE_DT_INST_OFFLOAD_DEFINE(inst, ...)

Like NET_DEVICE_DT_OFFLOAD_DEFINE for an instance of a DT_DRV_COMPAT compatible.

Parameters
  • inst: instance number. This is replaced by DT_DRV_COMPAT(inst) in the call to NET_DEVICE_DT_OFFLOAD_DEFINE.

  • ...: other parameters as expected by NET_DEVICE_DT_OFFLOAD_DEFINE.

Typedefs

typedef void (*net_if_mcast_callback_t)(struct net_if *iface, const struct in6_addr *addr, bool is_joined)

Define callback that is called whenever IPv6 multicast address group is joined or left.

Parameters
  • iface: A pointer to a struct net_if to which the multicast address is attached.

  • addr: IPv6 multicast address.

  • is_joined: True if the address is joined, false if left.

Define callback that is called after a network packet has been sent.

Parameters
  • iface: A pointer to a struct net_if to which the the net_pkt was sent to.

  • dst: Link layer address of the destination where the network packet was sent.

  • status: Send status, 0 is ok, < 0 error.

typedef void (*net_if_cb_t)(struct net_if *iface, void *user_data)

Callback used while iterating over network interfaces.

Parameters
  • iface: Pointer to current network interface

  • user_data: A valid pointer to user data or NULL

Enums

enum net_if_flag

Values:

enumerator NET_IF_UP

Interface is up/ready to receive and transmit

enumerator NET_IF_POINTOPOINT

Interface is pointopoint

enumerator NET_IF_PROMISC

Interface is in promiscuous mode

enumerator NET_IF_NO_AUTO_START

Do not start the interface immediately after initialization. This requires that either the device driver or some other entity will need to manually take the interface up when needed. For example for Ethernet this will happen when the driver calls the net_eth_carrier_on() function.

enumerator NET_IF_SUSPENDED

Power management specific: interface is being suspended

enumerator NET_IF_FORWARD_MULTICASTS

Flag defines if received multicasts of other interface are forwarded on this interface. This activates multicast routing / forwarding for this interface.

Functions

static inline void net_if_flag_set(struct net_if *iface, enum net_if_flag value)

Set a value in network interface flags.

Parameters
  • iface: Pointer to network interface

  • value: Flag value

static inline bool net_if_flag_test_and_set(struct net_if *iface, enum net_if_flag value)

Test and set a value in network interface flags.

Return

true if the bit was set, false if it wasn’t.

Parameters
  • iface: Pointer to network interface

  • value: Flag value

static inline void net_if_flag_clear(struct net_if *iface, enum net_if_flag value)

Clear a value in network interface flags.

Parameters
  • iface: Pointer to network interface

  • value: Flag value

static inline bool net_if_flag_is_set(struct net_if *iface, enum net_if_flag value)

Check if a value in network interface flags is set.

Return

True if the value is set, false otherwise

Parameters
  • iface: Pointer to network interface

  • value: Flag value

enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)

Send a packet through a net iface.

return verdict about the packet

Parameters
  • iface: Pointer to a network interface structure

  • pkt: Pointer to a net packet to send

static inline const struct net_l2 *const net_if_l2(struct net_if *iface)

Get a pointer to the interface L2.

Return

a pointer to the iface L2

Parameters
  • iface: a valid pointer to a network interface structure

enum net_verdict net_if_recv_data(struct net_if *iface, struct net_pkt *pkt)

Input a packet through a net iface.

Return

verdict about the packet

Parameters
  • iface: Pointer to a network interface structure

  • pkt: Pointer to a net packet to input

static inline void *net_if_l2_data(struct net_if *iface)

Get a pointer to the interface L2 private data.

Return

a pointer to the iface L2 data

Parameters
  • iface: a valid pointer to a network interface structure

static inline const struct device *net_if_get_device(struct net_if *iface)

Get an network interface’s device.

Return

a pointer to the device driver instance

Parameters
  • iface: Pointer to a network interface structure

void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)

Queue a packet to the net interface TX queue.

Parameters
  • iface: Pointer to a network interface structure

  • pkt: Pointer to a net packet to queue

static inline bool net_if_is_ip_offloaded(struct net_if *iface)

Return the IP offload status.

Return

True if IP offlining is active, false otherwise.

Parameters
  • iface: Network interface

static inline struct net_offload *net_if_offload(struct net_if *iface)

Return the IP offload plugin.

Return

NULL if there is no offload plugin defined, valid pointer otherwise

Parameters
  • iface: Network interface

static inline bool net_if_is_socket_offloaded(struct net_if *iface)

Return the socket offload status.

Return

True if socket offloading is active, false otherwise.

Parameters
  • iface: Network interface

Get an network interface’s link address.

Return

a pointer to the network link address

Parameters
  • iface: Pointer to a network interface structure

static inline struct net_if_config *net_if_get_config(struct net_if *iface)

Return network configuration for this network interface.

Return

Pointer to configuration

Parameters
  • iface: Pointer to a network interface structure

static inline void net_if_start_dad(struct net_if *iface)

Start duplicate address detection procedure.

Parameters
  • iface: Pointer to a network interface structure

void net_if_start_rs(struct net_if *iface)

Start neighbor discovery and send router solicitation message.

Parameters
  • iface: Pointer to a network interface structure

static inline void net_if_stop_rs(struct net_if *iface)

Stop neighbor discovery.

Parameters
  • iface: Pointer to a network interface structure

Set a network interface’s link address.

Return

0 on success

Parameters
  • iface: Pointer to a network interface structure

  • addr: A pointer to a uint8_t buffer representing the address. The buffer must remain valid throughout interface lifetime.

  • len: length of the address buffer

  • type: network bearer type of this link address

static inline uint16_t net_if_get_mtu(struct net_if *iface)

Get an network interface’s MTU.

Return

the MTU

Parameters
  • iface: Pointer to a network interface structure

static inline void net_if_set_mtu(struct net_if *iface, uint16_t mtu)

Set an network interface’s MTU.

Parameters
  • iface: Pointer to a network interface structure

  • mtu: New MTU, note that we store only 16 bit mtu value.

static inline void net_if_addr_set_lf(struct net_if_addr *ifaddr, bool is_infinite)

Set the infinite status of the network interface address.

Parameters
  • ifaddr: IP address for network interface

  • is_infinite: Infinite status

Get an interface according to link layer address.

Return

Network interface or NULL if not found.

Parameters
  • ll_addr: Link layer address.

struct net_if *net_if_lookup_by_dev(const struct device *dev)

Find an interface from it’s related device.

Return

a valid struct net_if pointer on success, NULL otherwise

Parameters
  • dev: A valid struct device pointer to relate with an interface

static inline struct net_if_config *net_if_config_get(struct net_if *iface)

Get network interface IP config.

Return

NULL if not found or pointer to correct config settings.

Parameters
  • iface: Interface to use.

static inline void net_if_router_rm(struct net_if_router *router)

Remove a router from the system.

Parameters
  • router: Pointer to existing router

struct net_if *net_if_get_default(void)

Get the default network interface.

Return

Default interface or NULL if no interfaces are configured.

struct net_if *net_if_get_first_by_type(const struct net_l2 *l2)

Get the first network interface according to its type.

Return

First network interface of a given type or NULL if no such interfaces was found.

Parameters
  • l2: Layer 2 type of the network interface.

int net_if_config_ipv6_get(struct net_if *iface, struct net_if_ipv6 **ipv6)

Allocate network interface IPv6 config.

This function will allocate new IPv6 config.

Return

0 if ok, <0 if error

Parameters
  • iface: Interface to use.

  • ipv6: Pointer to allocated IPv6 struct is returned to caller.

int net_if_config_ipv6_put(struct net_if *iface)

Release network interface IPv6 config.

Return

0 if ok, <0 if error

Parameters
  • iface: Interface to use.

struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr, struct net_if **iface)

Check if this IPv6 address belongs to one of the interfaces.

Return

Pointer to interface address, NULL if not found.

Parameters
  • addr: IPv6 address

  • iface: Pointer to interface is returned

struct net_if_addr *net_if_ipv6_addr_lookup_by_iface(struct net_if *iface, struct in6_addr *addr)

Check if this IPv6 address belongs to this specific interfaces.

Return

Pointer to interface address, NULL if not found.

Parameters
  • iface: Network interface

  • addr: IPv6 address

int net_if_ipv6_addr_lookup_by_index(const struct in6_addr *addr)

Check if this IPv6 address belongs to one of the interface indices.

Return

>0 if address was found in given network interface index, all other values mean address was not found

Parameters
  • addr: IPv6 address

struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface, struct in6_addr *addr, enum net_addr_type addr_type, uint32_t vlifetime)

Add a IPv6 address to an interface.

Return

Pointer to interface address, NULL if cannot be added

Parameters
  • iface: Network interface

  • addr: IPv6 address

  • addr_type: IPv6 address type

  • vlifetime: Validity time for this address

bool net_if_ipv6_addr_add_by_index(int index, struct in6_addr *addr, enum net_addr_type addr_type, uint32_t vlifetime)

Add a IPv6 address to an interface by index.

Return

True if ok, false if address could not be added

Parameters
  • index: Network interface index

  • addr: IPv6 address

  • addr_type: IPv6 address type

  • vlifetime: Validity time for this address

void net_if_ipv6_addr_update_lifetime(struct net_if_addr *ifaddr, uint32_t vlifetime)

Update validity lifetime time of an IPv6 address.

Parameters
  • ifaddr: Network IPv6 address

  • vlifetime: Validity time for this address

bool net_if_ipv6_addr_rm(struct net_if *iface, const struct in6_addr *addr)

Remove an IPv6 address from an interface.

Return

True if successfully removed, false otherwise

Parameters
  • iface: Network interface

  • addr: IPv6 address

bool net_if_ipv6_addr_rm_by_index(int index, const struct in6_addr *addr)

Remove an IPv6 address from an interface by index.

Return

True if successfully removed, false otherwise

Parameters
  • index: Network interface index

  • addr: IPv6 address

struct net_if_mcast_addr *net_if_ipv6_maddr_add(struct net_if *iface, const struct in6_addr *addr)

Add a IPv6 multicast address to an interface.

Return

Pointer to interface multicast address, NULL if cannot be added

Parameters
  • iface: Network interface

  • addr: IPv6 multicast address

bool net_if_ipv6_maddr_rm(struct net_if *iface, const struct in6_addr *addr)

Remove an IPv6 multicast address from an interface.

Return

True if successfully removed, false otherwise

Parameters
  • iface: Network interface

  • addr: IPv6 multicast address

struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(const struct in6_addr *addr, struct net_if **iface)

Check if this IPv6 multicast address belongs to a specific interface or one of the interfaces.

Return

Pointer to interface multicast address, NULL if not found.

Parameters
  • addr: IPv6 address

  • iface: If *iface is null, then pointer to interface is returned, otherwise the *iface value needs to be matched.

void net_if_mcast_mon_register(struct net_if_mcast_monitor *mon, struct net_if *iface, net_if_mcast_callback_t cb)

Register a multicast monitor.

Parameters
  • mon: Monitor handle. This is a pointer to a monitor storage structure which should be allocated by caller, but does not need to be initialized.

  • iface: Network interface

  • cb: Monitor callback

void net_if_mcast_mon_unregister(struct net_if_mcast_monitor *mon)

Unregister a multicast monitor.

Parameters
  • mon: Monitor handle

void net_if_mcast_monitor(struct net_if *iface, const struct in6_addr *addr, bool is_joined)

Call registered multicast monitors.

Parameters
  • iface: Network interface

  • addr: Multicast address

  • is_joined: Is this multicast address joined (true) or not (false)

static inline void net_if_ipv6_maddr_join(struct net_if_mcast_addr *addr)

Mark a given multicast address to be joined.

Parameters
  • addr: IPv6 multicast address

static inline bool net_if_ipv6_maddr_is_joined(struct net_if_mcast_addr *addr)

Check if given multicast address is joined or not.

Return

True if address is joined, False otherwise.

Parameters
  • addr: IPv6 multicast address

static inline void net_if_ipv6_maddr_leave(struct net_if_mcast_addr *addr)

Mark a given multicast address to be left.

Parameters
  • addr: IPv6 multicast address

struct net_if_ipv6_prefix *net_if_ipv6_prefix_get(struct net_if *iface, struct in6_addr *addr)

Return prefix that corresponds to this IPv6 address.

Return

Pointer to prefix, NULL if not found.

Parameters
  • iface: Network interface

  • addr: IPv6 address

struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface, struct in6_addr *addr, uint8_t len)

Check if this IPv6 prefix belongs to this interface.

Return

Pointer to prefix, NULL if not found.

Parameters
  • iface: Network interface

  • addr: IPv6 address

  • len: Prefix length

struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface, struct in6_addr *prefix, uint8_t len, uint32_t lifetime)

Add a IPv6 prefix to an network interface.

Return

Pointer to prefix, NULL if the prefix was not added.

Parameters
  • iface: Network interface

  • prefix: IPv6 address

  • len: Prefix length

  • lifetime: Prefix lifetime in seconds

bool net_if_ipv6_prefix_rm(struct net_if *iface, struct in6_addr *addr, uint8_t len)

Remove an IPv6 prefix from an interface.

Return

True if successfully removed, false otherwise

Parameters
  • iface: Network interface

  • addr: IPv6 prefix address

  • len: Prefix length

static inline void net_if_ipv6_prefix_set_lf(struct net_if_ipv6_prefix *prefix, bool is_infinite)

Set the infinite status of the prefix.

Parameters
  • prefix: IPv6 address

  • is_infinite: Infinite status

void net_if_ipv6_prefix_set_timer(struct net_if_ipv6_prefix *prefix, uint32_t lifetime)

Set the prefix lifetime timer.

Parameters
  • prefix: IPv6 address

  • lifetime: Prefix lifetime in seconds

void net_if_ipv6_prefix_unset_timer(struct net_if_ipv6_prefix *prefix)

Unset the prefix lifetime timer.

Parameters
  • prefix: IPv6 address

Check if this IPv6 address is part of the subnet of our network interface.

Return

True if address is part of our subnet, false otherwise

Parameters
  • iface: Network interface. This is returned to the caller. The iface can be NULL in which case we check all the interfaces.

  • addr: IPv6 address

static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)

Get the IPv6 address of the given router.

Return

pointer to the IPv6 address, or NULL if none

Parameters
  • router: a network router

struct net_if_router *net_if_ipv6_router_lookup(struct net_if *iface, struct in6_addr *addr)

Check if IPv6 address is one of the routers configured in the system.

Return

Pointer to router information, NULL if cannot be found

Parameters
  • iface: Network interface

  • addr: IPv6 address

struct net_if_router *net_if_ipv6_router_find_default(struct net_if *iface, struct in6_addr *addr)

Find default router for this IPv6 address.

Return

Pointer to router information, NULL if cannot be found

Parameters
  • iface: Network interface. This can be NULL in which case we go through all the network interfaces to find a suitable router.

  • addr: IPv6 address

void net_if_ipv6_router_update_lifetime(struct net_if_router *router, uint16_t lifetime)

Update validity lifetime time of a router.

Parameters
  • router: Network IPv6 address

  • lifetime: Lifetime of this router.

struct net_if_router *net_if_ipv6_router_add(struct net_if *iface, struct in6_addr *addr, uint16_t router_lifetime)

Add IPv6 router to the system.

Return

Pointer to router information, NULL if could not be added

Parameters
  • iface: Network interface

  • addr: IPv6 address

  • router_lifetime: Lifetime of the router

bool net_if_ipv6_router_rm(struct net_if_router *router)

Remove IPv6 router from the system.

Return

True if successfully removed, false otherwise

Parameters
  • router: Router information.

static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)

Get IPv6 hop limit specified for a given interface. This is the default value but can be overridden by the user.

Return

Hop limit

Parameters
  • iface: Network interface

static inline void net_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit)

Set the default IPv6 hop limit of a given interface.

Parameters
  • iface: Network interface

  • hop_limit: New hop limit

static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface, uint32_t reachable_time)

Set IPv6 reachable time for a given interface.

Parameters
  • iface: Network interface

  • reachable_time: New reachable time

static inline uint32_t net_if_ipv6_get_reachable_time(struct net_if *iface)

Get IPv6 reachable timeout specified for a given interface.

Return

Reachable timeout

Parameters
  • iface: Network interface

uint32_t net_if_ipv6_calc_reachable_time(struct net_if_ipv6 *ipv6)

Calculate next reachable time value for IPv6 reachable time.

Return

Reachable time

Parameters
  • ipv6: IPv6 address configuration

static inline void net_if_ipv6_set_reachable_time(struct net_if_ipv6 *ipv6)

Set IPv6 reachable time for a given interface. This requires that base reachable time is set for the interface.

Parameters
  • ipv6: IPv6 address configuration

static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface, uint32_t retrans_timer)

Set IPv6 retransmit timer for a given interface.

Parameters
  • iface: Network interface

  • retrans_timer: New retransmit timer

static inline uint32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)

Get IPv6 retransmit timer specified for a given interface.

Return

Retransmit timer

Parameters
  • iface: Network interface

static inline const struct in6_addr *net_if_ipv6_select_src_addr(struct net_if *iface, const struct in6_addr *dst)

Get a IPv6 source address that should be used when sending network data to destination.

Return

Pointer to IPv6 address to use, NULL if no IPv6 address could be found.

Parameters
  • iface: Interface that was used when packet was received. If the interface is not known, then NULL can be given.

  • dst: IPv6 destination address

static inline struct net_if *net_if_ipv6_select_src_iface(const struct in6_addr *dst)

Get a network interface that should be used when sending IPv6 network data to destination.

Return

Pointer to network interface to use, NULL if no suitable interface could be found.

Parameters
  • dst: IPv6 destination address

struct in6_addr *net_if_ipv6_get_ll(struct net_if *iface, enum net_addr_state addr_state)

Get a IPv6 link local address in a given state.

Return

Pointer to link local IPv6 address, NULL if no proper IPv6 address could be found.

Parameters
  • iface: Interface to use. Must be a valid pointer to an interface.

  • addr_state: IPv6 address state (preferred, tentative, deprecated)

struct in6_addr *net_if_ipv6_get_ll_addr(enum net_addr_state state, struct net_if **iface)

Return link local IPv6 address from the first interface that has a link local address matching give state.

Return

Pointer to IPv6 address, NULL if not found.

Parameters
  • state: IPv6 address state (ANY, TENTATIVE, PREFERRED, DEPRECATED)

  • iface: Pointer to interface is returned

void net_if_ipv6_dad_failed(struct net_if *iface, const struct in6_addr *addr)

Stop IPv6 Duplicate Address Detection (DAD) procedure if we find out that our IPv6 address is already in use.

Parameters
  • iface: Interface where the DAD was running.

  • addr: IPv6 address that failed DAD

struct in6_addr *net_if_ipv6_get_global_addr(enum net_addr_state state, struct net_if **iface)

Return global IPv6 address from the first interface that has a global IPv6 address matching the given state.

Return

Pointer to IPv6 address, NULL if not found.

Parameters
  • state: IPv6 address state (ANY, TENTATIVE, PREFERRED, DEPRECATED)

  • iface: Caller can give an interface to check. If iface is set to NULL, then all the interfaces are checked. Pointer to interface where the IPv6 address is defined is returned to the caller.

int net_if_config_ipv4_get(struct net_if *iface, struct net_if_ipv4 **ipv4)

Allocate network interface IPv4 config.

This function will allocate new IPv4 config.

Return

0 if ok, <0 if error

Parameters
  • iface: Interface to use.

  • ipv4: Pointer to allocated IPv4 struct is returned to caller.

int net_if_config_ipv4_put(struct net_if *iface)

Release network interface IPv4 config.

Return

0 if ok, <0 if error

Parameters
  • iface: Interface to use.

static inline uint8_t net_if_ipv4_get_ttl(struct net_if *iface)

Get IPv4 time-to-live value specified for a given interface.

Return

Time-to-live

Parameters
  • iface: Network interface

struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr, struct net_if **iface)

Check if this IPv4 address belongs to one of the interfaces.

Return

Pointer to interface address, NULL if not found.

Parameters
  • addr: IPv4 address

  • iface: Interface is returned

struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface, struct in_addr *addr, enum net_addr_type addr_type, uint32_t vlifetime)

Add a IPv4 address to an interface.

Return

Pointer to interface address, NULL if cannot be added

Parameters
  • iface: Network interface

  • addr: IPv4 address

  • addr_type: IPv4 address type

  • vlifetime: Validity time for this address

bool net_if_ipv4_addr_rm(struct net_if *iface, const struct in_addr *addr)

Remove a IPv4 address from an interface.

Return

True if successfully removed, false otherwise

Parameters
  • iface: Network interface

  • addr: IPv4 address

int net_if_ipv4_addr_lookup_by_index(const struct in_addr *addr)

Check if this IPv4 address belongs to one of the interface indices.

Return

>0 if address was found in given network interface index, all other values mean address was not found

Parameters
  • addr: IPv4 address

bool net_if_ipv4_addr_add_by_index(int index, struct in_addr *addr, enum net_addr_type addr_type, uint32_t vlifetime)

Add a IPv4 address to an interface by network interface index.

Return

True if ok, false if the address could not be added

Parameters
  • index: Network interface index

  • addr: IPv4 address

  • addr_type: IPv4 address type

  • vlifetime: Validity time for this address

bool net_if_ipv4_addr_rm_by_index(int index, const struct in_addr *addr)

Remove a IPv4 address from an interface by interface index.

Return

True if successfully removed, false otherwise

Parameters
  • index: Network interface index

  • addr: IPv4 address

struct net_if_mcast_addr *net_if_ipv4_maddr_add(struct net_if *iface, const struct in_addr *addr)

Add a IPv4 multicast address to an interface.

Return

Pointer to interface multicast address, NULL if cannot be added

Parameters
  • iface: Network interface

  • addr: IPv4 multicast address

bool net_if_ipv4_maddr_rm(struct net_if *iface, const struct in_addr *addr)

Remove an IPv4 multicast address from an interface.

Return

True if successfully removed, false otherwise

Parameters
  • iface: Network interface

  • addr: IPv4 multicast address

struct net_if_mcast_addr *net_if_ipv4_maddr_lookup(const struct in_addr *addr, struct net_if **iface)

Check if this IPv4 multicast address belongs to a specific interface or one of the interfaces.

Return

Pointer to interface multicast address, NULL if not found.

Parameters
  • addr: IPv4 address

  • iface: If *iface is null, then pointer to interface is returned, otherwise the *iface value needs to be matched.

static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)

Get the IPv4 address of the given router.

Return

pointer to the IPv4 address, or NULL if none

Parameters
  • router: a network router

struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface, struct in_addr *addr)

Check if IPv4 address is one of the routers configured in the system.

Return

Pointer to router information, NULL if cannot be found

Parameters
  • iface: Network interface

  • addr: IPv4 address

struct net_if_router *net_if_ipv4_router_find_default(struct net_if *iface, struct in_addr *addr)

Find default router for this IPv4 address.

Return

Pointer to router information, NULL if cannot be found

Parameters
  • iface: Network interface. This can be NULL in which case we go through all the network interfaces to find a suitable router.

  • addr: IPv4 address

struct net_if_router *net_if_ipv4_router_add(struct net_if *iface, struct in_addr *addr, bool is_default, uint16_t router_lifetime)

Add IPv4 router to the system.

Return

Pointer to router information, NULL if could not be added

Parameters
  • iface: Network interface

  • addr: IPv4 address

  • is_default: Is this router the default one

  • router_lifetime: Lifetime of the router

bool net_if_ipv4_router_rm(struct net_if_router *router)

Remove IPv4 router from the system.

Return

True if successfully removed, false otherwise

Parameters
  • router: Router information.

bool net_if_ipv4_addr_mask_cmp(struct net_if *iface, const struct in_addr *addr)

Check if the given IPv4 address belongs to local subnet.

Return

True if address is part of local subnet, false otherwise.

Parameters
  • iface: Interface to use. Must be a valid pointer to an interface.

  • addr: IPv4 address

bool net_if_ipv4_is_addr_bcast(struct net_if *iface, const struct in_addr *addr)

Check if the given IPv4 address is a broadcast address.

Return

True if address is a broadcast address, false otherwise.

Parameters
  • iface: Interface to use. Must be a valid pointer to an interface.

  • addr: IPv4 address, this should be in network byte order

static inline struct net_if *net_if_ipv4_select_src_iface(const struct in_addr *dst)

Get a network interface that should be used when sending IPv4 network data to destination.

Return

Pointer to network interface to use, NULL if no suitable interface could be found.

Parameters
  • dst: IPv4 destination address

static inline const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *iface, const struct in_addr *dst)

Get a IPv4 source address that should be used when sending network data to destination.

Return

Pointer to IPv4 address to use, NULL if no IPv4 address could be found.

Parameters
  • iface: Interface to use when sending the packet. If the interface is not known, then NULL can be given.

  • dst: IPv4 destination address

struct in_addr *net_if_ipv4_get_ll(struct net_if *iface, enum net_addr_state addr_state)

Get a IPv4 link local address in a given state.

Return

Pointer to link local IPv4 address, NULL if no proper IPv4 address could be found.

Parameters
  • iface: Interface to use. Must be a valid pointer to an interface.

  • addr_state: IPv4 address state (preferred, tentative, deprecated)

struct in_addr *net_if_ipv4_get_global_addr(struct net_if *iface, enum net_addr_state addr_state)

Get a IPv4 global address in a given state.

Return

Pointer to link local IPv4 address, NULL if no proper IPv4 address could be found.

Parameters
  • iface: Interface to use. Must be a valid pointer to an interface.

  • addr_state: IPv4 address state (preferred, tentative, deprecated)

void net_if_ipv4_set_netmask(struct net_if *iface, const struct in_addr *netmask)

Set IPv4 netmask for an interface.

Parameters
  • iface: Interface to use.

  • netmask: IPv4 netmask

bool net_if_ipv4_set_netmask_by_index(int index, const struct in_addr *netmask)

Set IPv4 netmask for an interface index.

Return

True if netmask was added, false otherwise.

Parameters
  • index: Network interface index

  • netmask: IPv4 netmask

void net_if_ipv4_set_gw(struct net_if *iface, const struct in_addr *gw)

Set IPv4 gateway for an interface.

Parameters
  • iface: Interface to use.

  • gw: IPv4 address of an gateway

bool net_if_ipv4_set_gw_by_index(int index, const struct in_addr *gw)

Set IPv4 gateway for an interface index.

Return

True if gateway was added, false otherwise.

Parameters
  • index: Network interface index

  • gw: IPv4 address of an gateway

struct net_if *net_if_select_src_iface(const struct sockaddr *dst)

Get a network interface that should be used when sending IPv6 or IPv4 network data to destination.

Return

Pointer to network interface to use. Note that the function will return the default network interface if the best network interface is not found.

Parameters
  • dst: IPv6 or IPv4 destination address

Register a link callback.

Parameters
  • link: Caller specified handler for the callback.

  • cb: Callback to register.

Unregister a link callback.

Parameters
  • link: Caller specified handler for the callback.

Call a link callback function.

Parameters
  • iface: Network interface.

  • lladdr: Destination link layer address

  • status: 0 is ok, < 0 error

bool net_if_need_calc_rx_checksum(struct net_if *iface)

Check if received network packet checksum calculation can be avoided or not. For example many ethernet devices support network packet offloading in which case the IP stack does not need to calculate the checksum.

Return

True if checksum needs to be calculated, false otherwise.

Parameters
  • iface: Network interface

bool net_if_need_calc_tx_checksum(struct net_if *iface)

Check if network packet checksum calculation can be avoided or not when sending the packet. For example many ethernet devices support network packet offloading in which case the IP stack does not need to calculate the checksum.

Return

True if checksum needs to be calculated, false otherwise.

Parameters
  • iface: Network interface

struct net_if *net_if_get_by_index(int index)

Get interface according to index.

This is a syscall only to provide access to the object for purposes of assigning permissions.

Return

Pointer to interface or NULL if not found.

Parameters
  • index: Interface index

int net_if_get_by_iface(struct net_if *iface)

Get interface index according to pointer.

Return

Interface index

Parameters
  • iface: Pointer to network interface

void net_if_foreach(net_if_cb_t cb, void *user_data)

Go through all the network interfaces and call callback for each interface.

Parameters
  • cb: User-supplied callback function to call

  • user_data: User specified data

int net_if_up(struct net_if *iface)

Bring interface up.

Return

0 on success

Parameters
  • iface: Pointer to network interface

static inline bool net_if_is_up(struct net_if *iface)

Check if interface is up.

Return

True if interface is up, False if it is down.

Parameters
  • iface: Pointer to network interface

int net_if_down(struct net_if *iface)

Bring interface down.

Return

0 on success

Parameters
  • iface: Pointer to network interface

int net_if_set_promisc(struct net_if *iface)

Set network interface into promiscuous mode.

Note that not all network technologies will support this.

Return

0 on success, <0 if error

Parameters
  • iface: Pointer to network interface

void net_if_unset_promisc(struct net_if *iface)

Set network interface into normal mode.

Parameters
  • iface: Pointer to network interface

bool net_if_is_promisc(struct net_if *iface)

Check if promiscuous mode is set or not.

Return

True if interface is in promisc mode, False if interface is not in in promiscuous mode.

Parameters
  • iface: Pointer to network interface

static inline bool net_if_are_pending_tx_packets(struct net_if *iface)

Check if there are any pending TX network data for a given network interface.

Return

True if there are pending TX network packets for this network interface, False otherwise.

Parameters
  • iface: Pointer to network interface

struct net_if_addr
#include <net_if.h>

Network Interface unicast IP addresses.

Stores the unicast IP addresses assigned to this network interface.

struct net_if_mcast_addr
#include <net_if.h>

Network Interface multicast IP addresses.

Stores the multicast IP addresses assigned to this network interface.

struct net_if_ipv6_prefix
#include <net_if.h>

Network Interface IPv6 prefixes.

Stores the multicast IP addresses assigned to this network interface.

struct net_if_router
#include <net_if.h>

Information about routers in the system.

Stores the router information.

struct net_if_ipv6
#include <net_if.h>
struct net_if_ipv4
#include <net_if.h>
struct net_if_ip
#include <net_if.h>

Network interface IP address configuration.

struct net_if_config
#include <net_if.h>

IP and other configuration related data for network interface.

struct net_traffic_class
#include <net_if.h>

Network traffic class.

Traffic classes are used when sending or receiving data that is classified with different priorities. So some traffic can be marked as high priority and it will be sent or received first. There is always at least one work queue in the system for Rx and Tx. Each network packet that is transmitted or received goes through a work queue thread that will transmit it.

struct net_if_dev
#include <net_if.h>

Network Interface Device structure.

Used to handle a network interface on top of a device driver instance. There can be many net_if_dev instance against the same device.

Such interface is mainly to be used by the link layer, but is also tight to a network context: it then makes the relation with a network context and the network device.

Because of the strong relationship between a device driver and such network interface, each net_if_dev should be instantiated by

struct net_if
#include <net_if.h>

Network Interface structure.

Used to handle a network interface on top of a net_if_dev instance. There can be many net_if instance against the same net_if_dev instance.

struct net_if_mcast_monitor
#include <net_if.h>

Multicast monitor handler struct.

Stores the multicast callback information. Caller must make sure that the variable pointed by this is valid during the lifetime of registration. Typically this means that the variable cannot be allocated from stack.

#include <net_if.h>

Link callback handler struct.

Stores the link callback information. Caller must make sure that the variable pointed by this is valid during the lifetime of registration. Typically this means that the variable cannot be allocated from stack.