mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
Removed bcast_all, src_filter and iface_mode options. The former two are now
implemented by the wildcard interface.
This commit is contained in:
parent
6c1ab421da
commit
1f77b0f90e
14
src/config.c
14
src/config.c
@ -30,14 +30,10 @@ main_config_t get_main_config(void)
|
|||||||
config.udp_port = DEFAULT_PORT;
|
config.udp_port = DEFAULT_PORT;
|
||||||
config.router_port = DEFAULT_ROUTER_PORT;
|
config.router_port = DEFAULT_ROUTER_PORT;
|
||||||
config.w95_bug = true;
|
config.w95_bug = true;
|
||||||
config.bcast_all = false;
|
|
||||||
config.src_filter = true;
|
|
||||||
|
|
||||||
HKEY reg = reg_open_main(false);
|
HKEY reg = reg_open_main(false);
|
||||||
DWORD version = reg_get_dword(reg, "config_version", 1);
|
DWORD version = reg_get_dword(reg, "config_version", 1);
|
||||||
|
|
||||||
config.iface_mode = reg_get_dword(reg, "iface_mode", IFACE_MODE_ALL);
|
|
||||||
|
|
||||||
if(version == 1)
|
if(version == 1)
|
||||||
{
|
{
|
||||||
struct v1_global_config reg_config;
|
struct v1_global_config reg_config;
|
||||||
@ -46,8 +42,6 @@ main_config_t get_main_config(void)
|
|||||||
{
|
{
|
||||||
config.udp_port = reg_config.udp_port;
|
config.udp_port = reg_config.udp_port;
|
||||||
config.w95_bug = reg_config.w95_bug;
|
config.w95_bug = reg_config.w95_bug;
|
||||||
config.bcast_all = reg_config.bcast_all;
|
|
||||||
config.src_filter = reg_config.filter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config.router_port = reg_get_dword(reg, "control_port", config.router_port);
|
config.router_port = reg_get_dword(reg, "control_port", config.router_port);
|
||||||
@ -59,8 +53,6 @@ main_config_t get_main_config(void)
|
|||||||
config.udp_port = reg_get_dword(reg, "port", config.udp_port);
|
config.udp_port = reg_get_dword(reg, "port", config.udp_port);
|
||||||
config.router_port = reg_get_dword(reg, "router_port", config.router_port);
|
config.router_port = reg_get_dword(reg, "router_port", config.router_port);
|
||||||
config.w95_bug = reg_get_dword(reg, "w95_bug", config.w95_bug);
|
config.w95_bug = reg_get_dword(reg, "w95_bug", config.w95_bug);
|
||||||
config.bcast_all = reg_get_dword(reg, "bcast_all", config.bcast_all);
|
|
||||||
config.src_filter = reg_get_dword(reg, "src_filter", config.src_filter);
|
|
||||||
|
|
||||||
config.log_level = reg_get_dword(reg, "log_level", LOG_INFO);
|
config.log_level = reg_get_dword(reg, "log_level", LOG_INFO);
|
||||||
}
|
}
|
||||||
@ -74,13 +66,9 @@ bool set_main_config(const main_config_t *config)
|
|||||||
{
|
{
|
||||||
HKEY reg = reg_open_main(true);
|
HKEY reg = reg_open_main(true);
|
||||||
|
|
||||||
bool ok = reg_set_dword(reg, "iface_mode", config->iface_mode)
|
bool ok = reg_set_dword(reg, "port", config->udp_port)
|
||||||
|
|
||||||
&& reg_set_dword(reg, "port", config->udp_port)
|
|
||||||
&& reg_set_dword(reg, "router_port", config->router_port)
|
&& reg_set_dword(reg, "router_port", config->router_port)
|
||||||
&& reg_set_dword(reg, "w95_bug", config->w95_bug)
|
&& reg_set_dword(reg, "w95_bug", config->w95_bug)
|
||||||
&& reg_set_dword(reg, "bcast_all", config->bcast_all)
|
|
||||||
&& reg_set_dword(reg, "src_filter", config->src_filter)
|
|
||||||
|
|
||||||
&& reg_set_dword(reg, "log_level", config->log_level)
|
&& reg_set_dword(reg, "log_level", config->log_level)
|
||||||
|
|
||||||
|
24
src/config.h
24
src/config.h
@ -21,26 +21,6 @@
|
|||||||
#define DEFAULT_PORT 54792
|
#define DEFAULT_PORT 54792
|
||||||
#define DEFAULT_ROUTER_PORT 54793
|
#define DEFAULT_ROUTER_PORT 54793
|
||||||
|
|
||||||
/* IFACE_MODE_ALL
|
|
||||||
*
|
|
||||||
* Packets are sent/received on all interfaces and no source address filtering
|
|
||||||
* is performed. A single IPX interface is presented.
|
|
||||||
*
|
|
||||||
* IFACE_MODE_SINGLE
|
|
||||||
*
|
|
||||||
* Packets are sent/received on user-chosen interfaces. A single IPX interface
|
|
||||||
* is presented.
|
|
||||||
*
|
|
||||||
* IFACE_MODE_MULTI
|
|
||||||
*
|
|
||||||
* An IPX interface is presented for each (enabled) real interface and packets
|
|
||||||
* are sent or received on the single underlying interface of the IPX one.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define IFACE_MODE_ALL 1
|
|
||||||
#define IFACE_MODE_SINGLE 2
|
|
||||||
#define IFACE_MODE_MULTI 3
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -52,12 +32,8 @@ typedef struct main_config {
|
|||||||
uint16_t router_port;
|
uint16_t router_port;
|
||||||
|
|
||||||
bool w95_bug;
|
bool w95_bug;
|
||||||
bool bcast_all;
|
|
||||||
bool src_filter;
|
|
||||||
|
|
||||||
enum ipx_log_level log_level;
|
enum ipx_log_level log_level;
|
||||||
|
|
||||||
int iface_mode;
|
|
||||||
} main_config_t;
|
} main_config_t;
|
||||||
|
|
||||||
struct v1_global_config {
|
struct v1_global_config {
|
||||||
|
71
src/router.c
71
src/router.c
@ -304,51 +304,48 @@ DWORD router_main(void *arg) {
|
|||||||
addr32_t ra_net = addr32_in(ra->addr.sa_netnum);
|
addr32_t ra_net = addr32_in(ra->addr.sa_netnum);
|
||||||
addr48_t ra_node = addr48_in(ra->addr.sa_nodenum);
|
addr48_t ra_node = addr48_in(ra->addr.sa_nodenum);
|
||||||
|
|
||||||
/* Check source address */
|
/* Fetch the interface this socket is bound to. */
|
||||||
|
|
||||||
if(main_config.iface_mode != IFACE_MODE_ALL)
|
ipx_interface_t *iface = ipx_interface_by_addr(ra_net, ra_node);
|
||||||
|
|
||||||
|
if(!iface)
|
||||||
{
|
{
|
||||||
/* Fetch the interface this socket is bound to. */
|
char net_s[ADDR32_STRING_SIZE], node_s[ADDR48_STRING_SIZE];
|
||||||
|
|
||||||
ipx_interface_t *iface = ipx_interface_by_addr(ra_net, ra_node);
|
addr32_string(net_s, ra_net);
|
||||||
|
addr48_string(node_s, ra_node);
|
||||||
|
|
||||||
if(!iface)
|
log_printf(LOG_WARNING, "No iface for %s/%s! Stale bind?", net_s, node_s);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Iterate over the subnets and compare to the
|
||||||
|
* packet source IP address.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ipx_interface_ip_t *ip;
|
||||||
|
|
||||||
|
int source_ok = 0;
|
||||||
|
|
||||||
|
DL_FOREACH(iface->ipaddr, ip)
|
||||||
|
{
|
||||||
|
if((ip->ipaddr & ip->netmask) == (addr.sin_addr.s_addr & ip->netmask))
|
||||||
{
|
{
|
||||||
char net_s[ADDR32_STRING_SIZE], node_s[ADDR48_STRING_SIZE];
|
source_ok = 1;
|
||||||
|
break;
|
||||||
addr32_string(net_s, ra_net);
|
|
||||||
addr48_string(node_s, ra_node);
|
|
||||||
|
|
||||||
log_printf(LOG_WARNING, "No iface for %s/%s! Stale bind?", net_s, node_s);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Iterate over the subnets and compare
|
|
||||||
* to the packet source address.
|
free_ipx_interface(iface);
|
||||||
|
|
||||||
|
if(!source_ok)
|
||||||
|
{
|
||||||
|
/* Packet did not originate from an
|
||||||
|
* associated network.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipx_interface_ip_t *ip;
|
continue;
|
||||||
|
|
||||||
int source_ok = 0;
|
|
||||||
|
|
||||||
DL_FOREACH(iface->ipaddr, ip)
|
|
||||||
{
|
|
||||||
if((ip->ipaddr & ip->netmask) == (addr.sin_addr.s_addr & ip->netmask))
|
|
||||||
{
|
|
||||||
source_ok = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free_ipx_interface(iface);
|
|
||||||
|
|
||||||
if(!source_ok)
|
|
||||||
{
|
|
||||||
/* Source matching failed. */
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log_printf(LOG_DEBUG, "Relaying packet to local port %hu", ntohs(ra->local_port));
|
log_printf(LOG_DEBUG, "Relaying packet to local port %hu", ntohs(ra->local_port));
|
||||||
|
@ -724,7 +724,7 @@ static int send_packet(const ipx_packet *packet, int len, struct sockaddr *addr,
|
|||||||
packet->dest_socket
|
packet->dest_socket
|
||||||
);
|
);
|
||||||
|
|
||||||
log_printf(LOG_DEBUG, "Sending packet to %s (%s)", addr_s, inet_ntoa(v4->sin_addr));
|
log_printf(LOG_DEBUG, "Sending packet to %s (%s:%hu)", addr_s, inet_ntoa(v4->sin_addr), ntohs(v4->sin_port));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (r_sendto(send_fd, (char*)packet, len, 0, addr, addrlen) == len);
|
return (r_sendto(send_fd, (char*)packet, len, 0, addr, addrlen) == len);
|
||||||
@ -818,63 +818,45 @@ int WSAAPI sendto(SOCKET fd, const char *buf, int len, int flags, const struct s
|
|||||||
else{
|
else{
|
||||||
/* No cached address. Send using broadcast. */
|
/* No cached address. Send using broadcast. */
|
||||||
|
|
||||||
struct sockaddr_in bcast;
|
ipx_interface_t *iface = ipx_interface_by_addr(
|
||||||
|
addr32_in(packet->src_net),
|
||||||
|
addr48_in(packet->src_node)
|
||||||
|
);
|
||||||
|
|
||||||
bcast.sin_family = AF_INET;
|
if(iface && iface->ipaddr)
|
||||||
bcast.sin_port = htons(main_config.udp_port);
|
|
||||||
|
|
||||||
if(main_config.bcast_all)
|
|
||||||
{
|
{
|
||||||
/* Broadcast on all interfaces. */
|
/* Iterate over all the IPs associated
|
||||||
|
* with this interface and return
|
||||||
|
* success if the packet makes it out
|
||||||
|
* through any of them.
|
||||||
|
*/
|
||||||
|
|
||||||
bcast.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
ipx_interface_ip_t* ip;
|
||||||
|
|
||||||
success = send_packet(
|
DL_FOREACH(iface->ipaddr, ip)
|
||||||
packet,
|
{
|
||||||
psize,
|
struct sockaddr_in bcast;
|
||||||
(struct sockaddr*)(&bcast),
|
|
||||||
sizeof(bcast)
|
bcast.sin_family = AF_INET;
|
||||||
);
|
bcast.sin_port = htons(main_config.udp_port);
|
||||||
|
bcast.sin_addr.s_addr = ip->bcast;
|
||||||
|
|
||||||
|
success |= send_packet(
|
||||||
|
packet,
|
||||||
|
psize,
|
||||||
|
(struct sockaddr*)(&bcast),
|
||||||
|
sizeof(bcast)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/* Broadcast on associated interfaces. */
|
/* No IP addresses. */
|
||||||
|
|
||||||
ipx_interface_t *iface = ipx_interface_by_addr(
|
WSASetLastError(WSAENETDOWN);
|
||||||
addr32_in(packet->src_net),
|
success = 0;
|
||||||
addr48_in(packet->src_node)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(iface && iface->ipaddr)
|
|
||||||
{
|
|
||||||
/* Iterate over all the IPs associated
|
|
||||||
* with this interface and return
|
|
||||||
* success if the packet makes it out
|
|
||||||
* through any of them.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ipx_interface_ip_t* ip;
|
|
||||||
|
|
||||||
DL_FOREACH(iface->ipaddr, ip)
|
|
||||||
{
|
|
||||||
bcast.sin_addr.s_addr = ip->bcast;
|
|
||||||
|
|
||||||
success |= send_packet(
|
|
||||||
packet,
|
|
||||||
psize,
|
|
||||||
(struct sockaddr*)(&bcast),
|
|
||||||
sizeof(bcast)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
/* No IP addresses. */
|
|
||||||
|
|
||||||
WSASetLastError(WSAENETDOWN);
|
|
||||||
success = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
free_ipx_interface(iface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free_ipx_interface(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(packet);
|
free(packet);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user