aboutsummaryrefslogtreecommitdiff
path: root/lib/netdev-vport.c
diff options
context:
space:
mode:
authorEthan Jackson <ethan@nicira.com>2012-11-30 11:36:42 -0800
committerEthan Jackson <ethan@nicira.com>2013-01-03 17:30:48 -0800
commit35b769cb491586718a72dc133509e96b0a2feee8 (patch)
tree12053c026e5f6d84d27614e7287b22961100c3a0 /lib/netdev-vport.c
parent6f74491cda4414b746095314b36bca3e02b93840 (diff)
netdev-vport: Manage ethernet addresses in userspace.
Letting netdev-vport manage ethernet addresses itself instead of relying on the datapath has several advantages. It simplifies the code, is significantly more efficient, and will work when there is no longer a one to one mapping from netdev-vports to datapath vports. Signed-off-by: Ethan Jackson <ethan@nicira.com>
Diffstat (limited to 'lib/netdev-vport.c')
-rw-r--r--lib/netdev-vport.c34
1 files changed, 7 insertions, 27 deletions
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index c9cef5d7..e0e9479c 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -56,6 +56,7 @@ struct netdev_dev_vport {
struct netdev_dev netdev_dev;
struct ofpbuf *options;
unsigned int change_seq;
+ uint8_t etheraddr[ETH_ADDR_LEN];
};
struct netdev_vport {
@@ -207,6 +208,7 @@ netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
netdev_dev_init(&dev->netdev_dev, name, netdev_class);
dev->options = NULL;
dev->change_seq = 1;
+ eth_addr_random(dev->etheraddr);
*netdev_devp = &dev->netdev_dev;
route_table_register();
@@ -322,39 +324,17 @@ static int
netdev_vport_set_etheraddr(struct netdev *netdev,
const uint8_t mac[ETH_ADDR_LEN])
{
- struct dpif_linux_vport vport;
- int error;
-
- dpif_linux_vport_init(&vport);
- vport.cmd = OVS_VPORT_CMD_SET;
- vport.name = netdev_get_name(netdev);
- vport.address = mac;
-
- error = dpif_linux_vport_transact(&vport, NULL, NULL);
- if (!error) {
- netdev_vport_poll_notify(netdev);
- }
- return error;
+ memcpy(netdev_vport_get_dev(netdev)->etheraddr, mac, ETH_ADDR_LEN);
+ netdev_vport_poll_notify(netdev);
+ return 0;
}
static int
netdev_vport_get_etheraddr(const struct netdev *netdev,
uint8_t mac[ETH_ADDR_LEN])
{
- struct dpif_linux_vport reply;
- struct ofpbuf *buf;
- int error;
-
- error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
- if (!error) {
- if (reply.address) {
- memcpy(mac, reply.address, ETH_ADDR_LEN);
- } else {
- error = EOPNOTSUPP;
- }
- ofpbuf_delete(buf);
- }
- return error;
+ memcpy(mac, netdev_vport_get_dev(netdev)->etheraddr, ETH_ADDR_LEN);
+ return 0;
}
/* Copies 'src' into 'dst', performing format conversion in the process.