Fix a few bugs, tentative tun multiqueue support

This commit is contained in:
Nick Thomas
2013-08-22 02:03:31 +01:00
parent 1cdf838ac9
commit f36089eb23
5 changed files with 195 additions and 108 deletions

View File

@@ -293,7 +293,7 @@ struct rlocs* rlocs_new( char* filename )
json_object* config;
ssize_t have_read = 0;
char* json_text;
int fd;
int fd, ret;
fd = open( filename, O_RDONLY );
if ( errno < 0 ) {
@@ -301,8 +301,8 @@ struct rlocs* rlocs_new( char* filename )
return NULL;
}
fstat( fd, &filedata );
if ( errno < 0 ) {
ret = fstat( fd, &filedata );
if ( ret < 0 ) {
warn( "Error %s (%i) getting size of %s", strerror(errno), errno, filename );
return NULL;
}
@@ -477,36 +477,6 @@ int rlocs_find_two_ipv4(
}
/* Replaces the public key in the rloc struct with a private key so we can
* unwrap, as well as wrap, packets.
*/
int rloc_add_private_key( struct rloc *rloc, char *filename )
{
BIO *key_data = BIO_new_file( filename, "r" );
EC_KEY* key = PEM_read_bio_ECPrivateKey( key_data, NULL, NULL, NULL );
if ( key == NULL ) {
warn( "Failed to add private key %s", filename );
goto fail;
}
if ( !EVP_PKEY_assign_EC_KEY( rloc->key, key ) ) {
warn( "Failed to assign private key in %s to rloc", filename );
goto fail;
}
return 1;
fail:
show_ssl_errors();
if ( key != NULL ) {
EC_KEY_free( key );
}
return 0;
}
int rlocs_update_peer_context(struct rlocs *reg, struct rloc *x, struct rloc *y)
{
struct peer_context *entry = &reg->peer_contexts[x->context_id][y->context_id];
@@ -576,6 +546,43 @@ fail:
return 0;
}
/* Replaces the public key in the rloc struct with a private key so we can
* unwrap, as well as wrap, packets.
*/
int rlocs_add_private_key( struct rlocs *reg, struct rloc *rloc, char *filename )
{
int i;
BIO *key_data = BIO_new_file( filename, "r" );
EC_KEY* key = PEM_read_bio_ECPrivateKey( key_data, NULL, NULL, NULL );
if ( key == NULL ) {
warn( "Failed to add private key %s", filename );
goto fail;
}
if ( !EVP_PKEY_assign_EC_KEY( rloc->key, key ) ) {
warn( "Failed to assign private key in %s to rloc", filename );
goto fail;
}
// We need to update all the peer contexts touching this rloc now
for ( i = 0 ; i < reg->num_entries ; i++ ) {
rlocs_update_peer_context( reg, rloc, &reg->entries[i] );
rlocs_update_peer_context( reg, &reg->entries[i], rloc );
}
return 1;
fail:
show_ssl_errors();
if ( key != NULL ) {
EC_KEY_free( key );
}
return 0;
}
struct peer_context *rlocs_get_peer_ctx( struct rlocs *reg, struct rloc *x, struct rloc *y )
{