diff options
author | Christian Pointner <equinox@anytun.org> | 2009-01-06 10:26:06 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2009-01-06 10:26:06 +0000 |
commit | 9ab6316366701dca07e84f1fddacf0308f49bb24 (patch) | |
tree | 1ae5cd89d0c1d03ca016989442b1edd423b592de | |
parent | some cleanup (diff) |
cleaned up main_loop a little
-rw-r--r-- | src/uanytun.c | 86 |
1 files changed, 54 insertions, 32 deletions
diff --git a/src/uanytun.c b/src/uanytun.c index 051886a..609a873 100644 --- a/src/uanytun.c +++ b/src/uanytun.c @@ -93,65 +93,87 @@ int init_libgcrypt() #endif #endif -int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt) +#ifndef NO_CRYPT +int init_main_loop(options_t* opt, cipher_t* c, auth_algo_t* aa, key_derivation_t* kd_in, key_derivation_t* kd_out, seq_win_t* seq_win) +#else +int init_main_loop(options_t* opt, cipher_t* c, key_derivation_t* kd_in, key_derivation_t* kd_out, seq_win_t* seq_win) +#endif { - log_printf(INFO, "entering main loop"); - - plain_packet_t plain_packet; - plain_packet_init(&plain_packet); - encrypted_packet_t encrypted_packet; - encrypted_packet_init(&encrypted_packet); - int len = 0; - udp_endpoint_t remote; - seq_nr_t seq_nr = 0; - fd_set readfds; - - cipher_t c; - int ret = cipher_init(&c, opt->cipher_); + int ret = cipher_init(c, opt->cipher_); if(ret) { log_printf(ERR, "could not initialize cipher of type %s", opt->cipher_); return ret; } #ifndef NO_CRYPT - auth_algo_t aa; - ret = auth_algo_init(&aa, opt->auth_algo_); + ret = auth_algo_init(aa, opt->auth_algo_); if(ret) { log_printf(ERR, "could not initialize auth algo of type %s", opt->auth_algo_); - cipher_close(&c); + cipher_close(c); return ret; } - key_derivation_t kd_in; - ret = key_derivation_init(&kd_in, opt->kd_prf_, opt->ld_kdr_, opt->passphrase_, opt->key_.buf_, opt->key_.length_, opt->salt_.buf_, opt->salt_.length_); + ret = key_derivation_init(kd_in, opt->kd_prf_, opt->ld_kdr_, opt->passphrase_, opt->key_.buf_, opt->key_.length_, opt->salt_.buf_, opt->salt_.length_); if(ret) { log_printf(ERR, "could not initialize inbound key derivation of type %s", opt->kd_prf_); - cipher_close(&c); - auth_algo_close(&aa); + cipher_close(c); + auth_algo_close(aa); return ret; } - key_derivation_t kd_out; - ret = key_derivation_init(&kd_out, opt->kd_prf_, opt->ld_kdr_, opt->passphrase_, opt->key_.buf_, opt->key_.length_, opt->salt_.buf_, opt->salt_.length_); + ret = key_derivation_init(kd_out, opt->kd_prf_, opt->ld_kdr_, opt->passphrase_, opt->key_.buf_, opt->key_.length_, opt->salt_.buf_, opt->salt_.length_); if(ret) { log_printf(ERR, "could not initialize outbound key derivation of type %s", opt->kd_prf_); - cipher_close(&c); - auth_algo_close(&aa); - key_derivation_close(&kd_in); + cipher_close(c); + auth_algo_close(aa); + key_derivation_close(kd_in); return ret; } -#else - key_derivation_t kd_in, kd_out; #endif - int return_value = 0; - seq_win_t seq_win; - ret = seq_win_init(&seq_win, opt->seq_window_size_); + ret = seq_win_init(seq_win, opt->seq_window_size_); if(ret) { printf("could not initialize sequence window"); - return_value = ret; + cipher_close(c); +#ifndef NO_CRYPT + auth_algo_close(aa); + key_derivation_close(kd_in); + key_derivation_close(kd_out); +#endif + return ret; } + return 0; +} +int main_loop(tun_device_t* dev, udp_socket_t* sock, options_t* opt) +{ + log_printf(INFO, "entering main loop"); + + plain_packet_t plain_packet; + plain_packet_init(&plain_packet); + encrypted_packet_t encrypted_packet; + encrypted_packet_init(&encrypted_packet); + int len = 0; + udp_endpoint_t remote; + seq_nr_t seq_nr = 0; + fd_set readfds; + + cipher_t c; +#ifndef NO_CRYPT + auth_algo_t aa; +#endif + key_derivation_t kd_in, kd_out; + seq_win_t seq_win; + +#ifndef NO_CRYPT + int ret = init_main_loop(opt, &c, &aa, &kd_in, &kd_out, &seq_win); +#else + int ret = init_main_loop(opt, &c, &kd_in, &kd_out, &seq_win); +#endif + if(ret) + return ret; + + int return_value = 0; while(!return_value) { plain_packet_set_payload_length(&plain_packet, -1); encrypted_packet_set_length(&encrypted_packet, -1); |