]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
eliminate #define IpAddrSet sfip_var_t and related
authorRuss Combs <rucombs@cisco.com>
Fri, 2 May 2014 20:52:16 +0000 (16:52 -0400)
committerRuss Combs <rucombs@cisco.com>
Fri, 2 May 2014 20:52:16 +0000 (16:52 -0400)
24 files changed:
src/codecs/basic/cd_tcp.cc
src/detection/detect.cc
src/detection/treenodes.h
src/filters/sfrf.cc
src/filters/sfrf.h
src/filters/sfthd.cc
src/filters/sfthd.h
src/main.cc
src/main/modules.cc
src/main/policy.h
src/network_inspectors/perf_monitor/perf_base.cc
src/network_inspectors/stream5/stream_api.cc
src/network_inspectors/stream5/stream_common.h
src/network_inspectors/stream5/stream_tcp.cc
src/parser/CMakeLists.txt
src/parser/Makefile.am
src/parser/parse_ip.cc [moved from src/parser/ip_addr_set.cc with 78% similarity]
src/parser/parse_ip.h [moved from src/parser/ip_addr_set.h with 78% similarity]
src/parser/parse_rule.cc
src/parser/vars.cc
src/sfip/ipv6_port.h
src/sfip/sf_ip.cc
src/test/sfrf_test.cc
src/test/sfthd_test.cc

index 940bc95df927d660980d4c402f7c6a031f372064..184bb0cd9d9fbff84e44b6f52f7bc1518eb003d2 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "codecs/decode_module.h"
 #include "packet_io/sfdaq.h"
-#include "sfip/ipv6_port.h" /* #define IpAddrSet */
+#include "parser/parse_ip.h"
 #include "events/codec_events.h"
 
 #include "snort.h"
@@ -67,7 +67,7 @@ public:
     virtual inline PROTO_ID get_proto_id() { return PROTO_TCP; };
 };
 
-static IpAddrSet *SynToMulticastDstIp = NULL;
+static sfip_var_t *SynToMulticastDstIp = NULL;
 
 } // namespace
 
@@ -248,7 +248,7 @@ bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
             }
         }
 
-        if( IpAddrSetContains(SynToMulticastDstIp, GET_DST_ADDR(p)) )
+        if( sfvar_ip_in(SynToMulticastDstIp, GET_DST_ADDR(p)) )
         {
             codec_events::decoder_event(p, DECODE_SYN_TO_MULTICAST);
         }
