fix packet_peer_context to actually do the right thing
This commit is contained in:
@@ -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 rloc *src_rloc = NULL, *dst_rloc = NULL;
|
||||||
struct in_addr *ip4_src = (struct in_addr*) &pkt->hdr.ip.saddr;
|
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 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 ) {
|
switch( pkt->hdr.ip.version ) {
|
||||||
case 0x04: // ipv4
|
case 0x04: // ipv4
|
||||||
|
ip6_src = NULL;
|
||||||
|
ip6_dst = NULL;
|
||||||
|
if ( wrapping ) { // source and destination are eids
|
||||||
src_rloc = rloc_find_for_ipv4( reg, ip4_src );
|
src_rloc = rloc_find_for_ipv4( reg, ip4_src );
|
||||||
if ( src_rloc == NULL ) {
|
dst_rloc = rloc_find_for_ipv4( reg, ip4_dst );
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x06: // ipv6
|
case 0x06: // ipv6
|
||||||
src_rloc = rloc_find_for_ipv6( reg, &pkt->hdr.ip6.ip6_src );
|
ip4_src = NULL;
|
||||||
if ( src_rloc == NULL) {
|
ip6_src = NULL;
|
||||||
inet_ntop( AF_INET6, &pkt->hdr.ip6.ip6_src, bad_eid_txt, 128 );
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dst_rloc = rloc_find_for_ipv6( reg, &pkt->hdr.ip6.ip6_dst );
|
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 ) {
|
||||||
|
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 ) {
|
if ( dst_rloc == NULL ) {
|
||||||
|
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 );
|
inet_ntop( AF_INET6, &pkt->hdr.ip6.ip6_dst, bad_eid_txt, 128 );
|
||||||
}
|
}
|
||||||
break;
|
warn( "Couldn't find destination RLOC from %s", bad_eid_txt );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( src_rloc == NULL ) {
|
if ( src_rloc == NULL || dst_rloc == NULL ) {
|
||||||
warn( "Couldn't find source RLOC for %s, discarding packet", bad_eid_txt );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( dst_rloc == NULL ) {
|
|
||||||
warn( "Couldn't find destination RLOC for %s, discarding packet", bad_eid_txt );
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,6 +316,8 @@ int wrap_packet( struct rlocs *reg, struct packet *pkt, struct rsp_data *frag1,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug( "Wrapping, x=%s, y=%s", pctx->x->presentation, pctx->y->presentation );
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
switch ( pctx->x->family ) {
|
switch ( pctx->x->family ) {
|
||||||
@@ -397,6 +412,8 @@ int unwrap_packet( struct rlocs *reg, struct packet *pkt, struct rsp_data *out )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug( "Unwrapping, x=%s, y=%s", pctx->x->presentation, pctx->y->presentation );
|
||||||
|
|
||||||
switch ( pkt->hdr.ip.version ) {
|
switch ( pkt->hdr.ip.version ) {
|
||||||
case 0x04:
|
case 0x04:
|
||||||
result = unwrap_ipv4_packet( pctx, pkt, out );
|
result = unwrap_ipv4_packet( pctx, pkt, out );
|
||||||
|
@@ -87,8 +87,13 @@ void rlocs_init(void);
|
|||||||
|
|
||||||
struct rlocs *rlocs_new( char *filename );
|
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 );
|
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 );
|
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 );
|
struct rloc *rloc_find_by_address( struct rlocs *reg, struct in_addr *ipv4, struct in6_addr *ipv6 );
|
||||||
|
|
||||||
int rlocs_find_two_ipv4(
|
int rlocs_find_two_ipv4(
|
||||||
|
Reference in New Issue
Block a user