From: Russ Combs Date: Fri, 2 May 2014 20:52:16 +0000 (-0400) Subject: eliminate #define IpAddrSet sfip_var_t and related X-Git-Tag: 3.0.0-233~1535 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d2de9e8ee3ce7902fb9166945b444554941d315;p=thirdparty%2Fsnort3.git eliminate #define IpAddrSet sfip_var_t and related --- diff --git a/src/codecs/basic/cd_tcp.cc b/src/codecs/basic/cd_tcp.cc index 940bc95df..184bb0cd9 100644 --- a/src/codecs/basic/cd_tcp.cc +++ b/src/codecs/basic/cd_tcp.cc @@ -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); } diff --git a/src/detection/detect.cc b/src/detection/detect.cc index 11c6a6527..34ee118a3 100644 --- a/src/detection/detect.cc +++ b/src/detection/detect.cc @@ -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 diff --git a/src/detection/treenodes.h b/src/detection/treenodes.h index e1fd12cc0..2c02ecc56 100644 --- a/src/detection/treenodes.h +++ b/src/detection/treenodes.h @@ -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; diff --git a/src/filters/sfrf.cc b/src/filters/sfrf.cc index 2e4f3f8bf..6b64a7472 100644 --- a/src/filters/sfrf.cc +++ b/src/filters/sfrf.cc @@ -42,7 +42,7 @@ #include #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 diff --git a/src/filters/sfrf.h b/src/filters/sfrf.h index 7ceef1e0b..0cb438d32 100644 --- a/src/filters/sfrf.h +++ b/src/filters/sfrf.h @@ -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; diff --git a/src/filters/sfthd.cc b/src/filters/sfthd.cc index c081dae12..411e3f66a 100644 --- a/src/filters/sfthd.cc +++ b/src/filters/sfthd.cc @@ -44,7 +44,7 @@ #include #include -#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"); diff --git a/src/filters/sfthd.h b/src/filters/sfthd.h index 08d3118c9..4ee48a597 100644 --- a/src/filters/sfthd.h +++ b/src/filters/sfthd.h @@ -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 diff --git a/src/main.cc b/src/main.cc index 0d0a2f79a..26a860217 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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 diff --git a/src/main/modules.cc b/src/main/modules.cc index c73b5d4f4..7a822fe64 100644 --- a/src/main/modules.cc +++ b/src/main/modules.cc @@ -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); diff --git a/src/main/policy.h b/src/main/policy.h index 4a20f4df0..7a21ad628 100644 --- a/src/main/policy.h +++ b/src/main/policy.h @@ -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; diff --git a/src/network_inspectors/perf_monitor/perf_base.cc b/src/network_inspectors/perf_monitor/perf_base.cc index 7858fafc7..f8fa8b3e6 100644 --- a/src/network_inspectors/perf_monitor/perf_base.cc +++ b/src/network_inspectors/perf_monitor/perf_base.cc @@ -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); diff --git a/src/network_inspectors/stream5/stream_api.cc b/src/network_inspectors/stream5/stream_api.cc index 398f83a07..a40b5f2ce 100644 --- a/src/network_inspectors/stream5/stream_api.cc +++ b/src/network_inspectors/stream5/stream_api.cc @@ -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" diff --git a/src/network_inspectors/stream5/stream_common.h b/src/network_inspectors/stream5/stream_common.h index ef934baca..0d8ce8934 100644 --- a/src/network_inspectors/stream5/stream_common.h +++ b/src/network_inspectors/stream5/stream_common.h @@ -31,7 +31,7 @@ #include #include "utils/bitop_funcs.h" -#include "parser/ip_addr_set.h" +#include "sfip/ipv6_port.h" #include "framework/inspector.h" #include "mempool/mempool.h" diff --git a/src/network_inspectors/stream5/stream_tcp.cc b/src/network_inspectors/stream5/stream_tcp.cc index 046197a63..4c8821378 100644 --- a/src/network_inspectors/stream5/stream_tcp.cc +++ b/src/network_inspectors/stream5/stream_tcp.cc @@ -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" diff --git a/src/parser/CMakeLists.txt b/src/parser/CMakeLists.txt index 4411b1125..b7f0fbb05 100644 --- a/src/parser/CMakeLists.txt +++ b/src/parser/CMakeLists.txt @@ -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 diff --git a/src/parser/Makefile.am b/src/parser/Makefile.am index 4227b4d16..2d7d9007f 100644 --- a/src/parser/Makefile.am +++ b/src/parser/Makefile.am @@ -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 diff --git a/src/parser/ip_addr_set.cc b/src/parser/parse_ip.cc similarity index 78% rename from src/parser/ip_addr_set.cc rename to src/parser/parse_ip.cc index 11cf5a267..ddb4b0275 100644 --- a/src/parser/ip_addr_set.cc +++ b/src/parser/parse_ip.cc @@ -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 - * Martin Roesch + * 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 @@ -19,12 +15,9 @@ * 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); -} - diff --git a/src/parser/ip_addr_set.h b/src/parser/parse_ip.h similarity index 78% rename from src/parser/ip_addr_set.h rename to src/parser/parse_ip.h index aaa44870d..e19a04ca2 100644 --- a/src/parser/ip_addr_set.h +++ b/src/parser/parse_ip.h @@ -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 - * * 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 @@ -18,11 +16,10 @@ * 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 #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 diff --git a/src/parser/parse_rule.cc b/src/parser/parse_rule.cc index 810d6b236..6149b2b70 100644 --- a/src/parser/parse_rule.cc +++ b/src/parser/parse_rule.cc @@ -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)) { diff --git a/src/parser/vars.cc b/src/parser/vars.cc index 07d3e8ce7..e6d87c3ba 100644 --- a/src/parser/vars.cc +++ b/src/parser/vars.cc @@ -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; diff --git a/src/sfip/ipv6_port.h b/src/sfip/ipv6_port.h index 0fbe8b86c..01656efa4 100644 --- a/src/sfip/ipv6_port.h +++ b/src/sfip/ipv6_port.h @@ -34,11 +34,6 @@ 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 diff --git a/src/sfip/sf_ip.cc b/src/sfip/sf_ip.cc index e44ffc0f8..6feec989c 100644 --- a/src/sfip/sf_ip.cc +++ b/src/sfip/sf_ip.cc @@ -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); diff --git a/src/test/sfrf_test.cc b/src/test/sfrf_test.cc index fc83c9cf7..f7e7c3206 100644 --- a/src/test/sfrf_test.cc +++ b/src/test/sfrf_test.cc @@ -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); } diff --git a/src/test/sfthd_test.cc b/src/test/sfthd_test.cc index e245af5dc..5114a7237 100644 --- a/src/test/sfthd_test.cc +++ b/src/test/sfthd_test.cc @@ -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,