Zephyr Project API 4.5.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_ip.h
Go to the documentation of this file.
1
6
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
24
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
42
43/* Protocol families. */
44#define NET_PF_UNSPEC 0
45#define NET_PF_INET 1
46#define NET_PF_INET6 2
47#define NET_PF_PACKET 3
48#define NET_PF_CAN 4
49#define NET_PF_NET_MGMT 5
50#define NET_PF_LOCAL 6
51#define NET_PF_UNIX NET_PF_LOCAL
52
53/* Address families. */
54#define NET_AF_UNSPEC NET_PF_UNSPEC
55#define NET_AF_INET NET_PF_INET
56#define NET_AF_INET6 NET_PF_INET6
57#define NET_AF_PACKET NET_PF_PACKET
58#define NET_AF_CAN NET_PF_CAN
59#define NET_AF_NET_MGMT NET_PF_NET_MGMT
60#define NET_AF_LOCAL NET_PF_LOCAL
61#define NET_AF_UNIX NET_PF_UNIX
62
76
87
94
101#define net_ntohs(x) sys_be16_to_cpu(x)
102
109#define net_ntohl(x) sys_be32_to_cpu(x)
110
117#define net_ntohll(x) sys_be64_to_cpu(x)
118
125#define net_htons(x) sys_cpu_to_be16(x)
126
133#define net_htonl(x) sys_cpu_to_be32(x)
134
141#define net_htonll(x) sys_cpu_to_be64(x)
142
145 union {
149 };
150};
151
153#define NET_IPV6_ADDR_SIZE 16
154
164
166#define NET_IPV4_ADDR_SIZE 4
167
169typedef unsigned short int net_sa_family_t;
170
173
174/*
175 * Note that the sin_port and sin6_port are in network byte order
176 * in various net_sockaddr* structs.
177 */
178
186
193
204
210
244
246
248struct net_sockaddr_in6_ptr {
249 net_sa_family_t sin6_family;
250 uint16_t sin6_port;
251 struct net_in6_addr *sin6_addr;
252 uint8_t sin6_scope_id;
253};
254
256struct net_sockaddr_in_ptr {
257 net_sa_family_t sin_family;
258 uint16_t sin_port;
259 struct net_in_addr *sin_addr;
260};
261
263struct net_sockaddr_ll_ptr {
264 net_sa_family_t sll_family;
265 uint16_t sll_protocol;
266 int sll_ifindex;
267 uint16_t sll_hatype;
268 uint8_t sll_pkttype;
269 uint8_t sll_halen;
270 uint8_t *sll_addr;
271};
272
274struct net_sockaddr_un_ptr {
275 net_sa_family_t sun_family;
276 char *sun_path;
277};
278
279struct net_sockaddr_can_ptr {
280 net_sa_family_t can_family;
281 int can_ifindex;
282};
283
285
286#if !defined(HAVE_IOVEC)
288struct net_iovec {
289 void *iov_base;
290 size_t iov_len;
291};
292#endif
293
304
312
317};
318
320
321/* Alignment for headers and data. These are arch specific but define
322 * them here atm if not found already.
323 */
324#if !defined(NET_ALIGN_H)
325#define NET_ALIGN_H(x) ROUND_UP(x, __alignof__(struct net_cmsghdr))
326#endif
327#if !defined(NET_ALIGN_D)
328#define NET_ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
329#endif
330
332
333#if !defined(NET_CMSG_FIRSTHDR)
339#define NET_CMSG_FIRSTHDR(msghdr) \
340 ((msghdr)->msg_controllen >= sizeof(struct net_cmsghdr) ? \
341 (struct net_cmsghdr *)((msghdr)->msg_control) : NULL)
342#endif
343
344#if !defined(NET_CMSG_NXTHDR)
352#define NET_CMSG_NXTHDR(msghdr, cmsg) \
353 (((cmsg) == NULL) ? NET_CMSG_FIRSTHDR(msghdr) : \
354 (((cmsg)->cmsg_len < sizeof(struct net_cmsghdr) || \
355 (cmsg)->cmsg_len > (size_t)((uint8_t *)((msghdr)->msg_control) + \
356 (msghdr)->msg_controllen - \
357 (uint8_t *)(cmsg)) || \
358 (uint8_t *)(cmsg) + NET_ALIGN_H((cmsg)->cmsg_len) + \
359 NET_ALIGN_D(sizeof(struct net_cmsghdr)) > \
360 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
361 NULL : \
362 (struct net_cmsghdr *)((uint8_t *)(cmsg) + \
363 NET_ALIGN_H((cmsg)->cmsg_len))))
364#endif
365
366#if !defined(NET_CMSG_DATA)
374#define NET_CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + NET_ALIGN_D(sizeof(struct net_cmsghdr)))
375#endif
376
377#if !defined(NET_CMSG_SPACE)
382#define NET_CMSG_SPACE(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + NET_ALIGN_H(length))
383#endif
384
385#if !defined(NET_CMSG_LEN)
391#define NET_CMSG_LEN(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + length)
392#endif
393
395
396/* Packet types. */
397#define NET_PACKET_HOST 0 /* To us */
398#define NET_PACKET_BROADCAST 1 /* To all */
399#define NET_PACKET_MULTICAST 2 /* To group */
400#define NET_PACKET_OTHERHOST 3 /* To someone else */
401#define NET_PACKET_OUTGOING 4 /* Originated by us */
402#define NET_PACKET_LOOPBACK 5
403#define NET_PACKET_FASTROUTE 6
404
405/* ARP protocol HARDWARE identifiers. */
406#define NET_ARPHRD_ETHER 1
407#define NET_ARPHRD_PPP 512
408
409/* Note: These macros are defined in a specific order.
410 * The largest sockaddr size is the last one.
411 */
412#if defined(CONFIG_NET_IPV4)
413#undef NET_SOCKADDR_MAX_SIZE
414#undef NET_SOCKADDR_PTR_MAX_SIZE
415#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in))
416#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in_ptr))
417#endif
418
419#if defined(CONFIG_NET_SOCKETS_PACKET)
420#undef NET_SOCKADDR_MAX_SIZE
421#undef NET_SOCKADDR_PTR_MAX_SIZE
422#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_ll))
423#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_ll_ptr))
424#endif
425
426#if defined(CONFIG_NET_IPV6)
427#undef NET_SOCKADDR_MAX_SIZE
428#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in6))
429#if !defined(CONFIG_NET_SOCKETS_PACKET)
430#undef NET_SOCKADDR_PTR_MAX_SIZE
431#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in6_ptr))
432#endif
433#endif
434
435#if defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
436#define UNIX_PATH_MAX 108
437#undef NET_SOCKADDR_MAX_SIZE
438/* Define NET_SOCKADDR_MAX_SIZE to be struct of net_sa_family_t + char[UNIX_PATH_MAX] */
439#define NET_SOCKADDR_MAX_SIZE (UNIX_PATH_MAX+sizeof(net_sa_family_t))
440#if !defined(CONFIG_NET_SOCKETS_PACKET)
441#undef NET_SOCKADDR_PTR_MAX_SIZE
442#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_un_ptr))
443#endif
444#endif
445
446#if !defined(CONFIG_NET_IPV4)
447#if !defined(CONFIG_NET_IPV6)
448#if !defined(CONFIG_NET_SOCKETS_PACKET)
449#if !defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
450#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in6))
451#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in6_ptr))
452#endif
453#endif
454#endif
455#endif
456
458
459#define SOCKADDR_ALIGN (4)
460
465 char data[NET_SOCKADDR_MAX_SIZE - sizeof(net_sa_family_t)];
467} __aligned(SOCKADDR_ALIGN);
468
470
471struct net_sockaddr_ptr {
472 net_sa_family_t family;
473 char data[NET_SOCKADDR_PTR_MAX_SIZE - sizeof(net_sa_family_t)];
474} __aligned(SOCKADDR_ALIGN);
475
476/* Same as sockaddr in our case */
477struct net_sockaddr_storage {
478 net_sa_family_t ss_family;
479 char data[NET_SOCKADDR_MAX_SIZE - sizeof(net_sa_family_t)];
480} __aligned(SOCKADDR_ALIGN);
481
482/* Socket address struct for UNIX domain sockets */
483struct net_sockaddr_un {
484 net_sa_family_t sun_family; /* NET_AF_UNIX */
485 char sun_path[NET_SOCKADDR_MAX_SIZE - sizeof(net_sa_family_t)];
486};
487
488struct net_addr {
489 net_sa_family_t family;
490 union {
491#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
492 struct net_in6_addr net_in6_addr;
493 struct net_in_addr net_in_addr;
494#else
495 struct net_in6_addr in6_addr;
496 struct net_in_addr in_addr;
497#endif
498 };
499};
500
502extern const struct net_in6_addr net_in6addr_any;
503
505extern const struct net_in6_addr net_in6addr_loopback;
506
508
510#define NET_IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
511 0, 0, 0, 0, 0, 0, 0, 0 } } }
512
514#define NET_IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
515 0, 0, 0, 0, 0, 0, 0, 1 } } }
516
518#define NET_INADDR_ANY 0
519
521#define NET_INADDR_BROADCAST 0xffffffff
522
524#define NET_INADDR_ANY_INIT { { { NET_INADDR_ANY } } }
525
527#define NET_INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
528
530#define NET_INET_ADDRSTRLEN 16
531
535#define NET_INET6_ADDRSTRLEN 46
536
538
539/* These are for internal usage of the stack */
540#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxx.xxx.xxx.xxx")
541#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
542
544
550#if defined(CONFIG_NET_NATIVE_IPV6)
551 NET_IPV6_MTU = CONFIG_NET_IPV6_MTU,
552#else
554#endif
555
559#if defined(CONFIG_NET_NATIVE_IPV4)
560 NET_IPV4_MTU = CONFIG_NET_IPV4_MTU,
561#else
563#endif
564};
565
577
578#define NET_MAX_PRIORITIES 8
579
588
596
610
612
613struct net_ipv6_hdr {
614 uint8_t vtc;
615 uint8_t tcflow;
616 uint16_t flow;
617 uint16_t len;
618 uint8_t nexthdr;
619 uint8_t hop_limit;
622} __packed;
623
624struct net_ipv6_frag_hdr {
625 uint8_t nexthdr;
626 uint8_t reserved;
627 uint16_t offset;
628 uint32_t id;
629} __packed;
630
631struct net_ipv4_hdr {
632 uint8_t vhl;
633 uint8_t tos;
634 uint16_t len;
635 uint8_t id[2];
636 uint8_t offset[2];
637 uint8_t ttl;
638 uint8_t proto;
639 uint16_t chksum;
642} __packed;
643
644struct net_icmp_hdr {
645 uint8_t type;
646 uint8_t code;
647 uint16_t chksum;
648} __packed;
649
650struct net_udp_hdr {
651 uint16_t src_port;
652 uint16_t dst_port;
653 uint16_t len;
654 uint16_t chksum;
655} __packed;
656
662struct net_udp_opt_mrds {
664 uint16_t size;
666 uint8_t segs;
667};
668
673struct net_udp_opt_time {
675 uint32_t tsval;
677 uint32_t tsecr;
678};
679
680struct net_tcp_hdr {
681 uint16_t src_port;
682 uint16_t dst_port;
683 uint8_t seq[4];
684 uint8_t ack[4];
685 uint8_t offset;
687 uint8_t wnd[2];
688 uint16_t chksum;
689 uint8_t urg[2];
690 uint8_t optdata[0];
691} __packed;
692
693static inline const char *net_addr_type2str(enum net_addr_type type)
694{
695 switch (type) {
697 return "AUTO";
698 case NET_ADDR_DHCP:
699 return "DHCP";
700 case NET_ADDR_MANUAL:
701 return "MANUAL";
703 return "OVERRIDE";
704 case NET_ADDR_ANY:
705 default:
706 break;
707 }
708
709 return "<unknown>";
710}
711
712/* IPv6 extension headers types */
713#define NET_IPV6_NEXTHDR_HBHO 0
714#define NET_IPV6_NEXTHDR_DESTO 60
715#define NET_IPV6_NEXTHDR_ROUTING 43
716#define NET_IPV6_NEXTHDR_FRAG 44
717#define NET_IPV6_NEXTHDR_NONE 59
718
723union net_ip_header {
724 struct net_ipv4_hdr *ipv4;
725 struct net_ipv6_hdr *ipv6;
726};
727
728union net_proto_header {
729 struct net_udp_hdr *udp;
730 struct net_tcp_hdr *tcp;
731};
732
733#define NET_UDPH_LEN 8 /* Size of UDP header */
734#define NET_TCPH_LEN 20 /* Size of TCP header */
735#define NET_ICMPH_LEN 4 /* Size of ICMP header */
736
737#define NET_IPV6H_LEN 40 /* Size of IPv6 header */
738#define NET_ICMPV6H_LEN NET_ICMPH_LEN /* Size of ICMPv6 header */
739#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN) /* IPv6 + UDP */
740#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN) /* IPv6 + TCP */
741#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN) /* ICMPv6 + IPv6 */
742#define NET_IPV6_FRAGH_LEN 8
743
744#define NET_IPV4H_LEN 20 /* Size of IPv4 header */
745#define NET_ICMPV4H_LEN NET_ICMPH_LEN /* Size of ICMPv4 header */
746#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN) /* IPv4 + UDP */
747#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN) /* IPv4 + TCP */
748#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN) /* ICMPv4 + IPv4 */
749
750#define NET_IPV6H_LENGTH_OFFSET 0x04 /* Offset of the Length field in the IPv6 header */
751
752#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8 /* Mask for the 13-bit Fragment Offset field */
753#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff /* Mask for the 13-bit Fragment Offset field */
754#define NET_IPV4_MORE_FRAG_MASK 0x2000 /* Mask for the 1-bit More Fragments field */
755#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000 /* Mask for the 1-bit Do Not Fragment field */
756
758#if defined(CONFIG_NET_INTERFACE_NAME)
759#define NET_IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
760#else
761#if defined(Z_DEVICE_MAX_NAME_LEN)
762#define NET_IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
763#else
764#define NET_IFNAMSIZ 1
765#endif /* Z_DEVICE_MAX_NAME_LEN */
766#endif /* CONFIG_NET_INTERFACE_NAME */
767
769
774
776struct net_ifreq {
777 char ifr_name[NET_IFNAMSIZ];
778};
779
780
792
801
809
820
837
841#define NET_PACKET_MR_MULTICAST 0
842#define NET_PACKET_MR_PROMISC 1
843#define NET_PACKET_MR_ALLMULTI 2
844
853 unsigned int ipi6_ifindex;
854};
855
857static inline bool net_ipv6_is_addr_loopback_raw(const uint8_t *addr)
858{
859 return UNALIGNED_GET((uint32_t *)addr) == 0 &&
860 UNALIGNED_GET((uint32_t *)addr + 1) == 0 &&
861 UNALIGNED_GET((uint32_t *)addr + 2) == 0 &&
862 net_ntohl(UNALIGNED_GET((uint32_t *)addr + 3)) == 1;
863}
865
873static inline bool net_ipv6_is_addr_loopback(const struct net_in6_addr *addr)
874{
875 return net_ipv6_is_addr_loopback_raw(addr->s6_addr);
876}
877
879static inline bool net_ipv6_is_addr_mcast_raw(const uint8_t *addr)
880{
881 return addr[0] == 0xff;
882}
884
892static inline bool net_ipv6_is_addr_mcast(const struct net_in6_addr *addr)
893{
894 return net_ipv6_is_addr_mcast_raw(addr->s6_addr);
895}
896
897struct net_if;
898struct net_if_config;
899
901extern struct net_if_addr *net_if_ipv6_addr_lookup_raw(const uint8_t *addr,
902 struct net_if **ret);
903
904static inline bool net_ipv6_is_my_addr_raw(const uint8_t *addr)
905{
906 return net_if_ipv6_addr_lookup_raw(addr, NULL) != NULL;
907}
909
910extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct net_in6_addr *addr,
911 struct net_if **iface);
912
920static inline bool net_ipv6_is_my_addr(struct net_in6_addr *addr)
921{
922 return net_if_ipv6_addr_lookup(addr, NULL) != NULL;
923}
924
926 const struct net_in6_addr *addr, struct net_if **iface);
927
936static inline bool net_ipv6_is_my_maddr(struct net_in6_addr *maddr)
937{
938 return net_if_ipv6_maddr_lookup(maddr, NULL) != NULL;
939}
940
950static inline bool net_ipv6_is_prefix(const uint8_t *addr1,
951 const uint8_t *addr2,
952 uint8_t length)
953{
954 uint8_t bits = 128 - length;
955 uint8_t bytes = length / 8U;
956 uint8_t remain = bits % 8;
957 uint8_t mask;
958
959 if (length > 128) {
960 return false;
961 }
962
963 if (memcmp(addr1, addr2, bytes)) {
964 return false;
965 }
966
967 if (!remain) {
968 /* No remaining bits, the prefixes are the same as first
969 * bytes are the same.
970 */
971 return true;
972 }
973
974 /* Create a mask that has remaining most significant bits set */
975 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
976
977 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
978}
979
980
988static inline void net_ipv6_addr_prefix_mask(const uint8_t *inaddr,
989 uint8_t *outaddr,
990 uint8_t prefix_len)
991{
992 uint8_t bits = 128 - prefix_len;
993 uint8_t bytes = prefix_len / 8U;
994 uint8_t remain = bits % 8;
995 uint8_t mask;
996
997 memset(outaddr, 0, 16U);
998 memcpy(outaddr, inaddr, bytes);
999
1000 if (!remain) {
1001 /* No remaining bits, the prefixes are the same as first
1002 * bytes are the same.
1003 */
1004 return;
1005 }
1006
1007 /* Create a mask that has remaining most significant bits set */
1008 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
1009 outaddr[bytes] = inaddr[bytes] & mask;
1010}
1011
1013static inline bool net_ipv4_is_addr_loopback_raw(const uint8_t *addr)
1014{
1015 return addr[0] == 127U;
1016}
1018
1026static inline bool net_ipv4_is_addr_loopback(const struct net_in_addr *addr)
1027{
1028 return net_ipv4_is_addr_loopback_raw(addr->s4_addr);
1029}
1030
1032static inline bool net_ipv4_is_addr_unspecified_raw(const uint8_t *addr)
1033{
1034 return UNALIGNED_GET((uint32_t *)addr) == 0;
1035}
1037
1045static inline bool net_ipv4_is_addr_unspecified(const struct net_in_addr *addr)
1046{
1047 return net_ipv4_is_addr_unspecified_raw(addr->s4_addr);
1048}
1049
1051static inline bool net_ipv4_is_addr_mcast_raw(const uint8_t *addr)
1052{
1053 return (net_ntohl(UNALIGNED_GET((uint32_t *)addr)) & 0xF0000000) == 0xE0000000;
1054}
1056
1064static inline bool net_ipv4_is_addr_mcast(const struct net_in_addr *addr)
1065{
1066 return net_ipv4_is_addr_mcast_raw(addr->s4_addr);
1067}
1068
1070static inline bool net_ipv4_is_ll_addr_raw(const uint8_t *addr)
1071{
1072 return (net_ntohl(UNALIGNED_GET((uint32_t *)addr)) & 0xFFFF0000) == 0xA9FE0000;
1073}
1075
1083static inline bool net_ipv4_is_ll_addr(const struct net_in_addr *addr)
1084{
1085 return net_ipv4_is_ll_addr_raw(addr->s4_addr);
1086}
1087
1097static inline bool net_ipv4_is_private_addr(const struct net_in_addr *addr)
1098{
1099 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
1100
1101 masked_24 = net_ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFFFF00;
1102 masked_16 = masked_24 & 0xFFFF0000;
1103 masked_12 = masked_24 & 0xFFF00000;
1104 masked_10 = masked_24 & 0xFFC00000;
1105 masked_8 = masked_24 & 0xFF000000;
1106
1107 return masked_8 == 0x0A000000 || /* 10.0.0.0/8 */
1108 masked_10 == 0x64400000 || /* 100.64.0.0/10 */
1109 masked_12 == 0xAC100000 || /* 172.16.0.0/12 */
1110 masked_16 == 0xC0A80000 || /* 192.168.0.0/16 */
1111 masked_24 == 0xC0000200 || /* 192.0.2.0/24 */
1112 masked_24 == 0xC0336400 || /* 192.51.100.0/24 */
1113 masked_24 == 0xCB007100; /* 203.0.113.0/24 */
1114}
1115
1124#define net_ipaddr_copy(dest, src) \
1125 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
1126
1133static inline void net_ipv4_addr_copy_raw(uint8_t *dest,
1134 const uint8_t *src)
1135{
1136 net_ipaddr_copy((struct net_in_addr *)dest, (const struct net_in_addr *)src);
1137}
1138
1145static inline void net_ipv6_addr_copy_raw(uint8_t *dest,
1146 const uint8_t *src)
1147{
1148 memcpy(dest, src, sizeof(struct net_in6_addr));
1149}
1150
1159static inline bool net_ipv4_addr_cmp_raw(const uint8_t *addr1,
1160 const uint8_t *addr2)
1161{
1162 return UNALIGNED_GET((uint32_t *)addr1) == UNALIGNED_GET((uint32_t *)addr2);
1163}
1164
1173static inline bool net_ipv4_addr_cmp(const struct net_in_addr *addr1,
1174 const struct net_in_addr *addr2)
1175{
1176 return net_ipv4_addr_cmp_raw(addr1->s4_addr, addr2->s4_addr);
1177}
1178
1187static inline bool net_ipv6_addr_cmp(const struct net_in6_addr *addr1,
1188 const struct net_in6_addr *addr2)
1189{
1190 return !memcmp(addr1, addr2, sizeof(struct net_in6_addr));
1191}
1192
1201static inline bool net_ipv6_addr_cmp_raw(const uint8_t *addr1,
1202 const uint8_t *addr2)
1203{
1204 return net_ipv6_addr_cmp((const struct net_in6_addr *)addr1,
1205 (const struct net_in6_addr *)addr2);
1206}
1207
1209static inline bool net_ipv6_is_ll_addr_raw(const uint8_t *addr)
1210{
1211 return UNALIGNED_GET((uint16_t *)addr) == net_htons(0xFE80);
1212}
1214
1222static inline bool net_ipv6_is_ll_addr(const struct net_in6_addr *addr)
1223{
1224 return net_ipv6_is_ll_addr_raw(addr->s6_addr);
1225}
1226
1234static inline bool net_ipv6_is_sl_addr(const struct net_in6_addr *addr)
1235{
1236 return UNALIGNED_GET(&addr->s6_addr16[0]) == net_htons(0xFEC0);
1237}
1238
1239
1247static inline bool net_ipv6_is_ula_addr(const struct net_in6_addr *addr)
1248{
1249 return addr->s6_addr[0] == 0xFD;
1250}
1251
1259static inline bool net_ipv6_is_global_addr(const struct net_in6_addr *addr)
1260{
1261 return (addr->s6_addr[0] & 0xE0) == 0x20;
1262}
1263
1273static inline bool net_ipv6_is_private_addr(const struct net_in6_addr *addr)
1274{
1275 uint32_t masked_32, masked_7;
1276
1277 masked_32 = net_ntohl(UNALIGNED_GET(&addr->s6_addr32[0]));
1278 masked_7 = masked_32 & 0xfc000000;
1279
1280 return masked_32 == 0x20010db8 || /* 2001:db8::/32 */
1281 masked_7 == 0xfc000000; /* fc00::/7 */
1282}
1283
1290
1297
1304
1305struct net_if;
1306extern bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
1307 const struct net_in_addr *addr);
1308
1318static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
1319 const struct net_in_addr *addr)
1320{
1321 return net_if_ipv4_addr_mask_cmp(iface, addr);
1322}
1323
1325extern bool net_if_ipv4_is_addr_bcast_raw(struct net_if *iface,
1326 const uint8_t *addr);
1327
1328#if defined(CONFIG_NET_NATIVE_IPV4)
1329static inline bool net_ipv4_is_addr_bcast_raw(struct net_if *iface,
1330 const uint8_t *addr)
1331{
1332 if (net_ipv4_addr_cmp_raw(addr, net_ipv4_broadcast_address()->s4_addr)) {
1333 return true;
1334 }
1335
1336 return net_if_ipv4_is_addr_bcast_raw(iface, addr);
1337}
1338#else
1339static inline bool net_ipv4_is_addr_bcast_raw(struct net_if *iface,
1340 const uint8_t *addr)
1341{
1342 ARG_UNUSED(iface);
1343 ARG_UNUSED(addr);
1344
1345 return false;
1346}
1347#endif
1349
1350extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
1351 const struct net_in_addr *addr);
1352
1361#if defined(CONFIG_NET_NATIVE_IPV4)
1362static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1363 const struct net_in_addr *addr)
1364{
1366 return true;
1367 }
1368
1369 return net_if_ipv4_is_addr_bcast(iface, addr);
1370}
1371#else
1372static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1373 const struct net_in_addr *addr)
1374{
1375 ARG_UNUSED(iface);
1376 ARG_UNUSED(addr);
1377
1378 return false;
1379}
1380#endif
1381
1383extern struct net_if_addr *net_if_ipv4_addr_lookup_raw(const uint8_t *addr,
1384 struct net_if **ret);
1385
1386static inline bool net_ipv4_is_my_addr_raw(const uint8_t *addr)
1387{
1388 bool ret;
1389
1390 ret = net_if_ipv4_addr_lookup_raw(addr, NULL) != NULL;
1391 if (!ret) {
1392 ret = net_ipv4_is_addr_bcast_raw(NULL, addr);
1393 }
1394
1395 return ret;
1396}
1398
1399extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct net_in_addr *addr,
1400 struct net_if **iface);
1401
1411static inline bool net_ipv4_is_my_addr(const struct net_in_addr *addr)
1412{
1413 bool ret;
1414
1415 ret = net_if_ipv4_addr_lookup(addr, NULL) != NULL;
1416 if (!ret) {
1417 ret = net_ipv4_is_addr_bcast(NULL, addr);
1418 }
1419
1420 return ret;
1421}
1422
1424static inline bool net_ipv6_is_addr_unspecified_raw(const uint8_t *addr)
1425{
1426 return UNALIGNED_GET((uint32_t *)addr) == 0 &&
1427 UNALIGNED_GET((uint32_t *)addr + 1) == 0 &&
1428 UNALIGNED_GET((uint32_t *)addr + 2) == 0 &&
1429 UNALIGNED_GET((uint32_t *)addr + 3) == 0;
1430}
1432
1440static inline bool net_ipv6_is_addr_unspecified(const struct net_in6_addr *addr)
1441{
1442 return net_ipv6_is_addr_unspecified_raw(addr->s6_addr);
1443}
1444
1446static inline bool net_ipv6_is_addr_solicited_node_raw(const uint8_t *addr)
1447{
1448 return UNALIGNED_GET((uint32_t *)addr) == net_htonl(0xff020000) &&
1449 UNALIGNED_GET((uint32_t *)addr + 1) == 0x00000000 &&
1450 UNALIGNED_GET((uint32_t *)addr + 2) == net_htonl(0x00000001) &&
1451 ((UNALIGNED_GET((uint32_t *)addr + 3) & net_htonl(0xff000000)) ==
1452 net_htonl(0xff000000));
1453}
1455
1464static inline bool net_ipv6_is_addr_solicited_node(const struct net_in6_addr *addr)
1465{
1466 return net_ipv6_is_addr_solicited_node_raw(addr->s6_addr);
1467}
1468
1470static inline bool net_ipv6_is_addr_mcast_scope_raw(const uint8_t *addr,
1471 int scope)
1472{
1473 return (addr[0] == 0xff) && ((addr[1] & 0xF) == scope);
1474}
1476
1478static inline int net_ipv6_get_addr_mcast_scope_raw(const uint8_t *addr)
1479{
1480 if (addr[0] == 0xff) {
1481 return (addr[1] & 0xF);
1482 }
1483
1484 return -1;
1485}
1487
1498static inline bool net_ipv6_is_addr_mcast_scope(const struct net_in6_addr *addr,
1499 int scope)
1500{
1501 return net_ipv6_is_addr_mcast_scope_raw(addr->s6_addr, scope);
1502}
1503
1513static inline bool net_ipv6_is_same_mcast_scope(const struct net_in6_addr *addr_1,
1514 const struct net_in6_addr *addr_2)
1515{
1516 return (addr_1->s6_addr[0] == 0xff) && (addr_2->s6_addr[0] == 0xff) &&
1517 (addr_1->s6_addr[1] == addr_2->s6_addr[1]);
1518}
1519
1527static inline int net_ipv6_get_addr_mcast_scope(const struct net_in6_addr *addr)
1528{
1529 return net_ipv6_get_addr_mcast_scope_raw(addr->s6_addr);
1530}
1531
1533static inline bool net_ipv6_is_addr_mcast_iface_raw(const uint8_t *addr)
1534{
1535 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x01);
1536}
1537
1538static inline bool net_ipv6_is_addr_mcast_link_raw(const uint8_t *addr)
1539{
1540 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x02);
1541}
1542
1543static inline bool net_ipv6_is_addr_mcast_mesh_raw(const uint8_t *addr)
1544{
1545 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x03);
1546}
1547
1548static inline bool net_ipv6_is_addr_mcast_site_raw(const uint8_t *addr)
1549{
1550 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x05);
1551}
1552
1553static inline bool net_ipv6_is_addr_mcast_org_raw(const uint8_t *addr)
1554{
1555 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x08);
1556}
1558
1566static inline bool net_ipv6_is_addr_mcast_global(const struct net_in6_addr *addr)
1567{
1568 return net_ipv6_is_addr_mcast_scope(addr, 0x0e);
1569}
1570
1580static inline bool net_ipv6_is_addr_mcast_iface(const struct net_in6_addr *addr)
1581{
1582 return net_ipv6_is_addr_mcast_scope(addr, 0x01);
1583}
1584
1594static inline bool net_ipv6_is_addr_mcast_link(const struct net_in6_addr *addr)
1595{
1596 return net_ipv6_is_addr_mcast_scope(addr, 0x02);
1597}
1598
1608static inline bool net_ipv6_is_addr_mcast_mesh(const struct net_in6_addr *addr)
1609{
1610 return net_ipv6_is_addr_mcast_scope(addr, 0x03);
1611}
1612
1622static inline bool net_ipv6_is_addr_mcast_site(const struct net_in6_addr *addr)
1623{
1624 return net_ipv6_is_addr_mcast_scope(addr, 0x05);
1625}
1626
1636static inline bool net_ipv6_is_addr_mcast_org(const struct net_in6_addr *addr)
1637{
1638 return net_ipv6_is_addr_mcast_scope(addr, 0x08);
1639}
1640
1642static inline bool net_ipv6_is_addr_mcast_group_raw(const uint8_t *addr,
1643 const uint8_t *group)
1644{
1645 return UNALIGNED_GET((uint16_t *)addr + 1) == UNALIGNED_GET((uint16_t *)group + 1) &&
1646 UNALIGNED_GET((uint32_t *)addr + 1) == UNALIGNED_GET((uint32_t *)group + 1) &&
1647 UNALIGNED_GET((uint32_t *)addr + 2) == UNALIGNED_GET((uint32_t *)group + 2) &&
1648 UNALIGNED_GET((uint32_t *)addr + 3) == UNALIGNED_GET((uint32_t *)group + 3);
1649}
1651
1662static inline bool net_ipv6_is_addr_mcast_group(const struct net_in6_addr *addr,
1663 const struct net_in6_addr *group)
1664{
1665 return net_ipv6_is_addr_mcast_group_raw(addr->s6_addr, group->s6_addr);
1666}
1667
1669static inline bool net_ipv6_is_addr_mcast_all_nodes_group_raw(const uint8_t *addr)
1670{
1671 static const uint8_t all_nodes_mcast_group[NET_IPV6_ADDR_SIZE] = {
1672 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1673 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1674 };
1675
1676 return net_ipv6_is_addr_mcast_group_raw(addr, all_nodes_mcast_group);
1677}
1679
1688static inline bool
1690{
1691 return net_ipv6_is_addr_mcast_all_nodes_group_raw(addr->s6_addr);
1692}
1693
1703static inline bool
1709
1711static inline bool net_ipv6_is_addr_mcast_link_all_nodes_raw(const uint8_t *addr)
1712{
1713 return net_ipv6_is_addr_mcast_link_raw(addr) &&
1714 net_ipv6_is_addr_mcast_all_nodes_group_raw(addr);
1715}
1717
1727static inline bool
1733
1741static inline
1743 struct net_in6_addr *dst)
1744{
1745 dst->s6_addr[0] = 0xFF;
1746 dst->s6_addr[1] = 0x02;
1747 UNALIGNED_PUT(0, &dst->s6_addr16[1]);
1748 UNALIGNED_PUT(0, &dst->s6_addr16[2]);
1749 UNALIGNED_PUT(0, &dst->s6_addr16[3]);
1750 UNALIGNED_PUT(0, &dst->s6_addr16[4]);
1751 dst->s6_addr[10] = 0U;
1752 dst->s6_addr[11] = 0x01;
1753 dst->s6_addr[12] = 0xFF;
1754 dst->s6_addr[13] = src->s6_addr[13];
1755 UNALIGNED_PUT(UNALIGNED_GET(&src->s6_addr16[7]), &dst->s6_addr16[7]);
1756}
1757
1770static inline void net_ipv6_addr_create(struct net_in6_addr *addr,
1771 uint16_t addr0, uint16_t addr1,
1772 uint16_t addr2, uint16_t addr3,
1773 uint16_t addr4, uint16_t addr5,
1774 uint16_t addr6, uint16_t addr7)
1775{
1776 UNALIGNED_PUT(net_htons(addr0), &addr->s6_addr16[0]);
1777 UNALIGNED_PUT(net_htons(addr1), &addr->s6_addr16[1]);
1778 UNALIGNED_PUT(net_htons(addr2), &addr->s6_addr16[2]);
1779 UNALIGNED_PUT(net_htons(addr3), &addr->s6_addr16[3]);
1780 UNALIGNED_PUT(net_htons(addr4), &addr->s6_addr16[4]);
1781 UNALIGNED_PUT(net_htons(addr5), &addr->s6_addr16[5]);
1782 UNALIGNED_PUT(net_htons(addr6), &addr->s6_addr16[6]);
1783 UNALIGNED_PUT(net_htons(addr7), &addr->s6_addr16[7]);
1784}
1785
1792{
1793 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
1794}
1795
1802{
1803 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002);
1804}
1805
1812static inline void net_ipv6_addr_create_v4_mapped(const struct net_in_addr *addr4,
1813 struct net_in6_addr *addr6)
1814{
1815 net_ipv6_addr_create(addr6, 0, 0, 0, 0, 0, 0xffff,
1816 net_ntohs(addr4->s4_addr16[0]),
1817 net_ntohs(addr4->s4_addr16[1]));
1818}
1819
1828static inline bool net_ipv6_addr_is_v4_mapped(const struct net_in6_addr *addr)
1829{
1830 if (UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1831 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1832 UNALIGNED_GET(&addr->s6_addr16[5]) == 0xffff) {
1833 return true;
1834 }
1835
1836 return false;
1837}
1838
1847static inline void net_ipv6_addr_get_v4_mapped(const struct net_in6_addr *addr6,
1848 struct net_in_addr *addr4)
1849{
1850 addr4->s_addr = UNALIGNED_GET(&addr6->s6_addr32[3]);
1851}
1852
1872 const struct net_in6_addr *prefix,
1873 uint8_t *network_id, size_t network_id_len,
1874 uint8_t dad_counter,
1875 struct net_in6_addr *addr,
1876 struct net_linkaddr *lladdr);
1877
1884static inline void net_ipv6_addr_create_iid(struct net_in6_addr *addr,
1885 struct net_linkaddr *lladdr)
1886{
1887 (void)net_ipv6_addr_generate_iid(NULL, NULL, NULL, 0, 0, addr, lladdr);
1888}
1889
1891static inline bool net_ipv6_addr_based_on_ll_raw(const uint8_t *addr,
1892 const struct net_linkaddr *lladdr)
1893{
1894 if (addr == NULL || lladdr == NULL) {
1895 return false;
1896 }
1897
1898 switch (lladdr->len) {
1899 case 2:
1900 if (!memcmp(&addr[14], lladdr->addr, lladdr->len) &&
1901 addr[8] == 0U &&
1902 addr[9] == 0U &&
1903 addr[10] == 0U &&
1904 addr[11] == 0xff &&
1905 addr[12] == 0xfe) {
1906 return true;
1907 }
1908
1909 break;
1910 case 6:
1911 if (lladdr->type == NET_LINK_ETHERNET) {
1912 if (!memcmp(&addr[9], &lladdr->addr[1], 2) &&
1913 !memcmp(&addr[13], &lladdr->addr[3], 3) &&
1914 addr[11] == 0xff &&
1915 addr[12] == 0xfe &&
1916 (addr[8] ^ 0x02) == lladdr->addr[0]) {
1917 return true;
1918 }
1919 }
1920
1921 break;
1922 case 8:
1923 if (sizeof(lladdr->addr) < 8) {
1924 return false;
1925 }
1926
1927 if (!memcmp(&addr[9], &lladdr->addr[1],
1928 lladdr->len - 1) &&
1929 (addr[8] ^ 0x02) == lladdr->addr[0]) {
1930 return true;
1931 }
1932
1933 break;
1934 default:
1935 return false;
1936 }
1937
1938 return false;
1939}
1941
1947static inline bool net_ipv6_addr_based_on_ll(const struct net_in6_addr *addr,
1948 const struct net_linkaddr *lladdr)
1949{
1950 if (addr == NULL || lladdr == NULL) {
1951 return false;
1952 }
1953
1954 return net_ipv6_addr_based_on_ll_raw(addr->s6_addr, lladdr);
1955}
1956
1965static ALWAYS_INLINE struct net_sockaddr *net_sad(const struct net_sockaddr_storage *addr)
1966{
1967 return (struct net_sockaddr *)addr;
1968}
1969
1978static ALWAYS_INLINE struct net_sockaddr_storage *net_sas(const struct net_sockaddr *addr)
1979{
1980 return (struct net_sockaddr_storage *)addr;
1981}
1982
1991static ALWAYS_INLINE struct net_sockaddr_in6 *net_sin6(const struct net_sockaddr *addr)
1992{
1993 return (struct net_sockaddr_in6 *)addr;
1994}
1995
2004static ALWAYS_INLINE struct net_sockaddr_in *net_sin(const struct net_sockaddr *addr)
2005{
2006 return (struct net_sockaddr_in *)addr;
2007}
2008
2017static ALWAYS_INLINE
2018struct net_sockaddr_in6_ptr *net_sin6_ptr(const struct net_sockaddr_ptr *addr)
2019{
2020 return (struct net_sockaddr_in6_ptr *)addr;
2021}
2022
2031static ALWAYS_INLINE
2032struct net_sockaddr_in_ptr *net_sin_ptr(const struct net_sockaddr_ptr *addr)
2033{
2034 return (struct net_sockaddr_in_ptr *)addr;
2035}
2036
2045static ALWAYS_INLINE
2046struct net_sockaddr_ll_ptr *net_sll_ptr(const struct net_sockaddr_ptr *addr)
2047{
2048 return (struct net_sockaddr_ll_ptr *)addr;
2049}
2050
2059static ALWAYS_INLINE
2060struct net_sockaddr_can_ptr *net_can_ptr(const struct net_sockaddr_ptr *addr)
2061{
2062 return (struct net_sockaddr_can_ptr *)addr;
2063}
2064
2078__syscall int net_addr_pton(net_sa_family_t family, const char *src, void *dst);
2079
2091__syscall char *net_addr_ntop(net_sa_family_t family, const void *src,
2092 char *dst, size_t size);
2093
2105 struct net_sockaddr *mask);
2106
2118 uint8_t *mask_len);
2119
2141bool net_ipaddr_parse(const char *str, size_t str_len,
2142 struct net_sockaddr *addr);
2143
2171const char *net_ipaddr_parse_mask(const char *str, size_t str_len,
2172 struct net_sockaddr *addr, uint8_t *mask_len);
2173
2183int net_port_set_default(struct net_sockaddr *addr, uint16_t default_port);
2184
2193int net_port_set(struct net_sockaddr *addr, uint16_t port);
2194
2203int net_port_get(struct net_sockaddr *addr, uint16_t *port);
2204
2213static inline bool net_sockaddr_cmp(const struct net_sockaddr *a, const struct net_sockaddr *b)
2214{
2215 if (a->sa_family != b->sa_family) {
2216 return false;
2217 }
2218
2219 switch (a->sa_family) {
2220 case NET_AF_INET: {
2221 const struct net_sockaddr_in *a4 = net_sin(a);
2222 const struct net_sockaddr_in *b4 = net_sin(b);
2223
2224 if (a4->sin_port != b4->sin_port) {
2225 return false;
2226 }
2227
2228 return net_ipv4_addr_cmp(&a4->sin_addr, &b4->sin_addr);
2229 }
2230
2231 case NET_AF_INET6: {
2232 const struct net_sockaddr_in6 *a6 = net_sin6(a);
2233 const struct net_sockaddr_in6 *b6 = net_sin6(b);
2234
2235 if (a6->sin6_port != b6->sin6_port) {
2236 return false;
2237 }
2238
2239 return net_ipv6_addr_cmp(&a6->sin6_addr, &b6->sin6_addr);
2240 }
2241
2242 default:
2243 /* Invalid address family */
2244 return false;
2245 }
2246}
2247
2259static inline int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
2260{
2261 return (int32_t)(seq1 - seq2);
2262}
2263
2274static inline bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
2275{
2276 return net_tcp_seq_cmp(seq1, seq2) > 0;
2277}
2278
2290int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src);
2291
2301
2311
2320static inline enum net_priority net_vlan2priority(uint8_t priority)
2321{
2322 /* Map according to IEEE 802.1Q */
2323 static const uint8_t vlan2priority[] = {
2332 };
2333
2334 if (priority >= ARRAY_SIZE(vlan2priority)) {
2335 /* Use Best Effort as the default priority */
2336 return NET_PRIORITY_BE;
2337 }
2338
2339 return (enum net_priority)vlan2priority[priority];
2340}
2341
2349static inline uint8_t net_priority2vlan(enum net_priority priority)
2350{
2351 /* The conversion works both ways */
2352 return (uint8_t)net_vlan2priority(priority);
2353}
2354
2364
2372static inline size_t net_family2size(net_sa_family_t family)
2373{
2374 switch (family) {
2375 case NET_AF_INET:
2376 return sizeof(struct net_sockaddr_in);
2377 case NET_AF_INET6:
2378 return sizeof(struct net_sockaddr_in6);
2379 case NET_AF_PACKET:
2380 return sizeof(struct net_sockaddr_ll);
2381 case NET_AF_UNIX:
2382 return sizeof(struct net_sockaddr_un);
2383 case NET_AF_CAN:
2384 return sizeof(struct net_sockaddr_can);
2385 case NET_AF_NET_MGMT:
2386 return sizeof(struct net_sockaddr_nm);
2387 default:
2388 return 0;
2389 }
2390}
2391
2402#if defined(CONFIG_NET_IPV6_PE)
2403int net_ipv6_pe_add_filter(struct net_in6_addr *addr, bool is_denylist);
2404#else
2405static inline int net_ipv6_pe_add_filter(struct net_in6_addr *addr,
2406 bool is_denylist)
2407{
2408 ARG_UNUSED(addr);
2409 ARG_UNUSED(is_denylist);
2410
2411 return -ENOTSUP;
2412}
2413#endif /* CONFIG_NET_IPV6_PE */
2414
2422#if defined(CONFIG_NET_IPV6_PE)
2423int net_ipv6_pe_del_filter(struct net_in6_addr *addr);
2424#else
2425static inline int net_ipv6_pe_del_filter(struct net_in6_addr *addr)
2426{
2427 ARG_UNUSED(addr);
2428
2429 return -ENOTSUP;
2430}
2431#endif /* CONFIG_NET_IPV6_PE */
2432
2433#ifdef __cplusplus
2434}
2435#endif
2436
2437#include <zephyr/syscalls/net_ip.h>
2438
2439#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
2440#define ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
2441#include <zephyr/net/net_compat.h>
2442#undef ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
2443#endif /* CONFIG_NET_NAMESPACE_COMPAT_MODE */
2444
2448
2449#endif /* ZEPHYR_INCLUDE_NET_NET_IP_H_ */
#define NET_AF_PACKET
Packet family.
Definition net_ip.h:57
static bool net_ipv6_is_ula_addr(const struct net_in6_addr *addr)
Check if the given IPv6 address is a unique local address.
Definition net_ip.h:1247
int net_port_get(struct net_sockaddr *addr, uint16_t *port)
Get the port in the sockaddr structure.
static size_t net_family2size(net_sa_family_t family)
Return network address size for a given family.
Definition net_ip.h:2372
#define NET_IPV4_ADDR_SIZE
Binary size of the IPv4 address.
Definition net_ip.h:166
static ALWAYS_INLINE struct net_sockaddr * net_sad(const struct net_sockaddr_storage *addr)
Get net_sockaddr from net_sockaddr_storage.
Definition net_ip.h:1965
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:2320
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition net_ip.h:2259
static bool net_ipv6_is_my_maddr(struct net_in6_addr *maddr)
Check if IPv6 multicast address is found in one of the network interfaces.
Definition net_ip.h:936
const struct net_in_addr * net_ipv4_broadcast_address(void)
Return pointer to broadcast (all bits ones) IPv4 address.
#define NET_AF_CAN
Controller Area Network.
Definition net_ip.h:58
#define NET_IPV6_ADDR_SIZE
Binary size of the IPv6 address.
Definition net_ip.h:153
static bool net_ipv4_addr_cmp(const struct net_in_addr *addr1, const struct net_in_addr *addr2)
Compare two IPv4 addresses.
Definition net_ip.h:1173
#define NET_AF_NET_MGMT
Network management info.
Definition net_ip.h:59
static bool net_ipv6_addr_is_v4_mapped(const struct net_in6_addr *addr)
Is the IPv6 address an IPv4 mapped one.
Definition net_ip.h:1828
static bool net_ipv6_is_addr_unspecified(const struct net_in6_addr *addr)
Check if the IPv6 address is unspecified (all bits zero).
Definition net_ip.h:1440
static bool net_ipv6_is_addr_mcast_mesh(const struct net_in6_addr *addr)
Check if the IPv6 address is a mesh-local scope multicast address (FFx3::).
Definition net_ip.h:1608
static void net_ipv6_addr_create_v4_mapped(const struct net_in_addr *addr4, struct net_in6_addr *addr6)
Create IPv4 mapped IPv6 address.
Definition net_ip.h:1812
static bool net_ipv4_is_addr_mcast(const struct net_in_addr *addr)
Check if the IPv4 address is a multicast address.
Definition net_ip.h:1064
net_addr_state
What is the current state of the network address.
Definition net_ip.h:590
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:1159
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:172
static bool net_ipv6_is_private_addr(const struct net_in6_addr *addr)
Check if the given IPv6 address is from a private/local address range.
Definition net_ip.h:1273
static bool net_ipv4_is_addr_unspecified(const struct net_in_addr *addr)
Check if the IPv4 address is unspecified (all bits zero).
Definition net_ip.h:1045
static bool net_ipv6_is_addr_mcast(const struct net_in6_addr *addr)
Check if the IPv6 address is a multicast address.
Definition net_ip.h:892
struct net_if_addr * net_if_ipv6_addr_lookup(const struct net_in6_addr *addr, struct net_if **iface)
static bool net_ipv6_is_addr_mcast_iface(const struct net_in6_addr *addr)
Check if the IPv6 address is a interface scope multicast address (FFx1::).
Definition net_ip.h:1580
bool net_if_ipv4_is_addr_bcast(struct net_if *iface, const struct net_in_addr *addr)
int net_port_set_default(struct net_sockaddr *addr, uint16_t default_port)
Set the default port in the sockaddr structure.
#define net_ntohs(x)
Convert 16-bit value from network to host byte order.
Definition net_ip.h:101
static void net_ipv6_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv6 address raw buffer.
Definition net_ip.h:1145
static bool net_ipv4_addr_mask_cmp(struct net_if *iface, const struct net_in_addr *addr)
Check if the given address belongs to same subnet that has been configured for the interface.
Definition net_ip.h:1318
const char * net_family2str(net_sa_family_t family)
Return network address family value as a string.
static ALWAYS_INLINE struct net_sockaddr_in6 * net_sin6(const struct net_sockaddr *addr)
Get net_sockaddr_in6 from net_sockaddr.
Definition net_ip.h:1991
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:988
#define NET_AF_INET6
IP protocol family version 6.
Definition net_ip.h:56
struct net_if_addr * net_if_ipv4_addr_lookup(const struct net_in_addr *addr, struct net_if **iface)
int net_ipv6_addr_generate_iid(struct net_if *iface, const struct net_in6_addr *prefix, uint8_t *network_id, size_t network_id_len, uint8_t dad_counter, struct net_in6_addr *addr, struct net_linkaddr *lladdr)
Generate IPv6 address using a prefix and interface identifier.
#define net_htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:133
const char * net_ipaddr_parse_mask(const char *str, size_t str_len, struct net_sockaddr *addr, uint8_t *mask_len)
Parse a string that contains either IPv4 or IPv6 address and optional mask len, and store the informa...
static bool net_ipv4_is_my_addr(const struct net_in_addr *addr)
Check if the IPv4 address is assigned to any network interface in the system.
Definition net_ip.h:1411
static bool net_ipv4_is_addr_loopback(const struct net_in_addr *addr)
Check if the IPv4 address is a loopback address (127.0.0.0/8).
Definition net_ip.h:1026
int net_addr_pton(net_sa_family_t family, const char *src, void *dst)
Convert a string to IP address.
int net_mask_len_to_netmask(net_sa_family_t family, uint8_t mask_len, struct net_sockaddr *mask)
Create netmask from mask length.
static bool net_ipv4_is_ll_addr(const struct net_in_addr *addr)
Check if the given IPv4 address is a link local address.
Definition net_ip.h:1083
static bool net_ipv6_addr_cmp(const struct net_in6_addr *addr1, const struct net_in6_addr *addr2)
Compare two IPv6 addresses.
Definition net_ip.h:1187
static void net_ipv6_addr_create_ll_allnodes_mcast(struct net_in6_addr *addr)
Create link local allnodes multicast IPv6 address.
Definition net_ip.h:1791
static ALWAYS_INLINE struct net_sockaddr_in_ptr * net_sin_ptr(const struct net_sockaddr_ptr *addr)
Get net_sockaddr_in_ptr from sockaddr_ptr.
Definition net_ip.h:2032
net_ip_protocol_secure
Protocol numbers for TLS protocols.
Definition net_ip.h:78
static void net_ipv6_addr_get_v4_mapped(const struct net_in6_addr *addr6, struct net_in_addr *addr4)
Get the IPv4 address from an IPv4 mapped IPv6 address.
Definition net_ip.h:1847
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:1124
int net_port_set(struct net_sockaddr *addr, uint16_t port)
Set the port in the sockaddr structure.
static bool net_ipv6_addr_based_on_ll(const struct net_in6_addr *addr, const struct net_linkaddr *lladdr)
Check if given address is based on link layer address.
Definition net_ip.h:1947
net_ip_mtu
IP Maximum Transfer Unit.
Definition net_ip.h:546
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 int net_ipv6_get_addr_mcast_scope(const struct net_in6_addr *addr)
Returns the scope of the given IPv6 address.
Definition net_ip.h:1527
static bool net_sockaddr_cmp(const struct net_sockaddr *a, const struct net_sockaddr *b)
Compare socket addresses.
Definition net_ip.h:2213
static ALWAYS_INLINE struct net_sockaddr_storage * net_sas(const struct net_sockaddr *addr)
Get net_sockaddr_storage from net_sockaddr.
Definition net_ip.h:1978
int net_netmask_to_mask_len(net_sa_family_t family, struct net_sockaddr *mask, uint8_t *mask_len)
Create mask length from netmask.
static void net_ipv6_addr_create_iid(struct net_in6_addr *addr, struct net_linkaddr *lladdr)
Create IPv6 address interface identifier.
Definition net_ip.h:1884
static ALWAYS_INLINE struct net_sockaddr_ll_ptr * net_sll_ptr(const struct net_sockaddr_ptr *addr)
Get net_sockaddr_ll_ptr from sockaddr_ptr.
Definition net_ip.h:2046
#define NET_AF_UNIX
Inter-process communication.
Definition net_ip.h:61
unsigned short int net_sa_family_t
Socket address family type.
Definition net_ip.h:169
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:2349
static bool net_ipv6_is_addr_mcast_site(const struct net_in6_addr *addr)
Check if the IPv6 address is a site scope multicast address (FFx5::).
Definition net_ip.h:1622
bool net_ipaddr_parse(const char *str, size_t str_len, struct net_sockaddr *addr)
Parse a string that contains either IPv4 or IPv6 address and optional port, and store the information...
bool net_if_ipv4_addr_mask_cmp(struct net_if *iface, const struct net_in_addr *addr)
static bool net_ipv6_is_addr_mcast_scope(const struct net_in6_addr *addr, int scope)
Check if the IPv6 address is a given scope multicast address (FFyx::).
Definition net_ip.h:1498
#define SOCKADDR_ALIGN
Definition net_ip.h:459
static bool net_ipv6_is_my_addr(struct net_in6_addr *addr)
Check if IPv6 address is found in one of the network interfaces.
Definition net_ip.h:920
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:950
static bool net_ipv6_is_addr_loopback(const struct net_in6_addr *addr)
Check if the IPv6 address is a loopback address (::1).
Definition net_ip.h:873
static bool net_ipv6_is_addr_mcast_org(const struct net_in6_addr *addr)
Check if the IPv6 address is an organization scope multicast address (FFx8::).
Definition net_ip.h:1636
static int net_ipv6_pe_add_filter(struct net_in6_addr *addr, bool is_denylist)
Add IPv6 prefix as a privacy extension filter.
Definition net_ip.h:2405
static bool net_ipv6_is_addr_mcast_group(const struct net_in6_addr *addr, const struct net_in6_addr *group)
Check if the IPv6 address belongs to certain multicast group.
Definition net_ip.h:1662
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition net_ip.h:2274
net_sock_type
Socket type.
Definition net_ip.h:89
static bool net_ipv6_is_addr_solicited_node(const struct net_in6_addr *addr)
Check if the IPv6 address is solicited node multicast address FF02:0:0:0:0:1:FFXX:XXXX defined in @rf...
Definition net_ip.h:1464
static void net_ipv6_addr_create(struct net_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:1770
static ALWAYS_INLINE struct net_sockaddr_can_ptr * net_can_ptr(const struct net_sockaddr_ptr *addr)
Get net_sockaddr_can_ptr from net_sockaddr_ptr.
Definition net_ip.h:2060
static bool net_ipv6_is_global_addr(const struct net_in6_addr *addr)
Check if the given IPv6 address is a global address.
Definition net_ip.h:1259
static bool net_ipv6_is_addr_mcast_link_all_nodes(const struct net_in6_addr *addr)
Check if the IPv6 address is a link local scope all nodes multicast address (FF02::1).
Definition net_ip.h:1728
const struct net_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 net_in6_addr *addr)
Check if the IPv6 address belongs to the all nodes multicast group.
Definition net_ip.h:1689
static bool net_ipv6_is_same_mcast_scope(const struct net_in6_addr *addr_1, const struct net_in6_addr *addr_2)
Check if the IPv6 addresses have the same multicast scope (FFyx::).
Definition net_ip.h:1513
static int net_ipv6_pe_del_filter(struct net_in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition net_ip.h:2425
#define NET_AF_INET
IP protocol family version 4.
Definition net_ip.h:55
static bool net_ipv6_is_ll_addr(const struct net_in6_addr *addr)
Check if the given IPv6 address is a link local address.
Definition net_ip.h:1222
static ALWAYS_INLINE struct net_sockaddr_in6_ptr * net_sin6_ptr(const struct net_sockaddr_ptr *addr)
Get net_sockaddr_in6_ptr from net_sockaddr_ptr.
Definition net_ip.h:2018
struct net_if_mcast_addr * net_if_ipv6_maddr_lookup(const struct net_in6_addr *addr, struct net_if **iface)
static bool net_ipv4_is_private_addr(const struct net_in_addr *addr)
Check if the given IPv4 address is from a private address range.
Definition net_ip.h:1097
static void net_ipv6_addr_create_solicited_node(const struct net_in6_addr *src, struct net_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:1742
static bool net_ipv6_is_addr_mcast_link(const struct net_in6_addr *addr)
Check if the IPv6 address is a link local scope multicast address (FFx2::).
Definition net_ip.h:1594
#define net_ntohl(x)
Convert 32-bit value from network to host byte order.
Definition net_ip.h:109
#define net_htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:125
static void net_ipv6_addr_create_ll_allrouters_mcast(struct net_in6_addr *addr)
Create link local allrouters multicast IPv6 address.
Definition net_ip.h:1801
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.
net_priority
Network packet priority settings described in IEEE 802.1Q Annex I.1.
Definition net_ip.h:567
static bool net_ipv6_is_addr_mcast_iface_all_nodes(const struct net_in6_addr *addr)
Check if the IPv6 address is a interface scope all nodes multicast address (FF01::1).
Definition net_ip.h:1704
static bool net_ipv6_is_sl_addr(const struct net_in6_addr *addr)
Check if the given IPv6 address is a site local address.
Definition net_ip.h:1234
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
const struct net_in6_addr * net_ipv6_unspecified_address(void)
Return pointer to any (all bits zeros) IPv6 address.
static void net_ipv4_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv4 address raw buffer.
Definition net_ip.h:1133
static bool net_ipv6_is_addr_mcast_global(const struct net_in6_addr *addr)
Check if the IPv6 address is a global multicast address (FFxE::/16).
Definition net_ip.h:1566
static ALWAYS_INLINE struct net_sockaddr_in * net_sin(const struct net_sockaddr *addr)
Get net_sockaddr_in from net_sockaddr.
Definition net_ip.h:2004
char * net_addr_ntop(net_sa_family_t family, const void *src, char *dst, size_t size)
Convert IP address to string form.
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:1201
net_addr_type
How the network address is assigned to network interface.
Definition net_ip.h:598
static bool net_ipv4_is_addr_bcast(struct net_if *iface, const struct net_in_addr *addr)
Check if the given IPv4 address is a broadcast address.
Definition net_ip.h:1372
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition net_ip.h:591
@ NET_ADDR_TENTATIVE
Tentative address.
Definition net_ip.h:592
@ NET_ADDR_DEPRECATED
Deprecated address.
Definition net_ip.h:594
@ NET_ADDR_PREFERRED
Preferred address.
Definition net_ip.h:593
@ NET_IPPROTO_TLS_1_2
TLS 1.2 protocol.
Definition net_ip.h:81
@ NET_IPPROTO_TLS_1_1
TLS 1.1 protocol.
Definition net_ip.h:80
@ NET_IPPROTO_TLS_1_0
TLS 1.0 protocol.
Definition net_ip.h:79
@ NET_IPPROTO_DTLS_1_2
DTLS 1.2 protocol.
Definition net_ip.h:84
@ NET_IPPROTO_TLS_1_3
TLS 1.3 protocol.
Definition net_ip.h:82
@ NET_IPPROTO_QUIC
QUIC protocol.
Definition net_ip.h:85
@ NET_IPPROTO_DTLS_1_0
DTLS 1.0 protocol.
Definition net_ip.h:83
@ NET_IPV4_MTU
IPv4 MTU length.
Definition net_ip.h:562
@ NET_IPV6_MTU
IPv6 MTU length.
Definition net_ip.h:553
@ NET_SOCK_STREAM
Stream socket type.
Definition net_ip.h:90
@ NET_SOCK_RAW
RAW socket type.
Definition net_ip.h:92
@ NET_SOCK_DGRAM
Datagram socket type.
Definition net_ip.h:91
@ NET_PRIORITY_NC
Network control (highest).
Definition net_ip.h:575
@ NET_PRIORITY_IC
Internetwork control.
Definition net_ip.h:574
@ NET_PRIORITY_CA
Critical applications.
Definition net_ip.h:571
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter.
Definition net_ip.h:573
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition net_ip.h:572
@ NET_PRIORITY_BE
Best effort (default).
Definition net_ip.h:569
@ NET_PRIORITY_EE
Excellent effort.
Definition net_ip.h:570
@ NET_PRIORITY_BK
Background (lowest).
Definition net_ip.h:568
@ NET_IPPROTO_TCP
TCP protocol.
Definition net_ip.h:70
@ NET_IPPROTO_ICMP
ICMP protocol.
Definition net_ip.h:66
@ NET_IPPROTO_ICMPV6
ICMPv6 protocol.
Definition net_ip.h:73
@ NET_IPPROTO_UDP
UDP protocol.
Definition net_ip.h:71
@ NET_IPPROTO_IP
IP protocol (pseudo-val for setsockopt()).
Definition net_ip.h:65
@ NET_IPPROTO_RAW
RAW IP packets.
Definition net_ip.h:74
@ NET_IPPROTO_IGMP
IGMP protocol.
Definition net_ip.h:67
@ NET_IPPROTO_IPV6
IPv6 protocol.
Definition net_ip.h:72
@ NET_IPPROTO_IPIP
IPIP tunnels.
Definition net_ip.h:69
@ NET_IPPROTO_ETH_P_ALL
Every packet, from Linux if_ether.h.
Definition net_ip.h:68
@ NET_ADDR_ANY
Default value.
Definition net_ip.h:600
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition net_ip.h:608
@ NET_ADDR_DHCP
Address is from DHCP.
Definition net_ip.h:604
@ NET_ADDR_MANUAL
Manually set address.
Definition net_ip.h:606
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition net_ip.h:602
#define NET_LINK_ADDR_MAX_LENGTH
Maximum length of the link address.
Definition net_linkaddr.h:49
@ NET_LINK_ETHERNET
Ethernet link address.
Definition net_linkaddr.h:66
#define ARRAY_SIZE(array)
Number of elements in the given array.
Definition util.h:118
#define ENOTSUP
Unsupported value.
Definition errno.h:115
#define NULL
Definition iar_missing_defs.h:20
#define in_addr
Definition in.h:20
#define in6_addr
Definition in.h:21
#define ALWAYS_INLINE
Definition common.h:186
Network namespace compatibility mode header.
Public API for network link address.
flags
Definition parser.h:86
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__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)
Group structure.
Definition grp.h:18
Control message ancillary data.
Definition net_ip.h:306
net_socklen_t cmsg_len
Number of bytes, including header.
Definition net_ip.h:307
int cmsg_level
Originating protocol.
Definition net_ip.h:308
int cmsg_type
Protocol-specific type.
Definition net_ip.h:309
z_max_align_t cmsg_data[]
Flexible array member to force alignment of net_cmsghdr.
Definition net_ip.h:310
Network Interface unicast IP addresses.
Definition net_if.h:59
IP and other configuration related data for network interface.
Definition net_if.h:708
Network Interface multicast IP addresses.
Definition net_if.h:174
Network Interface structure.
Definition net_if.h:857
Interface description structure.
Definition net_ip.h:776
char ifr_name[NET_IFNAMSIZ]
Network interface name.
Definition net_ip.h:777
IPv6 address struct.
Definition net_ip.h:144
uint16_t s6_addr16[8]
In big endian.
Definition net_ip.h:147
uint32_t s6_addr32[4]
In big endian.
Definition net_ip.h:148
uint8_t s6_addr[16]
IPv6 address buffer.
Definition net_ip.h:146
Incoming IPv6 packet information.
Definition net_ip.h:851
unsigned int ipi6_ifindex
Receive interface index.
Definition net_ip.h:853
struct net_in6_addr ipi6_addr
Destination IPv6 address.
Definition net_ip.h:852
IPv4 address struct.
Definition net_ip.h:156
uint16_t s4_addr16[2]
In big endian.
Definition net_ip.h:159
uint32_t s4_addr32[1]
In big endian.
Definition net_ip.h:160
uint32_t s_addr
In big endian, for POSIX compatibility.
Definition net_ip.h:161
uint8_t s4_addr[4]
IPv4 address buffer.
Definition net_ip.h:158
Incoming IPv4 packet information.
Definition net_ip.h:787
unsigned int ipi_ifindex
Network interface index.
Definition net_ip.h:788
struct net_in_addr ipi_addr
Header Destination address.
Definition net_ip.h:790
struct net_in_addr ipi_spec_dst
Local address.
Definition net_ip.h:789
IO vector array element.
Definition net_ip.h:288
void * iov_base
Pointer to data.
Definition net_ip.h:289
size_t iov_len
Length of the data.
Definition net_ip.h:290
Struct used when setting a IPv4 multicast network interface.
Definition net_ip.h:805
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:806
struct net_in_addr imr_interface
IP address of local interface.
Definition net_ip.h:807
Struct used when joining or leaving a IPv4 multicast group.
Definition net_ip.h:796
int imr_ifindex
Network interface index.
Definition net_ip.h:799
struct net_in_addr imr_address
IP address of local interface.
Definition net_ip.h:798
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:797
Struct used when joining or leaving a IPv6 multicast group.
Definition net_ip.h:813
struct net_in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition net_ip.h:815
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition net_ip.h:818
Linger option struct for the SO_LINGER socket option.
Definition net_ip.h:314
int l_onoff
Whether the linger behaviour is enabled.
Definition net_ip.h:315
int l_linger
Linger time in seconds.
Definition net_ip.h:316
Hardware link address structure.
Definition net_linkaddr.h:83
uint8_t addr[6]
The array of bytes representing the address.
Definition net_linkaddr.h:91
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:85
uint8_t len
The real length of the ll address.
Definition net_linkaddr.h:88
Message struct.
Definition net_ip.h:295
int msg_flags
Flags on received message.
Definition net_ip.h:302
struct net_iovec * msg_iov
Scatter/gather array.
Definition net_ip.h:298
net_socklen_t msg_namelen
Size of socket address.
Definition net_ip.h:297
size_t msg_controllen
Ancillary data buffer len.
Definition net_ip.h:301
void * msg_control
Ancillary data.
Definition net_ip.h:300
void * msg_name
Optional socket address, big endian.
Definition net_ip.h:296
size_t msg_iovlen
Number of elements in msg_iov.
Definition net_ip.h:299
Struct used when setting a packet socket multicast filtering.
Definition net_ip.h:824
uint16_t mr_type
Packet type (action).
Definition net_ip.h:829
uint8_t mr_address[NET_LINK_ADDR_MAX_LENGTH]
Physical layer address.
Definition net_ip.h:835
uint16_t mr_alen
Address length.
Definition net_ip.h:832
int mr_ifindex
Network interface index.
Definition net_ip.h:826
struct net_sockaddr_can - The net_sockaddr structure for CAN sockets.
Definition net_ip.h:206
int can_ifindex
SocketCAN network interface index.
Definition net_ip.h:208
net_sa_family_t can_family
Address family.
Definition net_ip.h:207
Socket address struct for IPv6.
Definition net_ip.h:180
struct net_in6_addr sin6_addr
IPv6 address.
Definition net_ip.h:183
net_sa_family_t sin6_family
NET_AF_INET6.
Definition net_ip.h:181
uint8_t sin6_scope_id
Interfaces for a scope.
Definition net_ip.h:184
uint16_t sin6_port
Port number.
Definition net_ip.h:182
Socket address struct for IPv4.
Definition net_ip.h:188
uint16_t sin_port
Port number.
Definition net_ip.h:190
struct net_in_addr sin_addr
IPv4 address.
Definition net_ip.h:191
net_sa_family_t sin_family
NET_AF_INET.
Definition net_ip.h:189
Socket address struct for packet socket.
Definition net_ip.h:195
uint8_t sll_pkttype
Packet type.
Definition net_ip.h:200
int sll_ifindex
Interface number.
Definition net_ip.h:198
net_sa_family_t sll_family
Always NET_AF_PACKET.
Definition net_ip.h:196
uint16_t sll_hatype
ARP hardware type.
Definition net_ip.h:199
uint8_t sll_halen
Length of address.
Definition net_ip.h:201
uint16_t sll_protocol
Physical-layer protocol.
Definition net_ip.h:197
uint8_t sll_addr[8]
Physical-layer address, big endian.
Definition net_ip.h:202
struct net_sockaddr_nm - The net_sockaddr structure for NET_MGMT sockets
Definition net_ip.h:229
uint64_t nm_mask
net_mgmt mask
Definition net_ip.h:242
int nm_ifindex
Network interface related to this address.
Definition net_ip.h:234
uintptr_t nm_pid
Thread id or similar that is used to separate the different sockets.
Definition net_ip.h:239
net_sa_family_t nm_family
AF_NET_MGMT address family.
Definition net_ip.h:231
Generic sockaddr struct.
Definition net_ip.h:462
net_sa_family_t sa_family
Address family.
Definition net_ip.h:463
IPv6/IPv4 network connection tuple.
Definition net_ip.h:581
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition net_ip.h:582
uint16_t local_port
UDP/TCP local port.
Definition net_ip.h:585
enum net_ip_protocol ip_proto
IP protocol.
Definition net_ip.h:586
uint16_t remote_port
UDP/TCP remote port.
Definition net_ip.h:584
struct net_addr * local_addr
IPv6/IPv4 local address.
Definition net_ip.h:583
Byte order helpers.
Misc utilities.
Macros to abstract toolchain specific capabilities.