projects
/
openvswitch
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
stream-ssl: Fix unimportant memory leak.
[openvswitch]
/
lib
/
dpif-linux.c
diff --git
a/lib/dpif-linux.c
b/lib/dpif-linux.c
index 4d8c8048ddf1496d1fb60dbb101c4234dc6fdff8..94c3cf5c5a756af34c100d4facc3b4bc4bdf30d5 100644
(file)
--- a/
lib/dpif-linux.c
+++ b/
lib/dpif-linux.c
@@
-1,5
+1,5
@@
/*
/*
- * 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.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-61,6
+61,7
@@
static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(9999, 5);
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 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 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);
@@
-77,9
+78,16
@@
dpif_linux_cast(const struct dpif *dpif)
static int
dpif_linux_enumerate(struct svec *all_dps)
{
static int
dpif_linux_enumerate(struct svec *all_dps)
{
+ int major;
int error;
int i;
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;
error = 0;
for (i = 0; i < ODP_MAX; i++) {
struct dpif *dpif;
@@
-87,10
+95,10
@@
dpif_linux_enumerate(struct svec *all_dps)
int retval;
sprintf(devname, "dp%d", i);
int retval;
sprintf(devname, "dp%d", i);
- retval = dpif_open(devname, &dpif);
+ retval = dpif_open(devname,
"system",
&dpif);
if (!retval) {
svec_add(all_dps, devname);
if (!retval) {
svec_add(all_dps, devname);
- dpif_
close(dpif
);
+ dpif_
uninit(dpif, true
);
} else if (retval != ENODEV && !error) {
error = retval;
}
} else if (retval != ENODEV && !error) {
error = retval;
}
@@
-99,19
+107,20
@@
dpif_linux_enumerate(struct svec *all_dps)
}
static int
}
static int
-dpif_linux_open(const char *name
UNUSED, char *suffix
, bool create,
+dpif_linux_open(const char *name
, const char *type UNUSED
, bool create,
struct dpif **dpifp)
{
int minor;
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) {
if (create) {
if (minor >= 0) {
- return create_minor(
suffix
, minor, dpifp);
+ return create_minor(
name
, minor, dpifp);
} else {
/* Scan for unused minor number. */
for (minor = 0; minor < ODP_MAX; minor++) {
} else {
/* Scan for unused minor number. */
for (minor = 0; minor < ODP_MAX; minor++) {
- int error = create_minor(
suffix
, minor, dpifp);
+ int error = create_minor(
name
, minor, dpifp);
if (error != EBUSY) {
return error;
}
if (error != EBUSY) {
return error;
}
@@
-126,7
+135,7
@@
dpif_linux_open(const char *name UNUSED, char *suffix, bool create,
int error;
if (minor < 0) {
int error;
if (minor < 0) {
- error = lookup_minor(
suffix
, &minor);
+ error = lookup_minor(
name
, &minor);
if (error) {
return error;
}
if (error) {
return error;
}
@@
-148,7
+157,7
@@
dpif_linux_open(const char *name UNUSED, char *suffix, bool create,
VLOG_WARN("%s: probe returned unexpected error: %s",
dpif_name(*dpifp), strerror(error));
}
VLOG_WARN("%s: probe returned unexpected error: %s",
dpif_name(*dpifp), strerror(error));
}
- dpif_
close(*dpifp
);
+ dpif_
uninit(*dpifp, true
);
return error;
}
return error;
}
@@
-410,7
+419,7
@@
dpif_linux_recv(struct dpif *dpif_, struct ofpbuf **bufp)
return 0;
} else {
VLOG_WARN_RL(&error_rl, "%s: discarding message truncated "
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_name(dpif_), msg->length, retval);
error = ERANGE;
}
@@
-437,8
+446,7
@@
dpif_linux_recv_wait(struct dpif *dpif_)
}
const struct dpif_class dpif_linux_class = {
}
const struct dpif_class dpif_linux_class = {
- "", /* This is the default class. */
- "linux",
+ "system",
NULL,
NULL,
dpif_linux_enumerate,
NULL,
NULL,
dpif_linux_enumerate,
@@
-471,7
+479,7
@@
const struct dpif_class dpif_linux_class = {
};
\f
static int get_openvswitch_major(void);
};
\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
do_ioctl(const struct dpif *dpif_, int cmd, const void *arg)
@@
-540,11
+548,18
@@
error:
static int
make_openvswitch_device(int minor, char **fnp)
{
static int
make_openvswitch_device(int minor, char **fnp)
{
- dev_t dev = makedev(get_openvswitch_major(), minor);
const char dirname[] = "/dev/net";
const char dirname[] = "/dev/net";
+ int major;
+ dev_t dev;
struct stat s;
char fn[128];
struct stat s;
char fn[128];
+ major = get_openvswitch_major();
+ if (major < 0) {
+ return -major;
+ }
+ dev = makedev(major, minor);
+
*fnp = NULL;
sprintf(fn, "%s/dp%d", dirname, minor);
if (!stat(fn, &s)) {
*fnp = NULL;
sprintf(fn, "%s/dp%d", dirname, minor);
if (!stat(fn, &s)) {
@@
-553,7
+568,7
@@
make_openvswitch_device(int minor, char **fnp)
fn);
} else if (s.st_rdev != dev) {
VLOG_WARN_RL(&error_rl,
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 {
fn, major(s.st_rdev), minor(s.st_rdev),
major(dev), minor(dev));
} else {
@@
-596,20
+611,20
@@
success:
return 0;
}
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 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
}
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];
{
const char fn[] = "/proc/devices";
char line[128];
@@
-619,7
+634,7
@@
get_major(const char *target, int default_major)
file = fopen(fn, "r");
if (!file) {
VLOG_ERR("opening %s failed (%s)", fn, strerror(errno));
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++) {
}
for (ln = 1; fgets(line, sizeof line, file); ln++) {
@@
-645,22
+660,19
@@
get_major(const char *target, int default_major)
}
}
}
}
- 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
finish_open(struct dpif *dpif_, const char *local_ifname)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
}
static int
finish_open(struct dpif *dpif_, const char *local_ifname)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- dpif->local_ifname = strdup(local_ifname);
+ dpif->local_ifname =
x
strdup(local_ifname);
dpif->local_ifindex = if_nametoindex(local_ifname);
if (!dpif->local_ifindex) {
int error = errno;
dpif->local_ifindex = if_nametoindex(local_ifname);
if (!dpif->local_ifindex) {
int error = errno;
- dpif_
close(dpif_
);
+ dpif_
uninit(dpif_, true
);
VLOG_WARN("could not get ifindex of %s device: %s",
local_ifname, strerror(errno));
return error;
VLOG_WARN("could not get ifindex of %s device: %s",
local_ifname, strerror(errno));
return error;
@@
-677,7
+689,7
@@
create_minor(const char *name, int minor, struct dpif **dpifp)
if (!error) {
error = finish_open(*dpifp, name);
} else {
if (!error) {
error = finish_open(*dpifp, name);
} else {
- dpif_
close(*dpifp
);
+ dpif_
uninit(*dpifp, true
);
}
}
return error;
}
}
return error;