net: ip: Introduce mesh_local address flag

This commit introduces a concept of mesh-local IPv6 addresses. Such
addresses should only be used for mesh-local communication, therefore
should not be used to communicate with different subnets (i. e.
destinations outside the mesh).

As `addr_type` field already holds different kind of information
(whether address was created automatically/manually) it was not used in
this case.

Instead a mesh_local flag was added, so that we do not lose information
on how address was created. Address with such flag set will only be
selected as a source address automatically if the destination address
is within the same subnet it belongs to.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2019-01-24 15:56:10 +01:00 committed by Anas Nashif
parent 2433956500
commit 83b8abaf8a
3 changed files with 14 additions and 3 deletions

View file

@ -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;
};
/**

View file

@ -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;
}

View file

@ -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++;
}