This gets us to the point of seemingly being able to wrap and unwrap IPv4

Remarkably hard to test this on a single computer
This commit is contained in:
Nick Thomas
2013-08-06 18:44:13 +01:00
parent 13090d3c75
commit dcb4e5ef28
7 changed files with 189 additions and 13 deletions

View File

@@ -85,7 +85,7 @@ int link_set_up( char *link_name, int state )
int session_setup( struct session *session, char *config_file, char *listen_if, char *output_if )
{
memset( &session, 0, sizeof( struct session ) );
memset( session, 0, sizeof( struct session ) );
session->listen_if = -1;
session->output_if = -1;
@@ -130,6 +130,53 @@ int session_setup( struct session *session, char *config_file, char *listen_if,
return 1;
}
int session_upgrade_rlocs( struct session *session, int argc, char** args )
{
int i, num_rlocs = argc / 2;
if ( argc%2 != 0 ) {
warn( "Odd number of arguments. Format: [<rlc> <filename>]n" );
return 0;
}
for ( i = 0 ; i < num_rlocs ; i++ ) {
char *rloc_str = args[i*2];
char *filename = args[(i*2)+1];
struct rloc *rloc;
if ( strchr( rloc_str, ':' ) == NULL ) { /* IPv4 */
struct in_addr ip;
if ( inet_pton( AF_INET, rloc_str, &ip ) != 1 ) {
warn( "Couldn't parse %s as an IPv4 address", rloc_str );
return 0;
}
rloc = rloc_find_by_address( session->rlocs, &ip, NULL );
} else { /* IPv6 */
struct in6_addr ip6;
if ( inet_pton( AF_INET6, rloc_str, &ip6 ) != 1 ) {
warn( "Couldn't parse %s as an IPv6 address", rloc_str );
return 0;
}
rloc = rloc_find_by_address( session->rlocs, NULL, &ip6 );
}
if (rloc == NULL ) {
warn( "Couldn't find rloc for %s", rloc_str );
return 0;
}
if ( !rloc_add_private_key( rloc, filename ) ) {
warn( "Couldn't upgrade rloc %s with %s", rloc_str, filename );
return 0;
}
info( "Upgraded RLOC %s with private key %s", rloc_str, filename );
}
return 1;
}
void session_teardown( struct session *session )
{
rlocs_free( session->rlocs );