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.22 2002/09/09 21:24:41 guus Exp $
+ $Id: net_packet.c,v 1.1.2.26 2003/03/28 13:41:49 guus Exp $
*/
#include "config.h"
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
-#ifdef HAVE_NETINET_IN_SYSTM_H
-#include <netinet/in_systm.h>
-#endif
-#ifdef HAVE_NETINET_IP_H
-#include <netinet/ip.h>
-#endif
-#ifdef HAVE_NETINET_TCP_H
-#include <netinet/tcp.h>
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <net/if.h>
+#ifdef HAVE_NETINET_IN_SYSTM_H
+#include <netinet/in_systm.h>
+#endif
+#ifdef HAVE_NETINET_IP_H
+#include <netinet/ip.h>
+#endif
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>
+#endif
#include <openssl/rand.h>
#include <openssl/evp.h>
int keylifetime = 0;
int keyexpires = 0;
+EVP_CIPHER_CTX packet_ctx;
#define MAX_SEQNO 1073741824
/* VPN packet I/O */
-void receive_udppacket(node_t * n, vpn_packet_t * inpkt)
+void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
{
vpn_packet_t pkt1, pkt2;
vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
vpn_packet_t *outpkt = pkt[0];
int outlen, outpad;
long int complen = MTU + 12;
- EVP_CIPHER_CTX ctx;
char hmac[EVP_MAX_MD_SIZE];
cp();
if(myself->cipher) {
outpkt = pkt[nextpkt++];
- EVP_DecryptInit(&ctx, myself->cipher, myself->key,
+ EVP_DecryptInit_ex(&packet_ctx, myself->cipher, NULL, myself->key,
myself->key + myself->cipher->key_len);
- EVP_DecryptUpdate(&ctx, (char *) &outpkt->seqno, &outlen,
+ EVP_DecryptUpdate(&packet_ctx, (char *) &outpkt->seqno, &outlen,
(char *) &inpkt->seqno, inpkt->len);
- EVP_DecryptFinal(&ctx, (char *) &outpkt->seqno + outlen, &outpad);
-
+ EVP_DecryptFinal_ex(&packet_ctx, (char *) &outpkt->seqno + outlen, &outpad);
+
outpkt->len = outlen + outpad;
inpkt = outpkt;
}
receive_packet(n, inpkt);
}
-void receive_tcppacket(connection_t * c, char *buffer, int len)
+void receive_tcppacket(connection_t *c, char *buffer, int len)
{
vpn_packet_t outpkt;
receive_packet(c->node, &outpkt);
}
-void receive_packet(node_t * n, vpn_packet_t * packet)
+void receive_packet(node_t *n, vpn_packet_t *packet)
{
cp();
route_incoming(n, packet);
}
-void send_udppacket(node_t * n, vpn_packet_t * inpkt)
+void send_udppacket(node_t *n, vpn_packet_t *inpkt)
{
vpn_packet_t pkt1, pkt2;
vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
int origlen;
int outlen, outpad;
long int complen = MTU + 12;
- EVP_CIPHER_CTX ctx;
vpn_packet_t *copy;
static int priority = 0;
int origpriority;
if(n->cipher) {
outpkt = pkt[nextpkt++];
- EVP_EncryptInit(&ctx, n->cipher, n->key, n->key + n->cipher->key_len);
- EVP_EncryptUpdate(&ctx, (char *) &outpkt->seqno, &outlen,
+ EVP_EncryptInit_ex(&packet_ctx, n->cipher, NULL, n->key, n->key + n->cipher->key_len);
+ EVP_EncryptUpdate(&packet_ctx, (char *) &outpkt->seqno, &outlen,
(char *) &inpkt->seqno, inpkt->len);
- EVP_EncryptFinal(&ctx, (char *) &outpkt->seqno + outlen, &outpad);
+ EVP_EncryptFinal_ex(&packet_ctx, (char *) &outpkt->seqno + outlen, &outpad);
outpkt->len = outlen + outpad;
inpkt = outpkt;
if(debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_DEBUG, _("Setting outgoing packet priority to %d"),
priority);
- if(setsockopt(sock, SOL_IP, IP_TOS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */
+ if(setsockopt(listen_socket[sock].udp, 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));
}
/*
send a packet to the given vpn ip.
*/
-void send_packet(node_t * n, vpn_packet_t * packet)
+void send_packet(node_t *n, vpn_packet_t *packet)
{
node_t *via;
/* Broadcast a packet using the minimum spanning tree */
-void broadcast_packet(node_t * from, vpn_packet_t * packet)
+void broadcast_packet(node_t *from, vpn_packet_t *packet)
{
avl_node_t *node;
connection_t *c;
}
}
-void flush_queue(node_t * n)
+void flush_queue(node_t *n)
{
list_node_t *node, *next;