@@ -1008,7 +1008,8 @@ static inline unsigned short in_chksum_tcp6(pseudoheader6 *ph,
 
 static void tcp_codec_ginit()
 {
-    SynToMulticastDstIp = IpAddrSetParse(snort_conf, "[232.0.0.0/8,233.0.0.0/8,239.0.0.0/8]");
+    SynToMulticastDstIp = sfip_var_from_string(
+        "[232.0.0.0/8,233.0.0.0/8,239.0.0.0/8]");
 
     if( SynToMulticastDstIp == NULL )
         FatalError("Could not initialize SynToMulticastDstIp\n");
@@ -1020,7 +1021,7 @@ static void tcp_codec_ginit()
 static void tcp_codec_gterm()
 {
     if( SynToMulticastDstIp )
-        IpAddrSetDestroy(SynToMulticastDstIp);
+        sfvar_free(SynToMulticastDstIp);
 }
 
 
index 11c6a6527dae32d6d24ac3145f543f25139268db..34ee118a38fa52df41a4394c6508f22e2daa4a87 100644 (file)
@@ -505,43 +505,6 @@ bail:
 
 }
 
-/****************************************************************************
- *
- * Function: DumpList(IpAddrNode*)
- *
- * Purpose: print out the chain lists by header block node group
- *
- * Arguments: node => the head node
- *
- * Returns: void function
- *
- ***************************************************************************/
-void DumpList(IpAddrNode *idx, int negated)
-{
-    DEBUG_WRAP(int i=0;);
-    if(!idx)
-        return;
-
-    while(idx != NULL)
-    {
-       DEBUG_WRAP(DebugMessage(DEBUG_RULES,
-                        "[%d]    %s",
-                        i++, sfip_ntoa(idx->ip)););
-
-       if(negated)
-       {
-           DEBUG_WRAP(DebugMessage(DEBUG_RULES,
-                       "    (EXCEPTION_FLAG Active)\n"););
-       }
-       else
-       {
-           DEBUG_WRAP(DebugMessage(DEBUG_RULES, "\n"););
-       }
-
-       idx = idx->next;
-    }
-}
-
 #define CHECK_ADDR_SRC_ARGS(x) (x)->src_portobject
 #define CHECK_ADDR_DST_ARGS(x) (x)->dst_portobject
 
index e1fd12cc06e15fa56e925ac2cc9efb40fd95b440..2c02ecc56917fdc3dd7fa4a0e0f978e6bfd1e3e5 100644 (file)
@@ -134,8 +134,8 @@ struct RuleTreeNode
 {
     RuleFpList *rule_func; /* match functions.. (Bidirectional etc.. ) */
 
-    IpAddrSet *sip;
-    IpAddrSet *dip;
+    sfip_var_t *sip;
+    sfip_var_t *dip;
 
     PortObject * src_portobject;
     PortObject * dst_portobject;
index 2e4f3f8bfcd0945365f24f1ff49efedf10c7a92a..6b64a74724a380c05112905de656ccd76b4b0fdf 100644 (file)
@@ -42,7 +42,7 @@
 #include <arpa/inet.h>
 
 #include "snort.h"
-#include "parser/ip_addr_set.h"
+#include "sfip/ipv6_port.h"
 #include "generators.h"
 #include "rules.h"
 #include "treenodes.h"
@@ -193,7 +193,7 @@ static void SFRF_ConfigNodeFree(void *item)
 
     if (node->applyTo != NULL)
     {
-        IpAddrSetDestroy(node->applyTo);
+        sfvar_free(node->applyTo);
     }
 
     free(node);
@@ -451,7 +451,7 @@ static int SFRF_TestObject(
 
 static inline int SFRF_AppliesTo(tSFRFConfigNode* pCfg, snort_ip_p ip)
 {
-    return ( !pCfg->applyTo || IpAddrSetContains(pCfg->applyTo, ip) );
+    return ( !pCfg->applyTo || sfvar_ip_in(pCfg->applyTo, ip) );
 }
 
 /* Test a an event against the threshold database. Events without thresholding
index 7ceef1e0be205bbfb668956d0d940801cb0d4e4d..0cb438d32fc8d02255edea909e8e0691a4609a32 100644 (file)
@@ -33,8 +33,6 @@
  */
 
 #include "ipv6_port.h"
-#include "parser/ip_addr_set.h"
-
 #include "sflsq.h"
 #include "sfghash.h"
 #include "sfxhash.h"
@@ -104,7 +102,7 @@ typedef struct
     unsigned timeout;
 
     // ip set to restrict rate_filter
-    IpAddrSet* applyTo;
+    sfip_var_t* applyTo;
 
 } tSFRFConfigNode;
 
index c081dae128b75b31b0a67fd78f1e6b780bdc017d..411e3f66a7d4ee69ee413611cc76d76cced765e3 100644 (file)
@@ -44,7 +44,7 @@
 #include <string.h>
 #include <netinet/in.h>
 
-#include "parser/ip_addr_set.h"
+#include "sfip/ipv6_port.h"
 #include "sflsq.h"
 #include "sfghash.h"
 #include "sfxhash.h"
@@ -175,7 +175,7 @@ static void sfthd_node_free(void *node)
 
     if (sfthd_node->ip_address != NULL)
     {
-        IpAddrSetDestroy(sfthd_node->ip_address);
+        sfvar_free(sfthd_node->ip_address);
     }
 
     free(sfthd_node);
@@ -636,7 +636,7 @@ int sfthd_create_threshold(SnortConfig *sc,
                            int priority,
                            int count,
                            int seconds,
-                           IpAddrSet* ip_address)
+                           sfip_var_t* ip_address)
 {
     //allocate memory fpr sfthd_array if needed.
     PolicyId policyId = get_network_policy()->policy_id;
@@ -704,7 +704,7 @@ static inline int sfthd_test_suppress (
     snort_ip_p ip)
 {
     if ( !sfthd_node->ip_address ||
-         IpAddrSetContains(sfthd_node->ip_address, ip) )
+         sfvar_ip_in(sfthd_node->ip_address, ip) )
     {
 #ifdef THD_DEBUG
         printf("THD_DEBUG: SUPPRESS NODE, do not log events with this IP\n");
index 08d3118c97f52bb2e6acda8f43096b592b0d130e..4ee48a597ec5b47d485690ddcd50b3037e1255d2 100644 (file)
@@ -31,7 +31,6 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
-#include "parser/ip_addr_set.h"
 
 #include "sflsq.h"
 #include "sfghash.h"
@@ -139,7 +138,7 @@ typedef struct {
     int      count;
     unsigned seconds;
     uint64_t filtered;
-    IpAddrSet* ip_address;
+    sfip_var_t* ip_address;
 
 } THD_NODE;
 
@@ -178,7 +177,7 @@ typedef struct _THDX_STRUCT
     int  priority;
     int  count;
     unsigned int  seconds;
-    IpAddrSet* ip_address;
+    sfip_var_t* ip_address;
 
 } THDX_STRUCT;
 
@@ -256,7 +255,7 @@ int sfthd_create_threshold(
     int          priority,
     int          count,
     int          seconds,
-    IpAddrSet*   ip_address
+    sfip_var_t*   ip_address
 );
 
 //  1: don't log due to event_filter
index 0d0a2f79ad423597b42ea551e5334c9b9eea650c..26a8602170b5a71991ba8af14d24546a051e79c2 100644 (file)
@@ -182,7 +182,8 @@ void Request::respond(const char* s) const
         LogMessage("%s", s);
         return;
     }
-    write(fd, s, strlen(s));
+    if ( write(fd, s, strlen(s)) )
+        return;  // FIXIT count errors?
 }
 
 void Request::show_prompt() const
