-
Notifications
You must be signed in to change notification settings - Fork 2k
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
sys: net: add gnrc netdev2 support #3683
Conversation
#define ENABLE_DEBUG (0) | ||
#include "debug.h" | ||
|
||
static gnrc_pktsnip_t *_recv(gnrc_netdev2_t *gnrc_netdev2) |
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.
@authmillenon Could you help me rewriting this so the packet doesn't get copied twice?
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.
If I manage to spot the problem, 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.
Well, to get it work, I create a big-enough pktsnip, and then build another one, copying the data I need.
I tried to just mark out the ethernet header, snip_remove that, and than use the initial big pktsnip, add the netif hdr, go... but It didn't manage to get it to work without memory leaks.
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 would there be memory leaks?
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.
Right now there are none. But right now data is copied twice (once into "whole_pkt", and then partly into pkt).
Initially I wanted to just mark the headers in "whole_pkt", but I don't know why edit how.
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 in general this should work (without error checking to make the code look a little simpler):
if (bytes_expected) {
ethernet_hdr_t *hdr;
gnrc_pktsnip_t *netif_hdr, *eth_hdr;
gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, NULL, bytes_expected, GNRC_NETTYPE_UNDEF);
int nread = dev->driver->recv(dev, pkt->data, bytes_expected);
if (nread < bytes_expected) {
gnrc_pktbuf_realloc_data(pkt, nread);
}
eth_hdr = gnrc_pktbuf_mark(pkt, sizeof(ethernet_hdr_t), GNRC_NETTYPE_UNDEF);
hdr = eth_hdr->data;
gnrc_netif_hdr_init(netif_hdr->data, ETHERNET_ADDR_LEN, ETHERNET_ADDR_LEN);
gnrc_netif_hdr_set_src_addr(netif_hdr->data, hdr->src, ETHERNET_ADDR_LEN);
gnrc_netif_hdr_set_dst_addr(netif_hdr->data, hdr->dst, ETHERNET_ADDR_LEN);
((gnrc_netif_hdr_t *)netif_hdr->data)->if_pid = thread_getpid();
gnrc_pktbuf_remove_snip(pkt, hdr);
LL_APPEND(pkt, hdr);
return pkt;
}
return 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.
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.
@authmillenon Hm, I don't quite get it.
I think you're mixing up hdr and eth_hdr in the last lines, right?
Where do you mark the payload according to ethertype?
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 you're mixing up hdr and eth_hdr in the last lines, right?
Right, that tends to happen when you head-compile ^^
Where do you mark the payload according to ethertype?
Forgot it. Just throw a
pkt->type = gnrc_nettype_from_ethertype(byteorder_ntohs(hdr->type));
in there after you set hdr
(the real one this time), but before you remove eth_hdr
in the gnrc_pktbuf_remove_snip(pkt, eth_hdr);
line.
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.
yup, that did it. thanks.
Okay, can you just quickly explain to me: is this a |
Well, the PR contains both. gnrc_netdev2 is a "generic wrapper", gnrc_netdev2_eth contains ethernet specific code. |
} | ||
|
||
safe_out: | ||
gnrc_pktbuf_release(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.
This potentially releases NULL pointers which does not fulfill the function's precondition.
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.
fixed
db6880b
to
2bc998c
Compare
|
2bc998c
to
b22f769
Compare
|
Rebase please. |
b22f769
to
9e72aa4
Compare
|
(triggered CI) |
@emmanuelsearch Could you try this on OS X? |
Sure. What test should I run? |
Anything using the network. Do you know how to ping e.g., "gnrc_networking" from your OS X host? edit This PR replaces the tap network driver native uses. |
/** | ||
* @brief netdev2 handle this adapter is working with | ||
*/ | ||
netdev2_t *dev; |
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.
const
?
@thomaseichinger Hm, I've no clue about OS X networking. If you've got no time to test this, could you shortly explain how we can test native networking? @emmanuelsearch I can confirm that tapsetup is broken on OS X. @OlegHahm Would you mind testing on Linux? |
Of course I can test. The question is what and how? |
Well, this PR replaces dev_eth_tap, so testing of native networking is needed. It should behave as before. |
typedef struct dev_eth_tap { | ||
dev_eth_t ethdev; /**< dev_eth internal member */ | ||
typedef struct netdev2_tap { | ||
netdev2_t netdev; /**< netdev2 internal member */ | ||
char tap_name[IFNAMSIZ]; /**< host dev file name */ |
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.
IFNAMSIZ
is undeclared, according to gcc.
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.
Even with the latest commit (f5f0392)?
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 have to admit I have no clue why this broke.
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.
Ah, yes, the remote wasn't up to date. Sorry for the noise.
see kaspar030#12 |
and with RPL initialized I get after some time:
on the non-root node. To reproduce:
|
@OlegHahm Hm, netopt.h explicitly states that the result is "uint16_t", but gnrc_ndp wants to read into size_t. I feel weird removing the assert... Could you remove it just for testing? @authmillenon, do you agree we should use uint16_t in gnrc_ndp? |
Fix for assertion PR'ed in #3774. |
I get a strange error if I just remove the assert:
If I put the case block in curly bracket it compiles again... |
But without the assert things seem to work as they should. |
Go ahead! |
e87907b
to
8deb11b
Compare
8deb11b
to
4e5a675
Compare
|
Double green! |
Nice, but no ACK ... |
Sorry, couldn't find a way to break it. ACK |
&go! thanks for testing! |
sys: net: add gnrc netdev2 support
This adds netdev2 support to gnrc and adapts dev_eth_tap to the new interface.
The new device driver structure has several advantages:
While this is marked WIP as I'd like to test this more, it is working fine on native.Depends on #3210.(netdev2 merged)