/*
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static int do_ioctl(const struct dpif *, int cmd, const void *arg);
static int lookup_minor(const char *name, int *minor);
static int finish_open(struct dpif *, const char *local_ifname);
+static int get_openvswitch_major(void);
static int create_minor(const char *name, int minor, struct dpif **dpifp);
static int open_minor(int minor, struct dpif **dpifp);
static int make_openvswitch_device(int minor, char **fnp);
static int
dpif_linux_enumerate(struct svec *all_dps)
{
+ int major;
int error;
int i;
+ /* Check that the Open vSwitch module is loaded. */
+ major = get_openvswitch_major();
+ if (major < 0) {
+ return -major;
+ }
+
error = 0;
for (i = 0; i < ODP_MAX; i++) {
struct dpif *dpif;
}
static int
-dpif_linux_open(const char *name UNUSED, char *suffix, bool create,
+dpif_linux_open(const char *name OVS_UNUSED, char *suffix, bool create,
struct dpif **dpifp)
{
int minor;
- minor = !strncmp(name, "dp", 2) && isdigit(name[2]) ? atoi(name + 2) : -1;
+ minor = !strncmp(name, "dp", 2)
+ && isdigit((unsigned char)name[2]) ? atoi(name + 2) : -1;
if (create) {
if (minor >= 0) {
return create_minor(suffix, minor, dpifp);
static int
dpif_linux_get_stats(const struct dpif *dpif_, struct odp_stats *stats)
{
+ memset(stats, 0, sizeof *stats);
return do_ioctl(dpif_, ODP_DP_STATS, stats);
}
return do_ioctl(dpif_, ODP_SET_LISTEN_MASK, &listen_mask);
}
+static int
+dpif_linux_get_sflow_probability(const struct dpif *dpif_,
+ uint32_t *probability)
+{
+ return do_ioctl(dpif_, ODP_GET_SFLOW_PROBABILITY, probability);
+}
+
+static int
+dpif_linux_set_sflow_probability(struct dpif *dpif_, uint32_t probability)
+{
+ return do_ioctl(dpif_, ODP_SET_SFLOW_PROBABILITY, &probability);
+}
+
static int
dpif_linux_recv(struct dpif *dpif_, struct ofpbuf **bufp)
{
return 0;
} else {
VLOG_WARN_RL(&error_rl, "%s: discarding message truncated "
- "from %zu bytes to %d",
+ "from %"PRIu32" bytes to %d",
dpif_name(dpif_), msg->length, retval);
error = ERANGE;
}
dpif_linux_execute,
dpif_linux_recv_get_mask,
dpif_linux_recv_set_mask,
+ dpif_linux_get_sflow_probability,
+ dpif_linux_set_sflow_probability,
dpif_linux_recv,
dpif_linux_recv_wait,
};
\f
static int get_openvswitch_major(void);
-static int get_major(const char *target, int default_major);
+static int get_major(const char *target);
static int
do_ioctl(const struct dpif *dpif_, int cmd, const void *arg)
static int
make_openvswitch_device(int minor, char **fnp)
{
- dev_t dev = makedev(get_openvswitch_major(), minor);
const char dirname[] = "/dev/net";
+ int major;
+ dev_t dev;
struct stat s;
char fn[128];
*fnp = NULL;
+
+ major = get_openvswitch_major();
+ if (major < 0) {
+ return -major;
+ }
+ dev = makedev(major, minor);
+
sprintf(fn, "%s/dp%d", dirname, minor);
if (!stat(fn, &s)) {
if (!S_ISCHR(s.st_mode)) {
fn);
} else if (s.st_rdev != dev) {
VLOG_WARN_RL(&error_rl,
- "%s is device %u:%u instead of %u:%u, fixing",
+ "%s is device %u:%u but should be %u:%u, fixing",
fn, major(s.st_rdev), minor(s.st_rdev),
major(dev), minor(dev));
} else {
return 0;
}
-
+/* Return the major device number of the Open vSwitch device. If it
+ * cannot be determined, a negative errno is returned. */
static int
get_openvswitch_major(void)
{
- static unsigned int openvswitch_major;
- if (!openvswitch_major) {
- enum { DEFAULT_MAJOR = 248 };
- openvswitch_major = get_major("openvswitch", DEFAULT_MAJOR);
+ static int openvswitch_major = -1;
+ if (openvswitch_major < 0) {
+ openvswitch_major = get_major("openvswitch");
}
return openvswitch_major;
}
static int
-get_major(const char *target, int default_major)
+get_major(const char *target)
{
const char fn[] = "/proc/devices";
char line[128];
file = fopen(fn, "r");
if (!file) {
VLOG_ERR("opening %s failed (%s)", fn, strerror(errno));
- goto error;
+ return -errno;
}
for (ln = 1; fgets(line, sizeof line, file); ln++) {
}
}
- VLOG_ERR("%s: %s major not found (is the module loaded?), using "
- "default major %d", fn, target, default_major);
-error:
- VLOG_INFO("using default major %d for %s", default_major, target);
- return default_major;
+ VLOG_ERR("%s: %s major not found (is the module loaded?)", fn, target);
+ return -ENODEV;
}
static int