namespace{
-const uint32_t ICMP_HEADER_LEN = 4;
-const uint32_t ICMP_NORMAL_LEN = 8;
-
class Icmp4Codec : public Codec{
bool Icmp4Codec::decode(const uint8_t* raw_pkt, const uint32_t raw_len,
Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
{
- if(raw_len < ICMP_HEADER_LEN)
+ if(raw_len < icmp4::hdr_len())
{
DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
"WARNING: Truncated ICMP4 header (%d bytes).\n", raw_len););
}
}
- lyr_len = ICMP_HEADER_LEN;
-
- p->dsize = (u_short)(raw_len - ICMP_HEADER_LEN);
- p->data = raw_pkt + ICMP_HEADER_LEN;
+ lyr_len = icmp4::hdr_len();
DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "ICMP type: %d code: %d\n",
p->icmph->type, p->icmph->code););
/* Run a bunch of ICMP decoder rules */
- p->dsize = (u_short)(raw_len - lyr_len);
- p->data = raw_pkt + lyr_len;
+ p->dsize = (u_short)(raw_len - lyr_len); // setting for use in ICMP4MiscTests
ICMP4MiscTests(p);
p->proto_bits |= PROTO_BIT__ICMP;
p->proto_bits &= ~(PROTO_BIT__UDP | PROTO_BIT__TCP);
-
- next_prot_id = -1;
return true;
}
break;
default:
+ DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
+ "WARNING: ICMP6_TYPE (type %d).\n", p->icmp6h->type););
codec_events::decoder_event(p, DECODE_ICMP6_TYPE_OTHER);
lyr_len = icmp6::hdr_min_len();
c->icmp6h = (ICMP6Hdr*)lyr->start;
}
-#endif
/*
* CHECKSUM
return (unsigned short)(~cksum);
}
+#endif
static Codec* ctor()
{
Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
{
uint32_t ip_len; /* length from the start of the ip hdr to the pkt end */
+ uint16_t hlen; /* ip header length */
// dc.ip++;
ip_len = ntohs(p->iph->ip_len);
/* get the IP header length */
- lyr_len = ipv4::get_pkt_hdr_len(p->iph) << 2;
+ hlen = ipv4::get_pkt_hdr_len(p->iph) << 2;
/* header length sanity check */
- if(lyr_len < ipv4::hdr_len())
+ if(hlen < ipv4::hdr_len())
{
DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
- "Bogus IP header length of %i bytes\n", lyr_len););
+ "Bogus IP header length of %i bytes\n", hlen););
codec_events::decoder_event(p, DECODE_IPV4_INVALID_HEADER_LEN);
}
#endif
- if(ip_len < lyr_len)
+ if(ip_len < hlen)
{
DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
"IP dgm len (%d bytes) < IP hdr "
- "len (%d bytes), packet discarded\n", ip_len, lyr_len););
+ "len (%d bytes), packet discarded\n", ip_len, hlen););
codec_events::decoder_event(p, DECODE_IPV4_DGRAM_LT_IPHDR);
* need to check them (should make this a command line/config
* option
*/
- int16_t csum = in_chksum_ip((u_short *)p->iph, lyr_len);
+ int16_t csum = in_chksum_ip((u_short *)p->iph, hlen);
if(csum)
{
}
/* test for IP options */
- p->ip_options_len = (uint16_t)(lyr_len - ipv4::hdr_len());
+ p->ip_options_len = (uint16_t)(hlen - ipv4::hdr_len());
if(p->ip_options_len > 0)
{
p->actual_ip_len = (uint16_t) ip_len;
/* set the remaining packet length */
- ip_len -= lyr_len;
+ ip_len -= hlen;
/* check for fragmented packets */
p->frag_offset = ntohs(p->iph->ip_off);
{
/* set the packet fragment flag */
p->frag_flag = 1;
- p->ip_frag_start = raw_packet + lyr_len;
+ p->ip_frag_start = raw_packet + hlen;
p->ip_frag_len = (uint16_t)ip_len;
// dc.frags++;
}
}
/* Set some convienience pointers */
- p->ip_data = raw_packet + lyr_len;
+ p->ip_data = raw_packet + hlen;
p->ip_dsize = (u_short) ip_len;
/* See if there are any ip_proto only rules that match */
p->proto_bits |= PROTO_BIT__IP;
IPMiscTests(p);
+ lyr_len = hlen;
/* if this packet isn't a fragment
* or if it is, its a UDP packet and offset is 0 */
(p->iph->ip_proto == IPPROTO_UDP)))
{
DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "IP header length: %lu\n",
- (unsigned long)lyr_len););
+ (unsigned long)hlen););
next_prot_id = p->iph->ip_proto;
- return true;
}
else
{
/* set the payload pointer and payload size */
- p->data = raw_packet + lyr_len;
+ p->data = raw_packet + hlen;
p->dsize = (u_short) ip_len;
}
#if 0
+#endif
case IPPROTO_IP_MOBILITY:
case IPPROTO_SUN_ND:
case IPPROTO_PIM:
- if ( Event_Enabled(DECODE_IP_BAD_PROTO) )
- codec_events::decoder_event(p, DECODE_IP_BAD_PROTO));
-// dc.other++;
+ codec_events::decoder_event(p, DECODE_IP_BAD_PROTO);
p->data = pkt;
p->dsize = (uint16_t)len;
return;
case IPPROTO_PGM:
-// dc.other++;
p->data = pkt;
p->dsize = (uint16_t)len;
- if ( Event_Enabled(DECODE_PGM_NAK_OVERFLOW) )
CheckPGMVuln(p);
return;
case IPPROTO_IGMP:
-// dc.other++;
p->data = pkt;
p->dsize = (uint16_t)len;
-
- if ( Event_Enabled(DECODE_IGMP_OPTIONS_DOS) )
- CheckIGMPVuln(p);
+ CheckIGMPVuln(p);
return;
-#endif
+
default:
if (GET_IPH_PROTO(p) >= MIN_UNASSIGNED_IP_PROTO)
codec_events::decoder_event(p, DECODE_IP_UNASSIGNED_PROTO);
-// dc.other++;
p->data = pkt;
p->dsize = (uint16_t)len;
return;
Packet* encode_pkt = NULL;
uint64_t total_rebuilt_pkts = 0;
-static inline int IsIcmp (int type)
-{
- static constexpr int s_icmp[ENC_MAX] = { 0, 0, 1, 1, 1 };
- return ( s_icmp[type] );
-}
-
//-------------------------------------------------------------------------
// encoders operate layer by layer:
// * base+off is start of packet
Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
{
lyr_len = sizeof(ERSpanType2Hdr);
- uint32_t payload_len;
ERSpanType2Hdr *erSpan2Hdr = (ERSpanType2Hdr *)raw_pkt;
if (len < sizeof(ERSpanType2Hdr))
bool Erspan3Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
{
- lyr_len= sizeof(ERSpanType3Hdr);
- uint32_t payload_len;
+ lyr_len = sizeof(ERSpanType3Hdr);
ERSpanType3Hdr *erSpan3Hdr = (ERSpanType3Hdr *)raw_pkt;
if (len < sizeof(ERSpanType3Hdr))
static const uint32_t GRE_SRE_HEADER_LEN = 4;
/* GRE version 1 used with PPTP */
-static const uint32_t GRE_V1_HEADER_LEN =8;
+/* static const uint32_t GRE_V1_HEADER_LEN == GRE_HEADER_LEN + GRE_KEY_LEN; */
static const uint32_t GRE_V1_ACK_LEN = 4;
#define GRE_V1_FLAGS(x) (x->version & 0x78)
bool GtpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
{
- uint32_t header_len;
uint8_t next_hdr_type;
uint8_t version;
uint8_t ip_ver;
else if (ip_ver == 0x60)
next_prot_id = ipv6::prot_id();
}
+
+ return true;
}
const uint16_t PPPoE_CODE_PADS = 0x65; /* PPPoE Active Discovery Session-confirmation */
const uint16_t PPPoE_CODE_PADT = 0xa7; /* PPPoE Active Discovery Terminate */
-/* PPPoE tag types */
+#if 0
+/* PPPoE tag types - currently not used*/
+
const uint16_t PPPoE_TAG_END_OF_LIST = 0x0000;
const uint16_t PPPoE_TAG_SERVICE_NAME = 0x0101;
const uint16_t PPPoE_TAG_AC_NAME = 0x0102;
const uint16_t PPPoE_TAG_SERVICE_NAME_ERROR = 0x0201;
const uint16_t PPPoE_TAG_AC_SYSTEM_ERROR = 0x0202;
const uint16_t PPPoE_TAG_GENERIC_ERROR = 0x0203;
-
+#endif
} // namespace
-
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
/*
** Copyright (C) 2002-2013 Sourcefire, Inc.
** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+// cd_swipe.cc author Josh Rosenbaum <jorosenba@cisco.com>
namespace{
-const uint32_t ICMP_HEADER_LEN = 4;
-const uint32_t ICMP_NORMAL_LEN = 8;
const uint16_t SWIPE_PROT_ID = 53;
class SwipeCodec : public Codec{
bool SwipeCodec::decode(const uint8_t* raw_packet, const uint32_t raw_len,
Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
{
-
+ // currently unsupported
codec_events::decoder_event(p, DECODE_IP_BAD_PROTO);
-// dc.other++;
- p->data = raw_packet;
- p->dsize = (uint16_t)raw_len;
-
- lyr_len = 0;
- next_prot_id = -1;
return true;
}
PREPROC_PROFILE_START(icmpIdPerfStats);
if( (p->icmph->type == ICMP_ECHO || p->icmph->type == ICMP_ECHOREPLY)
- || (p->icmph->type == ICMP6_ECHO || p->icmph->type == ICMP6_REPLY)
+ || (p->icmph->type == (uint16_t)ICMP6_ECHO || p->icmph->type == (uint16_t)ICMP6_REPLY)
)
{
/* test the rule ID value against the ICMP extension ID field */
PREPROC_PROFILE_START(icmpSeqPerfStats);
if( (p->icmph->type == ICMP_ECHO || p->icmph->type == ICMP_ECHOREPLY)
- || (p->icmph->type == ICMP6_ECHO || p->icmph->type == ICMP6_REPLY)
+ || (p->icmph->type == (uint16_t)ICMP6_ECHO || p->icmph->type == (uint16_t)ICMP6_REPLY)
)
{
/* test the rule ID value against the ICMP extension ID field */
// helper functions
//-------------------------------------------------------------------------
-// note that we now have multiple preproc configs saved by parser
-// (s5-global, s5-tcp, ..., etc.) but just one ppapi. that means
-// we must call the config func multiple times but add only the 1st
-// instance to the policy list.
+#if 0
+// not need until instatiate && codec modules implemented
static inline const CodecApi* GetApi(const char* keyword)
{
for ( auto* p : s_codecs )
return p;
return NULL;
}
+#endif
//-------------------------------------------------------------------------
if (prev_prot_id != FINISHED_DECODE)
{
if(s_proto_map[prev_prot_id])
- pkt_cnt.other_codecs++;
- else
pkt_cnt.discards++;
+ else
+ pkt_cnt.other_codecs++;
}
s_stats[mapped_prot + stat_offset]++;
{
ICMPHdr* h = (ICMPHdr*)(p->layers[layer].start);
- if ( (h->type == ICMP6_ECHO || h->type == ICMP6_REPLY) &&
+ if ( (h->type == (uint16_t)ICMP6_ECHO || h->type == (uint16_t)ICMP6_REPLY) &&
(h->code != 0) )
{
h->code = static_cast<icmp4::IcmpCode>(0);
namespace icmp4
{
- // class to hold any data which should be hidden
- namespace detail
- {
-
-
+namespace detail
+{
+const uint32_t ICMP_HEADER_LEN = 4;
- }
+} // namespace
// do NOT add 'ICMP_' to the begining of these const because they
return (type == (uint32_t) IcmpType::ECHO);
}
-
+inline uint32_t hdr_len()
+{
+ return detail::ICMP_HEADER_LEN;
+}
/*
* CHECKSUM