Improve CLI error handling for setmtu command

This commit is contained in:
Joseph Henry 2024-03-05 00:13:07 -08:00
parent 9724e04e6e
commit bbe97dd080
No known key found for this signature in database
GPG Key ID: C45B33FF5EBC9344
2 changed files with 13 additions and 4 deletions

View File

@ -591,7 +591,7 @@ static int cli(int argc,char **argv)
printf("200 setmtu OK" ZT_EOL_S); printf("200 setmtu OK" ZT_EOL_S);
return 0; return 0;
} else { } 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 1;
} }
return 0; return 0;

View File

@ -1543,7 +1543,7 @@ public:
// control plane endpoints // control plane endpoints
std::string bondShowPath = "/bond/show/([0-9a-fA-F]{10})"; std::string bondShowPath = "/bond/show/([0-9a-fA-F]{10})";
std::string bondRotatePath = "/bond/rotate/([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 configPath = "/config";
std::string configPostPath = "/config/settings"; std::string configPostPath = "/config/settings";
std::string healthPath = "/health"; std::string healthPath = "/health";
@ -1719,12 +1719,21 @@ public:
auto setMtu = [&, setContent](const httplib::Request &req, httplib::Response &res) { auto setMtu = [&, setContent](const httplib::Request &req, httplib::Response &res) {
if (!_node->bondController()->inUse()) { 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; res.status = 400;
return; 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; 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, "{}"); setContent(req, res, "{}");
}; };
_controlPlane.Post(setBondMtuPath, setMtu); _controlPlane.Post(setBondMtuPath, setMtu);