From 373be31fa1c25f0ed52f18a2ec2536591467e1a9 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 7 Dec 2012 11:28:26 -0500 Subject: [PATCH] netdev-bsd: Use underlying tap device on netdev_bsd_listen(). This is a trivial port to netdev-bsd of Justin Pettit's netdev-linux commit 33d82a56d (netdev-linux: Use underlying tap device on netdev_linux_listen().), which had the commit message: Commit acf608 (ofproto-dpif: Use a single underlying datapath across multiple bridges.) broke connectivity to userspace datapath devices. The code assumed the first caller to open a tap device with netdev_linux_open() wanted to write to it. This commit moves that logic to when netdev_linux_listen() is called. This fixes the userspace datapath on FreeBSD. Signed-off-by: Ed Maste Signed-off-by: Ben Pfaff --- lib/netdev-bsd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c index 256955dfb..6e562db3f 100644 --- a/lib/netdev-bsd.c +++ b/lib/netdev-bsd.c @@ -398,7 +398,6 @@ netdev_bsd_destroy(struct netdev_dev *netdev_dev_) static int netdev_bsd_open_system(struct netdev_dev *netdev_dev_, struct netdev **netdevp) { - struct netdev_dev_bsd *netdev_dev = netdev_dev_bsd_cast(netdev_dev_); struct netdev_bsd *netdev; int error; enum netdev_flags flags; @@ -414,15 +413,6 @@ netdev_bsd_open_system(struct netdev_dev *netdev_dev_, struct netdev **netdevp) goto error; } - /* The first user that opens a tap port(from dpif_create_and_open()) will - * receive the file descriptor associated with the tap device. Instead, the - * following users will open the tap device as a normal 'system' device. */ - if (!strcmp(netdev_dev_get_type(netdev_dev_), "tap") && - !netdev_dev->tap_opened) { - netdev_dev->tap_opened = true; - netdev->netdev_fd = netdev_dev->tap_fd; - } - *netdevp = &netdev->netdev; return 0; @@ -450,6 +440,9 @@ static int netdev_bsd_listen(struct netdev *netdev_) { struct netdev_bsd *netdev = netdev_bsd_cast(netdev_); + struct netdev_dev_bsd *netdev_dev = + netdev_dev_bsd_cast(netdev_get_dev(netdev_)); + char errbuf[PCAP_ERRBUF_SIZE]; int error; int fd = -1; @@ -459,6 +452,13 @@ netdev_bsd_listen(struct netdev *netdev_) return 0; } + if (!strcmp(netdev_get_type(netdev_), "tap") && + !netdev_dev->tap_opened) { + netdev->netdev_fd = netdev_dev->tap_fd; + netdev_dev->tap_opened = true; + return 0; + } + /* open the pcap device. The device is opened in non-promiscuous mode * because the interface flags are manually set by the caller. */ errbuf[0] = '\0'; -- 2.43.0