Make net modules mostly unaware of being (soon :-)) userland buildable too.

Some cleanup, in the way...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1908 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2002-11-12 21:06:11 +00:00
parent a0a6d75d61
commit 3a26c0afcb
8 changed files with 117 additions and 295 deletions

View File

@ -12,10 +12,11 @@
#include <string.h>
#include <stdlib.h>
#ifdef _KERNEL_MODE
#include <Drivers.h>
#include <module.h>
#include <KernelExport.h>
#ifdef _KERNEL_MODE
#define spawn_thread spawn_kernel_thread
#endif
@ -25,7 +26,6 @@
#include "sys/socket.h"
#include "sys/socketvar.h"
#include "net/if.h" /* for ifnet definition */
//#include "net_server/net_server.h"
#include "protocols.h"
#include "net_module.h"
#include "net_timer.h"
@ -60,11 +60,8 @@ static int init_done = 0;
/* Forward prototypes... */
/* Private for this file */
#ifdef _KERNEL_MODE
static status_t core_std_ops(int32 op, ...);
#else
#define core_std_ops NULL
#endif
status_t std_ops(int32 op, ...);
static int start_stack(void);
static int stop_stack(void);
static void add_protosw(struct protosw *[], int layer);
@ -73,11 +70,11 @@ static struct net_module *module_list = NULL;
int net_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen);
_EXPORT struct core_module_info core_info = {
struct core_module_info core_info = {
{
CORE_MODULE_PATH,
NET_CORE_MODULE_NAME,
B_KEEP_LOADED,
core_std_ops
std_ops
},
start_stack,
@ -659,7 +656,7 @@ static void domain_init(void)
* NB these don't have any additional functions so we just use the
* system defined module_info structures
*/
#ifdef _KERNEL_MODE
static void find_protocol_modules(void)
{
void *ml = open_module_list(NETWORK_PROTOCOLS);
@ -746,7 +743,12 @@ static void find_interface_modules(void)
close_module_list(ml);
}
#else
/* TODO: userland modules support is now moved in
src/servers/net/userland_modules.cpp
These two hacks are no more needed, should be removed soon...
*/
#if 0
static void _find_interface_modules(char *dirpath)
{
@ -987,11 +989,7 @@ static int stop_stack(void)
printf("trying to unload modules\n");
nm = module_list;
do {
#ifdef _KERNEL_MODE
put_module(nm->name);
#else
unload_add_on(nm->iid);
#endif
onm = nm;
nm = nm->next;
onm->next = NULL;
@ -1014,13 +1012,16 @@ static int stop_stack(void)
return 0;
}
#ifdef _KERNEL_MODE
static status_t core_std_ops(int32 op, ...)
// #pragma mark -
_EXPORT status_t std_ops(int32 op, ...)
{
switch(op) {
case B_MODULE_INIT:
printf("core: B_MODULE_INIT\n");
load_driver_symbols("core");
break;
case B_MODULE_UNINIT:
// the stack is keeping loaded, so don't stop it
printf("core: B_MODULE_UNINIT\n");
@ -1037,6 +1038,3 @@ _EXPORT module_info *modules[] = {
NULL
};
#else
_EXPORT module_info *modules = (module_info *)&core_info;
#endif

View File

@ -26,19 +26,15 @@
#include "core_funcs.h"
#include "net_timer.h"
#define ETHERNET_MODULE_PATH "network/interfaces/ethernet"
#include <KernelExport.h>
#define spawn_thread spawn_kernel_thread
#define printf dprintf
#ifdef _KERNEL_MODE
#include <KernelExport.h>
#define spawn_thread spawn_kernel_thread
#define printf dprintf
/* forward prototypes */
int ether_dev_start(ifnet *dev);
int ether_dev_stop (ifnet *dev);
/* forward prototypes */
int ether_dev_start(ifnet *dev);
int ether_dev_stop (ifnet *dev);
#endif
static int32 std_ops(int32 op, ...);
status_t std_ops(int32 op, ...);
/* Local variables */
static struct protosw *proto[IPPROTO_MAX];
@ -903,9 +899,9 @@ static int ether_stop()
return 0;
}
_EXPORT struct kernel_net_module_info device_info = {
struct kernel_net_module_info device_info = {
{
ETHERNET_MODULE_PATH,
"network/interfaces/ethernet",
0,
std_ops
},
@ -914,20 +910,21 @@ _EXPORT struct kernel_net_module_info device_info = {
ether_stop
};
// #pragma mark -
static int32 std_ops(int32 op, ...)
_EXPORT status_t std_ops(int32 op, ...)
{
switch(op) {
case B_MODULE_INIT:
get_module(CORE_MODULE_PATH, (module_info**)&core);
get_module(NET_CORE_MODULE_NAME, (module_info**)&core);
if (!core)
return B_ERROR;
#ifdef _KERNEL_MODE
load_driver_symbols("ethernet");
#endif
return B_OK;
case B_MODULE_UNINIT:
return B_OK;
default:
return B_ERROR;
}

View File

@ -19,15 +19,10 @@
#include "net_module.h"
#include "core_funcs.h"
#ifdef _KERNEL_MODE
#include <KernelExport.h>
#define printf dprintf
#define LOOP_MODULE_PATH "network/interfaces/loopback"
#else
#define LOOP_MODULE_PATH "interfaces/loopback"
#endif
static status_t std_ops(int32 op, ...);
status_t std_ops(int32 op, ...);
static struct core_module_info *core = NULL;
@ -144,9 +139,9 @@ static int loopback_module_init(void *cpp)
return 0;
}
_EXPORT struct kernel_net_module_info device_info = {
struct kernel_net_module_info device_info = {
{
LOOP_MODULE_PATH,
"network/interfaces/loopback",
0,
std_ops
},
@ -154,11 +149,13 @@ _EXPORT struct kernel_net_module_info device_info = {
NULL,
};
static status_t std_ops(int32 op, ...)
// #pragma mark -
_EXPORT status_t std_ops(int32 op, ...)
{
switch(op) {
case B_MODULE_INIT:
get_module(CORE_MODULE_PATH, (module_info **)&core);
get_module(NET_CORE_MODULE_NAME, (module_info **)&core);
if (!core)
return B_ERROR;
return B_OK;
@ -175,5 +172,3 @@ _EXPORT module_info *modules[] = {
NULL
};

View File

@ -1,9 +1,9 @@
/* icmp.c
*/
#ifndef _KERNEL
#include <stdio.h>
#include <string.h>
#ifndef _KERNEL_MODE
#include <stdio.h>
#include <string.h>
#endif
#include "net_misc.h"
@ -25,12 +25,8 @@
#include "icmp_module.h"
#include "ipv4_module.h"
#ifdef _KERNEL_MODE
#include <KernelExport.h>
static status_t icmp_ops(int32 op, ...);
#else
#define icmp_ops NULL
#endif
status_t std_ops(int32 op, ...);
/* private variables */
static struct core_module_info *core = NULL;
@ -38,9 +34,6 @@ static struct raw_module_info *raw = NULL;
static struct protosw* proto[IPPROTO_MAX];
static struct in_ifaddr *ic_ifaddr = NULL;
static struct ipv4_module_info *ipm = NULL;
#ifndef _KERNEL_MODE
static image_id ipid = -1;
#endif
struct icmpstat icmpstat;
@ -382,16 +375,14 @@ static void icmp_init(void)
memset(proto, 0, sizeof(struct protosw *) * IPPROTO_MAX);
add_protosw(proto, NET_LAYER2);
#ifdef _KERNEL
if (!raw)
get_module(RAW_MODULE_PATH, (module_info**)&raw);
#endif
get_module(NET_RAW_MODULE_NAME, (module_info**)&raw);
ic_ifaddr = get_primary_addr();
}
struct protosw my_proto = {
"ICMP (v4)",
ICMP_MODULE_PATH,
NET_ICMP_MODULE_NAME,
0,
NULL,
IPPROTO_ICMP,
@ -420,30 +411,8 @@ static int icmp_protocol_init(void *cpp)
add_domain(NULL, AF_INET);
add_protocol(&my_proto, AF_INET);
#ifndef _KERNEL_MODE
if (!ipm) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
strcat(path, "/" IPV4_MODULE_PATH);
ipid = load_add_on(path);
if (ipid > 0) {
status_t rv = get_image_symbol(ipid, "protocol_info",
B_SYMBOL_TYPE_DATA, (void**)&ipm);
if (rv < 0) {
printf("Failed to get access to IPv4 information!\n");
return -1;
}
} else {
printf("Failed to load the IPv4 module...\n");
return -1;
}
ipm->set_core(cpp);
}
#else
if (!ipm)
get_module(IPV4_MODULE_PATH, (module_info**)&ipm);
#endif
get_module(NET_IPV4_MODULE_NAME, (module_info**)&ipm);
return 0;
}
@ -455,42 +424,36 @@ static int icmp_protocol_stop(void)
return 0;
}
#ifndef _KERNEL_MODE
void set_core(struct core_module_info *cp)
{
core = cp;
}
#endif
_EXPORT struct icmp_module_info protocol_info = {
struct icmp_module_info protocol_info = {
{
{
ICMP_MODULE_PATH,
NET_ICMP_MODULE_NAME,
0,
icmp_ops
std_ops
},
icmp_protocol_init,
icmp_protocol_stop
},
#ifndef _KERNEL_MODE
set_core,
#endif
icmp_error
};
#ifdef _KERNEL_MODE
static status_t icmp_ops(int32 op, ...)
// #pragma mark -
_EXPORT status_t std_ops(int32 op, ...)
{
switch(op) {
case B_MODULE_INIT:
if (!core)
get_module(CORE_MODULE_PATH, (module_info**)&core);
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
if (!core)
return B_ERROR;
load_driver_symbols("icmp");
return B_OK;
case B_MODULE_UNINIT:
break;
default:
return B_ERROR;
}
@ -498,8 +461,7 @@ static status_t icmp_ops(int32 op, ...)
}
_EXPORT module_info *modules[] = {
(module_info *)&protocol_info,
(module_info *) &protocol_info,
NULL
};
#endif

View File

@ -3,7 +3,7 @@
*/
#ifndef _KERNEL_MODE
#include <stdio.h>
#include <stdio.h>
#endif
#include <unistd.h>
#include <kernel/OS.h>
@ -27,12 +27,8 @@
#include "ipv4_module.h"
#include "icmp_module.h"
#ifdef _KERNEL_MODE
#include <KernelExport.h>
static status_t ipv4_ops(int32 op, ...);
#else
#define ipv4_ops NULL
#endif /* _KERNEL_MODE */
static status_t std_ops(int32 op, ...);
#define INA struct in_ifaddr *
#define SA struct sockaddr *
@ -46,9 +42,6 @@ static uint16 ip_id = 0;
static sem_id id_lock = -1;
static struct in_ifaddr *ip_ifaddr = NULL;
static struct icmp_module_info *icmp = NULL;
#ifndef _KERNEL_MODE
static image_id icmpid = -1;
#endif
static struct ipq ipq;
static net_timer_id timerid;
@ -1157,7 +1150,7 @@ static void ipv4_init(void)
struct protosw my_proto = {
"IPv4",
IPV4_MODULE_PATH,
NET_IPV4_MODULE_NAME,
0,
NULL,
IPPROTO_IP,
@ -1185,30 +1178,8 @@ static int ipv4_module_init(void *cpp)
add_domain(NULL, AF_INET);
add_protocol(&my_proto, AF_INET);
#ifndef _KERNEL_MODE
if (!icmp) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
strcat(path, "/" ICMP_MODULE_PATH);
icmpid = load_add_on(path);
if (icmpid > 0) {
status_t rv = get_image_symbol(icmpid, "protocol_info",
B_SYMBOL_TYPE_DATA, (void**)&icmp);
if (rv < 0) {
printf("Failed to get access to IPv4 information!\n");
return -1;
}
} else {
printf("Failed to load the IPv4 module...\n");
return -1;
}
icmp->set_core(cpp);
}
#else
if (!icmp)
get_module(ICMP_MODULE_PATH, (module_info**)&icmp);
#endif
get_module(NET_ICMP_MODULE_NAME, (module_info **) &icmp);
return 0;
}
@ -1222,28 +1193,17 @@ static int ipv4_module_stop(void)
return 0;
}
#ifndef _KERNEL_MODE
void set_core(struct core_module_info *cp)
{
core = cp;
}
#endif
_EXPORT struct ipv4_module_info protocol_info = {
struct ipv4_module_info protocol_info = {
{
{
IPV4_MODULE_PATH,
NET_IPV4_MODULE_NAME,
0,
ipv4_ops
std_ops
},
ipv4_module_init,
ipv4_module_stop
},
#ifndef _KERNEL_MODE
set_core,
#endif
ipv4_output,
get_ip_id,
ipv4_ctloutput,
@ -1252,18 +1212,21 @@ _EXPORT struct ipv4_module_info protocol_info = {
ip_srcroute
};
#ifdef _KERNEL_MODE
static status_t ipv4_ops(int32 op, ...)
// #pragma mark -
_EXPORT status_t std_ops(int32 op, ...)
{
switch (op) {
case B_MODULE_INIT:
get_module(CORE_MODULE_PATH, (module_info**)&core);
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
if (!core)
return B_ERROR;
load_driver_symbols("ipv4");
return B_OK;
case B_MODULE_UNINIT:
return B_OK;
default:
return B_ERROR;
}
@ -1272,7 +1235,7 @@ static status_t ipv4_ops(int32 op, ...)
_EXPORT module_info *modules[] = {
(module_info*) &protocol_info,
(module_info *) &protocol_info,
NULL
};
#endif

View File

@ -19,13 +19,8 @@
#include "raw_module.h"
#include "ipv4_module.h"
#ifdef _KERNEL_MODE
#include <KernelExport.h>
static status_t raw_ops(int32 op, ...);
#else /* _KERNEL_MODE */
#define raw_ops NULL
static image_id ipid;
#endif
status_t std_ops(int32 op, ...);
static struct core_module_info *core = NULL;
static struct ipv4_module_info *ipm = NULL;
@ -262,17 +257,13 @@ int rip_ctloutput(int op, struct socket *so, int level,
break;
/* XXX - Add other options here */
}
#ifdef _KERNEL_MODE
return ipm->ctloutput(op, so, level, optnum, m);
#else
/* XXX - get this working for app...? */
return 0;
#endif
}
static struct protosw my_protocol = {
"Raw IP module",
RAW_MODULE_PATH,
NET_RAW_MODULE_NAME,
SOCK_RAW,
NULL,
0,
@ -299,42 +290,15 @@ static int raw_module_init(void *cpp)
add_domain(NULL, AF_INET);
add_protocol(&my_protocol, AF_INET);
#ifndef _KERNEL_MODE
if (!ipm) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
strcat(path, "/" IPV4_MODULE_PATH);
ipid = load_add_on(path);
if (ipid > 0) {
status_t rv = get_image_symbol(ipid, "protocol_info",
B_SYMBOL_TYPE_DATA, (void**)&ipm);
if (rv < 0) {
printf("Failed to get access to IPv4 information!\n");
return -1;
}
ipm->set_core(cpp);
} else {
printf("Failed to load the IPv4 module...%ld [%s]\n",
ipid, strerror(ipid));
return -1;
}
}
#else
if (!ipm)
get_module(IPV4_MODULE_PATH, (module_info**)&ipm);
#endif
get_module(NET_IPV4_MODULE_NAME, (module_info**) &ipm);
return 0;
}
static int raw_module_stop(void)
{
#ifndef _KERNEL_MODE
unload_add_on(ipid);
#else
put_module(IPV4_MODULE_PATH);
#endif
put_module(NET_IPV4_MODULE_NAME);
remove_protocol(&my_protocol);
remove_domain(AF_INET);
@ -342,12 +306,12 @@ static int raw_module_stop(void)
return 0;
}
_EXPORT struct raw_module_info protocol_info = {
struct raw_module_info protocol_info = {
{
{
RAW_MODULE_PATH,
NET_RAW_MODULE_NAME,
0,
raw_ops
std_ops
},
raw_module_init,
raw_module_stop
@ -355,17 +319,20 @@ _EXPORT struct raw_module_info protocol_info = {
&rip_input
};
#ifdef _KERNEL_MODE
static status_t raw_ops(int32 op, ...)
// #pragma mark -
_EXPORT status_t std_ops(int32 op, ...)
{
switch(op) {
case B_MODULE_INIT:
get_module(CORE_MODULE_PATH, (module_info**)&core);
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
if (!core)
return B_ERROR;
return B_OK;
case B_MODULE_UNINIT:
break;
default:
return B_ERROR;
}
@ -373,8 +340,6 @@ static status_t raw_ops(int32 op, ...)
}
_EXPORT module_info *modules[] = {
(module_info*)&protocol_info,
(module_info *) &protocol_info,
NULL
};
#endif

View File

@ -29,15 +29,9 @@
#include "ipv4_module.h"
#include "net_timer.h"
#ifdef _KERNEL_MODE
#include <KernelExport.h>
#define TCP_MODULE_PATH "network/protocol/tcp"
static status_t tcp_ops(int32 op, ...);
#else /* _KERNEL_MODE */
#define tcp_ops NULL
#define TCP_MODULE_PATH "modules/protocol/tcp"
static image_id ipid = -1;
#endif
#define NET_TCP_MODULE_NAME "network/protocols/tcp"
status_t std_ops(int32 op, ...);
struct core_module_info *core = NULL;
struct ipv4_module_info *ipm = NULL;
@ -506,7 +500,7 @@ int tcp_userreq(struct socket *so, int req, struct mbuf *m,
static struct protosw my_proto = {
"TCP Module",
TCP_MODULE_PATH,
NET_TCP_MODULE_NAME,
SOCK_STREAM,
NULL,
IPPROTO_TCP,
@ -534,30 +528,8 @@ static int tcp_module_init(void *cpp)
add_domain(NULL, AF_INET);
add_protocol(&my_proto, AF_INET);
#ifndef _KERNEL_MODE
if (!ipm) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
strcat(path, "/" IPV4_MODULE_PATH);
ipid = load_add_on(path);
if (ipid > 0) {
status_t rv = get_image_symbol(ipid, "protocol_info",
B_SYMBOL_TYPE_DATA, (void**)&ipm);
if (rv < 0) {
printf("Failed to get access to IPv4 information!\n");
return -1;
}
} else {
printf("Failed to load the IPv4 module...\n");
return -1;
}
ipm->set_core(cpp);
}
#else
if (!ipm)
get_module(IPV4_MODULE_PATH, (module_info**)&ipm);
#endif
get_module(NET_IPV4_MODULE_NAME, (module_info **) &ipm);
return 0;
}
@ -567,11 +539,7 @@ static int tcp_module_stop(void)
net_remove_timer(slowtim);
net_remove_timer(fasttim);
#ifndef _KERNEL_MODE
unload_add_on(ipid);
#else
put_module(IPV4_MODULE_PATH);
#endif
put_module(NET_IPV4_MODULE_NAME);
remove_protocol(&my_proto);
remove_domain(AF_INET);
@ -579,27 +547,30 @@ static int tcp_module_stop(void)
return 0;
}
_EXPORT struct kernel_net_module_info protocol_info = {
struct kernel_net_module_info protocol_info = {
{
TCP_MODULE_PATH,
NET_TCP_MODULE_NAME,
0,
tcp_ops
std_ops
},
tcp_module_init,
tcp_module_stop
};
#ifdef _KERNEL_MODE
static status_t tcp_ops(int32 op, ...)
// #pragma mark -
_EXPORT status_t std_ops(int32 op, ...)
{
switch(op) {
case B_MODULE_INIT:
get_module(CORE_MODULE_PATH, (module_info**)&core);
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
if (!core)
return B_ERROR;
return B_OK;
case B_MODULE_UNINIT:
break;
default:
return B_ERROR;
}
@ -607,8 +578,7 @@ static status_t tcp_ops(int32 op, ...)
}
_EXPORT module_info *modules[] = {
(module_info*)&protocol_info,
(module_info *) &protocol_info,
NULL
};
#endif

View File

@ -24,14 +24,9 @@
#include "core_funcs.h"
#include "icmp_module.h"
#ifdef _KERNEL_MODE
#include <KernelExport.h>
static status_t udp_ops(int32 op, ...);
#define UDP_MODULE_PATH "network/protocol/udp"
#else /* _KERNEL */
#define udp_ops NULL
#define UDP_MODULE_PATH "modules/protocol/udp"
#endif
status_t std_ops(int32 op, ...);
#define NET_UDP_MODULE_NAME "network/protocols/udp"
/* Private variables */
static struct core_module_info *core = NULL;
@ -42,9 +37,6 @@ static struct udpstat udpstat;
static uint32 udp_sendspace; /* size of send buffer */
static uint32 udp_recvspace; /* size of recieve buffer */
static struct icmp_module_info *icmp = NULL;
#ifndef _KERNEL_MODE
static image_id icmpid = -1;
#endif
static struct in_addr zeroin_addr = {0};
@ -354,7 +346,7 @@ void udp_init(void)
static struct protosw my_proto = {
"UDP Module",
UDP_MODULE_PATH,
NET_UDP_MODULE_NAME,
SOCK_DGRAM,
NULL,
IPPROTO_UDP,
@ -380,30 +372,8 @@ static int udp_module_init(void *cpp)
add_domain(NULL, AF_INET);
add_protocol(&my_proto, AF_INET);
#ifndef _KERNEL_MODE
if (!icmp) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
strcat(path, "/" ICMP_MODULE_PATH);
icmpid = load_add_on(path);
if (icmpid > 0) {
status_t rv = get_image_symbol(icmpid, "protocol_info",
B_SYMBOL_TYPE_DATA, (void**)&icmp);
if (rv < 0) {
printf("Failed to get access to IPv4 information!\n");
return -1;
}
} else {
printf("Failed to load the IPv4 module...\n");
return -1;
}
icmp->set_core(cpp);
}
#else
if (!icmp)
get_module(ICMP_MODULE_PATH, (module_info**)&icmp);
#endif
get_module(NET_ICMP_MODULE_NAME, (module_info **) &icmp);
return 0;
}
@ -415,27 +385,30 @@ static int udp_module_stop(void)
return 0;
}
_EXPORT struct kernel_net_module_info protocol_info = {
struct kernel_net_module_info protocol_info = {
{
UDP_MODULE_PATH,
NET_UDP_MODULE_NAME,
B_KEEP_LOADED,
udp_ops
std_ops
},
udp_module_init,
udp_module_stop
};
#ifdef _KERNEL_MODE
static status_t udp_ops(int32 op, ...)
// #pragma mark -
_EXPORT status_t std_ops(int32 op, ...)
{
switch(op) {
case B_MODULE_INIT:
get_module(CORE_MODULE_PATH, (module_info**)&core);
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
if (!core)
return B_ERROR;
return B_OK;
case B_MODULE_UNINIT:
break;
default:
return B_ERROR;
}
@ -443,7 +416,6 @@ static status_t udp_ops(int32 op, ...)
}
_EXPORT module_info *modules[] = {
(module_info *)&protocol_info,
(module_info *) &protocol_info,
NULL
};
#endif