Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
net_ip.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2016 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_NET_IP_H_
14#define ZEPHYR_INCLUDE_NET_NET_IP_H_
15
23#include <string.h>
24#include <zephyr/types.h>
25#include <stdbool.h>
26#include <zephyr/sys/util.h>
28#include <zephyr/toolchain.h>
29
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
37/* Specifying VLAN tag here in order to avoid circular dependencies */
38#define NET_VLAN_TAG_UNSPEC 0x0fff
41/* Protocol families. */
42#define PF_UNSPEC 0
43#define PF_INET 1
44#define PF_INET6 2
45#define PF_PACKET 3
46#define PF_CAN 4
47#define PF_NET_MGMT 5
48#define PF_LOCAL 6
49#define PF_UNIX PF_LOCAL
51/* Address families. */
52#define AF_UNSPEC PF_UNSPEC
53#define AF_INET PF_INET
54#define AF_INET6 PF_INET6
55#define AF_PACKET PF_PACKET
56#define AF_CAN PF_CAN
57#define AF_NET_MGMT PF_NET_MGMT
58#define AF_LOCAL PF_LOCAL
59#define AF_UNIX PF_UNIX
72};
73
81};
82
88};
89
96#define ntohs(x) sys_be16_to_cpu(x)
97
104#define ntohl(x) sys_be32_to_cpu(x)
105
112#define ntohll(x) sys_be64_to_cpu(x)
113
120#define htons(x) sys_cpu_to_be16(x)
121
128#define htonl(x) sys_cpu_to_be32(x)
129
136#define htonll(x) sys_cpu_to_be64(x)
137
139struct in6_addr {
140 union {
142 uint16_t s6_addr16[8]; /* In big endian */
143 uint32_t s6_addr32[4]; /* In big endian */
144 };
145};
146
147/* Binary size of the IPv6 address */
148#define NET_IPV6_ADDR_SIZE 16
149
151struct in_addr {
152 union {
154 uint16_t s4_addr16[2]; /* In big endian */
155 uint32_t s4_addr32[1]; /* In big endian */
156 uint32_t s_addr; /* In big endian, for POSIX compatibility. */
157 };
158};
159
160/* Binary size of the IPv4 address */
161#define NET_IPV4_ADDR_SIZE 4
162
164typedef unsigned short int sa_family_t;
165
167#ifndef __socklen_t_defined
168typedef size_t socklen_t;
169#define __socklen_t_defined
170#endif
171
172/*
173 * Note that the sin_port and sin6_port are in network byte order
174 * in various sockaddr* structs.
175 */
176
179 sa_family_t sin6_family; /* AF_INET6 */
180 uint16_t sin6_port; /* Port number */
181 struct in6_addr sin6_addr; /* IPv6 address */
182 uint8_t sin6_scope_id; /* interfaces for a scope */
183};
184
186 sa_family_t sin6_family; /* AF_INET6 */
187 uint16_t sin6_port; /* Port number */
188 struct in6_addr *sin6_addr; /* IPv6 address */
189 uint8_t sin6_scope_id; /* interfaces for a scope */
190};
191
194 sa_family_t sin_family; /* AF_INET */
195 uint16_t sin_port; /* Port number */
196 struct in_addr sin_addr; /* IPv4 address */
197};
198
200 sa_family_t sin_family; /* AF_INET */
201 uint16_t sin_port; /* Port number */
202 struct in_addr *sin_addr; /* IPv4 address */
203};
204
207 sa_family_t sll_family; /* Always AF_PACKET */
208 uint16_t sll_protocol; /* Physical-layer protocol */
209 int sll_ifindex; /* Interface number */
210 uint16_t sll_hatype; /* ARP hardware type */
211 uint8_t sll_pkttype; /* Packet type */
212 uint8_t sll_halen; /* Length of address */
213 uint8_t sll_addr[8]; /* Physical-layer address, big endian */
214};
215
217 sa_family_t sll_family; /* Always AF_PACKET */
218 uint16_t sll_protocol; /* Physical-layer protocol */
219 int sll_ifindex; /* Interface number */
220 uint16_t sll_hatype; /* ARP hardware type */
221 uint8_t sll_pkttype; /* Packet type */
222 uint8_t sll_halen; /* Length of address */
223 uint8_t *sll_addr; /* Physical-layer address, big endian */
224};
225
229};
230
231#if !defined(HAVE_IOVEC)
232struct iovec {
233 void *iov_base;
234 size_t iov_len;
235};
236#endif
237
238struct msghdr {
239 void *msg_name; /* optional socket address, big endian */
240 socklen_t msg_namelen; /* size of socket address */
241 struct iovec *msg_iov; /* scatter/gather array */
242 size_t msg_iovlen; /* number of elements in msg_iov */
243 void *msg_control; /* ancillary data */
244 size_t msg_controllen; /* ancillary data buffer len */
245 int msg_flags; /* flags on received message */
246};
247
248struct cmsghdr {
249 socklen_t cmsg_len; /* Number of bytes, including header */
250 int cmsg_level; /* Originating protocol */
251 int cmsg_type; /* Protocol-specific type */
252 /* Flexible array member to force alignment of cmsghdr */
253 z_max_align_t cmsg_data[];
254};
255
256/* Alignment for headers and data. These are arch specific but define
257 * them here atm if not found alredy.
258 */
259#if !defined(ALIGN_H)
260#define ALIGN_H(x) ROUND_UP(x, __alignof__(struct cmsghdr))
261#endif
262#if !defined(ALIGN_D)
263#define ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
264#endif
265
266#if !defined(CMSG_FIRSTHDR)
267#define CMSG_FIRSTHDR(msghdr) \
268 ((msghdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
269 (struct cmsghdr *)((msghdr)->msg_control) : NULL)
270#endif
271
272#if !defined(CMSG_NXTHDR)
273#define CMSG_NXTHDR(msghdr, cmsg) \
274 (((cmsg) == NULL) ? CMSG_FIRSTHDR(msghdr) : \
275 (((uint8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) + \
276 ALIGN_D(sizeof(struct cmsghdr)) > \
277 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
278 NULL : \
279 (struct cmsghdr *)((uint8_t *)(cmsg) + \
280 ALIGN_H((cmsg)->cmsg_len))))
281#endif
282
283#if !defined(CMSG_DATA)
284#define CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + ALIGN_D(sizeof(struct cmsghdr)))
285#endif
286
287#if !defined(CMSG_SPACE)
288#define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + ALIGN_H(length))
289#endif
290
291#if !defined(CMSG_LEN)
292#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + length)
293#endif
294
297/* Packet types. */
298#define PACKET_HOST 0 /* To us */
299#define PACKET_BROADCAST 1 /* To all */
300#define PACKET_MULTICAST 2 /* To group */
301#define PACKET_OTHERHOST 3 /* To someone else */
302#define PACKET_OUTGOING 4 /* Originated by us */
303#define PACKET_LOOPBACK 5
304#define PACKET_FASTROUTE 6
305
306/* ARP protocol HARDWARE identifiers. */
307#define ARPHRD_ETHER 1
308
309/* Note: These macros are defined in a specific order.
310 * The largest sockaddr size is the last one.
311 */
312#if defined(CONFIG_NET_IPV4)
313#undef NET_SOCKADDR_MAX_SIZE
314#undef NET_SOCKADDR_PTR_MAX_SIZE
315#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in))
316#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in_ptr))
317#endif
318
319#if defined(CONFIG_NET_SOCKETS_PACKET)
320#undef NET_SOCKADDR_MAX_SIZE
321#undef NET_SOCKADDR_PTR_MAX_SIZE
322#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_ll))
323#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_ll_ptr))
324#endif
325
326#if defined(CONFIG_NET_IPV6)
327#undef NET_SOCKADDR_MAX_SIZE
328#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
329#if !defined(CONFIG_NET_SOCKETS_PACKET)
330#undef NET_SOCKADDR_PTR_MAX_SIZE
331#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
332#endif
333#endif
334
335#if !defined(CONFIG_NET_IPV4)
336#if !defined(CONFIG_NET_IPV6)
337#if !defined(CONFIG_NET_SOCKETS_PACKET)
338#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
339#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
340#endif
341#endif
342#endif
343
347struct sockaddr {
349 char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
350};
351
354struct sockaddr_ptr {
355 sa_family_t family;
356 char data[NET_SOCKADDR_PTR_MAX_SIZE - sizeof(sa_family_t)];
357};
358
359/* Same as sockaddr in our case */
360struct sockaddr_storage {
361 sa_family_t ss_family;
362 char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
363};
364
365/* Socket address struct for UNIX domain sockets */
366struct sockaddr_un {
367 sa_family_t sun_family; /* AF_UNIX */
368 char sun_path[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
369};
370
371struct net_addr {
372 sa_family_t family;
373 union {
374 struct in6_addr in6_addr;
375 struct in_addr in_addr;
376 };
377};
378
379#define IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, \
380 0, 0, 0, 0, 0, 0, 0 } } }
381#define IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, \
382 0, 0, 0, 0, 0, 0, 0, 0, 1 } } }
383
384extern const struct in6_addr in6addr_any;
385extern const struct in6_addr in6addr_loopback;
386
390#define INET_ADDRSTRLEN 16
394#define INET6_ADDRSTRLEN 46
395
398/* These are for internal usage of the stack */
399#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")
400#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
401
402#define INADDR_ANY 0
403#define INADDR_ANY_INIT { { { INADDR_ANY } } }
404
405#define INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
406
414
419};
420
430 NET_PRIORITY_NC = 7
431} __packed;
432
433#define NET_MAX_PRIORITIES 8 /* How many priority values there are */
434
436struct net_tuple {
437 struct net_addr *remote_addr;
438 struct net_addr *local_addr;
442};
443
450} __packed;
451
464} __packed;
465
468struct net_ipv6_hdr {
469 uint8_t vtc;
470 uint8_t tcflow;
471 uint16_t flow;
472 uint16_t len;
473 uint8_t nexthdr;
474 uint8_t hop_limit;
477} __packed;
478
479struct net_ipv6_frag_hdr {
480 uint8_t nexthdr;
481 uint8_t reserved;
482 uint16_t offset;
483 uint32_t id;
484} __packed;
485
486struct net_ipv4_hdr {
487 uint8_t vhl;
488 uint8_t tos;
489 uint16_t len;
490 uint8_t id[2];
491 uint8_t offset[2];
492 uint8_t ttl;
493 uint8_t proto;
494 uint16_t chksum;
497} __packed;
498
499struct net_icmp_hdr {
500 uint8_t type;
501 uint8_t code;
502 uint16_t chksum;
503} __packed;
504
505struct net_udp_hdr {
506 uint16_t src_port;
507 uint16_t dst_port;
508 uint16_t len;
509 uint16_t chksum;
510} __packed;
511
512struct net_tcp_hdr {
513 uint16_t src_port;
514 uint16_t dst_port;
515 uint8_t seq[4];
516 uint8_t ack[4];
517 uint8_t offset;
519 uint8_t wnd[2];
520 uint16_t chksum;
521 uint8_t urg[2];
522 uint8_t optdata[0];
523} __packed;
524
525static inline const char *net_addr_type2str(enum net_addr_type type)
526{
527 switch (type) {
529 return "AUTO";
530 case NET_ADDR_DHCP:
531 return "DHCP";
532 case NET_ADDR_MANUAL:
533 return "MANUAL";
535 return "OVERRIDE";
536 case NET_ADDR_ANY:
537 default:
538 break;
539 }
540
541 return "<unknown>";
542}
543
544/* IPv6 extension headers types */
545#define NET_IPV6_NEXTHDR_HBHO 0
546#define NET_IPV6_NEXTHDR_DESTO 60
547#define NET_IPV6_NEXTHDR_ROUTING 43
548#define NET_IPV6_NEXTHDR_FRAG 44
549#define NET_IPV6_NEXTHDR_NONE 59
550
555union net_ip_header {
556 struct net_ipv4_hdr *ipv4;
557 struct net_ipv6_hdr *ipv6;
558};
559
560union net_proto_header {
561 struct net_udp_hdr *udp;
562 struct net_tcp_hdr *tcp;
563};
564
565#define NET_UDPH_LEN 8 /* Size of UDP header */
566#define NET_TCPH_LEN 20 /* Size of TCP header */
567#define NET_ICMPH_LEN 4 /* Size of ICMP header */
568
569#define NET_IPV6H_LEN 40 /* Size of IPv6 header */
570#define NET_ICMPV6H_LEN NET_ICMPH_LEN /* Size of ICMPv6 header */
571#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN) /* IPv6 + UDP */
572#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN) /* IPv6 + TCP */
573#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN) /* ICMPv6 + IPv6 */
574#define NET_IPV6_FRAGH_LEN 8
575
576#define NET_IPV4H_LEN 20 /* Size of IPv4 header */
577#define NET_ICMPV4H_LEN NET_ICMPH_LEN /* Size of ICMPv4 header */
578#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN) /* IPv4 + UDP */
579#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN) /* IPv4 + TCP */
580#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN) /* ICMPv4 + IPv4 */
581
582#define NET_IPV6H_LENGTH_OFFSET 0x04 /* Offset of the Length field in the IPv6 header */
583
584#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8 /* Mask for the 13-bit Fragment Offset field */
585#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff /* Mask for the 13-bit Fragment Offset field */
586#define NET_IPV4_MORE_FRAG_MASK 0x2000 /* Mask for the 1-bit More Fragments field */
587#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000 /* Mask for the 1-bit Do Not Fragment field */
588
598static inline bool net_ipv6_is_addr_loopback(struct in6_addr *addr)
599{
600 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
601 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
602 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
603 ntohl(UNALIGNED_GET(&addr->s6_addr32[3])) == 1;
604}
605
613static inline bool net_ipv6_is_addr_mcast(const struct in6_addr *addr)
614{
615 return addr->s6_addr[0] == 0xFF;
616}
617
618struct net_if;
619struct net_if_config;
620
621extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
622 struct net_if **iface);
623
631static inline bool net_ipv6_is_my_addr(struct in6_addr *addr)
632{
633 return net_if_ipv6_addr_lookup(addr, NULL) != NULL;
634}
635
637 const struct in6_addr *addr, struct net_if **iface);
638
647static inline bool net_ipv6_is_my_maddr(struct in6_addr *maddr)
648{
649 return net_if_ipv6_maddr_lookup(maddr, NULL) != NULL;
650}
651
661static inline bool net_ipv6_is_prefix(const uint8_t *addr1,
662 const uint8_t *addr2,
663 uint8_t length)
664{
665 uint8_t bits = 128 - length;
666 uint8_t bytes = length / 8U;
667 uint8_t remain = bits % 8;
668 uint8_t mask;
669
670 if (length > 128) {
671 return false;
672 }
673
674 if (memcmp(addr1, addr2, bytes)) {
675 return false;
676 }
677
678 if (!remain) {
679 /* No remaining bits, the prefixes are the same as first
680 * bytes are the same.
681 */
682 return true;
683 }
684
685 /* Create a mask that has remaining most significant bits set */
686 mask = ((0xff << (8 - remain)) ^ 0xff) << remain;
687
688 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
689}
690
698static inline bool net_ipv4_is_addr_loopback(struct in_addr *addr)
699{
700 return addr->s4_addr[0] == 127U;
701}
702
710static inline bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
711{
712 return UNALIGNED_GET(&addr->s_addr) == 0;
713}
714
722static inline bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
723{
724 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xF0000000) == 0xE0000000;
725}
726
734static inline bool net_ipv4_is_ll_addr(const struct in_addr *addr)
735{
736 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFF0000) == 0xA9FE0000;
737}
738
747#define net_ipaddr_copy(dest, src) \
748 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
749
756static inline void net_ipv4_addr_copy_raw(uint8_t *dest,
757 const uint8_t *src)
758{
759 net_ipaddr_copy((struct in_addr *)dest, (const struct in_addr *)src);
760}
761
768static inline void net_ipv6_addr_copy_raw(uint8_t *dest,
769 const uint8_t *src)
770{
771 memcpy(dest, src, sizeof(struct in6_addr));
772}
773
782static inline bool net_ipv4_addr_cmp(const struct in_addr *addr1,
783 const struct in_addr *addr2)
784{
785 return UNALIGNED_GET(&addr1->s_addr) == UNALIGNED_GET(&addr2->s_addr);
786}
787
796static inline bool net_ipv4_addr_cmp_raw(const uint8_t *addr1,
797 const uint8_t *addr2)
798{
799 return net_ipv4_addr_cmp((const struct in_addr *)addr1,
800 (const struct in_addr *)addr2);
801}
802
811static inline bool net_ipv6_addr_cmp(const struct in6_addr *addr1,
812 const struct in6_addr *addr2)
813{
814 return !memcmp(addr1, addr2, sizeof(struct in6_addr));
815}
816
825static inline bool net_ipv6_addr_cmp_raw(const uint8_t *addr1,
826 const uint8_t *addr2)
827{
828 return net_ipv6_addr_cmp((const struct in6_addr *)addr1,
829 (const struct in6_addr *)addr2);
830}
831
839static inline bool net_ipv6_is_ll_addr(const struct in6_addr *addr)
840{
841 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFE80);
842}
843
851static inline bool net_ipv6_is_sl_addr(const struct in6_addr *addr)
852{
853 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFEC0);
854}
855
856
864static inline bool net_ipv6_is_ula_addr(const struct in6_addr *addr)
865{
866 return addr->s6_addr[0] == 0xFD;
867}
868
876static inline bool net_ipv6_is_global_addr(const struct in6_addr *addr)
877{
878 return (addr->s6_addr[0] & 0xE0) == 0x20;
879}
880
887
894
901
902struct net_if;
903extern bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
904 const struct in_addr *addr);
905
915static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
916 const struct in_addr *addr)
917{
918 return net_if_ipv4_addr_mask_cmp(iface, addr);
919}
920
921extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
922 const struct in_addr *addr);
923
932#if defined(CONFIG_NET_NATIVE_IPV4)
933static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
934 const struct in_addr *addr)
935{
937 return true;
938 }
939
940 return net_if_ipv4_is_addr_bcast(iface, addr);
941}
942#else
943static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
944 const struct in_addr *addr)
945{
946 ARG_UNUSED(iface);
947 ARG_UNUSED(addr);
948
949 return false;
950}
951#endif
952
953extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
954 struct net_if **iface);
955
965static inline bool net_ipv4_is_my_addr(const struct in_addr *addr)
966{
967 bool ret;
968
969 ret = net_if_ipv4_addr_lookup(addr, NULL) != NULL;
970 if (!ret) {
971 ret = net_ipv4_is_addr_bcast(NULL, addr);
972 }
973
974 return ret;
975}
976
984static inline bool net_ipv6_is_addr_unspecified(const struct in6_addr *addr)
985{
986 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
987 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
988 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
989 UNALIGNED_GET(&addr->s6_addr32[3]) == 0;
990}
991
1000static inline bool net_ipv6_is_addr_solicited_node(const struct in6_addr *addr)
1001{
1002 return UNALIGNED_GET(&addr->s6_addr32[0]) == htonl(0xff020000) &&
1003 UNALIGNED_GET(&addr->s6_addr32[1]) == 0x00000000 &&
1004 UNALIGNED_GET(&addr->s6_addr32[2]) == htonl(0x00000001) &&
1005 ((UNALIGNED_GET(&addr->s6_addr32[3]) & htonl(0xff000000)) ==
1006 htonl(0xff000000));
1007}
1008
1019static inline bool net_ipv6_is_addr_mcast_scope(const struct in6_addr *addr,
1020 int scope)
1021{
1022 return (addr->s6_addr[0] == 0xff) && (addr->s6_addr[1] == scope);
1023}
1024
1034static inline bool net_ipv6_is_same_mcast_scope(const struct in6_addr *addr_1,
1035 const struct in6_addr *addr_2)
1036{
1037 return (addr_1->s6_addr[0] == 0xff) && (addr_2->s6_addr[0] == 0xff) &&
1038 (addr_1->s6_addr[1] == addr_2->s6_addr[1]);
1039}
1040
1048static inline bool net_ipv6_is_addr_mcast_global(const struct in6_addr *addr)
1049{
1050 return net_ipv6_is_addr_mcast_scope(addr, 0x0e);
1051}
1052
1062static inline bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
1063{
1064 return net_ipv6_is_addr_mcast_scope(addr, 0x01);
1065}
1066
1076static inline bool net_ipv6_is_addr_mcast_link(const struct in6_addr *addr)
1077{
1078 return net_ipv6_is_addr_mcast_scope(addr, 0x02);
1079}
1080
1090static inline bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
1091{
1092 return net_ipv6_is_addr_mcast_scope(addr, 0x03);
1093}
1094
1104static inline bool net_ipv6_is_addr_mcast_site(const struct in6_addr *addr)
1105{
1106 return net_ipv6_is_addr_mcast_scope(addr, 0x05);
1107}
1108
1118static inline bool net_ipv6_is_addr_mcast_org(const struct in6_addr *addr)
1119{
1120 return net_ipv6_is_addr_mcast_scope(addr, 0x08);
1121}
1122
1133static inline bool net_ipv6_is_addr_mcast_group(const struct in6_addr *addr,
1134 const struct in6_addr *group)
1135{
1136 return UNALIGNED_GET(&addr->s6_addr16[1]) == group->s6_addr16[1] &&
1137 UNALIGNED_GET(&addr->s6_addr16[2]) == group->s6_addr16[2] &&
1138 UNALIGNED_GET(&addr->s6_addr16[3]) == group->s6_addr16[3] &&
1139 UNALIGNED_GET(&addr->s6_addr32[1]) == group->s6_addr32[1] &&
1140 UNALIGNED_GET(&addr->s6_addr32[2]) == group->s6_addr32[1] &&
1141 UNALIGNED_GET(&addr->s6_addr32[3]) == group->s6_addr32[3];
1142}
1143
1152static inline bool
1154{
1155 static const struct in6_addr all_nodes_mcast_group = {
1156 { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1157 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
1158 };
1159
1160 return net_ipv6_is_addr_mcast_group(addr, &all_nodes_mcast_group);
1161}
1162
1172static inline bool
1174{
1175 return net_ipv6_is_addr_mcast_iface(addr) &&
1177}
1178
1188static inline bool
1190{
1191 return net_ipv6_is_addr_mcast_link(addr) &&
1193}
1194
1202static inline
1204 struct in6_addr *dst)
1205{
1206 dst->s6_addr[0] = 0xFF;
1207 dst->s6_addr[1] = 0x02;
1208 UNALIGNED_PUT(0, &dst->s6_addr16[1]);
1209 UNALIGNED_PUT(0, &dst->s6_addr16[2]);
1210 UNALIGNED_PUT(0, &dst->s6_addr16[3]);
1211 UNALIGNED_PUT(0, &dst->s6_addr16[4]);
1212 dst->s6_addr[10] = 0U;
1213 dst->s6_addr[11] = 0x01;
1214 dst->s6_addr[12] = 0xFF;
1215 dst->s6_addr[13] = src->s6_addr[13];
1216 UNALIGNED_PUT(UNALIGNED_GET(&src->s6_addr16[7]), &dst->s6_addr16[7]);
1217}
1218
1231static inline void net_ipv6_addr_create(struct in6_addr *addr,
1232 uint16_t addr0, uint16_t addr1,
1233 uint16_t addr2, uint16_t addr3,
1234 uint16_t addr4, uint16_t addr5,
1235 uint16_t addr6, uint16_t addr7)
1236{
1237 UNALIGNED_PUT(htons(addr0), &addr->s6_addr16[0]);
1238 UNALIGNED_PUT(htons(addr1), &addr->s6_addr16[1]);
1239 UNALIGNED_PUT(htons(addr2), &addr->s6_addr16[2]);
1240 UNALIGNED_PUT(htons(addr3), &addr->s6_addr16[3]);
1241 UNALIGNED_PUT(htons(addr4), &addr->s6_addr16[4]);
1242 UNALIGNED_PUT(htons(addr5), &addr->s6_addr16[5]);
1243 UNALIGNED_PUT(htons(addr6), &addr->s6_addr16[6]);
1244 UNALIGNED_PUT(htons(addr7), &addr->s6_addr16[7]);
1245}
1246
1252static inline void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
1253{
1254 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
1255}
1256
1263{
1264 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002);
1265}
1266
1273static inline void net_ipv6_addr_create_v4_mapped(const struct in_addr *addr4,
1274 struct in6_addr *addr6)
1275{
1276 net_ipv6_addr_create(addr6, 0, 0, 0, 0, 0, 0xffff,
1277 ntohs(addr4->s4_addr16[0]),
1278 ntohs(addr4->s4_addr16[1]));
1279}
1280
1289static inline bool net_ipv6_addr_is_v4_mapped(const struct in6_addr *addr)
1290{
1291 if (UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1292 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1293 UNALIGNED_GET(&addr->s6_addr16[5]) == 0xffff) {
1294 return true;
1295 }
1296
1297 return false;
1298}
1299
1306static inline void net_ipv6_addr_create_iid(struct in6_addr *addr,
1307 struct net_linkaddr *lladdr)
1308{
1309 UNALIGNED_PUT(htonl(0xfe800000), &addr->s6_addr32[0]);
1310 UNALIGNED_PUT(0, &addr->s6_addr32[1]);
1311
1312 switch (lladdr->len) {
1313 case 2:
1314 /* The generated IPv6 shall not toggle the
1315 * Universal/Local bit. RFC 6282 ch 3.2.2
1316 */
1317 if (lladdr->type == NET_LINK_IEEE802154) {
1318 UNALIGNED_PUT(0, &addr->s6_addr32[2]);
1319 addr->s6_addr[11] = 0xff;
1320 addr->s6_addr[12] = 0xfe;
1321 addr->s6_addr[13] = 0U;
1322 addr->s6_addr[14] = lladdr->addr[0];
1323 addr->s6_addr[15] = lladdr->addr[1];
1324 }
1325
1326 break;
1327 case 6:
1328 /* We do not toggle the Universal/Local bit
1329 * in Bluetooth. See RFC 7668 ch 3.2.2
1330 */
1331 memcpy(&addr->s6_addr[8], lladdr->addr, 3);
1332 addr->s6_addr[11] = 0xff;
1333 addr->s6_addr[12] = 0xfe;
1334 memcpy(&addr->s6_addr[13], lladdr->addr + 3, 3);
1335
1336#if defined(CONFIG_NET_L2_BT_ZEP1656)
1337 /* Workaround against older Linux kernel BT IPSP code.
1338 * This will be removed eventually.
1339 */
1340 if (lladdr->type == NET_LINK_BLUETOOTH) {
1341 addr->s6_addr[8] ^= 0x02;
1342 }
1343#endif
1344
1345 if (lladdr->type == NET_LINK_ETHERNET) {
1346 addr->s6_addr[8] ^= 0x02;
1347 }
1348
1349 break;
1350 case 8:
1351 memcpy(&addr->s6_addr[8], lladdr->addr, lladdr->len);
1352 addr->s6_addr[8] ^= 0x02;
1353 break;
1354 }
1355}
1356
1362static inline bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr,
1363 const struct net_linkaddr *lladdr)
1364{
1365 if (!addr || !lladdr) {
1366 return false;
1367 }
1368
1369 switch (lladdr->len) {
1370 case 2:
1371 if (!memcmp(&addr->s6_addr[14], lladdr->addr, lladdr->len) &&
1372 addr->s6_addr[8] == 0U &&
1373 addr->s6_addr[9] == 0U &&
1374 addr->s6_addr[10] == 0U &&
1375 addr->s6_addr[11] == 0xff &&
1376 addr->s6_addr[12] == 0xfe) {
1377 return true;
1378 }
1379
1380 break;
1381 case 6:
1382 if (lladdr->type == NET_LINK_ETHERNET) {
1383 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1384 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1385 addr->s6_addr[11] == 0xff &&
1386 addr->s6_addr[12] == 0xfe &&
1387 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1388 return true;
1389 }
1390 } else if (lladdr->type == NET_LINK_BLUETOOTH) {
1391 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1392 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1393 addr->s6_addr[11] == 0xff &&
1394 addr->s6_addr[12] == 0xfe
1395#if defined(CONFIG_NET_L2_BT_ZEP1656)
1396 /* Workaround against older Linux kernel BT IPSP
1397 * code. This will be removed eventually.
1398 */
1399 && (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]
1400#endif
1401 ) {
1402 return true;
1403 }
1404 }
1405
1406 break;
1407 case 8:
1408 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1],
1409 lladdr->len - 1) &&
1410 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1411 return true;
1412 }
1413
1414 break;
1415 }
1416
1417 return false;
1418}
1419
1428static inline struct sockaddr_in6 *net_sin6(const struct sockaddr *addr)
1429{
1430 return (struct sockaddr_in6 *)addr;
1431}
1432
1441static inline struct sockaddr_in *net_sin(const struct sockaddr *addr)
1442{
1443 return (struct sockaddr_in *)addr;
1444}
1445
1454static inline
1455struct sockaddr_in6_ptr *net_sin6_ptr(const struct sockaddr_ptr *addr)
1456{
1457 return (struct sockaddr_in6_ptr *)addr;
1458}
1459
1468static inline
1469struct sockaddr_in_ptr *net_sin_ptr(const struct sockaddr_ptr *addr)
1470{
1471 return (struct sockaddr_in_ptr *)addr;
1472}
1473
1482static inline
1483struct sockaddr_ll_ptr *net_sll_ptr(const struct sockaddr_ptr *addr)
1484{
1485 return (struct sockaddr_ll_ptr *)addr;
1486}
1487
1496static inline
1497struct sockaddr_can_ptr *net_can_ptr(const struct sockaddr_ptr *addr)
1498{
1499 return (struct sockaddr_can_ptr *)addr;
1500}
1501
1515__syscall int net_addr_pton(sa_family_t family, const char *src, void *dst);
1516
1528__syscall char *net_addr_ntop(sa_family_t family, const void *src,
1529 char *dst, size_t size);
1530
1552bool net_ipaddr_parse(const char *str, size_t str_len,
1553 struct sockaddr *addr);
1554
1566static inline int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
1567{
1568 return (int32_t)(seq1 - seq2);
1569}
1570
1581static inline bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
1582{
1583 return net_tcp_seq_cmp(seq1, seq2) > 0;
1584}
1585
1597int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src);
1598
1608
1618
1627static inline enum net_priority net_vlan2priority(uint8_t priority)
1628{
1629 /* Map according to IEEE 802.1Q */
1630 static const uint8_t vlan2priority[] = {
1639 };
1640
1641 if (priority >= ARRAY_SIZE(vlan2priority)) {
1642 /* Use Best Effort as the default priority */
1643 return NET_PRIORITY_BE;
1644 }
1645
1646 return (enum net_priority)vlan2priority[priority];
1647}
1648
1656static inline uint8_t net_priority2vlan(enum net_priority priority)
1657{
1658 /* The conversion works both ways */
1659 return (uint8_t)net_vlan2priority(priority);
1660}
1661
1670const char *net_family2str(sa_family_t family);
1671
1672#ifdef __cplusplus
1673}
1674#endif
1675
1676#include <syscalls/net_ip.h>
1677
1683#endif /* ZEPHYR_INCLUDE_NET_NET_IP_H_ */
static bool net_ipv6_is_my_addr(struct in6_addr *addr)
Check if IPv6 address is found in one of the network interfaces.
Definition: net_ip.h:631
struct net_if_addr * net_if_ipv4_addr_lookup(const struct in_addr *addr, struct net_if **iface)
static void net_ipv6_addr_create(struct in6_addr *addr, uint16_t addr0, uint16_t addr1, uint16_t addr2, uint16_t addr3, uint16_t addr4, uint16_t addr5, uint16_t addr6, uint16_t addr7)
Construct an IPv6 address from eight 16-bit words.
Definition: net_ip.h:1231
static bool net_ipv4_addr_cmp(const struct in_addr *addr1, const struct in_addr *addr2)
Compare two IPv4 addresses.
Definition: net_ip.h:782
#define NET_IPV4_ADDR_SIZE
Definition: net_ip.h:161
struct net_if_addr * net_if_ipv6_addr_lookup(const struct in6_addr *addr, struct net_if **iface)
static bool net_ipv6_is_addr_mcast_org(const struct in6_addr *addr)
Check if the IPv6 address is an organization scope multicast address (FFx8::).
Definition: net_ip.h:1118
static enum net_priority net_vlan2priority(uint8_t priority)
Convert network packet VLAN priority to network packet priority so we can place the packet into corre...
Definition: net_ip.h:1627
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition: net_ip.h:1566
static bool net_ipv6_is_addr_mcast(const struct in6_addr *addr)
Check if the IPv6 address is a multicast address.
Definition: net_ip.h:613
#define NET_IPV6_ADDR_SIZE
Definition: net_ip.h:148
int net_addr_pton(sa_family_t family, const char *src, void *dst)
Convert a string to IP address.
unsigned short int sa_family_t
Socket address family type.
Definition: net_ip.h:164
static void net_ipv6_addr_create_ll_allrouters_mcast(struct in6_addr *addr)
Create link local allrouters multicast IPv6 address.
Definition: net_ip.h:1262
char * net_addr_ntop(sa_family_t family, const void *src, char *dst, size_t size)
Convert IP address to string form.
net_addr_state
What is the current state of the network address.
Definition: net_ip.h:445
static bool net_ipv4_addr_cmp_raw(const uint8_t *addr1, const uint8_t *addr2)
Compare two raw IPv4 address buffers.
Definition: net_ip.h:796
static bool net_ipv6_addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2)
Compare two IPv6 addresses.
Definition: net_ip.h:811
static bool net_ipv6_is_addr_mcast_iface_all_nodes(const struct in6_addr *addr)
Check if the IPv6 address is a interface scope all nodes multicast address (FF01::1).
Definition: net_ip.h:1173
static bool net_ipv4_is_my_addr(const struct in_addr *addr)
Check if the IPv4 address is assigned to any network interface in the system.
Definition: net_ip.h:965
static bool net_ipv6_is_same_mcast_scope(const struct in6_addr *addr_1, const struct in6_addr *addr_2)
Check if the IPv6 addresses have the same multicast scope (FFyx::).
Definition: net_ip.h:1034
static void net_ipv6_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv6 address raw buffer.
Definition: net_ip.h:768
static bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
Check if the IPv6 address is a mesh-local scope multicast address (FFx3::).
Definition: net_ip.h:1090
static struct sockaddr_in_ptr * net_sin_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in_ptr from sockaddr_ptr.
Definition: net_ip.h:1469
const struct in_addr * net_ipv4_broadcast_address(void)
Return pointer to broadcast (all bits ones) IPv4 address.
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition: net_ip.h:120
static bool net_ipv6_addr_is_v4_mapped(const struct in6_addr *addr)
Is the IPv6 address an IPv4 mapped one.
Definition: net_ip.h:1289
bool net_if_ipv4_addr_mask_cmp(struct net_if *iface, const struct in_addr *addr)
static bool net_ipv6_is_addr_mcast_global(const struct in6_addr *addr)
Check if the IPv6 address is a global multicast address (FFxE::/16).
Definition: net_ip.h:1048
static void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
Create link local allnodes multicast IPv6 address.
Definition: net_ip.h:1252
static bool net_ipv6_is_addr_solicited_node(const struct in6_addr *addr)
Check if the IPv6 address is solicited node multicast address FF02:0:0:0:0:1:FFXX:XXXX defined in RFC...
Definition: net_ip.h:1000
static void net_ipv6_addr_create_solicited_node(const struct in6_addr *src, struct in6_addr *dst)
Create solicited node IPv6 multicast address FF02:0:0:0:0:1:FFXX:XXXX defined in RFC 3513.
Definition: net_ip.h:1203
static bool net_ipv6_is_addr_mcast_group(const struct in6_addr *addr, const struct in6_addr *group)
Check if the IPv6 address belongs to certain multicast group.
Definition: net_ip.h:1133
static bool net_ipv6_is_addr_mcast_site(const struct in6_addr *addr)
Check if the IPv6 address is a site scope multicast address (FFx5::).
Definition: net_ip.h:1104
static bool net_ipv6_is_sl_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a site local address.
Definition: net_ip.h:851
static void net_ipv6_addr_create_iid(struct in6_addr *addr, struct net_linkaddr *lladdr)
Create IPv6 address interface identifier.
Definition: net_ip.h:1306
static bool net_ipv6_is_addr_mcast_link(const struct in6_addr *addr)
Check if the IPv6 address is a link local scope multicast address (FFx2::).
Definition: net_ip.h:1076
static bool net_ipv4_addr_mask_cmp(struct net_if *iface, const struct in_addr *addr)
Check if the given address belongs to same subnet that has been configured for the interface.
Definition: net_ip.h:915
net_ip_protocol_secure
Protocol numbers for TLS protocols.
Definition: net_ip.h:75
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition: net_ip.h:747
net_ip_mtu
Definition: net_ip.h:409
int net_rx_priority2tc(enum net_priority prio)
Convert Rx network packet priority to traffic class so we can place the packet into correct Rx queue.
static bool net_ipv4_is_addr_loopback(struct in_addr *addr)
Check if the IPv4 address is a loopback address (127.0.0.0/8).
Definition: net_ip.h:698
int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src)
Convert a string of hex values to array of bytes.
static uint8_t net_priority2vlan(enum net_priority priority)
Convert network packet priority to network packet VLAN priority.
Definition: net_ip.h:1656
static void net_ipv6_addr_create_v4_mapped(const struct in_addr *addr4, struct in6_addr *addr6)
Create IPv4 mapped IPv6 address.
Definition: net_ip.h:1273
bool net_if_ipv4_is_addr_bcast(struct net_if *iface, const struct in_addr *addr)
static bool net_ipv6_is_prefix(const uint8_t *addr1, const uint8_t *addr2, uint8_t length)
Check if two IPv6 addresses are same when compared after prefix mask.
Definition: net_ip.h:661
bool net_ipaddr_parse(const char *str, size_t str_len, struct sockaddr *addr)
Parse a string that contains either IPv4 or IPv6 address and optional port, and store the information...
static bool net_ipv6_is_addr_loopback(struct in6_addr *addr)
Check if the IPv6 address is a loopback address (::1).
Definition: net_ip.h:598
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition: net_ip.h:1581
net_sock_type
Socket type.
Definition: net_ip.h:84
const struct in6_addr * net_ipv6_unspecified_address(void)
Return pointer to any (all bits zeros) IPv6 address.
static bool net_ipv6_is_global_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a global address.
Definition: net_ip.h:876
static bool net_ipv6_is_addr_mcast_link_all_nodes(const struct in6_addr *addr)
Check if the IPv6 address is a link local scope all nodes multicast address (FF02::1).
Definition: net_ip.h:1189
const char * net_family2str(sa_family_t family)
Return network address family value as a string.
static bool net_ipv4_is_ll_addr(const struct in_addr *addr)
Check if the given IPv4 address is a link local address.
Definition: net_ip.h:734
static struct sockaddr_can_ptr * net_can_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_can_ptr from sockaddr_ptr.
Definition: net_ip.h:1497
#define ntohl(x)
Convert 32-bit value from network to host byte order.
Definition: net_ip.h:104
static bool net_ipv4_is_addr_bcast(struct net_if *iface, const struct in_addr *addr)
Check if the given IPv4 address is a broadcast address.
Definition: net_ip.h:943
static bool net_ipv6_is_ll_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a link local address.
Definition: net_ip.h:839
static struct sockaddr_in * net_sin(const struct sockaddr *addr)
Get sockaddr_in from sockaddr.
Definition: net_ip.h:1441
const struct in_addr * net_ipv4_unspecified_address(void)
Return pointer to any (all bits zeros) IPv4 address.
static bool net_ipv6_is_addr_mcast_all_nodes_group(const struct in6_addr *addr)
Check if the IPv6 address belongs to the all nodes multicast group.
Definition: net_ip.h:1153
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
static struct sockaddr_ll_ptr * net_sll_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_ll_ptr from sockaddr_ptr.
Definition: net_ip.h:1483
static struct sockaddr_in6 * net_sin6(const struct sockaddr *addr)
Get sockaddr_in6 from sockaddr.
Definition: net_ip.h:1428
#define ntohs(x)
Convert 16-bit value from network to host byte order.
Definition: net_ip.h:96
struct net_if_mcast_addr * net_if_ipv6_maddr_lookup(const struct in6_addr *addr, struct net_if **iface)
static bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
Check if the IPv4 address is unspecified (all bits zero)
Definition: net_ip.h:710
static bool net_ipv6_is_addr_mcast_scope(const struct in6_addr *addr, int scope)
Check if the IPv6 address is a given scope multicast address (FFyx::).
Definition: net_ip.h:1019
static bool net_ipv6_is_ula_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a unique local address.
Definition: net_ip.h:864
static bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
Check if the IPv6 address is a interface scope multicast address (FFx1::).
Definition: net_ip.h:1062
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition: net_ip.h:128
int net_tx_priority2tc(enum net_priority prio)
Convert Tx network packet priority to traffic class so we can place the packet into correct Tx queue.
static struct sockaddr_in6_ptr * net_sin6_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in6_ptr from sockaddr_ptr.
Definition: net_ip.h:1455
net_priority
Network packet priority settings described in IEEE 802.1Q Annex I.1.
Definition: net_ip.h:422
static bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
Check if the IPv4 address is a multicast address.
Definition: net_ip.h:722
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition: net_ip.h:62
static bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr, const struct net_linkaddr *lladdr)
Check if given address is based on link layer address.
Definition: net_ip.h:1362
static void net_ipv4_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv4 address raw buffer.
Definition: net_ip.h:756
static bool net_ipv6_is_my_maddr(struct in6_addr *maddr)
Check if IPv6 multicast address is found in one of the network interfaces.
Definition: net_ip.h:647
static bool net_ipv6_addr_cmp_raw(const uint8_t *addr1, const uint8_t *addr2)
Compare two raw IPv6 address buffers.
Definition: net_ip.h:825
static bool net_ipv6_is_addr_unspecified(const struct in6_addr *addr)
Check if the IPv6 address is unspecified (all bits zero)
Definition: net_ip.h:984
net_addr_type
How the network address is assigned to network interface.
Definition: net_ip.h:453
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition: net_ip.h:446
@ NET_ADDR_TENTATIVE
Tentative address
Definition: net_ip.h:447
@ NET_ADDR_DEPRECATED
Deprecated address
Definition: net_ip.h:449
@ NET_ADDR_PREFERRED
Preferred address
Definition: net_ip.h:448
@ IPPROTO_TLS_1_1
TLS 1.1 protocol.
Definition: net_ip.h:77
@ IPPROTO_TLS_1_0
TLS 1.0 protocol.
Definition: net_ip.h:76
@ IPPROTO_DTLS_1_0
DTLS 1.0 protocol.
Definition: net_ip.h:79
@ IPPROTO_TLS_1_2
TLS 1.2 protocol.
Definition: net_ip.h:78
@ IPPROTO_DTLS_1_2
DTLS 1.2 protocol.
Definition: net_ip.h:80
@ NET_IPV4_MTU
IPv4 MTU length.
Definition: net_ip.h:418
@ NET_IPV6_MTU
IPv6 MTU length.
Definition: net_ip.h:413
@ SOCK_DGRAM
Datagram socket type.
Definition: net_ip.h:86
@ SOCK_RAW
RAW socket type
Definition: net_ip.h:87
@ SOCK_STREAM
Stream socket type
Definition: net_ip.h:85
@ NET_PRIORITY_NC
Network control (highest)
Definition: net_ip.h:430
@ NET_PRIORITY_IC
Internetwork control
Definition: net_ip.h:429
@ NET_PRIORITY_CA
Critical applications
Definition: net_ip.h:426
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter
Definition: net_ip.h:428
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition: net_ip.h:427
@ NET_PRIORITY_BE
Best effort (default)
Definition: net_ip.h:424
@ NET_PRIORITY_EE
Excellent effort
Definition: net_ip.h:425
@ NET_PRIORITY_BK
Background (lowest)
Definition: net_ip.h:423
@ IPPROTO_IP
IP protocol (pseudo-val for setsockopt()
Definition: net_ip.h:63
@ IPPROTO_RAW
RAW IP packets
Definition: net_ip.h:71
@ IPPROTO_IPIP
IPIP tunnels
Definition: net_ip.h:66
@ IPPROTO_TCP
TCP protocol
Definition: net_ip.h:67
@ IPPROTO_IGMP
IGMP protocol
Definition: net_ip.h:65
@ IPPROTO_ICMP
ICMP protocol
Definition: net_ip.h:64
@ IPPROTO_IPV6
IPv6 protocol
Definition: net_ip.h:69
@ IPPROTO_UDP
UDP protocol
Definition: net_ip.h:68
@ IPPROTO_ICMPV6
ICMPv6 protocol.
Definition: net_ip.h:70
@ NET_ADDR_ANY
Default value.
Definition: net_ip.h:455
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition: net_ip.h:463
@ NET_ADDR_DHCP
Address is from DHCP.
Definition: net_ip.h:459
@ NET_ADDR_MANUAL
Manually set address.
Definition: net_ip.h:461
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition: net_ip.h:457
@ NET_LINK_IEEE802154
IEEE 802.15.4 link address.
Definition: net_linkaddr.h:51
@ NET_LINK_ETHERNET
Ethernet link address.
Definition: net_linkaddr.h:55
@ NET_LINK_BLUETOOTH
Bluetooth IPSP link address.
Definition: net_linkaddr.h:53
#define ARRAY_SIZE(array)
Number of elements in the given array.
Definition: util.h:124
Public API for network link address.
flags
Definition: parser.h:96
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__INT32_TYPE__ int32_t
Definition: stdint.h:74
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
int memcmp(const void *m1, const void *m2, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
Definition: net_ip.h:248
int cmsg_type
Definition: net_ip.h:251
socklen_t cmsg_len
Definition: net_ip.h:249
z_max_align_t cmsg_data[]
Definition: net_ip.h:253
int cmsg_level
Definition: net_ip.h:250
IPv6 address struct.
Definition: net_ip.h:139
uint8_t s6_addr[16]
Definition: net_ip.h:141
uint32_t s6_addr32[4]
Definition: net_ip.h:143
uint16_t s6_addr16[8]
Definition: net_ip.h:142
IPv4 address struct.
Definition: net_ip.h:151
uint8_t s4_addr[4]
Definition: net_ip.h:153
uint32_t s_addr
Definition: net_ip.h:156
uint16_t s4_addr16[2]
Definition: net_ip.h:154
uint32_t s4_addr32[1]
Definition: net_ip.h:155
Definition: net_ip.h:232
void * iov_base
Definition: net_ip.h:233
size_t iov_len
Definition: net_ip.h:234
Definition: net_ip.h:238
struct iovec * msg_iov
Definition: net_ip.h:241
socklen_t msg_namelen
Definition: net_ip.h:240
void * msg_name
Definition: net_ip.h:239
int msg_flags
Definition: net_ip.h:245
size_t msg_controllen
Definition: net_ip.h:244
size_t msg_iovlen
Definition: net_ip.h:242
void * msg_control
Definition: net_ip.h:243
Network Interface unicast IP addresses.
Definition: net_if.h:52
IP and other configuration related data for network interface.
Definition: net_if.h:492
Network Interface multicast IP addresses.
Definition: net_if.h:93
Network Interface structure.
Definition: net_if.h:615
Hardware link address structure.
Definition: net_linkaddr.h:67
uint8_t * addr
The array of byte representing the address.
Definition: net_linkaddr.h:69
uint8_t type
What kind of address is this for.
Definition: net_linkaddr.h:75
uint8_t len
Length of that address array.
Definition: net_linkaddr.h:72
IPv6/IPv4 network connection tuple.
Definition: net_ip.h:436
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition: net_ip.h:437
uint16_t local_port
UDP/TCP local port
Definition: net_ip.h:440
enum net_ip_protocol ip_proto
IP protocol
Definition: net_ip.h:441
uint16_t remote_port
UDP/TCP remote port
Definition: net_ip.h:439
struct net_addr * local_addr
IPv6/IPv4 local address
Definition: net_ip.h:438
Definition: net_ip.h:226
sa_family_t can_family
Definition: net_ip.h:227
int can_ifindex
Definition: net_ip.h:228
Definition: net_ip.h:185
sa_family_t sin6_family
Definition: net_ip.h:186
uint16_t sin6_port
Definition: net_ip.h:187
uint8_t sin6_scope_id
Definition: net_ip.h:189
struct in6_addr * sin6_addr
Definition: net_ip.h:188
Socket address struct for IPv6.
Definition: net_ip.h:178
uint8_t sin6_scope_id
Definition: net_ip.h:182
struct in6_addr sin6_addr
Definition: net_ip.h:181
uint16_t sin6_port
Definition: net_ip.h:180
sa_family_t sin6_family
Definition: net_ip.h:179
Definition: net_ip.h:199
struct in_addr * sin_addr
Definition: net_ip.h:202
uint16_t sin_port
Definition: net_ip.h:201
sa_family_t sin_family
Definition: net_ip.h:200
Socket address struct for IPv4.
Definition: net_ip.h:193
uint16_t sin_port
Definition: net_ip.h:195
struct in_addr sin_addr
Definition: net_ip.h:196
sa_family_t sin_family
Definition: net_ip.h:194
Definition: net_ip.h:216
uint8_t * sll_addr
Definition: net_ip.h:223
uint16_t sll_hatype
Definition: net_ip.h:220
int sll_ifindex
Definition: net_ip.h:219
uint8_t sll_pkttype
Definition: net_ip.h:221
sa_family_t sll_family
Definition: net_ip.h:217
uint8_t sll_halen
Definition: net_ip.h:222
uint16_t sll_protocol
Definition: net_ip.h:218
Socket address struct for packet socket.
Definition: net_ip.h:206
uint8_t sll_pkttype
Definition: net_ip.h:211
uint16_t sll_hatype
Definition: net_ip.h:210
sa_family_t sll_family
Definition: net_ip.h:207
uint16_t sll_protocol
Definition: net_ip.h:208
int sll_ifindex
Definition: net_ip.h:209
uint8_t sll_halen
Definition: net_ip.h:212
uint8_t sll_addr[8]
Definition: net_ip.h:213
Generic sockaddr struct.
Definition: net_ip.h:347
char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)]
Definition: net_ip.h:349
sa_family_t sa_family
Definition: net_ip.h:348
Byte order helpers.
Macros to abstract toolchain specific capabilities.
Misc utilities.