From: Josh Date: Thu, 23 Oct 2014 23:56:45 +0000 (-0500) Subject: additional more ntohs and htons to protocol header files X-Git-Tag: 3.0.0-233~1268^2~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=671242a0a2caf75bcdde90429baafeee1e447baf;p=thirdparty%2Fsnort3.git additional more ntohs and htons to protocol header files --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b12495c2..dc44b4852 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.9) project (snort CXX C) set (SNORT_VERSION_MAJOR 2) diff --git a/src/codecs/ip/cd_ipv4.cc b/src/codecs/ip/cd_ipv4.cc index d78d5e333..4a86ee68a 100644 --- a/src/codecs/ip/cd_ipv4.cc +++ b/src/codecs/ip/cd_ipv4.cc @@ -182,7 +182,7 @@ bool Ipv4Codec::decode(const RawData& raw, CodecData& codec, DecodeData& snort) * with datalink DLT_RAW it's impossible to differ ARP datagrams from IP. * So we are just ignoring non IP datagrams */ - if (iph->get_ver() != 4) + if (iph->ver() != 4) { if ((codec.codec_flags & CODEC_UNSURE_ENCAP) == 0) codec_events::decoder_event(codec, DECODE_NOT_IPV4_DGRAM); @@ -190,8 +190,8 @@ bool Ipv4Codec::decode(const RawData& raw, CodecData& codec, DecodeData& snort) } /* get the IP datagram length */ - ip_len = ntohs(iph->ip_len); - hlen = iph->get_hlen() << 2; + ip_len = iph->len(); + hlen = iph->hlen(); /* header length sanity check */ if(hlen < ip::IP4_HEADER_LEN) @@ -592,7 +592,7 @@ void Ipv4Codec::log(TextLog* const text_log, const uint8_t* raw_pkt, TextLog_Putc(text_log, '\t'); - const uint16_t hlen = ip4h->get_hlen() << 2; + const uint16_t hlen = ip4h->hlen(); const uint16_t len = ip4h->len(); const uint16_t frag_off = ip4h->off(); @@ -702,7 +702,7 @@ bool Ipv4Codec::update(Packet* p, Layer* lyr, uint32_t* len) { IP4Hdr* h = (IP4Hdr*)(lyr->start); int i = lyr - p->layers; - uint16_t hlen = h->get_hlen() << 2; + uint16_t hlen = h->hlen(); *len += hlen; @@ -710,7 +710,7 @@ bool Ipv4Codec::update(Packet* p, Layer* lyr, uint32_t* len) *len += p->dsize; - h->set_ip_len(htons((uint16_t)*len)); + h->set_ip_len((uint16_t)*len); if ( !PacketWasCooked(p) || (p->packet_flags & PKT_REBUILT_FRAG) ) @@ -738,7 +738,7 @@ void Ipv4Codec::format(EncodeFlags f, const Packet* p, Packet* c, Layer* lyr) if ( f & ENC_FLAG_DEF ) { lyr->length = ip::IP4_HEADER_LEN; - ch->set_ip_len(htons(ip::IP4_HEADER_LEN)); + ch->set_ip_len(ip::IP4_HEADER_LEN); ch->set_hlen(ip::IP4_HEADER_LEN >> 2); #if 0 @@ -747,7 +747,7 @@ void Ipv4Codec::format(EncodeFlags f, const Packet* p, Packet* c, Layer* lyr) if ( i + 1 == p->num_layers ) { lyr->length = ip::IP4_HEADER_LEN; - ch->set_ip_len(htons(ip::IP4_HEADER_LEN)); + ch->set_ip_len(ip::IP4_HEADER_LEN); ch->set_hlen(ip::IP4_HEADER_LEN >> 2); } #endif diff --git a/src/codecs/ip/cd_ipv6.cc b/src/codecs/ip/cd_ipv6.cc index 0cc96b85f..3dc9fcc1f 100644 --- a/src/codecs/ip/cd_ipv6.cc +++ b/src/codecs/ip/cd_ipv6.cc @@ -144,7 +144,7 @@ bool Ipv6Codec::decode(const RawData& raw, CodecData& codec, DecodeData& snort) /* Verify version in IP6 Header agrees */ - if(ip6h->get_ver() != 6) + if(ip6h->ver() != 6) { if ((codec.codec_flags & CODEC_UNSURE_ENCAP) == 0) codec_events::decoder_event(codec, DECODE_IPV6_IS_NOT); @@ -199,11 +199,11 @@ bool Ipv6Codec::decode(const RawData& raw, CodecData& codec, DecodeData& snort) CheckIPV6Multicast(ip6h, codec); snort.set_pkt_type(PktType::IP); - codec.next_prot_id = ip6h->get_next(); + codec.next_prot_id = ip6h->next(); codec.lyr_len = ip::IP6_HEADER_LEN; codec.curr_ip6_extension = 0; codec.ip6_extension_count = 0; - codec.ip6_csum_proto = ip6h->get_next(); + codec.ip6_csum_proto = ip6h->next(); codec.codec_flags &= ~CODEC_ROUTING_SEEN; // FIXIT-M J tunnel-byppas is NOT checked!! @@ -583,7 +583,7 @@ void Ipv6Codec::log(TextLog* const text_log, const uint8_t* raw_pkt, TextLog_Print(text_log, "Next:0x%02X TTL:%u TOS:0x%X DgmLen:%u", - ip6h->get_next(), ip6h->get_hop_lim(), ip6h->tos(), + ip6h->next(), ip6h->hop_lim(), ip6h->tos(), ip6h->len()); } diff --git a/src/codecs/ip/cd_tcp.cc b/src/codecs/ip/cd_tcp.cc index e238209cc..51747e9a3 100644 --- a/src/codecs/ip/cd_tcp.cc +++ b/src/codecs/ip/cd_tcp.cc @@ -294,7 +294,7 @@ bool TcpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort) dsize = 0; if ( (tcph->th_flags & TH_URG) && - ((dsize == 0) || ntohs(tcph->th_urp) > dsize) ) + ((dsize == 0) || tcph->urp() > dsize) ) codec_events::decoder_event(codec, DECODE_TCP_BAD_URP); // Now that we are returning true, set the tcp header @@ -583,7 +583,7 @@ void TcpCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, ntohs(tcph->th_win), tcph->off() << 2); if((tcph->th_flags & TH_URG) != 0) - TextLog_Print(text_log, "UrgPtr: 0x%X", (uint16_t) ntohs(tcph->th_urp)); + TextLog_Print(text_log, "UrgPtr: 0x%X", tcph->urp()); /* dump the TCP options */ diff --git a/src/codecs/ip/cd_udp.cc b/src/codecs/ip/cd_udp.cc index c3a93a553..eb4c20bb1 100644 --- a/src/codecs/ip/cd_udp.cc +++ b/src/codecs/ip/cd_udp.cc @@ -193,7 +193,7 @@ bool UdpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort) } else if(snort.ip_api.is_ip6()) { - const uint16_t ip_len = snort.ip_api.len(); + const uint16_t ip_len = snort.ip_api.get_ip6h()->len(); /* subtract the distance from udp header to 1st ip6 extension */ /* This gives the length of the UDP "payload", when fragmented */ uhlen = ip_len - ((uint8_t *)udph - snort.ip_api.ip_data()); @@ -201,9 +201,8 @@ bool UdpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snort) } else { - const uint16_t ip_len = snort.ip_api.len(); - /* Don't forget, IP_HLEN is a word - multiply x 4 */ - uhlen = ip_len - (snort.ip_api.hlen() * 4 ); + const ip::IP4Hdr* const ip4h = snort.ip_api.get_ip4h(); + uhlen = ip4h->len() - ip4h->hlen(); fragmented_udp_flag = true; } diff --git a/src/codecs/misc/cd_icmp4_ip.cc b/src/codecs/misc/cd_icmp4_ip.cc index 509e84144..e09a6d015 100644 --- a/src/codecs/misc/cd_icmp4_ip.cc +++ b/src/codecs/misc/cd_icmp4_ip.cc @@ -83,13 +83,13 @@ bool Icmp4IpCodec::decode(const RawData& raw, CodecData& codec, DecodeData& snor * with datalink DLT_RAW it's impossible to differ ARP datagrams from IP. * So we are just ignoring non IP datagrams */ - if((ip4h->get_ver() != 4) && !snort.ip_api.is_ip6()) + if((ip4h->ver() != 4) && !snort.ip_api.is_ip6()) { codec_events::decoder_event(codec, DECODE_ICMP_ORIG_IP_VER_MISMATCH); return false; } - const uint32_t hlen = ip4h->get_hlen() << 2; /* set the IP header length */ + const uint32_t hlen = ip4h->hlen(); /* set the IP header length */ if(raw.len < hlen) { @@ -191,7 +191,7 @@ void Icmp4IpCodec::log(TextLog* const text_log, const uint8_t* raw_pkt, TextLog_NewLine(text_log); TextLog_Puts(text_log, "\t\t"); - const uint16_t hlen = ip4h->get_hlen() << 2; + const uint16_t hlen = ip4h->hlen(); const uint16_t len = ip4h->len(); const uint16_t frag_off = ip4h->off(); diff --git a/src/codecs/misc/cd_icmp6_ip.cc b/src/codecs/misc/cd_icmp6_ip.cc index 7c5fe78b8..e5f4c06f3 100644 --- a/src/codecs/misc/cd_icmp6_ip.cc +++ b/src/codecs/misc/cd_icmp6_ip.cc @@ -83,7 +83,7 @@ bool Icmp6IpCodec::decode(const RawData& raw, CodecData& codec, DecodeData&) * with datalink DLT_RAW it's impossible to differ ARP datagrams from IP. * So we are just ignoring non IP datagrams */ - if(ip6h->get_ver() != 6) + if(ip6h->ver() != 6) { codec_events::decoder_event(codec, DECODE_ICMP_ORIG_IP_VER_MISMATCH); return false; @@ -109,7 +109,7 @@ bool Icmp6IpCodec::decode(const RawData& raw, CodecData& codec, DecodeData&) // ICMP codec. Therefore, doing a minor decode here. // FIXIT-J L Will fail to decode Ipv6 options - switch(ip6h->get_next()) + switch(ip6h->next()) { case IPPROTO_TCP: /* decode the interesting part of the header */ codec.proto_bits |= PROTO_BIT__TCP_EMBED_ICMP; diff --git a/src/log/log_text.cc b/src/log/log_text.cc index 4d0ec0580..af8dd322d 100644 --- a/src/log/log_text.cc +++ b/src/log/log_text.cc @@ -626,8 +626,8 @@ void LogIPHeader(TextLog* log, Packet * p) (is_ip6 ? layer::get_inner_ip6_frag() : nullptr); TextLog_Print(log, "%s TTL:%u TOS:0x%X ID:%u IpLen:%u DgmLen:%u", - protocol_names[ip6h->get_next()], - ip6h->get_hop_lim(), + protocol_names[ip6h->next()], + ip6h->hop_lim(), ip6h->tos(), (ip6_frag ? ip6_frag->id() : 0), ip::IP6_HEADER_LEN, @@ -657,7 +657,7 @@ void LogIPHeader(TextLog* log, Packet * p) ip4h->ttl(), ip4h->tos(), ip4h->id(), - ip4h->get_hlen() << 2, + ip4h->hlen(), ip4h->len()); frag_off = ip4h->off(); @@ -886,7 +886,7 @@ void LogTCPHeader(TextLog* log, Packet * p) if((tcph->th_flags & TH_URG) != 0) { - TextLog_Print(log, " UrgPtr: 0x%X\n", (uint16_t) ntohs(tcph->th_urp)); + TextLog_Print(log, " UrgPtr: 0x%X\n", tcph->urp()); } else { diff --git a/src/loggers/alert_csv.cc b/src/loggers/alert_csv.cc index 8593f1644..63d75dd76 100644 --- a/src/loggers/alert_csv.cc +++ b/src/loggers/alert_csv.cc @@ -355,7 +355,7 @@ void CsvLogger::alert(Packet *p, const char *msg, Event *event) else if (!strcasecmp("ip_len", type)) { if (p->has_ip()) - TextLog_Print(csv_log, "%d", p->ptrs.ip_api.len() << 2); + TextLog_Print(csv_log, "%d", p->ptrs.ip_api.pay_len()); } else if (!strcasecmp("dgm_len", type)) { diff --git a/src/managers/codec_manager.h b/src/managers/codec_manager.h index 0c0fedaee..746bcf639 100644 --- a/src/managers/codec_manager.h +++ b/src/managers/codec_manager.h @@ -17,7 +17,7 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// packet_manager.h author Josh Rosenbaum +// codec_manager.h author Josh Rosenbaum #ifndef MANAGERS_CODEC_MANAGER_H #define MANAGERS_CODEC_MANAGER_H diff --git a/src/network_inspectors/normalize/norm.cc b/src/network_inspectors/normalize/norm.cc index 82dabb73e..00bd01785 100644 --- a/src/network_inspectors/normalize/norm.cc +++ b/src/network_inspectors/normalize/norm.cc @@ -485,9 +485,9 @@ static int Norm_TCP ( changes++; } else if ( Norm_IsEnabled(c, NORM_TCP_URP) && - (ntohs(h->th_urp) > p->dsize) ) + (h->urp() > p->dsize) ) { - h->th_urp = ntohs(p->dsize); + h->set_urp(p->dsize); normStats[PC_TCP_URP]++; sfBase.iPegs[PERF_COUNT_TCP_URP]++; changes++; diff --git a/src/network_inspectors/port_scan/port_scan.cc b/src/network_inspectors/port_scan/port_scan.cc index 46d18243b..2dbd471e3 100644 --- a/src/network_inspectors/port_scan/port_scan.cc +++ b/src/network_inspectors/port_scan/port_scan.cc @@ -422,7 +422,7 @@ static int MakePortscanPkt(PS_PKT *ps_pkt, PS_PROTO *proto, int proto_type, // FIXIT-L: IP4 is gauranteed to have been set in update(). Is IP6() // also gauranteed? if(g_tmp_pkt->ptrs.ip_api.is_ip6()) - ((ip::IP6Hdr*)g_tmp_pkt->ptrs.ip_api.get_ip6h())->set_len(htons((uint16_t)ip_size)); + ((ip::IP6Hdr*)g_tmp_pkt->ptrs.ip_api.get_ip6h())->set_len((uint16_t)ip_size); return 0; } diff --git a/src/protocols/ip.cc b/src/protocols/ip.cc index 26434f575..dcc58dab3 100644 --- a/src/protocols/ip.cc +++ b/src/protocols/ip.cc @@ -71,7 +71,7 @@ void IpApi::set(const ip::IP6Hdr* h6) bool IpApi::set(const uint8_t* raw_ip_data) { const IP4Hdr* h4 = reinterpret_cast(raw_ip_data); - if (h4->get_ver() == 4) + if (h4->ver() == 4) { set(h4); return true; @@ -79,7 +79,7 @@ bool IpApi::set(const uint8_t* raw_ip_data) const IP6Hdr* h6 = reinterpret_cast(raw_ip_data); - if (h6->get_ver() == 6) + if (h6->ver() == 6) { set(h6); return true; @@ -116,10 +116,10 @@ uint16_t IpApi::off() const const uint8_t* IpApi::ip_data() const { if (ip4h) - return reinterpret_cast(ip4h) + (ip4h->get_hlen() << 2); + return reinterpret_cast(ip4h) + (ip4h->hlen()); if (ip6h) - return reinterpret_cast(ip6h) + IP6_HEADER_LEN; + return reinterpret_cast(ip6h) + ip6h->hlen(); return nullptr; } @@ -149,7 +149,7 @@ uint16_t IpApi::dgram_len() const uint16_t IpApi::pay_len() const { if (ip4h) - return ip4h->len() - IP4_HEADER_LEN; + return ip4h->len() - ip4h->hlen(); if (ip6h) return ip6h->len(); diff --git a/src/protocols/ip.h b/src/protocols/ip.h index 1d098b630..61ca7846a 100644 --- a/src/protocols/ip.h +++ b/src/protocols/ip.h @@ -107,28 +107,28 @@ public: { return ip4h ? ip4h->tos() : ip6h ? ip6h->tos() : 0; } inline uint8_t ttl() const - { return ip4h ? ip4h->ttl() : ip6h ? ip6h->get_hop_lim() : 0; } + { return ip4h ? ip4h->ttl() : ip6h ? ip6h->hop_lim() : 0; } /* This is different than the Packet's ip_proto_next field - this * variable hold the first non-ip and non-ipv6 extension protocols, * while proto() returns the next or proto() field of the raw IP * header */ inline uint8_t proto() const - { return ip4h ? ip4h->proto() : ip6h ? ip6h->get_next() : 0xFF; } + { return ip4h ? ip4h->proto() : ip6h ? ip6h->next() : 0xFF; } // NOTE: ipv4 len contains header, ipv6 header does not. If you // want a standard, use dgram_len() or pay_len() instead. - inline uint16_t len() const - { return ip4h ? ip4h->len() : ip6h ? ip6h->len() : 0; } +// inline uint16_t len() const +// { return ip4h ? ip4h->len() : ip6h ? ip6h->len() : 0; } inline uint16_t raw_len() const { return ip4h ? ip4h->raw_len() : ip6h ? ip6h->raw_len() : 0; } inline uint8_t hlen() const - { return ip4h ? ip4h->get_hlen() : ip6h ? ip6h->get_hlen() : 0; } + { return ip4h ? ip4h->hlen() : ip6h ? ip6h->hlen() : 0; } inline uint8_t ver() const - { return ip4h ? ip4h->get_ver() : ip6h ? ip6h->get_ver() : 0; } + { return ip4h ? ip4h->ver() : ip6h ? ip6h->ver() : 0; } // only relevent to IP4. diff --git a/src/protocols/ipv4.h b/src/protocols/ipv4.h index 9e7bdf2bd..f74938daa 100644 --- a/src/protocols/ipv4.h +++ b/src/protocols/ipv4.h @@ -74,12 +74,11 @@ struct IP4Hdr uint32_t ip_dst; /* dest IP */ /* getters */ - inline uint8_t get_hlen() const - { return ip_verhl & 0x0f; } -// { return (ip_verhl & 0x0f) << 2; } //FIXIT-M J return the actual length + inline uint8_t hlen() const + { return (ip_verhl & 0x0f) << 2; } - inline uint8_t get_ver() const - { return ((ip_verhl & 0xf0) >> 4); } + inline uint8_t ver() const + { return (ip_verhl >> 4); } inline uint8_t tos() const { return ip_tos; }; @@ -100,7 +99,10 @@ struct IP4Hdr { return ntohs(ip_id); } inline uint8_t get_opt_len() const - { return (get_hlen() << 2) - IP4_HEADER_LEN; } + { return hlen() - IP4_HEADER_LEN; } + + inline uint16_t csum() const + { return ntohs(ip_csum); } /* booleans */ @@ -111,20 +113,10 @@ struct IP4Hdr { return ip_dst == IP4_BROADCAST; } inline bool has_options() const - { return get_hlen() > 5; } - - /* setters */ - inline void set_hlen(uint8_t value) - { ip_verhl = (ip_verhl & 0xf0) | (value & 0x0f); } + { return hlen() > 20; } - inline void set_ip_len(uint16_t value) - { ip_len = value; } - - inline void set_proto(uint8_t prot) - { ip_proto = prot; } /* Access raw data */ - inline uint16_t raw_len() const { return ip_len; } @@ -134,7 +126,7 @@ struct IP4Hdr inline uint16_t raw_off() const { return ip_off; } - inline uint16_t get_csum() const + inline uint16_t raw_csum() const { return ip_csum; } inline uint32_t get_src() const @@ -142,6 +134,19 @@ struct IP4Hdr inline uint32_t get_dst() const { return ip_dst; } + + + + /* setters */ + inline void set_hlen(uint8_t value) + { ip_verhl = (ip_verhl & 0xf0) | (value & 0x0f); } + + inline void set_proto(uint8_t prot) + { ip_proto = prot; } + + inline void set_ip_len(uint16_t new_len) + { ip_len = htons(new_len); } + } ; diff --git a/src/protocols/ipv6.h b/src/protocols/ipv6.h index bdc224e34..869f755bd 100644 --- a/src/protocols/ipv6.h +++ b/src/protocols/ipv6.h @@ -106,7 +106,7 @@ struct IP6Frag inline uint32_t id() const { return ntohl(ip6f_ident); } - inline uint8_t get_res() const + inline uint8_t res() const { return ip6f_reserved; } @@ -145,24 +145,30 @@ struct IP6Hdr inline uint16_t len() const { return ntohs(ip6_payload_len); } + /* Same function as ipv4 */ + inline uint8_t proto() const + { return ip6_next; } - inline uint8_t get_ver() const - { return (uint8_t)(ntohl(ip6_vtf) >> 28); } - - inline uint8_t get_next() const + inline uint8_t next() const { return ip6_next; } - inline uint8_t get_hop_lim() const + inline uint8_t hop_lim() const { return ip6_hoplim; } + inline uint8_t ver() const + { return (uint8_t)(ntohl(ip6_vtf) >> 28); } + inline uint16_t tos() const { return (uint16_t)((ntohl(ip6_vtf) & 0x0FF00000) >> 20); } + inline uint32_t flow() const + { return (uint16_t)((ntohl(ip6_vtf) & 0x000FFFFF) >> 20); } + // becaise Snort expects this in terms of 32 bit words. - inline uint8_t get_hlen() const - { return IP6_HEADER_LEN / 4; } + inline uint8_t hlen() const + { return IP6_HEADER_LEN; } inline const snort_in6_addr* get_src() const { return &ip6_src; } @@ -199,12 +205,16 @@ struct IP6Hdr /* setters */ inline void set_len(uint16_t new_len) - { ip6_payload_len = new_len; } + { ip6_payload_len = htons(new_len); } inline void set_proto(uint8_t prot) { ip6_next = prot; } + inline void set_raw_len(uint16_t new_len) + { ip6_payload_len = new_len; } + + /* Access raw data */ inline uint16_t raw_len() const diff --git a/src/protocols/layer.cc b/src/protocols/layer.cc index bd21119ae..e8dcab76e 100644 --- a/src/protocols/layer.cc +++ b/src/protocols/layer.cc @@ -209,7 +209,7 @@ uint8_t get_outer_ip_next_pro(const Packet* const p) return reinterpret_cast(layers[i].start)->proto(); case ETHERTYPE_IPV6: case IPPROTO_ID_IPV6: - return reinterpret_cast(layers[i].start)->get_next(); + return reinterpret_cast(layers[i].start)->next(); default: break; } diff --git a/src/protocols/layer.h b/src/protocols/layer.h index 7f37e0f8c..a0df7c550 100644 --- a/src/protocols/layer.h +++ b/src/protocols/layer.h @@ -40,7 +40,7 @@ struct Layer { * * Generally calculated by * (layers_entire_length) - length; - * (ip::IP4Hdr*) ip4h->get_hlen() * 4 - length; + * (ip::IP4Hdr*) ip4h->hlen()- length; */ }; diff --git a/src/protocols/packet_manager.cc b/src/protocols/packet_manager.cc index 1472c7b47..48b0c03ba 100644 --- a/src/protocols/packet_manager.cc +++ b/src/protocols/packet_manager.cc @@ -485,7 +485,7 @@ const uint8_t* PacketManager::encode_reject( UnreachResponse type, const ip::IP4Hdr* const ip4h = reinterpret_cast(p->layers[inner_ip_index].start); - const uint8_t ip_len = ip4h->get_hlen() << 2; + const uint8_t ip_len = ip4h->hlen(); if (!buf.allocate(ip_len)) return nullptr; diff --git a/src/protocols/tcp.h b/src/protocols/tcp.h index 14ee82b42..c672a267c 100644 --- a/src/protocols/tcp.h +++ b/src/protocols/tcp.h @@ -98,6 +98,15 @@ struct TCPHdr inline uint16_t dst_port() const { return ntohs(th_dport); } + inline uint16_t win() const + { return ntohs(th_win); } + + inline uint16_t cksum() const + { return ntohs(th_sum); } + + inline uint16_t urp() const + { return ntohs(th_urp); } + inline uint32_t seq() const { return ntohl(th_seq); } @@ -122,6 +131,7 @@ struct TCPHdr inline bool is_rst() const { return (th_flags & TH_RST); } + /* raw data access */ inline uint8_t raw_src_port() const { return th_sport; } @@ -135,9 +145,25 @@ struct TCPHdr inline uint8_t raw_hdr_len() const { return th_offx2 >> 4; } + inline uint16_t raw_win() const + { return th_win; } + + inline uint16_t raw_cksum() const + { return th_sum; } + + inline uint16_t raw_urp() const + { return th_urp; } + + // setters inline void set_offset(uint8_t val) { th_offx2 = (uint8_t)((th_offx2 & 0x0f) | (val << 4)); } + + inline void set_urp(uint16_t new_urp) + { th_urp = htons(new_urp); } + + inline void set_raw_urp(uint16_t new_urp) + { th_urp = new_urp; } }; } // namespace tcp diff --git a/src/stream/ip/ip_defrag.cc b/src/stream/ip/ip_defrag.cc index ca7b98137..7c8a00c5d 100644 --- a/src/stream/ip/ip_defrag.cc +++ b/src/stream/ip/ip_defrag.cc @@ -1918,7 +1918,7 @@ left_overlap_last: { DEBUG_WRAP(DebugMessage(DEBUG_FRAG, "Overly large fragment %d 0x%x 0x%x %d\n", - fragLength, p->ptrs.ip_api.len(), p->ptrs.ip_api.off(), + fragLength, p->ptrs.ip_api.dgram_len(), p->ptrs.ip_api.off(), net_frag_offset << 3);); MODULE_PROFILE_END(fragInsertPerfStats); return FRAG_INSERT_FAILED; @@ -2302,7 +2302,7 @@ int Defrag::new_tracker(Packet *p, FragTracker* ft) { DEBUG_WRAP(DebugMessage(DEBUG_FRAG, "Overly large fragment length:%d(0x%x) off:0x%x(%d)\n", - fragLength, p->ptrs.ip_api.len(), p->ptrs.ip_api.off() << 3, + fragLength, p->ptrs.ip_api.dgram_len(), p->ptrs.ip_api.off() << 3, p->ptrs.ip_api.off() << 3);); /* Ah, crap. Return that tracker. */ diff --git a/src/stream/tcp/tcp_session.cc b/src/stream/tcp/tcp_session.cc index 0305434b1..c8bd7bd06 100644 --- a/src/stream/tcp/tcp_session.cc +++ b/src/stream/tcp/tcp_session.cc @@ -3106,7 +3106,7 @@ static int AddStreamNode( /* handle the urg ptr */ if(p->ptrs.tcph->th_flags & TH_URG) { - if(ntohs(p->ptrs.tcph->th_urp) < p->dsize) + if(p->ptrs.tcph->urp() < p->dsize) { switch(st->os_policy) { @@ -3114,7 +3114,7 @@ static int AddStreamNode( case STREAM_POLICY_OLD_LINUX: /* Linux, Old linux discard data from urgent pointer */ /* If urg pointer is 0, it's treated as a 1 */ - ss->urg_offset = ntohs(p->ptrs.tcph->th_urp); + ss->urg_offset = p->ptrs.tcph->urp(); if (ss->urg_offset == 0) { ss->urg_offset = 1; @@ -3133,7 +3133,7 @@ static int AddStreamNode( case STREAM_POLICY_IRIX: /* Others discard data from urgent pointer */ /* If urg pointer is beyond this packet, it's treated as a 0 */ - ss->urg_offset = ntohs(p->ptrs.tcph->th_urp); + ss->urg_offset = p->ptrs.tcph->urp(); if (ss->urg_offset > p->dsize) { ss->urg_offset = 0; diff --git a/tools/snort2lua/config_states/config_binding.cc b/tools/snort2lua/config_states/config_binding.cc index 223675dc0..b6e4eb67c 100644 --- a/tools/snort2lua/config_states/config_binding.cc +++ b/tools/snort2lua/config_states/config_binding.cc @@ -20,6 +20,7 @@ #include #include +#include #include "conversion_state.h" #include "utils/converter.h" diff --git a/tools/snort2lua/preprocessor_states/pps_normalizers.cc b/tools/snort2lua/preprocessor_states/pps_normalizers.cc index 989c287a1..15b817d69 100644 --- a/tools/snort2lua/preprocessor_states/pps_normalizers.cc +++ b/tools/snort2lua/preprocessor_states/pps_normalizers.cc @@ -33,7 +33,7 @@ namespace preprocessors template static ConversionState* norm_sans_options_ctor(Converter& c) { - c.get_table_api().open_table("normalize"); + c.get_table_api().open_table("normalizer"); c.get_table_api().add_diff_option_comment("preprocessor normalize_" + *norm_option, *norm_option + " = "); c.get_table_api().add_option(*norm_option, true); c.get_table_api().close_table(); @@ -103,7 +103,7 @@ bool Ip4Normalizer::convert(std::istringstream& data_stream) std::string keyword; bool retval = true; - table_api.open_table("normalize"); + table_api.open_table("normalizer"); table_api.open_table("ip4"); table_api.add_option("base", true); @@ -173,7 +173,7 @@ bool TcpNormalizer::convert(std::istringstream& data_stream) std::string value; bool retval = true; - table_api.open_table("normalize"); + table_api.open_table("normalizer"); table_api.open_table("tcp"); table_api.add_option("base", true);