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

sys: net: add gnrc netdev2 support #3683

Merged
merged 3 commits into from
Sep 4, 2015

Conversation

kaspar030
Copy link
Contributor

This adds netdev2 support to gnrc and adapts dev_eth_tap to the new interface.

The new device driver structure has several advantages:

  • drivers written against netdev2 are not dependend on gnrc
  • a lot of link-layer code can be shared

While this is marked WIP as I'd like to test this more, it is working fine on native.

Depends on #3210. (netdev2 merged)

@kaspar030 kaspar030 added Area: network Area: Networking State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet NSTF labels Aug 21, 2015
@kaspar030 kaspar030 added the State: waiting for other PR State: The PR requires another PR to be merged first label Aug 21, 2015
#define ENABLE_DEBUG (0)
#include "debug.h"

static gnrc_pktsnip_t *_recv(gnrc_netdev2_t *gnrc_netdev2)
Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@miri64
Copy link
Member

miri64 commented Aug 21, 2015

Okay, can you just quickly explain to me: is this a gnrc_netdev2_eth wrapper (just for ethernet devices) or a gnrc_netdev2 wrapper (for all netdev2 devices)?

@kaspar030
Copy link
Contributor Author

Well, the PR contains both. gnrc_netdev2 is a "generic wrapper", gnrc_netdev2_eth contains ethernet specific code.

}

safe_out:
gnrc_pktbuf_release(pkt);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@kaspar030 kaspar030 force-pushed the add_gnrc_netdev2_support branch from db6880b to 2bc998c Compare August 26, 2015 09:41
@kaspar030
Copy link
Contributor Author

  • rebased
  • added a lot of license headers & doxygen

@kaspar030
Copy link
Contributor Author

  • fixed unnecessary copying in _recv for ethernet packets

@kaspar030 kaspar030 added Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. and removed State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Aug 26, 2015
@miri64
Copy link
Member

miri64 commented Aug 26, 2015

Rebase please.

@kaspar030 kaspar030 force-pushed the add_gnrc_netdev2_support branch from b22f769 to 9e72aa4 Compare August 26, 2015 16:45
@kaspar030
Copy link
Contributor Author

  • rebased

@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Aug 26, 2015
@kaspar030
Copy link
Contributor Author

(triggered CI)

@kaspar030
Copy link
Contributor Author

@emmanuelsearch Could you try this on OS X?

@emmanuelsearch
Copy link
Member

Sure. What test should I run?

@kaspar030
Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

const?

@kaspar030
Copy link
Contributor Author

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

@kaspar030 kaspar030 assigned OlegHahm and unassigned miri64 Sep 3, 2015
@OlegHahm
Copy link
Member

OlegHahm commented Sep 3, 2015

Of course I can test. The question is what and how?

@kaspar030
Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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.

@OlegHahm
Copy link
Member

OlegHahm commented Sep 3, 2015

see kaspar030#12

@OlegHahm
Copy link
Member

OlegHahm commented Sep 3, 2015

and with RPL initialized I get after some time:

gnrc_networking.elf: /home/oleg/git/RIOT/cpu/native/netdev2_tap/netdev2_tap.c:151: _get: Assertion `max_len == 2' failed.

on the non-root node.

To reproduce:

  • start two native instances with gnrc_networking
  • call rpl init 7 on both
  • call ifconfig 7 add affe::1 and rpl root 1 affe::1 on one of them
  • see the crash on the other one

@kaspar030
Copy link
Contributor Author

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

@kaspar030
Copy link
Contributor Author

Fix for assertion PR'ed in #3774.

@OlegHahm
Copy link
Member

OlegHahm commented Sep 3, 2015

I get a strange error if I just remove the assert:

"make" -C /home/oleg/git/RIOT/cpu/native/netdev2_tap
/home/oleg/git/RIOT/cpu/native/netdev2_tap/netdev2_tap.c: In function ‘_get’
/home/oleg/git/RIOT/cpu/native/netdev2_tap/netdev2_tap.c:151:13: error: a label can only be part of a statement and a declaration is not a statement
             uint16_t *tgt = (uint16_t*)value;

If I put the case block in curly bracket it compiles again...

@OlegHahm
Copy link
Member

OlegHahm commented Sep 3, 2015

But without the assert things seem to work as they should.

@kaspar030
Copy link
Contributor Author

@OlegHahm Assuming #3774 gets merged, should I squash?

@OlegHahm
Copy link
Member

OlegHahm commented Sep 4, 2015

Go ahead!

@kaspar030 kaspar030 force-pushed the add_gnrc_netdev2_support branch from e87907b to 8deb11b Compare September 4, 2015 10:19
@kaspar030 kaspar030 added State: waiting for other PR State: The PR requires another PR to be merged first and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Sep 4, 2015
@kaspar030 kaspar030 force-pushed the add_gnrc_netdev2_support branch from 8deb11b to 4e5a675 Compare September 4, 2015 13:39
@kaspar030
Copy link
Contributor Author

  • squash-added missing license header

@OlegHahm
Copy link
Member

OlegHahm commented Sep 4, 2015

Double green!

@kaspar030
Copy link
Contributor Author

Nice, but no ACK ...

@OlegHahm
Copy link
Member

OlegHahm commented Sep 4, 2015

Sorry, couldn't find a way to break it. ACK

@kaspar030
Copy link
Contributor Author

&go! thanks for testing!

kaspar030 added a commit that referenced this pull request Sep 4, 2015
@kaspar030 kaspar030 merged commit 48baf5d into RIOT-OS:master Sep 4, 2015
@kaspar030 kaspar030 deleted the add_gnrc_netdev2_support branch September 4, 2015 16:00
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 Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants