RUN_FLAG__IP_FRAGS_ONLY = 0x00200000,
RUN_FLAG__DUMP_RULE_STATE = 0x00400000,
+ RUN_FLAG__TEST_FEATURES = 0x00800000,
+
#ifdef SHELL
- RUN_FLAG__SHELL = 0x00800000,
+ RUN_FLAG__SHELL = 0x01000000,
#endif
#ifdef PIGLET
- RUN_FLAG__PIGLET = 0x01000000,
+ RUN_FLAG__PIGLET = 0x02000000,
#endif
};
bool assure_established() const
{ return run_flags & RUN_FLAG__ASSURE_EST; }
+ bool test_features() const
+ { return run_flags & RUN_FLAG__TEST_FEATURES; }
+
// other stuff
uint8_t min_ttl() const
{ return get_network_policy()->min_ttl; }
#endif
//-------------------------------------------------------------------------
-// why not
+// hex conversion helper funcs
//-------------------------------------------------------------------------
[[noreturn]] static void c2x(const char* s)
{ "--enable-inline-test", Parameter::PT_IMPLIED, nullptr, nullptr,
"enable Inline-Test Mode Operation" },
+ { "--enable-test-features", Parameter::PT_IMPLIED, nullptr, nullptr,
+ "enable features used in testing" },
+
{ "--gen-msg-map", Parameter::PT_IMPLIED, nullptr, nullptr,
"dump configured rules in gen-msg.map format for use by other tools" },
else if ( v.is("--enable-inline-test") )
sc->run_flags |= RUN_FLAG__INLINE_TEST;
+ else if ( v.is("--enable-test-features") )
+ {
+ sc->run_flags |= RUN_FLAG__TEST_FEATURES;
+ SfIp::test_features = true;
+ }
+
else if ( v.is("--gen-msg-map") )
{
sc->run_flags |= (RUN_FLAG__DUMP_MSG_MAP | RUN_FLAG__TEST);
TEST(appid_debug, ipv6_test)
{
// set_constraints()
+ SfIp::test_features = true;
AppIdDebugSessionConstraints constraints = { };
SetConstraints(IpProtocol::UDP, "2001:db8:85a3::8a2e:370:7334", 1234,
"2001:db8:85a3::8a2e:370:7335", 443, constraints);
CHECK_EQUAL(appidDebug->is_active(), true);
// get_debug_session()
-#ifdef REG_TEST
const char* str = "2001:0db8:85a3:0000:0000:8a2e:0370:7334 1234 -> "
"2001:0db8:85a3:0000:0000:8a2e:0370:7335 443 17 AS=100 ID=3";
-#else
- const char* str = "2001:db8:85a3::8a2e:370:7334 1234 -> "
- "2001:db8:85a3::8a2e:370:7335 443 17 AS=100 ID=3";
-#endif
+
CHECK_TRUE(strcmp(appidDebug->get_debug_session(), str) == 0);
delete &session.get_api();
using namespace snort;
+bool SfIp::test_features{ false };
+
/* Masks off 'val' bits from the IP contained within 'ip' */
inline int SfIp::cidr_mask(int val)
{
return buf;
}
-#if !defined(REG_TEST) && !defined(CATCH_TEST_BUILD)
- if (!inet_ntop(family, ip_raw, buf, bufsize))
- snprintf(buf, bufsize, "ERROR");
-#else
- /* 4 fields of at most 3 characters each */
- if (family == AF_INET)
+ if ( !SfIp::test_features )
{
- int i;
- const uint8_t* p = (const uint8_t*)ip_raw;
-
- for (i=0; p < ((const uint8_t*)ip_raw) + 4; p++)
- {
- i += sprintf(&buf[i], "%d", *p);
-
- /* If this is the last iteration, this could technically cause one
- * extra byte to be written past the end. */
- if (i < bufsize && ((p + 1) < ((const uint8_t*)ip_raw+4)))
- buf[i] = '.';
-
- i++;
- }
+ if (!inet_ntop(family, ip_raw, buf, bufsize))
+ snprintf(buf, bufsize, "ERROR");
}
else
{
- int i;
- const uint16_t* p = (const uint16_t*)ip_raw;
+ /* 4 fields of at most 3 characters each */
+ if (family == AF_INET)
+ {
+ int i;
+ const uint8_t* p = (const uint8_t*)ip_raw;
+
+ for (i=0; p < ((const uint8_t*)ip_raw) + 4; p++)
+ {
+ i += sprintf(&buf[i], "%d", *p);
- for (i=0; p < ((const uint16_t*)ip_raw) + 8; p++)
+ /* If this is the last iteration, this could technically cause one
+ * extra byte to be written past the end. */
+ if (i < bufsize && ((p + 1) < ((const uint8_t*)ip_raw+4)))
+ buf[i] = '.';
+
+ i++;
+ }
+ }
+ else
{
- i += sprintf(&buf[i], "%04x", ntohs(*p));
+ int i;
+ const uint16_t* p = (const uint16_t*)ip_raw;
+
+ for (i=0; p < ((const uint16_t*)ip_raw) + 8; p++)
+ {
+ i += sprintf(&buf[i], "%04x", ntohs(*p));
- /* If this is the last iteration, this could technically cause one
- * extra byte to be written past the end. */
- if (i < bufsize && ((p + 1) < ((const uint16_t*)ip_raw) + 8))
- buf[i] = ':';
+ /* If this is the last iteration, this could technically cause one
+ * extra byte to be written past the end. */
+ if (i < bufsize && ((p + 1) < ((const uint16_t*)ip_raw) + 8))
+ buf[i] = ':';
- i++;
+ i++;
+ }
}
}
-#endif
return buf;
}
void obfuscate(const SfCidr* ob);
+ static bool test_features;
+
private:
int cidr_mask(int val);
bool _is_equals(const SfIp& rhs) const;
sfip_var_t* var1;
sfip_var_t* var2;
+ SfIp::test_features = true;
+
SECTION("basic list merge")
{
table = sfvt_alloc_table();
CHECK(sfvt_add_str(table, "my_cidr [ 192.168.0.0/16, f0:e0:d0:c0::8/64, 10.10.1.8/19,"
" f0:e0:d1:c1::1/32]", &var2) == SFIP_SUCCESS);
print_var_list(var2->head);
+
CHECK(!strcmp("10.10.0.0,192.168.0.0,00f0:00e0:0000:0000:0000:0000:0000:0000",
sfipvar_test_buff));
SECTION("merge contained IPs and negated-IPs")
{
+
+ SfIp::test_features = true;
+
table = sfvt_alloc_table();
CHECK(sfvt_add_str(table, "foo 1.2.3.4, cafe:feed:beef::0/48", &var1) == SFIP_SUCCESS);
/* Check merged IP lists */
print_var_list(var1->head);
+
CHECK(!strcmp("1.2.0.0,cafe:0000:0000:0000:0000:0000:0000:0000", sfipvar_test_buff));
print_var_list(var1->neg_head);
CHECK(!strcmp("!9.0.0.0,!dead:beef:0000:0000:0000:0000:0000:0000", sfipvar_test_buff));
static int RunFunc(const char* func, const char* arg1, const char* arg2)
{
+ SfIp::test_features = true;
+
SfCidr cidr1, cidr2;
const SfIp* ip1, * ip2;
int result = SFIP_FAILURE;
}
else if (keyword == "use_static_footprint_sizes")
{
- table_api.add_diff_option_comment("use_static_footprint_sizes",
- "stream.footprint = 192");
- table_api.close_table();
- table_api.open_top_level_table("stream");
- table_api.add_option("footprint", 192);
+ table_api.add_deleted_comment("use_static_footprint_sizes");
table_api.close_table();
table_api.open_table("stream_tcp");
}