added buffer, datalink and socket module references to the stack module so we don't have to load them in each other module.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20673 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,17 +31,16 @@ public:
|
||||
|
||||
|
||||
extern net_stack_module_info *gStackModule;
|
||||
extern net_buffer_module_info *gBufferModule;
|
||||
|
||||
class NetModuleBundle {
|
||||
class NetModuleBundleGetter {
|
||||
public:
|
||||
static net_stack_module_info *Stack() { return gStackModule; }
|
||||
static net_buffer_module_info *Buffer() { return gBufferModule; }
|
||||
static net_buffer_module_info *Buffer() { return gStackModule->buffer_module; }
|
||||
};
|
||||
|
||||
|
||||
template<typename LockingBase = BenaphoreLocking,
|
||||
typename ModuleBundle = NetModuleBundle>
|
||||
typename ModuleBundle = NetModuleBundleGetter>
|
||||
class DatagramSocket {
|
||||
public:
|
||||
DatagramSocket(const char *name, net_socket *socket);
|
||||
@@ -78,7 +77,6 @@ protected:
|
||||
typedef DoublyLinkedListCLink<net_buffer> NetBufferLink;
|
||||
typedef DoublyLinkedList<net_buffer, NetBufferLink> BufferList;
|
||||
|
||||
status_t fStatus;
|
||||
net_socket *fSocket;
|
||||
sem_id fNotify;
|
||||
BufferList fBuffers;
|
||||
@@ -96,8 +94,10 @@ DECL_DATAGRAM_SOCKET(inline)::DatagramSocket(const char *name,
|
||||
net_socket *socket)
|
||||
: fSocket(socket), fCurrentBytes(0)
|
||||
{
|
||||
fStatus = LockingBase::Init(&fLock, name);
|
||||
if (fStatus >= B_OK)
|
||||
status_t status = LockingBase::Init(&fLock, name);
|
||||
if (status < B_OK)
|
||||
fNotify = status;
|
||||
else
|
||||
fNotify = create_sem(0, name);
|
||||
}
|
||||
|
||||
@@ -105,18 +105,13 @@ DECL_DATAGRAM_SOCKET(inline)::DatagramSocket(const char *name,
|
||||
DECL_DATAGRAM_SOCKET(inline)::~DatagramSocket()
|
||||
{
|
||||
_Clear();
|
||||
|
||||
if (fStatus >= B_OK) {
|
||||
delete_sem(fNotify);
|
||||
LockingBase::Destroy(&fLock);
|
||||
}
|
||||
delete_sem(fNotify);
|
||||
LockingBase::Destroy(&fLock);
|
||||
}
|
||||
|
||||
|
||||
DECL_DATAGRAM_SOCKET(inline status_t)::InitCheck() const
|
||||
{
|
||||
if (fStatus < 0)
|
||||
return fStatus;
|
||||
return fNotify;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,10 @@ struct net_device_monitor {
|
||||
struct net_stack_module_info {
|
||||
module_info info;
|
||||
|
||||
struct net_buffer_module_info *buffer_module;
|
||||
struct net_datalink_module_info *datalink_module;
|
||||
struct net_socket_module_info *socket_module;
|
||||
|
||||
status_t (*register_domain)(int family, const char *name,
|
||||
struct net_protocol_module_info *module,
|
||||
struct net_address_module_info *addressModule,
|
||||
|
||||
@@ -728,28 +728,25 @@ arp_init()
|
||||
status_t status = get_module(NET_STACK_MODULE_NAME, (module_info **)&sStackModule);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
status = get_module(NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule);
|
||||
if (status < B_OK)
|
||||
goto err1;
|
||||
|
||||
gBufferModule = sStackModule->buffer_module;
|
||||
|
||||
status = benaphore_init(&sCacheLock, "arp cache");
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
goto err1;
|
||||
|
||||
sCache = hash_init(64, offsetof(struct arp_entry, next),
|
||||
&arp_entry::Compare, &arp_entry::Hash);
|
||||
if (sCache == NULL) {
|
||||
status = B_NO_MEMORY;
|
||||
goto err3;
|
||||
goto err2;
|
||||
}
|
||||
|
||||
register_generic_syscall(ARP_SYSCALLS, arp_control, 1, 0);
|
||||
return B_OK;
|
||||
|
||||
err3:
|
||||
benaphore_destroy(&sCacheLock);
|
||||
err2:
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
benaphore_destroy(&sCacheLock);
|
||||
err1:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return status;
|
||||
@@ -761,7 +758,6 @@ arp_uninit()
|
||||
{
|
||||
unregister_generic_syscall(ARP_SYSCALLS, 1);
|
||||
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -300,11 +300,8 @@ icmp_std_ops(int32 op, ...)
|
||||
status_t status = get_module(NET_STACK_MODULE_NAME, (module_info **)&sStackModule);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
status = get_module(NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule);
|
||||
if (status < B_OK) {
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return status;
|
||||
}
|
||||
|
||||
gBufferModule = sStackModule->buffer_module;
|
||||
|
||||
sStackModule->register_domain_protocols(AF_INET, SOCK_DGRAM, IPPROTO_ICMP,
|
||||
"network/protocols/icmp/v1",
|
||||
@@ -317,7 +314,6 @@ icmp_std_ops(int32 op, ...)
|
||||
}
|
||||
|
||||
case B_MODULE_UNINIT:
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
|
||||
|
||||
@@ -1117,31 +1117,28 @@ init_ipv4()
|
||||
status_t status = get_module(NET_STACK_MODULE_NAME, (module_info **)&gStackModule);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
status = get_module(NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule);
|
||||
if (status < B_OK)
|
||||
goto err1;
|
||||
status = get_module(NET_DATALINK_MODULE_NAME, (module_info **)&sDatalinkModule);
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
|
||||
gBufferModule = gStackModule->buffer_module;
|
||||
sDatalinkModule = gStackModule->datalink_module;
|
||||
|
||||
sPacketID = (int32)system_time();
|
||||
|
||||
status = benaphore_init(&sRawSocketsLock, "raw sockets");
|
||||
if (status < B_OK)
|
||||
goto err3;
|
||||
goto err1;
|
||||
|
||||
status = benaphore_init(&sFragmentLock, "IPv4 Fragments");
|
||||
if (status < B_OK)
|
||||
goto err4;
|
||||
goto err2;
|
||||
|
||||
status = benaphore_init(&sReceivingProtocolLock, "IPv4 receiving protocols");
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
goto err3;
|
||||
|
||||
sFragmentHash = hash_init(MAX_HASH_FRAGMENTS, FragmentPacket::NextOffset(),
|
||||
&FragmentPacket::Compare, &FragmentPacket::Hash);
|
||||
if (sFragmentHash == NULL)
|
||||
goto err6;
|
||||
goto err4;
|
||||
|
||||
new (&sRawSockets) RawSocketList;
|
||||
// static initializers do not work in the kernel,
|
||||
@@ -1151,27 +1148,23 @@ init_ipv4()
|
||||
status = gStackModule->register_domain_protocols(AF_INET, SOCK_RAW, 0,
|
||||
"network/protocols/ipv4/v1", NULL);
|
||||
if (status < B_OK)
|
||||
goto err7;
|
||||
goto err5;
|
||||
|
||||
status = gStackModule->register_domain(AF_INET, "internet", &gIPv4Module,
|
||||
&gIPv4AddressModule, &sDomain);
|
||||
if (status < B_OK)
|
||||
goto err7;
|
||||
goto err5;
|
||||
|
||||
return B_OK;
|
||||
|
||||
err7:
|
||||
hash_uninit(sFragmentHash);
|
||||
err6:
|
||||
benaphore_destroy(&sReceivingProtocolLock);
|
||||
err5:
|
||||
benaphore_destroy(&sFragmentLock);
|
||||
hash_uninit(sFragmentHash);
|
||||
err4:
|
||||
benaphore_destroy(&sRawSocketsLock);
|
||||
benaphore_destroy(&sReceivingProtocolLock);
|
||||
err3:
|
||||
put_module(NET_DATALINK_MODULE_NAME);
|
||||
benaphore_destroy(&sFragmentLock);
|
||||
err2:
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
benaphore_destroy(&sRawSocketsLock);
|
||||
err1:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return status;
|
||||
@@ -1198,8 +1191,6 @@ uninit_ipv4()
|
||||
benaphore_destroy(&sRawSocketsLock);
|
||||
benaphore_destroy(&sReceivingProtocolLock);
|
||||
|
||||
put_module(NET_DATALINK_MODULE_NAME);
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -634,54 +634,43 @@ tcp_init()
|
||||
status = get_module(NET_STACK_MODULE_NAME, (module_info **)&gStackModule);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
status = get_module(NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule);
|
||||
if (status < B_OK)
|
||||
goto err1;
|
||||
status = get_module(NET_SOCKET_MODULE_NAME, (module_info **)&gSocketModule);
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
status = get_module(NET_DATALINK_MODULE_NAME, (module_info **)&gDatalinkModule);
|
||||
if (status < B_OK)
|
||||
goto err3;
|
||||
|
||||
gBufferModule = gStackModule->buffer_module;
|
||||
gSocketModule = gStackModule->socket_module;
|
||||
gDatalinkModule = gStackModule->datalink_module;
|
||||
|
||||
gEndpointManager = new (std::nothrow) EndpointManager();
|
||||
if (gEndpointManager == NULL) {
|
||||
status = B_NO_MEMORY;
|
||||
goto err4;
|
||||
goto err1;
|
||||
}
|
||||
status = gEndpointManager->InitCheck();
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
goto err2;
|
||||
|
||||
status = gStackModule->register_domain_protocols(AF_INET, SOCK_STREAM, 0,
|
||||
"network/protocols/tcp/v1",
|
||||
"network/protocols/ipv4/v1",
|
||||
NULL);
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
goto err2;
|
||||
|
||||
status = gStackModule->register_domain_protocols(AF_INET, SOCK_STREAM, IPPROTO_TCP,
|
||||
"network/protocols/tcp/v1",
|
||||
"network/protocols/ipv4/v1",
|
||||
NULL);
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
goto err2;
|
||||
|
||||
status = gStackModule->register_domain_receiving_protocol(AF_INET, IPPROTO_TCP,
|
||||
"network/protocols/tcp/v1");
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
goto err2;
|
||||
|
||||
return B_OK;
|
||||
|
||||
err5:
|
||||
delete gEndpointManager;
|
||||
err4:
|
||||
put_module(NET_DATALINK_MODULE_NAME);
|
||||
err3:
|
||||
put_module(NET_SOCKET_MODULE_NAME);
|
||||
err2:
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
delete gEndpointManager;
|
||||
err1:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
|
||||
@@ -694,12 +683,7 @@ static status_t
|
||||
tcp_uninit()
|
||||
{
|
||||
delete gEndpointManager;
|
||||
|
||||
put_module(NET_DATALINK_MODULE_NAME);
|
||||
put_module(NET_SOCKET_MODULE_NAME);
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -178,8 +178,6 @@ public:
|
||||
UdpEndpointManager();
|
||||
~UdpEndpointManager();
|
||||
|
||||
status_t DemuxIncomingBuffer(net_domain *domain,
|
||||
net_buffer *buffer);
|
||||
status_t ReceiveData(net_buffer *buffer);
|
||||
|
||||
UdpDomainSupport *OpenEndpoint(UdpEndpoint *endpoint);
|
||||
@@ -203,7 +201,6 @@ static UdpEndpointManager *sUdpEndpointManager;
|
||||
|
||||
net_stack_module_info *gStackModule;
|
||||
net_buffer_module_info *gBufferModule;
|
||||
static net_datalink_module_info *sDatalinkModule;
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
@@ -543,21 +540,6 @@ UdpEndpointManager::InitCheck() const
|
||||
// #pragma mark - inbound
|
||||
|
||||
|
||||
status_t
|
||||
UdpEndpointManager::DemuxIncomingBuffer(net_domain *domain, net_buffer *buffer)
|
||||
{
|
||||
UdpDomainSupport *domainSupport = _GetDomain(domain, false);
|
||||
if (domainSupport == NULL) {
|
||||
// we don't instantiate domain supports in the
|
||||
// RX path as we are only interested in delivering
|
||||
// data to existing sockets.
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
return domainSupport->DemuxIncomingBuffer(buffer);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
UdpEndpointManager::ReceiveData(net_buffer *buffer)
|
||||
{
|
||||
@@ -621,7 +603,15 @@ UdpEndpointManager::ReceiveData(net_buffer *buffer)
|
||||
bufferHeader.Remove();
|
||||
// remove UDP-header from buffer before passing it on
|
||||
|
||||
status_t status = DemuxIncomingBuffer(domain, buffer);
|
||||
UdpDomainSupport *domainSupport = _GetDomain(domain, false);
|
||||
if (domainSupport == NULL) {
|
||||
// we don't instantiate domain supports in the
|
||||
// RX path as we are only interested in delivering
|
||||
// data to existing sockets.
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t status = domainSupport->DemuxIncomingBuffer(buffer);
|
||||
if (status < B_OK) {
|
||||
TRACE_EPM(" ReceiveData(): no endpoint.");
|
||||
// TODO: send ICMP-error
|
||||
@@ -904,11 +894,11 @@ UdpEndpoint::SendData(net_buffer *buffer)
|
||||
TRACE_EP("SendData(%p [%lu bytes])", buffer, buffer->size);
|
||||
|
||||
net_route *route = NULL;
|
||||
status_t status = sDatalinkModule->get_buffer_route(Domain(), buffer,
|
||||
&route);
|
||||
status_t status = gStackModule->datalink_module->get_buffer_route(Domain(),
|
||||
buffer, &route);
|
||||
if (status >= B_OK) {
|
||||
status = SendRoutedData(buffer, route);
|
||||
sDatalinkModule->put_route(Domain(), route);
|
||||
gStackModule->datalink_module->put_route(Domain(), route);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -1134,48 +1124,39 @@ init_udp()
|
||||
status = get_module(NET_STACK_MODULE_NAME, (module_info **)&gStackModule);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
status = get_module(NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule);
|
||||
if (status < B_OK)
|
||||
goto err1;
|
||||
status = get_module(NET_DATALINK_MODULE_NAME, (module_info **)&sDatalinkModule);
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
gBufferModule = gStackModule->buffer_module;
|
||||
|
||||
sUdpEndpointManager = new (std::nothrow) UdpEndpointManager;
|
||||
if (sUdpEndpointManager == NULL) {
|
||||
status = ENOBUFS;
|
||||
goto err3;
|
||||
goto err1;
|
||||
}
|
||||
status = sUdpEndpointManager->InitCheck();
|
||||
if (status != B_OK)
|
||||
goto err3;
|
||||
goto err1;
|
||||
|
||||
status = gStackModule->register_domain_protocols(AF_INET, SOCK_DGRAM, IPPROTO_IP,
|
||||
"network/protocols/udp/v1",
|
||||
"network/protocols/ipv4/v1",
|
||||
NULL);
|
||||
if (status < B_OK)
|
||||
goto err4;
|
||||
goto err2;
|
||||
status = gStackModule->register_domain_protocols(AF_INET, SOCK_DGRAM, IPPROTO_UDP,
|
||||
"network/protocols/udp/v1",
|
||||
"network/protocols/ipv4/v1",
|
||||
NULL);
|
||||
if (status < B_OK)
|
||||
goto err4;
|
||||
goto err2;
|
||||
|
||||
status = gStackModule->register_domain_receiving_protocol(AF_INET, IPPROTO_UDP,
|
||||
"network/protocols/udp/v1");
|
||||
if (status < B_OK)
|
||||
goto err4;
|
||||
goto err2;
|
||||
|
||||
return B_OK;
|
||||
|
||||
err4:
|
||||
delete sUdpEndpointManager;
|
||||
err3:
|
||||
put_module(NET_DATALINK_MODULE_NAME);
|
||||
err2:
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
delete sUdpEndpointManager;
|
||||
err1:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
|
||||
@@ -1189,8 +1170,6 @@ uninit_udp()
|
||||
{
|
||||
TRACE_EPM("uninit_udp()");
|
||||
delete sUdpEndpointManager;
|
||||
put_module(NET_DATALINK_MODULE_NAME);
|
||||
put_module(NET_BUFFER_MODULE_NAME);
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -894,6 +894,11 @@ net_stack_module_info gNetStackModule = {
|
||||
0,
|
||||
stack_std_ops
|
||||
},
|
||||
|
||||
&gNetBufferModule,
|
||||
&gNetDatalinkModule,
|
||||
&gNetSocketModule,
|
||||
|
||||
register_domain,
|
||||
unregister_domain,
|
||||
get_domain,
|
||||
|
||||
Reference in New Issue
Block a user