From c7b1b0a53559a2383b329e72c84fb77a51df4d75 Mon Sep 17 00:00:00 2001 From: Pravin B Shelar Date: Fri, 9 Mar 2012 13:00:29 -0800 Subject: [PATCH] netdev-linux: Cache error code from do_get_ifindex(). Signed-off-by: Pravin B Shelar --- lib/netdev-linux.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index d177d38b..bc486b0c 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -381,6 +381,7 @@ struct netdev_dev_linux { int ether_addr_error; /* Cached error code from set/get etheraddr. */ 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. */ uint32_t current; /* Cached from ETHTOOL_GSET. */ uint32_t advertised; /* Cached from ETHTOOL_GSET. */ @@ -543,6 +544,7 @@ netdev_dev_linux_update(struct netdev_dev_linux *dev, /* Keep drv-info */ netdev_dev_linux_changed(dev, change->ifi_flags, VALID_DRVINFO); + /* Update netdev from rtnl-change msg. */ if (change->mtu) { dev->mtu = change->mtu; dev->cache_valid |= VALID_MTU; @@ -555,6 +557,10 @@ netdev_dev_linux_update(struct netdev_dev_linux *dev, dev->ether_addr_error = 0; } + dev->ifindex = change->ifi_index; + dev->cache_valid |= VALID_IFINDEX; + dev->get_ifindex_error = 0; + } else { netdev_dev_linux_changed(dev, change->ifi_flags, 0); } @@ -4404,17 +4410,22 @@ get_ifindex(const struct netdev *netdev_, int *ifindexp) { struct netdev_dev_linux *netdev_dev = netdev_dev_linux_cast(netdev_get_dev(netdev_)); - *ifindexp = 0; + if (!(netdev_dev->cache_valid & VALID_IFINDEX)) { int ifindex = do_get_ifindex(netdev_get_name(netdev_)); + if (ifindex < 0) { - return -ifindex; + netdev_dev->get_ifindex_error = -ifindex; + netdev_dev->ifindex = 0; + } else { + netdev_dev->get_ifindex_error = 0; + netdev_dev->ifindex = ifindex; } netdev_dev->cache_valid |= VALID_IFINDEX; - netdev_dev->ifindex = ifindex; } + *ifindexp = netdev_dev->ifindex; - return 0; + return netdev_dev->get_ifindex_error; } static int -- 2.30.2