netdev: Allow get_mtu and set_mtu provider functions to be null.
authorBen Pfaff <blp@nicira.com>
Thu, 15 Sep 2011 17:41:15 +0000 (10:41 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 15 Sep 2011 17:41:15 +0000 (10:41 -0700)
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.

lib/netdev-provider.h
lib/netdev-vport.c
lib/netdev.c

index b8f6529..22b00f7 100644 (file)
@@ -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.
index f215ec6..cf475b2 100644 (file)
@@ -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 */            \
index 0074de0..1a668c8 100644 (file)
@@ -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));