use module_dependencies to load the required modules by udp, tcp, ipv4, icmp and arp.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20676 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -30,12 +30,13 @@ public:
|
||||
};
|
||||
|
||||
|
||||
extern net_buffer_module_info *gBufferModule;
|
||||
extern net_stack_module_info *gStackModule;
|
||||
|
||||
class NetModuleBundleGetter {
|
||||
public:
|
||||
static net_stack_module_info *Stack() { return gStackModule; }
|
||||
static net_buffer_module_info *Buffer() { return gStackModule->buffer_module; }
|
||||
static net_buffer_module_info *Buffer() { return gBufferModule; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -55,10 +55,6 @@ 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,
|
||||
|
||||
@@ -98,7 +98,7 @@ struct arp_protocol : net_datalink_protocol {
|
||||
|
||||
static void arp_timer(struct net_timer *timer, void *data);
|
||||
|
||||
struct net_buffer_module_info *gBufferModule;
|
||||
net_buffer_module_info *gBufferModule;
|
||||
static net_stack_module_info *sStackModule;
|
||||
static hash_table *sCache;
|
||||
static benaphore sCacheLock;
|
||||
@@ -725,31 +725,19 @@ arp_control(const char *subsystem, uint32 function,
|
||||
static status_t
|
||||
arp_init()
|
||||
{
|
||||
status_t status = get_module(NET_STACK_MODULE_NAME, (module_info **)&sStackModule);
|
||||
status_t status = benaphore_init(&sCacheLock, "arp cache");
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
gBufferModule = sStackModule->buffer_module;
|
||||
|
||||
status = benaphore_init(&sCacheLock, "arp cache");
|
||||
if (status < B_OK)
|
||||
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 err2;
|
||||
benaphore_destroy(&sCacheLock);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
register_generic_syscall(ARP_SYSCALLS, arp_control, 1, 0);
|
||||
return B_OK;
|
||||
|
||||
err2:
|
||||
benaphore_destroy(&sCacheLock);
|
||||
err1:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -757,8 +745,6 @@ static status_t
|
||||
arp_uninit()
|
||||
{
|
||||
unregister_generic_syscall(ARP_SYSCALLS, 1);
|
||||
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -966,6 +952,13 @@ static net_datalink_protocol_module_info sARPModule = {
|
||||
arp_control,
|
||||
};
|
||||
|
||||
|
||||
module_dependency module_dependencies[] = {
|
||||
{NET_STACK_MODULE_NAME, (module_info **)&sStackModule},
|
||||
{NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule},
|
||||
{}
|
||||
};
|
||||
|
||||
module_info *modules[] = {
|
||||
(module_info *)&sARPModule,
|
||||
NULL
|
||||
|
||||
@@ -62,8 +62,8 @@ struct icmp_protocol : net_protocol {
|
||||
};
|
||||
|
||||
|
||||
net_buffer_module_info *gBufferModule;
|
||||
static net_stack_module_info *sStackModule;
|
||||
struct net_buffer_module_info *gBufferModule;
|
||||
|
||||
|
||||
net_protocol *
|
||||
@@ -297,12 +297,6 @@ icmp_std_ops(int32 op, ...)
|
||||
switch (op) {
|
||||
case B_MODULE_INIT:
|
||||
{
|
||||
status_t status = get_module(NET_STACK_MODULE_NAME, (module_info **)&sStackModule);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
gBufferModule = sStackModule->buffer_module;
|
||||
|
||||
sStackModule->register_domain_protocols(AF_INET, SOCK_DGRAM, IPPROTO_ICMP,
|
||||
"network/protocols/icmp/v1",
|
||||
"network/protocols/ipv4/v1",
|
||||
@@ -314,7 +308,6 @@ icmp_std_ops(int32 op, ...)
|
||||
}
|
||||
|
||||
case B_MODULE_UNINIT:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
|
||||
default:
|
||||
@@ -353,6 +346,12 @@ net_protocol_module_info sICMPModule = {
|
||||
icmp_error_reply,
|
||||
};
|
||||
|
||||
module_dependency module_dependencies[] = {
|
||||
{NET_STACK_MODULE_NAME, (module_info **)&sStackModule},
|
||||
{NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule},
|
||||
{}
|
||||
};
|
||||
|
||||
module_info *modules[] = {
|
||||
(module_info *)&sICMPModule,
|
||||
NULL
|
||||
|
||||
@@ -1115,31 +1115,24 @@ ipv4_error_reply(net_protocol *protocol, net_buffer *causedError, uint32 code,
|
||||
status_t
|
||||
init_ipv4()
|
||||
{
|
||||
status_t status = get_module(NET_STACK_MODULE_NAME, (module_info **)&gStackModule);
|
||||
sPacketID = (int32)system_time();
|
||||
|
||||
status_t status = benaphore_init(&sRawSocketsLock, "raw sockets");
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
gBufferModule = gStackModule->buffer_module;
|
||||
sDatalinkModule = gStackModule->datalink_module;
|
||||
|
||||
sPacketID = (int32)system_time();
|
||||
|
||||
status = benaphore_init(&sRawSocketsLock, "raw sockets");
|
||||
status = benaphore_init(&sFragmentLock, "IPv4 Fragments");
|
||||
if (status < B_OK)
|
||||
goto err1;
|
||||
|
||||
status = benaphore_init(&sFragmentLock, "IPv4 Fragments");
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
|
||||
status = benaphore_init(&sReceivingProtocolLock, "IPv4 receiving protocols");
|
||||
if (status < B_OK)
|
||||
goto err3;
|
||||
goto err2;
|
||||
|
||||
sFragmentHash = hash_init(MAX_HASH_FRAGMENTS, FragmentPacket::NextOffset(),
|
||||
&FragmentPacket::Compare, &FragmentPacket::Hash);
|
||||
if (sFragmentHash == NULL)
|
||||
goto err4;
|
||||
goto err3;
|
||||
|
||||
new (&sRawSockets) RawSocketList;
|
||||
// static initializers do not work in the kernel,
|
||||
@@ -1149,25 +1142,23 @@ init_ipv4()
|
||||
status = gStackModule->register_domain_protocols(AF_INET, SOCK_RAW, 0,
|
||||
"network/protocols/ipv4/v1", NULL);
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
goto err4;
|
||||
|
||||
status = gStackModule->register_domain(AF_INET, "internet", &gIPv4Module,
|
||||
&gIPv4AddressModule, &sDomain);
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
goto err4;
|
||||
|
||||
return B_OK;
|
||||
|
||||
err5:
|
||||
hash_uninit(sFragmentHash);
|
||||
err4:
|
||||
benaphore_destroy(&sReceivingProtocolLock);
|
||||
hash_uninit(sFragmentHash);
|
||||
err3:
|
||||
benaphore_destroy(&sFragmentLock);
|
||||
benaphore_destroy(&sReceivingProtocolLock);
|
||||
err2:
|
||||
benaphore_destroy(&sRawSocketsLock);
|
||||
benaphore_destroy(&sFragmentLock);
|
||||
err1:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
benaphore_destroy(&sRawSocketsLock);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1242,6 +1233,13 @@ net_protocol_module_info gIPv4Module = {
|
||||
ipv4_error_reply,
|
||||
};
|
||||
|
||||
module_dependency module_dependencies[] = {
|
||||
{NET_STACK_MODULE_NAME, (module_info **)&gStackModule},
|
||||
{NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule},
|
||||
{NET_DATALINK_MODULE_NAME, (module_info **)&sDatalinkModule},
|
||||
{}
|
||||
};
|
||||
|
||||
module_info *modules[] = {
|
||||
(module_info *)&gIPv4Module,
|
||||
NULL
|
||||
|
||||
@@ -631,48 +631,37 @@ tcp_init()
|
||||
gDomain = NULL;
|
||||
gAddressModule = NULL;
|
||||
|
||||
status = get_module(NET_STACK_MODULE_NAME, (module_info **)&gStackModule);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
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 err1;
|
||||
}
|
||||
if (gEndpointManager == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
status = gEndpointManager->InitCheck();
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
goto err1;
|
||||
|
||||
status = gStackModule->register_domain_protocols(AF_INET, SOCK_STREAM, 0,
|
||||
"network/protocols/tcp/v1",
|
||||
"network/protocols/ipv4/v1",
|
||||
NULL);
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
goto err1;
|
||||
|
||||
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 err2;
|
||||
goto err1;
|
||||
|
||||
status = gStackModule->register_domain_receiving_protocol(AF_INET, IPPROTO_TCP,
|
||||
"network/protocols/tcp/v1");
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
goto err1;
|
||||
|
||||
return B_OK;
|
||||
|
||||
err2:
|
||||
delete gEndpointManager;
|
||||
err1:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
delete gEndpointManager;
|
||||
|
||||
TRACE(("init_tcp() fails with %lx (%s)\n", status, strerror(status)));
|
||||
return status;
|
||||
@@ -683,7 +672,6 @@ static status_t
|
||||
tcp_uninit()
|
||||
{
|
||||
delete gEndpointManager;
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -734,6 +722,14 @@ net_protocol_module_info sTCPModule = {
|
||||
tcp_error_reply,
|
||||
};
|
||||
|
||||
module_dependency module_dependencies[] = {
|
||||
{NET_STACK_MODULE_NAME, (module_info **)&gStackModule},
|
||||
{NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule},
|
||||
{NET_DATALINK_MODULE_NAME, (module_info **)&gDatalinkModule},
|
||||
{NET_SOCKET_MODULE_NAME, (module_info **)&gSocketModule},
|
||||
{}
|
||||
};
|
||||
|
||||
module_info *modules[] = {
|
||||
(module_info *)&sTCPModule,
|
||||
NULL
|
||||
|
||||
@@ -199,8 +199,9 @@ private:
|
||||
|
||||
static UdpEndpointManager *sUdpEndpointManager;
|
||||
|
||||
net_stack_module_info *gStackModule;
|
||||
net_buffer_module_info *gBufferModule;
|
||||
net_datalink_module_info *gDatalinkModule;
|
||||
net_stack_module_info *gStackModule;
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
@@ -894,11 +895,11 @@ UdpEndpoint::SendData(net_buffer *buffer)
|
||||
TRACE_EP("SendData(%p [%lu bytes])", buffer, buffer->size);
|
||||
|
||||
net_route *route = NULL;
|
||||
status_t status = gStackModule->datalink_module->get_buffer_route(Domain(),
|
||||
status_t status = gDatalinkModule->get_buffer_route(Domain(),
|
||||
buffer, &route);
|
||||
if (status >= B_OK) {
|
||||
status = SendRoutedData(buffer, route);
|
||||
gStackModule->datalink_module->put_route(Domain(), route);
|
||||
gDatalinkModule->put_route(Domain(), route);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -1121,16 +1122,10 @@ init_udp()
|
||||
status_t status;
|
||||
TRACE_EPM("init_udp()");
|
||||
|
||||
status = get_module(NET_STACK_MODULE_NAME, (module_info **)&gStackModule);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
gBufferModule = gStackModule->buffer_module;
|
||||
|
||||
sUdpEndpointManager = new (std::nothrow) UdpEndpointManager;
|
||||
if (sUdpEndpointManager == NULL) {
|
||||
status = ENOBUFS;
|
||||
goto err1;
|
||||
}
|
||||
if (sUdpEndpointManager == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
status = sUdpEndpointManager->InitCheck();
|
||||
if (status != B_OK)
|
||||
goto err1;
|
||||
@@ -1140,25 +1135,23 @@ init_udp()
|
||||
"network/protocols/ipv4/v1",
|
||||
NULL);
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
goto err1;
|
||||
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 err2;
|
||||
goto err1;
|
||||
|
||||
status = gStackModule->register_domain_receiving_protocol(AF_INET, IPPROTO_UDP,
|
||||
"network/protocols/udp/v1");
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
goto err1;
|
||||
|
||||
return B_OK;
|
||||
|
||||
err2:
|
||||
delete sUdpEndpointManager;
|
||||
err1:
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
delete sUdpEndpointManager;
|
||||
|
||||
TRACE_EPM("init_udp() fails with %lx (%s)", status, strerror(status));
|
||||
return status;
|
||||
@@ -1170,7 +1163,6 @@ uninit_udp()
|
||||
{
|
||||
TRACE_EPM("uninit_udp()");
|
||||
delete sUdpEndpointManager;
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -1221,6 +1213,13 @@ net_protocol_module_info sUDPModule = {
|
||||
udp_error_reply,
|
||||
};
|
||||
|
||||
module_dependency module_dependencies[] = {
|
||||
{NET_STACK_MODULE_NAME, (module_info **)&gStackModule},
|
||||
{NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule},
|
||||
{NET_DATALINK_MODULE_NAME, (module_info **)&gDatalinkModule},
|
||||
{}
|
||||
};
|
||||
|
||||
module_info *modules[] = {
|
||||
(module_info *)&sUDPModule,
|
||||
NULL
|
||||
|
||||
@@ -895,10 +895,6 @@ net_stack_module_info gNetStackModule = {
|
||||
stack_std_ops
|
||||
},
|
||||
|
||||
&gNetBufferModule,
|
||||
&gNetDatalinkModule,
|
||||
&gNetSocketModule,
|
||||
|
||||
register_domain,
|
||||
unregister_domain,
|
||||
get_domain,
|
||||
|
||||
Reference in New Issue
Block a user