-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Teredo tunnel supports #13
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* Copyright (C) 2012 Open Information Security Foundation | ||
* | ||
* You can copy, redistribute or modify this Program under the terms of | ||
* the GNU General Public License version 2 as published by the Free | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
/** | ||
* \ingroup decode | ||
* | ||
* @{ | ||
*/ | ||
|
||
|
||
/** | ||
* \file | ||
* | ||
* \author Eric Leblond <eric@regit.org> | ||
* | ||
* Decode Teredo Tunneling protocol | ||
*/ | ||
|
||
#include "suricata-common.h" | ||
#include "decode.h" | ||
#include "decode-ipv6.h" | ||
#include "util-debug.h" | ||
|
||
/** | ||
* \brief Function to decode Teredo packets | ||
* | ||
* \retval 0 if packet is not a Teredo packet, 1 if it is | ||
*/ | ||
int DecodeTeredo(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq) | ||
{ | ||
|
||
unsigned char *start = p->payload; | ||
|
||
/* Is this packet to short to contain an IPv6 packet ? */ | ||
if (UDP_GET_LEN(p) < UDP_HEADER_LEN + IPV6_HEADER_LEN) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the "len" parameter passed to this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can for sure. Doing this. |
||
return 0; | ||
|
||
/* Teredo encapsulate IPv6 in UDP and can add some custom message | ||
* part before the IPv6 packet. Here we iter on the messages to get | ||
* on the IPv6 packet. */ | ||
while (start[0] == 0x0) { | ||
switch (p->payload[1]) { | ||
/* origin indication: compatible with tunnel */ | ||
case 0x0: | ||
if (UDP_GET_LEN(p) >= 8 + UDP_HEADER_LEN + IPV6_HEADER_LEN) | ||
start = p->payload + 8; | ||
else | ||
return 0; | ||
break; | ||
/* authentication: negotiation not real tunnel */ | ||
case 0x1: | ||
return 0; | ||
/* this case is not possible in Teredo: not that protocol */ | ||
default: | ||
return 0; | ||
} | ||
} | ||
|
||
if (IP_GET_RAW_VER(start) == 6) { | ||
IPV6Hdr *thdr = (IPV6Hdr *)start; | ||
/* This does looks like Teredo protocol, let's pray together */ | ||
if (UDP_GET_LEN(p) == UDP_HEADER_LEN + IPV6_HEADER_LEN + | ||
IPV6_GET_RAW_PLEN(thdr) + (start - p->payload)) { | ||
if (pq != NULL) { | ||
/* spawn off tunnel packet */ | ||
Packet *tp = PacketPseudoPktSetup(p, start, | ||
IPV4_GET_IPLEN(p) - (start - p->payload), | ||
IPPROTO_IPV6); | ||
if (tp != NULL) { | ||
/* send that to the Tunnel decoder */ | ||
DecodeTunnel(tv, dtv, tp, GET_PKT_DATA(tp), | ||
GET_PKT_LEN(tp), pq, IPPROTO_IPV6); | ||
|
||
/* add the tp to the packet queue. */ | ||
PacketEnqueue(pq,tp); | ||
} | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Copyright (C) 2012 Open Information Security Foundation | ||
* | ||
* You can copy, redistribute or modify this Program under the terms of | ||
* the GNU General Public License version 2 as published by the Free | ||
* Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* version 2 along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
int DecodeTeredo(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, | ||
uint8_t *pkt, uint16_t len, PacketQueue *pq); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use p->payload, not "pkt"? The decode function normally operate on the buffer that is passed to it through the function parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to work on the content of the UDP packet: Toredo data are put inside UDP payload.
The Packet has already been successfully decoded as UDP and thus we can use p->payload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but it is different than the normal flow of things. Maybe just pass p->payload and p->payload_len to this function and use the pkt, len parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems consistent with other part of the decoding engine. Doing this.