-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.9)
project (snort CXX C)
set (SNORT_VERSION_MAJOR 2)
* 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);
}
/* 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)
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();
{
IP4Hdr* h = (IP4Hdr*)(lyr->start);
int i = lyr - p->layers;
- uint16_t hlen = h->get_hlen() << 2;
+ uint16_t hlen = h->hlen();
*len += hlen;
*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) )
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
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
/* 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);
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!!
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());
}
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
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 */
}
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());
}
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;
}
* 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)
{
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();
* 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;
// 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;
(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,
ip4h->ttl(),
ip4h->tos(),
ip4h->id(),
- ip4h->get_hlen() << 2,
+ ip4h->hlen(),
ip4h->len());
frag_off = ip4h->off();
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
{
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))
{
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-// packet_manager.h author Josh Rosenbaum <jrosenba@cisco.com>
+// codec_manager.h author Josh Rosenbaum <jrosenba@cisco.com>
#ifndef MANAGERS_CODEC_MANAGER_H
#define MANAGERS_CODEC_MANAGER_H
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++;
// 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;
}
bool IpApi::set(const uint8_t* raw_ip_data)
{
const IP4Hdr* h4 = reinterpret_cast<const IP4Hdr*>(raw_ip_data);
- if (h4->get_ver() == 4)
+ if (h4->ver() == 4)
{
set(h4);
return true;
const IP6Hdr* h6 = reinterpret_cast<const IP6Hdr*>(raw_ip_data);
- if (h6->get_ver() == 6)
+ if (h6->ver() == 6)
{
set(h6);
return true;
const uint8_t* IpApi::ip_data() const
{
if (ip4h)
- return reinterpret_cast<const uint8_t*>(ip4h) + (ip4h->get_hlen() << 2);
+ return reinterpret_cast<const uint8_t*>(ip4h) + (ip4h->hlen());
if (ip6h)
- return reinterpret_cast<const uint8_t*>(ip6h) + IP6_HEADER_LEN;
+ return reinterpret_cast<const uint8_t*>(ip6h) + ip6h->hlen();
return nullptr;
}
uint16_t IpApi::pay_len() const
{
if (ip4h)
- return ip4h->len() - IP4_HEADER_LEN;
+ return ip4h->len() - ip4h->hlen();
if (ip6h)
return ip6h->len();
{ 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.
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; };
{ 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 */
{ 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; }
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
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); }
+
} ;
inline uint32_t id() const
{ return ntohl(ip6f_ident); }
- inline uint8_t get_res() const
+ inline uint8_t res() const
{ return ip6f_reserved; }
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; }
/* 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
return reinterpret_cast<const ip::IP4Hdr*>(layers[i].start)->proto();
case ETHERTYPE_IPV6:
case IPPROTO_ID_IPV6:
- return reinterpret_cast<const ip::IP6Hdr*>(layers[i].start)->get_next();
+ return reinterpret_cast<const ip::IP6Hdr*>(layers[i].start)->next();
default:
break;
}
*
* Generally calculated by
* (layers_entire_length) - length;
- * (ip::IP4Hdr*) ip4h->get_hlen() * 4 - length;
+ * (ip::IP4Hdr*) ip4h->hlen()- length;
*/
};
const ip::IP4Hdr* const ip4h =
reinterpret_cast<const ip::IP4Hdr*>(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;
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); }
inline bool is_rst() const
{ return (th_flags & TH_RST); }
+
/* raw data access */
inline uint8_t raw_src_port() const
{ return th_sport; }
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
{
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;
{
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. */
/* 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)
{
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;
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;
#include <sstream>
#include <vector>
+#include <stdexcept>
#include "conversion_state.h"
#include "utils/converter.h"
template<const std::string *norm_option>
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 + " = <bool>");
c.get_table_api().add_option(*norm_option, true);
c.get_table_api().close_table();
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);
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);