From 98b3f44d3ecaed5550cf3353052c1b8537c4f020 Mon Sep 17 00:00:00 2001 From: "Parzych, Hubert" Date: Tue, 10 Oct 2023 08:46:10 +0200 Subject: [PATCH] feat: Add process PID to SessionMeta --- libebpfdiscovery/src/Discovery.cpp | 4 +--- libebpfdiscoveryshared/headers/ebpfdiscoveryshared/Types.h | 1 + libebpfdiscoveryskel/src/Handlers.h | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libebpfdiscovery/src/Discovery.cpp b/libebpfdiscovery/src/Discovery.cpp index b0af007c..294907f4 100644 --- a/libebpfdiscovery/src/Discovery.cpp +++ b/libebpfdiscovery/src/Discovery.cpp @@ -27,7 +27,6 @@ namespace ebpfdiscovery { static void printSession(const Session& session, const DiscoverySessionMeta& meta) { const auto& request{session.parser.result}; std::cout << request.method << " " << request.host << request.url; - if (const auto& xForwardedFor{request.xForwardedFor}; !xForwardedFor.empty()) { std::cout << " X-Forwarded-For: " << '"' << xForwardedFor << '"'; } else if (discoverySessionFlagsIsIPv4(meta.flags)) { @@ -37,8 +36,7 @@ static void printSession(const Session& session, const DiscoverySessionMeta& met if (auto srcIpv6{ipv6ToString(meta.sourceIPData)}; !srcIpv6.empty()) std::cout << " srcIpv6: " << '"' << srcIpv6 << '"'; } - - std::cout << '\n'; + std::cout << " pid: " << meta.pid << '\n'; } Discovery::Discovery() : Discovery(DiscoveryConfig{}) { diff --git a/libebpfdiscoveryshared/headers/ebpfdiscoveryshared/Types.h b/libebpfdiscoveryshared/headers/ebpfdiscoveryshared/Types.h index 29ac5b66..c48fc93c 100644 --- a/libebpfdiscoveryshared/headers/ebpfdiscoveryshared/Types.h +++ b/libebpfdiscoveryshared/headers/ebpfdiscoveryshared/Types.h @@ -134,6 +134,7 @@ __attribute__((always_inline)) inline static void discoverySessionFlagsSetIPv6(D struct DiscoverySessionMeta { __u8 sourceIPData[16]; DiscoverySessionFlags flags; + __u32 pid; }; struct DiscoverySession { diff --git a/libebpfdiscoveryskel/src/Handlers.h b/libebpfdiscoveryskel/src/Handlers.h index b870810b..69e56e0e 100644 --- a/libebpfdiscoveryskel/src/Handlers.h +++ b/libebpfdiscoveryskel/src/Handlers.h @@ -150,6 +150,7 @@ __attribute__((always_inline)) inline static void handleRead( } sessionPtr->id = allSessionStatePtr->sessionCounter; + sessionPtr->meta.pid = event.dataKey.pid; allSessionStatePtr->sessionCounter++; sessionFillIP((struct DiscoveryTrackedSessionKey*)&event.dataKey, sessionPtr); } else {