UDP packets.
along with this program; if not, write to the Free Software
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"
for(i = 0; i < listen_sockets; i++)
{
- FD_SET(tcp_socket[i], fs);
- FD_SET(udp_socket[i], fs);
+ FD_SET(listen_socket[i].tcp, fs);
+ FD_SET(listen_socket[i].udp, fs);
}
FD_SET(device_fd, fs);
for(i = 0; i < listen_sockets; i++)
{
- if(FD_ISSET(udp_socket[i], f))
- handle_incoming_vpn_data(udp_socket[i]);
- if(FD_ISSET(tcp_socket[i], f))
- handle_new_meta_connection(tcp_socket[i]);
+ if(FD_ISSET(listen_socket[i].udp, f))
+ handle_incoming_vpn_data(listen_socket[i].udp);
+ if(FD_ISSET(listen_socket[i].tcp, f))
+ handle_new_meta_connection(listen_socket[i].tcp);
}
for(node = connection_tree->head; node; node = node->next)
along with this program; if not, write to the Free Software
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__
struct addrinfo *aip;
} outgoing_t;
+typedef struct listen_socket_t {
+ int tcp;
+ int udp;
+ sockaddr_t sa;
+} listen_socket_t;
+
extern int maxtimeout;
extern int seconds_till_retry;
extern int addressfamily;
#include "connection.h" /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
-extern int tcp_socket[MAXSOCKETS];
-extern int udp_socket[MAXSOCKETS];
+extern listen_socket_t listen_socket[MAXSOCKETS];
extern int listen_sockets;
extern int keyexpires;
extern int keylifetime;
along with this program; if not, write to the Free Software
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"
vpn_packet_t *copy;
static int priority = 0;
int origpriority;
+ int sock;
cp
+ /* Make sure we have a valid key */
+
if(!n->status.validkey)
{
if(debug_lvl >= DEBUG_TRAFFIC)
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 */
#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;
if(debug_lvl >= DEBUG_TRAFFIC)
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));
}
#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"),
n->name, n->hostname, strerror(errno));
along with this program; if not, write to the Free Software
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"
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;
- 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;
if(debug_lvl >= DEBUG_CONNECTIONS)
free(hostname);
}
+ listen_socket[listen_sockets].sa.sa = *aip->ai_addr;
listen_sockets++;
}
for(i = 0; i < listen_sockets; i++)
{
- close(udp_socket[i]);
- close(tcp_socket[i]);
+ close(listen_socket[i].tcp);
+ close(listen_socket[i].udp);
}
exit_events();
along with this program; if not, write to the Free Software
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"
int maxtimeout = 900;
int seconds_till_retry = 5;
-int tcp_socket[MAXSOCKETS];
-int udp_socket[MAXSOCKETS];
+listen_socket_t listen_socket[MAXSOCKETS];
int listen_sockets = 0;
/* Setup sockets */