Reorganise so we have wrapper, unwraper and hide-eid.
unwrapper and hide-eid don't work yet, of course.
This commit is contained in:
82
pass-1/hide-eid.c
Normal file
82
pass-1/hide-eid.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "util.h"
|
||||
#include "rlocs.h"
|
||||
#include "packet.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/uio.h>
|
||||
|
||||
/*
|
||||
* Entry point. Expects an invocation like:
|
||||
* hide-eid <filename of rloc database> <listen_ifname> <output_ifname>
|
||||
*
|
||||
* hide-eid wraps packets that come to it unwrapped, and unwraps packets that
|
||||
* come to it wrapped. This makes it handy for all-in-one boxes
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
struct session session;
|
||||
struct recv_pkt recv_pkt;
|
||||
struct rsp_data to_send;
|
||||
ssize_t count;
|
||||
int result = 0;
|
||||
|
||||
if ( argc < 4 ) {
|
||||
warn( "Usage: %s <rloc database> <listen_ifname> <output_ifname>", argv[0] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
rlocs_init();
|
||||
if ( !session_setup( &session, argv[1], argv[2], argv[3] ) ) {
|
||||
warn( "Failed to set up session, exiting" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset( &recv_pkt, 0, sizeof( struct recv_pkt ) );
|
||||
memset( &to_send, 0, sizeof( struct rsp_data ) );
|
||||
|
||||
warn( "TODO: Write BGP interventions to file" );
|
||||
|
||||
info( "Processing packets" );
|
||||
while(1) {
|
||||
if ( ( count = read( session.listen_if, &recv_pkt, sizeof( struct recv_pkt ) ) ) < 0 ) {
|
||||
warn( "Failed to get a packet (%s)", strerror( errno ) );
|
||||
break;
|
||||
}
|
||||
|
||||
info( "Got a packet \\o/. %zu bytes", count );
|
||||
|
||||
switch( recv_pkt.hdr.ip.version ) {
|
||||
case 0x04 :
|
||||
//result = wrap_ipv4_packet( wrap.rlocs, &recv_pkt, &to_send );
|
||||
break;
|
||||
case 0x06 :
|
||||
//result = wrap_ipv6_packet( wrap.rlocs, &recv_pkt, &to_send );
|
||||
break;
|
||||
default:
|
||||
warn( "Unknown IP version: %i", recv_pkt.hdr.ip.version );
|
||||
}
|
||||
warn( "TODO: select wrap / unwrap functionality based on destination IP" );
|
||||
|
||||
if ( !result ) {
|
||||
warn( "Failed to process received packet, dropping." );
|
||||
continue;
|
||||
}
|
||||
|
||||
// no failure, but nothing to forward.
|
||||
if ( to_send.count == 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ( count = writev( session.output_if, to_send.iovs, to_send.count ) ) < 0 ) {
|
||||
warn( "Error writing processed packet to output: %s", strerror(errno) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
info( "Finished, cleaning up" );
|
||||
session_teardown( &session );
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user