return TM_ECODE_OK;
}
+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))) {
+ return p->vlan_id[layer];
+ } else {
+ return GET_VLAN_ID(p->vlanh[layer]);
+ }
+ return 0;
+}
+
#ifdef UNITTESTS
/** \todo Must GRE+VLAN and Multi-Vlan packets to
* create more tests
#ifndef __DECODE_VLAN_H__
#define __DECODE_VLAN_H__
+uint16_t DecodeVLANGetId(const struct Packet_ *, uint8_t layer);
+
/** Vlan type */
#define ETHERNET_TYPE_VLAN 0x8100
#define GET_VLAN_ID(vlanh) ((uint16_t)(ntohs((vlanh)->vlan_cfi) & 0x0FFF))
#define GET_VLAN_PROTO(vlanh) ((ntohs((vlanh)->protocol)))
+#define VLAN_GET_ID1(p) DecodeVLANGetId((p), 0)
+#define VLAN_GET_ID2(p) DecodeVLANGetId((p), 1)
+
/** Vlan header struct */
typedef struct VLANHdr_ {
uint16_t vlan_cfi;
switch (p->vlan_idx) {
case 1:
json_object_set_new(js, "vlan",
- json_integer(ntohs(GET_VLAN_ID(p->vlanh[0]))));
+ json_integer(ntohs(VLAN_GET_ID1(p))));
break;
case 2:
js_vlan = json_array();
if (unlikely(js != NULL)) {
json_array_append_new(js_vlan,
- json_integer(ntohs(GET_VLAN_ID(p->vlanh[0]))));
+ json_integer(ntohs(VLAN_GET_ID1(p))));
json_array_append_new(js_vlan,
- json_integer(ntohs(GET_VLAN_ID(p->vlanh[1]))));
+ json_integer(ntohs(VLAN_GET_ID2(p))));
json_object_set_new(js, "vlan", js_vlan);
}
break;