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.105 2001/05/07 19:08:43 guus Exp $
+ $Id: net.c,v 1.35.4.111 2001/06/05 16:09:55 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
+#ifdef HAVE_LINUX
+ #include <netinet/ip.h>
+ #include <netinet/tcp.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int keylifetime = 0;
int keyexpires = 0;
-char *unknown = NULL;
-
void send_udppacket(connection_t *cl, vpn_packet_t *inpkt)
{
vpn_packet_t outpkt;
cp
}
+void receive_tcppacket(connection_t *cl, char *buffer, int len)
+{
+ vpn_packet_t outpkt;
+cp
+ outpkt.len = len;
+ memcpy(outpkt.data, buffer, len);
+
+ receive_packet(cl, &outpkt);
+cp
+}
+
void accept_packet(vpn_packet_t *packet)
{
cp
if(write(tap_fd, packet->data - 2, packet->len + 2) < 0)
syslog(LOG_ERR, _("Can't write to ethertap device: %m"));
else
- total_tap_out += packet->len + 2;
+ total_tap_out += packet->len;
}
cp
}
send_udppacket(cl, packet);
}
+/* Broadcast a packet to all active connections */
+
+void broadcast_packet(connection_t *from, vpn_packet_t *packet)
+{
+ avl_node_t *node;
+ connection_t *cl;
+cp
+ if(debug_lvl >= DEBUG_TRAFFIC)
+ syslog(LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"),
+ packet->len, from->name, from->hostname);
+
+ for(node = connection_tree->head; node; node = node->next)
+ {
+ cl = (connection_t *)node->data;
+ if(cl->status.meta && cl != from)
+ send_packet(cl, packet);
+ }
+cp
+}
+
void flush_queue(connection_t *cl)
{
list_node_t *node, *next;
{
#ifdef HAVE_LINUX
# ifdef HAVE_TUNTAP
- tapfname = "/dev/misc/net/tun";
+ tapfname = "/dev/net/tun";
# else
tapfname = "/dev/tap0";
# endif
option = 1;
setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option));
+#ifdef HAVE_LINUX
setsockopt(nfd, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
option = IPTOS_LOWDELAY;
return -1;
}
}
+#endif
memset(&a, 0, sizeof(a));
a.sin_family = AF_INET;
option = 1;
setsockopt(cl->meta_socket, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option));
+#ifdef HAVE_LINUX
setsockopt(cl->meta_socket, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
option = IPTOS_LOWDELAY;
setsockopt(cl->meta_socket, SOL_IP, IP_TOS, &option, sizeof(option));
-
+#endif
/* Connect */
a.sin_family = AF_INET;
cp
myself = new_connection();
- asprintf(&myself->hostname, "MYSELF");
+ asprintf(&myself->hostname, _("MYSELF"));
myself->options = 0;
myself->protocol_version = PROT_CURRENT;
cfg = get_config_val(upstreamcfg, config_connectto);
if(!cfg)
- if(upstreamcfg == config)
{
- /* No upstream IP given, we're listen only. */
- signal(SIGALRM, SIG_IGN);
- return;
+ if(upstreamcfg == config)
+ {
+ /* No upstream IP given, we're listen only. */
+ signal(SIGALRM, SIG_IGN);
+ return;
+ }
}
else
{
return NULL;
}
- p->name = unknown;
+ asprintf(&p->name, _("UNKNOWN"));
p->address = ntohl(ci.sin_addr.s_addr);
p->hostname = hostlookup(ci.sin_addr.s_addr);
p->port = htons(ci.sin_port); /* This one will be overwritten later */
return;
}
+ cl->last_ping_time = time(NULL);
+
receive_udppacket(cl, &pkt);
cp
}
syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 seconds"));
}
- /* Inactivate */
+ /* Deactivate */
cl->status.active = 0;
cp
vp.len = lenin - 2;
}
- total_tap_in += lenin;
+ total_tap_in += vp.len;
if(lenin < 32)
{