| 57 | constexpr uint8_t PP2_TYPE_NETNS = 0x30; |
| 58 | |
| 59 | class ProxyProtocol |
| 60 | { |
| 61 | public: |
| 62 | ProxyProtocol() {} |
| 63 | ProxyProtocol(ProxyProtocolVersion pp_ver, uint16_t family, IpEndpoint src, IpEndpoint dst) |
| 64 | : version(pp_ver), ip_family(family), src_addr(src), dst_addr(dst) |
| 65 | { |
| 66 | } |
| 67 | ProxyProtocol(const ProxyProtocol &other) |
| 68 | : version(other.version), ip_family(other.ip_family), src_addr(other.src_addr), dst_addr(other.dst_addr) |
| 69 | { |
| 70 | if (!other.additional_data.empty()) { |
| 71 | set_additional_data(other.additional_data); |
| 72 | } |
| 73 | } |
| 74 | ProxyProtocol(ProxyProtocol &&other) |
| 75 | : version(other.version), ip_family(other.ip_family), src_addr(other.src_addr), dst_addr(other.dst_addr) |
| 76 | { |
| 77 | if (!other.additional_data.empty()) { |
| 78 | set_additional_data(other.additional_data); |
| 79 | } |
| 80 | other.additional_data.clear(); |
| 81 | other.tlv.clear(); |
| 82 | } |
| 83 | ~ProxyProtocol() = default; |
| 84 | int set_additional_data(std::string_view data); |
| 85 | void set_ipv4_addrs(in_addr_t src_addr, uint16_t src_port, in_addr_t dst_addr, uint16_t dst_port); |
| 86 | void set_ipv6_addrs(const in6_addr &src_addr, uint16_t src_port, const in6_addr &dst_addr, uint16_t dst_port); |
| 87 | |
| 88 | std::optional<std::string_view> get_tlv(const uint8_t tlvCode) const; |
| 89 | |
| 90 | ProxyProtocolVersion version = ProxyProtocolVersion::UNDEFINED; |
| 91 | uint16_t ip_family = AF_UNSPEC; |
| 92 | int type = 0; |
| 93 | IpEndpoint src_addr = {}; |
| 94 | IpEndpoint dst_addr = {}; |
| 95 | std::unordered_map<uint8_t, std::string_view> tlv; |
| 96 | |
| 97 | ProxyProtocol & |
| 98 | operator=(const ProxyProtocol &other) |
| 99 | { |
| 100 | if (&other == this) { |
| 101 | return *this; |
| 102 | } |
| 103 | version = other.version; |
| 104 | ip_family = other.ip_family; |
| 105 | src_addr = other.src_addr; |
| 106 | dst_addr = other.dst_addr; |
| 107 | if (!other.additional_data.empty()) { |
| 108 | set_additional_data(other.additional_data); |
| 109 | } else { |
| 110 | additional_data.clear(); |
| 111 | tlv.clear(); |
| 112 | } |
| 113 | return *this; |
| 114 | } |
| 115 | |
| 116 | ProxyProtocol & |