From 1f77b0f90e358f6d483b152aeb920ffc74220790 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Sat, 10 Nov 2012 22:24:47 +0000 Subject: [PATCH] Removed bcast_all, src_filter and iface_mode options. The former two are now implemented by the wildcard interface. --- src/config.c | 14 +-------- src/config.h | 24 --------------- src/router.c | 71 +++++++++++++++++++++----------------------- src/winsock.c | 82 ++++++++++++++++++++------------------------------- 4 files changed, 67 insertions(+), 124 deletions(-) diff --git a/src/config.c b/src/config.c index f031f8a..da0f0e6 100644 --- a/src/config.c +++ b/src/config.c @@ -30,14 +30,10 @@ main_config_t get_main_config(void) config.udp_port = DEFAULT_PORT; config.router_port = DEFAULT_ROUTER_PORT; config.w95_bug = true; - config.bcast_all = false; - config.src_filter = true; HKEY reg = reg_open_main(false); DWORD version = reg_get_dword(reg, "config_version", 1); - config.iface_mode = reg_get_dword(reg, "iface_mode", IFACE_MODE_ALL); - if(version == 1) { 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.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); @@ -59,8 +53,6 @@ main_config_t get_main_config(void) config.udp_port = reg_get_dword(reg, "port", config.udp_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.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); } @@ -74,13 +66,9 @@ bool set_main_config(const main_config_t *config) { HKEY reg = reg_open_main(true); - bool ok = reg_set_dword(reg, "iface_mode", config->iface_mode) - - && reg_set_dword(reg, "port", config->udp_port) + bool ok = reg_set_dword(reg, "port", config->udp_port) && reg_set_dword(reg, "router_port", config->router_port) && 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) diff --git a/src/config.h b/src/config.h index 97d2baa..8cb0112 100644 --- a/src/config.h +++ b/src/config.h @@ -21,26 +21,6 @@ #define DEFAULT_PORT 54792 #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" #ifdef __cplusplus @@ -52,12 +32,8 @@ typedef struct main_config { uint16_t router_port; bool w95_bug; - bool bcast_all; - bool src_filter; enum ipx_log_level log_level; - - int iface_mode; } main_config_t; struct v1_global_config { diff --git a/src/router.c b/src/router.c index 6ff24e7..c63fe60 100644 --- a/src/router.c +++ b/src/router.c @@ -304,51 +304,48 @@ DWORD router_main(void *arg) { addr32_t ra_net = addr32_in(ra->addr.sa_netnum); 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]; - - 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; + source_ok = 1; + break; } - - /* 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; - - 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; - } + continue; } log_printf(LOG_DEBUG, "Relaying packet to local port %hu", ntohs(ra->local_port)); diff --git a/src/winsock.c b/src/winsock.c index 2340308..38adf3d 100644 --- a/src/winsock.c +++ b/src/winsock.c @@ -724,7 +724,7 @@ static int send_packet(const ipx_packet *packet, int len, struct sockaddr *addr, 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); @@ -818,63 +818,45 @@ int WSAAPI sendto(SOCKET fd, const char *buf, int len, int flags, const struct s else{ /* 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; - bcast.sin_port = htons(main_config.udp_port); - - if(main_config.bcast_all) + if(iface && iface->ipaddr) { - /* 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( - packet, - psize, - (struct sockaddr*)(&bcast), - sizeof(bcast) - ); + DL_FOREACH(iface->ipaddr, ip) + { + struct sockaddr_in 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{ - /* Broadcast on associated interfaces. */ + /* No IP addresses. */ - ipx_interface_t *iface = ipx_interface_by_addr( - addr32_in(packet->src_net), - 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); + WSASetLastError(WSAENETDOWN); + success = 0; } + + free_ipx_interface(iface); } free(packet);