1
#pragma once
2

            
3
#include <cstdint>
4
#include <vector>
5

            
6
#include "envoy/config/core/v3/socket_option.pb.h"
7
#include "envoy/network/socket.h"
8

            
9
#include "source/common/common/logger.h"
10

            
11
#include "absl/types/optional.h"
12

            
13
namespace Envoy {
14
namespace Cilium {
15

            
16
// Socket Option that sets the socket option SO_MARK on the socket.
17
// The mark contains the Cilium magic mark, cluster and security identity.
18
// It uses the Cilium Privileged Service to call out to the starter process to do the actual
19
// privileged syscall - as the Envoy process itself doesn't have the required capabilities.
20
class CiliumMarkSocketOption : public Network::Socket::Option,
21
                               public Logger::Loggable<Logger::Id::filter> {
22
public:
23
  CiliumMarkSocketOption(uint32_t mark);
24
  absl::optional<Network::Socket::Option::Details>
25
  getOptionDetails(const Network::Socket&,
26
                   envoy::config::core::v3::SocketOption::SocketState) const override {
27
    return absl::nullopt;
28
  }
29

            
30
  bool setOption(Network::Socket& socket,
31
                 envoy::config::core::v3::SocketOption::SocketState state) const override;
32

            
33
  void hashKey([[maybe_unused]] std::vector<uint8_t>& key) const override {}
34

            
35
  bool isSupported() const override { return true; }
36

            
37
  uint32_t mark_;
38
};
39

            
40
} // namespace Cilium
41
} // namespace Envoy