]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
removing SFIP macros
authorJosh <jrosenba@cisco.com>
Tue, 12 Aug 2014 22:57:03 +0000 (18:57 -0400)
committerJosh <jrosenba@cisco.com>
Wed, 13 Aug 2014 16:21:31 +0000 (12:21 -0400)
44 files changed:
src/codecs/ip/cd_icmp6.cc
src/codecs/ip/cd_ipv6.cc
src/codecs/ip/cd_udp.cc
src/detection/fpdetect.cc
src/detection/tag.cc
src/file_api/file_resume_block.cc
src/filters/rate_filter.cc
src/filters/sfrf.cc
src/filters/sfthd.cc
src/flow/expect_cache.cc
src/ips_options/ips_rpc.cc
src/log/messages.cc
src/managers/packet_manager.cc
src/network_inspectors/arp_spoof/arp_spoof.cc
src/network_inspectors/perf_monitor/perf_flow.cc
src/network_inspectors/port_scan/port_scan.cc
src/network_inspectors/port_scan/ps_detect.cc
src/protocols/gre.h
src/protocols/ip.h
src/protocols/layer.h
src/protocols/packet.h
src/service_inspectors/ftp_telnet/ftp_bounce_lookup.cc
src/service_inspectors/ftp_telnet/ftp_parse.cc
src/service_inspectors/ftp_telnet/ftpp_si.cc
src/service_inspectors/ftp_telnet/pp_ftp.cc
src/service_inspectors/http_inspect/hi_client.cc
src/service_inspectors/http_inspect/hi_main.cc
src/service_inspectors/http_inspect/hi_si.cc
src/sfip/CMakeLists.txt
src/sfip/Makefile.am
src/sfip/ipv6_port.h
src/sfip/sf_ip.h
src/sfip/sf_iph.cc [deleted file]
src/sfip/sf_iph.h [deleted file]
src/sfip/sfip_t.h
src/stream/icmp/icmp_session.cc
src/stream/ip/ip_session.cc
src/stream/stream_api.cc
src/stream/tcp/tcp_session.cc
src/stream/udp/udp_session.cc
src/target_based/sftarget_reader.cc
src/test/sfrf_test.cc
src/test/sfthd_test.cc
src/time/ppm.cc

index 12c532fafff26bdb2794d643256390822974c704..3b6d93036d8fcca0772f8515cb9e96eec89910e7 100644 (file)
@@ -137,7 +137,7 @@ bool Icmp6Codec::decode(const uint8_t* raw_pkt, const uint32_t& raw_len,
                 p->dsize -= sizeof(ICMPHdr::icmp_hun.idseq);
                 p->data += sizeof(ICMPHdr::icmp_hun.idseq);
 
-                if ( ipv6::is_multicast(p->ip_api.get_dst()->ip.u6_addr8[0]) )
+                if ( ipv6::is_multicast(p->ip_api.get_dst()->ip8[0]) )
                     codec_events::decoder_event(p, DECODE_ICMP6_DST_MULTICAST);
             }
             else
index 12137fb9650584a03636b0081973a9b5582b1076..24130aaf8f196422e30b09b3d16436ce6ead01a5 100644 (file)
@@ -162,14 +162,13 @@ bool Ipv6Codec::decode(const uint8_t *raw_pkt, const uint32_t& raw_len,
         goto decodeipv6_fail;
     }
 
+#if 0
+    // multiple encapsulations are now allowed.  this alert is no longer valid
+    if (p->encapsulations)
+        codec_events::decoder_alert_encapsulated(p, DECODE_IP_MULTIPLE_ENCAPSULATION,
+                        raw_pkt, raw_len);
+#endif
 
-    // This will need to go
-    if (p->family != NO_IP)
-    {
-        if (p->encapsulations)
-            codec_events::decoder_alert_encapsulated(p, DECODE_IP_MULTIPLE_ENCAPSULATION,
-                            raw_pkt, raw_len);
-    }
 
     payload_len = ntohs(ip6h->ip6plen) + ipv6::hdr_len();
 
@@ -252,7 +251,7 @@ static inline void IPV6CheckIsatap(const ipv6::IP6RawHdr* ip6h, Packet* p)
            fe80:0000:0000:0000:0000:5efe, followed by the IPv4 address. */
         if (isatap_interface_id == 0x00005EFE)
         {
-            if (p->ip_api.get_src()->ip.u6_addr32[0] != ip6h->ip6_src.u6_addr32[3])
+            if (p->ip_api.get_src()->ip32[0] != ip6h->ip6_src.u6_addr32[3])
                 codec_events::decoder_event(p, DECODE_IPV6_ISATAP_SPOOF);
         }
     }
