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
207struct net_sockaddr_in6_ptr {
215struct net_sockaddr_in_ptr {
218 struct net_in_addr *sin_addr;
222struct net_sockaddr_ll_ptr {
233struct net_sockaddr_un_ptr {
238struct net_sockaddr_can_ptr {
245#if !defined(HAVE_IOVEC)
277#if !defined(NET_ALIGN_H)
278#define NET_ALIGN_H(x) ROUND_UP(x, __alignof__(struct net_cmsghdr))
280#if !defined(NET_ALIGN_D)
281#define NET_ALIGN_D(x) ROUND_UP(x, __alignof__(z_max_align_t))
286#if !defined(NET_CMSG_FIRSTHDR)
292#define NET_CMSG_FIRSTHDR(msghdr) \
293 ((msghdr)->msg_controllen >= sizeof(struct net_cmsghdr) ? \
294 (struct net_cmsghdr *)((msghdr)->msg_control) : NULL)
297#if !defined(NET_CMSG_NXTHDR)
302#define NET_CMSG_NXTHDR(msghdr, cmsg) \
303 (((cmsg) == NULL) ? NET_CMSG_FIRSTHDR(msghdr) : \
304 (((uint8_t *)(cmsg) + NET_ALIGN_H((cmsg)->cmsg_len) + \
305 NET_ALIGN_D(sizeof(struct net_cmsghdr)) > \
306 (uint8_t *)((msghdr)->msg_control) + (msghdr)->msg_controllen) ? \
308 (struct net_cmsghdr *)((uint8_t *)(cmsg) + \
309 NET_ALIGN_H((cmsg)->cmsg_len))))
312#if !defined(NET_CMSG_DATA)
320#define NET_CMSG_DATA(cmsg) ((uint8_t *)(cmsg) + NET_ALIGN_D(sizeof(struct net_cmsghdr)))
323#if !defined(NET_CMSG_SPACE)
328#define NET_CMSG_SPACE(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + NET_ALIGN_H(length))
331#if !defined(NET_CMSG_LEN)
337#define NET_CMSG_LEN(length) (NET_ALIGN_D(sizeof(struct net_cmsghdr)) + length)
343#define NET_PACKET_HOST 0
344#define NET_PACKET_BROADCAST 1
345#define NET_PACKET_MULTICAST 2
346#define NET_PACKET_OTHERHOST 3
347#define NET_PACKET_OUTGOING 4
348#define NET_PACKET_LOOPBACK 5
349#define NET_PACKET_FASTROUTE 6
352#define NET_ARPHRD_ETHER 1
353#define NET_ARPHRD_PPP 512
358#if defined(CONFIG_NET_IPV4)
359#undef NET_SOCKADDR_MAX_SIZE
360#undef NET_SOCKADDR_PTR_MAX_SIZE
361#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in))
362#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in_ptr))
365#if defined(CONFIG_NET_SOCKETS_PACKET)
366#undef NET_SOCKADDR_MAX_SIZE
367#undef NET_SOCKADDR_PTR_MAX_SIZE
368#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_ll))
369#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_ll_ptr))
372#if defined(CONFIG_NET_IPV6)
373#undef NET_SOCKADDR_MAX_SIZE
374#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in6))
375#if !defined(CONFIG_NET_SOCKETS_PACKET)
376#undef NET_SOCKADDR_PTR_MAX_SIZE
377#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in6_ptr))
381#if defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
382#define UNIX_PATH_MAX 108
383#undef NET_SOCKADDR_MAX_SIZE
385#define NET_SOCKADDR_MAX_SIZE (UNIX_PATH_MAX+sizeof(net_sa_family_t))
386#if !defined(CONFIG_NET_SOCKETS_PACKET)
387#undef NET_SOCKADDR_PTR_MAX_SIZE
388#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_un_ptr))
392#if !defined(CONFIG_NET_IPV4)
393#if !defined(CONFIG_NET_IPV6)
394#if !defined(CONFIG_NET_SOCKETS_PACKET)
395#if !defined(CONFIG_NET_NATIVE_OFFLOADED_SOCKETS)
396#define NET_SOCKADDR_MAX_SIZE (sizeof(struct net_sockaddr_in6))
397#define NET_SOCKADDR_PTR_MAX_SIZE (sizeof(struct net_sockaddr_in6_ptr))
405#define SOCKADDR_ALIGN (4)
417struct net_sockaddr_ptr {
423struct net_sockaddr_storage {
429struct net_sockaddr_un {
437#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
438 struct net_in6_addr net_in6_addr;
439 struct net_in_addr net_in_addr;
456#define NET_IN6ADDR_ANY_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
457 0, 0, 0, 0, 0, 0, 0, 0 } } }
460#define NET_IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
461 0, 0, 0, 0, 0, 0, 0, 1 } } }
464#define NET_INADDR_ANY 0
467#define NET_INADDR_BROADCAST 0xffffffff
470#define NET_INADDR_ANY_INIT { { { NET_INADDR_ANY } } }
473#define NET_INADDR_LOOPBACK_INIT { { { 127, 0, 0, 1 } } }
476#define NET_INET_ADDRSTRLEN 16
481#define NET_INET6_ADDRSTRLEN 46
486#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxx.xxx.xxx.xxx")
487#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")
496#if defined(CONFIG_NET_NATIVE_IPV6)
505#if defined(CONFIG_NET_NATIVE_IPV4)
524#define NET_MAX_PRIORITIES 8
570struct net_ipv6_frag_hdr {
616static inline const char *net_addr_type2str(
enum net_addr_type type)
636#define NET_IPV6_NEXTHDR_HBHO 0
637#define NET_IPV6_NEXTHDR_DESTO 60
638#define NET_IPV6_NEXTHDR_ROUTING 43
639#define NET_IPV6_NEXTHDR_FRAG 44
640#define NET_IPV6_NEXTHDR_NONE 59
647 struct net_ipv4_hdr *ipv4;
648 struct net_ipv6_hdr *ipv6;
651union net_proto_header {
652 struct net_udp_hdr *udp;
653 struct net_tcp_hdr *tcp;
656#define NET_UDPH_LEN 8
657#define NET_TCPH_LEN 20
658#define NET_ICMPH_LEN 4
660#define NET_IPV6H_LEN 40
661#define NET_ICMPV6H_LEN NET_ICMPH_LEN
662#define NET_IPV6UDPH_LEN (NET_UDPH_LEN + NET_IPV6H_LEN)
663#define NET_IPV6TCPH_LEN (NET_TCPH_LEN + NET_IPV6H_LEN)
664#define NET_IPV6ICMPH_LEN (NET_IPV6H_LEN + NET_ICMPH_LEN)
665#define NET_IPV6_FRAGH_LEN 8
667#define NET_IPV4H_LEN 20
668#define NET_ICMPV4H_LEN NET_ICMPH_LEN
669#define NET_IPV4UDPH_LEN (NET_UDPH_LEN + NET_IPV4H_LEN)
670#define NET_IPV4TCPH_LEN (NET_TCPH_LEN + NET_IPV4H_LEN)
671#define NET_IPV4ICMPH_LEN (NET_IPV4H_LEN + NET_ICMPH_LEN)
673#define NET_IPV6H_LENGTH_OFFSET 0x04
675#define NET_IPV6_FRAGH_OFFSET_MASK 0xfff8
676#define NET_IPV4_FRAGH_OFFSET_MASK 0x1fff
677#define NET_IPV4_MORE_FRAG_MASK 0x2000
678#define NET_IPV4_DO_NOT_FRAG_MASK 0x4000
681#if defined(CONFIG_NET_INTERFACE_NAME)
682#define NET_IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
684#if defined(Z_DEVICE_MAX_NAME_LEN)
685#define NET_IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
687#define NET_IFNAMSIZ 1
756static inline bool net_ipv6_is_addr_loopback_raw(
const uint8_t *addr)
758 return UNALIGNED_GET((
uint32_t *)addr) == 0 &&
759 UNALIGNED_GET((
uint32_t *)addr + 1) == 0 &&
760 UNALIGNED_GET((
uint32_t *)addr + 2) == 0 &&
774 return net_ipv6_is_addr_loopback_raw(addr->
s6_addr);
778static inline bool net_ipv6_is_addr_mcast_raw(
const uint8_t *addr)
780 return addr[0] == 0xff;
793 return net_ipv6_is_addr_mcast_raw(addr->
s6_addr);
803static inline bool net_ipv6_is_my_addr_raw(
const uint8_t *addr)
805 return net_if_ipv6_addr_lookup_raw(addr,
NULL) !=
NULL;
862 if (
memcmp(addr1, addr2, bytes)) {
874 mask = (
uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
876 return (addr1[bytes] & mask) == (addr2[bytes] & mask);
891 uint8_t bits = 128 - prefix_len;
892 uint8_t bytes = prefix_len / 8U;
897 memcpy(outaddr, inaddr, bytes);
907 mask = (
uint8_t)((0xff << (8 - remain)) ^ 0xff) << remain;
908 outaddr[bytes] = inaddr[bytes] & mask;
912static inline bool net_ipv4_is_addr_loopback_raw(
const uint8_t *addr)
914 return addr[0] == 127U;
927 return net_ipv4_is_addr_loopback_raw(addr->
s4_addr);
931static inline bool net_ipv4_is_addr_unspecified_raw(
const uint8_t *addr)
933 return UNALIGNED_GET((
uint32_t *)addr) == 0;
946 return net_ipv4_is_addr_unspecified_raw(addr->
s4_addr);
950static inline bool net_ipv4_is_addr_mcast_raw(
const uint8_t *addr)
965 return net_ipv4_is_addr_mcast_raw(addr->
s4_addr);
969static inline bool net_ipv4_is_ll_addr_raw(
const uint8_t *addr)
984 return net_ipv4_is_ll_addr_raw(addr->
s4_addr);
998 uint32_t masked_24, masked_16, masked_12, masked_10, masked_8;
1001 masked_16 = masked_24 & 0xFFFF0000;
1002 masked_12 = masked_24 & 0xFFF00000;
1003 masked_10 = masked_24 & 0xFFC00000;
1004 masked_8 = masked_24 & 0xFF000000;
1006 return masked_8 == 0x0A000000 ||
1007 masked_10 == 0x64400000 ||
1008 masked_12 == 0xAC100000 ||
1009 masked_16 == 0xC0A80000 ||
1010 masked_24 == 0xC0000200 ||
1011 masked_24 == 0xC0336400 ||
1012 masked_24 == 0xCB007100;
1023#define net_ipaddr_copy(dest, src) \
1024 UNALIGNED_PUT(UNALIGNED_GET(src), dest)
1061 return UNALIGNED_GET((
uint32_t *)addr1) == UNALIGNED_GET((
uint32_t *)addr2);
1108static inline bool net_ipv6_is_ll_addr_raw(
const uint8_t *addr)
1123 return net_ipv6_is_ll_addr_raw(addr->
s6_addr);
1148 return addr->
s6_addr[0] == 0xFD;
1160 return (addr->
s6_addr[0] & 0xE0) == 0x20;
1177 masked_7 = masked_32 & 0xfc000000;
1179 return masked_32 == 0x20010db8 ||
1180 masked_7 == 0xfc000000;
1224extern bool net_if_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1227#if defined(CONFIG_NET_NATIVE_IPV4)
1228static inline bool net_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1235 return net_if_ipv4_is_addr_bcast_raw(iface, addr);
1238static inline bool net_ipv4_is_addr_bcast_raw(
struct net_if *iface,
1260#if defined(CONFIG_NET_NATIVE_IPV4)
1285static inline bool net_ipv4_is_my_addr_raw(
const uint8_t *addr)
1289 ret = net_if_ipv4_addr_lookup_raw(addr,
NULL) !=
NULL;
1291 ret = net_ipv4_is_addr_bcast_raw(
NULL, addr);
1323static inline bool net_ipv6_is_addr_unspecified_raw(
const uint8_t *addr)
1325 return UNALIGNED_GET((
uint32_t *)addr) == 0 &&
1326 UNALIGNED_GET((
uint32_t *)addr + 1) == 0 &&
1327 UNALIGNED_GET((
uint32_t *)addr + 2) == 0 &&
1328 UNALIGNED_GET((
uint32_t *)addr + 3) == 0;
1341 return net_ipv6_is_addr_unspecified_raw(addr->
s6_addr);
1345static inline bool net_ipv6_is_addr_solicited_node_raw(
const uint8_t *addr)
1348 UNALIGNED_GET((
uint32_t *)addr + 1) == 0x00000000 &&
1365 return net_ipv6_is_addr_solicited_node_raw(addr->
s6_addr);
1369static inline bool net_ipv6_is_addr_mcast_scope_raw(
const uint8_t *addr,
1372 return (addr[0] == 0xff) && ((addr[1] & 0xF) == scope);
1377static inline int net_ipv6_get_addr_mcast_scope_raw(
const uint8_t *addr)
1379 if (addr[0] == 0xff) {
1380 return (addr[1] & 0xF);
1400 return net_ipv6_is_addr_mcast_scope_raw(addr->
s6_addr, scope);
1415 return (addr_1->
s6_addr[0] == 0xff) && (addr_2->
s6_addr[0] == 0xff) &&
1428 return net_ipv6_get_addr_mcast_scope_raw(addr->
s6_addr);
1432static inline bool net_ipv6_is_addr_mcast_iface_raw(
const uint8_t *addr)
1434 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x01);
1437static inline bool net_ipv6_is_addr_mcast_link_raw(
const uint8_t *addr)
1439 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x02);
1442static inline bool net_ipv6_is_addr_mcast_mesh_raw(
const uint8_t *addr)
1444 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x03);
1447static inline bool net_ipv6_is_addr_mcast_site_raw(
const uint8_t *addr)
1449 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x05);
1452static inline bool net_ipv6_is_addr_mcast_org_raw(
const uint8_t *addr)
1454 return net_ipv6_is_addr_mcast_scope_raw(addr, 0x08);
1541static inline bool net_ipv6_is_addr_mcast_group_raw(
const uint8_t *addr,
1564 return net_ipv6_is_addr_mcast_group_raw(addr->
s6_addr,
group->s6_addr);
1568static inline bool net_ipv6_is_addr_mcast_all_nodes_group_raw(
const uint8_t *addr)
1571 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1572 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
1575 return net_ipv6_is_addr_mcast_group_raw(addr, all_nodes_mcast_group);
1590 return net_ipv6_is_addr_mcast_all_nodes_group_raw(addr->
s6_addr);
1610static inline bool net_ipv6_is_addr_mcast_link_all_nodes_raw(
const uint8_t *addr)
1612 return net_ipv6_is_addr_mcast_link_raw(addr) &&
1613 net_ipv6_is_addr_mcast_all_nodes_group_raw(addr);
1729 if (UNALIGNED_GET(&addr->
s6_addr32[0]) == 0 &&
1730 UNALIGNED_GET(&addr->
s6_addr32[1]) == 0 &&
1731 UNALIGNED_GET(&addr->
s6_addr16[5]) == 0xffff) {
1758 uint8_t *network_id,
size_t network_id_len,
1776static inline bool net_ipv6_addr_based_on_ll_raw(
const uint8_t *addr,
1779 if (addr ==
NULL || lladdr ==
NULL) {
1783 switch (lladdr->
len) {
1797 if (!
memcmp(&addr[9], &lladdr->
addr[1], 2) &&
1801 (addr[8] ^ 0x02) == lladdr->
addr[0]) {
1808 if (
sizeof(lladdr->
addr) < 8) {
1814 (addr[8] ^ 0x02) == lladdr->
addr[0]) {
1835 if (addr ==
NULL || lladdr ==
NULL) {
1839 return net_ipv6_addr_based_on_ll_raw(addr->
s6_addr, lladdr);
1890struct net_sockaddr_in6_ptr *
net_sin6_ptr(
const struct net_sockaddr_ptr *addr)
1892 return (
struct net_sockaddr_in6_ptr *)addr;
1904struct net_sockaddr_in_ptr *
net_sin_ptr(
const struct net_sockaddr_ptr *addr)
1906 return (
struct net_sockaddr_in_ptr *)addr;
1918struct net_sockaddr_ll_ptr *
net_sll_ptr(
const struct net_sockaddr_ptr *addr)
1920 return (
struct net_sockaddr_ll_ptr *)addr;
1932struct net_sockaddr_can_ptr *
net_can_ptr(
const struct net_sockaddr_ptr *addr)
1934 return (
struct net_sockaddr_can_ptr *)addr;
1964 char *dst,
size_t size);
2070 return (
int32_t)(seq1 - seq2);
2132 static const uint8_t vlan2priority[] = {
2184#if defined(CONFIG_NET_IPV6_PE)
2191 ARG_UNUSED(is_denylist);
2204#if defined(CONFIG_NET_IPV6_PE)
2219#include <zephyr/syscalls/net_ip.h>
2221#if defined(CONFIG_NET_NAMESPACE_COMPAT_MODE)
2222#define ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
2224#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:1932
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:1146
#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:2129
static int32_t net_tcp_seq_cmp(uint32_t seq1, uint32_t seq2)
Compare TCP sequence numbers.
Definition net_ip.h:2068
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:835
const struct net_in_addr * net_ipv4_broadcast_address(void)
Return pointer to broadcast (all bits ones) IPv4 address.
#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:1072
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:1727
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:1339
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:1507
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:1711
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:963
net_addr_state
What is the current state of the network address.
Definition net_ip.h:536
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:1058
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:1172
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:944
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:791
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:1479
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:1044
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:1217
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:887
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:1850
#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:1863
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:1904
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:1310
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:925
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:982
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:1086
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:1690
net_ip_protocol_secure
Protocol numbers for TLS protocols.
Definition net_ip.h:78
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:1023
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:1832
net_ip_mtu
IP Maximum Transfer Unit.
Definition net_ip.h:492
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:1426
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:1769
static struct net_sockaddr_in * net_sin(const struct net_sockaddr *addr)
Get net_sockaddr_in from net_sockaddr.
Definition net_ip.h:1876
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:2158
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:1521
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:1397
#define SOCKADDR_ALIGN
Definition net_ip.h:405
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:819
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:849
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:772
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:1535
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:2187
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:1561
static bool net_tcp_seq_greater(uint32_t seq1, uint32_t seq2)
Check that one TCP sequence number is greater.
Definition net_ip.h:2083
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:1363
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:1669
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:1158
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:1918
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:1627
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:1890
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:1588
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:1412
static int net_ipv6_pe_del_filter(struct net_in6_addr *addr)
Delete IPv6 prefix from privacy extension filter list.
Definition net_ip.h:2207
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:1121
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:996
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:1641
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:1493
#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:1700
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:513
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:1603
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:1133
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:1032
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:1465
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:1100
net_addr_type
How the network address is assigned to network interface.
Definition net_ip.h:544
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:1271
@ NET_ADDR_ANY_STATE
Default (invalid) address type.
Definition net_ip.h:537
@ NET_ADDR_TENTATIVE
Tentative address.
Definition net_ip.h:538
@ NET_ADDR_DEPRECATED
Deprecated address.
Definition net_ip.h:540
@ NET_ADDR_PREFERRED
Preferred address.
Definition net_ip.h:539
@ 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:508
@ NET_IPV6_MTU
IPv6 MTU length.
Definition net_ip.h:499
@ 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:521
@ NET_PRIORITY_IC
Internetwork control.
Definition net_ip.h:520
@ NET_PRIORITY_CA
Critical applications.
Definition net_ip.h:517
@ NET_PRIORITY_VO
Voice, < 10 ms latency and jitter.
Definition net_ip.h:519
@ NET_PRIORITY_VI
Video, < 100 ms latency and jitter.
Definition net_ip.h:518
@ NET_PRIORITY_BE
Best effort (default)
Definition net_ip.h:515
@ NET_PRIORITY_EE
Excellent effort.
Definition net_ip.h:516
@ NET_PRIORITY_BK
Background (lowest)
Definition net_ip.h:514
@ 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:546
@ NET_ADDR_OVERRIDABLE
Manually set address which is overridable by DHCP.
Definition net_ip.h:554
@ NET_ADDR_DHCP
Address is from DHCP.
Definition net_ip.h:550
@ NET_ADDR_MANUAL
Manually set address.
Definition net_ip.h:552
@ NET_ADDR_AUTOCONF
Auto configured address.
Definition net_ip.h:548
@ 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
__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)
Group structure.
Definition grp.h:18
Control message ancillary data.
Definition net_ip.h:265
net_socklen_t cmsg_len
Number of bytes, including header.
Definition net_ip.h:266
int cmsg_level
Originating protocol.
Definition net_ip.h:267
int cmsg_type
Protocol-specific type.
Definition net_ip.h:268
z_max_align_t cmsg_data[]
Flexible array member to force alignment of net_cmsghdr.
Definition net_ip.h:269
Network Interface unicast IP addresses.
Definition net_if.h:56
IP and other configuration related data for network interface.
Definition net_if.h:586
Network Interface multicast IP addresses.
Definition net_if.h:161
Network Interface structure.
Definition net_if.h:726
Interface description structure.
Definition net_ip.h:699
char ifr_name[NET_IFNAMSIZ]
Network interface name.
Definition net_ip.h:700
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:750
unsigned int ipi6_ifindex
Receive interface index.
Definition net_ip.h:752
struct net_in6_addr ipi6_addr
Destination IPv6 address.
Definition net_ip.h:751
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:710
unsigned int ipi_ifindex
Network interface index.
Definition net_ip.h:711
struct net_in_addr ipi_addr
Header Destination address.
Definition net_ip.h:713
struct net_in_addr ipi_spec_dst
Local address.
Definition net_ip.h:712
IO vector array element.
Definition net_ip.h:247
void * iov_base
Pointer to data.
Definition net_ip.h:248
size_t iov_len
Length of the data.
Definition net_ip.h:249
Struct used when setting a IPv4 multicast network interface.
Definition net_ip.h:728
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:729
struct net_in_addr imr_interface
IP address of local interface.
Definition net_ip.h:730
Struct used when joining or leaving a IPv4 multicast group.
Definition net_ip.h:719
int imr_ifindex
Network interface index.
Definition net_ip.h:722
struct net_in_addr imr_address
IP address of local interface.
Definition net_ip.h:721
struct net_in_addr imr_multiaddr
IP multicast group address.
Definition net_ip.h:720
Struct used when joining or leaving a IPv6 multicast group.
Definition net_ip.h:736
struct net_in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition net_ip.h:738
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition net_ip.h:741
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:254
int msg_flags
Flags on received message.
Definition net_ip.h:261
struct net_iovec * msg_iov
Scatter/gather array.
Definition net_ip.h:257
net_socklen_t msg_namelen
Size of socket address.
Definition net_ip.h:256
size_t msg_controllen
Ancillary data buffer len.
Definition net_ip.h:260
void * msg_control
Ancillary data.
Definition net_ip.h:259
void * msg_name
Optional socket address, big endian.
Definition net_ip.h:255
size_t msg_iovlen
Number of elements in msg_iov.
Definition net_ip.h:258
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
Generic sockaddr struct.
Definition net_ip.h:408
net_sa_family_t sa_family
Address family.
Definition net_ip.h:409
IPv6/IPv4 network connection tuple.
Definition net_ip.h:527
struct net_addr * remote_addr
IPv6/IPv4 remote address.
Definition net_ip.h:528
uint16_t local_port
UDP/TCP local port.
Definition net_ip.h:531
enum net_ip_protocol ip_proto
IP protocol.
Definition net_ip.h:532
uint16_t remote_port
UDP/TCP remote port.
Definition net_ip.h:530
struct net_addr * local_addr
IPv6/IPv4 local address.
Definition net_ip.h:529