-
Notifications
You must be signed in to change notification settings - Fork 2.1k
gnrc_ipv6_nib: provide internal implementation for off-link entries #7212
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
gnrc_ipv6_nib: provide internal implementation for off-link entries #7212
Conversation
sys/include/net/gnrc/ipv6/nib/conf.h
Outdated
/** | ||
* @brief Number of off-link entries in NIB | ||
* | ||
* @note **This number has direct influence on the maximum number of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of enclosing this with ** ... **
you could rather use @attention
instead of @note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to keep the style of the original ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand - and docu styling might be separate more general issue anyway 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix in a different PR ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first round ..
sys/include/net/gnrc/ipv6/nib/conf.h
Outdated
/** | ||
* @brief Number of off-link entries in NIB | ||
* | ||
* @attention This number has direct influence on the maximum number of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to clarify: how exactly does GNRC_IPV6_NIB_OFFL_NUMOF
influences the max. number? I would assume it is the max. number, or is there another number that is added to that?
DEBUG("nib: Allocating on-link node entry (addr = %s, iface = %u)\n", | ||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), iface); | ||
for (unsigned i = 0; i < GNRC_IPV6_NIB_NUMOF; i++) { | ||
_nib_onl_entry_t *tmp = &_nodes[i]; | ||
|
||
if ((_nib_onl_get_if(tmp) == iface) && | ||
(ipv6_addr_equal(addr, &tmp->ipv6))) { | ||
((addr == NULL) || (ipv6_addr_equal(addr, &tmp->ipv6)))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need this check for addr == NULL
here? There's a @pre
in the doxygen of this function, that addr != NULL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you probably need to remove the doxygen @pre
then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @pre
is wrong. For prefix list entries the next-hop address may be NULL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found an error here, while debugging NDP-RD. Will fix.
@@ -62,14 +64,13 @@ _nib_onl_entry_t *_nib_onl_alloc(const ipv6_addr_t *addr, unsigned iface) | |||
{ | |||
_nib_onl_entry_t *node = NULL; | |||
|
|||
assert(addr != NULL); | |||
DEBUG("nib: Allocating on-link node entry (addr = %s, iface = %u)\n", | |||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), iface); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line will crash if addr == NULL
@@ -341,6 +343,96 @@ _nib_dr_entry_t *_nib_drl_get_dr(void) | |||
return _prime_def_router; | |||
} | |||
|
|||
_nib_offl_entry_t *_nib_offl_alloc(const ipv6_addr_t *next_hop, unsigned iface, | |||
const ipv6_addr_t *pfx, unsigned pfx_len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix your browser font :P
_nib_offl_entry_t *dst = NULL; | ||
|
||
assert((pfx != NULL) && (!ipv6_addr_is_unspecified(pfx)) && | ||
(pfx_len != 0) && (pfx_len <= 128)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just taste, but I like pfx_len > 0
more, because it's in harmony with px_len <= 128
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dito, don't know what came over me.
_nib_offl_entry_t *_nib_dst_alloc(const ipv6_addr_t *next_hop, unsigned iface, | ||
const ipv6_addr_t *pfx, unsigned pfx_len); | ||
_nib_offl_entry_t *_nib_offl_alloc(const ipv6_addr_t *next_hop, unsigned iface, | ||
const ipv6_addr_t *pfx, unsigned pfx_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is fixed here, I know :P
* @return NULL, if no space is left. | ||
*/ | ||
static inline _nib_offl_entry_t *_nib_dc_add(const ipv6_addr_t *next_hop, | ||
unsigned iface, | ||
const ipv6_addr_t *dst) | ||
{ | ||
return _nib_dst_add(next_hop, iface, dst, IPV6_ADDR_BIT_LEN, _DC); | ||
assert(next_hop != NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also add assert(dst != NULL);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's checked in _nib_offl_alloc()
(which is called by _nib_offl_add()
)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That may be true for now, but what if this code changes with time and possibly by another developer?. IMO these asserts
also have a documentational character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright...
* interfaces and then tries to add another. | ||
* Expected result: should return NULL | ||
*/ | ||
static void test_nib_offl_alloc__no_space_left_diff_next_hop_iface(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont' think you need the above two test cases when you introduce this test case that combines both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, checking for behavior different addresses, different interfaces and different addresses and different interfaces are disjunct test-cases. One simple mix-up of &&
and ||
in the implementation would let fail at least one of them.
* tries to add another. | ||
* Expected result: should return NULL | ||
*/ | ||
static void test_nib_offl_alloc__no_space_left_diff_next_hop_iface_pfx(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the same, the above two test cases are not really necessary, are they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above.
* equal to the last. | ||
* Expected result: should return not NULL (the last) | ||
*/ | ||
static void test_nib_offl_alloc__success_duplicate(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many test cases that are very similar .. can you collapse them? It is hard to maintain so many test cases in case of changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are subtle differences that are not easily parameterized out. Ideally, this API shouldn't change much.
Comments addressed. |
Done: the problem was, if a Prefix List entry was allocated first and a neighbor cache entry to the same interface later, the allocation would create a new entry. The last two commits add a fix and a corresponding test for this. |
Oops, now the address isn't set ^^ will fix |
(fixed and |
Ping @cgundogan? You promised to review last week :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks better now .. the goal draws nearer (:
(_nib_onl_get_if(tmp_node) == iface) && | ||
((next_hop == NULL) || ipv6_addr_is_unspecified(&tmp_node->ipv6) || | ||
(ipv6_addr_equal(next_hop, &tmp_node->ipv6))) && | ||
(ipv6_addr_match_prefix(&tmp->pfx, pfx) >= pfx_len)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a pretty ugly chain of conditions. Care to outsource into an inlined function or provide code documentation on what happens here?
@@ -232,8 +237,6 @@ static inline void _nib_onl_set_if(_nib_onl_entry_t *node, unsigned iface) | |||
/** | |||
* @brief Creates or gets an existing on-link entry by address | |||
* | |||
* @pre `(addr != NULL)`. | |||
* | |||
* @param[in] addr An IPv6 address. May not be NULL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May not be NULL.
* @return NULL, if no space is left. | ||
*/ | ||
static inline _nib_offl_entry_t *_nib_dc_add(const ipv6_addr_t *next_hop, | ||
unsigned iface, | ||
const ipv6_addr_t *dst) | ||
{ | ||
return _nib_dst_add(next_hop, iface, dst, IPV6_ADDR_BIT_LEN, _DC); | ||
assert(next_hop != NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That may be true for now, but what if this code changes with time and possibly by another developer?. IMO these asserts
also have a documentational character.
Addressed comments |
@miri64 great, thanks for your patience! Please squash the commits and then let's murdock have some fun! |
34ab23a
to
124d6c8
Compare
Squashed |
Murdock spits out some errors here. |
124d6c8
to
c1f9b15
Compare
Problem was the amended inline function requested in #7212 (comment). Fixed and squashed immediately. |
Now murdock is happy (: GO |
Implementation off the off-link component of the NIB back-end.
I needed to move some stuff around, to keep consistency, but other than that the change should be straight forward.
This PR is part of the network layer remodelling effort:
