make format

pull/686/head
cathugger 5 years ago
parent a9dac85c28
commit 72b1ea613c
No known key found for this signature in database
GPG Key ID: 9BADDA2DAF6F01A8

@ -117,7 +117,8 @@ namespace llarp
dst = net::IPPacket::TruncateV6(m_Parent->GetIfAddr());
else
dst = pkt.dstv4();
pkt.UpdateIPv4Address(xhtonl(net::IPPacket::TruncateV6(m_IP)), xhtonl(dst));
pkt.UpdateIPv4Address(xhtonl(net::IPPacket::TruncateV6(m_IP)),
xhtonl(dst));
m_UpstreamQueue.emplace(pkt, counter);
m_TxRate += buf.underlying.sz;
m_LastActive = m_Parent->Now();

@ -366,7 +366,8 @@ namespace llarp
else if(msg.questions[0].qtype == dns::qTypeA
|| msg.questions[0].qtype == dns::qTypeAAAA)
{
const bool isV6 = msg.questions[0].qtype == dns::qTypeAAAA && SupportsV6();
const bool isV6 =
msg.questions[0].qtype == dns::qTypeAAAA && SupportsV6();
const bool isV4 = msg.questions[0].qtype == dns::qTypeA;
llarp::service::Address addr;
// on MacOS this is a typeA query
@ -414,7 +415,8 @@ namespace llarp
return EnsurePathToService(
addr,
[=](const Address &, OutboundContext *ctx) {
SendDNSReply(addr, ctx, replyMsg, reply, false, isV6 || !isV4);
SendDNSReply(addr, ctx, replyMsg, reply, false,
isV6 || !isV4);
},
2000);
}
@ -778,8 +780,7 @@ namespace llarp
{
return false;
}
pkt.UpdateIPv4Address(
xhtonl(net::IPPacket::TruncateV6(themIP)),
pkt.UpdateIPv4Address(xhtonl(net::IPPacket::TruncateV6(themIP)),
xhtonl(net::IPPacket::TruncateV6(usIP)));
}
else if(pkt.IsV6())

