Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_if.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11
12#ifndef ZEPHYR_INCLUDE_NET_NET_IF_H_
13#define ZEPHYR_INCLUDE_NET_NET_IF_H_
14
23
24#include <zephyr/device.h>
25#include <zephyr/sys/slist.h>
27#include <zephyr/net/net_core.h>
28#include <zephyr/net/hostname.h>
30#include <zephyr/net/net_ip.h>
31#include <zephyr/net/net_l2.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)
43#endif
44
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
58 struct net_addr address;
59
64
65#if defined(CONFIG_NET_NATIVE_IPV6)
66 struct net_timeout lifetime;
67#endif
68
71
74
75#if defined(CONFIG_NET_NATIVE_IPV6)
76#if defined(CONFIG_NET_IPV6_PE)
80 uint32_t addr_create_time;
81
84 uint32_t addr_preferred_lifetime;
85
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 {
98 sys_snode_t dad_node;
99
101 sys_snode_t dad_need_node;
102
104 uint32_t dad_start;
105
107 uint8_t dad_count;
108 };
109#endif /* CONFIG_NET_IPV6_DAD */
110#if defined(CONFIG_NET_IPV4_ACD)
111 struct {
113 sys_snode_t acd_node;
114
116 sys_snode_t acd_need_node;
117
119 k_timepoint_t acd_timeout;
120
122 uint8_t acd_count;
123
125 uint8_t acd_state;
126 };
127#endif /* CONFIG_NET_IPV4_ACD */
128 uint8_t _dummy;
129 };
130
131#if defined(CONFIG_NET_IPV6_DAD) || defined(CONFIG_NET_IPV4_ACD)
133 uint8_t ifindex;
134#endif
135
138
141
144
149
152
153 uint8_t _unused : 3;
154};
155
163 struct net_addr address;
164
169
172
173#if defined(CONFIG_NET_IPV4_IGMPV3)
175 struct net_addr sources[CONFIG_NET_IF_MCAST_IPV4_SOURCE_COUNT];
176
178 uint16_t sources_len;
179
181 uint8_t record_type;
182#endif
183
186
189
190 uint8_t _unused : 6;
191};
192
201
204
206 struct net_if *iface;
207
210
213
216
217 uint8_t _unused : 6;
218};
219
228
230 struct net_addr address;
231
233 struct net_if *iface;
234
237
240
243
246
249
250 uint8_t _unused : 5;
251};
252
308
319
320#if defined(CONFIG_NET_OFFLOAD)
321struct net_offload;
322#endif /* CONFIG_NET_OFFLOAD */
323
325#if defined(CONFIG_NET_IPV6)
326#define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT
327#define NET_IF_MAX_IPV6_MADDR CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT
328#define NET_IF_MAX_IPV6_PREFIX CONFIG_NET_IF_IPV6_PREFIX_COUNT
329#else
330#define NET_IF_MAX_IPV6_ADDR 0
331#define NET_IF_MAX_IPV6_MADDR 0
332#define NET_IF_MAX_IPV6_PREFIX 0
333#endif
334/* @endcond */
335
339 struct net_if_addr unicast[NET_IF_MAX_IPV6_ADDR];
340
342 struct net_if_mcast_addr mcast[NET_IF_MAX_IPV6_MADDR];
343
345 struct net_if_ipv6_prefix prefix[NET_IF_MAX_IPV6_PREFIX];
346
349
352
355
356#if defined(CONFIG_NET_IPV6_IID_STABLE)
358 struct net_if_addr *iid;
359
363 uint32_t network_counter;
364#endif /* CONFIG_NET_IPV6_IID_STABLE */
365
366#if defined(CONFIG_NET_IPV6_PE)
371 uint32_t desync_factor;
372#endif /* CONFIG_NET_IPV6_PE */
373
374#if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
376 sys_snode_t rs_node;
377
378 /* RS start time */
379 uint32_t rs_start;
380
382 uint8_t rs_count;
383#endif
384
387
390};
391
392#if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6)
394struct net_if_dhcpv6 {
396 sys_snode_t node;
397
399 struct net_dhcpv6_duid_storage clientid;
400
402 struct net_dhcpv6_duid_storage serverid;
403
405 enum net_dhcpv6_state state;
406
408 struct net_dhcpv6_params params;
409
411 uint64_t timeout;
412
414 uint64_t exchange_start;
415
417 uint64_t t1;
418
420 uint64_t t2;
421
425 uint64_t expire;
426
428 uint32_t addr_iaid;
429
431 uint32_t prefix_iaid;
432
434 uint32_t retransmit_timeout;
435
437 int16_t server_preference;
438
440 uint8_t retransmissions;
441
443 uint8_t tid[DHCPV6_TID_SIZE];
444
446 uint8_t prefix_len;
447
449 struct net_in6_addr prefix;
450
452 struct net_in6_addr addr;
453};
454#endif /* defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) */
455
457#if defined(CONFIG_NET_IPV4)
458#define NET_IF_MAX_IPV4_ADDR CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT
459#define NET_IF_MAX_IPV4_MADDR CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT
460#else
461#define NET_IF_MAX_IPV4_ADDR 0
462#define NET_IF_MAX_IPV4_MADDR 0
463#endif
465
477
481 struct net_if_addr_ipv4 unicast[NET_IF_MAX_IPV4_ADDR];
482
484 struct net_if_mcast_addr mcast[NET_IF_MAX_IPV4_MADDR];
485
488
491
494
495#if defined(CONFIG_NET_IPV4_ACD)
497 uint8_t conflict_cnt;
498#endif
499};
500
501#if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
502struct net_if_dhcpv4 {
504 sys_snode_t node;
505
507 int64_t timer_start;
508
510 uint32_t request_time;
511
512 uint32_t xid;
513
515 uint32_t lease_time;
516
518 uint32_t renewal_time;
519
521 uint32_t rebinding_time;
522
524 struct net_in_addr server_id;
525
527 struct net_in_addr requested_ip;
528
530 struct net_in_addr netmask;
531
536 enum net_dhcpv4_state state;
537
539 uint8_t attempts;
540
542 struct net_in_addr request_server_addr;
543
545 struct net_in_addr response_src_addr;
546
547#ifdef CONFIG_NET_DHCPV4_OPTION_NTP_SERVER
549 struct net_in_addr ntp_addr;
550#endif
551};
552#endif /* CONFIG_NET_DHCPV4 */
553
554#if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
555struct net_if_ipv4_autoconf {
557 struct net_if *iface;
558
560 struct net_in_addr requested_ip;
561
565};
566#endif /* CONFIG_NET_IPV4_AUTO */
567
571struct net_if_ip {
572#if defined(CONFIG_NET_IPV6)
573 struct net_if_ipv6 *ipv6;
574#endif /* CONFIG_NET_IPV6 */
575
576#if defined(CONFIG_NET_IPV4)
577 struct net_if_ipv4 *ipv4;
578#endif /* CONFIG_NET_IPV4 */
579};
580
585#if defined(CONFIG_NET_IP)
587 struct net_if_ip ip;
588#endif
589
590#if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
591 struct net_if_dhcpv4 dhcpv4;
592#endif /* CONFIG_NET_DHCPV4 */
593
594#if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6)
595 struct net_if_dhcpv6 dhcpv6;
596#endif /* CONFIG_NET_DHCPV6 */
597
598#if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
599 struct net_if_ipv4_autoconf ipv4auto;
600#endif /* CONFIG_NET_IPV4_AUTO */
601
602#if defined(CONFIG_NET_L2_VIRTUAL)
607 sys_slist_t virtual_interfaces;
608#endif /* CONFIG_NET_L2_VIRTUAL */
609
610#if defined(CONFIG_NET_INTERFACE_NAME)
615 char name[CONFIG_NET_INTERFACE_NAME_LEN + 1];
616#endif
617};
618
630 struct k_fifo fifo;
631
632#if NET_TC_COUNT > 1 || defined(CONFIG_NET_TC_TX_SKIP_FOR_HIGH_PRIO) \
633 || defined(CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO)
635 struct k_sem fifo_slot;
636#endif
637
640
643};
644
651typedef int (*net_socket_create_t)(int, int, int);
652
674 const struct device *dev;
675
677 const struct net_l2 * const l2;
678
680 void *l2_data;
681
683 ATOMIC_DEFINE(flags, NET_IF_NUM_FLAGS);
684
686 struct net_linkaddr link_addr;
687
688#if defined(CONFIG_NET_OFFLOAD)
694 struct net_offload *offload;
695#endif /* CONFIG_NET_OFFLOAD */
696
698 uint16_t mtu;
699
700#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
704 net_socket_create_t socket_offload;
705#endif /* CONFIG_NET_SOCKETS_OFFLOAD */
706
708 enum net_if_oper_state oper_state;
709
719 int64_t oper_state_change_time;
723};
724
733struct net_if {
738 struct net_if_dev *if_dev;
739
740#if defined(CONFIG_NET_STATISTICS_PER_INTERFACE)
742 struct net_stats stats;
743
745 IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS,
746 (struct prometheus_collector *collector);)
747#endif /* CONFIG_NET_STATISTICS_PER_INTERFACE */
748
750 struct net_if_config config;
751
752#if defined(CONFIG_NET_POWER_MANAGEMENT)
757 int tx_pending;
758#endif
759
761 struct k_mutex lock;
762
764 struct k_mutex tx_lock;
765
770 uint8_t pe_enabled : 1;
771
775 uint8_t pe_prefer_public : 1;
776
778 uint8_t _unused : 6;
782};
783
785
786static inline void net_if_lock(struct net_if *iface)
787{
788 NET_ASSERT(iface);
789
790 (void)k_mutex_lock(&iface->lock, K_FOREVER);
791}
792
793static inline void net_if_unlock(struct net_if *iface)
794{
795 NET_ASSERT(iface);
796
797 k_mutex_unlock(&iface->lock);
798}
799
800static inline bool net_if_flag_is_set(struct net_if *iface,
801 enum net_if_flag value);
802
803static inline void net_if_tx_lock(struct net_if *iface)
804{
805 NET_ASSERT(iface);
806
808 return;
809 }
810
811 (void)k_mutex_lock(&iface->tx_lock, K_FOREVER);
812}
813
814static inline void net_if_tx_unlock(struct net_if *iface)
815{
816 NET_ASSERT(iface);
817
819 return;
820 }
821
822 k_mutex_unlock(&iface->tx_lock);
823}
824
826
833static inline void net_if_flag_set(struct net_if *iface,
834 enum net_if_flag value)
835{
836 if (iface == NULL) {
837 return;
838 }
839
840 NET_ASSERT(iface->if_dev != NULL);
841
842 atomic_set_bit(iface->if_dev->flags, value);
843}
844
853static inline bool net_if_flag_test_and_set(struct net_if *iface,
854 enum net_if_flag value)
855{
856 if (iface == NULL) {
857 return false;
858 }
859
860 NET_ASSERT(iface->if_dev != NULL);
861
862 return atomic_test_and_set_bit(iface->if_dev->flags, value);
863}
864
871static inline void net_if_flag_clear(struct net_if *iface,
872 enum net_if_flag value)
873{
874 if (iface == NULL) {
875 return;
876 }
877
878 NET_ASSERT(iface->if_dev != NULL);
879
880 atomic_clear_bit(iface->if_dev->flags, value);
881}
882
891static inline bool net_if_flag_test_and_clear(struct net_if *iface,
892 enum net_if_flag value)
893{
894 if (iface == NULL) {
895 return false;
896 }
897
898 NET_ASSERT(iface->if_dev != NULL);
899
900 return atomic_test_and_clear_bit(iface->if_dev->flags, value);
901}
902
911static inline bool net_if_flag_is_set(struct net_if *iface,
912 enum net_if_flag value)
913{
914 if (iface == NULL) {
915 return false;
916 }
917
918 NET_ASSERT(iface->if_dev != NULL);
919
920 return atomic_test_bit(iface->if_dev->flags, value);
921}
922
932 struct net_if *iface, enum net_if_oper_state oper_state)
933{
934 if (iface == NULL) {
935 return NET_IF_OPER_UNKNOWN;
936 }
937
938 NET_ASSERT(iface->if_dev != NULL);
939
940 if (oper_state <= NET_IF_OPER_UP) {
941 iface->if_dev->oper_state = oper_state;
942 }
943
944 net_if_lock(iface);
945
946 iface->if_dev->oper_state_change_time = k_uptime_get();
947
948 net_if_unlock(iface);
949
950 return iface->if_dev->oper_state;
951}
952
960static inline enum net_if_oper_state net_if_oper_state(struct net_if *iface)
961{
962 if (iface == NULL) {
963 return NET_IF_OPER_UNKNOWN;
964 }
965
966 NET_ASSERT(iface->if_dev != NULL);
967
968 return iface->if_dev->oper_state;
969}
970
983static inline int net_if_oper_state_change_time(struct net_if *iface,
984 int64_t *change_time)
985{
986 if (iface == NULL || change_time == NULL) {
987 return -EINVAL;
988 }
989
990 NET_ASSERT(iface->if_dev != NULL);
991
992 net_if_lock(iface);
993
994 *change_time = iface->if_dev->oper_state_change_time;
995
996 net_if_unlock(iface);
997
998 return 0;
999}
1000
1011 struct net_pkt *pkt, k_timeout_t timeout);
1012
1022static inline enum net_verdict net_if_send_data(struct net_if *iface,
1023 struct net_pkt *pkt)
1024{
1026
1027 return net_if_try_send_data(iface, pkt, timeout);
1028}
1029
1037static inline const struct net_l2 *net_if_l2(struct net_if *iface)
1038{
1039 if (iface == NULL) {
1040 return NULL;
1041 }
1042
1043 NET_ASSERT(iface->if_dev != NULL);
1044
1045 return iface->if_dev->l2;
1046}
1047
1056enum net_verdict net_if_recv_data(struct net_if *iface, struct net_pkt *pkt);
1057
1065static inline void *net_if_l2_data(struct net_if *iface)
1066{
1067 if (iface == NULL) {
1068 return NULL;
1069 }
1070
1071 NET_ASSERT(iface->if_dev != NULL);
1072
1073 return iface->if_dev->l2_data;
1074}
1075
1083static inline const struct device *net_if_get_device(struct net_if *iface)
1084{
1085 if (iface == NULL) {
1086 return NULL;
1087 }
1088
1089 NET_ASSERT(iface->if_dev != NULL);
1090
1091 return iface->if_dev->dev;
1092}
1093
1101void net_if_try_queue_tx(struct net_if *iface, struct net_pkt *pkt, k_timeout_t timeout);
1102
1110static inline void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
1111{
1113
1114 net_if_try_queue_tx(iface, pkt, timeout);
1115}
1116
1124static inline bool net_if_is_ip_offloaded(struct net_if *iface)
1125{
1126#if defined(CONFIG_NET_OFFLOAD)
1127 __ASSERT_NO_MSG(iface == NULL || iface->if_dev != NULL);
1128 return (iface != NULL && iface->if_dev->offload != NULL);
1129#else
1130 ARG_UNUSED(iface);
1131
1132 return false;
1133#endif
1134}
1135
1143bool net_if_is_offloaded(struct net_if *iface);
1144
1152static inline struct net_offload *net_if_offload(struct net_if *iface)
1153{
1154#if defined(CONFIG_NET_OFFLOAD)
1155 if (iface == NULL) {
1156 return NULL;
1157 }
1158
1159 NET_ASSERT(iface->if_dev != NULL);
1160
1161 return iface->if_dev->offload;
1162#else
1163 ARG_UNUSED(iface);
1164
1165 return NULL;
1166#endif
1167}
1168
1175static inline void net_if_offload_set(struct net_if *iface, struct net_offload *offload)
1176{
1177#if defined(CONFIG_NET_OFFLOAD)
1178 if (iface == NULL) {
1179 return;
1180 }
1181
1182 NET_ASSERT(iface->if_dev != NULL);
1183
1184 iface->if_dev->offload = offload;
1185#else
1186 ARG_UNUSED(iface);
1187 ARG_UNUSED(offload);
1188#endif
1189}
1190
1198static inline bool net_if_is_socket_offloaded(struct net_if *iface)
1199{
1200#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
1201 if (iface == NULL) {
1202 return false;
1203 }
1204
1205 NET_ASSERT(iface->if_dev != NULL);
1206
1207 return (iface->if_dev->socket_offload != NULL);
1208#else
1209 ARG_UNUSED(iface);
1210
1211 return false;
1212#endif
1213}
1214
1221static inline void net_if_socket_offload_set(
1222 struct net_if *iface, net_socket_create_t socket_offload)
1223{
1224#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
1225 if (iface == NULL) {
1226 return;
1227 }
1228
1229 NET_ASSERT(iface->if_dev != NULL);
1230
1231 iface->if_dev->socket_offload = socket_offload;
1232#else
1233 ARG_UNUSED(iface);
1234 ARG_UNUSED(socket_offload);
1235#endif
1236}
1237
1246{
1247#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
1248 if (iface == NULL) {
1249 return NULL;
1250 }
1251
1252 NET_ASSERT(iface->if_dev != NULL);
1253
1254 return iface->if_dev->socket_offload;
1255#else
1256 ARG_UNUSED(iface);
1257
1258 return NULL;
1259#endif
1260}
1261
1269static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface)
1270{
1271 if (iface == NULL) {
1272 return NULL;
1273 }
1274
1275 NET_ASSERT(iface->if_dev != NULL);
1276
1277 return &iface->if_dev->link_addr;
1278}
1279
1287static inline struct net_if_config *net_if_get_config(struct net_if *iface)
1288{
1289 if (iface == NULL) {
1290 return NULL;
1291 }
1292
1293 return &iface->config;
1294}
1295
1301#if defined(CONFIG_NET_IPV6_DAD) && defined(CONFIG_NET_NATIVE_IPV6)
1302void net_if_start_dad(struct net_if *iface);
1303#else
1304static inline void net_if_start_dad(struct net_if *iface)
1305{
1306 ARG_UNUSED(iface);
1307}
1308#endif
1309
1315void net_if_start_rs(struct net_if *iface);
1316
1317
1323#if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
1324void net_if_stop_rs(struct net_if *iface);
1325#else
1326static inline void net_if_stop_rs(struct net_if *iface)
1327{
1328 ARG_UNUSED(iface);
1329}
1330#endif /* CONFIG_NET_IPV6_ND */
1331
1344#if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
1345void net_if_nbr_reachability_hint(struct net_if *iface, const struct net_in6_addr *ipv6_addr);
1346#else
1347static inline void net_if_nbr_reachability_hint(struct net_if *iface,
1348 const struct net_in6_addr *ipv6_addr)
1349{
1350 ARG_UNUSED(iface);
1351 ARG_UNUSED(ipv6_addr);
1352}
1353#endif
1354
1356
1357static inline int net_if_set_link_addr_unlocked(struct net_if *iface,
1358 const uint8_t *addr, uint8_t len,
1359 enum net_link_type type)
1360{
1361 int ret;
1362
1363 if (net_if_flag_is_set(iface, NET_IF_RUNNING)) {
1364 return -EPERM;
1365 }
1366
1367 if (len > sizeof(net_if_get_link_addr(iface)->addr)) {
1368 return -EINVAL;
1369 }
1370
1371 ret = net_linkaddr_create(net_if_get_link_addr(iface), addr, len, type);
1372 if (ret < 0) {
1373 return ret;
1374 }
1375
1376 net_hostname_set_postfix(addr, len);
1377
1378 return 0;
1379}
1380
1381int net_if_set_link_addr_locked(struct net_if *iface,
1382 const uint8_t *addr, uint8_t len,
1383 enum net_link_type type);
1384
1385#if CONFIG_NET_IF_LOG_LEVEL >= LOG_LEVEL_DBG
1386extern int net_if_addr_unref_debug(struct net_if *iface,
1387 net_sa_family_t family,
1388 const void *addr,
1389 struct net_if_addr **ifaddr,
1390 const char *caller, int line);
1391#define net_if_addr_unref(iface, family, addr, ifaddr) \
1392 net_if_addr_unref_debug(iface, family, addr, ifaddr, __func__, __LINE__)
1393
1394extern struct net_if_addr *net_if_addr_ref_debug(struct net_if *iface,
1395 net_sa_family_t family,
1396 const void *addr,
1397 const char *caller,
1398 int line);
1399#define net_if_addr_ref(iface, family, addr) \
1400 net_if_addr_ref_debug(iface, family, addr, __func__, __LINE__)
1401#else
1402extern int net_if_addr_unref(struct net_if *iface,
1403 net_sa_family_t family,
1404 const void *addr,
1405 struct net_if_addr **ifaddr);
1406extern struct net_if_addr *net_if_addr_ref(struct net_if *iface,
1407 net_sa_family_t family,
1408 const void *addr);
1409#endif /* CONFIG_NET_IF_LOG_LEVEL */
1410
1412
1423static inline int net_if_set_link_addr(struct net_if *iface,
1424 const uint8_t *addr, uint8_t len,
1425 enum net_link_type type)
1426{
1427#if defined(CONFIG_NET_RAW_MODE)
1428 return net_if_set_link_addr_unlocked(iface, addr, len, type);
1429#else
1430 return net_if_set_link_addr_locked(iface, addr, len, type);
1431#endif
1432}
1433
1441static inline uint16_t net_if_get_mtu(struct net_if *iface)
1442{
1443 if (iface == NULL) {
1444 return 0U;
1445 }
1446
1447 NET_ASSERT(iface->if_dev != NULL);
1448
1449 return iface->if_dev->mtu;
1450}
1451
1458static inline void net_if_set_mtu(struct net_if *iface,
1459 uint16_t mtu)
1460{
1461 if (iface == NULL) {
1462 return;
1463 }
1464
1465 NET_ASSERT(iface->if_dev != NULL);
1466
1467 iface->if_dev->mtu = mtu;
1468}
1469
1476static inline void net_if_addr_set_lf(struct net_if_addr *ifaddr,
1477 bool is_infinite)
1478{
1479 if (ifaddr == NULL) {
1480 return;
1481 }
1482
1483 ifaddr->is_infinite = is_infinite;
1484}
1485
1494
1502struct net_if *net_if_lookup_by_dev(const struct device *dev);
1503
1509void net_if_router_rm(struct net_if_router *router);
1510
1516void net_if_set_default(struct net_if *iface);
1517
1524
1533struct net_if *net_if_get_first_by_type(const struct net_l2 *l2);
1534
1542
1543#if defined(CONFIG_NET_L2_IEEE802154)
1550static inline struct net_if *net_if_get_ieee802154(void)
1551{
1552 return net_if_get_first_by_type(&NET_L2_GET_NAME(IEEE802154));
1553}
1554#endif /* CONFIG_NET_L2_IEEE802154 */
1555
1567 struct net_if_ipv6 **ipv6);
1568
1577
1578
1580struct net_if_addr *net_if_ipv6_addr_lookup_raw(const uint8_t *addr,
1581 struct net_if **ret);
1583
1593 struct net_if **iface);
1594
1596struct net_if_addr *net_if_ipv6_addr_lookup_by_iface_raw(struct net_if *iface,
1597 const uint8_t *addr);
1599
1609 const struct net_in6_addr *addr);
1610
1619__syscall int net_if_ipv6_addr_lookup_by_index(const struct net_in6_addr *addr);
1620
1632 const struct net_in6_addr *addr,
1634 uint32_t vlifetime);
1635
1646__syscall bool net_if_ipv6_addr_add_by_index(int index,
1647 const struct net_in6_addr *addr,
1649 uint32_t vlifetime);
1650
1658 uint32_t vlifetime);
1659
1668bool net_if_ipv6_addr_rm(struct net_if *iface, const struct net_in6_addr *addr);
1669
1678__syscall bool net_if_ipv6_addr_rm_by_index(int index,
1679 const struct net_in6_addr *addr);
1680
1689typedef void (*net_if_ip_addr_cb_t)(struct net_if *iface,
1690 struct net_if_addr *addr,
1691 void *user_data);
1692
1702 void *user_data);
1703
1713 const struct net_in6_addr *addr);
1714
1723bool net_if_ipv6_maddr_rm(struct net_if *iface, const struct net_in6_addr *addr);
1724
1733typedef void (*net_if_ip_maddr_cb_t)(struct net_if *iface,
1734 struct net_if_mcast_addr *maddr,
1735 void *user_data);
1736
1746 void *user_data);
1747
1748
1750struct net_if_mcast_addr *net_if_ipv6_maddr_lookup_raw(const uint8_t *maddr,
1751 struct net_if **ret);
1753
1765 struct net_if **iface);
1766
1777typedef void (*net_if_mcast_callback_t)(struct net_if *iface,
1778 const struct net_addr *addr,
1779 bool is_joined);
1780
1799
1809 struct net_if *iface,
1811
1818
1826void net_if_mcast_monitor(struct net_if *iface, const struct net_addr *addr,
1827 bool is_joined);
1828
1836 struct net_if_mcast_addr *addr);
1837
1845static inline bool net_if_ipv6_maddr_is_joined(struct net_if_mcast_addr *addr)
1846{
1847 if (addr == NULL) {
1848 return false;
1849 }
1850
1851 return addr->is_joined;
1852}
1853
1861 struct net_if_mcast_addr *addr);
1862
1872 const struct net_in6_addr *addr);
1873
1884 const struct net_in6_addr *addr,
1885 uint8_t len);
1886
1898 const struct net_in6_addr *prefix,
1899 uint8_t len,
1901
1911bool net_if_ipv6_prefix_rm(struct net_if *iface, const struct net_in6_addr *addr,
1912 uint8_t len);
1913
1921 bool is_infinite)
1922{
1923 prefix->is_infinite = is_infinite;
1924}
1925
1934
1941
1952bool net_if_ipv6_addr_onlink(struct net_if **iface, const struct net_in6_addr *addr);
1953
1960#if defined(CONFIG_NET_NATIVE_IPV6)
1961static inline struct net_in6_addr *net_if_router_ipv6(struct net_if_router *router)
1962{
1963 if (router == NULL) {
1964 return NULL;
1965 }
1966
1967 return &router->address.in6_addr;
1968}
1969#else
1970static inline struct net_in6_addr *net_if_router_ipv6(struct net_if_router *router)
1971{
1972 static struct net_in6_addr addr;
1973
1974 ARG_UNUSED(router);
1975
1976 return &addr;
1977}
1978#endif
1979
1990 const struct net_in6_addr *addr);
1991
2002 const struct net_in6_addr *addr);
2003
2012
2024 const struct net_in6_addr *addr,
2025 bool is_default,
2026 uint16_t router_lifetime);
2027
2036
2045#if defined(CONFIG_NET_NATIVE_IPV6)
2047#else
2049{
2050 ARG_UNUSED(iface);
2051
2052 return 0;
2053}
2054#endif /* CONFIG_NET_NATIVE_IPV6 */
2055
2062#if defined(CONFIG_NET_NATIVE_IPV6)
2063void net_if_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit);
2064#else
2065static inline void net_if_ipv6_set_hop_limit(struct net_if *iface,
2066 uint8_t hop_limit)
2067{
2068 ARG_UNUSED(iface);
2069 ARG_UNUSED(hop_limit);
2070}
2071#endif /* CONFIG_NET_NATIVE_IPV6 */
2072
2081#if defined(CONFIG_NET_NATIVE_IPV6)
2083#else
2085{
2086 ARG_UNUSED(iface);
2087
2088 return 0;
2089}
2090#endif /* CONFIG_NET_NATIVE_IPV6 */
2091
2098#if defined(CONFIG_NET_NATIVE_IPV6)
2099void net_if_ipv6_set_mcast_hop_limit(struct net_if *iface, uint8_t hop_limit);
2100#else
2102 uint8_t hop_limit)
2103{
2104 ARG_UNUSED(iface);
2105 ARG_UNUSED(hop_limit);
2106}
2107#endif /* CONFIG_NET_NATIVE_IPV6 */
2108
2116 uint32_t reachable_time)
2117{
2118#if defined(CONFIG_NET_NATIVE_IPV6)
2119 if (iface == NULL) {
2120 return;
2121 }
2122
2123 if (!iface->config.ip.ipv6) {
2124 return;
2125 }
2126
2127 iface->config.ip.ipv6->base_reachable_time = reachable_time;
2128#else
2129 ARG_UNUSED(iface);
2130 ARG_UNUSED(reachable_time);
2131
2132#endif
2133}
2134
2143{
2144#if defined(CONFIG_NET_NATIVE_IPV6)
2145 if (iface == NULL) {
2146 return 0;
2147 }
2148
2149 if (!iface->config.ip.ipv6) {
2150 return 0;
2151 }
2152
2153 return iface->config.ip.ipv6->reachable_time;
2154#else
2155 ARG_UNUSED(iface);
2156 return 0;
2157#endif
2158}
2159
2168
2175static inline void net_if_ipv6_set_reachable_time(struct net_if_ipv6 *ipv6)
2176{
2177#if defined(CONFIG_NET_NATIVE_IPV6)
2178 if (ipv6 == NULL) {
2179 return;
2180 }
2181
2183#else
2184 ARG_UNUSED(ipv6);
2185#endif
2186}
2187
2194static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
2195 uint32_t retrans_timer)
2196{
2197#if defined(CONFIG_NET_NATIVE_IPV6)
2198 if (iface == NULL) {
2199 return;
2200 }
2201
2202 if (!iface->config.ip.ipv6) {
2203 return;
2204 }
2205
2206 iface->config.ip.ipv6->retrans_timer = retrans_timer;
2207#else
2208 ARG_UNUSED(iface);
2209 ARG_UNUSED(retrans_timer);
2210#endif
2211}
2212
2221{
2222#if defined(CONFIG_NET_NATIVE_IPV6)
2223 if (iface == NULL) {
2224 return 0;
2225 }
2226
2227 if (!iface->config.ip.ipv6) {
2228 return 0;
2229 }
2230
2231 return iface->config.ip.ipv6->retrans_timer;
2232#else
2233 ARG_UNUSED(iface);
2234 return 0;
2235#endif
2236}
2237
2249#if defined(CONFIG_NET_IPV6)
2250const struct net_in6_addr *net_if_ipv6_select_src_addr(struct net_if *iface,
2251 const struct net_in6_addr *dst);
2252#else
2253static inline const struct net_in6_addr *net_if_ipv6_select_src_addr(
2254 struct net_if *iface, const struct net_in6_addr *dst)
2255{
2256 ARG_UNUSED(iface);
2257 ARG_UNUSED(dst);
2258
2259 return NULL;
2260}
2261#endif
2262
2276#if defined(CONFIG_NET_IPV6)
2277const struct net_in6_addr *net_if_ipv6_select_src_addr_hint(struct net_if *iface,
2278 const struct net_in6_addr *dst,
2279 int flags);
2280#else
2282 struct net_if *iface, const struct net_in6_addr *dst, int flags)
2283{
2284 ARG_UNUSED(iface);
2285 ARG_UNUSED(dst);
2286 ARG_UNUSED(flags);
2287
2288 return NULL;
2289}
2290#endif
2291
2301#if defined(CONFIG_NET_IPV6)
2302struct net_if *net_if_ipv6_select_src_iface(const struct net_in6_addr *dst);
2303#else
2305 const struct net_in6_addr *dst)
2306{
2307 ARG_UNUSED(dst);
2308
2309 return NULL;
2310}
2311#endif
2312
2325#if defined(CONFIG_NET_IPV6)
2326struct net_if *net_if_ipv6_select_src_iface_addr(const struct net_in6_addr *dst,
2327 const struct net_in6_addr **src_addr);
2328#else
2330 const struct net_in6_addr *dst, const struct net_in6_addr **src_addr)
2331{
2332 ARG_UNUSED(dst);
2333 ARG_UNUSED(src_addr);
2334
2335 return NULL;
2336}
2337#endif /* CONFIG_NET_IPV6 */
2338
2349 enum net_addr_state addr_state);
2350
2361 struct net_if **iface);
2362
2370void net_if_ipv6_dad_failed(struct net_if *iface, const struct net_in6_addr *addr);
2371
2384 struct net_if **iface);
2385
2397 struct net_if_ipv4 **ipv4);
2398
2407
2416
2423void net_if_ipv4_set_ttl(struct net_if *iface, uint8_t ttl);
2424
2433
2441
2452bool net_if_ipv4_addr_onlink(struct net_if **iface, const struct net_in_addr *addr);
2453
2463 struct net_if **iface);
2464
2476 const struct net_in_addr *addr,
2478 uint32_t vlifetime);
2479
2488bool net_if_ipv4_addr_rm(struct net_if *iface, const struct net_in_addr *addr);
2489
2498__syscall int net_if_ipv4_addr_lookup_by_index(const struct net_in_addr *addr);
2499
2510__syscall bool net_if_ipv4_addr_add_by_index(int index,
2511 const struct net_in_addr *addr,
2513 uint32_t vlifetime);
2514
2523__syscall bool net_if_ipv4_addr_rm_by_index(int index,
2524 const struct net_in_addr *addr);
2525
2535 void *user_data);
2536
2546 const struct net_in_addr *addr);
2547
2556bool net_if_ipv4_maddr_rm(struct net_if *iface, const struct net_in_addr *addr);
2557
2567 void *user_data);
2568
2580 struct net_if **iface);
2581
2589 struct net_if_mcast_addr *addr);
2590
2598static inline bool net_if_ipv4_maddr_is_joined(struct net_if_mcast_addr *addr)
2599{
2600 if (addr == NULL) {
2601 return false;
2602 }
2603
2604 return addr->is_joined;
2605}
2606
2614 struct net_if_mcast_addr *addr);
2615
2622#if defined(CONFIG_NET_NATIVE_IPV4)
2623static inline struct net_in_addr *net_if_router_ipv4(struct net_if_router *router)
2624{
2625 if (router == NULL) {
2626 return NULL;
2627 }
2628
2629 return &router->address.in_addr;
2630}
2631#else
2632static inline struct net_in_addr *net_if_router_ipv4(struct net_if_router *router)
2633{
2634 static struct net_in_addr addr;
2635
2636 ARG_UNUSED(router);
2637
2638 return &addr;
2639}
2640#endif
2641
2652 const struct net_in_addr *addr);
2653
2664 const struct net_in_addr *addr);
2676 const struct net_in_addr *addr,
2677 bool is_default,
2678 uint16_t router_lifetime);
2679
2688
2698 const struct net_in_addr *addr);
2699
2709 const struct net_in_addr *addr);
2710
2720#if defined(CONFIG_NET_IPV4)
2721struct net_if *net_if_ipv4_select_src_iface(const struct net_in_addr *dst);
2722#else
2724 const struct net_in_addr *dst)
2725{
2726 ARG_UNUSED(dst);
2727
2728 return NULL;
2729}
2730#endif
2731
2744#if defined(CONFIG_NET_IPV4)
2745struct net_if *net_if_ipv4_select_src_iface_addr(const struct net_in_addr *dst,
2746 const struct net_in_addr **src_addr);
2747#else
2749 const struct net_in_addr *dst, const struct net_in_addr **src_addr)
2750{
2751 ARG_UNUSED(dst);
2752 ARG_UNUSED(src_addr);
2753
2754 return NULL;
2755}
2756#endif /* CONFIG_NET_IPV4 */
2757
2769#if defined(CONFIG_NET_IPV4)
2770const struct net_in_addr *net_if_ipv4_select_src_addr(struct net_if *iface,
2771 const struct net_in_addr *dst);
2772#else
2773static inline const struct net_in_addr *net_if_ipv4_select_src_addr(
2774 struct net_if *iface, const struct net_in_addr *dst)
2775{
2776 ARG_UNUSED(iface);
2777 ARG_UNUSED(dst);
2778
2779 return NULL;
2780}
2781#endif
2782
2793 enum net_addr_state addr_state);
2794
2805 enum net_addr_state addr_state);
2806
2817 const struct net_in_addr *addr);
2818
2829 const struct net_in_addr *addr,
2830 const struct net_in_addr *netmask);
2831
2842 const struct net_in_addr *addr,
2843 const struct net_in_addr *netmask);
2844
2853
2860void net_if_ipv4_set_gw(struct net_if *iface, const struct net_in_addr *gw);
2861
2870__syscall bool net_if_ipv4_set_gw_by_index(int index, const struct net_in_addr *gw);
2871
2883
2892typedef void (*net_if_link_callback_t)(struct net_if *iface,
2893 struct net_linkaddr *dst,
2894 int status);
2895
2911
2920
2927
2935void net_if_call_link_cb(struct net_if *iface, struct net_linkaddr *lladdr,
2936 int status);
2937
2939
2940/* used to ensure encoding of checksum support in net_if.h and
2941 * ethernet.h is the same
2942 */
2943#define NET_IF_CHECKSUM_NONE_BIT 0
2944#define NET_IF_CHECKSUM_IPV4_HEADER_BIT BIT(0)
2945#define NET_IF_CHECKSUM_IPV4_ICMP_BIT BIT(1)
2946/* Space for future protocols and restrictions for IPV4 */
2947#define NET_IF_CHECKSUM_IPV6_HEADER_BIT BIT(10)
2948#define NET_IF_CHECKSUM_IPV6_ICMP_BIT BIT(11)
2949/* Space for future protocols and restrictions for IPV6 */
2950#define NET_IF_CHECKSUM_TCP_BIT BIT(21)
2951#define NET_IF_CHECKSUM_UDP_BIT BIT(22)
2952
2954
2960 NET_IF_CHECKSUM_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
2962 NET_IF_CHECKSUM_IPV4_TCP = NET_IF_CHECKSUM_IPV4_HEADER_BIT |
2963 NET_IF_CHECKSUM_TCP_BIT,
2965 NET_IF_CHECKSUM_IPV4_UDP = NET_IF_CHECKSUM_IPV4_HEADER_BIT |
2966 NET_IF_CHECKSUM_UDP_BIT,
2968 NET_IF_CHECKSUM_IPV4_ICMP = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
2970 NET_IF_CHECKSUM_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
2972 NET_IF_CHECKSUM_IPV6_TCP = NET_IF_CHECKSUM_IPV6_HEADER_BIT |
2973 NET_IF_CHECKSUM_TCP_BIT,
2975 NET_IF_CHECKSUM_IPV6_UDP = NET_IF_CHECKSUM_IPV6_HEADER_BIT |
2976 NET_IF_CHECKSUM_UDP_BIT,
2978 NET_IF_CHECKSUM_IPV6_ICMP = NET_IF_CHECKSUM_IPV6_ICMP_BIT
2979};
2980
2991#if defined(CONFIG_NET_CHECKSUM_OFFLOAD)
2992bool net_if_need_calc_rx_checksum(struct net_if *iface,
2993 enum net_if_checksum_type chksum_type);
2994#else /* CONFIG_NET_CHECKSUM_OFFLOAD */
2995static inline bool net_if_need_calc_rx_checksum(struct net_if *iface,
2996 enum net_if_checksum_type chksum_type)
2997{
2998 ARG_UNUSED(iface);
2999 ARG_UNUSED(chksum_type);
3000 return true;
3001}
3002#endif /* CONFIG_NET_CHECKSUM_OFFLOAD */
3003
3015#if defined(CONFIG_NET_CHECKSUM_OFFLOAD)
3016bool net_if_need_calc_tx_checksum(struct net_if *iface,
3017 enum net_if_checksum_type chksum_type);
3018#else /* CONFIG_NET_CHECKSUM_OFFLOAD */
3019static inline bool net_if_need_calc_tx_checksum(struct net_if *iface,
3020 enum net_if_checksum_type chksum_type)
3021{
3022 ARG_UNUSED(iface);
3023 ARG_UNUSED(chksum_type);
3024 return true;
3025}
3026#endif /* CONFIG_NET_CHECKSUM_OFFLOAD */
3027
3038__syscall struct net_if *net_if_get_by_index(int index);
3039
3047int net_if_get_by_iface(struct net_if *iface);
3048
3056typedef void (*net_if_cb_t)(struct net_if *iface, void *user_data);
3057
3065void net_if_foreach(net_if_cb_t cb, void *user_data);
3066
3074int net_if_up(struct net_if *iface);
3075
3083static inline bool net_if_is_up(struct net_if *iface)
3084{
3085 if (iface == NULL) {
3086 return false;
3087 }
3088
3089 return net_if_flag_is_set(iface, NET_IF_UP) &&
3091}
3092
3100int net_if_down(struct net_if *iface);
3101
3109static inline bool net_if_is_admin_up(struct net_if *iface)
3110{
3111 if (iface == NULL) {
3112 return false;
3113 }
3114
3115 return net_if_flag_is_set(iface, NET_IF_UP);
3116}
3117
3126void net_if_carrier_on(struct net_if *iface);
3127
3136void net_if_carrier_off(struct net_if *iface);
3137
3145static inline bool net_if_is_carrier_ok(struct net_if *iface)
3146{
3147 if (iface == NULL) {
3148 return false;
3149 }
3150
3151 return net_if_flag_is_set(iface, NET_IF_LOWER_UP);
3152}
3153
3164void net_if_dormant_on(struct net_if *iface);
3165
3174void net_if_dormant_off(struct net_if *iface);
3175
3183static inline bool net_if_is_dormant(struct net_if *iface)
3184{
3185 if (iface == NULL) {
3186 return false;
3187 }
3188
3189 return net_if_flag_is_set(iface, NET_IF_DORMANT);
3190}
3191
3192#if defined(CONFIG_NET_PKT_TIMESTAMP_THREAD) || defined(__DOXYGEN__)
3200typedef void (*net_if_timestamp_callback_t)(struct net_pkt *pkt);
3201
3227
3239 struct net_pkt *pkt,
3240 struct net_if *iface,
3242
3249
3256
3257/*
3258 * @brief Add timestamped TX buffer to be handled
3259 *
3260 * @param pkt Timestamped buffer
3261 */
3263#endif /* CONFIG_NET_PKT_TIMESTAMP_THREAD */
3264
3274#if defined(CONFIG_NET_PROMISCUOUS_MODE)
3275int net_if_set_promisc(struct net_if *iface);
3276#else
3277static inline int net_if_set_promisc(struct net_if *iface)
3278{
3279 ARG_UNUSED(iface);
3280
3281 return -ENOTSUP;
3282}
3283#endif
3284
3290#if defined(CONFIG_NET_PROMISCUOUS_MODE)
3291void net_if_unset_promisc(struct net_if *iface);
3292#else
3293static inline void net_if_unset_promisc(struct net_if *iface)
3294{
3295 ARG_UNUSED(iface);
3296}
3297#endif
3298
3307#if defined(CONFIG_NET_PROMISCUOUS_MODE)
3308bool net_if_is_promisc(struct net_if *iface);
3309#else
3310static inline bool net_if_is_promisc(struct net_if *iface)
3311{
3312 ARG_UNUSED(iface);
3313
3314 return false;
3315}
3316#endif
3317
3327static inline bool net_if_are_pending_tx_packets(struct net_if *iface)
3328{
3329#if defined(CONFIG_NET_POWER_MANAGEMENT)
3330 return !!iface->tx_pending;
3331#else
3332 ARG_UNUSED(iface);
3333
3334 return false;
3335#endif
3336}
3337
3338#ifdef CONFIG_NET_POWER_MANAGEMENT
3346int net_if_suspend(struct net_if *iface);
3347
3355int net_if_resume(struct net_if *iface);
3356
3364bool net_if_is_suspended(struct net_if *iface);
3365#endif /* CONFIG_NET_POWER_MANAGEMENT */
3366
3374bool net_if_is_ethernet(struct net_if *iface);
3375
3382
3390bool net_if_is_wifi(struct net_if *iface);
3391
3398
3405
3412
3427int net_if_get_name(struct net_if *iface, char *buf, int len);
3428
3443int net_if_set_name(struct net_if *iface, const char *buf);
3444
3452int net_if_get_by_name(const char *name);
3453
3455struct net_if_api {
3456 void (*init)(struct net_if *iface);
3457};
3458
3459#define NET_IF_DHCPV4_INIT \
3460 IF_ENABLED(UTIL_AND(IS_ENABLED(CONFIG_NET_DHCPV4), \
3461 IS_ENABLED(CONFIG_NET_NATIVE_IPV4)), \
3462 (.dhcpv4.state = NET_DHCPV4_DISABLED,))
3463
3464#define NET_IF_DHCPV6_INIT \
3465 IF_ENABLED(UTIL_AND(IS_ENABLED(CONFIG_NET_DHCPV6), \
3466 IS_ENABLED(CONFIG_NET_NATIVE_IPV6)), \
3467 (.dhcpv6.state = NET_DHCPV6_DISABLED,))
3468
3469#define NET_IF_CONFIG_INIT \
3470 .config = { \
3471 IF_ENABLED(CONFIG_NET_IP, (.ip = {},)) \
3472 NET_IF_DHCPV4_INIT \
3473 NET_IF_DHCPV6_INIT \
3474 }
3475
3476#define NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, sfx) \
3477 net_stats_##dev_id##_##sfx##_collector
3478#define NET_PROMETHEUS_INIT(dev_id, sfx) \
3479 IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS, \
3480 (.collector = &NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, sfx),))
3481
3482#define NET_IF_GET_NAME(dev_id, sfx) __net_if_##dev_id##_##sfx
3483#define NET_IF_DEV_GET_NAME(dev_id, sfx) __net_if_dev_##dev_id##_##sfx
3484
3485#define NET_IF_GET(dev_id, sfx) \
3486 ((struct net_if *)&NET_IF_GET_NAME(dev_id, sfx))
3487
3488#if defined(CONFIG_NET_STATISTICS_VIA_PROMETHEUS)
3489extern int net_stats_prometheus_scrape(struct prometheus_collector *collector,
3490 struct prometheus_metric *metric,
3491 void *user_data);
3492#endif /* CONFIG_NET_STATISTICS_VIA_PROMETHEUS */
3493
3494#define NET_IF_INIT(dev_id, sfx, _l2, _mtu) \
3495 static STRUCT_SECTION_ITERABLE(net_if_dev, \
3496 NET_IF_DEV_GET_NAME(dev_id, sfx)) = { \
3497 .dev = &(DEVICE_NAME_GET(dev_id)), \
3498 .l2 = &(NET_L2_GET_NAME(_l2)), \
3499 .l2_data = &(NET_L2_GET_DATA(dev_id, sfx)), \
3500 .mtu = _mtu, \
3501 .flags = {BIT(NET_IF_LOWER_UP)}, \
3502 }; \
3503 static STRUCT_SECTION_ITERABLE(net_if, \
3504 NET_IF_GET_NAME(dev_id, sfx)) = { \
3505 .if_dev = &(NET_IF_DEV_GET_NAME(dev_id, sfx)), \
3506 NET_IF_CONFIG_INIT \
3507 }; \
3508 IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS, \
3509 (static PROMETHEUS_COLLECTOR_DEFINE( \
3510 NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, \
3511 sfx), \
3512 net_stats_prometheus_scrape, \
3513 NET_IF_GET(dev_id, sfx)); \
3514 NET_STATS_PROMETHEUS(NET_IF_GET(dev_id, sfx), \
3515 dev_id, sfx);))
3516
3517#define NET_IF_OFFLOAD_INIT(dev_id, sfx, _mtu) \
3518 static STRUCT_SECTION_ITERABLE(net_if_dev, \
3519 NET_IF_DEV_GET_NAME(dev_id, sfx)) = { \
3520 .dev = &(DEVICE_NAME_GET(dev_id)), \
3521 .mtu = _mtu, \
3522 .l2 = &(NET_L2_GET_NAME(OFFLOADED_NETDEV)), \
3523 .flags = {BIT(NET_IF_LOWER_UP)}, \
3524 }; \
3525 static STRUCT_SECTION_ITERABLE(net_if, \
3526 NET_IF_GET_NAME(dev_id, sfx)) = { \
3527 .if_dev = &(NET_IF_DEV_GET_NAME(dev_id, sfx)), \
3528 NET_IF_CONFIG_INIT \
3529 }; \
3530 IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS, \
3531 (static PROMETHEUS_COLLECTOR_DEFINE( \
3532 NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, \
3533 sfx), \
3534 net_stats_prometheus_scrape, \
3535 NET_IF_GET(dev_id, sfx)); \
3536 NET_STATS_PROMETHEUS(NET_IF_GET(dev_id, sfx), \
3537 dev_id, sfx);))
3538
3539
3541
3542/* Network device initialization macros */
3543
3551#define NET_IF_DECLARE(dev_id, inst) \
3552 static struct net_if NET_IF_GET_NAME(dev_id, inst)
3553
3554#define Z_NET_DEVICE_IF_INIT_INSTANCE(dev_id, instance, l2, \
3555 l2_ctx_type, mtu) \
3556 NET_L2_DATA_INIT(dev_id, instance, l2_ctx_type); \
3557 NET_IF_INIT(dev_id, instance, l2, mtu)
3558
3559#define Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
3560 init_fn, pm, data, config, prio, \
3561 api, l2, l2_ctx_type, mtu) \
3562 Z_DEVICE_STATE_DEFINE(dev_id); \
3563 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, NULL, \
3564 Z_DEVICE_DT_FLAGS(node_id), pm, data, \
3565 config, POST_KERNEL, prio, api, \
3566 &Z_DEVICE_STATE_NAME(dev_id)); \
3567 Z_NET_DEVICE_IF_INIT_INSTANCE(dev_id, instance, l2, \
3568 l2_ctx_type, mtu)
3569
3570#define Z_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
3571 config, prio, api, l2, l2_ctx_type, mtu) \
3572 Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, init_fn, \
3573 pm, data, config, prio, api, l2, \
3574 l2_ctx_type, mtu)
3575
3582#define NET_IF_DT_DECLARE(node_id, instance) \
3583 NET_IF_DECLARE(Z_DEVICE_DT_DEV_ID(node_id), instance)
3584
3592#define NET_IF_DT_INST_DECLARE(inst, ...) NET_IF_DT_DECLARE(DT_DRV_INST(inst), __VA_ARGS__)
3593
3601#define NET_IF_DT_GET(node_id, instance) NET_IF_GET(Z_DEVICE_DT_DEV_ID(node_id), instance)
3602
3611#define NET_IF_DT_INST_GET(inst, ...) NET_IF_DT_GET(DT_DRV_INST(inst), __VA_ARGS__)
3612
3632#define NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, prio, \
3633 api, l2, l2_ctx_type, mtu) \
3634 Z_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, pm, \
3635 data, config, prio, api, l2, l2_ctx_type, mtu)
3636
3648#define NET_DEVICE_DT_ADD_IFACE(node_id, l2, l2_ctx_type, mtu, instance) \
3649 Z_NET_DEVICE_IF_INIT_INSTANCE(Z_DEVICE_DT_DEV_ID(node_id), instance, l2, l2_ctx_type, mtu)
3650
3659#define NET_DEVICE_DT_INST_ADD_IFACE(inst, ...) \
3660 NET_DEVICE_DT_ADD_IFACE(DT_DRV_INST(inst), __VA_ARGS__)
3661
3680#define NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, \
3681 config, prio, api, l2, l2_ctx_type, mtu) \
3682 Z_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
3683 DEVICE_DT_NAME(node_id), init_fn, pm, data, \
3684 config, prio, api, l2, l2_ctx_type, mtu)
3685
3694#define NET_DEVICE_DT_INST_DEFINE(inst, ...) \
3695 NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
3696
3720#define NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, pm, \
3721 data, config, prio, api, l2, \
3722 l2_ctx_type, mtu) \
3723 Z_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
3724 instance, init_fn, pm, data, config, \
3725 prio, api, l2, l2_ctx_type, mtu)
3726
3749#define NET_DEVICE_DT_DEFINE_INSTANCE(node_id, instance, init_fn, pm, \
3750 data, config, prio, api, l2, \
3751 l2_ctx_type, mtu) \
3752 Z_NET_DEVICE_INIT_INSTANCE(node_id, \
3753 Z_DEVICE_DT_DEV_ID(node_id), \
3754 DEVICE_DT_NAME(node_id), instance, \
3755 init_fn, pm, data, config, prio, \
3756 api, l2, l2_ctx_type, mtu)
3757
3767#define NET_DEVICE_DT_INST_DEFINE_INSTANCE(inst, ...) \
3768 NET_DEVICE_DT_DEFINE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
3769
3770#define Z_NET_DEVICE_OFFLOAD_INIT(node_id, dev_id, name, init_fn, pm, \
3771 data, config, prio, api, mtu) \
3772 Z_DEVICE_STATE_DEFINE(dev_id); \
3773 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, NULL, \
3774 Z_DEVICE_DT_FLAGS(node_id), pm, data, \
3775 config, POST_KERNEL, prio, api, \
3776 &Z_DEVICE_STATE_NAME(dev_id)); \
3777 NET_IF_OFFLOAD_INIT(dev_id, 0, mtu)
3778
3798#define NET_DEVICE_OFFLOAD_INIT(dev_id, name, init_fn, pm, data, \
3799 config, prio, api, mtu) \
3800 Z_NET_DEVICE_OFFLOAD_INIT(DT_INVALID_NODE, dev_id, name, \
3801 init_fn, pm, data, config, prio, api, \
3802 mtu)
3803
3822#define NET_DEVICE_DT_OFFLOAD_DEFINE(node_id, init_fn, pm, data, \
3823 config, prio, api, mtu) \
3824 Z_NET_DEVICE_OFFLOAD_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
3825 DEVICE_DT_NAME(node_id), init_fn, pm, \
3826 data, config, prio, api, mtu)
3827
3837#define NET_DEVICE_DT_INST_OFFLOAD_DEFINE(inst, ...) \
3838 NET_DEVICE_DT_OFFLOAD_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
3839
3845#define NET_IFACE_COUNT(_dst) \
3846 do { \
3847 extern struct net_if _net_if_list_start[]; \
3848 extern struct net_if _net_if_list_end[]; \
3849 *(_dst) = ((uintptr_t)_net_if_list_end - \
3850 (uintptr_t)_net_if_list_start) / \
3851 sizeof(struct net_if); \
3852 } while (0)
3853
3854#ifdef __cplusplus
3855}
3856#endif
3857
3858#include <zephyr/syscalls/net_if.h>
3859
3863
3864#endif /* ZEPHYR_INCLUDE_NET_NET_IF_H_ */
struct z_thread_stack_element k_thread_stack_t
Typedef of struct z_thread_stack_element.
Definition arch_interface.h:46
Prometheus collector APIs.
DHCPv4 Client Handler.
DHCPv6 client.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
static void atomic_set_bit(atomic_t *target, int bit)
Atomically set a bit.
Definition atomic.h:242
static bool atomic_test_bit(const atomic_t *target, int bit)
Atomically get and test a bit.
Definition atomic.h:135
static void atomic_clear_bit(atomic_t *target, int bit)
Atomically clear a bit.
Definition atomic.h:224
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition atomic.h:119
static bool atomic_test_and_clear_bit(atomic_t *target, int bit)
Atomically clear a bit and test it.
Definition atomic.h:155
static bool atomic_test_and_set_bit(atomic_t *target, int bit)
Atomically set a bit and test it.
Definition atomic.h:178
#define K_FOREVER
Generate infinite timeout delay.
Definition kernel.h:1682
#define K_NO_WAIT
Generate null timeout delay.
Definition kernel.h:1572
static int64_t k_uptime_get(void)
Get system uptime.
Definition kernel.h:2187
net_addr_state
What is the current state of the network address.
Definition net_ip.h:577
unsigned short int net_sa_family_t
Socket address family type.
Definition net_ip.h:169
net_addr_type
How the network address is assigned to network interface.
Definition net_ip.h:585
bool k_is_in_isr(void)
Determine if code is running at interrupt level.
int k_mutex_unlock(struct k_mutex *mutex)
Unlock a mutex.
int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout)
Lock a mutex.
net_verdict
Net Verdict.
Definition net_core.h:84
static int net_hostname_set_postfix(const uint8_t *hostname_postfix, int postfix_len)
Set the device hostname postfix.
Definition hostname.h:118
int net_if_get_by_iface(struct net_if *iface)
Get interface index according to pointer.
int net_if_up(struct net_if *iface)
Bring interface up.
struct net_if * net_if_get_first_up(void)
Get the first network interface which is up.
int net_if_set_name(struct net_if *iface, const char *buf)
Set network interface name.
struct net_if_router * net_if_ipv4_router_add(struct net_if *iface, const struct net_in_addr *addr, bool is_default, uint16_t router_lifetime)
Add IPv4 router to the system.
void net_if_ipv4_set_gw(struct net_if *iface, const struct net_in_addr *gw)
Set IPv4 gateway for an interface.
static bool net_if_is_carrier_ok(struct net_if *iface)
Check if carrier is present on network device.
Definition net_if.h:3145
static bool net_if_is_admin_up(struct net_if *iface)
Check if interface was brought up by the administrator.
Definition net_if.h:3109
void net_if_set_default(struct net_if *iface)
Set the default network interface.
void(* net_if_mcast_callback_t)(struct net_if *iface, const struct net_addr *addr, bool is_joined)
Define a callback that is called whenever a IPv6 or IPv4 multicast address group is joined or left.
Definition net_if.h:1777
static bool net_if_need_calc_tx_checksum(struct net_if *iface, enum net_if_checksum_type chksum_type)
Check if network packet checksum calculation can be avoided or not when sending the packet.
Definition net_if.h:3019
bool net_if_ipv4_addr_onlink(struct net_if **iface, const struct net_in_addr *addr)
Check if this IPv4 address is part of the subnet of our network interface.
void(* net_if_link_callback_t)(struct net_if *iface, struct net_linkaddr *dst, int status)
Define callback that is called after a network packet has been sent.
Definition net_if.h:2892
struct net_if * net_if_get_wifi_sta(void)
Get Wi-Fi network station interface.
struct net_in_addr net_if_ipv4_get_gw(struct net_if *iface)
Get IPv4 gateway of an interface.
void net_if_add_tx_timestamp(struct net_pkt *pkt)
void net_if_ipv4_maddr_leave(struct net_if *iface, struct net_if_mcast_addr *addr)
Mark a given multicast address to be left.
struct net_if_mcast_addr * net_if_ipv6_maddr_add(struct net_if *iface, const struct net_in6_addr *addr)
Add a IPv6 multicast address to an interface.
int net_if_get_by_name(const char *name)
Get interface index according to its name.
static struct net_in6_addr * net_if_router_ipv6(struct net_if_router *router)
Get the IPv6 address of the given router.
Definition net_if.h:1970
void net_if_register_timestamp_cb(struct net_if_timestamp_cb *handle, struct net_pkt *pkt, struct net_if *iface, net_if_timestamp_callback_t cb)
Register a timestamp callback.
struct net_if * net_if_get_by_link_addr(struct net_linkaddr *ll_addr)
Get an interface according to link layer address.
bool net_if_ipv4_addr_rm_by_index(int index, const struct net_in_addr *addr)
Remove a IPv4 address from an interface by interface index.
void net_if_dormant_off(struct net_if *iface)
Mark interface as not dormant.
bool net_if_ipv6_router_rm(struct net_if_router *router)
Remove IPv6 router from the system.
static struct net_if * net_if_ipv4_select_src_iface(const struct net_in_addr *dst)
Get a network interface that should be used when sending IPv4 network data to destination.
Definition net_if.h:2723
static enum net_if_oper_state net_if_oper_state_set(struct net_if *iface, enum net_if_oper_state oper_state)
Set an operational state on an interface.
Definition net_if.h:931
int net_if_down(struct net_if *iface)
Bring interface down.
struct net_if_ipv6_prefix * net_if_ipv6_prefix_add(struct net_if *iface, const struct net_in6_addr *prefix, uint8_t len, uint32_t lifetime)
Add a IPv6 prefix to an network interface.
bool net_if_ipv4_addr_rm(struct net_if *iface, const struct net_in_addr *addr)
Remove a IPv4 address from an interface.
static struct net_if * net_if_ipv4_select_src_iface_addr(const struct net_in_addr *dst, const struct net_in_addr **src_addr)
Get a network interface that should be used when sending IPv4 network data to destination.
Definition net_if.h:2748
static void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
Queue a packet to the net interface TX queue.
Definition net_if.h:1110
void net_if_ipv6_prefix_unset_timer(struct net_if_ipv6_prefix *prefix)
Unset the prefix lifetime timer.
bool net_if_ipv4_addr_add_by_index(int index, const struct net_in_addr *addr, enum net_addr_type addr_type, uint32_t vlifetime)
Add a IPv4 address to an interface by network interface index.
int net_if_config_ipv4_get(struct net_if *iface, struct net_if_ipv4 **ipv4)
Allocate network interface IPv4 config.
void net_if_carrier_on(struct net_if *iface)
Underlying network device has detected the carrier (cable connected).
void net_if_try_queue_tx(struct net_if *iface, struct net_pkt *pkt, k_timeout_t timeout)
Try enqueuing a packet to the net interface TX queue.
static struct net_if * net_if_ipv6_select_src_iface(const struct net_in6_addr *dst)
Get a network interface that should be used when sending IPv6 network data to destination.
Definition net_if.h:2304
void net_if_mcast_monitor(struct net_if *iface, const struct net_addr *addr, bool is_joined)
Call registered multicast monitors.
static int net_if_set_link_addr(struct net_if *iface, const uint8_t *addr, uint8_t len, enum net_link_type type)
Set a network interface's link address.
Definition net_if.h:1423
struct net_if_addr * net_if_ipv6_addr_add(struct net_if *iface, const struct net_in6_addr *addr, enum net_addr_type addr_type, uint32_t vlifetime)
Add a IPv6 address to an interface.
static void * net_if_l2_data(struct net_if *iface)
Get a pointer to the interface L2 private data.
Definition net_if.h:1065
static bool net_if_are_pending_tx_packets(struct net_if *iface)
Check if there are any pending TX network data for a given network interface.
Definition net_if.h:3327
static bool net_if_flag_test_and_set(struct net_if *iface, enum net_if_flag value)
Test and set a value in network interface flags.
Definition net_if.h:853
struct net_if_addr * net_if_ipv6_addr_lookup(const struct net_in6_addr *addr, struct net_if **iface)
Check if this IPv6 address belongs to one of the interfaces.
bool net_if_ipv4_is_addr_bcast(struct net_if *iface, const struct net_in_addr *addr)
Check if the given IPv4 address is a broadcast address.
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1269
void net_if_ipv6_maddr_join(struct net_if *iface, struct net_if_mcast_addr *addr)
Mark a given multicast address to be joined.
struct net_if_router * net_if_ipv4_router_lookup(struct net_if *iface, const struct net_in_addr *addr)
Check if IPv4 address is one of the routers configured in the system.
bool net_if_ipv6_prefix_rm(struct net_if *iface, const struct net_in6_addr *addr, uint8_t len)
Remove an IPv6 prefix from an interface.
static struct net_in_addr * net_if_router_ipv4(struct net_if_router *router)
Get the IPv4 address of the given router.
Definition net_if.h:2632
static struct net_offload * net_if_offload(struct net_if *iface)
Return the IP offload plugin.
Definition net_if.h:1152
struct net_if * net_if_get_first_ethernet(void)
Get first Cabled Ethernet network interface.
static void net_if_flag_set(struct net_if *iface, enum net_if_flag value)
Set a value in network interface flags.
Definition net_if.h:833
bool net_if_ipv6_addr_onlink(struct net_if **iface, const struct net_in6_addr *addr)
Check if this IPv6 address is part of the subnet of our network interface.
struct net_if_addr * net_if_ipv4_addr_lookup(const struct net_in_addr *addr, struct net_if **iface)
Check if this IPv4 address belongs to one of the interfaces.
struct net_if * net_if_get_default(void)
Get the default network interface.
void net_if_ipv4_set_ttl(struct net_if *iface, uint8_t ttl)
Set IPv4 time-to-live value specified to a given interface.
static const struct net_in6_addr * net_if_ipv6_select_src_addr_hint(struct net_if *iface, const struct net_in6_addr *dst, int flags)
Get a IPv6 source address that should be used when sending network data to destination.
Definition net_if.h:2281
int net_if_config_ipv6_get(struct net_if *iface, struct net_if_ipv6 **ipv6)
Allocate network interface IPv6 config.
static uint8_t net_if_ipv6_get_mcast_hop_limit(struct net_if *iface)
Get IPv6 multicast hop limit specified for a given interface.
Definition net_if.h:2084
void net_if_ipv6_addr_foreach(struct net_if *iface, net_if_ip_addr_cb_t cb, void *user_data)
Go through all IPv6 addresses on a network interface and call callback for each used address.
static void net_if_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit)
Set the default IPv6 hop limit of a given interface.
Definition net_if.h:2065
enum net_verdict net_if_try_send_data(struct net_if *iface, struct net_pkt *pkt, k_timeout_t timeout)
Try sending a packet through a net iface.
int net_if_get_name(struct net_if *iface, char *buf, int len)
Get network interface name.
static const struct net_in6_addr * net_if_ipv6_select_src_addr(struct net_if *iface, const struct net_in6_addr *dst)
Get a IPv6 source address that should be used when sending network data to destination.
Definition net_if.h:2253
static void net_if_nbr_reachability_hint(struct net_if *iface, const struct net_in6_addr *ipv6_addr)
Provide a reachability hint for IPv6 Neighbor Discovery.
Definition net_if.h:1347
void(* net_if_timestamp_callback_t)(struct net_pkt *pkt)
Define callback that is called after a network packet has been timestamped.
Definition net_if.h:3200
static uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
Get IPv6 hop limit specified for a given interface.
Definition net_if.h:2048
void net_if_carrier_off(struct net_if *iface)
Underlying network device has lost the carrier (cable disconnected).
void net_if_ipv6_prefix_set_timer(struct net_if_ipv6_prefix *prefix, uint32_t lifetime)
Set the prefix lifetime timer.
void net_if_unregister_link_cb(struct net_if_link_cb *link)
Unregister a link callback.
bool net_if_ipv4_router_rm(struct net_if_router *router)
Remove IPv4 router from the system.
static bool net_if_is_ip_offloaded(struct net_if *iface)
Return the IP offload status.
Definition net_if.h:1124
bool net_if_ipv6_maddr_rm(struct net_if *iface, const struct net_in6_addr *addr)
Remove an IPv6 multicast address from an interface.
static bool net_if_is_dormant(struct net_if *iface)
Check if the interface is dormant.
Definition net_if.h:3183
struct net_if * net_if_get_first_wifi(void)
Get first Wi-Fi network interface.
struct net_in_addr * net_if_ipv4_get_ll(struct net_if *iface, enum net_addr_state addr_state)
Get a IPv4 link local address in a given state.
bool net_if_is_ethernet(struct net_if *iface)
Check if the network interface is cabled ethernet.
uint8_t net_if_ipv4_get_mcast_ttl(struct net_if *iface)
Get IPv4 multicast time-to-live value specified for a given interface.
struct net_if_mcast_addr * net_if_ipv4_maddr_add(struct net_if *iface, const struct net_in_addr *addr)
Add a IPv4 multicast address to an interface.
void(* net_if_ip_maddr_cb_t)(struct net_if *iface, struct net_if_mcast_addr *maddr, void *user_data)
Callback used while iterating over network interface multicast IP addresses.
Definition net_if.h:1733
struct net_if * net_if_get_by_index(int index)
Get interface according to index.
enum net_verdict net_if_recv_data(struct net_if *iface, struct net_pkt *pkt)
Input a packet through a net iface.
struct net_if * net_if_get_first_by_type(const struct net_l2 *l2)
Get the first network interface according to its type.
struct net_in_addr * net_if_ipv4_get_global_addr(struct net_if *iface, enum net_addr_state addr_state)
Get a IPv4 global address in a given state.
static void net_if_set_mtu(struct net_if *iface, uint16_t mtu)
Set an network interface's MTU.
Definition net_if.h:1458
struct net_in6_addr * net_if_ipv6_get_ll(struct net_if *iface, enum net_addr_state addr_state)
Get a IPv6 link local address in a given state.
uint8_t net_if_ipv4_get_ttl(struct net_if *iface)
Get IPv4 time-to-live value specified for a given interface.
static bool net_if_is_up(struct net_if *iface)
Check if interface is up and running.
Definition net_if.h:3083
struct net_if_addr * net_if_ipv4_addr_add(struct net_if *iface, const struct net_in_addr *addr, enum net_addr_type addr_type, uint32_t vlifetime)
Add a IPv4 address to an interface.
static void net_if_ipv6_set_reachable_time(struct net_if_ipv6 *ipv6)
Set IPv6 reachable time for a given interface.
Definition net_if.h:2175
static enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
Send a packet through a net iface.
Definition net_if.h:1022
bool net_if_ipv4_set_gw_by_index(int index, const struct net_in_addr *gw)
Set IPv4 gateway for an interface index.
int net_if_config_ipv4_put(struct net_if *iface)
Release network interface IPv4 config.
void net_if_dormant_on(struct net_if *iface)
Mark interface as dormant.
struct net_in6_addr * net_if_ipv6_get_ll_addr(enum net_addr_state state, struct net_if **iface)
Return link local IPv6 address from the first interface that has a link local address matching give s...
int net_if_config_ipv6_put(struct net_if *iface)
Release network interface IPv6 config.
static struct net_if * net_if_ipv6_select_src_iface_addr(const struct net_in6_addr *dst, const struct net_in6_addr **src_addr)
Get a network interface that should be used when sending IPv6 network data to destination.
Definition net_if.h:2329
struct net_if_router * net_if_ipv6_router_add(struct net_if *iface, const struct net_in6_addr *addr, bool is_default, uint16_t router_lifetime)
Add IPv6 router to the system.
net_if_checksum_type
Type of checksum for which support in the interface will be queried.
Definition net_if.h:2958
void net_if_ipv6_dad_failed(struct net_if *iface, const struct net_in6_addr *addr)
Stop IPv6 Duplicate Address Detection (DAD) procedure if we find out that our IPv6 address is already...
void net_if_mcast_mon_register(struct net_if_mcast_monitor *mon, struct net_if *iface, net_if_mcast_callback_t cb)
Register a multicast monitor.
bool net_if_ipv4_addr_mask_cmp(struct net_if *iface, const struct net_in_addr *addr)
Check if the given IPv4 address belongs to local subnet.
void net_if_ipv4_set_mcast_ttl(struct net_if *iface, uint8_t ttl)
Set IPv4 multicast time-to-live value specified to a given interface.
static void net_if_start_dad(struct net_if *iface)
Start duplicate address detection procedure.
Definition net_if.h:1304
void net_if_foreach(net_if_cb_t cb, void *user_data)
Go through all the network interfaces and call callback for each interface.
struct net_if_ipv6_prefix * net_if_ipv6_prefix_lookup(struct net_if *iface, const struct net_in6_addr *addr, uint8_t len)
Check if this IPv6 prefix belongs to this interface.
struct net_if_ipv6_prefix * net_if_ipv6_prefix_get(struct net_if *iface, const struct net_in6_addr *addr)
Return prefix that corresponds to this IPv6 address.
static void net_if_unset_promisc(struct net_if *iface)
Set network interface into normal mode.
Definition net_if.h:3293
static void net_if_socket_offload_set(struct net_if *iface, net_socket_create_t socket_offload)
Set the function to create an offloaded socket.
Definition net_if.h:1221
static uint32_t net_if_ipv6_get_reachable_time(struct net_if *iface)
Get IPv6 reachable timeout specified for a given interface.
Definition net_if.h:2142
static bool net_if_is_promisc(struct net_if *iface)
Check if promiscuous mode is set or not.
Definition net_if.h:3310
static bool net_if_ipv4_maddr_is_joined(struct net_if_mcast_addr *addr)
Check if given multicast address is joined or not.
Definition net_if.h:2598
static void net_if_ipv6_prefix_set_lf(struct net_if_ipv6_prefix *prefix, bool is_infinite)
Set the infinite status of the prefix.
Definition net_if.h:1920
bool net_if_ipv4_set_netmask_by_addr(struct net_if *iface, const struct net_in_addr *addr, const struct net_in_addr *netmask)
Set IPv4 netmask for an interface index for a given address.
bool net_if_is_wifi(struct net_if *iface)
Check if the network interface supports Wi-Fi.
bool net_if_ipv4_set_netmask_by_addr_by_index(int index, const struct net_in_addr *addr, const struct net_in_addr *netmask)
Set IPv4 netmask for an interface index for a given address.
void net_if_unregister_timestamp_cb(struct net_if_timestamp_cb *handle)
Unregister a timestamp callback.
bool net_if_ipv4_maddr_rm(struct net_if *iface, const struct net_in_addr *addr)
Remove an IPv4 multicast address from an interface.
void net_if_register_link_cb(struct net_if_link_cb *link, net_if_link_callback_t cb)
Register a link callback.
void net_if_call_link_cb(struct net_if *iface, struct net_linkaddr *lladdr, int status)
Call a link callback function.
int net_if_ipv6_addr_lookup_by_index(const struct net_in6_addr *addr)
Check if this IPv6 address belongs to one of the interface indices.
void net_if_ipv6_router_update_lifetime(struct net_if_router *router, uint16_t lifetime)
Update validity lifetime time of a router.
void net_if_ipv4_addr_foreach(struct net_if *iface, net_if_ip_addr_cb_t cb, void *user_data)
Go through all IPv4 addresses on a network interface and call callback for each used address.
struct net_in_addr net_if_ipv4_get_netmask_by_addr(struct net_if *iface, const struct net_in_addr *addr)
Get IPv4 netmask related to an address of an interface.
static void net_if_stop_rs(struct net_if *iface)
Stop neighbor discovery.
Definition net_if.h:1326
uint32_t net_if_ipv6_calc_reachable_time(struct net_if_ipv6 *ipv6)
Calculate next reachable time value for IPv6 reachable time.
static void net_if_ipv6_set_base_reachable_time(struct net_if *iface, uint32_t reachable_time)
Set IPv6 reachable time for a given interface.
Definition net_if.h:2115
struct net_if * net_if_select_src_iface(const struct net_sockaddr *dst)
Get a network interface that should be used when sending IPv6 or IPv4 network data to destination.
void(* net_if_ip_addr_cb_t)(struct net_if *iface, struct net_if_addr *addr, void *user_data)
Callback used while iterating over network interface IP addresses.
Definition net_if.h:1689
void net_if_ipv6_maddr_foreach(struct net_if *iface, net_if_ip_maddr_cb_t cb, void *user_data)
Go through all IPv6 multicast addresses on a network interface and call callback for each used addres...
struct net_if_mcast_addr * net_if_ipv4_maddr_lookup(const struct net_in_addr *addr, struct net_if **iface)
Check if this IPv4 multicast address belongs to a specific interface or one of the interfaces.
static bool net_if_flag_test_and_clear(struct net_if *iface, enum net_if_flag value)
Test and clear a value in network interface flags.
Definition net_if.h:891
void net_if_start_rs(struct net_if *iface)
Start neighbor discovery and send router solicitation message.
static int net_if_oper_state_change_time(struct net_if *iface, int64_t *change_time)
Get an operational state change time of an interface.
Definition net_if.h:983
static bool net_if_ipv6_maddr_is_joined(struct net_if_mcast_addr *addr)
Check if given multicast address is joined or not.
Definition net_if.h:1845
struct net_if_router * net_if_ipv6_router_find_default(struct net_if *iface, const struct net_in6_addr *addr)
Find default router for this IPv6 address.
static bool net_if_need_calc_rx_checksum(struct net_if *iface, enum net_if_checksum_type chksum_type)
Check if received network packet checksum calculation can be avoided or not.
Definition net_if.h:2995
void(* net_if_cb_t)(struct net_if *iface, void *user_data)
Callback used while iterating over network interfaces.
Definition net_if.h:3056
struct net_if_router * net_if_ipv6_router_lookup(struct net_if *iface, const struct net_in6_addr *addr)
Check if IPv6 address is one of the routers configured in the system.
static uint16_t net_if_get_mtu(struct net_if *iface)
Get an network interface's MTU.
Definition net_if.h:1441
bool net_if_ipv6_addr_rm(struct net_if *iface, const struct net_in6_addr *addr)
Remove an IPv6 address from an interface.
void net_if_ipv6_maddr_leave(struct net_if *iface, struct net_if_mcast_addr *addr)
Mark a given multicast address to be left.
void net_if_mcast_mon_unregister(struct net_if_mcast_monitor *mon)
Unregister a multicast monitor.
struct net_if_mcast_addr * net_if_ipv6_maddr_lookup(const struct net_in6_addr *addr, struct net_if **iface)
Check if this IPv6 multicast address belongs to a specific interface or one of the interfaces.
bool net_if_ipv6_addr_add_by_index(int index, const struct net_in6_addr *addr, enum net_addr_type addr_type, uint32_t vlifetime)
Add a IPv6 address to an interface by index.
static void net_if_ipv6_set_retrans_timer(struct net_if *iface, uint32_t retrans_timer)
Set IPv6 retransmit timer for a given interface.
Definition net_if.h:2194
void net_if_call_timestamp_cb(struct net_pkt *pkt)
Call a timestamp callback function.
struct net_if * net_if_lookup_by_dev(const struct device *dev)
Find an interface from it's related device.
bool net_if_ipv6_addr_rm_by_index(int index, const struct net_in6_addr *addr)
Remove an IPv6 address from an interface by index.
void net_if_router_rm(struct net_if_router *router)
Remove a router from the system.
static uint32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)
Get IPv6 retransmit timer specified for a given interface.
Definition net_if.h:2220
net_if_oper_state
Network interface operational status (RFC 2863).
Definition net_if.h:310
static bool net_if_flag_is_set(struct net_if *iface, enum net_if_flag value)
Check if a value in network interface flags is set.
Definition net_if.h:911
static struct net_if_config * net_if_get_config(struct net_if *iface)
Return network configuration for this network interface.
Definition net_if.h:1287
void net_if_ipv4_maddr_join(struct net_if *iface, struct net_if_mcast_addr *addr)
Mark a given multicast address to be joined.
struct net_if_addr * net_if_ipv6_addr_lookup_by_iface(struct net_if *iface, const struct net_in6_addr *addr)
Check if this IPv6 address belongs to this specific interfaces.
static void net_if_addr_set_lf(struct net_if_addr *ifaddr, bool is_infinite)
Set the infinite status of the network interface address.
Definition net_if.h:1476
net_if_flag
Network interface flags.
Definition net_if.h:254
int net_if_ipv4_addr_lookup_by_index(const struct net_in_addr *addr)
Check if this IPv4 address belongs to one of the interface indices.
static const struct net_in_addr * net_if_ipv4_select_src_addr(struct net_if *iface, const struct net_in_addr *dst)
Get a IPv4 source address that should be used when sending network data to destination.
Definition net_if.h:2773
void net_if_ipv4_maddr_foreach(struct net_if *iface, net_if_ip_maddr_cb_t cb, void *user_data)
Go through all IPv4 multicast addresses on a network interface and call callback for each used addres...
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition net_if.h:1083
bool net_if_is_offloaded(struct net_if *iface)
Return offload status of a given network interface.
int(* net_socket_create_t)(int, int, int)
A function prototype to create an offloaded socket.
Definition net_if.h:651
void net_if_ipv6_addr_update_lifetime(struct net_if_addr *ifaddr, uint32_t vlifetime)
Update validity lifetime time of an IPv6 address.
static void net_if_offload_set(struct net_if *iface, struct net_offload *offload)
Set the IP offload plugin.
Definition net_if.h:1175
static bool net_if_is_socket_offloaded(struct net_if *iface)
Return the socket offload status.
Definition net_if.h:1198
struct net_in6_addr * net_if_ipv6_get_global_addr(enum net_addr_state state, struct net_if **iface)
Return global IPv6 address from the first interface that has a global IPv6 address matching the given...
static void net_if_ipv6_set_mcast_hop_limit(struct net_if *iface, uint8_t hop_limit)
Set the default IPv6 multicast hop limit of a given interface.
Definition net_if.h:2101
struct net_if * net_if_get_wifi_sap(void)
Get first Wi-Fi network Soft-AP interface.
static int net_if_set_promisc(struct net_if *iface)
Set network interface into promiscuous mode.
Definition net_if.h:3277
static const struct net_l2 * net_if_l2(struct net_if *iface)
Get a pointer to the interface L2.
Definition net_if.h:1037
static net_socket_create_t net_if_socket_offload(struct net_if *iface)
Return the function to create an offloaded socket.
Definition net_if.h:1245
static void net_if_flag_clear(struct net_if *iface, enum net_if_flag value)
Clear a value in network interface flags.
Definition net_if.h:871
struct net_if_router * net_if_ipv4_router_find_default(struct net_if *iface, const struct net_in_addr *addr)
Find default router for this IPv4 address.
@ NET_IF_CHECKSUM_IPV4_ICMP
Interface supports checksum calculation for ICMP4 payload in IPv4.
Definition net_if.h:2968
@ NET_IF_CHECKSUM_IPV6_TCP
Interface supports checksum calculation for TCP payload in IPv6.
Definition net_if.h:2972
@ NET_IF_CHECKSUM_IPV6_UDP
Interface supports checksum calculation for UDP payload in IPv6.
Definition net_if.h:2975
@ NET_IF_CHECKSUM_IPV4_HEADER
Interface supports IP version 4 header checksum calculation.
Definition net_if.h:2960
@ NET_IF_CHECKSUM_IPV4_TCP
Interface supports checksum calculation for TCP payload in IPv4.
Definition net_if.h:2962
@ NET_IF_CHECKSUM_IPV6_HEADER
Interface supports IP version 6 header checksum calculation.
Definition net_if.h:2970
@ NET_IF_CHECKSUM_IPV6_ICMP
Interface supports checksum calculation for ICMP6 payload in IPv6.
Definition net_if.h:2978
@ NET_IF_CHECKSUM_IPV4_UDP
Interface supports checksum calculation for UDP payload in IPv4.
Definition net_if.h:2965
@ NET_IF_OPER_TESTING
Training mode.
Definition net_if.h:315
@ NET_IF_OPER_DORMANT
Waiting external action.
Definition net_if.h:316
@ NET_IF_OPER_UP
Interface is up.
Definition net_if.h:317
@ NET_IF_OPER_NOTPRESENT
Hardware missing.
Definition net_if.h:312
@ NET_IF_OPER_UNKNOWN
Initial (unknown) value.
Definition net_if.h:311
@ NET_IF_OPER_DOWN
Interface is down.
Definition net_if.h:313
@ NET_IF_OPER_LOWERLAYERDOWN
Lower layer interface is down.
Definition net_if.h:314
@ NET_IF_NO_AUTO_START
Do not bring the interface immediately up after initialization.
Definition net_if.h:268
@ NET_IF_IPV6_NO_MLD
IPv6 Multicast Listener Discovery disabled.
Definition net_if.h:298
@ NET_IF_POINTOPOINT
Interface is pointopoint.
Definition net_if.h:259
@ NET_IF_IPV6_NO_ND
IPv6 Neighbor Discovery disabled.
Definition net_if.h:295
@ NET_IF_FORWARD_MULTICASTS
Flag defines if received multicasts of other interface are forwarded on this interface.
Definition net_if.h:277
@ NET_IF_IPV4
Interface supports IPv4.
Definition net_if.h:280
@ NET_IF_PROMISC
Interface is in promiscuous mode.
Definition net_if.h:262
@ NET_IF_DORMANT
Driver signals dormant.
Definition net_if.h:292
@ NET_IF_SUSPENDED
Power management specific: interface is being suspended.
Definition net_if.h:271
@ NET_IF_IPV6
Interface supports IPv6.
Definition net_if.h:283
@ NET_IF_UP
Interface is admin up.
Definition net_if.h:256
@ NET_IF_LOWER_UP
Driver signals L1 is up.
Definition net_if.h:289
@ NET_IF_RUNNING
Interface up and running (ready to receive and transmit).
Definition net_if.h:286
@ NET_IF_NO_TX_LOCK
Mutex locking on TX data path disabled on the interface.
Definition net_if.h:301
net_link_type
Type of the link address.
Definition net_linkaddr.h:58
static int net_linkaddr_create(struct net_linkaddr *lladdr, const uint8_t *addr, uint8_t len, enum net_link_type type)
Create a link address structure.
Definition net_linkaddr.h:179
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:52
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:42
#define IF_ENABLED(_flag, _code)
Insert code if _flag is defined and equals 1.
Definition util_macro.h:278
#define EINVAL
Invalid argument.
Definition errno.h:60
#define ENOTSUP
Unsupported value.
Definition errno.h:114
#define EPERM
Not owner.
Definition errno.h:39
Hostname configuration definitions.
IPv4 Autoconfiguration.
net_ipv4_autoconf_state
Current state of IPv4 Autoconfiguration.
Definition ipv4_autoconf.h:15
Network core definitions.
IPv6 and IPv4 definitions.
Public API for network L2 interface.
Public API for network link address.
Network statistics.
Network timer with wrap around.
flags
Definition parser.h:97
state
Definition parser_state.h:29
Header file for the single-linked list API.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT64_TYPE__ int64_t
Definition stdint.h:75
__INT16_TYPE__ int16_t
Definition stdint.h:73
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Kernel FIFO structure.
Definition kernel.h:2935
Kernel mutex structure.
Definition kernel.h:3477
Semaphore structure.
Definition kernel.h:3703
Thread Structure.
Definition thread.h:259
Kernel timeout type.
Definition clock.h:65
Kernel timepoint type.
Definition clock.h:291
DHCPv6 client configuration parameters.
Definition dhcpv6.h:63
Network Interface unicast IPv4 address and netmask.
Definition net_if.h:471
struct net_in_addr netmask
Netmask.
Definition net_if.h:475
struct net_if_addr ipv4
IPv4 address.
Definition net_if.h:473
Network Interface unicast IP addresses.
Definition net_if.h:56
struct net_addr address
IP address.
Definition net_if.h:58
uint8_t is_mesh_local
Is this IP address usage limited to the subnet (mesh) or not.
Definition net_if.h:143
uint8_t is_temporary
Is this IP address temporary and generated for example by IPv6 privacy extension (RFC 8981).
Definition net_if.h:148
enum net_addr_state addr_state
What is the current state of the address.
Definition net_if.h:73
uint8_t is_infinite
Is the IP address valid forever.
Definition net_if.h:137
atomic_t atomic_ref
Reference counter.
Definition net_if.h:63
uint8_t is_added
Was this address added or not.
Definition net_if.h:151
enum net_addr_type addr_type
How the IP address was set.
Definition net_if.h:70
uint8_t is_used
Is this IP address used or not.
Definition net_if.h:140
IP and other configuration related data for network interface.
Definition net_if.h:584
Network Interface Device structure.
Definition net_if.h:669
Network interface IP address configuration.
Definition net_if.h:571
IPv4 configuration.
Definition net_if.h:479
uint8_t mcast_ttl
IPv4 time-to-live for multicast packets.
Definition net_if.h:493
struct net_if_addr_ipv4 unicast[NET_IF_MAX_IPV4_ADDR]
Unicast IP addresses.
Definition net_if.h:481
struct net_in_addr gw
Gateway.
Definition net_if.h:487
uint8_t ttl
IPv4 time-to-live.
Definition net_if.h:490
struct net_if_mcast_addr mcast[NET_IF_MAX_IPV4_MADDR]
Multicast IP addresses.
Definition net_if.h:484
Network Interface IPv6 prefixes.
Definition net_if.h:198
struct net_if * iface
Backpointer to network interface where this prefix is used.
Definition net_if.h:206
uint8_t is_infinite
Is the IP prefix valid forever.
Definition net_if.h:212
uint8_t len
Prefix length.
Definition net_if.h:209
uint8_t is_used
Is this prefix used or not.
Definition net_if.h:215
struct net_timeout lifetime
Prefix lifetime.
Definition net_if.h:200
struct net_in6_addr prefix
IPv6 prefix.
Definition net_if.h:203
IPv6 configuration.
Definition net_if.h:337
struct net_if_ipv6_prefix prefix[NET_IF_MAX_IPV6_PREFIX]
Prefixes.
Definition net_if.h:345
uint32_t base_reachable_time
Default reachable time (RFC 4861, page 52).
Definition net_if.h:348
uint8_t hop_limit
IPv6 hop limit.
Definition net_if.h:386
struct net_if_mcast_addr mcast[NET_IF_MAX_IPV6_MADDR]
Multicast IP addresses.
Definition net_if.h:342
uint32_t retrans_timer
Retransmit timer (RFC 4861, page 52).
Definition net_if.h:354
struct net_if_addr unicast[NET_IF_MAX_IPV6_ADDR]
Unicast IP addresses.
Definition net_if.h:339
uint8_t mcast_hop_limit
IPv6 multicast hop limit.
Definition net_if.h:389
uint32_t reachable_time
Reachable time (RFC 4861, page 20).
Definition net_if.h:351
Network Interface multicast IP addresses.
Definition net_if.h:161
struct net_addr address
IP address.
Definition net_if.h:163
uint8_t is_joined
Did we join to this group.
Definition net_if.h:188
sys_snode_t rejoin_node
Rejoining multicast groups list node.
Definition net_if.h:171
atomic_t atomic_ref
Reference counter.
Definition net_if.h:168
uint8_t is_used
Is this multicast IP address used or not.
Definition net_if.h:185
Multicast monitor handler struct.
Definition net_if.h:1789
sys_snode_t node
Node information for the slist.
Definition net_if.h:1791
net_if_mcast_callback_t cb
Multicast callback.
Definition net_if.h:1797
struct net_if * iface
Network interface.
Definition net_if.h:1794
Information about routers in the system.
Definition net_if.h:225
struct net_if * iface
Network interface the router is connected to.
Definition net_if.h:233
uint8_t is_default
Is default router.
Definition net_if.h:245
uint16_t lifetime
Router lifetime.
Definition net_if.h:239
uint8_t is_infinite
Is the router valid forever.
Definition net_if.h:248
uint8_t is_used
Is this router used or not.
Definition net_if.h:242
struct net_addr address
IP address.
Definition net_if.h:230
sys_snode_t node
Slist lifetime timer node.
Definition net_if.h:227
uint32_t life_start
Router life timer start.
Definition net_if.h:236
Timestamp callback handler struct.
Definition net_if.h:3210
sys_snode_t node
Node information for the slist.
Definition net_if.h:3212
struct net_if * iface
Net interface for which the callback is needed.
Definition net_if.h:3222
struct net_pkt * pkt
Packet for which the callback is needed.
Definition net_if.h:3217
net_if_timestamp_callback_t cb
Timestamp callback.
Definition net_if.h:3225
Network Interface structure.
Definition net_if.h:733
IPv6 address struct.
Definition net_ip.h:144
IPv4 address struct.
Definition net_ip.h:156
Network L2 structure.
Definition net_l2.h:58
Hardware link address structure.
Definition net_linkaddr.h:83
Network packet.
Definition net_pkt.h:119
Generic sockaddr struct.
Definition net_ip.h:449
All network statistics in one struct.
Definition net_stats.h:423
Generic struct for handling network timeouts.
Definition net_timeout.h:57
Network traffic class.
Definition net_if.h:628
k_thread_stack_t * stack
Stack for this handler.
Definition net_if.h:642
struct k_thread handler
Traffic class handler thread.
Definition net_if.h:639
struct k_fifo fifo
Fifo for handling this Tx or Rx packet.
Definition net_if.h:630
Prometheus collector definition.
Definition collector.h:50
Type used to represent a Prometheus metric base.
Definition metric.h:47
Iterable sections helpers.