Browse Source

Improve CLI error handling for setmtu command

pull/4/head
Joseph Henry 2 years ago
parent
commit
bbe97dd080
No known key found for this signature in database
GPG Key ID: C45B33FF5EBC9344
  1. 2
      one.cpp
  2. 15
      service/OneService.cpp

2
one.cpp

@ -591,7 +591,7 @@ static int cli(int argc,char **argv)
printf("200 setmtu OK" ZT_EOL_S);
return 0;
} else {
printf("no link match found, new MTU was not applied" ZT_EOL_S);
printf("%d Failed to set MTU: %s" ZT_EOL_S, scode, responseBody.c_str());
return 1;
}
return 0;

15
service/OneService.cpp

@ -1543,7 +1543,7 @@ public:
// control plane endpoints
std::string bondShowPath = "/bond/show/([0-9a-fA-F]{10})";
std::string bondRotatePath = "/bond/rotate/([0-9a-fA-F]{10})";
std::string setBondMtuPath = "/bond/setmtu/([0-9]{3,5})/([a-zA-Z0-9_]{1,16})/([0-9a-fA-F\\.\\:]{1,39})";
std::string setBondMtuPath = "/bond/setmtu/([0-9]{1,6})/([a-zA-Z0-9_]{1,16})/([0-9a-fA-F\\.\\:]{1,39})";
std::string configPath = "/config";
std::string configPostPath = "/config/settings";
std::string healthPath = "/health";
@ -1719,12 +1719,21 @@ public:
auto setMtu = [&, setContent](const httplib::Request &req, httplib::Response &res) {
if (!_node->bondController()->inUse()) {
setContent(req, res, "");
setContent(req, res, "Bonding layer isn't active yet");
res.status = 400;
return;
}
uint32_t mtu = atoi(req.matches[1].str().c_str());
if (mtu < 68 || mtu > 65535) {
setContent(req, res, "Specified MTU is not reasonable");
res.status = 400;
return;
}
uint16_t mtu = atoi(req.matches[1].str().c_str());
res.status = _node->bondController()->setAllMtuByTuple(mtu, req.matches[2].str().c_str(), req.matches[3].str().c_str()) ? 200 : 400;
if (res.status == 400) {
setContent(req, res, "Unable to find specified link");
return;
}
setContent(req, res, "{}");
};
_controlPlane.Post(setBondMtuPath, setMtu);

Loading…
Cancel
Save