LCOV - code coverage report
Current view: top level - zephyr/net - net_if.h Coverage Total Hit
Test: new.info Lines: 99.6 % 263 262
Test Date: 2025-09-05 22:20:39

            Line data    Source code
       1            1 : /*
       2              :  * Copyright (c) 2016 Intel Corporation.
       3              :  *
       4              :  * SPDX-License-Identifier: Apache-2.0
       5              :  */
       6              : 
       7              : /**
       8              :  * @file
       9              :  * @brief Public API for network interface
      10              :  */
      11              : 
      12              : #ifndef ZEPHYR_INCLUDE_NET_NET_IF_H_
      13              : #define ZEPHYR_INCLUDE_NET_NET_IF_H_
      14              : 
      15              : /**
      16              :  * @brief Network Interface abstraction layer
      17              :  * @defgroup net_if Network Interface abstraction layer
      18              :  * @since 1.5
      19              :  * @version 1.0.0
      20              :  * @ingroup networking
      21              :  * @{
      22              :  */
      23              : 
      24              : #include <zephyr/device.h>
      25              : #include <zephyr/sys/slist.h>
      26              : #include <zephyr/sys/iterable_sections.h>
      27              : #include <zephyr/net/net_core.h>
      28              : #include <zephyr/net/hostname.h>
      29              : #include <zephyr/net/net_linkaddr.h>
      30              : #include <zephyr/net/net_ip.h>
      31              : #include <zephyr/net/net_l2.h>
      32              : #include <zephyr/net/net_stats.h>
      33              : #include <zephyr/net/net_timeout.h>
      34              : 
      35              : #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
      36              : #include <zephyr/net/dhcpv4.h>
      37              : #endif
      38              : #if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6)
      39              : #include <zephyr/net/dhcpv6.h>
      40              : #endif
      41              : #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
      42              : #include <zephyr/net/ipv4_autoconf.h>
      43              : #endif
      44              : 
      45              : #include <zephyr/net/prometheus/collector.h>
      46              : 
      47              : #ifdef __cplusplus
      48              : extern "C" {
      49              : #endif
      50              : 
      51              : /**
      52              :  * @brief Network Interface unicast IP addresses
      53              :  *
      54              :  * Stores the unicast IP addresses assigned to this network interface.
      55              :  */
      56            1 : struct net_if_addr {
      57              :         /** IP address */
      58            1 :         struct net_addr address;
      59              : 
      60              :         /** Reference counter. This is used to prevent address removal if there
      61              :          * are sockets that have bound the local endpoint to this address.
      62              :          */
      63            1 :         atomic_t atomic_ref;
      64              : 
      65              : #if defined(CONFIG_NET_NATIVE_IPV6)
      66              :         struct net_timeout lifetime;
      67              : #endif
      68              : 
      69              :         /** How the IP address was set */
      70            1 :         enum net_addr_type addr_type;
      71              : 
      72              :         /** What is the current state of the address */
      73            1 :         enum net_addr_state addr_state;
      74              : 
      75              : #if defined(CONFIG_NET_NATIVE_IPV6)
      76              : #if defined(CONFIG_NET_IPV6_PE)
      77              :         /** Address creation time. This is used to determine if the maximum
      78              :          * lifetime for this address is reached or not. The value is in seconds.
      79              :          */
      80              :         uint32_t addr_create_time;
      81              : 
      82              :         /** Preferred lifetime for the address in seconds.
      83              :          */
      84              :         uint32_t addr_preferred_lifetime;
      85              : 
      86              :         /** Address timeout value. This is only used if DAD needs to be redone
      87              :          * for this address because of earlier DAD failure. This value is in
      88              :          * seconds.
      89              :          */
      90              :         int32_t addr_timeout;
      91              : #endif
      92              : #endif /* CONFIG_NET_NATIVE_IPV6 */
      93              : 
      94              :         union {
      95              : #if defined(CONFIG_NET_IPV6_DAD)
      96              :                 struct {
      97              :                         /** Duplicate address detection (DAD) timer */
      98              :                         sys_snode_t dad_node;
      99              : 
     100              :                         /** DAD needed list node */
     101              :                         sys_snode_t dad_need_node;
     102              : 
     103              :                         /** DAD start time */
     104              :                         uint32_t dad_start;
     105              : 
     106              :                         /** How many times we have done DAD */
     107              :                         uint8_t dad_count;
     108              :                 };
     109              : #endif /* CONFIG_NET_IPV6_DAD */
     110              : #if defined(CONFIG_NET_IPV4_ACD)
     111              :                 struct {
     112              :                         /** Address conflict detection (ACD) timer. */
     113              :                         sys_snode_t acd_node;
     114              : 
     115              :                         /** ACD needed list node */
     116              :                         sys_snode_t acd_need_node;
     117              : 
     118              :                         /** ACD timeout value. */
     119              :                         k_timepoint_t acd_timeout;
     120              : 
     121              :                         /** ACD probe/announcement counter. */
     122              :                         uint8_t acd_count;
     123              : 
     124              :                         /** ACD status. */
     125              :                         uint8_t acd_state;
     126              :                 };
     127              : #endif /* CONFIG_NET_IPV4_ACD */
     128              :                 uint8_t _dummy;
     129            0 :         };
     130              : 
     131              : #if defined(CONFIG_NET_IPV6_DAD) || defined(CONFIG_NET_IPV4_ACD)
     132              :         /** What interface the conflict detection is running */
     133              :         uint8_t ifindex;
     134              : #endif
     135              : 
     136              :         /** Is the IP address valid forever */
     137            1 :         uint8_t is_infinite : 1;
     138              : 
     139              :         /** Is this IP address used or not */
     140            1 :         uint8_t is_used : 1;
     141              : 
     142              :         /** Is this IP address usage limited to the subnet (mesh) or not */
     143            1 :         uint8_t is_mesh_local : 1;
     144              : 
     145              :         /** Is this IP address temporary and generated for example by
     146              :          * IPv6 privacy extension (RFC 8981)
     147              :          */
     148            1 :         uint8_t is_temporary : 1;
     149              : 
     150              :         /** Was this address added or not */
     151            1 :         uint8_t is_added : 1;
     152              : 
     153              :         uint8_t _unused : 3;
     154              : };
     155              : 
     156              : /**
     157              :  * @brief Network Interface multicast IP addresses
     158              :  *
     159              :  * Stores the multicast IP addresses assigned to this network interface.
     160              :  */
     161            1 : struct net_if_mcast_addr {
     162              :         /** IP address */
     163            1 :         struct net_addr address;
     164              : 
     165              :         /** Rejoining multicast groups list node */
     166            1 :         sys_snode_t rejoin_node;
     167              : 
     168              : #if defined(CONFIG_NET_IPV4_IGMPV3)
     169              :         /** Sources to filter on */
     170              :         struct net_addr sources[CONFIG_NET_IF_MCAST_IPV4_SOURCE_COUNT];
     171              : 
     172              :         /** Number of sources to be used by the filter */
     173              :         uint16_t sources_len;
     174              : 
     175              :         /** Filter mode (used in IGMPV3) */
     176              :         uint8_t record_type;
     177              : #endif
     178              : 
     179              :         /** Is this multicast IP address used or not */
     180            1 :         uint8_t is_used : 1;
     181              : 
     182              :         /** Did we join to this group */
     183            1 :         uint8_t is_joined : 1;
     184              : 
     185              :         uint8_t _unused : 6;
     186              : };
     187              : 
     188              : /**
     189              :  * @brief Network Interface IPv6 prefixes
     190              :  *
     191              :  * Stores the IPV6 prefixes assigned to this network interface.
     192              :  */
     193            1 : struct net_if_ipv6_prefix {
     194              :         /** Prefix lifetime */
     195            1 :         struct net_timeout lifetime;
     196              : 
     197              :         /** IPv6 prefix */
     198            1 :         struct in6_addr prefix;
     199              : 
     200              :         /** Backpointer to network interface where this prefix is used */
     201            1 :         struct net_if *iface;
     202              : 
     203              :         /** Prefix length */
     204            1 :         uint8_t len;
     205              : 
     206              :         /** Is the IP prefix valid forever */
     207            1 :         uint8_t is_infinite : 1;
     208              : 
     209              :         /** Is this prefix used or not */
     210            1 :         uint8_t is_used : 1;
     211              : 
     212              :         uint8_t _unused : 6;
     213              : };
     214              : 
     215              : /**
     216              :  * @brief Information about routers in the system.
     217              :  *
     218              :  * Stores the router information.
     219              :  */
     220            1 : struct net_if_router {
     221              :         /** Slist lifetime timer node */
     222            1 :         sys_snode_t node;
     223              : 
     224              :         /** IP address */
     225            1 :         struct net_addr address;
     226              : 
     227              :         /** Network interface the router is connected to */
     228            1 :         struct net_if *iface;
     229              : 
     230              :         /** Router life timer start */
     231            1 :         uint32_t life_start;
     232              : 
     233              :         /** Router lifetime */
     234            1 :         uint16_t lifetime;
     235              : 
     236              :         /** Is this router used or not */
     237            1 :         uint8_t is_used : 1;
     238              : 
     239              :         /** Is default router */
     240            1 :         uint8_t is_default : 1;
     241              : 
     242              :         /** Is the router valid forever */
     243            1 :         uint8_t is_infinite : 1;
     244              : 
     245              :         uint8_t _unused : 5;
     246              : };
     247              : 
     248              : /** Network interface flags. */
     249            1 : enum net_if_flag {
     250              :         /** Interface is admin up. */
     251              :         NET_IF_UP,
     252              : 
     253              :         /** Interface is pointopoint */
     254              :         NET_IF_POINTOPOINT,
     255              : 
     256              :         /** Interface is in promiscuous mode */
     257              :         NET_IF_PROMISC,
     258              : 
     259              :         /** Do not start the interface immediately after initialization.
     260              :          * This requires that either the device driver or some other entity
     261              :          * will need to manually take the interface up when needed.
     262              :          * For example for Ethernet this will happen when the driver calls
     263              :          * the net_eth_carrier_on() function.
     264              :          */
     265              :         NET_IF_NO_AUTO_START,
     266              : 
     267              :         /** Power management specific: interface is being suspended */
     268              :         NET_IF_SUSPENDED,
     269              : 
     270              :         /** Flag defines if received multicasts of other interface are
     271              :          * forwarded on this interface. This activates multicast
     272              :          * routing / forwarding for this interface.
     273              :          */
     274              :         NET_IF_FORWARD_MULTICASTS,
     275              : 
     276              :         /** Interface supports IPv4 */
     277              :         NET_IF_IPV4,
     278              : 
     279              :         /** Interface supports IPv6 */
     280              :         NET_IF_IPV6,
     281              : 
     282              :         /** Interface up and running (ready to receive and transmit). */
     283              :         NET_IF_RUNNING,
     284              : 
     285              :         /** Driver signals L1 is up. */
     286              :         NET_IF_LOWER_UP,
     287              : 
     288              :         /** Driver signals dormant. */
     289              :         NET_IF_DORMANT,
     290              : 
     291              :         /** IPv6 Neighbor Discovery disabled. */
     292              :         NET_IF_IPV6_NO_ND,
     293              : 
     294              :         /** IPv6 Multicast Listener Discovery disabled. */
     295              :         NET_IF_IPV6_NO_MLD,
     296              : 
     297              :         /** Mutex locking on TX data path disabled on the interface. */
     298              :         NET_IF_NO_TX_LOCK,
     299              : 
     300              : /** @cond INTERNAL_HIDDEN */
     301              :         /* Total number of flags - must be at the end of the enum */
     302              :         NET_IF_NUM_FLAGS
     303              : /** @endcond */
     304              : };
     305              : 
     306              : /** @brief Network interface operational status (RFC 2863). */
     307            1 : enum net_if_oper_state {
     308              :         NET_IF_OPER_UNKNOWN,        /**< Initial (unknown) value */
     309              :         NET_IF_OPER_NOTPRESENT,     /**< Hardware missing */
     310              :         NET_IF_OPER_DOWN,           /**< Interface is down */
     311              :         NET_IF_OPER_LOWERLAYERDOWN, /**< Lower layer interface is down */
     312              :         NET_IF_OPER_TESTING,        /**< Training mode */
     313              :         NET_IF_OPER_DORMANT,        /**< Waiting external action */
     314              :         NET_IF_OPER_UP,             /**< Interface is up */
     315              : } __packed;
     316              : 
     317              : #if defined(CONFIG_NET_OFFLOAD)
     318              : struct net_offload;
     319              : #endif /* CONFIG_NET_OFFLOAD */
     320              : 
     321              : /** @cond INTERNAL_HIDDEN */
     322              : #if defined(CONFIG_NET_IPV6)
     323              : #define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT
     324              : #define NET_IF_MAX_IPV6_MADDR CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT
     325              : #define NET_IF_MAX_IPV6_PREFIX CONFIG_NET_IF_IPV6_PREFIX_COUNT
     326              : #else
     327              : #define NET_IF_MAX_IPV6_ADDR 0
     328              : #define NET_IF_MAX_IPV6_MADDR 0
     329              : #define NET_IF_MAX_IPV6_PREFIX 0
     330              : #endif
     331              : /* @endcond */
     332              : 
     333              : /** IPv6 configuration */
     334            1 : struct net_if_ipv6 {
     335              :         /** Unicast IP addresses */
     336            1 :         struct net_if_addr unicast[NET_IF_MAX_IPV6_ADDR];
     337              : 
     338              :         /** Multicast IP addresses */
     339            1 :         struct net_if_mcast_addr mcast[NET_IF_MAX_IPV6_MADDR];
     340              : 
     341              :         /** Prefixes */
     342            1 :         struct net_if_ipv6_prefix prefix[NET_IF_MAX_IPV6_PREFIX];
     343              : 
     344              :         /** Default reachable time (RFC 4861, page 52) */
     345            1 :         uint32_t base_reachable_time;
     346              : 
     347              :         /** Reachable time (RFC 4861, page 20) */
     348            1 :         uint32_t reachable_time;
     349              : 
     350              :         /** Retransmit timer (RFC 4861, page 52) */
     351            1 :         uint32_t retrans_timer;
     352              : 
     353              : #if defined(CONFIG_NET_IPV6_IID_STABLE)
     354              :         /** IID (Interface Identifier) pointer used for link local address */
     355              :         struct net_if_addr *iid;
     356              : 
     357              :         /** Incremented when network interface goes down so that we can
     358              :          * generate new stable addresses when interface comes back up.
     359              :          */
     360              :         uint32_t network_counter;
     361              : #endif /* CONFIG_NET_IPV6_IID_STABLE */
     362              : 
     363              : #if defined(CONFIG_NET_IPV6_PE)
     364              :         /** Privacy extension DESYNC_FACTOR value from RFC 8981 ch 3.4.
     365              :          * "DESYNC_FACTOR is a random value within the range 0 - MAX_DESYNC_FACTOR.
     366              :          * It is computed every time a temporary address is created.
     367              :          */
     368              :         uint32_t desync_factor;
     369              : #endif /* CONFIG_NET_IPV6_PE */
     370              : 
     371              : #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
     372              :         /** Router solicitation timer node */
     373              :         sys_snode_t rs_node;
     374              : 
     375              :         /* RS start time */
     376              :         uint32_t rs_start;
     377              : 
     378              :         /** RS count */
     379              :         uint8_t rs_count;
     380              : #endif
     381              : 
     382              :         /** IPv6 hop limit */
     383            1 :         uint8_t hop_limit;
     384              : 
     385              :         /** IPv6 multicast hop limit */
     386            1 :         uint8_t mcast_hop_limit;
     387              : };
     388              : 
     389              : #if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6)
     390              : /** DHCPv6 configuration */
     391              : struct net_if_dhcpv6 {
     392              :         /** Used for timer list. */
     393              :         sys_snode_t node;
     394              : 
     395              :         /** Generated Client ID. */
     396              :         struct net_dhcpv6_duid_storage clientid;
     397              : 
     398              :         /** Server ID of the selected server. */
     399              :         struct net_dhcpv6_duid_storage serverid;
     400              : 
     401              :         /** DHCPv6 client state. */
     402              :         enum net_dhcpv6_state state;
     403              : 
     404              :         /** DHCPv6 client configuration parameters. */
     405              :         struct net_dhcpv6_params params;
     406              : 
     407              :         /** Timeout for the next event, absolute time, milliseconds. */
     408              :         uint64_t timeout;
     409              : 
     410              :         /** Time of the current exchange start, absolute time, milliseconds */
     411              :         uint64_t exchange_start;
     412              : 
     413              :         /** Renewal time, absolute time, milliseconds. */
     414              :         uint64_t t1;
     415              : 
     416              :         /** Rebinding time, absolute time, milliseconds. */
     417              :         uint64_t t2;
     418              : 
     419              :         /** The time when the last lease expires (terminates rebinding,
     420              :          *  DHCPv6 RFC8415, ch. 18.2.5). Absolute time, milliseconds.
     421              :          */
     422              :         uint64_t expire;
     423              : 
     424              :         /** Generated IAID for IA_NA. */
     425              :         uint32_t addr_iaid;
     426              : 
     427              :         /** Generated IAID for IA_PD. */
     428              :         uint32_t prefix_iaid;
     429              : 
     430              :         /** Retransmit timeout for the current message, milliseconds. */
     431              :         uint32_t retransmit_timeout;
     432              : 
     433              :         /** Current best server preference received. */
     434              :         int16_t server_preference;
     435              : 
     436              :         /** Retransmission counter. */
     437              :         uint8_t retransmissions;
     438              : 
     439              :         /** Transaction ID for current exchange. */
     440              :         uint8_t tid[DHCPV6_TID_SIZE];
     441              : 
     442              :         /** Prefix length. */
     443              :         uint8_t prefix_len;
     444              : 
     445              :         /** Assigned IPv6 prefix. */
     446              :         struct in6_addr prefix;
     447              : 
     448              :         /** Assigned IPv6 address. */
     449              :         struct in6_addr addr;
     450              : };
     451              : #endif /* defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) */
     452              : 
     453              : /** @cond INTERNAL_HIDDEN */
     454              : #if defined(CONFIG_NET_IPV4)
     455              : #define NET_IF_MAX_IPV4_ADDR CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT
     456              : #define NET_IF_MAX_IPV4_MADDR CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT
     457              : #else
     458              : #define NET_IF_MAX_IPV4_ADDR 0
     459              : #define NET_IF_MAX_IPV4_MADDR 0
     460              : #endif
     461              : /** @endcond */
     462              : 
     463              : /**
     464              :  * @brief Network Interface unicast IPv4 address and netmask
     465              :  *
     466              :  * Stores the unicast IPv4 address and related netmask.
     467              :  */
     468            1 : struct net_if_addr_ipv4 {
     469              :         /** IPv4 address */
     470            1 :         struct net_if_addr ipv4;
     471              :         /** Netmask */
     472            1 :         struct in_addr netmask;
     473              : };
     474              : 
     475              : /** IPv4 configuration */
     476            1 : struct net_if_ipv4 {
     477              :         /** Unicast IP addresses */
     478            1 :         struct net_if_addr_ipv4 unicast[NET_IF_MAX_IPV4_ADDR];
     479              : 
     480              :         /** Multicast IP addresses */
     481            1 :         struct net_if_mcast_addr mcast[NET_IF_MAX_IPV4_MADDR];
     482              : 
     483              :         /** Gateway */
     484            1 :         struct in_addr gw;
     485              : 
     486              :         /** IPv4 time-to-live */
     487            1 :         uint8_t ttl;
     488              : 
     489              :         /** IPv4 time-to-live for multicast packets */
     490            1 :         uint8_t mcast_ttl;
     491              : 
     492              : #if defined(CONFIG_NET_IPV4_ACD)
     493              :         /** IPv4 conflict count.  */
     494              :         uint8_t conflict_cnt;
     495              : #endif
     496              : };
     497              : 
     498              : #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
     499              : struct net_if_dhcpv4 {
     500              :         /** Used for timer lists */
     501              :         sys_snode_t node;
     502              : 
     503              :         /** Timer start */
     504              :         int64_t timer_start;
     505              : 
     506              :         /** Time for INIT, INIT-REBOOT, DISCOVER, REQUESTING, RENEWAL */
     507              :         uint32_t request_time;
     508              : 
     509              :         uint32_t xid;
     510              : 
     511              :         /** IP address Lease time */
     512              :         uint32_t lease_time;
     513              : 
     514              :         /** IP address Renewal time */
     515              :         uint32_t renewal_time;
     516              : 
     517              :         /** IP address Rebinding time */
     518              :         uint32_t rebinding_time;
     519              : 
     520              :         /** Server ID */
     521              :         struct in_addr server_id;
     522              : 
     523              :         /** Requested IP addr */
     524              :         struct in_addr requested_ip;
     525              : 
     526              :         /** Received netmask from the server */
     527              :         struct in_addr netmask;
     528              : 
     529              :         /**
     530              :          *  DHCPv4 client state in the process of network
     531              :          *  address allocation.
     532              :          */
     533              :         enum net_dhcpv4_state state;
     534              : 
     535              :         /** Number of attempts made for REQUEST and RENEWAL messages */
     536              :         uint8_t attempts;
     537              : 
     538              :         /** The address of the server the request is sent to */
     539              :         struct in_addr request_server_addr;
     540              : 
     541              :         /** The source address of a received DHCP message */
     542              :         struct in_addr response_src_addr;
     543              : 
     544              : #ifdef CONFIG_NET_DHCPV4_OPTION_NTP_SERVER
     545              :         /** NTP server address */
     546              :         struct in_addr ntp_addr;
     547              : #endif
     548              : };
     549              : #endif /* CONFIG_NET_DHCPV4 */
     550              : 
     551              : #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
     552              : struct net_if_ipv4_autoconf {
     553              :         /** Backpointer to correct network interface */
     554              :         struct net_if *iface;
     555              : 
     556              :         /** Requested IP addr */
     557              :         struct in_addr requested_ip;
     558              : 
     559              :         /** IPV4 Autoconf state in the process of network address allocation.
     560              :          */
     561              :         enum net_ipv4_autoconf_state state;
     562              : };
     563              : #endif /* CONFIG_NET_IPV4_AUTO */
     564              : 
     565              : /** @cond INTERNAL_HIDDEN */
     566              : /* We always need to have at least one IP config */
     567              : #define NET_IF_MAX_CONFIGS 1
     568              : /** @endcond */
     569              : 
     570              : /**
     571              :  * @brief Network interface IP address configuration.
     572              :  */
     573            1 : struct net_if_ip {
     574              : #if defined(CONFIG_NET_IPV6)
     575              :         struct net_if_ipv6 *ipv6;
     576              : #endif /* CONFIG_NET_IPV6 */
     577              : 
     578              : #if defined(CONFIG_NET_IPV4)
     579              :         struct net_if_ipv4 *ipv4;
     580              : #endif /* CONFIG_NET_IPV4 */
     581              : };
     582              : 
     583              : /**
     584              :  * @brief IP and other configuration related data for network interface.
     585              :  */
     586            1 : struct net_if_config {
     587              : #if defined(CONFIG_NET_IP)
     588              :         /** IP address configuration setting */
     589              :         struct net_if_ip ip;
     590              : #endif
     591              : 
     592              : #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
     593              :         struct net_if_dhcpv4 dhcpv4;
     594              : #endif /* CONFIG_NET_DHCPV4 */
     595              : 
     596              : #if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6)
     597              :         struct net_if_dhcpv6 dhcpv6;
     598              : #endif /* CONFIG_NET_DHCPV6 */
     599              : 
     600              : #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
     601              :         struct net_if_ipv4_autoconf ipv4auto;
     602              : #endif /* CONFIG_NET_IPV4_AUTO */
     603              : 
     604              : #if defined(CONFIG_NET_L2_VIRTUAL)
     605              :         /**
     606              :          * This list keeps track of the virtual network interfaces
     607              :          * that are attached to this network interface.
     608              :          */
     609              :         sys_slist_t virtual_interfaces;
     610              : #endif /* CONFIG_NET_L2_VIRTUAL */
     611              : 
     612              : #if defined(CONFIG_NET_INTERFACE_NAME)
     613              :         /**
     614              :          * Network interface can have a name and it is possible
     615              :          * to search a network interface using this name.
     616              :          */
     617              :         char name[CONFIG_NET_INTERFACE_NAME_LEN + 1];
     618              : #endif
     619              : };
     620              : 
     621              : /**
     622              :  * @brief Network traffic class.
     623              :  *
     624              :  * Traffic classes are used when sending or receiving data that is classified
     625              :  * with different priorities. So some traffic can be marked as high priority
     626              :  * and it will be sent or received first. Each network packet that is
     627              :  * transmitted or received goes through a fifo to a thread that will transmit
     628              :  * it.
     629              :  */
     630            1 : struct net_traffic_class {
     631              :         /** Fifo for handling this Tx or Rx packet */
     632            1 :         struct k_fifo fifo;
     633              : 
     634              : #if NET_TC_COUNT > 1 || defined(CONFIG_NET_TC_TX_SKIP_FOR_HIGH_PRIO) \
     635              :         || defined(CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO)
     636              :         /** Semaphore for tracking the available slots in the fifo */
     637              :         struct k_sem fifo_slot;
     638              : #endif
     639              : 
     640              :         /** Traffic class handler thread */
     641            1 :         struct k_thread handler;
     642              : 
     643              :         /** Stack for this handler */
     644            1 :         k_thread_stack_t *stack;
     645              : };
     646              : 
     647              : /**
     648              :  * @typedef net_socket_create_t
     649              : 
     650              :  * @brief A function prototype to create an offloaded socket. The prototype is
     651              :  *        compatible with socket() function.
     652              :  */
     653            1 : typedef int (*net_socket_create_t)(int, int, int);
     654              : 
     655              : /**
     656              :  * @brief Network Interface Device structure
     657              :  *
     658              :  * Used to handle a network interface on top of a device driver instance.
     659              :  * There can be many net_if_dev instance against the same device.
     660              :  *
     661              :  * Such interface is mainly to be used by the link layer, but is also tight
     662              :  * to a network context: it then makes the relation with a network context
     663              :  * and the network device.
     664              :  *
     665              :  * Because of the strong relationship between a device driver and such
     666              :  * network interface, each net_if_dev should be instantiated by one of the
     667              :  * network device init macros found in net_if.h.
     668              :  */
     669            1 : struct net_if_dev {
     670              :         /** The actually device driver instance the net_if is related to */
     671            1 :         const struct device *dev;
     672              : 
     673              :         /** Interface's L2 layer */
     674            1 :         const struct net_l2 * const l2;
     675              : 
     676              :         /** Interface's private L2 data pointer */
     677            1 :         void *l2_data;
     678              : 
     679              :         /** For internal use */
     680            1 :         ATOMIC_DEFINE(flags, NET_IF_NUM_FLAGS);
     681              : 
     682              :         /** The hardware link address */
     683            1 :         struct net_linkaddr link_addr;
     684              : 
     685              : #if defined(CONFIG_NET_OFFLOAD)
     686              :         /** TCP/IP Offload functions.
     687              :          * If non-NULL, then the TCP/IP stack is located
     688              :          * in the communication chip that is accessed via this
     689              :          * network interface.
     690              :          */
     691              :         struct net_offload *offload;
     692              : #endif /* CONFIG_NET_OFFLOAD */
     693              : 
     694              :         /** The hardware MTU */
     695            1 :         uint16_t mtu;
     696              : 
     697              : #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
     698              :         /** A function pointer to create an offloaded socket.
     699              :          *  If non-NULL, the interface is considered offloaded at socket level.
     700              :          */
     701              :         net_socket_create_t socket_offload;
     702              : #endif /* CONFIG_NET_SOCKETS_OFFLOAD */
     703              : 
     704              :         /** RFC 2863 operational status */
     705            1 :         enum net_if_oper_state oper_state;
     706              : 
     707              :         /** Last time the operational state was changed.
     708              :          * This is used to determine how long the interface has been in the
     709              :          * current operational state.
     710              :          *
     711              :          * This value is set to 0 when the interface is created, and then
     712              :          * updated whenever the operational state changes.
     713              :          *
     714              :          * The value is in milliseconds since boot.
     715              :          */
     716            1 :         int64_t oper_state_change_time;
     717              : };
     718              : 
     719              : /**
     720              :  * @brief Network Interface structure
     721              :  *
     722              :  * Used to handle a network interface on top of a net_if_dev instance.
     723              :  * There can be many net_if instance against the same net_if_dev instance.
     724              :  *
     725              :  */
     726            1 : struct net_if {
     727              :         /** The net_if_dev instance the net_if is related to */
     728            1 :         struct net_if_dev *if_dev;
     729              : 
     730              : #if defined(CONFIG_NET_STATISTICS_PER_INTERFACE)
     731              :         /** Network statistics related to this network interface */
     732              :         struct net_stats stats;
     733              : 
     734              :         /** Promethus collector for this network interface */
     735              :         IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS,
     736              :                    (struct prometheus_collector *collector);)
     737              : #endif /* CONFIG_NET_STATISTICS_PER_INTERFACE */
     738              : 
     739              :         /** Network interface instance configuration */
     740            1 :         struct net_if_config config;
     741              : 
     742              : #if defined(CONFIG_NET_POWER_MANAGEMENT)
     743              :         /** Keep track of packets pending in traffic queues. This is
     744              :          * needed to avoid putting network device driver to sleep if
     745              :          * there are packets waiting to be sent.
     746              :          */
     747              :         int tx_pending;
     748              : #endif
     749              : 
     750              :         /** Mutex protecting this network interface instance */
     751            1 :         struct k_mutex lock;
     752              : 
     753              :         /** Mutex used when sending data */
     754            1 :         struct k_mutex tx_lock;
     755              : 
     756              :         /** Network interface specific flags */
     757              :         /** Enable IPv6 privacy extension (RFC 8981), this is enabled
     758              :          * by default if PE support is enabled in configuration.
     759              :          */
     760            1 :         uint8_t pe_enabled : 1;
     761              : 
     762              :         /** If PE is enabled, then this tells whether public addresses
     763              :          * are preferred over temporary ones for this interface.
     764              :          */
     765            1 :         uint8_t pe_prefer_public : 1;
     766              : 
     767              :         /** Unused bit flags (ignore) */
     768              :         uint8_t _unused : 6;
     769              : };
     770              : 
     771              : /** @cond INTERNAL_HIDDEN */
     772              : 
     773              : static inline void net_if_lock(struct net_if *iface)
     774              : {
     775              :         NET_ASSERT(iface);
     776              : 
     777              :         (void)k_mutex_lock(&iface->lock, K_FOREVER);
     778              : }
     779              : 
     780              : static inline void net_if_unlock(struct net_if *iface)
     781              : {
     782              :         NET_ASSERT(iface);
     783              : 
     784              :         k_mutex_unlock(&iface->lock);
     785              : }
     786              : 
     787              : static inline bool net_if_flag_is_set(struct net_if *iface,
     788              :                                       enum net_if_flag value);
     789              : 
     790              : static inline void net_if_tx_lock(struct net_if *iface)
     791              : {
     792              :         NET_ASSERT(iface);
     793              : 
     794              :         if (net_if_flag_is_set(iface, NET_IF_NO_TX_LOCK)) {
     795              :                 return;
     796              :         }
     797              : 
     798              :         (void)k_mutex_lock(&iface->tx_lock, K_FOREVER);
     799              : }
     800              : 
     801              : static inline void net_if_tx_unlock(struct net_if *iface)
     802              : {
     803              :         NET_ASSERT(iface);
     804              : 
     805              :         if (net_if_flag_is_set(iface, NET_IF_NO_TX_LOCK)) {
     806              :                 return;
     807              :         }
     808              : 
     809              :         k_mutex_unlock(&iface->tx_lock);
     810              : }
     811              : 
     812              : /** @endcond */
     813              : 
     814              : /**
     815              :  * @brief Set a value in network interface flags
     816              :  *
     817              :  * @param iface Pointer to network interface
     818              :  * @param value Flag value
     819              :  */
     820            1 : static inline void net_if_flag_set(struct net_if *iface,
     821              :                                    enum net_if_flag value)
     822              : {
     823              :         if (iface == NULL || iface->if_dev == NULL) {
     824              :                 return;
     825              :         }
     826              : 
     827              :         atomic_set_bit(iface->if_dev->flags, value);
     828              : }
     829              : 
     830              : /**
     831              :  * @brief Test and set a value in network interface flags
     832              :  *
     833              :  * @param iface Pointer to network interface
     834              :  * @param value Flag value
     835              :  *
     836              :  * @return true if the bit was set, false if it wasn't.
     837              :  */
     838            1 : static inline bool net_if_flag_test_and_set(struct net_if *iface,
     839              :                                             enum net_if_flag value)
     840              : {
     841              :         if (iface == NULL || iface->if_dev == NULL) {
     842              :                 return false;
     843              :         }
     844              : 
     845              :         return atomic_test_and_set_bit(iface->if_dev->flags, value);
     846              : }
     847              : 
     848              : /**
     849              :  * @brief Clear a value in network interface flags
     850              :  *
     851              :  * @param iface Pointer to network interface
     852              :  * @param value Flag value
     853              :  */
     854            1 : static inline void net_if_flag_clear(struct net_if *iface,
     855              :                                      enum net_if_flag value)
     856              : {
     857              :         if (iface == NULL || iface->if_dev == NULL) {
     858              :                 return;
     859              :         }
     860              : 
     861              :         atomic_clear_bit(iface->if_dev->flags, value);
     862              : }
     863              : 
     864              : /**
     865              :  * @brief Test and clear a value in network interface flags
     866              :  *
     867              :  * @param iface Pointer to network interface
     868              :  * @param value Flag value
     869              :  *
     870              :  * @return true if the bit was set, false if it wasn't.
     871              :  */
     872            1 : static inline bool net_if_flag_test_and_clear(struct net_if *iface,
     873              :                                               enum net_if_flag value)
     874              : {
     875              :         if (iface == NULL || iface->if_dev == NULL) {
     876              :                 return false;
     877              :         }
     878              : 
     879              :         return atomic_test_and_clear_bit(iface->if_dev->flags, value);
     880              : }
     881              : 
     882              : /**
     883              :  * @brief Check if a value in network interface flags is set
     884              :  *
     885              :  * @param iface Pointer to network interface
     886              :  * @param value Flag value
     887              :  *
     888              :  * @return True if the value is set, false otherwise
     889              :  */
     890            1 : static inline bool net_if_flag_is_set(struct net_if *iface,
     891              :                                       enum net_if_flag value)
     892              : {
     893              :         if (iface == NULL || iface->if_dev == NULL) {
     894              :                 return false;
     895              :         }
     896              : 
     897              :         return atomic_test_bit(iface->if_dev->flags, value);
     898              : }
     899              : 
     900              : /**
     901              :  * @brief Set an operational state on an interface
     902              :  *
     903              :  * @param iface Pointer to network interface
     904              :  * @param oper_state Operational state to set
     905              :  *
     906              :  * @return The new operational state of an interface
     907              :  */
     908            1 : static inline enum net_if_oper_state net_if_oper_state_set(
     909              :         struct net_if *iface, enum net_if_oper_state oper_state)
     910              : {
     911              :         if (iface == NULL || iface->if_dev == NULL) {
     912              :                 return NET_IF_OPER_UNKNOWN;
     913              :         }
     914              : 
     915              :         BUILD_ASSERT((enum net_if_oper_state)(-1) > 0 && NET_IF_OPER_UNKNOWN == 0);
     916              :         if (oper_state <= NET_IF_OPER_UP) {
     917              :                 iface->if_dev->oper_state = oper_state;
     918              :         }
     919              : 
     920              :         net_if_lock(iface);
     921              : 
     922              :         iface->if_dev->oper_state_change_time = k_uptime_get();
     923              : 
     924              :         net_if_unlock(iface);
     925              : 
     926              :         return iface->if_dev->oper_state;
     927              : }
     928              : 
     929              : /**
     930              :  * @brief Get an operational state of an interface
     931              :  *
     932              :  * @param iface Pointer to network interface
     933              :  *
     934              :  * @return Operational state of an interface
     935              :  */
     936            1 : static inline enum net_if_oper_state net_if_oper_state(struct net_if *iface)
     937              : {
     938              :         if (iface == NULL || iface->if_dev == NULL) {
     939              :                 return NET_IF_OPER_UNKNOWN;
     940              :         }
     941              : 
     942              :         return iface->if_dev->oper_state;
     943              : }
     944              : 
     945              : /**
     946              :  * @brief Get an operational state change time of an interface
     947              :  *
     948              :  * @param iface Pointer to network interface
     949              :  * @param change_time Pointer to store the change time. Time the operational
     950              :  *        state of an interface was last changed, in milliseconds since boot.
     951              :  *        If the interface operational state has not been changed yet,
     952              :  *        then the value is 0.
     953              :  *
     954              :  * @return 0 if ok, -EINVAL if operational state change time could not be
     955              :  *         retrieved (for example if iface or change_time is NULL).
     956              :  */
     957            1 : static inline int net_if_oper_state_change_time(struct net_if *iface,
     958              :                                                 int64_t *change_time)
     959              : {
     960              :         if (iface == NULL || iface->if_dev == NULL || change_time == NULL) {
     961              :                 return -EINVAL;
     962              :         }
     963              : 
     964              :         net_if_lock(iface);
     965              : 
     966              :         *change_time = iface->if_dev->oper_state_change_time;
     967              : 
     968              :         net_if_unlock(iface);
     969              : 
     970              :         return 0;
     971              : }
     972              : 
     973              : /**
     974              :  * @brief Try sending a packet through a net iface
     975              :  *
     976              :  * @param iface Pointer to a network interface structure
     977              :  * @param pkt Pointer to a net packet to send
     978              :  * @param timeout timeout for attempting to send
     979              :  *
     980              :  * @return verdict about the packet
     981              :  */
     982            1 : enum net_verdict net_if_try_send_data(struct net_if *iface,
     983              :                                       struct net_pkt *pkt, k_timeout_t timeout);
     984              : 
     985              : /**
     986              :  * @brief Send a packet through a net iface
     987              :  *
     988              :  * This is equivalent to net_if_try_queue_tx with an infinite timeout
     989              :  * @param iface Pointer to a network interface structure
     990              :  * @param pkt Pointer to a net packet to send
     991              :  *
     992              :  * @return verdict about the packet
     993              :  */
     994            1 : static inline enum net_verdict net_if_send_data(struct net_if *iface,
     995              :                                                 struct net_pkt *pkt)
     996              : {
     997              :         k_timeout_t timeout = k_is_in_isr() ? K_NO_WAIT : K_FOREVER;
     998              : 
     999              :         return net_if_try_send_data(iface, pkt, timeout);
    1000              : }
    1001              : 
    1002              : /**
    1003              :  * @brief Get a pointer to the interface L2
    1004              :  *
    1005              :  * @param iface a valid pointer to a network interface structure
    1006              :  *
    1007              :  * @return a pointer to the iface L2
    1008              :  */
    1009            1 : static inline const struct net_l2 *net_if_l2(struct net_if *iface)
    1010              : {
    1011              :         if (iface == NULL || iface->if_dev == NULL) {
    1012              :                 return NULL;
    1013              :         }
    1014              : 
    1015              :         return iface->if_dev->l2;
    1016              : }
    1017              : 
    1018              : /**
    1019              :  * @brief Input a packet through a net iface
    1020              :  *
    1021              :  * @param iface Pointer to a network interface structure
    1022              :  * @param pkt Pointer to a net packet to input
    1023              :  *
    1024              :  * @return verdict about the packet
    1025              :  */
    1026            1 : enum net_verdict net_if_recv_data(struct net_if *iface, struct net_pkt *pkt);
    1027              : 
    1028              : /**
    1029              :  * @brief Get a pointer to the interface L2 private data
    1030              :  *
    1031              :  * @param iface a valid pointer to a network interface structure
    1032              :  *
    1033              :  * @return a pointer to the iface L2 data
    1034              :  */
    1035            1 : static inline void *net_if_l2_data(struct net_if *iface)
    1036              : {
    1037              :         if (iface == NULL || iface->if_dev == NULL) {
    1038              :                 return NULL;
    1039              :         }
    1040              : 
    1041              :         return iface->if_dev->l2_data;
    1042              : }
    1043              : 
    1044              : /**
    1045              :  * @brief Get an network interface's device
    1046              :  *
    1047              :  * @param iface Pointer to a network interface structure
    1048              :  *
    1049              :  * @return a pointer to the device driver instance
    1050              :  */
    1051            1 : static inline const struct device *net_if_get_device(struct net_if *iface)
    1052              : {
    1053              :         if (iface == NULL || iface->if_dev == NULL) {
    1054              :                 return NULL;
    1055              :         }
    1056              : 
    1057              :         return iface->if_dev->dev;
    1058              : }
    1059              : 
    1060              : /**
    1061              :  * @brief Try enqueuing a packet to the net interface TX queue
    1062              :  *
    1063              :  * @param iface Pointer to a network interface structure
    1064              :  * @param pkt Pointer to a net packet to queue
    1065              :  * @param timeout Timeout for the enqueuing attempt
    1066              :  */
    1067            1 : void net_if_try_queue_tx(struct net_if *iface, struct net_pkt *pkt, k_timeout_t timeout);
    1068              : 
    1069              : /**
    1070              :  * @brief Queue a packet to the net interface TX queue
    1071              :  *
    1072              :  * This is equivalent to net_if_try_queue_tx with an infinite timeout
    1073              :  * @param iface Pointer to a network interface structure
    1074              :  * @param pkt Pointer to a net packet to queue
    1075              :  */
    1076            1 : static inline void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
    1077              : {
    1078              :         k_timeout_t timeout = k_is_in_isr() ? K_NO_WAIT : K_FOREVER;
    1079              : 
    1080              :         net_if_try_queue_tx(iface, pkt, timeout);
    1081              : }
    1082              : 
    1083              : /**
    1084              :  * @brief Return the IP offload status
    1085              :  *
    1086              :  * @param iface Network interface
    1087              :  *
    1088              :  * @return True if IP offloading is active, false otherwise.
    1089              :  */
    1090            1 : static inline bool net_if_is_ip_offloaded(struct net_if *iface)
    1091              : {
    1092              : #if defined(CONFIG_NET_OFFLOAD)
    1093              :         return (iface != NULL && iface->if_dev != NULL &&
    1094              :                 iface->if_dev->offload != NULL);
    1095              : #else
    1096              :         ARG_UNUSED(iface);
    1097              : 
    1098              :         return false;
    1099              : #endif
    1100              : }
    1101              : 
    1102              : /**
    1103              :  * @brief Return offload status of a given network interface.
    1104              :  *
    1105              :  * @param iface Network interface
    1106              :  *
    1107              :  * @return True if IP or socket offloading is active, false otherwise.
    1108              :  */
    1109            1 : bool net_if_is_offloaded(struct net_if *iface);
    1110              : 
    1111              : /**
    1112              :  * @brief Return the IP offload plugin
    1113              :  *
    1114              :  * @param iface Network interface
    1115              :  *
    1116              :  * @return NULL if there is no offload plugin defined, valid pointer otherwise
    1117              :  */
    1118            1 : static inline struct net_offload *net_if_offload(struct net_if *iface)
    1119              : {
    1120              : #if defined(CONFIG_NET_OFFLOAD)
    1121              :         if (iface == NULL || iface->if_dev == NULL) {
    1122              :                 return NULL;
    1123              :         }
    1124              : 
    1125              :         return iface->if_dev->offload;
    1126              : #else
    1127              :         ARG_UNUSED(iface);
    1128              : 
    1129              :         return NULL;
    1130              : #endif
    1131              : }
    1132              : 
    1133              : /**
    1134              :  * @brief Return the socket offload status
    1135              :  *
    1136              :  * @param iface Network interface
    1137              :  *
    1138              :  * @return True if socket offloading is active, false otherwise.
    1139              :  */
    1140            1 : static inline bool net_if_is_socket_offloaded(struct net_if *iface)
    1141              : {
    1142              : #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
    1143              :         if (iface == NULL || iface->if_dev == NULL) {
    1144              :                 return false;
    1145              :         }
    1146              : 
    1147              :         return (iface->if_dev->socket_offload != NULL);
    1148              : #else
    1149              :         ARG_UNUSED(iface);
    1150              : 
    1151              :         return false;
    1152              : #endif
    1153              : }
    1154              : 
    1155              : /**
    1156              :  * @brief Set the function to create an offloaded socket
    1157              :  *
    1158              :  * @param iface Network interface
    1159              :  * @param socket_offload A function to create an offloaded socket
    1160              :  */
    1161            1 : static inline void net_if_socket_offload_set(
    1162              :                 struct net_if *iface, net_socket_create_t socket_offload)
    1163              : {
    1164              : #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
    1165              :         if (iface == NULL || iface->if_dev == NULL) {
    1166              :                 return;
    1167              :         }
    1168              : 
    1169              :         iface->if_dev->socket_offload = socket_offload;
    1170              : #else
    1171              :         ARG_UNUSED(iface);
    1172              :         ARG_UNUSED(socket_offload);
    1173              : #endif
    1174              : }
    1175              : 
    1176              : /**
    1177              :  * @brief Return the function to create an offloaded socket
    1178              :  *
    1179              :  * @param iface Network interface
    1180              :  *
    1181              :  * @return NULL if the interface is not socket offloaded, valid pointer otherwise
    1182              :  */
    1183            1 : static inline net_socket_create_t net_if_socket_offload(struct net_if *iface)
    1184              : {
    1185              : #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
    1186              :         if (iface == NULL || iface->if_dev == NULL) {
    1187              :                 return NULL;
    1188              :         }
    1189              : 
    1190              :         return iface->if_dev->socket_offload;
    1191              : #else
    1192              :         ARG_UNUSED(iface);
    1193              : 
    1194              :         return NULL;
    1195              : #endif
    1196              : }
    1197              : 
    1198              : /**
    1199              :  * @brief Get an network interface's link address
    1200              :  *
    1201              :  * @param iface Pointer to a network interface structure
    1202              :  *
    1203              :  * @return a pointer to the network link address
    1204              :  */
    1205            1 : static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface)
    1206              : {
    1207              :         if (iface == NULL || iface->if_dev == NULL) {
    1208              :                 return NULL;
    1209              :         }
    1210              : 
    1211              :         return &iface->if_dev->link_addr;
    1212              : }
    1213              : 
    1214              : /**
    1215              :  * @brief Return network configuration for this network interface
    1216              :  *
    1217              :  * @param iface Pointer to a network interface structure
    1218              :  *
    1219              :  * @return Pointer to configuration
    1220              :  */
    1221            1 : static inline struct net_if_config *net_if_get_config(struct net_if *iface)
    1222              : {
    1223              :         if (iface == NULL) {
    1224              :                 return NULL;
    1225              :         }
    1226              : 
    1227              :         return &iface->config;
    1228              : }
    1229              : 
    1230              : /**
    1231              :  * @brief Start duplicate address detection procedure.
    1232              :  *
    1233              :  * @param iface Pointer to a network interface structure
    1234              :  */
    1235              : #if defined(CONFIG_NET_IPV6_DAD) && defined(CONFIG_NET_NATIVE_IPV6)
    1236              : void net_if_start_dad(struct net_if *iface);
    1237              : #else
    1238            1 : static inline void net_if_start_dad(struct net_if *iface)
    1239              : {
    1240              :         ARG_UNUSED(iface);
    1241              : }
    1242              : #endif
    1243              : 
    1244              : /**
    1245              :  * @brief Start neighbor discovery and send router solicitation message.
    1246              :  *
    1247              :  * @param iface Pointer to a network interface structure
    1248              :  */
    1249            1 : void net_if_start_rs(struct net_if *iface);
    1250              : 
    1251              : 
    1252              : /**
    1253              :  * @brief Stop neighbor discovery.
    1254              :  *
    1255              :  * @param iface Pointer to a network interface structure
    1256              :  */
    1257              : #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
    1258              : void net_if_stop_rs(struct net_if *iface);
    1259              : #else
    1260            1 : static inline void net_if_stop_rs(struct net_if *iface)
    1261              : {
    1262              :         ARG_UNUSED(iface);
    1263              : }
    1264              : #endif /* CONFIG_NET_IPV6_ND */
    1265              : 
    1266              : /**
    1267              :  * @brief Provide a reachability hint for IPv6 Neighbor Discovery.
    1268              :  *
    1269              :  * This function is intended for upper-layer protocols to inform the IPv6
    1270              :  * Neighbor Discovery process about an active link to a specific neighbor.
    1271              :  * By signaling a recent "forward progress" event, such as the reception of
    1272              :  * an ACK, this function can help reduce unnecessary ND traffic as per the
    1273              :  * guidelines in RFC 4861 (section 7.3).
    1274              :  *
    1275              :  * @param iface A pointer to the network interface.
    1276              :  * @param ipv6_addr Pointer to the IPv6 address of the neighbor node.
    1277              :  */
    1278              : #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
    1279              : void net_if_nbr_reachability_hint(struct net_if *iface, const struct in6_addr *ipv6_addr);
    1280              : #else
    1281            1 : static inline void net_if_nbr_reachability_hint(struct net_if *iface,
    1282              :                                                 const struct in6_addr *ipv6_addr)
    1283              : {
    1284              :         ARG_UNUSED(iface);
    1285              :         ARG_UNUSED(ipv6_addr);
    1286              : }
    1287              : #endif
    1288              : 
    1289              : /** @cond INTERNAL_HIDDEN */
    1290              : 
    1291              : static inline int net_if_set_link_addr_unlocked(struct net_if *iface,
    1292              :                                                 uint8_t *addr, uint8_t len,
    1293              :                                                 enum net_link_type type)
    1294              : {
    1295              :         int ret;
    1296              : 
    1297              :         if (net_if_flag_is_set(iface, NET_IF_RUNNING)) {
    1298              :                 return -EPERM;
    1299              :         }
    1300              : 
    1301              :         if (len > sizeof(net_if_get_link_addr(iface)->addr)) {
    1302              :                 return -EINVAL;
    1303              :         }
    1304              : 
    1305              :         ret = net_linkaddr_create(net_if_get_link_addr(iface), addr, len, type);
    1306              :         if (ret < 0) {
    1307              :                 return ret;
    1308              :         }
    1309              : 
    1310              :         net_hostname_set_postfix(addr, len);
    1311              : 
    1312              :         return 0;
    1313              : }
    1314              : 
    1315              : int net_if_set_link_addr_locked(struct net_if *iface,
    1316              :                                 uint8_t *addr, uint8_t len,
    1317              :                                 enum net_link_type type);
    1318              : 
    1319              : #if CONFIG_NET_IF_LOG_LEVEL >= LOG_LEVEL_DBG
    1320              : extern int net_if_addr_unref_debug(struct net_if *iface,
    1321              :                                    sa_family_t family,
    1322              :                                    const void *addr,
    1323              :                                    struct net_if_addr **ifaddr,
    1324              :                                    const char *caller, int line);
    1325              : #define net_if_addr_unref(iface, family, addr, ifaddr)                  \
    1326              :         net_if_addr_unref_debug(iface, family, addr, ifaddr, __func__, __LINE__)
    1327              : 
    1328              : extern struct net_if_addr *net_if_addr_ref_debug(struct net_if *iface,
    1329              :                                                  sa_family_t family,
    1330              :                                                  const void *addr,
    1331              :                                                  const char *caller,
    1332              :                                                  int line);
    1333              : #define net_if_addr_ref(iface, family, addr) \
    1334              :         net_if_addr_ref_debug(iface, family, addr, __func__, __LINE__)
    1335              : #else
    1336              : extern int net_if_addr_unref(struct net_if *iface,
    1337              :                              sa_family_t family,
    1338              :                              const void *addr,
    1339              :                              struct net_if_addr **ifaddr);
    1340              : extern struct net_if_addr *net_if_addr_ref(struct net_if *iface,
    1341              :                                            sa_family_t family,
    1342              :                                            const void *addr);
    1343              : #endif /* CONFIG_NET_IF_LOG_LEVEL */
    1344              : 
    1345              : /** @endcond */
    1346              : 
    1347              : /**
    1348              :  * @brief Set a network interface's link address
    1349              :  *
    1350              :  * @param iface Pointer to a network interface structure
    1351              :  * @param addr A pointer to a uint8_t buffer representing the address.
    1352              :  *             The buffer must remain valid throughout interface lifetime.
    1353              :  * @param len length of the address buffer
    1354              :  * @param type network bearer type of this link address
    1355              :  *
    1356              :  * @return 0 on success
    1357              :  */
    1358            1 : static inline int net_if_set_link_addr(struct net_if *iface,
    1359              :                                        uint8_t *addr, uint8_t len,
    1360              :                                        enum net_link_type type)
    1361              : {
    1362              : #if defined(CONFIG_NET_RAW_MODE)
    1363              :         return net_if_set_link_addr_unlocked(iface, addr, len, type);
    1364              : #else
    1365              :         return net_if_set_link_addr_locked(iface, addr, len, type);
    1366              : #endif
    1367              : }
    1368              : 
    1369              : /**
    1370              :  * @brief Get an network interface's MTU
    1371              :  *
    1372              :  * @param iface Pointer to a network interface structure
    1373              :  *
    1374              :  * @return the MTU
    1375              :  */
    1376            1 : static inline uint16_t net_if_get_mtu(struct net_if *iface)
    1377              : {
    1378              :         if (iface == NULL || iface->if_dev == NULL) {
    1379              :                 return 0U;
    1380              :         }
    1381              : 
    1382              :         return iface->if_dev->mtu;
    1383              : }
    1384              : 
    1385              : /**
    1386              :  * @brief Set an network interface's MTU
    1387              :  *
    1388              :  * @param iface Pointer to a network interface structure
    1389              :  * @param mtu New MTU, note that we store only 16 bit mtu value.
    1390              :  */
    1391            1 : static inline void net_if_set_mtu(struct net_if *iface,
    1392              :                                   uint16_t mtu)
    1393              : {
    1394              :         if (iface == NULL || iface->if_dev == NULL) {
    1395              :                 return;
    1396              :         }
    1397              : 
    1398              :         iface->if_dev->mtu = mtu;
    1399              : }
    1400              : 
    1401              : /**
    1402              :  * @brief Set the infinite status of the network interface address
    1403              :  *
    1404              :  * @param ifaddr IP address for network interface
    1405              :  * @param is_infinite Infinite status
    1406              :  */
    1407            1 : static inline void net_if_addr_set_lf(struct net_if_addr *ifaddr,
    1408              :                                       bool is_infinite)
    1409              : {
    1410              :         if (ifaddr == NULL) {
    1411              :                 return;
    1412              :         }
    1413              : 
    1414              :         ifaddr->is_infinite = is_infinite;
    1415              : }
    1416              : 
    1417              : /**
    1418              :  * @brief Get an interface according to link layer address.
    1419              :  *
    1420              :  * @param ll_addr Link layer address.
    1421              :  *
    1422              :  * @return Network interface or NULL if not found.
    1423              :  */
    1424            1 : struct net_if *net_if_get_by_link_addr(struct net_linkaddr *ll_addr);
    1425              : 
    1426              : /**
    1427              :  * @brief Find an interface from it's related device
    1428              :  *
    1429              :  * @param dev A valid struct device pointer to relate with an interface
    1430              :  *
    1431              :  * @return a valid struct net_if pointer on success, NULL otherwise
    1432              :  */
    1433            1 : struct net_if *net_if_lookup_by_dev(const struct device *dev);
    1434              : 
    1435              : /**
    1436              :  * @brief Get network interface IP config
    1437              :  *
    1438              :  * @param iface Interface to use.
    1439              :  *
    1440              :  * @return NULL if not found or pointer to correct config settings.
    1441              :  */
    1442            1 : static inline struct net_if_config *net_if_config_get(struct net_if *iface)
    1443              : {
    1444              :         if (iface == NULL) {
    1445              :                 return NULL;
    1446              :         }
    1447              : 
    1448              :         return &iface->config;
    1449              : }
    1450              : 
    1451              : /**
    1452              :  * @brief Remove a router from the system
    1453              :  *
    1454              :  * @param router Pointer to existing router
    1455              :  */
    1456            1 : void net_if_router_rm(struct net_if_router *router);
    1457              : 
    1458              : /**
    1459              :  * @brief Set the default network interface.
    1460              :  *
    1461              :  * @param iface New default interface, or NULL to revert to the one set by Kconfig.
    1462              :  */
    1463            1 : void net_if_set_default(struct net_if *iface);
    1464              : 
    1465              : /**
    1466              :  * @brief Get the default network interface.
    1467              :  *
    1468              :  * @return Default interface or NULL if no interfaces are configured.
    1469              :  */
    1470            1 : struct net_if *net_if_get_default(void);
    1471              : 
    1472              : /**
    1473              :  * @brief Get the first network interface according to its type.
    1474              :  *
    1475              :  * @param l2 Layer 2 type of the network interface.
    1476              :  *
    1477              :  * @return First network interface of a given type or NULL if no such
    1478              :  * interfaces was found.
    1479              :  */
    1480            1 : struct net_if *net_if_get_first_by_type(const struct net_l2 *l2);
    1481              : 
    1482              : /**
    1483              :  * @brief Get the first network interface which is up.
    1484              :  *
    1485              :  * @return First network interface which is up or NULL if all
    1486              :  * interfaces are down.
    1487              :  */
    1488            1 : struct net_if *net_if_get_first_up(void);
    1489              : 
    1490              : #if defined(CONFIG_NET_L2_IEEE802154)
    1491              : /**
    1492              :  * @brief Get the first IEEE 802.15.4 network interface.
    1493              :  *
    1494              :  * @return First IEEE 802.15.4 network interface or NULL if no such
    1495              :  * interfaces was found.
    1496              :  */
    1497              : static inline struct net_if *net_if_get_ieee802154(void)
    1498              : {
    1499              :         return net_if_get_first_by_type(&NET_L2_GET_NAME(IEEE802154));
    1500              : }
    1501              : #endif /* CONFIG_NET_L2_IEEE802154 */
    1502              : 
    1503              : /**
    1504              :  * @brief Allocate network interface IPv6 config.
    1505              :  *
    1506              :  * @details This function will allocate new IPv6 config.
    1507              :  *
    1508              :  * @param iface Interface to use.
    1509              :  * @param ipv6 Pointer to allocated IPv6 struct is returned to caller.
    1510              :  *
    1511              :  * @return 0 if ok, <0 if error
    1512              :  */
    1513            1 : int net_if_config_ipv6_get(struct net_if *iface,
    1514              :                            struct net_if_ipv6 **ipv6);
    1515              : 
    1516              : /**
    1517              :  * @brief Release network interface IPv6 config.
    1518              :  *
    1519              :  * @param iface Interface to use.
    1520              :  *
    1521              :  * @return 0 if ok, <0 if error
    1522              :  */
    1523            1 : int net_if_config_ipv6_put(struct net_if *iface);
    1524              : 
    1525              : 
    1526              : /** @cond INTERNAL_HIDDEN */
    1527              : struct net_if_addr *net_if_ipv6_addr_lookup_raw(const uint8_t *addr,
    1528              :                                                 struct net_if **ret);
    1529              : /** @endcond */
    1530              : 
    1531              : /**
    1532              :  * @brief Check if this IPv6 address belongs to one of the interfaces.
    1533              :  *
    1534              :  * @param addr IPv6 address
    1535              :  * @param iface Pointer to interface is returned
    1536              :  *
    1537              :  * @return Pointer to interface address, NULL if not found.
    1538              :  */
    1539            1 : struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
    1540              :                                             struct net_if **iface);
    1541              : 
    1542              : /** @cond INTERNAL_HIDDEN */
    1543              : struct net_if_addr *net_if_ipv6_addr_lookup_by_iface_raw(struct net_if *iface,
    1544              :                                                          const uint8_t *addr);
    1545              : /** @endcond */
    1546              : 
    1547              : /**
    1548              :  * @brief Check if this IPv6 address belongs to this specific interfaces.
    1549              :  *
    1550              :  * @param iface Network interface
    1551              :  * @param addr IPv6 address
    1552              :  *
    1553              :  * @return Pointer to interface address, NULL if not found.
    1554              :  */
    1555            1 : struct net_if_addr *net_if_ipv6_addr_lookup_by_iface(struct net_if *iface,
    1556              :                                                      const struct in6_addr *addr);
    1557              : 
    1558              : /**
    1559              :  * @brief Check if this IPv6 address belongs to one of the interface indices.
    1560              :  *
    1561              :  * @param addr IPv6 address
    1562              :  *
    1563              :  * @return >0 if address was found in given network interface index,
    1564              :  * all other values mean address was not found
    1565              :  */
    1566            1 : __syscall int net_if_ipv6_addr_lookup_by_index(const struct in6_addr *addr);
    1567              : 
    1568              : /**
    1569              :  * @brief Add a IPv6 address to an interface
    1570              :  *
    1571              :  * @param iface Network interface
    1572              :  * @param addr IPv6 address
    1573              :  * @param addr_type IPv6 address type
    1574              :  * @param vlifetime Validity time for this address
    1575              :  *
    1576              :  * @return Pointer to interface address, NULL if cannot be added
    1577              :  */
    1578            1 : struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface,
    1579              :                                          const struct in6_addr *addr,
    1580              :                                          enum net_addr_type addr_type,
    1581              :                                          uint32_t vlifetime);
    1582              : 
    1583              : /**
    1584              :  * @brief Add a IPv6 address to an interface by index
    1585              :  *
    1586              :  * @param index Network interface index
    1587              :  * @param addr IPv6 address
    1588              :  * @param addr_type IPv6 address type
    1589              :  * @param vlifetime Validity time for this address
    1590              :  *
    1591              :  * @return True if ok, false if address could not be added
    1592              :  */
    1593            1 : __syscall bool net_if_ipv6_addr_add_by_index(int index,
    1594              :                                              const struct in6_addr *addr,
    1595              :                                              enum net_addr_type addr_type,
    1596              :                                              uint32_t vlifetime);
    1597              : 
    1598              : /**
    1599              :  * @brief Update validity lifetime time of an IPv6 address.
    1600              :  *
    1601              :  * @param ifaddr Network IPv6 address
    1602              :  * @param vlifetime Validity time for this address
    1603              :  */
    1604            1 : void net_if_ipv6_addr_update_lifetime(struct net_if_addr *ifaddr,
    1605              :                                       uint32_t vlifetime);
    1606              : 
    1607              : /**
    1608              :  * @brief Remove an IPv6 address from an interface
    1609              :  *
    1610              :  * @param iface Network interface
    1611              :  * @param addr IPv6 address
    1612              :  *
    1613              :  * @return True if successfully removed, false otherwise
    1614              :  */
    1615            1 : bool net_if_ipv6_addr_rm(struct net_if *iface, const struct in6_addr *addr);
    1616              : 
    1617              : /**
    1618              :  * @brief Remove an IPv6 address from an interface by index
    1619              :  *
    1620              :  * @param index Network interface index
    1621              :  * @param addr IPv6 address
    1622              :  *
    1623              :  * @return True if successfully removed, false otherwise
    1624              :  */
    1625            1 : __syscall bool net_if_ipv6_addr_rm_by_index(int index,
    1626              :                                             const struct in6_addr *addr);
    1627              : 
    1628              : /**
    1629              :  * @typedef net_if_ip_addr_cb_t
    1630              :  * @brief Callback used while iterating over network interface IP addresses
    1631              :  *
    1632              :  * @param iface Pointer to the network interface the address belongs to
    1633              :  * @param addr Pointer to current IP address
    1634              :  * @param user_data A valid pointer to user data or NULL
    1635              :  */
    1636            1 : typedef void (*net_if_ip_addr_cb_t)(struct net_if *iface,
    1637              :                                     struct net_if_addr *addr,
    1638              :                                     void *user_data);
    1639              : 
    1640              : /**
    1641              :  * @brief Go through all IPv6 addresses on a network interface and call callback
    1642              :  * for each used address.
    1643              :  *
    1644              :  * @param iface Pointer to the network interface
    1645              :  * @param cb User-supplied callback function to call
    1646              :  * @param user_data User specified data
    1647              :  */
    1648            1 : void net_if_ipv6_addr_foreach(struct net_if *iface, net_if_ip_addr_cb_t cb,
    1649              :                               void *user_data);
    1650              : 
    1651              : /**
    1652              :  * @brief Add a IPv6 multicast address to an interface
    1653              :  *
    1654              :  * @param iface Network interface
    1655              :  * @param addr IPv6 multicast address
    1656              :  *
    1657              :  * @return Pointer to interface multicast address, NULL if cannot be added
    1658              :  */
    1659            1 : struct net_if_mcast_addr *net_if_ipv6_maddr_add(struct net_if *iface,
    1660              :                                                 const struct in6_addr *addr);
    1661              : 
    1662              : /**
    1663              :  * @brief Remove an IPv6 multicast address from an interface
    1664              :  *
    1665              :  * @param iface Network interface
    1666              :  * @param addr IPv6 multicast address
    1667              :  *
    1668              :  * @return True if successfully removed, false otherwise
    1669              :  */
    1670            1 : bool net_if_ipv6_maddr_rm(struct net_if *iface, const struct in6_addr *addr);
    1671              : 
    1672              : /**
    1673              :  * @typedef net_if_ip_maddr_cb_t
    1674              :  * @brief Callback used while iterating over network interface multicast IP addresses
    1675              :  *
    1676              :  * @param iface Pointer to the network interface the address belongs to
    1677              :  * @param maddr Pointer to current multicast IP address
    1678              :  * @param user_data A valid pointer to user data or NULL
    1679              :  */
    1680            1 : typedef void (*net_if_ip_maddr_cb_t)(struct net_if *iface,
    1681              :                                      struct net_if_mcast_addr *maddr,
    1682              :                                      void *user_data);
    1683              : 
    1684              : /**
    1685              :  * @brief Go through all IPv6 multicast addresses on a network interface and call
    1686              :  * callback for each used address.
    1687              :  *
    1688              :  * @param iface Pointer to the network interface
    1689              :  * @param cb User-supplied callback function to call
    1690              :  * @param user_data User specified data
    1691              :  */
    1692            1 : void net_if_ipv6_maddr_foreach(struct net_if *iface, net_if_ip_maddr_cb_t cb,
    1693              :                                void *user_data);
    1694              : 
    1695              : 
    1696              : /** @cond INTERNAL_HIDDEN */
    1697              : struct net_if_mcast_addr *net_if_ipv6_maddr_lookup_raw(const uint8_t *maddr,
    1698              :                                                        struct net_if **ret);
    1699              : /** @endcond */
    1700              : 
    1701              : /**
    1702              :  * @brief Check if this IPv6 multicast address belongs to a specific interface
    1703              :  * or one of the interfaces.
    1704              :  *
    1705              :  * @param addr IPv6 address
    1706              :  * @param iface If *iface is null, then pointer to interface is returned,
    1707              :  * otherwise the *iface value needs to be matched.
    1708              :  *
    1709              :  * @return Pointer to interface multicast address, NULL if not found.
    1710              :  */
    1711            1 : struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(const struct in6_addr *addr,
    1712              :                                                    struct net_if **iface);
    1713              : 
    1714              : /**
    1715              :  * @typedef net_if_mcast_callback_t
    1716              : 
    1717              :  * @brief Define a callback that is called whenever a IPv6 or IPv4 multicast
    1718              :  *        address group is joined or left.
    1719              :  * @param iface A pointer to a struct net_if to which the multicast address is
    1720              :  *        attached.
    1721              :  * @param addr IP multicast address.
    1722              :  * @param is_joined True if the multicast group is joined, false if group is left.
    1723              :  */
    1724            1 : typedef void (*net_if_mcast_callback_t)(struct net_if *iface,
    1725              :                                         const struct net_addr *addr,
    1726              :                                         bool is_joined);
    1727              : 
    1728              : /**
    1729              :  * @brief Multicast monitor handler struct.
    1730              :  *
    1731              :  * Stores the multicast callback information. Caller must make sure that
    1732              :  * the variable pointed by this is valid during the lifetime of
    1733              :  * registration. Typically this means that the variable cannot be
    1734              :  * allocated from stack.
    1735              :  */
    1736            1 : struct net_if_mcast_monitor {
    1737              :         /** Node information for the slist. */
    1738            1 :         sys_snode_t node;
    1739              : 
    1740              :         /** Network interface */
    1741            1 :         struct net_if *iface;
    1742              : 
    1743              :         /** Multicast callback */
    1744            1 :         net_if_mcast_callback_t cb;
    1745              : };
    1746              : 
    1747              : /**
    1748              :  * @brief Register a multicast monitor
    1749              :  *
    1750              :  * @param mon Monitor handle. This is a pointer to a monitor storage structure
    1751              :  * which should be allocated by caller, but does not need to be initialized.
    1752              :  * @param iface Network interface or NULL for all interfaces
    1753              :  * @param cb Monitor callback
    1754              :  */
    1755            1 : void net_if_mcast_mon_register(struct net_if_mcast_monitor *mon,
    1756              :                                struct net_if *iface,
    1757              :                                net_if_mcast_callback_t cb);
    1758              : 
    1759              : /**
    1760              :  * @brief Unregister a multicast monitor
    1761              :  *
    1762              :  * @param mon Monitor handle
    1763              :  */
    1764            1 : void net_if_mcast_mon_unregister(struct net_if_mcast_monitor *mon);
    1765              : 
    1766              : /**
    1767              :  * @brief Call registered multicast monitors
    1768              :  *
    1769              :  * @param iface Network interface
    1770              :  * @param addr Multicast address
    1771              :  * @param is_joined Is this multicast address group joined (true) or not (false)
    1772              :  */
    1773            1 : void net_if_mcast_monitor(struct net_if *iface, const struct net_addr *addr,
    1774              :                           bool is_joined);
    1775              : 
    1776              : /**
    1777              :  * @brief Mark a given multicast address to be joined.
    1778              :  *
    1779              :  * @param iface Network interface the address belongs to
    1780              :  * @param addr IPv6 multicast address
    1781              :  */
    1782            1 : void net_if_ipv6_maddr_join(struct net_if *iface,
    1783              :                             struct net_if_mcast_addr *addr);
    1784              : 
    1785              : /**
    1786              :  * @brief Check if given multicast address is joined or not.
    1787              :  *
    1788              :  * @param addr IPv6 multicast address
    1789              :  *
    1790              :  * @return True if address is joined, False otherwise.
    1791              :  */
    1792            1 : static inline bool net_if_ipv6_maddr_is_joined(struct net_if_mcast_addr *addr)
    1793              : {
    1794              :         if (addr == NULL) {
    1795              :                 return false;
    1796              :         }
    1797              : 
    1798              :         return addr->is_joined;
    1799              : }
    1800              : 
    1801              : /**
    1802              :  * @brief Mark a given multicast address to be left.
    1803              :  *
    1804              :  * @param iface Network interface the address belongs to
    1805              :  * @param addr IPv6 multicast address
    1806              :  */
    1807            1 : void net_if_ipv6_maddr_leave(struct net_if *iface,
    1808              :                              struct net_if_mcast_addr *addr);
    1809              : 
    1810              : /**
    1811              :  * @brief Return prefix that corresponds to this IPv6 address.
    1812              :  *
    1813              :  * @param iface Network interface
    1814              :  * @param addr IPv6 address
    1815              :  *
    1816              :  * @return Pointer to prefix, NULL if not found.
    1817              :  */
    1818            1 : struct net_if_ipv6_prefix *net_if_ipv6_prefix_get(struct net_if *iface,
    1819              :                                                   const struct in6_addr *addr);
    1820              : 
    1821              : /**
    1822              :  * @brief Check if this IPv6 prefix belongs to this interface
    1823              :  *
    1824              :  * @param iface Network interface
    1825              :  * @param addr IPv6 address
    1826              :  * @param len Prefix length
    1827              :  *
    1828              :  * @return Pointer to prefix, NULL if not found.
    1829              :  */
    1830            1 : struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
    1831              :                                                      const struct in6_addr *addr,
    1832              :                                                      uint8_t len);
    1833              : 
    1834              : /**
    1835              :  * @brief Add a IPv6 prefix to an network interface.
    1836              :  *
    1837              :  * @param iface Network interface
    1838              :  * @param prefix IPv6 address
    1839              :  * @param len Prefix length
    1840              :  * @param lifetime Prefix lifetime in seconds
    1841              :  *
    1842              :  * @return Pointer to prefix, NULL if the prefix was not added.
    1843              :  */
    1844            1 : struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
    1845              :                                                   const struct in6_addr *prefix,
    1846              :                                                   uint8_t len,
    1847              :                                                   uint32_t lifetime);
    1848              : 
    1849              : /**
    1850              :  * @brief Remove an IPv6 prefix from an interface
    1851              :  *
    1852              :  * @param iface Network interface
    1853              :  * @param addr IPv6 prefix address
    1854              :  * @param len Prefix length
    1855              :  *
    1856              :  * @return True if successfully removed, false otherwise
    1857              :  */
    1858            1 : bool net_if_ipv6_prefix_rm(struct net_if *iface, const struct in6_addr *addr,
    1859              :                            uint8_t len);
    1860              : 
    1861              : /**
    1862              :  * @brief Set the infinite status of the prefix
    1863              :  *
    1864              :  * @param prefix IPv6 address
    1865              :  * @param is_infinite Infinite status
    1866              :  */
    1867            1 : static inline void net_if_ipv6_prefix_set_lf(struct net_if_ipv6_prefix *prefix,
    1868              :                                              bool is_infinite)
    1869              : {
    1870              :         prefix->is_infinite = is_infinite;
    1871              : }
    1872              : 
    1873              : /**
    1874              :  * @brief Set the prefix lifetime timer.
    1875              :  *
    1876              :  * @param prefix IPv6 address
    1877              :  * @param lifetime Prefix lifetime in seconds
    1878              :  */
    1879            1 : void net_if_ipv6_prefix_set_timer(struct net_if_ipv6_prefix *prefix,
    1880              :                                   uint32_t lifetime);
    1881              : 
    1882              : /**
    1883              :  * @brief Unset the prefix lifetime timer.
    1884              :  *
    1885              :  * @param prefix IPv6 address
    1886              :  */
    1887            1 : void net_if_ipv6_prefix_unset_timer(struct net_if_ipv6_prefix *prefix);
    1888              : 
    1889              : /**
    1890              :  * @brief Check if this IPv6 address is part of the subnet of our
    1891              :  * network interface.
    1892              :  *
    1893              :  * @param iface Network interface. This is returned to the caller.
    1894              :  * The iface can be NULL in which case we check all the interfaces.
    1895              :  * @param addr IPv6 address
    1896              :  *
    1897              :  * @return True if address is part of our subnet, false otherwise
    1898              :  */
    1899            1 : bool net_if_ipv6_addr_onlink(struct net_if **iface, const struct in6_addr *addr);
    1900              : 
    1901              : /**
    1902              :  * @brief Get the IPv6 address of the given router
    1903              :  * @param router a network router
    1904              :  *
    1905              :  * @return pointer to the IPv6 address, or NULL if none
    1906              :  */
    1907              : #if defined(CONFIG_NET_NATIVE_IPV6)
    1908              : static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)
    1909              : {
    1910              :         if (router == NULL) {
    1911              :                 return NULL;
    1912              :         }
    1913              : 
    1914              :         return &router->address.in6_addr;
    1915              : }
    1916              : #else
    1917            1 : static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)
    1918              : {
    1919              :         static struct in6_addr addr;
    1920              : 
    1921              :         ARG_UNUSED(router);
    1922              : 
    1923              :         return &addr;
    1924              : }
    1925              : #endif
    1926              : 
    1927              : /**
    1928              :  * @brief Check if IPv6 address is one of the routers configured
    1929              :  * in the system.
    1930              :  *
    1931              :  * @param iface Network interface
    1932              :  * @param addr IPv6 address
    1933              :  *
    1934              :  * @return Pointer to router information, NULL if cannot be found
    1935              :  */
    1936            1 : struct net_if_router *net_if_ipv6_router_lookup(struct net_if *iface,
    1937              :                                                 const struct in6_addr *addr);
    1938              : 
    1939              : /**
    1940              :  * @brief Find default router for this IPv6 address.
    1941              :  *
    1942              :  * @param iface Network interface. This can be NULL in which case we
    1943              :  * go through all the network interfaces to find a suitable router.
    1944              :  * @param addr IPv6 address
    1945              :  *
    1946              :  * @return Pointer to router information, NULL if cannot be found
    1947              :  */
    1948            1 : struct net_if_router *net_if_ipv6_router_find_default(struct net_if *iface,
    1949              :                                                       const struct in6_addr *addr);
    1950              : 
    1951              : /**
    1952              :  * @brief Update validity lifetime time of a router.
    1953              :  *
    1954              :  * @param router Network IPv6 address
    1955              :  * @param lifetime Lifetime of this router.
    1956              :  */
    1957            1 : void net_if_ipv6_router_update_lifetime(struct net_if_router *router,
    1958              :                                         uint16_t lifetime);
    1959              : 
    1960              : /**
    1961              :  * @brief Add IPv6 router to the system.
    1962              :  *
    1963              :  * @param iface Network interface
    1964              :  * @param addr IPv6 address
    1965              :  * @param router_lifetime Lifetime of the router
    1966              :  *
    1967              :  * @return Pointer to router information, NULL if could not be added
    1968              :  */
    1969            1 : struct net_if_router *net_if_ipv6_router_add(struct net_if *iface,
    1970              :                                              const struct in6_addr *addr,
    1971              :                                              uint16_t router_lifetime);
    1972              : 
    1973              : /**
    1974              :  * @brief Remove IPv6 router from the system.
    1975              :  *
    1976              :  * @param router Router information.
    1977              :  *
    1978              :  * @return True if successfully removed, false otherwise
    1979              :  */
    1980            1 : bool net_if_ipv6_router_rm(struct net_if_router *router);
    1981              : 
    1982              : /**
    1983              :  * @brief Get IPv6 hop limit specified for a given interface. This is the
    1984              :  * default value but can be overridden by the user.
    1985              :  *
    1986              :  * @param iface Network interface
    1987              :  *
    1988              :  * @return Hop limit
    1989              :  */
    1990              : #if defined(CONFIG_NET_NATIVE_IPV6)
    1991              : uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface);
    1992              : #else
    1993            1 : static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
    1994              : {
    1995              :         ARG_UNUSED(iface);
    1996              : 
    1997              :         return 0;
    1998              : }
    1999              : #endif /* CONFIG_NET_NATIVE_IPV6 */
    2000              : 
    2001              : /**
    2002              :  * @brief Set the default IPv6 hop limit of a given interface.
    2003              :  *
    2004              :  * @param iface Network interface
    2005              :  * @param hop_limit New hop limit
    2006              :  */
    2007              : #if defined(CONFIG_NET_NATIVE_IPV6)
    2008              : void net_if_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit);
    2009              : #else
    2010            1 : static inline void net_if_ipv6_set_hop_limit(struct net_if *iface,
    2011              :                                              uint8_t hop_limit)
    2012              : {
    2013              :         ARG_UNUSED(iface);
    2014              :         ARG_UNUSED(hop_limit);
    2015              : }
    2016              : #endif /* CONFIG_NET_NATIVE_IPV6 */
    2017              : 
    2018              : /** @cond INTERNAL_HIDDEN */
    2019              : 
    2020              : /* The old hop limit setter function is deprecated because the naming
    2021              :  * of it was incorrect. The API name was missing "_if_" so this function
    2022              :  * should not be used.
    2023              :  */
    2024              : __deprecated
    2025              : static inline void net_ipv6_set_hop_limit(struct net_if *iface,
    2026              :                                           uint8_t hop_limit)
    2027              : {
    2028              :         net_if_ipv6_set_hop_limit(iface, hop_limit);
    2029              : }
    2030              : 
    2031              : /** @endcond */
    2032              : 
    2033              : /**
    2034              :  * @brief Get IPv6 multicast hop limit specified for a given interface. This is the
    2035              :  * default value but can be overridden by the user.
    2036              :  *
    2037              :  * @param iface Network interface
    2038              :  *
    2039              :  * @return Hop limit
    2040              :  */
    2041              : #if defined(CONFIG_NET_NATIVE_IPV6)
    2042              : uint8_t net_if_ipv6_get_mcast_hop_limit(struct net_if *iface);
    2043              : #else
    2044            1 : static inline uint8_t net_if_ipv6_get_mcast_hop_limit(struct net_if *iface)
    2045              : {
    2046              :         ARG_UNUSED(iface);
    2047              : 
    2048              :         return 0;
    2049              : }
    2050              : #endif /* CONFIG_NET_NATIVE_IPV6 */
    2051              : 
    2052              : /**
    2053              :  * @brief Set the default IPv6 multicast hop limit of a given interface.
    2054              :  *
    2055              :  * @param iface Network interface
    2056              :  * @param hop_limit New hop limit
    2057              :  */
    2058              : #if defined(CONFIG_NET_NATIVE_IPV6)
    2059              : void net_if_ipv6_set_mcast_hop_limit(struct net_if *iface, uint8_t hop_limit);
    2060              : #else
    2061            1 : static inline void net_if_ipv6_set_mcast_hop_limit(struct net_if *iface,
    2062              :                                                    uint8_t hop_limit)
    2063              : {
    2064              :         ARG_UNUSED(iface);
    2065              :         ARG_UNUSED(hop_limit);
    2066              : }
    2067              : #endif /* CONFIG_NET_NATIVE_IPV6 */
    2068              : 
    2069              : /**
    2070              :  * @brief Set IPv6 reachable time for a given interface
    2071              :  *
    2072              :  * @param iface Network interface
    2073              :  * @param reachable_time New reachable time
    2074              :  */
    2075            1 : static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
    2076              :                                                        uint32_t reachable_time)
    2077              : {
    2078              : #if defined(CONFIG_NET_NATIVE_IPV6)
    2079              :         if (iface == NULL) {
    2080              :                 return;
    2081              :         }
    2082              : 
    2083              :         if (!iface->config.ip.ipv6) {
    2084              :                 return;
    2085              :         }
    2086              : 
    2087              :         iface->config.ip.ipv6->base_reachable_time = reachable_time;
    2088              : #else
    2089              :         ARG_UNUSED(iface);
    2090              :         ARG_UNUSED(reachable_time);
    2091              : 
    2092              : #endif
    2093              : }
    2094              : 
    2095              : /**
    2096              :  * @brief Get IPv6 reachable timeout specified for a given interface
    2097              :  *
    2098              :  * @param iface Network interface
    2099              :  *
    2100              :  * @return Reachable timeout
    2101              :  */
    2102            1 : static inline uint32_t net_if_ipv6_get_reachable_time(struct net_if *iface)
    2103              : {
    2104              : #if defined(CONFIG_NET_NATIVE_IPV6)
    2105              :         if (iface == NULL) {
    2106              :                 return 0;
    2107              :         }
    2108              : 
    2109              :         if (!iface->config.ip.ipv6) {
    2110              :                 return 0;
    2111              :         }
    2112              : 
    2113              :         return iface->config.ip.ipv6->reachable_time;
    2114              : #else
    2115              :         ARG_UNUSED(iface);
    2116              :         return 0;
    2117              : #endif
    2118              : }
    2119              : 
    2120              : /**
    2121              :  * @brief Calculate next reachable time value for IPv6 reachable time
    2122              :  *
    2123              :  * @param ipv6 IPv6 address configuration
    2124              :  *
    2125              :  * @return Reachable time
    2126              :  */
    2127            1 : uint32_t net_if_ipv6_calc_reachable_time(struct net_if_ipv6 *ipv6);
    2128              : 
    2129              : /**
    2130              :  * @brief Set IPv6 reachable time for a given interface. This requires
    2131              :  * that base reachable time is set for the interface.
    2132              :  *
    2133              :  * @param ipv6 IPv6 address configuration
    2134              :  */
    2135            1 : static inline void net_if_ipv6_set_reachable_time(struct net_if_ipv6 *ipv6)
    2136              : {
    2137              : #if defined(CONFIG_NET_NATIVE_IPV6)
    2138              :         if (ipv6 == NULL) {
    2139              :                 return;
    2140              :         }
    2141              : 
    2142              :         ipv6->reachable_time = net_if_ipv6_calc_reachable_time(ipv6);
    2143              : #else
    2144              :         ARG_UNUSED(ipv6);
    2145              : #endif
    2146              : }
    2147              : 
    2148              : /**
    2149              :  * @brief Set IPv6 retransmit timer for a given interface
    2150              :  *
    2151              :  * @param iface Network interface
    2152              :  * @param retrans_timer New retransmit timer
    2153              :  */
    2154            1 : static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
    2155              :                                                  uint32_t retrans_timer)
    2156              : {
    2157              : #if defined(CONFIG_NET_NATIVE_IPV6)
    2158              :         if (iface == NULL) {
    2159              :                 return;
    2160              :         }
    2161              : 
    2162              :         if (!iface->config.ip.ipv6) {
    2163              :                 return;
    2164              :         }
    2165              : 
    2166              :         iface->config.ip.ipv6->retrans_timer = retrans_timer;
    2167              : #else
    2168              :         ARG_UNUSED(iface);
    2169              :         ARG_UNUSED(retrans_timer);
    2170              : #endif
    2171              : }
    2172              : 
    2173              : /**
    2174              :  * @brief Get IPv6 retransmit timer specified for a given interface
    2175              :  *
    2176              :  * @param iface Network interface
    2177              :  *
    2178              :  * @return Retransmit timer
    2179              :  */
    2180            1 : static inline uint32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)
    2181              : {
    2182              : #if defined(CONFIG_NET_NATIVE_IPV6)
    2183              :         if (iface == NULL) {
    2184              :                 return 0;
    2185              :         }
    2186              : 
    2187              :         if (!iface->config.ip.ipv6) {
    2188              :                 return 0;
    2189              :         }
    2190              : 
    2191              :         return iface->config.ip.ipv6->retrans_timer;
    2192              : #else
    2193              :         ARG_UNUSED(iface);
    2194              :         return 0;
    2195              : #endif
    2196              : }
    2197              : 
    2198              : /**
    2199              :  * @brief Get a IPv6 source address that should be used when sending
    2200              :  * network data to destination.
    2201              :  *
    2202              :  * @param iface Interface that was used when packet was received.
    2203              :  * If the interface is not known, then NULL can be given.
    2204              :  * @param dst IPv6 destination address
    2205              :  *
    2206              :  * @return Pointer to IPv6 address to use, NULL if no IPv6 address
    2207              :  * could be found.
    2208              :  */
    2209              : #if defined(CONFIG_NET_IPV6)
    2210              : const struct in6_addr *net_if_ipv6_select_src_addr(struct net_if *iface,
    2211              :                                                    const struct in6_addr *dst);
    2212              : #else
    2213            1 : static inline const struct in6_addr *net_if_ipv6_select_src_addr(
    2214              :         struct net_if *iface, const struct in6_addr *dst)
    2215              : {
    2216              :         ARG_UNUSED(iface);
    2217              :         ARG_UNUSED(dst);
    2218              : 
    2219              :         return NULL;
    2220              : }
    2221              : #endif
    2222              : 
    2223              : /**
    2224              :  * @brief Get a IPv6 source address that should be used when sending
    2225              :  * network data to destination. Use a hint set to the socket to select
    2226              :  * the proper address.
    2227              :  *
    2228              :  * @param iface Interface that was used when packet was received.
    2229              :  * If the interface is not known, then NULL can be given.
    2230              :  * @param dst IPv6 destination address
    2231              :  * @param flags Hint from the related socket. See RFC 5014 for value details.
    2232              :  *
    2233              :  * @return Pointer to IPv6 address to use, NULL if no IPv6 address
    2234              :  * could be found.
    2235              :  */
    2236              : #if defined(CONFIG_NET_IPV6)
    2237              : const struct in6_addr *net_if_ipv6_select_src_addr_hint(struct net_if *iface,
    2238              :                                                         const struct in6_addr *dst,
    2239              :                                                         int flags);
    2240              : #else
    2241            1 : static inline const struct in6_addr *net_if_ipv6_select_src_addr_hint(
    2242              :         struct net_if *iface, const struct in6_addr *dst, int flags)
    2243              : {
    2244              :         ARG_UNUSED(iface);
    2245              :         ARG_UNUSED(dst);
    2246              :         ARG_UNUSED(flags);
    2247              : 
    2248              :         return NULL;
    2249              : }
    2250              : #endif
    2251              : 
    2252              : /**
    2253              :  * @brief Get a network interface that should be used when sending
    2254              :  * IPv6 network data to destination.
    2255              :  *
    2256              :  * @param dst IPv6 destination address
    2257              :  *
    2258              :  * @return Pointer to network interface to use, NULL if no suitable interface
    2259              :  * could be found.
    2260              :  */
    2261              : #if defined(CONFIG_NET_IPV6)
    2262              : struct net_if *net_if_ipv6_select_src_iface(const struct in6_addr *dst);
    2263              : #else
    2264            1 : static inline struct net_if *net_if_ipv6_select_src_iface(
    2265              :         const struct in6_addr *dst)
    2266              : {
    2267              :         ARG_UNUSED(dst);
    2268              : 
    2269              :         return NULL;
    2270              : }
    2271              : #endif
    2272              : 
    2273              : /**
    2274              :  * @brief Get a network interface that should be used when sending
    2275              :  * IPv6 network data to destination. Also return the source IPv6 address from
    2276              :  * that network interface.
    2277              :  *
    2278              :  * @param dst IPv6 destination address
    2279              :  * @param src_addr IPv6 source address. This can be set to NULL if the source
    2280              :  *                 address is not needed.
    2281              :  *
    2282              :  * @return Pointer to network interface to use, NULL if no suitable interface
    2283              :  * could be found.
    2284              :  */
    2285              : #if defined(CONFIG_NET_IPV6)
    2286              : struct net_if *net_if_ipv6_select_src_iface_addr(const struct in6_addr *dst,
    2287              :                                                  const struct in6_addr **src_addr);
    2288              : #else
    2289            1 : static inline struct net_if *net_if_ipv6_select_src_iface_addr(
    2290              :         const struct in6_addr *dst, const struct in6_addr **src_addr)
    2291              : {
    2292              :         ARG_UNUSED(dst);
    2293              :         ARG_UNUSED(src_addr);
    2294              : 
    2295              :         return NULL;
    2296              : }
    2297              : #endif /* CONFIG_NET_IPV6 */
    2298              : 
    2299              : /**
    2300              :  * @brief Get a IPv6 link local address in a given state.
    2301              :  *
    2302              :  * @param iface Interface to use. Must be a valid pointer to an interface.
    2303              :  * @param addr_state IPv6 address state (preferred, tentative, deprecated)
    2304              :  *
    2305              :  * @return Pointer to link local IPv6 address, NULL if no proper IPv6 address
    2306              :  * could be found.
    2307              :  */
    2308            1 : struct in6_addr *net_if_ipv6_get_ll(struct net_if *iface,
    2309              :                                     enum net_addr_state addr_state);
    2310              : 
    2311              : /**
    2312              :  * @brief Return link local IPv6 address from the first interface that has
    2313              :  * a link local address matching give state.
    2314              :  *
    2315              :  * @param state IPv6 address state (ANY, TENTATIVE, PREFERRED, DEPRECATED)
    2316              :  * @param iface Pointer to interface is returned
    2317              :  *
    2318              :  * @return Pointer to IPv6 address, NULL if not found.
    2319              :  */
    2320            1 : struct in6_addr *net_if_ipv6_get_ll_addr(enum net_addr_state state,
    2321              :                                          struct net_if **iface);
    2322              : 
    2323              : /**
    2324              :  * @brief Stop IPv6 Duplicate Address Detection (DAD) procedure if
    2325              :  * we find out that our IPv6 address is already in use.
    2326              :  *
    2327              :  * @param iface Interface where the DAD was running.
    2328              :  * @param addr IPv6 address that failed DAD
    2329              :  */
    2330            1 : void net_if_ipv6_dad_failed(struct net_if *iface, const struct in6_addr *addr);
    2331              : 
    2332              : /**
    2333              :  * @brief Return global IPv6 address from the first interface that has
    2334              :  * a global IPv6 address matching the given state.
    2335              :  *
    2336              :  * @param state IPv6 address state (ANY, TENTATIVE, PREFERRED, DEPRECATED)
    2337              :  * @param iface Caller can give an interface to check. If iface is set to NULL,
    2338              :  * then all the interfaces are checked. Pointer to interface where the IPv6
    2339              :  * address is defined is returned to the caller.
    2340              :  *
    2341              :  * @return Pointer to IPv6 address, NULL if not found.
    2342              :  */
    2343            1 : struct in6_addr *net_if_ipv6_get_global_addr(enum net_addr_state state,
    2344              :                                              struct net_if **iface);
    2345              : 
    2346              : /**
    2347              :  * @brief Allocate network interface IPv4 config.
    2348              :  *
    2349              :  * @details This function will allocate new IPv4 config.
    2350              :  *
    2351              :  * @param iface Interface to use.
    2352              :  * @param ipv4 Pointer to allocated IPv4 struct is returned to caller.
    2353              :  *
    2354              :  * @return 0 if ok, <0 if error
    2355              :  */
    2356            1 : int net_if_config_ipv4_get(struct net_if *iface,
    2357              :                            struct net_if_ipv4 **ipv4);
    2358              : 
    2359              : /**
    2360              :  * @brief Release network interface IPv4 config.
    2361              :  *
    2362              :  * @param iface Interface to use.
    2363              :  *
    2364              :  * @return 0 if ok, <0 if error
    2365              :  */
    2366            1 : int net_if_config_ipv4_put(struct net_if *iface);
    2367              : 
    2368              : /**
    2369              :  * @brief Get IPv4 time-to-live value specified for a given interface
    2370              :  *
    2371              :  * @param iface Network interface
    2372              :  *
    2373              :  * @return Time-to-live
    2374              :  */
    2375            1 : uint8_t net_if_ipv4_get_ttl(struct net_if *iface);
    2376              : 
    2377              : /**
    2378              :  * @brief Set IPv4 time-to-live value specified to a given interface
    2379              :  *
    2380              :  * @param iface Network interface
    2381              :  * @param ttl Time-to-live value
    2382              :  */
    2383            1 : void net_if_ipv4_set_ttl(struct net_if *iface, uint8_t ttl);
    2384              : 
    2385              : /**
    2386              :  * @brief Get IPv4 multicast time-to-live value specified for a given interface
    2387              :  *
    2388              :  * @param iface Network interface
    2389              :  *
    2390              :  * @return Time-to-live
    2391              :  */
    2392            1 : uint8_t net_if_ipv4_get_mcast_ttl(struct net_if *iface);
    2393              : 
    2394              : /**
    2395              :  * @brief Set IPv4 multicast time-to-live value specified to a given interface
    2396              :  *
    2397              :  * @param iface Network interface
    2398              :  * @param ttl Time-to-live value
    2399              :  */
    2400            1 : void net_if_ipv4_set_mcast_ttl(struct net_if *iface, uint8_t ttl);
    2401              : 
    2402              : /**
    2403              :  * @brief Check if this IPv4 address belongs to one of the interfaces.
    2404              :  *
    2405              :  * @param addr IPv4 address
    2406              :  * @param iface Interface is returned
    2407              :  *
    2408              :  * @return Pointer to interface address, NULL if not found.
    2409              :  */
    2410            1 : struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
    2411              :                                             struct net_if **iface);
    2412              : 
    2413              : /**
    2414              :  * @brief Add a IPv4 address to an interface
    2415              :  *
    2416              :  * @param iface Network interface
    2417              :  * @param addr IPv4 address
    2418              :  * @param addr_type IPv4 address type
    2419              :  * @param vlifetime Validity time for this address
    2420              :  *
    2421              :  * @return Pointer to interface address, NULL if cannot be added
    2422              :  */
    2423            1 : struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface,
    2424              :                                          const struct in_addr *addr,
    2425              :                                          enum net_addr_type addr_type,
    2426              :                                          uint32_t vlifetime);
    2427              : 
    2428              : /**
    2429              :  * @brief Remove a IPv4 address from an interface
    2430              :  *
    2431              :  * @param iface Network interface
    2432              :  * @param addr IPv4 address
    2433              :  *
    2434              :  * @return True if successfully removed, false otherwise
    2435              :  */
    2436            1 : bool net_if_ipv4_addr_rm(struct net_if *iface, const struct in_addr *addr);
    2437              : 
    2438              : /**
    2439              :  * @brief Check if this IPv4 address belongs to one of the interface indices.
    2440              :  *
    2441              :  * @param addr IPv4 address
    2442              :  *
    2443              :  * @return >0 if address was found in given network interface index,
    2444              :  * all other values mean address was not found
    2445              :  */
    2446            1 : __syscall int net_if_ipv4_addr_lookup_by_index(const struct in_addr *addr);
    2447              : 
    2448              : /**
    2449              :  * @brief Add a IPv4 address to an interface by network interface index
    2450              :  *
    2451              :  * @param index Network interface index
    2452              :  * @param addr IPv4 address
    2453              :  * @param addr_type IPv4 address type
    2454              :  * @param vlifetime Validity time for this address
    2455              :  *
    2456              :  * @return True if ok, false if the address could not be added
    2457              :  */
    2458            1 : __syscall bool net_if_ipv4_addr_add_by_index(int index,
    2459              :                                              const struct in_addr *addr,
    2460              :                                              enum net_addr_type addr_type,
    2461              :                                              uint32_t vlifetime);
    2462              : 
    2463              : /**
    2464              :  * @brief Remove a IPv4 address from an interface by interface index
    2465              :  *
    2466              :  * @param index Network interface index
    2467              :  * @param addr IPv4 address
    2468              :  *
    2469              :  * @return True if successfully removed, false otherwise
    2470              :  */
    2471            1 : __syscall bool net_if_ipv4_addr_rm_by_index(int index,
    2472              :                                             const struct in_addr *addr);
    2473              : 
    2474              : /**
    2475              :  * @brief Go through all IPv4 addresses on a network interface and call callback
    2476              :  * for each used address.
    2477              :  *
    2478              :  * @param iface Pointer to the network interface
    2479              :  * @param cb User-supplied callback function to call
    2480              :  * @param user_data User specified data
    2481              :  */
    2482            1 : void net_if_ipv4_addr_foreach(struct net_if *iface, net_if_ip_addr_cb_t cb,
    2483              :                               void *user_data);
    2484              : 
    2485              : /**
    2486              :  * @brief Add a IPv4 multicast address to an interface
    2487              :  *
    2488              :  * @param iface Network interface
    2489              :  * @param addr IPv4 multicast address
    2490              :  *
    2491              :  * @return Pointer to interface multicast address, NULL if cannot be added
    2492              :  */
    2493            1 : struct net_if_mcast_addr *net_if_ipv4_maddr_add(struct net_if *iface,
    2494              :                                                 const struct in_addr *addr);
    2495              : 
    2496              : /**
    2497              :  * @brief Remove an IPv4 multicast address from an interface
    2498              :  *
    2499              :  * @param iface Network interface
    2500              :  * @param addr IPv4 multicast address
    2501              :  *
    2502              :  * @return True if successfully removed, false otherwise
    2503              :  */
    2504            1 : bool net_if_ipv4_maddr_rm(struct net_if *iface, const struct in_addr *addr);
    2505              : 
    2506              : /**
    2507              :  * @brief Go through all IPv4 multicast addresses on a network interface and call
    2508              :  * callback for each used address.
    2509              :  *
    2510              :  * @param iface Pointer to the network interface
    2511              :  * @param cb User-supplied callback function to call
    2512              :  * @param user_data User specified data
    2513              :  */
    2514            1 : void net_if_ipv4_maddr_foreach(struct net_if *iface, net_if_ip_maddr_cb_t cb,
    2515              :                                void *user_data);
    2516              : 
    2517              : /**
    2518              :  * @brief Check if this IPv4 multicast address belongs to a specific interface
    2519              :  * or one of the interfaces.
    2520              :  *
    2521              :  * @param addr IPv4 address
    2522              :  * @param iface If *iface is null, then pointer to interface is returned,
    2523              :  * otherwise the *iface value needs to be matched.
    2524              :  *
    2525              :  * @return Pointer to interface multicast address, NULL if not found.
    2526              :  */
    2527            1 : struct net_if_mcast_addr *net_if_ipv4_maddr_lookup(const struct in_addr *addr,
    2528              :                                                    struct net_if **iface);
    2529              : 
    2530              : /**
    2531              :  * @brief Mark a given multicast address to be joined.
    2532              :  *
    2533              :  * @param iface Network interface the address belongs to
    2534              :  * @param addr IPv4 multicast address
    2535              :  */
    2536            1 : void net_if_ipv4_maddr_join(struct net_if *iface,
    2537              :                             struct net_if_mcast_addr *addr);
    2538              : 
    2539              : /**
    2540              :  * @brief Check if given multicast address is joined or not.
    2541              :  *
    2542              :  * @param addr IPv4 multicast address
    2543              :  *
    2544              :  * @return True if address is joined, False otherwise.
    2545              :  */
    2546            1 : static inline bool net_if_ipv4_maddr_is_joined(struct net_if_mcast_addr *addr)
    2547              : {
    2548              :         if (addr == NULL) {
    2549              :                 return false;
    2550              :         }
    2551              : 
    2552              :         return addr->is_joined;
    2553              : }
    2554              : 
    2555              : /**
    2556              :  * @brief Mark a given multicast address to be left.
    2557              :  *
    2558              :  * @param iface Network interface the address belongs to
    2559              :  * @param addr IPv4 multicast address
    2560              :  */
    2561            1 : void net_if_ipv4_maddr_leave(struct net_if *iface,
    2562              :                              struct net_if_mcast_addr *addr);
    2563              : 
    2564              : /**
    2565              :  * @brief Get the IPv4 address of the given router
    2566              :  * @param router a network router
    2567              :  *
    2568              :  * @return pointer to the IPv4 address, or NULL if none
    2569              :  */
    2570              : #if defined(CONFIG_NET_NATIVE_IPV4)
    2571              : static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)
    2572              : {
    2573              :         if (router == NULL) {
    2574              :                 return NULL;
    2575              :         }
    2576              : 
    2577              :         return &router->address.in_addr;
    2578              : }
    2579              : #else
    2580            1 : static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)
    2581              : {
    2582              :         static struct in_addr addr;
    2583              : 
    2584              :         ARG_UNUSED(router);
    2585              : 
    2586              :         return &addr;
    2587              : }
    2588              : #endif
    2589              : 
    2590              : /**
    2591              :  * @brief Check if IPv4 address is one of the routers configured
    2592              :  * in the system.
    2593              :  *
    2594              :  * @param iface Network interface
    2595              :  * @param addr IPv4 address
    2596              :  *
    2597              :  * @return Pointer to router information, NULL if cannot be found
    2598              :  */
    2599            1 : struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface,
    2600              :                                                 const struct in_addr *addr);
    2601              : 
    2602              : /**
    2603              :  * @brief Find default router for this IPv4 address.
    2604              :  *
    2605              :  * @param iface Network interface. This can be NULL in which case we
    2606              :  * go through all the network interfaces to find a suitable router.
    2607              :  * @param addr IPv4 address
    2608              :  *
    2609              :  * @return Pointer to router information, NULL if cannot be found
    2610              :  */
    2611            1 : struct net_if_router *net_if_ipv4_router_find_default(struct net_if *iface,
    2612              :                                                       const struct in_addr *addr);
    2613              : /**
    2614              :  * @brief Add IPv4 router to the system.
    2615              :  *
    2616              :  * @param iface Network interface
    2617              :  * @param addr IPv4 address
    2618              :  * @param is_default Is this router the default one
    2619              :  * @param router_lifetime Lifetime of the router
    2620              :  *
    2621              :  * @return Pointer to router information, NULL if could not be added
    2622              :  */
    2623            1 : struct net_if_router *net_if_ipv4_router_add(struct net_if *iface,
    2624              :                                              const struct in_addr *addr,
    2625              :                                              bool is_default,
    2626              :                                              uint16_t router_lifetime);
    2627              : 
    2628              : /**
    2629              :  * @brief Remove IPv4 router from the system.
    2630              :  *
    2631              :  * @param router Router information.
    2632              :  *
    2633              :  * @return True if successfully removed, false otherwise
    2634              :  */
    2635            1 : bool net_if_ipv4_router_rm(struct net_if_router *router);
    2636              : 
    2637              : /**
    2638              :  * @brief Check if the given IPv4 address belongs to local subnet.
    2639              :  *
    2640              :  * @param iface Interface to use. Must be a valid pointer to an interface.
    2641              :  * @param addr IPv4 address
    2642              :  *
    2643              :  * @return True if address is part of local subnet, false otherwise.
    2644              :  */
    2645            1 : bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
    2646              :                                const struct in_addr *addr);
    2647              : 
    2648              : /**
    2649              :  * @brief Check if the given IPv4 address is a broadcast address.
    2650              :  *
    2651              :  * @param iface Interface to use. Must be a valid pointer to an interface.
    2652              :  * @param addr IPv4 address, this should be in network byte order
    2653              :  *
    2654              :  * @return True if address is a broadcast address, false otherwise.
    2655              :  */
    2656            1 : bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
    2657              :                                const struct in_addr *addr);
    2658              : 
    2659              : /**
    2660              :  * @brief Get a network interface that should be used when sending
    2661              :  * IPv4 network data to destination.
    2662              :  *
    2663              :  * @param dst IPv4 destination address
    2664              :  *
    2665              :  * @return Pointer to network interface to use, NULL if no suitable interface
    2666              :  * could be found.
    2667              :  */
    2668              : #if defined(CONFIG_NET_IPV4)
    2669              : struct net_if *net_if_ipv4_select_src_iface(const struct in_addr *dst);
    2670              : #else
    2671            1 : static inline struct net_if *net_if_ipv4_select_src_iface(
    2672              :         const struct in_addr *dst)
    2673              : {
    2674              :         ARG_UNUSED(dst);
    2675              : 
    2676              :         return NULL;
    2677              : }
    2678              : #endif
    2679              : 
    2680              : /**
    2681              :  * @brief Get a network interface that should be used when sending
    2682              :  * IPv4 network data to destination. Also return the source IPv4 address from
    2683              :  * that network interface.
    2684              :  *
    2685              :  * @param dst IPv4 destination address
    2686              :  * @param src_addr IPv4 source address. This can be set to NULL if the source
    2687              :  *                 address is not needed.
    2688              :  *
    2689              :  * @return Pointer to network interface to use, NULL if no suitable interface
    2690              :  * could be found.
    2691              :  */
    2692              : #if defined(CONFIG_NET_IPV4)
    2693              : struct net_if *net_if_ipv4_select_src_iface_addr(const struct in_addr *dst,
    2694              :                                                  const struct in_addr **src_addr);
    2695              : #else
    2696            1 : static inline struct net_if *net_if_ipv4_select_src_iface_addr(
    2697              :         const struct in_addr *dst, const struct in_addr **src_addr)
    2698              : {
    2699              :         ARG_UNUSED(dst);
    2700              :         ARG_UNUSED(src_addr);
    2701              : 
    2702              :         return NULL;
    2703              : }
    2704              : #endif /* CONFIG_NET_IPV4 */
    2705              : 
    2706              : /**
    2707              :  * @brief Get a IPv4 source address that should be used when sending
    2708              :  * network data to destination.
    2709              :  *
    2710              :  * @param iface Interface to use when sending the packet.
    2711              :  * If the interface is not known, then NULL can be given.
    2712              :  * @param dst IPv4 destination address
    2713              :  *
    2714              :  * @return Pointer to IPv4 address to use, NULL if no IPv4 address
    2715              :  * could be found.
    2716              :  */
    2717              : #if defined(CONFIG_NET_IPV4)
    2718              : const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *iface,
    2719              :                                                   const struct in_addr *dst);
    2720              : #else
    2721            1 : static inline const struct in_addr *net_if_ipv4_select_src_addr(
    2722              :         struct net_if *iface, const struct in_addr *dst)
    2723              : {
    2724              :         ARG_UNUSED(iface);
    2725              :         ARG_UNUSED(dst);
    2726              : 
    2727              :         return NULL;
    2728              : }
    2729              : #endif
    2730              : 
    2731              : /**
    2732              :  * @brief Get a IPv4 link local address in a given state.
    2733              :  *
    2734              :  * @param iface Interface to use. Must be a valid pointer to an interface.
    2735              :  * @param addr_state IPv4 address state (preferred, tentative, deprecated)
    2736              :  *
    2737              :  * @return Pointer to link local IPv4 address, NULL if no proper IPv4 address
    2738              :  * could be found.
    2739              :  */
    2740            1 : struct in_addr *net_if_ipv4_get_ll(struct net_if *iface,
    2741              :                                    enum net_addr_state addr_state);
    2742              : 
    2743              : /**
    2744              :  * @brief Get a IPv4 global address in a given state.
    2745              :  *
    2746              :  * @param iface Interface to use. Must be a valid pointer to an interface.
    2747              :  * @param addr_state IPv4 address state (preferred, tentative, deprecated)
    2748              :  *
    2749              :  * @return Pointer to link local IPv4 address, NULL if no proper IPv4 address
    2750              :  * could be found.
    2751              :  */
    2752            1 : struct in_addr *net_if_ipv4_get_global_addr(struct net_if *iface,
    2753              :                                             enum net_addr_state addr_state);
    2754              : 
    2755              : /**
    2756              :  * @brief Get IPv4 netmask related to an address of an interface.
    2757              :  *
    2758              :  * @param iface Interface to use.
    2759              :  * @param addr IPv4 address to check.
    2760              :  *
    2761              :  * @return The netmask set on the interface related to the give address,
    2762              :  *         unspecified address if not found.
    2763              :  */
    2764            1 : struct in_addr net_if_ipv4_get_netmask_by_addr(struct net_if *iface,
    2765              :                                                const struct in_addr *addr);
    2766              : 
    2767              : /**
    2768              :  * @brief Get IPv4 netmask of an interface.
    2769              :  *
    2770              :  * @deprecated Use net_if_ipv4_get_netmask_by_addr() instead.
    2771              :  *
    2772              :  * @param iface Interface to use.
    2773              :  *
    2774              :  * @return The netmask set on the interface, unspecified address if not found.
    2775              :  */
    2776            1 : __deprecated struct in_addr net_if_ipv4_get_netmask(struct net_if *iface);
    2777              : 
    2778              : /**
    2779              :  * @brief Set IPv4 netmask for an interface.
    2780              :  *
    2781              :  * @deprecated Use net_if_ipv4_set_netmask_by_addr() instead.
    2782              :  *
    2783              :  * @param iface Interface to use.
    2784              :  * @param netmask IPv4 netmask
    2785              :  */
    2786            1 : __deprecated void net_if_ipv4_set_netmask(struct net_if *iface,
    2787              :                                           const struct in_addr *netmask);
    2788              : 
    2789              : /**
    2790              :  * @brief Set IPv4 netmask for an interface index.
    2791              :  *
    2792              :  * @deprecated Use net_if_ipv4_set_netmask_by_addr() instead.
    2793              :  *
    2794              :  * @param index Network interface index
    2795              :  * @param netmask IPv4 netmask
    2796              :  *
    2797              :  * @return True if netmask was added, false otherwise.
    2798              :  */
    2799            1 : __deprecated __syscall bool net_if_ipv4_set_netmask_by_index(int index,
    2800              :                                                              const struct in_addr *netmask);
    2801              : 
    2802              : /**
    2803              :  * @brief Set IPv4 netmask for an interface index for a given address.
    2804              :  *
    2805              :  * @param index Network interface index
    2806              :  * @param addr IPv4 address related to this netmask
    2807              :  * @param netmask IPv4 netmask
    2808              :  *
    2809              :  * @return True if netmask was added, false otherwise.
    2810              :  */
    2811            1 : __syscall bool net_if_ipv4_set_netmask_by_addr_by_index(int index,
    2812              :                                                         const struct in_addr *addr,
    2813              :                                                         const struct in_addr *netmask);
    2814              : 
    2815              : /**
    2816              :  * @brief Set IPv4 netmask for an interface index for a given address.
    2817              :  *
    2818              :  * @param iface Network interface
    2819              :  * @param addr IPv4 address related to this netmask
    2820              :  * @param netmask IPv4 netmask
    2821              :  *
    2822              :  * @return True if netmask was added, false otherwise.
    2823              :  */
    2824            1 : bool net_if_ipv4_set_netmask_by_addr(struct net_if *iface,
    2825              :                                      const struct in_addr *addr,
    2826              :                                      const struct in_addr *netmask);
    2827              : 
    2828              : /**
    2829              :  * @brief Get IPv4 gateway of an interface.
    2830              :  *
    2831              :  * @param iface Interface to use.
    2832              :  *
    2833              :  * @return The gateway set on the interface, unspecified address if not found.
    2834              :  */
    2835            1 : struct in_addr net_if_ipv4_get_gw(struct net_if *iface);
    2836              : 
    2837              : /**
    2838              :  * @brief Set IPv4 gateway for an interface.
    2839              :  *
    2840              :  * @param iface Interface to use.
    2841              :  * @param gw IPv4 address of an gateway
    2842              :  */
    2843            1 : void net_if_ipv4_set_gw(struct net_if *iface, const struct in_addr *gw);
    2844              : 
    2845              : /**
    2846              :  * @brief Set IPv4 gateway for an interface index.
    2847              :  *
    2848              :  * @param index Network interface index
    2849              :  * @param gw IPv4 address of an gateway
    2850              :  *
    2851              :  * @return True if gateway was added, false otherwise.
    2852              :  */
    2853            1 : __syscall bool net_if_ipv4_set_gw_by_index(int index, const struct in_addr *gw);
    2854              : 
    2855              : /**
    2856              :  * @brief Get a network interface that should be used when sending
    2857              :  * IPv6 or IPv4 network data to destination.
    2858              :  *
    2859              :  * @param dst IPv6 or IPv4 destination address
    2860              :  *
    2861              :  * @return Pointer to network interface to use. Note that the function
    2862              :  * will return the default network interface if the best network interface
    2863              :  * is not found.
    2864              :  */
    2865            1 : struct net_if *net_if_select_src_iface(const struct sockaddr *dst);
    2866              : 
    2867              : /**
    2868              :  * @typedef net_if_link_callback_t
    2869              :  * @brief Define callback that is called after a network packet
    2870              :  *        has been sent.
    2871              :  * @param iface A pointer to a struct net_if to which the net_pkt was sent to.
    2872              :  * @param dst Link layer address of the destination where the network packet was sent.
    2873              :  * @param status Send status, 0 is ok, < 0 error.
    2874              :  */
    2875            1 : typedef void (*net_if_link_callback_t)(struct net_if *iface,
    2876              :                                        struct net_linkaddr *dst,
    2877              :                                        int status);
    2878              : 
    2879              : /**
    2880              :  * @brief Link callback handler struct.
    2881              :  *
    2882              :  * Stores the link callback information. Caller must make sure that
    2883              :  * the variable pointed by this is valid during the lifetime of
    2884              :  * registration. Typically this means that the variable cannot be
    2885              :  * allocated from stack.
    2886              :  */
    2887            1 : struct net_if_link_cb {
    2888              :         /** Node information for the slist. */
    2889            1 :         sys_snode_t node;
    2890              : 
    2891              :         /** Link callback */
    2892            1 :         net_if_link_callback_t cb;
    2893              : };
    2894              : 
    2895              : /**
    2896              :  * @brief Register a link callback.
    2897              :  *
    2898              :  * @param link Caller specified handler for the callback.
    2899              :  * @param cb Callback to register.
    2900              :  */
    2901            1 : void net_if_register_link_cb(struct net_if_link_cb *link,
    2902              :                              net_if_link_callback_t cb);
    2903              : 
    2904              : /**
    2905              :  * @brief Unregister a link callback.
    2906              :  *
    2907              :  * @param link Caller specified handler for the callback.
    2908              :  */
    2909            1 : void net_if_unregister_link_cb(struct net_if_link_cb *link);
    2910              : 
    2911              : /**
    2912              :  * @brief Call a link callback function.
    2913              :  *
    2914              :  * @param iface Network interface.
    2915              :  * @param lladdr Destination link layer address
    2916              :  * @param status 0 is ok, < 0 error
    2917              :  */
    2918            1 : void net_if_call_link_cb(struct net_if *iface, struct net_linkaddr *lladdr,
    2919              :                          int status);
    2920              : 
    2921              : /** @cond INTERNAL_HIDDEN */
    2922              : 
    2923              : /* used to ensure encoding of checksum support in net_if.h and
    2924              :  * ethernet.h is the same
    2925              :  */
    2926              : #define NET_IF_CHECKSUM_NONE_BIT                        0
    2927              : #define NET_IF_CHECKSUM_IPV4_HEADER_BIT                 BIT(0)
    2928              : #define NET_IF_CHECKSUM_IPV4_ICMP_BIT                   BIT(1)
    2929              : /* Space for future protocols and restrictions for IPV4 */
    2930              : #define NET_IF_CHECKSUM_IPV6_HEADER_BIT                 BIT(10)
    2931              : #define NET_IF_CHECKSUM_IPV6_ICMP_BIT                   BIT(11)
    2932              : /* Space for future protocols and restrictions for IPV6 */
    2933              : #define NET_IF_CHECKSUM_TCP_BIT                         BIT(21)
    2934              : #define NET_IF_CHECKSUM_UDP_BIT                         BIT(22)
    2935              : 
    2936              : /** @endcond */
    2937              : 
    2938              : /**
    2939              :  * @brief Type of checksum for which support in the interface will be queried.
    2940              :  */
    2941            1 : enum net_if_checksum_type {
    2942              :         /** Interface supports IP version 4 header checksum calculation */
    2943              :         NET_IF_CHECKSUM_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
    2944              :         /** Interface supports checksum calculation for TCP payload in IPv4 */
    2945              :         NET_IF_CHECKSUM_IPV4_TCP    = NET_IF_CHECKSUM_IPV4_HEADER_BIT |
    2946              :                                       NET_IF_CHECKSUM_TCP_BIT,
    2947              :         /** Interface supports checksum calculation for UDP payload in IPv4 */
    2948              :         NET_IF_CHECKSUM_IPV4_UDP    = NET_IF_CHECKSUM_IPV4_HEADER_BIT |
    2949              :                                       NET_IF_CHECKSUM_UDP_BIT,
    2950              :         /** Interface supports checksum calculation for ICMP4 payload in IPv4 */
    2951              :         NET_IF_CHECKSUM_IPV4_ICMP   = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
    2952              :         /** Interface supports IP version 6 header checksum calculation */
    2953              :         NET_IF_CHECKSUM_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
    2954              :         /** Interface supports checksum calculation for TCP payload in IPv6 */
    2955              :         NET_IF_CHECKSUM_IPV6_TCP    = NET_IF_CHECKSUM_IPV6_HEADER_BIT |
    2956              :                                       NET_IF_CHECKSUM_TCP_BIT,
    2957              :         /** Interface supports checksum calculation for UDP payload in IPv6 */
    2958              :         NET_IF_CHECKSUM_IPV6_UDP    = NET_IF_CHECKSUM_IPV6_HEADER_BIT |
    2959              :                                       NET_IF_CHECKSUM_UDP_BIT,
    2960              :         /** Interface supports checksum calculation for ICMP6 payload in IPv6 */
    2961              :         NET_IF_CHECKSUM_IPV6_ICMP   = NET_IF_CHECKSUM_IPV6_ICMP_BIT
    2962              : };
    2963              : 
    2964              : /**
    2965              :  * @brief Check if received network packet checksum calculation can be avoided
    2966              :  * or not. For example many ethernet devices support network packet offloading
    2967              :  * in which case the IP stack does not need to calculate the checksum.
    2968              :  *
    2969              :  * @param iface Network interface
    2970              :  * @param chksum_type L3 and/or L4 protocol for which to compute checksum
    2971              :  *
    2972              :  * @return True if checksum needs to be calculated, false otherwise.
    2973              :  */
    2974            1 : bool net_if_need_calc_rx_checksum(struct net_if *iface,
    2975              :                                   enum net_if_checksum_type chksum_type);
    2976              : 
    2977              : /**
    2978              :  * @brief Check if network packet checksum calculation can be avoided or not
    2979              :  * when sending the packet. For example many ethernet devices support network
    2980              :  * packet offloading in which case the IP stack does not need to calculate the
    2981              :  * checksum.
    2982              :  *
    2983              :  * @param iface Network interface
    2984              :  * @param chksum_type L3 and/or L4 protocol for which to compute checksum
    2985              :  *
    2986              :  * @return True if checksum needs to be calculated, false otherwise.
    2987              :  */
    2988            1 : bool net_if_need_calc_tx_checksum(struct net_if *iface,
    2989              :                                   enum net_if_checksum_type chksum_type);
    2990              : 
    2991              : /**
    2992              :  * @brief Get interface according to index
    2993              :  *
    2994              :  * @details This is a syscall only to provide access to the object for purposes
    2995              :  *          of assigning permissions.
    2996              :  *
    2997              :  * @param index Interface index
    2998              :  *
    2999              :  * @return Pointer to interface or NULL if not found.
    3000              :  */
    3001            1 : __syscall struct net_if *net_if_get_by_index(int index);
    3002              : 
    3003              : /**
    3004              :  * @brief Get interface index according to pointer
    3005              :  *
    3006              :  * @param iface Pointer to network interface
    3007              :  *
    3008              :  * @return Interface index
    3009              :  */
    3010            1 : int net_if_get_by_iface(struct net_if *iface);
    3011              : 
    3012              : /**
    3013              :  * @typedef net_if_cb_t
    3014              :  * @brief Callback used while iterating over network interfaces
    3015              :  *
    3016              :  * @param iface Pointer to current network interface
    3017              :  * @param user_data A valid pointer to user data or NULL
    3018              :  */
    3019            1 : typedef void (*net_if_cb_t)(struct net_if *iface, void *user_data);
    3020              : 
    3021              : /**
    3022              :  * @brief Go through all the network interfaces and call callback
    3023              :  * for each interface.
    3024              :  *
    3025              :  * @param cb User-supplied callback function to call
    3026              :  * @param user_data User specified data
    3027              :  */
    3028            1 : void net_if_foreach(net_if_cb_t cb, void *user_data);
    3029              : 
    3030              : /**
    3031              :  * @brief Bring interface up
    3032              :  *
    3033              :  * @param iface Pointer to network interface
    3034              :  *
    3035              :  * @return 0 on success
    3036              :  */
    3037            1 : int net_if_up(struct net_if *iface);
    3038              : 
    3039              : /**
    3040              :  * @brief Check if interface is up and running.
    3041              :  *
    3042              :  * @param iface Pointer to network interface
    3043              :  *
    3044              :  * @return True if interface is up, False if it is down.
    3045              :  */
    3046            1 : static inline bool net_if_is_up(struct net_if *iface)
    3047              : {
    3048              :         if (iface == NULL) {
    3049              :                 return false;
    3050              :         }
    3051              : 
    3052              :         return net_if_flag_is_set(iface, NET_IF_UP) &&
    3053              :                net_if_flag_is_set(iface, NET_IF_RUNNING);
    3054              : }
    3055              : 
    3056              : /**
    3057              :  * @brief Bring interface down
    3058              :  *
    3059              :  * @param iface Pointer to network interface
    3060              :  *
    3061              :  * @return 0 on success
    3062              :  */
    3063            1 : int net_if_down(struct net_if *iface);
    3064              : 
    3065              : /**
    3066              :  * @brief Check if interface was brought up by the administrator.
    3067              :  *
    3068              :  * @param iface Pointer to network interface
    3069              :  *
    3070              :  * @return True if interface is admin up, false otherwise.
    3071              :  */
    3072            1 : static inline bool net_if_is_admin_up(struct net_if *iface)
    3073              : {
    3074              :         if (iface == NULL) {
    3075              :                 return false;
    3076              :         }
    3077              : 
    3078              :         return net_if_flag_is_set(iface, NET_IF_UP);
    3079              : }
    3080              : 
    3081              : /**
    3082              :  * @brief Underlying network device has detected the carrier (cable connected).
    3083              :  *
    3084              :  * @details The function should be used by the respective network device driver
    3085              :  *          or L2 implementation to update its state on a network interface.
    3086              :  *
    3087              :  * @param iface Pointer to network interface
    3088              :  */
    3089            1 : void net_if_carrier_on(struct net_if *iface);
    3090              : 
    3091              : /**
    3092              :  * @brief Underlying network device has lost the carrier (cable disconnected).
    3093              :  *
    3094              :  * @details The function should be used by the respective network device driver
    3095              :  *          or L2 implementation to update its state on a network interface.
    3096              :  *
    3097              :  * @param iface Pointer to network interface
    3098              :  */
    3099            1 : void net_if_carrier_off(struct net_if *iface);
    3100              : 
    3101              : /**
    3102              :  * @brief Check if carrier is present on network device.
    3103              :  *
    3104              :  * @param iface Pointer to network interface
    3105              :  *
    3106              :  * @return True if carrier is present, false otherwise.
    3107              :  */
    3108            1 : static inline bool net_if_is_carrier_ok(struct net_if *iface)
    3109              : {
    3110              :         if (iface == NULL) {
    3111              :                 return false;
    3112              :         }
    3113              : 
    3114              :         return net_if_flag_is_set(iface, NET_IF_LOWER_UP);
    3115              : }
    3116              : 
    3117              : /**
    3118              :  * @brief Mark interface as dormant. Dormant state indicates that the interface
    3119              :  *        is not ready to pass packets yet, but is waiting for some event
    3120              :  *        (for example Wi-Fi network association).
    3121              :  *
    3122              :  * @details The function should be used by the respective network device driver
    3123              :  *          or L2 implementation to update its state on a network interface.
    3124              :  *
    3125              :  * @param iface Pointer to network interface
    3126              :  */
    3127            1 : void net_if_dormant_on(struct net_if *iface);
    3128              : 
    3129              : /**
    3130              :  * @brief Mark interface as not dormant.
    3131              :  *
    3132              :  * @details The function should be used by the respective network device driver
    3133              :  *          or L2 implementation to update its state on a network interface.
    3134              :  *
    3135              :  * @param iface Pointer to network interface
    3136              :  */
    3137            1 : void net_if_dormant_off(struct net_if *iface);
    3138              : 
    3139              : /**
    3140              :  * @brief Check if the interface is dormant.
    3141              :  *
    3142              :  * @param iface Pointer to network interface
    3143              :  *
    3144              :  * @return True if interface is dormant, false otherwise.
    3145              :  */
    3146            1 : static inline bool net_if_is_dormant(struct net_if *iface)
    3147              : {
    3148              :         if (iface == NULL) {
    3149              :                 return false;
    3150              :         }
    3151              : 
    3152              :         return net_if_flag_is_set(iface, NET_IF_DORMANT);
    3153              : }
    3154              : 
    3155              : #if defined(CONFIG_NET_PKT_TIMESTAMP) && defined(CONFIG_NET_NATIVE)
    3156              : /**
    3157              :  * @typedef net_if_timestamp_callback_t
    3158              :  * @brief Define callback that is called after a network packet
    3159              :  *        has been timestamped.
    3160              :  * @param "struct net_pkt *pkt" A pointer on a struct net_pkt which has
    3161              :  *        been timestamped after being sent.
    3162              :  */
    3163              : typedef void (*net_if_timestamp_callback_t)(struct net_pkt *pkt);
    3164              : 
    3165              : /**
    3166              :  * @brief Timestamp callback handler struct.
    3167              :  *
    3168              :  * Stores the timestamp callback information. Caller must make sure that
    3169              :  * the variable pointed by this is valid during the lifetime of
    3170              :  * registration. Typically this means that the variable cannot be
    3171              :  * allocated from stack.
    3172              :  */
    3173              : struct net_if_timestamp_cb {
    3174              :         /** Node information for the slist. */
    3175              :         sys_snode_t node;
    3176              : 
    3177              :         /** Packet for which the callback is needed.
    3178              :          *  A NULL value means all packets.
    3179              :          */
    3180              :         struct net_pkt *pkt;
    3181              : 
    3182              :         /** Net interface for which the callback is needed.
    3183              :          *  A NULL value means all interfaces.
    3184              :          */
    3185              :         struct net_if *iface;
    3186              : 
    3187              :         /** Timestamp callback */
    3188              :         net_if_timestamp_callback_t cb;
    3189              : };
    3190              : 
    3191              : /**
    3192              :  * @brief Register a timestamp callback.
    3193              :  *
    3194              :  * @param handle Caller specified handler for the callback.
    3195              :  * @param pkt Net packet for which the callback is registered. NULL for all
    3196              :  *            packets.
    3197              :  * @param iface Net interface for which the callback is. NULL for all
    3198              :  *              interfaces.
    3199              :  * @param cb Callback to register.
    3200              :  */
    3201              : void net_if_register_timestamp_cb(struct net_if_timestamp_cb *handle,
    3202              :                                   struct net_pkt *pkt,
    3203              :                                   struct net_if *iface,
    3204              :                                   net_if_timestamp_callback_t cb);
    3205              : 
    3206              : /**
    3207              :  * @brief Unregister a timestamp callback.
    3208              :  *
    3209              :  * @param handle Caller specified handler for the callback.
    3210              :  */
    3211              : void net_if_unregister_timestamp_cb(struct net_if_timestamp_cb *handle);
    3212              : 
    3213              : /**
    3214              :  * @brief Call a timestamp callback function.
    3215              :  *
    3216              :  * @param pkt Network buffer.
    3217              :  */
    3218              : void net_if_call_timestamp_cb(struct net_pkt *pkt);
    3219              : 
    3220              : /*
    3221              :  * @brief Add timestamped TX buffer to be handled
    3222              :  *
    3223              :  * @param pkt Timestamped buffer
    3224              :  */
    3225              : void net_if_add_tx_timestamp(struct net_pkt *pkt);
    3226              : #endif /* CONFIG_NET_PKT_TIMESTAMP */
    3227              : 
    3228              : /**
    3229              :  * @brief Set network interface into promiscuous mode
    3230              :  *
    3231              :  * @details Note that not all network technologies will support this.
    3232              :  *
    3233              :  * @param iface Pointer to network interface
    3234              :  *
    3235              :  * @return 0 on success, <0 if error
    3236              :  */
    3237              : #if defined(CONFIG_NET_PROMISCUOUS_MODE)
    3238              : int net_if_set_promisc(struct net_if *iface);
    3239              : #else
    3240            1 : static inline int net_if_set_promisc(struct net_if *iface)
    3241              : {
    3242              :         ARG_UNUSED(iface);
    3243              : 
    3244              :         return -ENOTSUP;
    3245              : }
    3246              : #endif
    3247              : 
    3248              : /**
    3249              :  * @brief Set network interface into normal mode
    3250              :  *
    3251              :  * @param iface Pointer to network interface
    3252              :  */
    3253              : #if defined(CONFIG_NET_PROMISCUOUS_MODE)
    3254              : void net_if_unset_promisc(struct net_if *iface);
    3255              : #else
    3256            1 : static inline void net_if_unset_promisc(struct net_if *iface)
    3257              : {
    3258              :         ARG_UNUSED(iface);
    3259              : }
    3260              : #endif
    3261              : 
    3262              : /**
    3263              :  * @brief Check if promiscuous mode is set or not.
    3264              :  *
    3265              :  * @param iface Pointer to network interface
    3266              :  *
    3267              :  * @return True if interface is in promisc mode,
    3268              :  *         False if interface is not in promiscuous mode.
    3269              :  */
    3270              : #if defined(CONFIG_NET_PROMISCUOUS_MODE)
    3271              : bool net_if_is_promisc(struct net_if *iface);
    3272              : #else
    3273            1 : static inline bool net_if_is_promisc(struct net_if *iface)
    3274              : {
    3275              :         ARG_UNUSED(iface);
    3276              : 
    3277              :         return false;
    3278              : }
    3279              : #endif
    3280              : 
    3281              : /**
    3282              :  * @brief Check if there are any pending TX network data for a given network
    3283              :  *        interface.
    3284              :  *
    3285              :  * @param iface Pointer to network interface
    3286              :  *
    3287              :  * @return True if there are pending TX network packets for this network
    3288              :  *         interface, False otherwise.
    3289              :  */
    3290            1 : static inline bool net_if_are_pending_tx_packets(struct net_if *iface)
    3291              : {
    3292              : #if defined(CONFIG_NET_POWER_MANAGEMENT)
    3293              :         return !!iface->tx_pending;
    3294              : #else
    3295              :         ARG_UNUSED(iface);
    3296              : 
    3297              :         return false;
    3298              : #endif
    3299              : }
    3300              : 
    3301              : #ifdef CONFIG_NET_POWER_MANAGEMENT
    3302              : /**
    3303              :  * @brief Suspend a network interface from a power management perspective
    3304              :  *
    3305              :  * @param iface Pointer to network interface
    3306              :  *
    3307              :  * @return 0 on success, or -EALREADY/-EBUSY as possible errors.
    3308              :  */
    3309              : int net_if_suspend(struct net_if *iface);
    3310              : 
    3311              : /**
    3312              :  * @brief Resume a network interface from a power management perspective
    3313              :  *
    3314              :  * @param iface Pointer to network interface
    3315              :  *
    3316              :  * @return 0 on success, or -EALREADY as a possible error.
    3317              :  */
    3318              : int net_if_resume(struct net_if *iface);
    3319              : 
    3320              : /**
    3321              :  * @brief Check if the network interface is suspended or not.
    3322              :  *
    3323              :  * @param iface Pointer to network interface
    3324              :  *
    3325              :  * @return True if interface is suspended, False otherwise.
    3326              :  */
    3327              : bool net_if_is_suspended(struct net_if *iface);
    3328              : #endif /* CONFIG_NET_POWER_MANAGEMENT */
    3329              : 
    3330              : /**
    3331              :  * @brief Check if the network interface supports Wi-Fi.
    3332              :  *
    3333              :  * @param iface Pointer to network interface
    3334              :  *
    3335              :  * @return True if interface supports Wi-Fi, False otherwise.
    3336              :  */
    3337            1 : bool net_if_is_wifi(struct net_if *iface);
    3338              : 
    3339              : /**
    3340              :  * @brief Get first Wi-Fi network interface.
    3341              :  *
    3342              :  * @return Pointer to network interface, NULL if not found.
    3343              :  */
    3344            1 : struct net_if *net_if_get_first_wifi(void);
    3345              : 
    3346              : /**
    3347              :  * @brief Get Wi-Fi network station interface.
    3348              :  *
    3349              :  * @return Pointer to network interface, NULL if not found.
    3350              :  */
    3351            1 : struct net_if *net_if_get_wifi_sta(void);
    3352              : 
    3353              : /**
    3354              :  * @brief Get first Wi-Fi network Soft-AP interface.
    3355              :  *
    3356              :  * @return Pointer to network interface, NULL if not found.
    3357              :  */
    3358            1 : struct net_if *net_if_get_wifi_sap(void);
    3359              : 
    3360              : /**
    3361              :  * @brief Get network interface name.
    3362              :  *
    3363              :  * @details If interface name support is not enabled, empty string is returned.
    3364              :  *
    3365              :  * @param iface Pointer to network interface
    3366              :  * @param buf User supplied buffer
    3367              :  * @param len Length of the user supplied buffer
    3368              :  *
    3369              :  * @return Length of the interface name copied to buf,
    3370              :  *         -EINVAL if invalid parameters,
    3371              :  *         -ERANGE if name cannot be copied to the user supplied buffer,
    3372              :  *         -ENOTSUP if interface name support is disabled,
    3373              :  */
    3374            1 : int net_if_get_name(struct net_if *iface, char *buf, int len);
    3375              : 
    3376              : /**
    3377              :  * @brief Set network interface name.
    3378              :  *
    3379              :  * @details Normally this function is not needed to call as the system
    3380              :  *          will automatically assign a name to the network interface.
    3381              :  *
    3382              :  * @param iface Pointer to network interface
    3383              :  * @param buf User supplied name
    3384              :  *
    3385              :  * @return 0 name is set correctly
    3386              :  *         -ENOTSUP interface name support is disabled
    3387              :  *         -EINVAL if invalid parameters are given,
    3388              :  *         -ENAMETOOLONG if name is too long
    3389              :  */
    3390            1 : int net_if_set_name(struct net_if *iface, const char *buf);
    3391              : 
    3392              : /**
    3393              :  * @brief Get interface index according to its name
    3394              :  *
    3395              :  * @param name Name of the network interface
    3396              :  *
    3397              :  * @return Interface index
    3398              :  */
    3399            1 : int net_if_get_by_name(const char *name);
    3400              : 
    3401              : /** @cond INTERNAL_HIDDEN */
    3402              : struct net_if_api {
    3403              :         void (*init)(struct net_if *iface);
    3404              : };
    3405              : 
    3406              : #define NET_IF_DHCPV4_INIT                                              \
    3407              :         IF_ENABLED(UTIL_AND(IS_ENABLED(CONFIG_NET_DHCPV4),              \
    3408              :                             IS_ENABLED(CONFIG_NET_NATIVE_IPV4)),        \
    3409              :                    (.dhcpv4.state = NET_DHCPV4_DISABLED,))
    3410              : 
    3411              : #define NET_IF_DHCPV6_INIT                                              \
    3412              :         IF_ENABLED(UTIL_AND(IS_ENABLED(CONFIG_NET_DHCPV6),              \
    3413              :                             IS_ENABLED(CONFIG_NET_NATIVE_IPV6)),        \
    3414              :                    (.dhcpv6.state = NET_DHCPV6_DISABLED,))
    3415              : 
    3416              : #define NET_IF_CONFIG_INIT                              \
    3417              :         .config = {                                     \
    3418              :                 IF_ENABLED(CONFIG_NET_IP, (.ip = {},))  \
    3419              :                 NET_IF_DHCPV4_INIT                      \
    3420              :                 NET_IF_DHCPV6_INIT                      \
    3421              :         }
    3422              : 
    3423              : #define NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, sfx)                  \
    3424              :         net_stats_##dev_id##_##sfx##_collector
    3425              : #define NET_PROMETHEUS_INIT(dev_id, sfx)                                \
    3426              :         IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS,                \
    3427              :                    (.collector = &NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, sfx),))
    3428              : 
    3429              : #define NET_IF_GET_NAME(dev_id, sfx) __net_if_##dev_id##_##sfx
    3430              : #define NET_IF_DEV_GET_NAME(dev_id, sfx) __net_if_dev_##dev_id##_##sfx
    3431              : 
    3432              : #define NET_IF_GET(dev_id, sfx)                                         \
    3433              :         ((struct net_if *)&NET_IF_GET_NAME(dev_id, sfx))
    3434              : 
    3435              : #if defined(CONFIG_NET_STATISTICS_VIA_PROMETHEUS)
    3436              : extern int net_stats_prometheus_scrape(struct prometheus_collector *collector,
    3437              :                                        struct prometheus_metric *metric,
    3438              :                                        void *user_data);
    3439              : #endif /* CONFIG_NET_STATISTICS_VIA_PROMETHEUS */
    3440              : 
    3441              : #define NET_IF_INIT(dev_id, sfx, _l2, _mtu, _num_configs)               \
    3442              :         static STRUCT_SECTION_ITERABLE(net_if_dev,                      \
    3443              :                                 NET_IF_DEV_GET_NAME(dev_id, sfx)) = {   \
    3444              :                 .dev = &(DEVICE_NAME_GET(dev_id)),                  \
    3445              :                 .l2 = &(NET_L2_GET_NAME(_l2)),                              \
    3446              :                 .l2_data = &(NET_L2_GET_DATA(dev_id, sfx)),         \
    3447              :                 .mtu = _mtu,                                            \
    3448              :                 .flags = {BIT(NET_IF_LOWER_UP)},                        \
    3449              :         };                                                              \
    3450              :         static Z_DECL_ALIGN(struct net_if)                              \
    3451              :                        NET_IF_GET_NAME(dev_id, sfx)[_num_configs]       \
    3452              :                        __used __noasan __in_section(_net_if, static,    \
    3453              :                                            dev_id) = {                  \
    3454              :                 [0 ... (_num_configs - 1)] = {                          \
    3455              :                         .if_dev = &(NET_IF_DEV_GET_NAME(dev_id, sfx)),      \
    3456              :                         NET_IF_CONFIG_INIT                              \
    3457              :                 }                                                       \
    3458              :         };                                                              \
    3459              :         IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS,                \
    3460              :                    (static PROMETHEUS_COLLECTOR_DEFINE(                 \
    3461              :                            NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id,    \
    3462              :                                                              sfx),      \
    3463              :                            net_stats_prometheus_scrape,                 \
    3464              :                            NET_IF_GET(dev_id, sfx));                    \
    3465              :                     NET_STATS_PROMETHEUS(NET_IF_GET(dev_id, sfx),       \
    3466              :                                          dev_id, sfx);))
    3467              : 
    3468              : #define NET_IF_OFFLOAD_INIT(dev_id, sfx, _mtu)                          \
    3469              :         static STRUCT_SECTION_ITERABLE(net_if_dev,                      \
    3470              :                                 NET_IF_DEV_GET_NAME(dev_id, sfx)) = {   \
    3471              :                 .dev = &(DEVICE_NAME_GET(dev_id)),                  \
    3472              :                 .mtu = _mtu,                                            \
    3473              :                 .l2 = &(NET_L2_GET_NAME(OFFLOADED_NETDEV)),         \
    3474              :                 .flags = {BIT(NET_IF_LOWER_UP)},                        \
    3475              :         };                                                              \
    3476              :         static Z_DECL_ALIGN(struct net_if)                              \
    3477              :                 NET_IF_GET_NAME(dev_id, sfx)[NET_IF_MAX_CONFIGS]        \
    3478              :                        __used __noasan __in_section(_net_if, static,    \
    3479              :                                            dev_id) = {                  \
    3480              :                 [0 ... (NET_IF_MAX_CONFIGS - 1)] = {                    \
    3481              :                         .if_dev = &(NET_IF_DEV_GET_NAME(dev_id, sfx)),      \
    3482              :                         NET_IF_CONFIG_INIT                              \
    3483              :                 }                                                       \
    3484              :         };                                                              \
    3485              :         IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS,                \
    3486              :                    (static PROMETHEUS_COLLECTOR_DEFINE(                 \
    3487              :                            NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id,    \
    3488              :                                                              sfx),      \
    3489              :                            net_stats_prometheus_scrape,                 \
    3490              :                            NET_IF_GET(dev_id, sfx));                    \
    3491              :                     NET_STATS_PROMETHEUS(NET_IF_GET(dev_id, sfx),       \
    3492              :                                          dev_id, sfx);))
    3493              : 
    3494              : 
    3495              : /** @endcond */
    3496              : 
    3497              : /* Network device initialization macros */
    3498              : 
    3499              : #define Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance,     \
    3500              :                                    init_fn, pm, data, config, prio,     \
    3501              :                                    api, l2, l2_ctx_type, mtu)           \
    3502              :         Z_DEVICE_STATE_DEFINE(dev_id);                                  \
    3503              :         Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, NULL,           \
    3504              :                         Z_DEVICE_DT_FLAGS(node_id), pm, data,           \
    3505              :                         config, POST_KERNEL, prio, api,                 \
    3506              :                         &Z_DEVICE_STATE_NAME(dev_id));                      \
    3507              :         NET_L2_DATA_INIT(dev_id, instance, l2_ctx_type);                \
    3508              :         NET_IF_INIT(dev_id, instance, l2, mtu, NET_IF_MAX_CONFIGS)
    3509              : 
    3510              : #define Z_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data,     \
    3511              :                           config, prio, api, l2, l2_ctx_type, mtu)      \
    3512              :         Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, init_fn,   \
    3513              :                                    pm, data, config, prio, api, l2,     \
    3514              :                                    l2_ctx_type, mtu)
    3515              : 
    3516              : /**
    3517              :  * @brief Create a network interface and bind it to network device.
    3518              :  *
    3519              :  * @param dev_id Network device id.
    3520              :  * @param name The name this instance of the driver exposes to
    3521              :  * the system.
    3522              :  * @param init_fn Address to the init function of the driver.
    3523              :  * @param pm Reference to struct pm_device associated with the device.
    3524              :  * (optional).
    3525              :  * @param data Pointer to the device's private data.
    3526              :  * @param config The address to the structure containing the
    3527              :  * configuration information for this instance of the driver.
    3528              :  * @param prio The initialization level at which configuration occurs.
    3529              :  * @param api Provides an initial pointer to the API function struct
    3530              :  * used by the driver. Can be NULL.
    3531              :  * @param l2 Network L2 layer for this network interface.
    3532              :  * @param l2_ctx_type Type of L2 context data.
    3533              :  * @param mtu Maximum transfer unit in bytes for this network interface.
    3534              :  */
    3535              : #define NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, prio,  \
    3536            1 :                         api, l2, l2_ctx_type, mtu)                      \
    3537              :         Z_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, pm,   \
    3538              :                           data, config, prio, api, l2, l2_ctx_type, mtu)
    3539              : 
    3540              : /**
    3541              :  * @brief Like NET_DEVICE_INIT but taking metadata from a devicetree node.
    3542              :  * Create a network interface and bind it to network device.
    3543              :  *
    3544              :  * @param node_id The devicetree node identifier.
    3545              :  * @param init_fn Address to the init function of the driver.
    3546              :  * @param pm Reference to struct pm_device associated with the device.
    3547              :  * (optional).
    3548              :  * @param data Pointer to the device's private data.
    3549              :  * @param config The address to the structure containing the
    3550              :  * configuration information for this instance of the driver.
    3551              :  * @param prio The initialization level at which configuration occurs.
    3552              :  * @param api Provides an initial pointer to the API function struct
    3553              :  * used by the driver. Can be NULL.
    3554              :  * @param l2 Network L2 layer for this network interface.
    3555              :  * @param l2_ctx_type Type of L2 context data.
    3556              :  * @param mtu Maximum transfer unit in bytes for this network interface.
    3557              :  */
    3558              : #define NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data,                \
    3559            1 :                              config, prio, api, l2, l2_ctx_type, mtu)   \
    3560              :         Z_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
    3561              :                           DEVICE_DT_NAME(node_id), init_fn, pm, data,   \
    3562              :                           config, prio, api, l2, l2_ctx_type, mtu)
    3563              : 
    3564              : /**
    3565              :  * @brief Like NET_DEVICE_DT_DEFINE for an instance of a DT_DRV_COMPAT compatible
    3566              :  *
    3567              :  * @param inst instance number.  This is replaced by
    3568              :  * <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_DEFINE.
    3569              :  *
    3570              :  * @param ... other parameters as expected by NET_DEVICE_DT_DEFINE.
    3571              :  */
    3572            1 : #define NET_DEVICE_DT_INST_DEFINE(inst, ...) \
    3573              :         NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
    3574              : 
    3575              : /**
    3576              :  * @brief Create multiple network interfaces and bind them to network device.
    3577              :  * If your network device needs more than one instance of a network interface,
    3578              :  * use this macro below and provide a different instance suffix each time
    3579              :  * (0, 1, 2, ... or a, b, c ... whatever works for you)
    3580              :  *
    3581              :  * @param dev_id Network device id.
    3582              :  * @param name The name this instance of the driver exposes to
    3583              :  * the system.
    3584              :  * @param instance Instance identifier.
    3585              :  * @param init_fn Address to the init function of the driver.
    3586              :  * @param pm Reference to struct pm_device associated with the device.
    3587              :  * (optional).
    3588              :  * @param data Pointer to the device's private data.
    3589              :  * @param config The address to the structure containing the
    3590              :  * configuration information for this instance of the driver.
    3591              :  * @param prio The initialization level at which configuration occurs.
    3592              :  * @param api Provides an initial pointer to the API function struct
    3593              :  * used by the driver. Can be NULL.
    3594              :  * @param l2 Network L2 layer for this network interface.
    3595              :  * @param l2_ctx_type Type of L2 context data.
    3596              :  * @param mtu Maximum transfer unit in bytes for this network interface.
    3597              :  */
    3598              : #define NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, pm,   \
    3599              :                                  data, config, prio, api, l2,           \
    3600            1 :                                  l2_ctx_type, mtu)                      \
    3601              :         Z_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name,       \
    3602              :                                    instance, init_fn, pm, data, config, \
    3603              :                                    prio, api, l2, l2_ctx_type, mtu)
    3604              : 
    3605              : /**
    3606              :  * @brief Like NET_DEVICE_OFFLOAD_INIT but taking metadata from a devicetree.
    3607              :  * Create multiple network interfaces and bind them to network device.
    3608              :  * If your network device needs more than one instance of a network interface,
    3609              :  * use this macro below and provide a different instance suffix each time
    3610              :  * (0, 1, 2, ... or a, b, c ... whatever works for you)
    3611              :  *
    3612              :  * @param node_id The devicetree node identifier.
    3613              :  * @param instance Instance identifier.
    3614              :  * @param init_fn Address to the init function of the driver.
    3615              :  * @param pm Reference to struct pm_device associated with the device.
    3616              :  * (optional).
    3617              :  * @param data Pointer to the device's private data.
    3618              :  * @param config The address to the structure containing the
    3619              :  * configuration information for this instance of the driver.
    3620              :  * @param prio The initialization level at which configuration occurs.
    3621              :  * @param api Provides an initial pointer to the API function struct
    3622              :  * used by the driver. Can be NULL.
    3623              :  * @param l2 Network L2 layer for this network interface.
    3624              :  * @param l2_ctx_type Type of L2 context data.
    3625              :  * @param mtu Maximum transfer unit in bytes for this network interface.
    3626              :  */
    3627              : #define NET_DEVICE_DT_DEFINE_INSTANCE(node_id, instance, init_fn, pm,   \
    3628              :                                       data, config, prio, api, l2,      \
    3629            1 :                                       l2_ctx_type, mtu)                 \
    3630              :         Z_NET_DEVICE_INIT_INSTANCE(node_id,                             \
    3631              :                                    Z_DEVICE_DT_DEV_ID(node_id),         \
    3632              :                                    DEVICE_DT_NAME(node_id), instance,   \
    3633              :                                    init_fn, pm, data, config, prio,     \
    3634              :                                    api, l2, l2_ctx_type, mtu)
    3635              : 
    3636              : /**
    3637              :  * @brief Like NET_DEVICE_DT_DEFINE_INSTANCE for an instance of a DT_DRV_COMPAT
    3638              :  * compatible
    3639              :  *
    3640              :  * @param inst instance number.  This is replaced by
    3641              :  * <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_DEFINE_INSTANCE.
    3642              :  *
    3643              :  * @param ... other parameters as expected by NET_DEVICE_DT_DEFINE_INSTANCE.
    3644              :  */
    3645            1 : #define NET_DEVICE_DT_INST_DEFINE_INSTANCE(inst, ...) \
    3646              :         NET_DEVICE_DT_DEFINE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
    3647              : 
    3648              : #define Z_NET_DEVICE_OFFLOAD_INIT(node_id, dev_id, name, init_fn, pm,   \
    3649              :                                   data, config, prio, api, mtu)         \
    3650              :         Z_DEVICE_STATE_DEFINE(dev_id);                                  \
    3651              :         Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, NULL,           \
    3652              :                         Z_DEVICE_DT_FLAGS(node_id), pm, data,           \
    3653              :                         config, POST_KERNEL, prio, api,                 \
    3654              :                         &Z_DEVICE_STATE_NAME(dev_id));                      \
    3655              :         NET_IF_OFFLOAD_INIT(dev_id, 0, mtu)
    3656              : 
    3657              : /**
    3658              :  * @brief Create a offloaded network interface and bind it to network device.
    3659              :  * The offloaded network interface is implemented by a device vendor HAL or
    3660              :  * similar.
    3661              :  *
    3662              :  * @param dev_id Network device id.
    3663              :  * @param name The name this instance of the driver exposes to
    3664              :  * the system.
    3665              :  * @param init_fn Address to the init function of the driver.
    3666              :  * @param pm Reference to struct pm_device associated with the device.
    3667              :  * (optional).
    3668              :  * @param data Pointer to the device's private data.
    3669              :  * @param config The address to the structure containing the
    3670              :  * configuration information for this instance of the driver.
    3671              :  * @param prio The initialization level at which configuration occurs.
    3672              :  * @param api Provides an initial pointer to the API function struct
    3673              :  * used by the driver. Can be NULL.
    3674              :  * @param mtu Maximum transfer unit in bytes for this network interface.
    3675              :  */
    3676              : #define NET_DEVICE_OFFLOAD_INIT(dev_id, name, init_fn, pm, data,        \
    3677            1 :                                 config, prio, api, mtu)                 \
    3678              :         Z_NET_DEVICE_OFFLOAD_INIT(DT_INVALID_NODE, dev_id, name,        \
    3679              :                                   init_fn, pm, data, config, prio, api, \
    3680              :                                   mtu)
    3681              : 
    3682              : /**
    3683              :  * @brief Like NET_DEVICE_OFFLOAD_INIT but taking metadata from a devicetree
    3684              :  * node. Create a offloaded network interface and bind it to network device.
    3685              :  * The offloaded network interface is implemented by a device vendor HAL or
    3686              :  * similar.
    3687              :  *
    3688              :  * @param node_id The devicetree node identifier.
    3689              :  * @param init_fn Address to the init function of the driver.
    3690              :  * @param pm Reference to struct pm_device associated with the device.
    3691              :  * (optional).
    3692              :  * @param data Pointer to the device's private data.
    3693              :  * @param config The address to the structure containing the
    3694              :  * configuration information for this instance of the driver.
    3695              :  * @param prio The initialization level at which configuration occurs.
    3696              :  * @param api Provides an initial pointer to the API function struct
    3697              :  * used by the driver. Can be NULL.
    3698              :  * @param mtu Maximum transfer unit in bytes for this network interface.
    3699              :  */
    3700              : #define NET_DEVICE_DT_OFFLOAD_DEFINE(node_id, init_fn, pm, data,        \
    3701            1 :                                      config, prio, api, mtu)            \
    3702              :         Z_NET_DEVICE_OFFLOAD_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
    3703              :                                   DEVICE_DT_NAME(node_id), init_fn, pm, \
    3704              :                                   data, config, prio, api, mtu)
    3705              : 
    3706              : /**
    3707              :  * @brief Like NET_DEVICE_DT_OFFLOAD_DEFINE for an instance of a DT_DRV_COMPAT
    3708              :  * compatible
    3709              :  *
    3710              :  * @param inst instance number.  This is replaced by
    3711              :  * <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_OFFLOAD_DEFINE.
    3712              :  *
    3713              :  * @param ... other parameters as expected by NET_DEVICE_DT_OFFLOAD_DEFINE.
    3714              :  */
    3715            1 : #define NET_DEVICE_DT_INST_OFFLOAD_DEFINE(inst, ...) \
    3716              :         NET_DEVICE_DT_OFFLOAD_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
    3717              : 
    3718              : /**
    3719              :  * @brief Count the number of network interfaces.
    3720              :  *
    3721              :  * @param[out] _dst Pointer to location where result is written.
    3722              :  */
    3723            1 : #define NET_IFACE_COUNT(_dst) \
    3724              :                 do {                                                    \
    3725              :                         extern struct net_if _net_if_list_start[];      \
    3726              :                         extern struct net_if _net_if_list_end[];        \
    3727              :                         *(_dst) = ((uintptr_t)_net_if_list_end -        \
    3728              :                                    (uintptr_t)_net_if_list_start) /     \
    3729              :                                 sizeof(struct net_if);                  \
    3730              :                 } while (0)
    3731              : 
    3732              : #ifdef __cplusplus
    3733              : }
    3734              : #endif
    3735              : 
    3736              : #include <zephyr/syscalls/net_if.h>
    3737              : 
    3738              : /**
    3739              :  * @}
    3740              :  */
    3741              : 
    3742              : #endif /* ZEPHYR_INCLUDE_NET_NET_IF_H_ */
        

Generated by: LCOV version 2.0-1