From: Josh Date: Wed, 30 Apr 2014 21:36:39 +0000 (-0400) Subject: Refactor packet manager X-Git-Tag: 3.0.0-233~1542^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ca6e87013b21082f00f190e6a96bee5df391fb5;p=thirdparty%2Fsnort3.git Refactor packet manager --- diff --git a/src/codecs/basic/cd_esp.cc b/src/codecs/basic/cd_esp.cc index d37482d90..1604a3b7e 100644 --- a/src/codecs/basic/cd_esp.cc +++ b/src/codecs/basic/cd_esp.cc @@ -30,6 +30,7 @@ #include "codecs/decode_module.h" #include "managers/packet_manager.h" #include "events/codec_events.h" +#include "protocols/undefined_protocols.h" namespace { @@ -122,9 +123,7 @@ bool EspCodec::decode(const uint8_t *raw_pkt, const uint32_t len, else { p->packet_flags |= PKT_TRUST; - p->data = esp_payload; - p->dsize = (u_short) len - lyr_len; - next_prot_id = -1; + next_prot_id = FINISHED_DECODE; return true; } diff --git a/src/codecs/basic/cd_icmp6.cc b/src/codecs/basic/cd_icmp6.cc index 33f8d63e5..bd13cd989 100644 --- a/src/codecs/basic/cd_icmp6.cc +++ b/src/codecs/basic/cd_icmp6.cc @@ -67,8 +67,10 @@ void Icmp6Codec::get_protocol_ids(std::vector& v) static void DecodeICMPEmbeddedIP6(const uint8_t *pkt, const uint32_t len, Packet *p); -static unsigned short in_chksum_icmp6(pseudoheader6 *, unsigned short *, int); +#if 0 +static unsigned short in_chksum_icmp6(pseudoheader6 *, unsigned short *, int); +#endif //-------------------------------------------------------------------- @@ -76,7 +78,7 @@ static unsigned short in_chksum_icmp6(pseudoheader6 *, unsigned short *, int); //-------------------------------------------------------------------- bool Icmp6Codec::decode(const uint8_t* raw_pkt, const uint32_t len, - Packet* p, uint16_t &lyr_len, uint16_t &next_prot_id) + Packet* p, uint16_t &lyr_len, uint16_t & /* next_prot_id */) { if(len < icmp6::hdr_min_len()) { @@ -331,7 +333,6 @@ bool Icmp6Codec::decode(const uint8_t* raw_pkt, const uint32_t len, p->proto_bits |= PROTO_BIT__ICMP; p->proto_bits &= ~(PROTO_BIT__UDP | PROTO_BIT__TCP); - next_prot_id = -1; return true; } diff --git a/src/codecs/basic/cd_tcp.cc b/src/codecs/basic/cd_tcp.cc index 26f2e44a9..940bc95df 100644 --- a/src/codecs/basic/cd_tcp.cc +++ b/src/codecs/basic/cd_tcp.cc @@ -59,7 +59,7 @@ public: virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, - Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); + Packet *, uint16_t &lyr_len, uint16_t &); // DELETE @@ -106,7 +106,7 @@ void TcpCodec::get_protocol_ids(std::vector& v) * Returns: void function */ bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, - Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) + Packet *p, uint16_t &lyr_len, uint16_t& /*next_prot_id*/) { if(len < tcp::hdr_len()) { @@ -116,9 +116,6 @@ bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, codec_events::decoder_event(p, DECODE_TCP_DGRAM_LT_TCPHDR); p->tcph = NULL; -// dc.discards++; -// dc.tdisc++; - return false; } diff --git a/src/codecs/plugins/cd_arp.cc b/src/codecs/plugins/cd_arp.cc index 4ac2206d8..3aab33cca 100644 --- a/src/codecs/plugins/cd_arp.cc +++ b/src/codecs/plugins/cd_arp.cc @@ -40,7 +40,7 @@ public: virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, - Packet *, uint16_t &lyr_len, uint16_t &next_prot_id); + Packet *, uint16_t &lyr_len, uint16_t &); // DELETE from here and below @@ -78,10 +78,8 @@ void ArpCodec::get_protocol_ids(std::vector& v) * Returns: void function */ bool ArpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, - Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) + Packet *p, uint16_t &lyr_len, uint16_t& /* next_prot_id */) { -// dc.arp++; - // if (p->greh != NULL) // dc.gre_arp++; @@ -90,15 +88,12 @@ bool ArpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, if(len < sizeof(EtherARP)) { codec_events::decoder_event(p, DECODE_ARP_TRUNCATED); - -// dc.discards++; return false; } p->proto_bits |= PROTO_BIT__ARP; lyr_len = sizeof(*p->ah); - next_prot_id = -1; - + return true; } diff --git a/src/codecs/plugins/cd_mpls.cc b/src/codecs/plugins/cd_mpls.cc index 95ca5dabe..1f12ff1fa 100644 --- a/src/codecs/plugins/cd_mpls.cc +++ b/src/codecs/plugins/cd_mpls.cc @@ -159,7 +159,6 @@ bool MplsCodec::decode(const uint8_t *raw_pkt, const uint32_t len, break; default: - next_prot_id = -1; break; } diff --git a/src/codecs/plugins/cd_pppencap.cc b/src/codecs/plugins/cd_pppencap.cc index 3cf99983d..fd8e0c55f 100644 --- a/src/codecs/plugins/cd_pppencap.cc +++ b/src/codecs/plugins/cd_pppencap.cc @@ -93,7 +93,6 @@ bool PppEncap::decode(const uint8_t *raw_pkt, const uint32_t len, p->data = raw_pkt; p->dsize = (uint16_t)len; - next_prot_id = -1; return true; #endif /* WORDS_MUSTALIGN */ @@ -167,7 +166,6 @@ bool PppEncap::decode(const uint8_t *raw_pkt, const uint32_t len, break; default: - next_prot_id = -1; break; } return true; diff --git a/src/codecs/plugins/cd_swipe.cc b/src/codecs/plugins/cd_swipe.cc index c1c6eb900..ae49df3ff 100644 --- a/src/codecs/plugins/cd_swipe.cc +++ b/src/codecs/plugins/cd_swipe.cc @@ -40,7 +40,7 @@ public: virtual void get_protocol_ids(std::vector& v); virtual bool decode(const uint8_t* raw_packet, const uint32_t raw_len, - Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id); + Packet *p, uint16_t &lyr_len, uint16_t &); }; } // namespace @@ -53,7 +53,7 @@ void SwipeCodec::get_protocol_ids(std::vector &proto_ids) bool SwipeCodec::decode(const uint8_t* raw_packet, const uint32_t raw_len, - Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id) + Packet *p, uint16_t &lyr_len, uint16_t& /*next_prot_id*/) { // currently unsupported codec_events::decoder_event(p, DECODE_IP_BAD_PROTO); diff --git a/src/ips_options/ips_icmp_id.cc b/src/ips_options/ips_icmp_id.cc index 63ff5fd68..2c59aa351 100644 --- a/src/ips_options/ips_icmp_id.cc +++ b/src/ips_options/ips_icmp_id.cc @@ -146,7 +146,7 @@ int IcmpIdOption::eval(Packet *p) PREPROC_PROFILE_START(icmpIdPerfStats); if( (p->icmph->type == ICMP_ECHO || p->icmph->type == ICMP_ECHOREPLY) - || (p->icmph->type == (uint16_t)ICMP6_ECHO || p->icmph->type == (uint16_t)ICMP6_REPLY) + || ((uint16_t)p->icmph->type == ICMP6_ECHO || (uint16_t)p->icmph->type == ICMP6_REPLY) ) { /* test the rule ID value against the ICMP extension ID field */ diff --git a/src/ips_options/ips_icmp_seq.cc b/src/ips_options/ips_icmp_seq.cc index 445f7ed27..88972054b 100644 --- a/src/ips_options/ips_icmp_seq.cc +++ b/src/ips_options/ips_icmp_seq.cc @@ -145,7 +145,7 @@ int IcmpSeqOption::eval(Packet *p) PREPROC_PROFILE_START(icmpSeqPerfStats); if( (p->icmph->type == ICMP_ECHO || p->icmph->type == ICMP_ECHOREPLY) - || (p->icmph->type == (uint16_t)ICMP6_ECHO || p->icmph->type == (uint16_t)ICMP6_REPLY) + || ((uint16_t)p->icmph->type == ICMP6_ECHO || (uint16_t)p->icmph->type == ICMP6_REPLY) ) { /* test the rule ID value against the ICMP extension ID field */ diff --git a/src/network_inspectors/normalize/norm.cc b/src/network_inspectors/normalize/norm.cc index 80cc26a73..afad6e601 100644 --- a/src/network_inspectors/normalize/norm.cc +++ b/src/network_inspectors/normalize/norm.cc @@ -283,7 +283,7 @@ static int Norm_ICMP6 ( { ICMPHdr* h = (ICMPHdr*)(p->layers[layer].start); - if ( (h->type == (uint16_t)ICMP6_ECHO || h->type == (uint16_t)ICMP6_REPLY) && + if ( ((uint16_t)h->type == ICMP6_ECHO || (uint16_t)h->type == ICMP6_REPLY) && (h->code != 0) ) { h->code = static_cast(0); diff --git a/src/protocols/ipv6.h b/src/protocols/ipv6.h index 8b7b6d6da..fe00136a8 100644 --- a/src/protocols/ipv6.h +++ b/src/protocols/ipv6.h @@ -65,6 +65,9 @@ struct in6_addr #define IPRAW_HDR_VER(p_rawiph) \ (ntohl(p_rawiph->ip6_vtf) >> 28) +#if 0 +// defined in dnet.h and currently unused. + #ifndef IP_PROTO_HOPOPTS # define IP_PROTO_HOPOPTS 0 #endif @@ -77,6 +80,7 @@ struct in6_addr #define IP_PROTO_ICMPV6 58 #define IP_PROTO_IPV6 41 #define IP_PROTO_IPIP 4 +#endif #define IP6F_OFFSET_MASK 0xfff8 /* mask out offset from _offlg */ #define IP6F_MF_MASK 0x0001 /* more-fragments flag */