Zephyr API Documentation 4.0.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_BROADCAST 0xffffffff
443
445#define INADDR_ANY_INIT { { { INADDR_ANY } } }
446
448#define INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
449
451#define INET_ADDRSTRLEN 16
455#define INET6_ADDRSTRLEN 46
456
459/* These are for internal usage of the stack */
460#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")
461#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
462
470#if defined(CONFIG_NET_NATIVE_IPV6)
471 NET_IPV6_MTU = CONFIG_NET_IPV6_MTU,
472#else
474#endif
475
480};
481
493
494#define NET_MAX_PRIORITIES 8
504
512
526
529struct net_ipv6_hdr {
530 uint8_t vtc;
531 uint8_t tcflow;
532 uint16_t flow;
533 uint16_t len;
534 uint8_t nexthdr;
535 uint8_t hop_limit;
538} __packed;
539
540struct net_ipv6_frag_hdr {
541 uint8_t nexthdr;
542 uint8_t reserved;
543 uint16_t offset;
544 uint32_t id;
545} __packed;
546
547struct net_ipv4_hdr {
548 uint8_t vhl;
549 uint8_t tos;
550 uint16_t len;
551 uint8_t id[2];
552 uint8_t offset[2];
553 uint8_t ttl;
554 uint8_t proto;
555 uint16_t chksum;
558} __packed;
559
560struct net_icmp_hdr {
561 uint8_t type;
562 uint8_t code;
563 uint16_t chksum;
564} __packed;
565
566struct net_udp_hdr {
567 uint16_t src_port;
568 uint16_t dst_port;
569 uint16_t len;
570 uint16_t chksum;
571} __packed;
572
573struct net_tcp_hdr {
574 uint16_t src_port;
575 uint16_t dst_port;
576 uint8_t seq[4];
577 uint8_t ack[4];
578 uint8_t offset;
580 uint8_t wnd[2];
581 uint16_t chksum;
582 uint8_t urg[2];
583 uint8_t optdata[0];
584} __packed;
585
586static inline const char *net_addr_type2str(enum net_addr_type type)
587{
588 switch (type) {
590 return "AUTO";
591 case NET_ADDR_DHCP:
592 return "DHCP";
593 case NET_ADDR_MANUAL:
594 return "MANUAL";
596 return "OVERRIDE";
597 case NET_ADDR_ANY:
598 default:
599 break;
600 }
601
602 return "<unknown>";
603}
604
605/* IPv6 extension headers types */
606#define NET_IPV6_NEXTHDR_HBHO 0
607#define NET_IPV6_NEXTHDR_DESTO 60
608#define NET_IPV6_NEXTHDR_ROUTING 43
609#define NET_IPV6_NEXTHDR_FRAG 44
610#define NET_IPV6_NEXTHDR_NONE 59
611
616union net_ip_header {
617 struct net_ipv4_hdr *ipv4;
618 struct net_ipv6_hdr *ipv6;
619};
620
621union net_proto_header {
622 struct net_udp_hdr *udp;
623 struct net_tcp_hdr *tcp;
624};
625
626#define NET_UDPH_LEN 8 /* Size of UDP header */
627#define NET_TCPH_LEN 20 /* Size of TCP header */
628#define NET_ICMPH_LEN 4 /* Size of ICMP header */
629
630#define NET_IPV6H_LEN 40 /* Size of IPv6 header */
631#define NET_ICMPV6H_LEN NET_ICMPH_LEN /* Size of ICMPv6 header */
632#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN) /* IPv6 + UDP */
633#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN) /* IPv6 + TCP */
634#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN) /* ICMPv6 + IPv6 */
635#define NET_IPV6_FRAGH_LEN 8
636
637#define NET_IPV4H_LEN 20 /* Size of IPv4 header */
638#define NET_ICMPV4H_LEN NET_ICMPH_LEN /* Size of ICMPv4 header */
639#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN) /* IPv4 + UDP */
640#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN) /* IPv4 + TCP */
641#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN) /* ICMPv4 + IPv4 */
642
643#define NET_IPV6H_LENGTH_OFFSET 0x04 /* Offset of the Length field in the IPv6 header */
644
645#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8 /* Mask for the 13-bit Fragment Offset field */
646#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff /* Mask for the 13-bit Fragment Offset field */
647#define NET_IPV4_MORE_FRAG_MASK 0x2000 /* Mask for the 1-bit More Fragments field */
648#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000 /* Mask for the 1-bit Do Not Fragment field */
649
659static inline bool net_ipv6_is_addr_loopback(struct in6_addr *addr)
660{
661 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
662 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
663 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
664 ntohl(UNALIGNED_GET(&addr->s6_addr32[3])) == 1;
665}
666
674static inline bool net_ipv6_is_addr_mcast(const struct in6_addr *addr)
675{
676 return addr->s6_addr[0] == 0xFF;
677}
678
679struct net_if;
680struct net_if_config;
681
682extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
683 struct net_if **iface);
684
692static inline bool net_ipv6_is_my_addr(struct in6_addr *addr)
693{
694 return net_if_ipv6_addr_lookup(addr, NULL) != NULL;
695}
696
698 const struct in6_addr *addr, struct net_if **iface);
699
708static inline bool net_ipv6_is_my_maddr(struct in6_addr *maddr)
709{
710 return net_if_ipv6_maddr_lookup(maddr, NULL) != NULL;
711}
712
722static inline bool net_ipv6_is_prefix(const uint8_t *addr1,
723 const uint8_t *addr2,
724 uint8_t length)
725{
726 uint8_t bits = 128 - length;
727 uint8_t bytes = length / 8U;
728 uint8_t remain = bits % 8;
729 uint8_t mask;
730
731 if (length > 128) {
732 return false;
733 }
734
735 if (memcmp(addr1, addr2, bytes)) {
736 return false;
737 }
738
739 if (!remain) {
740 /* No remaining bits, the prefixes are the same as first
741 * bytes are the same.
742 */
743 return true;
744 }
745
746 /* Create a mask that has remaining most significant bits set */
747 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
748
749 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
750}
751
752
760static inline void net_ipv6_addr_prefix_mask(const uint8_t *inaddr,
761 uint8_t *outaddr,
762 uint8_t prefix_len)
763{
764 uint8_t bits = 128 - prefix_len;
765 uint8_t bytes = prefix_len / 8U;
766 uint8_t remain = bits % 8;
767 uint8_t mask;
768
769 memset(outaddr, 0, 16U);
770 memcpy(outaddr, inaddr, bytes);
771
772 if (!remain) {
773 /* No remaining bits, the prefixes are the same as first
774 * bytes are the same.
775 */
776 return;
777 }
778
779 /* Create a mask that has remaining most significant bits set */
780 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
781 outaddr[bytes] = inaddr[bytes] & mask;
782}
783
791static inline bool net_ipv4_is_addr_loopback(struct in_addr *addr)
792{
793 return addr->s4_addr[0] == 127U;
794}
795
803static inline bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
804{
805 return UNALIGNED_GET(&addr->s_addr) == 0;
806}
807
815static inline bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
816{
817 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xF0000000) == 0xE0000000;
818}
819
827static inline bool net_ipv4_is_ll_addr(const struct in_addr *addr)
828{
829 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFF0000) == 0xA9FE0000;
830}
831
841static inline bool net_ipv4_is_private_addr(const struct in_addr *addr)
842{
843 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
844
845 masked_24 = ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFFFF00;
846 masked_16 = masked_24 & 0xFFFF0000;
847 masked_12 = masked_24 & 0xFFF00000;
848 masked_10 = masked_24 & 0xFFC00000;
849 masked_8 = masked_24 & 0xFF000000;
850
851 return masked_8 == 0x0A000000 || /* 10.0.0.0/8 */
852 masked_10 == 0x64400000 || /* 100.64.0.0/10 */
853 masked_12 == 0xAC100000 || /* 172.16.0.0/12 */
854 masked_16 == 0xC0A80000 || /* 192.168.0.0/16 */
855 masked_24 == 0xC0000200 || /* 192.0.2.0/24 */
856 masked_24 == 0xC0336400 || /* 192.51.100.0/24 */
857 masked_24 == 0xCB007100; /* 203.0.113.0/24 */
858}
859
868#define net_ipaddr_copy(dest, src) \
869 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
870
877static inline void net_ipv4_addr_copy_raw(uint8_t *dest,
878 const uint8_t *src)
879{
880 net_ipaddr_copy((struct in_addr *)dest, (const struct in_addr *)src);
881}
882
889static inline void net_ipv6_addr_copy_raw(uint8_t *dest,
890 const uint8_t *src)
891{
892 memcpy(dest, src, sizeof(struct in6_addr));
893}
894
903static inline bool net_ipv4_addr_cmp(const struct in_addr *addr1,
904 const struct in_addr *addr2)
905{
906 return UNALIGNED_GET(&addr1->s_addr) == UNALIGNED_GET(&addr2->s_addr);
907}
908
917static inline bool net_ipv4_addr_cmp_raw(const uint8_t *addr1,
918 const uint8_t *addr2)
919{
920 return net_ipv4_addr_cmp((const struct in_addr *)addr1,
921 (const struct in_addr *)addr2);
922}
923
932static inline bool net_ipv6_addr_cmp(const struct in6_addr *addr1,
933 const struct in6_addr *addr2)
934{
935 return !memcmp(addr1, addr2, sizeof(struct in6_addr));
936}
937
946static inline bool net_ipv6_addr_cmp_raw(const uint8_t *addr1,
947 const uint8_t *addr2)
948{
949 return net_ipv6_addr_cmp((const struct in6_addr *)addr1,
950 (const struct in6_addr *)addr2);
951}
952
960static inline bool net_ipv6_is_ll_addr(const struct in6_addr *addr)
961{
962 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFE80);
963}
964
972static inline bool net_ipv6_is_sl_addr(const struct in6_addr *addr)
973{
974 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFEC0);
975}
976
977
985static inline bool net_ipv6_is_ula_addr(const struct in6_addr *addr)
986{
987 return addr->s6_addr[0] == 0xFD;
988}
989
997static inline bool net_ipv6_is_global_addr(const struct in6_addr *addr)
998{
999 return (addr->s6_addr[0] & 0xE0) == 0x20;
1000}
1001
1011static inline bool net_ipv6_is_private_addr(const struct in6_addr *addr)
1012{
1013 uint32_t masked_32, masked_7;
1014
1015 masked_32 = ntohl(UNALIGNED_GET(&addr->s6_addr32[0]));
1016 masked_7 = masked_32 & 0xfc000000;
1017
1018 return masked_32 == 0x20010db8 || /* 2001:db8::/32 */
1019 masked_7 == 0xfc000000; /* fc00::/7 */
1020}
1021
1028
1035
1042
1043struct net_if;
1044extern bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
1045 const struct in_addr *addr);
1046
1056static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
1057 const struct in_addr *addr)
1058{
1059 return net_if_ipv4_addr_mask_cmp(iface, addr);
1060}
1061
1062extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
1063 const struct in_addr *addr);
1064
1073#if defined(CONFIG_NET_NATIVE_IPV4)
1074static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1075 const struct in_addr *addr)
1076{
1078 return true;
1079 }
1080
1081 return net_if_ipv4_is_addr_bcast(iface, addr);
1082}
1083#else
1084static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1085 const struct in_addr *addr)
1086{
1087 ARG_UNUSED(iface);
1088 ARG_UNUSED(addr);
1089
1090 return false;
1091}
1092#endif
1093
1094extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
1095 struct net_if **iface);
1096
1106static inline bool net_ipv4_is_my_addr(const struct in_addr *addr)
1107{
1108 bool ret;
1109
1110 ret = net_if_ipv4_addr_lookup(addr, NULL) != NULL;
1111 if (!ret) {
1112 ret = net_ipv4_is_addr_bcast(NULL, addr);
1113 }
1114
1115 return ret;
1116}
1117
1125static inline bool net_ipv6_is_addr_unspecified(const struct in6_addr *addr)
1126{
1127 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1128 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1129 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
1130 UNALIGNED_GET(&addr->s6_addr32[3]) == 0;
1131}
1132
1141static inline bool net_ipv6_is_addr_solicited_node(const struct in6_addr *addr)
1142{
1143 return UNALIGNED_GET(&addr->s6_addr32[0]) == htonl(0xff020000) &&
1144 UNALIGNED_GET(&addr->s6_addr32[1]) == 0x00000000 &&
1145 UNALIGNED_GET(&addr->s6_addr32[2]) == htonl(0x00000001) &&
1146 ((UNALIGNED_GET(&addr->s6_addr32[3]) & htonl(0xff000000)) ==
1147 htonl(0xff000000));
1148}
1149
1160static inline bool net_ipv6_is_addr_mcast_scope(const struct in6_addr *addr,
1161 int scope)
1162{
1163 return (addr->s6_addr[0] == 0xff) && ((addr->s6_addr[1] & 0xF) == scope);
1164}
1165
1175static inline bool net_ipv6_is_same_mcast_scope(const struct in6_addr *addr_1,
1176 const struct in6_addr *addr_2)
1177{
1178 return (addr_1->s6_addr[0] == 0xff) && (addr_2->s6_addr[0] == 0xff) &&
1179 (addr_1->s6_addr[1] == addr_2->s6_addr[1]);
1180}
1181
1189static inline bool net_ipv6_is_addr_mcast_global(const struct in6_addr *addr)
1190{
1191 return net_ipv6_is_addr_mcast_scope(addr, 0x0e);
1192}
1193
1203static inline bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
1204{
1205 return net_ipv6_is_addr_mcast_scope(addr, 0x01);
1206}
1207
1217static inline bool net_ipv6_is_addr_mcast_link(const struct in6_addr *addr)
1218{
1219 return net_ipv6_is_addr_mcast_scope(addr, 0x02);
1220}
1221
1231static inline bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
1232{
1233 return net_ipv6_is_addr_mcast_scope(addr, 0x03);
1234}
1235
1245static inline bool net_ipv6_is_addr_mcast_site(const struct in6_addr *addr)
1246{
1247 return net_ipv6_is_addr_mcast_scope(addr, 0x05);
1248}
1249
1259static inline bool net_ipv6_is_addr_mcast_org(const struct in6_addr *addr)
1260{
1261 return net_ipv6_is_addr_mcast_scope(addr, 0x08);
1262}
1263
1274static inline bool net_ipv6_is_addr_mcast_group(const struct in6_addr *addr,
1275 const struct in6_addr *group)
1276{
1277 return UNALIGNED_GET(&addr->s6_addr16[1]) == group->s6_addr16[1] &&
1278 UNALIGNED_GET(&addr->s6_addr16[2]) == group->s6_addr16[2] &&
1279 UNALIGNED_GET(&addr->s6_addr16[3]) == group->s6_addr16[3] &&
1280 UNALIGNED_GET(&addr->s6_addr32[1]) == group->s6_addr32[1] &&
1281 UNALIGNED_GET(&addr->s6_addr32[2]) == group->s6_addr32[1] &&
1282 UNALIGNED_GET(&addr->s6_addr32[3]) == group->s6_addr32[3];
1283}
1284
1293static inline bool
1295{
1296 static const struct in6_addr all_nodes_mcast_group = {
1297 { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1298 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
1299 };
1300
1301 return net_ipv6_is_addr_mcast_group(addr, &all_nodes_mcast_group);
1302}
1303
1313static inline bool
1319
1329static inline bool
1335
1343static inline
1345 struct in6_addr *dst)
1346{
1347 dst->s6_addr[0] = 0xFF;
1348 dst->s6_addr[1] = 0x02;
1349 UNALIGNED_PUT(0, &dst->s6_addr16[1]);
1350 UNALIGNED_PUT(0, &dst->s6_addr16[2]);
1351 UNALIGNED_PUT(0, &dst->s6_addr16[3]);
1352 UNALIGNED_PUT(0, &dst->s6_addr16[4]);
1353 dst->s6_addr[10] = 0U;
1354 dst->s6_addr[11] = 0x01;
1355 dst->s6_addr[12] = 0xFF;
1356 dst->s6_addr[13] = src->s6_addr[13];
1357 UNALIGNED_PUT(UNALIGNED_GET(&src->s6_addr16[7]), &dst->s6_addr16[7]);
1358}
1359
1372static inline void net_ipv6_addr_create(struct in6_addr *addr,
1373 uint16_t addr0, uint16_t addr1,
1374 uint16_t addr2, uint16_t addr3,
1375 uint16_t addr4, uint16_t addr5,
1376 uint16_t addr6, uint16_t addr7)
1377{
1378 UNALIGNED_PUT(htons(addr0), &addr->s6_addr16[0]);
1379 UNALIGNED_PUT(htons(addr1), &addr->s6_addr16[1]);
1380 UNALIGNED_PUT(htons(addr2), &addr->s6_addr16[2]);
1381 UNALIGNED_PUT(htons(addr3), &addr->s6_addr16[3]);
1382 UNALIGNED_PUT(htons(addr4), &addr->s6_addr16[4]);
1383 UNALIGNED_PUT(htons(addr5), &addr->s6_addr16[5]);
1384 UNALIGNED_PUT(htons(addr6), &addr->s6_addr16[6]);
1385 UNALIGNED_PUT(htons(addr7), &addr->s6_addr16[7]);
1386}
1387
1393static inline void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
1394{
1395 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
1396}
1397
1404{
1405 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002);
1406}
1407
1414static inline void net_ipv6_addr_create_v4_mapped(const struct in_addr *addr4,
1415 struct in6_addr *addr6)
1416{
1417 net_ipv6_addr_create(addr6, 0, 0, 0, 0, 0, 0xffff,
1418 ntohs(addr4->s4_addr16[0]),
1419 ntohs(addr4->s4_addr16[1]));
1420}
1421
1430static inline bool net_ipv6_addr_is_v4_mapped(const struct in6_addr *addr)
1431{
1432 if (UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1433 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1434 UNALIGNED_GET(&addr->s6_addr16[5]) == 0xffff) {
1435 return true;
1436 }
1437
1438 return false;
1439}
1440
1460 const struct in6_addr *prefix,
1461 uint8_t *network_id, size_t network_id_len,
1462 uint8_t dad_counter,
1463 struct in6_addr *addr,
1464 struct net_linkaddr *lladdr);
1465
1472static inline void net_ipv6_addr_create_iid(struct in6_addr *addr,
1473 struct net_linkaddr *lladdr)
1474{
1475 (void)net_ipv6_addr_generate_iid(NULL, NULL, NULL, 0, 0, addr, lladdr);
1476}
1477
1483static inline bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr,
1484 const struct net_linkaddr *lladdr)
1485{
1486 if (!addr || !lladdr) {
1487 return false;
1488 }
1489
1490 switch (lladdr->len) {
1491 case 2:
1492 if (!memcmp(&addr->s6_addr[14], lladdr->addr, lladdr->len) &&
1493 addr->s6_addr[8] == 0U &&
1494 addr->s6_addr[9] == 0U &&
1495 addr->s6_addr[10] == 0U &&
1496 addr->s6_addr[11] == 0xff &&
1497 addr->s6_addr[12] == 0xfe) {
1498 return true;
1499 }
1500
1501 break;
1502 case 6:
1503 if (lladdr->type == NET_LINK_ETHERNET) {
1504 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1505 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1506 addr->s6_addr[11] == 0xff &&
1507 addr->s6_addr[12] == 0xfe &&
1508 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1509 return true;
1510 }
1511 }
1512
1513 break;
1514 case 8:
1515 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1],
1516 lladdr->len - 1) &&
1517 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1518 return true;
1519 }
1520
1521 break;
1522 }
1523
1524 return false;
1525}
1526
1535static inline struct sockaddr_in6 *net_sin6(const struct sockaddr *addr)
1536{
1537 return (struct sockaddr_in6 *)addr;
1538}
1539
1548static inline struct sockaddr_in *net_sin(const struct sockaddr *addr)
1549{
1550 return (struct sockaddr_in *)addr;
1551}
1552
1561static inline
1562struct sockaddr_in6_ptr *net_sin6_ptr(const struct sockaddr_ptr *addr)
1563{
1564 return (struct sockaddr_in6_ptr *)addr;
1565}
1566
1575static inline
1576struct sockaddr_in_ptr *net_sin_ptr(const struct sockaddr_ptr *addr)
1577{
1578 return (struct sockaddr_in_ptr *)addr;
1579}
1580
1589static inline
1590struct sockaddr_ll_ptr *net_sll_ptr(const struct sockaddr_ptr *addr)
1591{
1592 return (struct sockaddr_ll_ptr *)addr;
1593}
1594
1603static inline
1604struct sockaddr_can_ptr *net_can_ptr(const struct sockaddr_ptr *addr)
1605{
1606 return (struct sockaddr_can_ptr *)addr;
1607}
1608
1622__syscall int net_addr_pton(sa_family_t family, const char *src, void *dst);
1623
1635__syscall char *net_addr_ntop(sa_family_t family, const void *src,
1636 char *dst, size_t size);
1637
1659bool net_ipaddr_parse(const char *str, size_t str_len,
1660 struct sockaddr *addr);
1661
1671int net_port_set_default(struct sockaddr *addr, uint16_t default_port);
1672
1684static inline int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
1685{
1686 return (int32_t)(seq1 - seq2);
1687}
1688
1699static inline bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
1700{
1701 return net_tcp_seq_cmp(seq1, seq2) > 0;
1702}
1703
1715int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src);
1716
1726
1736
1745static inline enum net_priority net_vlan2priority(uint8_t priority)
1746{
1747 /* Map according to IEEE 802.1Q */
1748 static const uint8_t vlan2priority[] = {
1757 };
1758
1759 if (priority >= ARRAY_SIZE(vlan2priority)) {
1760 /* Use Best Effort as the default priority */
1761 return NET_PRIORITY_BE;
1762 }
1763
1764 return (enum net_priority)vlan2priority[priority];
1765}
1766
1774static inline uint8_t net_priority2vlan(enum net_priority priority)
1775{
1776 /* The conversion works both ways */
1777 return (uint8_t)net_vlan2priority(priority);
1778}
1779
1788const char *net_family2str(sa_family_t family);
1789
1800#if defined(CONFIG_NET_IPV6_PE)
1801int net_ipv6_pe_add_filter(struct in6_addr *addr, bool is_denylist);
1802#else
1803static inline int net_ipv6_pe_add_filter(struct in6_addr *addr,
1804 bool is_denylist)
1805{
1806 ARG_UNUSED(addr);
1807 ARG_UNUSED(is_denylist);
1808
1809 return -ENOTSUP;
1810}
1811#endif /* CONFIG_NET_IPV6_PE */
1812
1820#if defined(CONFIG_NET_IPV6_PE)
1821int net_ipv6_pe_del_filter(struct in6_addr *addr);
1822#else
1823static inline int net_ipv6_pe_del_filter(struct in6_addr *addr)
1824{
1825 ARG_UNUSED(addr);
1826
1827 return -ENOTSUP;
1828}
1829#endif /* CONFIG_NET_IPV6_PE */
1830
1831#ifdef __cplusplus
1832}
1833#endif
1834
1835#include <zephyr/syscalls/net_ip.h>
1836
1842#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:692
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:1372
static bool net_ipv4_addr_cmp(const struct in_addr *addr1, const struct in_addr *addr2)
Compare two IPv4 addresses.
Definition net_ip.h:903
#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:1259
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:1745
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:1803
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition net_ip.h:1684
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:674
#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:1403
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:506
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:917
static bool net_ipv6_addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2)
Compare two IPv6 addresses.
Definition net_ip.h:932
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:1314
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:1106
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:1175
static void net_ipv6_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv6 address raw buffer.
Definition net_ip.h:889
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:1231
static struct sockaddr_in_ptr * net_sin_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in_ptr from sockaddr_ptr.
Definition net_ip.h:1576
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:760
#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:1430
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:1189
static void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
Create link local allnodes multicast IPv6 address.
Definition net_ip.h:1393
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:1141
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:1344
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:1274
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:1245
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:972
static void net_ipv6_addr_create_iid(struct in6_addr *addr, struct net_linkaddr *lladdr)
Create IPv6 address interface identifier.
Definition net_ip.h:1472
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:841
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:1217
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:1056
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:868
static int net_ipv6_pe_del_filter(struct in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition net_ip.h:1823
net_ip_mtu
IP Maximum Transfer Unit.
Definition net_ip.h:466
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.
int net_ipv6_addr_generate_iid(struct net_if *iface, const struct in6_addr *prefix, uint8_t *network_id, size_t network_id_len, uint8_t dad_counter, struct in6_addr *addr, struct net_linkaddr *lladdr)
Generate IPv6 address using a prefix and interface identifier.
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:791
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:1774
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:1414
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:722
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:659
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition net_ip.h:1699
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:997
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:1330
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:827
static struct sockaddr_can_ptr * net_can_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_can_ptr from sockaddr_ptr.
Definition net_ip.h:1604
#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:1084
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:960
static struct sockaddr_in * net_sin(const struct sockaddr *addr)
Get sockaddr_in from sockaddr.
Definition net_ip.h:1548
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:1294
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:1011
static struct sockaddr_ll_ptr * net_sll_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_ll_ptr from sockaddr_ptr.
Definition net_ip.h:1590
static struct sockaddr_in6 * net_sin6(const struct sockaddr *addr)
Get sockaddr_in6 from sockaddr.
Definition net_ip.h:1535
#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:803
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:1160
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:985
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:1203
#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:1562
net_priority
Network packet priority settings described in IEEE 802.1Q Annex I.1.
Definition net_ip.h:483
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:815
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:1483
static void net_ipv4_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv4 address raw buffer.
Definition net_ip.h:877
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:708
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:946
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:1125
net_addr_type
How the network address is assigned to network interface.
Definition net_ip.h:514
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition net_ip.h:507
@ NET_ADDR_TENTATIVE
Tentative address
Definition net_ip.h:508
@ NET_ADDR_DEPRECATED
Deprecated address
Definition net_ip.h:510
@ NET_ADDR_PREFERRED
Preferred address
Definition net_ip.h:509
@ 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:479
@ NET_IPV6_MTU
IPv6 MTU length.
Definition net_ip.h:473
@ 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:491
@ NET_PRIORITY_IC
Internetwork control
Definition net_ip.h:490
@ NET_PRIORITY_CA
Critical applications
Definition net_ip.h:487
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter
Definition net_ip.h:489
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition net_ip.h:488
@ NET_PRIORITY_BE
Best effort (default)
Definition net_ip.h:485
@ NET_PRIORITY_EE
Excellent effort
Definition net_ip.h:486
@ NET_PRIORITY_BK
Background (lowest)
Definition net_ip.h:484
@ 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:516
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition net_ip.h:524
@ NET_ADDR_DHCP
Address is from DHCP.
Definition net_ip.h:520
@ NET_ADDR_MANUAL
Manually set address.
Definition net_ip.h:522
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition net_ip.h:518
@ 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:120
#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:567
Network Interface multicast IP addresses.
Definition net_if.h:145
Network Interface structure.
Definition net_if.h:690
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:497
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition net_ip.h:498
uint16_t local_port
UDP/TCP local port
Definition net_ip.h:501
enum net_ip_protocol ip_proto
IP protocol
Definition net_ip.h:502
uint16_t remote_port
UDP/TCP remote port
Definition net_ip.h:500
struct net_addr * local_addr
IPv6/IPv4 local address
Definition net_ip.h:499
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.