13#ifndef ZEPHYR_INCLUDE_NET_NET_IP_H_
14#define ZEPHYR_INCLUDE_NET_NET_IP_H_
40#define NET_VLAN_TAG_UNSPEC 0x0fff
44#define NET_PF_UNSPEC 0
47#define NET_PF_PACKET 3
49#define NET_PF_NET_MGMT 5
51#define NET_PF_UNIX NET_PF_LOCAL
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
100#define net_ntohs(x) sys_be16_to_cpu(x)
108#define net_ntohl(x) sys_be32_to_cpu(x)
116#define net_ntohll(x) sys_be64_to_cpu(x)
124#define net_htons(x) sys_cpu_to_be16(x)
132#define net_htonl(x) sys_cpu_to_be32(x)
140#define net_htonll(x) sys_cpu_to_be64(x)
152#define NET_IPV6_ADDR_SIZE 16
165#define NET_IPV4_ADDR_SIZE 4
247struct net_sockaddr_in6_ptr {
255struct net_sockaddr_in_ptr {
258 struct net_in_addr *sin_addr;
262struct net_sockaddr_ll_ptr {
273struct net_sockaddr_un_ptr {
278struct net_sockaddr_can_ptr {
285#if !defined(HAVE_IOVEC)
317#if !defined(NET_ALIGN_H)
318#define NET_ALIGN_H(x) ROUND_UP(x, __alignof__(struct net_cmsghdr))
320#if !defined(NET_ALIGN_D)
321#define NET_ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
326#if !defined(NET_CMSG_FIRSTHDR)
332#define NET_CMSG_FIRSTHDR(msghdr) \
333 ((msghdr)->msg_controllen >= sizeof(struct net_cmsghdr) ? \
334 (struct net_cmsghdr *)((msghdr)->msg_control) : NULL)
337#if !defined(NET_CMSG_NXTHDR)
342#define NET_CMSG_NXTHDR(msghdr, cmsg) \
343 (((cmsg) == NULL) ? NET_CMSG_FIRSTHDR(msghdr) : \
344 (((uint8_t *)(cmsg) + NET_ALIGN_H((cmsg)->cmsg_len) + \
345 NET_ALIGN_D(sizeof(struct net_cmsghdr)) > \
346 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
348 (struct net_cmsghdr *)((uint8_t *)(cmsg) + \
349 NET_ALIGN_H((cmsg)->cmsg_len))))
352#if !defined(NET_CMSG_DATA)
360#define NET_CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + NET_ALIGN_D(sizeof(struct net_cmsghdr)))
363#if !defined(NET_CMSG_SPACE)
368#define NET_CMSG_SPACE(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + NET_ALIGN_H(length))
371#if !defined(NET_CMSG_LEN)
377#define NET_CMSG_LEN(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + length)
383#define NET_PACKET_HOST 0
384#define NET_PACKET_BROADCAST 1
385#define NET_PACKET_MULTICAST 2
386#define NET_PACKET_OTHERHOST 3
387#define NET_PACKET_OUTGOING 4
388#define NET_PACKET_LOOPBACK 5
389#define NET_PACKET_FASTROUTE 6
392#define NET_ARPHRD_ETHER 1
393#define NET_ARPHRD_PPP 512
398#if defined(CONFIG_NET_IPV4)
399#undef NET_SOCKADDR_MAX_SIZE
400#undef NET_SOCKADDR_PTR_MAX_SIZE
401#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in))
402#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in_ptr))
405#if defined(CONFIG_NET_SOCKETS_PACKET)
406#undef NET_SOCKADDR_MAX_SIZE
407#undef NET_SOCKADDR_PTR_MAX_SIZE
408#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_ll))
409#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_ll_ptr))
412#if defined(CONFIG_NET_IPV6)
413#undef NET_SOCKADDR_MAX_SIZE
414#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in6))
415#if !defined(CONFIG_NET_SOCKETS_PACKET)
416#undef NET_SOCKADDR_PTR_MAX_SIZE
417#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in6_ptr))
421#if defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
422#define UNIX_PATH_MAX 108
423#undef NET_SOCKADDR_MAX_SIZE
425#define NET_SOCKADDR_MAX_SIZE (UNIX_PATH_MAX+sizeof(net_sa_family_t))
426#if !defined(CONFIG_NET_SOCKETS_PACKET)
427#undef NET_SOCKADDR_PTR_MAX_SIZE
428#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_un_ptr))
432#if !defined(CONFIG_NET_IPV4)
433#if !defined(CONFIG_NET_IPV6)
434#if !defined(CONFIG_NET_SOCKETS_PACKET)
435#if !defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
436#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in6))
437#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in6_ptr))
445#define SOCKADDR_ALIGN (4)
457struct net_sockaddr_ptr {
463struct net_sockaddr_storage {
469struct net_sockaddr_un {
477#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
478 struct net_in6_addr net_in6_addr;
479 struct net_in_addr net_in_addr;
496#define NET_IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
497 0, 0, 0, 0, 0, 0, 0, 0 } } }
500#define NET_IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
501 0, 0, 0, 0, 0, 0, 0, 1 } } }
504#define NET_INADDR_ANY 0
507#define NET_INADDR_BROADCAST 0xffffffff
510#define NET_INADDR_ANY_INIT { { { NET_INADDR_ANY } } }
513#define NET_INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
516#define NET_INET_ADDRSTRLEN 16
521#define NET_INET6_ADDRSTRLEN 46
526#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxx.xxx.xxx.xxx")
527#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
536#if defined(CONFIG_NET_NATIVE_IPV6)
545#if defined(CONFIG_NET_NATIVE_IPV4)
564#define NET_MAX_PRIORITIES 8
610struct net_ipv6_frag_hdr {
656static inline const char *net_addr_type2str(
enum net_addr_type type)
676#define NET_IPV6_NEXTHDR_HBHO 0
677#define NET_IPV6_NEXTHDR_DESTO 60
678#define NET_IPV6_NEXTHDR_ROUTING 43
679#define NET_IPV6_NEXTHDR_FRAG 44
680#define NET_IPV6_NEXTHDR_NONE 59
687 struct net_ipv4_hdr *ipv4;
688 struct net_ipv6_hdr *ipv6;
691union net_proto_header {
692 struct net_udp_hdr *udp;
693 struct net_tcp_hdr *tcp;
696#define NET_UDPH_LEN 8
697#define NET_TCPH_LEN 20
698#define NET_ICMPH_LEN 4
700#define NET_IPV6H_LEN 40
701#define NET_ICMPV6H_LEN NET_ICMPH_LEN
702#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN)
703#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN)
704#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN)
705#define NET_IPV6_FRAGH_LEN 8
707#define NET_IPV4H_LEN 20
708#define NET_ICMPV4H_LEN NET_ICMPH_LEN
709#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN)
710#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN)
711#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN)
713#define NET_IPV6H_LENGTH_OFFSET 0x04
715#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8
716#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff
717#define NET_IPV4_MORE_FRAG_MASK 0x2000
718#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000
721#if defined(CONFIG_NET_INTERFACE_NAME)
722#define NET_IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
724#if defined(Z_DEVICE_MAX_NAME_LEN)
725#define NET_IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
727#define NET_IFNAMSIZ 1
796static inline bool net_ipv6_is_addr_loopback_raw(
const uint8_t *addr)
798 return UNALIGNED_GET((
uint32_t *)addr) == 0 &&
799 UNALIGNED_GET((
uint32_t *)addr + 1) == 0 &&
800 UNALIGNED_GET((
uint32_t *)addr + 2) == 0 &&
814 return net_ipv6_is_addr_loopback_raw(addr->
s6_addr);
818static inline bool net_ipv6_is_addr_mcast_raw(
const uint8_t *addr)
820 return addr[0] == 0xff;
833 return net_ipv6_is_addr_mcast_raw(addr->
s6_addr);
843static inline bool net_ipv6_is_my_addr_raw(
const uint8_t *addr)
845 return net_if_ipv6_addr_lookup_raw(addr,
NULL) !=
NULL;
902 if (
memcmp(addr1, addr2, bytes)) {
914 mask = (
uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
916 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
931 uint8_t bits = 128 - prefix_len;
932 uint8_t bytes = prefix_len / 8U;
937 memcpy(outaddr, inaddr, bytes);
947 mask = (
uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
948 outaddr[bytes] = inaddr[bytes] & mask;
952static inline bool net_ipv4_is_addr_loopback_raw(
const uint8_t *addr)
954 return addr[0] == 127U;
967 return net_ipv4_is_addr_loopback_raw(addr->
s4_addr);
971static inline bool net_ipv4_is_addr_unspecified_raw(
const uint8_t *addr)
973 return UNALIGNED_GET((
uint32_t *)addr) == 0;
986 return net_ipv4_is_addr_unspecified_raw(addr->
s4_addr);
990static inline bool net_ipv4_is_addr_mcast_raw(
const uint8_t *addr)
1005 return net_ipv4_is_addr_mcast_raw(addr->
s4_addr);
1009static inline bool net_ipv4_is_ll_addr_raw(
const uint8_t *addr)
1024 return net_ipv4_is_ll_addr_raw(addr->
s4_addr);
1038 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
1041 masked_16 = masked_24 & 0xFFFF0000;
1042 masked_12 = masked_24 & 0xFFF00000;
1043 masked_10 = masked_24 & 0xFFC00000;
1044 masked_8 = masked_24 & 0xFF000000;
1046 return masked_8 == 0x0A000000 ||
1047 masked_10 == 0x64400000 ||
1048 masked_12 == 0xAC100000 ||
1049 masked_16 == 0xC0A80000 ||
1050 masked_24 == 0xC0000200 ||
1051 masked_24 == 0xC0336400 ||
1052 masked_24 == 0xCB007100;
1063#define net_ipaddr_copy(dest, src) \
1064 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
1101 return UNALIGNED_GET((
uint32_t *)addr1) == UNALIGNED_GET((
uint32_t *)addr2);
1148static inline bool net_ipv6_is_ll_addr_raw(
const uint8_t *addr)
1163 return net_ipv6_is_ll_addr_raw(addr->
s6_addr);
1188 return addr->
s6_addr[0] == 0xFD;
1200 return (addr->
s6_addr[0] & 0xE0) == 0x20;
1217 masked_7 = masked_32 & 0xfc000000;
1219 return masked_32 == 0x20010db8 ||
1220 masked_7 == 0xfc000000;
1264extern bool net_if_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1267#if defined(CONFIG_NET_NATIVE_IPV4)
1268static inline bool net_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1275 return net_if_ipv4_is_addr_bcast_raw(iface, addr);
1278static inline bool net_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1300#if defined(CONFIG_NET_NATIVE_IPV4)
1325static inline bool net_ipv4_is_my_addr_raw(
const uint8_t *addr)
1329 ret = net_if_ipv4_addr_lookup_raw(addr,
NULL) !=
NULL;
1331 ret = net_ipv4_is_addr_bcast_raw(
NULL, addr);
1363static inline bool net_ipv6_is_addr_unspecified_raw(
const uint8_t *addr)
1365 return UNALIGNED_GET((
uint32_t *)addr) == 0 &&
1366 UNALIGNED_GET((
uint32_t *)addr + 1) == 0 &&
1367 UNALIGNED_GET((
uint32_t *)addr + 2) == 0 &&
1368 UNALIGNED_GET((
uint32_t *)addr + 3) == 0;
1381 return net_ipv6_is_addr_unspecified_raw(addr->
s6_addr);
1385static inline bool net_ipv6_is_addr_solicited_node_raw(
const uint8_t *addr)
1388 UNALIGNED_GET((
uint32_t *)addr + 1) == 0x00000000 &&
1405 return net_ipv6_is_addr_solicited_node_raw(addr->
s6_addr);
1409static inline bool net_ipv6_is_addr_mcast_scope_raw(
const uint8_t *addr,
1412 return (addr[0] == 0xff) && ((addr[1] & 0xF) == scope);
1417static inline int net_ipv6_get_addr_mcast_scope_raw(
const uint8_t *addr)
1419 if (addr[0] == 0xff) {
1420 return (addr[1] & 0xF);
1440 return net_ipv6_is_addr_mcast_scope_raw(addr->
s6_addr, scope);
1455 return (addr_1->
s6_addr[0] == 0xff) && (addr_2->
s6_addr[0] == 0xff) &&
1468 return net_ipv6_get_addr_mcast_scope_raw(addr->
s6_addr);
1472static inline bool net_ipv6_is_addr_mcast_iface_raw(
const uint8_t *addr)
1474 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x01);
1477static inline bool net_ipv6_is_addr_mcast_link_raw(
const uint8_t *addr)
1479 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x02);
1482static inline bool net_ipv6_is_addr_mcast_mesh_raw(
const uint8_t *addr)
1484 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x03);
1487static inline bool net_ipv6_is_addr_mcast_site_raw(
const uint8_t *addr)
1489 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x05);
1492static inline bool net_ipv6_is_addr_mcast_org_raw(
const uint8_t *addr)
1494 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x08);
1581static inline bool net_ipv6_is_addr_mcast_group_raw(
const uint8_t *addr,
1604 return net_ipv6_is_addr_mcast_group_raw(addr->
s6_addr,
group->s6_addr);
1608static inline bool net_ipv6_is_addr_mcast_all_nodes_group_raw(
const uint8_t *addr)
1611 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1612 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1615 return net_ipv6_is_addr_mcast_group_raw(addr, all_nodes_mcast_group);
1630 return net_ipv6_is_addr_mcast_all_nodes_group_raw(addr->
s6_addr);
1650static inline bool net_ipv6_is_addr_mcast_link_all_nodes_raw(
const uint8_t *addr)
1652 return net_ipv6_is_addr_mcast_link_raw(addr) &&
1653 net_ipv6_is_addr_mcast_all_nodes_group_raw(addr);
1769 if (UNALIGNED_GET(&addr->
s6_addr32[0]) == 0 &&
1770 UNALIGNED_GET(&addr->
s6_addr32[1]) == 0 &&
1771 UNALIGNED_GET(&addr->
s6_addr16[5]) == 0xffff) {
1812 uint8_t *network_id,
size_t network_id_len,
1830static inline bool net_ipv6_addr_based_on_ll_raw(
const uint8_t *addr,
1833 if (addr ==
NULL || lladdr ==
NULL) {
1837 switch (lladdr->
len) {
1851 if (!
memcmp(&addr[9], &lladdr->
addr[1], 2) &&
1855 (addr[8] ^ 0x02) == lladdr->
addr[0]) {
1862 if (
sizeof(lladdr->
addr) < 8) {
1868 (addr[8] ^ 0x02) == lladdr->
addr[0]) {
1889 if (addr ==
NULL || lladdr ==
NULL) {
1893 return net_ipv6_addr_based_on_ll_raw(addr->
s6_addr, lladdr);
1944struct net_sockaddr_in6_ptr *
net_sin6_ptr(
const struct net_sockaddr_ptr *addr)
1946 return (
struct net_sockaddr_in6_ptr *)addr;
1958struct net_sockaddr_in_ptr *
net_sin_ptr(
const struct net_sockaddr_ptr *addr)
1960 return (
struct net_sockaddr_in_ptr *)addr;
1972struct net_sockaddr_ll_ptr *
net_sll_ptr(
const struct net_sockaddr_ptr *addr)
1974 return (
struct net_sockaddr_ll_ptr *)addr;
1986struct net_sockaddr_can_ptr *
net_can_ptr(
const struct net_sockaddr_ptr *addr)
1988 return (
struct net_sockaddr_can_ptr *)addr;
2018 char *dst,
size_t size);
2124 return (
int32_t)(seq1 - seq2);
2186 static const uint8_t vlan2priority[] = {
2245 return sizeof(
struct net_sockaddr_un);
2265#if defined(CONFIG_NET_IPV6_PE)
2272 ARG_UNUSED(is_denylist);
2285#if defined(CONFIG_NET_IPV6_PE)
2300#include <zephyr/syscalls/net_ip.h>
2302#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
2303#define ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
2305#undef ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
static 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:1986
#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:1186
static size_t net_family2size(net_sa_family_t family)
Return network address size for a given family.
Definition net_ip.h:2235
#define NET_IPV4_ADDR_SIZE
Binary size of the IPv4 address.
Definition net_ip.h:165
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:2183
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition net_ip.h:2122
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:875
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:152
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:1112
#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:1767
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:1379
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:1547
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:1751
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:1003
net_addr_state
What is the current state of the network address.
Definition net_ip.h:576
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:1098
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:171
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:1212
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:984
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:831
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:1519
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:100
static void net_ipv6_addr_copy_raw(uint8_t *dest, const uint8_t *src)
Copy an IPv6 address raw buffer.
Definition net_ip.h:1084
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:1257
const char * net_family2str(net_sa_family_t family)
Return network address family value as a string.
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:927
#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.
static struct net_sockaddr * net_sad(const struct net_sockaddr_storage *addr)
Get net_sockaddr from net_sockaddr_storage.
Definition net_ip.h:1904
#define net_htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:132
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 struct net_sockaddr_in6 * net_sin6(const struct net_sockaddr *addr)
Get net_sockaddr_in6 from net_sockaddr.
Definition net_ip.h:1917
static 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:1958
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:1350
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:965
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:1022
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:1126
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:1730
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:1786
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:1063
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:1886
net_ip_mtu
IP Maximum Transfer Unit.
Definition net_ip.h:532
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:1466
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:1823
static struct net_sockaddr_in * net_sin(const struct net_sockaddr *addr)
Get net_sockaddr_in from net_sockaddr.
Definition net_ip.h:1930
#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:168
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:2212
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:1561
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:1437
#define SOCKADDR_ALIGN
Definition net_ip.h:445
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:859
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:889
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:812
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:1575
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:2268
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:1601
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition net_ip.h:2137
net_sock_type
Socket type.
Definition net_ip.h:88
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:1403
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:1709
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:1198
static 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:1972
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:1667
const struct net_in_addr * net_ipv4_unspecified_address(void)
Return pointer to any (all bits zeros) IPv4 address.
static 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:1944
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:1628
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:1452
static int net_ipv6_pe_del_filter(struct net_in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition net_ip.h:2288
#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:1161
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:1036
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:1681
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:1533
#define net_ntohl(x)
Convert 32-bit value from network to host byte order.
Definition net_ip.h:108
#define net_htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:124
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:1740
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:553
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:1643
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:1173
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:1072
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:1505
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:1140
net_addr_type
How the network address is assigned to network interface.
Definition net_ip.h:584
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:1311
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition net_ip.h:577
@ NET_ADDR_TENTATIVE
Tentative address.
Definition net_ip.h:578
@ NET_ADDR_DEPRECATED
Deprecated address.
Definition net_ip.h:580
@ NET_ADDR_PREFERRED
Preferred address.
Definition net_ip.h:579
@ 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_DTLS_1_0
DTLS 1.0 protocol.
Definition net_ip.h:83
@ NET_IPV4_MTU
IPv4 MTU length.
Definition net_ip.h:548
@ NET_IPV6_MTU
IPv6 MTU length.
Definition net_ip.h:539
@ NET_SOCK_STREAM
Stream socket type.
Definition net_ip.h:89
@ NET_SOCK_RAW
RAW socket type.
Definition net_ip.h:91
@ NET_SOCK_DGRAM
Datagram socket type.
Definition net_ip.h:90
@ NET_PRIORITY_NC
Network control (highest).
Definition net_ip.h:561
@ NET_PRIORITY_IC
Internetwork control.
Definition net_ip.h:560
@ NET_PRIORITY_CA
Critical applications.
Definition net_ip.h:557
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter.
Definition net_ip.h:559
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition net_ip.h:558
@ NET_PRIORITY_BE
Best effort (default).
Definition net_ip.h:555
@ NET_PRIORITY_EE
Excellent effort.
Definition net_ip.h:556
@ NET_PRIORITY_BK
Background (lowest).
Definition net_ip.h:554
@ 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.
Definition net_ip.h:68
@ NET_ADDR_ANY
Default value.
Definition net_ip.h:586
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition net_ip.h:594
@ NET_ADDR_DHCP
Address is from DHCP.
Definition net_ip.h:590
@ NET_ADDR_MANUAL
Manually set address.
Definition net_ip.h:592
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition net_ip.h:588
@ NET_LINK_ETHERNET
Ethernet link address.
Definition net_linkaddr.h:55
#define ARRAY_SIZE(array)
Number of elements in the given array.
Definition util.h:118
#define ENOTSUP
Unsupported value.
Definition errno.h:114
#define NULL
Definition iar_missing_defs.h:20
#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:305
net_socklen_t cmsg_len
Number of bytes, including header.
Definition net_ip.h:306
int cmsg_level
Originating protocol.
Definition net_ip.h:307
int cmsg_type
Protocol-specific type.
Definition net_ip.h:308
z_max_align_t cmsg_data[]
Flexible array member to force alignment of net_cmsghdr.
Definition net_ip.h:309
Network Interface unicast IP addresses.
Definition net_if.h:56
IP and other configuration related data for network interface.
Definition net_if.h:591
Network Interface multicast IP addresses.
Definition net_if.h:161
Network Interface structure.
Definition net_if.h:731
Interface description structure.
Definition net_ip.h:739
char ifr_name[NET_IFNAMSIZ]
Network interface name.
Definition net_ip.h:740
IPv6 address struct.
Definition net_ip.h:143
uint16_t s6_addr16[8]
In big endian.
Definition net_ip.h:146
uint32_t s6_addr32[4]
In big endian.
Definition net_ip.h:147
uint8_t s6_addr[16]
IPv6 address buffer.
Definition net_ip.h:145
Incoming IPv6 packet information.
Definition net_ip.h:790
unsigned int ipi6_ifindex
Receive interface index.
Definition net_ip.h:792
struct net_in6_addr ipi6_addr
Destination IPv6 address.
Definition net_ip.h:791
IPv4 address struct.
Definition net_ip.h:155
uint16_t s4_addr16[2]
In big endian.
Definition net_ip.h:158
uint32_t s4_addr32[1]
In big endian.
Definition net_ip.h:159
uint32_t s_addr
In big endian, for POSIX compatibility.
Definition net_ip.h:160
uint8_t s4_addr[4]
IPv4 address buffer.
Definition net_ip.h:157
Incoming IPv4 packet information.
Definition net_ip.h:750
unsigned int ipi_ifindex
Network interface index.
Definition net_ip.h:751
struct net_in_addr ipi_addr
Header Destination address.
Definition net_ip.h:753
struct net_in_addr ipi_spec_dst
Local address.
Definition net_ip.h:752
IO vector array element.
Definition net_ip.h:287
void * iov_base
Pointer to data.
Definition net_ip.h:288
size_t iov_len
Length of the data.
Definition net_ip.h:289
Struct used when setting a IPv4 multicast network interface.
Definition net_ip.h:768
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:769
struct net_in_addr imr_interface
IP address of local interface.
Definition net_ip.h:770
Struct used when joining or leaving a IPv4 multicast group.
Definition net_ip.h:759
int imr_ifindex
Network interface index.
Definition net_ip.h:762
struct net_in_addr imr_address
IP address of local interface.
Definition net_ip.h:761
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:760
Struct used when joining or leaving a IPv6 multicast group.
Definition net_ip.h:776
struct net_in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition net_ip.h:778
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition net_ip.h:781
Hardware link address structure.
Definition net_linkaddr.h:72
uint8_t addr[6]
The array of bytes representing the address.
Definition net_linkaddr.h:80
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:74
uint8_t len
The real length of the ll address.
Definition net_linkaddr.h:77
Message struct.
Definition net_ip.h:294
int msg_flags
Flags on received message.
Definition net_ip.h:301
struct net_iovec * msg_iov
Scatter/gather array.
Definition net_ip.h:297
net_socklen_t msg_namelen
Size of socket address.
Definition net_ip.h:296
size_t msg_controllen
Ancillary data buffer len.
Definition net_ip.h:300
void * msg_control
Ancillary data.
Definition net_ip.h:299
void * msg_name
Optional socket address, big endian.
Definition net_ip.h:295
size_t msg_iovlen
Number of elements in msg_iov.
Definition net_ip.h:298
struct net_sockaddr_can - The net_sockaddr structure for CAN sockets.
Definition net_ip.h:205
int can_ifindex
SocketCAN network interface index.
Definition net_ip.h:207
net_sa_family_t can_family
Address family.
Definition net_ip.h:206
Socket address struct for IPv6.
Definition net_ip.h:179
struct net_in6_addr sin6_addr
IPv6 address.
Definition net_ip.h:182
net_sa_family_t sin6_family
NET_AF_INET6.
Definition net_ip.h:180
uint8_t sin6_scope_id
Interfaces for a scope.
Definition net_ip.h:183
uint16_t sin6_port
Port number.
Definition net_ip.h:181
Socket address struct for IPv4.
Definition net_ip.h:187
uint16_t sin_port
Port number.
Definition net_ip.h:189
struct net_in_addr sin_addr
IPv4 address.
Definition net_ip.h:190
net_sa_family_t sin_family
NET_AF_INET.
Definition net_ip.h:188
Socket address struct for packet socket.
Definition net_ip.h:194
uint8_t sll_pkttype
Packet type.
Definition net_ip.h:199
int sll_ifindex
Interface number.
Definition net_ip.h:197
net_sa_family_t sll_family
Always NET_AF_PACKET.
Definition net_ip.h:195
uint16_t sll_hatype
ARP hardware type.
Definition net_ip.h:198
uint8_t sll_halen
Length of address.
Definition net_ip.h:200
uint16_t sll_protocol
Physical-layer protocol.
Definition net_ip.h:196
uint8_t sll_addr[8]
Physical-layer address, big endian.
Definition net_ip.h:201
struct net_sockaddr_nm - The net_sockaddr structure for NET_MGMT sockets
Definition net_ip.h:228
uint64_t nm_mask
net_mgmt mask
Definition net_ip.h:241
int nm_ifindex
Network interface related to this address.
Definition net_ip.h:233
uintptr_t nm_pid
Thread id or similar that is used to separate the different sockets.
Definition net_ip.h:238
net_sa_family_t nm_family
AF_NET_MGMT address family.
Definition net_ip.h:230
Generic sockaddr struct.
Definition net_ip.h:448
net_sa_family_t sa_family
Address family.
Definition net_ip.h:449
IPv6/IPv4 network connection tuple.
Definition net_ip.h:567
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition net_ip.h:568
uint16_t local_port
UDP/TCP local port.
Definition net_ip.h:571
enum net_ip_protocol ip_proto
IP protocol.
Definition net_ip.h:572
uint16_t remote_port
UDP/TCP remote port.
Definition net_ip.h:570
struct net_addr * local_addr
IPv6/IPv4 local address.
Definition net_ip.h:569