decode: clean up tunnel decode logic

Don't use mix of existing and custom types to indicate the next
layer.
pull/1540/head
Victor Julien 10 years ago
parent ef7cd043cc
commit aa6b24f814

@ -201,7 +201,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, ui
{ {
if (pq != NULL) { if (pq != NULL) {
Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len, Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len,
len - header_len, IPPROTO_IP, pq); len - header_len, DECODE_TUNNEL_IPV4, pq);
if (tp != NULL) { if (tp != NULL) {
PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
PacketEnqueue(pq,tp); PacketEnqueue(pq,tp);
@ -214,7 +214,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, ui
{ {
if (pq != NULL) { if (pq != NULL) {
Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len, Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len,
len - header_len, PPP_OVER_GRE, pq); len - header_len, DECODE_TUNNEL_PPP, pq);
if (tp != NULL) { if (tp != NULL) {
PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
PacketEnqueue(pq,tp); PacketEnqueue(pq,tp);
@ -227,7 +227,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, ui
{ {
if (pq != NULL) { if (pq != NULL) {
Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len, Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len,
len - header_len, IPPROTO_IPV6, pq); len - header_len, DECODE_TUNNEL_IPV6, pq);
if (tp != NULL) { if (tp != NULL) {
PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
PacketEnqueue(pq,tp); PacketEnqueue(pq,tp);
@ -240,7 +240,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, ui
{ {
if (pq != NULL) { if (pq != NULL) {
Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len, Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len,
len - header_len, VLAN_OVER_GRE, pq); len - header_len, DECODE_TUNNEL_VLAN, pq);
if (tp != NULL) { if (tp != NULL) {
PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
PacketEnqueue(pq,tp); PacketEnqueue(pq,tp);

@ -583,7 +583,7 @@ int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
/* spawn off tunnel packet */ /* spawn off tunnel packet */
Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + IPV4_GET_HLEN(p), Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + IPV4_GET_HLEN(p),
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p),
IPV4_GET_IPPROTO(p), pq); DECODE_TUNNEL_IPV6, pq);
if (tp != NULL) { if (tp != NULL) {
PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV4); PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV4);
PacketEnqueue(pq,tp); PacketEnqueue(pq,tp);

@ -60,7 +60,7 @@ static void DecodeIPv4inIPv6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, u
} }
if (IP_GET_RAW_VER(pkt) == 4) { if (IP_GET_RAW_VER(pkt) == 4) {
if (pq != NULL) { if (pq != NULL) {
Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt, plen, IPPROTO_IP, pq); Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt, plen, DECODE_TUNNEL_IPV4, pq);
if (tp != NULL) { if (tp != NULL) {
PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV6); PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV6);
/* add the tp to the packet queue. */ /* add the tp to the packet queue. */
@ -88,7 +88,7 @@ static int DecodeIP6inIP6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint
} }
if (IP_GET_RAW_VER(pkt) == 6) { if (IP_GET_RAW_VER(pkt) == 6) {
if (unlikely(pq != NULL)) { if (unlikely(pq != NULL)) {
Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt, plen, IPPROTO_IPV6, pq); Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt, plen, DECODE_TUNNEL_IPV6, pq);
if (tp != NULL) { if (tp != NULL) {
PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV6); PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV6);
PacketEnqueue(pq,tp); PacketEnqueue(pq,tp);

@ -91,7 +91,7 @@ int DecodeTeredo(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
int blen = len - (start - pkt); int blen = len - (start - pkt);
/* spawn off tunnel packet */ /* spawn off tunnel packet */
Packet *tp = PacketTunnelPktSetup(tv, dtv, p, start, blen, Packet *tp = PacketTunnelPktSetup(tv, dtv, p, start, blen,
IPPROTO_IPV6, pq); DECODE_TUNNEL_IPV6, pq);
if (tp != NULL) { if (tp != NULL) {
PKT_SET_SRC(tp, PKT_SRC_DECODER_TEREDO); PKT_SET_SRC(tp, PKT_SRC_DECODER_TEREDO);
/* add the tp to the packet queue. */ /* add the tp to the packet queue. */

@ -67,17 +67,19 @@
#include "output-flow.h" #include "output-flow.h"
int DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, int DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
uint8_t *pkt, uint16_t len, PacketQueue *pq, uint8_t proto) uint8_t *pkt, uint16_t len, PacketQueue *pq, enum DecodeTunnelProto proto)
{ {
switch (proto) { switch (proto) {
case PPP_OVER_GRE: case DECODE_TUNNEL_PPP:
return DecodePPP(tv, dtv, p, pkt, len, pq); return DecodePPP(tv, dtv, p, pkt, len, pq);
case IPPROTO_IP: case DECODE_TUNNEL_IPV4:
return DecodeIPV4(tv, dtv, p, pkt, len, pq); return DecodeIPV4(tv, dtv, p, pkt, len, pq);
case IPPROTO_IPV6: case DECODE_TUNNEL_IPV6:
return DecodeIPV6(tv, dtv, p, pkt, len, pq); return DecodeIPV6(tv, dtv, p, pkt, len, pq);
case VLAN_OVER_GRE: case DECODE_TUNNEL_VLAN:
return DecodeVLAN(tv, dtv, p, pkt, len, pq); return DecodeVLAN(tv, dtv, p, pkt, len, pq);
case DECODE_TUNNEL_ETHERNET:
return DecodeEthernet(tv, dtv, p, pkt, len, pq);
default: default:
SCLogInfo("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.", proto); SCLogInfo("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.", proto);
break; break;
@ -251,7 +253,8 @@ inline int PacketCopyData(Packet *p, uint8_t *pktdata, int pktlen)
* \retval p the pseudo packet or NULL if out of memory * \retval p the pseudo packet or NULL if out of memory
*/ */
Packet *PacketTunnelPktSetup(ThreadVars *tv, DecodeThreadVars *dtv, Packet *parent, Packet *PacketTunnelPktSetup(ThreadVars *tv, DecodeThreadVars *dtv, Packet *parent,
uint8_t *pkt, uint16_t len, uint8_t proto, PacketQueue *pq) uint8_t *pkt, uint16_t len, enum DecodeTunnelProto proto,
PacketQueue *pq)
{ {
int ret; int ret;

@ -829,12 +829,19 @@ typedef struct DecodeThreadVars_
#define IS_TUNNEL_PKT_VERDICTED(p) (((p)->flags & PKT_TUNNEL_VERDICTED)) #define IS_TUNNEL_PKT_VERDICTED(p) (((p)->flags & PKT_TUNNEL_VERDICTED))
#define SET_TUNNEL_PKT_VERDICTED(p) ((p)->flags |= PKT_TUNNEL_VERDICTED) #define SET_TUNNEL_PKT_VERDICTED(p) ((p)->flags |= PKT_TUNNEL_VERDICTED)
enum DecodeTunnelProto {
DECODE_TUNNEL_ETHERNET,
DECODE_TUNNEL_VLAN,
DECODE_TUNNEL_IPV4,
DECODE_TUNNEL_IPV6,
DECODE_TUNNEL_PPP,
};
void DecodeRegisterPerfCounters(DecodeThreadVars *, ThreadVars *);
Packet *PacketTunnelPktSetup(ThreadVars *tv, DecodeThreadVars *dtv, Packet *parent, Packet *PacketTunnelPktSetup(ThreadVars *tv, DecodeThreadVars *dtv, Packet *parent,
uint8_t *pkt, uint16_t len, uint8_t proto, PacketQueue *pq); uint8_t *pkt, uint16_t len, enum DecodeTunnelProto proto, PacketQueue *pq);
Packet *PacketDefragPktSetup(Packet *parent, uint8_t *pkt, uint16_t len, uint8_t proto); Packet *PacketDefragPktSetup(Packet *parent, uint8_t *pkt, uint16_t len, uint8_t proto);
void PacketDefragPktSetupParent(Packet *parent); void PacketDefragPktSetupParent(Packet *parent);
void DecodeRegisterPerfCounters(DecodeThreadVars *, ThreadVars *);
Packet *PacketGetFromQueueOrAlloc(void); Packet *PacketGetFromQueueOrAlloc(void);
Packet *PacketGetFromAlloc(void); Packet *PacketGetFromAlloc(void);
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p); void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p);
@ -855,7 +862,7 @@ int DecodeSll(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, P
int DecodePPP(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *); int DecodePPP(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
int DecodePPPOESession(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *); int DecodePPPOESession(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
int DecodePPPOEDiscovery(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *); int DecodePPPOEDiscovery(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
int DecodeTunnel(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *, uint8_t) __attribute__ ((warn_unused_result)); int DecodeTunnel(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *, enum DecodeTunnelProto) __attribute__ ((warn_unused_result));
int DecodeNull(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *); int DecodeNull(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
int DecodeRaw(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *); int DecodeRaw(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
int DecodeIPV4(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *); int DecodeIPV4(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);

Loading…
Cancel
Save