Skip to content

Commit

Permalink
Adding "so_bindtodevice_check config" opt (#28)
Browse files Browse the repository at this point in the history
* adding a new config opt: so_bindtodevice_check ...

* adding so_bindtodevice doku ...

* Changelog update ...
  • Loading branch information
scuzzilla authored May 29, 2024
1 parent a05c0ea commit 743fd1a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
5 changes: 5 additions & 0 deletions doc/CONFIG-KEYS
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ VALUES: [value >= "1" and value <= "5"]
DESC: Defining the amount of running threads busy with processing incoming Huawei's gRPC messages.
DEFAULT: "1"

KEY: so_bindtodevice_check
VALUES: ["true" or "false"]
DESC: When set to "false", this disables the checks related to socket binding to a particular device.
DEFAULT: "true"

KEY: writer_id
DESC: adding meta data information to the data-stream. This could be helpful to identify the collector sourcing the data-stream.
Irrelevant when used in Library mode, pmtelemetryd will override this information.
Expand Down
3 changes: 2 additions & 1 deletion doc/Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ The keys used are:
!: fixed/modified feature, -: deleted feature, +: new feature


current (main branch) -- 05-12-2023
current (main branch) -- 29-05-2024
+ Adding the ability to disable the checks related to socket binding to a particular device

v1.1.4 -- 05-12-2023
+ Adding automatic version number retrieval from the VERSION file
Expand Down
19 changes: 13 additions & 6 deletions src/core/mdt_dialout_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ bool CustomSocketMutator::bindtodevice_socket_mutator(int fd)
int type;
socklen_t len = sizeof(type);

std::string iface = main_cfg_parameters.at("iface");
const std::string iface = main_cfg_parameters.at("iface");
const std::string sbc = main_cfg_parameters.at("so_bindtodevice_check");

if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &len) != 0) {
spdlog::get("multi-logger")->
Expand All @@ -68,12 +69,18 @@ bool CustomSocketMutator::bindtodevice_socket_mutator(int fd)
std::abort();
}

if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
iface.c_str(), strlen(iface.c_str())) != 0) {
if (sbc.compare("true") == 0) {
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
iface.c_str(), strlen(iface.c_str())) != 0) {
spdlog::get("multi-logger")->
error("[CustomSocketMutator()]: Unable to bind [{}] "
"on the configured socket(s)", iface);
std::abort();
}
} else {
spdlog::get("multi-logger")->
error("[CustomSocketMutator()]: Unable to bind [{}] "
"on the configured socket(s)", iface);
std::abort();
warn("[CustomSocketMutator()]: SO_BINDTODEVICE "
"check disabled");
}

log_socket_options(fd);
Expand Down
27 changes: 27 additions & 0 deletions src/utils/cfg_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,33 @@ bool MainCfgHandler::lookup_main_parameters(const std::string &cfg_path,
return false;
}

bool so_bindtodevice_check = main_params.exists("so_bindtodevice_check");
if (so_bindtodevice_check == true) {
libconfig::Setting &so_bindtodevice_check =
main_params.lookup("so_bindtodevice_check");
try {
std::string so_bindtodevice_check_s = so_bindtodevice_check;
if (so_bindtodevice_check_s.empty() == false &&
(so_bindtodevice_check_s.compare("true") == 0 ||
so_bindtodevice_check_s.compare("false") == 0 )) {
params.insert({"so_bindtodevice_check", so_bindtodevice_check_s});
} else {
spdlog::get("multi-logger")->
error("[so_bindtodevice_check] configuration "
"issue: [ {} ] is an invalid value",
so_bindtodevice_check_s);
return false;
}
} catch (const libconfig::SettingTypeException &ste) {
spdlog::get("multi-logger")->
error("[so_bindtodevice_check] configuration issue: "
"{}", ste.what());
return false;
}
} else {
params.insert({"so_bindtodevice_check", "true"});
}

std::string ipv4_socket_cisco_s;
bool ipv4_socket_cisco = main_params.exists("ipv4_socket_cisco");
if (ipv4_socket_cisco == true) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/cfg_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class MainCfgHandler {
const std::string juniper_workers;
const std::string huawei_workers;
const std::string data_delivery_method;
const std::string so_bindtodevice_check;
};

// Data manipulation configuration parameters
Expand Down

0 comments on commit 743fd1a

Please sign in to comment.