diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 24039a4833b..aacc792be72 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -79,10 +79,10 @@ static int loopback_send(const struct device *dev, struct net_pkt *pkt) if (net_pkt_family(pkt) == AF_INET6) { struct in6_addr addr; - net_ipaddr_copy(&addr, &NET_IPV6_HDR(pkt)->src); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->src, - &NET_IPV6_HDR(pkt)->dst); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->dst, &addr); + net_ipv6_addr_copy_raw((uint8_t *)&addr, NET_IPV6_HDR(pkt)->src); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->src, + NET_IPV6_HDR(pkt)->dst); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->dst, (uint8_t *)&addr); } else { struct in_addr addr; diff --git a/include/net/net_ip.h b/include/net/net_ip.h index a0f4052e4a5..cbade3f2537 100644 --- a/include/net/net_ip.h +++ b/include/net/net_ip.h @@ -466,8 +466,8 @@ struct net_ipv6_hdr { uint16_t len; uint8_t nexthdr; uint8_t hop_limit; - struct in6_addr src; - struct in6_addr dst; + uint8_t src[NET_IPV6_ADDR_SIZE]; + uint8_t dst[NET_IPV6_ADDR_SIZE]; } __packed; struct net_ipv6_frag_hdr { @@ -751,6 +751,18 @@ static inline void net_ipv4_addr_copy_raw(uint8_t *dest, net_ipaddr_copy((struct in_addr *)dest, (const struct in_addr *)src); } +/** + * @brief Copy an IPv6 address raw buffer + * + * @param dest Destination IP address. + * @param src Source IP address. + */ +static inline void net_ipv6_addr_copy_raw(uint8_t *dest, + const uint8_t *src) +{ + memcpy(dest, src, sizeof(struct in6_addr)); +} + /** * @brief Compare two IPv4 addresses * @@ -794,6 +806,21 @@ static inline bool net_ipv6_addr_cmp(const struct in6_addr *addr1, return !memcmp(addr1, addr2, sizeof(struct in6_addr)); } +/** + * @brief Compare two raw IPv6 address buffers + * + * @param addr1 Pointer to IPv6 address buffer. + * @param addr2 Pointer to IPv6 address buffer. + * + * @return True if the addresses are the same, false otherwise. + */ +static inline bool net_ipv6_addr_cmp_raw(const uint8_t *addr1, + const uint8_t *addr2) +{ + return net_ipv6_addr_cmp((const struct in6_addr *)addr1, + (const struct in6_addr *)addr2); +} + /** * @brief Check if the given IPv6 address is a link local address. * diff --git a/include/net/net_pkt.h b/include/net/net_pkt.h index 50b6106077e..91ba8d6ff28 100644 --- a/include/net/net_pkt.h +++ b/include/net/net_pkt.h @@ -1199,7 +1199,7 @@ static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt) { net_if_ipv6_select_src_addr(net_context_get_iface( net_pkt_context(pkt)), - &NET_IPV6_HDR(pkt)->src); + (struct in6_addr *)NET_IPV6_HDR(pkt)->src); } static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite) diff --git a/samples/bluetooth/ipsp/src/main.c b/samples/bluetooth/ipsp/src/main.c index 507e0cc9eff..72db7d03073 100644 --- a/samples/bluetooth/ipsp/src/main.c +++ b/samples/bluetooth/ipsp/src/main.c @@ -166,8 +166,8 @@ static inline void set_dst_addr(sa_family_t family, struct net_udp_hdr *udp_hdr, struct sockaddr *dst_addr) { - net_ipaddr_copy(&net_sin6(dst_addr)->sin6_addr, - &ipv6_hdr->src); + net_ipv6_addr_copy_raw((uint8_t *)&net_sin6(dst_addr)->sin6_addr, + ipv6_hdr->src); net_sin6(dst_addr)->sin6_family = AF_INET6; net_sin6(dst_addr)->sin6_port = udp_hdr->src_port; } diff --git a/samples/net/zperf/src/zperf_session.c b/samples/net/zperf/src/zperf_session.c index 0d46e048d3b..747aeb75758 100644 --- a/samples/net/zperf/src/zperf_session.c +++ b/samples/net/zperf/src/zperf_session.c @@ -48,7 +48,7 @@ struct session *get_session(struct net_pkt *pkt, port = udp_hdr->src_port; if (net_pkt_family(pkt) == AF_INET6) { - net_ipaddr_copy(&ipv6, &ip_hdr->ipv6->src); + net_ipv6_addr_copy_raw((uint8_t *)&ipv6, ip_hdr->ipv6->src); } else if (net_pkt_family(pkt) == AF_INET) { net_ipv4_addr_copy_raw((uint8_t *)&ipv4, ip_hdr->ipv4->src); } else { diff --git a/samples/net/zperf/src/zperf_udp_receiver.c b/samples/net/zperf/src/zperf_udp_receiver.c index 82cec143c5c..aed76ea11fd 100644 --- a/samples/net/zperf/src/zperf_udp_receiver.c +++ b/samples/net/zperf/src/zperf_udp_receiver.c @@ -37,8 +37,8 @@ static inline void set_dst_addr(const struct shell *shell, struct sockaddr *dst_addr) { if (IS_ENABLED(CONFIG_NET_IPV6) && family == AF_INET6) { - net_ipaddr_copy(&net_sin6(dst_addr)->sin6_addr, - &ip_hdr->ipv6->src); + net_ipv6_addr_copy_raw((uint8_t *)&net_sin6(dst_addr)->sin6_addr, + ip_hdr->ipv6->src); net_sin6(dst_addr)->sin6_family = AF_INET6; net_sin6(dst_addr)->sin6_port = udp_hdr->src_port; } diff --git a/subsys/net/ip/6lo.c b/subsys/net/ip/6lo.c index 5fe675af6dd..9fcf2d27612 100644 --- a/subsys/net/ip/6lo.c +++ b/subsys/net/ip/6lo.c @@ -31,7 +31,7 @@ struct net_6lo_context { uint8_t compress : 1; uint8_t cid : 4; uint8_t unused : 2; -} __packed; +}; static inline uint8_t get_6co_compress(struct net_icmpv6_nd_opt_6co *opt) { @@ -368,7 +368,8 @@ static uint8_t *compress_sa(struct net_ipv6_hdr *ipv6, struct net_pkt *pkt, NET_ASSERT(net_pkt_lladdr_src(pkt)->addr); /* Address is fully elided */ - if (net_ipv6_addr_based_on_ll(&ipv6->src, net_pkt_lladdr_src(pkt))) { + if (net_ipv6_addr_based_on_ll((struct in6_addr *)ipv6->src, + net_pkt_lladdr_src(pkt))) { NET_DBG("SAM_11 src address is fully elided"); *iphc |= NET_6LO_IPHC_SAM_11; @@ -376,12 +377,12 @@ static uint8_t *compress_sa(struct net_ipv6_hdr *ipv6, struct net_pkt *pkt, } /* Following 64 bits are 0000:00ff:fe00:XXXX */ - if (net_6lo_addr_16_bit_compressible(&ipv6->src)) { + if (net_6lo_addr_16_bit_compressible((struct in6_addr *)ipv6->src)) { NET_DBG("SAM_10 src addr 16 bit compressible"); *iphc |= NET_6LO_IPHC_SAM_10; inline_ptr -= sizeof(uint16_t); - memmove(inline_ptr, &ipv6->src.s6_addr[14], sizeof(uint16_t)); + memmove(inline_ptr, &ipv6->src[14], sizeof(uint16_t)); return inline_ptr; } @@ -391,7 +392,7 @@ static uint8_t *compress_sa(struct net_ipv6_hdr *ipv6, struct net_pkt *pkt, *iphc |= NET_6LO_IPHC_SAM_01; inline_ptr -= 8U; - memmove(inline_ptr, &ipv6->src.s6_addr[8], 8U); + memmove(inline_ptr, &ipv6->src[8], 8U); return inline_ptr; } @@ -401,7 +402,7 @@ static uint8_t *set_sa_inline(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr, { *iphc |= NET_6LO_IPHC_SAM_00; inline_ptr -= 16U; - memmove(inline_ptr, &ipv6->src.s6_addr[0], 16U); + memmove(inline_ptr, &ipv6->src[0], 16U); return inline_ptr; } @@ -415,7 +416,8 @@ static uint8_t *compress_sa_ctx(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr, NET_DBG("SAC_1 src address context based"); *iphc |= NET_6LO_IPHC_SAC_1; - if (net_ipv6_addr_based_on_ll(&ipv6->src, net_pkt_lladdr_src(pkt))) { + if (net_ipv6_addr_based_on_ll((struct in6_addr *)ipv6->src, + net_pkt_lladdr_src(pkt))) { NET_DBG("SAM_11 src address is fully elided"); /* Address is fully elided */ @@ -424,13 +426,13 @@ static uint8_t *compress_sa_ctx(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr, } /* Following 64 bits are 0000:00ff:fe00:XXXX */ - if (net_6lo_addr_16_bit_compressible(&ipv6->src)) { + if (net_6lo_addr_16_bit_compressible((struct in6_addr *)ipv6->src)) { NET_DBG("SAM_10 src addr 16 bit compressible"); *iphc |= NET_6LO_IPHC_SAM_10; inline_ptr -= sizeof(uint16_t); - memmove(inline_ptr, &ipv6->src.s6_addr[14], sizeof(uint16_t)); + memmove(inline_ptr, &ipv6->src[14], sizeof(uint16_t)); return inline_ptr; } @@ -440,7 +442,7 @@ static uint8_t *compress_sa_ctx(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr, *iphc |= NET_6LO_IPHC_SAM_01; inline_ptr -= 8U; - memmove(inline_ptr, &ipv6->src.s6_addr[8], 8U); + memmove(inline_ptr, &ipv6->src[8], 8U); return inline_ptr; } @@ -454,44 +456,44 @@ static uint8_t *compress_da_mcast(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr NET_DBG("M_1 dst is mcast"); - if (net_6lo_maddr_8_bit_compressible(&ipv6->dst)) { + if (net_6lo_maddr_8_bit_compressible((struct in6_addr *)ipv6->dst)) { NET_DBG("DAM_11 dst maddr 8 bit compressible"); /* last byte */ *iphc |= NET_6LO_IPHC_DAM_11; inline_ptr -= sizeof(uint8_t); - memmove(inline_ptr, &ipv6->dst.s6_addr[15], sizeof(uint8_t)); + memmove(inline_ptr, &ipv6->dst[15], sizeof(uint8_t)); return inline_ptr; } - if (net_6lo_maddr_32_bit_compressible(&ipv6->dst)) { + if (net_6lo_maddr_32_bit_compressible((struct in6_addr *)ipv6->dst)) { NET_DBG("DAM_10 4 bytes: 2nd byte + last three bytes"); /* 4 bytes: 2nd byte + last three bytes */ *iphc |= NET_6LO_IPHC_DAM_10; inline_ptr -= 3U; - memmove(inline_ptr, &ipv6->dst.s6_addr[13], 3U); + memmove(inline_ptr, &ipv6->dst[13], 3U); inline_ptr -= sizeof(uint8_t); - memmove(inline_ptr, &ipv6->dst.s6_addr[1], sizeof(uint8_t)); + memmove(inline_ptr, &ipv6->dst[1], sizeof(uint8_t)); return inline_ptr; } - if (net_6lo_maddr_48_bit_compressible(&ipv6->dst)) { + if (net_6lo_maddr_48_bit_compressible((struct in6_addr *)ipv6->dst)) { NET_DBG("DAM_01 6 bytes: 2nd byte + last five bytes"); /* 6 bytes: 2nd byte + last five bytes */ *iphc |= NET_6LO_IPHC_DAM_01; inline_ptr -= 5U; - memmove(inline_ptr, &ipv6->dst.s6_addr[11], 5U); + memmove(inline_ptr, &ipv6->dst[11], 5U); inline_ptr -= sizeof(uint8_t); - memmove(inline_ptr, &ipv6->dst.s6_addr[1], sizeof(uint8_t)); + memmove(inline_ptr, &ipv6->dst[1], sizeof(uint8_t)); return inline_ptr; } @@ -500,7 +502,7 @@ static uint8_t *compress_da_mcast(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr /* complete address NET_6LO_IPHC_DAM_00 */ inline_ptr -= 16U; - memmove(inline_ptr, &ipv6->dst.s6_addr[0], 16U); + memmove(inline_ptr, &ipv6->dst[0], 16U); return inline_ptr; } @@ -509,8 +511,10 @@ static uint8_t *compress_da(struct net_ipv6_hdr *ipv6, struct net_pkt *pkt, uint8_t *inline_ptr, uint16_t *iphc) { NET_ASSERT(net_pkt_lladdr_dst(pkt)->addr); + /* Address is fully elided */ - if (net_ipv6_addr_based_on_ll(&ipv6->dst, net_pkt_lladdr_dst(pkt))) { + if (net_ipv6_addr_based_on_ll((struct in6_addr *)ipv6->dst, + net_pkt_lladdr_dst(pkt))) { NET_DBG("DAM_11 dst addr fully elided"); *iphc |= NET_6LO_IPHC_DAM_11; @@ -518,13 +522,13 @@ static uint8_t *compress_da(struct net_ipv6_hdr *ipv6, struct net_pkt *pkt, } /* Following 64 bits are 0000:00ff:fe00:XXXX */ - if (net_6lo_addr_16_bit_compressible(&ipv6->dst)) { + if (net_6lo_addr_16_bit_compressible((struct in6_addr *)ipv6->dst)) { NET_DBG("DAM_10 dst addr 16 bit compressible"); *iphc |= NET_6LO_IPHC_DAM_10; inline_ptr -= sizeof(uint16_t); - memmove(inline_ptr, &ipv6->dst.s6_addr[14], sizeof(uint16_t)); + memmove(inline_ptr, &ipv6->dst[14], sizeof(uint16_t)); return inline_ptr; } @@ -534,7 +538,7 @@ static uint8_t *compress_da(struct net_ipv6_hdr *ipv6, struct net_pkt *pkt, *iphc |= NET_6LO_IPHC_DAM_01; inline_ptr -= 8U; - memmove(inline_ptr, &ipv6->dst.s6_addr[8], 8U); + memmove(inline_ptr, &ipv6->dst[8], 8U); return inline_ptr; } @@ -544,7 +548,7 @@ static uint8_t *set_da_inline(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr, { *iphc |= NET_6LO_IPHC_DAM_00; inline_ptr -= 16U; - memmove(inline_ptr, &ipv6->dst.s6_addr[0], 16U); + memmove(inline_ptr, &ipv6->dst[0], 16U); return inline_ptr; } @@ -555,7 +559,8 @@ static uint8_t *compress_da_ctx(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr, { *iphc |= NET_6LO_IPHC_DAC_1; - if (net_ipv6_addr_based_on_ll(&ipv6->dst, net_pkt_lladdr_dst(pkt))) { + if (net_ipv6_addr_based_on_ll((struct in6_addr *)ipv6->dst, + net_pkt_lladdr_dst(pkt))) { NET_DBG("DAM_11 dst addr fully elided"); *iphc |= NET_6LO_IPHC_DAM_11; @@ -563,12 +568,12 @@ static uint8_t *compress_da_ctx(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr, } /* Following 64 bits are 0000:00ff:fe00:XXXX */ - if (net_6lo_addr_16_bit_compressible(&ipv6->dst)) { + if (net_6lo_addr_16_bit_compressible((struct in6_addr *)ipv6->dst)) { NET_DBG("DAM_10 dst addr 16 bit compressible"); *iphc |= NET_6LO_IPHC_DAM_10; inline_ptr -= sizeof(uint16_t); - memmove(inline_ptr, &ipv6->dst.s6_addr[14], sizeof(uint16_t)); + memmove(inline_ptr, &ipv6->dst[14], sizeof(uint16_t)); return inline_ptr; } @@ -578,7 +583,7 @@ static uint8_t *compress_da_ctx(struct net_ipv6_hdr *ipv6, uint8_t *inline_ptr, *iphc |= NET_6LO_IPHC_DAM_01; inline_ptr -= 8U; - memmove(inline_ptr, &ipv6->dst.s6_addr[8], 8U); + memmove(inline_ptr, &ipv6->dst[8], 8U); return inline_ptr; } @@ -687,7 +692,8 @@ static struct net_6lo_context *get_src_addr_ctx(struct net_pkt *pkt, /* If compress flag is unset means use only in uncompression. */ struct net_6lo_context *src; - src = get_6lo_context_by_addr(net_pkt_iface(pkt), &ipv6->src); + src = get_6lo_context_by_addr(net_pkt_iface(pkt), + (struct in6_addr *)ipv6->src); if (!src || !src->compress) { return NULL; } @@ -701,7 +707,8 @@ static struct net_6lo_context *get_dst_addr_ctx(struct net_pkt *pkt, /* If compress flag is unset means use only in uncompression. */ struct net_6lo_context *dst; - dst = get_6lo_context_by_addr(net_pkt_iface(pkt), &ipv6->dst); + dst = get_6lo_context_by_addr(net_pkt_iface(pkt), + (struct in6_addr *)ipv6->dst); if (!dst || !dst->compress) { return NULL; } @@ -752,12 +759,12 @@ static inline int compress_IPHC_header(struct net_pkt *pkt) inline_pos = compress_nh_udp(udp, inline_pos, false); } - if (net_6lo_ll_prefix_padded_with_zeros(&ipv6->dst)) { + if (net_6lo_ll_prefix_padded_with_zeros((struct in6_addr *)ipv6->dst)) { inline_pos = compress_da(ipv6, pkt, inline_pos, &iphc); goto da_end; } - if (net_ipv6_is_addr_mcast(&ipv6->dst)) { + if (net_ipv6_is_addr_mcast((struct in6_addr *)ipv6->dst)) { inline_pos = compress_da_mcast(ipv6, inline_pos, &iphc); goto da_end; } @@ -774,12 +781,12 @@ static inline int compress_IPHC_header(struct net_pkt *pkt) inline_pos = set_da_inline(ipv6, inline_pos, &iphc); da_end: - if (net_6lo_ll_prefix_padded_with_zeros(&ipv6->src)) { + if (net_6lo_ll_prefix_padded_with_zeros((struct in6_addr *)ipv6->src)) { inline_pos = compress_sa(ipv6, pkt, inline_pos, &iphc); goto sa_end; } - if (net_ipv6_is_addr_unspecified(&ipv6->src)) { + if (net_ipv6_is_addr_unspecified((struct in6_addr *)ipv6->src)) { NET_DBG("SAM_00, SAC_1 unspecified src address"); /* Unspecified IPv6 src address */ @@ -919,53 +926,58 @@ static inline uint8_t *uncompress_sa(uint16_t iphc, uint8_t *cursor, struct net_ipv6_hdr *ipv6, struct net_pkt *pkt) { + struct in6_addr src_ip; NET_DBG("SAC_0"); + net_ipv6_addr_copy_raw((uint8_t *)&src_ip, ipv6->src); + switch (iphc & NET_6LO_IPHC_SAM_MASK) { case NET_6LO_IPHC_SAM_00: NET_DBG("SAM_00 full src addr inlined"); - memmove(ipv6->src.s6_addr, cursor, sizeof(ipv6->src.s6_addr)); - cursor += sizeof(ipv6->src.s6_addr); + memmove(src_ip.s6_addr, cursor, sizeof(src_ip.s6_addr)); + cursor += sizeof(src_ip.s6_addr); break; case NET_6LO_IPHC_SAM_01: NET_DBG("SAM_01 last 64 bits are inlined"); - memmove(&ipv6->src.s6_addr[8], cursor, 8); + memmove(&src_ip.s6_addr[8], cursor, 8); cursor += 8U; - ipv6->src.s6_addr32[0] = 0x00; - ipv6->src.s6_addr32[1] = 0x00; - ipv6->src.s6_addr[0] = 0xFE; - ipv6->src.s6_addr[1] = 0x80; + src_ip.s6_addr32[0] = 0x00; + src_ip.s6_addr32[1] = 0x00; + src_ip.s6_addr[0] = 0xFE; + src_ip.s6_addr[1] = 0x80; break; case NET_6LO_IPHC_SAM_10: NET_DBG("SAM_10 src addr 16 bit compressed"); - memmove(&ipv6->src.s6_addr[14], cursor, 2); + memmove(&src_ip.s6_addr[14], cursor, 2); cursor += 2U; - ipv6->src.s6_addr16[6] = 0x00; + src_ip.s6_addr16[6] = 0x00; - ipv6->src.s6_addr32[0] = 0x00; - ipv6->src.s6_addr32[1] = 0x00; - ipv6->src.s6_addr32[2] = 0x00; - ipv6->src.s6_addr[0] = 0xFE; - ipv6->src.s6_addr[1] = 0x80; - ipv6->src.s6_addr[11] = 0xFF; - ipv6->src.s6_addr[12] = 0xFE; + src_ip.s6_addr32[0] = 0x00; + src_ip.s6_addr32[1] = 0x00; + src_ip.s6_addr32[2] = 0x00; + src_ip.s6_addr[0] = 0xFE; + src_ip.s6_addr[1] = 0x80; + src_ip.s6_addr[11] = 0xFF; + src_ip.s6_addr[12] = 0xFE; break; case NET_6LO_IPHC_SAM_11: NET_DBG("SAM_11 generate src addr from ll"); - net_ipv6_addr_create_iid(&ipv6->src, net_pkt_lladdr_src(pkt)); + net_ipv6_addr_create_iid(&src_ip, net_pkt_lladdr_src(pkt)); break; } + net_ipv6_addr_copy_raw(ipv6->src, (uint8_t *)&src_ip); + return cursor; } @@ -975,15 +987,19 @@ static inline uint8_t *uncompress_sa_ctx(uint16_t iphc, uint8_t *cursor, struct net_6lo_context *ctx, struct net_pkt *pkt) { + struct in6_addr src_ip; + + net_ipv6_addr_copy_raw((uint8_t *)&src_ip, ipv6->src); + switch (iphc & NET_6LO_IPHC_SAM_MASK) { case NET_6LO_IPHC_SAM_01: NET_DBG("SAM_01 last 64 bits are inlined"); /* First 8 bytes are from context */ - memmove(&ipv6->src.s6_addr[0], &ctx->prefix.s6_addr[0], 8); + memmove(&src_ip.s6_addr[0], &ctx->prefix.s6_addr[0], 8); /* And the rest are carried in-line*/ - memmove(&ipv6->src.s6_addr[8], cursor, 8); + memmove(&src_ip.s6_addr[8], cursor, 8); cursor += 8U; break; @@ -991,16 +1007,16 @@ static inline uint8_t *uncompress_sa_ctx(uint16_t iphc, uint8_t *cursor, NET_DBG("SAM_10 src addr 16 bit compressed"); /* 16 bit carried in-line */ - memmove(&ipv6->src.s6_addr[14], cursor, 2); + memmove(&src_ip.s6_addr[14], cursor, 2); cursor += 2U; /* First 8 bytes are from context */ - memmove(&ipv6->src.s6_addr[0], &ctx->prefix.s6_addr[0], 8); + memmove(&src_ip.s6_addr[0], &ctx->prefix.s6_addr[0], 8); - ipv6->src.s6_addr32[2] = 0x00; - ipv6->src.s6_addr16[6] = 0x00; - ipv6->src.s6_addr[11] = 0xFF; - ipv6->src.s6_addr[12] = 0xFE; + src_ip.s6_addr32[2] = 0x00; + src_ip.s6_addr16[6] = 0x00; + src_ip.s6_addr[11] = 0xFF; + src_ip.s6_addr[12] = 0xFE; break; case NET_6LO_IPHC_SAM_11: @@ -1011,16 +1027,18 @@ static inline uint8_t *uncompress_sa_ctx(uint16_t iphc, uint8_t *cursor, * the encapsulating header. * (e.g., 802.15.4 or IPv6 source address). */ - net_ipv6_addr_create_iid(&ipv6->src, net_pkt_lladdr_src(pkt)); + net_ipv6_addr_create_iid(&src_ip, net_pkt_lladdr_src(pkt)); /* net_ipv6_addr_create_iid will copy first 8 bytes * as link local prefix. * Overwrite first 8 bytes from context prefix here. */ - memmove(&ipv6->src.s6_addr[0], &ctx->prefix.s6_addr[0], 8); + memmove(&src_ip.s6_addr[0], &ctx->prefix.s6_addr[0], 8); break; } + net_ipv6_addr_copy_raw(ipv6->src, (uint8_t *)&src_ip); + return cursor; } #endif @@ -1029,8 +1047,12 @@ static inline uint8_t *uncompress_sa_ctx(uint16_t iphc, uint8_t *cursor, static inline uint8_t *uncompress_da_mcast(uint16_t iphc, uint8_t *cursor, struct net_ipv6_hdr *ipv6) { + struct in6_addr dst_ip; + NET_DBG("Dst is multicast"); + net_ipv6_addr_copy_raw((uint8_t *)&dst_ip, ipv6->dst); + if (iphc & NET_6LO_IPHC_DAC_1) { NET_WARN("Unsupported DAM options"); return 0; @@ -1047,59 +1069,61 @@ static inline uint8_t *uncompress_da_mcast(uint16_t iphc, uint8_t *cursor, case NET_6LO_IPHC_DAM_00: NET_DBG("DAM_00 full dst addr inlined"); - memmove(&ipv6->dst.s6_addr[0], cursor, - sizeof(ipv6->dst.s6_addr)); + memmove(&dst_ip.s6_addr[0], cursor, + sizeof(dst_ip.s6_addr)); - cursor += sizeof(ipv6->dst.s6_addr); + cursor += sizeof(dst_ip.s6_addr); break; case NET_6LO_IPHC_DAM_01: NET_DBG("DAM_01 2nd byte and last five bytes"); - ipv6->dst.s6_addr[1] = *cursor; + dst_ip.s6_addr[1] = *cursor; cursor++; - memmove(&ipv6->dst.s6_addr[11], cursor, 5); + memmove(&dst_ip.s6_addr[11], cursor, 5); cursor += 5U; - ipv6->dst.s6_addr[0] = 0xFF; - ipv6->dst.s6_addr16[1] = 0x00; - ipv6->dst.s6_addr32[1] = 0x00; - ipv6->dst.s6_addr[10] = 0x00; - ipv6->dst.s6_addr16[4] = 0x00; + dst_ip.s6_addr[0] = 0xFF; + dst_ip.s6_addr16[1] = 0x00; + dst_ip.s6_addr32[1] = 0x00; + dst_ip.s6_addr[10] = 0x00; + dst_ip.s6_addr16[4] = 0x00; break; case NET_6LO_IPHC_DAM_10: NET_DBG("DAM_10 2nd byte and last three bytes"); - ipv6->dst.s6_addr[1] = *cursor; + dst_ip.s6_addr[1] = *cursor; cursor++; - memmove(&ipv6->dst.s6_addr[13], cursor, 3); + memmove(&dst_ip.s6_addr[13], cursor, 3); cursor += 3U; - ipv6->dst.s6_addr[0] = 0xFF; - ipv6->dst.s6_addr16[1] = 0x00; - ipv6->dst.s6_addr32[1] = 0x00; - ipv6->dst.s6_addr32[2] = 0x00; - ipv6->dst.s6_addr[12] = 0x00; + dst_ip.s6_addr[0] = 0xFF; + dst_ip.s6_addr16[1] = 0x00; + dst_ip.s6_addr32[1] = 0x00; + dst_ip.s6_addr32[2] = 0x00; + dst_ip.s6_addr[12] = 0x00; break; case NET_6LO_IPHC_DAM_11: NET_DBG("DAM_11 8 bit compressed"); - ipv6->dst.s6_addr[15] = *cursor; + dst_ip.s6_addr[15] = *cursor; cursor++; - ipv6->dst.s6_addr[14] = 0x00; + dst_ip.s6_addr[14] = 0x00; - ipv6->dst.s6_addr32[0] = 0x00; - ipv6->dst.s6_addr32[1] = 0x00; - ipv6->dst.s6_addr32[2] = 0x00; - ipv6->dst.s6_addr16[6] = 0x00; - ipv6->dst.s6_addr[0] = 0xFF; - ipv6->dst.s6_addr[1] = 0x02; + dst_ip.s6_addr32[0] = 0x00; + dst_ip.s6_addr32[1] = 0x00; + dst_ip.s6_addr32[2] = 0x00; + dst_ip.s6_addr16[6] = 0x00; + dst_ip.s6_addr[0] = 0xFF; + dst_ip.s6_addr[1] = 0x02; break; } + net_ipv6_addr_copy_raw(ipv6->dst, (uint8_t *)&dst_ip); + return cursor; } @@ -1108,55 +1132,59 @@ static inline uint8_t *uncompress_da(uint16_t iphc, uint8_t *cursor, struct net_ipv6_hdr *ipv6, struct net_pkt *pkt) { + struct in6_addr dst_ip; + NET_DBG("DAC_0"); + net_ipv6_addr_copy_raw((uint8_t *)&dst_ip, ipv6->dst); + switch (iphc & NET_6LO_IPHC_DAM_MASK) { case NET_6LO_IPHC_DAM_00: NET_DBG("DAM_00 full dst addr inlined"); - memmove(&ipv6->dst.s6_addr[0], cursor, - sizeof(ipv6->dst.s6_addr)); - cursor += sizeof(ipv6->dst.s6_addr); + memmove(&dst_ip.s6_addr[0], cursor, + sizeof(dst_ip.s6_addr)); + cursor += sizeof(dst_ip.s6_addr); break; case NET_6LO_IPHC_DAM_01: NET_DBG("DAM_01 last 64 bits are inlined"); - memmove(&ipv6->dst.s6_addr[8], cursor, 8); + memmove(&dst_ip.s6_addr[8], cursor, 8); cursor += 8U; - ipv6->dst.s6_addr32[0] = 0x00; - ipv6->dst.s6_addr32[1] = 0x00; - ipv6->dst.s6_addr[0] = 0xFE; - ipv6->dst.s6_addr[1] = 0x80; - - + dst_ip.s6_addr32[0] = 0x00; + dst_ip.s6_addr32[1] = 0x00; + dst_ip.s6_addr[0] = 0xFE; + dst_ip.s6_addr[1] = 0x80; break; case NET_6LO_IPHC_DAM_10: NET_DBG("DAM_10 dst addr 16 bit compressed"); - memmove(&ipv6->dst.s6_addr[14], cursor, 2); + memmove(&dst_ip.s6_addr[14], cursor, 2); cursor += 2U; - ipv6->dst.s6_addr32[0] = 0x00; - ipv6->dst.s6_addr32[1] = 0x00; - ipv6->dst.s6_addr32[2] = 0x00; - ipv6->dst.s6_addr16[6] = 0x00; - ipv6->dst.s6_addr[0] = 0xFE; - ipv6->dst.s6_addr[1] = 0x80; - ipv6->dst.s6_addr[11] = 0xFF; - ipv6->dst.s6_addr[12] = 0xFE; + dst_ip.s6_addr32[0] = 0x00; + dst_ip.s6_addr32[1] = 0x00; + dst_ip.s6_addr32[2] = 0x00; + dst_ip.s6_addr16[6] = 0x00; + dst_ip.s6_addr[0] = 0xFE; + dst_ip.s6_addr[1] = 0x80; + dst_ip.s6_addr[11] = 0xFF; + dst_ip.s6_addr[12] = 0xFE; break; case NET_6LO_IPHC_DAM_11: NET_DBG("DAM_11 generate dst addr from ll"); - net_ipv6_addr_create_iid(&ipv6->dst, net_pkt_lladdr_dst(pkt)); + net_ipv6_addr_create_iid(&dst_ip, net_pkt_lladdr_dst(pkt)); break; } + net_ipv6_addr_copy_raw(ipv6->dst, (uint8_t *)&dst_ip); + return cursor; } @@ -1166,34 +1194,38 @@ static inline uint8_t *uncompress_da_ctx(uint16_t iphc, uint8_t *cursor, struct net_6lo_context *ctx, struct net_pkt *pkt) { + struct in6_addr dst_ip; + NET_DBG("DAC_1"); + net_ipv6_addr_copy_raw((uint8_t *)&dst_ip, ipv6->dst); + switch (iphc & NET_6LO_IPHC_DAM_MASK) { case NET_6LO_IPHC_DAM_01: NET_DBG("DAM_01 last 64 bits are inlined"); /* Last 8 bytes carried in-line */ - memmove(&ipv6->dst.s6_addr[8], cursor, 8); + memmove(&dst_ip.s6_addr[8], cursor, 8); cursor += 8U; /* First 8 bytes are from context */ - memmove(&ipv6->dst.s6_addr[0], &ctx->prefix.s6_addr[0], 8); + memmove(&dst_ip.s6_addr[0], &ctx->prefix.s6_addr[0], 8); break; case NET_6LO_IPHC_DAM_10: NET_DBG("DAM_10 src addr 16 bit compressed"); /* 16 bit carried in-line */ - memmove(&ipv6->dst.s6_addr[14], cursor, 2); + memmove(&dst_ip.s6_addr[14], cursor, 2); cursor += 2U; /* First 8 bytes are from context */ - memmove(&ipv6->dst.s6_addr[0], &ctx->prefix.s6_addr[0], 8); + memmove(&dst_ip.s6_addr[0], &ctx->prefix.s6_addr[0], 8); - ipv6->dst.s6_addr32[2] = 0x00; - ipv6->dst.s6_addr16[6] = 0x00; - ipv6->dst.s6_addr[11] = 0xFF; - ipv6->dst.s6_addr[12] = 0xFE; + dst_ip.s6_addr32[2] = 0x00; + dst_ip.s6_addr16[6] = 0x00; + dst_ip.s6_addr[11] = 0xFF; + dst_ip.s6_addr[12] = 0xFE; break; case NET_6LO_IPHC_DAM_11: @@ -1204,17 +1236,19 @@ static inline uint8_t *uncompress_da_ctx(uint16_t iphc, uint8_t *cursor, * the encapsulating header. * (e.g., 802.15.4 or IPv6 source address). */ - net_ipv6_addr_create_iid(&ipv6->dst, net_pkt_lladdr_dst(pkt)); + net_ipv6_addr_create_iid(&dst_ip, net_pkt_lladdr_dst(pkt)); /* net_ipv6_addr_create_iid will copy first 8 bytes * as link local prefix. * Overwrite first 8 bytes from context prefix here. */ - memmove(&ipv6->dst.s6_addr[0], &ctx->prefix.s6_addr[0], 8); + memmove(&dst_ip.s6_addr[0], &ctx->prefix.s6_addr[0], 8); break; } + net_ipv6_addr_copy_raw(ipv6->dst, (uint8_t *)&dst_ip); + return cursor; } #endif @@ -1406,8 +1440,8 @@ static bool uncompress_IPHC_header(struct net_pkt *pkt) if ((iphc & NET_6LO_IPHC_SAM_MASK) == NET_6LO_IPHC_SAM_00) { NET_DBG("SAM_00 unspecified address"); - memset(&ipv6->src.s6_addr[0], 0, - sizeof(ipv6->src.s6_addr)); + memset(&ipv6->src[0], 0, + sizeof(ipv6->src)); } else if (IS_ENABLED(CONFIG_NET_6LO_CONTEXT)) { #if defined(CONFIG_NET_6LO_CONTEXT) if (!src) { diff --git a/subsys/net/ip/connection.c b/subsys/net/ip/connection.c index a95716ce862..9828aa5f7a9 100644 --- a/subsys/net/ip/connection.c +++ b/subsys/net/ip/connection.c @@ -420,18 +420,18 @@ static bool conn_addr_cmp(struct net_pkt *pkt, if (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6 && addr->sa_family == AF_INET6) { - struct in6_addr *addr6; + uint8_t *addr6; if (is_remote) { - addr6 = &ip_hdr->ipv6->src; + addr6 = ip_hdr->ipv6->src; } else { - addr6 = &ip_hdr->ipv6->dst; + addr6 = ip_hdr->ipv6->dst; } if (!net_ipv6_is_addr_unspecified( &net_sin6(addr)->sin6_addr)) { - if (!net_ipv6_addr_cmp(&net_sin6(addr)->sin6_addr, - addr6)) { + if (!net_ipv6_addr_cmp_raw((uint8_t *)&net_sin6(addr)->sin6_addr, + addr6)) { return false; } } @@ -501,9 +501,9 @@ static bool conn_are_end_points_valid(struct net_pkt *pkt, } } else if (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6) { - if (net_ipv6_addr_cmp(&ip_hdr->ipv6->src, - &ip_hdr->ipv6->dst) || - net_ipv6_is_my_addr(&ip_hdr->ipv6->src)) { + if (net_ipv6_addr_cmp_raw(ip_hdr->ipv6->src, + ip_hdr->ipv6->dst) || + net_ipv6_is_my_addr((struct in6_addr *)ip_hdr->ipv6->src)) { my_src_addr = true; } } @@ -622,7 +622,7 @@ enum net_verdict net_conn_input(struct net_pkt *pkt, } } else if (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6) { - if (net_ipv6_is_addr_mcast(&ip_hdr->ipv6->dst)) { + if (net_ipv6_is_addr_mcast((struct in6_addr *)ip_hdr->ipv6->dst)) { is_mcast_pkt = true; } } diff --git a/subsys/net/ip/icmpv6.c b/subsys/net/ip/icmpv6.c index 0f4185309b2..76f2ee22a30 100644 --- a/subsys/net/ip/icmpv6.c +++ b/subsys/net/ip/icmpv6.c @@ -132,11 +132,11 @@ enum net_verdict icmpv6_handle_echo_request(struct net_pkt *pkt, goto drop; } - if (net_ipv6_is_addr_mcast(&ip_hdr->dst)) { + if (net_ipv6_is_addr_mcast((struct in6_addr *)ip_hdr->dst)) { src = net_if_ipv6_select_src_addr(net_pkt_iface(pkt), - &ip_hdr->dst); + (struct in6_addr *)ip_hdr->dst); } else { - src = &ip_hdr->dst; + src = (struct in6_addr *)ip_hdr->dst; } /* We must not set the destination ll address here but trust @@ -146,7 +146,7 @@ enum net_verdict icmpv6_handle_echo_request(struct net_pkt *pkt, net_pkt_lladdr_dst(reply)->addr = NULL; net_pkt_lladdr_src(reply)->addr = NULL; - if (net_ipv6_create(reply, src, &ip_hdr->src)) { + if (net_ipv6_create(reply, src, (struct in6_addr *)ip_hdr->src)) { NET_DBG("DROP: wrong buffer"); goto drop; } @@ -279,14 +279,14 @@ int net_icmpv6_send_error(struct net_pkt *orig, uint8_t type, uint8_t code, net_pkt_lladdr_src(pkt)->len = net_pkt_lladdr_dst(orig)->len; net_pkt_lladdr_dst(pkt)->len = net_pkt_lladdr_src(orig)->len; - if (net_ipv6_is_addr_mcast(&ip_hdr->dst)) { + if (net_ipv6_is_addr_mcast((struct in6_addr *)ip_hdr->dst)) { src = net_if_ipv6_select_src_addr(net_pkt_iface(pkt), - &ip_hdr->dst); + (struct in6_addr *)ip_hdr->dst); } else { - src = &ip_hdr->dst; + src = (struct in6_addr *)ip_hdr->dst; } - if (net_ipv6_create(pkt, src, &ip_hdr->src) || + if (net_ipv6_create(pkt, src, (struct in6_addr *)ip_hdr->src) || net_icmpv6_create(pkt, type, code)) { goto drop; } diff --git a/subsys/net/ip/ipv6.c b/subsys/net/ip/ipv6.c index b9e32a43b50..2cb8fb9174c 100644 --- a/subsys/net/ip/ipv6.c +++ b/subsys/net/ip/ipv6.c @@ -75,8 +75,8 @@ int net_ipv6_create(struct net_pkt *pkt, net_if_ipv6_get_hop_limit(net_pkt_iface(pkt)); } - net_ipaddr_copy(&ipv6_hdr->dst, dst); - net_ipaddr_copy(&ipv6_hdr->src, src); + net_ipv6_addr_copy_raw(ipv6_hdr->dst, (uint8_t *)dst); + net_ipv6_addr_copy_raw(ipv6_hdr->src, (uint8_t *)src); net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv6_hdr)); net_pkt_set_ipv6_ext_len(pkt, 0); @@ -153,7 +153,7 @@ static inline bool ipv6_drop_on_unknown_option(struct net_pkt *pkt, case 0x40: break; case 0xc0: - if (net_ipv6_is_addr_mcast(&hdr->dst)) { + if (net_ipv6_is_addr_mcast((struct in6_addr *)hdr->dst)) { break; } @@ -290,21 +290,23 @@ static enum net_verdict ipv6_route_packet(struct net_pkt *pkt, /* Check if the packet can be routed */ if (IS_ENABLED(CONFIG_NET_ROUTING)) { - found = net_route_get_info(NULL, &hdr->dst, &route, - &nexthop); + found = net_route_get_info(NULL, (struct in6_addr *)hdr->dst, + &route, &nexthop); } else { found = net_route_get_info(net_pkt_iface(pkt), - &hdr->dst, &route, &nexthop); + (struct in6_addr *)hdr->dst, + &route, &nexthop); } if (found) { int ret; if (IS_ENABLED(CONFIG_NET_ROUTING) && - (net_ipv6_is_ll_addr(&hdr->src) || - net_ipv6_is_ll_addr(&hdr->dst))) { + (net_ipv6_is_ll_addr((struct in6_addr *)hdr->src) || + net_ipv6_is_ll_addr((struct in6_addr *)hdr->dst))) { /* RFC 4291 ch 2.5.6 */ - ipv6_no_route_info(pkt, &hdr->src, &hdr->dst); + ipv6_no_route_info(pkt, (struct in6_addr *)hdr->src, + (struct in6_addr *)hdr->dst); goto drop; } @@ -327,7 +329,8 @@ static enum net_verdict ipv6_route_packet(struct net_pkt *pkt, pkt, net_pkt_orig_iface(pkt), net_pkt_iface(pkt)); - add_route(net_pkt_orig_iface(pkt), &hdr->src, 128); + add_route(net_pkt_orig_iface(pkt), + (struct in6_addr *)hdr->src, 128); } ret = net_route_packet(pkt, nexthop); @@ -343,7 +346,7 @@ static enum net_verdict ipv6_route_packet(struct net_pkt *pkt, struct net_if *iface = NULL; int ret; - if (net_if_ipv6_addr_onlink(&iface, &hdr->dst)) { + if (net_if_ipv6_addr_onlink(&iface, (struct in6_addr *)hdr->dst)) { ret = net_route_packet_if(pkt, iface); if (ret < 0) { NET_DBG("Cannot re-route pkt %p " @@ -385,9 +388,9 @@ static enum net_verdict ipv6_forward_mcast_packet(struct net_pkt *pkt, /* check if routing loop could be created or if the destination is of * interface local scope or if from link local source */ - if (net_ipv6_is_addr_mcast(&hdr->src) || - net_ipv6_is_addr_mcast_iface(&hdr->dst) || - net_ipv6_is_ll_addr(&hdr->src)) { + if (net_ipv6_is_addr_mcast((struct in6_addr *)hdr->src) || + net_ipv6_is_addr_mcast_iface((struct in6_addr *)hdr->dst) || + net_ipv6_is_ll_addr((struct in6_addr *)hdr->src)) { return NET_CONTINUE; } @@ -464,29 +467,30 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback) log_strdup(net_sprint_ipv6_addr(&hdr->src)), log_strdup(net_sprint_ipv6_addr(&hdr->dst))); - if (net_ipv6_is_addr_unspecified(&hdr->src)) { + if (net_ipv6_is_addr_unspecified((struct in6_addr *)hdr->src)) { NET_DBG("DROP: src addr is %s", "unspecified"); goto drop; } - if (net_ipv6_is_addr_mcast(&hdr->src) || - net_ipv6_is_addr_mcast_scope(&hdr->dst, 0)) { + if (net_ipv6_is_addr_mcast((struct in6_addr *)hdr->src) || + net_ipv6_is_addr_mcast_scope((struct in6_addr *)hdr->dst, 0)) { NET_DBG("DROP: multicast packet"); goto drop; } if (!is_loopback) { - if (net_ipv6_is_addr_loopback(&hdr->dst) || - net_ipv6_is_addr_loopback(&hdr->src)) { + if (net_ipv6_is_addr_loopback((struct in6_addr *)hdr->dst) || + net_ipv6_is_addr_loopback((struct in6_addr *)hdr->src)) { NET_DBG("DROP: ::1 packet"); goto drop; } - if (net_ipv6_is_addr_mcast_iface(&hdr->dst) || + if (net_ipv6_is_addr_mcast_iface((struct in6_addr *)hdr->dst) || (net_ipv6_is_addr_mcast_group( - &hdr->dst, net_ipv6_unspecified_address()) && - (net_ipv6_is_addr_mcast_site(&hdr->dst) || - net_ipv6_is_addr_mcast_org(&hdr->dst)))) { + (struct in6_addr *)hdr->dst, + net_ipv6_unspecified_address()) && + (net_ipv6_is_addr_mcast_site((struct in6_addr *)hdr->dst) || + net_ipv6_is_addr_mcast_org((struct in6_addr *)hdr->dst)))) { NET_DBG("DROP: invalid scope multicast packet"); goto drop; } @@ -500,7 +504,7 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback) net_pkt_set_family(pkt, PF_INET6); if (IS_ENABLED(CONFIG_NET_ROUTE_MCAST) && - net_ipv6_is_addr_mcast(&hdr->dst)) { + net_ipv6_is_addr_mcast((struct in6_addr *)hdr->dst)) { /* If the packet is a multicast packet and multicast routing * is activated, we give the packet to the routing engine. * @@ -513,8 +517,8 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback) } } - if (!net_ipv6_is_addr_mcast(&hdr->dst)) { - if (!net_ipv6_is_my_addr(&hdr->dst)) { + if (!net_ipv6_is_addr_mcast((struct in6_addr *)hdr->dst)) { + if (!net_ipv6_is_my_addr((struct in6_addr *)hdr->dst)) { if (ipv6_route_packet(pkt, hdr) == NET_OK) { return NET_OK; } @@ -528,16 +532,18 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback) * RFC 4291 ch 2.5.6 */ if (IS_ENABLED(CONFIG_NET_ROUTING) && - net_ipv6_is_ll_addr(&hdr->src) && - !net_if_ipv6_addr_lookup_by_iface(pkt_iface, &hdr->dst)) { - ipv6_no_route_info(pkt, &hdr->src, &hdr->dst); + net_ipv6_is_ll_addr((struct in6_addr *)hdr->src) && + !net_if_ipv6_addr_lookup_by_iface( + pkt_iface, (struct in6_addr *)hdr->dst)) { + ipv6_no_route_info(pkt, (struct in6_addr *)hdr->src, + (struct in6_addr *)hdr->dst); goto drop; } } - if (net_ipv6_is_addr_mcast(&hdr->dst) && - !(net_ipv6_is_addr_mcast_iface(&hdr->dst) || - net_ipv6_is_addr_mcast_link_all_nodes(&hdr->dst))) { + if (net_ipv6_is_addr_mcast((struct in6_addr *)hdr->dst) && + !(net_ipv6_is_addr_mcast_iface((struct in6_addr *)hdr->dst) || + net_ipv6_is_addr_mcast_link_all_nodes((struct in6_addr *)hdr->dst))) { /* If we receive a packet with a interface-local or * link-local all-nodes multicast destination address we * always have to pass it to the upper layer. @@ -548,7 +554,8 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback) * packet will be dropped. * RFC4291 ch 2.7.1, ch 2.8 */ - if_mcast_addr = net_if_ipv6_maddr_lookup(&hdr->dst, &pkt_iface); + if_mcast_addr = net_if_ipv6_maddr_lookup( + (struct in6_addr *)hdr->dst, &pkt_iface); if (!if_mcast_addr || !net_if_ipv6_maddr_is_joined(if_mcast_addr)) { @@ -679,7 +686,7 @@ enum net_verdict net_ipv6_input(struct net_pkt *pkt, bool is_loopback) struct net_addr remote_addr; remote_addr.family = AF_INET6; - net_ipaddr_copy(&remote_addr.in6_addr, &hdr->src); + net_ipv6_addr_copy_raw((uint8_t *)&remote_addr.in6_addr, hdr->src); /* Get rid of the old IP header */ net_pkt_cursor_restore(pkt, &hdr_start); diff --git a/subsys/net/ip/ipv6_fragment.c b/subsys/net/ip/ipv6_fragment.c index 6995d3ed1e0..79b00822d2b 100644 --- a/subsys/net/ip/ipv6_fragment.c +++ b/subsys/net/ip/ipv6_fragment.c @@ -491,7 +491,8 @@ enum net_verdict net_ipv6_handle_fragment_hdr(struct net_pkt *pkt, goto drop; } - reass = reassembly_get(id, &hdr->src, &hdr->dst); + reass = reassembly_get(id, (struct in6_addr *)hdr->src, + (struct in6_addr *)hdr->dst); if (!reass) { NET_DBG("Cannot get reassembly slot, dropping pkt %p", pkt); goto drop; diff --git a/subsys/net/ip/ipv6_nbr.c b/subsys/net/ip/ipv6_nbr.c index dd4afa6b36d..aec8250d8ea 100644 --- a/subsys/net/ip/ipv6_nbr.c +++ b/subsys/net/ip/ipv6_nbr.c @@ -843,9 +843,9 @@ ignore_frag_error: */ if ((net_pkt_lladdr_dst(pkt)->addr && ((IS_ENABLED(CONFIG_NET_ROUTING) && - net_ipv6_is_ll_addr(&ip_hdr->dst)) || + net_ipv6_is_ll_addr((struct in6_addr *)ip_hdr->dst)) || !IS_ENABLED(CONFIG_NET_ROUTING))) || - net_ipv6_is_addr_mcast(&ip_hdr->dst) || + net_ipv6_is_addr_mcast((struct in6_addr *)ip_hdr->dst) || /* Workaround Linux bug, see: * https://github.com/zephyrproject-rtos/zephyr/issues/3111 */ @@ -854,8 +854,8 @@ ignore_frag_error: return NET_OK; } - if (net_if_ipv6_addr_onlink(&iface, &ip_hdr->dst)) { - nexthop = &ip_hdr->dst; + if (net_if_ipv6_addr_onlink(&iface, (struct in6_addr *)ip_hdr->dst)) { + nexthop = (struct in6_addr *)ip_hdr->dst; net_pkt_set_iface(pkt, iface); } else { /* We need to figure out where the destination @@ -863,7 +863,8 @@ ignore_frag_error: */ bool try_route = false; - nexthop = check_route(NULL, &ip_hdr->dst, &try_route); + nexthop = check_route(NULL, (struct in6_addr *)ip_hdr->dst, + &try_route); if (!nexthop) { return NET_DROP; } @@ -936,7 +937,8 @@ try_send: #if defined(CONFIG_NET_IPV6_ND) /* We need to send NS and wait for NA before sending the packet. */ ret = net_ipv6_send_ns(net_pkt_iface(pkt), pkt, - &ip_hdr->src, NULL, nexthop, false); + (struct in6_addr *)ip_hdr->src, NULL, nexthop, + false); if (ret < 0) { /* In case of an error, the NS send function will unref * the pkt. @@ -1198,7 +1200,8 @@ static enum net_verdict handle_ns_input(struct net_pkt *pkt, switch (nd_opt_hdr->type) { case NET_ICMPV6_ND_OPT_SLLAO: - if (net_ipv6_is_addr_unspecified(&ip_hdr->src)) { + if (net_ipv6_is_addr_unspecified( + (struct in6_addr *)ip_hdr->src)) { goto drop; } @@ -1245,7 +1248,7 @@ static enum net_verdict handle_ns_input(struct net_pkt *pkt, nexthop = check_route(NULL, &ns_hdr->tgt, NULL); if (nexthop) { ns_routing_info(pkt, nexthop, &ns_hdr->tgt); - na_dst = &ip_hdr->dst; + na_dst = (struct in6_addr *)ip_hdr->dst; /* Note that the target is not the address of * the "nethop" as that is a link-local address * which is not routable. @@ -1257,7 +1260,8 @@ static enum net_verdict handle_ns_input(struct net_pkt *pkt, * received. */ na_src = net_if_ipv6_select_src_addr( - net_pkt_iface(pkt), &ip_hdr->src); + net_pkt_iface(pkt), + (struct in6_addr *)ip_hdr->src); if (!na_src) { NET_DBG("DROP: No interface address " "for dst %s iface %p/%d", @@ -1280,22 +1284,22 @@ static enum net_verdict handle_ns_input(struct net_pkt *pkt, goto drop; } else { tgt = &ifaddr->address.in6_addr; - na_src = &ip_hdr->dst; + na_src = (struct in6_addr *)ip_hdr->dst; } nexthop_found: #if !defined(CONFIG_NET_IPV6_DAD) - if (net_ipv6_is_addr_unspecified(&ip_hdr->src)) { + if (net_ipv6_is_addr_unspecified((struct in6_addr *)ip_hdr->src)) { goto drop; } #else /* CONFIG_NET_IPV6_DAD */ /* Do DAD */ - if (net_ipv6_is_addr_unspecified(&ip_hdr->src)) { + if (net_ipv6_is_addr_unspecified((struct in6_addr *)ip_hdr->src)) { - if (!net_ipv6_is_addr_solicited_node(&ip_hdr->dst)) { + if (!net_ipv6_is_addr_solicited_node((struct in6_addr *)ip_hdr->dst)) { NET_DBG("DROP: Not solicited node addr %s", log_strdup(net_sprint_ipv6_addr(&ip_hdr->dst))); goto drop; @@ -1314,27 +1318,30 @@ nexthop_found: } /* We reuse the received packet for the NA addresses*/ - net_ipv6_addr_create_ll_allnodes_mcast(&ip_hdr->dst); - net_ipaddr_copy(&ip_hdr->src, - net_if_ipv6_select_src_addr(net_pkt_iface(pkt), - &ip_hdr->dst)); - na_src = &ip_hdr->src; - na_dst = &ip_hdr->dst; + net_ipv6_addr_create_ll_allnodes_mcast( + (struct in6_addr *)ip_hdr->dst); + net_ipaddr_copy((struct in6_addr *)ip_hdr->src, + net_if_ipv6_select_src_addr( + net_pkt_iface(pkt), + (struct in6_addr *)ip_hdr->dst)); + + na_src = (struct in6_addr *)ip_hdr->src; + na_dst = (struct in6_addr *)ip_hdr->dst; flags = NET_ICMPV6_NA_FLAG_OVERRIDE; goto send_na; } #endif /* CONFIG_NET_IPV6_DAD */ - if (net_ipv6_is_my_addr(&ip_hdr->src)) { + if (net_ipv6_is_my_addr((struct in6_addr *)ip_hdr->src)) { NET_DBG("DROP: Duplicate IPv6 %s address", log_strdup(net_sprint_ipv6_addr(&ip_hdr->src))); goto drop; } /* Address resolution */ - if (net_ipv6_is_addr_solicited_node(&ip_hdr->dst)) { + if (net_ipv6_is_addr_solicited_node((struct in6_addr *)ip_hdr->dst)) { na_src = &ns_hdr->tgt; - na_dst = &ip_hdr->src; + na_dst = (struct in6_addr *)ip_hdr->src; flags = NET_ICMPV6_NA_FLAG_SOLICITED | NET_ICMPV6_NA_FLAG_OVERRIDE; goto send_na; @@ -1347,15 +1354,17 @@ nexthop_found: /* Neighbor Unreachability Detection (NUD) */ if (IS_ENABLED(CONFIG_NET_ROUTING)) { - ifaddr = net_if_ipv6_addr_lookup(&ip_hdr->dst, NULL); + ifaddr = net_if_ipv6_addr_lookup((struct in6_addr *)ip_hdr->dst, + NULL); } else { - ifaddr = net_if_ipv6_addr_lookup_by_iface(net_pkt_iface(pkt), - &ip_hdr->dst); + ifaddr = net_if_ipv6_addr_lookup_by_iface( + net_pkt_iface(pkt), + (struct in6_addr *)ip_hdr->dst); } if (ifaddr) { na_src = &ns_hdr->tgt; - na_dst = &ip_hdr->src; + na_dst = (struct in6_addr *)ip_hdr->src; tgt = &ifaddr->address.in6_addr; flags = NET_ICMPV6_NA_FLAG_SOLICITED | NET_ICMPV6_NA_FLAG_OVERRIDE; @@ -1368,7 +1377,7 @@ nexthop_found: send_na: if (src_lladdr.len) { if (!net_ipv6_nbr_add(net_pkt_iface(pkt), - &ip_hdr->src, + (struct in6_addr *)ip_hdr->src, &src_lladdr, false, NET_IPV6_NBR_STATE_INCOMPLETE)) { goto drop; @@ -1741,7 +1750,7 @@ static enum net_verdict handle_na_input(struct net_pkt *pkt, (ip_hdr->hop_limit != NET_IPV6_ND_HOP_LIMIT) || net_ipv6_is_addr_mcast(&na_hdr->tgt) || (na_hdr->flags & NET_ICMPV6_NA_FLAG_SOLICITED && - net_ipv6_is_addr_mcast(&ip_hdr->dst))) && + net_ipv6_is_addr_mcast((struct in6_addr *)ip_hdr->dst))) && (icmp_hdr->code != 0U)) { goto drop; } @@ -2046,7 +2055,7 @@ static inline struct net_nbr *handle_ra_neighbor(struct net_pkt *pkt, uint8_t le lladdr.addr = llstorage.addr; return net_ipv6_nbr_add(net_pkt_iface(pkt), - &NET_IPV6_HDR(pkt)->src, + (struct in6_addr *)NET_IPV6_HDR(pkt)->src, &lladdr, true, NET_IPV6_NBR_STATE_STALE); } @@ -2294,7 +2303,7 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt, sizeof(struct net_icmpv6_ra_hdr) + sizeof(struct net_icmpv6_nd_opt_hdr))) || (ip_hdr->hop_limit != NET_IPV6_ND_HOP_LIMIT) || - !net_ipv6_is_ll_addr(&ip_hdr->src)) && + !net_ipv6_is_ll_addr((struct in6_addr *)ip_hdr->src)) && icmp_hdr->code != 0U) { goto drop; } @@ -2414,7 +2423,8 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt, net_pkt_get_data(pkt, &nd_access); } - router = net_if_ipv6_router_lookup(net_pkt_iface(pkt), &ip_hdr->src); + router = net_if_ipv6_router_lookup(net_pkt_iface(pkt), + (struct in6_addr *)ip_hdr->src); if (router) { if (!router_lifetime) { /* TODO: Start rs_timer on iface if no routers @@ -2431,7 +2441,8 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt, } } else { net_if_ipv6_router_add(net_pkt_iface(pkt), - &ip_hdr->src, router_lifetime); + (struct in6_addr *)ip_hdr->src, + router_lifetime); } if (nbr && net_ipv6_nbr_data(nbr)->pending) { diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index 279a1d07d51..9cc57f47821 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -199,7 +199,7 @@ static inline int check_ip_addr(struct net_pkt *pkt) { #if defined(CONFIG_NET_IPV6) if (net_pkt_family(pkt) == AF_INET6) { - if (net_ipv6_addr_cmp(&NET_IPV6_HDR(pkt)->dst, + if (net_ipv6_addr_cmp((struct in6_addr *)NET_IPV6_HDR(pkt)->dst, net_ipv6_unspecified_address())) { NET_DBG("IPv6 dst address missing"); return -EADDRNOTAVAIL; @@ -208,17 +208,19 @@ static inline int check_ip_addr(struct net_pkt *pkt) /* If the destination address is our own, then route it * back to us. */ - if (net_ipv6_is_addr_loopback(&NET_IPV6_HDR(pkt)->dst) || - net_ipv6_is_my_addr(&NET_IPV6_HDR(pkt)->dst)) { + if (net_ipv6_is_addr_loopback( + (struct in6_addr *)NET_IPV6_HDR(pkt)->dst) || + net_ipv6_is_my_addr( + (struct in6_addr *)NET_IPV6_HDR(pkt)->dst)) { struct in6_addr addr; /* Swap the addresses so that in receiving side * the packet is accepted. */ - net_ipaddr_copy(&addr, &NET_IPV6_HDR(pkt)->src); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->src, - &NET_IPV6_HDR(pkt)->dst); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->dst, &addr); + net_ipv6_addr_copy_raw((uint8_t *)&addr, NET_IPV6_HDR(pkt)->src); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->src, + NET_IPV6_HDR(pkt)->dst); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->dst, (uint8_t *)&addr); return 1; } @@ -229,7 +231,8 @@ static inline int check_ip_addr(struct net_pkt *pkt) * in local host, so this is similar as how ::1 unicast * addresses are handled. See RFC 3513 ch 2.7 for details. */ - if (net_ipv6_is_addr_mcast_iface(&NET_IPV6_HDR(pkt)->dst)) { + if (net_ipv6_is_addr_mcast_iface( + (struct in6_addr *)NET_IPV6_HDR(pkt)->dst)) { NET_DBG("IPv6 interface scope mcast dst address"); return 1; } @@ -237,7 +240,8 @@ static inline int check_ip_addr(struct net_pkt *pkt) /* The source check must be done after the destination check * as having src ::1 is perfectly ok if dst is ::1 too. */ - if (net_ipv6_is_addr_loopback(&NET_IPV6_HDR(pkt)->src)) { + if (net_ipv6_is_addr_loopback( + (struct in6_addr *)NET_IPV6_HDR(pkt)->src)) { NET_DBG("IPv6 loopback src address"); return -EADDRNOTAVAIL; } diff --git a/subsys/net/ip/route.c b/subsys/net/ip/route.c index 6a4b478604f..99716b81bf8 100644 --- a/subsys/net/ip/route.c +++ b/subsys/net/ip/route.c @@ -659,7 +659,7 @@ int net_route_mcast_forward_packet(struct net_pkt *pkt, if (!net_if_flag_is_set(route->iface, NET_IF_FORWARD_MULTICASTS) || - !net_ipv6_is_prefix(hdr->dst.s6_addr, + !net_ipv6_is_prefix(hdr->dst, route->group.s6_addr, route->prefix_len) || (pkt->iface == route->iface)) { diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index fceefcab748..42958f52285 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -185,9 +185,9 @@ static int tcp_endpoint_set(union tcp_endpoint *ep, struct net_pkt *pkt, ep->sin6.sin6_port = src == TCP_EP_SRC ? th_sport(th) : th_dport(th); - net_ipaddr_copy(&ep->sin6.sin6_addr, - src == TCP_EP_SRC ? - &ip->src : &ip->dst); + net_ipv6_addr_copy_raw((uint8_t *)&ep->sin6.sin6_addr, + src == TCP_EP_SRC ? + ip->src : ip->dst); ep->sa.sa_family = AF_INET6; } else { ret = -EINVAL; @@ -837,8 +837,10 @@ static bool is_destination_local(struct net_pkt *pkt) } if (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(pkt) == AF_INET6) { - if (net_ipv6_is_addr_loopback(&NET_IPV6_HDR(pkt)->dst) || - net_ipv6_is_my_addr(&NET_IPV6_HDR(pkt)->dst)) { + if (net_ipv6_is_addr_loopback( + (struct in6_addr *)NET_IPV6_HDR(pkt)->dst) || + net_ipv6_is_my_addr( + (struct in6_addr *)NET_IPV6_HDR(pkt)->dst)) { return true; } } diff --git a/subsys/net/l2/canbus/6locan.c b/subsys/net/l2/canbus/6locan.c index 0f655771757..333612a7f57 100644 --- a/subsys/net/l2/canbus/6locan.c +++ b/subsys/net/l2/canbus/6locan.c @@ -1041,7 +1041,7 @@ static void canbus_ipv6_mcast_to_dest(struct net_pkt *pkt, struct net_canbus_lladdr *dest_addr) { dest_addr->addr = - sys_be16_to_cpu(UNALIGNED_GET(&NET_IPV6_HDR(pkt)->dst.s6_addr16[7])); + sys_be16_to_cpu(UNALIGNED_GET((uint16_t *)&NET_IPV6_HDR(pkt)->dst[14])); } static inline uint16_t canbus_eth_to_can_addr(struct net_linkaddr *lladdr) @@ -1062,7 +1062,7 @@ static int canbus_send(struct net_if *iface, struct net_pkt *pkt) return -EINVAL; } - mcast = net_ipv6_is_addr_mcast(&NET_IPV6_HDR(pkt)->dst); + mcast = net_ipv6_is_addr_mcast((struct in6_addr *)NET_IPV6_HDR(pkt)->dst); if (mcast || canbus_dest_is_mcast(pkt)) { canbus_ipv6_mcast_to_dest(pkt, &dest_addr); } else if (IS_ENABLED(CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR) && diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index edf62efa8b6..9f3e96ae888 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -415,11 +415,11 @@ static bool ethernet_fill_in_dst_on_ipv6_mcast(struct net_pkt *pkt, struct net_eth_addr *dst) { if (net_pkt_family(pkt) == AF_INET6 && - net_ipv6_is_addr_mcast(&NET_IPV6_HDR(pkt)->dst)) { + net_ipv6_is_addr_mcast((struct in6_addr *)NET_IPV6_HDR(pkt)->dst)) { memcpy(dst, (uint8_t *)multicast_eth_addr.addr, sizeof(struct net_eth_addr) - 4); memcpy((uint8_t *)dst + 2, - (uint8_t *)(&NET_IPV6_HDR(pkt)->dst) + 12, + NET_IPV6_HDR(pkt)->dst + 12, sizeof(struct net_eth_addr) - 2); return true; @@ -446,7 +446,7 @@ static enum net_verdict set_vlan_tag(struct ethernet_context *ctx, if (net_pkt_family(pkt) == AF_INET6) { struct net_if *target; - if (net_if_ipv6_addr_lookup(&NET_IPV6_HDR(pkt)->src, + if (net_if_ipv6_addr_lookup((struct in6_addr *)NET_IPV6_HDR(pkt)->src, &target)) { if (target != iface) { NET_DBG("Iface %p should be %p", iface, diff --git a/subsys/net/l2/ieee802154/ieee802154.c b/subsys/net/l2/ieee802154/ieee802154.c index c6fd3642f70..81a264e69a3 100644 --- a/subsys/net/l2/ieee802154/ieee802154.c +++ b/subsys/net/l2/ieee802154/ieee802154.c @@ -292,8 +292,8 @@ static int ieee802154_send(struct net_if *iface, struct net_pkt *pkt) frame_buf = net_buf_alloc(&frame_buf_pool, K_FOREVER); } - ll_hdr_size = ieee802154_compute_header_size(iface, - &NET_IPV6_HDR(pkt)->dst); + ll_hdr_size = ieee802154_compute_header_size( + iface, (struct in6_addr *)&NET_IPV6_HDR(pkt)->dst); /* len will hold the hdr size difference on success */ len = net_6lo_compress(pkt, true); diff --git a/subsys/net/l2/virtual/ipip/ipip.c b/subsys/net/l2/virtual/ipip/ipip.c index d44b0ec0e02..1a43c4e0191 100644 --- a/subsys/net/l2/virtual/ipip/ipip.c +++ b/subsys/net/l2/virtual/ipip/ipip.c @@ -329,7 +329,7 @@ static enum net_verdict interface_input(struct net_if *input_iface, } /* RFC4213 chapter 3.6 */ - iface = net_if_ipv6_select_src_iface(&hdr->dst); + iface = net_if_ipv6_select_src_iface((struct in6_addr *)hdr->dst); if (iface == NULL) { NET_DBG("DROP: not for me (dst %s)", net_sprint_ipv6_addr(&hdr->dst)); diff --git a/subsys/net/lib/dns/llmnr_responder.c b/subsys/net/lib/dns/llmnr_responder.c index 8aeeb1f3649..e3aef5d17c2 100644 --- a/subsys/net/lib/dns/llmnr_responder.c +++ b/subsys/net/lib/dns/llmnr_responder.c @@ -76,7 +76,7 @@ static void create_ipv6_dst_addr(struct net_pkt *pkt, addr->sin6_family = AF_INET6; addr->sin6_port = udp_hdr->src_port; - net_ipaddr_copy(&addr->sin6_addr, &NET_IPV6_HDR(pkt)->src); + net_ipv6_addr_copy_raw((uint8_t *)&addr->sin6_addr, NET_IPV6_HDR(pkt)->src); } #endif @@ -301,7 +301,7 @@ static int create_ipv4_answer(struct net_context *ctx, } else if (qtype == DNS_RR_TYPE_AAAA) { #if defined(CONFIG_NET_IPV6) addr = get_ipv6_src(net_pkt_iface(pkt), - &ip_hdr->ipv6->src); + (struct in6_addr *)ip_hdr->ipv6->src); if (!addr) { return -ENOENT; } @@ -343,7 +343,7 @@ static int create_ipv6_answer(struct net_context *ctx, if (qtype == DNS_RR_TYPE_AAAA) { addr = get_ipv6_src(net_pkt_iface(pkt), - &ip_hdr->ipv6->src); + (struct in6_addr *)ip_hdr->ipv6->src); if (!addr) { return -ENOENT; } diff --git a/subsys/net/lib/dns/mdns_responder.c b/subsys/net/lib/dns/mdns_responder.c index 6ee3b709435..b720f9b0d3d 100644 --- a/subsys/net/lib/dns/mdns_responder.c +++ b/subsys/net/lib/dns/mdns_responder.c @@ -264,7 +264,7 @@ static int send_response(struct net_context *ctx, const struct in6_addr *addr; addr = net_if_ipv6_select_src_addr(net_pkt_iface(pkt), - &ip_hdr->ipv6->src); + (struct in6_addr *)ip_hdr->ipv6->src); ret = create_answer(ctx, query, qtype, sizeof(struct in6_addr), (uint8_t *)addr); @@ -353,7 +353,7 @@ static void send_sd_response(struct net_context *ctx, if (IS_ENABLED(CONFIG_NET_IPV6)) { /* Look up the local IPv6 address */ addr6 = net_if_ipv6_select_src_addr(net_pkt_iface(pkt), - &ip_hdr->ipv6->src); + (struct in6_addr *)ip_hdr->ipv6->src); } ret = dns_sd_query_extract(dns_msg->msg, diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index c7bbea9ed68..c48f480b238 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -889,7 +889,7 @@ static int sock_get_pkt_src_addr(struct net_pkt *pkt, goto error; } - net_ipaddr_copy(&addr6->sin6_addr, &ipv6_hdr->src); + net_ipv6_addr_copy_raw((uint8_t *)&addr6->sin6_addr, ipv6_hdr->src); port = &addr6->sin6_port; } else { ret = -ENOTSUP; diff --git a/tests/net/6lo/src/main.c b/tests/net/6lo/src/main.c index 0cc196cec7f..cf015976fdb 100644 --- a/tests/net/6lo/src/main.c +++ b/tests/net/6lo/src/main.c @@ -46,54 +46,54 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_6LO_LOG_LEVEL); */ #define src_sac1_sam00 \ - { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } #define src_sam00 \ - { { { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } + { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } #define src_sam01 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } #define src_sam10 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } #define src_sam11 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb } #define dst_m1_dam00 \ - { { { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } } } + { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } #define dst_m1_dam01 \ - { { { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 } } } + { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 } #define dst_m1_dam10 \ - { { { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33 } } } + { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33 } #define dst_m1_dam11 \ - { { { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11 } } } + { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11 } #define dst_dam00 \ - { { { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } + { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } #define dst_dam01 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } #define dst_dam10 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } #define dst_dam11 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xaa } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xaa } uint8_t src_mac[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb }; uint8_t dst_mac[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xaa }; @@ -129,23 +129,23 @@ static struct net_icmpv6_nd_opt_6co ctx2 = { }; #define src_sac1_sam01 \ - { { { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } } } + { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } #define dst_dac1_dam01 \ - { { { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } } } + { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } #define src_sac1_sam10 \ - { { { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } } } + { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } #define dst_dac1_dam10 \ - { { { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } } } + { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } #define src_sac1_sam11 \ - { { { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb } } } + { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb } #define dst_dac1_dam11 \ - { { { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xaa } } } + { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xaa } #endif /* UDP Ports */ diff --git a/tests/net/checksum_offload/src/main.c b/tests/net/checksum_offload/src/main.c index a1dcf821037..69edbcbbd32 100644 --- a/tests/net/checksum_offload/src/main.c +++ b/tests/net/checksum_offload/src/main.c @@ -163,10 +163,10 @@ static int eth_tx_offloading_disabled(const struct device *dev, if (net_pkt_family(pkt) == AF_INET6) { struct in6_addr addr; - net_ipaddr_copy(&addr, &NET_IPV6_HDR(pkt)->src); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->src, - &NET_IPV6_HDR(pkt)->dst); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->dst, &addr); + net_ipv6_addr_copy_raw((uint8_t *)&addr, NET_IPV6_HDR(pkt)->src); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->src, + NET_IPV6_HDR(pkt)->dst); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->dst, (uint8_t *)&addr); } else { struct in_addr addr; diff --git a/tests/net/context/src/main.c b/tests/net/context/src/main.c index b2790575bb1..93540671a5f 100644 --- a/tests/net/context/src/main.c +++ b/tests/net/context/src/main.c @@ -914,10 +914,10 @@ static int tester_send(const struct device *dev, struct net_pkt *pkt) if (net_pkt_family(pkt) == AF_INET6) { struct in6_addr addr; - net_ipaddr_copy(&addr, &NET_IPV6_HDR(pkt)->src); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->src, - &NET_IPV6_HDR(pkt)->dst); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->dst, &addr); + net_ipv6_addr_copy_raw((uint8_t *)&addr, NET_IPV6_HDR(pkt)->src); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->src, + NET_IPV6_HDR(pkt)->dst); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->dst, (uint8_t *)&addr); } else { struct in_addr addr; diff --git a/tests/net/ieee802154/fragment/src/main.c b/tests/net/ieee802154/fragment/src/main.c index ce4e1846db0..0b405fa9ff6 100644 --- a/tests/net/ieee802154/fragment/src/main.c +++ b/tests/net/ieee802154/fragment/src/main.c @@ -45,48 +45,48 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_L2_IEEE802154_LOG_LEVEL); */ #define src_sac1_sam00 \ - { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } #define src_sam00 \ - { { { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } + { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } #define src_sam01 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } #define src_sam10 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } #define dst_m1_dam00 \ - { { { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } } } + { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } #define dst_m1_dam01 \ - { { { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 } } } + { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 } #define dst_m1_dam10 \ - { { { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33 } } } + { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33 } #define dst_m1_dam11 \ - { { { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11 } } } + { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11 } #define dst_dam00 \ - { { { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } + { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } #define dst_dam01 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa } #define dst_dam10 \ - { { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } } } + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb } /* UDP Ports */ diff --git a/tests/net/route_mcast/src/main.c b/tests/net/route_mcast/src/main.c index 6acafc6bd8d..44fa73a79cf 100644 --- a/tests/net/route_mcast/src/main.c +++ b/tests/net/route_mcast/src/main.c @@ -214,8 +214,8 @@ static bool check_packet_addresses(struct net_pkt *pkt) &ipv6_hdr->src, sizeof(struct in6_addr)) != 0) || (memcmp(&active_scenario.mcast, - &ipv6_hdr->dst, - sizeof(struct in6_addr)) != 0)) { + ipv6_hdr->dst, + sizeof(struct in6_addr)) != 0)) { return false; } diff --git a/tests/net/traffic_class/src/main.c b/tests/net/traffic_class/src/main.c index 6f442fc9bce..2dca0005534 100644 --- a/tests/net/traffic_class/src/main.c +++ b/tests/net/traffic_class/src/main.c @@ -172,10 +172,10 @@ static int eth_tx(const struct device *dev, struct net_pkt *pkt) /* Swap IP src and destination address so that we can receive * the packet and the stack will not reject it. */ - net_ipaddr_copy(&addr, &NET_IPV6_HDR(pkt)->src); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->src, - &NET_IPV6_HDR(pkt)->dst); - net_ipaddr_copy(&NET_IPV6_HDR(pkt)->dst, &addr); + net_ipv6_addr_copy_raw((uint8_t *)&addr, NET_IPV6_HDR(pkt)->src); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->src, + NET_IPV6_HDR(pkt)->dst); + net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->dst, (uint8_t *)&addr); udp_hdr = net_udp_get_hdr(pkt, &hdr); zassert_not_null(udp_hdr, "UDP header missing");