fix packet_peer_context to actually do the right thing

This commit is contained in:
Nick Thomas
2013-08-22 02:54:36 +01:00
parent f36089eb23
commit 08b209d810
2 changed files with 43 additions and 21 deletions

View File

@@ -166,42 +166,55 @@ struct peer_context *packet_peer_context( struct rlocs *reg, struct packet *pkt,
struct rloc *src_rloc = NULL, *dst_rloc = NULL;
struct in_addr *ip4_src = (struct in_addr*) &pkt->hdr.ip.saddr;
struct in_addr *ip4_dst = (struct in_addr*) &pkt->hdr.ip.daddr;
struct in6_addr *ip6_src = &pkt->hdr.ip6.ip6_src;
struct in6_addr *ip6_dst = &pkt->hdr.ip6.ip6_dst;
switch( pkt->hdr.ip.version ) {
case 0x04: // ipv4
src_rloc = rloc_find_for_ipv4( reg, ip4_src );
if ( src_rloc == NULL ) {
inet_ntop( AF_INET, ip4_src, bad_eid_txt, 128 );
break;
}
dst_rloc = rloc_find_for_ipv4( reg, (struct in_addr *)&pkt->hdr.ip.daddr );
if ( dst_rloc == NULL ) {
inet_ntop( AF_INET, ip4_dst, bad_eid_txt, 128 );
ip6_src = NULL;
ip6_dst = NULL;
if ( wrapping ) { // source and destination are eids
src_rloc = rloc_find_for_ipv4( reg, ip4_src );
dst_rloc = rloc_find_for_ipv4( reg, ip4_dst );
}
break;
case 0x06: // ipv6
src_rloc = rloc_find_for_ipv6( reg, &pkt->hdr.ip6.ip6_src );
if ( src_rloc == NULL) {
inet_ntop( AF_INET6, &pkt->hdr.ip6.ip6_src, bad_eid_txt, 128 );
break;
}
dst_rloc = rloc_find_for_ipv6( reg, &pkt->hdr.ip6.ip6_dst );
if (dst_rloc == NULL ) {
inet_ntop( AF_INET6, &pkt->hdr.ip6.ip6_dst, bad_eid_txt, 128 );
ip4_src = NULL;
ip6_src = NULL;
if ( wrapping ) { // source and destination are eids
src_rloc = rloc_find_for_ipv6( reg, ip6_src );
dst_rloc = rloc_find_for_ipv6( reg, ip6_dst );
}
break;
}
if ( !wrapping ) { // source and destination are rlocs
src_rloc = rloc_find_by_address( reg, ip4_src, ip6_src );
dst_rloc = rloc_find_by_address( reg, ip4_dst, ip6_dst );
}
if ( src_rloc == NULL ) {
warn( "Couldn't find source RLOC for %s, discarding packet", bad_eid_txt );
return NULL;
if ( ip4_src != NULL ) {
inet_ntop( AF_INET, ip4_src, bad_eid_txt, 128 );
} else if ( ip6_src != NULL ) {
inet_ntop( AF_INET6, &pkt->hdr.ip6.ip6_src, bad_eid_txt, 128 );
}
warn( "Couldn't find source RLOC from %s", bad_eid_txt );
}
if ( dst_rloc == NULL ) {
warn( "Couldn't find destination RLOC for %s, discarding packet", bad_eid_txt );
if ( ip4_dst != NULL ) {
inet_ntop( AF_INET, ip4_dst, bad_eid_txt, 128 );
} else if ( ip6_dst != NULL ) {
inet_ntop( AF_INET6, &pkt->hdr.ip6.ip6_dst, bad_eid_txt, 128 );
}
warn( "Couldn't find destination RLOC from %s", bad_eid_txt );
}
if ( src_rloc == NULL || dst_rloc == NULL ) {
return NULL;
}
@@ -303,6 +316,8 @@ int wrap_packet( struct rlocs *reg, struct packet *pkt, struct rsp_data *frag1,
return 0;
}
debug( "Wrapping, x=%s, y=%s", pctx->x->presentation, pctx->y->presentation );
int result = 0;
switch ( pctx->x->family ) {
@@ -397,6 +412,8 @@ int unwrap_packet( struct rlocs *reg, struct packet *pkt, struct rsp_data *out )
return 0;
}
debug( "Unwrapping, x=%s, y=%s", pctx->x->presentation, pctx->y->presentation );
switch ( pkt->hdr.ip.version ) {
case 0x04:
result = unwrap_ipv4_packet( pctx, pkt, out );

View File

@@ -87,8 +87,13 @@ void rlocs_init(void);
struct rlocs *rlocs_new( char *filename );
// find a struct rlocs corresponding to a particular IPv4 eid
struct rloc *rloc_find_for_ipv4( struct rlocs *reg, struct in_addr *eid );
// find a struct rlocs corresponding to a particular IPv6 eid
struct rloc *rloc_find_for_ipv6( struct rlocs *reg, struct in6_addr *eid );
// find a struct rloc corresponding to a particular IPv4 or IPv6 RLOC
struct rloc *rloc_find_by_address( struct rlocs *reg, struct in_addr *ipv4, struct in6_addr *ipv6 );
int rlocs_find_two_ipv4(