netdev-linux: Cache the result of previous reading of in4 address.
authorAlex Wang <alexw@nicira.com>
Fri, 24 Jul 2015 21:28:42 +0000 (14:28 -0700)
committerAlex Wang <alexw@nicira.com>
Tue, 28 Jul 2015 16:34:31 +0000 (09:34 -0700)
This commit makes netdev_linux_set_in4() cache the result of previous
reading of in4 address (successful or not).

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/netdev-linux.c

index bdc672d..712cb5a 100644 (file)
@@ -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;