Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
25#include <string.h>
26#include <zephyr/types.h>
27#include <stdbool.h>
28#include <zephyr/sys/util.h>
30#include <zephyr/toolchain.h>
31
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
39/* Specifying VLAN tag here in order to avoid circular dependencies */
40#define NET_VLAN_TAG_UNSPEC 0x0fff
43/* Protocol families. */
44#define PF_UNSPEC 0
45#define PF_INET 1
46#define PF_INET6 2
47#define PF_PACKET 3
48#define PF_CAN 4
49#define PF_NET_MGMT 5
50#define PF_LOCAL 6
51#define PF_UNIX PF_LOCAL
53/* Address families. */
54#define AF_UNSPEC PF_UNSPEC
55#define AF_INET PF_INET
56#define AF_INET6 PF_INET6
57#define AF_PACKET PF_PACKET
58#define AF_CAN PF_CAN
59#define AF_NET_MGMT PF_NET_MGMT
60#define AF_LOCAL PF_LOCAL
61#define AF_UNIX PF_UNIX
75
85
92
99#define ntohs(x) sys_be16_to_cpu(x)
100
107#define ntohl(x) sys_be32_to_cpu(x)
108
115#define ntohll(x) sys_be64_to_cpu(x)
116
123#define htons(x) sys_cpu_to_be16(x)
124
131#define htonl(x) sys_cpu_to_be32(x)
132
139#define htonll(x) sys_cpu_to_be64(x)
140
142struct in6_addr {
143 union {
147 };
148};
149
151#define NET_IPV6_ADDR_SIZE 16
152
162
164#define NET_IPV4_ADDR_SIZE 4
165
167typedef unsigned short int sa_family_t;
168
170#ifndef __socklen_t_defined
171typedef size_t socklen_t;
172#define __socklen_t_defined
173#endif
174
175/*
176 * Note that the sin_port and sin6_port are in network byte order
177 * in various sockaddr* structs.
178 */
179
187
194
205
209struct sockaddr_in6_ptr {
210 sa_family_t sin6_family;
211 uint16_t sin6_port;
212 struct in6_addr *sin6_addr;
213 uint8_t sin6_scope_id;
214};
215
217struct sockaddr_in_ptr {
218 sa_family_t sin_family;
219 uint16_t sin_port;
220 struct in_addr *sin_addr;
221};
222
224struct sockaddr_ll_ptr {
225 sa_family_t sll_family;
226 uint16_t sll_protocol;
227 int sll_ifindex;
228 uint16_t sll_hatype;
229 uint8_t sll_pkttype;
230 uint8_t sll_halen;
231 uint8_t *sll_addr;
232};
233
234struct sockaddr_can_ptr {
235 sa_family_t can_family;
236 int can_ifindex;
237};
238
241#if !defined(HAVE_IOVEC)
243struct iovec {
244 void *iov_base;
245 size_t iov_len;
246};
247#endif
248
259
261struct cmsghdr {
265 z_max_align_t cmsg_data[];
266};
267
270/* Alignment for headers and data. These are arch specific but define
271 * them here atm if not found already.
272 */
273#if !defined(ALIGN_H)
274#define ALIGN_H(x) ROUND_UP(x, __alignof__(struct cmsghdr))
275#endif
276#if !defined(ALIGN_D)
277#define ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
278#endif
279
282#if !defined(CMSG_FIRSTHDR)
288#define CMSG_FIRSTHDR(msghdr) \
289 ((msghdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
290 (struct cmsghdr *)((msghdr)->msg_control) : NULL)
291#endif
292
293#if !defined(CMSG_NXTHDR)
298#define CMSG_NXTHDR(msghdr, cmsg) \
299 (((cmsg) == NULL) ? CMSG_FIRSTHDR(msghdr) : \
300 (((uint8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) + \
301 ALIGN_D(sizeof(struct cmsghdr)) > \
302 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
303 NULL : \
304 (struct cmsghdr *)((uint8_t *)(cmsg) + \
305 ALIGN_H((cmsg)->cmsg_len))))
306#endif
307
308#if !defined(CMSG_DATA)
316#define CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + ALIGN_D(sizeof(struct cmsghdr)))
317#endif
318
319#if !defined(CMSG_SPACE)
324#define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + ALIGN_H(length))
325#endif
326
327#if !defined(CMSG_LEN)
333#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + length)
334#endif
335
338/* Packet types. */
339#define PACKET_HOST 0 /* To us */
340#define PACKET_BROADCAST 1 /* To all */
341#define PACKET_MULTICAST 2 /* To group */
342#define PACKET_OTHERHOST 3 /* To someone else */
343#define PACKET_OUTGOING 4 /* Originated by us */
344#define PACKET_LOOPBACK 5
345#define PACKET_FASTROUTE 6
346
347/* ARP protocol HARDWARE identifiers. */
348#define ARPHRD_ETHER 1
349
350/* Note: These macros are defined in a specific order.
351 * The largest sockaddr size is the last one.
352 */
353#if defined(CONFIG_NET_IPV4)
354#undef NET_SOCKADDR_MAX_SIZE
355#undef NET_SOCKADDR_PTR_MAX_SIZE
356#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in))
357#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in_ptr))
358#endif
359
360#if defined(CONFIG_NET_SOCKETS_PACKET)
361#undef NET_SOCKADDR_MAX_SIZE
362#undef NET_SOCKADDR_PTR_MAX_SIZE
363#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_ll))
364#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_ll_ptr))
365#endif
366
367#if defined(CONFIG_NET_IPV6)
368#undef NET_SOCKADDR_MAX_SIZE
369#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
370#if !defined(CONFIG_NET_SOCKETS_PACKET)
371#undef NET_SOCKADDR_PTR_MAX_SIZE
372#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
373#endif
374#endif
375
376#if !defined(CONFIG_NET_IPV4)
377#if !defined(CONFIG_NET_IPV6)
378#if !defined(CONFIG_NET_SOCKETS_PACKET)
379#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
380#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
381#endif
382#endif
383#endif
384
388struct sockaddr {
391 char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
393};
394
397struct sockaddr_ptr {
398 sa_family_t family;
399 char data[NET_SOCKADDR_PTR_MAX_SIZE - sizeof(sa_family_t)];
400};
401
402/* Same as sockaddr in our case */
403struct sockaddr_storage {
404 sa_family_t ss_family;
405 char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
406};
407
408/* Socket address struct for UNIX domain sockets */
409struct sockaddr_un {
410 sa_family_t sun_family; /* AF_UNIX */
411 char sun_path[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
412};
413
414struct net_addr {
415 sa_family_t family;
416 union {
417 struct in6_addr in6_addr;
418 struct in_addr in_addr;
419 };
420};
421
423extern const struct in6_addr in6addr_any;
424
426extern const struct in6_addr in6addr_loopback;
427
431#define IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, \
432 0, 0, 0, 0, 0, 0, 0 } } }
433
435#define IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, \
436 0, 0, 0, 0, 0, 0, 0, 0, 1 } } }
437
439#define INADDR_ANY 0
440
442#define INADDR_ANY_INIT { { { INADDR_ANY } } }
443
445#define INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
446
448#define INET_ADDRSTRLEN 16
452#define INET6_ADDRSTRLEN 46
453
456/* These are for internal usage of the stack */
457#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")
458#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
459
467#if defined(CONFIG_NET_NATIVE_IPV6)
468 NET_IPV6_MTU = CONFIG_NET_IPV6_MTU,
469#else
471#endif
472
477};
478
490
491#define NET_MAX_PRIORITIES 8
501
509
523
526struct net_ipv6_hdr {
527 uint8_t vtc;
528 uint8_t tcflow;
529 uint16_t flow;
530 uint16_t len;
531 uint8_t nexthdr;
532 uint8_t hop_limit;
535} __packed;
536
537struct net_ipv6_frag_hdr {
538 uint8_t nexthdr;
539 uint8_t reserved;
540 uint16_t offset;
541 uint32_t id;
542} __packed;
543
544struct net_ipv4_hdr {
545 uint8_t vhl;
546 uint8_t tos;
547 uint16_t len;
548 uint8_t id[2];
549 uint8_t offset[2];
550 uint8_t ttl;
551 uint8_t proto;
552 uint16_t chksum;
555} __packed;
556
557struct net_icmp_hdr {
558 uint8_t type;
559 uint8_t code;
560 uint16_t chksum;
561} __packed;
562
563struct net_udp_hdr {
564 uint16_t src_port;
565 uint16_t dst_port;
566 uint16_t len;
567 uint16_t chksum;
568} __packed;
569
570struct net_tcp_hdr {
571 uint16_t src_port;
572 uint16_t dst_port;
573 uint8_t seq[4];
574 uint8_t ack[4];
575 uint8_t offset;
577 uint8_t wnd[2];
578 uint16_t chksum;
579 uint8_t urg[2];
580 uint8_t optdata[0];
581} __packed;
582
583static inline const char *net_addr_type2str(enum net_addr_type type)
584{
585 switch (type) {
587 return "AUTO";
588 case NET_ADDR_DHCP:
589 return "DHCP";
590 case NET_ADDR_MANUAL:
591 return "MANUAL";
593 return "OVERRIDE";
594 case NET_ADDR_ANY:
595 default:
596 break;
597 }
598
599 return "<unknown>";
600}
601
602/* IPv6 extension headers types */
603#define NET_IPV6_NEXTHDR_HBHO 0
604#define NET_IPV6_NEXTHDR_DESTO 60
605#define NET_IPV6_NEXTHDR_ROUTING 43
606#define NET_IPV6_NEXTHDR_FRAG 44
607#define NET_IPV6_NEXTHDR_NONE 59
608
613union net_ip_header {
614 struct net_ipv4_hdr *ipv4;
615 struct net_ipv6_hdr *ipv6;
616};
617
618union net_proto_header {
619 struct net_udp_hdr *udp;
620 struct net_tcp_hdr *tcp;
621};
622
623#define NET_UDPH_LEN 8 /* Size of UDP header */
624#define NET_TCPH_LEN 20 /* Size of TCP header */
625#define NET_ICMPH_LEN 4 /* Size of ICMP header */
626
627#define NET_IPV6H_LEN 40 /* Size of IPv6 header */
628#define NET_ICMPV6H_LEN NET_ICMPH_LEN /* Size of ICMPv6 header */
629#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN) /* IPv6 + UDP */
630#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN) /* IPv6 + TCP */
631#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN) /* ICMPv6 + IPv6 */
632#define NET_IPV6_FRAGH_LEN 8
633
634#define NET_IPV4H_LEN 20 /* Size of IPv4 header */
635#define NET_ICMPV4H_LEN NET_ICMPH_LEN /* Size of ICMPv4 header */
636#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN) /* IPv4 + UDP */
637#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN) /* IPv4 + TCP */
638#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN) /* ICMPv4 + IPv4 */
639
640#define NET_IPV6H_LENGTH_OFFSET 0x04 /* Offset of the Length field in the IPv6 header */
641
642#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8 /* Mask for the 13-bit Fragment Offset field */
643#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff /* Mask for the 13-bit Fragment Offset field */
644#define NET_IPV4_MORE_FRAG_MASK 0x2000 /* Mask for the 1-bit More Fragments field */
645#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000 /* Mask for the 1-bit Do Not Fragment field */
646
656static inline bool net_ipv6_is_addr_loopback(struct in6_addr *addr)
657{
658 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
659 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
660 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
661 ntohl(UNALIGNED_GET(&addr->s6_addr32[3])) == 1;
662}
663
671static inline bool net_ipv6_is_addr_mcast(const struct in6_addr *addr)
672{
673 return addr->s6_addr[0] == 0xFF;
674}
675
676struct net_if;
677struct net_if_config;
678
679extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
680 struct net_if **iface);
681
689static inline bool net_ipv6_is_my_addr(struct in6_addr *addr)
690{
691 return net_if_ipv6_addr_lookup(addr, NULL) != NULL;
692}
693
695 const struct in6_addr *addr, struct net_if **iface);
696
705static inline bool net_ipv6_is_my_maddr(struct in6_addr *maddr)
706{
707 return net_if_ipv6_maddr_lookup(maddr, NULL) != NULL;
708}
709
719static inline bool net_ipv6_is_prefix(const uint8_t *addr1,
720 const uint8_t *addr2,
721 uint8_t length)
722{
723 uint8_t bits = 128 - length;
724 uint8_t bytes = length / 8U;
725 uint8_t remain = bits % 8;
726 uint8_t mask;
727
728 if (length > 128) {
729 return false;
730 }
731
732 if (memcmp(addr1, addr2, bytes)) {
733 return false;
734 }
735
736 if (!remain) {
737 /* No remaining bits, the prefixes are the same as first
738 * bytes are the same.
739 */
740 return true;
741 }
742
743 /* Create a mask that has remaining most significant bits set */
744 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
745
746 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
747}
748
749
757static inline void net_ipv6_addr_prefix_mask(const uint8_t *inaddr,
758 uint8_t *outaddr,
759 uint8_t prefix_len)
760{
761 uint8_t bits = 128 - prefix_len;
762 uint8_t bytes = prefix_len / 8U;
763 uint8_t remain = bits % 8;
764 uint8_t mask;
765
766 memset(outaddr, 0, 16U);
767 memcpy(outaddr, inaddr, bytes);
768
769 if (!remain) {
770 /* No remaining bits, the prefixes are the same as first
771 * bytes are the same.
772 */
773 return;
774 }
775
776 /* Create a mask that has remaining most significant bits set */
777 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
778 outaddr[bytes] = inaddr[bytes] & mask;
779}
780
788static inline bool net_ipv4_is_addr_loopback(struct in_addr *addr)
789{
790 return addr->s4_addr[0] == 127U;
791}
792
800static inline bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
801{
802 return UNALIGNED_GET(&addr->s_addr) == 0;
803}
804
812static inline bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
813{
814 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xF0000000) == 0xE0000000;
815}
816
824static inline bool net_ipv4_is_ll_addr(const struct in_addr *addr)
825{
826 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFF0000) == 0xA9FE0000;
827}
828
838static inline bool net_ipv4_is_private_addr(const struct in_addr *addr)
839{
840 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
841
842 masked_24 = ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFFFF00;
843 masked_16 = masked_24 & 0xFFFF0000;
844 masked_12 = masked_24 & 0xFFF00000;
845 masked_10 = masked_24 & 0xFFC00000;
846 masked_8 = masked_24 & 0xFF000000;
847
848 return masked_8 == 0x0A000000 || /* 10.0.0.0/8 */
849 masked_10 == 0x64400000 || /* 100.64.0.0/10 */
850 masked_12 == 0xAC100000 || /* 172.16.0.0/12 */
851 masked_16 == 0xC0A80000 || /* 192.168.0.0/16 */
852 masked_24 == 0xC0000200 || /* 192.0.2.0/24 */
853 masked_24 == 0xC0336400 || /* 192.51.100.0/24 */
854 masked_24 == 0xCB007100; /* 203.0.113.0/24 */
855}
856
865#define net_ipaddr_copy(dest, src) \
866 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
867
874static inline void net_ipv4_addr_copy_raw(uint8_t *dest,
875 const uint8_t *src)
876{
877 net_ipaddr_copy((struct in_addr *)dest, (const struct in_addr *)src);
878}
879
886static inline void net_ipv6_addr_copy_raw(uint8_t *dest,
887 const uint8_t *src)
888{
889 memcpy(dest, src, sizeof(struct in6_addr));
890}
891
900static inline bool net_ipv4_addr_cmp(const struct in_addr *addr1,
901 const struct in_addr *addr2)
902{
903 return UNALIGNED_GET(&addr1->s_addr) == UNALIGNED_GET(&addr2->s_addr);
904}
905
914static inline bool net_ipv4_addr_cmp_raw(const uint8_t *addr1,
915 const uint8_t *addr2)
916{
917 return net_ipv4_addr_cmp((const struct in_addr *)addr1,
918 (const struct in_addr *)addr2);
919}
920
929static inline bool net_ipv6_addr_cmp(const struct in6_addr *addr1,
930 const struct in6_addr *addr2)
931{
932 return !memcmp(addr1, addr2, sizeof(struct in6_addr));
933}
934
943static inline bool net_ipv6_addr_cmp_raw(const uint8_t *addr1,
944 const uint8_t *addr2)
945{
946 return net_ipv6_addr_cmp((const struct in6_addr *)addr1,
947 (const struct in6_addr *)addr2);
948}
949
957static inline bool net_ipv6_is_ll_addr(const struct in6_addr *addr)
958{
959 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFE80);
960}
961
969static inline bool net_ipv6_is_sl_addr(const struct in6_addr *addr)
970{
971 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFEC0);
972}
973
974
982static inline bool net_ipv6_is_ula_addr(const struct in6_addr *addr)
983{
984 return addr->s6_addr[0] == 0xFD;
985}
986
994static inline bool net_ipv6_is_global_addr(const struct in6_addr *addr)
995{
996 return (addr->s6_addr[0] & 0xE0) == 0x20;
997}
998
1008static inline bool net_ipv6_is_private_addr(const struct in6_addr *addr)
1009{
1010 uint32_t masked_32, masked_7;
1011
1012 masked_32 = ntohl(UNALIGNED_GET(&addr->s6_addr32[0]));
1013 masked_7 = masked_32 & 0xfc000000;
1014
1015 return masked_32 == 0x20010db8 || /* 2001:db8::/32 */
1016 masked_7 == 0xfc000000; /* fc00::/7 */
1017}
1018
1025
1032
1039
1040struct net_if;
1041extern bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
1042 const struct in_addr *addr);
1043
1053static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
1054 const struct in_addr *addr)
1055{
1056 return net_if_ipv4_addr_mask_cmp(iface, addr);
1057}
1058
1059extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
1060 const struct in_addr *addr);
1061
1070#if defined(CONFIG_NET_NATIVE_IPV4)
1071static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1072 const struct in_addr *addr)
1073{
1075 return true;
1076 }
1077
1078 return net_if_ipv4_is_addr_bcast(iface, addr);
1079}
1080#else
1081static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1082 const struct in_addr *addr)
1083{
1084 ARG_UNUSED(iface);
1085 ARG_UNUSED(addr);
1086
1087 return false;
1088}
1089#endif
1090
1091extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
1092 struct net_if **iface);
1093
1103static inline bool net_ipv4_is_my_addr(const struct in_addr *addr)
1104{
1105 bool ret;
1106
1107 ret = net_if_ipv4_addr_lookup(addr, NULL) != NULL;
1108 if (!ret) {
1109 ret = net_ipv4_is_addr_bcast(NULL, addr);
1110 }
1111
1112 return ret;
1113}
1114
1122static inline bool net_ipv6_is_addr_unspecified(const struct in6_addr *addr)
1123{
1124 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1125 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1126 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
1127 UNALIGNED_GET(&addr->s6_addr32[3]) == 0;
1128}
1129
1138static inline bool net_ipv6_is_addr_solicited_node(const struct in6_addr *addr)
1139{
1140 return UNALIGNED_GET(&addr->s6_addr32[0]) == htonl(0xff020000) &&
1141 UNALIGNED_GET(&addr->s6_addr32[1]) == 0x00000000 &&
1142 UNALIGNED_GET(&addr->s6_addr32[2]) == htonl(0x00000001) &&
1143 ((UNALIGNED_GET(&addr->s6_addr32[3]) & htonl(0xff000000)) ==
1144 htonl(0xff000000));
1145}
1146
1157static inline bool net_ipv6_is_addr_mcast_scope(const struct in6_addr *addr,
1158 int scope)
1159{
1160 return (addr->s6_addr[0] == 0xff) && ((addr->s6_addr[1] & 0xF) == scope);
1161}
1162
1172static inline bool net_ipv6_is_same_mcast_scope(const struct in6_addr *addr_1,
1173 const struct in6_addr *addr_2)
1174{
1175 return (addr_1->s6_addr[0] == 0xff) && (addr_2->s6_addr[0] == 0xff) &&
1176 (addr_1->s6_addr[1] == addr_2->s6_addr[1]);
1177}
1178
1186static inline bool net_ipv6_is_addr_mcast_global(const struct in6_addr *addr)
1187{
1188 return net_ipv6_is_addr_mcast_scope(addr, 0x0e);
1189}
1190
1200static inline bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
1201{
1202 return net_ipv6_is_addr_mcast_scope(addr, 0x01);
1203}
1204
1214static inline bool net_ipv6_is_addr_mcast_link(const struct in6_addr *addr)
1215{
1216 return net_ipv6_is_addr_mcast_scope(addr, 0x02);
1217}
1218
1228static inline bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
1229{
1230 return net_ipv6_is_addr_mcast_scope(addr, 0x03);
1231}
1232
1242static inline bool net_ipv6_is_addr_mcast_site(const struct in6_addr *addr)
1243{
1244 return net_ipv6_is_addr_mcast_scope(addr, 0x05);
1245}
1246
1256static inline bool net_ipv6_is_addr_mcast_org(const struct in6_addr *addr)
1257{
1258 return net_ipv6_is_addr_mcast_scope(addr, 0x08);
1259}
1260
1271static inline bool net_ipv6_is_addr_mcast_group(const struct in6_addr *addr,
1272 const struct in6_addr *group)
1273{
1274 return UNALIGNED_GET(&addr->s6_addr16[1]) == group->s6_addr16[1] &&
1275 UNALIGNED_GET(&addr->s6_addr16[2]) == group->s6_addr16[2] &&
1276 UNALIGNED_GET(&addr->s6_addr16[3]) == group->s6_addr16[3] &&
1277 UNALIGNED_GET(&addr->s6_addr32[1]) == group->s6_addr32[1] &&
1278 UNALIGNED_GET(&addr->s6_addr32[2]) == group->s6_addr32[1] &&
1279 UNALIGNED_GET(&addr->s6_addr32[3]) == group->s6_addr32[3];
1280}
1281
1290static inline bool
1292{
1293 static const struct in6_addr all_nodes_mcast_group = {
1294 { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1295 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
1296 };
1297
1298 return net_ipv6_is_addr_mcast_group(addr, &all_nodes_mcast_group);
1299}
1300
1310static inline bool
1316
1326static inline bool
1332
1340static inline
1342 struct in6_addr *dst)
1343{
1344 dst->s6_addr[0] = 0xFF;
1345 dst->s6_addr[1] = 0x02;
1346 UNALIGNED_PUT(0, &dst->s6_addr16[1]);
1347 UNALIGNED_PUT(0, &dst->s6_addr16[2]);
1348 UNALIGNED_PUT(0, &dst->s6_addr16[3]);
1349 UNALIGNED_PUT(0, &dst->s6_addr16[4]);
1350 dst->s6_addr[10] = 0U;
1351 dst->s6_addr[11] = 0x01;
1352 dst->s6_addr[12] = 0xFF;
1353 dst->s6_addr[13] = src->s6_addr[13];
1354 UNALIGNED_PUT(UNALIGNED_GET(&src->s6_addr16[7]), &dst->s6_addr16[7]);
1355}
1356
1369static inline void net_ipv6_addr_create(struct in6_addr *addr,
1370 uint16_t addr0, uint16_t addr1,
1371 uint16_t addr2, uint16_t addr3,
1372 uint16_t addr4, uint16_t addr5,
1373 uint16_t addr6, uint16_t addr7)
1374{
1375 UNALIGNED_PUT(htons(addr0), &addr->s6_addr16[0]);
1376 UNALIGNED_PUT(htons(addr1), &addr->s6_addr16[1]);
1377 UNALIGNED_PUT(htons(addr2), &addr->s6_addr16[2]);
1378 UNALIGNED_PUT(htons(addr3), &addr->s6_addr16[3]);
1379 UNALIGNED_PUT(htons(addr4), &addr->s6_addr16[4]);
1380 UNALIGNED_PUT(htons(addr5), &addr->s6_addr16[5]);
1381 UNALIGNED_PUT(htons(addr6), &addr->s6_addr16[6]);
1382 UNALIGNED_PUT(htons(addr7), &addr->s6_addr16[7]);
1383}
1384
1390static inline void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
1391{
1392 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
1393}
1394
1401{
1402 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002);
1403}
1404
1411static inline void net_ipv6_addr_create_v4_mapped(const struct in_addr *addr4,
1412 struct in6_addr *addr6)
1413{
1414 net_ipv6_addr_create(addr6, 0, 0, 0, 0, 0, 0xffff,
1415 ntohs(addr4->s4_addr16[0]),
1416 ntohs(addr4->s4_addr16[1]));
1417}
1418
1427static inline bool net_ipv6_addr_is_v4_mapped(const struct in6_addr *addr)
1428{
1429 if (UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1430 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1431 UNALIGNED_GET(&addr->s6_addr16[5]) == 0xffff) {
1432 return true;
1433 }
1434
1435 return false;
1436}
1437
1444static inline void net_ipv6_addr_create_iid(struct in6_addr *addr,
1445 struct net_linkaddr *lladdr)
1446{
1447 UNALIGNED_PUT(htonl(0xfe800000), &addr->s6_addr32[0]);
1448 UNALIGNED_PUT(0, &addr->s6_addr32[1]);
1449
1450 switch (lladdr->len) {
1451 case 2:
1452 /* The generated IPv6 shall not toggle the
1453 * Universal/Local bit. RFC 6282 ch 3.2.2
1454 */
1455 if (lladdr->type == NET_LINK_IEEE802154) {
1456 UNALIGNED_PUT(0, &addr->s6_addr32[2]);
1457 addr->s6_addr[11] = 0xff;
1458 addr->s6_addr[12] = 0xfe;
1459 addr->s6_addr[13] = 0U;
1460 addr->s6_addr[14] = lladdr->addr[0];
1461 addr->s6_addr[15] = lladdr->addr[1];
1462 }
1463
1464 break;
1465 case 6:
1466 /* We do not toggle the Universal/Local bit
1467 * in Bluetooth. See RFC 7668 ch 3.2.2
1468 */
1469 memcpy(&addr->s6_addr[8], lladdr->addr, 3);
1470 addr->s6_addr[11] = 0xff;
1471 addr->s6_addr[12] = 0xfe;
1472 memcpy(&addr->s6_addr[13], lladdr->addr + 3, 3);
1473
1474 if (lladdr->type == NET_LINK_ETHERNET) {
1475 addr->s6_addr[8] ^= 0x02;
1476 }
1477
1478 break;
1479 case 8:
1480 memcpy(&addr->s6_addr[8], lladdr->addr, lladdr->len);
1481 addr->s6_addr[8] ^= 0x02;
1482 break;
1483 }
1484}
1485
1491static inline bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr,
1492 const struct net_linkaddr *lladdr)
1493{
1494 if (!addr || !lladdr) {
1495 return false;
1496 }
1497
1498 switch (lladdr->len) {
1499 case 2:
1500 if (!memcmp(&addr->s6_addr[14], lladdr->addr, lladdr->len) &&
1501 addr->s6_addr[8] == 0U &&
1502 addr->s6_addr[9] == 0U &&
1503 addr->s6_addr[10] == 0U &&
1504 addr->s6_addr[11] == 0xff &&
1505 addr->s6_addr[12] == 0xfe) {
1506 return true;
1507 }
1508
1509 break;
1510 case 6:
1511 if (lladdr->type == NET_LINK_ETHERNET) {
1512 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1513 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1514 addr->s6_addr[11] == 0xff &&
1515 addr->s6_addr[12] == 0xfe &&
1516 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1517 return true;
1518 }
1519 }
1520
1521 break;
1522 case 8:
1523 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1],
1524 lladdr->len - 1) &&
1525 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1526 return true;
1527 }
1528
1529 break;
1530 }
1531
1532 return false;
1533}
1534
1543static inline struct sockaddr_in6 *net_sin6(const struct sockaddr *addr)
1544{
1545 return (struct sockaddr_in6 *)addr;
1546}
1547
1556static inline struct sockaddr_in *net_sin(const struct sockaddr *addr)
1557{
1558 return (struct sockaddr_in *)addr;
1559}
1560
1569static inline
1570struct sockaddr_in6_ptr *net_sin6_ptr(const struct sockaddr_ptr *addr)
1571{
1572 return (struct sockaddr_in6_ptr *)addr;
1573}
1574
1583static inline
1584struct sockaddr_in_ptr *net_sin_ptr(const struct sockaddr_ptr *addr)
1585{
1586 return (struct sockaddr_in_ptr *)addr;
1587}
1588
1597static inline
1598struct sockaddr_ll_ptr *net_sll_ptr(const struct sockaddr_ptr *addr)
1599{
1600 return (struct sockaddr_ll_ptr *)addr;
1601}
1602
1611static inline
1612struct sockaddr_can_ptr *net_can_ptr(const struct sockaddr_ptr *addr)
1613{
1614 return (struct sockaddr_can_ptr *)addr;
1615}
1616
1630__syscall int net_addr_pton(sa_family_t family, const char *src, void *dst);
1631
1643__syscall char *net_addr_ntop(sa_family_t family, const void *src,
1644 char *dst, size_t size);
1645
1667bool net_ipaddr_parse(const char *str, size_t str_len,
1668 struct sockaddr *addr);
1669
1679int net_port_set_default(struct sockaddr *addr, uint16_t default_port);
1680
1692static inline int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
1693{
1694 return (int32_t)(seq1 - seq2);
1695}
1696
1707static inline bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
1708{
1709 return net_tcp_seq_cmp(seq1, seq2) > 0;
1710}
1711
1723int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src);
1724
1734
1744
1753static inline enum net_priority net_vlan2priority(uint8_t priority)
1754{
1755 /* Map according to IEEE 802.1Q */
1756 static const uint8_t vlan2priority[] = {
1765 };
1766
1767 if (priority >= ARRAY_SIZE(vlan2priority)) {
1768 /* Use Best Effort as the default priority */
1769 return NET_PRIORITY_BE;
1770 }
1771
1772 return (enum net_priority)vlan2priority[priority];
1773}
1774
1782static inline uint8_t net_priority2vlan(enum net_priority priority)
1783{
1784 /* The conversion works both ways */
1785 return (uint8_t)net_vlan2priority(priority);
1786}
1787
1796const char *net_family2str(sa_family_t family);
1797
1808#if defined(CONFIG_NET_IPV6_PE)
1809int net_ipv6_pe_add_filter(struct in6_addr *addr, bool is_denylist);
1810#else
1811static inline int net_ipv6_pe_add_filter(struct in6_addr *addr,
1812 bool is_denylist)
1813{
1814 ARG_UNUSED(addr);
1815 ARG_UNUSED(is_denylist);
1816
1817 return -ENOTSUP;
1818}
1819#endif /* CONFIG_NET_IPV6_PE */
1820
1828#if defined(CONFIG_NET_IPV6_PE)
1829int net_ipv6_pe_del_filter(struct in6_addr *addr);
1830#else
1831static inline int net_ipv6_pe_del_filter(struct in6_addr *addr)
1832{
1833 ARG_UNUSED(addr);
1834
1835 return -ENOTSUP;
1836}
1837#endif /* CONFIG_NET_IPV6_PE */
1838
1839#ifdef __cplusplus
1840}
1841#endif
1842
1843#include <zephyr/syscalls/net_ip.h>
1844
1850#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:689
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:1369
static bool net_ipv4_addr_cmp(const struct in_addr *addr1, const struct in_addr *addr2)
Compare two IPv4 addresses.
Definition net_ip.h:900
#define NET_IPV4_ADDR_SIZE
Binary size of the IPv4 address.
Definition net_ip.h:164
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:1256
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:1753
static int net_ipv6_pe_add_filter(struct in6_addr *addr, bool is_denylist)
Add IPv6 prefix as a privacy extension filter.
Definition net_ip.h:1811
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition net_ip.h:1692
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:671
#define NET_IPV6_ADDR_SIZE
Binary size of the IPv6 address.
Definition net_ip.h:151
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:167
static void net_ipv6_addr_create_ll_allrouters_mcast(struct in6_addr *addr)
Create link local allrouters multicast IPv6 address.
Definition net_ip.h:1400
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:503
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:914
static bool net_ipv6_addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2)
Compare two IPv6 addresses.
Definition net_ip.h:929
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:1311
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:1103
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:1172
static void net_ipv6_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv6 address raw buffer.
Definition net_ip.h:886
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:1228
static struct sockaddr_in_ptr * net_sin_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in_ptr from sockaddr_ptr.
Definition net_ip.h:1584
const struct in_addr * net_ipv4_broadcast_address(void)
Return pointer to broadcast (all bits ones) IPv4 address.
static void net_ipv6_addr_prefix_mask(const uint8_t *inaddr, uint8_t *outaddr, uint8_t prefix_len)
Get the IPv6 network address via the unicast address and the prefix mask.
Definition net_ip.h:757
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:123
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:1427
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:1186
static void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
Create link local allnodes multicast IPv6 address.
Definition net_ip.h:1390
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:1138
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:1341
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:1271
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:1242
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:969
static void net_ipv6_addr_create_iid(struct in6_addr *addr, struct net_linkaddr *lladdr)
Create IPv6 address interface identifier.
Definition net_ip.h:1444
static bool net_ipv4_is_private_addr(const struct in_addr *addr)
Check if the given IPv4 address is from a private address range.
Definition net_ip.h:838
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:1214
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:1053
net_ip_protocol_secure
Protocol numbers for TLS protocols.
Definition net_ip.h:77
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:865
static int net_ipv6_pe_del_filter(struct in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition net_ip.h:1831
net_ip_mtu
IP Maximum Transfer Unit.
Definition net_ip.h:463
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:788
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:1782
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:1411
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:719
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...
int net_port_set_default(struct sockaddr *addr, uint16_t default_port)
Set the default port in the sockaddr structure.
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:656
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition net_ip.h:1707
net_sock_type
Socket type.
Definition net_ip.h:87
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:994
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:1327
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:824
static struct sockaddr_can_ptr * net_can_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_can_ptr from sockaddr_ptr.
Definition net_ip.h:1612
#define ntohl(x)
Convert 32-bit value from network to host byte order.
Definition net_ip.h:107
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:1081
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:957
static struct sockaddr_in * net_sin(const struct sockaddr *addr)
Get sockaddr_in from sockaddr.
Definition net_ip.h:1556
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:1291
size_t socklen_t
Length of a socket address.
Definition net_ip.h:171
static bool net_ipv6_is_private_addr(const struct in6_addr *addr)
Check if the given IPv6 address is from a private/local address range.
Definition net_ip.h:1008
static struct sockaddr_ll_ptr * net_sll_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_ll_ptr from sockaddr_ptr.
Definition net_ip.h:1598
static struct sockaddr_in6 * net_sin6(const struct sockaddr *addr)
Get sockaddr_in6 from sockaddr.
Definition net_ip.h:1543
#define ntohs(x)
Convert 16-bit value from network to host byte order.
Definition net_ip.h:99
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:800
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:1157
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:982
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:1200
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:131
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:1570
net_priority
Network packet priority settings described in IEEE 802.1Q Annex I.1.
Definition net_ip.h:480
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:812
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
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:1491
static void net_ipv4_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv4 address raw buffer.
Definition net_ip.h:874
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:705
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:943
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:1122
net_addr_type
How the network address is assigned to network interface.
Definition net_ip.h:511
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition net_ip.h:504
@ NET_ADDR_TENTATIVE
Tentative address
Definition net_ip.h:505
@ NET_ADDR_DEPRECATED
Deprecated address
Definition net_ip.h:507
@ NET_ADDR_PREFERRED
Preferred address
Definition net_ip.h:506
@ IPPROTO_TLS_1_1
TLS 1.1 protocol.
Definition net_ip.h:79
@ IPPROTO_TLS_1_0
TLS 1.0 protocol.
Definition net_ip.h:78
@ IPPROTO_DTLS_1_0
DTLS 1.0 protocol.
Definition net_ip.h:82
@ IPPROTO_TLS_1_3
TLS 1.3 protocol.
Definition net_ip.h:81
@ IPPROTO_TLS_1_2
TLS 1.2 protocol.
Definition net_ip.h:80
@ IPPROTO_DTLS_1_2
DTLS 1.2 protocol.
Definition net_ip.h:83
@ NET_IPV4_MTU
IPv4 MTU length.
Definition net_ip.h:476
@ NET_IPV6_MTU
IPv6 MTU length.
Definition net_ip.h:470
@ SOCK_DGRAM
Datagram socket type.
Definition net_ip.h:89
@ SOCK_RAW
RAW socket type
Definition net_ip.h:90
@ SOCK_STREAM
Stream socket type
Definition net_ip.h:88
@ NET_PRIORITY_NC
Network control (highest)
Definition net_ip.h:488
@ NET_PRIORITY_IC
Internetwork control
Definition net_ip.h:487
@ NET_PRIORITY_CA
Critical applications
Definition net_ip.h:484
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter
Definition net_ip.h:486
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition net_ip.h:485
@ NET_PRIORITY_BE
Best effort (default)
Definition net_ip.h:482
@ NET_PRIORITY_EE
Excellent effort
Definition net_ip.h:483
@ NET_PRIORITY_BK
Background (lowest)
Definition net_ip.h:481
@ IPPROTO_IP
IP protocol (pseudo-val for setsockopt()
Definition net_ip.h:65
@ IPPROTO_RAW
RAW IP packets
Definition net_ip.h:73
@ IPPROTO_IPIP
IPIP tunnels
Definition net_ip.h:68
@ IPPROTO_TCP
TCP protocol
Definition net_ip.h:69
@ IPPROTO_IGMP
IGMP protocol
Definition net_ip.h:67
@ IPPROTO_ICMP
ICMP protocol
Definition net_ip.h:66
@ IPPROTO_IPV6
IPv6 protocol
Definition net_ip.h:71
@ IPPROTO_UDP
UDP protocol
Definition net_ip.h:70
@ IPPROTO_ICMPV6
ICMPv6 protocol.
Definition net_ip.h:72
@ NET_ADDR_ANY
Default value.
Definition net_ip.h:513
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition net_ip.h:521
@ NET_ADDR_DHCP
Address is from DHCP.
Definition net_ip.h:517
@ NET_ADDR_MANUAL
Manually set address.
Definition net_ip.h:519
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition net_ip.h:515
@ NET_LINK_IEEE802154
IEEE 802.15.4 link address.
Definition net_linkaddr.h:53
@ NET_LINK_ETHERNET
Ethernet link address.
Definition net_linkaddr.h:57
#define ARRAY_SIZE(array)
Number of elements in the given array.
Definition util.h:111
#define ENOTSUP
Unsupported value.
Definition errno.h:114
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
void * memset(void *buf, int c, size_t n)
int memcmp(const void *m1, const void *m2, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
Control message ancillary data.
Definition net_ip.h:261
int cmsg_type
Protocol-specific type.
Definition net_ip.h:264
socklen_t cmsg_len
Number of bytes, including header.
Definition net_ip.h:262
z_max_align_t cmsg_data[]
Flexible array member to force alignment of cmsghdr.
Definition net_ip.h:265
int cmsg_level
Originating protocol.
Definition net_ip.h:263
Group structure.
Definition grp.h:18
IPv6 address struct.
Definition net_ip.h:142
uint8_t s6_addr[16]
IPv6 address buffer.
Definition net_ip.h:144
uint32_t s6_addr32[4]
In big endian.
Definition net_ip.h:146
uint16_t s6_addr16[8]
In big endian.
Definition net_ip.h:145
IPv4 address struct.
Definition net_ip.h:154
uint8_t s4_addr[4]
IPv4 address buffer.
Definition net_ip.h:156
uint32_t s_addr
In big endian, for POSIX compatibility.
Definition net_ip.h:159
uint16_t s4_addr16[2]
In big endian.
Definition net_ip.h:157
uint32_t s4_addr32[1]
In big endian.
Definition net_ip.h:158
IO vector array element.
Definition net_ip.h:243
void * iov_base
Pointer to data.
Definition net_ip.h:244
size_t iov_len
Length of the data.
Definition net_ip.h:245
Message struct.
Definition net_ip.h:250
struct iovec * msg_iov
Scatter/gather array.
Definition net_ip.h:253
socklen_t msg_namelen
Size of socket address.
Definition net_ip.h:252
void * msg_name
Optional socket address, big endian.
Definition net_ip.h:251
int msg_flags
Flags on received message.
Definition net_ip.h:257
size_t msg_controllen
Ancillary data buffer len.
Definition net_ip.h:256
size_t msg_iovlen
Number of elements in msg_iov.
Definition net_ip.h:254
void * msg_control
Ancillary data.
Definition net_ip.h:255
Network Interface unicast IP addresses.
Definition net_if.h:54
IP and other configuration related data for network interface.
Definition net_if.h:557
Network Interface multicast IP addresses.
Definition net_if.h:145
Network Interface structure.
Definition net_if.h:680
Hardware link address structure.
Definition net_linkaddr.h:69
uint8_t * addr
The array of byte representing the address.
Definition net_linkaddr.h:71
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:77
uint8_t len
Length of that address array.
Definition net_linkaddr.h:74
IPv6/IPv4 network connection tuple.
Definition net_ip.h:494
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition net_ip.h:495
uint16_t local_port
UDP/TCP local port
Definition net_ip.h:498
enum net_ip_protocol ip_proto
IP protocol
Definition net_ip.h:499
uint16_t remote_port
UDP/TCP remote port
Definition net_ip.h:497
struct net_addr * local_addr
IPv6/IPv4 local address
Definition net_ip.h:496
Socket address struct for IPv6.
Definition net_ip.h:181
uint8_t sin6_scope_id
Interfaces for a scope.
Definition net_ip.h:185
struct in6_addr sin6_addr
IPv6 address
Definition net_ip.h:184
uint16_t sin6_port
Port number
Definition net_ip.h:183
sa_family_t sin6_family
AF_INET6
Definition net_ip.h:182
Socket address struct for IPv4.
Definition net_ip.h:189
uint16_t sin_port
Port number
Definition net_ip.h:191
struct in_addr sin_addr
IPv4 address.
Definition net_ip.h:192
sa_family_t sin_family
AF_INET
Definition net_ip.h:190
Socket address struct for packet socket.
Definition net_ip.h:196
uint8_t sll_pkttype
Packet type
Definition net_ip.h:201
uint16_t sll_hatype
ARP hardware type
Definition net_ip.h:200
sa_family_t sll_family
Always AF_PACKET
Definition net_ip.h:197
uint16_t sll_protocol
Physical-layer protocol
Definition net_ip.h:198
int sll_ifindex
Interface number
Definition net_ip.h:199
uint8_t sll_halen
Length of address
Definition net_ip.h:202
uint8_t sll_addr[8]
Physical-layer address, big endian.
Definition net_ip.h:203
Generic sockaddr struct.
Definition net_ip.h:388
sa_family_t sa_family
Address family.
Definition net_ip.h:389
Byte order helpers.
Misc utilities.
Macros to abstract toolchain specific capabilities.