Skip to content

Commit 934687b

Browse files
kjbraceydeepakvenugopal
authored andcommitted
Tighten core "for us" check for unicast addresses
Basic "is this packet for us" check was special-cased for link-local addresses, but had no other scope handling. Tighten this up to apply the scope zones already configured in the interfaces and used for packet forwarding. We now only accept a packet on interface B for an address configured on interface A if A and B are in the same scope zone for that address. Main visible impact will be that Thread border routers will no longer accept mesh-local addresses on the Ethernet interface. Change-Id: Ib79526f1ada36fa409378b4824315221cc543321
1 parent 58a60e7 commit 934687b

File tree

8 files changed

+21
-16
lines changed

8 files changed

+21
-16
lines changed

source/Core/address.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,14 +1354,17 @@ int8_t addr_interface_address_compare(protocol_interface_info_entry_t *cur, cons
13541354
return 0;
13551355
}
13561356

1357-
/* If link-local, that's it */
1358-
if (addr_is_ipv6_link_local(addr)) {
1359-
return -1;
1357+
/* Then check other interfaces, enforcing scope zones */
1358+
uint_fast8_t scope = addr_ipv6_scope(addr, cur);
1359+
ns_list_foreach(protocol_interface_info_entry_t, other, &protocol_interface_info_list) {
1360+
if (other != cur &&
1361+
other->zone_index[scope] == cur->zone_index[scope] &&
1362+
addr_is_assigned_to_interface(other, addr)) {
1363+
return 0;
1364+
}
13601365
}
13611366

1362-
/* Now check other interfaces */
1363-
/* TODO: should only do this if both current and other interface have forwarding enabled */
1364-
return protcol_interface_address_compare(cur, addr);
1367+
return -1;
13651368
}
13661369

13671370
int8_t addr_interface_select_source(protocol_interface_info_entry_t *cur, uint8_t *src_ptr, const uint8_t *dest, uint32_t addr_preferences)

source/Core/ns_socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ int16_t socket_buffer_sendmsg(int8_t sid, buffer_t *buf, const struct ns_msghdr
13011301
* address is valid in one of the available interfaces
13021302
* */
13031303
if (buf->src_sa.addr_type == ADDR_IPV6 &&
1304-
protcol_interface_address_compare(NULL, buf->src_sa.address) != 0) {
1304+
protocol_interface_address_compare(buf->src_sa.address) != 0) {
13051305
tr_warn("Specified source address %s is not valid",trace_ipv6(buf->src_sa.address));
13061306
ret_val = -3;
13071307
goto fail;

source/NWK_INTERFACE/Include/protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,5 +507,5 @@ extern void protocol_core_dhcpv6_allocated_address_remove(protocol_interface_inf
507507

508508
extern void nwk_bootsrap_state_update(arm_nwk_interface_status_type_e posted_event, protocol_interface_info_entry_t *cur);
509509
void bootsrap_next_state_kick(icmp_state_t new_state, protocol_interface_info_entry_t *cur);
510-
int8_t protcol_interface_address_compare(protocol_interface_info_entry_t *cur, const uint8_t *addr);
510+
int8_t protocol_interface_address_compare(const uint8_t *addr);
511511
#endif /* _NS_PROTOCOL_H */

source/NWK_INTERFACE/protocol_core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,10 +1085,12 @@ void protocol_core_dhcpv6_allocated_address_remove(protocol_interface_info_entry
10851085
}
10861086
}
10871087

1088-
int8_t protcol_interface_address_compare(protocol_interface_info_entry_t *cur, const uint8_t *addr)
1088+
/* XXX note that this does not perform any scope checks, so will for example match
1089+
* link local addresses on any interface - you may want addr_interface_address_compare */
1090+
int8_t protocol_interface_address_compare(const uint8_t *addr)
10891091
{
1090-
ns_list_foreach(protocol_interface_info_entry_t, other, &protocol_interface_info_list) {
1091-
if (other != cur && addr_is_assigned_to_interface(other, addr)) {
1092+
ns_list_foreach(protocol_interface_info_entry_t, cur, &protocol_interface_info_list) {
1093+
if (addr_is_assigned_to_interface(cur, addr)) {
10921094
return 0;
10931095
}
10941096
}

source/RPL/rpl_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ static buffer_t *rpl_control_dio_handler(protocol_interface_info_entry_t *cur, r
855855
}
856856

857857
/* Even if we're not currently rooting - what if it's our address? Ignore stale info on network */
858-
if (protcol_interface_address_compare(NULL, dodagid) == 0) {
858+
if (addr_interface_address_compare(cur, dodagid) == 0) {
859859
tr_info("DIO our DODAGID %s", trace_ipv6(dodagid));
860860
/* Should we transmit poison? */
861861
goto invalid_parent;

source/RPL/rpl_downward.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ static bool rpl_downward_process_targets_for_transit(rpl_dodag_t *dodag, bool st
10591059
/* In Non-Storing mode, add the transit to the target, and we'll re-evaluate system routes later */
10601060
ipv6_route_table_remove_info(-1, ROUTE_RPL_DAO_SR, target);
10611061
if (transit_opt) {
1062-
if (protcol_interface_address_compare(NULL, parent) == 0) {
1062+
if (protocol_interface_address_compare(parent) == 0) {
10631063
/* If we're transit, it's on-link */
10641064
ipv6_route_add_with_info(prefix, prefix_len, interface_id, NULL, ROUTE_RPL_DAO_SR, target, 0, target->lifetime, 0);
10651065
} else {
@@ -1122,7 +1122,7 @@ static void rpl_downward_link_transits_to_targets(rpl_instance_t *instance)
11221122
}
11231123
ns_list_foreach(rpl_dao_target_t, target, &instance->dao_targets) {
11241124
ns_list_foreach(rpl_dao_root_transit_t, transit, &target->info.root.transits) {
1125-
if (protcol_interface_address_compare(NULL, transit->transit) == 0) {
1125+
if (protocol_interface_address_compare(transit->transit) == 0) {
11261126
/* It points to us (the DODAG root) - mark this with NULL */
11271127
transit->parent = NULL;
11281128
target->connected = true;

source/libNET/src/socket_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ int8_t socket_bind(int8_t socket, const ns_address_t *address)
656656
return -4;
657657
}
658658

659-
if (protcol_interface_address_compare(NULL, address->address) != 0) {
659+
if (protocol_interface_address_compare(address->address) != 0) {
660660
return -3;
661661
}
662662

test/nanostack/unittest/stub/protocol_core_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void protocol_core_dhcpv6_allocated_address_remove(protocol_interface_info_entry
234234
{
235235
}
236236

237-
int8_t protcol_interface_address_compare(protocol_interface_info_entry_t *cur, const uint8_t *addr)
237+
int8_t protocol_interface_address_compare(const uint8_t *addr)
238238
{
239239
return protocol_core_stub.int8_value;
240240
}

0 commit comments

Comments
 (0)