From: Max Fillinger Date: Mon, 8 Jul 2019 14:01:23 +0000 (+0200) Subject: decode vlan: Always fill in vlan_id X-Git-Tag: suricata-5.0.0-rc1~207 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d3b04b0e3a013c12261e0d70d76cc9eb83d5773;p=thirdparty%2Fsuricata.git decode vlan: Always fill in vlan_id 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 --- diff --git a/src/decode-vlan.c b/src/decode-vlan.c index 78e257eb3a..9a714341a4 100644 --- a/src/decode-vlan.c +++ b/src/decode-vlan.c @@ -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; } diff --git a/src/decode.h b/src/decode.h index 719f15da87..6cb54c01fe 100644 --- a/src/decode.h +++ b/src/decode.h @@ -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; \ diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 1dbf0bb010..f9d374897d 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -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) { diff --git a/src/source-pfring.c b/src/source-pfring.c index 70b5a71fd9..d253aa62b1 100644 --- a/src/source-pfring.c +++ b/src/source-pfring.c @@ -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 " diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 3c10dc7d03..b1bf2b890d 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -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);