From 08b209d810498285b2e2964a9461287b02d7b4c3 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 22 Aug 2013 02:54:36 +0100 Subject: [PATCH] fix packet_peer_context to actually do the right thing --- pass-1/packet.c | 59 +++++++++++++++++++++++++++++++------------------ pass-1/rlocs.h | 5 +++++ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/pass-1/packet.c b/pass-1/packet.c index acc3976..b4f312b 100644 --- a/pass-1/packet.c +++ b/pass-1/packet.c @@ -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 ); diff --git a/pass-1/rlocs.h b/pass-1/rlocs.h index b9ccb00..a60f2e6 100644 --- a/pass-1/rlocs.h +++ b/pass-1/rlocs.h @@ -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(