Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/net/ipv6: Simplify type #14759

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions sys/include/net/ipv6/addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ extern "C" {
/**
* @brief Data type to represent an IPv6 address.
*/
typedef union {
uint8_t u8[16]; /**< divided by 16 8-bit words. */
network_uint16_t u16[8]; /**< divided by 8 16-bit words. */
network_uint32_t u32[4]; /**< divided by 4 32-bit words. */
network_uint64_t u64[2]; /**< divided by 2 64-bit words. */
typedef struct {
uint8_t u8[16]; /**< 16 bytes of IPv6 address */
} ipv6_addr_t;

/**
Expand Down Expand Up @@ -113,6 +110,11 @@ typedef union {
0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00 }}

/**
* @brief Length of the link local prefix
*/
#define IPV6_ADDR_LINK_LOCAL_PREFIX_BYTES (8U)

/**
* @brief Static initializer for the interface-local all nodes multicast IPv6
* address (ff01::1)
Expand Down Expand Up @@ -375,7 +377,7 @@ static inline bool ipv6_addr_is_ipv4_mapped(const ipv6_addr_t *addr)
{
return ((memcmp(addr, &ipv6_addr_unspecified,
sizeof(ipv6_addr_t) - sizeof(ipv4_addr_t) - 2) == 0) &&
(addr->u16[5].u16 == 0xffff));
(addr->u8[10] == 0xff) && (addr->u8[11] == 0xff));
}

/**
Expand Down Expand Up @@ -412,7 +414,8 @@ static inline bool ipv6_addr_is_multicast(const ipv6_addr_t *addr)
*/
static inline bool ipv6_addr_is_link_local(const ipv6_addr_t *addr)
{
return (memcmp(addr, &ipv6_addr_link_local_prefix, sizeof(addr->u64[0])) == 0) ||
return (memcmp(addr, &ipv6_addr_link_local_prefix,
IPV6_ADDR_LINK_LOCAL_PREFIX_BYTES) == 0) ||
(ipv6_addr_is_multicast(addr) &&
(addr->u8[1] & 0x0f) == IPV6_ADDR_MCAST_SCP_LINK_LOCAL);
}
Expand All @@ -435,10 +438,9 @@ static inline bool ipv6_addr_is_link_local(const ipv6_addr_t *addr)
*/
static inline bool ipv6_addr_is_site_local(const ipv6_addr_t *addr)
{
return (((byteorder_ntohs(addr->u16[0]) & 0xffc0) ==
IPV6_ADDR_SITE_LOCAL_PREFIX) ||
return (((addr->u8[0] == 0xfe) && ((addr->u8[1] & 0xc0) == 0xc0)) ||
(ipv6_addr_is_multicast(addr) &&
(addr->u8[1] & 0x0f) == IPV6_ADDR_MCAST_SCP_SITE_LOCAL));
(addr->u8[1] & 0x0f) == IPV6_ADDR_MCAST_SCP_SITE_LOCAL));
}

/**
Expand Down Expand Up @@ -587,7 +589,8 @@ static inline void ipv6_addr_set_loopback(ipv6_addr_t *addr)
*/
static inline void ipv6_addr_set_link_local_prefix(ipv6_addr_t *addr)
{
memcpy(addr, &ipv6_addr_link_local_prefix, sizeof(addr->u64[0]));
memcpy(addr, &ipv6_addr_link_local_prefix,
IPV6_ADDR_LINK_LOCAL_PREFIX_BYTES);
}

/**
Expand All @@ -603,7 +606,7 @@ static inline void ipv6_addr_set_link_local_prefix(ipv6_addr_t *addr)
*/
static inline void ipv6_addr_set_iid(ipv6_addr_t *addr, uint64_t iid)
{
addr->u64[1] = byteorder_htonll(iid);
byteorder_htobebufll(&addr->u8[8], iid);
}

/**
Expand All @@ -619,7 +622,7 @@ static inline void ipv6_addr_set_iid(ipv6_addr_t *addr, uint64_t iid)
*/
static inline void ipv6_addr_set_aiid(ipv6_addr_t *addr, uint8_t *iid)
{
memcpy(&addr->u64[1], iid, sizeof(addr->u64[1]));
memcpy(&addr->u8[8], iid, 8);
}

/**
Expand Down Expand Up @@ -687,11 +690,16 @@ static inline void ipv6_addr_set_all_routers_multicast(ipv6_addr_t *addr, unsign
*/
static inline void ipv6_addr_set_solicited_nodes(ipv6_addr_t *out, const ipv6_addr_t *in)
{
out->u64[0] = byteorder_htonll(0xff02000000000000);
out->u32[2] = byteorder_htonl(1);
out->u8[12] = 0xff;
static const ipv6_addr_t solicited_node_addr = {
.u8 = {
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00
}
};
*out = solicited_node_addr;
Comment on lines +693 to +699
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the already predefined prefix here?

Suggested change
static const ipv6_addr_t solicited_node_addr = {
.u8 = {
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00
}
};
*out = solicited_node_addr;
*out = ipv6_addr_solicited_node_prefix;

out->u8[13] = in->u8[13];
out->u16[7] = in->u16[7];
out->u8[14] = in->u8[14];
out->u8[15] = in->u8[15];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion sys/net/gnrc/network_layer/ipv6/nib/_nib-6ln.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool _resolve_addr_from_ipv6(const ipv6_addr_t *dst, gnrc_netif_t *netif,
uint8_t l2addr_len;

if ((l2addr_len = gnrc_netif_ipv6_iid_to_addr(netif,
(eui64_t *)&dst->u64[1],
(eui64_t *)&dst->u8[8],
nce->l2addr)) > 0) {
DEBUG("nib: resolve address %s%%%u by reverse translating to ",
ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)),
Expand Down
2 changes: 1 addition & 1 deletion sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ static inline int _get_l2addr_from_ipv6(const gnrc_netif_t *netif,
gnrc_ipv6_nib_nc_t *nce)
{
int res = gnrc_netif_ipv6_iid_to_addr(netif,
(eui64_t *)&node->ipv6.u64[1],
(eui64_t *)&node->ipv6.u8[8],
nce->l2addr);
if (res >= 0) {
DEBUG("nib: resolve address %s%%%u by reverse translating to ",
Expand Down
4 changes: 2 additions & 2 deletions sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void _auto_configure_addr(gnrc_netif_t *netif, const ipv6_addr_t *pfx,
#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LN)
bool new_address = false;
#endif /* CONFIG_GNRC_IPV6_NIB_6LN */
gnrc_netif_ipv6_get_iid(netif, (eui64_t *)&addr.u64[1]);
gnrc_netif_ipv6_get_iid(netif, (eui64_t *)&addr.u8[8]);
ipv6_addr_init_prefix(&addr, pfx, pfx_len);
if ((idx = gnrc_netif_ipv6_addr_idx(netif, &addr)) < 0) {
if ((idx = gnrc_netif_ipv6_addr_add_internal(netif, &addr, pfx_len,
Expand Down Expand Up @@ -138,7 +138,7 @@ static bool _try_addr_reconfiguration(gnrc_netif_t *netif)
if (remove_old) {
for (unsigned i = 0; i < CONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF; i++) {
ipv6_addr_t *addr = &netif->ipv6.addrs[i];
if (addr->u64[1].u64 == orig_iid.uint64.u64) {
if (!memcmp(&addr->u8[8], &orig_iid, sizeof(orig_iid))) {
gnrc_netif_ipv6_addr_remove_internal(netif, addr);
}
}
Expand Down
6 changes: 2 additions & 4 deletions sys/net/gnrc/network_layer/ndp/gnrc_ndp.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ gnrc_pktsnip_t *gnrc_ndp_nbr_sol_build(const ipv6_addr_t *tgt,
if (pkt != NULL) {
ndp_nbr_sol_t *nbr_sol = pkt->data;
nbr_sol->resv.u32 = 0;
nbr_sol->tgt.u64[0].u64 = tgt->u64[0].u64;
nbr_sol->tgt.u64[1].u64 = tgt->u64[1].u64;
memcpy(&nbr_sol->tgt, tgt, sizeof(*tgt));
}
#if ENABLE_DEBUG
else {
Expand All @@ -67,8 +66,7 @@ gnrc_pktsnip_t *gnrc_ndp_nbr_adv_build(const ipv6_addr_t *tgt, uint8_t flags,
ndp_nbr_adv_t *nbr_adv = pkt->data;
nbr_adv->flags = (flags & NDP_NBR_ADV_FLAGS_MASK);
nbr_adv->resv[0] = nbr_adv->resv[1] = nbr_adv->resv[2] = 0;
nbr_adv->tgt.u64[0].u64 = tgt->u64[0].u64;
nbr_adv->tgt.u64[1].u64 = tgt->u64[1].u64;
memcpy(&nbr_adv->tgt, tgt, sizeof(*tgt));
}
#if ENABLE_DEBUG
else {
Expand Down
58 changes: 24 additions & 34 deletions sys/net/gnrc/network_layer/sixlowpan/iphc/gnrc_sixlowpan_iphc.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
#define NHC_IPV6_EXT_EID_MOB (0x04 << 1)
#define NHC_IPV6_EXT_EID_IPV6 (0x07 << 1)

static const uint8_t addr_fffe[] = { 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00 };
static const uint8_t zeros8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

/* currently only used with forwarding output, remove guard if more debug info
* is added */
#ifdef MODULE_GNRC_SIXLOWPAN_FRAG_VRB
Expand Down Expand Up @@ -246,15 +249,14 @@ static size_t _iphc_ipv6_decode(const uint8_t *iphc_hdr,

case IPHC_SAC_SAM_16:
ipv6_addr_set_link_local_prefix(&ipv6_hdr->src);
ipv6_hdr->src.u32[2] = byteorder_htonl(0x000000ff);
ipv6_hdr->src.u16[6] = byteorder_htons(0xfe00);
memcpy(&ipv6_hdr->src.u8[8], addr_fffe, sizeof(addr_fffe));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipv6_hdr was completely zeroed in l. 166 so it might make more sense to just set the non-zero values here and remove addr_fffe altogether:

Suggested change
memcpy(&ipv6_hdr->src.u8[8], addr_fffe, sizeof(addr_fffe));
ipv6_hdr->src.u8[11] = 0xff;
ipv6_hdr->src.u8[12] = 0xfe;

memcpy(ipv6_hdr->src.u8 + 14, iphc_hdr + payload_offset, 2);
payload_offset += 2;
break;

case IPHC_SAC_SAM_L2:
if (gnrc_netif_hdr_ipv6_iid_from_src(
iface, netif_hdr, (eui64_t *)(&ipv6_hdr->src.u64[1])
iface, netif_hdr, (eui64_t *)(&ipv6_hdr->src.u8[8])
) < 0) {
DEBUG("6lo iphc: could not get source's IID\n");
return 0;
Expand All @@ -276,8 +278,7 @@ static size_t _iphc_ipv6_decode(const uint8_t *iphc_hdr,

case IPHC_SAC_SAM_CTX_16:
assert(ctx != NULL);
ipv6_hdr->src.u32[2] = byteorder_htonl(0x000000ff);
ipv6_hdr->src.u16[6] = byteorder_htons(0xfe00);
memcpy(&ipv6_hdr->src.u8[8], addr_fffe, sizeof(addr_fffe));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Suggested change
memcpy(&ipv6_hdr->src.u8[8], addr_fffe, sizeof(addr_fffe));
ipv6_hdr->src.u8[11] = 0xff;
ipv6_hdr->src.u8[12] = 0xfe;

memcpy(ipv6_hdr->src.u8 + 14, iphc_hdr + payload_offset, 2);
ipv6_addr_init_prefix(&ipv6_hdr->src, &ctx->prefix,
ctx->prefix_len);
Expand All @@ -287,7 +288,7 @@ static size_t _iphc_ipv6_decode(const uint8_t *iphc_hdr,
case IPHC_SAC_SAM_CTX_L2:
assert(ctx != NULL);
if (gnrc_netif_hdr_ipv6_iid_from_src(
iface, netif_hdr, (eui64_t *)(&ipv6_hdr->src.u64[1])
iface, netif_hdr, (eui64_t *)(&ipv6_hdr->src.u8[8])
) < 0) {
DEBUG("6lo iphc: could not get source's IID\n");
return 0;
Expand Down Expand Up @@ -330,15 +331,14 @@ static size_t _iphc_ipv6_decode(const uint8_t *iphc_hdr,

case IPHC_M_DAC_DAM_U_16:
ipv6_addr_set_link_local_prefix(&ipv6_hdr->dst);
ipv6_hdr->dst.u32[2] = byteorder_htonl(0x000000ff);
ipv6_hdr->dst.u16[6] = byteorder_htons(0xfe00);
memcpy(&ipv6_hdr->dst.u8[8], addr_fffe, sizeof(addr_fffe));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Suggested change
memcpy(&ipv6_hdr->dst.u8[8], addr_fffe, sizeof(addr_fffe));
ipv6_hdr->dst.u8[11] = 0xff;
ipv6_hdr->dst.u8[12] = 0xfe;

memcpy(ipv6_hdr->dst.u8 + 14, iphc_hdr + payload_offset, 2);
payload_offset += 2;
break;

case IPHC_M_DAC_DAM_U_L2:
if (gnrc_netif_hdr_ipv6_iid_from_dst(
iface, netif_hdr, (eui64_t *)(&ipv6_hdr->dst.u64[1])
iface, netif_hdr, (eui64_t *)(&ipv6_hdr->dst.u8[8])
) < 0) {
DEBUG("6lo iphc: could not get destination's IID\n");
return 0;
Expand All @@ -355,8 +355,7 @@ static size_t _iphc_ipv6_decode(const uint8_t *iphc_hdr,
break;

case IPHC_M_DAC_DAM_U_CTX_16:
ipv6_hdr->dst.u32[2] = byteorder_htonl(0x000000ff);
ipv6_hdr->dst.u16[6] = byteorder_htons(0xfe00);
memcpy(&ipv6_hdr->dst.u8[8], addr_fffe, sizeof(addr_fffe));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Suggested change
memcpy(&ipv6_hdr->dst.u8[8], addr_fffe, sizeof(addr_fffe));
ipv6_hdr->dst.u8[11] = 0xff;
ipv6_hdr->dst.u8[12] = 0xfe;

memcpy(ipv6_hdr->dst.u8 + 14, iphc_hdr + payload_offset, 2);
assert(ctx != NULL);
ipv6_addr_init_prefix(&ipv6_hdr->dst, &ctx->prefix,
Expand All @@ -366,7 +365,7 @@ static size_t _iphc_ipv6_decode(const uint8_t *iphc_hdr,

case IPHC_M_DAC_DAM_U_CTX_L2:
if (gnrc_netif_hdr_ipv6_iid_from_dst(
iface, netif_hdr, (eui64_t *)(&ipv6_hdr->dst.u64[1])
iface, netif_hdr, (eui64_t *)(&ipv6_hdr->dst.u8[8])
) < 0) {
DEBUG("6lo iphc: could not get destination's IID\n");
return 0;
Expand Down Expand Up @@ -1091,24 +1090,24 @@ static size_t _iphc_ipv6_encode(gnrc_pktsnip_t *pkt,
}
gnrc_netif_release(iface);

if ((ipv6_hdr->src.u64[1].u64 == iid.uint64.u64) ||
if ((!memcmp(&ipv6_hdr->src.u8[8], &iid, sizeof(iid))) ||
_context_overlaps_iid(src_ctx, &ipv6_hdr->src, &iid)) {
/* 0 bits. The address is derived from link-layer address */
iphc_hdr[IPHC2_IDX] |= IPHC_SAC_SAM_L2;
addr_comp = true;
}
else if ((byteorder_ntohl(ipv6_hdr->src.u32[2]) == 0x000000ff) &&
(byteorder_ntohs(ipv6_hdr->src.u16[6]) == 0xfe00)) {
else if (!memcmp(&ipv6_hdr->src.u8[8],
addr_fffe, sizeof(addr_fffe))) {
Comment on lines +1099 to +1100
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather check byte-wise here then?

/* 16 bits. The address is derived using 16 bits carried inline */
iphc_hdr[IPHC2_IDX] |= IPHC_SAC_SAM_16;
memcpy(iphc_hdr + inline_pos, ipv6_hdr->src.u16 + 7, 2);
memcpy(iphc_hdr + inline_pos, ipv6_hdr->src.u8 + 14, 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While pointer arithmetics are cool, time taught me, that it is waaay clearer if you use array notation ;-)

Suggested change
memcpy(iphc_hdr + inline_pos, ipv6_hdr->src.u8 + 14, 2);
memcpy(iphc_hdr + inline_pos, &ipv6_hdr->src.u8[14], 2);

inline_pos += 2;
addr_comp = true;
}
else {
/* 64 bits. The address is derived using 64 bits carried inline */
iphc_hdr[IPHC2_IDX] |= IPHC_SAC_SAM_64;
memcpy(iphc_hdr + inline_pos, ipv6_hdr->src.u64 + 1, 8);
memcpy(iphc_hdr + inline_pos, ipv6_hdr->src.u8 + 8, 8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
memcpy(iphc_hdr + inline_pos, ipv6_hdr->src.u8 + 8, 8);
memcpy(iphc_hdr + inline_pos, &ipv6_hdr->src.u8[8], 8);

inline_pos += 8;
addr_comp = true;
}
Expand All @@ -1129,22 +1128,17 @@ static size_t _iphc_ipv6_encode(gnrc_pktsnip_t *pkt,
iphc_hdr[IPHC2_IDX] |= SIXLOWPAN_IPHC2_M;

/* if multicast address is of format ffXX::XXXX:XXXX:XXXX */
if ((ipv6_hdr->dst.u16[1].u16 == 0) &&
(ipv6_hdr->dst.u32[1].u32 == 0) &&
(ipv6_hdr->dst.u16[4].u16 == 0)) {
if (!memcpy(&ipv6_hdr->dst.u8[2], zeros8, 8)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just from reading the code its not clear where zeros8 comes from, I'd rather compare byte-wise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you're saying that this

    if (!memcpy(ipv6_hdr->dest.u8[2], zeros8, 8)) {
        /* ... */
    }

is less readable than this

    int is_all_zero = 1;
    for (size_t i = 2; i < 10; i++) {
        if (ipv6_hdr->dst.u8[2] != 0) {
            is_zero = 0;
            break;
        }
    }
    if (!is_all_zero) {
        /* ... */
    }

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, but both your proposals are more obscure than

if ((ipv6_hdr->dest.u8[2] == 0) && (ipv6_hdr->dest.u8[3] == 0) &&
    (ipv6_hdr->dest.u8[4] == 0) && (ipv6_hdr->dest.u8[5] == 0) &&
    (ipv6_hdr->dest.u8[6] == 0) && (ipv6_hdr->dest.u8[7] == 0) &&
    (ipv6_hdr->dest.u8[8] == 0) && (ipv6_hdr->dest.u8[9] == 0)) {

(I think even you reversed the logic in your second proposal ;-))

/* if multicast address is of format ff02::XX */
if ((ipv6_hdr->dst.u8[1] == 0x02) &&
(ipv6_hdr->dst.u32[2].u32 == 0) &&
(ipv6_hdr->dst.u16[6].u16 == 0) &&
(ipv6_hdr->dst.u8[14] == 0)) {
!memcmp(&ipv6_hdr->dst.u8[8], zeros8, 7)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

/* 8 bits. The address is derived using 8 bits carried inline */
iphc_hdr[IPHC2_IDX] |= IPHC_M_DAC_DAM_M_8;
iphc_hdr[inline_pos++] = ipv6_hdr->dst.u8[15];
addr_comp = true;
}
/* if multicast address is of format ffXX::XX:XXXX */
else if ((ipv6_hdr->dst.u16[5].u16 == 0) &&
(ipv6_hdr->dst.u8[12] == 0)) {
else if (!memcmp(&ipv6_hdr->dst.u8[10], &zeros8, 3)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially here.

/* 32 bits. The address is derived using 32 bits carried inline */
iphc_hdr[IPHC2_IDX] |= IPHC_M_DAC_DAM_M_32;
iphc_hdr[inline_pos++] = ipv6_hdr->dst.u8[1];
Expand All @@ -1166,10 +1160,7 @@ static size_t _iphc_ipv6_encode(gnrc_pktsnip_t *pkt,
else {
gnrc_sixlowpan_ctx_t *ctx;
ipv6_addr_t unicast_prefix;
unicast_prefix.u16[0] = ipv6_hdr->dst.u16[2];
unicast_prefix.u16[1] = ipv6_hdr->dst.u16[3];
unicast_prefix.u16[2] = ipv6_hdr->dst.u16[4];
unicast_prefix.u16[3] = ipv6_hdr->dst.u16[5];
memcpy(unicast_prefix.u8, &ipv6_hdr->dst.u8[4], 8);

ctx = gnrc_sixlowpan_ctx_lookup_addr(&unicast_prefix);

Expand All @@ -1184,7 +1175,7 @@ static size_t _iphc_ipv6_encode(gnrc_pktsnip_t *pkt,
}
iphc_hdr[inline_pos++] = ipv6_hdr->dst.u8[1];
iphc_hdr[inline_pos++] = ipv6_hdr->dst.u8[2];
memcpy(iphc_hdr + inline_pos, ipv6_hdr->dst.u16 + 6, 4);
memcpy(iphc_hdr + inline_pos, ipv6_hdr->dst.u8 + 12, 4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
memcpy(iphc_hdr + inline_pos, ipv6_hdr->dst.u8 + 12, 4);
memcpy(iphc_hdr + inline_pos, &ipv6_hdr->dst.u8[12], 4);

inline_pos += 4;
addr_comp = true;
}
Expand All @@ -1208,17 +1199,16 @@ static size_t _iphc_ipv6_encode(gnrc_pktsnip_t *pkt,
return 0;
}

if ((ipv6_hdr->dst.u64[1].u64 == iid.uint64.u64) ||
if (!memcmp(&ipv6_hdr->dst.u8[8], &iid, sizeof(iid)) ||
_context_overlaps_iid(dst_ctx, &(ipv6_hdr->dst), &iid)) {
/* 0 bits. The address is derived using the link-layer address */
iphc_hdr[IPHC2_IDX] |= IPHC_M_DAC_DAM_U_L2;
addr_comp = true;
}
else if ((byteorder_ntohl(ipv6_hdr->dst.u32[2]) == 0x000000ff) &&
(byteorder_ntohs(ipv6_hdr->dst.u16[6]) == 0xfe00)) {
else if (!memcmp(&ipv6_hdr->dst.u8[8], addr_fffe, sizeof(addr_fffe))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

/* 16 bits. The address is derived using 16 bits carried inline */
iphc_hdr[IPHC2_IDX] |= IPHC_M_DAC_DAM_U_16;
memcpy(&(iphc_hdr[inline_pos]), &(ipv6_hdr->dst.u16[7]), 2);
memcpy(&(iphc_hdr[inline_pos]), &(ipv6_hdr->dst.u8[14]), 2);
inline_pos += 2;
addr_comp = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ gnrc_pktsnip_t *gnrc_sixlowpan_nd_opt_abr_build(uint32_t version, uint16_t ltime
abr_opt->vlow = byteorder_htons(version & 0xffff);
abr_opt->vhigh = byteorder_htons(version >> 16);
abr_opt->ltime = byteorder_htons(ltime);
abr_opt->braddr.u64[0] = braddr->u64[0];
abr_opt->braddr.u64[1] = braddr->u64[1];
memcpy(&abr_opt->braddr, braddr, sizeof(*braddr));
}

return pkt;
Expand Down
3 changes: 1 addition & 2 deletions sys/net/network_layer/ipv6/addr/ipv6_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const ipv6_addr_t ipv6_addr_all_routers_site_local = IPV6_ADDR_ALL_ROUTERS_SITE_

bool ipv6_addr_equal(const ipv6_addr_t *a, const ipv6_addr_t *b)
{
return (a->u64[0].u64 == b->u64[0].u64) &&
(a->u64[1].u64 == b->u64[1].u64);
return !memcmp(a, b, sizeof(*a));
}

uint8_t ipv6_addr_match_prefix(const ipv6_addr_t *a, const ipv6_addr_t *b)
Expand Down
Loading