From 7ae51e190c72c106cbb99a2b2fdd979f94dd94a5 Mon Sep 17 00:00:00 2001 From: Alex Wang Date: Fri, 24 Jul 2015 14:28:42 -0700 Subject: [PATCH] netdev-linux: Cache the result of previous reading of in4 address. This commit makes netdev_linux_set_in4() cache the result of previous reading of in4 address (successful or not). Signed-off-by: Alex Wang Acked-by: Ben Pfaff --- lib/netdev-linux.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index bdc672d0f..712cb5ab7 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -458,6 +458,7 @@ struct netdev_linux { int netdev_policing_error; /* Cached error code from set policing. */ int get_features_error; /* Cached error code from ETHTOOL_GSET. */ int get_ifindex_error; /* Cached error code from SIOCGIFINDEX. */ + int in4_error; /* Cached error code from reading in4 addr. */ int in6_error; /* Cached error code from reading in6 addr. */ enum netdev_features current; /* Cached from ETHTOOL_GSET. */ @@ -2422,12 +2423,11 @@ netdev_linux_get_in4(const struct netdev *netdev_, if (!error) { error = netdev_linux_get_ipv4(netdev_, &netdev->netmask, SIOCGIFNETMASK, "SIOCGIFNETMASK"); - if (!error) { - netdev->cache_valid |= VALID_IN4; - } } + netdev->in4_error = error; + netdev->cache_valid |= VALID_IN4; } else { - error = 0; + error = netdev->in4_error; } if (!error) { @@ -2453,7 +2453,6 @@ netdev_linux_set_in4(struct netdev *netdev_, struct in_addr address, ovs_mutex_lock(&netdev->mutex); error = do_set_addr(netdev_, SIOCSIFADDR, "SIOCSIFADDR", address); if (!error) { - netdev->cache_valid |= VALID_IN4; netdev->address = address; netdev->netmask = netmask; if (address.s_addr != INADDR_ANY) { @@ -2461,6 +2460,13 @@ netdev_linux_set_in4(struct netdev *netdev_, struct in_addr address, "SIOCSIFNETMASK", netmask); } } + + if (!error) { + netdev->cache_valid |= VALID_IN4; + netdev->in4_error = 0; + } else { + netdev->cache_valid &= ~VALID_IN4; + } ovs_mutex_unlock(&netdev->mutex); return error; -- 2.20.1