@ -220,7 +220,8 @@ namespace llarp
else
{
if(pkt.IsV4())
pkt.UpdateIPv4Address(xhtonl(pkt.srcv4()),
pkt.UpdateIPv4Address(
xhtonl(pkt.srcv4()),
xhtonl(net::IPPacket::TruncateV6(m_OurIP)));
else
return false;

@ -102,7 +102,6 @@ namespace llarp
return huint32_t{ntohl(Header()->daddr)};
}
#if 0
static uint32_t
ipchksum_pseudoIPv4(nuint32_t src_ip, nuint32_t dst_ip, uint8_t proto,
@ -141,7 +140,6 @@ namespace llarp
}
#endif
#define ADD32CS(x) ((uint32_t)(x & 0xFFff) + (uint32_t)(x >> 16))
#define SUB32CS(x) ((uint32_t)((~x) & 0xFFff) + (uint32_t)((~x) >> 16))
@ -150,10 +148,9 @@ namespace llarp
nuint32_t old_dst_ip, nuint32_t new_src_ip,
nuint32_t new_dst_ip)
{
uint32_t sum = uint32_t(old_sum.n) +
ADD32CS(old_src_ip.n) + ADD32CS(old_dst_ip.n) +
SUB32CS(new_src_ip.n) + SUB32CS(new_dst_ip.n);
uint32_t sum = uint32_t(old_sum.n) + ADD32CS(old_src_ip.n)
+ ADD32CS(old_dst_ip.n) + SUB32CS(new_src_ip.n)
+ SUB32CS(new_dst_ip.n);
// only need to do it 2 times to be sure
// proof: 0xFFff + 0xFFff = 0x1FFfe -> 0xFFff
@ -164,19 +161,26 @@ namespace llarp
}
static nuint16_t
deltaIPv6Checksum(nuint16_t old_sum,
const uint32_t old_src_ip[4], const uint32_t old_dst_ip[4],
const uint32_t new_src_ip[4], const uint32_t new_dst_ip[4])
deltaIPv6Checksum(nuint16_t old_sum, const uint32_t old_src_ip[4],
const uint32_t old_dst_ip[4],
const uint32_t new_src_ip[4],
const uint32_t new_dst_ip[4])
{
/* we don't actually care in what way integers are arranged in memory internally */
/* as long as uint16 pairs are swapped in correct direction, result will be correct (assuming there are no gaps in structure) */
/* we represent 128bit stuff there as 4 32bit ints, that should be more or less correct */
/* we could do 64bit ints too but then we couldn't reuse 32bit macros and that'd suck for 32bit cpus */
#define ADDN128CS(x) (ADD32CS(x[0]) + ADD32CS(x[1]) + ADD32CS(x[2]) + ADD32CS(x[3]))
#define SUBN128CS(x) (SUB32CS(x[0]) + SUB32CS(x[1]) + SUB32CS(x[2]) + SUB32CS(x[3]))
uint32_t sum = uint32_t(old_sum.n) +
ADDN128CS(old_src_ip) + ADDN128CS(old_dst_ip) +
SUBN128CS(new_src_ip) + SUBN128CS(new_dst_ip);
/* we don't actually care in what way integers are arranged in memory
* internally */
/* as long as uint16 pairs are swapped in correct direction, result will
* be correct (assuming there are no gaps in structure) */
/* we represent 128bit stuff there as 4 32bit ints, that should be more or
* less correct */
/* we could do 64bit ints too but then we couldn't reuse 32bit macros and
* that'd suck for 32bit cpus */
#define ADDN128CS(x) \
(ADD32CS(x[0]) + ADD32CS(x[1]) + ADD32CS(x[2]) + ADD32CS(x[3]))
#define SUBN128CS(x) \
(SUB32CS(x[0]) + SUB32CS(x[1]) + SUB32CS(x[2]) + SUB32CS(x[3]))
uint32_t sum = uint32_t(old_sum.n) + ADDN128CS(old_src_ip)
+ ADDN128CS(old_dst_ip) + SUBN128CS(new_src_ip)
+ SUBN128CS(new_dst_ip);
#undef ADDN128CS
#undef SUBN128CS
@ -191,7 +195,6 @@ namespace llarp
#undef ADD32CS
#undef SUB32CS
static void
deltaChecksumIPv4TCP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz,
size_t fragoff, size_t chksumoff, nuint32_t oSrcIP,
@ -231,7 +234,6 @@ namespace llarp
check->n = 0x0000;
}
static void
deltaChecksumIPv4UDP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz,
size_t fragoff, nuint32_t oSrcIP, nuint32_t oDstIP,
@ -257,9 +259,9 @@ namespace llarp
static void
deltaChecksumIPv6UDP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz,
size_t fragoff,
const uint32_t oSrcIP[4], const uint32_t oDstIP[4],
const uint32_t nSrcIP[4], const uint32_t nDstIP[4])
size_t fragoff, const uint32_t oSrcIP[4],
const uint32_t oDstIP[4], const uint32_t nSrcIP[4],
const uint32_t nDstIP[4])
{
if(fragoff > 6)
return;
@ -286,7 +288,6 @@ namespace llarp
// check->n = 0xFFff;
}
void
IPPacket::UpdateIPv4Address(nuint32_t nSrcIP, nuint32_t nDstIP)
{
@ -363,14 +364,17 @@ namespace llarp
switch(hdr->proto)
{
case 6: // TCP
deltaChecksumIPv6TCP(pld, psz, fragoff, 16, oSrcIP, oDstIP, nSrcIP, nDstIP);
deltaChecksumIPv6TCP(pld, psz, fragoff, 16, oSrcIP, oDstIP, nSrcIP,
nDstIP);
break;
case 17: // UDP
case 136: // UDP-Lite - same checksum place, same 0->0xFFff condition
deltaChecksumIPv6UDP(pld, psz, fragoff, oSrcIP, oDstIP, nSrcIP, nDstIP);
deltaChecksumIPv6UDP(pld, psz, fragoff, oSrcIP, oDstIP, nSrcIP,
nDstIP);
break;
case 33: // DCCP
deltaChecksumIPv6TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, nDstIP);
deltaChecksumIPv6TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP,
nDstIP);
break;
}
}

Loading…
Cancel
Save