Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix in netmasks #1091

Merged
merged 2 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 45 additions & 18 deletions userspace/libsinsp/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ bool flt_compare_ipv4net(cmpop op, uint64_t operand1, ipv4net* operand2)
switch(op)
{
case CO_EQ:
case CO_IN:
{
return ((operand1 & operand2->m_netmask) == (operand2->m_ip & operand2->m_netmask));
}
Expand Down Expand Up @@ -1133,32 +1134,58 @@ bool sinsp_filter_check::flt_compare(cmpop op, ppm_param_type type, void* operan
{
if (op == CO_IN || op == CO_PMATCH)
{
// For raw strings, the length may not be set. So we do a strlen to find it.
if(type == PT_CHARBUF && op1_len == 0)
// Certain filterchecks can't be done as a set
// membership test/group match. For these, just loop over the
// values and see if any value is equal.
switch(type)
{
op1_len = strlen((char *) operand1);
}
case PT_IPV4NET:
case PT_SOCKADDR:
case PT_SOCKTUPLE:
case PT_FDLIST:
case PT_FSPATH:
case PT_SIGSET:
for (uint16_t i=0; i < m_val_storages.size(); i++)
{
if (::flt_compare(CO_EQ,
type,
operand1,
filter_value_p(i)))
{
return true;
}
}
return false;
break;
default:
// For raw strings, the length may not be set. So we do a strlen to find it.
if(type == PT_CHARBUF && op1_len == 0)
{
op1_len = strlen((char *) operand1);
}

filter_value_t item((uint8_t *) operand1, op1_len);
filter_value_t item((uint8_t *) operand1, op1_len);

if (op == CO_IN)
{
if(op1_len >= m_val_storages_min_size &&
op1_len <= m_val_storages_max_size &&
m_val_storages_members.find(item) != m_val_storages_members.end())
if (op == CO_IN)
{
return true;
if(op1_len >= m_val_storages_min_size &&
op1_len <= m_val_storages_max_size &&
m_val_storages_members.find(item) != m_val_storages_members.end())
{
return true;
}
}
}
else
{
if (m_val_storages_paths.match(item))
else
{
return true;
if (m_val_storages_paths.match(item))
{
return true;
}
}
}

return false;
return false;
break;
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/filterchecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ bool sinsp_filter_check_fd::compare_net(sinsp_evt *evt)

if(evt_type == SCAP_FD_IPV4_SOCK)
{
if(m_cmpop == CO_EQ)
if(m_cmpop == CO_EQ || m_cmpop == CO_IN)
{
if(flt_compare_ipv4net(m_cmpop, m_fdinfo->m_sockinfo.m_ipv4info.m_fields.m_sip, (ipv4net*)filter_value_p()) ||
flt_compare_ipv4net(m_cmpop, m_fdinfo->m_sockinfo.m_ipv4info.m_fields.m_dip, (ipv4net*)filter_value_p()))
Expand Down