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.157 2002/02/20 16:04:07 guus Exp $
+ $Id: net.c,v 1.35.4.158 2002/02/26 23:26:41 guus Exp $
*/
#include "config.h"
{
avl_node_t *node;
connection_t *c;
+ int i;
cp
FD_ZERO(fs);
FD_SET(c->socket, fs);
}
- FD_SET(tcp_socket, fs);
- FD_SET(udp_socket, fs);
+ for(i = 0; i < tcp_sockets; i++)
+ FD_SET(tcp_socket[i], fs);
+
+ for(i = 0; i < udp_sockets; i++)
+ FD_SET(udp_socket[i], fs);
+
FD_SET(device_fd, fs);
cp
}
{
connection_t *c;
avl_node_t *node;
- int result;
+ int result, i;
int len = sizeof(result);
vpn_packet_t packet;
cp
route_outgoing(&packet);
}
- if(FD_ISSET(udp_socket, f))
- handle_incoming_vpn_data();
+ for(i = 0; i < udp_sockets; i++)
+ if(FD_ISSET(udp_socket[i], f))
+ handle_incoming_vpn_data(udp_socket[i]);
for(node = connection_tree->head; node; node = node->next)
{
}
}
- if(FD_ISSET(tcp_socket, f))
- handle_new_meta_connection();
+ for(i = 0; i < tcp_sockets; i++)
+ if(FD_ISSET(tcp_socket[i], f))
+ handle_new_meta_connection(tcp_socket[i]);
cp
}
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.42 2002/02/26 22:47:51 guus Exp $
+ $Id: net.h,v 1.9.4.43 2002/02/26 23:26:41 guus Exp $
*/
#ifndef __TINC_NET_H__
#define MAXSIZE 1600 /* MTU + header (seqno) and trailer (CBC padding and HMAC) */
#define MAXBUFSIZE 2048 /* Probably way too much, but it must fit every possible request. */
+#define MAXSOCKETS 128 /* Overkill... */
typedef struct mac_t
{
#include "connection.h" /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
-extern int tcp_socket;
-extern int udp_socket;
+extern int tcp_socket[MAXSOCKETS];
+extern int udp_socket[MAXSOCKETS];
+extern int tcp_sockets;
+extern int udp_sockets;
extern int keyexpires;
extern int keylifetime;
extern int do_prune;
extern char *myport;
extern void retry_outgoing(outgoing_t *);
-extern void handle_incoming_vpn_data(void);
+extern void handle_incoming_vpn_data(int);
extern void finish_connecting(connection_t *);
extern void do_outgoing_connection(connection_t *);
-extern int handle_new_meta_connection(void);
+extern int handle_new_meta_connection(int);
extern int setup_listen_socket(sockaddr_t *);
extern int setup_vpn_in_socket(sockaddr_t *);
extern void send_packet(struct node_t *, vpn_packet_t *);
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.4 2002/02/20 22:37:38 guus Exp $
+ $Id: net_packet.c,v 1.1.2.5 2002/02/26 23:26:41 guus Exp $
*/
#include "config.h"
/* Send the packet */
- if((sendto(udp_socket, (char *)&inpkt->seqno, inpkt->len, 0, &(n->address.sa), SALEN(n->address.sa))) < 0)
+ if((sendto(udp_socket[0], (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));
cp
}
-void handle_incoming_vpn_data(void)
+void handle_incoming_vpn_data(int sock)
{
vpn_packet_t pkt;
int x, l = sizeof(x);
socklen_t fromlen = sizeof(from);
node_t *n;
cp
- if(getsockopt(udp_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
+ if(getsockopt(sock, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
{
syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%s"),
- __FILE__, __LINE__, udp_socket, strerror(errno));
+ __FILE__, __LINE__, sock, strerror(errno));
return;
}
if(x)
return;
}
- if((pkt.len = recvfrom(udp_socket, (char *)&pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen)) <= 0)
+ if((pkt.len = recvfrom(sock, (char *)&pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen)) <= 0)
{
syslog(LOG_ERR, _("Receiving packet failed: %s"), strerror(errno));
return;
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.4 2002/02/20 22:15:32 guus Exp $
+ $Id: net_setup.c,v 1.1.2.5 2002/02/26 23:26:41 guus Exp $
*/
#include "config.h"
{
config_t *cfg;
subnet_t *subnet;
- char *name, *mode, *afname, *cipher, *digest;
- struct addrinfo hint, *ai;
- int choice, err;
+ char *name, *hostname, *mode, *afname, *cipher, *digest;
+ struct addrinfo hint, *ai, *aip;
+ int choice, err, sock;
cp
myself = new_node();
myself->connection = new_connection();
return -1;
}
- if((tcp_socket = setup_listen_socket((sockaddr_t *)ai->ai_addr)) < 0)
+ tcp_sockets = 0;
+
+ for(aip = ai; aip; aip = aip->ai_next)
{
- syslog(LOG_ERR, _("Unable to set up a listening TCP socket!"));
- return -1;
+ if((sock = setup_listen_socket((sockaddr_t *)aip->ai_addr)) < 0)
+ continue;
+
+ tcp_socket[++tcp_sockets] = sock;
+ if(debug_lvl >= DEBUG_CONNECTIONS)
+ {
+ hostname = sockaddr2hostname((sockaddr_t *)aip->ai_addr);
+ syslog(LOG_NOTICE, _("Listening on %s/tcp"), hostname);
+ free(hostname);
+ }
}
freeaddrinfo(ai);
return -1;
}
- if((udp_socket = setup_vpn_in_socket((sockaddr_t *)ai->ai_addr)) < 0)
+ udp_sockets = 0;
+
+ for(aip = ai; aip; aip = aip->ai_next)
{
- syslog(LOG_ERR, _("Unable to set up a listening UDP socket!"));
- return -1;
+ if((sock = setup_vpn_in_socket((sockaddr_t *)aip->ai_addr)) < 0)
+ continue;
+
+ udp_socket[++udp_sockets] = sock;
+ if(debug_lvl >= DEBUG_CONNECTIONS)
+ {
+ hostname = sockaddr2hostname((sockaddr_t *)aip->ai_addr);
+ syslog(LOG_NOTICE, _("Listening on %s/udp"), hostname);
+ free(hostname);
+ }
}
freeaddrinfo(ai);
- syslog(LOG_NOTICE, _("Ready: listening on port %s"), myport);
+ syslog(LOG_NOTICE, _("Ready"));
cp
return 0;
}
{
avl_node_t *node, *next;
connection_t *c;
+ int i;
cp
for(node = connection_tree->head; node; node = next)
{
if(myself && myself->connection)
terminate_connection(myself->connection, 0);
- close(udp_socket);
- close(tcp_socket);
+ for(i = 0; i < udp_sockets; i++)
+ close(udp_socket[i]);
+ for(i = 0; i < tcp_sockets; i++)
+ close(tcp_socket[i]);
exit_events();
exit_edges();
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.3 2002/02/20 22:37:38 guus Exp $
+ $Id: net_socket.c,v 1.1.2.4 2002/02/26 23:26:41 guus Exp $
*/
#include "config.h"
int maxtimeout = 900;
int seconds_till_retry = 5;
-int tcp_socket = -1;
-int udp_socket = -1;
+int tcp_socket[MAXSOCKETS];
+int udp_socket[MAXSOCKETS];
+int tcp_sockets = 0;
+int udp_sockets = 0;
+
/* Setup sockets */
int setup_listen_socket(sockaddr_t *sa)
accept a new tcp connect and create a
new connection
*/
-int handle_new_meta_connection()
+int handle_new_meta_connection(int sock)
{
connection_t *c;
sockaddr_t sa;
int fd, len = sizeof(sa);
cp
- if((fd = accept(tcp_socket, &sa.sa, &len)) < 0)
+ if((fd = accept(sock, &sa.sa, &len)) < 0)
{
syslog(LOG_ERR, _("Accepting a new connection failed: %s"), strerror(errno));
return -1;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol.h,v 1.5.4.26 2002/02/11 15:59:18 guus Exp $
+ $Id: protocol.h,v 1.5.4.27 2002/02/26 23:26:41 guus Exp $
*/
#ifndef __TINC_PROTOCOL_H__
/* Maximum size of strings in a request */
-#define MAX_STRING_SIZE 1024
-#define MAX_STRING "%1024s"
+#define MAX_STRING_SIZE 2048
+#define MAX_STRING "%2048s"
/* Basic functions */