mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
New router code nearing completion.
This commit is contained in:
parent
2674e3356f
commit
bcbaea33c4
@ -53,7 +53,6 @@ static DWORD router_tid = 0;
|
|||||||
|
|
||||||
static int init_router(void);
|
static int init_router(void);
|
||||||
static DWORD WINAPI router_main(LPVOID argp);
|
static DWORD WINAPI router_main(LPVOID argp);
|
||||||
static void add_host(const unsigned char *net, const unsigned char *node, uint32_t ipaddr);
|
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE me, DWORD why, LPVOID res) {
|
BOOL WINAPI DllMain(HINSTANCE me, DWORD why, LPVOID res) {
|
||||||
if(why == DLL_PROCESS_ATTACH) {
|
if(why == DLL_PROCESS_ATTACH) {
|
||||||
@ -323,7 +322,7 @@ static DWORD WINAPI router_main(LPVOID notused) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add a host to the hosts list or update an existing one */
|
/* Add a host to the hosts list or update an existing one */
|
||||||
static void add_host(const unsigned char *net, const unsigned char *node, uint32_t ipaddr) {
|
void add_host(const unsigned char *net, const unsigned char *node, uint32_t ipaddr) {
|
||||||
ipx_host *hptr = hosts;
|
ipx_host *hptr = hosts;
|
||||||
|
|
||||||
while(hptr) {
|
while(hptr) {
|
||||||
|
@ -117,6 +117,7 @@ ipx_socket *get_socket(SOCKET fd);
|
|||||||
void lock_mutex(void);
|
void lock_mutex(void);
|
||||||
void unlock_mutex(void);
|
void unlock_mutex(void);
|
||||||
ipx_host *find_host(const unsigned char *net, const unsigned char *node);
|
ipx_host *find_host(const unsigned char *net, const unsigned char *node);
|
||||||
|
void add_host(const unsigned char *net, const unsigned char *node, uint32_t ipaddr);
|
||||||
|
|
||||||
void log_open();
|
void log_open();
|
||||||
void log_close();
|
void log_close();
|
||||||
|
55
src/router.c
55
src/router.c
@ -21,6 +21,7 @@
|
|||||||
#include "router.h"
|
#include "router.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "ipxwrapper.h"
|
#include "ipxwrapper.h"
|
||||||
|
#include "interface.h"
|
||||||
|
|
||||||
/* Allocate router_vars structure and initialise all members
|
/* Allocate router_vars structure and initialise all members
|
||||||
* Returns NULL on failure
|
* Returns NULL on failure
|
||||||
@ -165,7 +166,59 @@ DWORD router_main(void *arg) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Deliver packet */
|
ipx_packet *packet = (ipx_packet*)router->recvbuf;
|
||||||
|
|
||||||
|
/* Check that the packet arrived from the subnet of an enabled network
|
||||||
|
* interface and drop it if not.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(global_conf.filter) {
|
||||||
|
struct ipx_interface *iface = router->interfaces;
|
||||||
|
|
||||||
|
while(iface) {
|
||||||
|
if((iface->ipaddr & iface->netmask) == (addr.sin_addr.s_addr & iface->netmask)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
iface = iface->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!iface) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
packet->size = ntohs(packet->size);
|
||||||
|
|
||||||
|
if(packet->size > MAX_PACKET_SIZE || packet->size + sizeof(ipx_packet) - 1 != len) {
|
||||||
|
log_printf("Recieved packet with incorrect size field, discarding");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_host(packet->src_net, packet->src_node, addr.sin_addr.s_addr);
|
||||||
|
|
||||||
|
struct router_addr *ra = router->addrs;
|
||||||
|
|
||||||
|
while(ra) {
|
||||||
|
unsigned char f6[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
|
||||||
|
|
||||||
|
/* TODO: Packet type filter and shutdown checks */
|
||||||
|
|
||||||
|
if(
|
||||||
|
(memcmp(packet->dest_net, ra->addr.sa_netnum, 4) == 0 || memcmp(packet->dest_net, f6, 4) == 0) &&
|
||||||
|
(memcmp(packet->dest_node, ra->addr.sa_nodenum, 6) == 0 || memcmp(packet->dest_node, f6, 6) == 0) &&
|
||||||
|
packet->dest_socket == ra->addr.sa_socket
|
||||||
|
) {
|
||||||
|
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||||
|
addr.sin_port = htons(ra->local_port);
|
||||||
|
|
||||||
|
if(sendto(router->udp_sock, (char*)packet, len, 0, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
||||||
|
log_printf("Error relaying packet: %s", w32_error(WSAGetLastError()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ra = ra->next;
|
||||||
|
}
|
||||||
|
|
||||||
LeaveCriticalSection(&(router->crit_sec));
|
LeaveCriticalSection(&(router->crit_sec));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user