First pass at fragmenting
This commit is contained in:
@@ -87,6 +87,7 @@ int rlocs_rloc_from_json(struct rlocs* reg, const char* key, json_object* val )
|
||||
warn( "Couldn't parse %s as an IP address", key );
|
||||
return 0;
|
||||
}
|
||||
strncpy( rloc->presentation, key, 128 );
|
||||
|
||||
// Next, we need to read and store the PEM-encoded RSA public key
|
||||
pem_data = json_object_get_string( val );
|
||||
@@ -371,7 +372,7 @@ struct rlocs* rlocs_new( char* filename )
|
||||
goto fail;
|
||||
}
|
||||
|
||||
int i, len = json_object_array_length( maps_field );
|
||||
int i, j, len = json_object_array_length( maps_field );
|
||||
for ( i = 0; i < len ; i++ ) {
|
||||
json_object *map_field = json_object_array_get_idx( maps_field, i );
|
||||
|
||||
@@ -380,6 +381,13 @@ struct rlocs* rlocs_new( char* filename )
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
// Set our default path mtu for all peers
|
||||
for ( i = 0 ; i < MAX_RLOCS ; i++ ) {
|
||||
for( j = 0 ; j < MAX_RLOCS ; j++ ) {
|
||||
result->peer_contexts[i][j].path_mtu = DEFAULT_PATH_MTU;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -444,6 +452,31 @@ struct rloc *rloc_find_by_address( struct rlocs *reg, struct in_addr *ipv4, stru
|
||||
return i < reg->num_entries ? current : NULL;
|
||||
}
|
||||
|
||||
int rlocs_find_two_ipv4(
|
||||
struct rlocs *reg,
|
||||
struct rloc **s_rloc_ptr, struct in_addr *s_rloc_addr,
|
||||
struct rloc **d_rloc_ptr, struct in_addr *d_rloc_addr
|
||||
)
|
||||
{
|
||||
struct rloc *s_rloc = *s_rloc_ptr;
|
||||
struct rloc *d_rloc = *d_rloc_ptr;
|
||||
|
||||
char addr_str[128];
|
||||
|
||||
if ( ( s_rloc = rloc_find_by_address( reg, s_rloc_addr, NULL ) ) == NULL ) {
|
||||
inet_ntop( AF_INET, s_rloc_addr, &addr_str[0], 128 );
|
||||
debug( "Couldn't find source rloc (%s) in DB", addr_str );
|
||||
return 0;
|
||||
}
|
||||
if ( ( d_rloc = rloc_find_by_address( reg, d_rloc_addr, NULL ) ) == NULL ) {
|
||||
inet_ntop( AF_INET, d_rloc_addr, &addr_str[0], 128 );
|
||||
debug( "Couldn't find destination rloc (%s) in DB", addr_str );
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Replaces the public key in the rloc struct with a private key so we can
|
||||
* unwrap, as well as wrap, packets.
|
||||
*/
|
||||
@@ -474,9 +507,9 @@ fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rlocs_update_key_context(struct rlocs *reg, struct rloc *x, struct rloc *y)
|
||||
int rlocs_update_peer_context(struct rlocs *reg, struct rloc *x, struct rloc *y)
|
||||
{
|
||||
struct key_context *entry = ®->key_contexts[x->context_id][y->context_id];
|
||||
struct peer_context *entry = ®->peer_contexts[x->context_id][y->context_id];
|
||||
|
||||
unsigned char secret[1024]; // Should be enough buffer space
|
||||
size_t secret_len = 1024;
|
||||
@@ -525,6 +558,7 @@ int rlocs_update_key_context(struct rlocs *reg, struct rloc *x, struct rloc *y)
|
||||
* decrypt packet data. */
|
||||
|
||||
EVP_CIPHER_CTX_init( &entry->ctx );
|
||||
entry->path_mtu = DEFAULT_PATH_MTU;
|
||||
entry->in_use = 1;
|
||||
|
||||
return 1;
|
||||
@@ -539,11 +573,16 @@ fail:
|
||||
}
|
||||
|
||||
|
||||
static inline struct peer_context *rlocs_get_peer_ctx( struct rlocs *reg, struct rloc *x, struct rloc *y )
|
||||
{
|
||||
return ®->peer_contexts[x->context_id][y->context_id];
|
||||
}
|
||||
|
||||
ssize_t rlocs_encrypt( struct rlocs *reg, struct rloc *x, struct rloc *y, unsigned char *data, size_t data_len, unsigned char *dest, size_t dest_len )
|
||||
{
|
||||
struct key_context *entry = ®->key_contexts[x->context_id][y->context_id];
|
||||
struct peer_context *entry = rlocs_get_peer_ctx( reg, x, y );
|
||||
|
||||
if ( !entry->in_use && !rlocs_update_key_context( reg, x, y ) ) {
|
||||
if ( !entry->in_use && !rlocs_update_peer_context( reg, x, y ) ) {
|
||||
warn( "Couldn't build an encryption context for these rlocs" );
|
||||
return -1;
|
||||
}
|
||||
@@ -611,9 +650,9 @@ fail:
|
||||
|
||||
ssize_t rlocs_decrypt( struct rlocs *reg, struct rloc *x, struct rloc *y, unsigned char *data, size_t data_len, unsigned char *dest, size_t dest_len )
|
||||
{
|
||||
struct key_context *entry = ®->key_contexts[x->context_id][y->context_id];
|
||||
struct peer_context *entry = rlocs_get_peer_ctx( reg, x, y );
|
||||
|
||||
if ( !entry->in_use && !rlocs_update_key_context( reg, x, y ) ) {
|
||||
if ( !entry->in_use && !rlocs_update_peer_context( reg, x, y ) ) {
|
||||
warn( "Couldn't build a decryption context for these rlocs" );
|
||||
return -1;
|
||||
}
|
||||
@@ -700,6 +739,20 @@ void rlocs_debug_output( struct rlocs *reg )
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned short rlocs_get_path_mtu( struct rlocs *reg, struct rloc *x, struct rloc *y )
|
||||
{
|
||||
struct peer_context *entry = rlocs_get_peer_ctx( reg, x, y );
|
||||
|
||||
return entry->path_mtu;
|
||||
|
||||
}
|
||||
|
||||
void rlocs_set_path_mtu( struct rlocs *reg, struct rloc *x, struct rloc *y, unsigned short new_mtu )
|
||||
{
|
||||
struct peer_context *entry = rlocs_get_peer_ctx( reg, x, y );
|
||||
entry->path_mtu = new_mtu;
|
||||
return;
|
||||
}
|
||||
|
||||
void rlocs_free( struct rlocs* registry )
|
||||
{
|
||||
@@ -710,6 +763,9 @@ void rlocs_free( struct rlocs* registry )
|
||||
EVP_PKEY_free( registry->entries[i].key );
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: free our ctxes and other peer_context items
|
||||
|
||||
// No need to do json_object_put() here.
|
||||
free( registry );
|
||||
return;
|
||||
|
Reference in New Issue
Block a user