* Fixed ignoring the netmask when computing the broadcast. Renamed a few

variables to make the function a bit clearer, hopefully.
* Fixed the wrong order of releasing the reference, and removing the object
  from the hash table -- thanks Rene!
* Added a bit of documentation to InterfaceAddress::Prepare().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40455 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2011-02-11 23:04:25 +00:00
parent e06c0a1d50
commit 5ebd954871
+15 -13
View File
@@ -396,6 +396,10 @@ InterfaceAddress::Set(sockaddr** _address, const sockaddr* to)
} }
/*! Makes sure that the sockaddr object pointed to by \a _address is large
enough to hold \a size bytes.
\a _address may point to NULL when calling this method.
*/
/*static*/ sockaddr* /*static*/ sockaddr*
InterfaceAddress::Prepare(sockaddr** _address, size_t size) InterfaceAddress::Prepare(sockaddr** _address, size_t size)
{ {
@@ -714,11 +718,11 @@ Interface::RemoveAddresses()
while (InterfaceAddress* address = fAddresses.RemoveHead()) { while (InterfaceAddress* address = fAddresses.RemoveHead()) {
locker.Unlock(); locker.Unlock();
address->ReleaseReference();
if (address->LocalIsDefined()) { if (address->LocalIsDefined()) {
MutexLocker hashLocker(sHashLock); MutexLocker hashLocker(sHashLock);
sAddressTable.Remove(address); sAddressTable.Remove(address);
} }
address->ReleaseReference();
locker.Lock(); locker.Lock();
} }
@@ -1354,31 +1358,29 @@ update_interface_address(InterfaceAddress* interfaceAddress, int32 option,
if (status == B_OK) { if (status == B_OK) {
sockaddr* address = *_address; sockaddr* address = *_address;
if (option == SIOCSIFADDR) { if (option == SIOCSIFADDR || option == SIOCSIFNETMASK) {
// Reset netmask and broadcast addresses to defaults // Reset netmask and broadcast addresses to defaults
net_domain* domain = interfaceAddress->domain; net_domain* domain = interfaceAddress->domain;
sockaddr* netmask = NULL; sockaddr* defaultNetmask = NULL;
const sockaddr* oldNetmask = NULL; const sockaddr* netmask = NULL;
if (option == SIOCSIFADDR) { if (option == SIOCSIFADDR) {
netmask = InterfaceAddress::Prepare( defaultNetmask = InterfaceAddress::Prepare(
&interfaceAddress->mask, address->sa_len); &interfaceAddress->mask, address->sa_len);
} else { } else
oldNetmask = oldAddress; netmask = newAddress;
netmask = interfaceAddress->mask;
}
// Reset the broadcast address if the address family has // Reset the broadcast address if the address family has
// such // such
sockaddr* broadcast = NULL; sockaddr* defaultBroadcast = NULL;
if ((domain->address_module->flags if ((domain->address_module->flags
& NET_ADDRESS_MODULE_FLAG_BROADCAST_ADDRESS) != 0) { & NET_ADDRESS_MODULE_FLAG_BROADCAST_ADDRESS) != 0) {
broadcast = InterfaceAddress::Prepare( defaultBroadcast = InterfaceAddress::Prepare(
&interfaceAddress->destination, address->sa_len); &interfaceAddress->destination, address->sa_len);
} else } else
InterfaceAddress::Set(&interfaceAddress->destination, NULL); InterfaceAddress::Set(&interfaceAddress->destination, NULL);
domain->address_module->set_to_defaults(netmask, broadcast, domain->address_module->set_to_defaults(defaultNetmask,
interfaceAddress->local, oldNetmask); defaultBroadcast, interfaceAddress->local, netmask);
} }
interfaceAddress->AddDefaultRoutes(option); interfaceAddress->AddDefaultRoutes(option);