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

@@ -5,8 +5,11 @@
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/uio.h>
#define MAX_SESSIONS 32
int process_icmpv4_rloc_update( struct rlocs *reg, struct packet *packet )
{
@@ -77,35 +80,30 @@ int process_packet( struct rlocs *reg, struct packet *pkt, struct rsp_data *frag
return wrap_packet( reg, pkt, frag1, frag2 );
}
/*
* 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)
#define ARG_NUM_SESSIONS 1
#define ARG_RLOC_DB 2
#define ARG_IFNAME 3
#define ARG_LAST 4
int do_session( int multi, int argc, char **argv )
{
struct session session;
struct packet recv_pkt;
struct session session;
struct rsp_data frag1;
struct rsp_data frag2;
ssize_t count;
if ( argc < 4 ) {
warn( "Usage: %s <rloc database> <listen_ifname> <output_ifname> [ <rloc> <keyfile> ]n", argv[0] );
return 1;
}
rlocs_init();
if ( !session_setup( &session, argv[1], argv[2], argv[3] ) ) {
if ( !session_setup( &session, argv[ARG_RLOC_DB], argv[ARG_IFNAME], multi ) ) {
warn( "Failed to set up session, exiting" );
return 1;
}
if (argc > 4 ) {
if ( !session_upgrade_rlocs( &session, argc - 4, argv + 4 ) ) {
if (argc > ARG_LAST ) {
if ( !session_upgrade_rlocs( &session, argc - ARG_LAST, argv + ARG_LAST ) ) {
warn( "Failed to upgrade rlocs for session, exiting" );
session_teardown( &session );
return 1;
@@ -122,7 +120,7 @@ int main(int argc, char** argv)
while( 1 ) {
int rsp_count;
if ( ( count = read( session.listen_if, &recv_pkt, sizeof( struct packet ) ) ) < 0 ) {
if ( ( count = read( session.fd, &recv_pkt, sizeof( struct packet ) ) ) < 0 ) {
warn( "Failed to get a packet (%s)", strerror( errno ) );
break;
}
@@ -138,13 +136,13 @@ int main(int argc, char** argv)
}
if ( rsp_count > 0 ) {
if ( ( count = writev( session.output_if, frag1.iovs, frag1.count ) ) < 0 ) {
if ( ( count = writev( session.fd, frag1.iovs, frag1.count ) ) < 0 ) {
debug( "Error writing processed packet to output: %s", strerror(errno) );
}
}
if ( rsp_count == 2 ) {
if ( ( count = writev( session.output_if, frag2.iovs, frag2.count ) ) < 0 ) {
if ( ( count = writev( session.fd, frag2.iovs, frag2.count ) ) < 0 ) {
debug( "Error writing second processed packet to output: %s", strerror(errno) );
}
}
@@ -156,3 +154,81 @@ int main(int argc, char** argv)
return 0;
}
/*
* 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)
{
pid_t pids[MAX_SESSIONS];
int num_sessions, i;
int num_returned = 0, ret = 0;
if ( argc < ARG_LAST ) {
warn( "Usage: %s <number of sessions> <rloc database> <ifname> [ <rloc> <keyfile> ]n", argv[0] );
return 1;
}
memset( &pids, 0, sizeof( pid_t ) * MAX_SESSIONS );
num_sessions = atoi( argv[ARG_NUM_SESSIONS] );
if ( num_sessions <= 0 || num_sessions > MAX_SESSIONS ) {
warn( "Bad value: %s for number of sessions", argv[ARG_NUM_SESSIONS] );
}
// Don't spawn a child process if there's only 1 of us
if ( num_sessions == 1 ) {
return do_session( 0, argc, argv );
}
for( i = 0 ; i < num_sessions ; i++ ) {
pids[i] = fork();
if ( pids[i] == -1 ) {
warn( "fork() failure!" );
exit(1);
}
if ( pids[i] == 0 ) {
int ret = do_session( 1, argc, argv );
info( "Child process %i exiting with status %i", getpid(), ret );
exit( ret );
} else {
info( "Child session %i started", pids[i] );
}
}
// wait on all sessions returning
// todo: pass sigterm, etc to children
while ( num_returned < num_sessions ) {
int status;
pid_t pid;
pid = waitpid( -1, &status, 0 );
if ( pid == -1 ) {
warn( "waitpid() failure: %s", strerror(errno) );
ret = 1;
break;
}
if ( WIFEXITED( status ) ) {
for ( i = 0 ; i < num_sessions ; i++ ) {
if ( pids[i] == pid ) {
info( "Child pid %i exited", pid );
pids[i] = -1;
num_returned += 1;
// TODO: if exit status was bad, set ret to 1
break;
}
}
}
}
return ret;
}