Skip to content

Commit

Permalink
net: openthread: Set mesh_local flag in mesh-local OT addresses
Browse files Browse the repository at this point in the history
Mark automatically and statically configured mesh-local addresses
with mesh_local flag, so that they are not used as a source for
off-mesh destinations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
  • Loading branch information
rlubos committed Jan 28, 2019
1 parent 24955db commit d79034a
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions subsys/net/l2/openthread/openthread_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LOG_MODULE_DECLARE(net_l2_openthread, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
#include <net/openthread.h>

#include <openthread/ip6.h>
#include <openthread/thread.h>

#include "openthread_utils.h"

Expand All @@ -25,6 +26,15 @@ static bool is_anycast_locator(const otNetifAddress *address)
address->mAddress.mFields.m8[14] == ALOC16_MASK;
}

static bool is_mesh_local(struct openthread_context *context,
const u8_t *address)
{
const otMeshLocalPrefix *ml_prefix =
otThreadGetMeshLocalPrefix(context->instance);

return (memcmp(address, ml_prefix->m8, sizeof(ml_prefix)) == 0);
}

int pkt_list_add(struct openthread_context *context, struct net_pkt *pkt)
{
u16_t i_idx = context->pkt_list_in_idx;
Expand Down Expand Up @@ -77,6 +87,7 @@ void pkt_list_remove_last(struct openthread_context *context)
void add_ipv6_addr_to_zephyr(struct openthread_context *context)
{
const otNetifAddress *address;
struct net_if_addr *if_addr;

for (address = otIp6GetUnicastAddresses(context->instance);
address; address = address->mNext) {
Expand All @@ -94,9 +105,18 @@ void add_ipv6_addr_to_zephyr(struct openthread_context *context)
buf, sizeof(buf))));
}

net_if_ipv6_addr_add(context->iface,
(struct in6_addr *)(&address->mAddress),
NET_ADDR_ANY, 0);
if_addr = net_if_ipv6_addr_add(
context->iface,
(struct in6_addr *)(&address->mAddress),
NET_ADDR_AUTOCONF, 0);

if (if_addr == NULL) {
NET_ERR("Cannot add OpenThread unicast address");
continue;
}

if_addr->is_mesh_local = is_mesh_local(
context, address->mAddress.mFields.m8);
}
}

Expand Down Expand Up @@ -124,6 +144,9 @@ void add_ipv6_addr_to_ot(struct openthread_context *context)
}
}

ipv6->unicast[i].is_mesh_local = is_mesh_local(
context, ipv6->unicast[i].address.in6_addr.s6_addr);

addr.mValid = true;
addr.mPreferred = true;
addr.mPrefixLength = 64;
Expand Down

0 comments on commit d79034a

Please sign in to comment.