summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-09-15 10:41:15 -0700
committerBen Pfaff <blp@nicira.com>2011-09-15 10:41:15 -0700
commit14622f22abd93ca464c9be1b6b58d6f0fb2bb186 (patch)
treef0da08fad41f064d74044246468d62794c2e7156
parent98fbd5b28b4e67d3cabe2ef1c7d1dfec9a1067ce (diff)
downloadopenvswitch-14622f22abd93ca464c9be1b6b58d6f0fb2bb186.tar.gz
netdev: Allow get_mtu and set_mtu provider functions to be null.
Most netdev provider functions are allowed to be null if the implementation does not support this feature. This commit adds this feature for get_mtu and set_mtu, and changes netdev-vport to take advantage of it. Also, changes netdev_get_mtu() to report an MTU of 0 on error, instead of leaving the MTU indeterminate.
-rw-r--r--lib/netdev-provider.h6
-rw-r--r--lib/netdev-vport.c18
-rw-r--r--lib/netdev.c21
3 files changed, 21 insertions, 24 deletions
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index b8f652919..22b00f728 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -248,13 +248,15 @@ struct netdev_class {
* bytes for Ethernet devices.
*
* If 'netdev' does not have an MTU (e.g. as some tunnels do not), then
- * this function should return EOPNOTSUPP. */
+ * this function should return EOPNOTSUPP. This function may be set to
+ * null if it would always return EOPNOTSUPP. */
int (*get_mtu)(const struct netdev *netdev, int *mtup);
/* Sets 'netdev''s MTU to 'mtu'.
*
* If 'netdev' does not have an MTU (e.g. as some tunnels do not), then
- * this function should return EOPNOTSUPP. */
+ * this function should return EOPNOTSUPP. This function may be set to
+ * null if it would always return EOPNOTSUPP. */
int (*set_mtu)(const struct netdev *netdev, int mtu);
/* Returns the ifindex of 'netdev', if successful, as a positive number.
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index f215ec6e0..cf475b242 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -361,20 +361,6 @@ netdev_vport_get_etheraddr(const struct netdev *netdev,
return error;
}
-static int
-netdev_vport_get_mtu(const struct netdev *netdev OVS_UNUSED,
- int *mtup OVS_UNUSED)
-{
- return EOPNOTSUPP;
-}
-
-static int
-netdev_vport_set_mtu(const struct netdev *netdev OVS_UNUSED,
- int mtu OVS_UNUSED)
-{
- return EOPNOTSUPP;
-}
-
int
netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
{
@@ -872,8 +858,8 @@ unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
\
netdev_vport_set_etheraddr, \
netdev_vport_get_etheraddr, \
- netdev_vport_get_mtu, \
- netdev_vport_set_mtu, \
+ NULL, /* get_mtu */ \
+ NULL, /* set_mtu */ \
NULL, /* get_ifindex */ \
NULL, /* get_carrier */ \
NULL, /* get_miimon */ \
diff --git a/lib/netdev.c b/lib/netdev.c
index 0074de025..1a668c8b1 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -531,14 +531,21 @@ netdev_get_name(const struct netdev *netdev)
*
* If successful, returns 0 and stores the MTU size in '*mtup'. Returns
* EOPNOTSUPP if 'netdev' does not have an MTU (as e.g. some tunnels do not).
- * On other failure, returns a positive errno value. */
+ * On other failure, returns a positive errno value. On failure, sets '*mtup'
+ * to 0. */
int
netdev_get_mtu(const struct netdev *netdev, int *mtup)
{
- int error = netdev_get_dev(netdev)->netdev_class->get_mtu(netdev, mtup);
- if (error && error != EOPNOTSUPP) {
- VLOG_WARN_RL(&rl, "failed to retrieve MTU for network device %s: %s",
- netdev_get_name(netdev), strerror(error));
+ const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class;
+ int error;
+
+ error = class->get_mtu ? class->get_mtu(netdev, mtup) : EOPNOTSUPP;
+ if (error) {
+ *mtup = 0;
+ if (error != EOPNOTSUPP) {
+ VLOG_WARN_RL(&rl, "failed to retrieve MTU for network device %s: "
+ "%s", netdev_get_name(netdev), strerror(error));
+ }
}
return error;
}
@@ -552,8 +559,10 @@ netdev_get_mtu(const struct netdev *netdev, int *mtup)
int
netdev_set_mtu(const struct netdev *netdev, int mtu)
{
- int error = netdev_get_dev(netdev)->netdev_class->set_mtu(netdev, mtu);
+ const struct netdev_class *class = netdev_get_dev(netdev)->netdev_class;
+ int error;
+ error = class->set_mtu ? class->set_mtu(netdev, mtu) : EOPNOTSUPP;
if (error && error != EOPNOTSUPP) {
VLOG_WARN_RL(&rl, "failed to retrieve MTU for network device %s: %s",
netdev_get_name(netdev), strerror(error));