Prep for 6-in-6, 4-in-6, 6-in-4

This commit is contained in:
Nick Thomas
2013-08-15 00:09:23 +01:00
parent 2ffff92d36
commit 1cdf838ac9
5 changed files with 212 additions and 113 deletions

View File

@@ -8,7 +8,7 @@
#include <sys/uio.h>
int process_icmp_rloc_update( struct rlocs *reg, struct packet *packet )
int process_icmpv4_rloc_update( struct rlocs *reg, struct packet *packet )
{
uint16_t hdr_len = packet->hdr.ip.ihl * 4;
uint16_t inner_ip_hdr_offset = hdr_len + sizeof( struct icmphdr );
@@ -46,40 +46,35 @@ int process_icmp_rloc_update( struct rlocs *reg, struct packet *packet )
return 1;
}
int process_ipv4_packet( struct rlocs *reg, struct packet *packet, struct rsp_data *frag1, struct rsp_data *frag2 )
{
int result, updated;
switch ( packet->hdr.ip.protocol ) {
case IPPROTO_HIDE_EID:
// doesn't need fragmenting, or if it does, tough
result = unwrap_ipv4_packet( reg, packet, frag1 );
break;
case IPPROTO_ICMP:
if ( ( updated = process_icmp_rloc_update( reg, packet ) ) != 0 ) {
result = 0;
break;
}
// intentional fallthrough for ICMP not addressed to us.
// -1 (error) and 1 ( dealt with ) don't need to respond.
default:
result = wrap_ipv4_packet( reg, packet, frag1, frag2 );
break;
}
return result;
int process_icmpv6_rloc_update( struct rlocs *reg, struct packet *packet )
{
warn( "STUB: process_icmpv6_rloc_update" );
return 0;
}
int process_packet( struct rlocs *reg, struct packet *packet, struct rsp_data *frag1, struct rsp_data *frag2 )
int process_packet( struct rlocs *reg, struct packet *pkt, struct rsp_data *frag1, struct rsp_data *frag2 )
{
if ( packet->hdr.ip.version == 0x04 ) {
return process_ipv4_packet( reg, packet, frag1, frag2 );
int protocol = packet_find_protocol( pkt );
if ( protocol == -1 ) {
warn( "Couldn't work out version / protocol of received packet, discarding" );
return 0;
}
warn( "Can't process IP protocol version %i yet; dropping packet", packet->hdr.ip.version );
if ( protocol == IPPROTO_HIDE_EID ) {
return unwrap_packet( reg, pkt, frag1 );
}
return 0;
if ( protocol == IPPROTO_ICMP && process_icmpv4_rloc_update( reg, pkt ) ) {
return 0;
}
if ( protocol == IPPROTO_ICMPV6 && process_icmpv6_rloc_update( reg, pkt ) ) {
return 0;
}
return wrap_packet( reg, pkt, frag1, frag2 );
}
/*
@@ -160,4 +155,4 @@ int main(int argc, char** argv)
session_teardown( &session );
return 0;
}
}