#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"
virtual inline PROTO_ID get_proto_id() { return PROTO_TCP; };
};
-static IpAddrSet *SynToMulticastDstIp = NULL;
+static sfip_var_t *SynToMulticastDstIp = NULL;
} // namespace
}
}
- 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);
}
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");
static void tcp_codec_gterm()
{
if( SynToMulticastDstIp )
- IpAddrSetDestroy(SynToMulticastDstIp);
+ sfvar_free(SynToMulticastDstIp);
}
}
-/****************************************************************************
- *
- * 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
{
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;
#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"
if (node->applyTo != NULL)
{
- IpAddrSetDestroy(node->applyTo);
+ sfvar_free(node->applyTo);
}
free(node);
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
*/
#include "ipv6_port.h"
-#include "parser/ip_addr_set.h"
-
#include "sflsq.h"
#include "sfghash.h"
#include "sfxhash.h"
unsigned timeout;
// ip set to restrict rate_filter
- IpAddrSet* applyTo;
+ sfip_var_t* applyTo;
} tSFRFConfigNode;
#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"
if (sfthd_node->ip_address != NULL)
{
- IpAddrSetDestroy(sfthd_node->ip_address);
+ sfvar_free(sfthd_node->ip_address);
}
free(sfthd_node);
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;
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");
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include "parser/ip_addr_set.h"
#include "sflsq.h"
#include "sfghash.h"
int count;
unsigned seconds;
uint64_t filtered;
- IpAddrSet* ip_address;
+ sfip_var_t* ip_address;
} THD_NODE;
int priority;
int count;
unsigned int seconds;
- IpAddrSet* ip_address;
+ sfip_var_t* ip_address;
} THDX_STRUCT;
int priority,
int count,
int seconds,
- IpAddrSet* ip_address
+ sfip_var_t* ip_address
);
// 1: don't log due to event_filter
LogMessage("%s", s);
return;
}
- write(fd, s, strlen(s));
+ if ( write(fd, s, strlen(s)) )
+ return; // FIXIT count errors?
}
void Request::show_prompt() const
#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"
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;
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();
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);
unsigned char flags;
uint32_t id;
- IpAddrSet *addrset;
+ sfip_var_t *addrset;
struct _VarEntry *prev;
struct _VarEntry *next;
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);
#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"
#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"
#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"
parser.h
parse_conf.cc
parse_conf.h
+ parse_ip.cc
+ parse_ip.h
parse_rule.cc
parse_rule.h
parse_otn.cc
config_file.cc
config_file.h
keywords.h
- ip_addr_set.cc
- ip_addr_set.h
mstring.cc
mstring.h
vars.cc
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
/*
-** 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"
#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;
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)
{
return ret;
}
-void IpAddrSetDestroy(IpAddrSet *ipAddrSet)
-{
-
- if(!ipAddrSet)
- return;
-
- sfvar_free(ipAddrSet);
-}
-
/*
-** 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"
#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
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))
{
free(p->value);
if (p->addrset)
{
- IpAddrSetDestroy(p->addrset);
+ sfvar_free(p->addrset);
}
free(p);
p = q;
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
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);
#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"
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);
}
#include "snort.h"
#include "sfip/sf_ip.h"
+#include "parser/parse_ip.h"
#include "filters/sfthd.h"
#include "utils/util.h"
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,