Zephyr API Documentation  3.7.0-rc1
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
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 {
144 };
145};
146
148#define NET_IPV6_ADDR_SIZE 16
149
151struct in_addr {
152 union {
157 };
158};
159
161#define NET_IPV4_ADDR_SIZE 4
162
164typedef unsigned short int sa_family_t;
165
167#ifndef __socklen_t_defined
168typedef size_t socklen_t;
169#define __socklen_t_defined
170#endif
171
172/*
173 * Note that the sin_port and sin6_port are in network byte order
174 * in various sockaddr* structs.
175 */
176
183};
184
190};
191
201};
202
206struct sockaddr_in6_ptr {
207 sa_family_t sin6_family;
208 uint16_t sin6_port;
209 struct in6_addr *sin6_addr;
210 uint8_t sin6_scope_id;
211};
212
214struct sockaddr_in_ptr {
215 sa_family_t sin_family;
216 uint16_t sin_port;
217 struct in_addr *sin_addr;
218};
219
221struct sockaddr_ll_ptr {
222 sa_family_t sll_family;
223 uint16_t sll_protocol;
224 int sll_ifindex;
225 uint16_t sll_hatype;
226 uint8_t sll_pkttype;
227 uint8_t sll_halen;
228 uint8_t *sll_addr;
229};
230
231struct sockaddr_can_ptr {
232 sa_family_t can_family;
233 int can_ifindex;
234};
235
238#if !defined(HAVE_IOVEC)
240struct iovec {
241 void *iov_base;
242 size_t iov_len;
243};
244#endif
245
247struct msghdr {
248 void *msg_name;
250 struct iovec *msg_iov;
251 size_t msg_iovlen;
255};
256
258struct cmsghdr {
262 z_max_align_t cmsg_data[];
263};
264
267/* Alignment for headers and data. These are arch specific but define
268 * them here atm if not found alredy.
269 */
270#if !defined(ALIGN_H)
271#define ALIGN_H(x) ROUND_UP(x, __alignof__(struct cmsghdr))
272#endif
273#if !defined(ALIGN_D)
274#define ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
275#endif
276
279#if !defined(CMSG_FIRSTHDR)
285#define CMSG_FIRSTHDR(msghdr) \
286 ((msghdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
287 (struct cmsghdr *)((msghdr)->msg_control) : NULL)
288#endif
289
290#if !defined(CMSG_NXTHDR)
295#define CMSG_NXTHDR(msghdr, cmsg) \
296 (((cmsg) == NULL) ? CMSG_FIRSTHDR(msghdr) : \
297 (((uint8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) + \
298 ALIGN_D(sizeof(struct cmsghdr)) > \
299 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
300 NULL : \
301 (struct cmsghdr *)((uint8_t *)(cmsg) + \
302 ALIGN_H((cmsg)->cmsg_len))))
303#endif
304
305#if !defined(CMSG_DATA)
313#define CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + ALIGN_D(sizeof(struct cmsghdr)))
314#endif
315
316#if !defined(CMSG_SPACE)
321#define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + ALIGN_H(length))
322#endif
323
324#if !defined(CMSG_LEN)
330#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + length)
331#endif
332
335/* Packet types. */
336#define PACKET_HOST 0 /* To us */
337#define PACKET_BROADCAST 1 /* To all */
338#define PACKET_MULTICAST 2 /* To group */
339#define PACKET_OTHERHOST 3 /* To someone else */
340#define PACKET_OUTGOING 4 /* Originated by us */
341#define PACKET_LOOPBACK 5
342#define PACKET_FASTROUTE 6
343
344/* ARP protocol HARDWARE identifiers. */
345#define ARPHRD_ETHER 1
346
347/* Note: These macros are defined in a specific order.
348 * The largest sockaddr size is the last one.
349 */
350#if defined(CONFIG_NET_IPV4)
351#undef NET_SOCKADDR_MAX_SIZE
352#undef NET_SOCKADDR_PTR_MAX_SIZE
353#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in))
354#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in_ptr))
355#endif
356
357#if defined(CONFIG_NET_SOCKETS_PACKET)
358#undef NET_SOCKADDR_MAX_SIZE
359#undef NET_SOCKADDR_PTR_MAX_SIZE
360#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_ll))
361#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_ll_ptr))
362#endif
363
364#if defined(CONFIG_NET_IPV6)
365#undef NET_SOCKADDR_MAX_SIZE
366#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
367#if !defined(CONFIG_NET_SOCKETS_PACKET)
368#undef NET_SOCKADDR_PTR_MAX_SIZE
369#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
370#endif
371#endif
372
373#if !defined(CONFIG_NET_IPV4)
374#if !defined(CONFIG_NET_IPV6)
375#if !defined(CONFIG_NET_SOCKETS_PACKET)
376#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
377#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
378#endif
379#endif
380#endif
381
385struct sockaddr {
388 char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
390};
391
394struct sockaddr_ptr {
395 sa_family_t family;
396 char data[NET_SOCKADDR_PTR_MAX_SIZE - sizeof(sa_family_t)];
397};
398
399/* Same as sockaddr in our case */
400struct sockaddr_storage {
401 sa_family_t ss_family;
402 char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
403};
404
405/* Socket address struct for UNIX domain sockets */
406struct sockaddr_un {
407 sa_family_t sun_family; /* AF_UNIX */
408 char sun_path[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
409};
410
411struct net_addr {
412 sa_family_t family;
413 union {
414 struct in6_addr in6_addr;
415 struct in_addr in_addr;
416 };
417};
418
420extern const struct in6_addr in6addr_any;
421
423extern const struct in6_addr in6addr_loopback;
424
428#define IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, \
429 0, 0, 0, 0, 0, 0, 0 } } }
430
432#define IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, \
433 0, 0, 0, 0, 0, 0, 0, 0, 1 } } }
434
436#define INADDR_ANY 0
437
439#define INADDR_ANY_INIT { { { INADDR_ANY } } }
440
442#define INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
443
445#define INET_ADDRSTRLEN 16
449#define INET6_ADDRSTRLEN 46
450
453/* These are for internal usage of the stack */
454#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")
455#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
456
464#if defined(CONFIG_NET_NATIVE_IPV6)
465 NET_IPV6_MTU = CONFIG_NET_IPV6_MTU,
466#else
468#endif
469
474};
475
485 NET_PRIORITY_NC = 7
486} __packed;
487
488#define NET_MAX_PRIORITIES 8
491struct net_tuple {
492 struct net_addr *remote_addr;
493 struct net_addr *local_addr;
497};
498
505} __packed;
506
519} __packed;
520
523struct net_ipv6_hdr {
524 uint8_t vtc;
525 uint8_t tcflow;
526 uint16_t flow;
527 uint16_t len;
528 uint8_t nexthdr;
529 uint8_t hop_limit;
532} __packed;
533
534struct net_ipv6_frag_hdr {
535 uint8_t nexthdr;
536 uint8_t reserved;
537 uint16_t offset;
538 uint32_t id;
539} __packed;
540
541struct net_ipv4_hdr {
542 uint8_t vhl;
543 uint8_t tos;
544 uint16_t len;
545 uint8_t id[2];
546 uint8_t offset[2];
547 uint8_t ttl;
548 uint8_t proto;
549 uint16_t chksum;
552} __packed;
553
554struct net_icmp_hdr {
555 uint8_t type;
556 uint8_t code;
557 uint16_t chksum;
558} __packed;
559
560struct net_udp_hdr {
561 uint16_t src_port;
562 uint16_t dst_port;
563 uint16_t len;
564 uint16_t chksum;
565} __packed;
566
567struct net_tcp_hdr {
568 uint16_t src_port;
569 uint16_t dst_port;
570 uint8_t seq[4];
571 uint8_t ack[4];
572 uint8_t offset;
574 uint8_t wnd[2];
575 uint16_t chksum;
576 uint8_t urg[2];
577 uint8_t optdata[0];
578} __packed;
579
580static inline const char *net_addr_type2str(enum net_addr_type type)
581{
582 switch (type) {
584 return "AUTO";
585 case NET_ADDR_DHCP:
586 return "DHCP";
587 case NET_ADDR_MANUAL:
588 return "MANUAL";
590 return "OVERRIDE";
591 case NET_ADDR_ANY:
592 default:
593 break;
594 }
595
596 return "<unknown>";
597}
598
599/* IPv6 extension headers types */
600#define NET_IPV6_NEXTHDR_HBHO 0
601#define NET_IPV6_NEXTHDR_DESTO 60
602#define NET_IPV6_NEXTHDR_ROUTING 43
603#define NET_IPV6_NEXTHDR_FRAG 44
604#define NET_IPV6_NEXTHDR_NONE 59
605
610union net_ip_header {
611 struct net_ipv4_hdr *ipv4;
612 struct net_ipv6_hdr *ipv6;
613};
614
615union net_proto_header {
616 struct net_udp_hdr *udp;
617 struct net_tcp_hdr *tcp;
618};
619
620#define NET_UDPH_LEN 8 /* Size of UDP header */
621#define NET_TCPH_LEN 20 /* Size of TCP header */
622#define NET_ICMPH_LEN 4 /* Size of ICMP header */
623
624#define NET_IPV6H_LEN 40 /* Size of IPv6 header */
625#define NET_ICMPV6H_LEN NET_ICMPH_LEN /* Size of ICMPv6 header */
626#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN) /* IPv6 + UDP */
627#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN) /* IPv6 + TCP */
628#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN) /* ICMPv6 + IPv6 */
629#define NET_IPV6_FRAGH_LEN 8
630
631#define NET_IPV4H_LEN 20 /* Size of IPv4 header */
632#define NET_ICMPV4H_LEN NET_ICMPH_LEN /* Size of ICMPv4 header */
633#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN) /* IPv4 + UDP */
634#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN) /* IPv4 + TCP */
635#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN) /* ICMPv4 + IPv4 */
636
637#define NET_IPV6H_LENGTH_OFFSET 0x04 /* Offset of the Length field in the IPv6 header */
638
639#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8 /* Mask for the 13-bit Fragment Offset field */
640#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff /* Mask for the 13-bit Fragment Offset field */
641#define NET_IPV4_MORE_FRAG_MASK 0x2000 /* Mask for the 1-bit More Fragments field */
642#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000 /* Mask for the 1-bit Do Not Fragment field */
643
653static inline bool net_ipv6_is_addr_loopback(struct in6_addr *addr)
654{
655 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
656 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
657 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
658 ntohl(UNALIGNED_GET(&addr->s6_addr32[3])) == 1;
659}
660
668static inline bool net_ipv6_is_addr_mcast(const struct in6_addr *addr)
669{
670 return addr->s6_addr[0] == 0xFF;
671}
672
673struct net_if;
674struct net_if_config;
675
676extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
677 struct net_if **iface);
678
686static inline bool net_ipv6_is_my_addr(struct in6_addr *addr)
687{
688 return net_if_ipv6_addr_lookup(addr, NULL) != NULL;
689}
690
692 const struct in6_addr *addr, struct net_if **iface);
693
702static inline bool net_ipv6_is_my_maddr(struct in6_addr *maddr)
703{
704 return net_if_ipv6_maddr_lookup(maddr, NULL) != NULL;
705}
706
716static inline bool net_ipv6_is_prefix(const uint8_t *addr1,
717 const uint8_t *addr2,
718 uint8_t length)
719{
720 uint8_t bits = 128 - length;
721 uint8_t bytes = length / 8U;
722 uint8_t remain = bits % 8;
723 uint8_t mask;
724
725 if (length > 128) {
726 return false;
727 }
728
729 if (memcmp(addr1, addr2, bytes)) {
730 return false;
731 }
732
733 if (!remain) {
734 /* No remaining bits, the prefixes are the same as first
735 * bytes are the same.
736 */
737 return true;
738 }
739
740 /* Create a mask that has remaining most significant bits set */
741 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
742
743 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
744}
745
753static inline bool net_ipv4_is_addr_loopback(struct in_addr *addr)
754{
755 return addr->s4_addr[0] == 127U;
756}
757
765static inline bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
766{
767 return UNALIGNED_GET(&addr->s_addr) == 0;
768}
769
777static inline bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
778{
779 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xF0000000) == 0xE0000000;
780}
781
789static inline bool net_ipv4_is_ll_addr(const struct in_addr *addr)
790{
791 return (ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFF0000) == 0xA9FE0000;
792}
793
803static inline bool net_ipv4_is_private_addr(const struct in_addr *addr)
804{
805 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
806
807 masked_24 = ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFFFF00;
808 masked_16 = masked_24 & 0xFFFF0000;
809 masked_12 = masked_24 & 0xFFF00000;
810 masked_10 = masked_24 & 0xFFC00000;
811 masked_8 = masked_24 & 0xFF000000;
812
813 return masked_8 == 0x0A000000 || /* 10.0.0.0/8 */
814 masked_10 == 0x64400000 || /* 100.64.0.0/10 */
815 masked_12 == 0xAC100000 || /* 172.16.0.0/12 */
816 masked_16 == 0xC0A80000 || /* 192.168.0.0/16 */
817 masked_24 == 0xC0000200 || /* 192.0.2.0/24 */
818 masked_24 == 0xC0336400 || /* 192.51.100.0/24 */
819 masked_24 == 0xCB007100; /* 203.0.113.0/24 */
820}
821
830#define net_ipaddr_copy(dest, src) \
831 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
832
839static inline void net_ipv4_addr_copy_raw(uint8_t *dest,
840 const uint8_t *src)
841{
842 net_ipaddr_copy((struct in_addr *)dest, (const struct in_addr *)src);
843}
844
851static inline void net_ipv6_addr_copy_raw(uint8_t *dest,
852 const uint8_t *src)
853{
854 memcpy(dest, src, sizeof(struct in6_addr));
855}
856
865static inline bool net_ipv4_addr_cmp(const struct in_addr *addr1,
866 const struct in_addr *addr2)
867{
868 return UNALIGNED_GET(&addr1->s_addr) == UNALIGNED_GET(&addr2->s_addr);
869}
870
879static inline bool net_ipv4_addr_cmp_raw(const uint8_t *addr1,
880 const uint8_t *addr2)
881{
882 return net_ipv4_addr_cmp((const struct in_addr *)addr1,
883 (const struct in_addr *)addr2);
884}
885
894static inline bool net_ipv6_addr_cmp(const struct in6_addr *addr1,
895 const struct in6_addr *addr2)
896{
897 return !memcmp(addr1, addr2, sizeof(struct in6_addr));
898}
899
908static inline bool net_ipv6_addr_cmp_raw(const uint8_t *addr1,
909 const uint8_t *addr2)
910{
911 return net_ipv6_addr_cmp((const struct in6_addr *)addr1,
912 (const struct in6_addr *)addr2);
913}
914
922static inline bool net_ipv6_is_ll_addr(const struct in6_addr *addr)
923{
924 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFE80);
925}
926
934static inline bool net_ipv6_is_sl_addr(const struct in6_addr *addr)
935{
936 return UNALIGNED_GET(&addr->s6_addr16[0]) == htons(0xFEC0);
937}
938
939
947static inline bool net_ipv6_is_ula_addr(const struct in6_addr *addr)
948{
949 return addr->s6_addr[0] == 0xFD;
950}
951
959static inline bool net_ipv6_is_global_addr(const struct in6_addr *addr)
960{
961 return (addr->s6_addr[0] & 0xE0) == 0x20;
962}
963
973static inline bool net_ipv6_is_private_addr(const struct in6_addr *addr)
974{
975 uint32_t masked_32, masked_7;
976
977 masked_32 = ntohl(UNALIGNED_GET(&addr->s6_addr32[0]));
978 masked_7 = masked_32 & 0xfc000000;
979
980 return masked_32 == 0x20010db8 || /* 2001:db8::/32 */
981 masked_7 == 0xfc000000; /* fc00::/7 */
982}
983
990
997
1004
1005struct net_if;
1006extern bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
1007 const struct in_addr *addr);
1008
1018static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
1019 const struct in_addr *addr)
1020{
1021 return net_if_ipv4_addr_mask_cmp(iface, addr);
1022}
1023
1024extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
1025 const struct in_addr *addr);
1026
1035#if defined(CONFIG_NET_NATIVE_IPV4)
1036static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1037 const struct in_addr *addr)
1038{
1040 return true;
1041 }
1042
1043 return net_if_ipv4_is_addr_bcast(iface, addr);
1044}
1045#else
1046static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1047 const struct in_addr *addr)
1048{
1049 ARG_UNUSED(iface);
1050 ARG_UNUSED(addr);
1051
1052 return false;
1053}
1054#endif
1055
1056extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
1057 struct net_if **iface);
1058
1068static inline bool net_ipv4_is_my_addr(const struct in_addr *addr)
1069{
1070 bool ret;
1071
1072 ret = net_if_ipv4_addr_lookup(addr, NULL) != NULL;
1073 if (!ret) {
1074 ret = net_ipv4_is_addr_bcast(NULL, addr);
1075 }
1076
1077 return ret;
1078}
1079
1087static inline bool net_ipv6_is_addr_unspecified(const struct in6_addr *addr)
1088{
1089 return UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1090 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1091 UNALIGNED_GET(&addr->s6_addr32[2]) == 0 &&
1092 UNALIGNED_GET(&addr->s6_addr32[3]) == 0;
1093}
1094
1103static inline bool net_ipv6_is_addr_solicited_node(const struct in6_addr *addr)
1104{
1105 return UNALIGNED_GET(&addr->s6_addr32[0]) == htonl(0xff020000) &&
1106 UNALIGNED_GET(&addr->s6_addr32[1]) == 0x00000000 &&
1107 UNALIGNED_GET(&addr->s6_addr32[2]) == htonl(0x00000001) &&
1108 ((UNALIGNED_GET(&addr->s6_addr32[3]) & htonl(0xff000000)) ==
1109 htonl(0xff000000));
1110}
1111
1122static inline bool net_ipv6_is_addr_mcast_scope(const struct in6_addr *addr,
1123 int scope)
1124{
1125 return (addr->s6_addr[0] == 0xff) && ((addr->s6_addr[1] & 0xF) == scope);
1126}
1127
1137static inline bool net_ipv6_is_same_mcast_scope(const struct in6_addr *addr_1,
1138 const struct in6_addr *addr_2)
1139{
1140 return (addr_1->s6_addr[0] == 0xff) && (addr_2->s6_addr[0] == 0xff) &&
1141 (addr_1->s6_addr[1] == addr_2->s6_addr[1]);
1142}
1143
1151static inline bool net_ipv6_is_addr_mcast_global(const struct in6_addr *addr)
1152{
1153 return net_ipv6_is_addr_mcast_scope(addr, 0x0e);
1154}
1155
1165static inline bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
1166{
1167 return net_ipv6_is_addr_mcast_scope(addr, 0x01);
1168}
1169
1179static inline bool net_ipv6_is_addr_mcast_link(const struct in6_addr *addr)
1180{
1181 return net_ipv6_is_addr_mcast_scope(addr, 0x02);
1182}
1183
1193static inline bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
1194{
1195 return net_ipv6_is_addr_mcast_scope(addr, 0x03);
1196}
1197
1207static inline bool net_ipv6_is_addr_mcast_site(const struct in6_addr *addr)
1208{
1209 return net_ipv6_is_addr_mcast_scope(addr, 0x05);
1210}
1211
1221static inline bool net_ipv6_is_addr_mcast_org(const struct in6_addr *addr)
1222{
1223 return net_ipv6_is_addr_mcast_scope(addr, 0x08);
1224}
1225
1236static inline bool net_ipv6_is_addr_mcast_group(const struct in6_addr *addr,
1237 const struct in6_addr *group)
1238{
1239 return UNALIGNED_GET(&addr->s6_addr16[1]) == group->s6_addr16[1] &&
1240 UNALIGNED_GET(&addr->s6_addr16[2]) == group->s6_addr16[2] &&
1241 UNALIGNED_GET(&addr->s6_addr16[3]) == group->s6_addr16[3] &&
1242 UNALIGNED_GET(&addr->s6_addr32[1]) == group->s6_addr32[1] &&
1243 UNALIGNED_GET(&addr->s6_addr32[2]) == group->s6_addr32[1] &&
1244 UNALIGNED_GET(&addr->s6_addr32[3]) == group->s6_addr32[3];
1245}
1246
1255static inline bool
1257{
1258 static const struct in6_addr all_nodes_mcast_group = {
1259 { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1260 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
1261 };
1262
1263 return net_ipv6_is_addr_mcast_group(addr, &all_nodes_mcast_group);
1264}
1265
1275static inline bool
1277{
1278 return net_ipv6_is_addr_mcast_iface(addr) &&
1280}
1281
1291static inline bool
1293{
1294 return net_ipv6_is_addr_mcast_link(addr) &&
1296}
1297
1305static inline
1307 struct in6_addr *dst)
1308{
1309 dst->s6_addr[0] = 0xFF;
1310 dst->s6_addr[1] = 0x02;
1311 UNALIGNED_PUT(0, &dst->s6_addr16[1]);
1312 UNALIGNED_PUT(0, &dst->s6_addr16[2]);
1313 UNALIGNED_PUT(0, &dst->s6_addr16[3]);
1314 UNALIGNED_PUT(0, &dst->s6_addr16[4]);
1315 dst->s6_addr[10] = 0U;
1316 dst->s6_addr[11] = 0x01;
1317 dst->s6_addr[12] = 0xFF;
1318 dst->s6_addr[13] = src->s6_addr[13];
1319 UNALIGNED_PUT(UNALIGNED_GET(&src->s6_addr16[7]), &dst->s6_addr16[7]);
1320}
1321
1334static inline void net_ipv6_addr_create(struct in6_addr *addr,
1335 uint16_t addr0, uint16_t addr1,
1336 uint16_t addr2, uint16_t addr3,
1337 uint16_t addr4, uint16_t addr5,
1338 uint16_t addr6, uint16_t addr7)
1339{
1340 UNALIGNED_PUT(htons(addr0), &addr->s6_addr16[0]);
1341 UNALIGNED_PUT(htons(addr1), &addr->s6_addr16[1]);
1342 UNALIGNED_PUT(htons(addr2), &addr->s6_addr16[2]);
1343 UNALIGNED_PUT(htons(addr3), &addr->s6_addr16[3]);
1344 UNALIGNED_PUT(htons(addr4), &addr->s6_addr16[4]);
1345 UNALIGNED_PUT(htons(addr5), &addr->s6_addr16[5]);
1346 UNALIGNED_PUT(htons(addr6), &addr->s6_addr16[6]);
1347 UNALIGNED_PUT(htons(addr7), &addr->s6_addr16[7]);
1348}
1349
1355static inline void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
1356{
1357 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
1358}
1359
1366{
1367 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002);
1368}
1369
1376static inline void net_ipv6_addr_create_v4_mapped(const struct in_addr *addr4,
1377 struct in6_addr *addr6)
1378{
1379 net_ipv6_addr_create(addr6, 0, 0, 0, 0, 0, 0xffff,
1380 ntohs(addr4->s4_addr16[0]),
1381 ntohs(addr4->s4_addr16[1]));
1382}
1383
1392static inline bool net_ipv6_addr_is_v4_mapped(const struct in6_addr *addr)
1393{
1394 if (UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1395 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1396 UNALIGNED_GET(&addr->s6_addr16[5]) == 0xffff) {
1397 return true;
1398 }
1399
1400 return false;
1401}
1402
1409static inline void net_ipv6_addr_create_iid(struct in6_addr *addr,
1410 struct net_linkaddr *lladdr)
1411{
1412 UNALIGNED_PUT(htonl(0xfe800000), &addr->s6_addr32[0]);
1413 UNALIGNED_PUT(0, &addr->s6_addr32[1]);
1414
1415 switch (lladdr->len) {
1416 case 2:
1417 /* The generated IPv6 shall not toggle the
1418 * Universal/Local bit. RFC 6282 ch 3.2.2
1419 */
1420 if (lladdr->type == NET_LINK_IEEE802154) {
1421 UNALIGNED_PUT(0, &addr->s6_addr32[2]);
1422 addr->s6_addr[11] = 0xff;
1423 addr->s6_addr[12] = 0xfe;
1424 addr->s6_addr[13] = 0U;
1425 addr->s6_addr[14] = lladdr->addr[0];
1426 addr->s6_addr[15] = lladdr->addr[1];
1427 }
1428
1429 break;
1430 case 6:
1431 /* We do not toggle the Universal/Local bit
1432 * in Bluetooth. See RFC 7668 ch 3.2.2
1433 */
1434 memcpy(&addr->s6_addr[8], lladdr->addr, 3);
1435 addr->s6_addr[11] = 0xff;
1436 addr->s6_addr[12] = 0xfe;
1437 memcpy(&addr->s6_addr[13], lladdr->addr + 3, 3);
1438
1439 if (lladdr->type == NET_LINK_ETHERNET) {
1440 addr->s6_addr[8] ^= 0x02;
1441 }
1442
1443 break;
1444 case 8:
1445 memcpy(&addr->s6_addr[8], lladdr->addr, lladdr->len);
1446 addr->s6_addr[8] ^= 0x02;
1447 break;
1448 }
1449}
1450
1456static inline bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr,
1457 const struct net_linkaddr *lladdr)
1458{
1459 if (!addr || !lladdr) {
1460 return false;
1461 }
1462
1463 switch (lladdr->len) {
1464 case 2:
1465 if (!memcmp(&addr->s6_addr[14], lladdr->addr, lladdr->len) &&
1466 addr->s6_addr[8] == 0U &&
1467 addr->s6_addr[9] == 0U &&
1468 addr->s6_addr[10] == 0U &&
1469 addr->s6_addr[11] == 0xff &&
1470 addr->s6_addr[12] == 0xfe) {
1471 return true;
1472 }
1473
1474 break;
1475 case 6:
1476 if (lladdr->type == NET_LINK_ETHERNET) {
1477 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1], 2) &&
1478 !memcmp(&addr->s6_addr[13], &lladdr->addr[3], 3) &&
1479 addr->s6_addr[11] == 0xff &&
1480 addr->s6_addr[12] == 0xfe &&
1481 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1482 return true;
1483 }
1484 }
1485
1486 break;
1487 case 8:
1488 if (!memcmp(&addr->s6_addr[9], &lladdr->addr[1],
1489 lladdr->len - 1) &&
1490 (addr->s6_addr[8] ^ 0x02) == lladdr->addr[0]) {
1491 return true;
1492 }
1493
1494 break;
1495 }
1496
1497 return false;
1498}
1499
1508static inline struct sockaddr_in6 *net_sin6(const struct sockaddr *addr)
1509{
1510 return (struct sockaddr_in6 *)addr;
1511}
1512
1521static inline struct sockaddr_in *net_sin(const struct sockaddr *addr)
1522{
1523 return (struct sockaddr_in *)addr;
1524}
1525
1534static inline
1535struct sockaddr_in6_ptr *net_sin6_ptr(const struct sockaddr_ptr *addr)
1536{
1537 return (struct sockaddr_in6_ptr *)addr;
1538}
1539
1548static inline
1549struct sockaddr_in_ptr *net_sin_ptr(const struct sockaddr_ptr *addr)
1550{
1551 return (struct sockaddr_in_ptr *)addr;
1552}
1553
1562static inline
1563struct sockaddr_ll_ptr *net_sll_ptr(const struct sockaddr_ptr *addr)
1564{
1565 return (struct sockaddr_ll_ptr *)addr;
1566}
1567
1576static inline
1577struct sockaddr_can_ptr *net_can_ptr(const struct sockaddr_ptr *addr)
1578{
1579 return (struct sockaddr_can_ptr *)addr;
1580}
1581
1595__syscall int net_addr_pton(sa_family_t family, const char *src, void *dst);
1596
1608__syscall char *net_addr_ntop(sa_family_t family, const void *src,
1609 char *dst, size_t size);
1610
1632bool net_ipaddr_parse(const char *str, size_t str_len,
1633 struct sockaddr *addr);
1634
1644int net_port_set_default(struct sockaddr *addr, uint16_t default_port);
1645
1657static inline int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
1658{
1659 return (int32_t)(seq1 - seq2);
1660}
1661
1672static inline bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
1673{
1674 return net_tcp_seq_cmp(seq1, seq2) > 0;
1675}
1676
1688int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src);
1689
1699
1709
1718static inline enum net_priority net_vlan2priority(uint8_t priority)
1719{
1720 /* Map according to IEEE 802.1Q */
1721 static const uint8_t vlan2priority[] = {
1730 };
1731
1732 if (priority >= ARRAY_SIZE(vlan2priority)) {
1733 /* Use Best Effort as the default priority */
1734 return NET_PRIORITY_BE;
1735 }
1736
1737 return (enum net_priority)vlan2priority[priority];
1738}
1739
1747static inline uint8_t net_priority2vlan(enum net_priority priority)
1748{
1749 /* The conversion works both ways */
1750 return (uint8_t)net_vlan2priority(priority);
1751}
1752
1761const char *net_family2str(sa_family_t family);
1762
1773#if defined(CONFIG_NET_IPV6_PE)
1774int net_ipv6_pe_add_filter(struct in6_addr *addr, bool is_denylist);
1775#else
1776static inline int net_ipv6_pe_add_filter(struct in6_addr *addr,
1777 bool is_denylist)
1778{
1779 ARG_UNUSED(addr);
1780 ARG_UNUSED(is_denylist);
1781
1782 return -ENOTSUP;
1783}
1784#endif /* CONFIG_NET_IPV6_PE */
1785
1793#if defined(CONFIG_NET_IPV6_PE)
1794int net_ipv6_pe_del_filter(struct in6_addr *addr);
1795#else
1796static inline int net_ipv6_pe_del_filter(struct in6_addr *addr)
1797{
1798 ARG_UNUSED(addr);
1799
1800 return -ENOTSUP;
1801}
1802#endif /* CONFIG_NET_IPV6_PE */
1803
1804#ifdef __cplusplus
1805}
1806#endif
1807
1808#include <zephyr/syscalls/net_ip.h>
1809
1815#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:686
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:1334
static bool net_ipv4_addr_cmp(const struct in_addr *addr1, const struct in_addr *addr2)
Compare two IPv4 addresses.
Definition: net_ip.h:865
#define NET_IPV4_ADDR_SIZE
Binary size of the IPv4 address.
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:1221
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:1718
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:1776
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition: net_ip.h:1657
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:668
#define NET_IPV6_ADDR_SIZE
Binary size of the IPv6 address.
Definition: net_ip.h:148
int net_addr_pton(sa_family_t family, const char *src, void *dst)
Convert a string to IP address.
unsigned short int sa_family_t
Socket address family type.
Definition: net_ip.h:164
static void net_ipv6_addr_create_ll_allrouters_mcast(struct in6_addr *addr)
Create link local allrouters multicast IPv6 address.
Definition: net_ip.h:1365
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:500
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:879
static bool net_ipv6_addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2)
Compare two IPv6 addresses.
Definition: net_ip.h:894
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:1276
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:1068
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:1137
static void net_ipv6_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv6 address raw buffer.
Definition: net_ip.h:851
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:1193
static struct sockaddr_in_ptr * net_sin_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in_ptr from sockaddr_ptr.
Definition: net_ip.h:1549
const struct in_addr * net_ipv4_broadcast_address(void)
Return pointer to broadcast (all bits ones) IPv4 address.
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition: net_ip.h:120
static bool net_ipv6_addr_is_v4_mapped(const struct in6_addr *addr)
Is the IPv6 address an IPv4 mapped one.
Definition: net_ip.h:1392
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:1151
static void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
Create link local allnodes multicast IPv6 address.
Definition: net_ip.h:1355
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:1103
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:1306
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:1236
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:1207
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:934
static void net_ipv6_addr_create_iid(struct in6_addr *addr, struct net_linkaddr *lladdr)
Create IPv6 address interface identifier.
Definition: net_ip.h:1409
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:803
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:1179
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:1018
net_ip_protocol_secure
Protocol numbers for TLS protocols.
Definition: net_ip.h:75
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition: net_ip.h:830
static int net_ipv6_pe_del_filter(struct in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition: net_ip.h:1796
net_ip_mtu
IP Maximum Transfer Unit.
Definition: net_ip.h:460
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:753
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:1747
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:1376
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:716
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:653
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition: net_ip.h:1672
net_sock_type
Socket type.
Definition: net_ip.h:84
const struct in6_addr * net_ipv6_unspecified_address(void)
Return pointer to any (all bits zeros) IPv6 address.
static bool net_ipv6_is_global_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a global address.
Definition: net_ip.h:959
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:1292
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:789
static struct sockaddr_can_ptr * net_can_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_can_ptr from sockaddr_ptr.
Definition: net_ip.h:1577
#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:1046
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:922
static struct sockaddr_in * net_sin(const struct sockaddr *addr)
Get sockaddr_in from sockaddr.
Definition: net_ip.h:1521
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:1256
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
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:973
static struct sockaddr_ll_ptr * net_sll_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_ll_ptr from sockaddr_ptr.
Definition: net_ip.h:1563
static struct sockaddr_in6 * net_sin6(const struct sockaddr *addr)
Get sockaddr_in6 from sockaddr.
Definition: net_ip.h:1508
#define ntohs(x)
Convert 16-bit value from network to host byte order.
Definition: net_ip.h:96
struct net_if_mcast_addr * net_if_ipv6_maddr_lookup(const struct in6_addr *addr, struct net_if **iface)
static bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
Check if the IPv4 address is unspecified (all bits zero)
Definition: net_ip.h:765
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:1122
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:947
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:1165
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition: net_ip.h:128
int net_tx_priority2tc(enum net_priority prio)
Convert Tx network packet priority to traffic class so we can place the packet into correct Tx queue.
static struct sockaddr_in6_ptr * net_sin6_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in6_ptr from sockaddr_ptr.
Definition: net_ip.h:1535
net_priority
Network packet priority settings described in IEEE 802.1Q Annex I.1.
Definition: net_ip.h:477
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:777
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition: net_ip.h:62
static bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr, const struct net_linkaddr *lladdr)
Check if given address is based on link layer address.
Definition: net_ip.h:1456
static void net_ipv4_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv4 address raw buffer.
Definition: net_ip.h:839
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:702
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:908
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:1087
net_addr_type
How the network address is assigned to network interface.
Definition: net_ip.h:508
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition: net_ip.h:501
@ NET_ADDR_TENTATIVE
Tentative address
Definition: net_ip.h:502
@ NET_ADDR_DEPRECATED
Deprecated address
Definition: net_ip.h:504
@ NET_ADDR_PREFERRED
Preferred address
Definition: net_ip.h:503
@ IPPROTO_TLS_1_1
TLS 1.1 protocol.
Definition: net_ip.h:77
@ IPPROTO_TLS_1_0
TLS 1.0 protocol.
Definition: net_ip.h:76
@ IPPROTO_DTLS_1_0
DTLS 1.0 protocol.
Definition: net_ip.h:79
@ IPPROTO_TLS_1_2
TLS 1.2 protocol.
Definition: net_ip.h:78
@ IPPROTO_DTLS_1_2
DTLS 1.2 protocol.
Definition: net_ip.h:80
@ NET_IPV4_MTU
IPv4 MTU length.
Definition: net_ip.h:473
@ NET_IPV6_MTU
IPv6 MTU length.
Definition: net_ip.h:467
@ SOCK_DGRAM
Datagram socket type.
Definition: net_ip.h:86
@ SOCK_RAW
RAW socket type
Definition: net_ip.h:87
@ SOCK_STREAM
Stream socket type
Definition: net_ip.h:85
@ NET_PRIORITY_NC
Network control (highest)
Definition: net_ip.h:485
@ NET_PRIORITY_IC
Internetwork control
Definition: net_ip.h:484
@ NET_PRIORITY_CA
Critical applications
Definition: net_ip.h:481
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter
Definition: net_ip.h:483
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition: net_ip.h:482
@ NET_PRIORITY_BE
Best effort (default)
Definition: net_ip.h:479
@ NET_PRIORITY_EE
Excellent effort
Definition: net_ip.h:480
@ NET_PRIORITY_BK
Background (lowest)
Definition: net_ip.h:478
@ IPPROTO_IP
IP protocol (pseudo-val for setsockopt()
Definition: net_ip.h:63
@ IPPROTO_RAW
RAW IP packets
Definition: net_ip.h:71
@ IPPROTO_IPIP
IPIP tunnels
Definition: net_ip.h:66
@ IPPROTO_TCP
TCP protocol
Definition: net_ip.h:67
@ IPPROTO_IGMP
IGMP protocol
Definition: net_ip.h:65
@ IPPROTO_ICMP
ICMP protocol
Definition: net_ip.h:64
@ IPPROTO_IPV6
IPv6 protocol
Definition: net_ip.h:69
@ IPPROTO_UDP
UDP protocol
Definition: net_ip.h:68
@ IPPROTO_ICMPV6
ICMPv6 protocol.
Definition: net_ip.h:70
@ NET_ADDR_ANY
Default value.
Definition: net_ip.h:510
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition: net_ip.h:518
@ NET_ADDR_DHCP
Address is from DHCP.
Definition: net_ip.h:514
@ NET_ADDR_MANUAL
Manually set address.
Definition: net_ip.h:516
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition: net_ip.h:512
@ NET_LINK_IEEE802154
IEEE 802.15.4 link address.
Definition: net_linkaddr.h:51
@ NET_LINK_ETHERNET
Ethernet link address.
Definition: net_linkaddr.h:55
#define ARRAY_SIZE(array)
Number of elements in the given array.
Definition: util.h:127
#define ENOTSUP
Unsupported value.
Definition: errno.h:115
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)
Control message ancillary data.
Definition: net_ip.h:258
int cmsg_type
Protocol-specific type.
Definition: net_ip.h:261
socklen_t cmsg_len
Number of bytes, including header.
Definition: net_ip.h:259
z_max_align_t cmsg_data[]
Flexible array member to force alignment of cmsghdr.
Definition: net_ip.h:262
int cmsg_level
Originating protocol.
Definition: net_ip.h:260
IPv6 address struct.
Definition: net_ip.h:139
uint8_t s6_addr[16]
IPv6 address buffer.
Definition: net_ip.h:141
uint32_t s6_addr32[4]
In big endian.
Definition: net_ip.h:143
uint16_t s6_addr16[8]
In big endian.
Definition: net_ip.h:142
IPv4 address struct.
Definition: net_ip.h:151
uint8_t s4_addr[4]
IPv4 address buffer.
Definition: net_ip.h:153
uint32_t s_addr
In big endian, for POSIX compatibility.
Definition: net_ip.h:156
uint16_t s4_addr16[2]
In big endian.
Definition: net_ip.h:154
uint32_t s4_addr32[1]
In big endian.
Definition: net_ip.h:155
IO vector array element.
Definition: net_ip.h:240
void * iov_base
Pointer to data.
Definition: net_ip.h:241
size_t iov_len
Length of the data.
Definition: net_ip.h:242
Message struct.
Definition: net_ip.h:247
struct iovec * msg_iov
Scatter/gather array.
Definition: net_ip.h:250
socklen_t msg_namelen
Size of socket address.
Definition: net_ip.h:249
void * msg_name
Optional socket address, big endian.
Definition: net_ip.h:248
int msg_flags
Flags on received message.
Definition: net_ip.h:254
size_t msg_controllen
Ancillary data buffer len.
Definition: net_ip.h:253
size_t msg_iovlen
Number of elements in msg_iov.
Definition: net_ip.h:251
void * msg_control
Ancillary data.
Definition: net_ip.h:252
Network Interface unicast IP addresses.
Definition: net_if.h:52
IP and other configuration related data for network interface.
Definition: net_if.h:555
Network Interface multicast IP addresses.
Definition: net_if.h:143
Network Interface structure.
Definition: net_if.h:678
Hardware link address structure.
Definition: net_linkaddr.h:67
uint8_t * addr
The array of byte representing the address.
Definition: net_linkaddr.h:69
uint8_t type
What kind of address is this for.
Definition: net_linkaddr.h:75
uint8_t len
Length of that address array.
Definition: net_linkaddr.h:72
IPv6/IPv4 network connection tuple.
Definition: net_ip.h:491
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition: net_ip.h:492
uint16_t local_port
UDP/TCP local port
Definition: net_ip.h:495
enum net_ip_protocol ip_proto
IP protocol
Definition: net_ip.h:496
uint16_t remote_port
UDP/TCP remote port
Definition: net_ip.h:494
struct net_addr * local_addr
IPv6/IPv4 local address
Definition: net_ip.h:493
Socket address struct for IPv6.
Definition: net_ip.h:178
uint8_t sin6_scope_id
Interfaces for a scope.
Definition: net_ip.h:182
struct in6_addr sin6_addr
IPv6 address
Definition: net_ip.h:181
uint16_t sin6_port
Port number
Definition: net_ip.h:180
sa_family_t sin6_family
AF_INET6
Definition: net_ip.h:179
Socket address struct for IPv4.
Definition: net_ip.h:186
uint16_t sin_port
Port number
Definition: net_ip.h:188
struct in_addr sin_addr
IPv4 address.
Definition: net_ip.h:189
sa_family_t sin_family
AF_INET
Definition: net_ip.h:187
Socket address struct for packet socket.
Definition: net_ip.h:193
uint8_t sll_pkttype
Packet type
Definition: net_ip.h:198
uint16_t sll_hatype
ARP hardware type
Definition: net_ip.h:197
sa_family_t sll_family
Always AF_PACKET
Definition: net_ip.h:194
uint16_t sll_protocol
Physical-layer protocol
Definition: net_ip.h:195
int sll_ifindex
Interface number
Definition: net_ip.h:196
uint8_t sll_halen
Length of address
Definition: net_ip.h:199
uint8_t sll_addr[8]
Physical-layer address, big endian.
Definition: net_ip.h:200
Generic sockaddr struct.
Definition: net_ip.h:385
sa_family_t sa_family
Address family.
Definition: net_ip.h:386
Byte order helpers.
Macros to abstract toolchain specific capabilities.
Misc utilities.