]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/proxyp/Header.cc
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "proxyp/Elements.h"
11 #include "proxyp/Header.h"
12 #include "sbuf/Stream.h"
13 #include "sbuf/StringConvert.h"
14 #include "SquidConfig.h"
17 ProxyProtocol::Header::Header(const SBuf
&ver
, const Two::Command cmd
):
20 ignoreAddresses_(false)
24 ProxyProtocol::Header::toMime() const
27 for (const auto &p
: PseudoHeaderFields
) {
28 const auto value
= getValues(p
.second
);
30 result
<< p
.first
<< ": " << value
<< "\r\n";
32 // cannot reuse Header::getValues(): need the original TLVs layout
33 for (const auto &tlv
: tlvs
)
34 result
<< tlv
.type
<< ": " << tlv
.value
<< "\r\n";
39 ProxyProtocol::Header::getValues(const uint32_t headerType
, const char sep
) const
43 case Two::htPseudoVersion
:
46 case Two::htPseudoCommand
:
47 return ToSBuf(command_
);
49 case Two::htPseudoSrcAddr
: {
52 auto logAddr
= sourceAddress
;
53 logAddr
.applyClientMask(Config
.Addrs
.client_netmask
);
54 char ipBuf
[MAX_IPSTRLEN
];
55 return SBuf(logAddr
.toStr(ipBuf
, sizeof(ipBuf
)));
58 case Two::htPseudoDstAddr
: {
61 char ipBuf
[MAX_IPSTRLEN
];
62 return SBuf(destinationAddress
.toStr(ipBuf
, sizeof(ipBuf
)));
65 case Two::htPseudoSrcPort
: {
66 return hasAddresses() ? ToSBuf(sourceAddress
.port()) : SBuf();
69 case Two::htPseudoDstPort
: {
70 return hasAddresses() ? ToSBuf(destinationAddress
.port()) : SBuf();
75 for (const auto &m
: tlvs
) {
76 if (m
.type
== headerType
) {
77 // XXX: result.tellp() always returns -1
78 if (!result
.buf().isEmpty())
89 ProxyProtocol::Header::getElem(const uint32_t headerType
, const char *member
, const char sep
) const
91 const auto whole
= SBufToString(getValues(headerType
, sep
));
92 return getListMember(whole
, member
, sep
);
96 ProxyProtocol::Header::addressFamily() const
98 static const SBuf
v4("4");
99 static const SBuf
v6("6");
100 static const SBuf
vMix("mix");
102 (sourceAddress
.isIPv6() && destinationAddress
.isIPv6()) ? v6
:
103 (sourceAddress
.isIPv4() && destinationAddress
.isIPv4()) ? v4
: