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
101#define net_ntohs(x) sys_be16_to_cpu(x)
109#define net_ntohl(x) sys_be32_to_cpu(x)
117#define net_ntohll(x) sys_be64_to_cpu(x)
125#define net_htons(x) sys_cpu_to_be16(x)
133#define net_htonl(x) sys_cpu_to_be32(x)
141#define net_htonll(x) sys_cpu_to_be64(x)
153#define NET_IPV6_ADDR_SIZE 16
166#define NET_IPV4_ADDR_SIZE 4
248struct net_sockaddr_in6_ptr {
256struct net_sockaddr_in_ptr {
259 struct net_in_addr *sin_addr;
263struct net_sockaddr_ll_ptr {
274struct net_sockaddr_un_ptr {
279struct net_sockaddr_can_ptr {
286#if !defined(HAVE_IOVEC)
324#if !defined(NET_ALIGN_H)
325#define NET_ALIGN_H(x) ROUND_UP(x, __alignof__(struct net_cmsghdr))
327#if !defined(NET_ALIGN_D)
328#define NET_ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
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)
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) ? \
355 (struct net_cmsghdr *)((uint8_t *)(cmsg) + \
356 NET_ALIGN_H((cmsg)->cmsg_len))))
359#if !defined(NET_CMSG_DATA)
367#define NET_CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + NET_ALIGN_D(sizeof(struct net_cmsghdr)))
370#if !defined(NET_CMSG_SPACE)
375#define NET_CMSG_SPACE(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + NET_ALIGN_H(length))
378#if !defined(NET_CMSG_LEN)
384#define NET_CMSG_LEN(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + length)
390#define NET_PACKET_HOST 0
391#define NET_PACKET_BROADCAST 1
392#define NET_PACKET_MULTICAST 2
393#define NET_PACKET_OTHERHOST 3
394#define NET_PACKET_OUTGOING 4
395#define NET_PACKET_LOOPBACK 5
396#define NET_PACKET_FASTROUTE 6
399#define NET_ARPHRD_ETHER 1
400#define NET_ARPHRD_PPP 512
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))
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))
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))
428#if defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
429#define UNIX_PATH_MAX 108
430#undef NET_SOCKADDR_MAX_SIZE
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))
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))
452#define SOCKADDR_ALIGN (4)
464struct net_sockaddr_ptr {
470struct net_sockaddr_storage {
476struct net_sockaddr_un {
484#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
485 struct net_in6_addr net_in6_addr;
486 struct net_in_addr net_in_addr;
503#define NET_IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
504 0, 0, 0, 0, 0, 0, 0, 0 } } }
507#define NET_IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
508 0, 0, 0, 0, 0, 0, 0, 1 } } }
511#define NET_INADDR_ANY 0
514#define NET_INADDR_BROADCAST 0xffffffff
517#define NET_INADDR_ANY_INIT { { { NET_INADDR_ANY } } }
520#define NET_INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
523#define NET_INET_ADDRSTRLEN 16
528#define NET_INET6_ADDRSTRLEN 46
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")
543#if defined(CONFIG_NET_NATIVE_IPV6)
552#if defined(CONFIG_NET_NATIVE_IPV4)
571#define NET_MAX_PRIORITIES 8
617struct net_ipv6_frag_hdr {
663static inline const char *net_addr_type2str(
enum net_addr_type type)
683#define NET_IPV6_NEXTHDR_HBHO 0
684#define NET_IPV6_NEXTHDR_DESTO 60
685#define NET_IPV6_NEXTHDR_ROUTING 43
686#define NET_IPV6_NEXTHDR_FRAG 44
687#define NET_IPV6_NEXTHDR_NONE 59
694 struct net_ipv4_hdr *ipv4;
695 struct net_ipv6_hdr *ipv6;
698union net_proto_header {
699 struct net_udp_hdr *udp;
700 struct net_tcp_hdr *tcp;
703#define NET_UDPH_LEN 8
704#define NET_TCPH_LEN 20
705#define NET_ICMPH_LEN 4
707#define NET_IPV6H_LEN 40
708#define NET_ICMPV6H_LEN NET_ICMPH_LEN
709#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN)
710#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN)
711#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN)
712#define NET_IPV6_FRAGH_LEN 8
714#define NET_IPV4H_LEN 20
715#define NET_ICMPV4H_LEN NET_ICMPH_LEN
716#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN)
717#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN)
718#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN)
720#define NET_IPV6H_LENGTH_OFFSET 0x04
722#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8
723#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff
724#define NET_IPV4_MORE_FRAG_MASK 0x2000
725#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000
728#if defined(CONFIG_NET_INTERFACE_NAME)
729#define NET_IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
731#if defined(Z_DEVICE_MAX_NAME_LEN)
732#define NET_IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
734#define NET_IFNAMSIZ 1
803static inline bool net_ipv6_is_addr_loopback_raw(
const uint8_t *addr)
805 return UNALIGNED_GET((
uint32_t *)addr) == 0 &&
806 UNALIGNED_GET((
uint32_t *)addr + 1) == 0 &&
807 UNALIGNED_GET((
uint32_t *)addr + 2) == 0 &&
821 return net_ipv6_is_addr_loopback_raw(addr->
s6_addr);
825static inline bool net_ipv6_is_addr_mcast_raw(
const uint8_t *addr)
827 return addr[0] == 0xff;
840 return net_ipv6_is_addr_mcast_raw(addr->
s6_addr);
850static inline bool net_ipv6_is_my_addr_raw(
const uint8_t *addr)
852 return net_if_ipv6_addr_lookup_raw(addr, NULL) != NULL;
909 if (
memcmp(addr1, addr2, bytes)) {
921 mask = (
uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
923 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
938 uint8_t bits = 128 - prefix_len;
939 uint8_t bytes = prefix_len / 8U;
944 memcpy(outaddr, inaddr, bytes);
954 mask = (
uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
955 outaddr[bytes] = inaddr[bytes] & mask;
959static inline bool net_ipv4_is_addr_loopback_raw(
const uint8_t *addr)
961 return addr[0] == 127U;
974 return net_ipv4_is_addr_loopback_raw(addr->
s4_addr);
978static inline bool net_ipv4_is_addr_unspecified_raw(
const uint8_t *addr)
980 return UNALIGNED_GET((
uint32_t *)addr) == 0;
993 return net_ipv4_is_addr_unspecified_raw(addr->
s4_addr);
997static inline bool net_ipv4_is_addr_mcast_raw(
const uint8_t *addr)
1012 return net_ipv4_is_addr_mcast_raw(addr->
s4_addr);
1016static inline bool net_ipv4_is_ll_addr_raw(
const uint8_t *addr)
1031 return net_ipv4_is_ll_addr_raw(addr->
s4_addr);
1045 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
1048 masked_16 = masked_24 & 0xFFFF0000;
1049 masked_12 = masked_24 & 0xFFF00000;
1050 masked_10 = masked_24 & 0xFFC00000;
1051 masked_8 = masked_24 & 0xFF000000;
1053 return masked_8 == 0x0A000000 ||
1054 masked_10 == 0x64400000 ||
1055 masked_12 == 0xAC100000 ||
1056 masked_16 == 0xC0A80000 ||
1057 masked_24 == 0xC0000200 ||
1058 masked_24 == 0xC0336400 ||
1059 masked_24 == 0xCB007100;
1070#define net_ipaddr_copy(dest, src) \
1071 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
1108 return UNALIGNED_GET((
uint32_t *)addr1) == UNALIGNED_GET((
uint32_t *)addr2);
1155static inline bool net_ipv6_is_ll_addr_raw(
const uint8_t *addr)
1170 return net_ipv6_is_ll_addr_raw(addr->
s6_addr);
1195 return addr->
s6_addr[0] == 0xFD;
1207 return (addr->
s6_addr[0] & 0xE0) == 0x20;
1224 masked_7 = masked_32 & 0xfc000000;
1226 return masked_32 == 0x20010db8 ||
1227 masked_7 == 0xfc000000;
1271extern bool net_if_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1274#if defined(CONFIG_NET_NATIVE_IPV4)
1275static inline bool net_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1282 return net_if_ipv4_is_addr_bcast_raw(iface, addr);
1285static inline bool net_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1307#if defined(CONFIG_NET_NATIVE_IPV4)
1332static inline bool net_ipv4_is_my_addr_raw(
const uint8_t *addr)
1336 ret = net_if_ipv4_addr_lookup_raw(addr, NULL) != NULL;
1338 ret = net_ipv4_is_addr_bcast_raw(NULL, addr);
1370static inline bool net_ipv6_is_addr_unspecified_raw(
const uint8_t *addr)
1372 return UNALIGNED_GET((
uint32_t *)addr) == 0 &&
1373 UNALIGNED_GET((
uint32_t *)addr + 1) == 0 &&
1374 UNALIGNED_GET((
uint32_t *)addr + 2) == 0 &&
1375 UNALIGNED_GET((
uint32_t *)addr + 3) == 0;
1388 return net_ipv6_is_addr_unspecified_raw(addr->
s6_addr);
1392static inline bool net_ipv6_is_addr_solicited_node_raw(
const uint8_t *addr)
1395 UNALIGNED_GET((
uint32_t *)addr + 1) == 0x00000000 &&
1412 return net_ipv6_is_addr_solicited_node_raw(addr->
s6_addr);
1416static inline bool net_ipv6_is_addr_mcast_scope_raw(
const uint8_t *addr,
1419 return (addr[0] == 0xff) && ((addr[1] & 0xF) == scope);
1424static inline int net_ipv6_get_addr_mcast_scope_raw(
const uint8_t *addr)
1426 if (addr[0] == 0xff) {
1427 return (addr[1] & 0xF);
1447 return net_ipv6_is_addr_mcast_scope_raw(addr->
s6_addr, scope);
1462 return (addr_1->
s6_addr[0] == 0xff) && (addr_2->
s6_addr[0] == 0xff) &&
1475 return net_ipv6_get_addr_mcast_scope_raw(addr->
s6_addr);
1479static inline bool net_ipv6_is_addr_mcast_iface_raw(
const uint8_t *addr)
1481 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x01);
1484static inline bool net_ipv6_is_addr_mcast_link_raw(
const uint8_t *addr)
1486 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x02);
1489static inline bool net_ipv6_is_addr_mcast_mesh_raw(
const uint8_t *addr)
1491 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x03);
1494static inline bool net_ipv6_is_addr_mcast_site_raw(
const uint8_t *addr)
1496 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x05);
1499static inline bool net_ipv6_is_addr_mcast_org_raw(
const uint8_t *addr)
1501 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x08);
1588static inline bool net_ipv6_is_addr_mcast_group_raw(
const uint8_t *addr,
1611 return net_ipv6_is_addr_mcast_group_raw(addr->
s6_addr,
group->s6_addr);
1615static inline bool net_ipv6_is_addr_mcast_all_nodes_group_raw(
const uint8_t *addr)
1618 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1619 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1622 return net_ipv6_is_addr_mcast_group_raw(addr, all_nodes_mcast_group);
1637 return net_ipv6_is_addr_mcast_all_nodes_group_raw(addr->
s6_addr);
1657static inline bool net_ipv6_is_addr_mcast_link_all_nodes_raw(
const uint8_t *addr)
1659 return net_ipv6_is_addr_mcast_link_raw(addr) &&
1660 net_ipv6_is_addr_mcast_all_nodes_group_raw(addr);
1776 if (UNALIGNED_GET(&addr->
s6_addr32[0]) == 0 &&
1777 UNALIGNED_GET(&addr->
s6_addr32[1]) == 0 &&
1778 UNALIGNED_GET(&addr->
s6_addr16[5]) == 0xffff) {
1819 uint8_t *network_id,
size_t network_id_len,
1837static inline bool net_ipv6_addr_based_on_ll_raw(
const uint8_t *addr,
1840 if (addr == NULL || lladdr == NULL) {
1844 switch (lladdr->
len) {
1858 if (!
memcmp(&addr[9], &lladdr->
addr[1], 2) &&
1862 (addr[8] ^ 0x02) == lladdr->
addr[0]) {
1869 if (
sizeof(lladdr->
addr) < 8) {
1875 (addr[8] ^ 0x02) == lladdr->
addr[0]) {
1896 if (addr == NULL || lladdr == NULL) {
1900 return net_ipv6_addr_based_on_ll_raw(addr->
s6_addr, lladdr);
1926 return (
struct net_sockaddr_storage *)addr;
1964struct net_sockaddr_in6_ptr *
net_sin6_ptr(
const struct net_sockaddr_ptr *addr)
1966 return (
struct net_sockaddr_in6_ptr *)addr;
1978struct net_sockaddr_in_ptr *
net_sin_ptr(
const struct net_sockaddr_ptr *addr)
1980 return (
struct net_sockaddr_in_ptr *)addr;
1992struct net_sockaddr_ll_ptr *
net_sll_ptr(
const struct net_sockaddr_ptr *addr)
1994 return (
struct net_sockaddr_ll_ptr *)addr;
2006struct net_sockaddr_can_ptr *
net_can_ptr(
const struct net_sockaddr_ptr *addr)
2008 return (
struct net_sockaddr_can_ptr *)addr;
2038 char *dst,
size_t size);
2164 return (
int32_t)(seq1 - seq2);
2226 static const uint8_t vlan2priority[] = {
2285 return sizeof(
struct net_sockaddr_un);
2305#if defined(CONFIG_NET_IPV6_PE)
2312 ARG_UNUSED(is_denylist);
2325#if defined(CONFIG_NET_IPV6_PE)
2340#include <zephyr/syscalls/net_ip.h>
2342#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
2343#define ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
2345#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:2006
#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:1193
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:2275
#define NET_IPV4_ADDR_SIZE
Binary size of the IPv4 address.
Definition net_ip.h:166
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:2223
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition net_ip.h:2162
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:882
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:1119
#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:1774
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:1386
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:1554
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:1758
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:1010
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:1105
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:1219
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:991
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:838
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:1526
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:1091
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:1264
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:934
#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:1911
#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 struct net_sockaddr_in6 * net_sin6(const struct net_sockaddr *addr)
Get net_sockaddr_in6 from net_sockaddr.
Definition net_ip.h:1937
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:1978
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:1357
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:972
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:1029
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:1133
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:1737
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:1793
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:1070
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:1893
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:1473
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:1830
static struct net_sockaddr_in * net_sin(const struct net_sockaddr *addr)
Get net_sockaddr_in from net_sockaddr.
Definition net_ip.h:1950
#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:2252
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:1568
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:1444
#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:866
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:896
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:819
static struct net_sockaddr_storage * net_sas(const struct net_sockaddr *addr)
Get net_sockaddr_storage from net_sockaddr.
Definition net_ip.h:1924
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:1582
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:2308
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:1608
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition net_ip.h:2177
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:1410
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:1716
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:1205
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:1992
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:1674
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:1964
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:1635
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:1459
static int net_ipv6_pe_del_filter(struct net_in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition net_ip.h:2328
#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:1168
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:1043
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:1688
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:1540
#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:1747
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:1650
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:1180
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:1079
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:1512
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:1147
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:1318
@ 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.
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
@ 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:114
#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:584
Network Interface multicast IP addresses.
Definition net_if.h:161
Network Interface structure.
Definition net_if.h:733
Interface description structure.
Definition net_ip.h:746
char ifr_name[NET_IFNAMSIZ]
Network interface name.
Definition net_ip.h:747
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:797
unsigned int ipi6_ifindex
Receive interface index.
Definition net_ip.h:799
struct net_in6_addr ipi6_addr
Destination IPv6 address.
Definition net_ip.h:798
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:757
unsigned int ipi_ifindex
Network interface index.
Definition net_ip.h:758
struct net_in_addr ipi_addr
Header Destination address.
Definition net_ip.h:760
struct net_in_addr ipi_spec_dst
Local address.
Definition net_ip.h:759
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:775
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:776
struct net_in_addr imr_interface
IP address of local interface.
Definition net_ip.h:777
Struct used when joining or leaving a IPv4 multicast group.
Definition net_ip.h:766
int imr_ifindex
Network interface index.
Definition net_ip.h:769
struct net_in_addr imr_address
IP address of local interface.
Definition net_ip.h:768
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:767
Struct used when joining or leaving a IPv6 multicast group.
Definition net_ip.h:783
struct net_in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition net_ip.h:785
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition net_ip.h:788
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 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