]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
decode vlan: Always fill in vlan_id
authorMax Fillinger <maximilian.fillinger@fox-it.com>
Mon, 8 Jul 2019 14:01:23 +0000 (16:01 +0200)
committerMax Fillinger <maximilian.fillinger@fox-it.com>
Wed, 10 Jul 2019 10:10:22 +0000 (12:10 +0200)
Since the vlan.use-for-tracking setting is now handled in flow-hash.c,
we can fill in the vlan_id fields unconditionally. This makes the vlanh
fields unnecessary.

Related to https://redmine.openinfosecfoundation.org/issues/3076

src/decode-vlan.c
src/decode.h
src/source-af-packet.c
src/source-pfring.c
src/stream-tcp.c

index 78e257eb3aa100211809a5a6d5ab2dcd7a583fba..9a714341a4283cd356cb6fc4006832118bdf4fe0 100644 (file)
@@ -77,21 +77,17 @@ int DecodeVLAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
         return TM_ECODE_FAILED;
     }
 
-    p->vlanh[p->vlan_idx] = (VLANHdr *)pkt;
-    if(p->vlanh[p->vlan_idx] == NULL)
+    VLANHdr *vlan_hdr = (VLANHdr *)pkt;
+    if(vlan_hdr == NULL)
         return TM_ECODE_FAILED;
 
-    proto = GET_VLAN_PROTO(p->vlanh[p->vlan_idx]);
+    proto = GET_VLAN_PROTO(vlan_hdr);
 
     SCLogDebug("p %p pkt %p VLAN protocol %04x VLAN PRI %d VLAN CFI %d VLAN ID %d Len: %" PRIu32 "",
-            p, pkt, proto, GET_VLAN_PRIORITY(p->vlanh[p->vlan_idx]),
-            GET_VLAN_CFI(p->vlanh[p->vlan_idx]), GET_VLAN_ID(p->vlanh[p->vlan_idx]), len);
+            p, pkt, proto, GET_VLAN_PRIORITY(vlan_hdr), GET_VLAN_CFI(vlan_hdr),
+            GET_VLAN_ID(vlan_hdr), len);
 
-    /* only store the id for flow hashing if it's not disabled. */
-    if (dtv->vlan_disabled == 0)
-        p->vlan_id[p->vlan_idx] = (uint16_t)GET_VLAN_ID(p->vlanh[p->vlan_idx]);
-
-    p->vlan_idx++;
+    p->vlan_id[p->vlan_idx++] = (uint16_t)GET_VLAN_ID(vlan_hdr);
 
     switch (proto)   {
         case ETHERNET_TYPE_IP:
@@ -146,11 +142,8 @@ uint16_t DecodeVLANGetId(const Packet *p, uint8_t layer)
 {
     if (unlikely(layer > 1))
         return 0;
-
-    if (p->vlanh[layer] == NULL && (p->vlan_idx >= (layer + 1))) {
+    if (p->vlan_idx > layer) {
         return p->vlan_id[layer];
-    } else {
-        return GET_VLAN_ID(p->vlanh[layer]);
     }
     return 0;
 }
@@ -288,7 +281,7 @@ static int DecodeVLANtest03 (void)
     DecodeVLAN(&tv, &dtv, p, raw_vlan, sizeof(raw_vlan), NULL);
 
 
-    if(p->vlanh[0] == NULL) {
+    if(p->vlan_id[0] == 0) {
         goto error;
     }
 
index 719f15da87a5d3a56d1f87017149afb51a5e2b38..6cb54c01fefaf5dcbc1d7c9e4ac6ba32052c6791 100644 (file)
@@ -535,8 +535,6 @@ typedef struct Packet_
 
     GREHdr *greh;
 
-    VLANHdr *vlanh[2];
-
     /* ptr to the payload of the packet
      * with it's length. */
     uint8_t *payload;
@@ -795,8 +793,6 @@ void CaptureStatsSetup(ThreadVars *tv, CaptureStats *s);
         (p)->pppoesh = NULL;                    \
         (p)->pppoedh = NULL;                    \
         (p)->greh = NULL;                       \
-        (p)->vlanh[0] = NULL;                   \
-        (p)->vlanh[1] = NULL;                   \
         (p)->payload = NULL;                    \
         (p)->payload_len = 0;                   \
         (p)->BypassPacketsFlow = NULL;          \
index 1dbf0bb010b04fa95133a3131062c44a218e8ef5..f9d374897de46bb283e688cb7f2ab192504fd613 100644 (file)
@@ -952,7 +952,6 @@ static int AFPReadFromRing(AFPThreadVars *ptv)
             (h.h2->tp_status & TP_STATUS_VLAN_VALID || h.h2->tp_vlan_tci)) {
             p->vlan_id[0] = h.h2->tp_vlan_tci & 0x0fff;
             p->vlan_idx = 1;
-            p->vlanh[0] = NULL;
         }
 
         if (ptv->flags & AFP_ZERO_COPY) {
@@ -1076,7 +1075,6 @@ static inline int AFPParsePacketV3(AFPThreadVars *ptv, struct tpacket_block_desc
             (ppd->tp_status & TP_STATUS_VLAN_VALID || ppd->hv1.tp_vlan_tci)) {
         p->vlan_id[0] = ppd->hv1.tp_vlan_tci & 0x0fff;
         p->vlan_idx = 1;
-        p->vlanh[0] = NULL;
     }
 
     if (ptv->flags & AFP_ZERO_COPY) {
index 70b5a71fd9c492cdce33e2f92a6ccfd9a912d344..d253aa62b1b42f7655df8f3f0dd51c7bea4919ac 100644 (file)
@@ -262,7 +262,6 @@ static inline void PfringProcessPacket(void *user, struct pfring_pkthdr *h, Pack
     {
         p->vlan_id[0] = h->extended_hdr.parsed_pkt.vlan_id & 0x0fff;
         p->vlan_idx = 1;
-        p->vlanh[0] = NULL;
 
         if (!ptv->vlan_hdr_warned) {
             SCLogWarning(SC_ERR_PF_RING_VLAN, "no VLAN header in the raw "
index 3c10dc7d0342045f4891969b8d47629fa7b3757e..b1bf2b890d33d9b14fd43e7544562ab698cb8e68 100644 (file)
@@ -10284,7 +10284,7 @@ static int StreamTcpTest40(void)
 
     DecodeVLAN(&tv, &dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), NULL);
 
-    FAIL_IF(p->vlanh[0] == NULL);
+    FAIL_IF(p->vlan_id[0] == 0);
 
     FAIL_IF(p->tcph == NULL);