diff options
author | Ben Pfaff <blp@nicira.com> | 2011-08-05 14:15:32 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2011-08-08 10:24:24 -0700 |
commit | 7b6b0ef47e398a2fbda48fd385f9781b2df8bebb (patch) | |
tree | bae52e2382bf61228cee38bb32ddaa3b8345a689 /lib/netdev-dummy.c | |
parent | 8cea3c07718d55c6eea288be87b3ea9e4d3b88cd (diff) |
netdev: Clean up and refactor packet receive interface.
The Open vSwitch tree only has one user of the ability for a netdev to
receive packets from a network device. Thus, this commit simplifies the
common-case use of the netdev interface by replacing the "ethertype" option
from "struct netdev_options" by a new netdev_listen() call.
The only user of netdev_listen() wants to receive all packets from a
network device, so this commit also removes the ability to restrict the
received packets to a particular protocol. (This ability was once used by
the Open vSwitch integrated DHCP client, but that code has been removed.)
This commit also simplifies and improves the implementation of the code
in netdev-linux that started listening to a network device. Before, I had
not figured out how to avoid receiving all packets on all devices before
binding to a particular device, but I took a closer look at the kernel code
and figured it out.
I've tested that the userspace datapath (dpif-netdev), the only user of
netdev_recv(), still works after this change.
Diffstat (limited to 'lib/netdev-dummy.c')
-rw-r--r-- | lib/netdev-dummy.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c index 9cd06f19..15d97cff 100644 --- a/lib/netdev-dummy.c +++ b/lib/netdev-dummy.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Nicira Networks. + * Copyright (c) 2010, 2011 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -102,8 +102,7 @@ netdev_dummy_destroy(struct netdev_dev *netdev_dev_) } static int -netdev_dummy_open(struct netdev_dev *netdev_dev_, int ethertype OVS_UNUSED, - struct netdev **netdevp) +netdev_dummy_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp) { struct netdev_dummy *netdev; @@ -122,6 +121,22 @@ netdev_dummy_close(struct netdev *netdev_) } static int +netdev_dummy_listen(struct netdev *netdev_ OVS_UNUSED) +{ + /* It's OK to listen on a dummy device. It just never receives any + * packets. */ + return 0; +} + +static int +netdev_dummy_recv(struct netdev *netdev_ OVS_UNUSED, + void *buffer OVS_UNUSED, size_t size OVS_UNUSED) +{ + /* A dummy device never receives any packets. */ + return -EAGAIN; +} + +static int netdev_dummy_set_etheraddr(struct netdev *netdev, const uint8_t mac[ETH_ADDR_LEN]) { @@ -234,7 +249,8 @@ static const struct netdev_class dummy_class = { NULL, /* enumerate */ - NULL, /* recv */ + netdev_dummy_listen, /* listen */ + netdev_dummy_recv, /* recv */ NULL, /* recv_wait */ NULL, /* drain */ |