summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-02-23 15:30:41 +0200
committerHanoh Haim <hhaim@cisco.com>2016-02-23 15:30:41 +0200
commit68ebd739646a27f1bb92ce8eacb5bb76f6399580 (patch)
tree7611dbc58173e642a728e87c4ae7445f54391f62 /src
parente138e3c2b3f6dabb2641957e68034a2fe4674892 (diff)
fix ipv4 checksum error in case of pkt_size>128 and field offset less than ip-header (fd.io issue - Miro)
Diffstat (limited to 'src')
-rw-r--r--src/stateless/cp/trex_stream.cpp2
-rw-r--r--src/stateless/cp/trex_stream.h12
-rw-r--r--src/stateless/cp/trex_stream_vm.cpp22
-rw-r--r--src/stateless/cp/trex_stream_vm.h6
4 files changed, 36 insertions, 6 deletions
diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp
index fb0b35d5..05c14cba 100644
--- a/src/stateless/cp/trex_stream.cpp
+++ b/src/stateless/cp/trex_stream.cpp
@@ -62,7 +62,9 @@ TrexStream::vm_compile() {
}
/* compile */
+ m_vm.set_pkt(m_pkt.binary);
m_vm.compile(m_pkt.len);
+ m_vm.set_pkt(0);
/* create DP object */
m_vm_dp = m_vm.generate_dp_object();
diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h
index 2ab90c99..5240e96d 100644
--- a/src/stateless/cp/trex_stream.h
+++ b/src/stateless/cp/trex_stream.h
@@ -68,22 +68,26 @@ static inline uint16_t get_log2_size(uint16_t size){
* ==>62
*
*/
+
static inline uint16_t calc_writable_mbuf_size(uint16_t max_offset_writable,
uint16_t pkt_size){
- if ( pkt_size<=64 ){
- return (pkt_size);
- }
if (pkt_size<=128) {
return (pkt_size);
}
//pkt_size> 128
+ // if reside is less than 64 keep it as a single packet
uint16_t non_writable = pkt_size - (max_offset_writable +1) ;
if ( non_writable<64 ) {
return (pkt_size);
}
- return(max_offset_writable+1);
+
+ // keep the r/w at least 60 byte
+ if ((max_offset_writable+1)<=60) {
+ return 60;
+ }
+ return max_offset_writable+1;
}
diff --git a/src/stateless/cp/trex_stream_vm.cpp b/src/stateless/cp/trex_stream_vm.cpp
index f83025dd..b0cadfb6 100644
--- a/src/stateless/cp/trex_stream_vm.cpp
+++ b/src/stateless/cp/trex_stream_vm.cpp
@@ -396,8 +396,6 @@ void StreamVm::build_program(){
if (ins_type == StreamVmInstruction::itFIX_IPV4_CS) {
StreamVmInstructionFixChecksumIpv4 *lpFix =(StreamVmInstructionFixChecksumIpv4 *)inst;
- add_field_cnt(lpFix->m_pkt_offset +12);
-
if ( (lpFix->m_pkt_offset + IPV4_HDR_LEN) > m_pkt_size ) {
std::stringstream ss;
@@ -405,6 +403,26 @@ void StreamVm::build_program(){
err(ss.str());
}
+ uint16_t offset_next_layer = IPV4_HDR_LEN;
+
+ if ( m_pkt ){
+ IPHeader * ipv4= (IPHeader *)(m_pkt+lpFix->m_pkt_offset);
+ offset_next_layer = ipv4->getSize();
+ }
+
+ if (offset_next_layer<IPV4_HDR_LEN) {
+ offset_next_layer=IPV4_HDR_LEN;
+ }
+
+ if ( (lpFix->m_pkt_offset + offset_next_layer) > m_pkt_size ) {
+
+ std::stringstream ss;
+ ss << "instruction id '" << ins_id << "' fix ipv4 command offset " << lpFix->m_pkt_offset << "plus "<<offset_next_layer<< " is too high relative to packet size "<< m_pkt_size;
+ err(ss.str());
+ }
+ /* calculate this offset from the packet */
+ add_field_cnt(lpFix->m_pkt_offset + offset_next_layer);
+
StreamDPOpIpv4Fix ipv_fix;
ipv_fix.m_offset = lpFix->m_pkt_offset;
ipv_fix.m_op = StreamDPVmInstructions::ditFIX_IPV4_CS;
diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h
index 13504703..c16545d9 100644
--- a/src/stateless/cp/trex_stream_vm.h
+++ b/src/stateless/cp/trex_stream_vm.h
@@ -1408,6 +1408,7 @@ public:
m_split_instr=NULL;
m_is_compiled = false;
+ m_pkt=0;
}
@@ -1511,6 +1512,10 @@ public:
/* raise exception */
void err(const std::string &err);
+ void set_pkt(uint8_t *pkt){
+ m_pkt=pkt;
+ }
+
/**
* return a pointer to a flow var / client var
@@ -1565,6 +1570,7 @@ private:
StreamDPVmInstructions m_instructions;
StreamVmInstructionVar *m_split_instr;
+ uint8_t *m_pkt;