13#ifndef ZEPHYR_INCLUDE_NET_NET_IP_H_
14#define ZEPHYR_INCLUDE_NET_NET_IP_H_
40#define NET_VLAN_TAG_UNSPEC 0x0fff
51#define PF_UNIX PF_LOCAL
54#define AF_UNSPEC PF_UNSPEC
55#define AF_INET PF_INET
56#define AF_INET6 PF_INET6
57#define AF_PACKET PF_PACKET
59#define AF_NET_MGMT PF_NET_MGMT
60#define AF_LOCAL PF_LOCAL
61#define AF_UNIX PF_UNIX
99#define ntohs(x) sys_be16_to_cpu(x)
107#define ntohl(x) sys_be32_to_cpu(x)
115#define ntohll(x) sys_be64_to_cpu(x)
123#define htons(x) sys_cpu_to_be16(x)
131#define htonl(x) sys_cpu_to_be32(x)
139#define htonll(x) sys_cpu_to_be64(x)
151#define NET_IPV6_ADDR_SIZE 16
164#define NET_IPV4_ADDR_SIZE 4
170#ifndef __socklen_t_defined
172#define __socklen_t_defined
209struct sockaddr_in6_ptr {
217struct sockaddr_in_ptr {
224struct sockaddr_ll_ptr {
234struct sockaddr_can_ptr {
241#if !defined(HAVE_IOVEC)
274#define ALIGN_H(x) ROUND_UP(x, __alignof__(struct cmsghdr))
277#define ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
282#if !defined(CMSG_FIRSTHDR)
288#define CMSG_FIRSTHDR(msghdr) \
289 ((msghdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
290 (struct cmsghdr *)((msghdr)->msg_control) : NULL)
293#if !defined(CMSG_NXTHDR)
298#define CMSG_NXTHDR(msghdr, cmsg) \
299 (((cmsg) == NULL) ? CMSG_FIRSTHDR(msghdr) : \
300 (((uint8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) + \
301 ALIGN_D(sizeof(struct cmsghdr)) > \
302 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
304 (struct cmsghdr *)((uint8_t *)(cmsg) + \
305 ALIGN_H((cmsg)->cmsg_len))))
308#if !defined(CMSG_DATA)
316#define CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + ALIGN_D(sizeof(struct cmsghdr)))
319#if !defined(CMSG_SPACE)
324#define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + ALIGN_H(length))
327#if !defined(CMSG_LEN)
333#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + length)
340#define PACKET_BROADCAST 1
341#define PACKET_MULTICAST 2
342#define PACKET_OTHERHOST 3
343#define PACKET_OUTGOING 4
344#define PACKET_LOOPBACK 5
345#define PACKET_FASTROUTE 6
348#define ARPHRD_ETHER 1
353#if defined(CONFIG_NET_IPV4)
354#undef NET_SOCKADDR_MAX_SIZE
355#undef NET_SOCKADDR_PTR_MAX_SIZE
356#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in))
357#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in_ptr))
360#if defined(CONFIG_NET_SOCKETS_PACKET)
361#undef NET_SOCKADDR_MAX_SIZE
362#undef NET_SOCKADDR_PTR_MAX_SIZE
363#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_ll))
364#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_ll_ptr))
367#if defined(CONFIG_NET_IPV6)
368#undef NET_SOCKADDR_MAX_SIZE
369#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
370#if !defined(CONFIG_NET_SOCKETS_PACKET)
371#undef NET_SOCKADDR_PTR_MAX_SIZE
372#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
376#if !defined(CONFIG_NET_IPV4)
377#if !defined(CONFIG_NET_IPV6)
378#if !defined(CONFIG_NET_SOCKETS_PACKET)
379#define NET_SOCKADDR_MAX_SIZE (sizeof(struct sockaddr_in6))
380#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct sockaddr_in6_ptr))
391 char data[NET_SOCKADDR_MAX_SIZE -
sizeof(
sa_family_t)];
399 char data[NET_SOCKADDR_PTR_MAX_SIZE -
sizeof(
sa_family_t)];
403struct sockaddr_storage {
405 char data[NET_SOCKADDR_MAX_SIZE -
sizeof(
sa_family_t)];
411 char sun_path[NET_SOCKADDR_MAX_SIZE -
sizeof(
sa_family_t)];
423extern const struct in6_addr in6addr_any;
426extern const struct in6_addr in6addr_loopback;
431#define IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, \
432 0, 0, 0, 0, 0, 0, 0 } } }
435#define IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, \
436 0, 0, 0, 0, 0, 0, 0, 0, 1 } } }
442#define INADDR_ANY_INIT { { { INADDR_ANY } } }
445#define INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
448#define INET_ADDRSTRLEN 16
452#define INET6_ADDRSTRLEN 46
457#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")
458#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
467#if defined(CONFIG_NET_NATIVE_IPV6)
491#define NET_MAX_PRIORITIES 8
537struct net_ipv6_frag_hdr {
583static inline const char *net_addr_type2str(
enum net_addr_type type)
603#define NET_IPV6_NEXTHDR_HBHO 0
604#define NET_IPV6_NEXTHDR_DESTO 60
605#define NET_IPV6_NEXTHDR_ROUTING 43
606#define NET_IPV6_NEXTHDR_FRAG 44
607#define NET_IPV6_NEXTHDR_NONE 59
614 struct net_ipv4_hdr *ipv4;
615 struct net_ipv6_hdr *ipv6;
618union net_proto_header {
619 struct net_udp_hdr *udp;
620 struct net_tcp_hdr *tcp;
623#define NET_UDPH_LEN 8
624#define NET_TCPH_LEN 20
625#define NET_ICMPH_LEN 4
627#define NET_IPV6H_LEN 40
628#define NET_ICMPV6H_LEN NET_ICMPH_LEN
629#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN)
630#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN)
631#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN)
632#define NET_IPV6_FRAGH_LEN 8
634#define NET_IPV4H_LEN 20
635#define NET_ICMPV4H_LEN NET_ICMPH_LEN
636#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN)
637#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN)
638#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN)
640#define NET_IPV6H_LENGTH_OFFSET 0x04
642#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8
643#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff
644#define NET_IPV4_MORE_FRAG_MASK 0x2000
645#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000
658 return UNALIGNED_GET(&addr->
s6_addr32[0]) == 0 &&
659 UNALIGNED_GET(&addr->
s6_addr32[1]) == 0 &&
660 UNALIGNED_GET(&addr->
s6_addr32[2]) == 0 &&
673 return addr->
s6_addr[0] == 0xFF;
732 if (
memcmp(addr1, addr2, bytes)) {
744 mask = (
uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
746 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
761 uint8_t bits = 128 - prefix_len;
762 uint8_t bytes = prefix_len / 8U;
767 memcpy(outaddr, inaddr, bytes);
777 mask = (
uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
778 outaddr[bytes] = inaddr[bytes] & mask;
790 return addr->
s4_addr[0] == 127U;
802 return UNALIGNED_GET(&addr->
s_addr) == 0;
814 return (
ntohl(UNALIGNED_GET(&addr->
s_addr)) & 0xF0000000) == 0xE0000000;
826 return (
ntohl(UNALIGNED_GET(&addr->
s_addr)) & 0xFFFF0000) == 0xA9FE0000;
840 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
842 masked_24 =
ntohl(UNALIGNED_GET(&addr->
s_addr)) & 0xFFFFFF00;
843 masked_16 = masked_24 & 0xFFFF0000;
844 masked_12 = masked_24 & 0xFFF00000;
845 masked_10 = masked_24 & 0xFFC00000;
846 masked_8 = masked_24 & 0xFF000000;
848 return masked_8 == 0x0A000000 ||
849 masked_10 == 0x64400000 ||
850 masked_12 == 0xAC100000 ||
851 masked_16 == 0xC0A80000 ||
852 masked_24 == 0xC0000200 ||
853 masked_24 == 0xC0336400 ||
854 masked_24 == 0xCB007100;
865#define net_ipaddr_copy(dest, src) \
866 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
903 return UNALIGNED_GET(&addr1->
s_addr) == UNALIGNED_GET(&addr2->
s_addr);
918 (
const struct in_addr *)addr2);
984 return addr->
s6_addr[0] == 0xFD;
996 return (addr->
s6_addr[0] & 0xE0) == 0x20;
1013 masked_7 = masked_32 & 0xfc000000;
1015 return masked_32 == 0x20010db8 ||
1016 masked_7 == 0xfc000000;
1070#if defined(CONFIG_NET_NATIVE_IPV4)
1124 return UNALIGNED_GET(&addr->
s6_addr32[0]) == 0 &&
1125 UNALIGNED_GET(&addr->
s6_addr32[1]) == 0 &&
1126 UNALIGNED_GET(&addr->
s6_addr32[2]) == 0 &&
1127 UNALIGNED_GET(&addr->
s6_addr32[3]) == 0;
1140 return UNALIGNED_GET(&addr->
s6_addr32[0]) ==
htonl(0xff020000) &&
1141 UNALIGNED_GET(&addr->
s6_addr32[1]) == 0x00000000 &&
1160 return (addr->
s6_addr[0] == 0xff) && ((addr->
s6_addr[1] & 0xF) == scope);
1175 return (addr_1->
s6_addr[0] == 0xff) && (addr_2->
s6_addr[0] == 0xff) &&
1274 return UNALIGNED_GET(&addr->
s6_addr16[1]) ==
group->s6_addr16[1] &&
1293 static const struct in6_addr all_nodes_mcast_group = {
1294 { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1295 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }
1429 if (UNALIGNED_GET(&addr->
s6_addr32[0]) == 0 &&
1430 UNALIGNED_GET(&addr->
s6_addr32[1]) == 0 &&
1431 UNALIGNED_GET(&addr->
s6_addr16[5]) == 0xffff) {
1450 switch (lladdr->
len) {
1494 if (!addr || !lladdr) {
1498 switch (lladdr->
len) {
1572 return (
struct sockaddr_in6_ptr *)addr;
1586 return (
struct sockaddr_in_ptr *)addr;
1600 return (
struct sockaddr_ll_ptr *)addr;
1614 return (
struct sockaddr_can_ptr *)addr;
1644 char *dst,
size_t size);
1694 return (
int32_t)(seq1 - seq2);
1756 static const uint8_t vlan2priority[] = {
1808#if defined(CONFIG_NET_IPV6_PE)
1815 ARG_UNUSED(is_denylist);
1828#if defined(CONFIG_NET_IPV6_PE)
1843#include <zephyr/syscalls/net_ip.h>
static bool net_ipv6_is_my_addr(struct in6_addr *addr)
Check if IPv6 address is found in one of the network interfaces.
Definition net_ip.h:689
struct net_if_addr * net_if_ipv4_addr_lookup(const struct in_addr *addr, struct net_if **iface)
static void net_ipv6_addr_create(struct in6_addr *addr, uint16_t addr0, uint16_t addr1, uint16_t addr2, uint16_t addr3, uint16_t addr4, uint16_t addr5, uint16_t addr6, uint16_t addr7)
Construct an IPv6 address from eight 16-bit words.
Definition net_ip.h:1369
static bool net_ipv4_addr_cmp(const struct in_addr *addr1, const struct in_addr *addr2)
Compare two IPv4 addresses.
Definition net_ip.h:900
#define NET_IPV4_ADDR_SIZE
Binary size of the IPv4 address.
Definition net_ip.h:164
struct net_if_addr * net_if_ipv6_addr_lookup(const struct in6_addr *addr, struct net_if **iface)
static bool net_ipv6_is_addr_mcast_org(const struct in6_addr *addr)
Check if the IPv6 address is an organization scope multicast address (FFx8::).
Definition net_ip.h:1256
static enum net_priority net_vlan2priority(uint8_t priority)
Convert network packet VLAN priority to network packet priority so we can place the packet into corre...
Definition net_ip.h:1753
static int net_ipv6_pe_add_filter(struct in6_addr *addr, bool is_denylist)
Add IPv6 prefix as a privacy extension filter.
Definition net_ip.h:1811
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition net_ip.h:1692
static bool net_ipv6_is_addr_mcast(const struct in6_addr *addr)
Check if the IPv6 address is a multicast address.
Definition net_ip.h:671
#define NET_IPV6_ADDR_SIZE
Binary size of the IPv6 address.
Definition net_ip.h:151
int net_addr_pton(sa_family_t family, const char *src, void *dst)
Convert a string to IP address.
unsigned short int sa_family_t
Socket address family type.
Definition net_ip.h:167
static void net_ipv6_addr_create_ll_allrouters_mcast(struct in6_addr *addr)
Create link local allrouters multicast IPv6 address.
Definition net_ip.h:1400
char * net_addr_ntop(sa_family_t family, const void *src, char *dst, size_t size)
Convert IP address to string form.
net_addr_state
What is the current state of the network address.
Definition net_ip.h:503
static bool net_ipv4_addr_cmp_raw(const uint8_t *addr1, const uint8_t *addr2)
Compare two raw IPv4 address buffers.
Definition net_ip.h:914
static bool net_ipv6_addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2)
Compare two IPv6 addresses.
Definition net_ip.h:929
static bool net_ipv6_is_addr_mcast_iface_all_nodes(const struct in6_addr *addr)
Check if the IPv6 address is a interface scope all nodes multicast address (FF01::1).
Definition net_ip.h:1311
static bool net_ipv4_is_my_addr(const struct in_addr *addr)
Check if the IPv4 address is assigned to any network interface in the system.
Definition net_ip.h:1103
static bool net_ipv6_is_same_mcast_scope(const struct in6_addr *addr_1, const struct in6_addr *addr_2)
Check if the IPv6 addresses have the same multicast scope (FFyx::).
Definition net_ip.h:1172
static void net_ipv6_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv6 address raw buffer.
Definition net_ip.h:886
static bool net_ipv6_is_addr_mcast_mesh(const struct in6_addr *addr)
Check if the IPv6 address is a mesh-local scope multicast address (FFx3::).
Definition net_ip.h:1228
static struct sockaddr_in_ptr * net_sin_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in_ptr from sockaddr_ptr.
Definition net_ip.h:1584
const struct in_addr * net_ipv4_broadcast_address(void)
Return pointer to broadcast (all bits ones) IPv4 address.
static void net_ipv6_addr_prefix_mask(const uint8_t *inaddr, uint8_t *outaddr, uint8_t prefix_len)
Get the IPv6 network address via the unicast address and the prefix mask.
Definition net_ip.h:757
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:123
static bool net_ipv6_addr_is_v4_mapped(const struct in6_addr *addr)
Is the IPv6 address an IPv4 mapped one.
Definition net_ip.h:1427
bool net_if_ipv4_addr_mask_cmp(struct net_if *iface, const struct in_addr *addr)
static bool net_ipv6_is_addr_mcast_global(const struct in6_addr *addr)
Check if the IPv6 address is a global multicast address (FFxE::/16).
Definition net_ip.h:1186
static void net_ipv6_addr_create_ll_allnodes_mcast(struct in6_addr *addr)
Create link local allnodes multicast IPv6 address.
Definition net_ip.h:1390
static bool net_ipv6_is_addr_solicited_node(const struct in6_addr *addr)
Check if the IPv6 address is solicited node multicast address FF02:0:0:0:0:1:FFXX:XXXX defined in RFC...
Definition net_ip.h:1138
static void net_ipv6_addr_create_solicited_node(const struct in6_addr *src, struct in6_addr *dst)
Create solicited node IPv6 multicast address FF02:0:0:0:0:1:FFXX:XXXX defined in RFC 3513.
Definition net_ip.h:1341
static bool net_ipv6_is_addr_mcast_group(const struct in6_addr *addr, const struct in6_addr *group)
Check if the IPv6 address belongs to certain multicast group.
Definition net_ip.h:1271
static bool net_ipv6_is_addr_mcast_site(const struct in6_addr *addr)
Check if the IPv6 address is a site scope multicast address (FFx5::).
Definition net_ip.h:1242
static bool net_ipv6_is_sl_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a site local address.
Definition net_ip.h:969
static void net_ipv6_addr_create_iid(struct in6_addr *addr, struct net_linkaddr *lladdr)
Create IPv6 address interface identifier.
Definition net_ip.h:1444
static bool net_ipv4_is_private_addr(const struct in_addr *addr)
Check if the given IPv4 address is from a private address range.
Definition net_ip.h:838
static bool net_ipv6_is_addr_mcast_link(const struct in6_addr *addr)
Check if the IPv6 address is a link local scope multicast address (FFx2::).
Definition net_ip.h:1214
static bool net_ipv4_addr_mask_cmp(struct net_if *iface, const struct in_addr *addr)
Check if the given address belongs to same subnet that has been configured for the interface.
Definition net_ip.h:1053
net_ip_protocol_secure
Protocol numbers for TLS protocols.
Definition net_ip.h:77
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:865
static int net_ipv6_pe_del_filter(struct in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition net_ip.h:1831
net_ip_mtu
IP Maximum Transfer Unit.
Definition net_ip.h:463
int net_rx_priority2tc(enum net_priority prio)
Convert Rx network packet priority to traffic class so we can place the packet into correct Rx queue.
static bool net_ipv4_is_addr_loopback(struct in_addr *addr)
Check if the IPv4 address is a loopback address (127.0.0.0/8).
Definition net_ip.h:788
int net_bytes_from_str(uint8_t *buf, int buf_len, const char *src)
Convert a string of hex values to array of bytes.
static uint8_t net_priority2vlan(enum net_priority priority)
Convert network packet priority to network packet VLAN priority.
Definition net_ip.h:1782
static void net_ipv6_addr_create_v4_mapped(const struct in_addr *addr4, struct in6_addr *addr6)
Create IPv4 mapped IPv6 address.
Definition net_ip.h:1411
bool net_if_ipv4_is_addr_bcast(struct net_if *iface, const struct in_addr *addr)
static bool net_ipv6_is_prefix(const uint8_t *addr1, const uint8_t *addr2, uint8_t length)
Check if two IPv6 addresses are same when compared after prefix mask.
Definition net_ip.h:719
bool net_ipaddr_parse(const char *str, size_t str_len, struct sockaddr *addr)
Parse a string that contains either IPv4 or IPv6 address and optional port, and store the information...
int net_port_set_default(struct sockaddr *addr, uint16_t default_port)
Set the default port in the sockaddr structure.
static bool net_ipv6_is_addr_loopback(struct in6_addr *addr)
Check if the IPv6 address is a loopback address (::1).
Definition net_ip.h:656
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition net_ip.h:1707
net_sock_type
Socket type.
Definition net_ip.h:87
const struct in6_addr * net_ipv6_unspecified_address(void)
Return pointer to any (all bits zeros) IPv6 address.
static bool net_ipv6_is_global_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a global address.
Definition net_ip.h:994
static bool net_ipv6_is_addr_mcast_link_all_nodes(const struct in6_addr *addr)
Check if the IPv6 address is a link local scope all nodes multicast address (FF02::1).
Definition net_ip.h:1327
const char * net_family2str(sa_family_t family)
Return network address family value as a string.
static bool net_ipv4_is_ll_addr(const struct in_addr *addr)
Check if the given IPv4 address is a link local address.
Definition net_ip.h:824
static struct sockaddr_can_ptr * net_can_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_can_ptr from sockaddr_ptr.
Definition net_ip.h:1612
#define ntohl(x)
Convert 32-bit value from network to host byte order.
Definition net_ip.h:107
static bool net_ipv4_is_addr_bcast(struct net_if *iface, const struct in_addr *addr)
Check if the given IPv4 address is a broadcast address.
Definition net_ip.h:1081
static bool net_ipv6_is_ll_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a link local address.
Definition net_ip.h:957
static struct sockaddr_in * net_sin(const struct sockaddr *addr)
Get sockaddr_in from sockaddr.
Definition net_ip.h:1556
const struct in_addr * net_ipv4_unspecified_address(void)
Return pointer to any (all bits zeros) IPv4 address.
static bool net_ipv6_is_addr_mcast_all_nodes_group(const struct in6_addr *addr)
Check if the IPv6 address belongs to the all nodes multicast group.
Definition net_ip.h:1291
size_t socklen_t
Length of a socket address.
Definition net_ip.h:171
static bool net_ipv6_is_private_addr(const struct in6_addr *addr)
Check if the given IPv6 address is from a private/local address range.
Definition net_ip.h:1008
static struct sockaddr_ll_ptr * net_sll_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_ll_ptr from sockaddr_ptr.
Definition net_ip.h:1598
static struct sockaddr_in6 * net_sin6(const struct sockaddr *addr)
Get sockaddr_in6 from sockaddr.
Definition net_ip.h:1543
#define ntohs(x)
Convert 16-bit value from network to host byte order.
Definition net_ip.h:99
struct net_if_mcast_addr * net_if_ipv6_maddr_lookup(const struct in6_addr *addr, struct net_if **iface)
static bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
Check if the IPv4 address is unspecified (all bits zero)
Definition net_ip.h:800
static bool net_ipv6_is_addr_mcast_scope(const struct in6_addr *addr, int scope)
Check if the IPv6 address is a given scope multicast address (FFyx::).
Definition net_ip.h:1157
static bool net_ipv6_is_ula_addr(const struct in6_addr *addr)
Check if the given IPv6 address is a unique local address.
Definition net_ip.h:982
static bool net_ipv6_is_addr_mcast_iface(const struct in6_addr *addr)
Check if the IPv6 address is a interface scope multicast address (FFx1::).
Definition net_ip.h:1200
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:131
int net_tx_priority2tc(enum net_priority prio)
Convert Tx network packet priority to traffic class so we can place the packet into correct Tx queue.
static struct sockaddr_in6_ptr * net_sin6_ptr(const struct sockaddr_ptr *addr)
Get sockaddr_in6_ptr from sockaddr_ptr.
Definition net_ip.h:1570
net_priority
Network packet priority settings described in IEEE 802.1Q Annex I.1.
Definition net_ip.h:480
static bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
Check if the IPv4 address is a multicast address.
Definition net_ip.h:812
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
static bool net_ipv6_addr_based_on_ll(const struct in6_addr *addr, const struct net_linkaddr *lladdr)
Check if given address is based on link layer address.
Definition net_ip.h:1491
static void net_ipv4_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv4 address raw buffer.
Definition net_ip.h:874
static bool net_ipv6_is_my_maddr(struct in6_addr *maddr)
Check if IPv6 multicast address is found in one of the network interfaces.
Definition net_ip.h:705
static bool net_ipv6_addr_cmp_raw(const uint8_t *addr1, const uint8_t *addr2)
Compare two raw IPv6 address buffers.
Definition net_ip.h:943
static bool net_ipv6_is_addr_unspecified(const struct in6_addr *addr)
Check if the IPv6 address is unspecified (all bits zero)
Definition net_ip.h:1122
net_addr_type
How the network address is assigned to network interface.
Definition net_ip.h:511
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition net_ip.h:504
@ NET_ADDR_TENTATIVE
Tentative address
Definition net_ip.h:505
@ NET_ADDR_DEPRECATED
Deprecated address
Definition net_ip.h:507
@ NET_ADDR_PREFERRED
Preferred address
Definition net_ip.h:506
@ IPPROTO_TLS_1_1
TLS 1.1 protocol.
Definition net_ip.h:79
@ IPPROTO_TLS_1_0
TLS 1.0 protocol.
Definition net_ip.h:78
@ IPPROTO_DTLS_1_0
DTLS 1.0 protocol.
Definition net_ip.h:82
@ IPPROTO_TLS_1_3
TLS 1.3 protocol.
Definition net_ip.h:81
@ IPPROTO_TLS_1_2
TLS 1.2 protocol.
Definition net_ip.h:80
@ IPPROTO_DTLS_1_2
DTLS 1.2 protocol.
Definition net_ip.h:83
@ NET_IPV4_MTU
IPv4 MTU length.
Definition net_ip.h:476
@ NET_IPV6_MTU
IPv6 MTU length.
Definition net_ip.h:470
@ SOCK_DGRAM
Datagram socket type.
Definition net_ip.h:89
@ SOCK_RAW
RAW socket type
Definition net_ip.h:90
@ SOCK_STREAM
Stream socket type
Definition net_ip.h:88
@ NET_PRIORITY_NC
Network control (highest)
Definition net_ip.h:488
@ NET_PRIORITY_IC
Internetwork control
Definition net_ip.h:487
@ NET_PRIORITY_CA
Critical applications
Definition net_ip.h:484
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter
Definition net_ip.h:486
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition net_ip.h:485
@ NET_PRIORITY_BE
Best effort (default)
Definition net_ip.h:482
@ NET_PRIORITY_EE
Excellent effort
Definition net_ip.h:483
@ NET_PRIORITY_BK
Background (lowest)
Definition net_ip.h:481
@ IPPROTO_IP
IP protocol (pseudo-val for setsockopt()
Definition net_ip.h:65
@ IPPROTO_RAW
RAW IP packets
Definition net_ip.h:73
@ IPPROTO_IPIP
IPIP tunnels
Definition net_ip.h:68
@ IPPROTO_TCP
TCP protocol
Definition net_ip.h:69
@ IPPROTO_IGMP
IGMP protocol
Definition net_ip.h:67
@ IPPROTO_ICMP
ICMP protocol
Definition net_ip.h:66
@ IPPROTO_IPV6
IPv6 protocol
Definition net_ip.h:71
@ IPPROTO_UDP
UDP protocol
Definition net_ip.h:70
@ IPPROTO_ICMPV6
ICMPv6 protocol.
Definition net_ip.h:72
@ NET_ADDR_ANY
Default value.
Definition net_ip.h:513
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition net_ip.h:521
@ NET_ADDR_DHCP
Address is from DHCP.
Definition net_ip.h:517
@ NET_ADDR_MANUAL
Manually set address.
Definition net_ip.h:519
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition net_ip.h:515
@ NET_LINK_IEEE802154
IEEE 802.15.4 link address.
Definition net_linkaddr.h:53
@ NET_LINK_ETHERNET
Ethernet link address.
Definition net_linkaddr.h:57
#define ARRAY_SIZE(array)
Number of elements in the given array.
Definition util.h:111
#define ENOTSUP
Unsupported value.
Definition errno.h:114
Public API for network link address.
flags
Definition parser.h:96
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
void * memset(void *buf, int c, size_t n)
int memcmp(const void *m1, const void *m2, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
Control message ancillary data.
Definition net_ip.h:261
int cmsg_type
Protocol-specific type.
Definition net_ip.h:264
socklen_t cmsg_len
Number of bytes, including header.
Definition net_ip.h:262
z_max_align_t cmsg_data[]
Flexible array member to force alignment of cmsghdr.
Definition net_ip.h:265
int cmsg_level
Originating protocol.
Definition net_ip.h:263
Group structure.
Definition grp.h:18
IPv6 address struct.
Definition net_ip.h:142
uint8_t s6_addr[16]
IPv6 address buffer.
Definition net_ip.h:144
uint32_t s6_addr32[4]
In big endian.
Definition net_ip.h:146
uint16_t s6_addr16[8]
In big endian.
Definition net_ip.h:145
IPv4 address struct.
Definition net_ip.h:154
uint8_t s4_addr[4]
IPv4 address buffer.
Definition net_ip.h:156
uint32_t s_addr
In big endian, for POSIX compatibility.
Definition net_ip.h:159
uint16_t s4_addr16[2]
In big endian.
Definition net_ip.h:157
uint32_t s4_addr32[1]
In big endian.
Definition net_ip.h:158
IO vector array element.
Definition net_ip.h:243
void * iov_base
Pointer to data.
Definition net_ip.h:244
size_t iov_len
Length of the data.
Definition net_ip.h:245
Message struct.
Definition net_ip.h:250
struct iovec * msg_iov
Scatter/gather array.
Definition net_ip.h:253
socklen_t msg_namelen
Size of socket address.
Definition net_ip.h:252
void * msg_name
Optional socket address, big endian.
Definition net_ip.h:251
int msg_flags
Flags on received message.
Definition net_ip.h:257
size_t msg_controllen
Ancillary data buffer len.
Definition net_ip.h:256
size_t msg_iovlen
Number of elements in msg_iov.
Definition net_ip.h:254
void * msg_control
Ancillary data.
Definition net_ip.h:255
Network Interface unicast IP addresses.
Definition net_if.h:54
IP and other configuration related data for network interface.
Definition net_if.h:557
Network Interface multicast IP addresses.
Definition net_if.h:145
Network Interface structure.
Definition net_if.h:680
Hardware link address structure.
Definition net_linkaddr.h:69
uint8_t * addr
The array of byte representing the address.
Definition net_linkaddr.h:71
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:77
uint8_t len
Length of that address array.
Definition net_linkaddr.h:74
IPv6/IPv4 network connection tuple.
Definition net_ip.h:494
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition net_ip.h:495
uint16_t local_port
UDP/TCP local port
Definition net_ip.h:498
enum net_ip_protocol ip_proto
IP protocol
Definition net_ip.h:499
uint16_t remote_port
UDP/TCP remote port
Definition net_ip.h:497
struct net_addr * local_addr
IPv6/IPv4 local address
Definition net_ip.h:496
Socket address struct for IPv6.
Definition net_ip.h:181
uint8_t sin6_scope_id
Interfaces for a scope.
Definition net_ip.h:185
struct in6_addr sin6_addr
IPv6 address
Definition net_ip.h:184
uint16_t sin6_port
Port number
Definition net_ip.h:183
sa_family_t sin6_family
AF_INET6
Definition net_ip.h:182
Socket address struct for IPv4.
Definition net_ip.h:189
uint16_t sin_port
Port number
Definition net_ip.h:191
struct in_addr sin_addr
IPv4 address.
Definition net_ip.h:192
sa_family_t sin_family
AF_INET
Definition net_ip.h:190
Socket address struct for packet socket.
Definition net_ip.h:196
uint8_t sll_pkttype
Packet type
Definition net_ip.h:201
uint16_t sll_hatype
ARP hardware type
Definition net_ip.h:200
sa_family_t sll_family
Always AF_PACKET
Definition net_ip.h:197
uint16_t sll_protocol
Physical-layer protocol
Definition net_ip.h:198
int sll_ifindex
Interface number
Definition net_ip.h:199
uint8_t sll_halen
Length of address
Definition net_ip.h:202
uint8_t sll_addr[8]
Physical-layer address, big endian.
Definition net_ip.h:203
Generic sockaddr struct.
Definition net_ip.h:388
sa_family_t sa_family
Address family.
Definition net_ip.h:389