]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
decode: clean up tunnel decode logic
authorVictor Julien <victor@inliniac.net>
Wed, 20 May 2015 19:42:19 +0000 (21:42 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 10 Jun 2015 10:35:46 +0000 (12:35 +0200)
Don't use mix of existing and custom types to indicate the next
layer.

src/decode-gre.c
src/decode-ipv4.c
src/decode-ipv6.c
src/decode-teredo.c
src/decode.c
src/decode.h

index af4c1af55b080c69d8c8366e9a8860739cab241a..f827cabe8815877705f2a6b57c18b486f3a51f0b 100644 (file)
@@ -201,7 +201,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, ui
             {
                 if (pq != NULL) {
                     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) {
                         PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
                         PacketEnqueue(pq,tp);
@@ -214,7 +214,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, ui
             {
                 if (pq != NULL) {
                     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) {
                         PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
                         PacketEnqueue(pq,tp);
@@ -227,7 +227,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, ui
             {
                 if (pq != NULL) {
                     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) {
                         PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
                         PacketEnqueue(pq,tp);
@@ -240,7 +240,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, ui
             {
                 if (pq != NULL) {
                     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) {
                         PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
                         PacketEnqueue(pq,tp);
index 856ae5b6d6473a558b7dc27e0e2312aeb4f63117..63aae4ede45b520255456025cf1cb9f7a48ce131 100644 (file)
@@ -583,7 +583,7 @@ int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
                     /* spawn off tunnel packet */
                     Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + IPV4_GET_HLEN(p),
                             IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p),
-                            IPV4_GET_IPPROTO(p), pq);
+                            DECODE_TUNNEL_IPV6, pq);
                     if (tp != NULL) {
                         PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV4);
                         PacketEnqueue(pq,tp);
index efd6f10f5033416da7c3aa06557c8a9f020cb38c..21ae5226e2ceae352d3af175d809a9d9567bee4e 100644 (file)
@@ -60,7 +60,7 @@ static void DecodeIPv4inIPv6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, u
     }
     if (IP_GET_RAW_VER(pkt) == 4) {
         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) {
                 PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV6);
                 /* 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 (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) {
                 PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV6);
                 PacketEnqueue(pq,tp);
index b4199a052d64c13a38aa0afa6caa7825f331d15c..208760277d0e9a7fdf27897fef082362e659fa9e 100644 (file)
@@ -91,7 +91,7 @@ int DecodeTeredo(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
                 int blen = len - (start - pkt);
                 /* spawn off tunnel packet */
                 Packet *tp = PacketTunnelPktSetup(tv, dtv, p, start, blen,
-                                                  IPPROTO_IPV6, pq);
+                                                  DECODE_TUNNEL_IPV6, pq);
                 if (tp != NULL) {
                     PKT_SET_SRC(tp, PKT_SRC_DECODER_TEREDO);
                     /* add the tp to the packet queue. */
index 16f5476b411a670df8b21db476e7c80c3dd131e5..ca96ee0adf88dd1c3140091d4ffee0026b704961 100644 (file)
 #include "output-flow.h"
 
 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) {
-        case PPP_OVER_GRE:
+        case DECODE_TUNNEL_PPP:
             return DecodePPP(tv, dtv, p, pkt, len, pq);
-        case IPPROTO_IP:
+        case DECODE_TUNNEL_IPV4:
             return DecodeIPV4(tv, dtv, p, pkt, len, pq);
-        case IPPROTO_IPV6:
+        case DECODE_TUNNEL_IPV6:
             return DecodeIPV6(tv, dtv, p, pkt, len, pq);
-       case VLAN_OVER_GRE:
+        case DECODE_TUNNEL_VLAN:
             return DecodeVLAN(tv, dtv, p, pkt, len, pq);
+        case DECODE_TUNNEL_ETHERNET:
+            return DecodeEthernet(tv, dtv, p, pkt, len, pq);
         default:
             SCLogInfo("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.", proto);
             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
  */
 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;
 
index 11501cdffcc1e013b3b6572d096215f89598d806..830b3b360a1c932479fbb5094d3d066602b936f5 100644 (file)
@@ -829,12 +829,19 @@ typedef struct DecodeThreadVars_
 #define IS_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,
-                             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);
 void PacketDefragPktSetupParent(Packet *parent);
+void DecodeRegisterPerfCounters(DecodeThreadVars *, ThreadVars *);
 Packet *PacketGetFromQueueOrAlloc(void);
 Packet *PacketGetFromAlloc(void);
 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 DecodePPPOESession(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 DecodeRaw(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);
 int DecodeIPV4(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t, PacketQueue *);