[ovs-dev] [PATCH] netdev-linux: Improve netdev_linux_set_etheraddr().

Ben Pfaff blp at nicira.com
Fri Oct 2 18:05:35 UTC 2009


Thank you, I pushed this out.

Justin Pettit <jpettit at nicira.com> writes:

> Looks good to me.
>
> --Justin
>
>
> On Oct 2, 2009, at 10:09 AM, Ben Pfaff wrote:
>
>> 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.
>> ---
>> 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 50a0d2d..8426197 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;
>> }
>> --
>> 1.6.3.3
>>
>>
>> _______________________________________________
>> dev mailing list
>> dev at openvswitch.org
>> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org




More information about the dev mailing list