diff options
| author | Ben Pfaff <blp@nicira.com> | 2009-10-01 13:27:47 -0700 |
|---|---|---|
| committer | Ben Pfaff <blp@nicira.com> | 2009-10-02 11:04:06 -0700 |
| commit | eb395f2ebf46888353e5966dd7969a1c49402334 (patch) | |
| tree | 16cb6093417abd60f8b3e8e9680b6fea9bc671cb /lib/netdev-linux.c | |
| parent | c0e5f6cabeeb8153144fead66c1f37a5014d9060 (diff) | |
| download | openvswitch-eb395f2ebf46888353e5966dd7969a1c49402334.tar.gz | |
netdev-linux: Improve netdev_linux_set_etheraddr().
Fixes a bug whereby netdev_linux_set_etheraddr() would update the cached
Ethernet address but not mark it valid. (This potentially wasted a system
call later but wasn't harmful.)
As an added optimization, don't set the Ethernet address at all if the
new address is the same as the current address.
Diffstat (limited to 'lib/netdev-linux.c')
| -rw-r--r-- | lib/netdev-linux.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index c71bdd492..73247030d 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -492,9 +492,17 @@ netdev_linux_set_etheraddr(struct netdev *netdev_, const uint8_t mac[ETH_ADDR_LEN]) { struct netdev_linux *netdev = netdev_linux_cast(netdev_); - int error = set_etheraddr(netdev_get_name(netdev_), ARPHRD_ETHER, mac); - if (!error) { - memcpy(netdev->cache->etheraddr, mac, ETH_ADDR_LEN); + int error; + + if (!(netdev->cache->valid & VALID_ETHERADDR) + || !eth_addr_equals(netdev->cache->etheraddr, mac)) { + error = set_etheraddr(netdev_get_name(netdev_), ARPHRD_ETHER, mac); + if (!error) { + netdev->cache->valid |= VALID_ETHERADDR; + memcpy(netdev->cache->etheraddr, mac, ETH_ADDR_LEN); + } + } else { + error = 0; } return error; } |
