summaryrefslogtreecommitdiff
path: root/src/uanytun.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-28 22:34:14 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-28 22:34:14 +0000
commit682b26674e11191f2469f6b37fd92f7176a9a588 (patch)
tree4986a5e84b9b9de42061d69e1ca1fd7d314a6fef /src/uanytun.c
parentfixed build ;) (diff)
processing of device packets works now (null cipher and no auth algo)
Diffstat (limited to 'src/uanytun.c')
-rw-r--r--src/uanytun.c79
1 files changed, 48 insertions, 31 deletions
diff --git a/src/uanytun.c b/src/uanytun.c
index a7e1f7d..649ac7a 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -53,7 +53,7 @@
#include "daemon.h"
#include "sysexec.h"
-void main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
+int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
{
log_printf(INFO, "entering main loop");
@@ -65,6 +65,13 @@ void main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
udp_endpoint_t remote;
seq_nr_t seq_nr = 0;
+ cipher_t* c;
+ cipher_init(&c, opt->cipher_);
+ if(!c) {
+ log_printf(ERR, "could not initialize cipher of type %s", opt->cipher_);
+ return -1;
+ }
+
while(1) {
plain_packet_set_payload_length(&plain_packet, -1);
encrypted_packet_set_length(&encrypted_packet, -1);
@@ -72,42 +79,51 @@ void main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt)
// TODO: add select
// if dev->fd_ is ready:
- len = tun_read(dev, plain_packet_get_payload(&plain_packet), plain_packet_get_payload_length(&plain_packet));
- plain_packet_set_payload_length(&plain_packet, len);
-
- // TODO: cipher packet
- // TODO: add auth-tag
-
- encrypted_packet_set_seq_nr(&encrypted_packet, seq_nr);
- encrypted_packet_set_sender_id(&encrypted_packet, opt->sender_id_);
- encrypted_packet_set_mux(&encrypted_packet, opt->mux_);
-
- udp_write(sock, encrypted_packet_get_packet(&encrypted_packet), encrypted_packet_get_length(&encrypted_packet));
-
-
+ if(1) {
+ len = tun_read(dev, plain_packet_get_payload(&plain_packet), plain_packet_get_payload_length(&plain_packet));
+ plain_packet_set_payload_length(&plain_packet, len);
+
+ if(dev->type_ = TYPE_TUN)
+ plain_packet_set_type(&plain_packet, PAYLOAD_TYPE_TUN);
+ else if(dev->type_ = TYPE_TAP)
+ plain_packet_set_type(&plain_packet, PAYLOAD_TYPE_TAP);
+ else
+ plain_packet_set_type(&plain_packet, PAYLOAD_TYPE_UNKNOWN);
+
+ cipher_encrypt(c, &plain_packet, &encrypted_packet, seq_nr, opt->sender_id_, opt->mux_);
+ seq_nr++;
+
+ // TODO: add auth-tag
+
+ udp_write(sock, encrypted_packet_get_packet(&encrypted_packet), encrypted_packet_get_length(&encrypted_packet));
+ }
// if sock->fd_ is ready:
- len = udp_read(sock, encrypted_packet_get_packet(&encrypted_packet), encrypted_packet_get_length(&encrypted_packet), &remote);
- encrypted_packet_set_length(&encrypted_packet, len);
+/* len = udp_read(sock, encrypted_packet_get_packet(&encrypted_packet), encrypted_packet_get_length(&encrypted_packet), &remote); */
+/* encrypted_packet_set_length(&encrypted_packet, len); */
- // TODO: check auth-tag
+/* // TODO: check auth-tag */
- if(encrypted_packet_get_mux(&encrypted_packet) != opt->mux_)
- continue;
+/* if(encrypted_packet_get_mux(&encrypted_packet) != opt->mux_) */
+/* continue; */
- // TODO: check seq nr for sender id
+/* // TODO: check seq nr for sender id */
- if(memcmp(&remote, &(sock->remote_end_), sizeof(remote))) {
- memcpy(&(sock->remote_end_), &remote, sizeof(remote));
- char* addrstring = udp_endpoint_to_string(remote);
- log_printf(NOTICE, "autodetected remote host changed %s", addrstring);
- free(addrstring);
- }
+/* if(memcmp(&remote, &(sock->remote_end_), sizeof(remote))) { */
+/* memcpy(&(sock->remote_end_), &remote, sizeof(remote)); */
+/* char* addrstring = udp_endpoint_to_string(remote); */
+/* log_printf(NOTICE, "autodetected remote host changed %s", addrstring); */
+/* free(addrstring); */
+/* } */
- // TODO: decipher packet
+/* // TODO: decipher packet */
- tun_write(dev, plain_packet_get_payload(&plain_packet), plain_packet_get_payload_length(&plain_packet));
+/* tun_write(dev, plain_packet_get_payload(&plain_packet), plain_packet_get_payload_length(&plain_packet)); */
}
+
+ cipher_close(&c);
+
+ return 0;
}
void print_hex_dump(const u_int8_t* buf, u_int32_t len)
@@ -195,13 +211,14 @@ int main(int argc, char* argv[])
fclose(pid_file);
}
- main_loop(dev, sock, opt);
+ ret = main_loop(dev, sock, opt);
tun_close(&dev);
udp_close(&sock);
options_clear(&opt);
- log_printf(NOTICE, "normal shutdown");
+ if(!ret)
+ log_printf(NOTICE, "normal shutdown");
- return 0;
+ return ret;
}