diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-02-23 15:30:41 +0200 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-02-23 15:30:41 +0200 |
commit | 68ebd739646a27f1bb92ce8eacb5bb76f6399580 (patch) | |
tree | 7611dbc58173e642a728e87c4ae7445f54391f62 /src/stateless/cp/trex_stream_vm.cpp | |
parent | e138e3c2b3f6dabb2641957e68034a2fe4674892 (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/stateless/cp/trex_stream_vm.cpp')
-rw-r--r-- | src/stateless/cp/trex_stream_vm.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
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; |