bool TcpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort)
{
- if(raw.len < tcp::TCP_HEADER_LEN)
+ if(raw.len < tcp::TCP_MIN_HEADER_LEN)
{
codec_events::decoder_event(codec, DECODE_TCP_DGRAM_LT_TCPHDR);
return false;
const tcp::TCPHdr* tcph = reinterpret_cast<const tcp::TCPHdr*>(raw.data);
const uint16_t tcph_len = tcph->hdr_len();
- if(tcph_len < tcp::TCP_HEADER_LEN)
+ if(tcph_len < tcp::TCP_MIN_HEADER_LEN)
{
codec_events::decoder_event(codec, DECODE_TCP_INVALID_OFFSET);
return false;
/* if options are present, decode them */
- uint16_t tcp_opt_len = (uint16_t)(tcph->hdr_len() - tcp::TCP_HEADER_LEN);
+ uint16_t tcp_opt_len = (uint16_t)(tcph->hdr_len() - tcp::TCP_MIN_HEADER_LEN);
if(tcp_opt_len > 0)
- DecodeTCPOptions((uint8_t *) (raw.data + tcp::TCP_HEADER_LEN), tcp_opt_len, codec);
+ DecodeTCPOptions((uint8_t *) (raw.data + tcp::TCP_MIN_HEADER_LEN), tcp_opt_len, codec);
int dsize = raw.len - tcph->hdr_len();
* 4) increment option code ptr
*
* TCP_OPTLENMAX = 40 because of
- * (((2^4) - 1) * 4 - tcp::TCP_HEADER_LEN
+ * (((2^4) - 1) * 4 - tcp::TCP_MIN_HEADER_LEN
*
*/
{
const tcp::TCPHdr* const hi = reinterpret_cast<const tcp::TCPHdr*>(raw_in);
- if (!buf.allocate(tcp::TCP_HEADER_LEN))
+ if (!buf.allocate(tcp::TCP_MIN_HEADER_LEN))
return false;
tcp::TCPHdr* tcph_out = reinterpret_cast<tcp::TCPHdr*>(buf.base);
}
tcph_out->th_offx2 = 0;
- tcph_out->set_offset(tcp::TCP_HEADER_LEN >> 2);
+ tcph_out->set_offset(tcp::TCP_MIN_HEADER_LEN >> 2);
tcph_out->th_win = 0;
tcph_out->th_urp = 0;
p->ptrs.dp = save_dp;
}
else
+ {
+ PktType tmp_type = p->type();
+ p->ptrs.set_pkt_type(PktType::IP);
LogIPHeader(log, p);
+ p->ptrs.set_pkt_type(tmp_type);
+ }
p->ptrs.ip_api = save_ip_api;
p->packet_flags |= save_frag_flag;
break;
case tcp::TcpOptCode::TIMESTAMP:
- TextLog_Print(log, "TS: %u %u", extract_32_bits(opt.data), opt.data + 4);
+ TextLog_Print(log, "TS: %u %u", extract_32_bits(opt.data), extract_32_bits(opt.data + 4));
break;
case tcp::TcpOptCode::CC:
LogNetData(log, buf, dlen + payload_len, NULL);
}
- free(payload);
+ free(payload);
return 0;
}
while (layer::set_outer_ip_api(p, p->ptrs.ip_api, num_layer) &&
tmp_api != p->ptrs.ip_api)
{
+#ifdef REG_TEST
+ // In Snort, cooked packets should not print an outer IP Header
+ if (p->is_cooked())
+ break;
+#endif
+
LogOuterIPHeader(log, p);
if (first)
LogNetData(log, p->pkt, p->pkth->caplen, p);
}
#ifdef REG_TEST
- TextLog_Print(log, "\n%s\n", SEPARATOR);
+ TextLog_Print(log, "\n%s\n\n", SEPARATOR);
#endif
}
if ( tcp_options_len > 0 )
{
const Layer& lyr = p->layers[layer];
- uint8_t* opts = const_cast<uint8_t*>(lyr.start) + tcp::TCP_HEADER_LEN;
+ uint8_t* opts = const_cast<uint8_t*>(lyr.start) + tcp::TCP_MIN_HEADER_LEN;
// lyr.length only includes valid tcp options
- uint8_t valid_opts_len = lyr.length - tcp::TCP_HEADER_LEN;
+ uint8_t valid_opts_len = lyr.length - tcp::TCP_MIN_HEADER_LEN;
if ( Norm_IsEnabled(c, NORM_TCP_OPT) )
{
inline bool is_udp() const
{ return ptrs.get_pkt_type() == PktType::UDP; }
+ inline bool is_cooked() const
+ { return packet_flags & PKT_PSEUDO; }
+
/* Get general, non-boolean information */
inline PktType type() const
{ return ptrs.get_pkt_type(); } // defined in codec.h
{
-constexpr uint8_t TCP_HEADER_LEN = 20; // this is actually the minimal TCP header lenght
+constexpr uint8_t TCP_MIN_HEADER_LEN = 20; // this is actually the minimal TCP header lenght
constexpr int OPT_TRUNC = -1;
constexpr int OPT_BADLEN = -2;
{ return th_offx2 >> 4; }
inline uint8_t options_len() const
- { return hdr_len() - TCP_HEADER_LEN; }
+ { return hdr_len() - TCP_MIN_HEADER_LEN; }
inline uint16_t src_port() const
{ return ntohs(th_sport); }
TcpOptIterator::TcpOptIterator(const TCPHdr* const tcp_header, const Packet* const p)
{
const uint8_t* const hdr = (const uint8_t* const)tcp_header;
- start_ptr = hdr + TCP_HEADER_LEN;
+ start_ptr = hdr + TCP_MIN_HEADER_LEN;
end_ptr = start_ptr; // == begin()
for (int i = p->num_layers-1; i >= 0; --i)
TcpOptIterator::TcpOptIterator(const TCPHdr* const tcp_header, const uint32_t valid_hdr_len)
{
const uint8_t* const hdr = (const uint8_t* const)tcp_header;
- start_ptr = hdr + TCP_HEADER_LEN;
+ start_ptr = hdr + TCP_MIN_HEADER_LEN;
- if (valid_hdr_len < TCP_HEADER_LEN)
+ if (valid_hdr_len < TCP_MIN_HEADER_LEN)
end_ptr = start_ptr;
else
end_ptr = hdr + valid_hdr_len;