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 * @ingroup networking
19 * @{
20 */
21
22 #include <zephyr/device.h>
23 #include <zephyr/sys/slist.h>
24 #include <zephyr/sys/iterable_sections.h>
25 #include <zephyr/net/net_core.h>
26 #include <zephyr/net/hostname.h>
27 #include <zephyr/net/net_linkaddr.h>
28 #include <zephyr/net/net_ip.h>
29 #include <zephyr/net/net_l2.h>
30 #include <zephyr/net/net_stats.h>
31 #include <zephyr/net/net_timeout.h>
32
33 #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
34 #include <zephyr/net/dhcpv4.h>
35 #endif
36 #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
37 #include <zephyr/net/ipv4_autoconf.h>
38 #endif
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /**
45 * @brief Network Interface unicast IP addresses
46 *
47 * Stores the unicast IP addresses assigned to this network interface.
48 */
49 struct net_if_addr {
50 /** IP address */
51 struct net_addr address;
52
53 #if defined(CONFIG_NET_NATIVE_IPV6)
54 struct net_timeout lifetime;
55 #endif
56
57 #if defined(CONFIG_NET_IPV6_DAD) && defined(CONFIG_NET_NATIVE_IPV6)
58 /** Duplicate address detection (DAD) timer */
59 sys_snode_t dad_node;
60 uint32_t dad_start;
61 #endif
62 /** How the IP address was set */
63 enum net_addr_type addr_type;
64
65 /** What is the current state of the address */
66 enum net_addr_state addr_state;
67
68 #if defined(CONFIG_NET_IPV6_DAD) && defined(CONFIG_NET_NATIVE_IPV6)
69 /** How many times we have done DAD */
70 uint8_t dad_count;
71 #endif
72
73 /** Is the IP address valid forever */
74 uint8_t is_infinite : 1;
75
76 /** Is this IP address used or not */
77 uint8_t is_used : 1;
78
79 /** Is this IP address usage limited to the subnet (mesh) or not */
80 uint8_t is_mesh_local : 1;
81
82 uint8_t _unused : 5;
83 };
84
85 /**
86 * @brief Network Interface multicast IP addresses
87 *
88 * Stores the multicast IP addresses assigned to this network interface.
89 */
90 struct net_if_mcast_addr {
91 /** IP address */
92 struct net_addr address;
93
94 /** Is this multicast IP address used or not */
95 uint8_t is_used : 1;
96
97 /** Did we join to this group */
98 uint8_t is_joined : 1;
99
100 uint8_t _unused : 6;
101 };
102
103 /**
104 * @brief Network Interface IPv6 prefixes
105 *
106 * Stores the multicast IP addresses assigned to this network interface.
107 */
108 struct net_if_ipv6_prefix {
109 /** Prefix lifetime */
110 struct net_timeout lifetime;
111
112 /** IPv6 prefix */
113 struct in6_addr prefix;
114
115 /** Backpointer to network interface where this prefix is used */
116 struct net_if *iface;
117
118 /** Prefix length */
119 uint8_t len;
120
121 /** Is the IP prefix valid forever */
122 uint8_t is_infinite : 1;
123
124 /** Is this prefix used or not */
125 uint8_t is_used : 1;
126
127 uint8_t _unused : 6;
128 };
129
130 /**
131 * @brief Information about routers in the system.
132 *
133 * Stores the router information.
134 */
135 struct net_if_router {
136 /** Slist lifetime timer node */
137 sys_snode_t node;
138
139 /** IP address */
140 struct net_addr address;
141
142 /** Network interface the router is connected to */
143 struct net_if *iface;
144
145 /** Router life timer start */
146 uint32_t life_start;
147
148 /** Router lifetime */
149 uint16_t lifetime;
150
151 /** Is this router used or not */
152 uint8_t is_used : 1;
153
154 /** Is default router */
155 uint8_t is_default : 1;
156
157 /** Is the router valid forever */
158 uint8_t is_infinite : 1;
159
160 uint8_t _unused : 5;
161 };
162
163 /** Network interface flags. */
164 enum net_if_flag {
165 /** Interface is admin up. */
166 NET_IF_UP,
167
168 /** Interface is pointopoint */
169 NET_IF_POINTOPOINT,
170
171 /** Interface is in promiscuous mode */
172 NET_IF_PROMISC,
173
174 /** Do not start the interface immediately after initialization.
175 * This requires that either the device driver or some other entity
176 * will need to manually take the interface up when needed.
177 * For example for Ethernet this will happen when the driver calls
178 * the net_eth_carrier_on() function.
179 */
180 NET_IF_NO_AUTO_START,
181
182 /** Power management specific: interface is being suspended */
183 NET_IF_SUSPENDED,
184
185 /** Flag defines if received multicasts of other interface are
186 * forwarded on this interface. This activates multicast
187 * routing / forwarding for this interface.
188 */
189 NET_IF_FORWARD_MULTICASTS,
190
191 /** Interface supports IPv4 */
192 NET_IF_IPV4,
193
194 /** Interface supports IPv6 */
195 NET_IF_IPV6,
196
197 /** Interface up and running (ready to receive and transmit). */
198 NET_IF_RUNNING,
199
200 /** Driver signals L1 is up. */
201 NET_IF_LOWER_UP,
202
203 /** Driver signals dormant. */
204 NET_IF_DORMANT,
205
206 /** IPv6 Neighbor Discovery disabled. */
207 NET_IF_IPV6_NO_ND,
208
209 /** IPv6 Multicast Listener Discovery disabled. */
210 NET_IF_IPV6_NO_MLD,
211
212 /** @cond INTERNAL_HIDDEN */
213 /* Total number of flags - must be at the end of the enum */
214 NET_IF_NUM_FLAGS
215 /** @endcond */
216 };
217
218 /** Network interface operational status (RFC 2863). */
219 enum net_if_oper_state {
220 NET_IF_OPER_UNKNOWN,
221 NET_IF_OPER_NOTPRESENT,
222 NET_IF_OPER_DOWN,
223 NET_IF_OPER_LOWERLAYERDOWN,
224 NET_IF_OPER_TESTING,
225 NET_IF_OPER_DORMANT,
226 NET_IF_OPER_UP,
227 } __packed;
228
229 #if defined(CONFIG_NET_OFFLOAD)
230 struct net_offload;
231 #endif /* CONFIG_NET_OFFLOAD */
232
233 /** @cond INTERNAL_HIDDEN */
234 #if defined(CONFIG_NET_NATIVE_IPV6)
235 #define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT
236 #define NET_IF_MAX_IPV6_MADDR CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT
237 #define NET_IF_MAX_IPV6_PREFIX CONFIG_NET_IF_IPV6_PREFIX_COUNT
238 #else
239 #define NET_IF_MAX_IPV6_ADDR 0
240 #define NET_IF_MAX_IPV6_MADDR 0
241 #define NET_IF_MAX_IPV6_PREFIX 0
242 #endif
243 /* @endcond */
244
245 struct net_if_ipv6 {
246 /** Unicast IP addresses */
247 struct net_if_addr unicast[NET_IF_MAX_IPV6_ADDR];
248
249 /** Multicast IP addresses */
250 struct net_if_mcast_addr mcast[NET_IF_MAX_IPV6_MADDR];
251
252 /** Prefixes */
253 struct net_if_ipv6_prefix prefix[NET_IF_MAX_IPV6_PREFIX];
254
255 /** Default reachable time (RFC 4861, page 52) */
256 uint32_t base_reachable_time;
257
258 /** Reachable time (RFC 4861, page 20) */
259 uint32_t reachable_time;
260
261 /** Retransmit timer (RFC 4861, page 52) */
262 uint32_t retrans_timer;
263 #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
264 /** Router solicitation timer node */
265 sys_snode_t rs_node;
266
267 /* RS start time */
268 uint32_t rs_start;
269
270 /** RS count */
271 uint8_t rs_count;
272 #endif
273
274 /** IPv6 hop limit */
275 uint8_t hop_limit;
276 };
277
278 /** @cond INTERNAL_HIDDEN */
279 #if defined(CONFIG_NET_NATIVE_IPV4)
280 #define NET_IF_MAX_IPV4_ADDR CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT
281 #define NET_IF_MAX_IPV4_MADDR CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT
282 #else
283 #define NET_IF_MAX_IPV4_ADDR 0
284 #define NET_IF_MAX_IPV4_MADDR 0
285 #endif
286 /** @endcond */
287
288 struct net_if_ipv4 {
289 /** Unicast IP addresses */
290 struct net_if_addr unicast[NET_IF_MAX_IPV4_ADDR];
291
292 /** Multicast IP addresses */
293 struct net_if_mcast_addr mcast[NET_IF_MAX_IPV4_MADDR];
294
295 /** Gateway */
296 struct in_addr gw;
297
298 /** Netmask */
299 struct in_addr netmask;
300
301 /** IPv4 time-to-live */
302 uint8_t ttl;
303 };
304
305 #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
306 struct net_if_dhcpv4 {
307 /** Used for timer lists */
308 sys_snode_t node;
309
310 /** Timer start */
311 int64_t timer_start;
312
313 /** Time for INIT, DISCOVER, REQUESTING, RENEWAL */
314 uint32_t request_time;
315
316 uint32_t xid;
317
318 /** IP address Lease time */
319 uint32_t lease_time;
320
321 /** IP address Renewal time */
322 uint32_t renewal_time;
323
324 /** IP address Rebinding time */
325 uint32_t rebinding_time;
326
327 /** Server ID */
328 struct in_addr server_id;
329
330 /** Requested IP addr */
331 struct in_addr requested_ip;
332
333 /**
334 * DHCPv4 client state in the process of network
335 * address allocation.
336 */
337 enum net_dhcpv4_state state;
338
339 /** Number of attempts made for REQUEST and RENEWAL messages */
340 uint8_t attempts;
341
342 /** The address of the server the request is sent to */
343 struct in_addr request_server_addr;
344
345 /** The source address of a received DHCP message */
346 struct in_addr response_src_addr;
347 };
348 #endif /* CONFIG_NET_DHCPV4 */
349
350 #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
351 struct net_if_ipv4_autoconf {
352 /** Used for timer lists */
353 sys_snode_t node;
354
355 /** Backpointer to correct network interface */
356 struct net_if *iface;
357
358 /** Timer start */
359 int64_t timer_start;
360
361 /** Time for INIT, DISCOVER, REQUESTING, RENEWAL */
362 uint32_t timer_timeout;
363
364 /** Current IP addr */
365 struct in_addr current_ip;
366
367 /** Requested IP addr */
368 struct in_addr requested_ip;
369
370 /** IPV4 Autoconf state in the process of network address allocation.
371 */
372 enum net_ipv4_autoconf_state state;
373
374 /** Number of sent probe requests */
375 uint8_t probe_cnt;
376
377 /** Number of sent announcements */
378 uint8_t announce_cnt;
379
380 /** Incoming conflict count */
381 uint8_t conflict_cnt;
382 };
383 #endif /* CONFIG_NET_IPV4_AUTO */
384
385 /** @cond INTERNAL_HIDDEN */
386 /* We always need to have at least one IP config */
387 #define NET_IF_MAX_CONFIGS 1
388 /** @endcond */
389
390 /**
391 * @brief Network interface IP address configuration.
392 */
393 struct net_if_ip {
394 #if defined(CONFIG_NET_NATIVE_IPV6)
395 struct net_if_ipv6 *ipv6;
396 #endif /* CONFIG_NET_IPV6 */
397
398 #if defined(CONFIG_NET_NATIVE_IPV4)
399 struct net_if_ipv4 *ipv4;
400 #endif /* CONFIG_NET_IPV4 */
401 };
402
403 /**
404 * @brief IP and other configuration related data for network interface.
405 */
406 struct net_if_config {
407 #if defined(CONFIG_NET_IP)
408 /** IP address configuration setting */
409 struct net_if_ip ip;
410 #endif
411
412 #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
413 struct net_if_dhcpv4 dhcpv4;
414 #endif /* CONFIG_NET_DHCPV4 */
415
416 #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
417 struct net_if_ipv4_autoconf ipv4auto;
418 #endif /* CONFIG_NET_IPV4_AUTO */
419
420 #if defined(CONFIG_NET_L2_VIRTUAL)
421 /**
422 * This list keeps track of the virtual network interfaces
423 * that are attached to this network interface.
424 */
425 sys_slist_t virtual_interfaces;
426 #endif /* CONFIG_NET_L2_VIRTUAL */
427 };
428
429 /**
430 * @brief Network traffic class.
431 *
432 * Traffic classes are used when sending or receiving data that is classified
433 * with different priorities. So some traffic can be marked as high priority
434 * and it will be sent or received first. Each network packet that is
435 * transmitted or received goes through a fifo to a thread that will transmit
436 * it.
437 */
438 struct net_traffic_class {
439 /** Fifo for handling this Tx or Rx packet */
440 struct k_fifo fifo;
441
442 /** Traffic class handler thread */
443 struct k_thread handler;
444
445 /** Stack for this handler */
446 k_thread_stack_t *stack;
447 };
448
449 /**
450 * @typedef net_socket_create_t
451
452 * @brief A function prototype to create an offloaded socket. The prototype is
453 * compatible with socket() function.
454 */
455 typedef int (*net_socket_create_t)(int, int, int);
456
457 /**
458 * @brief Network Interface Device structure
459 *
460 * Used to handle a network interface on top of a device driver instance.
461 * There can be many net_if_dev instance against the same device.
462 *
463 * Such interface is mainly to be used by the link layer, but is also tight
464 * to a network context: it then makes the relation with a network context
465 * and the network device.
466 *
467 * Because of the strong relationship between a device driver and such
468 * network interface, each net_if_dev should be instantiated by
469 */
470 struct net_if_dev {
471 /** The actually device driver instance the net_if is related to */
472 const struct device *dev;
473
474 /** Interface's L2 layer */
475 const struct net_l2 * const l2;
476
477 /** Interface's private L2 data pointer */
478 void *l2_data;
479
480 /* For internal use */
481 ATOMIC_DEFINE(flags, NET_IF_NUM_FLAGS);
482
483 /** The hardware link address */
484 struct net_linkaddr link_addr;
485
486 #if defined(CONFIG_NET_OFFLOAD)
487 /** TCP/IP Offload functions.
488 * If non-NULL, then the TCP/IP stack is located
489 * in the communication chip that is accessed via this
490 * network interface.
491 */
492 struct net_offload *offload;
493 #endif /* CONFIG_NET_OFFLOAD */
494
495 /** The hardware MTU */
496 uint16_t mtu;
497
498 #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
499 /** A function pointer to create an offloaded socket.
500 * If non-NULL, the interface is considered offloaded at socket level.
501 */
502 net_socket_create_t socket_offload;
503 #endif /* CONFIG_NET_SOCKETS_OFFLOAD */
504
505 /** RFC 2863 operational status */
506 enum net_if_oper_state oper_state;
507 };
508
509 /**
510 * @brief Network Interface structure
511 *
512 * Used to handle a network interface on top of a net_if_dev instance.
513 * There can be many net_if instance against the same net_if_dev instance.
514 *
515 */
516 struct net_if {
517 /** The net_if_dev instance the net_if is related to */
518 struct net_if_dev *if_dev;
519
520 #if defined(CONFIG_NET_STATISTICS_PER_INTERFACE)
521 /** Network statistics related to this network interface */
522 struct net_stats stats;
523 #endif /* CONFIG_NET_STATISTICS_PER_INTERFACE */
524
525 /** Network interface instance configuration */
526 struct net_if_config config;
527
528 #if defined(CONFIG_NET_POWER_MANAGEMENT)
529 /** Keep track of packets pending in traffic queues. This is
530 * needed to avoid putting network device driver to sleep if
531 * there are packets waiting to be sent.
532 */
533 int tx_pending;
534 #endif
535
536 struct k_mutex lock;
537 };
538
net_if_lock(struct net_if * iface)539 static inline void net_if_lock(struct net_if *iface)
540 {
541 NET_ASSERT(iface);
542
543 (void)k_mutex_lock(&iface->lock, K_FOREVER);
544 }
545
net_if_unlock(struct net_if * iface)546 static inline void net_if_unlock(struct net_if *iface)
547 {
548 NET_ASSERT(iface);
549
550 k_mutex_unlock(&iface->lock);
551 }
552
553 /**
554 * @brief Set a value in network interface flags
555 *
556 * @param iface Pointer to network interface
557 * @param value Flag value
558 */
net_if_flag_set(struct net_if * iface,enum net_if_flag value)559 static inline void net_if_flag_set(struct net_if *iface,
560 enum net_if_flag value)
561 {
562 NET_ASSERT(iface);
563 NET_ASSERT(iface->if_dev);
564
565 atomic_set_bit(iface->if_dev->flags, value);
566 }
567
568 /**
569 * @brief Test and set a value in network interface flags
570 *
571 * @param iface Pointer to network interface
572 * @param value Flag value
573 *
574 * @return true if the bit was set, false if it wasn't.
575 */
net_if_flag_test_and_set(struct net_if * iface,enum net_if_flag value)576 static inline bool net_if_flag_test_and_set(struct net_if *iface,
577 enum net_if_flag value)
578 {
579 NET_ASSERT(iface);
580 NET_ASSERT(iface->if_dev);
581
582 return atomic_test_and_set_bit(iface->if_dev->flags, value);
583 }
584
585 /**
586 * @brief Clear a value in network interface flags
587 *
588 * @param iface Pointer to network interface
589 * @param value Flag value
590 */
net_if_flag_clear(struct net_if * iface,enum net_if_flag value)591 static inline void net_if_flag_clear(struct net_if *iface,
592 enum net_if_flag value)
593 {
594 NET_ASSERT(iface);
595 NET_ASSERT(iface->if_dev);
596
597 atomic_clear_bit(iface->if_dev->flags, value);
598 }
599
600 /**
601 * @brief Test and clear a value in network interface flags
602 *
603 * @param iface Pointer to network interface
604 * @param value Flag value
605 *
606 * @return true if the bit was set, false if it wasn't.
607 */
net_if_flag_test_and_clear(struct net_if * iface,enum net_if_flag value)608 static inline bool net_if_flag_test_and_clear(struct net_if *iface,
609 enum net_if_flag value)
610 {
611 NET_ASSERT(iface);
612 NET_ASSERT(iface->if_dev);
613
614 return atomic_test_and_clear_bit(iface->if_dev->flags, value);
615 }
616
617 /**
618 * @brief Check if a value in network interface flags is set
619 *
620 * @param iface Pointer to network interface
621 * @param value Flag value
622 *
623 * @return True if the value is set, false otherwise
624 */
net_if_flag_is_set(struct net_if * iface,enum net_if_flag value)625 static inline bool net_if_flag_is_set(struct net_if *iface,
626 enum net_if_flag value)
627 {
628 NET_ASSERT(iface);
629 NET_ASSERT(iface->if_dev);
630
631 if (iface == NULL) {
632 return false;
633 }
634
635 return atomic_test_bit(iface->if_dev->flags, value);
636 }
637
638 /**
639 * @brief Set an operational state on an interface
640 *
641 * @param iface Pointer to network interface
642 * @param oper_state Operational state to set
643 *
644 * @return The new operational state of an interface
645 */
net_if_oper_state_set(struct net_if * iface,enum net_if_oper_state oper_state)646 static inline enum net_if_oper_state net_if_oper_state_set(
647 struct net_if *iface, enum net_if_oper_state oper_state)
648 {
649 NET_ASSERT(iface);
650 NET_ASSERT(iface->if_dev);
651
652 if (oper_state >= NET_IF_OPER_UNKNOWN && oper_state <= NET_IF_OPER_UP) {
653 iface->if_dev->oper_state = oper_state;
654 }
655
656 return iface->if_dev->oper_state;
657 }
658
659 /**
660 * @brief Get an operational state of an interface
661 *
662 * @param iface Pointer to network interface
663 *
664 * @return Operational state of an interface
665 */
net_if_oper_state(struct net_if * iface)666 static inline enum net_if_oper_state net_if_oper_state(struct net_if *iface)
667 {
668 NET_ASSERT(iface);
669 NET_ASSERT(iface->if_dev);
670
671 return iface->if_dev->oper_state;
672 }
673
674 /**
675 * @brief Send a packet through a net iface
676 *
677 * @param iface Pointer to a network interface structure
678 * @param pkt Pointer to a net packet to send
679 *
680 * return verdict about the packet
681 */
682 enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt);
683
684 /**
685 * @brief Get a pointer to the interface L2
686 *
687 * @param iface a valid pointer to a network interface structure
688 *
689 * @return a pointer to the iface L2
690 */
net_if_l2(struct net_if * iface)691 static inline const struct net_l2 *net_if_l2(struct net_if *iface)
692 {
693 if (!iface || !iface->if_dev) {
694 return NULL;
695 }
696
697 return iface->if_dev->l2;
698 }
699
700 /**
701 * @brief Input a packet through a net iface
702 *
703 * @param iface Pointer to a network interface structure
704 * @param pkt Pointer to a net packet to input
705 *
706 * @return verdict about the packet
707 */
708 enum net_verdict net_if_recv_data(struct net_if *iface, struct net_pkt *pkt);
709
710 /**
711 * @brief Get a pointer to the interface L2 private data
712 *
713 * @param iface a valid pointer to a network interface structure
714 *
715 * @return a pointer to the iface L2 data
716 */
net_if_l2_data(struct net_if * iface)717 static inline void *net_if_l2_data(struct net_if *iface)
718 {
719 NET_ASSERT(iface);
720 NET_ASSERT(iface->if_dev);
721
722 return iface->if_dev->l2_data;
723 }
724
725 /**
726 * @brief Get an network interface's device
727 *
728 * @param iface Pointer to a network interface structure
729 *
730 * @return a pointer to the device driver instance
731 */
net_if_get_device(struct net_if * iface)732 static inline const struct device *net_if_get_device(struct net_if *iface)
733 {
734 NET_ASSERT(iface);
735 NET_ASSERT(iface->if_dev);
736
737 return iface->if_dev->dev;
738 }
739
740 /**
741 * @brief Queue a packet to the net interface TX queue
742 *
743 * @param iface Pointer to a network interface structure
744 * @param pkt Pointer to a net packet to queue
745 */
746 void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt);
747
748 /**
749 * @brief Return the IP offload status
750 *
751 * @param iface Network interface
752 *
753 * @return True if IP offloading is active, false otherwise.
754 */
net_if_is_ip_offloaded(struct net_if * iface)755 static inline bool net_if_is_ip_offloaded(struct net_if *iface)
756 {
757 #if defined(CONFIG_NET_OFFLOAD)
758 NET_ASSERT(iface);
759 NET_ASSERT(iface->if_dev);
760
761 return (iface->if_dev->offload != NULL);
762 #else
763 ARG_UNUSED(iface);
764
765 return false;
766 #endif
767 }
768
769 /**
770 * @brief Return the IP offload plugin
771 *
772 * @param iface Network interface
773 *
774 * @return NULL if there is no offload plugin defined, valid pointer otherwise
775 */
net_if_offload(struct net_if * iface)776 static inline struct net_offload *net_if_offload(struct net_if *iface)
777 {
778 #if defined(CONFIG_NET_OFFLOAD)
779 NET_ASSERT(iface);
780 NET_ASSERT(iface->if_dev);
781
782 return iface->if_dev->offload;
783 #else
784 ARG_UNUSED(iface);
785
786 return NULL;
787 #endif
788 }
789
790 /**
791 * @brief Return the socket offload status
792 *
793 * @param iface Network interface
794 *
795 * @return True if socket offloading is active, false otherwise.
796 */
net_if_is_socket_offloaded(struct net_if * iface)797 static inline bool net_if_is_socket_offloaded(struct net_if *iface)
798 {
799 #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
800 NET_ASSERT(iface);
801 NET_ASSERT(iface->if_dev);
802
803 return (iface->if_dev->socket_offload != NULL);
804 #else
805 ARG_UNUSED(iface);
806
807 return false;
808 #endif
809 }
810
811 /**
812 * @brief Set the function to create an offloaded socket
813 *
814 * @param iface Network interface
815 * @param socket_offload A function to create an offloaded socket
816 */
net_if_socket_offload_set(struct net_if * iface,net_socket_create_t socket_offload)817 static inline void net_if_socket_offload_set(
818 struct net_if *iface, net_socket_create_t socket_offload)
819 {
820 #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
821 NET_ASSERT(iface);
822 NET_ASSERT(iface->if_dev);
823
824 iface->if_dev->socket_offload = socket_offload;
825 #else
826 ARG_UNUSED(iface);
827 ARG_UNUSED(socket_offload);
828 #endif
829 }
830
831 /**
832 * @brief Return the function to create an offloaded socket
833 *
834 * @param iface Network interface
835 *
836 * @return NULL if the interface is not socket offloaded, valid pointer otherwise
837 */
net_if_socket_offload(struct net_if * iface)838 static inline net_socket_create_t net_if_socket_offload(struct net_if *iface)
839 {
840 #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
841 NET_ASSERT(iface);
842 NET_ASSERT(iface->if_dev);
843
844 return iface->if_dev->socket_offload;
845 #else
846 ARG_UNUSED(iface);
847
848 return NULL;
849 #endif
850 }
851
852 /**
853 * @brief Get an network interface's link address
854 *
855 * @param iface Pointer to a network interface structure
856 *
857 * @return a pointer to the network link address
858 */
net_if_get_link_addr(struct net_if * iface)859 static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface)
860 {
861 NET_ASSERT(iface);
862 NET_ASSERT(iface->if_dev);
863
864 return &iface->if_dev->link_addr;
865 }
866
867 /**
868 * @brief Return network configuration for this network interface
869 *
870 * @param iface Pointer to a network interface structure
871 *
872 * @return Pointer to configuration
873 */
net_if_get_config(struct net_if * iface)874 static inline struct net_if_config *net_if_get_config(struct net_if *iface)
875 {
876 NET_ASSERT(iface);
877
878 return &iface->config;
879 }
880
881 /**
882 * @brief Start duplicate address detection procedure.
883 *
884 * @param iface Pointer to a network interface structure
885 */
886 #if defined(CONFIG_NET_IPV6_DAD) && defined(CONFIG_NET_NATIVE_IPV6)
887 void net_if_start_dad(struct net_if *iface);
888 #else
net_if_start_dad(struct net_if * iface)889 static inline void net_if_start_dad(struct net_if *iface)
890 {
891 ARG_UNUSED(iface);
892 }
893 #endif
894
895 /**
896 * @brief Start neighbor discovery and send router solicitation message.
897 *
898 * @param iface Pointer to a network interface structure
899 */
900 void net_if_start_rs(struct net_if *iface);
901
902
903 /**
904 * @brief Stop neighbor discovery.
905 *
906 * @param iface Pointer to a network interface structure
907 */
908 #if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
909 void net_if_stop_rs(struct net_if *iface);
910 #else
net_if_stop_rs(struct net_if * iface)911 static inline void net_if_stop_rs(struct net_if *iface)
912 {
913 ARG_UNUSED(iface);
914 }
915 #endif /* CONFIG_NET_IPV6_ND */
916
917 /** @cond INTERNAL_HIDDEN */
918
net_if_set_link_addr_unlocked(struct net_if * iface,uint8_t * addr,uint8_t len,enum net_link_type type)919 static inline int net_if_set_link_addr_unlocked(struct net_if *iface,
920 uint8_t *addr, uint8_t len,
921 enum net_link_type type)
922 {
923 if (net_if_flag_is_set(iface, NET_IF_RUNNING)) {
924 return -EPERM;
925 }
926
927 net_if_get_link_addr(iface)->addr = addr;
928 net_if_get_link_addr(iface)->len = len;
929 net_if_get_link_addr(iface)->type = type;
930
931 net_hostname_set_postfix(addr, len);
932
933 return 0;
934 }
935
936 int net_if_set_link_addr_locked(struct net_if *iface,
937 uint8_t *addr, uint8_t len,
938 enum net_link_type type);
939 /** @endcond */
940
941 /**
942 * @brief Set a network interface's link address
943 *
944 * @param iface Pointer to a network interface structure
945 * @param addr A pointer to a uint8_t buffer representing the address.
946 * The buffer must remain valid throughout interface lifetime.
947 * @param len length of the address buffer
948 * @param type network bearer type of this link address
949 *
950 * @return 0 on success
951 */
net_if_set_link_addr(struct net_if * iface,uint8_t * addr,uint8_t len,enum net_link_type type)952 static inline int net_if_set_link_addr(struct net_if *iface,
953 uint8_t *addr, uint8_t len,
954 enum net_link_type type)
955 {
956 #if defined(CONFIG_NET_RAW_MODE)
957 return net_if_set_link_addr_unlocked(iface, addr, len, type);
958 #else
959 return net_if_set_link_addr_locked(iface, addr, len, type);
960 #endif
961 }
962
963 /**
964 * @brief Get an network interface's MTU
965 *
966 * @param iface Pointer to a network interface structure
967 *
968 * @return the MTU
969 */
net_if_get_mtu(struct net_if * iface)970 static inline uint16_t net_if_get_mtu(struct net_if *iface)
971 {
972 if (iface == NULL) {
973 return 0U;
974 }
975
976 NET_ASSERT(iface->if_dev);
977
978 return iface->if_dev->mtu;
979 }
980
981 /**
982 * @brief Set an network interface's MTU
983 *
984 * @param iface Pointer to a network interface structure
985 * @param mtu New MTU, note that we store only 16 bit mtu value.
986 */
net_if_set_mtu(struct net_if * iface,uint16_t mtu)987 static inline void net_if_set_mtu(struct net_if *iface,
988 uint16_t mtu)
989 {
990 if (iface == NULL) {
991 return;
992 }
993
994 NET_ASSERT(iface->if_dev);
995
996 iface->if_dev->mtu = mtu;
997 }
998
999 /**
1000 * @brief Set the infinite status of the network interface address
1001 *
1002 * @param ifaddr IP address for network interface
1003 * @param is_infinite Infinite status
1004 */
net_if_addr_set_lf(struct net_if_addr * ifaddr,bool is_infinite)1005 static inline void net_if_addr_set_lf(struct net_if_addr *ifaddr,
1006 bool is_infinite)
1007 {
1008 NET_ASSERT(ifaddr);
1009
1010 ifaddr->is_infinite = is_infinite;
1011 }
1012
1013 /**
1014 * @brief Get an interface according to link layer address.
1015 *
1016 * @param ll_addr Link layer address.
1017 *
1018 * @return Network interface or NULL if not found.
1019 */
1020 struct net_if *net_if_get_by_link_addr(struct net_linkaddr *ll_addr);
1021
1022 /**
1023 * @brief Find an interface from it's related device
1024 *
1025 * @param dev A valid struct device pointer to relate with an interface
1026 *
1027 * @return a valid struct net_if pointer on success, NULL otherwise
1028 */
1029 struct net_if *net_if_lookup_by_dev(const struct device *dev);
1030
1031 /**
1032 * @brief Get network interface IP config
1033 *
1034 * @param iface Interface to use.
1035 *
1036 * @return NULL if not found or pointer to correct config settings.
1037 */
net_if_config_get(struct net_if * iface)1038 static inline struct net_if_config *net_if_config_get(struct net_if *iface)
1039 {
1040 NET_ASSERT(iface);
1041
1042 return &iface->config;
1043 }
1044
1045 /**
1046 * @brief Remove a router from the system
1047 *
1048 * @param router Pointer to existing router
1049 */
1050 void net_if_router_rm(struct net_if_router *router);
1051
1052 /**
1053 * @brief Set the default network interface.
1054 *
1055 * @param iface New default interface, or NULL to revert to the one set by Kconfig.
1056 */
1057 void net_if_set_default(struct net_if *iface);
1058
1059 /**
1060 * @brief Get the default network interface.
1061 *
1062 * @return Default interface or NULL if no interfaces are configured.
1063 */
1064 struct net_if *net_if_get_default(void);
1065
1066 /**
1067 * @brief Get the first network interface according to its type.
1068 *
1069 * @param l2 Layer 2 type of the network interface.
1070 *
1071 * @return First network interface of a given type or NULL if no such
1072 * interfaces was found.
1073 */
1074 struct net_if *net_if_get_first_by_type(const struct net_l2 *l2);
1075
1076 /**
1077 * @brief Get the first network interface which is up.
1078 *
1079 * @return First network interface which is up or NULL if all
1080 * interfaces are down.
1081 */
1082 struct net_if *net_if_get_first_up(void);
1083
1084 #if defined(CONFIG_NET_L2_IEEE802154)
1085 /**
1086 * @brief Get the first IEEE 802.15.4 network interface.
1087 *
1088 * @return First IEEE 802.15.4 network interface or NULL if no such
1089 * interfaces was found.
1090 */
net_if_get_ieee802154(void)1091 static inline struct net_if *net_if_get_ieee802154(void)
1092 {
1093 return net_if_get_first_by_type(&NET_L2_GET_NAME(IEEE802154));
1094 }
1095 #endif /* CONFIG_NET_L2_IEEE802154 */
1096
1097 /**
1098 * @brief Allocate network interface IPv6 config.
1099 *
1100 * @details This function will allocate new IPv6 config.
1101 *
1102 * @param iface Interface to use.
1103 * @param ipv6 Pointer to allocated IPv6 struct is returned to caller.
1104 *
1105 * @return 0 if ok, <0 if error
1106 */
1107 int net_if_config_ipv6_get(struct net_if *iface,
1108 struct net_if_ipv6 **ipv6);
1109
1110 /**
1111 * @brief Release network interface IPv6 config.
1112 *
1113 * @param iface Interface to use.
1114 *
1115 * @return 0 if ok, <0 if error
1116 */
1117 int net_if_config_ipv6_put(struct net_if *iface);
1118
1119 /**
1120 * @brief Check if this IPv6 address belongs to one of the interfaces.
1121 *
1122 * @param addr IPv6 address
1123 * @param iface Pointer to interface is returned
1124 *
1125 * @return Pointer to interface address, NULL if not found.
1126 */
1127 struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
1128 struct net_if **iface);
1129
1130 /**
1131 * @brief Check if this IPv6 address belongs to this specific interfaces.
1132 *
1133 * @param iface Network interface
1134 * @param addr IPv6 address
1135 *
1136 * @return Pointer to interface address, NULL if not found.
1137 */
1138 struct net_if_addr *net_if_ipv6_addr_lookup_by_iface(struct net_if *iface,
1139 struct in6_addr *addr);
1140
1141 /**
1142 * @brief Check if this IPv6 address belongs to one of the interface indices.
1143 *
1144 * @param addr IPv6 address
1145 *
1146 * @return >0 if address was found in given network interface index,
1147 * all other values mean address was not found
1148 */
1149 __syscall int net_if_ipv6_addr_lookup_by_index(const struct in6_addr *addr);
1150
1151 /**
1152 * @brief Add a IPv6 address to an interface
1153 *
1154 * @param iface Network interface
1155 * @param addr IPv6 address
1156 * @param addr_type IPv6 address type
1157 * @param vlifetime Validity time for this address
1158 *
1159 * @return Pointer to interface address, NULL if cannot be added
1160 */
1161 struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface,
1162 struct in6_addr *addr,
1163 enum net_addr_type addr_type,
1164 uint32_t vlifetime);
1165
1166 /**
1167 * @brief Add a IPv6 address to an interface by index
1168 *
1169 * @param index Network interface index
1170 * @param addr IPv6 address
1171 * @param addr_type IPv6 address type
1172 * @param vlifetime Validity time for this address
1173 *
1174 * @return True if ok, false if address could not be added
1175 */
1176 __syscall bool net_if_ipv6_addr_add_by_index(int index,
1177 struct in6_addr *addr,
1178 enum net_addr_type addr_type,
1179 uint32_t vlifetime);
1180
1181 /**
1182 * @brief Update validity lifetime time of an IPv6 address.
1183 *
1184 * @param ifaddr Network IPv6 address
1185 * @param vlifetime Validity time for this address
1186 */
1187 void net_if_ipv6_addr_update_lifetime(struct net_if_addr *ifaddr,
1188 uint32_t vlifetime);
1189
1190 /**
1191 * @brief Remove an IPv6 address from an interface
1192 *
1193 * @param iface Network interface
1194 * @param addr IPv6 address
1195 *
1196 * @return True if successfully removed, false otherwise
1197 */
1198 bool net_if_ipv6_addr_rm(struct net_if *iface, const struct in6_addr *addr);
1199
1200 /**
1201 * @brief Remove an IPv6 address from an interface by index
1202 *
1203 * @param index Network interface index
1204 * @param addr IPv6 address
1205 *
1206 * @return True if successfully removed, false otherwise
1207 */
1208 __syscall bool net_if_ipv6_addr_rm_by_index(int index,
1209 const struct in6_addr *addr);
1210
1211 /**
1212 * @brief Add a IPv6 multicast address to an interface
1213 *
1214 * @param iface Network interface
1215 * @param addr IPv6 multicast address
1216 *
1217 * @return Pointer to interface multicast address, NULL if cannot be added
1218 */
1219 struct net_if_mcast_addr *net_if_ipv6_maddr_add(struct net_if *iface,
1220 const struct in6_addr *addr);
1221
1222 /**
1223 * @brief Remove an IPv6 multicast address from an interface
1224 *
1225 * @param iface Network interface
1226 * @param addr IPv6 multicast address
1227 *
1228 * @return True if successfully removed, false otherwise
1229 */
1230 bool net_if_ipv6_maddr_rm(struct net_if *iface, const struct in6_addr *addr);
1231
1232 /**
1233 * @brief Check if this IPv6 multicast address belongs to a specific interface
1234 * or one of the interfaces.
1235 *
1236 * @param addr IPv6 address
1237 * @param iface If *iface is null, then pointer to interface is returned,
1238 * otherwise the *iface value needs to be matched.
1239 *
1240 * @return Pointer to interface multicast address, NULL if not found.
1241 */
1242 struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(const struct in6_addr *addr,
1243 struct net_if **iface);
1244
1245 /**
1246 * @typedef net_if_mcast_callback_t
1247
1248 * @brief Define callback that is called whenever IPv6 multicast address group
1249 * is joined or left.
1250
1251 * @param iface A pointer to a struct net_if to which the multicast address is
1252 * attached.
1253 * @param addr IP multicast address.
1254 * @param is_joined True if the address is joined, false if left.
1255 */
1256 typedef void (*net_if_mcast_callback_t)(struct net_if *iface,
1257 const struct net_addr *addr,
1258 bool is_joined);
1259
1260 /**
1261 * @brief Multicast monitor handler struct.
1262 *
1263 * Stores the multicast callback information. Caller must make sure that
1264 * the variable pointed by this is valid during the lifetime of
1265 * registration. Typically this means that the variable cannot be
1266 * allocated from stack.
1267 */
1268 struct net_if_mcast_monitor {
1269 /** Node information for the slist. */
1270 sys_snode_t node;
1271
1272 /** Network interface */
1273 struct net_if *iface;
1274
1275 /** Multicast callback */
1276 net_if_mcast_callback_t cb;
1277 };
1278
1279 /**
1280 * @brief Register a multicast monitor
1281 *
1282 * @param mon Monitor handle. This is a pointer to a monitor storage structure
1283 * which should be allocated by caller, but does not need to be initialized.
1284 * @param iface Network interface
1285 * @param cb Monitor callback
1286 */
1287 void net_if_mcast_mon_register(struct net_if_mcast_monitor *mon,
1288 struct net_if *iface,
1289 net_if_mcast_callback_t cb);
1290
1291 /**
1292 * @brief Unregister a multicast monitor
1293 *
1294 * @param mon Monitor handle
1295 */
1296 void net_if_mcast_mon_unregister(struct net_if_mcast_monitor *mon);
1297
1298 /**
1299 * @brief Call registered multicast monitors
1300 *
1301 * @param iface Network interface
1302 * @param addr Multicast address
1303 * @param is_joined Is this multicast address joined (true) or not (false)
1304 */
1305 void net_if_mcast_monitor(struct net_if *iface, const struct net_addr *addr,
1306 bool is_joined);
1307
1308 /**
1309 * @brief Mark a given multicast address to be joined.
1310 *
1311 * @param iface Network interface the address belongs to
1312 * @param addr IPv6 multicast address
1313 */
1314 void net_if_ipv6_maddr_join(struct net_if *iface,
1315 struct net_if_mcast_addr *addr);
1316
1317 /**
1318 * @brief Check if given multicast address is joined or not.
1319 *
1320 * @param addr IPv6 multicast address
1321 *
1322 * @return True if address is joined, False otherwise.
1323 */
net_if_ipv6_maddr_is_joined(struct net_if_mcast_addr * addr)1324 static inline bool net_if_ipv6_maddr_is_joined(struct net_if_mcast_addr *addr)
1325 {
1326 NET_ASSERT(addr);
1327
1328 return addr->is_joined;
1329 }
1330
1331 /**
1332 * @brief Mark a given multicast address to be left.
1333 *
1334 * @param iface Network interface the address belongs to
1335 * @param addr IPv6 multicast address
1336 */
1337 void net_if_ipv6_maddr_leave(struct net_if *iface,
1338 struct net_if_mcast_addr *addr);
1339
1340 /**
1341 * @brief Return prefix that corresponds to this IPv6 address.
1342 *
1343 * @param iface Network interface
1344 * @param addr IPv6 address
1345 *
1346 * @return Pointer to prefix, NULL if not found.
1347 */
1348 struct net_if_ipv6_prefix *net_if_ipv6_prefix_get(struct net_if *iface,
1349 struct in6_addr *addr);
1350
1351 /**
1352 * @brief Check if this IPv6 prefix belongs to this interface
1353 *
1354 * @param iface Network interface
1355 * @param addr IPv6 address
1356 * @param len Prefix length
1357 *
1358 * @return Pointer to prefix, NULL if not found.
1359 */
1360 struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
1361 struct in6_addr *addr,
1362 uint8_t len);
1363
1364 /**
1365 * @brief Add a IPv6 prefix to an network interface.
1366 *
1367 * @param iface Network interface
1368 * @param prefix IPv6 address
1369 * @param len Prefix length
1370 * @param lifetime Prefix lifetime in seconds
1371 *
1372 * @return Pointer to prefix, NULL if the prefix was not added.
1373 */
1374 struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
1375 struct in6_addr *prefix,
1376 uint8_t len,
1377 uint32_t lifetime);
1378
1379 /**
1380 * @brief Remove an IPv6 prefix from an interface
1381 *
1382 * @param iface Network interface
1383 * @param addr IPv6 prefix address
1384 * @param len Prefix length
1385 *
1386 * @return True if successfully removed, false otherwise
1387 */
1388 bool net_if_ipv6_prefix_rm(struct net_if *iface, struct in6_addr *addr,
1389 uint8_t len);
1390
1391 /**
1392 * @brief Set the infinite status of the prefix
1393 *
1394 * @param prefix IPv6 address
1395 * @param is_infinite Infinite status
1396 */
net_if_ipv6_prefix_set_lf(struct net_if_ipv6_prefix * prefix,bool is_infinite)1397 static inline void net_if_ipv6_prefix_set_lf(struct net_if_ipv6_prefix *prefix,
1398 bool is_infinite)
1399 {
1400 prefix->is_infinite = is_infinite;
1401 }
1402
1403 /**
1404 * @brief Set the prefix lifetime timer.
1405 *
1406 * @param prefix IPv6 address
1407 * @param lifetime Prefix lifetime in seconds
1408 */
1409 void net_if_ipv6_prefix_set_timer(struct net_if_ipv6_prefix *prefix,
1410 uint32_t lifetime);
1411
1412 /**
1413 * @brief Unset the prefix lifetime timer.
1414 *
1415 * @param prefix IPv6 address
1416 */
1417 void net_if_ipv6_prefix_unset_timer(struct net_if_ipv6_prefix *prefix);
1418
1419 /**
1420 * @brief Check if this IPv6 address is part of the subnet of our
1421 * network interface.
1422 *
1423 * @param iface Network interface. This is returned to the caller.
1424 * The iface can be NULL in which case we check all the interfaces.
1425 * @param addr IPv6 address
1426 *
1427 * @return True if address is part of our subnet, false otherwise
1428 */
1429 bool net_if_ipv6_addr_onlink(struct net_if **iface, struct in6_addr *addr);
1430
1431 /**
1432 * @brief Get the IPv6 address of the given router
1433 * @param router a network router
1434 *
1435 * @return pointer to the IPv6 address, or NULL if none
1436 */
1437 #if defined(CONFIG_NET_NATIVE_IPV6)
net_if_router_ipv6(struct net_if_router * router)1438 static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)
1439 {
1440 NET_ASSERT(router);
1441
1442 return &router->address.in6_addr;
1443 }
1444 #else
net_if_router_ipv6(struct net_if_router * router)1445 static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)
1446 {
1447 static struct in6_addr addr;
1448
1449 ARG_UNUSED(router);
1450
1451 return &addr;
1452 }
1453 #endif
1454
1455 /**
1456 * @brief Check if IPv6 address is one of the routers configured
1457 * in the system.
1458 *
1459 * @param iface Network interface
1460 * @param addr IPv6 address
1461 *
1462 * @return Pointer to router information, NULL if cannot be found
1463 */
1464 struct net_if_router *net_if_ipv6_router_lookup(struct net_if *iface,
1465 struct in6_addr *addr);
1466
1467 /**
1468 * @brief Find default router for this IPv6 address.
1469 *
1470 * @param iface Network interface. This can be NULL in which case we
1471 * go through all the network interfaces to find a suitable router.
1472 * @param addr IPv6 address
1473 *
1474 * @return Pointer to router information, NULL if cannot be found
1475 */
1476 struct net_if_router *net_if_ipv6_router_find_default(struct net_if *iface,
1477 struct in6_addr *addr);
1478
1479 /**
1480 * @brief Update validity lifetime time of a router.
1481 *
1482 * @param router Network IPv6 address
1483 * @param lifetime Lifetime of this router.
1484 */
1485 void net_if_ipv6_router_update_lifetime(struct net_if_router *router,
1486 uint16_t lifetime);
1487
1488 /**
1489 * @brief Add IPv6 router to the system.
1490 *
1491 * @param iface Network interface
1492 * @param addr IPv6 address
1493 * @param router_lifetime Lifetime of the router
1494 *
1495 * @return Pointer to router information, NULL if could not be added
1496 */
1497 struct net_if_router *net_if_ipv6_router_add(struct net_if *iface,
1498 struct in6_addr *addr,
1499 uint16_t router_lifetime);
1500
1501 /**
1502 * @brief Remove IPv6 router from the system.
1503 *
1504 * @param router Router information.
1505 *
1506 * @return True if successfully removed, false otherwise
1507 */
1508 bool net_if_ipv6_router_rm(struct net_if_router *router);
1509
1510 /**
1511 * @brief Get IPv6 hop limit specified for a given interface. This is the
1512 * default value but can be overridden by the user.
1513 *
1514 * @param iface Network interface
1515 *
1516 * @return Hop limit
1517 */
1518 uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface);
1519
1520 /**
1521 * @brief Set the default IPv6 hop limit of a given interface.
1522 *
1523 * @param iface Network interface
1524 * @param hop_limit New hop limit
1525 */
1526 void net_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit);
1527
1528 /**
1529 * @brief Set IPv6 reachable time for a given interface
1530 *
1531 * @param iface Network interface
1532 * @param reachable_time New reachable time
1533 */
net_if_ipv6_set_base_reachable_time(struct net_if * iface,uint32_t reachable_time)1534 static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
1535 uint32_t reachable_time)
1536 {
1537 #if defined(CONFIG_NET_NATIVE_IPV6)
1538 NET_ASSERT(iface);
1539
1540 if (!iface->config.ip.ipv6) {
1541 return;
1542 }
1543
1544 iface->config.ip.ipv6->base_reachable_time = reachable_time;
1545 #endif
1546 }
1547
1548 /**
1549 * @brief Get IPv6 reachable timeout specified for a given interface
1550 *
1551 * @param iface Network interface
1552 *
1553 * @return Reachable timeout
1554 */
net_if_ipv6_get_reachable_time(struct net_if * iface)1555 static inline uint32_t net_if_ipv6_get_reachable_time(struct net_if *iface)
1556 {
1557 #if defined(CONFIG_NET_NATIVE_IPV6)
1558 NET_ASSERT(iface);
1559
1560 if (!iface->config.ip.ipv6) {
1561 return 0;
1562 }
1563
1564 return iface->config.ip.ipv6->reachable_time;
1565 #else
1566 return 0;
1567 #endif
1568 }
1569
1570 /**
1571 * @brief Calculate next reachable time value for IPv6 reachable time
1572 *
1573 * @param ipv6 IPv6 address configuration
1574 *
1575 * @return Reachable time
1576 */
1577 uint32_t net_if_ipv6_calc_reachable_time(struct net_if_ipv6 *ipv6);
1578
1579 /**
1580 * @brief Set IPv6 reachable time for a given interface. This requires
1581 * that base reachable time is set for the interface.
1582 *
1583 * @param ipv6 IPv6 address configuration
1584 */
net_if_ipv6_set_reachable_time(struct net_if_ipv6 * ipv6)1585 static inline void net_if_ipv6_set_reachable_time(struct net_if_ipv6 *ipv6)
1586 {
1587 #if defined(CONFIG_NET_NATIVE_IPV6)
1588 if (ipv6 == NULL) {
1589 return;
1590 }
1591
1592 ipv6->reachable_time = net_if_ipv6_calc_reachable_time(ipv6);
1593 #endif
1594 }
1595
1596 /**
1597 * @brief Set IPv6 retransmit timer for a given interface
1598 *
1599 * @param iface Network interface
1600 * @param retrans_timer New retransmit timer
1601 */
net_if_ipv6_set_retrans_timer(struct net_if * iface,uint32_t retrans_timer)1602 static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
1603 uint32_t retrans_timer)
1604 {
1605 #if defined(CONFIG_NET_NATIVE_IPV6)
1606 NET_ASSERT(iface);
1607
1608 if (!iface->config.ip.ipv6) {
1609 return;
1610 }
1611
1612 iface->config.ip.ipv6->retrans_timer = retrans_timer;
1613 #endif
1614 }
1615
1616 /**
1617 * @brief Get IPv6 retransmit timer specified for a given interface
1618 *
1619 * @param iface Network interface
1620 *
1621 * @return Retransmit timer
1622 */
net_if_ipv6_get_retrans_timer(struct net_if * iface)1623 static inline uint32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)
1624 {
1625 #if defined(CONFIG_NET_NATIVE_IPV6)
1626 NET_ASSERT(iface);
1627
1628 if (!iface->config.ip.ipv6) {
1629 return 0;
1630 }
1631
1632 return iface->config.ip.ipv6->retrans_timer;
1633 #else
1634 return 0;
1635 #endif
1636 }
1637
1638 /**
1639 * @brief Get a IPv6 source address that should be used when sending
1640 * network data to destination.
1641 *
1642 * @param iface Interface that was used when packet was received.
1643 * If the interface is not known, then NULL can be given.
1644 * @param dst IPv6 destination address
1645 *
1646 * @return Pointer to IPv6 address to use, NULL if no IPv6 address
1647 * could be found.
1648 */
1649 #if defined(CONFIG_NET_NATIVE_IPV6)
1650 const struct in6_addr *net_if_ipv6_select_src_addr(struct net_if *iface,
1651 const struct in6_addr *dst);
1652 #else
net_if_ipv6_select_src_addr(struct net_if * iface,const struct in6_addr * dst)1653 static inline const struct in6_addr *net_if_ipv6_select_src_addr(
1654 struct net_if *iface, const struct in6_addr *dst)
1655 {
1656 ARG_UNUSED(iface);
1657 ARG_UNUSED(dst);
1658
1659 return NULL;
1660 }
1661 #endif
1662
1663 /**
1664 * @brief Get a network interface that should be used when sending
1665 * IPv6 network data to destination.
1666 *
1667 * @param dst IPv6 destination address
1668 *
1669 * @return Pointer to network interface to use, NULL if no suitable interface
1670 * could be found.
1671 */
1672 #if defined(CONFIG_NET_NATIVE_IPV6)
1673 struct net_if *net_if_ipv6_select_src_iface(const struct in6_addr *dst);
1674 #else
net_if_ipv6_select_src_iface(const struct in6_addr * dst)1675 static inline struct net_if *net_if_ipv6_select_src_iface(
1676 const struct in6_addr *dst)
1677 {
1678 ARG_UNUSED(dst);
1679
1680 return NULL;
1681 }
1682 #endif
1683
1684 /**
1685 * @brief Get a IPv6 link local address in a given state.
1686 *
1687 * @param iface Interface to use. Must be a valid pointer to an interface.
1688 * @param addr_state IPv6 address state (preferred, tentative, deprecated)
1689 *
1690 * @return Pointer to link local IPv6 address, NULL if no proper IPv6 address
1691 * could be found.
1692 */
1693 struct in6_addr *net_if_ipv6_get_ll(struct net_if *iface,
1694 enum net_addr_state addr_state);
1695
1696 /**
1697 * @brief Return link local IPv6 address from the first interface that has
1698 * a link local address matching give state.
1699 *
1700 * @param state IPv6 address state (ANY, TENTATIVE, PREFERRED, DEPRECATED)
1701 * @param iface Pointer to interface is returned
1702 *
1703 * @return Pointer to IPv6 address, NULL if not found.
1704 */
1705 struct in6_addr *net_if_ipv6_get_ll_addr(enum net_addr_state state,
1706 struct net_if **iface);
1707
1708 /**
1709 * @brief Stop IPv6 Duplicate Address Detection (DAD) procedure if
1710 * we find out that our IPv6 address is already in use.
1711 *
1712 * @param iface Interface where the DAD was running.
1713 * @param addr IPv6 address that failed DAD
1714 */
1715 void net_if_ipv6_dad_failed(struct net_if *iface, const struct in6_addr *addr);
1716
1717 /**
1718 * @brief Return global IPv6 address from the first interface that has
1719 * a global IPv6 address matching the given state.
1720 *
1721 * @param state IPv6 address state (ANY, TENTATIVE, PREFERRED, DEPRECATED)
1722 * @param iface Caller can give an interface to check. If iface is set to NULL,
1723 * then all the interfaces are checked. Pointer to interface where the IPv6
1724 * address is defined is returned to the caller.
1725 *
1726 * @return Pointer to IPv6 address, NULL if not found.
1727 */
1728 struct in6_addr *net_if_ipv6_get_global_addr(enum net_addr_state state,
1729 struct net_if **iface);
1730
1731 /**
1732 * @brief Allocate network interface IPv4 config.
1733 *
1734 * @details This function will allocate new IPv4 config.
1735 *
1736 * @param iface Interface to use.
1737 * @param ipv4 Pointer to allocated IPv4 struct is returned to caller.
1738 *
1739 * @return 0 if ok, <0 if error
1740 */
1741 int net_if_config_ipv4_get(struct net_if *iface,
1742 struct net_if_ipv4 **ipv4);
1743
1744 /**
1745 * @brief Release network interface IPv4 config.
1746 *
1747 * @param iface Interface to use.
1748 *
1749 * @return 0 if ok, <0 if error
1750 */
1751 int net_if_config_ipv4_put(struct net_if *iface);
1752
1753 /**
1754 * @brief Get IPv4 time-to-live value specified for a given interface
1755 *
1756 * @param iface Network interface
1757 *
1758 * @return Time-to-live
1759 */
1760 uint8_t net_if_ipv4_get_ttl(struct net_if *iface);
1761
1762 /**
1763 * @brief Set IPv4 time-to-live value specified to a given interface
1764 *
1765 * @param iface Network interface
1766 * @param ttl Time-to-live value
1767 */
1768 void net_if_ipv4_set_ttl(struct net_if *iface, uint8_t ttl);
1769
1770 /**
1771 * @brief Check if this IPv4 address belongs to one of the interfaces.
1772 *
1773 * @param addr IPv4 address
1774 * @param iface Interface is returned
1775 *
1776 * @return Pointer to interface address, NULL if not found.
1777 */
1778 struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
1779 struct net_if **iface);
1780
1781 /**
1782 * @brief Add a IPv4 address to an interface
1783 *
1784 * @param iface Network interface
1785 * @param addr IPv4 address
1786 * @param addr_type IPv4 address type
1787 * @param vlifetime Validity time for this address
1788 *
1789 * @return Pointer to interface address, NULL if cannot be added
1790 */
1791 struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface,
1792 struct in_addr *addr,
1793 enum net_addr_type addr_type,
1794 uint32_t vlifetime);
1795
1796 /**
1797 * @brief Remove a IPv4 address from an interface
1798 *
1799 * @param iface Network interface
1800 * @param addr IPv4 address
1801 *
1802 * @return True if successfully removed, false otherwise
1803 */
1804 bool net_if_ipv4_addr_rm(struct net_if *iface, const struct in_addr *addr);
1805
1806 /**
1807 * @brief Check if this IPv4 address belongs to one of the interface indices.
1808 *
1809 * @param addr IPv4 address
1810 *
1811 * @return >0 if address was found in given network interface index,
1812 * all other values mean address was not found
1813 */
1814 __syscall int net_if_ipv4_addr_lookup_by_index(const struct in_addr *addr);
1815
1816 /**
1817 * @brief Add a IPv4 address to an interface by network interface index
1818 *
1819 * @param index Network interface index
1820 * @param addr IPv4 address
1821 * @param addr_type IPv4 address type
1822 * @param vlifetime Validity time for this address
1823 *
1824 * @return True if ok, false if the address could not be added
1825 */
1826 __syscall bool net_if_ipv4_addr_add_by_index(int index,
1827 struct in_addr *addr,
1828 enum net_addr_type addr_type,
1829 uint32_t vlifetime);
1830
1831 /**
1832 * @brief Remove a IPv4 address from an interface by interface index
1833 *
1834 * @param index Network interface index
1835 * @param addr IPv4 address
1836 *
1837 * @return True if successfully removed, false otherwise
1838 */
1839 __syscall bool net_if_ipv4_addr_rm_by_index(int index,
1840 const struct in_addr *addr);
1841
1842 /**
1843 * @brief Add a IPv4 multicast address to an interface
1844 *
1845 * @param iface Network interface
1846 * @param addr IPv4 multicast address
1847 *
1848 * @return Pointer to interface multicast address, NULL if cannot be added
1849 */
1850 struct net_if_mcast_addr *net_if_ipv4_maddr_add(struct net_if *iface,
1851 const struct in_addr *addr);
1852
1853 /**
1854 * @brief Remove an IPv4 multicast address from an interface
1855 *
1856 * @param iface Network interface
1857 * @param addr IPv4 multicast address
1858 *
1859 * @return True if successfully removed, false otherwise
1860 */
1861 bool net_if_ipv4_maddr_rm(struct net_if *iface, const struct in_addr *addr);
1862
1863 /**
1864 * @brief Check if this IPv4 multicast address belongs to a specific interface
1865 * or one of the interfaces.
1866 *
1867 * @param addr IPv4 address
1868 * @param iface If *iface is null, then pointer to interface is returned,
1869 * otherwise the *iface value needs to be matched.
1870 *
1871 * @return Pointer to interface multicast address, NULL if not found.
1872 */
1873 struct net_if_mcast_addr *net_if_ipv4_maddr_lookup(const struct in_addr *addr,
1874 struct net_if **iface);
1875
1876 /**
1877 * @brief Mark a given multicast address to be joined.
1878 *
1879 * @param iface Network interface the address belongs to
1880 * @param addr IPv4 multicast address
1881 */
1882 void net_if_ipv4_maddr_join(struct net_if *iface,
1883 struct net_if_mcast_addr *addr);
1884
1885 /**
1886 * @brief Check if given multicast address is joined or not.
1887 *
1888 * @param addr IPv4 multicast address
1889 *
1890 * @return True if address is joined, False otherwise.
1891 */
net_if_ipv4_maddr_is_joined(struct net_if_mcast_addr * addr)1892 static inline bool net_if_ipv4_maddr_is_joined(struct net_if_mcast_addr *addr)
1893 {
1894 NET_ASSERT(addr);
1895
1896 return addr->is_joined;
1897 }
1898
1899 /**
1900 * @brief Mark a given multicast address to be left.
1901 *
1902 * @param iface Network interface the address belongs to
1903 * @param addr IPv4 multicast address
1904 */
1905 void net_if_ipv4_maddr_leave(struct net_if *iface,
1906 struct net_if_mcast_addr *addr);
1907
1908 /**
1909 * @brief Get the IPv4 address of the given router
1910 * @param router a network router
1911 *
1912 * @return pointer to the IPv4 address, or NULL if none
1913 */
1914 #if defined(CONFIG_NET_NATIVE_IPV4)
net_if_router_ipv4(struct net_if_router * router)1915 static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)
1916 {
1917 NET_ASSERT(router);
1918
1919 return &router->address.in_addr;
1920 }
1921 #else
net_if_router_ipv4(struct net_if_router * router)1922 static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)
1923 {
1924 static struct in_addr addr;
1925
1926 ARG_UNUSED(router);
1927
1928 return &addr;
1929 }
1930 #endif
1931
1932 /**
1933 * @brief Check if IPv4 address is one of the routers configured
1934 * in the system.
1935 *
1936 * @param iface Network interface
1937 * @param addr IPv4 address
1938 *
1939 * @return Pointer to router information, NULL if cannot be found
1940 */
1941 struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface,
1942 struct in_addr *addr);
1943
1944 /**
1945 * @brief Find default router for this IPv4 address.
1946 *
1947 * @param iface Network interface. This can be NULL in which case we
1948 * go through all the network interfaces to find a suitable router.
1949 * @param addr IPv4 address
1950 *
1951 * @return Pointer to router information, NULL if cannot be found
1952 */
1953 struct net_if_router *net_if_ipv4_router_find_default(struct net_if *iface,
1954 struct in_addr *addr);
1955 /**
1956 * @brief Add IPv4 router to the system.
1957 *
1958 * @param iface Network interface
1959 * @param addr IPv4 address
1960 * @param is_default Is this router the default one
1961 * @param router_lifetime Lifetime of the router
1962 *
1963 * @return Pointer to router information, NULL if could not be added
1964 */
1965 struct net_if_router *net_if_ipv4_router_add(struct net_if *iface,
1966 struct in_addr *addr,
1967 bool is_default,
1968 uint16_t router_lifetime);
1969
1970 /**
1971 * @brief Remove IPv4 router from the system.
1972 *
1973 * @param router Router information.
1974 *
1975 * @return True if successfully removed, false otherwise
1976 */
1977 bool net_if_ipv4_router_rm(struct net_if_router *router);
1978
1979 /**
1980 * @brief Check if the given IPv4 address belongs to local subnet.
1981 *
1982 * @param iface Interface to use. Must be a valid pointer to an interface.
1983 * @param addr IPv4 address
1984 *
1985 * @return True if address is part of local subnet, false otherwise.
1986 */
1987 bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
1988 const struct in_addr *addr);
1989
1990 /**
1991 * @brief Check if the given IPv4 address is a broadcast address.
1992 *
1993 * @param iface Interface to use. Must be a valid pointer to an interface.
1994 * @param addr IPv4 address, this should be in network byte order
1995 *
1996 * @return True if address is a broadcast address, false otherwise.
1997 */
1998 bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
1999 const struct in_addr *addr);
2000
2001 /**
2002 * @brief Get a network interface that should be used when sending
2003 * IPv4 network data to destination.
2004 *
2005 * @param dst IPv4 destination address
2006 *
2007 * @return Pointer to network interface to use, NULL if no suitable interface
2008 * could be found.
2009 */
2010 #if defined(CONFIG_NET_NATIVE_IPV4)
2011 struct net_if *net_if_ipv4_select_src_iface(const struct in_addr *dst);
2012 #else
net_if_ipv4_select_src_iface(const struct in_addr * dst)2013 static inline struct net_if *net_if_ipv4_select_src_iface(
2014 const struct in_addr *dst)
2015 {
2016 ARG_UNUSED(dst);
2017
2018 return NULL;
2019 }
2020 #endif
2021
2022 /**
2023 * @brief Get a IPv4 source address that should be used when sending
2024 * network data to destination.
2025 *
2026 * @param iface Interface to use when sending the packet.
2027 * If the interface is not known, then NULL can be given.
2028 * @param dst IPv4 destination address
2029 *
2030 * @return Pointer to IPv4 address to use, NULL if no IPv4 address
2031 * could be found.
2032 */
2033 #if defined(CONFIG_NET_NATIVE_IPV4)
2034 const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *iface,
2035 const struct in_addr *dst);
2036 #else
net_if_ipv4_select_src_addr(struct net_if * iface,const struct in_addr * dst)2037 static inline const struct in_addr *net_if_ipv4_select_src_addr(
2038 struct net_if *iface, const struct in_addr *dst)
2039 {
2040 ARG_UNUSED(iface);
2041 ARG_UNUSED(dst);
2042
2043 return NULL;
2044 }
2045 #endif
2046
2047 /**
2048 * @brief Get a IPv4 link local address in a given state.
2049 *
2050 * @param iface Interface to use. Must be a valid pointer to an interface.
2051 * @param addr_state IPv4 address state (preferred, tentative, deprecated)
2052 *
2053 * @return Pointer to link local IPv4 address, NULL if no proper IPv4 address
2054 * could be found.
2055 */
2056 struct in_addr *net_if_ipv4_get_ll(struct net_if *iface,
2057 enum net_addr_state addr_state);
2058
2059 /**
2060 * @brief Get a IPv4 global address in a given state.
2061 *
2062 * @param iface Interface to use. Must be a valid pointer to an interface.
2063 * @param addr_state IPv4 address state (preferred, tentative, deprecated)
2064 *
2065 * @return Pointer to link local IPv4 address, NULL if no proper IPv4 address
2066 * could be found.
2067 */
2068 struct in_addr *net_if_ipv4_get_global_addr(struct net_if *iface,
2069 enum net_addr_state addr_state);
2070
2071 /**
2072 * @brief Set IPv4 netmask for an interface.
2073 *
2074 * @param iface Interface to use.
2075 * @param netmask IPv4 netmask
2076 */
2077 void net_if_ipv4_set_netmask(struct net_if *iface,
2078 const struct in_addr *netmask);
2079
2080 /**
2081 * @brief Set IPv4 netmask for an interface index.
2082 *
2083 * @param index Network interface index
2084 * @param netmask IPv4 netmask
2085 *
2086 * @return True if netmask was added, false otherwise.
2087 */
2088 __syscall bool net_if_ipv4_set_netmask_by_index(int index,
2089 const struct in_addr *netmask);
2090
2091 /**
2092 * @brief Set IPv4 gateway for an interface.
2093 *
2094 * @param iface Interface to use.
2095 * @param gw IPv4 address of an gateway
2096 */
2097 void net_if_ipv4_set_gw(struct net_if *iface, const struct in_addr *gw);
2098
2099 /**
2100 * @brief Set IPv4 gateway for an interface index.
2101 *
2102 * @param index Network interface index
2103 * @param gw IPv4 address of an gateway
2104 *
2105 * @return True if gateway was added, false otherwise.
2106 */
2107 __syscall bool net_if_ipv4_set_gw_by_index(int index, const struct in_addr *gw);
2108
2109 /**
2110 * @brief Get a network interface that should be used when sending
2111 * IPv6 or IPv4 network data to destination.
2112 *
2113 * @param dst IPv6 or IPv4 destination address
2114 *
2115 * @return Pointer to network interface to use. Note that the function
2116 * will return the default network interface if the best network interface
2117 * is not found.
2118 */
2119 struct net_if *net_if_select_src_iface(const struct sockaddr *dst);
2120
2121 /**
2122 * @typedef net_if_link_callback_t
2123 * @brief Define callback that is called after a network packet
2124 * has been sent.
2125 * @param iface A pointer to a struct net_if to which the the net_pkt was sent to.
2126 * @param dst Link layer address of the destination where the network packet was sent.
2127 * @param status Send status, 0 is ok, < 0 error.
2128 */
2129 typedef void (*net_if_link_callback_t)(struct net_if *iface,
2130 struct net_linkaddr *dst,
2131 int status);
2132
2133 /**
2134 * @brief Link callback handler struct.
2135 *
2136 * Stores the link callback information. Caller must make sure that
2137 * the variable pointed by this is valid during the lifetime of
2138 * registration. Typically this means that the variable cannot be
2139 * allocated from stack.
2140 */
2141 struct net_if_link_cb {
2142 /** Node information for the slist. */
2143 sys_snode_t node;
2144
2145 /** Link callback */
2146 net_if_link_callback_t cb;
2147 };
2148
2149 /**
2150 * @brief Register a link callback.
2151 *
2152 * @param link Caller specified handler for the callback.
2153 * @param cb Callback to register.
2154 */
2155 void net_if_register_link_cb(struct net_if_link_cb *link,
2156 net_if_link_callback_t cb);
2157
2158 /**
2159 * @brief Unregister a link callback.
2160 *
2161 * @param link Caller specified handler for the callback.
2162 */
2163 void net_if_unregister_link_cb(struct net_if_link_cb *link);
2164
2165 /**
2166 * @brief Call a link callback function.
2167 *
2168 * @param iface Network interface.
2169 * @param lladdr Destination link layer address
2170 * @param status 0 is ok, < 0 error
2171 */
2172 void net_if_call_link_cb(struct net_if *iface, struct net_linkaddr *lladdr,
2173 int status);
2174
2175 /**
2176 * @brief Check if received network packet checksum calculation can be avoided
2177 * or not. For example many ethernet devices support network packet offloading
2178 * in which case the IP stack does not need to calculate the checksum.
2179 *
2180 * @param iface Network interface
2181 *
2182 * @return True if checksum needs to be calculated, false otherwise.
2183 */
2184 bool net_if_need_calc_rx_checksum(struct net_if *iface);
2185
2186 /**
2187 * @brief Check if network packet checksum calculation can be avoided or not
2188 * when sending the packet. For example many ethernet devices support network
2189 * packet offloading in which case the IP stack does not need to calculate the
2190 * checksum.
2191 *
2192 * @param iface Network interface
2193 *
2194 * @return True if checksum needs to be calculated, false otherwise.
2195 */
2196 bool net_if_need_calc_tx_checksum(struct net_if *iface);
2197
2198 /**
2199 * @brief Get interface according to index
2200 *
2201 * @details This is a syscall only to provide access to the object for purposes
2202 * of assigning permissions.
2203 *
2204 * @param index Interface index
2205 *
2206 * @return Pointer to interface or NULL if not found.
2207 */
2208 __syscall struct net_if *net_if_get_by_index(int index);
2209
2210 /**
2211 * @brief Get interface index according to pointer
2212 *
2213 * @param iface Pointer to network interface
2214 *
2215 * @return Interface index
2216 */
2217 int net_if_get_by_iface(struct net_if *iface);
2218
2219 /**
2220 * @typedef net_if_cb_t
2221 * @brief Callback used while iterating over network interfaces
2222 *
2223 * @param iface Pointer to current network interface
2224 * @param user_data A valid pointer to user data or NULL
2225 */
2226 typedef void (*net_if_cb_t)(struct net_if *iface, void *user_data);
2227
2228 /**
2229 * @brief Go through all the network interfaces and call callback
2230 * for each interface.
2231 *
2232 * @param cb User-supplied callback function to call
2233 * @param user_data User specified data
2234 */
2235 void net_if_foreach(net_if_cb_t cb, void *user_data);
2236
2237 /**
2238 * @brief Bring interface up
2239 *
2240 * @param iface Pointer to network interface
2241 *
2242 * @return 0 on success
2243 */
2244 int net_if_up(struct net_if *iface);
2245
2246 /**
2247 * @brief Check if interface is is up and running.
2248 *
2249 * @param iface Pointer to network interface
2250 *
2251 * @return True if interface is up, False if it is down.
2252 */
net_if_is_up(struct net_if * iface)2253 static inline bool net_if_is_up(struct net_if *iface)
2254 {
2255 NET_ASSERT(iface);
2256
2257 return net_if_flag_is_set(iface, NET_IF_UP) &&
2258 net_if_flag_is_set(iface, NET_IF_RUNNING);
2259 }
2260
2261 /**
2262 * @brief Bring interface down
2263 *
2264 * @param iface Pointer to network interface
2265 *
2266 * @return 0 on success
2267 */
2268 int net_if_down(struct net_if *iface);
2269
2270 /**
2271 * @brief Check if interface was brought up by the administrator.
2272 *
2273 * @param iface Pointer to network interface
2274 *
2275 * @return True if interface is admin up, false otherwise.
2276 */
net_if_is_admin_up(struct net_if * iface)2277 static inline bool net_if_is_admin_up(struct net_if *iface)
2278 {
2279 NET_ASSERT(iface);
2280
2281 return net_if_flag_is_set(iface, NET_IF_UP);
2282 }
2283
2284 /**
2285 * @brief Underlying network device has detected the carrier (cable connected).
2286 *
2287 * @details The function should be used by the respective network device driver
2288 * or L2 implementation to update its state on a network interface.
2289 *
2290 * @param iface Pointer to network interface
2291 */
2292 void net_if_carrier_on(struct net_if *iface);
2293
2294 /**
2295 * @brief Underlying network device has lost the carrier (cable disconnected).
2296 *
2297 * @details The function should be used by the respective network device driver
2298 * or L2 implementation to update its state on a network interface.
2299 *
2300 * @param iface Pointer to network interface
2301 */
2302 void net_if_carrier_off(struct net_if *iface);
2303
2304 /**
2305 * @brief Check if carrier is present on network device.
2306 *
2307 * @param iface Pointer to network interface
2308 *
2309 * @return True if carrier is present, false otherwise.
2310 */
net_if_is_carrier_ok(struct net_if * iface)2311 static inline bool net_if_is_carrier_ok(struct net_if *iface)
2312 {
2313 NET_ASSERT(iface);
2314
2315 return net_if_flag_is_set(iface, NET_IF_LOWER_UP);
2316 }
2317
2318 /**
2319 * @brief Mark interface as dormant. Dormant state indicates that the interface
2320 * is not ready to pass packets yet, but is waiting for some event
2321 * (for example Wi-Fi network association).
2322 *
2323 * @details The function should be used by the respective network device driver
2324 * or L2 implementation to update its state on a network interface.
2325 *
2326 * @param iface Pointer to network interface
2327 */
2328 void net_if_dormant_on(struct net_if *iface);
2329
2330 /**
2331 * @brief Mark interface as not dormant.
2332 *
2333 * @details The function should be used by the respective network device driver
2334 * or L2 implementation to update its state on a network interface.
2335 *
2336 * @param iface Pointer to network interface
2337 */
2338 void net_if_dormant_off(struct net_if *iface);
2339
2340 /**
2341 * @brief Check if the interface is dormant.
2342 *
2343 * @param iface Pointer to network interface
2344 *
2345 * @return True if interface is dormant, false otherwise.
2346 */
net_if_is_dormant(struct net_if * iface)2347 static inline bool net_if_is_dormant(struct net_if *iface)
2348 {
2349 NET_ASSERT(iface);
2350
2351 return net_if_flag_is_set(iface, NET_IF_DORMANT);
2352 }
2353
2354 #if defined(CONFIG_NET_PKT_TIMESTAMP) && defined(CONFIG_NET_NATIVE)
2355 /**
2356 * @typedef net_if_timestamp_callback_t
2357 * @brief Define callback that is called after a network packet
2358 * has been timestamped.
2359 * @param "struct net_pkt *pkt" A pointer on a struct net_pkt which has
2360 * been timestamped after being sent.
2361 */
2362 typedef void (*net_if_timestamp_callback_t)(struct net_pkt *pkt);
2363
2364 /**
2365 * @brief Timestamp callback handler struct.
2366 *
2367 * Stores the timestamp callback information. Caller must make sure that
2368 * the variable pointed by this is valid during the lifetime of
2369 * registration. Typically this means that the variable cannot be
2370 * allocated from stack.
2371 */
2372 struct net_if_timestamp_cb {
2373 /** Node information for the slist. */
2374 sys_snode_t node;
2375
2376 /** Packet for which the callback is needed.
2377 * A NULL value means all packets.
2378 */
2379 struct net_pkt *pkt;
2380
2381 /** Net interface for which the callback is needed.
2382 * A NULL value means all interfaces.
2383 */
2384 struct net_if *iface;
2385
2386 /** Timestamp callback */
2387 net_if_timestamp_callback_t cb;
2388 };
2389
2390 /**
2391 * @brief Register a timestamp callback.
2392 *
2393 * @param handle Caller specified handler for the callback.
2394 * @param pkt Net packet for which the callback is registered. NULL for all
2395 * packets.
2396 * @param iface Net interface for which the callback is. NULL for all
2397 * interfaces.
2398 * @param cb Callback to register.
2399 */
2400 void net_if_register_timestamp_cb(struct net_if_timestamp_cb *handle,
2401 struct net_pkt *pkt,
2402 struct net_if *iface,
2403 net_if_timestamp_callback_t cb);
2404
2405 /**
2406 * @brief Unregister a timestamp callback.
2407 *
2408 * @param handle Caller specified handler for the callback.
2409 */
2410 void net_if_unregister_timestamp_cb(struct net_if_timestamp_cb *handle);
2411
2412 /**
2413 * @brief Call a timestamp callback function.
2414 *
2415 * @param pkt Network buffer.
2416 */
2417 void net_if_call_timestamp_cb(struct net_pkt *pkt);
2418
2419 /*
2420 * @brief Add timestamped TX buffer to be handled
2421 *
2422 * @param pkt Timestamped buffer
2423 */
2424 void net_if_add_tx_timestamp(struct net_pkt *pkt);
2425 #endif /* CONFIG_NET_PKT_TIMESTAMP */
2426
2427 /**
2428 * @brief Set network interface into promiscuous mode
2429 *
2430 * @details Note that not all network technologies will support this.
2431 *
2432 * @param iface Pointer to network interface
2433 *
2434 * @return 0 on success, <0 if error
2435 */
2436 #if defined(CONFIG_NET_PROMISCUOUS_MODE)
2437 int net_if_set_promisc(struct net_if *iface);
2438 #else
net_if_set_promisc(struct net_if * iface)2439 static inline int net_if_set_promisc(struct net_if *iface)
2440 {
2441 ARG_UNUSED(iface);
2442
2443 return -ENOTSUP;
2444 }
2445 #endif
2446
2447 /**
2448 * @brief Set network interface into normal mode
2449 *
2450 * @param iface Pointer to network interface
2451 */
2452 #if defined(CONFIG_NET_PROMISCUOUS_MODE)
2453 void net_if_unset_promisc(struct net_if *iface);
2454 #else
net_if_unset_promisc(struct net_if * iface)2455 static inline void net_if_unset_promisc(struct net_if *iface)
2456 {
2457 ARG_UNUSED(iface);
2458 }
2459 #endif
2460
2461 /**
2462 * @brief Check if promiscuous mode is set or not.
2463 *
2464 * @param iface Pointer to network interface
2465 *
2466 * @return True if interface is in promisc mode,
2467 * False if interface is not in in promiscuous mode.
2468 */
2469 #if defined(CONFIG_NET_PROMISCUOUS_MODE)
2470 bool net_if_is_promisc(struct net_if *iface);
2471 #else
net_if_is_promisc(struct net_if * iface)2472 static inline bool net_if_is_promisc(struct net_if *iface)
2473 {
2474 ARG_UNUSED(iface);
2475
2476 return false;
2477 }
2478 #endif
2479
2480 /**
2481 * @brief Check if there are any pending TX network data for a given network
2482 * interface.
2483 *
2484 * @param iface Pointer to network interface
2485 *
2486 * @return True if there are pending TX network packets for this network
2487 * interface, False otherwise.
2488 */
net_if_are_pending_tx_packets(struct net_if * iface)2489 static inline bool net_if_are_pending_tx_packets(struct net_if *iface)
2490 {
2491 #if defined(CONFIG_NET_POWER_MANAGEMENT)
2492 return !!iface->tx_pending;
2493 #else
2494 ARG_UNUSED(iface);
2495
2496 return false;
2497 #endif
2498 }
2499
2500 #ifdef CONFIG_NET_POWER_MANAGEMENT
2501 /**
2502 * @brief Suspend a network interface from a power management perspective
2503 *
2504 * @param iface Pointer to network interface
2505 *
2506 * @return 0 on success, or -EALREADY/-EBUSY as possible errors.
2507 */
2508 int net_if_suspend(struct net_if *iface);
2509
2510 /**
2511 * @brief Resume a network interface from a power management perspective
2512 *
2513 * @param iface Pointer to network interface
2514 *
2515 * @return 0 on success, or -EALREADY as a possible error.
2516 */
2517 int net_if_resume(struct net_if *iface);
2518
2519 /**
2520 * @brief Check if the network interface is suspended or not.
2521 *
2522 * @param iface Pointer to network interface
2523 *
2524 * @return True if interface is suspended, False otherwise.
2525 */
2526 bool net_if_is_suspended(struct net_if *iface);
2527 #endif /* CONFIG_NET_POWER_MANAGEMENT */
2528
2529 /** @cond INTERNAL_HIDDEN */
2530 struct net_if_api {
2531 void (*init)(struct net_if *iface);
2532 };
2533
2534 #if defined(CONFIG_NET_IP)
2535 #define NET_IF_IP_INIT .ip = {},
2536 #else
2537 #define NET_IF_IP_INIT
2538 #endif
2539
2540 #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
2541 #define NET_IF_DHCPV4_INIT .dhcpv4.state = NET_DHCPV4_DISABLED,
2542 #else
2543 #define NET_IF_DHCPV4_INIT
2544 #endif
2545
2546 #define NET_IF_CONFIG_INIT \
2547 .config = { \
2548 NET_IF_IP_INIT \
2549 NET_IF_DHCPV4_INIT \
2550 }
2551
2552 #define NET_IF_GET_NAME(dev_id, sfx) __net_if_##dev_id##_##sfx
2553 #define NET_IF_DEV_GET_NAME(dev_id, sfx) __net_if_dev_##dev_id##_##sfx
2554
2555 #define NET_IF_GET(dev_id, sfx) \
2556 ((struct net_if *)&NET_IF_GET_NAME(dev_id, sfx))
2557
2558 #define NET_IF_INIT(dev_id, sfx, _l2, _mtu, _num_configs) \
2559 static STRUCT_SECTION_ITERABLE(net_if_dev, \
2560 NET_IF_DEV_GET_NAME(dev_id, sfx)) = { \
2561 .dev = &(DEVICE_NAME_GET(dev_id)), \
2562 .l2 = &(NET_L2_GET_NAME(_l2)), \
2563 .l2_data = &(NET_L2_GET_DATA(dev_id, sfx)), \
2564 .mtu = _mtu, \
2565 }; \
2566 static Z_DECL_ALIGN(struct net_if) \
2567 NET_IF_GET_NAME(dev_id, sfx)[_num_configs] \
2568 __used __in_section(_net_if, static, \
2569 dev_id) = { \
2570 [0 ... (_num_configs - 1)] = { \
2571 .if_dev = &(NET_IF_DEV_GET_NAME(dev_id, sfx)), \
2572 NET_IF_CONFIG_INIT \
2573 } \
2574 }
2575
2576 #define NET_IF_OFFLOAD_INIT(dev_id, sfx, _mtu) \
2577 static STRUCT_SECTION_ITERABLE(net_if_dev, \
2578 NET_IF_DEV_GET_NAME(dev_id, sfx)) = { \
2579 .dev = &(DEVICE_NAME_GET(dev_id)), \
2580 .mtu = _mtu, \
2581 .l2 = &(NET_L2_GET_NAME(OFFLOADED_NETDEV)), \
2582 }; \
2583 static Z_DECL_ALIGN(struct net_if) \
2584 NET_IF_GET_NAME(dev_id, sfx)[NET_IF_MAX_CONFIGS] \
2585 __used __in_section(_net_if, static, \
2586 dev_id) = { \
2587 [0 ... (NET_IF_MAX_CONFIGS - 1)] = { \
2588 .if_dev = &(NET_IF_DEV_GET_NAME(dev_id, sfx)), \
2589 NET_IF_CONFIG_INIT \
2590 } \
2591 }
2592
2593 /** @endcond */
2594
2595 /* Network device initialization macros */
2596
2597 #define Z_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
2598 config, prio, api, l2, l2_ctx_type, mtu) \
2599 Z_DEVICE_STATE_DEFINE(dev_id); \
2600 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
2601 config, POST_KERNEL, prio, api, \
2602 &Z_DEVICE_STATE_NAME(dev_id)); \
2603 NET_L2_DATA_INIT(dev_id, 0, l2_ctx_type); \
2604 NET_IF_INIT(dev_id, 0, l2, mtu, NET_IF_MAX_CONFIGS)
2605
2606 /**
2607 * @brief Create a network interface and bind it to network device.
2608 *
2609 * @param dev_id Network device id.
2610 * @param name The name this instance of the driver exposes to
2611 * the system.
2612 * @param init_fn Address to the init function of the driver.
2613 * @param pm Reference to struct pm_device associated with the device.
2614 * (optional).
2615 * @param data Pointer to the device's private data.
2616 * @param config The address to the structure containing the
2617 * configuration information for this instance of the driver.
2618 * @param prio The initialization level at which configuration occurs.
2619 * @param api Provides an initial pointer to the API function struct
2620 * used by the driver. Can be NULL.
2621 * @param l2 Network L2 layer for this network interface.
2622 * @param l2_ctx_type Type of L2 context data.
2623 * @param mtu Maximum transfer unit in bytes for this network interface.
2624 */
2625 #define NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, prio, \
2626 api, l2, l2_ctx_type, mtu) \
2627 Z_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, pm, \
2628 data, config, prio, api, l2, l2_ctx_type, mtu)
2629
2630 /**
2631 * @brief Like NET_DEVICE_INIT but taking metadata from a devicetree node.
2632 * Create a network interface and bind it to network device.
2633 *
2634 * @param node_id The devicetree node identifier.
2635 * @param init_fn Address to the init function of the driver.
2636 * @param pm Reference to struct pm_device associated with the device.
2637 * (optional).
2638 * @param data Pointer to the device's private data.
2639 * @param config The address to the structure containing the
2640 * configuration information for this instance of the driver.
2641 * @param prio The initialization level at which configuration occurs.
2642 * @param api Provides an initial pointer to the API function struct
2643 * used by the driver. Can be NULL.
2644 * @param l2 Network L2 layer for this network interface.
2645 * @param l2_ctx_type Type of L2 context data.
2646 * @param mtu Maximum transfer unit in bytes for this network interface.
2647 */
2648 #define NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, \
2649 config, prio, api, l2, l2_ctx_type, mtu) \
2650 Z_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
2651 DEVICE_DT_NAME(node_id), init_fn, pm, data, \
2652 config, prio, api, l2, l2_ctx_type, mtu)
2653
2654 /**
2655 * @brief Like NET_DEVICE_DT_DEFINE for an instance of a DT_DRV_COMPAT compatible
2656 *
2657 * @param inst instance number. This is replaced by
2658 * <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_DEFINE.
2659 *
2660 * @param ... other parameters as expected by NET_DEVICE_DT_DEFINE.
2661 */
2662 #define NET_DEVICE_DT_INST_DEFINE(inst, ...) \
2663 NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
2664
2665 #define Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
2666 init_fn, pm, data, config, prio, \
2667 api, l2, l2_ctx_type, mtu) \
2668 Z_DEVICE_STATE_DEFINE(dev_id); \
2669 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
2670 config, POST_KERNEL, prio, api, \
2671 &Z_DEVICE_STATE_NAME(dev_id)); \
2672 NET_L2_DATA_INIT(dev_id, instance, l2_ctx_type); \
2673 NET_IF_INIT(dev_id, instance, l2, mtu, NET_IF_MAX_CONFIGS)
2674
2675 /**
2676 * @brief Create multiple network interfaces and bind them to network device.
2677 * If your network device needs more than one instance of a network interface,
2678 * use this macro below and provide a different instance suffix each time
2679 * (0, 1, 2, ... or a, b, c ... whatever works for you)
2680 *
2681 * @param dev_id Network device id.
2682 * @param name The name this instance of the driver exposes to
2683 * the system.
2684 * @param instance Instance identifier.
2685 * @param init_fn Address to the init function of the driver.
2686 * @param pm Reference to struct pm_device associated with the device.
2687 * (optional).
2688 * @param data Pointer to the device's private data.
2689 * @param config The address to the structure containing the
2690 * configuration information for this instance of the driver.
2691 * @param prio The initialization level at which configuration occurs.
2692 * @param api Provides an initial pointer to the API function struct
2693 * used by the driver. Can be NULL.
2694 * @param l2 Network L2 layer for this network interface.
2695 * @param l2_ctx_type Type of L2 context data.
2696 * @param mtu Maximum transfer unit in bytes for this network interface.
2697 */
2698 #define NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, pm, \
2699 data, config, prio, api, l2, \
2700 l2_ctx_type, mtu) \
2701 Z_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
2702 instance, init_fn, pm, data, config, \
2703 prio, api, l2, l2_ctx_type, mtu)
2704
2705 /**
2706 * @brief Like NET_DEVICE_OFFLOAD_INIT but taking metadata from a devicetree.
2707 * Create multiple network interfaces and bind them to network device.
2708 * If your network device needs more than one instance of a network interface,
2709 * use this macro below and provide a different instance suffix each time
2710 * (0, 1, 2, ... or a, b, c ... whatever works for you)
2711 *
2712 * @param node_id The devicetree node identifier.
2713 * @param instance Instance identifier.
2714 * @param init_fn Address to the init function of the driver.
2715 * @param pm Reference to struct pm_device associated with the device.
2716 * (optional).
2717 * @param data Pointer to the device's private data.
2718 * @param config The address to the structure containing the
2719 * configuration information for this instance of the driver.
2720 * @param prio The initialization level at which configuration occurs.
2721 * @param api Provides an initial pointer to the API function struct
2722 * used by the driver. Can be NULL.
2723 * @param l2 Network L2 layer for this network interface.
2724 * @param l2_ctx_type Type of L2 context data.
2725 * @param mtu Maximum transfer unit in bytes for this network interface.
2726 */
2727 #define NET_DEVICE_DT_DEFINE_INSTANCE(node_id, instance, init_fn, pm, \
2728 data, config, prio, api, l2, \
2729 l2_ctx_type, mtu) \
2730 Z_NET_DEVICE_INIT_INSTANCE(node_id, \
2731 Z_DEVICE_DT_DEV_ID(node_id), \
2732 DEVICE_DT_NAME(node_id), instance, \
2733 init_fn, pm, data, config, prio, \
2734 api, l2, l2_ctx_type, mtu)
2735
2736 /**
2737 * @brief Like NET_DEVICE_DT_DEFINE_INSTANCE for an instance of a DT_DRV_COMPAT
2738 * compatible
2739 *
2740 * @param inst instance number. This is replaced by
2741 * <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_DEFINE_INSTANCE.
2742 *
2743 * @param ... other parameters as expected by NET_DEVICE_DT_DEFINE_INSTANCE.
2744 */
2745 #define NET_DEVICE_DT_INST_DEFINE_INSTANCE(inst, ...) \
2746 NET_DEVICE_DT_DEFINE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
2747
2748 #define Z_NET_DEVICE_OFFLOAD_INIT(node_id, dev_id, name, init_fn, pm, \
2749 data, config, prio, api, mtu) \
2750 Z_DEVICE_STATE_DEFINE(dev_id); \
2751 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
2752 config, POST_KERNEL, prio, api, \
2753 &Z_DEVICE_STATE_NAME(dev_id)); \
2754 NET_IF_OFFLOAD_INIT(dev_id, 0, mtu)
2755
2756 /**
2757 * @brief Create a offloaded network interface and bind it to network device.
2758 * The offloaded network interface is implemented by a device vendor HAL or
2759 * similar.
2760 *
2761 * @param dev_id Network device id.
2762 * @param name The name this instance of the driver exposes to
2763 * the system.
2764 * @param init_fn Address to the init function of the driver.
2765 * @param pm Reference to struct pm_device associated with the device.
2766 * (optional).
2767 * @param data Pointer to the device's private data.
2768 * @param config The address to the structure containing the
2769 * configuration information for this instance of the driver.
2770 * @param prio The initialization level at which configuration occurs.
2771 * @param api Provides an initial pointer to the API function struct
2772 * used by the driver. Can be NULL.
2773 * @param mtu Maximum transfer unit in bytes for this network interface.
2774 */
2775 #define NET_DEVICE_OFFLOAD_INIT(dev_id, name, init_fn, pm, data, \
2776 config, prio, api, mtu) \
2777 Z_NET_DEVICE_OFFLOAD_INIT(DT_INVALID_NODE, dev_id, name, \
2778 init_fn, pm, data, config, prio, api, \
2779 mtu)
2780
2781 /**
2782 * @brief Like NET_DEVICE_OFFLOAD_INIT but taking metadata from a devicetree
2783 * node. Create a offloaded network interface and bind it to network device.
2784 * The offloaded network interface is implemented by a device vendor HAL or
2785 * similar.
2786 *
2787 * @param node_id The devicetree node identifier.
2788 * @param init_fn Address to the init function of the driver.
2789 * @param pm Reference to struct pm_device associated with the device.
2790 * (optional).
2791 * @param data Pointer to the device's private data.
2792 * @param config The address to the structure containing the
2793 * configuration information for this instance of the driver.
2794 * @param prio The initialization level at which configuration occurs.
2795 * @param api Provides an initial pointer to the API function struct
2796 * used by the driver. Can be NULL.
2797 * @param mtu Maximum transfer unit in bytes for this network interface.
2798 */
2799 #define NET_DEVICE_DT_OFFLOAD_DEFINE(node_id, init_fn, pm, data, \
2800 config, prio, api, mtu) \
2801 Z_NET_DEVICE_OFFLOAD_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
2802 DEVICE_DT_NAME(node_id), init_fn, pm, \
2803 data, config, prio, api, mtu)
2804
2805 /**
2806 * @brief Like NET_DEVICE_DT_OFFLOAD_DEFINE for an instance of a DT_DRV_COMPAT
2807 * compatible
2808 *
2809 * @param inst instance number. This is replaced by
2810 * <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_OFFLOAD_DEFINE.
2811 *
2812 * @param ... other parameters as expected by NET_DEVICE_DT_OFFLOAD_DEFINE.
2813 */
2814 #define NET_DEVICE_DT_INST_OFFLOAD_DEFINE(inst, ...) \
2815 NET_DEVICE_DT_OFFLOAD_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
2816
2817 #ifdef __cplusplus
2818 }
2819 #endif
2820
2821 #include <syscalls/net_if.h>
2822
2823 /**
2824 * @}
2825 */
2826
2827 #endif /* ZEPHYR_INCLUDE_NET_NET_IF_H_ */
2828