Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.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_ula_addr(const struct in6_addr *addr)
852{
853 return addr->s6_addr[0] == 0xFD;
854}
855
862
869
876
877struct net_if;
878extern bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
879 const struct in_addr *addr);
880
890static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
891 const struct in_addr *addr)
892{
893 return net_if_ipv4_addr_mask_cmp(iface, addr);
894}
895
896extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
897 const struct in_addr *addr);
898
907#if defined(CONFIG_NET_NATIVE_IPV4)
908static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
909 const struct in_addr *addr)
910{
912 return true;
913 }
914
915 return net_if_ipv4_is_addr_bcast(iface, addr);
916}
917#else
918static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
919 const struct in_addr *addr)
920{
921 ARG_UNUSED(iface);
922 ARG_UNUSED(addr);
923
924 return false;
925}
926#endif
927
928extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
929 struct net_if **iface);
930
940static inline bool net_ipv4_is_my_addr(const struct in_addr *addr)
941{
942 bool ret;
943
944 ret = net_if_ipv4_addr_lookup(addr, NULL) != NULL;
945 if (!ret) {
946 ret = net_ipv4_is_addr_bcast(NULL, addr);
947 }
948
949 return ret;
950}
951
959static inline bool net_ipv6_is_addr_unspecified(const struct in6_addr *addr)
960{
961 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
962 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
963 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
964 UNALIGNED_GET(&addr->s6_addr32[3]) == 0;
965}
966
975static inline bool net_ipv6_is_addr_solicited_node(const struct in6_addr *addr)
976{
977 return UNALIGNED_GET(&addr->s6_addr32[0]) == htonl(0xff020000) &&
978 UNALIGNED_GET(&addr->s6_addr32[1]) == 0x00000000 &&
979 UNALIGNED_GET(&addr->s6_addr32[2]) == htonl(0x00000001) &&
980 ((UNALIGNED_GET(&addr->s6_addr32[3]) & htonl(0xff000000)) ==
981 htonl(0xff000000));
982}
983
994static inline bool net_ipv6_is_addr_mcast_scope(const struct in6_addr *addr,
995 int scope)
996{
997 return (addr->s6_addr[0] == 0xff) && (addr->s6_addr[1] == scope);
998}
999
1009static inline bool net_ipv6_is_same_mcast_scope(const struct in6_addr *addr_1,
1010 const struct in6_addr *addr_2)
1011{
1012 return (addr_1->s6_addr[0] == 0xff) && (addr_2->s6_addr[0] == 0xff) &&
1013 (addr_1->s6_addr[1] == addr_2->s6_addr[1]);
1014}
1015
1023static inline bool net_ipv6_is_addr_mcast_global(const struct in6_addr *addr)
1024{
1025 return net_ipv6_is_addr_mcast_scope(addr, 0x0e);
1026}
1027
1037static inline bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
1038{
1039 return net_ipv6_is_addr_mcast_scope(addr, 0x01);
1040}
1041
1051static inline bool net_ipv6_is_addr_mcast_link(const struct in6_addr *addr)
1052{
1053 return net_ipv6_is_addr_mcast_scope(addr, 0x02);
1054}
1055
1065static inline bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
1066{
1067 return net_ipv6_is_addr_mcast_scope(addr, 0x03);
1068}
1069
1079static inline bool net_ipv6_is_addr_mcast_site(const struct in6_addr *addr)
1080{
1081 return net_ipv6_is_addr_mcast_scope(addr, 0x05);
1082}
1083
1093static inline bool net_ipv6_is_addr_mcast_org(const struct in6_addr *addr)
1094{
1095 return net_ipv6_is_addr_mcast_scope(addr, 0x08);
1096}
1097
1108static inline bool net_ipv6_is_addr_mcast_group(const struct in6_addr *addr,
1109 const struct in6_addr *group)
1110{
1111 return UNALIGNED_GET(&addr->s6_addr16[1]) == group->s6_addr16[1] &&
1112 UNALIGNED_GET(&addr->s6_addr16[2]) == group->s6_addr16[2] &&
1113 UNALIGNED_GET(&addr->s6_addr16[3]) == group->s6_addr16[3] &&
1114 UNALIGNED_GET(&addr->s6_addr32[1]) == group->s6_addr32[1] &&
1115 UNALIGNED_GET(&addr->s6_addr32[2]) == group->s6_addr32[1] &&
1116 UNALIGNED_GET(&addr->s6_addr32[3]) == group->s6_addr32[3];
1117}
1118
1127static inline bool
1129{
1130 static const struct in6_addr all_nodes_mcast_group = {
1131 { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1132 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
1133 };
1134
1135 return net_ipv6_is_addr_mcast_group(addr, &all_nodes_mcast_group);
1136}
1137
1147static inline bool
1149{
1150 return net_ipv6_is_addr_mcast_iface(addr) &&
1152}
1153
1163static inline bool
1165{
1166 return net_ipv6_is_addr_mcast_link(addr) &&
1168}
1169
1177static inline
1179 struct in6_addr *dst)
1180{
1181 dst->s6_addr[0] = 0xFF;
1182 dst->s6_addr[1] = 0x02;
1183 UNALIGNED_PUT(0, &dst->s6_addr16[1]);
1184 UNALIGNED_PUT(0, &dst->s6_addr16[2]);
1185 UNALIGNED_PUT(0, &dst->s6_addr16[3]);
1186 UNALIGNED_PUT(0, &dst->s6_addr16[4]);
1187 dst->s6_addr[10] = 0U;
1188 dst->s6_addr[11] = 0x01;
1189 dst->s6_addr[12] = 0xFF;
1190 dst->s6_addr[13] = src->s6_addr[13];
1191 UNALIGNED_PUT(UNALIGNED_GET(&src->s6_addr16[7]), &dst->s6_addr16[7]);
1192}
1193
1206static inline void net_ipv6_addr_create(struct in6_addr *addr,
1207 uint16_t addr0, uint16_t addr1,
1208 uint16_t addr2, uint16_t addr3,
1209 uint16_t addr4, uint16_t addr5,
1210 uint16_t addr6, uint16_t addr7)
1211{
1212 UNALIGNED_PUT(htons(addr0), &addr->s6_addr16[0]);
1213 UNALIGNED_PUT(htons(addr1), &addr->s6_addr16[1]);
1214 UNALIGNED_PUT(htons(addr2), &addr->s6_addr16[2]);
1215 UNALIGNED_PUT(htons(addr3), &addr->s6_addr16[3]);
1216 UNALIGNED_PUT(htons(addr4), &addr->s6_addr16[4]);
1217 UNALIGNED_PUT(htons(addr5), &addr->s6_addr16[5]);
1218 UNALIGNED_PUT(htons(addr6), &addr->s6_addr16[6]);
1219 UNALIGNED_PUT(htons(addr7), &addr->s6_addr16[7]);
1220}
1221
1227static inline void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
1228{
1229 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
1230}
1231
1238{
1239 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002);
1240}
1241
1248static inline void net_ipv6_addr_create_iid(struct in6_addr *addr,
1249 struct net_linkaddr *lladdr)
1250{
1251 UNALIGNED_PUT(htonl(0xfe800000), &addr->s6_addr32[0]);
1252 UNALIGNED_PUT(0, &addr->s6_addr32[1]);
1253
1254 switch (lladdr->len) {
1255 case 2:
1256 /* The generated IPv6 shall not toggle the
1257 * Universal/Local bit. RFC 6282 ch 3.2.2
1258 */
1259 if (lladdr->type == NET_LINK_IEEE802154) {
1260 UNALIGNED_PUT(0, &addr->s6_addr32[2]);
1261 addr->s6_addr[11] = 0xff;
1262 addr->s6_addr[12] = 0xfe;
1263 addr->s6_addr[13] = 0U;
1264 addr->s6_addr[14] = lladdr->addr[0];
1265 addr->s6_addr[15] = lladdr->addr[1];
1266 }
1267
1268 break;
1269 case 6:
1270 /* We do not toggle the Universal/Local bit
1271 * in Bluetooth. See RFC 7668 ch 3.2.2
1272 */
1273 memcpy(&addr->s6_addr[8], lladdr->addr, 3);
1274 addr->s6_addr[11] = 0xff;
1275 addr->s6_addr[12] = 0xfe;
1276 memcpy(&addr->s6_addr[13], lladdr->addr + 3, 3);
1277
1278#if defined(CONFIG_NET_L2_BT_ZEP1656)
1279 /* Workaround against older Linux kernel BT IPSP code.
1280 * This will be removed eventually.
1281 */
1282 if (lladdr->type == NET_LINK_BLUETOOTH) {
1283 addr->s6_addr[8] ^= 0x02;
1284 }
1285#endif
1286
1287 if (lladdr->type == NET_LINK_ETHERNET) {
1288 addr->s6_addr[8] ^= 0x02;
1289 }
1290
1291 break;
1292 case 8:
1293 memcpy(&addr->s6_addr[8], lladdr->addr, lladdr->len);
1294 addr->s6_addr[8] ^= 0x02;
1295 break;
1296 }
1297}
1298
1304static inline bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr,
1305 const struct net_linkaddr *lladdr)
1306{
1307 if (!addr || !lladdr) {
1308 return false;
1309 }
1310
1311 switch (lladdr->len) {
1312 case 2:
1313 if (!memcmp(&addr->s6_addr[14], lladdr->addr, lladdr->len) &&
1314 addr->s6_addr[8] == 0U &&
1315 addr->s6_addr[9] == 0U &&
1316 addr->s6_addr[10] == 0U &&
1317 addr->s6_addr[11] == 0xff &&
1318 addr->s6_addr[12] == 0xfe) {
1319 return true;
1320 }
1321
1322 break;
1323 case 6:
1324 if (lladdr->type == NET_LINK_ETHERNET) {
1325 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1326 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1327 addr->s6_addr[11] == 0xff &&
1328 addr->s6_addr[12] == 0xfe &&
1329 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1330 return true;
1331 }
1332 } else if (lladdr->type == NET_LINK_BLUETOOTH) {
1333 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1334 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1335 addr->s6_addr[11] == 0xff &&
1336 addr->s6_addr[12] == 0xfe
1337#if defined(CONFIG_NET_L2_BT_ZEP1656)
1338 /* Workaround against older Linux kernel BT IPSP
1339 * code. This will be removed eventually.
1340 */
1341 && (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]
1342#endif
1343 ) {
1344 return true;
1345 }
1346 }
1347
1348 break;
1349 case 8:
1350 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1],
1351 lladdr->len - 1) &&
1352 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1353 return true;
1354 }
1355
1356 break;
1357 }
1358
1359 return false;
1360}
1361
1370static inline struct sockaddr_in6 *net_sin6(const struct sockaddr *addr)
1371{
1372 return (struct sockaddr_in6 *)addr;
1373}
1374
1383static inline struct sockaddr_in *net_sin(const struct sockaddr *addr)
1384{
1385 return (struct sockaddr_in *)addr;
1386}
1387
1396static inline
1397struct sockaddr_in6_ptr *net_sin6_ptr(const struct sockaddr_ptr *addr)
1398{
1399 return (struct sockaddr_in6_ptr *)addr;
1400}
1401
1410static inline
1411struct sockaddr_in_ptr *net_sin_ptr(const struct sockaddr_ptr *addr)
1412{
1413 return (struct sockaddr_in_ptr *)addr;
1414}
1415
1424static inline
1425struct sockaddr_ll_ptr *net_sll_ptr(const struct sockaddr_ptr *addr)
1426{
1427 return (struct sockaddr_ll_ptr *)addr;
1428}
1429
1438static inline
1439struct sockaddr_can_ptr *net_can_ptr(const struct sockaddr_ptr *addr)
1440{
1441 return (struct sockaddr_can_ptr *)addr;
1442}
1443
1457__syscall int net_addr_pton(sa_family_t family, const char *src, void *dst);
1458
1470__syscall char *net_addr_ntop(sa_family_t family, const void *src,
1471 char *dst, size_t size);
1472
1494bool net_ipaddr_parse(const char *str, size_t str_len,
1495 struct sockaddr *addr);
1496
1508static inline int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
1509{
1510 return (int32_t)(seq1 - seq2);
1511}
1512
1523static inline bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
1524{
1525 return net_tcp_seq_cmp(seq1, seq2) > 0;
1526}
1527
1539int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src);
1540
1550
1560
1569static inline enum net_priority net_vlan2priority(uint8_t priority)
1570{
1571 /* Map according to IEEE 802.1Q */
1572 static const uint8_t vlan2priority[] = {
1581 };
1582
1583 if (priority >= ARRAY_SIZE(vlan2priority)) {
1584 /* Use Best Effort as the default priority */
1585 return NET_PRIORITY_BE;
1586 }
1587
1588 return (enum net_priority)vlan2priority[priority];
1589}
1590
1598static inline uint8_t net_priority2vlan(enum net_priority priority)
1599{
1600 /* The conversion works both ways */
1601 return (uint8_t)net_vlan2priority(priority);
1602}
1603
1612const char *net_family2str(sa_family_t family);
1613
1614#ifdef __cplusplus
1615}
1616#endif
1617
1618#include <syscalls/net_ip.h>
1619
1625#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:1206
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:1093
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:1569
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition: net_ip.h:1508
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:1237
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:1148
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:940
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:1009
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:1065
static struct sockaddr_in_ptr * net_sin_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in_ptr from sockaddr_ptr.
Definition: net_ip.h:1411
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
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:1023
static void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
Create link local allnodes multicast IPv6 address.
Definition: net_ip.h:1227
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:975
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:1178
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:1108
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:1079
static void net_ipv6_addr_create_iid(struct in6_addr *addr, struct net_linkaddr *lladdr)
Create IPv6 address interface identifier.
Definition: net_ip.h:1248
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:1051
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:890
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:1598
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:1523
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_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:1164
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:1439
#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:918
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:1383
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:1128
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:1425
static struct sockaddr_in6 * net_sin6(const struct sockaddr *addr)
Get sockaddr_in6 from sockaddr.
Definition: net_ip.h:1370
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:994
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:851
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:1037
#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:1397
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:1304
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:959
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
Definition: net_ip.h:430
@ NET_PRIORITY_IC
Internetwork control
Definition: net_ip.h:429
@ NET_PRIORITY_CA
Critical applications (highest)
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:472
Network Interface multicast IP addresses.
Definition: net_if.h:93
Network Interface structure.
Definition: net_if.h:595
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.