index c73b5d4f4cdee218c3cf8465a2a73d527f97e847..7a822fe6460d4ad406b877580ba84a2c60709720 100644 (file)
@@ -51,6 +51,7 @@ using namespace std;
 #include "filters/rate_filter.h"
 #include "codecs/decode_module.h"
 #include "time/ppm_module.h"
+#include "parser/parse_ip.h"
 
 #if defined(DEBUG_MSGS) || defined (REG_TEST)
 #include "file_api/file_api.h"
@@ -1369,7 +1370,7 @@ bool SuppressModule::set(const char*, Value& v, SnortConfig* sc)
         thdx.tracking = v.get_long() + 1;
 
     else if ( v.is("ip") )
-        thdx.ip_address = IpAddrSetParse(sc, v.get_string());
+        thdx.ip_address = sfip_var_from_string(v.get_string());
 
     else
         return false;
@@ -1448,7 +1449,7 @@ bool EventFilterModule::set(const char*, Value& v, SnortConfig* sc)
         thdx.tracking = v.get_long() + 1;
 
     else if ( v.is("ip") )
-        thdx.ip_address = IpAddrSetParse(sc, v.get_string());
+        thdx.ip_address = sfip_var_from_string(v.get_string());
 
     else if ( v.is("count") )
         thdx.count = v.get_long();
@@ -1549,7 +1550,7 @@ bool RateFilterModule::set(const char*, Value& v, SnortConfig* sc)
         thdx.timeout = v.get_long();
 
     else if ( v.is("apply_to") )
-        thdx.applyTo = IpAddrSetParse(sc, v.get_string());
+        thdx.applyTo = sfip_var_from_string(v.get_string());
 
     else if ( v.is("new_action") )
         thdx.newAction = (RuleType)(v.get_long() + 1);
index 4a20f4df0dc8638f67513258c6b0dd22d36a16db..7a21ad6280971ae011f4a3c178816d54f28a20d5 100644 (file)
@@ -105,7 +105,7 @@ typedef struct _VarEntry
     unsigned char flags;
     uint32_t id;
 
-    IpAddrSet *addrset;
+    sfip_var_t *addrset;
     struct _VarEntry *prev;
     struct _VarEntry *next;
 
index 7858fafc7b00aed8c8bdc02e2a9070fd6e2a0f73..f8fa8b3e62f31b94d29a115e6b315995615cd60f 100644 (file)
@@ -1403,11 +1403,13 @@ static void LogBasePerfStats(SFBASE_STATS *sfBaseStats,  FILE * fh )
 
     if (wrote != 1)
     {
-        WarningMessage("%s: Failed to write stats\n", __FUNCTION__);
+        WarningMessage("Failed to write stats: %s\n", strerror(errno));
 
         // fseek to adjust offset; ftruncate doesn't do that for us.
         fseek(fh, start, SEEK_SET);
-        ftruncate(fileno(fh), start);
+        
+        if ( ftruncate(fileno(fh), start) )
+            WarningMessage("Failed to truncate stats: %s\n", strerror(errno));
     }
 
     fflush(fh);
index 398f83a07dd387ab78ac35750d3c0cbc1a22046c..a40b5f2ce3cced1537c9d3d5a0e8a9cced87fa73 100644 (file)
@@ -45,7 +45,6 @@
 #include "stream_icmp.h"
 #include "stream_ip.h"
 #include "mstring.h"
-#include "parser/ip_addr_set.h"
 #include "decode.h"
 #include "detect.h"
 #include "generators.h"
index ef934bacac9944930d05e2cfeb1200e3695cb2f6..0d8ce8934df7875f030307ff7927a3d6d0b3d7a8 100644 (file)
@@ -31,7 +31,7 @@
 #include <netinet/in.h>
 
 #include "utils/bitop_funcs.h"
