Skip to content

Commit 743fd1a

Browse files
authored
Adding "so_bindtodevice_check config" opt (#28)
* adding a new config opt: so_bindtodevice_check ... * adding so_bindtodevice doku ... * Changelog update ...
1 parent a05c0ea commit 743fd1a

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

doc/CONFIG-KEYS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ VALUES: [value >= "1" and value <= "5"]
6262
DESC: Defining the amount of running threads busy with processing incoming Huawei's gRPC messages.
6363
DEFAULT: "1"
6464

65+
KEY: so_bindtodevice_check
66+
VALUES: ["true" or "false"]
67+
DESC: When set to "false", this disables the checks related to socket binding to a particular device.
68+
DEFAULT: "true"
69+
6570
KEY: writer_id
6671
DESC: adding meta data information to the data-stream. This could be helpful to identify the collector sourcing the data-stream.
6772
Irrelevant when used in Library mode, pmtelemetryd will override this information.

doc/Changelog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ The keys used are:
77
!: fixed/modified feature, -: deleted feature, +: new feature
88

99

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

1213
v1.1.4 -- 05-12-2023
1314
+ Adding automatic version number retrieval from the VERSION file

src/core/mdt_dialout_core.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ bool CustomSocketMutator::bindtodevice_socket_mutator(int fd)
5959
int type;
6060
socklen_t len = sizeof(type);
6161

62-
std::string iface = main_cfg_parameters.at("iface");
62+
const std::string iface = main_cfg_parameters.at("iface");
63+
const std::string sbc = main_cfg_parameters.at("so_bindtodevice_check");
6364

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

71-
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
72-
iface.c_str(), strlen(iface.c_str())) != 0) {
72+
if (sbc.compare("true") == 0) {
73+
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
74+
iface.c_str(), strlen(iface.c_str())) != 0) {
75+
spdlog::get("multi-logger")->
76+
error("[CustomSocketMutator()]: Unable to bind [{}] "
77+
"on the configured socket(s)", iface);
78+
std::abort();
79+
}
80+
} else {
7381
spdlog::get("multi-logger")->
74-
error("[CustomSocketMutator()]: Unable to bind [{}] "
75-
"on the configured socket(s)", iface);
76-
std::abort();
82+
warn("[CustomSocketMutator()]: SO_BINDTODEVICE "
83+
"check disabled");
7784
}
7885

7986
log_socket_options(fd);

src/utils/cfg_handler.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,33 @@ bool MainCfgHandler::lookup_main_parameters(const std::string &cfg_path,
287287
return false;
288288
}
289289

290+
bool so_bindtodevice_check = main_params.exists("so_bindtodevice_check");
291+
if (so_bindtodevice_check == true) {
292+
libconfig::Setting &so_bindtodevice_check =
293+
main_params.lookup("so_bindtodevice_check");
294+
try {
295+
std::string so_bindtodevice_check_s = so_bindtodevice_check;
296+
if (so_bindtodevice_check_s.empty() == false &&
297+
(so_bindtodevice_check_s.compare("true") == 0 ||
298+
so_bindtodevice_check_s.compare("false") == 0 )) {
299+
params.insert({"so_bindtodevice_check", so_bindtodevice_check_s});
300+
} else {
301+
spdlog::get("multi-logger")->
302+
error("[so_bindtodevice_check] configuration "
303+
"issue: [ {} ] is an invalid value",
304+
so_bindtodevice_check_s);
305+
return false;
306+
}
307+
} catch (const libconfig::SettingTypeException &ste) {
308+
spdlog::get("multi-logger")->
309+
error("[so_bindtodevice_check] configuration issue: "
310+
"{}", ste.what());
311+
return false;
312+
}
313+
} else {
314+
params.insert({"so_bindtodevice_check", "true"});
315+
}
316+
290317
std::string ipv4_socket_cisco_s;
291318
bool ipv4_socket_cisco = main_params.exists("ipv4_socket_cisco");
292319
if (ipv4_socket_cisco == true) {

src/utils/cfg_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class MainCfgHandler {
142142
const std::string juniper_workers;
143143
const std::string huawei_workers;
144144
const std::string data_delivery_method;
145+
const std::string so_bindtodevice_check;
145146
};
146147

147148
// Data manipulation configuration parameters

0 commit comments

Comments
 (0)