Remember sockaddrs of listening sockets, use appropriate one when sending

UDP packets.
This commit is contained in:
Guus Sliepen 2002-03-18 22:47:20 +00:00
parent 106fc2b769
commit 305505f5ec
5 changed files with 39 additions and 22 deletions

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: net.c,v 1.35.4.163 2002/03/11 11:45:12 guus Exp $ $Id: net.c,v 1.35.4.164 2002/03/18 22:47:20 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -94,8 +94,8 @@ cp
for(i = 0; i < listen_sockets; i++) for(i = 0; i < listen_sockets; i++)
{ {
FD_SET(tcp_socket[i], fs); FD_SET(listen_socket[i].tcp, fs);
FD_SET(udp_socket[i], fs); FD_SET(listen_socket[i].udp, fs);
} }
FD_SET(device_fd, fs); FD_SET(device_fd, fs);
@ -287,10 +287,10 @@ cp
for(i = 0; i < listen_sockets; i++) for(i = 0; i < listen_sockets; i++)
{ {
if(FD_ISSET(udp_socket[i], f)) if(FD_ISSET(listen_socket[i].udp, f))
handle_incoming_vpn_data(udp_socket[i]); handle_incoming_vpn_data(listen_socket[i].udp);
if(FD_ISSET(tcp_socket[i], f)) if(FD_ISSET(listen_socket[i].tcp, f))
handle_new_meta_connection(tcp_socket[i]); handle_new_meta_connection(listen_socket[i].tcp);
} }
for(node = connection_tree->head; node; node = node->next) for(node = connection_tree->head; node; node = node->next)

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: net.h,v 1.9.4.46 2002/03/01 14:09:31 guus Exp $ $Id: net.h,v 1.9.4.47 2002/03/18 22:47:20 guus Exp $
*/ */
#ifndef __TINC_NET_H__ #ifndef __TINC_NET_H__
@ -98,6 +98,12 @@ typedef struct outgoing_t {
struct addrinfo *aip; struct addrinfo *aip;
} outgoing_t; } outgoing_t;
typedef struct listen_socket_t {
int tcp;
int udp;
sockaddr_t sa;
} listen_socket_t;
extern int maxtimeout; extern int maxtimeout;
extern int seconds_till_retry; extern int seconds_till_retry;
extern int addressfamily; extern int addressfamily;
@ -107,8 +113,7 @@ extern char *status_text[];
#include "connection.h" /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */ #include "connection.h" /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
extern int tcp_socket[MAXSOCKETS]; extern listen_socket_t listen_socket[MAXSOCKETS];
extern int udp_socket[MAXSOCKETS];
extern int listen_sockets; extern int listen_sockets;
extern int keyexpires; extern int keyexpires;
extern int keylifetime; extern int keylifetime;

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: net_packet.c,v 1.1.2.10 2002/03/17 15:59:29 guus Exp $ $Id: net_packet.c,v 1.1.2.11 2002/03/18 22:47:20 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -194,7 +194,10 @@ void send_udppacket(node_t *n, vpn_packet_t *inpkt)
vpn_packet_t *copy; vpn_packet_t *copy;
static int priority = 0; static int priority = 0;
int origpriority; int origpriority;
int sock;
cp cp
/* Make sure we have a valid key */
if(!n->status.validkey) if(!n->status.validkey)
{ {
if(debug_lvl >= DEBUG_TRAFFIC) if(debug_lvl >= DEBUG_TRAFFIC)
@ -261,20 +264,29 @@ cp
inpkt->len += n->maclength; inpkt->len += n->maclength;
} }
/* Determine which socket we have to use */
for(sock = 0; sock < listen_sockets; sock++)
if(n->address.sa.sa_family == listen_socket[sock].sa.sa.sa_family)
break;
if(sock >= listen_sockets)
sock = 0; /* If none is available, just use the first and hope for the best. */
/* Send the packet */ /* Send the packet */
#if defined(SOL_IP) && defined(IP_TOS) #if defined(SOL_IP) && defined(IP_TOS)
if(priorityinheritance && origpriority != priority) if(priorityinheritance && origpriority != priority && listen_socket[sock].sa.sa.sa_family == AF_INET)
{ {
priority = origpriority; priority = origpriority;
if(debug_lvl >= DEBUG_TRAFFIC) if(debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_DEBUG, _("Setting outgoing packet priority to %d"), priority); syslog(LOG_DEBUG, _("Setting outgoing packet priority to %d"), priority);
if(setsockopt(udp_socket[0], SOL_IP, IP_TOS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */ if(setsockopt(sock, SOL_IP, IP_TOS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */
syslog(LOG_ERR, _("System call `%s' failed: %s"), "setsockopt", strerror(errno)); syslog(LOG_ERR, _("System call `%s' failed: %s"), "setsockopt", strerror(errno));
} }
#endif #endif
if((sendto(udp_socket[0], (char *)&inpkt->seqno, inpkt->len, 0, &(n->address.sa), SALEN(n->address.sa))) < 0) if((sendto(listen_socket[sock].udp, (char *)&inpkt->seqno, inpkt->len, 0, &(n->address.sa), SALEN(n->address.sa))) < 0)
{ {
syslog(LOG_ERR, _("Error sending packet to %s (%s): %s"), syslog(LOG_ERR, _("Error sending packet to %s (%s): %s"),
n->name, n->hostname, strerror(errno)); n->name, n->hostname, strerror(errno));

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: net_setup.c,v 1.1.2.10 2002/03/10 16:09:15 guus Exp $ $Id: net_setup.c,v 1.1.2.11 2002/03/18 22:47:20 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -486,10 +486,10 @@ cp
for(aip = ai; aip; aip = aip->ai_next) for(aip = ai; aip; aip = aip->ai_next)
{ {
if((tcp_socket[listen_sockets] = setup_listen_socket((sockaddr_t *)aip->ai_addr)) < 0) if((listen_socket[listen_sockets].tcp = setup_listen_socket((sockaddr_t *)aip->ai_addr)) < 0)
continue; continue;
if((udp_socket[listen_sockets] = setup_vpn_in_socket((sockaddr_t *)aip->ai_addr)) < 0) if((listen_socket[listen_sockets].udp = setup_vpn_in_socket((sockaddr_t *)aip->ai_addr)) < 0)
continue; continue;
if(debug_lvl >= DEBUG_CONNECTIONS) if(debug_lvl >= DEBUG_CONNECTIONS)
@ -499,6 +499,7 @@ cp
free(hostname); free(hostname);
} }
listen_socket[listen_sockets].sa.sa = *aip->ai_addr;
listen_sockets++; listen_sockets++;
} }
@ -576,8 +577,8 @@ cp
for(i = 0; i < listen_sockets; i++) for(i = 0; i < listen_sockets; i++)
{ {
close(udp_socket[i]); close(listen_socket[i].tcp);
close(tcp_socket[i]); close(listen_socket[i].udp);
} }
exit_events(); exit_events();

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: net_socket.c,v 1.1.2.9 2002/03/17 15:59:29 guus Exp $ $Id: net_socket.c,v 1.1.2.10 2002/03/18 22:47:20 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -70,8 +70,7 @@ int addressfamily = AF_INET;
int maxtimeout = 900; int maxtimeout = 900;
int seconds_till_retry = 5; int seconds_till_retry = 5;
int tcp_socket[MAXSOCKETS]; listen_socket_t listen_socket[MAXSOCKETS];
int udp_socket[MAXSOCKETS];
int listen_sockets = 0; int listen_sockets = 0;
/* Setup sockets */ /* Setup sockets */