Remove mis-placed add-ons.
Fix Jamfiles to stop collide with net stack v1 modules userland targets built from src/tests/add-ons/kernel/network. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6166 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,7 +2,7 @@ SubDir OBOS_TOP src tests kits net new_stack ;
|
|||||||
|
|
||||||
UseHeaders [ FDirName $(OBOS_TOP) src tests kits net new_stack headers ] ;
|
UseHeaders [ FDirName $(OBOS_TOP) src tests kits net new_stack headers ] ;
|
||||||
|
|
||||||
SimpleTest stack_tester :
|
SimpleTest new_stack_tester :
|
||||||
net_stack_server.cpp
|
net_stack_server.cpp
|
||||||
userland_modules.cpp
|
userland_modules.cpp
|
||||||
: be
|
: be
|
||||||
@@ -11,17 +11,36 @@ SimpleTest stack_tester :
|
|||||||
{
|
{
|
||||||
# symlink the userland add-ons dir to the dir where the net_stack_tester
|
# symlink the userland add-ons dir to the dir where the net_stack_tester
|
||||||
# lives
|
# lives
|
||||||
local dir = [ on stack_tester return $(LOCATE) ] ;
|
local dir = [ on new_stack_tester return $(LOCATE) ] ;
|
||||||
MakeLocate <network-add-ons>userland : $(OBOS_ADDON_DIR) ;
|
MakeLocate <network_v2-add-ons>userland : $(OBOS_ADDON_DIR) ;
|
||||||
MakeLocate <network-add-ons>add-ons : $(dir) ;
|
MakeLocate <network_v2-add-ons>add-ons : $(dir) ;
|
||||||
RelSymLink <network-add-ons>add-ons : <network-add-ons>userland : false ;
|
RelSymLink <network_v2-add-ons>add-ons : <network_v2-add-ons>userland : false ;
|
||||||
|
|
||||||
# alias for the stack_tester the modules link against
|
# alias for the stack_tester the modules link against
|
||||||
LOCATE on <installed>stack_tester = $(dir) ;
|
LOCATE on <installed>new_stack_tester = $(dir) ;
|
||||||
Depends <installed>stack_tester
|
Depends <installed>new_stack_tester : <network_v2-add-ons>add-ons ;
|
||||||
: stack_tester <network-add-ons>add-ons ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotFile userland_network_v2_modules ;
|
||||||
|
Depends userland_network_v2_modules :
|
||||||
|
# the main stack modules
|
||||||
|
<v2>stack
|
||||||
|
<userland>memory_pool
|
||||||
|
<userland>atomizer
|
||||||
|
|
||||||
|
# framing modules
|
||||||
|
<v2>ethernet_frame
|
||||||
|
|
||||||
|
# interfaces modules
|
||||||
|
<v2>loopback
|
||||||
|
<v2>ether_drivers
|
||||||
|
|
||||||
|
# protocols modules
|
||||||
|
<v2>arp
|
||||||
|
<v2>ipv4
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
SubInclude OBOS_TOP src tests kits net new_stack memory_pool ;
|
SubInclude OBOS_TOP src tests kits net new_stack memory_pool ;
|
||||||
SubInclude OBOS_TOP src tests kits net new_stack atomizer ;
|
SubInclude OBOS_TOP src tests kits net new_stack atomizer ;
|
||||||
SubInclude OBOS_TOP src tests kits net new_stack stack ;
|
SubInclude OBOS_TOP src tests kits net new_stack stack ;
|
||||||
|
|||||||
@@ -1,218 +0,0 @@
|
|||||||
/* ethernet.c - ethernet devices interface module
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <KernelExport.h>
|
|
||||||
#include <ByteOrder.h>
|
|
||||||
|
|
||||||
#include "net_stack.h"
|
|
||||||
|
|
||||||
status_t std_ops(int32 op, ...);
|
|
||||||
|
|
||||||
struct net_layer_module_info nlmi;
|
|
||||||
|
|
||||||
static struct net_stack_module_info *g_stack = NULL;
|
|
||||||
|
|
||||||
net_attribute_id ethernet_protocol_attr;
|
|
||||||
|
|
||||||
typedef struct ethernet_addr {
|
|
||||||
uint8 byte[6];
|
|
||||||
} ethernet_addr;
|
|
||||||
|
|
||||||
typedef struct ipv4_addr {
|
|
||||||
uint8 byte[4];
|
|
||||||
} ipv4_addr;
|
|
||||||
|
|
||||||
struct arp_header {
|
|
||||||
uint16 hardware_type; /* format of hardware address */
|
|
||||||
uint16 protocol_type; /* format of protocol address */
|
|
||||||
uint8 hardware_size; /* length of hardware address */
|
|
||||||
uint8 protocol_size; /* length of protocol address */
|
|
||||||
uint16 op; /* one of: */
|
|
||||||
|
|
||||||
// for ethernet/ipv4 arp packets
|
|
||||||
|
|
||||||
ethernet_addr sender_hardware_address; /* sender hardware address */
|
|
||||||
ipv4_addr sender_protocol_address; /* sender protocol address */
|
|
||||||
ethernet_addr target_hardware_address; /* target hardware address */
|
|
||||||
ipv4_addr target_protocol_address; /* target protocol address */
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
ARP_HARDWARE_TYPE_ETHERNET = 1, /* ethernet hardware format */
|
|
||||||
ARP_HARDWARE_TYPE_IEEE802 = 6, /* IEEE 802 hardware format */
|
|
||||||
ARP_HARDWARE_TYPE_FRAMEREALY = 15
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
ARP_OP_REQUEST = 1, /* request to resolve address */
|
|
||||||
ARP_OP_REPLY,
|
|
||||||
ARP_OP_RARP_REQUEST,
|
|
||||||
ARP_OP_RARP_REPLY
|
|
||||||
};
|
|
||||||
|
|
||||||
static void dump_arp(net_buffer *buffer)
|
|
||||||
{
|
|
||||||
struct arp_header arp;
|
|
||||||
const char *pname;
|
|
||||||
ethernet_addr *ea;
|
|
||||||
ipv4_addr *ia;
|
|
||||||
|
|
||||||
g_stack->read_buffer(buffer, 0, &arp, sizeof(arp));
|
|
||||||
|
|
||||||
switch(ntohs(arp.protocol_type)) {
|
|
||||||
case 0x0800: pname = "IPv4"; break;
|
|
||||||
case 0x0806: pname = "ARP"; break;
|
|
||||||
default: pname = "unknown"; break;
|
|
||||||
};
|
|
||||||
|
|
||||||
dprintf("========== Address Resolution Protocol ==========\n");
|
|
||||||
dprintf("Hardware : %s\n",
|
|
||||||
ntohs(arp.hardware_type) == ARP_HARDWARE_TYPE_ETHERNET ? "ethernet" : "unknown");
|
|
||||||
dprintf("Protocol : 0x%04x (%s)\n", ntohs(arp.protocol_type), pname);
|
|
||||||
dprintf("Operation : ");
|
|
||||||
switch(ntohs(arp.op)) {
|
|
||||||
case ARP_OP_REPLY:
|
|
||||||
dprintf("ARP Reply\n");
|
|
||||||
break;
|
|
||||||
case ARP_OP_REQUEST:
|
|
||||||
dprintf("ARP Request\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dprintf("Who knows? 0x%04x\n", ntohs(arp.op));
|
|
||||||
};
|
|
||||||
dprintf("Hardware address length: %d\n", arp.hardware_size);
|
|
||||||
dprintf("Protocol address length: %d\n", arp.protocol_size);
|
|
||||||
|
|
||||||
ea = &arp.sender_hardware_address;
|
|
||||||
dprintf("Sender Hardware Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
||||||
ea->byte[0], ea->byte[1], ea->byte[2], ea->byte[3], ea->byte[4], ea->byte[5]);
|
|
||||||
ia = &arp.sender_protocol_address;
|
|
||||||
dprintf("Sender Protocol Address: %d.%d.%d.%d\n",
|
|
||||||
ia->byte[0], ia->byte[1], ia->byte[2], ia->byte[3]);
|
|
||||||
|
|
||||||
ea = &arp.target_hardware_address;
|
|
||||||
dprintf("Target Hardware Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
||||||
ea->byte[0], ea->byte[1], ea->byte[2], ea->byte[3], ea->byte[4], ea->byte[5]);
|
|
||||||
ia = &arp.target_protocol_address;
|
|
||||||
dprintf("Target Protocol Address: %d.%d.%d.%d\n",
|
|
||||||
ia->byte[0], ia->byte[1], ia->byte[2], ia->byte[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------
|
|
||||||
status_t init(net_layer *me)
|
|
||||||
{
|
|
||||||
dprintf("%s: initing layer\n", me->name);
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t uninit(net_layer *me)
|
|
||||||
{
|
|
||||||
dprintf("%s: uniniting layer\n", me->name);
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t enable(net_layer *me, bool enable)
|
|
||||||
{
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t process_input(net_layer *me, net_buffer *buffer)
|
|
||||||
{
|
|
||||||
uint16 *protocol;
|
|
||||||
|
|
||||||
if (!buffer)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
if (g_stack->find_buffer_attribute(buffer, ethernet_protocol_attr, NULL, (void **) &protocol, NULL) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
if (*protocol != htons(0x0806)) // ARP on Ethernet protocol value
|
|
||||||
// Not an ARP packet
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
// TODO!
|
|
||||||
// dprintf("%s: packet %p is an ARP packet!\n", me->name, buffer);
|
|
||||||
dump_arp(buffer);
|
|
||||||
g_stack->delete_buffer(buffer, false);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t process_output(net_layer *me, net_buffer *buffer)
|
|
||||||
{
|
|
||||||
if (!buffer)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
// TODO!
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
status_t std_ops(int32 op, ...)
|
|
||||||
{
|
|
||||||
switch(op) {
|
|
||||||
case B_MODULE_INIT: {
|
|
||||||
status_t status;
|
|
||||||
net_layer *layer;
|
|
||||||
|
|
||||||
dprintf("arp: B_MODULE_INIT\n");
|
|
||||||
status = get_module(NET_STACK_MODULE_NAME, (module_info **) &g_stack);
|
|
||||||
if (status != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
ethernet_protocol_attr = g_stack->register_attribute_id("ethernet:protocol");
|
|
||||||
|
|
||||||
status = g_stack->register_layer("ARP", "ethernet/arp", 30, &nlmi, NULL, &layer);
|
|
||||||
if (status != B_OK)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
error:
|
|
||||||
g_stack->unregister_layer(layer);
|
|
||||||
put_module(NET_STACK_MODULE_NAME);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
|
||||||
dprintf("arp: B_MODULE_UNINIT\n");
|
|
||||||
put_module(NET_STACK_MODULE_NAME);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct net_layer_module_info nlmi = {
|
|
||||||
{
|
|
||||||
NET_LAYER_MODULES_ROOT "protocols/arp/v0",
|
|
||||||
0,
|
|
||||||
std_ops
|
|
||||||
},
|
|
||||||
|
|
||||||
init,
|
|
||||||
uninit,
|
|
||||||
enable,
|
|
||||||
NULL,
|
|
||||||
process_input,
|
|
||||||
process_output
|
|
||||||
};
|
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
|
||||||
(module_info*) &nlmi, // net_layer_module_info
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
Binary file not shown.
@@ -6,4 +6,4 @@ Addon <userland>atomizer : userland generic :
|
|||||||
atomizer.c
|
atomizer.c
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs <userland>atomizer : <installed>stack_tester ;
|
LinkSharedOSLibs <userland>atomizer : <installed>new_stack_tester ;
|
||||||
|
|||||||
@@ -1,348 +0,0 @@
|
|||||||
/* generic_ethernet.c - generic ethernet devices layer module
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include <sys/dirent.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <KernelExport.h>
|
|
||||||
#include <Drivers.h>
|
|
||||||
|
|
||||||
#include "net_stack.h"
|
|
||||||
|
|
||||||
enum {
|
|
||||||
ETHER_GETADDR = B_DEVICE_OP_CODES_END,
|
|
||||||
ETHER_INIT,
|
|
||||||
ETHER_NONBLOCK,
|
|
||||||
ETHER_ADDMULTI,
|
|
||||||
ETHER_REMMULTI,
|
|
||||||
ETHER_SETPROMISC,
|
|
||||||
ETHER_GETFRAMESIZE
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct generic_ethernet_device {
|
|
||||||
int fd;
|
|
||||||
int max_frame_size;
|
|
||||||
volatile thread_id reader_thread;
|
|
||||||
} generic_ethernet_device;
|
|
||||||
|
|
||||||
#define ETHER_ADDR_LEN 6 /* Ethernet address length */
|
|
||||||
#define ETHER_TYPE_LEN 2 /* Ethernet type field length */
|
|
||||||
#define ETHER_CRC_LEN 4 /* Ethernet CRC lenght */
|
|
||||||
#define ETHER_HDR_LEN ((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN)
|
|
||||||
#define ETHER_MIN_LEN 64 /* Minimum frame length, CRC included */
|
|
||||||
#define ETHER_MAX_LEN 1518 /* Maximum frame length, CRC included */
|
|
||||||
|
|
||||||
#define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
|
|
||||||
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
|
|
||||||
|
|
||||||
typedef struct ether_addr {
|
|
||||||
uint8 byte[ETHER_ADDR_LEN];
|
|
||||||
} ether_addr_t;
|
|
||||||
|
|
||||||
status_t lookup_devices(char *root, void *cookie);
|
|
||||||
status_t register_device(const char *path, void *cookie);
|
|
||||||
status_t device_reader(void *args);
|
|
||||||
status_t std_ops(int32 op, ...);
|
|
||||||
|
|
||||||
struct net_layer_module_info nlmi;
|
|
||||||
|
|
||||||
static struct net_stack_module_info *g_stack = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------
|
|
||||||
status_t init(net_layer *me)
|
|
||||||
{
|
|
||||||
printf("%s: initing layer\n", me->name);
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t uninit(net_layer *me)
|
|
||||||
{
|
|
||||||
generic_ethernet_device *ged = me->cookie;
|
|
||||||
|
|
||||||
printf("%s: uniniting layer\n", me->name);
|
|
||||||
|
|
||||||
close(ged->fd);
|
|
||||||
free(me->cookie);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t enable(net_layer *me, bool enable)
|
|
||||||
{
|
|
||||||
generic_ethernet_device *ged = me->cookie;
|
|
||||||
|
|
||||||
if (enable) {
|
|
||||||
// enable this layer
|
|
||||||
thread_id tid;
|
|
||||||
char name[B_OS_NAME_LENGTH * 2];
|
|
||||||
|
|
||||||
if (ged->reader_thread != -1)
|
|
||||||
// already up
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
strncpy(name, me->name, sizeof(name));
|
|
||||||
strncat(name, " reader", sizeof(name));
|
|
||||||
tid = spawn_kernel_thread(device_reader, name, B_NORMAL_PRIORITY, me);
|
|
||||||
if (tid < 0) {
|
|
||||||
printf("%s: failed to start device reader thread -> %d [%s]\n",
|
|
||||||
me->name, (int) tid, strerror(tid));
|
|
||||||
return tid;
|
|
||||||
};
|
|
||||||
|
|
||||||
ged->reader_thread = tid;
|
|
||||||
return resume_thread(tid);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
status_t dummy;
|
|
||||||
|
|
||||||
// disable this layer
|
|
||||||
if (ged->reader_thread == -1)
|
|
||||||
// already down
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
send_signal_etc(ged->reader_thread, SIGTERM, 0);
|
|
||||||
wait_for_thread(ged->reader_thread, &dummy);
|
|
||||||
printf("%s: device reader stopped.\n", me->name);
|
|
||||||
ged->reader_thread = -1;
|
|
||||||
return B_OK;
|
|
||||||
};
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t output_buffer(net_layer *me, net_buffer *buffer)
|
|
||||||
{
|
|
||||||
if (!buffer)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
// TODO!
|
|
||||||
printf("%s: output_buffer:\n", me->name);
|
|
||||||
g_stack->dump_buffer(buffer);
|
|
||||||
|
|
||||||
g_stack->delete_buffer(buffer, false);
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
status_t lookup_devices(char *root, void *cookie)
|
|
||||||
{
|
|
||||||
DIR *dir;
|
|
||||||
struct dirent *de;
|
|
||||||
struct stat st;
|
|
||||||
char path[1024];
|
|
||||||
status_t status;
|
|
||||||
|
|
||||||
dir = opendir(root);
|
|
||||||
if (!dir) {
|
|
||||||
printf("Couldn't open the directory %s\n", root);
|
|
||||||
return B_ERROR;
|
|
||||||
};
|
|
||||||
|
|
||||||
status = B_OK;
|
|
||||||
|
|
||||||
while ((de = readdir(dir)) != NULL) {
|
|
||||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
|
|
||||||
continue; // skip pseudo-directories
|
|
||||||
|
|
||||||
sprintf(path, "%s/%s", root, de->d_name);
|
|
||||||
|
|
||||||
if (stat(path, &st) < 0) {
|
|
||||||
printf("generic_ethernet: Can't stat(%s) entry! Skipping...\n", path);
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode))
|
|
||||||
status = lookup_devices(path, cookie);
|
|
||||||
else if (S_ISCHR(st.st_mode)) { // char device = driver!
|
|
||||||
if (strcmp(de->d_name, "stack") == 0 || // OBOS stack driver
|
|
||||||
strcmp(de->d_name, "server") == 0 || // OBOS server driver
|
|
||||||
strcmp(de->d_name, "api") == 0) // BONE stack driver
|
|
||||||
continue; // skip pseudo-entries
|
|
||||||
|
|
||||||
status = register_device(path, cookie);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t register_device(const char *path, void *cookie)
|
|
||||||
{
|
|
||||||
generic_ethernet_device *ged;
|
|
||||||
int frame_size;
|
|
||||||
ether_addr_t mac_address;
|
|
||||||
int fd;
|
|
||||||
status_t status;
|
|
||||||
char *name;
|
|
||||||
|
|
||||||
fd = open(path, O_RDWR);
|
|
||||||
if (fd < B_OK) {
|
|
||||||
printf("generic_ethernet: Unable to open %s device -> %d [%s]. Skipping...\n", path,
|
|
||||||
fd, strerror(fd));
|
|
||||||
return fd;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Init the network card
|
|
||||||
status = ioctl(fd, ETHER_INIT, NULL, 0);
|
|
||||||
if (status < B_OK) {
|
|
||||||
printf("generic_ethernet: Failed to init %s device -> %ld [%s]. Skipping...\n", path,
|
|
||||||
status, strerror(status));
|
|
||||||
close(fd);
|
|
||||||
return status;
|
|
||||||
};
|
|
||||||
|
|
||||||
// get the MAC address...
|
|
||||||
status = ioctl(fd, ETHER_GETADDR, &mac_address, 6);
|
|
||||||
if (status < B_OK) {
|
|
||||||
printf("generic_ethernet: Failed to get %s device MAC address -> %ld [%s]. Skipping...\n",
|
|
||||||
path, status, strerror(status));
|
|
||||||
close(fd);
|
|
||||||
return status;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try to determine the MTU to use
|
|
||||||
status = ioctl(fd, ETHER_GETFRAMESIZE, &frame_size, sizeof(frame_size));
|
|
||||||
if (status < B_OK) {
|
|
||||||
frame_size = ETHERMTU;
|
|
||||||
printf("generic_ethernet: %s device don't support ETHER_GETFRAMESIZE; defaulting to %d\n",
|
|
||||||
path, frame_size);
|
|
||||||
};
|
|
||||||
|
|
||||||
printf("generic_ethernet: Found device '%s': MAC address: %02x:%02x:%02x:%02x:%02x:%02x, MTU: %d bytes\n",
|
|
||||||
path,
|
|
||||||
mac_address.byte[0], mac_address.byte[1],
|
|
||||||
mac_address.byte[2], mac_address.byte[3],
|
|
||||||
mac_address.byte[4], mac_address.byte[5], frame_size);
|
|
||||||
|
|
||||||
ged = malloc(sizeof(*ged));
|
|
||||||
if (!ged) {
|
|
||||||
close(fd);
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
};
|
|
||||||
|
|
||||||
ged->fd = fd;
|
|
||||||
ged->max_frame_size = frame_size;
|
|
||||||
ged->reader_thread = -1;
|
|
||||||
|
|
||||||
name = malloc(strlen("ethernet/") + strlen(path));
|
|
||||||
strcpy(name, "ethernet/");
|
|
||||||
strcat(name, path + strlen("/dev/net/"));
|
|
||||||
|
|
||||||
return g_stack->register_layer(name, &nlmi, ged, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------
|
|
||||||
status_t device_reader(void *args)
|
|
||||||
{
|
|
||||||
net_layer *me = args;
|
|
||||||
generic_ethernet_device *ged = me->cookie;
|
|
||||||
net_buffer *buffer;
|
|
||||||
status_t status;
|
|
||||||
void *frame;
|
|
||||||
ssize_t sz;
|
|
||||||
|
|
||||||
printf("%s: device reader started.\n", me->name);
|
|
||||||
|
|
||||||
status = B_OK;
|
|
||||||
while(1) {
|
|
||||||
frame = malloc(ged->max_frame_size);
|
|
||||||
if (!frame) {
|
|
||||||
status = B_NO_MEMORY;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
// read on frame at time
|
|
||||||
sz = read(ged->fd, frame, ged->max_frame_size);
|
|
||||||
if (sz >= B_OK) {
|
|
||||||
buffer = g_stack->new_buffer();
|
|
||||||
if (!buffer) {
|
|
||||||
free(frame);
|
|
||||||
status = B_NO_MEMORY;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
g_stack->add_to_buffer(buffer, 0, frame, sz, (buffer_chunk_free_func) free);
|
|
||||||
|
|
||||||
printf("%s: input buffer:\n", me->name);
|
|
||||||
g_stack->dump_buffer(buffer);
|
|
||||||
/*
|
|
||||||
g_stack->add_buffer_attribut(buffer, "ethernet:header", FROM_BUFFER, 0, 14);
|
|
||||||
g_stack->add_buffer_attribut(buffer, "ethernet:to", FROM_BUFFER, 0, 6);
|
|
||||||
g_stack->add_buffer_attribut(buffer, "ethernet:from", FROM_BUFFER, 6, 6);
|
|
||||||
g_stack->add_buffer_attribut(buffer, "ethernet:protocol", FROM_BUFFER | NETWORK_ORDER, 12, 2);
|
|
||||||
*/
|
|
||||||
// strip ethernet header
|
|
||||||
g_stack->remove_from_buffer(buffer, 0, 14);
|
|
||||||
|
|
||||||
if (g_stack->push_buffer_up(me, buffer) != B_OK)
|
|
||||||
// nobody above us *eat* this buffer, so we drop it ourself :-(
|
|
||||||
g_stack->delete_buffer(buffer, false);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
ged->reader_thread = -1;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
status_t std_ops(int32 op, ...)
|
|
||||||
{
|
|
||||||
switch(op) {
|
|
||||||
case B_MODULE_INIT: {
|
|
||||||
status_t status;
|
|
||||||
|
|
||||||
printf("generic_ethernet: B_MODULE_INIT\n");
|
|
||||||
status = get_module(NET_STACK_MODULE_NAME, (module_info **) &g_stack);
|
|
||||||
if (status != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
lookup_devices("/dev/net", NULL);
|
|
||||||
return B_OK;
|
|
||||||
};
|
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
|
||||||
printf("generic_ethernet: B_MODULE_UNINIT\n");
|
|
||||||
put_module(NET_STACK_MODULE_NAME);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct net_layer_module_info nlmi = {
|
|
||||||
{
|
|
||||||
NET_LAYER_MODULES_ROOT "interfaces/generic_ethernet",
|
|
||||||
0,
|
|
||||||
std_ops
|
|
||||||
},
|
|
||||||
|
|
||||||
init,
|
|
||||||
uninit,
|
|
||||||
enable,
|
|
||||||
NULL, // no control()
|
|
||||||
output_buffer,
|
|
||||||
NULL // interface layer: no input_buffer()
|
|
||||||
};
|
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
|
||||||
(module_info*) &nlmi, // net_layer_module_info
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
Binary file not shown.
@@ -1,132 +0,0 @@
|
|||||||
/* ipv4.c - ipv4 protocol module
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <sys/dirent.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <KernelExport.h>
|
|
||||||
#include <ByteOrder.h>
|
|
||||||
|
|
||||||
#include "net_stack.h"
|
|
||||||
|
|
||||||
status_t std_ops(int32 op, ...);
|
|
||||||
|
|
||||||
struct net_layer_module_info nlmi;
|
|
||||||
|
|
||||||
static struct net_stack_module_info *g_stack = NULL;
|
|
||||||
|
|
||||||
net_attribute_id ethernet_protocol_attr;
|
|
||||||
|
|
||||||
// -------------------
|
|
||||||
status_t init(net_layer *me)
|
|
||||||
{
|
|
||||||
printf("%s: initing layer\n", me->name);
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t uninit(net_layer *me)
|
|
||||||
{
|
|
||||||
printf("%s: uniniting layer\n", me->name);
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t enable(net_layer *me, bool enable)
|
|
||||||
{
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t process_input(net_layer *me, net_buffer *buffer)
|
|
||||||
{
|
|
||||||
uint16 *protocol;
|
|
||||||
|
|
||||||
if (!buffer)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
if (g_stack->find_buffer_attribute(buffer, ethernet_protocol_attr, NULL, (void **) &protocol, NULL) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
if (*protocol != htons(0x0800)) // IPv4 on Ethernet protocol value
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
// TODO!
|
|
||||||
dprintf("%s: packet %p is an IPv4 packet!\n", me->name, buffer);
|
|
||||||
g_stack->delete_buffer(buffer, false);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t process_output(net_layer *me, net_buffer *buffer)
|
|
||||||
{
|
|
||||||
if (!buffer)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
// TODO!
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
status_t std_ops(int32 op, ...)
|
|
||||||
{
|
|
||||||
switch(op) {
|
|
||||||
case B_MODULE_INIT: {
|
|
||||||
status_t status;
|
|
||||||
net_layer *layer;
|
|
||||||
|
|
||||||
printf("ipv4: B_MODULE_INIT\n");
|
|
||||||
status = get_module(NET_STACK_MODULE_NAME, (module_info **) &g_stack);
|
|
||||||
if (status != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
ethernet_protocol_attr = g_stack->register_attribute_id("ethernet:protocol");
|
|
||||||
|
|
||||||
status = g_stack->register_layer("IPv4", "ethernet/ipv4", 2, &nlmi, NULL, &layer);
|
|
||||||
if (status != B_OK)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
error:
|
|
||||||
g_stack->unregister_layer(layer);
|
|
||||||
put_module(NET_STACK_MODULE_NAME);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
|
||||||
printf("ipv4: B_MODULE_UNINIT\n");
|
|
||||||
put_module(NET_STACK_MODULE_NAME);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct net_layer_module_info nlmi = {
|
|
||||||
{
|
|
||||||
NET_LAYER_MODULES_ROOT "protocols/ipv4/v0",
|
|
||||||
0,
|
|
||||||
std_ops
|
|
||||||
},
|
|
||||||
|
|
||||||
init,
|
|
||||||
uninit,
|
|
||||||
enable,
|
|
||||||
NULL,
|
|
||||||
process_input,
|
|
||||||
process_output
|
|
||||||
};
|
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
|
||||||
(module_info*) &nlmi, // net_layer_module_info
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
/* loopback.c - loopback interface module
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <KernelExport.h>
|
|
||||||
|
|
||||||
#include "net_stack.h"
|
|
||||||
|
|
||||||
status_t std_ops(int32 op, ...);
|
|
||||||
|
|
||||||
struct net_layer_module_info nlmi;
|
|
||||||
|
|
||||||
static struct net_stack_module_info *g_stack = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------
|
|
||||||
status_t init(net_layer *me)
|
|
||||||
{
|
|
||||||
dprintf("%s: initing layer\n", me->name);
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t uninit(net_layer *me)
|
|
||||||
{
|
|
||||||
dprintf("loopback: uniniting layer\n");
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t enable(net_layer *me, bool enable)
|
|
||||||
{
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t process_output(net_layer *me, net_buffer *buffer)
|
|
||||||
{
|
|
||||||
if (!buffer)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
// Here the magical loopback effect ;-)
|
|
||||||
return g_stack->send_up(me, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
status_t std_ops(int32 op, ...)
|
|
||||||
{
|
|
||||||
switch(op) {
|
|
||||||
case B_MODULE_INIT: {
|
|
||||||
status_t status;
|
|
||||||
|
|
||||||
dprintf("loopback: B_MODULE_INIT\n");
|
|
||||||
status = get_module(NET_STACK_MODULE_NAME, (module_info **) &g_stack);
|
|
||||||
if (status != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
return g_stack->register_layer("loopback", "loopback/frame", 0, &nlmi, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
case B_MODULE_UNINIT:
|
|
||||||
dprintf("loopback: B_MODULE_UNINIT\n");
|
|
||||||
put_module(NET_STACK_MODULE_NAME);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct net_layer_module_info nlmi = {
|
|
||||||
{
|
|
||||||
NET_LAYER_MODULES_ROOT "interfaces/loopback",
|
|
||||||
0,
|
|
||||||
std_ops
|
|
||||||
},
|
|
||||||
|
|
||||||
init,
|
|
||||||
uninit,
|
|
||||||
enable,
|
|
||||||
NULL, // no control()
|
|
||||||
NULL, // interface layer: processing input buffer doesn't make sense!
|
|
||||||
process_output
|
|
||||||
};
|
|
||||||
|
|
||||||
_EXPORT module_info *modules[] = {
|
|
||||||
(module_info*) &nlmi, // net_layer_module_info
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
Binary file not shown.
@@ -6,4 +6,4 @@ Addon <userland>memory_pool : userland generic :
|
|||||||
memory_pool.c
|
memory_pool.c
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs <userland>memory_pool : <installed>stack_tester ;
|
LinkSharedOSLibs <userland>memory_pool : <installed>new_stack_tester ;
|
||||||
|
|||||||
Binary file not shown.
@@ -2,7 +2,7 @@ SubDir OBOS_TOP src tests kits net new_stack stack ;
|
|||||||
|
|
||||||
UseHeaders [ FDirName $(OBOS_TOP) src tests kits net new_stack headers ] ;
|
UseHeaders [ FDirName $(OBOS_TOP) src tests kits net new_stack headers ] ;
|
||||||
|
|
||||||
Addon <userland>stack : userland network_v2 :
|
Addon <v2>stack : userland network_v2 :
|
||||||
stack.c
|
stack.c
|
||||||
attribute.c
|
attribute.c
|
||||||
layers_manager.c
|
layers_manager.c
|
||||||
@@ -11,4 +11,4 @@ Addon <userland>stack : userland network_v2 :
|
|||||||
dump.c
|
dump.c
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs <userland>stack : <installed>stack_tester be ;
|
LinkSharedOSLibs <v2>stack : <installed>new_stack_tester be ;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ status_t start_layers_manager(void)
|
|||||||
set_sem_owner(g_layers.lock, B_SYSTEM_TEAM);
|
set_sem_owner(g_layers.lock, B_SYSTEM_TEAM);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Load all network/interfaces/* modules and let them
|
// Load all network/* modules and let them
|
||||||
// register any layer they may support by calling init()
|
// register any layer they may support by calling init()
|
||||||
module_list = open_module_list(NET_MODULES_ROOT);
|
module_list = open_module_list(NET_MODULES_ROOT);
|
||||||
if (module_list) {
|
if (module_list) {
|
||||||
@@ -68,12 +68,15 @@ status_t start_layers_manager(void)
|
|||||||
if (!strlen(module_name))
|
if (!strlen(module_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (strcmp(module_name, NET_STACK_MODULE_NAME) == 0)
|
||||||
|
continue; // skip ourself! ;-)
|
||||||
|
|
||||||
dprintf("layers_manager: loading %s layer(s) module\n", module_name);
|
dprintf("layers_manager: loading %s layer(s) module\n", module_name);
|
||||||
if (get_module(module_name, (module_info **) &nlmi) != B_OK)
|
if (get_module(module_name, (module_info **) &nlmi) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// this module may have been acquire more time by calling register_layer()
|
// this module may have been acquire more time if he called register_layer(),
|
||||||
// or have B_KEEP_LOADED flag, so we don't care...
|
// or have a B_KEEP_LOADED flag, so we don't care...
|
||||||
put_module(module_name);
|
put_module(module_name);
|
||||||
};
|
};
|
||||||
close_module_list(module_list);
|
close_module_list(module_list);
|
||||||
|
|||||||
Reference in New Issue
Block a user