From: Ben Pfaff Date: Thu, 15 Sep 2011 17:41:15 +0000 (-0700) Subject: netdev: Allow get_mtu and set_mtu provider functions to be null. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14622f22abd93ca464c9be1b6b58d6f0fb2bb186;p=openvswitch 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. --- diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h index b8f65291..22b00f72 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 f215ec6e..cf475b24 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 0074de02..1a668c8b 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));