void CommandData::execute(const StringVector &args) { MasterIndexList masterIndices; DomainList domains; DomainList::const_iterator di; if (args.size()) { stringstream err; err << "'" << getName() << "' takes no arguments!"; throwInvalidUsageException(err); } masterIndices = getMasterIndices(); MasterIndexList::const_iterator mi; for (mi = masterIndices.begin(); mi != masterIndices.end(); mi++) { ec_ioctl_master_t io; MasterDevice m(*mi); m.open(MasterDevice::Read); m.getMaster(&io); domains = selectedDomains(m, io); for (di = domains.begin(); di != domains.end(); di++) { outputDomainData(m, *di); } } }
static int dump_domains(int argc, char** argv) { DomainList::Iterator iterator = sDomains.GetIterator(); while (net_domain_private* domain = iterator.Next()) { kprintf("domain: %p, %s, %d\n", domain, domain->name, domain->family); kprintf(" module: %p\n", domain->module); kprintf(" address_module: %p\n", domain->address_module); if (!domain->routes.IsEmpty()) kprintf(" routes:\n"); RouteList::Iterator routeIterator = domain->routes.GetIterator(); while (net_route_private* route = routeIterator.Next()) { kprintf(" %p: dest %s, mask %s, gw %s, flags %" B_PRIx32 ", " "address %p\n", route, 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, route->interface_address); } if (!domain->route_infos.IsEmpty()) kprintf(" route infos:\n"); RouteInfoList::Iterator infoIterator = domain->route_infos.GetIterator(); while (net_route_info* info = infoIterator.Next()) { kprintf(" %p\n", info); } } return 0; }
status_t register_domain(int family, const char* name, struct net_protocol_module_info* module, struct net_address_module_info* addressModule, net_domain** _domain) { TRACE(("register_domain(%d, %s)\n", family, name)); MutexLocker locker(sDomainLock); struct net_domain_private* domain = lookup_domain(family); if (domain != NULL) return B_NAME_IN_USE; domain = new(std::nothrow) net_domain_private; if (domain == NULL) return B_NO_MEMORY; recursive_lock_init(&domain->lock, name); domain->family = family; domain->name = name; domain->module = module; domain->address_module = addressModule; sDomains.Add(domain); *_domain = domain; return B_OK; }
status_t unregister_domain(net_domain* _domain) { TRACE(("unregister_domain(%p, %d, %s)\n", _domain, _domain->family, _domain->name)); net_domain_private* domain = (net_domain_private*)_domain; MutexLocker locker(sDomainLock); sDomains.Remove(domain); net_interface_private* interface = NULL; while (true) { interface = (net_interface_private*)list_remove_head_item( &domain->interfaces); if (interface == NULL) break; delete_interface(interface); } recursive_lock_destroy(&domain->lock); delete domain; return B_OK; }
Command::DomainList Command::selectedDomains(MasterDevice &m, const ec_ioctl_master_t &io) { DomainList list; PositionParser pp(io.domain_count); NumberListParser::List domList = pp.parse(domains.c_str()); NumberListParser::List::const_iterator di; for (di = domList.begin(); di != domList.end(); di++) { if (*di < io.domain_count) { ec_ioctl_domain_t d; m.getDomain(&d, *di); list.push_back(d); } } return list; }
/*! Scans the domain list for the specified family. You need to hold the sDomainLock when calling this function. */ static net_domain_private* lookup_domain(int family) { DomainList::Iterator iterator = sDomains.GetIterator(); while (net_domain_private* domain = iterator.Next()) { if (domain->family == family) return domain; } return NULL; }
status_t unregister_domain(net_domain* _domain) { TRACE(("unregister_domain(%p, %d, %s)\n", _domain, _domain->family, _domain->name)); net_domain_private* domain = (net_domain_private*)_domain; MutexLocker locker(sDomainLock); sDomains.Remove(domain); recursive_lock_destroy(&domain->lock); delete domain; return B_OK; }
void domain_removed_device_interface(net_device_interface* deviceInterface) { MutexLocker locker(sDomainLock); DomainList::Iterator iterator = sDomains.GetIterator(); while (net_domain_private* domain = iterator.Next()) { RecursiveLocker locker(domain->lock); net_interface_private* interface = find_interface(domain, deviceInterface->device->name); if (interface == NULL) continue; remove_interface_from_domain(interface); } }
static int dump_domains(int argc, char** argv) { DomainList::Iterator iterator = sDomains.GetIterator(); while (net_domain_private* domain = iterator.Next()) { kprintf("domain: %p, %s, %d\n", domain, domain->name, domain->family); kprintf(" module: %p\n", domain->module); kprintf(" address_module: %p\n", domain->address_module); if (!list_is_empty(&domain->interfaces)) kprintf(" interfaces:\n"); net_interface* interface = NULL; while (true) { interface = (net_interface*)list_get_next_item(&domain->interfaces, interface); if (interface == NULL) break; kprintf(" %p\n", interface); } if (!domain->routes.IsEmpty()) kprintf(" routes:\n"); RouteList::Iterator routeIterator = domain->routes.GetIterator(); while (net_route* route = routeIterator.Next()) { kprintf(" %p\n", route); } if (!domain->route_infos.IsEmpty()) kprintf(" route infos:\n"); RouteInfoList::Iterator infoIterator = domain->route_infos.GetIterator(); while (net_route_info* info = infoIterator.Next()) { kprintf(" %p\n", info); } } return 0; }
uint32 count_domain_interfaces() { MutexLocker locker(sDomainLock); uint32 count = 0; DomainList::Iterator iterator = sDomains.GetIterator(); while (net_domain_private* domain = iterator.Next()) { net_interface* interface = NULL; while (true) { interface = (net_interface*)list_get_next_item(&domain->interfaces, interface); if (interface == NULL) break; count++; } } return count; }
/*! Dumps a list of all interfaces into the supplied userland buffer. If the interfaces don't fit into the buffer, an error (\c ENOBUFS) is returned. */ status_t list_domain_interfaces(void* _buffer, size_t* bufferSize) { MutexLocker locker(sDomainLock); UserBuffer buffer(_buffer, *bufferSize); DomainList::Iterator iterator = sDomains.GetIterator(); while (net_domain_private* domain = iterator.Next()) { RecursiveLocker locker(domain->lock); net_interface* interface = NULL; while (true) { interface = (net_interface*)list_get_next_item(&domain->interfaces, interface); if (interface == NULL) break; ifreq request; strlcpy(request.ifr_name, interface->name, IF_NAMESIZE); if (interface->address != NULL) { memcpy(&request.ifr_addr, interface->address, interface->address->sa_len); } else { // empty address request.ifr_addr.sa_len = 2; request.ifr_addr.sa_family = AF_UNSPEC; } if (buffer.Copy(&request, IF_NAMESIZE + request.ifr_addr.sa_len) == NULL) return buffer.Status(); } } *bufferSize = buffer.ConsumedAmount(); return B_OK; }