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

gnrc_netif: add fetch-address and fetch-netif-flag functionalities. #6069

Merged
merged 1 commit into from Dec 2, 2016

Conversation

zhuoshuguo
Copy link
Contributor

@zhuoshuguo zhuoshuguo commented Nov 7, 2016

This PR introduces functionalities that enable fetching source, destination addresses, and netif header flags from netif header of a gnrc packet,

@miri64 miri64 added GNRC Area: network Area: Networking Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Nov 10, 2016
@miri64 miri64 added this to the Release 2017.01 milestone Nov 10, 2016
@miri64 miri64 self-assigned this Nov 10, 2016
@zhuoshuguo
Copy link
Contributor Author

@miri64 Ping~

@zhuoshuguo zhuoshuguo force-pushed the gnrc_mac_internal_helper branch 5 times, most recently from 497adf2 to dabe766 Compare November 19, 2016 23:42
@zhuoshuguo
Copy link
Contributor Author

Updated and added unitest codes.

@zhuoshuguo
Copy link
Contributor Author

Reflected module name "gnrc_mac" into internal functions.

@zhuoshuguo
Copy link
Contributor Author

Ping~ ;-)

Copy link
Member

@miri64 miri64 left a 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[]);
Copy link
Member

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[]);
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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);
Copy link
Member

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()

Copy link
Contributor Author

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. ;-)

@zhuoshuguo
Copy link
Contributor Author

@miri64 Updated.

*/

#ifndef GNRC_MAC_INTERNAL_H_
#define GNRC_MAC_INTERNAL_H_
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miri64 Should I also delete this internal.h (and internal.c and gnrc_mac makefile etc.) which contain nothing now in this PR, and introduce it in PR6074 ?

Copy link
Contributor Author

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this ? ;-) @miri64

Copy link
Member

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this ? ;-) @miri64

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gnrc_netif_hdr_get_...

@zhuoshuguo zhuoshuguo changed the title gnrc_mac: add mac internal helper functions. gnrc_netif: add fetch-destination-address and check-pkt-broadcast functionalities. Nov 29, 2016
*/
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);
Copy link
Contributor Author

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.

@zhuoshuguo
Copy link
Contributor Author

@miri64 Updated again.

*
* @return true if the packet is for broadcast, otherwise false
*/
bool gnrc_netif_hdr_chk_pkt_bcast(gnrc_pktsnip_t* pkt);
Copy link
Contributor Author

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*

Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor Author

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.;-)

@zhuoshuguo
Copy link
Contributor Author

@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)
Copy link
Contributor Author

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);
Copy link
Contributor Author

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);
Copy link
Member

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...

Copy link
Contributor Author

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)?

Copy link
Contributor Author

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?

Copy link
Member

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)

Copy link
Contributor Author

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? ;-)

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito

@miri64
Copy link
Member

miri64 commented Dec 1, 2016

Apart from minor style and grammar things we can go, as soon as they are fixed.

@zhuoshuguo
Copy link
Contributor Author

zhuoshuguo commented Dec 1, 2016

@miri64 Adopted all the style comments on space, and turned semicolon to comma.

@zhuoshuguo zhuoshuguo changed the title gnrc_netif: add fetch-destination-address and check-pkt-broadcast functionalities. gnrc_netif: add fetch-address and fetch-netif-flag functionalities. Dec 1, 2016
Copy link
Member

@miri64 miri64 left a 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
Copy link
Member

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 ;-)

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito

@zhuoshuguo
Copy link
Contributor Author

Remove comma~

@miri64
Copy link
Member

miri64 commented Dec 1, 2016

Please squash

@miri64 miri64 added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Dec 1, 2016
@zhuoshuguo
Copy link
Contributor Author

Squashed.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Dec 2, 2016
Copy link
Member

@miri64 miri64 left a 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;
Copy link
Member

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) {
Copy link
Member

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 .

@zhuoshuguo
Copy link
Contributor Author

Updated and squahsed again. (Sorry for the error, should have compiled locally to check..)

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK and go.

@miri64 miri64 merged commit be70241 into RIOT-OS:master Dec 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants