Zephyr Project API  3.3.0
A Scalable Open Source RTOS
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
167typedef size_t socklen_t;
168
169/*
170 * Note that the sin_port and sin6_port are in network byte order
171 * in various sockaddr* structs.
172 */
173
176 sa_family_t sin6_family; /* AF_INET6 */
177 uint16_t sin6_port; /* Port number */
178 struct in6_addr sin6_addr; /* IPv6 address */
179 uint8_t sin6_scope_id; /* interfaces for a scope */
180};
181
183 sa_family_t sin6_family; /* AF_INET6 */
184 uint16_t sin6_port; /* Port number */
185 struct in6_addr *sin6_addr; /* IPv6 address */
186 uint8_t sin6_scope_id; /* interfaces for a scope */
187};
188
191 sa_family_t sin_family; /* AF_INET */
192 uint16_t sin_port; /* Port number */
193 struct in_addr sin_addr; /* IPv4 address */
194};
195
197 sa_family_t sin_family; /* AF_INET */
198 uint16_t sin_port; /* Port number */
199 struct in_addr *sin_addr; /* IPv4 address */
200};
201
204 sa_family_t sll_family; /* Always AF_PACKET */
205 uint16_t sll_protocol; /* Physical-layer protocol */
206 int sll_ifindex; /* Interface number */
207 uint16_t sll_hatype; /* ARP hardware type */
208 uint8_t sll_pkttype; /* Packet type */
209 uint8_t sll_halen; /* Length of address */
210 uint8_t sll_addr[8]; /* Physical-layer address, big endian */
211};
212
214 sa_family_t sll_family; /* Always AF_PACKET */
215 uint16_t sll_protocol; /* Physical-layer protocol */
216 int sll_ifindex; /* Interface number */
217 uint16_t sll_hatype; /* ARP hardware type */
218 uint8_t sll_pkttype; /* Packet type */
219 uint8_t sll_halen; /* Length of address */
220 uint8_t *sll_addr; /* Physical-layer address, big endian */
221};
222
226};
227
228#if !defined(HAVE_IOVEC)
229struct iovec {
230 void *iov_base;
231 size_t iov_len;
232};
233#endif
234
235struct msghdr {
236 void *msg_name; /* optional socket address, big endian */
237 socklen_t msg_namelen; /* size of socket address */
238 struct iovec *msg_iov; /* scatter/gather array */
239 size_t msg_iovlen; /* number of elements in msg_iov */
240 void *msg_control; /* ancillary data */
241 size_t msg_controllen; /* ancillary data buffer len */
242 int msg_flags; /* flags on received message */
243};
244
245struct cmsghdr {
246 socklen_t cmsg_len; /* Number of bytes, including header */
247 int cmsg_level; /* Originating protocol */
248 int cmsg_type; /* Protocol-specific type */
249 /* Flexible array member to force alignment of cmsghdr */
250 z_max_align_t cmsg_data[];
251};
252
253/* Alignment for headers and data. These are arch specific but define
254 * them here atm if not found alredy.
255 */
256#if !defined(ALIGN_H)
257#define ALIGN_H(x) ROUND_UP(x, __alignof__(struct cmsghdr))
258#endif
259#if !defined(ALIGN_D)
260#define ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
261#endif
262
263#if !defined(CMSG_FIRSTHDR)
264#define CMSG_FIRSTHDR(msghdr) \
265 ((msghdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
266 (struct cmsghdr *)((msghdr)->msg_control) : NULL)
267#endif
268
269#if !defined(CMSG_NXTHDR)
270#define CMSG_NXTHDR(msghdr, cmsg) \
271 (((cmsg) == NULL) ? CMSG_FIRSTHDR(msghdr) : \
272 (((uint8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) + \
273 ALIGN_D(sizeof(struct cmsghdr)) > \
274 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
275 NULL : \
276 (struct cmsghdr *)((uint8_t *)(cmsg) + \
277 ALIGN_H((cmsg)->cmsg_len))))
278#endif
279
280#if !defined(CMSG_DATA)
281#define CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + ALIGN_D(sizeof(struct cmsghdr)))
282#endif
283
284#if !defined(CMSG_SPACE)
285#define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + ALIGN_H(length))
286#endif
287
288#if !defined(CMSG_LEN)
289#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + length)
290#endif
291
294/* Packet types. */
295#define PACKET_HOST 0 /* To us */
296#define PACKET_BROADCAST 1 /* To all */
297#define PACKET_MULTICAST 2 /* To group */
298#define PACKET_OTHERHOST 3 /* To someone else */
299#define PACKET_OUTGOING 4 /* Originated by us */
300#define PACKET_LOOPBACK 5
301#define PACKET_FASTROUTE 6
302
303/* ARP protocol HARDWARE identifiers. */
304#define ARPHRD_ETHER 1
305
306/* Note: These macros are defined in a specific order.
307 * The largest sockaddr size is the last one.
308 */
309#if defined(CONFIG_NET_IPV4)
310#undef NET_SOCKADDR_MAX_SIZE
311#undef NET_SOCKADDR_PTR_MAX_SIZE
312#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in))
313#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in_ptr))
314#endif
315
316#if defined(CONFIG_NET_SOCKETS_PACKET)
317#undef NET_SOCKADDR_MAX_SIZE
318#undef NET_SOCKADDR_PTR_MAX_SIZE
319#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_ll))
320#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_ll_ptr))
321#endif
322
323#if defined(CONFIG_NET_IPV6)
324#undef NET_SOCKADDR_MAX_SIZE
325#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
326#if !defined(CONFIG_NET_SOCKETS_PACKET)
327#undef NET_SOCKADDR_PTR_MAX_SIZE
328#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
329#endif
330#endif
331
332#if !defined(CONFIG_NET_IPV4)
333#if !defined(CONFIG_NET_IPV6)
334#if !defined(CONFIG_NET_SOCKETS_PACKET)
335#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
336#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
337#endif
338#endif
339#endif
340
344struct sockaddr {
346 char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
347};
348
351struct sockaddr_ptr {
352 sa_family_t family;
353 char data[NET_SOCKADDR_PTR_MAX_SIZE - sizeof(sa_family_t)];
354};
355
356/* Same as sockaddr in our case */
357struct sockaddr_storage {
358 sa_family_t ss_family;
359 char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
360};
361
362/* Socket address struct for UNIX domain sockets */
363struct sockaddr_un {
364 sa_family_t sun_family; /* AF_UNIX */
365 char sun_path[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
366};
367
368struct net_addr {
369 sa_family_t family;
370 union {
371 struct in6_addr in6_addr;
372 struct in_addr in_addr;
373 };
374};
375
376#define IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, \
377 0, 0, 0, 0, 0, 0, 0 } } }
378#define IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, \
379 0, 0, 0, 0, 0, 0, 0, 0, 1 } } }
380
381extern const struct in6_addr in6addr_any;
382extern const struct in6_addr in6addr_loopback;
383
387#define INET_ADDRSTRLEN 16
391#define INET6_ADDRSTRLEN 46
392
395/* These are for internal usage of the stack */
396#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")
397#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
398
399#define INADDR_ANY 0
400#define INADDR_ANY_INIT { { { INADDR_ANY } } }
401
402#define INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
403
411
416};
417
427 NET_PRIORITY_NC = 7
428} __packed;
429
430#define NET_MAX_PRIORITIES 8 /* How many priority values there are */
431
433struct net_tuple {
434 struct net_addr *remote_addr;
435 struct net_addr *local_addr;
439};
440
447} __packed;
448
461} __packed;
462
465struct net_ipv6_hdr {
466 uint8_t vtc;
467 uint8_t tcflow;
468 uint16_t flow;
469 uint16_t len;
470 uint8_t nexthdr;
471 uint8_t hop_limit;
474} __packed;
475
476struct net_ipv6_frag_hdr {
477 uint8_t nexthdr;
478 uint8_t reserved;
479 uint16_t offset;
480 uint32_t id;
481} __packed;
482
483struct net_ipv4_hdr {
484 uint8_t vhl;
485 uint8_t tos;
486 uint16_t len;
487 uint8_t id[2];
488 uint8_t offset[2];
489 uint8_t ttl;
490 uint8_t proto;
491 uint16_t chksum;
494} __packed;
495
496struct net_icmp_hdr {
497 uint8_t type;
498 uint8_t code;
499 uint16_t chksum;
500} __packed;
501
502struct net_udp_hdr {
503 uint16_t src_port;
504 uint16_t dst_port;
505 uint16_t len;
506 uint16_t chksum;
507} __packed;
508
509struct net_tcp_hdr {
510 uint16_t src_port;
511 uint16_t dst_port;
512 uint8_t seq[4];
513 uint8_t ack[4];
514 uint8_t offset;
516 uint8_t wnd[2];
517 uint16_t chksum;
518 uint8_t urg[2];
519 uint8_t optdata[0];
520} __packed;
521
522static inline const char *net_addr_type2str(enum net_addr_type type)
523{
524 switch (type) {
526 return "AUTO";
527 case NET_ADDR_DHCP:
528 return "DHCP";
529 case NET_ADDR_MANUAL:
530 return "MANUAL";
532 return "OVERRIDE";
533 case NET_ADDR_ANY:
534 default:
535 break;
536 }
537
538 return "<unknown>";
539}
540
541/* IPv6 extension headers types */
542#define NET_IPV6_NEXTHDR_HBHO 0
543#define NET_IPV6_NEXTHDR_DESTO 60
544#define NET_IPV6_NEXTHDR_ROUTING 43
545#define NET_IPV6_NEXTHDR_FRAG 44
546#define NET_IPV6_NEXTHDR_NONE 59
547
552union net_ip_header {
553 struct net_ipv4_hdr *ipv4;
554 struct net_ipv6_hdr *ipv6;
555};
556
557union net_proto_header {
558 struct net_udp_hdr *udp;
559 struct net_tcp_hdr *tcp;
560};
561
562#define NET_UDPH_LEN 8 /* Size of UDP header */
563#define NET_TCPH_LEN 20 /* Size of TCP header */
564#define NET_ICMPH_LEN 4 /* Size of ICMP header */
565
566#define NET_IPV6H_LEN 40 /* Size of IPv6 header */
567#define NET_ICMPV6H_LEN NET_ICMPH_LEN /* Size of ICMPv6 header */
568#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN) /* IPv6 + UDP */
569#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN) /* IPv6 + TCP */
570#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN) /* ICMPv6 + IPv6 */
571#define NET_IPV6_FRAGH_LEN 8
572
573#define NET_IPV4H_LEN 20 /* Size of IPv4 header */
574#define NET_ICMPV4H_LEN NET_ICMPH_LEN /* Size of ICMPv4 header */
575#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN) /* IPv4 + UDP */
576#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN) /* IPv4 + TCP */
577#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN) /* ICMPv4 + IPv4 */
578
579#define NET_IPV6H_LENGTH_OFFSET 0x04 /* Offset of the Length field in the IPv6 header */
580
581#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8 /* Mask for the 13-bit Fragment Offset field */
582#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff /* Mask for the 13-bit Fragment Offset field */
583#define NET_IPV4_MORE_FRAG_MASK 0x2000 /* Mask for the 1-bit More Fragments field */
584#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000 /* Mask for the 1-bit Do Not Fragment field */
585
595static inline bool net_ipv6_is_addr_loopback(struct in6_addr *addr)
596{
597 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
598 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
599 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
600 ntohl(UNALIGNED_GET(&addr->s6_addr32[3])) == 1;
601}
602
610static inline bool net_ipv6_is_addr_mcast(const struct in6_addr *addr)
611{
612 return addr->s6_addr[0] == 0xFF;
613}
614
615struct net_if;
616struct net_if_config;
617
618extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
619 struct net_if **iface);
620
628static inline bool net_ipv6_is_my_addr(struct in6_addr *addr)
629{
630 return net_if_ipv6_addr_lookup(addr, NULL) != NULL;
631}
632
634 const struct in6_addr *addr, struct net_if **iface);
635
644static inline bool net_ipv6_is_my_maddr(struct in6_addr *maddr)
645{
646 return net_if_ipv6_maddr_lookup(maddr, NULL) != NULL;
647}
648
658static inline bool net_ipv6_is_prefix(const uint8_t *addr1,
659 const uint8_t *addr2,
660 uint8_t length)
661{
662 uint8_t bits = 128 - length;
663 uint8_t bytes = length / 8U;
664 uint8_t remain = bits % 8;
665 uint8_t mask;
666
667 if (length > 128) {
668 return false;
669 }
670
671 if (memcmp(addr1, addr2, bytes)) {
672 return false;
673 }
674
675 if (!remain) {
676 /* No remaining bits, the prefixes are the same as first
677 * bytes are the same.
678 */
679 return true;
680 }
681
682 /* Create a mask that has remaining most significant bits set */
683 mask = ((0xff << (8 - remain)) ^ 0xff) << remain;
684
685 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
686}
687
695static inline bool net_ipv4_is_addr_loopback(struct in_addr *addr)
696{
697 return addr->s4_addr[0] == 127U;
698}
699
707static inline bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
708{
709 return UNALIGNED_GET(&addr->s_addr) == 0;
710}
711
719static inline bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
720{
721 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xF0000000) == 0xE0000000;
722}
723
731static inline bool net_ipv4_is_ll_addr(const struct in_addr *addr)
732{
733 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xA9FE0000) == 0xA9FE0000;
734}
735
744#define net_ipaddr_copy(dest, src) \
745 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
746
753static inline void net_ipv4_addr_copy_raw(uint8_t *dest,
754 const uint8_t *src)
755{
756 net_ipaddr_copy((struct in_addr *)dest, (const struct in_addr *)src);
757}
758
765static inline void net_ipv6_addr_copy_raw(uint8_t *dest,
766 const uint8_t *src)
767{
768 memcpy(dest, src, sizeof(struct in6_addr));
769}
770
779static inline bool net_ipv4_addr_cmp(const struct in_addr *addr1,
780 const struct in_addr *addr2)
781{
782 return UNALIGNED_GET(&addr1->s_addr) == UNALIGNED_GET(&addr2->s_addr);
783}
784
793static inline bool net_ipv4_addr_cmp_raw(const uint8_t *addr1,
794 const uint8_t *addr2)
795{
796 return net_ipv4_addr_cmp((const struct in_addr *)addr1,
797 (const struct in_addr *)addr2);
798}
799
808static inline bool net_ipv6_addr_cmp(const struct in6_addr *addr1,
809 const struct in6_addr *addr2)
810{
811 return !memcmp(addr1, addr2, sizeof(struct in6_addr));
812}
813
822static inline bool net_ipv6_addr_cmp_raw(const uint8_t *addr1,
823 const uint8_t *addr2)
824{
825 return net_ipv6_addr_cmp((const struct in6_addr *)addr1,
826 (const struct in6_addr *)addr2);
827}
828
836static inline bool net_ipv6_is_ll_addr(const struct in6_addr *addr)
837{
838 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFE80);
839}
840
848static inline bool net_ipv6_is_ula_addr(const struct in6_addr *addr)
849{
850 return addr->s6_addr[0] == 0xFD;
851}
852
859
866
873
874struct net_if;
875extern bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
876 const struct in_addr *addr);
877
887static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
888 const struct in_addr *addr)
889{
890 return net_if_ipv4_addr_mask_cmp(iface, addr);
891}
892
893extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
894 const struct in_addr *addr);
895
904#if defined(CONFIG_NET_NATIVE_IPV4)
905static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
906 const struct in_addr *addr)
907{
909 return true;
910 }
911
912 return net_if_ipv4_is_addr_bcast(iface, addr);
913}
914#else
915static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
916 const struct in_addr *addr)
917{
918 ARG_UNUSED(iface);
919 ARG_UNUSED(addr);
920
921 return false;
922}
923#endif
924
925extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
926 struct net_if **iface);
927
937static inline bool net_ipv4_is_my_addr(const struct in_addr *addr)
938{
939 bool ret;
940
941 ret = net_if_ipv4_addr_lookup(addr, NULL) != NULL;
942 if (!ret) {
943 ret = net_ipv4_is_addr_bcast(NULL, addr);
944 }
945
946 return ret;
947}
948
956static inline bool net_ipv6_is_addr_unspecified(const struct in6_addr *addr)
957{
958 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
959 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
960 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
961 UNALIGNED_GET(&addr->s6_addr32[3]) == 0;
962}
963
972static inline bool net_ipv6_is_addr_solicited_node(const struct in6_addr *addr)
973{
974 return UNALIGNED_GET(&addr->s6_addr32[0]) == htonl(0xff020000) &&
975 UNALIGNED_GET(&addr->s6_addr32[1]) == 0x00000000 &&
976 UNALIGNED_GET(&addr->s6_addr32[2]) == htonl(0x00000001) &&
977 ((UNALIGNED_GET(&addr->s6_addr32[3]) & htonl(0xff000000)) ==
978 htonl(0xff000000));
979}
980
991static inline bool net_ipv6_is_addr_mcast_scope(const struct in6_addr *addr,
992 int scope)
993{
994 return (addr->s6_addr[0] == 0xff) && (addr->s6_addr[1] == scope);
995}
996
1006static inline bool net_ipv6_is_same_mcast_scope(const struct in6_addr *addr_1,
1007 const struct in6_addr *addr_2)
1008{
1009 return (addr_1->s6_addr[0] == 0xff) && (addr_2->s6_addr[0] == 0xff) &&
1010 (addr_1->s6_addr[1] == addr_2->s6_addr[1]);
1011}
1012
1020static inline bool net_ipv6_is_addr_mcast_global(const struct in6_addr *addr)
1021{
1022 return net_ipv6_is_addr_mcast_scope(addr, 0x0e);
1023}
1024
1034static inline bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
1035{
1036 return net_ipv6_is_addr_mcast_scope(addr, 0x01);
1037}
1038
1048static inline bool net_ipv6_is_addr_mcast_link(const struct in6_addr *addr)
1049{
1050 return net_ipv6_is_addr_mcast_scope(addr, 0x02);
1051}
1052
1062static inline bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
1063{
1064 return net_ipv6_is_addr_mcast_scope(addr, 0x03);
1065}
1066
1076static inline bool net_ipv6_is_addr_mcast_site(const struct in6_addr *addr)
1077{
1078 return net_ipv6_is_addr_mcast_scope(addr, 0x05);
1079}
1080
1090static inline bool net_ipv6_is_addr_mcast_org(const struct in6_addr *addr)
1091{
1092 return net_ipv6_is_addr_mcast_scope(addr, 0x08);
1093}
1094
1105static inline bool net_ipv6_is_addr_mcast_group(const struct in6_addr *addr,
1106 const struct in6_addr *group)
1107{
1108 return UNALIGNED_GET(&addr->s6_addr16[1]) == group->s6_addr16[1] &&
1109 UNALIGNED_GET(&addr->s6_addr16[2]) == group->s6_addr16[2] &&
1110 UNALIGNED_GET(&addr->s6_addr16[3]) == group->s6_addr16[3] &&
1111 UNALIGNED_GET(&addr->s6_addr32[1]) == group->s6_addr32[1] &&
1112 UNALIGNED_GET(&addr->s6_addr32[2]) == group->s6_addr32[1] &&
1113 UNALIGNED_GET(&addr->s6_addr32[3]) == group->s6_addr32[3];
1114}
1115
1124static inline bool
1126{
1127 static const struct in6_addr all_nodes_mcast_group = {
1128 { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1129 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
1130 };
1131
1132 return net_ipv6_is_addr_mcast_group(addr, &all_nodes_mcast_group);
1133}
1134
1144static inline bool
1146{
1147 return net_ipv6_is_addr_mcast_iface(addr) &&
1149}
1150
1160static inline bool
1162{
1163 return net_ipv6_is_addr_mcast_link(addr) &&
1165}
1166
1174static inline
1176 struct in6_addr *dst)
1177{
1178 dst->s6_addr[0] = 0xFF;
1179 dst->s6_addr[1] = 0x02;
1180 UNALIGNED_PUT(0, &dst->s6_addr16[1]);
1181 UNALIGNED_PUT(0, &dst->s6_addr16[2]);
1182 UNALIGNED_PUT(0, &dst->s6_addr16[3]);
1183 UNALIGNED_PUT(0, &dst->s6_addr16[4]);
1184 dst->s6_addr[10] = 0U;
1185 dst->s6_addr[11] = 0x01;
1186 dst->s6_addr[12] = 0xFF;
1187 dst->s6_addr[13] = src->s6_addr[13];
1188 UNALIGNED_PUT(UNALIGNED_GET(&src->s6_addr16[7]), &dst->s6_addr16[7]);
1189}
1190
1203static inline void net_ipv6_addr_create(struct in6_addr *addr,
1204 uint16_t addr0, uint16_t addr1,
1205 uint16_t addr2, uint16_t addr3,
1206 uint16_t addr4, uint16_t addr5,
1207 uint16_t addr6, uint16_t addr7)
1208{
1209 UNALIGNED_PUT(htons(addr0), &addr->s6_addr16[0]);
1210 UNALIGNED_PUT(htons(addr1), &addr->s6_addr16[1]);
1211 UNALIGNED_PUT(htons(addr2), &addr->s6_addr16[2]);
1212 UNALIGNED_PUT(htons(addr3), &addr->s6_addr16[3]);
1213 UNALIGNED_PUT(htons(addr4), &addr->s6_addr16[4]);
1214 UNALIGNED_PUT(htons(addr5), &addr->s6_addr16[5]);
1215 UNALIGNED_PUT(htons(addr6), &addr->s6_addr16[6]);
1216 UNALIGNED_PUT(htons(addr7), &addr->s6_addr16[7]);
1217}
1218
1224static inline void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
1225{
1226 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
1227}
1228
1235{
1236 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002);
1237}
1238
1245static inline void net_ipv6_addr_create_iid(struct in6_addr *addr,
1246 struct net_linkaddr *lladdr)
1247{
1248 UNALIGNED_PUT(htonl(0xfe800000), &addr->s6_addr32[0]);
1249 UNALIGNED_PUT(0, &addr->s6_addr32[1]);
1250
1251 switch (lladdr->len) {
1252 case 2:
1253 /* The generated IPv6 shall not toggle the
1254 * Universal/Local bit. RFC 6282 ch 3.2.2
1255 */
1256 if (lladdr->type == NET_LINK_IEEE802154) {
1257 UNALIGNED_PUT(0, &addr->s6_addr32[2]);
1258 addr->s6_addr[11] = 0xff;
1259 addr->s6_addr[12] = 0xfe;
1260 addr->s6_addr[13] = 0U;
1261 addr->s6_addr[14] = lladdr->addr[0];
1262 addr->s6_addr[15] = lladdr->addr[1];
1263 }
1264
1265 break;
1266 case 6:
1267 /* We do not toggle the Universal/Local bit
1268 * in Bluetooth. See RFC 7668 ch 3.2.2
1269 */
1270 memcpy(&addr->s6_addr[8], lladdr->addr, 3);
1271 addr->s6_addr[11] = 0xff;
1272 addr->s6_addr[12] = 0xfe;
1273 memcpy(&addr->s6_addr[13], lladdr->addr + 3, 3);
1274
1275#if defined(CONFIG_NET_L2_BT_ZEP1656)
1276 /* Workaround against older Linux kernel BT IPSP code.
1277 * This will be removed eventually.
1278 */
1279 if (lladdr->type == NET_LINK_BLUETOOTH) {
1280 addr->s6_addr[8] ^= 0x02;
1281 }
1282#endif
1283
1284 if (lladdr->type == NET_LINK_ETHERNET) {
1285 addr->s6_addr[8] ^= 0x02;
1286 }
1287
1288 break;
1289 case 8:
1290 memcpy(&addr->s6_addr[8], lladdr->addr, lladdr->len);
1291 addr->s6_addr[8] ^= 0x02;
1292 break;
1293 }
1294}
1295
1301static inline bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr,
1302 const struct net_linkaddr *lladdr)
1303{
1304 if (!addr || !lladdr) {
1305 return false;
1306 }
1307
1308 switch (lladdr->len) {
1309 case 2:
1310 if (!memcmp(&addr->s6_addr[14], lladdr->addr, lladdr->len) &&
1311 addr->s6_addr[8] == 0U &&
1312 addr->s6_addr[9] == 0U &&
1313 addr->s6_addr[10] == 0U &&
1314 addr->s6_addr[11] == 0xff &&
1315 addr->s6_addr[12] == 0xfe) {
1316 return true;
1317 }
1318
1319 break;
1320 case 6:
1321 if (lladdr->type == NET_LINK_ETHERNET) {
1322 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1323 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1324 addr->s6_addr[11] == 0xff &&
1325 addr->s6_addr[12] == 0xfe &&
1326 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1327 return true;
1328 }
1329 } else if (lladdr->type == NET_LINK_BLUETOOTH) {
1330 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1331 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1332 addr->s6_addr[11] == 0xff &&
1333 addr->s6_addr[12] == 0xfe
1334#if defined(CONFIG_NET_L2_BT_ZEP1656)
1335 /* Workaround against older Linux kernel BT IPSP
1336 * code. This will be removed eventually.
1337 */
1338 && (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]
1339#endif
1340 ) {
1341 return true;
1342 }
1343 }
1344
1345 break;
1346 case 8:
1347 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1],
1348 lladdr->len - 1) &&
1349 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1350 return true;
1351 }
1352
1353 break;
1354 }
1355
1356 return false;
1357}
1358
1367static inline struct sockaddr_in6 *net_sin6(const struct sockaddr *addr)
1368{
1369 return (struct sockaddr_in6 *)addr;
1370}
1371
1380static inline struct sockaddr_in *net_sin(const struct sockaddr *addr)
1381{
1382 return (struct sockaddr_in *)addr;
1383}
1384
1393static inline
1394struct sockaddr_in6_ptr *net_sin6_ptr(const struct sockaddr_ptr *addr)
1395{
1396 return (struct sockaddr_in6_ptr *)addr;
1397}
1398
1407static inline
1408struct sockaddr_in_ptr *net_sin_ptr(const struct sockaddr_ptr *addr)
1409{
1410 return (struct sockaddr_in_ptr *)addr;
1411}
1412
1421static inline
1422struct sockaddr_ll_ptr *net_sll_ptr(const struct sockaddr_ptr *addr)
1423{
1424 return (struct sockaddr_ll_ptr *)addr;
1425}
1426
1435static inline
1436struct sockaddr_can_ptr *net_can_ptr(const struct sockaddr_ptr *addr)
1437{
1438 return (struct sockaddr_can_ptr *)addr;
1439}
1440
1454__syscall int net_addr_pton(sa_family_t family, const char *src, void *dst);
1455
1467__syscall char *net_addr_ntop(sa_family_t family, const void *src,
1468 char *dst, size_t size);
1469
1491bool net_ipaddr_parse(const char *str, size_t str_len,
1492 struct sockaddr *addr);
1493
1505static inline int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
1506{
1507 return (int32_t)(seq1 - seq2);
1508}
1509
1520static inline bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
1521{
1522 return net_tcp_seq_cmp(seq1, seq2) > 0;
1523}
1524
1536int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src);
1537
1547
1557
1566static inline enum net_priority net_vlan2priority(uint8_t priority)
1567{
1568 /* Map according to IEEE 802.1Q */
1569 static const uint8_t vlan2priority[] = {
1578 };
1579
1580 if (priority >= ARRAY_SIZE(vlan2priority)) {
1581 /* Use Best Effort as the default priority */
1582 return NET_PRIORITY_BE;
1583 }
1584
1585 return (enum net_priority)vlan2priority[priority];
1586}
1587
1595static inline uint8_t net_priority2vlan(enum net_priority priority)
1596{
1597 /* The conversion works both ways */
1598 return (uint8_t)net_vlan2priority(priority);
1599}
1600
1609const char *net_family2str(sa_family_t family);
1610
1611#ifdef __cplusplus
1612}
1613#endif
1614
1615#include <syscalls/net_ip.h>
1616
1622#endif /* ZEPHYR_INCLUDE_NET_NET_IP_H_ */
Byte order helpers.
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:628
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:1203
static bool net_ipv4_addr_cmp(const struct in_addr *addr1, const struct in_addr *addr2)
Compare two IPv4 addresses.
Definition: net_ip.h:779
#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:1090
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:1566
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition: net_ip.h:1505
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:610
#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
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:1234
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
Definition: net_ip.h:442
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:793
static bool net_ipv6_addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2)
Compare two IPv6 addresses.
Definition: net_ip.h:808
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:1145
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:937
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:1006
static void net_ipv6_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv6 address raw buffer.
Definition: net_ip.h:765
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:1062
static struct sockaddr_in_ptr * net_sin_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in_ptr from sockaddr_ptr. This is a helper so that the code calling this function can be...
Definition: net_ip.h:1408
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:1020
static void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
Create link local allnodes multicast IPv6 address.
Definition: net_ip.h:1224
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:972
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:1175
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:1105
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:1076
static void net_ipv6_addr_create_iid(struct in6_addr *addr, struct net_linkaddr *lladdr)
Create IPv6 address interface identifier.
Definition: net_ip.h:1245
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:1048
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:887
net_ip_protocol_secure
Definition: net_ip.h:75
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition: net_ip.h:744
net_ip_mtu
Definition: net_ip.h:406
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:695
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:1595
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:658
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:595
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition: net_ip.h:1520
net_sock_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:1161
const char * net_family2str(sa_family_t family)
Return network address family value as a string. This is only usable for debugging.
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:731
static struct sockaddr_can_ptr * net_can_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_can_ptr from sockaddr_ptr. This is a helper so that the code needing this functionality ...
Definition: net_ip.h:1436
#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:915
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:836
static struct sockaddr_in * net_sin(const struct sockaddr *addr)
Get sockaddr_in from sockaddr. This is a helper so that the code calling this function can be made sh...
Definition: net_ip.h:1380
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:1125
size_t socklen_t
Definition: net_ip.h:167
static struct sockaddr_ll_ptr * net_sll_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_ll_ptr from sockaddr_ptr. This is a helper so that the code calling this function can be...
Definition: net_ip.h:1422
static struct sockaddr_in6 * net_sin6(const struct sockaddr *addr)
Get sockaddr_in6 from sockaddr. This is a helper so that the code calling this function can be made s...
Definition: net_ip.h:1367
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:707
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:991
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:848
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:1034
#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. This is a helper so that the code calling this function can b...
Definition: net_ip.h:1394
net_priority
Definition: net_ip.h:419
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:719
net_ip_protocol
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:1301
static void net_ipv4_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv4 address raw buffer.
Definition: net_ip.h:753
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:644
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:822
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:956
net_addr_type
Definition: net_ip.h:450
@ NET_ADDR_ANY_STATE
Definition: net_ip.h:443
@ NET_ADDR_TENTATIVE
Definition: net_ip.h:444
@ NET_ADDR_DEPRECATED
Definition: net_ip.h:446
@ NET_ADDR_PREFERRED
Definition: net_ip.h:445
@ IPPROTO_TLS_1_1
Definition: net_ip.h:77
@ IPPROTO_TLS_1_0
Definition: net_ip.h:76
@ IPPROTO_DTLS_1_0
Definition: net_ip.h:79
@ IPPROTO_TLS_1_2
Definition: net_ip.h:78
@ IPPROTO_DTLS_1_2
Definition: net_ip.h:80
@ NET_IPV4_MTU
Definition: net_ip.h:415
@ NET_IPV6_MTU
Definition: net_ip.h:410
@ SOCK_DGRAM
Definition: net_ip.h:86
@ SOCK_RAW
Definition: net_ip.h:87
@ SOCK_STREAM
Definition: net_ip.h:85
@ NET_PRIORITY_NC
Definition: net_ip.h:427
@ NET_PRIORITY_IC
Definition: net_ip.h:426
@ NET_PRIORITY_CA
Definition: net_ip.h:423
@ NET_PRIORITY_VO
Definition: net_ip.h:425
@ NET_PRIORITY_VI
Definition: net_ip.h:424
@ NET_PRIORITY_BE
Definition: net_ip.h:421
@ NET_PRIORITY_EE
Definition: net_ip.h:422
@ NET_PRIORITY_BK
Definition: net_ip.h:420
@ IPPROTO_IP
Definition: net_ip.h:63
@ IPPROTO_RAW
Definition: net_ip.h:71
@ IPPROTO_IPIP
Definition: net_ip.h:66
@ IPPROTO_TCP
Definition: net_ip.h:67
@ IPPROTO_IGMP
Definition: net_ip.h:65
@ IPPROTO_ICMP
Definition: net_ip.h:64
@ IPPROTO_IPV6
Definition: net_ip.h:69
@ IPPROTO_UDP
Definition: net_ip.h:68
@ IPPROTO_ICMPV6
Definition: net_ip.h:70
@ NET_ADDR_ANY
Definition: net_ip.h:452
@ NET_ADDR_OVERRIDABLE
Definition: net_ip.h:460
@ NET_ADDR_DHCP
Definition: net_ip.h:456
@ NET_ADDR_MANUAL
Definition: net_ip.h:458
@ NET_ADDR_AUTOCONF
Definition: net_ip.h:454
@ NET_LINK_IEEE802154
Definition: net_linkaddr.h:51
@ NET_LINK_ETHERNET
Definition: net_linkaddr.h:55
@ NET_LINK_BLUETOOTH
Definition: net_linkaddr.h:53
#define ARRAY_SIZE(array)
Number of elements in the given array.
Definition: util.h:118
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:28
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:245
int cmsg_type
Definition: net_ip.h:248
socklen_t cmsg_len
Definition: net_ip.h:246
z_max_align_t cmsg_data[]
Definition: net_ip.h:250
int cmsg_level
Definition: net_ip.h:247
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
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:229
void * iov_base
Definition: net_ip.h:230
size_t iov_len
Definition: net_ip.h:231
Definition: net_ip.h:235
struct iovec * msg_iov
Definition: net_ip.h:238
socklen_t msg_namelen
Definition: net_ip.h:237
void * msg_name
Definition: net_ip.h:236
int msg_flags
Definition: net_ip.h:242
size_t msg_controllen
Definition: net_ip.h:241
size_t msg_iovlen
Definition: net_ip.h:239
void * msg_control
Definition: net_ip.h:240
Network Interface unicast IP addresses.
Definition: net_if.h:49
IP and other configuration related data for network interface.
Definition: net_if.h:400
Network Interface multicast IP addresses.
Definition: net_if.h:90
Network Interface structure.
Definition: net_if.h:510
Hardware link address structure.
Definition: net_linkaddr.h:67
uint8_t * addr
Definition: net_linkaddr.h:69
uint8_t type
Definition: net_linkaddr.h:75
uint8_t len
Definition: net_linkaddr.h:72
Definition: net_ip.h:433
struct net_addr * remote_addr
Definition: net_ip.h:434
uint16_t local_port
Definition: net_ip.h:437
enum net_ip_protocol ip_proto
Definition: net_ip.h:438
uint16_t remote_port
Definition: net_ip.h:436
struct net_addr * local_addr
Definition: net_ip.h:435
Definition: net_ip.h:223
sa_family_t can_family
Definition: net_ip.h:224
int can_ifindex
Definition: net_ip.h:225
Definition: net_ip.h:182
sa_family_t sin6_family
Definition: net_ip.h:183
uint16_t sin6_port
Definition: net_ip.h:184
uint8_t sin6_scope_id
Definition: net_ip.h:186
struct in6_addr * sin6_addr
Definition: net_ip.h:185
Definition: net_ip.h:175
uint8_t sin6_scope_id
Definition: net_ip.h:179
struct in6_addr sin6_addr
Definition: net_ip.h:178
uint16_t sin6_port
Definition: net_ip.h:177
sa_family_t sin6_family
Definition: net_ip.h:176
Definition: net_ip.h:196
struct in_addr * sin_addr
Definition: net_ip.h:199
uint16_t sin_port
Definition: net_ip.h:198
sa_family_t sin_family
Definition: net_ip.h:197
Definition: net_ip.h:190
uint16_t sin_port
Definition: net_ip.h:192
struct in_addr sin_addr
Definition: net_ip.h:193
sa_family_t sin_family
Definition: net_ip.h:191
Definition: net_ip.h:213
uint8_t * sll_addr
Definition: net_ip.h:220
uint16_t sll_hatype
Definition: net_ip.h:217
int sll_ifindex
Definition: net_ip.h:216
uint8_t sll_pkttype
Definition: net_ip.h:218
sa_family_t sll_family
Definition: net_ip.h:214
uint8_t sll_halen
Definition: net_ip.h:219
uint16_t sll_protocol
Definition: net_ip.h:215
Definition: net_ip.h:203
uint8_t sll_pkttype
Definition: net_ip.h:208
uint16_t sll_hatype
Definition: net_ip.h:207
sa_family_t sll_family
Definition: net_ip.h:204
uint16_t sll_protocol
Definition: net_ip.h:205
int sll_ifindex
Definition: net_ip.h:206
uint8_t sll_halen
Definition: net_ip.h:209
uint8_t sll_addr[8]
Definition: net_ip.h:210
Definition: net_ip.h:344
char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)]
Definition: net_ip.h:346
sa_family_t sa_family
Definition: net_ip.h:345
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
Macros to abstract toolchain specific capabilities.
Misc utilities.