Add refcounting to Mac and Linux QoS state to ensure it works properly with multiple clients

This means we can't control DSCP tagging per-client, but it shouldn't pose a big problem as routers that blackhole DSCP tagged traffic are pretty rare.
This commit is contained in:
Cameron Gutman 2024-02-01 18:17:12 -06:00
commit bb3b7984f3
2 changed files with 28 additions and 10 deletions

View file

@ -584,16 +584,25 @@ namespace platf {
return true;
}
// We can't track QoS state separately for each destination on this OS,
// so we keep a ref count to only disable QoS options when all clients
// are disconnected.
static std::atomic<int> qos_ref_count = 0;
class qos_t: public deinit_t {
public:
qos_t(int sockfd, std::vector<std::tuple<int, int, int>> options):
sockfd(sockfd), options(options) {}
sockfd(sockfd), options(options) {
qos_ref_count++;
}
virtual ~qos_t() {
for (const auto &tuple : options) {
auto reset_val = std::get<2>(tuple);
if (setsockopt(sockfd, std::get<0>(tuple), std::get<1>(tuple), &reset_val, sizeof(reset_val)) < 0) {
BOOST_LOG(warning) << "Failed to reset option: "sv << errno;
if (--qos_ref_count == 0) {
for (const auto &tuple : options) {
auto reset_val = std::get<2>(tuple);
if (setsockopt(sockfd, std::get<0>(tuple), std::get<1>(tuple), &reset_val, sizeof(reset_val)) < 0) {
BOOST_LOG(warning) << "Failed to reset option: "sv << errno;
}
}
}
}

View file

@ -407,16 +407,25 @@ namespace platf {
return true;
}
// We can't track QoS state separately for each destination on this OS,
// so we keep a ref count to only disable QoS options when all clients
// are disconnected.
static std::atomic<int> qos_ref_count = 0;
class qos_t: public deinit_t {
public:
qos_t(int sockfd, std::vector<std::tuple<int, int, int>> options):
sockfd(sockfd), options(options) {}
sockfd(sockfd), options(options) {
qos_ref_count++;
}
virtual ~qos_t() {
for (const auto &tuple : options) {
auto reset_val = std::get<2>(tuple);
if (setsockopt(sockfd, std::get<0>(tuple), std::get<1>(tuple), &reset_val, sizeof(reset_val)) < 0) {
BOOST_LOG(warning) << "Failed to reset option: "sv << errno;
if (--qos_ref_count == 0) {
for (const auto &tuple : options) {
auto reset_val = std::get<2>(tuple);
if (setsockopt(sockfd, std::get<0>(tuple), std::get<1>(tuple), &reset_val, sizeof(reset_val)) < 0) {
BOOST_LOG(warning) << "Failed to reset option: "sv << errno;
}
}
}
}