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_netif: add fetch-address and fetch-netif-flag functionalities. #6069
Conversation
@miri64 Ping~ |
497adf2
to
dabe766
Compare
Updated and added unitest codes. |
Reflected module name "gnrc_mac" into internal functions. |
Ping~ ;-) |
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.
Redoing the comments I already made in #6074
* | ||
* @return length of destination address | ||
*/ | ||
int gnrc_mac_get_dstaddr(gnrc_pktsnip_t* pkt, uint8_t* pointer_to_addr[]); |
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 don't know exactly what it was, but there was a problem with array parameters. Please use uint8_t **
pointer instead
* | ||
* @return length of destination address | ||
*/ | ||
int gnrc_mac_get_dstaddr(gnrc_pktsnip_t* pkt, uint8_t* pointer_to_addr[]); |
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.
It seems a bit arbitrary to put a gnrc_netif_hdr
specific function here. I would rather put it in that header.
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 mean to put this function into sys/include/net/gnrc/netif/hdr
?
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.
Yes.
* | ||
* @return pointer to data, NULL is not found | ||
*/ | ||
void* gnrc_mac_pktbuf_find(gnrc_pktsnip_t* pkt, gnrc_nettype_t type); |
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.
Anything speaking against using gnrc_pktsnip_search_type()
here?
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.
No, just lack of awareness. ;-) will remove this function.
* | ||
* @return true if the packet is for broadcast, otherwise false | ||
*/ | ||
static inline bool gnrc_mac_chk_pkt_bcast(gnrc_pktsnip_t* pkt) |
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.
It seems a bit arbitrary to put a gnrc_netif_hdr
specific function here. I would rather put it in that header.
assert(addr2); | ||
assert(add_len); | ||
|
||
return (memcmp(addr1, addr2, add_len) == 0); |
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.
Do you really need this function if it just wraps around memcpy()
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 guess not really, just want to feel straightforward when using. So, I remove this function. ;-)
@miri64 Updated. |
*/ | ||
|
||
#ifndef GNRC_MAC_INTERNAL_H_ | ||
#define GNRC_MAC_INTERNAL_H_ |
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.
I think I should~
* | ||
* @return true if the packet is for broadcast, otherwise false | ||
*/ | ||
static inline bool gnrc_netif_chk_pkt_bcast(gnrc_pktsnip_t* pkt) |
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.
How about this ? ;-) @miri64
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.
gnrc_netif_hdr_chk_...
* | ||
* @return length of destination address | ||
*/ | ||
int gnrc_netif_get_dstaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr); |
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.
How about this ? ;-) @miri64
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.
gnrc_netif_hdr_get_...
*/ | ||
static inline bool gnrc_netif_chk_pkt_bcast(gnrc_pktsnip_t* pkt) | ||
{ | ||
gnrc_netif_hdr_t* netif_hdr = gnrc_mac_pktbuf_find(pkt, GNRC_NETTYPE_NETIF); |
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.
my fault, still need some polish here.. will update soon.
95b3fb9
to
c3e7bc1
Compare
@miri64 Updated again. |
* | ||
* @return true if the packet is for broadcast, otherwise false | ||
*/ | ||
bool gnrc_netif_hdr_chk_pkt_bcast(gnrc_pktsnip_t* pkt); |
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.
@miri64 Do you think I should restrict the input to gnrc_netif_hdr_t *
, but not for gnrc_pktsnip_t*
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.
Yeah, I guess that would be the better idea. I also would prefer to still distinguish multicast and broadcast here.
* | ||
* @return length of destination address | ||
*/ | ||
int gnrc_netif_hdr_get_dstaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr); |
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.
Maybe also add an equivalent function for source address?
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.
@miri64 Yes, good idea, I will do it.;-)
@miri64 Updated again~ |
* | ||
* @return true if the packet is for multicast, otherwise false | ||
*/ | ||
static inline bool gnrc_netif_hdr_chk_pkt_mcast(gnrc_netif_hdr_t *hdr) |
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.
@miri64 Added check-multicast function also.
* | ||
* @return length of destination address | ||
*/ | ||
int gnrc_netif_hdr_get_srcaddr(gnrc_netif_hdr_t *hdr, uint8_t** pointer_to_addr); |
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.
@miri64 Added get-source_address function.
* | ||
* @return length of destination address | ||
*/ | ||
int gnrc_netif_hdr_get_dstaddr(gnrc_netif_hdr_t *hdr, uint8_t** pointer_to_addr); |
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.
Without the search functionality they are pretty much equivalent to http://doc.riot-os.org/group__net__gnrc__netif__hdr.html#gaae99832a0efea4a5a2501a8fc9469f21...
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.
@miri64 I understand, indeed, without the search functionality, it is just a very thin wrap... We just removed a more thick wrapper (the search func.) just now. So, do you think we should come back to the original state, where the input is gnrc_pktsnip_t*
and there will be the search functionality (I think this functionality is quite frequently used, at least in MAC)?
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.
Maybe still put that function (get_dstaddress(gnrc_pktsnip_t* pkt)
) to gnrc_mac
module?
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.
For the address stuff yes. For the flag stuff (bcast, mcast) I think it's best if they just return the flags. Otherwise you need to search for the netif header twice. The flags can then be checked externally (if necessary with a wrapper)
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.
For the address stuff yes.
So, for this, I return to the original state to gnrc_mac_get_dstaddr(gnrc_pktsnip_t* pkt)
(with search functionality) and keep this function in gnrc_mac
internal?
For the flag stuff (bcast, mcast) I think it's best if they just return the flags. Otherwise you need to search for the netif header twice. The flags can then be checked externally (if necessary with a wrapper)
Fot this, you mean a solution like: uint8_t (flag) gnrc_netif_hdr_get_flags(gnrc_netif_hdr_t *hdr)
, right? ;-)
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, for this, I return to the original state to gnrc_mac_get_dstaddr(gnrc_pktsnip_t* pkt) (with search functionality) […]
Yes (but not the name)
and keep this function in gnrc_mac internal?
No. Keep it here.
Fot this, you mean a solution like: uint8_t (flag) gnrc_netif_hdr_get_flags(gnrc_netif_hdr_t *hdr) , right? ;-)
Yes.
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.
@miri64 Got it! will adjust tomorrow~ And, thanks a lot for the huge help tonight ! :-)
* @param[out] pointer_to_addr pointer to address will be stored here | ||
* | ||
* @return length of destination address | ||
* @return -ENOENT, if no netif header is presented in @p pkt; or if no |
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.
Semicolon doesn't make any sense here language-wise.
* @param[out] pointer_to_addr pointer to address will be stored here | ||
* | ||
* @return length of source address | ||
* @return -ENOENT, if no netif header is presented in @p pkt; or if no |
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
|
||
assert(pkt != NULL); | ||
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF); | ||
if(pkt) { |
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.
Style (space between if
and (
).
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF); | ||
if(pkt) { | ||
netif_hdr = pkt->data; | ||
if(netif_hdr) { |
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
|
||
assert(pkt != NULL); | ||
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF); | ||
if(pkt) { |
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
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF); | ||
if(pkt) { | ||
netif_hdr = pkt->data; | ||
if(netif_hdr) { |
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
if(pkt) { | ||
netif_hdr = pkt->data; | ||
if(netif_hdr) { | ||
if((res = netif_hdr->dst_l2addr_len) <= 0) { |
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
|
||
assert(pkt != NULL); | ||
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF); | ||
if(pkt) { |
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
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF); | ||
if(pkt) { | ||
netif_hdr = pkt->data; | ||
if(netif_hdr) { |
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
if(pkt) { | ||
netif_hdr = pkt->data; | ||
if(netif_hdr) { | ||
if((res = netif_hdr.src_l2addr_len) <= 0) { |
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
Apart from minor style and grammar things we can go, as soon as they are fixed. |
96ed42e
to
af4f03f
Compare
@miri64 Adopted all the style comments on space, and turned semicolon to comma. |
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.
One last grammar thing
* @param[out] pointer_to_addr pointer to address will be stored here | ||
* | ||
* @return length of destination address | ||
* @return -ENOENT, if no netif header is presented in @p pkt, or if no |
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.
No comma, no semicolon. "or" suffices in this case ;-)
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.
Ha~ OK, just to be sure, like: if no netif header is presented in @p pkt or if no ...
?
* @param[out] pointer_to_addr pointer to address will be stored here | ||
* | ||
* @return length of source address | ||
* @return -ENOENT, if no netif header is presented in @p pkt, or if no |
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
af4f03f
to
d0a7d1a
Compare
Remove comma~ |
Please squash |
d0a7d1a
to
670f70c
Compare
Squashed. |
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.
Murdock found some errors. Please update and squash immediately.
@@ -38,4 +38,63 @@ gnrc_pktsnip_t *gnrc_netif_hdr_build(uint8_t *src, uint8_t src_len, uint8_t *dst | |||
return pkt; | |||
} | |||
|
|||
uint8_t gnrc_netif_hdr_get_flag(gnrc_pktsnip_t* pkt) | |||
{ | |||
int res; |
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.
Variable is not used. Please remove
if (pkt) { | ||
netif_hdr = pkt->data; | ||
if (netif_hdr) { | ||
if ((res = netif_hdr.src_l2addr_len) <= 0) { |
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.
Use structure dereference instead (->
) of .
670f70c
to
d749962
Compare
Updated and squahsed again. (Sorry for the error, should have compiled locally to check..) |
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.
ACK and go.
This PR introduces functionalities that enable fetching source, destination addresses, and
netif header
flags fromnetif header
of a gnrc packet,