Skip to content

Commit

Permalink
Merge pull request #549 from noironetworks/lmr-prune
Browse files Browse the repository at this point in the history
Fix prefixlen matching in prunefilter
  • Loading branch information
tbachman authored May 28, 2024
2 parents ad65ecc + 32bb175 commit 219bd5a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions agent-ovs/ovs/include/PacketLogHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class PacketFilterSpec: public PacketTuple {
if(!prefixLen.empty()) {
pfxLen = stoul(prefixLen);
}
if((pfxLen > 32) || (pfxLen == 0))
if((pfxLen > 128) || (pfxLen == 0))
return false;
return network::prefix_match( addr1, pfxLen,
addr2, pfxLen, is_exact_match);
Expand Down Expand Up @@ -281,7 +281,7 @@ class PacketFilterSpec: public PacketTuple {
for (auto &i:ip_fields) {
if(!fields[i].second.empty()) {
if(!compareIps(fields[i].second,p.fields[i].second,
fields[i+8].second)) {
fields[i+7].second)) {
return false;
}
}
Expand Down
45 changes: 45 additions & 0 deletions agent-ovs/ovs/test/PacketDecoder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,49 @@ BOOST_FIXTURE_TEST_CASE(user_prune_tests, PacketDecoderFixture) {
pktLogger.pruneLog(p3);
BOOST_CHECK(p3.pruneLog == true);
}

BOOST_FIXTURE_TEST_CASE(user_prune_ip_prefix_tests, PacketDecoderFixture) {
auto pktDecoder = pktLogger.getDecoder();
std::shared_ptr<PacketFilterSpec> filt1(new PacketFilterSpec());
ParseInfo p3(&pktDecoder);
filt1->setField(TFLD_SRC_IP,"14.0.0.0");
filt1->setField(TFLD_SPFX_LEN,"24");
filt1->setField(TFLD_DST_IP,"100.0.0.0");
filt1->setField(TFLD_DPFX_LEN,"24");
filt1->setField(TFLD_IP_PROTO,"17");
pktLogger.updatePruneFilter("filt1",filt1);
int ret = pktDecoder.decode(udp_buf, 66, p3);
BOOST_CHECK(ret == 0);
pktLogger.pruneLog(p3);
BOOST_CHECK(p3.pruneLog == true);
pktLogger.deletePruneFilter("filt1");
filt1.reset(new PacketFilterSpec());
filt1->setField(TFLD_SRC_IP,"14.0.0.0");
filt1->setField(TFLD_DST_IP,"100.0.0.0");
pktLogger.updatePruneFilter("filt2",filt1);
pktLogger.pruneLog(p3);
BOOST_CHECK(p3.pruneLog == false);
ParseInfo p4(&pktDecoder);
ret = pktDecoder.decode(udpv6_buf, 86, p4);
BOOST_CHECK(ret == 0);
pktLogger.pruneLog(p4);
BOOST_CHECK(p4.pruneLog == false);
pktLogger.deletePruneFilter("filt1");
filt1.reset(new PacketFilterSpec());
filt1->setField(TFLD_SRC_IP,"fe80::a00:27ff:fefe:8f95");
filt1->setField(TFLD_DST_IP,"ff02::1:2");
pktLogger.updatePruneFilter("filt3",filt1);
pktLogger.pruneLog(p4);
BOOST_CHECK(p4.pruneLog == true);
pktLogger.deletePruneFilter("filt1");
filt1.reset(new PacketFilterSpec());
filt1->setField(TFLD_SRC_IP,"fe80::");
filt1->setField(TFLD_SPFX_LEN,"64");
filt1->setField(TFLD_DST_IP,"ff02::1:0");
filt1->setField(TFLD_DPFX_LEN,"120");
pktLogger.updatePruneFilter("filt4",filt1);
pktLogger.pruneLog(p4);
BOOST_CHECK(p4.pruneLog == true);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 219bd5a

Please sign in to comment.