Check-in recent changes.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4816 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6f073e3ca9
commit
9c63790cc5
@ -1,11 +1,11 @@
|
||||
Jampfiles should replace these BeIDE projects files in the future.
|
||||
But, beware:
|
||||
- the net_server binary should be symlinked as _APP_ in each sub-drectories, so
|
||||
- the net_stack_server binary should be symlinked as _APP_ in each sub-drectories, so
|
||||
each module can be linked against it to find the kernel module API exported in this app.
|
||||
- the net_server will try to load the modules from a local add-ons folder, which should
|
||||
- the net_stack_server will try to load the modules from a local add-ons folder, which should
|
||||
be setup by hands today: please symlink each module like this:
|
||||
|
||||
net_server
|
||||
net_stack_server
|
||||
add-ons\
|
||||
generic\
|
||||
memory_pool -> ../../memory_pool/memory_pool
|
||||
|
@ -42,10 +42,20 @@ status_t enable(net_layer *me, bool enable)
|
||||
|
||||
status_t input_buffer(net_layer *me, net_buffer *buffer)
|
||||
{
|
||||
// uint16 *protocol;
|
||||
|
||||
if (!buffer)
|
||||
return B_ERROR;
|
||||
|
||||
/*
|
||||
if (g_stack->find_buffer_attribut(buffer, "ethernet:protocol", &protocol) != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
if (protocol != 0x0806)
|
||||
// Not an ARP packet
|
||||
return B_ERROR;
|
||||
*/
|
||||
// TODO!
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,124 +0,0 @@
|
||||
/* net_interface.h
|
||||
* definitions of interface networking module API
|
||||
*/
|
||||
|
||||
#ifndef OBOS_NET_INTERFACE_H
|
||||
#define OBOS_NET_INTERFACE_H
|
||||
|
||||
#include <drivers/module.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct net_buffer;
|
||||
|
||||
typedef struct if_data {
|
||||
/* generic interface information */
|
||||
// ifmedia_t ifi_media; /* media, see if_media.h */
|
||||
uint8 ifi_type; /* ethernet, tokenring, etc */
|
||||
uint8 ifi_addrlen; /* media address length */
|
||||
uint8 ifi_hdrlen; /* media header length */
|
||||
uint32 ifi_mtu; /* maximum transmission unit */
|
||||
/* this does not count framing; */
|
||||
/* e.g. ethernet would be 1500 */
|
||||
uint32 ifi_metric; /* routing metric (external only) */
|
||||
/* volatile statistics */
|
||||
uint32 ifi_ipackets; /* packets received on interface */
|
||||
uint32 ifi_ierrors; /* input errors on interface */
|
||||
uint32 ifi_opackets; /* packets sent on interface */
|
||||
uint32 ifi_oerrors; /* output errors on interface */
|
||||
uint32 ifi_collisions; /* collisions on csma interfaces */
|
||||
uint32 ifi_ibytes; /* total number of octets received */
|
||||
uint32 ifi_obytes; /* total number of octets sent */
|
||||
uint32 ifi_imcasts; /* packets received via multicast */
|
||||
uint32 ifi_omcasts; /* packets sent via multicast */
|
||||
uint32 ifi_iqdrops; /* dropped on input, this interface */
|
||||
uint32 ifi_noproto; /* destined for unsupported protocol */
|
||||
bigtime_t ifi_lastchange; /* time of last administrative change */
|
||||
} ifdata_t;
|
||||
|
||||
#define if_mtu if_data.ifi_mtu
|
||||
#define if_type if_data.ifi_type
|
||||
#define if_media if_data.ifi_media
|
||||
#define if_addrlen if_data.ifi_addrlen
|
||||
#define if_hdrlen if_data.ifi_hdrlen
|
||||
#define if_metric if_data.ifi_metric
|
||||
#define if_baudrate if_data.ifi_baudrate
|
||||
#define if_ipackets if_data.ifi_ipackets
|
||||
#define if_ierrors if_data.ifi_ierrors
|
||||
#define if_opackets if_data.ifi_opackets
|
||||
#define if_oerrors if_data.ifi_oerrors
|
||||
#define if_collisions if_data.ifi_collisions
|
||||
#define if_ibytes if_data.ifi_ibytes
|
||||
#define if_obytes if_data.ifi_obytes
|
||||
#define if_imcasts if_data.ifi_imcasts
|
||||
#define if_omcasts if_data.ifi_omcasts
|
||||
#define if_noproto if_data.ifi_noproto
|
||||
#define if_lastchange if_data.ifi_lastchange
|
||||
|
||||
|
||||
|
||||
#define IFF_UP 0x1 /* interface is up */
|
||||
#define IFF_BROADCAST 0x2 /* broadcast address valid */
|
||||
#define IFF_DEBUG 0x4 /* turn on debugging */
|
||||
#define IFF_LOOPBACK 0x8 /* is a loopback net */
|
||||
#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
|
||||
#define IFF_PTP IFF_POINTOPOINT
|
||||
#define IFF_NOARP 0x40 /* don't arp */
|
||||
#define IFF_AUTOUP 0x80 /* for autodial ppp - anytime the interface is downed, it will immediately be re-upped by the datalink */
|
||||
#define IFF_PROMISC 0x100 /* receive all packets */
|
||||
#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
|
||||
#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
|
||||
#define IFF_MULTICAST 0x8000 /* supports multicast */
|
||||
|
||||
/* flags set internally only: */
|
||||
#define IFF_CANTCHANGE (IFF_BROADCAST|IFF_LOOPBACK|IFF_POINTOPOINT| \
|
||||
IFF_NOARP|IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
|
||||
|
||||
|
||||
|
||||
typedef struct ifnet {
|
||||
struct ifnet *if_next;
|
||||
char *if_name;
|
||||
uint32 if_flags;
|
||||
struct net_interface_module_info *module;
|
||||
struct if_data if_data;
|
||||
volatile thread_id if_reader_thread;
|
||||
} ifnet_t;
|
||||
|
||||
typedef struct net_interface_hwaddr {
|
||||
uint32 len;
|
||||
uint8 hwaddr[256];
|
||||
} net_interface_hwaddr;
|
||||
|
||||
struct net_interface_module_info {
|
||||
module_info info;
|
||||
|
||||
status_t (*init)(void * params);
|
||||
status_t (*uninit)(ifnet_t *ifnet);
|
||||
|
||||
status_t (*up)(ifnet_t *ifnet);
|
||||
status_t (*down)(ifnet_t *ifnet);
|
||||
|
||||
status_t (*send_buffer)(ifnet_t *ifnet, struct net_buffer *buffer);
|
||||
status_t (*receive_buffer)(ifnet_t *ifnet, struct net_buffer **buffer);
|
||||
|
||||
status_t (*control)(ifnet_t *ifnet, int opcode, void *arg);
|
||||
|
||||
status_t (*get_hardware_address)(ifnet_t *ifnet, net_interface_hwaddr *hwaddr);
|
||||
status_t (*get_multicast_addresses)(ifnet_t *ifnet, net_interface_hwaddr **hwaddr, int nb_addresses);
|
||||
status_t (*set_multicast_addresses)(ifnet_t *ifnet, net_interface_hwaddr *hwaddr, int nb_addresses);
|
||||
|
||||
status_t (*set_mtu)(ifnet_t *ifnet, uint32 mtu);
|
||||
status_t (*set_promiscuous)(ifnet_t *ifnet, bool enable);
|
||||
status_t (*set_media)(ifnet_t *ifnet, uint32 media);
|
||||
};
|
||||
|
||||
#define NET_INTERFACE_MODULE_ROOT "network/interfaces/"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OBOS_NET_INTERFACE_H */
|
@ -1,43 +0,0 @@
|
||||
/* net_layer.h
|
||||
* definitions of networking layer(s) API
|
||||
*/
|
||||
|
||||
#ifndef OBOS_NET_LAYER_H
|
||||
#define OBOS_NET_LAYER_H
|
||||
|
||||
#include <drivers/module.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct net_buffer;
|
||||
|
||||
typedef struct net_layer {
|
||||
struct net_layer *next;
|
||||
char *name;
|
||||
int level;
|
||||
uint32 kind; // Filter, consumer, producer, etc...
|
||||
int chaining_constraint;
|
||||
struct net_layer_module_info *module;
|
||||
struct net_layer **layers_above;
|
||||
struct net_layer **layers_below;
|
||||
} net_layer;
|
||||
|
||||
struct net_layer_module_info {
|
||||
module_info info;
|
||||
|
||||
status_t (*init)(void * params);
|
||||
status_t (*uninit)(net_layer *me);
|
||||
status_t (*enable)(net_layer *me, bool enable);
|
||||
status_t (*input_buffer)(net_layer *me, struct net_buffer *buffer);
|
||||
status_t (*output_buffer)(net_layer *me, struct net_buffer *buffer);
|
||||
};
|
||||
|
||||
#define NET_LAYER_MODULE_ROOT "network/layers/"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OBOS_NET_LAYER_H */
|
@ -1,17 +0,0 @@
|
||||
/* net_protocol.h
|
||||
* definitions of protocol networking module API
|
||||
*/
|
||||
|
||||
#ifndef OBOS_NET_PROTOCOL_H
|
||||
#define OBOS_NET_PROTOCOL_H
|
||||
|
||||
#include <drivers/module.h>
|
||||
|
||||
struct net_protocol_module_info {
|
||||
module_info module;
|
||||
|
||||
};
|
||||
|
||||
#define NET_PROTOCOL_MODULE_ROOT "network/protocols/"
|
||||
|
||||
#endif /* OBOS_NET_PROTOCOL_H */
|
@ -1,254 +0,0 @@
|
||||
/* core.c */
|
||||
|
||||
/* This the heart of network stack
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <KernelExport.h>
|
||||
#include <OS.h>
|
||||
|
||||
#include "datalink.h"
|
||||
#include "buffer.h"
|
||||
|
||||
/* Defines we need */
|
||||
#define NETWORK_INTERFACES "network/interfaces"
|
||||
#define NETWORK_PROTOCOLS "network/protocols"
|
||||
|
||||
struct interfaces_list {
|
||||
ifnet_t *first;
|
||||
sem_id lock;
|
||||
};
|
||||
|
||||
static struct interfaces_list g_interfaces;
|
||||
|
||||
status_t enable_interface(ifnet_t *iface, bool enable);
|
||||
status_t interface_reader(void *args);
|
||||
|
||||
|
||||
// #pragma mark [Start/Stop functions]
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
status_t start_datalink_layer()
|
||||
{
|
||||
void *module_list;
|
||||
ifnet_t *iface;
|
||||
|
||||
g_interfaces.first = NULL;
|
||||
|
||||
g_interfaces.lock = create_sem(1, "net_interfaces list lock");
|
||||
if (g_interfaces.lock < B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
set_sem_owner(g_interfaces.lock, B_SYSTEM_TEAM);
|
||||
#endif
|
||||
|
||||
// Load all network/interfaces/* modules and let them
|
||||
// register any interface they may support by calling init()
|
||||
module_list = open_module_list(NET_INTERFACE_MODULE_ROOT);
|
||||
if (module_list) {
|
||||
size_t sz;
|
||||
char module_name[256];
|
||||
struct net_interface_module_info *nimi;
|
||||
|
||||
sz = sizeof(module_name);
|
||||
while(read_next_module_name(module_list, module_name, &sz) == B_OK) {
|
||||
if (strlen(module_name) && get_module(module_name, (module_info **) &nimi) == B_OK) {
|
||||
printf("datalink: initing %s interface module...\n", module_name);
|
||||
// allow this module to register one or more interfaces
|
||||
nimi->init(NULL);
|
||||
};
|
||||
sz = sizeof(module_name);
|
||||
};
|
||||
close_module_list(module_list);
|
||||
};
|
||||
|
||||
// auto-start interface(s)
|
||||
acquire_sem(g_interfaces.lock);
|
||||
iface = g_interfaces.first;
|
||||
while (iface) {
|
||||
enable_interface(iface, true);
|
||||
iface = iface->if_next;
|
||||
};
|
||||
release_sem(g_interfaces.lock);
|
||||
|
||||
puts("net datalink layer started.");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
status_t stop_datalink_layer()
|
||||
{
|
||||
ifnet_t *iface, *next;
|
||||
|
||||
delete_sem(g_interfaces.lock);
|
||||
g_interfaces.lock = -1;
|
||||
|
||||
// free the remaining interfaces entries
|
||||
iface = g_interfaces.first;
|
||||
while (iface) {
|
||||
printf("datalink: uninit interface %s\n", iface->if_name);
|
||||
// down the interface if currently up
|
||||
enable_interface(iface, false);
|
||||
|
||||
iface->module->uninit(iface);
|
||||
iface = iface->if_next;
|
||||
};
|
||||
|
||||
// unload all interface modules... and free iface structs
|
||||
iface = g_interfaces.first;
|
||||
while (iface) {
|
||||
printf("datalink: unloading %s interface module\n", iface->module->info.name);
|
||||
next = iface->if_next;
|
||||
put_module(iface->module->info.name);
|
||||
free(iface);
|
||||
iface = next;
|
||||
};
|
||||
|
||||
puts("net datalink layer stopped.");
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// #pragma mark [Public functions]
|
||||
|
||||
// --------------------------------------------------
|
||||
status_t register_interface(ifnet_t *iface)
|
||||
{
|
||||
status_t status;
|
||||
|
||||
if (!iface)
|
||||
return B_ERROR;
|
||||
|
||||
iface->if_reader_thread = -1;
|
||||
|
||||
status = acquire_sem(g_interfaces.lock);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
iface->if_next = g_interfaces.first;
|
||||
g_interfaces.first = iface;
|
||||
|
||||
release_sem(g_interfaces.lock);
|
||||
|
||||
printf("datalink: register_interface(%s)\n", iface->if_name);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
status_t unregister_interface(ifnet_t *iface)
|
||||
{
|
||||
status_t status;
|
||||
|
||||
if (!iface)
|
||||
return B_ERROR;
|
||||
|
||||
status = acquire_sem(g_interfaces.lock);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
if (g_interfaces.first == iface)
|
||||
g_interfaces.first = iface->if_next;
|
||||
else {
|
||||
ifnet_t * p = g_interfaces.first;
|
||||
while (p && p->if_next != iface)
|
||||
p = p->if_next;
|
||||
|
||||
if (!p)
|
||||
printf("datalink: unregister_interface(): %p iface not found in list!\n", iface);
|
||||
else
|
||||
p->if_next = iface->if_next;
|
||||
};
|
||||
|
||||
release_sem(g_interfaces.lock);
|
||||
|
||||
printf("datalink: unregister_interface(%s)\n", iface->if_name);
|
||||
|
||||
enable_interface(iface, false);
|
||||
iface->module->uninit(iface);
|
||||
put_module(iface->module->info.name);
|
||||
free(iface);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
status_t enable_interface(ifnet_t *iface, bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
// enable this interface
|
||||
thread_id tid;
|
||||
char name[B_OS_NAME_LENGTH * 2];
|
||||
|
||||
if (iface->if_flags & IFF_UP)
|
||||
// already up
|
||||
return B_OK;
|
||||
|
||||
iface->module->up(iface);
|
||||
|
||||
strncpy(name, iface->if_name, sizeof(name));
|
||||
strncat(name, " reader", sizeof(name));
|
||||
tid = spawn_kernel_thread(interface_reader, name, B_NORMAL_PRIORITY, iface);
|
||||
if (tid < 0) {
|
||||
printf("datalink: enable_interface(%s): failed to start reader thread -> %d [%s]\n",
|
||||
iface->if_name, (int) tid, strerror(tid));
|
||||
return tid;
|
||||
};
|
||||
|
||||
iface->if_reader_thread = tid;
|
||||
iface->if_flags |= IFF_UP;
|
||||
printf("datalink: %s interface reader started.\n", iface->if_name);
|
||||
return resume_thread(tid);
|
||||
|
||||
} else {
|
||||
|
||||
// disable this interface
|
||||
if ((iface->if_flags & IFF_UP) == 0)
|
||||
// already down
|
||||
return B_OK;
|
||||
|
||||
if (iface->if_reader_thread) {
|
||||
status_t status;
|
||||
|
||||
send_signal_etc(iface->if_reader_thread, SIGTERM, 0);
|
||||
wait_for_thread(iface->if_reader_thread, &status);
|
||||
iface->if_reader_thread = -1;
|
||||
printf("datalink: %s interface reader stopped.\n", iface->if_name);
|
||||
};
|
||||
|
||||
iface->if_flags &= ~IFF_UP;
|
||||
return iface->module->down(iface);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
status_t interface_reader(void *args)
|
||||
{
|
||||
ifnet_t *iface = args;
|
||||
net_buffer *buffer;
|
||||
status_t status;
|
||||
|
||||
if (!iface || iface->module == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
while(iface->if_flags & IFF_UP) {
|
||||
buffer = NULL;
|
||||
status = iface->module->receive_buffer(iface, &buffer);
|
||||
if (status < B_OK || buffer == NULL)
|
||||
continue;
|
||||
|
||||
dump_buffer(buffer);
|
||||
delete_buffer(buffer, false);
|
||||
};
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
/* datalink.h
|
||||
* private definitions for network datalink layer
|
||||
*/
|
||||
|
||||
#ifndef OBOS_NET_STACK_DATALINK_H
|
||||
#define OBOS_NET_STACK_DATALINK_H
|
||||
|
||||
#include "net_interface.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern status_t start_datalink_layer();
|
||||
extern status_t stop_datalink_layer();
|
||||
|
||||
extern status_t register_interface(ifnet_t *ifnet);
|
||||
extern status_t unregister_interface(ifnet_t *ifnet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OBOS_NET_STACK_DATALINK_H */
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user