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

net: ip: Introduce mesh_local flag #12731

Merged
merged 2 commits into from
Jan 29, 2019
Merged
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
5 changes: 4 additions & 1 deletion include/net/net_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ struct net_if_addr {
/** Is this IP address used or not */
u8_t is_used : 1;

u8_t _unused : 6;
/** Is this IP address usage limited to the subnet (mesh) or not */
u8_t is_mesh_local : 1;

u8_t _unused : 5;
};

/**
Expand Down
7 changes: 7 additions & 0 deletions subsys/net/ip/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,13 @@ static struct in6_addr *net_if_ipv6_get_best_match(struct net_if *iface,

len = get_diff_ipv6(dst, &ipv6->unicast[i].address.in6_addr);
if (len >= *best_so_far) {
/* Mesh local address can only be selected for the same
* subnet.
*/
if (ipv6->unicast[i].is_mesh_local && len < 64) {
continue;
}

*best_so_far = len;
src = &ipv6->unicast[i].address.in6_addr;
}
Expand Down
5 changes: 3 additions & 2 deletions subsys/net/ip/net_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,12 @@ static void iface_cb(struct net_if *iface, void *user_data)
continue;
}

PR("\t%s %s %s%s\n",
PR("\t%s %s %s%s%s\n",
net_sprint_ipv6_addr(&unicast->address.in6_addr),
addrtype2str(unicast->addr_type),
addrstate2str(unicast->addr_state),
unicast->is_infinite ? " infinite" : "");
unicast->is_infinite ? " infinite" : "",
unicast->is_mesh_local ? " meshlocal" : "");
count++;
}

Expand Down
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