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:
@@ -12,10 +12,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
#include <Drivers.h>
|
#include <Drivers.h>
|
||||||
#include <module.h>
|
#include <module.h>
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
|
|
||||||
|
#ifdef _KERNEL_MODE
|
||||||
#define spawn_thread spawn_kernel_thread
|
#define spawn_thread spawn_kernel_thread
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -25,7 +26,6 @@
|
|||||||
#include "sys/socket.h"
|
#include "sys/socket.h"
|
||||||
#include "sys/socketvar.h"
|
#include "sys/socketvar.h"
|
||||||
#include "net/if.h" /* for ifnet definition */
|
#include "net/if.h" /* for ifnet definition */
|
||||||
//#include "net_server/net_server.h"
|
|
||||||
#include "protocols.h"
|
#include "protocols.h"
|
||||||
#include "net_module.h"
|
#include "net_module.h"
|
||||||
#include "net_timer.h"
|
#include "net_timer.h"
|
||||||
@@ -60,11 +60,8 @@ static int init_done = 0;
|
|||||||
|
|
||||||
/* Forward prototypes... */
|
/* Forward prototypes... */
|
||||||
/* Private for this file */
|
/* Private for this file */
|
||||||
#ifdef _KERNEL_MODE
|
status_t std_ops(int32 op, ...);
|
||||||
static status_t core_std_ops(int32 op, ...);
|
|
||||||
#else
|
|
||||||
#define core_std_ops NULL
|
|
||||||
#endif
|
|
||||||
static int start_stack(void);
|
static int start_stack(void);
|
||||||
static int stop_stack(void);
|
static int stop_stack(void);
|
||||||
static void add_protosw(struct protosw *[], int layer);
|
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,
|
int net_sysctl(int *name, uint namelen, void *oldp, size_t *oldlenp,
|
||||||
void *newp, size_t newlen);
|
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,
|
B_KEEP_LOADED,
|
||||||
core_std_ops
|
std_ops
|
||||||
},
|
},
|
||||||
|
|
||||||
start_stack,
|
start_stack,
|
||||||
@@ -659,7 +656,7 @@ static void domain_init(void)
|
|||||||
* NB these don't have any additional functions so we just use the
|
* NB these don't have any additional functions so we just use the
|
||||||
* system defined module_info structures
|
* system defined module_info structures
|
||||||
*/
|
*/
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
static void find_protocol_modules(void)
|
static void find_protocol_modules(void)
|
||||||
{
|
{
|
||||||
void *ml = open_module_list(NETWORK_PROTOCOLS);
|
void *ml = open_module_list(NETWORK_PROTOCOLS);
|
||||||
@@ -746,7 +743,12 @@ static void find_interface_modules(void)
|
|||||||
close_module_list(ml);
|
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)
|
static void _find_interface_modules(char *dirpath)
|
||||||
{
|
{
|
||||||
@@ -987,11 +989,7 @@ static int stop_stack(void)
|
|||||||
printf("trying to unload modules\n");
|
printf("trying to unload modules\n");
|
||||||
nm = module_list;
|
nm = module_list;
|
||||||
do {
|
do {
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
put_module(nm->name);
|
put_module(nm->name);
|
||||||
#else
|
|
||||||
unload_add_on(nm->iid);
|
|
||||||
#endif
|
|
||||||
onm = nm;
|
onm = nm;
|
||||||
nm = nm->next;
|
nm = nm->next;
|
||||||
onm->next = NULL;
|
onm->next = NULL;
|
||||||
@@ -1014,13 +1012,16 @@ static int stop_stack(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
// #pragma mark -
|
||||||
static status_t core_std_ops(int32 op, ...)
|
|
||||||
|
_EXPORT status_t std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
|
printf("core: B_MODULE_INIT\n");
|
||||||
load_driver_symbols("core");
|
load_driver_symbols("core");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
// the stack is keeping loaded, so don't stop it
|
// the stack is keeping loaded, so don't stop it
|
||||||
printf("core: B_MODULE_UNINIT\n");
|
printf("core: B_MODULE_UNINIT\n");
|
||||||
@@ -1037,6 +1038,3 @@ _EXPORT module_info *modules[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
|
||||||
_EXPORT module_info *modules = (module_info *)&core_info;
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -26,19 +26,15 @@
|
|||||||
#include "core_funcs.h"
|
#include "core_funcs.h"
|
||||||
#include "net_timer.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
|
/* forward prototypes */
|
||||||
#include <KernelExport.h>
|
int ether_dev_start(ifnet *dev);
|
||||||
#define spawn_thread spawn_kernel_thread
|
int ether_dev_stop (ifnet *dev);
|
||||||
#define printf dprintf
|
|
||||||
|
|
||||||
/* forward prototypes */
|
status_t std_ops(int32 op, ...);
|
||||||
int ether_dev_start(ifnet *dev);
|
|
||||||
int ether_dev_stop (ifnet *dev);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int32 std_ops(int32 op, ...);
|
|
||||||
|
|
||||||
/* Local variables */
|
/* Local variables */
|
||||||
static struct protosw *proto[IPPROTO_MAX];
|
static struct protosw *proto[IPPROTO_MAX];
|
||||||
@@ -903,9 +899,9 @@ static int ether_stop()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_EXPORT struct kernel_net_module_info device_info = {
|
struct kernel_net_module_info device_info = {
|
||||||
{
|
{
|
||||||
ETHERNET_MODULE_PATH,
|
"network/interfaces/ethernet",
|
||||||
0,
|
0,
|
||||||
std_ops
|
std_ops
|
||||||
},
|
},
|
||||||
@@ -914,20 +910,21 @@ _EXPORT struct kernel_net_module_info device_info = {
|
|||||||
ether_stop
|
ether_stop
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
static int32 std_ops(int32 op, ...)
|
_EXPORT status_t std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
get_module(CORE_MODULE_PATH, (module_info**)&core);
|
get_module(NET_CORE_MODULE_NAME, (module_info**)&core);
|
||||||
if (!core)
|
if (!core)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
load_driver_symbols("ethernet");
|
load_driver_symbols("ethernet");
|
||||||
#endif
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,10 @@
|
|||||||
#include "net_module.h"
|
#include "net_module.h"
|
||||||
#include "core_funcs.h"
|
#include "core_funcs.h"
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
#define printf dprintf
|
#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;
|
static struct core_module_info *core = NULL;
|
||||||
|
|
||||||
@@ -144,9 +139,9 @@ static int loopback_module_init(void *cpp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_EXPORT struct kernel_net_module_info device_info = {
|
struct kernel_net_module_info device_info = {
|
||||||
{
|
{
|
||||||
LOOP_MODULE_PATH,
|
"network/interfaces/loopback",
|
||||||
0,
|
0,
|
||||||
std_ops
|
std_ops
|
||||||
},
|
},
|
||||||
@@ -154,11 +149,13 @@ _EXPORT struct kernel_net_module_info device_info = {
|
|||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static status_t std_ops(int32 op, ...)
|
// #pragma mark -
|
||||||
|
|
||||||
|
_EXPORT status_t std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
get_module(CORE_MODULE_PATH, (module_info **)&core);
|
get_module(NET_CORE_MODULE_NAME, (module_info **)&core);
|
||||||
if (!core)
|
if (!core)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -175,5 +172,3 @@ _EXPORT module_info *modules[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/* icmp.c
|
/* icmp.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _KERNEL
|
#ifndef _KERNEL_MODE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "net_misc.h"
|
#include "net_misc.h"
|
||||||
@@ -25,12 +25,8 @@
|
|||||||
#include "icmp_module.h"
|
#include "icmp_module.h"
|
||||||
#include "ipv4_module.h"
|
#include "ipv4_module.h"
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
static status_t icmp_ops(int32 op, ...);
|
status_t std_ops(int32 op, ...);
|
||||||
#else
|
|
||||||
#define icmp_ops NULL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* private variables */
|
/* private variables */
|
||||||
static struct core_module_info *core = NULL;
|
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 protosw* proto[IPPROTO_MAX];
|
||||||
static struct in_ifaddr *ic_ifaddr = NULL;
|
static struct in_ifaddr *ic_ifaddr = NULL;
|
||||||
static struct ipv4_module_info *ipm = NULL;
|
static struct ipv4_module_info *ipm = NULL;
|
||||||
#ifndef _KERNEL_MODE
|
|
||||||
static image_id ipid = -1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct icmpstat icmpstat;
|
struct icmpstat icmpstat;
|
||||||
|
|
||||||
@@ -382,16 +375,14 @@ static void icmp_init(void)
|
|||||||
|
|
||||||
memset(proto, 0, sizeof(struct protosw *) * IPPROTO_MAX);
|
memset(proto, 0, sizeof(struct protosw *) * IPPROTO_MAX);
|
||||||
add_protosw(proto, NET_LAYER2);
|
add_protosw(proto, NET_LAYER2);
|
||||||
#ifdef _KERNEL
|
|
||||||
if (!raw)
|
if (!raw)
|
||||||
get_module(RAW_MODULE_PATH, (module_info**)&raw);
|
get_module(NET_RAW_MODULE_NAME, (module_info**)&raw);
|
||||||
#endif
|
|
||||||
ic_ifaddr = get_primary_addr();
|
ic_ifaddr = get_primary_addr();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct protosw my_proto = {
|
struct protosw my_proto = {
|
||||||
"ICMP (v4)",
|
"ICMP (v4)",
|
||||||
ICMP_MODULE_PATH,
|
NET_ICMP_MODULE_NAME,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
IPPROTO_ICMP,
|
IPPROTO_ICMP,
|
||||||
@@ -420,30 +411,8 @@ static int icmp_protocol_init(void *cpp)
|
|||||||
add_domain(NULL, AF_INET);
|
add_domain(NULL, AF_INET);
|
||||||
add_protocol(&my_proto, 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)
|
if (!ipm)
|
||||||
get_module(IPV4_MODULE_PATH, (module_info**)&ipm);
|
get_module(NET_IPV4_MODULE_NAME, (module_info**)&ipm);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -455,42 +424,36 @@ static int icmp_protocol_stop(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _KERNEL_MODE
|
struct icmp_module_info protocol_info = {
|
||||||
void set_core(struct core_module_info *cp)
|
|
||||||
{
|
|
||||||
core = cp;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_EXPORT struct icmp_module_info protocol_info = {
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
ICMP_MODULE_PATH,
|
NET_ICMP_MODULE_NAME,
|
||||||
0,
|
0,
|
||||||
icmp_ops
|
std_ops
|
||||||
},
|
},
|
||||||
icmp_protocol_init,
|
icmp_protocol_init,
|
||||||
icmp_protocol_stop
|
icmp_protocol_stop
|
||||||
},
|
},
|
||||||
#ifndef _KERNEL_MODE
|
|
||||||
set_core,
|
|
||||||
#endif
|
|
||||||
icmp_error
|
icmp_error
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
// #pragma mark -
|
||||||
static status_t icmp_ops(int32 op, ...)
|
|
||||||
|
_EXPORT status_t std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
if (!core)
|
if (!core)
|
||||||
get_module(CORE_MODULE_PATH, (module_info**)&core);
|
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
|
||||||
if (!core)
|
if (!core)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
load_driver_symbols("icmp");
|
load_driver_symbols("icmp");
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -498,8 +461,7 @@ static status_t icmp_ops(int32 op, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
_EXPORT module_info *modules[] = {
|
||||||
(module_info *)&protocol_info,
|
(module_info *) &protocol_info,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _KERNEL_MODE
|
#ifndef _KERNEL_MODE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <kernel/OS.h>
|
#include <kernel/OS.h>
|
||||||
@@ -27,12 +27,8 @@
|
|||||||
#include "ipv4_module.h"
|
#include "ipv4_module.h"
|
||||||
#include "icmp_module.h"
|
#include "icmp_module.h"
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
static status_t ipv4_ops(int32 op, ...);
|
static status_t std_ops(int32 op, ...);
|
||||||
#else
|
|
||||||
#define ipv4_ops NULL
|
|
||||||
#endif /* _KERNEL_MODE */
|
|
||||||
|
|
||||||
#define INA struct in_ifaddr *
|
#define INA struct in_ifaddr *
|
||||||
#define SA struct sockaddr *
|
#define SA struct sockaddr *
|
||||||
@@ -46,9 +42,6 @@ static uint16 ip_id = 0;
|
|||||||
static sem_id id_lock = -1;
|
static sem_id id_lock = -1;
|
||||||
static struct in_ifaddr *ip_ifaddr = NULL;
|
static struct in_ifaddr *ip_ifaddr = NULL;
|
||||||
static struct icmp_module_info *icmp = NULL;
|
static struct icmp_module_info *icmp = NULL;
|
||||||
#ifndef _KERNEL_MODE
|
|
||||||
static image_id icmpid = -1;
|
|
||||||
#endif
|
|
||||||
static struct ipq ipq;
|
static struct ipq ipq;
|
||||||
static net_timer_id timerid;
|
static net_timer_id timerid;
|
||||||
|
|
||||||
@@ -1157,7 +1150,7 @@ static void ipv4_init(void)
|
|||||||
|
|
||||||
struct protosw my_proto = {
|
struct protosw my_proto = {
|
||||||
"IPv4",
|
"IPv4",
|
||||||
IPV4_MODULE_PATH,
|
NET_IPV4_MODULE_NAME,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
IPPROTO_IP,
|
IPPROTO_IP,
|
||||||
@@ -1185,30 +1178,8 @@ static int ipv4_module_init(void *cpp)
|
|||||||
add_domain(NULL, AF_INET);
|
add_domain(NULL, AF_INET);
|
||||||
add_protocol(&my_proto, 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)
|
if (!icmp)
|
||||||
get_module(ICMP_MODULE_PATH, (module_info**)&icmp);
|
get_module(NET_ICMP_MODULE_NAME, (module_info **) &icmp);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1222,28 +1193,17 @@ static int ipv4_module_stop(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _KERNEL_MODE
|
struct ipv4_module_info protocol_info = {
|
||||||
void set_core(struct core_module_info *cp)
|
|
||||||
{
|
|
||||||
core = cp;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_EXPORT struct ipv4_module_info protocol_info = {
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
IPV4_MODULE_PATH,
|
NET_IPV4_MODULE_NAME,
|
||||||
0,
|
0,
|
||||||
ipv4_ops
|
std_ops
|
||||||
},
|
},
|
||||||
ipv4_module_init,
|
ipv4_module_init,
|
||||||
ipv4_module_stop
|
ipv4_module_stop
|
||||||
},
|
},
|
||||||
|
|
||||||
#ifndef _KERNEL_MODE
|
|
||||||
set_core,
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ipv4_output,
|
ipv4_output,
|
||||||
get_ip_id,
|
get_ip_id,
|
||||||
ipv4_ctloutput,
|
ipv4_ctloutput,
|
||||||
@@ -1252,18 +1212,21 @@ _EXPORT struct ipv4_module_info protocol_info = {
|
|||||||
ip_srcroute
|
ip_srcroute
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
// #pragma mark -
|
||||||
static status_t ipv4_ops(int32 op, ...)
|
|
||||||
|
_EXPORT status_t std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
get_module(CORE_MODULE_PATH, (module_info**)&core);
|
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
|
||||||
if (!core)
|
if (!core)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
load_driver_symbols("ipv4");
|
load_driver_symbols("ipv4");
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -1272,7 +1235,7 @@ static status_t ipv4_ops(int32 op, ...)
|
|||||||
|
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
_EXPORT module_info *modules[] = {
|
||||||
(module_info*) &protocol_info,
|
(module_info *) &protocol_info,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -19,13 +19,8 @@
|
|||||||
#include "raw_module.h"
|
#include "raw_module.h"
|
||||||
#include "ipv4_module.h"
|
#include "ipv4_module.h"
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
static status_t raw_ops(int32 op, ...);
|
status_t std_ops(int32 op, ...);
|
||||||
#else /* _KERNEL_MODE */
|
|
||||||
#define raw_ops NULL
|
|
||||||
static image_id ipid;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static struct core_module_info *core = NULL;
|
static struct core_module_info *core = NULL;
|
||||||
static struct ipv4_module_info *ipm = NULL;
|
static struct ipv4_module_info *ipm = NULL;
|
||||||
@@ -262,17 +257,13 @@ int rip_ctloutput(int op, struct socket *so, int level,
|
|||||||
break;
|
break;
|
||||||
/* XXX - Add other options here */
|
/* XXX - Add other options here */
|
||||||
}
|
}
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
return ipm->ctloutput(op, so, level, optnum, m);
|
return ipm->ctloutput(op, so, level, optnum, m);
|
||||||
#else
|
|
||||||
/* XXX - get this working for app...? */
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct protosw my_protocol = {
|
static struct protosw my_protocol = {
|
||||||
"Raw IP module",
|
"Raw IP module",
|
||||||
RAW_MODULE_PATH,
|
NET_RAW_MODULE_NAME,
|
||||||
SOCK_RAW,
|
SOCK_RAW,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
@@ -299,42 +290,15 @@ static int raw_module_init(void *cpp)
|
|||||||
add_domain(NULL, AF_INET);
|
add_domain(NULL, AF_INET);
|
||||||
add_protocol(&my_protocol, 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)
|
if (!ipm)
|
||||||
get_module(IPV4_MODULE_PATH, (module_info**)&ipm);
|
get_module(NET_IPV4_MODULE_NAME, (module_info**) &ipm);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_module_stop(void)
|
static int raw_module_stop(void)
|
||||||
{
|
{
|
||||||
#ifndef _KERNEL_MODE
|
put_module(NET_IPV4_MODULE_NAME);
|
||||||
unload_add_on(ipid);
|
|
||||||
#else
|
|
||||||
put_module(IPV4_MODULE_PATH);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
remove_protocol(&my_protocol);
|
remove_protocol(&my_protocol);
|
||||||
remove_domain(AF_INET);
|
remove_domain(AF_INET);
|
||||||
@@ -342,12 +306,12 @@ static int raw_module_stop(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_EXPORT struct raw_module_info protocol_info = {
|
struct raw_module_info protocol_info = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
RAW_MODULE_PATH,
|
NET_RAW_MODULE_NAME,
|
||||||
0,
|
0,
|
||||||
raw_ops
|
std_ops
|
||||||
},
|
},
|
||||||
raw_module_init,
|
raw_module_init,
|
||||||
raw_module_stop
|
raw_module_stop
|
||||||
@@ -355,17 +319,20 @@ _EXPORT struct raw_module_info protocol_info = {
|
|||||||
&rip_input
|
&rip_input
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
// #pragma mark -
|
||||||
static status_t raw_ops(int32 op, ...)
|
|
||||||
|
_EXPORT status_t std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
get_module(CORE_MODULE_PATH, (module_info**)&core);
|
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
|
||||||
if (!core)
|
if (!core)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -373,8 +340,6 @@ static status_t raw_ops(int32 op, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
_EXPORT module_info *modules[] = {
|
||||||
(module_info*)&protocol_info,
|
(module_info *) &protocol_info,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -29,15 +29,9 @@
|
|||||||
#include "ipv4_module.h"
|
#include "ipv4_module.h"
|
||||||
#include "net_timer.h"
|
#include "net_timer.h"
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
#define TCP_MODULE_PATH "network/protocol/tcp"
|
#define NET_TCP_MODULE_NAME "network/protocols/tcp"
|
||||||
static status_t tcp_ops(int32 op, ...);
|
status_t std_ops(int32 op, ...);
|
||||||
#else /* _KERNEL_MODE */
|
|
||||||
#define tcp_ops NULL
|
|
||||||
#define TCP_MODULE_PATH "modules/protocol/tcp"
|
|
||||||
static image_id ipid = -1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct core_module_info *core = NULL;
|
struct core_module_info *core = NULL;
|
||||||
struct ipv4_module_info *ipm = 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 = {
|
static struct protosw my_proto = {
|
||||||
"TCP Module",
|
"TCP Module",
|
||||||
TCP_MODULE_PATH,
|
NET_TCP_MODULE_NAME,
|
||||||
SOCK_STREAM,
|
SOCK_STREAM,
|
||||||
NULL,
|
NULL,
|
||||||
IPPROTO_TCP,
|
IPPROTO_TCP,
|
||||||
@@ -534,30 +528,8 @@ static int tcp_module_init(void *cpp)
|
|||||||
add_domain(NULL, AF_INET);
|
add_domain(NULL, AF_INET);
|
||||||
add_protocol(&my_proto, 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)
|
if (!ipm)
|
||||||
get_module(IPV4_MODULE_PATH, (module_info**)&ipm);
|
get_module(NET_IPV4_MODULE_NAME, (module_info **) &ipm);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -567,11 +539,7 @@ static int tcp_module_stop(void)
|
|||||||
net_remove_timer(slowtim);
|
net_remove_timer(slowtim);
|
||||||
net_remove_timer(fasttim);
|
net_remove_timer(fasttim);
|
||||||
|
|
||||||
#ifndef _KERNEL_MODE
|
put_module(NET_IPV4_MODULE_NAME);
|
||||||
unload_add_on(ipid);
|
|
||||||
#else
|
|
||||||
put_module(IPV4_MODULE_PATH);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
remove_protocol(&my_proto);
|
remove_protocol(&my_proto);
|
||||||
remove_domain(AF_INET);
|
remove_domain(AF_INET);
|
||||||
@@ -579,27 +547,30 @@ static int tcp_module_stop(void)
|
|||||||
return 0;
|
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,
|
0,
|
||||||
tcp_ops
|
std_ops
|
||||||
},
|
},
|
||||||
tcp_module_init,
|
tcp_module_init,
|
||||||
tcp_module_stop
|
tcp_module_stop
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
// #pragma mark -
|
||||||
static status_t tcp_ops(int32 op, ...)
|
|
||||||
|
_EXPORT status_t std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
get_module(CORE_MODULE_PATH, (module_info**)&core);
|
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
|
||||||
if (!core)
|
if (!core)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -607,8 +578,7 @@ static status_t tcp_ops(int32 op, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
_EXPORT module_info *modules[] = {
|
||||||
(module_info*)&protocol_info,
|
(module_info *) &protocol_info,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -24,14 +24,9 @@
|
|||||||
#include "core_funcs.h"
|
#include "core_funcs.h"
|
||||||
#include "icmp_module.h"
|
#include "icmp_module.h"
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
static status_t udp_ops(int32 op, ...);
|
status_t std_ops(int32 op, ...);
|
||||||
#define UDP_MODULE_PATH "network/protocol/udp"
|
#define NET_UDP_MODULE_NAME "network/protocols/udp"
|
||||||
#else /* _KERNEL */
|
|
||||||
#define udp_ops NULL
|
|
||||||
#define UDP_MODULE_PATH "modules/protocol/udp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Private variables */
|
/* Private variables */
|
||||||
static struct core_module_info *core = NULL;
|
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_sendspace; /* size of send buffer */
|
||||||
static uint32 udp_recvspace; /* size of recieve buffer */
|
static uint32 udp_recvspace; /* size of recieve buffer */
|
||||||
static struct icmp_module_info *icmp = NULL;
|
static struct icmp_module_info *icmp = NULL;
|
||||||
#ifndef _KERNEL_MODE
|
|
||||||
static image_id icmpid = -1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static struct in_addr zeroin_addr = {0};
|
static struct in_addr zeroin_addr = {0};
|
||||||
|
|
||||||
@@ -354,7 +346,7 @@ void udp_init(void)
|
|||||||
|
|
||||||
static struct protosw my_proto = {
|
static struct protosw my_proto = {
|
||||||
"UDP Module",
|
"UDP Module",
|
||||||
UDP_MODULE_PATH,
|
NET_UDP_MODULE_NAME,
|
||||||
SOCK_DGRAM,
|
SOCK_DGRAM,
|
||||||
NULL,
|
NULL,
|
||||||
IPPROTO_UDP,
|
IPPROTO_UDP,
|
||||||
@@ -380,30 +372,8 @@ static int udp_module_init(void *cpp)
|
|||||||
add_domain(NULL, AF_INET);
|
add_domain(NULL, AF_INET);
|
||||||
add_protocol(&my_proto, 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)
|
if (!icmp)
|
||||||
get_module(ICMP_MODULE_PATH, (module_info**)&icmp);
|
get_module(NET_ICMP_MODULE_NAME, (module_info **) &icmp);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -415,27 +385,30 @@ static int udp_module_stop(void)
|
|||||||
return 0;
|
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,
|
B_KEEP_LOADED,
|
||||||
udp_ops
|
std_ops
|
||||||
},
|
},
|
||||||
udp_module_init,
|
udp_module_init,
|
||||||
udp_module_stop
|
udp_module_stop
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _KERNEL_MODE
|
// #pragma mark -
|
||||||
static status_t udp_ops(int32 op, ...)
|
|
||||||
|
_EXPORT status_t std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
get_module(CORE_MODULE_PATH, (module_info**)&core);
|
get_module(NET_CORE_MODULE_NAME, (module_info **) &core);
|
||||||
if (!core)
|
if (!core)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
case B_MODULE_UNINIT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -443,7 +416,6 @@ static status_t udp_ops(int32 op, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
_EXPORT module_info *modules[] = {
|
||||||
(module_info *)&protocol_info,
|
(module_info *) &protocol_info,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|||||||
Reference in New Issue
Block a user