Skip to content

Commit

Permalink
allow GRE socket to bind to specific interface
Browse files Browse the repository at this point in the history
  • Loading branch information
astibal committed May 6, 2024
1 parent 530ba6d commit af3d3d8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion socle
13 changes: 12 additions & 1 deletion src/service/cfgapi/cfgapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ bool CfgFactory::upgrade_schema(int upgrade_to_num) {
log.event(INF, "added settings.webhook.bind_interface");
return true;
}
else if(upgrade_to_num == 1028) {
log.event(INF, "added captures.remote.bind_interface");
return true;
}

return false;
}
Expand Down Expand Up @@ -949,6 +953,7 @@ bool CfgFactory::load_captures() {
load_if_exists(remote, "tun_type", CfgFactory::get()->capture_remote.tun_type);
load_if_exists(remote, "tun_dst", CfgFactory::get()->capture_remote.tun_dst);
load_if_exists(remote, "tun_ttl", CfgFactory::get()->capture_remote.tun_ttl);
load_if_exists(remote, "bind_interface", CfgFactory::get()->capture_remote.bind_interface);

CfgFactory::gre_export_apply(&traflog::PcapLog::single_instance());
}
Expand Down Expand Up @@ -2929,8 +2934,13 @@ void CfgFactory::gre_export_apply(traflog::PcapLog* pcaplog) {

auto exp = std::make_shared<traflog::GreExporter>(fam, ip);
pcaplog->ip_packet_hook = exp;
if(cfg->capture_remote.tun_ttl > 0)

if(cfg->capture_remote.tun_ttl > 0) {
exp->ttl(cfg->capture_remote.tun_ttl);
}
if(not cfg->capture_remote.bind_interface.empty()) {
exp->bind_if(cfg->capture_remote.bind_interface);
}

} else {
pcaplog->ip_packet_hook.reset();
Expand Down Expand Up @@ -5098,6 +5108,7 @@ int CfgFactory::save_captures(Config& ex) const {
remote.add("tun_type", Setting::TypeString) = CfgFactory::get()->capture_remote.tun_type;
remote.add("tun_dst", Setting::TypeString) = CfgFactory::get()->capture_remote.tun_dst;
remote.add("tun_ttl", Setting::TypeInt) = CfgFactory::get()->capture_remote.tun_ttl;
remote.add("bind_interface", Setting::TypeString) = CfgFactory::get()->capture_remote.bind_interface;


if(not objects.exists("options"))
Expand Down
3 changes: 2 additions & 1 deletion src/service/cfgapi/cfgapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class CfgFactory : public CfgFactoryBase {
public:
// Each version bump implies a config upgrade - we start on 1000
// see upgrade_schema() - control config upgrade
constexpr static inline const int SCHEMA_VERSION = 1027;
constexpr static inline const int SCHEMA_VERSION = 1028;

static inline std::atomic_bool LOAD_ERRORS = false;

Expand Down Expand Up @@ -341,6 +341,7 @@ class CfgFactory : public CfgFactoryBase {
std::string tun_type = "gre";
std::string tun_dst = "127.0.0.1";
int tun_ttl {1};
std::string bind_interface;
} capture_remote;

struct {
Expand Down

0 comments on commit af3d3d8

Please sign in to comment.