index 16d8e6bd26850e10731c058243945dd3431dbe57..e429d3dcea69fbc089346fd4af3d8c56beddc690 100644 (file)
@@ -336,8 +336,8 @@ bool UdpCodec::encode (EncState* enc, Buffer* out, const uint8_t* raw_in)
         {
             checksum::Pseudoheader ps;
             const IPHdr *ip4h = ip_api->get_ip4h();
-            ps.sip = ((IPHdr *)enc->ip_hdr)->ip_src;
-            ps.dip = ((IPHdr *)enc->ip_hdr)->ip_dst;
+            ps.sip = ip4h->get_src();
+            ps.dip = ip4h->get_dst();
             ps.zero = 0;
             ps.protocol = IPPROTO_UDP;
             ps.len = ho->uh_len;
index f2d874e1eb2229e9cedb55a52dbbe0da0207a9c7..800e5387e8dd4f278baa57e217d010bd2add4b74 100644 (file)
@@ -223,12 +223,12 @@ int fpLogEvent(RuleTreeNode *rtn, OptTreeNode *otn, Packet *p)
     else
     {
         sfip_t cleared;
-        IP_CLEAR(cleared);
+        sfip_clear(cleared);
 
         filterEvent = sfthreshold_test(
             otn->sigInfo.generator,
             otn->sigInfo.id,
-            IP_ARG(cleared), IP_ARG(cleared),
+            &cleared, &cleared,
             p->pkth->ts.tv_sec);
     }
 
index e5e819042021df488c38b949deca895312491683..9b868e20501ea855e1e4915b5a64892d2eac83ac 100644 (file)
@@ -367,8 +367,8 @@ static void AddTagNode(Packet *p, TagData *tag, int mode, uint32_t now,
         return;
     }
 
-    IP_COPY_VALUE(idx->key.sip, p->ip_api.get_src());
-    IP_COPY_VALUE(idx->key.dip, p->ip_api.get_dst());
+    sfip_copy(idx->key.sip, p->ip_api.get_src());
+    sfip_copy(idx->key.dip, p->ip_api.get_dst());
     idx->key.sp = p->sp;
     idx->key.dp = p->dp;
     idx->proto = p->ip_api.proto();
@@ -468,8 +468,8 @@ int CheckTagList(Packet *p, Event *event)
 
     DEBUG_WRAP(DebugMessage(DEBUG_FLOW, "[*] Checking session tag list (forward)...\n"););
 
-    IP_COPY_VALUE(idx.key.sip, p->ip_api.get_src());
-    IP_COPY_VALUE(idx.key.dip, p->ip_api.get_dst());
+    sfip_copy(idx.key.sip, p->ip_api.get_src());
+    sfip_copy(idx.key.dip, p->ip_api.get_dst());
     idx.key.sp = p->sp;
     idx.key.dp = p->dp;
 
@@ -478,8 +478,8 @@ int CheckTagList(Packet *p, Event *event)
 
     if(returned == NULL)
     {
-        IP_COPY_VALUE(idx.key.dip, p->ip_api.get_src());
-        IP_COPY_VALUE(idx.key.sip, p->ip_api.get_dst());
+        sfip_copy(idx.key.dip, p->ip_api.get_src());
+        sfip_copy(idx.key.sip, p->ip_api.get_dst());
         idx.key.dp = p->sp;
         idx.key.sp = p->dp;
 
@@ -499,7 +499,7 @@ int CheckTagList(Packet *p, Event *event)
                 **  Only switch sip, because that's all we check for
                 **  the host tags.
                 */
-                IP_COPY_VALUE(idx.key.sip, p->ip_api.get_src());
+                sfip_copy(idx.key.sip, p->ip_api.get_src());
 
                 returned = (TagNode *) sfxhash_find(host_tag_cache_ptr, &idx);
             }
index b15b20743cb3b0b64dd9288436e78d2b7eed369a..0e5cfc491e4048d6114a0e57be4e577157174641 100644 (file)
@@ -105,8 +105,8 @@ int file_resume_block_add_file(void *pkt, uint32_t file_sig, uint32_t timeout,
 
     srcIP = p->ip_api.get_src();
     dstIP = p->ip_api.get_dst();
-    IP_COPY_VALUE(hashKey.dip, dstIP);
-    IP_COPY_VALUE(hashKey.sip, srcIP);
+    sfip_copy(hashKey.dip, dstIP);
+    sfip_copy(hashKey.sip, srcIP);
     hashKey.file_sig = file_sig;
 
     hash_node = sfxhash_find_node(fileHash, &hashKey);
@@ -241,8 +241,8 @@ File_Verdict file_resume_block_check(void *pkt, uint32_t file_sig)
     }
     srcIP = p->ip_api.get_src();
     dstIP = p->ip_api.get_dst();
-    IP_COPY_VALUE(hashKey.dip, dstIP);
-    IP_COPY_VALUE(hashKey.sip, srcIP);
+    sfip_copy(hashKey.dip, dstIP);
+    sfip_copy(hashKey.sip, srcIP);
     hashKey.file_sig = file_sig;
 
     hash_node = sfxhash_find_node(fileHash, &hashKey);
index 6f6a08a9ea6aa2a86c89fe4694a030cfc3dc98af..0a756d36608b9baeede577f5c8708db1cd19bad7 100644 (file)
@@ -141,9 +141,9 @@ int RateFilter_Test(
     }
     else
     {
-        IP_CLEAR(cleared);
-        sip = IP_ARG(cleared);
-        dip = IP_ARG(cleared);
+        sfip_clear(cleared);
+        sip = &cleared;
+        dip = &cleared;
     }
 
     if ((snort_conf == NULL) || (snort_conf->rate_filter_config == NULL))
index 88e62e987ddf96da963ac5e12adb550c863baad8..572769d31bc73f1dbaf18ceca6ed691919812ccc 100644 (file)
@@ -566,8 +566,8 @@ int SFRF_TestThreshold(
             case SFRF_TRACK_BY_RULE:
                 {
                     sfip_t cleared;
-                    IP_CLEAR(cleared);
-                    newStatus = SFRF_TestObject(cfgNode, IP_ARG(cleared), curTime, op);
+                    sfip_clear(cleared);
+                    newStatus = SFRF_TestObject(cfgNode, &cleared, curTime, op);
                 }
                 break;
 
@@ -808,7 +808,7 @@ static tSFRFTrackingNode* _getSFRFTrackingNode(
     SFXHASH_NODE * hnode = NULL;
 
     /* Setup key */
-    key.ip = *(IP_PTR(ip));
+    key.ip = *(ip);
     key.tid = tid;
     key.policyId = get_network_policy()->policy_id;
 
index 38b3994d45b909d0c9f945515db04a58496b0911..62cb955cd2b36e0710d2b3da78d4e8dab247d7f7 100644 (file)
@@ -942,7 +942,7 @@ int sfthd_test_local(
 
     /* Set up the key */
     key.policyId = policy_id;
-    key.ip     = IP_VAL(ip);
+    key.ip = *ip;
     key.thd_id = sfthd_node->thd_id;
 
     /* Set up a new data element */
@@ -1033,7 +1033,7 @@ static inline int sfthd_test_global(
     */
 
     /* Set up the key */
-    key.ip     = IP_VAL(ip);
+    key.ip = *ip;
     key.gen_id = sfthd_node->gen_id;
     key.sig_id = sig_id;
     key.policyId = policy_id;
index 3f5827cde877b3152ee0eae7e0a61e6ff3a4100c..499864c4fc416c657cae9f95f0db6b34c1511bfd 100644 (file)
@@ -142,17 +142,17 @@ inline bool ExpectKey::set(
 
     if (rval == SFIP_LESSER || (rval == SFIP_EQUAL && cliPort < srvPort))
     {
-        IP_COPY_VALUE(ip1, cliIP);
+        sfip_copy(ip1, cliIP);
         port1 = cliPort;
-        IP_COPY_VALUE(ip2, srvIP);
+        sfip_copy(ip2, srvIP);
         port2 = srvPort;
         reverse = false;
     }
     else
     {
-        IP_COPY_VALUE(ip1, srvIP);
+        sfip_copy(ip1, srvIP);
         port1 = srvPort;
-        IP_COPY_VALUE(ip2, cliIP);
+        sfip_copy(ip2, cliIP);
         port2 = cliPort;
         reverse = true;
     }
index a2e3879dc44fc4d45e960918afe7f1ddc15d18f2..3baffe2c8bf4cc59ce346f5fb43325e8ff10c99c 100644 (file)
@@ -136,7 +136,7 @@ int RpcOption::eval(Cursor&, Packet *p)
 #endif
     PROFILE_VARS;
 
-    if(!p->iph_api || (IsTCP(p) && !p->tcph)
+    if(!p->ip_api.is_valid() || (IsTCP(p) && !p->tcph)
        || (IsUDP(p) && !p->udph))
         return 0; /* if error occured while ip header
                    * was processed, return 0 automagically.  */
index c7e3bfdc11e2feb0bea1cfd05e0b5845f5649a71..1965b450572b4397447c12951f3347cb33ca173f 100644 (file)
@@ -360,7 +360,7 @@ char * ObfuscateIpToText(const sfip_t *ip)
     if (ip == NULL)
         return ip_buf;
 
-    if (!IP_IS_SET(snort_conf->obfuscation_net))
+    if (!sfip_is_set(snort_conf->obfuscation_net))
     {
         if (ip->is_ip6())
             SnortSnprintf(ip_buf, buf_size, "x:x:x:x::x:x:x:x");
@@ -372,9 +372,9 @@ char * ObfuscateIpToText(const sfip_t *ip)
         sfip_t tmp;
         char *tmp_buf;
 
-        IP_COPY_VALUE(tmp, ip);
+        sfip_copy(tmp, ip);
 
-        if (IP_IS_SET(snort_conf->homenet))
+        if (sfip_is_set(snort_conf->homenet))
         {
             if (sfip_contains(&snort_conf->homenet, &tmp) == SFIP_CONTAINS)
                 sfip_obfuscate(&snort_conf->obfuscation_net, &tmp);
index a03e8d7f72c1505a14ca729b6046786c9fff086e..805edc14912860bfac7b730762d5ce9267138f0c 100644 (file)
@@ -562,10 +562,7 @@ SO_PUBLIC int PacketManager::encode_format_with_daq_info (
     Layer* lyr;
     int len;
     int num_layers = p->num_layers;
-
-    // TODO -- remove
     DAQ_PktHdr_t* pkth = (DAQ_PktHdr_t*)c->pkth;
-    uint8_t* pkt = (uint8_t*)c->pkt;
 
     if ( num_layers <= 0 )
         return -1;
index 3f425841490afeae7e140adce4333c83e0602584..ae2ec2be1aab140418c3fef32d992c0eb084ec5b 100644 (file)
@@ -127,7 +127,7 @@ static void PrintIPMacEntryList(IPMacEntryList& ipmel)
         sfip_t in;
         sfip_set_raw(&in, &p.ipv4_addr, AF_INET);
         // FIXIT replace all inet_ntoa() with thread safe
-        LogMessage("    %s -> ", inet_ntoa(IP_ARG(in)));
+        LogMessage("    %s -> ", inet_ntoa(&in));
 
         for (int i = 0; i < 6; i++)
         {
index 9e9c5d15f07af9c11d32e6e14095ca08f710f854..12718b3009ad13917c23233cc961e6789eecfc64 100644 (file)
@@ -288,16 +288,16 @@ static sfSFSValue *findFlowIPStats(SFFLOW *sfFlow, const sfip_t *src_addr, const
     sfSFSKey key;
     sfSFSValue *value;
 
-    if (IP_LESSER(src_addr, dst_addr))
+    if (sfip_lesser(src_addr, dst_addr))
     {
-        IP_COPY_VALUE(key.ipA, src_addr);
-        IP_COPY_VALUE(key.ipB, dst_addr);
+        sfip_copy(key.ipA, src_addr);
+        sfip_copy(key.ipB, dst_addr);
         *swapped = 0;
     }
     else
     {
-        IP_COPY_VALUE(key.ipA, dst_addr);
-        IP_COPY_VALUE(key.ipB, src_addr);
+        sfip_copy(key.ipA, dst_addr);
+        sfip_copy(key.ipB, src_addr);
         *swapped = 1;
     }
 
index 3da621cc2017c66886cc4a1ee119a7ff8aba4901..97ada1d9f3832783377fa5918c0a5c23ad3c7ddb 100644 (file)
@@ -65,7 +65,6 @@
 #include "snort.h"
 #include "filters/sfthreshold.h"
 #include "sfsnprintfappend.h"
-#include "sf_iph.h"
 #include "framework/inspector.h"
 #include "framework/share.h"
 #include "framework/plug_data.h"
@@ -193,7 +192,7 @@ static int LogPortscanAlert(Packet *p, uint32_t event_id,
     const sfip_t *src_addr;
     const sfip_t *dst_addr;
 
-    if(!p->iph_api)
+    if(!p->ip_api.is_valid())
         return -1;
 
     /* Do not log if being suppressed */
index 65531a4cbe9076c89b5c7bebc4d287ecd1d1566c..695b0cdab6523536f5960275e5011b8d225f85c5 100644 (file)
@@ -511,12 +511,12 @@ int PortScan::ps_tracker_lookup(PS_PKT *ps_pkt, PS_TRACKER **scanner,
     if (config->detect_scan_type &
         (PS_TYPE_PORTSCAN | PS_TYPE_DECOYSCAN | PS_TYPE_DISTPORTSCAN))
     {
-        IP_CLEAR(key.scanner);
+        sfip_clear(key.scanner);
 
         if(ps_pkt->reverse_pkt)
-            IP_COPY_VALUE(key.scanned, p->ip_api.get_src());
+            sfip_copy(key.scanned, p->ip_api.get_src());
         else
-            IP_COPY_VALUE(key.scanned, p->ip_api.get_dst());
+            sfip_copy(key.scanned, p->ip_api.get_dst());
 
         /*
         **  Get the scanned tracker.
@@ -529,12 +529,12 @@ int PortScan::ps_tracker_lookup(PS_PKT *ps_pkt, PS_TRACKER **scanner,
     */
     if(config->detect_scan_type & PS_TYPE_PORTSWEEP)
     {
-        IP_CLEAR(key.scanned);
+        sfip_clear(key.scanned);
 
         if(ps_pkt->reverse_pkt)
-            IP_COPY_VALUE(key.scanner, p->ip_api.get_dst());
+            sfip_copy(key.scanner, p->ip_api.get_dst());
         else
-            IP_COPY_VALUE(key.scanner, p->ip_api.get_src());
+            sfip_copy(key.scanner, p->ip_api.get_src());
 
         /*
         **  Get the scanner tracker
@@ -726,32 +726,32 @@ int PortScan::ps_proto_update(PS_PROTO *proto, int ps_cnt, int pri_cnt, const sf
     if(proto->connection_count < 0)
         proto->connection_count = 0;
 
-    if(!IP_EQUALITY_UNSET(&proto->u_ips, ip))
+    if(!sfip_unset_equals(&proto->u_ips, ip))
     {
         proto->u_ip_count++;
-        IP_COPY_VALUE(proto->u_ips, ip);
+        sfip_copy(proto->u_ips, ip);
     }
 
     /* we need to do the IP comparisons in host order */
 
     if(sfip_is_set(&proto->low_ip))
     {
-        if(IP_GREATER(&proto->low_ip, ip))
-            IP_COPY_VALUE(proto->low_ip, ip);
+        if(sfip_greater(&proto->low_ip, ip))
+            sfip_copy(proto->low_ip, ip);
     }
     else
     {
-        IP_COPY_VALUE(proto->low_ip, ip);
+        sfip_copy(proto->low_ip, ip);
     }
 
-    if(IP_IS_SET(proto->high_ip))
+    if(sfip_is_set(proto->high_ip))
     {
-        if(IP_LESSER(&proto->high_ip, ip))
-            IP_COPY_VALUE(proto->high_ip, ip);
+        if(sfip_lesser(&proto->high_ip, ip))
+            sfip_copy(proto->high_ip, ip);
     }
     else
     {
-        IP_COPY_VALUE(proto->high_ip, ip);
+        sfip_copy(proto->high_ip, ip);
     }
 
     if(proto->u_ports != port)
@@ -827,7 +827,7 @@ int PortScan::ps_tracker_update_tcp(PS_PKT *ps_pkt, PS_TRACKER *scanner,
     Packet  *p;
     uint32_t session_flags;
     sfip_t cleared;
-    IP_CLEAR(cleared);
+    sfip_clear(cleared);
 
     p = (Packet *)ps_pkt->pkt;
 
@@ -1006,7 +1006,7 @@ int PortScan::ps_tracker_update_ip(PS_PKT *ps_pkt, PS_TRACKER *scanner,
 {
     Packet *p;
     sfip_t cleared;
-    IP_CLEAR(cleared);
+    sfip_clear(cleared);
 
     p = (Packet *)ps_pkt->pkt;
 
@@ -1038,7 +1038,7 @@ int PortScan::ps_tracker_update_udp(PS_PKT *ps_pkt, PS_TRACKER *scanner,
 {
     Packet  *p;
     sfip_t    cleared;
-    IP_CLEAR(cleared);
+    sfip_clear(cleared);
 
     p = (Packet *)ps_pkt->pkt;
 
@@ -1095,7 +1095,7 @@ int PortScan::ps_tracker_update_icmp(
 {
     Packet  *p;
     sfip_t cleared;
-    IP_CLEAR(cleared);
+    sfip_clear(cleared);
 
     p = (Packet *)ps_pkt->pkt;
 
index e00515806d505a29d12338cdfd0244a96091cb1d..6911482ee6bebe2effc7cd9e8b708220f89f293c 100644 (file)
@@ -38,7 +38,7 @@ struct GREHdr
     inline uint8_t get_version() const
     { return version & 0x07; }
 
-    inline uint8_t get_proto() const
+    inline uint16_t get_proto() const
     { return ntohs(ether_type); }
 };
 
index c06a4db8c95a002af2054cd2c7c9b8e1d200c9d6..b0169885f7d7b1937bbfaacf60f028decf62ad01 100644 (file)
@@ -40,7 +40,7 @@
 #include "sfip/sfip_t.h"
 
 
-class Packet;
+struct Packet;
 
 namespace ip
 {
index cfc15bc3dabc3206c4845b6b1e29d60457cd6d63..8ef08c6287bf5b642eab71f3b5af34833ed4a36e 100644 (file)
@@ -82,6 +82,8 @@ namespace icmp
 struct ICMPHdr;
 }
 
+struct Packet;
+
 namespace layer
 {
 
index 65a65f4692b6f56b4de137f2f8c172a4d425bd09..604252c08f5aa8e482415c6a84ff76f5975f0361 100644 (file)
@@ -49,7 +49,6 @@ extern "C" {
 #include "main/snort_types.h"
 #include "sfip/ipv6_port.h"
 #include "sfip/sf_ip.h"
-#include "sfip/sf_iph.h"
 #include "codecs/sf_protocols.h"
 
 
@@ -191,8 +190,6 @@ struct Packet
     Flow* flow;   /* for session tracking */
 
     //vvv-----------------------------
-    IPH_API* iph_api;
-
     int family;
     //^^^-----------------------------
 
index ce0bcda1f26bf2f526621055ceaccdce822c9e02..bc876629c88183f2aa344e9c47ef6e124341c419 100644 (file)
@@ -129,7 +129,7 @@ int ftp_bounce_lookup_add(BOUNCE_LOOKUP *BounceLookup,
         return FTPP_INVALID_ARG;
     }
 
-    iRet = KMapAdd(BounceLookup, (void*)IP_PTR(Ip), IP_SIZE(Ip), (void*)BounceTo);
+    iRet = KMapAdd(BounceLookup, (void*)Ip, Ip->sfip_size(), (void*)BounceTo);
 
     if (iRet)
     {
@@ -185,7 +185,7 @@ FTP_BOUNCE_TO  *ftp_bounce_lookup_find(
 
     *iError = FTPP_SUCCESS;
 
-    BounceTo = (FTP_BOUNCE_TO *)KMapFind(BounceLookup, (void*)IP_PTR(Ip), IP_SIZE(Ip));
+    BounceTo = (FTP_BOUNCE_TO *)KMapFind(BounceLookup, (void*)Ip, Ip->sfip_size());
     if (!BounceTo)
     {
         *iError = FTPP_NOT_FOUND;
index a7287d27b9b25ce0f7c3591a41960c4f75fef41f..7e2c33053c41ee848760082f8fa04249585b0cc8 100644 (file)
@@ -840,7 +840,7 @@ int ProcessFTPAllowBounce(
         newBounce->porthi = high;
  
         int iRet = ftp_bounce_lookup_add(
-            ClientConf->bounce_lookup, IP_ARG(newBounce->ip), newBounce);
+            ClientConf->bounce_lookup, &newBounce->ip, newBounce);
 
         if (iRet)
         {
index 20cb1c4b5e5c6275e68d17e4183a93bae3d6bf83..91eb79f3abfaecbe90a39e8104046a52839c3391 100644 (file)
@@ -488,9 +488,9 @@ static inline int FTPResetsession(FTP_SESSION *Ftpsession)
     Ftpsession->server_conf = NULL;
 
     Ftpsession->encr_state = NO_STATE;
-    IP_CLEAR(Ftpsession->clientIP);
+    sfip_clear(Ftpsession->clientIP);
     Ftpsession->clientPort = 0;
-    IP_CLEAR(Ftpsession->serverIP);
+    sfip_clear(Ftpsession->serverIP);
     Ftpsession->serverPort = 0;
     Ftpsession->data_chan_state = NO_STATE;
     Ftpsession->data_chan_index = -1;
@@ -596,8 +596,8 @@ int FTPsessionInspection(
  */
 int SetSiInput(FTPP_SI_INPUT *SiInput, Packet *p)
 {   
-    IP_COPY_VALUE(SiInput->sip, p->ip_api.get_src());
-    IP_COPY_VALUE(SiInput->dip, p->ip_api.get_dst());
+    sfip_copy(SiInput->sip, p->ip_api.get_src());
+    sfip_copy(SiInput->dip, p->ip_api.get_dst());
     SiInput->sport = p->sp;
     SiInput->dport = p->dp;
         
index 47b756168a223431af5c9c5fe051d3b8d845dc77..2d742d868c8f1deb1b75fa7c1fab90fc66d47e33 100644 (file)
@@ -363,7 +363,7 @@ static int getIP2428 (
     int family = AF_UNSPEC, port = 0;
     char buf[64];
 
-    IP_CLEAR((*ipRet));
+    sfip_clear((*ipRet));
     *portRet = 0;
 
     /* check first delimiter */
@@ -787,7 +787,7 @@ static int validate_param(Packet *p,
                 break;
             }
 
-            if ( ThisFmt->type == e_extd_host_port && !IP_IS_SET(ipAddr) )
+            if ( ThisFmt->type == e_extd_host_port && !sfip_is_set(ipAddr) )
             {
                 // actually, we expect no addr in 229 responses, which is
                 // understood to be server address, so we set that here
@@ -795,12 +795,12 @@ static int validate_param(Packet *p,
             }
             if ( session->client_conf->bounce )
             {
-                if (!IP_EQUALITY(&ipAddr, p->ip_api.get_src()))
+                if (!sfip_equals(&ipAddr, p->ip_api.get_src()))
                 {
                     int alert = 1;
 
                     FTP_BOUNCE_TO *BounceTo = ftp_bounce_lookup_find(
-                        session->client_conf->bounce_lookup, (const sfip_t*)IP_ARG(ipAddr), &iRet);
+                        session->client_conf->bounce_lookup, &ipAddr, &iRet);
                     if (BounceTo)
                     {
                         if (BounceTo->portlo)
@@ -844,7 +844,7 @@ static int validate_param(Packet *p,
                 session->data_chan_state &= ~DATA_CHAN_PASV_CMD_ISSUED;
             }
 
-            IP_CLEAR(session->serverIP);
+            sfip_clear(session->serverIP);
             session->serverPort = 0;
         }
         break;
@@ -1088,7 +1088,7 @@ static int do_stateful_checks(FTP_SESSION *session, Packet *p,
                     sfip_t ipAddr;
                     uint16_t port=0;
                     const char *ip_begin = req->param_begin;
-                    IP_CLEAR(ipAddr);
+                    sfip_clear(ipAddr);
                     session->data_chan_state &= ~DATA_CHAN_PASV_CMD_ISSUED;
                     session->data_chan_state |= DATA_CHAN_PASV_CMD_ACCEPT;
                     session->data_chan_index = -1;
@@ -1124,14 +1124,14 @@ static int do_stateful_checks(FTP_SESSION *session, Packet *p,
                         );
                         if (iRet == FTPP_SUCCESS)
                         {
-                            if (!IP_IS_SET(ipAddr))
-                                IP_COPY_VALUE(session->serverIP, p->ip_api.get_src());
+                            if (!sfip_is_set(ipAddr))
+                                sfip_copy(session->serverIP, p->ip_api.get_src());
                             else
                             {
                                 session->serverIP = ipAddr;
                             }
                             session->serverPort = port;
-                            IP_COPY_VALUE(session->clientIP, p->ip_api.get_dst());
+                            sfip_copy(session->clientIP, p->ip_api.get_dst());
                             session->clientPort = 0;
 
                             if ((file_api->get_max_file_depth() > 0) || !(session->server_conf->data_chan))
@@ -1146,8 +1146,8 @@ static int do_stateful_checks(FTP_SESSION *session, Packet *p,
 
                                 /* Call into Streams to mark data channel as ftp-data */
                                 result = stream.set_application_protocol_id_expected(
-                                    IP_ARG(session->clientIP), session->clientPort,
-                                    IP_ARG(session->serverIP), session->serverPort,
+                                    &session->clientIP, session->clientPort,
+                                    &session->serverIP, session->serverPort,
                                     (uint8_t)(p->ip_api.proto()), ftp_data_app_id, fd);
 
                                 if (result < 0)
@@ -1158,8 +1158,8 @@ static int do_stateful_checks(FTP_SESSION *session, Packet *p,
                                 /* Call into Streams to mark data channel as something
                                  * to ignore. */
                                 stream.ignore_session(
-                                    IP_ARG(session->clientIP), session->clientPort,
-                                    IP_ARG(session->serverIP), session->serverPort,
+                                    &session->clientIP, session->clientPort,
+                                    &session->serverIP, session->serverPort,
                                     (uint8_t)(p->ip_api.proto()),
                                     FtpDataFlowData::flow_id, SSN_DIR_BOTH);
                             }
@@ -1189,13 +1189,13 @@ static int do_stateful_checks(FTP_SESSION *session, Packet *p,
                     session->data_chan_state &= ~DATA_CHAN_PORT_CMD_ISSUED;
                     session->data_chan_state |= DATA_CHAN_PORT_CMD_ACCEPT;
                     session->data_chan_index = -1;
-                    if (IP_IS_SET(session->clientIP))
+                    if (sfip_is_set(session->clientIP))
                     {
                         /* This means we're not in passive mode. */
                         /* Server is listening/sending from its own IP,
                          * FTP Port -1 */
                         /* Client IP, Port specified via PORT command */
-                        IP_COPY_VALUE(session->serverIP, p->ip_api.get_src());
+                        sfip_copy(session->serverIP, p->ip_api.get_src());
 
                         /* Can't necessarily guarantee this, especially
                          * in the case of a proxy'd connection where the
@@ -1217,8 +1217,8 @@ static int do_stateful_checks(FTP_SESSION *session, Packet *p,
 
                             /* Call into Streams to mark data channel as ftp-data */
                             result = stream.set_application_protocol_id_expected(
-                                IP_ARG(session->clientIP), session->clientPort,
-                                IP_ARG(session->serverIP), session->serverPort,
+                                &session->clientIP, session->clientPort,
+                                &session->serverIP, session->serverPort,
                                 (uint8_t)(p->ip_api.proto()), ftp_data_app_id, fd);
 
                             if (result < 0)
@@ -1229,8 +1229,8 @@ static int do_stateful_checks(FTP_SESSION *session, Packet *p,
                             /* Call into Streams to mark data channel as something
                              * to ignore. */
                             stream.ignore_session(
-                                IP_ARG(session->clientIP), session->clientPort,
-                                IP_ARG(session->serverIP), session->serverPort,
+                                &session->clientIP, session->clientPort,
+                                &session->serverIP, session->serverPort,
                                 (uint8_t)(p->ip_api.proto()),
                                 FtpDataFlowData::flow_id, SSN_DIR_BOTH);
                         }
@@ -1257,8 +1257,8 @@ static int do_stateful_checks(FTP_SESSION *session, Packet *p,
                 }
                 /* Clear the session info for next transfer -->
                  * reset host/port */
-                IP_CLEAR(session->serverIP);
-                IP_CLEAR(session->clientIP);
+                sfip_clear(session->serverIP);
+                sfip_clear(session->clientIP);
                 session->serverPort = session->clientPort = 0;
 
                 session->data_chan_state = NO_STATE;
index d41fe756c9a933ff373326f267e503b28501f0a6..7f16c4a935a8a8d5f228a0b45301d87d77f72039 100644 (file)
@@ -1870,7 +1870,7 @@ const u_char *extract_http_xff(HI_SESSION *session, const u_char *p, const u_cha
             }
             if(*true_ip)
             {
-                if(!IP_EQUALITY(*true_ip, tmp))
+                if(!sfip_equals(*true_ip, tmp))
                 {
                     sfip_free(*true_ip);
                     *true_ip = tmp;
index abd21a58c264cd863370a43b1dbb9a7dcb2d0e49..a7040fa5dddd87e0b02c71875aba450db7bb0640 100644 (file)
@@ -351,8 +351,8 @@ int PrintGlobalConf(HTTPINSPECT_GLOBAL_CONF *GlobalConf)
 
 static inline int SetSiInput(HI_SI_INPUT *SiInput, Packet *p)
 {
-    IP_COPY_VALUE(SiInput->sip, p->ip_api.get_src());
-    IP_COPY_VALUE(SiInput->dip, p->ip_api.get_dst());
+    sfip_copy(SiInput->sip, p->ip_api.get_src());
+    sfip_copy(SiInput->dip, p->ip_api.get_dst());
     SiInput->sport = p->sp;
     SiInput->dport = p->dp;
 
index e7c4e4e03fa3b99ec5ee60cfe6951734b3dc8813..4a4c9dda7b41e35ddf7898034d541ecdd1c03539 100644 (file)
@@ -95,11 +95,11 @@ static int InitServerConf(HTTPINSPECT_CONF *GlobalConf,
 
     if (sip.family == AF_INET)
     {
-        sip.ip.u6_addr32[0] = ntohl(sip.ip.u6_addr32[0]);
+        sip.ip32[0] = ntohl(sip.ip32[0]);
     }
     if (dip.family == AF_INET)
     {
-        dip.ip.u6_addr32[0] = ntohl(dip.ip.u6_addr32[0]);
+        dip.ip32[0] = ntohl(dip.ip32[0]);
     }
 
     ServerConfDip = ServerConfSip = GlobalConf;
index b42009a56b1e794e17ab236d8600700332e15beb..def8799929fde31aded85a70ce2411110ca363e7 100644 (file)
@@ -2,7 +2,6 @@
 
 set(SFIP_INCLUDES
     ipv6_port.h
-    sf_iph.h
     sf_ip.h
     sf_ipvar.h
     sfip_t.h
@@ -11,7 +10,6 @@ set(SFIP_INCLUDES
 add_library ( sfip STATIC
     ${SFIP_INCLUDES}
     sf_ip.cc
-    sf_iph.cc
     sf_ipvar.cc
     sf_vartable.cc
     sf_vartable.h 
index fcd725dde71907dbbcd553d5fe950fd8ac99c0bc..12934fc0e51a0e06e5a162751736cb61474d6c34 100644 (file)
@@ -7,13 +7,11 @@ x_includedir = $(pkgincludedir)/sfip
 x_include_HEADERS = \
 ipv6_port.h \
 sf_ip.h \
-sf_iph.h \
 sf_ipvar.h \
 sfip_t.h
 
 libsfip_a_SOURCES = \
 sf_ip.cc \
-sf_iph.cc \
 sf_ipvar.cc \
 sf_vartable.cc \
 sf_vartable.h
index c71084cfb63c14743dceaf1f3d1057ff35e47232..b54993af464555ec9786fb3c021a36ec3d790c04 100644 (file)
 #include "sfip/sf_ipvar.h"
 
 
-#ifdef inet_ntoa
-#undef inet_ntoa
-#endif
-#define inet_ntoa sfip_ntoa
 
 #if 0
 typedef const sfip_t *const sfip_t*;
@@ -59,10 +55,6 @@ typedef const sfip_t snort_ip;
 #define GET_IPH_OFF(p)   (p)->iph_api->iph_ret_off(p)
 #define GET_IPH_VER(p)   (p)->iph_api->iph_ret_ver(p)
 
-#endif
-
-
-#if 0
 #define p->ip_api.proto() ((uint8_t)(IS_IP6(p) ? ((p)->ip6h->next) : ((p)->iph_api->iph_ret_proto(p))))
 
 
@@ -80,18 +72,14 @@ typedef const sfip_t snort_ip;
 /* XXX make sure these aren't getting confused with sfip_is_valid within the code */
 #define IPH_IS_VALID(p) iph_is_valid(p)
 
-#endif
 
 #define IP_EQUALITY(x,y) (sfip_compare((x),(y)) == SFIP_EQUAL)
 #define IP_EQUALITY_UNSET(x,y) (sfip_compare_unset((x),(y)) == SFIP_EQUAL)
 #define IP_LESSER(x,y)   (sfip_compare((x),(y)) == SFIP_LESSER)
 #define IP_GREATER(x,y)  (sfip_compare((x),(y)) == SFIP_GREATER)
-
-
-
 #define IP_CLEAR(x) (x).bits = (x).family = 0; (x).ip32[0] = (x).ip32[1] = (x).ip32[2] = (x).ip32[3] = 0;
-
 #define IP_IS_SET(x) sfip_is_set(&x)
+#define IP_COPY_VALUE(x,y) ( x = *y)
 
 /* This loop trickery is intentional.  If each copy is performed
  * individually on each field, then the following expression gets broken:
@@ -101,7 +89,8 @@ typedef const sfip_t snort_ip;
  * If the macro is instead enclosed in braces, then having a semicolon
  * trailing the macro causes compile breakage.
  * So: use loop. */
-#define IP_COPY_VALUE(x,y) \
+
+ \
         do {  \
                 (x).bits = (y)->bits; \
                 (x).family = (y)->family; \
@@ -111,7 +100,6 @@ typedef const sfip_t snort_ip;
                 (x).ip32[3] = (y)->ip32[3]; \
         } while(0)
 
-#if 0
 #define GET_IPH_HLEN(p) ((p)->iph_api->iph_ret_hlen(p))
 #define SET_IPH_HLEN(p, val)
 
@@ -121,12 +109,14 @@ typedef const sfip_t snort_ip;
 
 #define GET_INNER_SRC_IP(p)  (IS_IP6(p) ? (&((p)->inner_ip6h.ip_src)):(&((p)->inner_ip4h.ip_src)))
 #define GET_INNER_DST_IP(p)  (IS_IP6(p) ? (&((p)->inner_ip6h.ip_dst)):(&((p)->inner_ip4h.ip_dst)))
-#endif
+
+
 #define IP_ARG(ipt)  (&ipt)
 #define IP_PTR(ipp)  (ipp)
 #define IP_VAL(ipt)  (*ipt)
 #define IP_SIZE(ipp) (sfip_size(ipp))
 
+
 static inline int sfip_equal (const sfip_t *ip1, const sfip_t *ip2)
 {
     if ( ip1->family != ip2->family )
@@ -143,6 +133,7 @@ static inline int sfip_equal (const sfip_t *ip1, const sfip_t *ip2)
     }
     return 0;
 }
+#endif
 
 #endif /* IPV6_PORT_H */
 
index dc6a7344177ee778cdc828b5b1d67cd0f3ac2e32..47dca2dfaf8f38f29f4b602616d296733b1af60e 100644 (file)
@@ -122,7 +122,7 @@ void sfip_obfuscate(sfip_t *ob, sfip_t *ip);
 static inline unsigned int sfip_size(const sfip_t *ipt)
 {
     if ( ipt->family == AF_INET6 ) return sizeof(*ipt);
-    return (unsigned int)((ipt->ip.u6_addr8+4) - (u_int8_t*)ipt);
+    return (unsigned int)((ipt->ip8+4) - (u_int8_t*)ipt);
 }
 
 /* Member-access *******************************************************/
@@ -160,9 +160,10 @@ static inline void sfip_set_bits(sfip_t *p, int bits) {
 /* Returns SFIP_EQUAL if so */
 SFIP_RET sfip_contains(const sfip_t *net, const sfip_t *ip);
 
+#if 0
 /* Returns 1 if the IP is non-zero. 0 otherwise */
 /* XXX This is a performance critical function, \
- *  need to determine if it's safe to not check these pointers */\
+ *  need to determine if it's safe to not check these pointers */
 static inline int sfip_is_set(const sfip_t *ip) {
 //    ARG_CHECK1(ip, -1);
     return ip->ip32[0] ||
@@ -171,6 +172,7 @@ static inline int sfip_is_set(const sfip_t *ip) {
               ip->ip32[2] ||
               ip->ip32[3] || ip->bits != 128)) || ((ip->family == AF_INET) && ip->bits != 32)  ;
 }
+#endif
 
 /* Return 1 if the IP is a loopback IP */
 int sfip_is_loopback(const sfip_t *ip);
@@ -214,7 +216,7 @@ static inline SFIP_RET _ip6_cmp(const sfip_t *ip1, const sfip_t *ip2) {
  * or greater than ip2 In the case of mismatched families, the IPv4 address
  * is converted to an IPv6 representation. */
 /* XXX-IPv6 Should add version of sfip_compare that just tests equality */
-static inline SFIP_RET sfip_compare(const sfip_t *ip1, const sfip_t *ip2) {
+static inline SFIP_RET sfip_compare(const sfip_t* const ip1, const sfip_t* const ip2) {
     int f1,f2;
 
     ARG_CHECK2(ip1, ip2, SFIP_ARG_ERR);
@@ -255,7 +257,7 @@ static inline SFIP_RET sfip_compare(const sfip_t *ip1, const sfip_t *ip2) {
  * or greater than ip2 In the case of mismatched families, the IPv4 address
  * is converted to an IPv6 representation. */
 /* XXX-IPv6 Should add version of sfip_compare that just tests equality */
-static inline SFIP_RET sfip_compare_unset(const sfip_t *ip1, const sfip_t *ip2) {
+static inline SFIP_RET sfip_compare_unset(const sfip_t* const ip1, const sfip_t* const ip2) {
     int f1,f2;
 
     ARG_CHECK2(ip1, ip2, SFIP_ARG_ERR);
@@ -292,17 +294,17 @@ static inline SFIP_RET sfip_compare_unset(const sfip_t *ip1, const sfip_t *ip2)
     return SFIP_FAILURE;
 }
 
-static inline int sfip_fast_lt4(const sfip_t *ip1, const sfip_t *ip2) {
+static inline int sfip_fast_lt4(const sfip_t* const ip1, const sfip_t* const ip2) {
     return *ip1->ip32 < *ip2->ip32;
 }
-static inline int sfip_fast_gt4(const sfip_t *ip1, const sfip_t *ip2) {
+static inline int sfip_fast_gt4(const sfip_t* const ip1, const sfip_t* const ip2) {
     return *ip1->ip32 > *ip2->ip32;
 }
-static inline int sfip_fast_eq4(const sfip_t *ip1, const sfip_t *ip2) {
+static inline int sfip_fast_eq4(const sfip_t* const ip1, const sfip_t* const ip2) {
     return *ip1->ip32 == *ip2->ip32;
 }
 
-static inline int sfip_fast_lt6(const sfip_t *ip1, const sfip_t *ip2) {
+static inline int sfip_fast_lt6(const sfip_t* const ip1, const sfip_t* const ip2) {
     const u_int32_t *p1, *p2;
 
     p1 = ip1->ip32;
@@ -323,7 +325,7 @@ static inline int sfip_fast_lt6(const sfip_t *ip1, const sfip_t *ip2) {
     return 0;
 }
 
-static inline int sfip_fast_gt6(const sfip_t *ip1, const sfip_t *ip2) {
+static inline int sfip_fast_gt6(const sfip_t* const ip1, const sfip_t* const ip2) {
     const u_int32_t *p1, *p2;
 
     p1 = ip1->ip32;
@@ -477,15 +479,15 @@ static inline int sfip_is_private(const sfip_t *ip)
 
 }
 
+#if 0
 #define sfip_equals(x,y) (sfip_compare(&x, &y) == SFIP_EQUAL)
 #define sfip_not_equals !sfip_equals
 #define sfip_clear(x) memset(x, 0, 16)
+#endif
 
 /* Printing ************************************************************/
 
 /* Uses a static buffer to return a string representation of the IP */
-char *sfip_to_str(const sfip_t *ip);
-#define sfip_ntoa(x) sfip_to_str(x)
 void sfip_raw_ntop(int family, const void *ip_raw, char *buf, int bufsize);
 void sfip_ntop(const sfip_t *ip, char *buf, int bufsize);
 
diff --git a/src/sfip/sf_iph.cc b/src/sfip/sf_iph.cc
deleted file mode 100644 (file)
index d9b7796..0000000
+++ /dev/null
@@ -1,536 +0,0 @@
-/****************************************************************************
- *
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
- * Copyright (C) 2007-2013 Sourcefire, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation.  You may not use, modify or
- * distribute this program under any other version of the GNU General
- * Public License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- ****************************************************************************/
-
-#include "sf_iph.h"
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include <string.h>
-#include "protocols/packet.h"
-
-#define FAILURE -1
-#define SUCCESS 0
-#define IP6_HDR_LEN 40
-
-/* Version is the first four bits of the uint32_t passed in */
-#define IP6_VER(x) \
-   (ntohl(x) >> 28)
-
-/* The 'Packet' structure is almost always allocated on the stack.
- * Likewise, return buffers will almost always be aswell.
- * So, for performance reasons, argument validation can be disabled
- * and removed from the code at compile time to prevent unecessary extra
- * conditionals from being checked at run-time. */
-#define ERR_CHK_LVL  0
-#if ERR_CHK_LVL == 2
-#define VALIDATE(x,y) if(!x || !y) return FAILURE;
-#elif ERR_CHK_LVL == 1
-#define VALIDATE(x,y) if(!y) return FAILURE;
-#else
-#define VALIDATE(x,y)
-#endif
-
-#if 0
-
-sfip_t *ip6_ret_src(const Packet *p)
-{
-    VALIDATE(p, 1);
-    return &p->ip6h->ip_src;
-}
-
-sfip_t *orig_ip6_ret_src(const Packet *p)
-{
-    VALIDATE(p, 1);
-
-    return nullptr;
-//  return &p->orig_ip6h->ip_src;
-}
-
-sfip_t *ip6_ret_dst(const Packet *p)
-{
-    VALIDATE(p, 1);
-
-    return &p->ip6h->ip_dst;
-}
-
-
-sfip_t *orig_ip6_ret_dst(const Packet *p)
-{
-    VALIDATE(p, 1);
-    return nullptr;
-//  return &p->orig_ip6h->ip_dst;
-}
-
-uint16_t ip6_ret_toc(const Packet *p)
-{
-    uint16_t toc;
-    VALIDATE(p,1);
-
-    toc = (uint16_t)((ntohl(p->ip6h->vcl) & 0x0FF00000) >> 20);
-
-    return 0;
-//  return toc;
-}
-
-uint16_t orig_ip6_ret_toc(const Packet *p)
-{
-    uint16_t toc;
-    VALIDATE(p,1);
-
-    return 0;
-//    toc = (uint16_t)((ntohl(p->orig_ip6h->vcl) & 0x0FF00000) >> 20);
-//  return toc;
-}
-
-uint8_t ip6_ret_hops(const Packet *p)
-{
-//    VALIDATE(p,1);
-
-    return p->ip6h->hop_lmt;
-}
-
-uint8_t orig_ip6_ret_hops(const Packet *p)
-{
-//    VALIDATE(p,1);
-
-    return 0;
-//  return p->orig_ip6h->hop_lmt;
-}
-
-uint16_t ip6_ret_len(const Packet *p)
-{
-    VALIDATE(p,1);
-
-    /* The length field does not include the header in IPv6, but does in IPv4.
-     * To make this analogous to IPv4, for Snort's purposes, we need to tack
-     * on the difference. */
-    return p->ip6h->len;
-}
-
-uint16_t orig_ip6_ret_len(const Packet *p)
-{
-    VALIDATE(p,1);
-
-    return 0;
-//  return p->orig_ip6h->len;
-}
-
-uint32_t ip6_ret_id(const Packet *p)
-{
-    IP6Frag *frag_hdr;
-    if (p->ip6_extension_count == 0)
-        return 0;
-
-    frag_hdr = (IP6Frag*)p->ip6_extensions[p->ip6_frag_index].data;
-
-    return frag_hdr->ip6f_ident;
-}
-
-uint32_t orig_ip6_ret_id(const Packet*)
-{
-// XXX-IPv6 "NOT YET IMPLEMENTED - IP6 identification"
-    return 0;
-}
-
-uint8_t ip6_ret_next(const Packet *p)
-{
-    VALIDATE(p,1);
-    return p->ip6h->next;
-}
-
-uint8_t orig_ip6_ret_next(const Packet *p)
-{
-    VALIDATE(p,1);
-    return 0;
-//  return p->orig_ip6h->next;
-}
-
-uint16_t ip6_ret_off(const Packet *p)
-{
-    IP6Frag *frag_hdr;
-    if (p->ip6_extension_count == 0)
-        return 0;
-
-    frag_hdr = (IP6Frag *)p->ip6_extensions[p->ip6_frag_index].data;
-
-    return frag_hdr->ip6f_offlg;
-}
-
-uint16_t orig_ip6_ret_off(const Packet*)
-{
-// XXX-IPv6 "NOT YET IMPLEMENTED - IP6 frag offset"
-    return 0;
-}
-
-uint8_t ip6_ret_ver(const Packet *p)
-{
-    return (uint8_t)IP6_VER(p->ip6h->vcl);
-}
-
-uint8_t orig_ip6_ret_ver(const Packet *p)
-{
-    return 0;
-//  return (uint8_t)IP6_VER(p->orig_ip6h->vcl);
-}
-
-sfip_t *ip4_ret_dst(const Packet *p)
-{
-    VALIDATE(p,1);
-    return &p->ip4h->ip_dst;
-}
-
-sfip_t *orig_ip4_ret_dst(const Packet *p)
-{
-    VALIDATE(p,1);
-    return nullptr;
-//  return &p->orig_ip4h->ip_dst;
-}
-
-sfip_t *ip4_ret_src(const Packet *p)
-{
-    VALIDATE(p,1);
-    return &p->ip4h->ip_src;
-}
-
-sfip_t *orig_ip4_ret_src(const Packet *p)
-{
-    VALIDATE(p,1);
-    return nullptr;
-//  return &p->orig_ip4h->ip_src;
-}
-
-uint16_t ip4_ret_tos(const Packet *p)
-{
-   VALIDATE(p,1);
-
-   return p->ip4h->ip_tos;
-}
-
-uint16_t orig_ip4_ret_tos(const Packet *p)
-{
-   VALIDATE(p,1);
-
-    return 0;
-//  return p->orig_ip4h->ip_tos;
-}
-
-uint8_t ip4_ret_ttl(const Packet *p)
-{
-    VALIDATE(p,1);
-
-    return p->ip4h->ip_ttl;
-}
-
-uint8_t orig_ip4_ret_ttl(const Packet *p)
-{
-    VALIDATE(p,1);
-
-    return 0;
-//  return p->orig_ip4h->ip_ttl;
-}
-
-uint16_t ip4_ret_len(const Packet *p)
-{
-    VALIDATE(p,1);
-
-    return p->ip4h->ip_len;
-}
-
-uint16_t orig_ip4_ret_len(const Packet *p)
-{
-    VALIDATE(p,1);
-
-    return 0;
-//  return p->orig_ip4h->ip_len;
-}
-
-uint32_t ip4_ret_id(const Packet *p)
-{
-    VALIDATE(p,1);
-
-    return (uint32_t)p->ip4h->ip_id;
-}
-
-uint32_t orig_ip4_ret_id(const Packet *p)
-{
-    VALIDATE(p,1);
-
-    return 0;
-//  return (uint32_t)p->orig_ip4h->ip_id;
-}
-
-uint8_t ip4_ret_proto(const Packet *p)
-{
-    // VALIDATION()
-
-    return p->ip4h->ip_proto;
-}
-
-uint8_t orig_ip4_ret_proto(const Packet *p)
-{
-    // VALIDATION()
-
-    return 0;
-//  return p->orig_ip4h->ip_proto;
-}
-
-uint16_t ip4_ret_off(const Packet *p)
-{
-    return p->ip4h->ip_off;
-}
-
-uint16_t orig_ip4_ret_off(const Packet *p)
-{
-    return 0;
-//  return p->orig_ip4h->ip_off;
-}
-
-uint8_t ip4_ret_ver(const Packet *p)
-{
-    return (p->iph->ip_verhl & 0xf0) >> 4;
-}
-
-#if 0
-uint8_t orig_ip4_ret_ver(const Packet *p)
-{
-    return (p->orig_iph->ip_verhl & 0xf0) >> 4;
-}
-#endif
-
-uint8_t ip4_ret_hlen(const Packet *p)
-{
-    return p->iph->ip_verhl & 0x0f;
-}
-
-uint8_t orig_ip4_ret_hlen(const Packet *p)
-{
-    return 0;
-//    return p->orig_iph->ip_verhl & 0x0f;
-}
-
-uint8_t ip6_ret_hlen(const Packet*)
-{
-    /* Snort is expecting this number to be in terms of 32 bit words */
-    return IP6_HDR_LEN / 4 ;
-}
-
-uint8_t orig_ip6_ret_hlen(const Packet*)
-{
-    return IP6_HDR_LEN / 4;
-}
-
-#endif
-
-IPH_API ip4 =
-{
-#if 0
-   ip4_ret_src,
-   ip4_ret_dst,
-   ip4_ret_tos,
-   ip4_ret_ttl,
-   ip4_ret_len,
-   ip4_ret_id,
-   ip4_ret_proto,
-   ip4_ret_off,
-   ip4_ret_ver,
-   ip4_ret_hlen,
-   orig_ip4_ret_src,
-   orig_ip4_ret_dst,
-   orig_ip4_ret_tos,
-   orig_ip4_ret_ttl,
-   orig_ip4_ret_len,
-   orig_ip4_ret_id,
-   orig_ip4_ret_proto,
-   orig_ip4_ret_off,
-   orig_ip4_ret_ver,
-   orig_ip4_ret_hlen,
-#endif
-   IPH_API_V4
-};
-
-IPH_API ip6 =
-{
-#if 0
-   ip6_ret_src,
-   ip6_ret_dst,
-   ip6_ret_toc,
-   ip6_ret_hops,
-   ip6_ret_len,
-   ip6_ret_id,
-   ip6_ret_next,
-   ip6_ret_off,
-   ip6_ret_ver,
-   ip6_ret_hlen,
-   orig_ip6_ret_src,
-   orig_ip6_ret_dst,
-   orig_ip6_ret_toc,
-   orig_ip6_ret_hops,
-   orig_ip6_ret_len,
-   orig_ip6_ret_id,
-   orig_ip6_ret_next,
-   orig_ip6_ret_off,
-   orig_ip6_ret_ver,
-   orig_ip6_ret_hlen,
-#endif
-   IPH_API_V6
-};
-
-static inline void _set_callbacks(Packet* p, int family, char orig)
-{
-    if ( !orig )
-    {
-        if(family == AF_INET)
-            p->iph_api = &ip4;
-        else
-            p->iph_api = &ip6;
-
-        p->family = family;
-    }
-}
-
-void set_callbacks(Packet* p, int family, char orig)
-{
-    _set_callbacks(p, family, orig);
-}
-
-void sfiph_build(Packet *p, const void *hdr, int family)
-{
-    ipv6::IP6RawHdr *hdr6;
-    IPHdr *hdr4;
-
-    if(!p || !hdr)
-        return;
-
-    /* If family is already set, we've been here before.
-     * That means this is a nested IP.  */
-#if 0
-    if (p->family != NO_IP)
-    {
-        if (p->iph_api->ver == IPH_API_V4)
-            memcpy(&p->outer_ip4h, &p->inner_ip4h, sizeof(IP4Hdr));
-        else if (p->iph_api->ver == IPH_API_V6)
-            memcpy(&p->outer_ip6h, &p->inner_ip6h, sizeof(IP6Hdr));
-
-    }
-#endif
-    _set_callbacks(p, family, CALLBACK_IP);
-
-#if 0
-
-    if(family == AF_INET)
-    {
-        hdr4 = (IPHdr*)hdr;
-
-        /* The struct Snort uses is identical to the actual IP6 struct,
-         * with the exception of the IP addresses. Copy over everything but
-         * the IPs */
-        memcpy(&p->inner_ip4h, hdr4, sizeof(IPHdr) - 8);
-        sfip_set_raw(&p->inner_ip4h.ip_src, &hdr4->ip_src, family);
-        sfip_set_raw(&p->inner_ip4h.ip_dst, &hdr4->ip_dst, family);
-//        p->actual_ip_len = ntohs(p->inner_ip4h.ip_len);
-        p->ip4h = &p->inner_ip4h;
-    }
-    else
-    {
-        hdr6 = (ipv6::IP6RawHdr*)hdr;
-
-        /* The struct Snort uses is identical to the actual IP6 struct,
-         * with the exception of the IP addresses. Copy over everything but
-         * the IPs*/
-        memcpy(&p->inner_ip6h, hdr6, sizeof(ipv6::IP6RawHdr) - 32);
-        sfip_set_raw(&p->inner_ip6h.ip_src, &hdr6->ip6_src, family);
-        sfip_set_raw(&p->inner_ip6h.ip_dst, &hdr6->ip6_dst, family);
-//        p->actual_ip_len = ntohs(p->inner_ip6h.len) + IP6_HDR_LEN;
-        p->ip6h = &p->inner_ip6h;
-    }
-#endif
-}
-
-void sfiph_orig_build(Packet *p, const void *hdr, int family)
-{
-#if 0
-    ipv6::IP6RawHdr *hdr6;
-    IPHdr *hdr4;
-
-    if(!p || !hdr)
-        return;
-
-    /* If iph_api is already set, we've been here before.
-     * That means this is a nested IP.  */
-    if (p->orig_iph_api && (p->orig_iph_api->ver == IPH_API_V4))
-        memcpy(&p->outer_orig_ip4h, &p->inner_orig_ip4h, sizeof(IP4Hdr));
-
-    else if (p->orig_iph_api && (p->orig_iph_api->ver == IPH_API_V6))
-        memcpy(&p->outer_orig_ip6h, &p->inner_orig_ip6h, sizeof(IP6Hdr));
-
-
-    _set_callbacks(p, family, CALLBACK_ICMP_ORIG);
-
-    if(family == AF_INET)
-    {
-        hdr4 = (IPHdr*)hdr;
-
-        /* The struct Snort uses is identical to the actual IP6 struct,
-         * with the exception of the IP addresses. Copy over everything but
-         * the IPs */
-        memcpy(&p->inner_orig_ip4h, hdr4, sizeof(IPHdr) - 8);
-        sfip_set_raw(&p->inner_orig_ip4h.ip_src, &hdr4->ip_src, family);
-        sfip_set_raw(&p->inner_orig_ip4h.ip_dst, &hdr4->ip_dst, family);
-        p->actual_ip_len = ntohs(p->inner_orig_ip4h.ip_len);
-        p->orig_ip4h = &p->inner_orig_ip4h;
-    }
-    else
-    {
-        hdr6 = (ipv6::IP6RawHdr*)hdr;
-
-        /* The struct Snort uses is identical to the actual IP6 struct,
-         * with the exception of the IP addresses. Copy over everything but
-         * the IPs*/
-        memcpy(&p->inner_orig_ip6h, hdr6, sizeof(ipv6::IP6RawHdr) - 32);
-        sfip_set_raw(&p->inner_orig_ip6h.ip_src, &hdr6->ip6_src, family);
-        sfip_set_raw(&p->inner_orig_ip6h.ip_dst, &hdr6->ip6_dst, family);
-        p->actual_ip_len = ntohs(p->inner_orig_ip6h.len) + IP6_HDR_LEN;
-        p->orig_ip6h = &p->inner_orig_ip6h;
-    }
-  #endif
-}
-
-#ifdef TESTER
-int main()
-{
-    Packet p;
-    IP4Hdr i4;
-    IP6Hdr i6;
-
-    /* This test assumes we get an IPv4 packet and verifies
-     * that the correct callbacks are setup, and they return
-     * the correct values. */
-
-    _set_callbacks(&p, AF_INET, CALLBACK_IP);
-
-    /* Same test as above, but with IPv6 */
-    _set_callbacks(&p, AF_INET6, CALLBACK_IP);
-
-    return 0;
-}
-#endif
diff --git a/src/sfip/sf_iph.h b/src/sfip/sf_iph.h
deleted file mode 100644 (file)
index 6bbdb1a..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*  
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
-** Copyright (C) 2007-2013 Sourcefire, Inc.
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License Version 2 as
-** published by the Free Software Foundation.  You may not use, modify or
-** distribute this program under any other version of the GNU General
-** Public License.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if nto, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-** USA
-*/
-
-#ifndef SF_IPH_H
-#define SF_IPH_H
-
-#include "sfip_t.h"
-
-struct Packet;
-
-typedef struct _IPH_API
-{
-#if 0
-    sfip_t *   (*iph_ret_src)(const Packet*);
-    sfip_t *   (*iph_ret_dst)(const Packet*);
-    uint16_t   (*iph_ret_tos)(const Packet*);
-    uint8_t    (*iph_ret_ttl)(const Packet*);
-    uint16_t   (*iph_ret_len)(const Packet*);
-    uint32_t   (*iph_ret_id)(const Packet*);
-    uint8_t    (*iph_ret_proto)(const Packet*);
-    uint16_t   (*iph_ret_off)(const Packet*);
-    uint8_t    (*iph_ret_ver)(const Packet*);
-    uint8_t    (*iph_ret_hlen)(const Packet*);
-
-    sfip_t *   (*orig_iph_ret_src)(const Packet*);
-    sfip_t *   (*orig_iph_ret_dst)(const Packet*);
-    uint16_t   (*orig_iph_ret_tos)(const Packet*);
-    uint8_t    (*orig_iph_ret_ttl)(const Packet*);
-    uint16_t   (*orig_iph_ret_len)(const Packet*);
-    uint32_t   (*orig_iph_ret_id)(const Packet*);
-    uint8_t    (*orig_iph_ret_proto)(const Packet*);
-    uint16_t   (*orig_iph_ret_off)(const Packet*);
-    uint8_t    (*orig_iph_ret_ver)(const Packet*);
-    uint8_t    (*orig_iph_ret_hlen)(const Packet*);
-#endif
-    char ver;
-} IPH_API;
-
-extern IPH_API ip4;
-extern IPH_API ip6;
-
-#define IPH_API_V4 4
-#define IPH_API_V6 6
-
-#define iph_is_valid(p) ((p)->family != NO_IP)
-#define NO_IP 0
-
-void sfiph_build(Packet*, const void *hdr, int family);
-
-/* Sets the callbacks to point at the family selected by
- *  * "family".  "family" is either AF_INET or AF_INET6 */
-#define CALLBACK_IP 0
-#define CALLBACK_ICMP_ORIG 1
-
-void set_callbacks(Packet*, int family, char orig);
-
-#endif
index f5fc2babfd861de53634ac06f547f55457c5e312..e3c8d5c0c71aebf4f123124ee7edf2784be3bb82 100644 (file)
  * 11/17/06
 */
 
-#ifndef SFIP_T_H
-#define SFIP_T_H
+#ifndef SFIP_SFIP_T_H
+#define SFIP_SFIP_T_H
 
+#include <cstddef>
 #include <stdint.h>
+#include <arpa/inet.h>
 
 #ifndef WIN32
 #include <netinet/in.h>
@@ -39,6 +41,7 @@
 #include <winsock2.h>
 #endif
 
+
 /* factored out for attribute table */
 
 struct sfip_t {
@@ -49,15 +52,11 @@ struct sfip_t {
      * must be the last field in this struct */
     union
     {
-        uint8_t  u6_addr8[16];
-        uint16_t u6_addr16[8];
-        uint32_t u6_addr32[4];
-/*      uint64_t    u6_addr64[2]; */
-    } ip;
-    #define ip8  ip.u6_addr8
-    #define ip16 ip.u6_addr16
-    #define ip32 ip.u6_addr32
-/*    #define ip64 ip.u6_addr64 */
+        uint8_t  ip8[16];
+        uint16_t ip16[8];
+        uint32_t ip32[4];
+/*      uint64_t    ip64[2]; */
+    };
 
     inline bool is_ip6() const
     { return family == AF_INET6; }
@@ -65,23 +64,80 @@ struct sfip_t {
     inline bool is_ip4() const
     { return family == AF_INET; }
 
+    // the '+ 4' is the int32_t IPv4 address
+    inline std::size_t sfip_size() const
+    { return is_ip6() ? sizeof(sfip_t) : offsetof(sfip_t, ip8) + 4; }
 
 };
 
-inline bool operator==(const sfip_t& lhs, const sfip_t& rhs)
+
+// because we can --- and this is leftover from Snort which we're stuck with
+#ifdef inet_ntoa
+#undef inet_ntoa
+#endif
+
+char *sfip_to_str(const sfip_t *ip);
+#define sfip_ntoa(x) sfip_to_str(x)
+#define inet_ntoa sfip_ntoa
+
+
+/*
+ * Implementing these functions rather than opeators since
+ * the Google style guide recomends staying away from
+ * operators.  Most of these are a copy and paste from sf_ip.h
+ */
+static inline int sfip_is_set(const sfip_t& ip);
+static inline int sfip_is_set(const sfip_t* const ip);
+static inline bool sfip_equals(const sfip_t& lhs, const sfip_t& rhs);
+static inline bool sfip_unset_equals(const sfip_t& lhs, const sfip_t& rhs);
+static inline bool sfip_not_equals(const sfip_t& lhs, const sfip_t& rhs);
+static inline bool sfip_lesser(const sfip_t* const lhs, const sfip_t* const rhs);
+static inline bool sfip_greater(const sfip_t* const lhs, const sfip_t* const rhs);
+static inline void sfip_clear(sfip_t& x);
+static inline void sfip_copy(sfip_t& lhs, const sfip_t* const rhs);
+
+
+
+/* Returns 1 if the IP is non-zero. 0 otherwise *
+ * XXX This is a performance critical function,
+ *  need to determine if it's safe to not check these pointers
+ *
+ * SNORT RELIC
+ */
+static inline int sfip_is_set(const sfip_t* const ip) {
+//    ARG_CHECK1(ip, -1);
+    return ip->ip32[0] ||
+            ( (ip->family == AF_INET6) &&
+              (ip->ip32[1] ||
+              ip->ip32[2] ||
+              ip->ip32[3] || ip->bits != 128)) || ((ip->family == AF_INET) && ip->bits != 32)  ;
+}
+
+static inline int sfip_is_set(const sfip_t& ip) {
+//    ARG_CHECK1(ip, -1);
+    return ip.ip32[0] ||
+            ( (ip.family == AF_INET6) &&
+              (ip.ip32[1] ||
+              ip.ip32[2] ||
+              ip.ip32[3] || ip.bits != 128)) || ((ip.family == AF_INET) && ip.bits != 32)  ;
+}
+
+
+
+static inline bool _is_sfip_equals(const sfip_t* const lhs, const sfip_t* const rhs)
 {
-    if (lhs.is_ip4())
+    if (lhs->is_ip4())
     {
-        return  (rhs.is_ip4()) &&
-                (lhs.ip.u6_addr32[0] == rhs.ip.u6_addr32[0]);
+        return  (rhs->is_ip4()) &&
+                (lhs->ip32[0] == rhs->ip32[0]);
     }
-    else if (lhs.is_ip6())
+    else if (lhs->is_ip6())
     {
-        return  (rhs.is_ip6()) &&
-                (lhs.ip.u6_addr32[0] == rhs.ip.u6_addr32[0]) &&
-                (lhs.ip.u6_addr32[1] == rhs.ip.u6_addr32[1]) &&
-                (lhs.ip.u6_addr32[2] == rhs.ip.u6_addr32[2]) &&
-                (lhs.ip.u6_addr32[3] == rhs.ip.u6_addr32[3]);
+        return  (rhs->is_ip6()) &&
+                (lhs->ip32[0] == rhs->ip32[0]) &&
+                (lhs->ip32[1] == rhs->ip32[1]) &&
+                (lhs->ip32[2] == rhs->ip32[2]) &&
+                (lhs->ip32[3] == rhs->ip32[3]);
     }
     else
     {
@@ -89,9 +145,88 @@ inline bool operator==(const sfip_t& lhs, const sfip_t& rhs)
     }
 }
 
-inline bool operator!=(const sfip_t& lhs, const sfip_t& rhs)
-{ return !(lhs == rhs); }
 
+static inline bool _is_sfip_lesser(const sfip_t* const lhs, const sfip_t* const rhs)
+{
+    if (lhs->is_ip4())
+    {
+        return (rhs->is_ip4() &&
+               (htonl(lhs->ip32[0]) < htonl(rhs->ip32[0])));
+    }
+    else if (lhs->is_ip6())
+    {
+        return (rhs->is_ip6() &&
+               (htonl(lhs->ip32[0]) < htonl(rhs->ip32[0])) &&
+               (htonl(lhs->ip32[1]) < htonl(rhs->ip32[1])) &&
+               (htonl(lhs->ip32[2]) < htonl(rhs->ip32[2])) &&
+               (htonl(lhs->ip32[3]) < htonl(rhs->ip32[3])));
+    }
+    else
+    {
+        return false;
+    }
+}
+
+
+static inline bool sfip_equals(const sfip_t* const lhs, const sfip_t* const rhs)
+{
+    if(!sfip_is_set(lhs) || !sfip_is_set(rhs))
+        return true;
+
+    return _is_sfip_equals(lhs, rhs);
+}
+
+
+static inline bool sfip_not_equals(const sfip_t* const lhs, const sfip_t* const rhs)
+{ return !sfip_equals(lhs,rhs); }
+
+
+static inline bool sfip_unset_equals(const sfip_t* const lhs, const sfip_t* const rhs)
+{
+    if(!sfip_is_set(lhs) || !sfip_is_set(rhs))
+        return false;
+
+    return _is_sfip_equals(lhs, rhs);
+}
+
+
+static inline bool sfip_lesser(const sfip_t* const lhs, const sfip_t* const rhs)
+{
+    // I'm copying and pasting.  Don't ask me why this is different then sfip_equals
+    if(!sfip_is_set(lhs) || !sfip_is_set(rhs))
+        return false;
+
+    return _is_sfip_lesser(lhs, rhs);
+}
+
+
+static inline bool sfip_greater(const sfip_t* const lhs, const sfip_t* const rhs)
+{
+    // I'm copying and pasting.  Don't ask me why this is different then sfip_equals
+    if(!sfip_is_set(lhs) || !sfip_is_set(rhs))
+        return false;
+
+    return _is_sfip_lesser(rhs, lhs);
+}
+
+
+static inline void sfip_clear(sfip_t& x)
+{
+    x.family = 0;
+    x.bits = 0;
+    x.ip32[0] = 0;
+    x.ip32[1] = 0;
+    x.ip32[2] = 0;
+    x.ip32[3] = 0;
+}
+
+/*
+ * This is the former macro IP_COPY_VALUE(x, y).  No need to assign
+ * specific operator since the default equals operator will
+ * correctly assign values
+ */
+static inline void sfip_copy(sfip_t& lhs, const sfip_t* const rhs)
+{ lhs = *rhs; }
 
 #endif
 
index 0660a1e4ff8b7201dc51b995735625c4c4f3ab29..e8ebf43b9d05b29ea1f826fced4fed4efe8fbdce 100644 (file)
@@ -122,7 +122,7 @@ static int ProcessIcmpUnreach(Packet *p)
         COPY4(skey.ip_h, dst->ip32);
         skey.port_h = dport;
     }
-    else if (IP_EQUALITY(iph.get_src(), iph.get_dst()))
+    else if (sfip_equals(iph.get_src(), iph.get_dst()))
     {
         COPY4(skey.ip_l, src->ip32);
         COPY4(skey.ip_h, skey.ip_l);
@@ -225,7 +225,7 @@ int IcmpSession::process(Packet* p)
 
 void IcmpSession::update_direction(char dir, const sfip_t *ip, uint16_t)
 {
-    if (IP_EQUALITY(&icmp_sender_ip, ip))
+    if (sfip_equals(&icmp_sender_ip, ip))
     {
         if ((dir == SSN_DIR_SENDER) && (flow->s5_state.direction == SSN_DIR_SENDER))
         {
@@ -233,7 +233,7 @@ void IcmpSession::update_direction(char dir, const sfip_t *ip, uint16_t)
             return;
         }
     }
-    else if (IP_EQUALITY(&icmp_responder_ip, ip))
+    else if (sfip_equals(&icmp_responder_ip, ip))
     {
         if ((dir == SSN_DIR_RESPONDER) && (flow->s5_state.direction == SSN_DIR_RESPONDER))
         {
index f756ccad8d7c8d9691fb42a915cbda4cd31d01d4..006a518827bd30fdafdad109d3f626c3d3dbb9fe 100644 (file)
@@ -130,8 +130,8 @@ bool IpSession::setup (Packet* p)
 
     ipStats.sessions++;
 
-    IP_COPY_VALUE(flow->client_ip, p->ip_api.get_src());
-    IP_COPY_VALUE(flow->server_ip, p->ip_api.get_dst());
+    sfip_copy(flow->client_ip, p->ip_api.get_src());
+    sfip_copy(flow->server_ip, p->ip_api.get_dst());
 
 #ifdef ENABLE_EXPECTED_IP
     if ( flow_con->expected_session(flow, p))
index 612d58ac0c048aae22bf6207fa128a0ae96d1bb4..db1f22bf04f19537830f0c0d4c94acc45d3f5d09 100644 (file)
@@ -456,7 +456,7 @@ int16_t Stream::get_application_protocol_id(Flow* flow)
         set_ip_protocol(flow);
     }
 
-    host_entry = SFAT_LookupHostEntryByIP(IP_ARG(flow->server_ip));
+    host_entry = SFAT_LookupHostEntryByIP(&flow->server_ip);
     if (host_entry)
     {
         set_application_protocol_id_from_host_entry(flow, host_entry, SSN_DIR_SERVER);
@@ -467,7 +467,7 @@ int16_t Stream::get_application_protocol_id(Flow* flow)
         }
     }
 
-    host_entry = SFAT_LookupHostEntryByIP(IP_ARG(flow->client_ip));
+    host_entry = SFAT_LookupHostEntryByIP(&flow->client_ip);
 
     if (host_entry)
     {
@@ -501,7 +501,7 @@ int16_t Stream::set_application_protocol_id(Flow* flow, int16_t id)
         set_ip_protocol(flow);
 
     SFAT_UpdateApplicationProtocol(
-        IP_ARG(flow->server_ip), ntohs(flow->server_port),
+        &flow->server_ip, ntohs(flow->server_port),
         flow->s5_state.ipprotocol, id);
 
     return id;
index 6efd79b1ef203106e239c60219e8e6004dbb338a..1e393144fd0f31f538a3ddd76258c9dc420e25e2 100644 (file)
@@ -78,7 +78,6 @@
 #include "flow/session.h"
 #include "profiler.h"
 #include "ipv6_port.h"
-#include "sf_iph.h"
 #include "fpdetect.h"
 #include "detection_util.h"
 #include "file_api/file_api.h"
@@ -553,7 +552,7 @@ void Stream5UpdatePerfBaseState(SFBASE *sf_base,
             sf_base->iSessionsEstablished++;
 
             if (perfmon_config && (perfmon_config->perf_flags & SFPERF_FLOWIP))
-                UpdateFlowIPState(&sfFlow, IP_ARG(lwssn->client_ip), IP_ARG(lwssn->server_ip), SFS_STATE_TCP_ESTABLISHED);
+                UpdateFlowIPState(&sfFlow, &lwssn->client_ip, &lwssn->server_ip, SFS_STATE_TCP_ESTABLISHED);
 
             lwssn->s5_state.session_flags |= SSNFLAG_COUNTED_ESTABLISH;
 
@@ -576,7 +575,7 @@ void Stream5UpdatePerfBaseState(SFBASE *sf_base,
                 sf_base->iSessionsEstablished--;
 
                 if (perfmon_config && (perfmon_config->perf_flags & SFPERF_FLOWIP))
-                    UpdateFlowIPState(&sfFlow, IP_ARG(lwssn->client_ip), IP_ARG(lwssn->server_ip), SFS_STATE_TCP_CLOSED);
+                    UpdateFlowIPState(&sfFlow, &lwssn->client_ip, &lwssn->server_ip, SFS_STATE_TCP_CLOSED);
             }
             else if (lwssn->s5_state.session_flags & SSNFLAG_COUNTED_INITIALIZE)
             {
@@ -597,7 +596,7 @@ void Stream5UpdatePerfBaseState(SFBASE *sf_base,
             sf_base->iSessionsEstablished--;
 
             if (perfmon_config && (perfmon_config->perf_flags & SFPERF_FLOWIP))
-                UpdateFlowIPState(&sfFlow, IP_ARG(lwssn->client_ip), IP_ARG(lwssn->server_ip), SFS_STATE_TCP_CLOSED);
+                UpdateFlowIPState(&sfFlow, &lwssn->client_ip, &lwssn->server_ip, SFS_STATE_TCP_CLOSED);
         }
         else if (lwssn->s5_state.session_flags & SSNFLAG_COUNTED_INITIALIZE)
         {
@@ -4727,9 +4726,9 @@ static int ProcessTcp(
                     "session direction.\n"););
             /* SYN packet from client */
             lwssn->s5_state.direction = FROM_CLIENT;
-            IP_COPY_VALUE(lwssn->client_ip, p->ip_api.get_src());
+            sfip_copy(lwssn->client_ip, p->ip_api.get_src());
             lwssn->client_port = p->tcph->th_sport;
-            IP_COPY_VALUE(lwssn->server_ip, p->ip_api.get_dst());
+            sfip_copy(lwssn->server_ip, p->ip_api.get_dst());
             lwssn->server_port = p->tcph->th_dport;
             lwssn->session_state |= STREAM5_STATE_SYN;
 
@@ -4762,9 +4761,9 @@ static int ProcessTcp(
                         "Stream5 SYN|ACK PACKET, establishing lightweight"
                         "session direction.\n"););
                 lwssn->s5_state.direction = FROM_SERVER;
-                IP_COPY_VALUE(lwssn->client_ip, p->ip_api.get_dst());
+                sfip_copy(lwssn->client_ip, p->ip_api.get_dst());
                 lwssn->client_port = p->tcph->th_dport;
-                IP_COPY_VALUE(lwssn->server_ip, p->ip_api.get_src());
+                sfip_copy(lwssn->server_ip, p->ip_api.get_src());
                 lwssn->server_port = p->tcph->th_sport;
             }
             lwssn->session_state |= STREAM5_STATE_SYN_ACK;
@@ -4797,17 +4796,17 @@ static int ProcessTcp(
             if (p->sp > p->dp)
             {
                 lwssn->s5_state.direction = FROM_CLIENT;
-                IP_COPY_VALUE(lwssn->client_ip, p->ip_api.get_src());
+                sfip_copy(lwssn->client_ip, p->ip_api.get_src());
                 lwssn->client_port = p->tcph->th_sport;
-                IP_COPY_VALUE(lwssn->server_ip, p->ip_api.get_dst());
+                sfip_copy(lwssn->server_ip, p->ip_api.get_dst());
                 lwssn->server_port = p->tcph->th_dport;
             }
             else
             {
                 lwssn->s5_state.direction = FROM_SERVER;
-                IP_COPY_VALUE(lwssn->client_ip, p->ip_api.get_dst());
+                sfip_copy(lwssn->client_ip, p->ip_api.get_dst());
                 lwssn->client_port = p->tcph->th_dport;
-                IP_COPY_VALUE(lwssn->server_ip, p->ip_api.get_src());
+                sfip_copy(lwssn->server_ip, p->ip_api.get_src());
                 lwssn->server_port = p->tcph->th_sport;
             }
             lwssn->session_state |= STREAM5_STATE_MIDSTREAM;
@@ -4962,9 +4961,9 @@ static int ProcessTcp(
                      !TCP_ISFLAGSET(p->tcph, TH_ACK))
             {
                 lwssn->s5_state.direction = FROM_CLIENT;
-                IP_COPY_VALUE(lwssn->client_ip, p->ip_api.get_src());
+                sfip_copy(lwssn->client_ip, p->ip_api.get_src());
                 lwssn->client_port = p->tcph->th_sport;
-                IP_COPY_VALUE(lwssn->server_ip, p->ip_api.get_dst());
+                sfip_copy(lwssn->server_ip, p->ip_api.get_dst());
                 lwssn->server_port = p->tcph->th_dport;
                 lwssn->session_state = STREAM5_STATE_SYN;
                 lwssn->set_ttl(p, true);
@@ -4981,9 +4980,9 @@ static int ProcessTcp(
             else if (TCP_ISFLAGSET(p->tcph, (TH_SYN|TH_ACK)))
             {
                 lwssn->s5_state.direction = FROM_SERVER;
-                IP_COPY_VALUE(lwssn->client_ip, p->ip_api.get_dst());
+                sfip_copy(lwssn->client_ip, p->ip_api.get_dst());
                 lwssn->client_port = p->tcph->th_dport;
-                IP_COPY_VALUE(lwssn->server_ip, p->ip_api.get_src());
+                sfip_copy(lwssn->server_ip, p->ip_api.get_src());
                 lwssn->server_port = p->tcph->th_sport;
                 lwssn->session_state = STREAM5_STATE_SYN_ACK;
                 lwssn->set_ttl(p, false);
@@ -6203,7 +6202,7 @@ int GetTcpRebuiltPackets(Packet *p, Flow *ssn,
 
     /* StreamTracker is the opposite of the ip of the reassembled
      * packet --> it came out the queue for the other side */
-    if (IP_EQUALITY(p->ip_api.get_src(), &tcpssn->tcp_client_ip))
+    if (sfip_equals(p->ip_api.get_src(), &tcpssn->tcp_client_ip))
     {
         st = &tcpssn->server;
     }
@@ -6251,7 +6250,7 @@ int GetTcpStreamSegments(Packet *p, Flow *ssn,
 
     /* StreamTracker is the opposite of the ip of the reassembled
      * packet --> it came out the queue for the other side */
-    if (IP_EQUALITY(p->ip_api.get_src(), &tcpssn->tcp_client_ip))
+    if (sfip_equals(p->ip_api.get_src(), &tcpssn->tcp_client_ip))
         st = &tcpssn->server;
     else
         st = &tcpssn->client;
@@ -6290,7 +6289,7 @@ int Stream5AddSessionAlertTcp(
     Stream5AlertInfo* ai;
     TcpSession *tcpssn = (TcpSession*)lwssn->session;
 
-    if (IP_EQUALITY(p->ip_api.get_src(),&tcpssn->tcp_client_ip))
+    if (sfip_equals(p->ip_api.get_src(),&tcpssn->tcp_client_ip))
     {
         st = &tcpssn->server;
     }
@@ -6328,7 +6327,7 @@ int Stream5CheckSessionAlertTcp(Flow *lwssn, Packet *p, uint32_t gid, uint32_t s
         return 0;
     }
 
-    if (IP_EQUALITY(p->ip_api.get_src(), &tcpssn->tcp_client_ip))
+    if (sfip_equals(p->ip_api.get_src(), &tcpssn->tcp_client_ip))
     {
         st = &tcpssn->server;
     }
@@ -6362,7 +6361,7 @@ int Stream5UpdateSessionAlertTcp (
     uint32_t seq_num;
     TcpSession *tcpssn = (TcpSession*)lwssn->session;
 
-    if (IP_EQUALITY(p->ip_api.get_src(), &tcpssn->tcp_client_ip))
+    if (sfip_equals(p->ip_api.get_src(), &tcpssn->tcp_client_ip))
     {
         st = &tcpssn->server;
     }
@@ -6397,7 +6396,7 @@ void Stream5SetExtraDataTcp (Flow* lwssn, Packet* p, uint32_t xid)
     StreamTracker *st;
     TcpSession *tcpssn = (TcpSession*)lwssn->session;
 
-    if (IP_EQUALITY(p->ip_api.get_src(),&tcpssn->tcp_client_ip))
+    if (sfip_equals(p->ip_api.get_src(),&tcpssn->tcp_client_ip))
         st = &tcpssn->server;
     else
         st = &tcpssn->client;
@@ -6410,7 +6409,7 @@ void Stream5ClearExtraDataTcp (Flow* lwssn, Packet* p, uint32_t xid)
     StreamTracker *st;
     TcpSession *tcpssn = (TcpSession*)lwssn->session;
 
-    if (IP_EQUALITY(p->ip_api.get_src(),&tcpssn->tcp_client_ip))
+    if (sfip_equals(p->ip_api.get_src(),&tcpssn->tcp_client_ip))
         st = &tcpssn->server;
     else
         st = &tcpssn->client;
@@ -6643,7 +6642,7 @@ void TcpSession::update_direction(
     uint16_t tmpPort;
     StreamTracker tmpTracker;
 
-    if (IP_EQUALITY(&tcp_client_ip, ip) && (tcp_client_port == port))
+    if (sfip_equals(&tcp_client_ip, ip) && (tcp_client_port == port))
     {
         if ((dir == SSN_DIR_CLIENT) && (flow->s5_state.direction == SSN_DIR_CLIENT))
         {
@@ -6651,7 +6650,7 @@ void TcpSession::update_direction(
             return;
         }
     }
-    else if (IP_EQUALITY(&tcp_server_ip, ip) && (tcp_server_port == port))
+    else if (sfip_equals(&tcp_server_ip, ip) && (tcp_server_port == port))
     {
         if ((dir == SSN_DIR_SERVER) && (flow->s5_state.direction == SSN_DIR_SERVER))
         {
index 9ac72787239d728bddeda1718204ff3e393749da..866ca59815e7e3252c76b654ec05cab299b4fc57 100644 (file)
@@ -152,13 +152,13 @@ bool UdpSession::setup(Packet* p)
     AddUDPSession(&sfBase);
 
     if (perfmon_config && (perfmon_config->perf_flags & SFPERF_FLOWIP))
-        UpdateFlowIPState(&sfFlow, IP_ARG(flow->client_ip),
-            IP_ARG(flow->server_ip), SFS_STATE_UDP_CREATED);
+        UpdateFlowIPState(&sfFlow, &flow->client_ip,
+            &flow->server_ip, SFS_STATE_UDP_CREATED);
 
     flow->s5_state.direction = FROM_SENDER;
-    IP_COPY_VALUE(flow->client_ip, p->ip_api.get_src());
+    sfip_copy(flow->client_ip, p->ip_api.get_src());
     flow->client_port = p->udph->uh_sport;
-    IP_COPY_VALUE(flow->server_ip, p->ip_api.get_dst());
+    sfip_copy(flow->server_ip, p->ip_api.get_dst());
     flow->server_port = p->udph->uh_dport;
 
     if ( flow_con->expected_flow(flow, p) )
@@ -179,7 +179,7 @@ void UdpSession::update_direction(
     sfip_t tmpIp;
     uint16_t tmpPort;
 
-    if (IP_EQUALITY(&udp_sender_ip, ip) && (udp_sender_port == port))
+    if (sfip_equals(&udp_sender_ip, ip) && (udp_sender_port == port))
     {
         if ((dir == SSN_DIR_SENDER) && (flow->s5_state.direction == SSN_DIR_SENDER))
         {
@@ -187,7 +187,7 @@ void UdpSession::update_direction(
             return;
         }
     }
-    else if (IP_EQUALITY(&udp_responder_ip, ip) && (udp_responder_port == port))
+    else if (sfip_equals(&udp_responder_ip, ip) && (udp_responder_port == port))
     {
         if ((dir == SSN_DIR_RESPONDER) && (flow->s5_state.direction == SSN_DIR_RESPONDER))
         {
index 6aa1b3b8f08237ed87e4c877139192204235539c..e3e28c162e6af42e66fcdae4ba5709602b70c22b 100644 (file)
@@ -376,7 +376,7 @@ HostAttributeEntry *SFAT_LookupHostEntryByIP(const sfip_t *ipAddr)
 
 HostAttributeEntry *SFAT_LookupHostEntryBySrc(Packet *p)
 {
-    if (!p || !p->iph_api)
+    if (!p || !p->ip_api.is_valid())
         return NULL;
 
     return SFAT_LookupHostEntryByIP(p->ip_api.get_src());
@@ -384,7 +384,7 @@ HostAttributeEntry *SFAT_LookupHostEntryBySrc(Packet *p)
 
 HostAttributeEntry *SFAT_LookupHostEntryByDst(Packet *p)
 {
-    if (!p || !p->iph_api)
+    if (!p || !p->ip_api.is_valid())
         return NULL;
 
     return SFAT_LookupHostEntryByIP(p->ip_api.get_dst());
index 03faf592d6e3647a55156786ff8ddfd226d468c1..0430a46fe9b51005f813c545b3a83981df668089 100644 (file)
@@ -951,7 +951,7 @@ static int EventTest (EventData* p) {
     sfip_pton(p->dip, &dip);
 
     status = SFRF_TestThreshold(
-        &rfc, p->gid, p->sid, IP_ARG(sip), IP_ARG(dip), curtime, op);
+        &rfc, p->gid, p->sid, &sip, &dip, curtime, op);
 
     if ( status >= RULE_TYPE__MAX ) status -= RULE_TYPE__MAX;
 
index 5ba680f72f381b6fcf0abb18a521708118a9e947..00d69e9351ddbfd6843c73c5bc7720156034f8f6 100644 (file)
@@ -804,12 +804,12 @@ static int EventTest (EventData* p, void* rule) {
     if ( rule )
     {
         status = sfthd_test_rule(
-            dThd, (THD_NODE *)rule, IP_ARG(sip), IP_ARG(dip), curtime);
+            dThd, (THD_NODE *)rule, &sip, &dip, curtime);
     }
     else
     {
         status = sfthd_test_threshold(
-            pThdObjs, pThd, p->gid, p->sid, IP_ARG(sip), IP_ARG(dip), curtime);
+            pThdObjs, pThd, p->gid, p->sid, &sip, &dip, curtime);
     }
 
     return status;
index 2c63771b92031161498cab9cbb0e05f9524a1fcb..9f1a181f77fb3f9a2a98e6f7e86c9dd49f92e90f 100644 (file)
@@ -374,12 +374,12 @@ void ppm_pkt_log(ppm_cfg_t *ppm_cfg, Packet* p)
         else
         {
             sfip_t cleared;
-            IP_CLEAR(cleared);
+            sfip_clear(cleared);
 
             filterEvent = sfthreshold_test(
                         potn->sigInfo.generator,
                         potn->sigInfo.id,
-                        IP_ARG(cleared), IP_ARG(cleared),
+                        &cleared, &cleared,
                         p->pkth->ts.tv_sec);
         }
 
@@ -452,12 +452,12 @@ void ppm_rule_log(ppm_cfg_t *ppm_cfg, uint64_t pktcnt, Packet *p)
                 else
                 {
                     sfip_t cleared;
-                    IP_CLEAR(cleared);
+                    sfip_clear(cleared);
 
                     filterEvent = sfthreshold_test(
                                 otn->sigInfo.generator,
                                 otn->sigInfo.id,
-                                IP_ARG(cleared), IP_ARG(cleared),
+                                &cleared, &cleared,
                                 p->pkth->ts.tv_sec);
                 }
 
@@ -506,12 +506,12 @@ void ppm_rule_log(ppm_cfg_t *ppm_cfg, uint64_t pktcnt, Packet *p)
                 else
                 {
                     sfip_t cleared;
-                    IP_CLEAR(cleared);
+                    sfip_clear(cleared);
 
                     filterEvent = sfthreshold_test(
                                 otn->sigInfo.generator,
                                 otn->sigInfo.id,
-                                IP_ARG(cleared), IP_ARG(cleared),
+                                &cleared, &cleared,
                                 p->pkth->ts.tv_sec);
                 }