#include <config.h>
#include <stdlib.h>
-#include <config.h>
-#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include "socket-util.h"
#include "shash.h"
#include "svec.h"
+#include "util.h"
#include "vlog.h"
VLOG_DEFINE_THIS_MODULE(netdev_bsd);
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
-static int netdev_bsd_do_ioctl(const struct netdev *, struct ifreq *,
- unsigned long cmd, const char *cmd_name);
+static int netdev_bsd_do_ioctl(const char *, struct ifreq *, unsigned long cmd,
+ const char *cmd_name);
static void destroy_tap(int fd, const char *name);
-static int get_flags(const struct netdev *, int *flagsp);
-static int set_flags(struct netdev *, int flags);
+static int get_flags(const struct netdev_dev *, int *flagsp);
+static int set_flags(const char *, int flags);
static int do_set_addr(struct netdev *netdev,
int ioctl_nr, const char *ioctl_name,
struct in_addr addr);
static struct netdev_bsd *
netdev_bsd_cast(const struct netdev *netdev)
{
- assert(is_netdev_bsd_class(netdev_dev_get_class(netdev_get_dev(netdev))));
+ ovs_assert(is_netdev_bsd_class(netdev_dev_get_class(
+ netdev_get_dev(netdev))));
return CONTAINER_OF(netdev, struct netdev_bsd, netdev);
}
static struct netdev_dev_bsd *
netdev_dev_bsd_cast(const struct netdev_dev *netdev_dev)
{
- assert(is_netdev_bsd_class(netdev_dev_get_class(netdev_dev)));
+ ovs_assert(is_netdev_bsd_class(netdev_dev_get_class(netdev_dev)));
return CONTAINER_OF(netdev_dev, struct netdev_dev_bsd, 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;
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;
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;
+ int fd = -1;
int one = 1;
if (netdev->netdev_fd >= 0) {
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';
struct ifreq ifr;
int error;
- error = netdev_bsd_do_ioctl(netdev_, &ifr, SIOCGIFMTU, "SIOCGIFMTU");
+ error = netdev_bsd_do_ioctl(netdev_get_name(netdev_), &ifr, SIOCGIFMTU,
+ "SIOCGIFMTU");
if (error) {
return error;
}
stats->rx_errors = ifmd.ifmd_data.ifi_ierrors;
stats->tx_errors = ifmd.ifmd_data.ifi_oerrors;
stats->rx_dropped = ifmd.ifmd_data.ifi_iqdrops;
- stats->tx_dropped = 0;
+ stats->tx_dropped = UINT64_MAX;
stats->multicast = ifmd.ifmd_data.ifi_imcasts;
stats->collisions = ifmd.ifmd_data.ifi_collisions;
- stats->rx_length_errors = 0;
- stats->rx_over_errors = 0;
- stats->rx_crc_errors = 0;
- stats->rx_frame_errors = 0;
- stats->rx_fifo_errors = 0;
- stats->rx_missed_errors = 0;
-
- stats->tx_aborted_errors = 0;
- stats->tx_carrier_errors = 0;
- stats->tx_fifo_errors = 0;
- stats->tx_heartbeat_errors = 0;
- stats->tx_window_errors = 0;
+ stats->rx_length_errors = UINT64_MAX;
+ stats->rx_over_errors = UINT64_MAX;
+ stats->rx_crc_errors = UINT64_MAX;
+ stats->rx_frame_errors = UINT64_MAX;
+ stats->rx_fifo_errors = UINT64_MAX;
+ stats->rx_missed_errors = UINT64_MAX;
+
+ stats->tx_aborted_errors = UINT64_MAX;
+ stats->tx_carrier_errors = UINT64_MAX;
+ stats->tx_fifo_errors = UINT64_MAX;
+ stats->tx_heartbeat_errors = UINT64_MAX;
+ stats->tx_window_errors = UINT64_MAX;
break;
}
}
media_list = xcalloc(ifmr.ifm_count, sizeof(int));
ifmr.ifm_ulist = media_list;
- if (!IFM_TYPE(ifmr.ifm_current) & IFM_ETHER) {
+ if (IFM_TYPE(ifmr.ifm_current) != IFM_ETHER) {
VLOG_DBG_RL(&rl, "%s: doesn't appear to be ethernet",
netdev_get_name(netdev));
error = EINVAL;
int error;
ifr.ifr_addr.sa_family = AF_INET;
- error = netdev_bsd_do_ioctl(netdev_, &ifr,
+ error = netdev_bsd_do_ioctl(netdev_get_name(netdev_), &ifr,
SIOCGIFADDR, "SIOCGIFADDR");
if (error) {
return error;
sin = (struct sockaddr_in *) &ifr.ifr_addr;
netdev_dev->in4 = sin->sin_addr;
netdev_dev->cache_valid |= VALID_IN4;
- error = netdev_bsd_do_ioctl(netdev_, &ifr,
+ error = netdev_bsd_do_ioctl(netdev_get_name(netdev_), &ifr,
SIOCGIFNETMASK, "SIOCGIFNETMASK");
if (error) {
return error;
}
static int
-netdev_bsd_update_flags(struct netdev *netdev, enum netdev_flags off,
+netdev_bsd_update_flags(struct netdev_dev *dev_, enum netdev_flags off,
enum netdev_flags on, enum netdev_flags *old_flagsp)
{
+ struct netdev_dev_bsd *netdev_dev;
int old_flags, new_flags;
int error;
- error = get_flags(netdev, &old_flags);
+ netdev_dev = netdev_dev_bsd_cast(dev_);
+ error = get_flags(dev_, &old_flags);
if (!error) {
*old_flagsp = iff_to_nd_flags(old_flags);
new_flags = (old_flags & ~nd_to_iff_flags(off)) | nd_to_iff_flags(on);
if (new_flags != old_flags) {
- error = set_flags(netdev, new_flags);
- netdev_dev_bsd_changed(netdev_dev_bsd_cast(netdev_get_dev(netdev)));
+ error = set_flags(netdev_dev_get_name(dev_), new_flags);
+ netdev_dev_bsd_changed(netdev_dev);
}
}
return error;
netdev_bsd_destroy,
NULL, /* get_config */
NULL, /* set_config */
+ NULL, /* get_tunnel_config */
netdev_bsd_open_system,
netdev_bsd_close,
netdev_bsd_get_in6,
NULL, /* add_router */
NULL, /* get_next_hop */
- NULL, /* get_drv_info */
+ NULL, /* get_status */
NULL, /* arp_lookup */
netdev_bsd_update_flags,
netdev_bsd_destroy,
NULL, /* get_config */
NULL, /* set_config */
+ NULL, /* get_tunnel_config */
netdev_bsd_open_system,
netdev_bsd_close,
netdev_bsd_get_in6,
NULL, /* add_router */
NULL, /* get_next_hop */
- NULL, /* get_drv_info */
+ NULL, /* get_status */
NULL, /* arp_lookup */
netdev_bsd_update_flags,
}
static int
-get_flags(const struct netdev *netdev, int *flags)
+get_flags(const struct netdev_dev *dev, int *flags)
{
struct ifreq ifr;
int error;
- error = netdev_bsd_do_ioctl(netdev, &ifr, SIOCGIFFLAGS, "SIOCGIFFLAGS");
+ error = netdev_bsd_do_ioctl(dev->name, &ifr, SIOCGIFFLAGS, "SIOCGIFFLAGS");
*flags = 0xFFFF0000 & (ifr.ifr_flagshigh << 16);
*flags |= 0x0000FFFF & ifr.ifr_flags;
}
static int
-set_flags(struct netdev *netdev, int flags)
+set_flags(const char *name, int flags)
{
struct ifreq ifr;
ifr.ifr_flags = 0x0000FFFF & flags;
ifr.ifr_flagshigh = (0xFFFF0000 & flags) >> 16;
- return netdev_bsd_do_ioctl(netdev, &ifr, SIOCSIFFLAGS, "SIOCSIFFLAGS");
+ return netdev_bsd_do_ioctl(name, &ifr, SIOCSIFFLAGS, "SIOCSIFFLAGS");
}
static int
}
static int
-netdev_bsd_do_ioctl(const struct netdev *netdev, struct ifreq *ifr,
- unsigned long cmd, const char *cmd_name)
+netdev_bsd_do_ioctl(const char *name, struct ifreq *ifr, unsigned long cmd,
+ const char *cmd_name)
{
- strncpy(ifr->ifr_name, netdev_get_name(netdev), sizeof ifr->ifr_name);
+ strncpy(ifr->ifr_name, name, sizeof ifr->ifr_name);
if (ioctl(af_inet_sock, cmd, ifr) == -1) {
- VLOG_DBG_RL(&rl, "%s: ioctl(%s) failed: %s",
- netdev_get_name(netdev), cmd_name, strerror(errno));
+ VLOG_DBG_RL(&rl, "%s: ioctl(%s) failed: %s", name, cmd_name,
+ strerror(errno));
return errno;
}
return 0;