* Made some functions static that should have been.
* Added a commented out dump_routes() function for debugging purposes. * Removed weird spaces, fixed indentation. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22722 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ff85245718
commit
9004a56437
@ -53,6 +53,26 @@ net_route_private::~net_route_private()
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static void
|
||||||
|
dump_routes(net_domain_private *domain)
|
||||||
|
{
|
||||||
|
RouteList::Iterator iterator = domain->routes.GetIterator();
|
||||||
|
uint32 count = 1;
|
||||||
|
|
||||||
|
while (iterator.HasNext()) {
|
||||||
|
net_route_private *route = iterator.Next();
|
||||||
|
|
||||||
|
dprintf(" [%lu] dest %s, mask %s, gw %s, flags %lx\n", count++,
|
||||||
|
AddressString(domain, route->destination ? route->destination : NULL).Data(),
|
||||||
|
AddressString(domain, route->mask ? route->mask : NULL).Data(),
|
||||||
|
AddressString(domain, route->gateway ? route->gateway : NULL).Data(),
|
||||||
|
route->flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
user_copy_address(const sockaddr *from, sockaddr **to)
|
user_copy_address(const sockaddr *from, sockaddr **to)
|
||||||
{
|
{
|
||||||
@ -115,11 +135,11 @@ find_route(struct net_domain *_domain, const net_route *description)
|
|||||||
|
|
||||||
if ((route->flags & (RTF_GATEWAY | RTF_HOST | RTF_LOCAL)) ==
|
if ((route->flags & (RTF_GATEWAY | RTF_HOST | RTF_LOCAL)) ==
|
||||||
(description->flags & (RTF_GATEWAY | RTF_HOST | RTF_LOCAL))
|
(description->flags & (RTF_GATEWAY | RTF_HOST | RTF_LOCAL))
|
||||||
&& domain->address_module->equal_masked_addresses(route->destination,
|
&& domain->address_module->equal_masked_addresses(route->destination,
|
||||||
description->destination, description->mask)
|
description->destination, description->mask)
|
||||||
&& domain->address_module->equal_addresses(route->mask,
|
&& domain->address_module->equal_addresses(route->mask,
|
||||||
description->mask)
|
description->mask)
|
||||||
&& domain->address_module->equal_addresses(route->gateway,
|
&& domain->address_module->equal_addresses(route->gateway,
|
||||||
description->gateway))
|
description->gateway))
|
||||||
return route;
|
return route;
|
||||||
}
|
}
|
||||||
@ -146,17 +166,17 @@ find_route(struct net_domain *_domain, const struct sockaddr *address)
|
|||||||
net_route_private *route = iterator.Next();
|
net_route_private *route = iterator.Next();
|
||||||
|
|
||||||
bool found;
|
bool found;
|
||||||
if (route->mask != NULL) {
|
if (route->mask != NULL) {
|
||||||
sockaddr maskedAddress;
|
sockaddr maskedAddress;
|
||||||
domain->address_module->mask_address(address, route->mask,
|
domain->address_module->mask_address(address, route->mask,
|
||||||
&maskedAddress);
|
&maskedAddress);
|
||||||
found = domain->address_module->equal_addresses(&maskedAddress,
|
found = domain->address_module->equal_addresses(&maskedAddress,
|
||||||
route->destination);
|
route->destination);
|
||||||
} else {
|
} else {
|
||||||
found = domain->address_module->equal_addresses(address,
|
found = domain->address_module->equal_addresses(address,
|
||||||
route->destination);
|
route->destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
TRACE((" found route: %s, flags %lx\n",
|
TRACE((" found route: %s, flags %lx\n",
|
||||||
AddressString(domain, route->destination).Data(), route->flags));
|
AddressString(domain, route->destination).Data(), route->flags));
|
||||||
@ -182,8 +202,9 @@ put_route_internal(struct net_domain_private *domain, net_route *_route)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct net_route *
|
static struct net_route *
|
||||||
get_route_internal(struct net_domain_private *domain, const struct sockaddr *address)
|
get_route_internal(struct net_domain_private *domain,
|
||||||
|
const struct sockaddr *address)
|
||||||
{
|
{
|
||||||
net_route_private *route = find_route(domain, address);
|
net_route_private *route = find_route(domain, address);
|
||||||
if (route != NULL && atomic_add(&route->ref_count, 1) == 0) {
|
if (route != NULL && atomic_add(&route->ref_count, 1) == 0) {
|
||||||
@ -195,14 +216,14 @@ get_route_internal(struct net_domain_private *domain, const struct sockaddr *add
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
update_route_infos(struct net_domain_private *domain)
|
update_route_infos(struct net_domain_private *domain)
|
||||||
{
|
{
|
||||||
RouteInfoList::Iterator iterator = domain->route_infos.GetIterator();
|
RouteInfoList::Iterator iterator = domain->route_infos.GetIterator();
|
||||||
|
|
||||||
while (iterator.HasNext()) {
|
while (iterator.HasNext()) {
|
||||||
net_route_info *info = iterator.Next();
|
net_route_info *info = iterator.Next();
|
||||||
|
|
||||||
put_route_internal(domain, info->route);
|
put_route_internal(domain, info->route);
|
||||||
info->route = get_route_internal(domain, &info->address);
|
info->route = get_route_internal(domain, &info->address);
|
||||||
}
|
}
|
||||||
@ -371,12 +392,12 @@ add_route(struct net_domain *_domain, const struct net_route *newRoute)
|
|||||||
if (route == NULL)
|
if (route == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
if (domain->address_module->copy_address(newRoute->destination,
|
if (domain->address_module->copy_address(newRoute->destination,
|
||||||
&route->destination, (newRoute->flags & RTF_DEFAULT) != 0,
|
&route->destination, (newRoute->flags & RTF_DEFAULT) != 0,
|
||||||
newRoute->mask) != B_OK
|
newRoute->mask) != B_OK
|
||||||
|| domain->address_module->copy_address(newRoute->mask, &route->mask,
|
|| domain->address_module->copy_address(newRoute->mask, &route->mask,
|
||||||
(newRoute->flags & RTF_DEFAULT) != 0, NULL) != B_OK
|
(newRoute->flags & RTF_DEFAULT) != 0, NULL) != B_OK
|
||||||
|| domain->address_module->copy_address(newRoute->gateway,
|
|| domain->address_module->copy_address(newRoute->gateway,
|
||||||
&route->gateway, false, NULL) != B_OK) {
|
&route->gateway, false, NULL) != B_OK) {
|
||||||
delete route;
|
delete route;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@ -396,10 +417,10 @@ add_route(struct net_domain *_domain, const struct net_route *newRoute)
|
|||||||
net_route_private *before = NULL;
|
net_route_private *before = NULL;
|
||||||
|
|
||||||
while ((before = iterator.Next()) != NULL) {
|
while ((before = iterator.Next()) != NULL) {
|
||||||
// if the before mask is less specific than the one of the route,
|
// if the before mask is less specific than the one of the route,
|
||||||
// we can insert it before that route.
|
// we can insert it before that route.
|
||||||
if (domain->address_module->first_mask_bit(before->mask)
|
if (domain->address_module->first_mask_bit(before->mask)
|
||||||
> domain->address_module->first_mask_bit(route->mask))
|
> domain->address_module->first_mask_bit(route->mask))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,6 +452,7 @@ remove_route(struct net_domain *_domain, const struct net_route *removeRoute)
|
|||||||
|
|
||||||
put_route_internal(domain, route);
|
put_route_internal(domain, route);
|
||||||
update_route_infos(domain);
|
update_route_infos(domain);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user