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
pull/4016/head
Max Fillinger 7 years ago
parent cef9961f59
commit 8d3b04b0e3

@ -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;
}

@ -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; \

@ -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) {

@ -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 "

@ -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);

Loading…
Cancel
Save