Zephyr API Documentation 4.4.99
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)
349#define NET_CMSG_NXTHDR(msghdr, cmsg) \
350 (((cmsg) == NULL) ? NET_CMSG_FIRSTHDR(msghdr) : \
351 (((uint8_t *)(cmsg) + NET_ALIGN_H((cmsg)->cmsg_len) + \
352 NET_ALIGN_D(sizeof(struct net_cmsghdr)) > \
353 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
354 NULL : \
355 (struct net_cmsghdr *)((uint8_t *)(cmsg) + \
356 NET_ALIGN_H((cmsg)->cmsg_len))))
357#endif
358
359#if !defined(NET_CMSG_DATA)
367#define NET_CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + NET_ALIGN_D(sizeof(struct net_cmsghdr)))
368#endif
369
370#if !defined(NET_CMSG_SPACE)
375#define NET_CMSG_SPACE(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + NET_ALIGN_H(length))
376#endif
377
378#if !defined(NET_CMSG_LEN)
384#define NET_CMSG_LEN(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + length)
385#endif
386
388
389/* Packet types. */
390#define NET_PACKET_HOST 0 /* To us */
391#define NET_PACKET_BROADCAST 1 /* To all */
392#define NET_PACKET_MULTICAST 2 /* To group */
393#define NET_PACKET_OTHERHOST 3 /* To someone else */
394#define NET_PACKET_OUTGOING 4 /* Originated by us */
395#define NET_PACKET_LOOPBACK 5
396#define NET_PACKET_FASTROUTE 6
397
398/* ARP protocol HARDWARE identifiers. */
399#define NET_ARPHRD_ETHER 1
400#define NET_ARPHRD_PPP 512
401
402/* Note: These macros are defined in a specific order.
403 * The largest sockaddr size is the last one.
404 */
405#if defined(CONFIG_NET_IPV4)
406#undef NET_SOCKADDR_MAX_SIZE
407#undef NET_SOCKADDR_PTR_MAX_SIZE
408#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in))
409#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in_ptr))
410#endif
411
412#if defined(CONFIG_NET_SOCKETS_PACKET)
413#undef NET_SOCKADDR_MAX_SIZE
414#undef NET_SOCKADDR_PTR_MAX_SIZE
415#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_ll))
416#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_ll_ptr))
417#endif
418
419#if defined(CONFIG_NET_IPV6)
420#undef NET_SOCKADDR_MAX_SIZE
421#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in6))
422#if !defined(CONFIG_NET_SOCKETS_PACKET)
423#undef NET_SOCKADDR_PTR_MAX_SIZE
424#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in6_ptr))
425#endif
426#endif
427
428#if defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
429#define UNIX_PATH_MAX 108
430#undef NET_SOCKADDR_MAX_SIZE
431/* Define NET_SOCKADDR_MAX_SIZE to be struct of net_sa_family_t + char[UNIX_PATH_MAX] */
432#define NET_SOCKADDR_MAX_SIZE (UNIX_PATH_MAX+sizeof(net_sa_family_t))
433#if !defined(CONFIG_NET_SOCKETS_PACKET)
434#undef NET_SOCKADDR_PTR_MAX_SIZE
435#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_un_ptr))
436#endif
437#endif
438
439#if !defined(CONFIG_NET_IPV4)
440#if !defined(CONFIG_NET_IPV6)
441#if !defined(CONFIG_NET_SOCKETS_PACKET)
442#if !defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
443#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in6))
444#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in6_ptr))
445#endif
446#endif
447#endif
448#endif
449
451
452#define SOCKADDR_ALIGN (4)
453
458 char data[NET_SOCKADDR_MAX_SIZE - sizeof(net_sa_family_t)];
460} __aligned(SOCKADDR_ALIGN);
461
463
464struct net_sockaddr_ptr {
465 net_sa_family_t family;
466 char data[NET_SOCKADDR_PTR_MAX_SIZE - sizeof(net_sa_family_t)];
467} __aligned(SOCKADDR_ALIGN);
468
469/* Same as sockaddr in our case */
470struct net_sockaddr_storage {
471 net_sa_family_t ss_family;
472 char data[NET_SOCKADDR_MAX_SIZE - sizeof(net_sa_family_t)];
473} __aligned(SOCKADDR_ALIGN);
474
475/* Socket address struct for UNIX domain sockets */
476struct net_sockaddr_un {
477 net_sa_family_t sun_family; /* NET_AF_UNIX */
478 char sun_path[NET_SOCKADDR_MAX_SIZE - sizeof(net_sa_family_t)];
479};
480
481struct net_addr {
482 net_sa_family_t family;
483 union {
484#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
485 struct net_in6_addr net_in6_addr;
486 struct net_in_addr net_in_addr;
487#else
488 struct net_in6_addr in6_addr;
489 struct net_in_addr in_addr;
490#endif
491 };
492};
493
495extern const struct net_in6_addr net_in6addr_any;
496
498extern const struct net_in6_addr net_in6addr_loopback;
499
501
503#define NET_IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
504 0, 0, 0, 0, 0, 0, 0, 0 } } }
505
507#define NET_IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
508 0, 0, 0, 0, 0, 0, 0, 1 } } }
509
511#define NET_INADDR_ANY 0
512
514#define NET_INADDR_BROADCAST 0xffffffff
515
517#define NET_INADDR_ANY_INIT { { { NET_INADDR_ANY } } }
518
520#define NET_INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
521
523#define NET_INET_ADDRSTRLEN 16
524
528#define NET_INET6_ADDRSTRLEN 46
529
531
532/* These are for internal usage of the stack */
533#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxx.xxx.xxx.xxx")
534#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
535
537
543#if defined(CONFIG_NET_NATIVE_IPV6)
544 NET_IPV6_MTU = CONFIG_NET_IPV6_MTU,
545#else
547#endif
548
552#if defined(CONFIG_NET_NATIVE_IPV4)
553 NET_IPV4_MTU = CONFIG_NET_IPV4_MTU,
554#else
556#endif
557};
558
570
571#define NET_MAX_PRIORITIES 8
572
581
589
603
605
606struct net_ipv6_hdr {
607 uint8_t vtc;
608 uint8_t tcflow;
609 uint16_t flow;
610 uint16_t len;
611 uint8_t nexthdr;
612 uint8_t hop_limit;
615} __packed;
616
617struct net_ipv6_frag_hdr {
618 uint8_t nexthdr;
619 uint8_t reserved;
620 uint16_t offset;
621 uint32_t id;
622} __packed;
623
624struct net_ipv4_hdr {
625 uint8_t vhl;
626 uint8_t tos;
627 uint16_t len;
628 uint8_t id[2];
629 uint8_t offset[2];
630 uint8_t ttl;
631 uint8_t proto;
632 uint16_t chksum;
635} __packed;
636
637struct net_icmp_hdr {
638 uint8_t type;
639 uint8_t code;
640 uint16_t chksum;
641} __packed;
642
643struct net_udp_hdr {
644 uint16_t src_port;
645 uint16_t dst_port;
646 uint16_t len;
647 uint16_t chksum;
648} __packed;
649
655struct net_udp_opt_mrds {
657 uint16_t size;
659 uint8_t segs;
660};
661
666struct net_udp_opt_time {
668 uint32_t tsval;
670 uint32_t tsecr;
671};
672
673struct net_tcp_hdr {
674 uint16_t src_port;
675 uint16_t dst_port;
676 uint8_t seq[4];
677 uint8_t ack[4];
678 uint8_t offset;
680 uint8_t wnd[2];
681 uint16_t chksum;
682 uint8_t urg[2];
683 uint8_t optdata[0];
684} __packed;
685
686static inline const char *net_addr_type2str(enum net_addr_type type)
687{
688 switch (type) {
690 return "AUTO";
691 case NET_ADDR_DHCP:
692 return "DHCP";
693 case NET_ADDR_MANUAL:
694 return "MANUAL";
696 return "OVERRIDE";
697 case NET_ADDR_ANY:
698 default:
699 break;
700 }
701
702 return "<unknown>";
703}
704
705/* IPv6 extension headers types */
706#define NET_IPV6_NEXTHDR_HBHO 0
707#define NET_IPV6_NEXTHDR_DESTO 60
708#define NET_IPV6_NEXTHDR_ROUTING 43
709#define NET_IPV6_NEXTHDR_FRAG 44
710#define NET_IPV6_NEXTHDR_NONE 59
711
716union net_ip_header {
717 struct net_ipv4_hdr *ipv4;
718 struct net_ipv6_hdr *ipv6;
719};
720
721union net_proto_header {
722 struct net_udp_hdr *udp;
723 struct net_tcp_hdr *tcp;
724};
725
726#define NET_UDPH_LEN 8 /* Size of UDP header */
727#define NET_TCPH_LEN 20 /* Size of TCP header */
728#define NET_ICMPH_LEN 4 /* Size of ICMP header */
729
730#define NET_IPV6H_LEN 40 /* Size of IPv6 header */
731#define NET_ICMPV6H_LEN NET_ICMPH_LEN /* Size of ICMPv6 header */
732#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN) /* IPv6 + UDP */
733#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN) /* IPv6 + TCP */
734#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN) /* ICMPv6 + IPv6 */
735#define NET_IPV6_FRAGH_LEN 8
736
737#define NET_IPV4H_LEN 20 /* Size of IPv4 header */
738#define NET_ICMPV4H_LEN NET_ICMPH_LEN /* Size of ICMPv4 header */
739#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN) /* IPv4 + UDP */
740#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN) /* IPv4 + TCP */
741#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN) /* ICMPv4 + IPv4 */
742
743#define NET_IPV6H_LENGTH_OFFSET 0x04 /* Offset of the Length field in the IPv6 header */
744
745#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8 /* Mask for the 13-bit Fragment Offset field */
746#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff /* Mask for the 13-bit Fragment Offset field */
747#define NET_IPV4_MORE_FRAG_MASK 0x2000 /* Mask for the 1-bit More Fragments field */
748#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000 /* Mask for the 1-bit Do Not Fragment field */
749
751#if defined(CONFIG_NET_INTERFACE_NAME)
752#define NET_IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
753#else
754#if defined(Z_DEVICE_MAX_NAME_LEN)
755#define NET_IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
756#else
757#define NET_IFNAMSIZ 1
758#endif /* Z_DEVICE_MAX_NAME_LEN */
759#endif /* CONFIG_NET_INTERFACE_NAME */
760
762
767
769struct net_ifreq {
770 char ifr_name[NET_IFNAMSIZ];
771};
772
773
785
794
802
813
830
834#define NET_PACKET_MR_MULTICAST 0
835#define NET_PACKET_MR_PROMISC 1
836#define NET_PACKET_MR_ALLMULTI 2
837
846 unsigned int ipi6_ifindex;
847};
848
850static inline bool net_ipv6_is_addr_loopback_raw(const uint8_t *addr)
851{
852 return UNALIGNED_GET((uint32_t *)addr) == 0 &&
853 UNALIGNED_GET((uint32_t *)addr + 1) == 0 &&
854 UNALIGNED_GET((uint32_t *)addr + 2) == 0 &&
855 net_ntohl(UNALIGNED_GET((uint32_t *)addr + 3)) == 1;
856}
858
866static inline bool net_ipv6_is_addr_loopback(const struct net_in6_addr *addr)
867{
868 return net_ipv6_is_addr_loopback_raw(addr->s6_addr);
869}
870
872static inline bool net_ipv6_is_addr_mcast_raw(const uint8_t *addr)
873{
874 return addr[0] == 0xff;
875}
877
885static inline bool net_ipv6_is_addr_mcast(const struct net_in6_addr *addr)
886{
887 return net_ipv6_is_addr_mcast_raw(addr->s6_addr);
888}
889
890struct net_if;
891struct net_if_config;
892
894extern struct net_if_addr *net_if_ipv6_addr_lookup_raw(const uint8_t *addr,
895 struct net_if **ret);
896
897static inline bool net_ipv6_is_my_addr_raw(const uint8_t *addr)
898{
899 return net_if_ipv6_addr_lookup_raw(addr, NULL) != NULL;
900}
902
903extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct net_in6_addr *addr,
904 struct net_if **iface);
905
913static inline bool net_ipv6_is_my_addr(struct net_in6_addr *addr)
914{
915 return net_if_ipv6_addr_lookup(addr, NULL) != NULL;
916}
917
919 const struct net_in6_addr *addr, struct net_if **iface);
920
929static inline bool net_ipv6_is_my_maddr(struct net_in6_addr *maddr)
930{
931 return net_if_ipv6_maddr_lookup(maddr, NULL) != NULL;
932}
933
943static inline bool net_ipv6_is_prefix(const uint8_t *addr1,
944 const uint8_t *addr2,
945 uint8_t length)
946{
947 uint8_t bits = 128 - length;
948 uint8_t bytes = length / 8U;
949 uint8_t remain = bits % 8;
950 uint8_t mask;
951
952 if (length > 128) {
953 return false;
954 }
955
956 if (memcmp(addr1, addr2, bytes)) {
957 return false;
958 }
959
960 if (!remain) {
961 /* No remaining bits, the prefixes are the same as first
962 * bytes are the same.
963 */
964 return true;
965 }
966
967 /* Create a mask that has remaining most significant bits set */
968 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
969
970 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
971}
972
973
981static inline void net_ipv6_addr_prefix_mask(const uint8_t *inaddr,
982 uint8_t *outaddr,
983 uint8_t prefix_len)
984{
985 uint8_t bits = 128 - prefix_len;
986 uint8_t bytes = prefix_len / 8U;
987 uint8_t remain = bits % 8;
988 uint8_t mask;
989
990 memset(outaddr, 0, 16U);
991 memcpy(outaddr, inaddr, bytes);
992
993 if (!remain) {
994 /* No remaining bits, the prefixes are the same as first
995 * bytes are the same.
996 */
997 return;
998 }
999
1000 /* Create a mask that has remaining most significant bits set */
1001 mask = (uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
1002 outaddr[bytes] = inaddr[bytes] & mask;
1003}
1004
1006static inline bool net_ipv4_is_addr_loopback_raw(const uint8_t *addr)
1007{
1008 return addr[0] == 127U;
1009}
1011
1019static inline bool net_ipv4_is_addr_loopback(const struct net_in_addr *addr)
1020{
1021 return net_ipv4_is_addr_loopback_raw(addr->s4_addr);
1022}
1023
1025static inline bool net_ipv4_is_addr_unspecified_raw(const uint8_t *addr)
1026{
1027 return UNALIGNED_GET((uint32_t *)addr) == 0;
1028}
1030
1038static inline bool net_ipv4_is_addr_unspecified(const struct net_in_addr *addr)
1039{
1040 return net_ipv4_is_addr_unspecified_raw(addr->s4_addr);
1041}
1042
1044static inline bool net_ipv4_is_addr_mcast_raw(const uint8_t *addr)
1045{
1046 return (net_ntohl(UNALIGNED_GET((uint32_t *)addr)) & 0xF0000000) == 0xE0000000;
1047}
1049
1057static inline bool net_ipv4_is_addr_mcast(const struct net_in_addr *addr)
1058{
1059 return net_ipv4_is_addr_mcast_raw(addr->s4_addr);
1060}
1061
1063static inline bool net_ipv4_is_ll_addr_raw(const uint8_t *addr)
1064{
1065 return (net_ntohl(UNALIGNED_GET((uint32_t *)addr)) & 0xFFFF0000) == 0xA9FE0000;
1066}
1068
1076static inline bool net_ipv4_is_ll_addr(const struct net_in_addr *addr)
1077{
1078 return net_ipv4_is_ll_addr_raw(addr->s4_addr);
1079}
1080
1090static inline bool net_ipv4_is_private_addr(const struct net_in_addr *addr)
1091{
1092 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
1093
1094 masked_24 = net_ntohl(UNALIGNED_GET(&addr->s_addr)) & 0xFFFFFF00;
1095 masked_16 = masked_24 & 0xFFFF0000;
1096 masked_12 = masked_24 & 0xFFF00000;
1097 masked_10 = masked_24 & 0xFFC00000;
1098 masked_8 = masked_24 & 0xFF000000;
1099
1100 return masked_8 == 0x0A000000 || /* 10.0.0.0/8 */
1101 masked_10 == 0x64400000 || /* 100.64.0.0/10 */
1102 masked_12 == 0xAC100000 || /* 172.16.0.0/12 */
1103 masked_16 == 0xC0A80000 || /* 192.168.0.0/16 */
1104 masked_24 == 0xC0000200 || /* 192.0.2.0/24 */
1105 masked_24 == 0xC0336400 || /* 192.51.100.0/24 */
1106 masked_24 == 0xCB007100; /* 203.0.113.0/24 */
1107}
1108
1117#define net_ipaddr_copy(dest, src) \
1118 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
1119
1126static inline void net_ipv4_addr_copy_raw(uint8_t *dest,
1127 const uint8_t *src)
1128{
1129 net_ipaddr_copy((struct net_in_addr *)dest, (const struct net_in_addr *)src);
1130}
1131
1138static inline void net_ipv6_addr_copy_raw(uint8_t *dest,
1139 const uint8_t *src)
1140{
1141 memcpy(dest, src, sizeof(struct net_in6_addr));
1142}
1143
1152static inline bool net_ipv4_addr_cmp_raw(const uint8_t *addr1,
1153 const uint8_t *addr2)
1154{
1155 return UNALIGNED_GET((uint32_t *)addr1) == UNALIGNED_GET((uint32_t *)addr2);
1156}
1157
1166static inline bool net_ipv4_addr_cmp(const struct net_in_addr *addr1,
1167 const struct net_in_addr *addr2)
1168{
1169 return net_ipv4_addr_cmp_raw(addr1->s4_addr, addr2->s4_addr);
1170}
1171
1180static inline bool net_ipv6_addr_cmp(const struct net_in6_addr *addr1,
1181 const struct net_in6_addr *addr2)
1182{
1183 return !memcmp(addr1, addr2, sizeof(struct net_in6_addr));
1184}
1185
1194static inline bool net_ipv6_addr_cmp_raw(const uint8_t *addr1,
1195 const uint8_t *addr2)
1196{
1197 return net_ipv6_addr_cmp((const struct net_in6_addr *)addr1,
1198 (const struct net_in6_addr *)addr2);
1199}
1200
1202static inline bool net_ipv6_is_ll_addr_raw(const uint8_t *addr)
1203{
1204 return UNALIGNED_GET((uint16_t *)addr) == net_htons(0xFE80);
1205}
1207
1215static inline bool net_ipv6_is_ll_addr(const struct net_in6_addr *addr)
1216{
1217 return net_ipv6_is_ll_addr_raw(addr->s6_addr);
1218}
1219
1227static inline bool net_ipv6_is_sl_addr(const struct net_in6_addr *addr)
1228{
1229 return UNALIGNED_GET(&addr->s6_addr16[0]) == net_htons(0xFEC0);
1230}
1231
1232
1240static inline bool net_ipv6_is_ula_addr(const struct net_in6_addr *addr)
1241{
1242 return addr->s6_addr[0] == 0xFD;
1243}
1244
1252static inline bool net_ipv6_is_global_addr(const struct net_in6_addr *addr)
1253{
1254 return (addr->s6_addr[0] & 0xE0) == 0x20;
1255}
1256
1266static inline bool net_ipv6_is_private_addr(const struct net_in6_addr *addr)
1267{
1268 uint32_t masked_32, masked_7;
1269
1270 masked_32 = net_ntohl(UNALIGNED_GET(&addr->s6_addr32[0]));
1271 masked_7 = masked_32 & 0xfc000000;
1272
1273 return masked_32 == 0x20010db8 || /* 2001:db8::/32 */
1274 masked_7 == 0xfc000000; /* fc00::/7 */
1275}
1276
1283
1290
1297
1298struct net_if;
1299extern bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
1300 const struct net_in_addr *addr);
1301
1311static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
1312 const struct net_in_addr *addr)
1313{
1314 return net_if_ipv4_addr_mask_cmp(iface, addr);
1315}
1316
1318extern bool net_if_ipv4_is_addr_bcast_raw(struct net_if *iface,
1319 const uint8_t *addr);
1320
1321#if defined(CONFIG_NET_NATIVE_IPV4)
1322static inline bool net_ipv4_is_addr_bcast_raw(struct net_if *iface,
1323 const uint8_t *addr)
1324{
1325 if (net_ipv4_addr_cmp_raw(addr, net_ipv4_broadcast_address()->s4_addr)) {
1326 return true;
1327 }
1328
1329 return net_if_ipv4_is_addr_bcast_raw(iface, addr);
1330}
1331#else
1332static inline bool net_ipv4_is_addr_bcast_raw(struct net_if *iface,
1333 const uint8_t *addr)
1334{
1335 ARG_UNUSED(iface);
1336 ARG_UNUSED(addr);
1337
1338 return false;
1339}
1340#endif
1342
1343extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
1344 const struct net_in_addr *addr);
1345
1354#if defined(CONFIG_NET_NATIVE_IPV4)
1355static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1356 const struct net_in_addr *addr)
1357{
1359 return true;
1360 }
1361
1362 return net_if_ipv4_is_addr_bcast(iface, addr);
1363}
1364#else
1365static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1366 const struct net_in_addr *addr)
1367{
1368 ARG_UNUSED(iface);
1369 ARG_UNUSED(addr);
1370
1371 return false;
1372}
1373#endif
1374
1376extern struct net_if_addr *net_if_ipv4_addr_lookup_raw(const uint8_t *addr,
1377 struct net_if **ret);
1378
1379static inline bool net_ipv4_is_my_addr_raw(const uint8_t *addr)
1380{
1381 bool ret;
1382
1383 ret = net_if_ipv4_addr_lookup_raw(addr, NULL) != NULL;
1384 if (!ret) {
1385 ret = net_ipv4_is_addr_bcast_raw(NULL, addr);
1386 }
1387
1388 return ret;
1389}
1391
1392extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct net_in_addr *addr,
1393 struct net_if **iface);
1394
1404static inline bool net_ipv4_is_my_addr(const struct net_in_addr *addr)
1405{
1406 bool ret;
1407
1408 ret = net_if_ipv4_addr_lookup(addr, NULL) != NULL;
1409 if (!ret) {
1410 ret = net_ipv4_is_addr_bcast(NULL, addr);
1411 }
1412
1413 return ret;
1414}
1415
1417static inline bool net_ipv6_is_addr_unspecified_raw(const uint8_t *addr)
1418{
1419 return UNALIGNED_GET((uint32_t *)addr) == 0 &&
1420 UNALIGNED_GET((uint32_t *)addr + 1) == 0 &&
1421 UNALIGNED_GET((uint32_t *)addr + 2) == 0 &&
1422 UNALIGNED_GET((uint32_t *)addr + 3) == 0;
1423}
1425
1433static inline bool net_ipv6_is_addr_unspecified(const struct net_in6_addr *addr)
1434{
1435 return net_ipv6_is_addr_unspecified_raw(addr->s6_addr);
1436}
1437
1439static inline bool net_ipv6_is_addr_solicited_node_raw(const uint8_t *addr)
1440{
1441 return UNALIGNED_GET((uint32_t *)addr) == net_htonl(0xff020000) &&
1442 UNALIGNED_GET((uint32_t *)addr + 1) == 0x00000000 &&
1443 UNALIGNED_GET((uint32_t *)addr + 2) == net_htonl(0x00000001) &&
1444 ((UNALIGNED_GET((uint32_t *)addr + 3) & net_htonl(0xff000000)) ==
1445 net_htonl(0xff000000));
1446}
1448
1457static inline bool net_ipv6_is_addr_solicited_node(const struct net_in6_addr *addr)
1458{
1459 return net_ipv6_is_addr_solicited_node_raw(addr->s6_addr);
1460}
1461
1463static inline bool net_ipv6_is_addr_mcast_scope_raw(const uint8_t *addr,
1464 int scope)
1465{
1466 return (addr[0] == 0xff) && ((addr[1] & 0xF) == scope);
1467}
1469
1471static inline int net_ipv6_get_addr_mcast_scope_raw(const uint8_t *addr)
1472{
1473 if (addr[0] == 0xff) {
1474 return (addr[1] & 0xF);
1475 }
1476
1477 return -1;
1478}
1480
1491static inline bool net_ipv6_is_addr_mcast_scope(const struct net_in6_addr *addr,
1492 int scope)
1493{
1494 return net_ipv6_is_addr_mcast_scope_raw(addr->s6_addr, scope);
1495}
1496
1506static inline bool net_ipv6_is_same_mcast_scope(const struct net_in6_addr *addr_1,
1507 const struct net_in6_addr *addr_2)
1508{
1509 return (addr_1->s6_addr[0] == 0xff) && (addr_2->s6_addr[0] == 0xff) &&
1510 (addr_1->s6_addr[1] == addr_2->s6_addr[1]);
1511}
1512
1520static inline int net_ipv6_get_addr_mcast_scope(const struct net_in6_addr *addr)
1521{
1522 return net_ipv6_get_addr_mcast_scope_raw(addr->s6_addr);
1523}
1524
1526static inline bool net_ipv6_is_addr_mcast_iface_raw(const uint8_t *addr)
1527{
1528 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x01);
1529}
1530
1531static inline bool net_ipv6_is_addr_mcast_link_raw(const uint8_t *addr)
1532{
1533 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x02);
1534}
1535
1536static inline bool net_ipv6_is_addr_mcast_mesh_raw(const uint8_t *addr)
1537{
1538 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x03);
1539}
1540
1541static inline bool net_ipv6_is_addr_mcast_site_raw(const uint8_t *addr)
1542{
1543 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x05);
1544}
1545
1546static inline bool net_ipv6_is_addr_mcast_org_raw(const uint8_t *addr)
1547{
1548 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x08);
1549}
1551
1559static inline bool net_ipv6_is_addr_mcast_global(const struct net_in6_addr *addr)
1560{
1561 return net_ipv6_is_addr_mcast_scope(addr, 0x0e);
1562}
1563
1573static inline bool net_ipv6_is_addr_mcast_iface(const struct net_in6_addr *addr)
1574{
1575 return net_ipv6_is_addr_mcast_scope(addr, 0x01);
1576}
1577
1587static inline bool net_ipv6_is_addr_mcast_link(const struct net_in6_addr *addr)
1588{
1589 return net_ipv6_is_addr_mcast_scope(addr, 0x02);
1590}
1591
1601static inline bool net_ipv6_is_addr_mcast_mesh(const struct net_in6_addr *addr)
1602{
1603 return net_ipv6_is_addr_mcast_scope(addr, 0x03);
1604}
1605
1615static inline bool net_ipv6_is_addr_mcast_site(const struct net_in6_addr *addr)
1616{
1617 return net_ipv6_is_addr_mcast_scope(addr, 0x05);
1618}
1619
1629static inline bool net_ipv6_is_addr_mcast_org(const struct net_in6_addr *addr)
1630{
1631 return net_ipv6_is_addr_mcast_scope(addr, 0x08);
1632}
1633
1635static inline bool net_ipv6_is_addr_mcast_group_raw(const uint8_t *addr,
1636 const uint8_t *group)
1637{
1638 return UNALIGNED_GET((uint16_t *)addr + 1) == UNALIGNED_GET((uint16_t *)group + 1) &&
1639 UNALIGNED_GET((uint32_t *)addr + 1) == UNALIGNED_GET((uint32_t *)group + 1) &&
1640 UNALIGNED_GET((uint32_t *)addr + 2) == UNALIGNED_GET((uint32_t *)group + 2) &&
1641 UNALIGNED_GET((uint32_t *)addr + 3) == UNALIGNED_GET((uint32_t *)group + 3);
1642}
1644
1655static inline bool net_ipv6_is_addr_mcast_group(const struct net_in6_addr *addr,
1656 const struct net_in6_addr *group)
1657{
1658 return net_ipv6_is_addr_mcast_group_raw(addr->s6_addr, group->s6_addr);
1659}
1660
1662static inline bool net_ipv6_is_addr_mcast_all_nodes_group_raw(const uint8_t *addr)
1663{
1664 static const uint8_t all_nodes_mcast_group[NET_IPV6_ADDR_SIZE] = {
1665 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1666 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1667 };
1668
1669 return net_ipv6_is_addr_mcast_group_raw(addr, all_nodes_mcast_group);
1670}
1672
1681static inline bool
1683{
1684 return net_ipv6_is_addr_mcast_all_nodes_group_raw(addr->s6_addr);
1685}
1686
1696static inline bool
1702
1704static inline bool net_ipv6_is_addr_mcast_link_all_nodes_raw(const uint8_t *addr)
1705{
1706 return net_ipv6_is_addr_mcast_link_raw(addr) &&
1707 net_ipv6_is_addr_mcast_all_nodes_group_raw(addr);
1708}
1710
1720static inline bool
1726
1734static inline
1736 struct net_in6_addr *dst)
1737{
1738 dst->s6_addr[0] = 0xFF;
1739 dst->s6_addr[1] = 0x02;
1740 UNALIGNED_PUT(0, &dst->s6_addr16[1]);
1741 UNALIGNED_PUT(0, &dst->s6_addr16[2]);
1742 UNALIGNED_PUT(0, &dst->s6_addr16[3]);
1743 UNALIGNED_PUT(0, &dst->s6_addr16[4]);
1744 dst->s6_addr[10] = 0U;
1745 dst->s6_addr[11] = 0x01;
1746 dst->s6_addr[12] = 0xFF;
1747 dst->s6_addr[13] = src->s6_addr[13];
1748 UNALIGNED_PUT(UNALIGNED_GET(&src->s6_addr16[7]), &dst->s6_addr16[7]);
1749}
1750
1763static inline void net_ipv6_addr_create(struct net_in6_addr *addr,
1764 uint16_t addr0, uint16_t addr1,
1765 uint16_t addr2, uint16_t addr3,
1766 uint16_t addr4, uint16_t addr5,
1767 uint16_t addr6, uint16_t addr7)
1768{
1769 UNALIGNED_PUT(net_htons(addr0), &addr->s6_addr16[0]);
1770 UNALIGNED_PUT(net_htons(addr1), &addr->s6_addr16[1]);
1771 UNALIGNED_PUT(net_htons(addr2), &addr->s6_addr16[2]);
1772 UNALIGNED_PUT(net_htons(addr3), &addr->s6_addr16[3]);
1773 UNALIGNED_PUT(net_htons(addr4), &addr->s6_addr16[4]);
1774 UNALIGNED_PUT(net_htons(addr5), &addr->s6_addr16[5]);
1775 UNALIGNED_PUT(net_htons(addr6), &addr->s6_addr16[6]);
1776 UNALIGNED_PUT(net_htons(addr7), &addr->s6_addr16[7]);
1777}
1778
1785{
1786 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
1787}
1788
1795{
1796 net_ipv6_addr_create(addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0002);
1797}
1798
1805static inline void net_ipv6_addr_create_v4_mapped(const struct net_in_addr *addr4,
1806 struct net_in6_addr *addr6)
1807{
1808 net_ipv6_addr_create(addr6, 0, 0, 0, 0, 0, 0xffff,
1809 net_ntohs(addr4->s4_addr16[0]),
1810 net_ntohs(addr4->s4_addr16[1]));
1811}
1812
1821static inline bool net_ipv6_addr_is_v4_mapped(const struct net_in6_addr *addr)
1822{
1823 if (UNALIGNED_GET(&addr->s6_addr32[0]) == 0 &&
1824 UNALIGNED_GET(&addr->s6_addr32[1]) == 0 &&
1825 UNALIGNED_GET(&addr->s6_addr16[5]) == 0xffff) {
1826 return true;
1827 }
1828
1829 return false;
1830}
1831
1840static inline void net_ipv6_addr_get_v4_mapped(const struct net_in6_addr *addr6,
1841 struct net_in_addr *addr4)
1842{
1843 addr4->s_addr = UNALIGNED_GET(&addr6->s6_addr32[3]);
1844}
1845
1865 const struct net_in6_addr *prefix,
1866 uint8_t *network_id, size_t network_id_len,
1867 uint8_t dad_counter,
1868 struct net_in6_addr *addr,
1869 struct net_linkaddr *lladdr);
1870
1877static inline void net_ipv6_addr_create_iid(struct net_in6_addr *addr,
1878 struct net_linkaddr *lladdr)
1879{
1880 (void)net_ipv6_addr_generate_iid(NULL, NULL, NULL, 0, 0, addr, lladdr);
1881}
1882
1884static inline bool net_ipv6_addr_based_on_ll_raw(const uint8_t *addr,
1885 const struct net_linkaddr *lladdr)
1886{
1887 if (addr == NULL || lladdr == NULL) {
1888 return false;
1889 }
1890
1891 switch (lladdr->len) {
1892 case 2:
1893 if (!memcmp(&addr[14], lladdr->addr, lladdr->len) &&
1894 addr[8] == 0U &&
1895 addr[9] == 0U &&
1896 addr[10] == 0U &&
1897 addr[11] == 0xff &&
1898 addr[12] == 0xfe) {
1899 return true;
1900 }
1901
1902 break;
1903 case 6:
1904 if (lladdr->type == NET_LINK_ETHERNET) {
1905 if (!memcmp(&addr[9], &lladdr->addr[1], 2) &&
1906 !memcmp(&addr[13], &lladdr->addr[3], 3) &&
1907 addr[11] == 0xff &&
1908 addr[12] == 0xfe &&
1909 (addr[8] ^ 0x02) == lladdr->addr[0]) {
1910 return true;
1911 }
1912 }
1913
1914 break;
1915 case 8:
1916 if (sizeof(lladdr->addr) < 8) {
1917 return false;
1918 }
1919
1920 if (!memcmp(&addr[9], &lladdr->addr[1],
1921 lladdr->len - 1) &&
1922 (addr[8] ^ 0x02) == lladdr->addr[0]) {
1923 return true;
1924 }
1925
1926 break;
1927 default:
1928 return false;
1929 }
1930
1931 return false;
1932}
1934
1940static inline bool net_ipv6_addr_based_on_ll(const struct net_in6_addr *addr,
1941 const struct net_linkaddr *lladdr)
1942{
1943 if (addr == NULL || lladdr == NULL) {
1944 return false;
1945 }
1946
1947 return net_ipv6_addr_based_on_ll_raw(addr->s6_addr, lladdr);
1948}
1949
1958static ALWAYS_INLINE struct net_sockaddr *net_sad(const struct net_sockaddr_storage *addr)
1959{
1960 return (struct net_sockaddr *)addr;
1961}
1962
1971static ALWAYS_INLINE struct net_sockaddr_storage *net_sas(const struct net_sockaddr *addr)
1972{
1973 return (struct net_sockaddr_storage *)addr;
1974}
1975
1984static ALWAYS_INLINE struct net_sockaddr_in6 *net_sin6(const struct net_sockaddr *addr)
1985{
1986 return (struct net_sockaddr_in6 *)addr;
1987}
1988
1997static ALWAYS_INLINE struct net_sockaddr_in *net_sin(const struct net_sockaddr *addr)
1998{
1999 return (struct net_sockaddr_in *)addr;
2000}
2001
2010static ALWAYS_INLINE
2011struct net_sockaddr_in6_ptr *net_sin6_ptr(const struct net_sockaddr_ptr *addr)
2012{
2013 return (struct net_sockaddr_in6_ptr *)addr;
2014}
2015
2024static ALWAYS_INLINE
2025struct net_sockaddr_in_ptr *net_sin_ptr(const struct net_sockaddr_ptr *addr)
2026{
2027 return (struct net_sockaddr_in_ptr *)addr;
2028}
2029
2038static ALWAYS_INLINE
2039struct net_sockaddr_ll_ptr *net_sll_ptr(const struct net_sockaddr_ptr *addr)
2040{
2041 return (struct net_sockaddr_ll_ptr *)addr;
2042}
2043
2052static ALWAYS_INLINE
2053struct net_sockaddr_can_ptr *net_can_ptr(const struct net_sockaddr_ptr *addr)
2054{
2055 return (struct net_sockaddr_can_ptr *)addr;
2056}
2057
2071__syscall int net_addr_pton(net_sa_family_t family, const char *src, void *dst);
2072
2084__syscall char *net_addr_ntop(net_sa_family_t family, const void *src,
2085 char *dst, size_t size);
2086
2098 struct net_sockaddr *mask);
2099
2111 uint8_t *mask_len);
2112
2134bool net_ipaddr_parse(const char *str, size_t str_len,
2135 struct net_sockaddr *addr);
2136
2164const char *net_ipaddr_parse_mask(const char *str, size_t str_len,
2165 struct net_sockaddr *addr, uint8_t *mask_len);
2166
2176int net_port_set_default(struct net_sockaddr *addr, uint16_t default_port);
2177
2186int net_port_set(struct net_sockaddr *addr, uint16_t port);
2187
2196int net_port_get(struct net_sockaddr *addr, uint16_t *port);
2197
2206static inline bool net_sockaddr_cmp(const struct net_sockaddr *a, const struct net_sockaddr *b)
2207{
2208 if (a->sa_family != b->sa_family) {
2209 return false;
2210 }
2211
2212 if (a->sa_family == NET_AF_INET) {
2213 const struct net_sockaddr_in *a4 = net_sin(a);
2214 const struct net_sockaddr_in *b4 = net_sin(b);
2215
2216 if (a4->sin_port != b4->sin_port) {
2217 return false;
2218 }
2219
2220 return net_ipv4_addr_cmp(&a4->sin_addr, &b4->sin_addr);
2221 }
2222
2223 if (b->sa_family == NET_AF_INET6) {
2224 const struct net_sockaddr_in6 *a6 = net_sin6(a);
2225 const struct net_sockaddr_in6 *b6 = net_sin6(b);
2226
2227 if (a6->sin6_port != b6->sin6_port) {
2228 return false;
2229 }
2230
2231 return net_ipv6_addr_cmp(&a6->sin6_addr, &b6->sin6_addr);
2232 }
2233
2234 /* Invalid address family */
2235 return false;
2236}
2237
2249static inline int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
2250{
2251 return (int32_t)(seq1 - seq2);
2252}
2253
2264static inline bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
2265{
2266 return net_tcp_seq_cmp(seq1, seq2) > 0;
2267}
2268
2280int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src);
2281
2291
2301
2310static inline enum net_priority net_vlan2priority(uint8_t priority)
2311{
2312 /* Map according to IEEE 802.1Q */
2313 static const uint8_t vlan2priority[] = {
2322 };
2323
2324 if (priority >= ARRAY_SIZE(vlan2priority)) {
2325 /* Use Best Effort as the default priority */
2326 return NET_PRIORITY_BE;
2327 }
2328
2329 return (enum net_priority)vlan2priority[priority];
2330}
2331
2339static inline uint8_t net_priority2vlan(enum net_priority priority)
2340{
2341 /* The conversion works both ways */
2342 return (uint8_t)net_vlan2priority(priority);
2343}
2344
2354
2362static inline size_t net_family2size(net_sa_family_t family)
2363{
2364 switch (family) {
2365 case NET_AF_INET:
2366 return sizeof(struct net_sockaddr_in);
2367 case NET_AF_INET6:
2368 return sizeof(struct net_sockaddr_in6);
2369 case NET_AF_PACKET:
2370 return sizeof(struct net_sockaddr_ll);
2371 case NET_AF_UNIX:
2372 return sizeof(struct net_sockaddr_un);
2373 case NET_AF_CAN:
2374 return sizeof(struct net_sockaddr_can);
2375 case NET_AF_NET_MGMT:
2376 return sizeof(struct net_sockaddr_nm);
2377 default:
2378 return 0;
2379 }
2380}
2381
2392#if defined(CONFIG_NET_IPV6_PE)
2393int net_ipv6_pe_add_filter(struct net_in6_addr *addr, bool is_denylist);
2394#else
2395static inline int net_ipv6_pe_add_filter(struct net_in6_addr *addr,
2396 bool is_denylist)
2397{
2398 ARG_UNUSED(addr);
2399 ARG_UNUSED(is_denylist);
2400
2401 return -ENOTSUP;
2402}
2403#endif /* CONFIG_NET_IPV6_PE */
2404
2412#if defined(CONFIG_NET_IPV6_PE)
2413int net_ipv6_pe_del_filter(struct net_in6_addr *addr);
2414#else
2415static inline int net_ipv6_pe_del_filter(struct net_in6_addr *addr)
2416{
2417 ARG_UNUSED(addr);
2418
2419 return -ENOTSUP;
2420}
2421#endif /* CONFIG_NET_IPV6_PE */
2422
2423#ifdef __cplusplus
2424}
2425#endif
2426
2427#include <zephyr/syscalls/net_ip.h>
2428
2429#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
2430#define ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
2431#include <zephyr/net/net_compat.h>
2432#undef ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
2433#endif /* CONFIG_NET_NAMESPACE_COMPAT_MODE */
2434
2438
2439#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:1240
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:2362
#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:1958
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:2310
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition net_ip.h:2249
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:929
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:1166
#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:1821
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:1433
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:1601
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:1805
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:1057
net_addr_state
What is the current state of the network address.
Definition net_ip.h:583
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:1152
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:1266
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:1038
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:885
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:1573
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:1138
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:1311
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:1984
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:981
#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:1404
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:1019
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:1076
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:1180
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:1784
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:2025
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:1840
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:1117
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:1940
net_ip_mtu
IP Maximum Transfer Unit.
Definition net_ip.h:539
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:1520
static bool net_sockaddr_cmp(const struct net_sockaddr *a, const struct net_sockaddr *b)
Compare socket addresses.
Definition net_ip.h:2206
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:1971
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:1877
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:2039
#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:2339
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:1615
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:1491
#define SOCKADDR_ALIGN
Definition net_ip.h:452
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:913
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:943
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:866
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:1629
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:2395
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:1655
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition net_ip.h:2264
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 RFC...
Definition net_ip.h:1457
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:1763
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:2053
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:1252
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:1721
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:1682
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:1506
static int net_ipv6_pe_del_filter(struct net_in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition net_ip.h:2415
#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:1215
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:2011
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:1090
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:1735
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:1587
#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:1794
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:560
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:1697
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:1227
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:1126
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:1559
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:1997
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:1194
net_addr_type
How the network address is assigned to network interface.
Definition net_ip.h:591
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:1365
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition net_ip.h:584
@ NET_ADDR_TENTATIVE
Tentative address.
Definition net_ip.h:585
@ NET_ADDR_DEPRECATED
Deprecated address.
Definition net_ip.h:587
@ NET_ADDR_PREFERRED
Preferred address.
Definition net_ip.h:586
@ 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:555
@ NET_IPV6_MTU
IPv6 MTU length.
Definition net_ip.h:546
@ 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:568
@ NET_PRIORITY_IC
Internetwork control.
Definition net_ip.h:567
@ NET_PRIORITY_CA
Critical applications.
Definition net_ip.h:564
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter.
Definition net_ip.h:566
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition net_ip.h:565
@ NET_PRIORITY_BE
Best effort (default).
Definition net_ip.h:562
@ NET_PRIORITY_EE
Excellent effort.
Definition net_ip.h:563
@ NET_PRIORITY_BK
Background (lowest).
Definition net_ip.h:561
@ 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:593
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition net_ip.h:601
@ NET_ADDR_DHCP
Address is from DHCP.
Definition net_ip.h:597
@ NET_ADDR_MANUAL
Manually set address.
Definition net_ip.h:599
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition net_ip.h:595
#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 in_addr
Definition in.h:20
#define in6_addr
Definition in.h:21
Network namespace compatibility mode header.
Public API for network link address.
flags
Definition parser.h:97
__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:56
IP and other configuration related data for network interface.
Definition net_if.h:615
Network Interface multicast IP addresses.
Definition net_if.h:161
Network Interface structure.
Definition net_if.h:764
Interface description structure.
Definition net_ip.h:769
char ifr_name[NET_IFNAMSIZ]
Network interface name.
Definition net_ip.h:770
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:844
unsigned int ipi6_ifindex
Receive interface index.
Definition net_ip.h:846
struct net_in6_addr ipi6_addr
Destination IPv6 address.
Definition net_ip.h:845
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:780
unsigned int ipi_ifindex
Network interface index.
Definition net_ip.h:781
struct net_in_addr ipi_addr
Header Destination address.
Definition net_ip.h:783
struct net_in_addr ipi_spec_dst
Local address.
Definition net_ip.h:782
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:798
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:799
struct net_in_addr imr_interface
IP address of local interface.
Definition net_ip.h:800
Struct used when joining or leaving a IPv4 multicast group.
Definition net_ip.h:789
int imr_ifindex
Network interface index.
Definition net_ip.h:792
struct net_in_addr imr_address
IP address of local interface.
Definition net_ip.h:791
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:790
Struct used when joining or leaving a IPv6 multicast group.
Definition net_ip.h:806
struct net_in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition net_ip.h:808
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition net_ip.h:811
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:817
uint16_t mr_type
Packet type (action).
Definition net_ip.h:822
uint8_t mr_address[NET_LINK_ADDR_MAX_LENGTH]
Physical layer address.
Definition net_ip.h:828
uint16_t mr_alen
Address length.
Definition net_ip.h:825
int mr_ifindex
Network interface index.
Definition net_ip.h:819
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:455
net_sa_family_t sa_family
Address family.
Definition net_ip.h:456
IPv6/IPv4 network connection tuple.
Definition net_ip.h:574
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition net_ip.h:575
uint16_t local_port
UDP/TCP local port.
Definition net_ip.h:578
enum net_ip_protocol ip_proto
IP protocol.
Definition net_ip.h:579
uint16_t remote_port
UDP/TCP remote port.
Definition net_ip.h:577
struct net_addr * local_addr
IPv6/IPv4 local address.
Definition net_ip.h:576
Byte order helpers.
Misc utilities.
Macros to abstract toolchain specific capabilities.