summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIdo Barnea <ibarnea@cisco.com>2017-03-22 12:50:28 +0200
committerIdo Barnea <ibarnea@cisco.com>2017-03-22 12:50:28 +0200
commit21d1e70dd1f25e3b1bd9f2916ccc8f2678eba870 (patch)
tree5bd675f452cad131510b47fd0bbdeb9d9a486538
parent9218827e7337abe0296b9bb27ea3ca0865f8ef0e (diff)
Use VLANHeader in pre_test
Signed-off-by: Ido Barnea <ibarnea@cisco.com>
-rw-r--r--src/pre_test.cpp37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/pre_test.cpp b/src/pre_test.cpp
index 9316d371..270ef33d 100644
--- a/src/pre_test.cpp
+++ b/src/pre_test.cpp
@@ -4,7 +4,7 @@
*/
/*
- Copyright (c) 2016-2016 Cisco Systems, Inc.
+ Copyright (c) 2016-2017 Cisco Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
#include <arpa/inet.h>
#include <common/Network/Packet/EthernetHeader.h>
#include <common/Network/Packet/Arp.h>
+#include "common/Network/Packet/VLANHeader.h"
#include "common/basic_utils.h"
#include "bp_sim.h"
#include "main_dpdk.h"
@@ -378,24 +379,40 @@ void CPretest::send_grat_arp_all() {
bool CPretest::is_arp(const uint8_t *p, uint16_t pkt_size, ArpHdr *&arp, uint16_t &vlan_tag) {
EthernetHeader *m_ether = (EthernetHeader *)p;
vlan_tag = 0;
+ uint16_t min_size = sizeof(EthernetHeader);
+ VLANHeader *vlan;
- if ((pkt_size < sizeof(EthernetHeader)) ||
- ((m_ether->getNextProtocol() != EthernetHeader::Protocol::ARP)
- && (m_ether->getNextProtocol() != EthernetHeader::Protocol::VLAN)))
+ if (pkt_size < min_size)
return false;
- if (m_ether->getNextProtocol() == EthernetHeader::Protocol::ARP) {
+ switch(m_ether->getNextProtocol()) {
+ case EthernetHeader::Protocol::ARP:
arp = (ArpHdr *)(p + 14);
- } else {
- if (m_ether->getVlanProtocol() != EthernetHeader::Protocol::ARP) {
+ min_size += sizeof(ArpHdr);
+ break;
+ case EthernetHeader::Protocol::VLAN:
+ vlan = (VLANHeader *)(p + 14);
+
+ min_size += sizeof(VLANHeader);
+ if (pkt_size < min_size)
+ return false;
+
+ if (vlan->getNextProtocolHostOrder() != EthernetHeader::Protocol::ARP) {
return false;
} else {
- vlan_tag = m_ether->getVlanTag() & 0xfff;
- arp = (ArpHdr *)(p + 18);
+ vlan_tag = vlan->getVlanTag();
+ arp = (ArpHdr *)(p + 14 + sizeof(VLANHeader));
}
+ min_size += sizeof(ArpHdr);
+ break;
+ default:
+ return false;
}
- return true;
+ if (pkt_size < min_size)
+ return false;
+ else
+ return true;
}
int CPretest::handle_rx(int port_id, int queue_id) {