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 exception with stoul for droppruning #573

Merged
merged 1 commit into from
Jun 28, 2024
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
3 changes: 2 additions & 1 deletion .travis/travis-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ popd
pushd agent-ovs
export LD_LIBRARY_PATH=/usr/local/lib
./autogen.sh &> /dev/null
./configure --enable-coverage --enable-gprof --enable-grpc &> /dev/null
# --enable-grpc
./configure --enable-coverage --enable-gprof &> /dev/null
make -j2
sudo make install
set +e
Expand Down
33 changes: 24 additions & 9 deletions agent-ovs/lib/FSPacketDropLogConfigSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,49 @@ static int validateMacMask(const std::string& arg,
}
return 0;
}
static int validatePrefix(int filter_idx, const std::string & arg,
optional<boost::asio::ip::address> &addr, optional<uint8_t> &pfxLen) {
static int validatePrefix(int filter_idx, const std::string & arg,
optional<boost::asio::ip::address> &addr, optional<uint8_t> &pfxLen) {
using namespace boost;
int ret=0;
if(arg.empty()) {
return ret;
}
std::string address_string = arg;
string address_string = arg;
string pfxLenArg;
bool maskPresent = false;
if(arg.find('/') != std::string::npos) {
std::vector<std::string> splitVec;
split(splitVec,arg, is_any_of("/"), token_compress_on);
address_string = splitVec[0];
pfxLen = strtol(splitVec[1].c_str(),NULL,10);
pfxLenArg = splitVec[1];
maskPresent = true;
}
boost::system::error_code ec;
addr = asio::ip::address::from_string(address_string, ec);
if (ec) {
LOG(ERROR) << "Invalid address for filter " << filter_idx;
return -1;
}
if(pfxLen) {
if(!pfxLenArg.empty()) {
LOG(INFO) << "PrefixLen is set!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that this is already merged, but do we feel that this should be an INFO level log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No doesn't need to be, missed removing it post debug. Can be removed with some later commit. Thanks

size_t *end = nullptr;
uint8_t pfxLenVal;
try {
pfxLenVal = stoul(pfxLenArg, end, 10);
} catch (std::exception const& ex) {
LOG(ERROR) << "Incorrect prefix length for filter" << filter_idx;
return -1;
}
if(addr.get().is_v4()) {
ret = (pfxLen.get()>32 || pfxLen.get()==0)?-1:0;
ret = (pfxLenVal>32)?-1:0;
} else {
ret = (pfxLen.get()>128 || pfxLen.get()==0)?-1:0;
ret = (pfxLenVal>128)?-1:0;
}
if (ret == 0) {
pfxLen = pfxLenVal;
}
} else {
pfxLen = (addr.get().is_v4()?32:128);
} else if(maskPresent) {
ret = -1;
}
if(ret != 0) {
LOG(ERROR) << "Incorrect prefix length for filter" << filter_idx;
Expand Down
1 change: 0 additions & 1 deletion agent-ovs/lib/test/ExtraConfigManager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ BOOST_FIXTURE_TEST_CASE( droplogpruneconfigsource, FSConfigFixture ) {
boost::optional<shared_ptr<DropPruneConfig>> dropPruneCfg = DropPruneConfig::resolve(agent.getFramework(), dropPruneUri);
BOOST_CHECK(dropPruneCfg.get()->getFilterName().get() == "flt1");
BOOST_CHECK(dropPruneCfg.get()->getSrcAddress().get() == "1.2.3.4");
BOOST_CHECK(dropPruneCfg.get()->getSrcPrefixLen().get() == 32);
BOOST_CHECK(dropPruneCfg.get()->getDstAddress().get() == "5.6.7.0");
BOOST_CHECK(dropPruneCfg.get()->getDstPrefixLen().get() == 24);
BOOST_CHECK(dropPruneCfg.get()->getSrcMac().get().toString() == "00:01:02:03:04:05");
Expand Down
4 changes: 2 additions & 2 deletions agent-ovs/ovs/OVSRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,15 @@ static void convertPruneFilter(std::shared_ptr<PacketDropLogPruneSpec> &sourceSp
}
if(sourceSpec->srcPfxLen) {
std::stringstream strSrcPfxLen;
strSrcPfxLen << sourceSpec->srcPfxLen.get();
strSrcPfxLen << (uint8_t)sourceSpec->srcPfxLen.get();
filter->setField(TFLD_SPFX_LEN,strSrcPfxLen.str());
}
if(sourceSpec->dstIp) {
filter->setField(TFLD_DST_IP,sourceSpec->dstIp.get().to_string());
}
if(sourceSpec->dstPfxLen) {
std::stringstream strDstPfxLen;
strDstPfxLen << sourceSpec->dstPfxLen.get();
strDstPfxLen << (uint8_t)sourceSpec->dstPfxLen.get();
filter->setField(TFLD_DPFX_LEN,strDstPfxLen.str());
}
if(sourceSpec->srcMac) {
Expand Down
6 changes: 5 additions & 1 deletion agent-ovs/ovs/include/PacketLogHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ class PacketFilterSpec: public PacketTuple {
pfxLen = 128;
}
if(!prefixLen.empty()) {
pfxLen = stoul(prefixLen);
try {
pfxLen = stoul(prefixLen);
} catch(std::exception const& ex) {
/*Should not get here as value is already vetted*/
}
}
if((pfxLen > 128) || (pfxLen == 0))
return false;
Expand Down