* Allow duplicates in the sAddressTable hash table; while it makes no sense to

have duplicates there, it should certainly not panic.
* Do not add unspecified addresses to the hash table.
* The result of adding the initial address of an interface was ignored; now, the
  interface is correctly destructed, if necessary.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40444 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2011-02-11 19:36:15 +00:00
parent 26143717a4
commit 4ae5863038
2 changed files with 36 additions and 13 deletions
+33 -12
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved. * Copyright 2006-2011, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -54,7 +54,8 @@ struct AddressHashDefinition {
size_t Hash(InterfaceAddress* address) const size_t Hash(InterfaceAddress* address) const
{ {
return address->domain->address_module->hash_address(address->local, false); return address->domain->address_module->hash_address(address->local,
false);
} }
bool Compare(const KeyType& key, InterfaceAddress* address) const bool Compare(const KeyType& key, InterfaceAddress* address) const
@@ -75,7 +76,7 @@ struct AddressHashDefinition {
} }
}; };
typedef BOpenHashTable<AddressHashDefinition, true, true> AddressTable; typedef BOpenHashTable<AddressHashDefinition, true, false> AddressTable;
static mutex sLock; static mutex sLock;
@@ -311,6 +312,13 @@ InterfaceAddress::RemoveDefaultRoutes(int32 option)
} }
bool
InterfaceAddress::LocalIsDefined() const
{
return local != NULL && local->sa_family != AF_UNSPEC;
}
#if ENABLE_DEBUGGER_COMMANDS #if ENABLE_DEBUGGER_COMMANDS
@@ -594,8 +602,10 @@ Interface::AddAddress(InterfaceAddress* address)
fAddresses.Add(address); fAddresses.Add(address);
locker.Unlock(); locker.Unlock();
MutexLocker hashLocker(sHashLock); if (address->LocalIsDefined()) {
sAddressTable.Insert(address); MutexLocker hashLocker(sHashLock);
sAddressTable.Insert(address);
}
return B_OK; return B_OK;
} }
@@ -614,8 +624,10 @@ Interface::RemoveAddress(InterfaceAddress* address)
locker.Unlock(); locker.Unlock();
MutexLocker hashLocker(sHashLock); if (address->LocalIsDefined()) {
sAddressTable.Remove(address); MutexLocker hashLocker(sHashLock);
sAddressTable.Remove(address);
}
} }
@@ -1198,12 +1210,19 @@ add_interface(const char* name, net_domain_private* domain,
locker.Unlock(); locker.Unlock();
notify_interface_added(interface); status_t status = add_interface_address(interface, domain, request);
add_interface_address(interface, domain, request); if (status == B_OK)
notify_interface_added(interface);
else {
locker.Lock();
sInterfaces.Remove(interface);
locker.Unlock();
interface->ReleaseReference();
}
interface->ReleaseReference(); interface->ReleaseReference();
return B_OK; return status;
} }
@@ -1316,7 +1335,8 @@ update_interface_address(InterfaceAddress* interfaceAddress, int32 option,
return B_OK; return B_OK;
} }
sAddressTable.Remove(interfaceAddress); if (interfaceAddress->LocalIsDefined())
sAddressTable.Remove(interfaceAddress);
// Copy new address over // Copy new address over
status_t status = InterfaceAddress::Set(_address, newAddress); status_t status = InterfaceAddress::Set(_address, newAddress);
@@ -1354,7 +1374,8 @@ update_interface_address(InterfaceAddress* interfaceAddress, int32 option,
notify_interface_changed(interface); notify_interface_changed(interface);
} }
sAddressTable.Insert(interfaceAddress); if (interfaceAddress->LocalIsDefined())
sAddressTable.Insert(interfaceAddress);
return status; return status;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved. * Copyright 2006-2011, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -47,6 +47,8 @@ struct InterfaceAddress : DoublyLinkedListLinkImpl<InterfaceAddress>,
void AddDefaultRoutes(int32 option); void AddDefaultRoutes(int32 option);
void RemoveDefaultRoutes(int32 option); void RemoveDefaultRoutes(int32 option);
bool LocalIsDefined() const;
InterfaceAddress*& HashTableLink() { return fLink; } InterfaceAddress*& HashTableLink() { return fLink; }
#if ENABLE_DEBUGGER_COMMANDS #if ENABLE_DEBUGGER_COMMANDS