Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IPv4-in-IPv6 #10

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/decode-ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@
#define IPV6_EXTHDRS ip6eh.ip6_exthdrs
#define IPV6_EH_CNT ip6eh.ip6_exthdrs_cnt

/**
* \brief Function to decode IPv4 in IPv6 packets
*
* \retval 0 if packet is not a IPv4 in IPv6 packet, 1 if it is
*/
static int DecodeIPv4inIPv6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t plen, PacketQueue *pq)
{
/* Try to detect IPv4 in IPv6 */
if (IP_GET_RAW_VER(pkt) == 4) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plen check is missing. We can't assume the buffer to be big enough for even this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I've forgot that IP_GET_RAW_VER was not checking the protocol inside the IPv6 header.

if (unlikely(plen < IPV4_HEADER_LEN + IPV4_HEADER_LEN)) {
ENGINE_SET_EVENT(p, IPV4_PKT_TOO_SMALL);
return 0;
}
if (pq != NULL) {
Packet *tp = PacketPseudoPktSetup(p, pkt, plen, IPPROTO_IP);
if (tp != NULL) {
DecodeTunnel(tv, dtv, tp, GET_PKT_DATA(tp),
GET_PKT_LEN(tp), pq, IPPROTO_IP);
PacketEnqueue(pq,tp);
return 1;
}
}
}
return 0;
}

static void
DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
{
Expand Down Expand Up @@ -408,6 +434,9 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
SCReturn;

default:
if (DecodeIPv4inIPv6(tv, dtv, p, pkt, plen, pq) == 1) {
SCReturn;
}
IPV6_SET_L4PROTO(p,nh);
SCReturn;
}
Expand Down Expand Up @@ -492,6 +521,9 @@ void DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
DecodeIPV6ExtHdrs(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq);
break;
default:
if (DecodeIPv4inIPv6(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq) == 1) {
SCReturn;
}
p->proto = IPV6_GET_NH(p);
break;
}
Expand Down