-#include "parser/ip_addr_set.h"
+#include "sfip/ipv6_port.h"
 #include "framework/inspector.h"
 
 #include "mempool/mempool.h"
index 046197a634e180922f51d20f0bcf43208411444b..4c8821378df7bc69837dd4c93dd958244343b9a1 100644 (file)
@@ -66,7 +66,6 @@
 #include "snort_bounds.h"
 #include "generators.h"
 #include "snort.h"
-#include "parser/ip_addr_set.h"
 #include "time/packet_time.h"
 #include "decode.h"
 #include "encode.h"
index 4411b11257562689fc247a04acc7374d207d5392..b7f0fbb05beac0a06e860e27eaf21e9669d888a9 100644 (file)
@@ -5,6 +5,8 @@ add_library (parser STATIC
     parser.h 
     parse_conf.cc 
     parse_conf.h 
+    parse_ip.cc 
+    parse_ip.h 
     parse_rule.cc 
     parse_rule.h 
     parse_otn.cc 
@@ -14,8 +16,6 @@ add_library (parser STATIC
     config_file.cc 
     config_file.h 
     keywords.h 
-    ip_addr_set.cc
-    ip_addr_set.h
     mstring.cc 
     mstring.h 
     vars.cc 
index 4227b4d168c53fdfdd18b3051309e0056e16b5d8..2d7d9007fc9c48042dd4791a354dfcb879599c46 100644 (file)
@@ -5,12 +5,12 @@ noinst_LIBRARIES = libparser.a
 libparser_a_SOURCES = \
 parser.cc parser.h \
 parse_conf.cc parse_conf.h \
+parse_ip.cc parse_ip.h \
 parse_rule.cc parse_rule.h \
 parse_otn.cc parse_otn.h \
 cmd_line.cc cmd_line.h \
 config_file.cc config_file.h \
 keywords.h \
-ip_addr_set.cc ip_addr_set.h \
 mstring.cc mstring.h \
 vars.cc vars.h
 
similarity index 78%
rename from src/parser/ip_addr_set.cc
rename to src/parser/parse_ip.cc
index 11cf5a267d6596ee4784cf262a4eedbc37ea4773..ddb4b02757d8d068a2370fbad5e1e583feb147b2 100644 (file)
@@ -1,9 +1,5 @@
 /*
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
- * Copyright (C) 2002-2013 Sourcefire, Inc.
- *
- * Author(s):  Andrew R. Baker <andrewb@snort.org>
- *             Martin Roesch   <roesch@sourcefire.com>
+ * Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
  *
  * 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
  * 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.
- *
  */
 
-/* includes */
-
-#include "ip_addr_set.h"
+#include "parse_ip.h"
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -46,9 +39,9 @@
 #include "ipv6_port.h"
 #include "sfip/sf_vartable.h"
 
-IpAddrSet *IpAddrSetParse(SnortConfig*, const char *addr)
+sfip_var_t* sfip_var_from_string(const char *addr)
 {
-    IpAddrSet *ret;
+    sfip_var_t *ret;
     int ret_code;
     vartable_t *ip_vartable;
 
@@ -57,7 +50,7 @@ IpAddrSet *IpAddrSetParse(SnortConfig*, const char *addr)
     DEBUG_WRAP(DebugMessage(DEBUG_CONFIGRULES,"Got address string: %s\n",
                 addr););
 
-    ret = (IpAddrSet*)SnortAlloc(sizeof(IpAddrSet));
+    ret = (sfip_var_t*)SnortAlloc(sizeof(sfip_var_t));
 
     if((ret_code = sfvt_add_to_var(ip_vartable, ret, addr)) != SFIP_SUCCESS)
     {
@@ -74,12 +67,3 @@ IpAddrSet *IpAddrSetParse(SnortConfig*, const char *addr)
     return ret;
 }
 
-void IpAddrSetDestroy(IpAddrSet *ipAddrSet)
-{
-
-    if(!ipAddrSet)
-        return;
-
-    sfvar_free(ipAddrSet);
-}
-
similarity index 78%
rename from src/parser/ip_addr_set.h
rename to src/parser/parse_ip.h
index aaa44870d5038116635c2100d5ae1d61c11cf128..e19a04ca2df7d29930640801ea9e9cb66eb021fc 100644 (file)
@@ -1,9 +1,7 @@
 /*
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
  * Copyright (C) 2002-2013 Sourcefire, Inc.
  *
- * Author(s):  Andrew R. Baker <andrewb@sourcefire.com>
- *
  * 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
  * 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.
- *
  */
 
-#ifndef IPADDRSET_H
-#define IPADDRSET_H
+#ifndef PARSE_IP_H
+#define PARSE_IP_H
 
 #include <sys/types.h>
 #include "snort_types.h"
@@ -30,8 +27,7 @@
 #include "ipv6_port.h"
 #include "sfip/sf_ipvar.h"
 
-void IpAddrSetDestroy(IpAddrSet *);
-IpAddrSet *IpAddrSetParse(struct SnortConfig*, const char*);
+sfip_var_t* sfip_var_from_string(const char*);
 
 #endif
 
index 810d6b23646f7f6af414b69e5b340a42090983f6..6149b2b7061948f68434302075fc5a8f70ca2f1a 100644 (file)
@@ -500,7 +500,7 @@ static int FinishPortListRule(rule_port_tables_t *port_tables, RuleTreeNode *rtn
     return 0;
 }
 
-static int ValidateIPList(IpAddrSet *addrset, const char *token)
+static int ValidateIPList(sfip_var_t *addrset, const char *token)
 {
     if(!addrset || !(addrset->head||addrset->neg_head))
     {
index 07d3e8ce723efe86a173673b621dcf5810703f86..e6d87c3ba443b9c8d145467696623015c0ea4008 100644 (file)
@@ -686,7 +686,7 @@ void DeleteVars(VarEntry *var_table)
             free(p->value);
         if (p->addrset)
         {
-            IpAddrSetDestroy(p->addrset);
+            sfvar_free(p->addrset);
         }
         free(p);
         p = q;
index 0fbe8b86cfd95e80e67b29e2b5587d3e756bfe45..01656efa4aafcfe3b7d84cd08daf4dcaf144dfb4 100644 (file)
 typedef sfip_t snort_ip;
 typedef sfip_t *snort_ip_p;
 
-#define IpAddrNode sfip_node_t
-#define IpAddrSet sfip_var_t
-#define IpAddrSetContains(x,y) sfvar_ip_in(x, y)
-#define IpAddrSetPrint sfvar_print
-
 #ifdef inet_ntoa
 #undef inet_ntoa
 #endif
index e44ffc0f8df17bc3bc9f1c5f346a8c8c462deaa0..6feec989c03b824e46237bdfc72520c479c7db38 100644 (file)
@@ -398,7 +398,7 @@ SFIP_RET sfip_contains(const sfip_t *net, const sfip_t *ip) {
     int net_fam, ip_fam;
     const unsigned int *p1, *p2;
 
-    /* SFIP_CONTAINS is returned here due to how IpAddrSetContains
+    /* SFIP_CONTAINS is returned here due to how sfvar_ip_in
      * handles zero'ed IPs" */
     ARG_CHECK2(net, ip, SFIP_CONTAINS);
 
index fc83c9cf7c74f0b050506bf9f5e4ce0390cab4cf..f7e7c320633646f17d63d7777e387e04bd4d57b3 100644 (file)
@@ -34,6 +34,7 @@
 #include "detection/rules.h"
 #include "detection/treenodes.h"
 #include "sfip/sf_ip.h"
+#include "parser/parse_ip.h"
 #include "filters/sfrf.h"
 #include "utils/util.h"
 
@@ -903,7 +904,7 @@ static void Init (unsigned cap) {
         cfg.seconds = p->seconds;
         cfg.newAction = (RuleType)RULE_NEW;
         cfg.timeout = p->timeout;
-        cfg.applyTo = p->ip ? IpAddrSetParse(snort_conf, p->ip) : NULL;
+        cfg.applyTo = p->ip ? sfip_var_from_string(p->ip) : NULL;
 
         p->create = SFRF_ConfigAdd(snort_conf, &rfc, &cfg);
     }
index e245af5dcf6abbfcc15023f7a57409cd771dba2c..5114a72378d9c368e0523f0e0bb5ce5b94a797aa 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "snort.h"
 #include "sfip/sf_ip.h"
+#include "parser/parse_ip.h"
 #include "filters/sfthd.h"
 #include "utils/util.h"
 
@@ -737,7 +738,7 @@ static void Init (ThreshData* base, int max) {
 
         if ( p->type != THD_TYPE_DETECT )
         {
-            IpAddrSet* set = p->ip ? IpAddrSetParse(snort_conf, p->ip) : NULL;
+            sfip_var_t* set = p->ip ? sfip_var_from_string(p->ip) : NULL;
 
             p->create = sfthd_create_threshold(snort_conf,
                 pThdObjs, p->gid, p->sid, p->tracking, p->type, PRIORITY,