};
-
uint16_t const IP_ID_COUNT = 8192;
THREAD_LOCAL rand_t* s_rand = 0;
-#if 0
-THREAD_LOCAL uint16_t s_id_index = 0;
-#endif
// this should be changed to type array
THREAD_LOCAL uint16_t s_id_pool[IP_ID_COUNT] = {};
} // namespace
-static inline void CheckPGMVuln(Packet *);
-static inline void CheckIGMPVuln(Packet *);
-static inline int pgm_nak_detect (uint8_t *, uint16_t );
static inline void IP4AddrTests (Packet* );
static inline void IPMiscTests(Packet *);
-static inline unsigned short in_chksum_ip( unsigned short *, int);
-
static void DecodeIPOptions(const uint8_t *start, uint32_t o_len, Packet *p);
/* set the real IP length for logging */
p->actual_ip_len = (uint16_t) ip_len;
+ p->packet_flags |= PKT_NEW_IP_LEN;
/* set the remaining packet length */
ip_len -= hlen;
p->actual_ip_len = ntohs(p->ip6h->len);
p->ip_data = raw_pkt + ipv6::hdr_len();
p->ip_dsize = ntohs(p->ip6h->len);
+ p->packet_flags |= PKT_NEW_IP_LEN;
lyr_len = sizeof(*hdr);
{
if ( pgm_nak_detect((uint8_t *)p->data, p->dsize) == PGM_NAK_VULN )
codec_events::decoder_event(p, DECODE_PGM_NAK_OVERFLOW);
-
+ return true;
}
void PgmCodec::get_protocol_ids(std::vector<uint16_t>& v)
// loop until the protocol id is no longer valid
while(s_protocols[mapped_prot]->decode(pkt, len, p, lyr_len, prot_id))
{
- PacketClass::PushLayer(p, s_protocols[mapped_prot], pkt, lyr_len);
+ PacketClass::push_layer(p, s_protocols[mapped_prot], pkt, lyr_len);
+
+ // since the IP length and the packet length may not be equal.
+ if (p->packet_flags & PKT_NEW_IP_LEN)
+ {
+ len = p->actual_ip_len;
+ p->packet_flags &= ~PKT_NEW_IP_LEN;
+ }
+
s_stats[mapped_prot + stat_offset]++;
mapped_prot = s_proto_map[prot_id];
prev_prot_id = prot_id; // used for 'other_codecs' statistics
#include "codecs/sf_protocols.h"
#include "log/messages.h"
-void PacketClass::PushLayer(Packet *p, Codec* const cd, const uint8_t *hdr_start, uint32_t len)
+void PacketClass::push_layer(Packet *p, Codec* const cd, const uint8_t *hdr_start, uint32_t len)
{
if ( p->next_layer < LAYER_MAX )
{
}
}
+// credit belong to dnet.h. copied directrly from their source code
+// src/ip-util.cc
+uint16_t ip_cksum_add(const void *buf, size_t len, int cksum = 0)
+{
+ uint16_t *sp = (uint16_t *)buf;
+ int n, sn;
+
+ sn = len / 2;
+ n = (sn + 15) / 16;
+
+ /* XXX - unroll loop using Duff's device. */
+ switch (sn % 16) {
+ case 0: do {
+ cksum += *sp++;
+ case 15:
+ cksum += *sp++;
+ case 14:
+ cksum += *sp++;
+ case 13:
+ cksum += *sp++;
+ case 12:
+ cksum += *sp++;
+ case 11:
+ cksum += *sp++;
+ case 10:
+ cksum += *sp++;
+ case 9:
+ cksum += *sp++;
+ case 8:
+ cksum += *sp++;
+ case 7:
+ cksum += *sp++;
+ case 6:
+ cksum += *sp++;
+ case 5:
+ cksum += *sp++;
+ case 4:
+ cksum += *sp++;
+ case 3:
+ cksum += *sp++;
+ case 2:
+ cksum += *sp++;
+ case 1:
+ cksum += *sp++;
+ } while (--n > 0);
+ }
+ if (len & 1)
+ cksum += (*(unsigned char*)sp << 8);
+
+ cksum = (cksum >> 16) + (cksum & 0x0000ffff);
+ cksum += (cksum >> 16);
+
+ return (uint16_t)(~cksum);
+}
+
#define PKT_IPREP_SOURCE_TRIGGERED 0x08000000
#define PKT_IPREP_DATA_SET 0x10000000
#define PKT_FILE_EVENT_SET 0x20000000
+#define PKT_NEW_IP_LEN 0X40000000 /* For Codecs to tell PacketManger a new length should be set */
// 0x40000000 are available
#define PKT_PDU_FULL (PKT_PDU_HEAD | PKT_PDU_TAIL)
class PacketClass{
public:
- static void PushLayer(Packet *p, Codec* const cd, const uint8_t *hdr_start, uint32_t len);
+ static void push_layer(Packet *p, Codec* const cd, const uint8_t *hdr_start, uint32_t len);
private: