From 891f5d156cd46a18d82f9bb4b3a556da0e10d174 Mon Sep 17 00:00:00 2001 From: cathugger Date: Tue, 11 Jun 2019 23:17:59 +0300 Subject: [PATCH 1/6] net/ip: cleanup --- llarp/net/ip.cpp | 230 ++++++++++++++++++----------------------------- 1 file changed, 87 insertions(+), 143 deletions(-) diff --git a/llarp/net/ip.cpp b/llarp/net/ip.cpp index 8b8cc6cb8..32cb169c5 100644 --- a/llarp/net/ip.cpp +++ b/llarp/net/ip.cpp @@ -20,12 +20,12 @@ namespace llarp { #if __BYTE_ORDER == __BIG_ENDIAN return huint128_t{addr.s6_addr32[0]} - | (huint128_t{addr.s6_addr32[1]} << 32) + | (huint128_t{addr.s6_addr32[1]} << 32) | (huint128_t{addr.s6_addr32[2]} << 64) | (huint128_t{addr.s6_addr32[3]} << 96); #else return huint128_t{ntohl(addr.s6_addr32[3])} - | (huint128_t{ntohl(addr.s6_addr32[2])} << 32) + | (huint128_t{ntohl(addr.s6_addr32[2])} << 32) | (huint128_t{ntohl(addr.s6_addr32[1])} << 64) | (huint128_t{ntohl(addr.s6_addr32[0])} << 96); #endif @@ -102,26 +102,6 @@ namespace llarp return huint32_t{ntohl(Header()->daddr)}; } - void - IPPacket::UpdateV6Address(huint128_t src, huint128_t dst) - { - if(sz <= 40) - return; - auto hdr = HeaderV6(); - auto oldSrc = hdr->srcaddr; - auto oldDst = hdr->dstaddr; - hdr->srcaddr = HUIntToIn6(src); - hdr->dstaddr = HUIntToIn6(dst); - const size_t ihs = 40; - auto pld = buf + ihs; - auto psz = sz - ihs; - switch(hdr->proto) - { - //tcp - case 6: - return; - } - } #if 0 static uint32_t @@ -161,84 +141,16 @@ namespace llarp } #endif - static nuint16_t - deltaIPv4Checksum(nuint16_t old_sum, nuint32_t old_src_ip, - nuint32_t old_dst_ip, nuint32_t new_src_ip, - nuint32_t new_dst_ip) - { -#define ADDIPCS(x) ((uint32_t)(x.n & 0xFFff) + (uint32_t)(x.n >> 16)) -#define SUBIPCS(x) ((uint32_t)((~x.n) & 0xFFff) + (uint32_t)((~x.n) >> 16)) - - uint32_t sum = uint32_t(old_sum.n) + ADDIPCS(old_src_ip) - + ADDIPCS(old_dst_ip) + SUBIPCS(new_src_ip) + SUBIPCS(new_dst_ip); - -#undef ADDIPCS -#undef SUBIPCS - - // only need to do it 2 times to be sure - // proof: 0xFFff + 0xFFff = 0x1FFfe -> 0xFFff - sum = (sum & 0xFFff) + (sum >> 16); - sum += sum >> 16; - - return nuint16_t{uint16_t(sum & 0xFFff)}; - } - - static void - checksumDstIPv4TCP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, - size_t fragoff, size_t chksumoff, nuint32_t oSrcIP, - nuint32_t oDstIP, nuint32_t nSrcIP, nuint32_t nDstIP) - { - if(fragoff > chksumoff) - return; - - auto check = (nuint16_t *)(pld + chksumoff - fragoff); - - *check = deltaIPv4Checksum(*check, oSrcIP, oDstIP, nSrcIP, nDstIP); - // usually, TCP checksum field cannot be 0xFFff, - // because one's complement addition cannot result in 0x0000, - // and there's inversion in the end; - // emulate that. - if(check->n == 0xFFff) - check->n = 0x0000; - } - - static void - checksumDstIPv4UDP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, - size_t fragoff, nuint32_t oSrcIP, nuint32_t oDstIP, - nuint32_t nSrcIP, nuint32_t nDstIP) - { - if(fragoff > 6) - return; - - auto check = (nuint16_t *)(pld + 6); - if(check->n == 0x0000) - return; // 0 is used to indicate "no checksum", don't change - - *check = deltaIPv4Checksum(*check, oSrcIP, oDstIP, nSrcIP, nDstIP); - // 0 is used to indicate "no checksum" - // 0xFFff and 0 are equivalent in one's complement math - // 0xFFff + 1 = 0x10000 -> 0x0001 (same as 0 + 1) - // infact it's impossible to get 0 with such addition, - // when starting from non-0 value. - // inside deltachksum we don't invert so it's safe to skip check there - // if(check->n == 0x0000) - // check->n = 0xFFff; - } void - IPPacket::UpdateV4Address(huint32_t newSrcIP, huint32_t newDstIP) + IPPacket::UpdateIPv4Address(nuint32_t nSrcIP, nuint32_t nDstIP) { llarp::LogDebug("set src=", newSrcIP, " dst=", newDstIP); + auto hdr = Header(); auto oSrcIP = nuint32_t{hdr->saddr}; auto oDstIP = nuint32_t{hdr->daddr}; - auto nSrcIP = xhtonl(newSrcIP); - auto nDstIP = xhtonl(newDstIP); - - // IPv4 checksum - auto v4chk = (nuint16_t *)&(hdr->check); - *v4chk = deltaIPv4Checksum(*v4chk, oSrcIP, oDstIP, nSrcIP, nDstIP); // L4 checksum auto ihs = size_t(hdr->ihl * 4); @@ -267,23 +179,98 @@ namespace llarp } } + // IPv4 checksum + auto v4chk = (nuint16_t *)&(hdr->check); + *v4chk = deltaIPv4Checksum(*v4chk, oSrcIP, oDstIP, nSrcIP, nDstIP); + // write new IP addresses hdr->saddr = nSrcIP.n; hdr->daddr = nDstIP.n; } + +#define ADD32CS(x) ((uint32_t)(x & 0xFFff) + (uint32_t)(x >> 16)) +#define SUB32CS(x) ((uint32_t)((~x) & 0xFFff) + (uint32_t)((~x) >> 16)) + + static nuint16_t + deltaIPv4Checksum(nuint16_t old_sum, nuint32_t old_src_ip, + 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); + + // only need to do it 2 times to be sure + // proof: 0xFFff + 0xFFff = 0x1FFfe -> 0xFFff + sum = (sum & 0xFFff) + (sum >> 16); + sum += sum >> 16; + + return nuint16_t{uint16_t(sum & 0xFFff)}; + } + + static nuint16_t + deltaIPv6Checksum(nuint16_t old_sum, + const uint32 old_src_ip[4], const uint32 old_dst_ip[4], + const uint32 new_src_ip[4], const uint32 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) + + ADDN128CS(old_src_ip) + ADDN128CS(old_dst_ip) + + SUBN128CS(new_src_ip) + SUBN128CS(new_dst_ip); +#undef ADDN128CS +#undef SUBN128CS + + // only need to do it 2 times to be sure + // proof: 0xFFff + 0xFFff = 0x1FFfe -> 0xFFff + sum = (sum & 0xFFff) + (sum >> 16); + sum += sum >> 16; + + return nuint16_t{uint16_t(sum & 0xFFff)}; + } + +#undef ADD32CS +#undef SUB32CS + + void + IPPacket::UpdateIPv6Address(huint128_t src, huint128_t dst) + { + if(sz <= 40) + return; + auto hdr = HeaderV6(); + auto oldSrc = hdr->srcaddr; + auto oldDst = hdr->dstaddr; + hdr->srcaddr = HUIntToIn6(src); + hdr->dstaddr = HUIntToIn6(dst); + const size_t ihs = 40; + auto pld = buf + ihs; + auto psz = sz - ihs; + switch(hdr->proto) + { + //tcp + case 6: + return; + } + } + + static void - checksumSrcIPv4TCP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, + deltaChecksumIPv4TCP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, size_t fragoff, size_t chksumoff, nuint32_t oSrcIP, - nuint32_t oDstIP) + nuint32_t oDstIP, nuint32_t nSrcIP, nuint32_t nDstIP) { if(fragoff > chksumoff) return; auto check = (nuint16_t *)(pld + chksumoff - fragoff); - *check = - deltaIPv4Checksum(*check, oSrcIP, oDstIP, nuint32_t{0}, nuint32_t{0}); + *check = deltaIPv4Checksum(*check, oSrcIP, oDstIP, nSrcIP, nDstIP); // usually, TCP checksum field cannot be 0xFFff, // because one's complement addition cannot result in 0x0000, // and there's inversion in the end; @@ -293,8 +280,9 @@ namespace llarp } static void - checksumSrcIPv4UDP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, - size_t fragoff, nuint32_t oSrcIP, nuint32_t oDstIP) + deltaChecksumIPv4UDP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, + size_t fragoff, nuint32_t oSrcIP, nuint32_t oDstIP, + nuint32_t nSrcIP, nuint32_t nDstIP) { if(fragoff > 6) return; @@ -303,8 +291,7 @@ namespace llarp if(check->n == 0x0000) return; // 0 is used to indicate "no checksum", don't change - *check = - deltaIPv4Checksum(*check, oSrcIP, oDstIP, nuint32_t{0}, nuint32_t{0}); + *check = deltaIPv4Checksum(*check, oSrcIP, oDstIP, nSrcIP, nDstIP); // 0 is used to indicate "no checksum" // 0xFFff and 0 are equivalent in one's complement math // 0xFFff + 1 = 0x10000 -> 0x0001 (same as 0 + 1) @@ -314,48 +301,5 @@ namespace llarp // if(check->n == 0x0000) // check->n = 0xFFff; } - /* - void - IPacket::UpdateIPv4PacketOnSrc() - { - auto hdr = Header(); - - auto oSrcIP = nuint32_t{hdr->saddr}; - auto oDstIP = nuint32_t{hdr->daddr}; - - // L4 - auto ihs = size_t(hdr->ihl * 4); - if(ihs <= sz) - { - auto pld = buf + ihs; - auto psz = sz - ihs; - - auto fragoff = size_t((ntohs(hdr->frag_off) & 0x1Fff) * 8); - - switch(hdr->protocol) - { - case 6: // TCP - checksumSrcIPv4TCP(pld, psz, fragoff, 16, oSrcIP, oDstIP); - break; - case 17: // UDP - case 136: // UDP-Lite - checksumSrcIPv4UDP(pld, psz, fragoff, oSrcIP, oDstIP); - break; - case 33: // DCCP - checksumSrcIPv4TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP); - break; - } - } - - // IPv4 - auto v4chk = (nuint16_t *)&(hdr->check); - *v4chk = - deltaIPv4Checksum(*v4chk, oSrcIP, oDstIP, nuint32_t{0}, nuint32_t{0}); - - // clear addresses - hdr->saddr = 0; - hdr->daddr = 0; - } - */ } // namespace net } // namespace llarp From 6730af207ff3dba956dce06a1dfb0a5482231fb8 Mon Sep 17 00:00:00 2001 From: cathugger Date: Tue, 11 Jun 2019 23:30:59 +0300 Subject: [PATCH 2/6] net/ip: IPv6 TCP/UDP delta chksum funcs --- llarp/net/ip.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/llarp/net/ip.cpp b/llarp/net/ip.cpp index 32cb169c5..ef529514e 100644 --- a/llarp/net/ip.cpp +++ b/llarp/net/ip.cpp @@ -145,7 +145,7 @@ namespace llarp void IPPacket::UpdateIPv4Address(nuint32_t nSrcIP, nuint32_t nDstIP) { - llarp::LogDebug("set src=", newSrcIP, " dst=", newDstIP); + llarp::LogDebug("set src=", nSrcIP, " dst=", nDstIP); auto hdr = Header(); @@ -279,6 +279,26 @@ namespace llarp check->n = 0x0000; } + static void + deltaChecksumIPv6TCP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, + size_t fragoff, size_t chksumoff, + const uint32_t oSrcIP[4], const uint32_t oDstIP[4], + const uint32_t nSrcIP[4], const uint32_t nDstIP[4]) + { + if(fragoff > chksumoff) + return; + + auto check = (nuint16_t *)(pld + chksumoff - fragoff); + + *check = deltaIPv6Checksum(*check, oSrcIP, oDstIP, nSrcIP, nDstIP); + // usually, TCP checksum field cannot be 0xFFff, + // because one's complement addition cannot result in 0x0000, + // and there's inversion in the end; + // emulate that. + if(check->n == 0xFFff) + check->n = 0x0000; + } + static void deltaChecksumIPv4UDP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, size_t fragoff, nuint32_t oSrcIP, nuint32_t oDstIP, @@ -301,5 +321,34 @@ namespace llarp // if(check->n == 0x0000) // check->n = 0xFFff; } + + 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]) + { + if(fragoff > 6) + return; + + auto check = (nuint16_t *)(pld + 6); + // 0 is used to indicate "no checksum", don't change + // even tho this shouldn't happen for IPv6, handle it properly + // we actually should drop/log 0-checksum packets per spec + // but that should be done at upper level than this function + // it's better to do correct thing there regardless + if(check->n == 0x0000) + return; + + *check = deltaIPv6Checksum(*check, oSrcIP, oDstIP, nSrcIP, nDstIP); + // 0 is used to indicate "no checksum" + // 0xFFff and 0 are equivalent in one's complement math + // 0xFFff + 1 = 0x10000 -> 0x0001 (same as 0 + 1) + // infact it's impossible to get 0 with such addition, + // when starting from non-0 value. + // inside deltachksum we don't invert so it's safe to skip check there + // if(check->n == 0x0000) + // check->n = 0xFFff; + } } // namespace net } // namespace llarp From e085f3e6c5a3c7c9fee90664e66ba379e16dd62d Mon Sep 17 00:00:00 2001 From: cathugger Date: Tue, 11 Jun 2019 23:52:13 +0300 Subject: [PATCH 3/6] net/ip: IPv6 packet deltachecksum --- llarp/net/ip.cpp | 68 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/llarp/net/ip.cpp b/llarp/net/ip.cpp index ef529514e..6f93afc31 100644 --- a/llarp/net/ip.cpp +++ b/llarp/net/ip.cpp @@ -188,6 +188,50 @@ namespace llarp hdr->daddr = nDstIP.n; } + void + IPPacket::UpdateIPv6Address(huint128_t src, huint128_t dst) + { + const size_t ihs = 40; + + // XXX should've been checked at upper level? + if(sz <= ihs) + return; + + auto hdr = HeaderV6(); + + const uint32_t oSrcIP = hdr->srcaddr; + const uint32_t oDstIP = hdr->dstaddr; + + // IPv6 address + hdr->srcaddr = HUIntToIn6(src); + hdr->dstaddr = HUIntToIn6(dst); + + // TODO IPv6 header options + auto pld = buf + ihs; + auto psz = sz - ihs; + + switch(hdr->proto) + { + case 6: // TCP + checksumDstIPv6TCP(pld, psz, fragoff, 16, &oSrcIP.s6_addr32, + &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, + &hdr->dstaddr.s6_addr32); + break; + case 17: // UDP + case 136: // UDP-Lite - same checksum place, same 0->0xFFff condition + checksumDstIPv6UDP(pld, psz, fragoff, &oSrcIP.s6_addr32, + &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, + &hdr->dstaddr.s6_addr32); + break; + case 33: // DCCP + checksumDstIPv6TCP(pld, psz, fragoff, 6, &oSrcIP.s6_addr32, + &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, + &hdr->dstaddr.s6_addr32); + break; + } + } + + #define ADD32CS(x) ((uint32_t)(x & 0xFFff) + (uint32_t)(x >> 16)) #define SUB32CS(x) ((uint32_t)((~x) & 0xFFff) + (uint32_t)((~x) >> 16)) @@ -238,27 +282,6 @@ namespace llarp #undef ADD32CS #undef SUB32CS - void - IPPacket::UpdateIPv6Address(huint128_t src, huint128_t dst) - { - if(sz <= 40) - return; - auto hdr = HeaderV6(); - auto oldSrc = hdr->srcaddr; - auto oldDst = hdr->dstaddr; - hdr->srcaddr = HUIntToIn6(src); - hdr->dstaddr = HUIntToIn6(dst); - const size_t ihs = 40; - auto pld = buf + ihs; - auto psz = sz - ihs; - switch(hdr->proto) - { - //tcp - case 6: - return; - } - } - static void deltaChecksumIPv4TCP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, @@ -299,6 +322,7 @@ 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, @@ -337,6 +361,8 @@ namespace llarp // we actually should drop/log 0-checksum packets per spec // but that should be done at upper level than this function // it's better to do correct thing there regardless + // XXX or maybe we should change this function to be able to return error? + // either way that's not a priority if(check->n == 0x0000) return; From 88acadf415ff370fcdf416cf91b705126edcb67e Mon Sep 17 00:00:00 2001 From: cathugger Date: Tue, 11 Jun 2019 23:56:48 +0300 Subject: [PATCH 4/6] net/ip: update names --- llarp/net/ip.cpp | 12 ++++++------ llarp/net/ip.hpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/llarp/net/ip.cpp b/llarp/net/ip.cpp index 6f93afc31..788dd3d5a 100644 --- a/llarp/net/ip.cpp +++ b/llarp/net/ip.cpp @@ -164,16 +164,16 @@ namespace llarp switch(hdr->protocol) { case 6: // TCP - checksumDstIPv4TCP(pld, psz, fragoff, 16, oSrcIP, oDstIP, nSrcIP, + deltaChecksumIPv4TCP(pld, psz, fragoff, 16, oSrcIP, oDstIP, nSrcIP, nDstIP); break; case 17: // UDP case 136: // UDP-Lite - same checksum place, same 0->0xFFff condition - checksumDstIPv4UDP(pld, psz, fragoff, oSrcIP, oDstIP, nSrcIP, + deltaChecksumIPv4UDP(pld, psz, fragoff, oSrcIP, oDstIP, nSrcIP, nDstIP); break; case 33: // DCCP - checksumDstIPv4TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, + deltaChecksumIPv4TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, nDstIP); break; } @@ -213,18 +213,18 @@ namespace llarp switch(hdr->proto) { case 6: // TCP - checksumDstIPv6TCP(pld, psz, fragoff, 16, &oSrcIP.s6_addr32, + deltaChecksumIPv6TCP(pld, psz, fragoff, 16, &oSrcIP.s6_addr32, &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, &hdr->dstaddr.s6_addr32); break; case 17: // UDP case 136: // UDP-Lite - same checksum place, same 0->0xFFff condition - checksumDstIPv6UDP(pld, psz, fragoff, &oSrcIP.s6_addr32, + deltaChecksumIPv6UDP(pld, psz, fragoff, &oSrcIP.s6_addr32, &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, &hdr->dstaddr.s6_addr32); break; case 33: // DCCP - checksumDstIPv6TCP(pld, psz, fragoff, 6, &oSrcIP.s6_addr32, + deltaChecksumIPv6TCP(pld, psz, fragoff, 6, &oSrcIP.s6_addr32, &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, &hdr->dstaddr.s6_addr32); break; diff --git a/llarp/net/ip.hpp b/llarp/net/ip.hpp index 927e4674b..a4fcb8a35 100644 --- a/llarp/net/ip.hpp +++ b/llarp/net/ip.hpp @@ -249,10 +249,10 @@ namespace llarp dst4to6() const; void - UpdateV4Address(huint32_t src, huint32_t dst); + UpdateIPv4Address(nuint32_t src, nuint32_t dst); void - UpdateV6Address(huint128_t src, huint128_t dst); + UpdateIPv6Address(huint128_t src, huint128_t dst); }; } // namespace net From a9dac85c2873281277dedc4ace381c9ef7170fd9 Mon Sep 17 00:00:00 2001 From: cathugger Date: Wed, 12 Jun 2019 00:27:06 +0300 Subject: [PATCH 5/6] fix stuff --- llarp/exit/endpoint.cpp | 4 +- llarp/handlers/exit.cpp | 2 +- llarp/handlers/tun.cpp | 12 +-- llarp/handlers/tun.hpp | 8 +- llarp/net/ip.cpp | 186 ++++++++++++++++++++-------------------- 5 files changed, 106 insertions(+), 106 deletions(-) diff --git a/llarp/exit/endpoint.cpp b/llarp/exit/endpoint.cpp index 78fb8b44a..68f1362ea 100644 --- a/llarp/exit/endpoint.cpp +++ b/llarp/exit/endpoint.cpp @@ -117,7 +117,7 @@ namespace llarp dst = net::IPPacket::TruncateV6(m_Parent->GetIfAddr()); else dst = pkt.dstv4(); - pkt.UpdateV4Address(net::IPPacket::TruncateV6(m_IP), 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(); @@ -136,7 +136,7 @@ namespace llarp src = m_Parent->GetIfAddr(); else src = pkt.srcv6(); - pkt.UpdateV6Address(src, m_IP); + pkt.UpdateIPv6Address(src, m_IP); const llarp_buffer_t& pktbuf = pkt.Buffer(); // life time extension const uint8_t queue_idx = pktbuf.sz / llarp::routing::ExitPadSize; if(m_DownstreamQueues.find(queue_idx) == m_DownstreamQueues.end()) diff --git a/llarp/handlers/exit.cpp b/llarp/handlers/exit.cpp index 371b88930..197bbc55b 100644 --- a/llarp/handlers/exit.cpp +++ b/llarp/handlers/exit.cpp @@ -440,7 +440,7 @@ namespace llarp if(!pkt.Load(buf)) return false; // rewrite ip - pkt.UpdateV6Address(from, m_IfAddr); + pkt.UpdateIPv6Address(from, m_IfAddr); return llarp_ev_tun_async_write(&m_Tun, pkt.Buffer()); } diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 26fd604ef..a87976d73 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -712,7 +712,7 @@ namespace llarp { if(m_Exit && pkt.IsV4() && !llarp::IsIPv4Bogon(pkt.dstv4())) { - pkt.UpdateV4Address({0}, pkt.dstv4()); + pkt.UpdateIPv4Address({0}, xhtonl(pkt.dstv4())); m_Exit->QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize); } @@ -738,9 +738,9 @@ namespace llarp // prepare packet for insertion into network // this includes clearing IP addresses, recalculating checksums, etc if(pkt.IsV4()) - pkt.UpdateV4Address({0}, {0}); + pkt.UpdateIPv4Address({0}, {0}); else - pkt.UpdateV6Address({0}, {0}); + pkt.UpdateIPv6Address({0}, {0}); if(sendFunc && sendFunc(pkt.Buffer())) return; @@ -778,13 +778,15 @@ namespace llarp { return false; } - pkt.UpdateV4Address(net::IPPacket::TruncateV6(themIP), net::IPPacket::TruncateV6(usIP)); + pkt.UpdateIPv4Address( + xhtonl(net::IPPacket::TruncateV6(themIP)), + xhtonl(net::IPPacket::TruncateV6(usIP))); } else if(pkt.IsV6()) { if(pkt.srcv6() != huint128_t{0} || pkt.dstv6() != huint128_t{0}) return false; - pkt.UpdateV6Address(themIP, usIP); + pkt.UpdateIPv6Address(themIP, usIP); } return true; }); diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 48d462b50..b2e131688 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -209,19 +209,19 @@ namespace llarp { if(pkt.IsV4()) { - pkt.UpdateV6Address(net::IPPacket::ExpandV4(pkt.srcv4()), + pkt.UpdateIPv6Address(net::IPPacket::ExpandV4(pkt.srcv4()), m_OurIP); } else { - pkt.UpdateV6Address(pkt.srcv6(), m_OurIP); + pkt.UpdateIPv6Address(pkt.srcv6(), m_OurIP); } } else { if(pkt.IsV4()) - pkt.UpdateV4Address(pkt.srcv4(), - net::IPPacket::TruncateV6(m_OurIP)); + pkt.UpdateIPv4Address(xhtonl(pkt.srcv4()), + xhtonl(net::IPPacket::TruncateV6(m_OurIP))); else return false; } diff --git a/llarp/net/ip.cpp b/llarp/net/ip.cpp index 788dd3d5a..6f132cf57 100644 --- a/llarp/net/ip.cpp +++ b/llarp/net/ip.cpp @@ -142,97 +142,6 @@ namespace llarp #endif - void - IPPacket::UpdateIPv4Address(nuint32_t nSrcIP, nuint32_t nDstIP) - { - llarp::LogDebug("set src=", nSrcIP, " dst=", nDstIP); - - auto hdr = Header(); - - auto oSrcIP = nuint32_t{hdr->saddr}; - auto oDstIP = nuint32_t{hdr->daddr}; - - // L4 checksum - auto ihs = size_t(hdr->ihl * 4); - if(ihs <= sz) - { - auto pld = buf + ihs; - auto psz = sz - ihs; - - auto fragoff = size_t((ntohs(hdr->frag_off) & 0x1Fff) * 8); - - switch(hdr->protocol) - { - case 6: // TCP - deltaChecksumIPv4TCP(pld, psz, fragoff, 16, oSrcIP, oDstIP, nSrcIP, - nDstIP); - break; - case 17: // UDP - case 136: // UDP-Lite - same checksum place, same 0->0xFFff condition - deltaChecksumIPv4UDP(pld, psz, fragoff, oSrcIP, oDstIP, nSrcIP, - nDstIP); - break; - case 33: // DCCP - deltaChecksumIPv4TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, - nDstIP); - break; - } - } - - // IPv4 checksum - auto v4chk = (nuint16_t *)&(hdr->check); - *v4chk = deltaIPv4Checksum(*v4chk, oSrcIP, oDstIP, nSrcIP, nDstIP); - - // write new IP addresses - hdr->saddr = nSrcIP.n; - hdr->daddr = nDstIP.n; - } - - void - IPPacket::UpdateIPv6Address(huint128_t src, huint128_t dst) - { - const size_t ihs = 40; - - // XXX should've been checked at upper level? - if(sz <= ihs) - return; - - auto hdr = HeaderV6(); - - const uint32_t oSrcIP = hdr->srcaddr; - const uint32_t oDstIP = hdr->dstaddr; - - // IPv6 address - hdr->srcaddr = HUIntToIn6(src); - hdr->dstaddr = HUIntToIn6(dst); - - // TODO IPv6 header options - auto pld = buf + ihs; - auto psz = sz - ihs; - - switch(hdr->proto) - { - case 6: // TCP - deltaChecksumIPv6TCP(pld, psz, fragoff, 16, &oSrcIP.s6_addr32, - &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, - &hdr->dstaddr.s6_addr32); - break; - case 17: // UDP - case 136: // UDP-Lite - same checksum place, same 0->0xFFff condition - deltaChecksumIPv6UDP(pld, psz, fragoff, &oSrcIP.s6_addr32, - &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, - &hdr->dstaddr.s6_addr32); - break; - case 33: // DCCP - deltaChecksumIPv6TCP(pld, psz, fragoff, 6, &oSrcIP.s6_addr32, - &oDstIP.s6_addr32, &hdr->srcaddr.s6_addr32, - &hdr->dstaddr.s6_addr32); - break; - } - } - - - #define ADD32CS(x) ((uint32_t)(x & 0xFFff) + (uint32_t)(x >> 16)) #define SUB32CS(x) ((uint32_t)((~x) & 0xFFff) + (uint32_t)((~x) >> 16)) @@ -256,8 +165,8 @@ namespace llarp static nuint16_t deltaIPv6Checksum(nuint16_t old_sum, - const uint32 old_src_ip[4], const uint32 old_dst_ip[4], - const uint32 new_src_ip[4], const uint32 new_dst_ip[4]) + 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) */ @@ -265,7 +174,7 @@ namespace llarp /* 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) + + 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 @@ -376,5 +285,94 @@ namespace llarp // if(check->n == 0x0000) // check->n = 0xFFff; } + + + void + IPPacket::UpdateIPv4Address(nuint32_t nSrcIP, nuint32_t nDstIP) + { + llarp::LogDebug("set src=", nSrcIP, " dst=", nDstIP); + + auto hdr = Header(); + + auto oSrcIP = nuint32_t{hdr->saddr}; + auto oDstIP = nuint32_t{hdr->daddr}; + + // L4 checksum + auto ihs = size_t(hdr->ihl * 4); + if(ihs <= sz) + { + auto pld = buf + ihs; + auto psz = sz - ihs; + + auto fragoff = size_t((ntohs(hdr->frag_off) & 0x1Fff) * 8); + + switch(hdr->protocol) + { + case 6: // TCP + deltaChecksumIPv4TCP(pld, psz, fragoff, 16, oSrcIP, oDstIP, nSrcIP, + nDstIP); + break; + case 17: // UDP + case 136: // UDP-Lite - same checksum place, same 0->0xFFff condition + deltaChecksumIPv4UDP(pld, psz, fragoff, oSrcIP, oDstIP, nSrcIP, + nDstIP); + break; + case 33: // DCCP + deltaChecksumIPv4TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, + nDstIP); + break; + } + } + + // IPv4 checksum + auto v4chk = (nuint16_t *)&(hdr->check); + *v4chk = deltaIPv4Checksum(*v4chk, oSrcIP, oDstIP, nSrcIP, nDstIP); + + // write new IP addresses + hdr->saddr = nSrcIP.n; + hdr->daddr = nDstIP.n; + } + + void + IPPacket::UpdateIPv6Address(huint128_t src, huint128_t dst) + { + const size_t ihs = 40; + + // XXX should've been checked at upper level? + if(sz <= ihs) + return; + + auto hdr = HeaderV6(); + + const auto oldSrcIP = hdr->srcaddr; + const auto oldDstIP = hdr->dstaddr; + const uint32_t *oSrcIP = oldSrcIP.s6_addr32; + const uint32_t *oDstIP = oldDstIP.s6_addr32; + + // IPv6 address + hdr->srcaddr = HUIntToIn6(src); + hdr->dstaddr = HUIntToIn6(dst); + const uint32_t *nSrcIP = hdr->srcaddr.s6_addr32; + const uint32_t *nDstIP = hdr->dstaddr.s6_addr32; + + // TODO IPv6 header options + auto pld = buf + ihs; + auto psz = sz - ihs; + const size_t fragoff = 0; + + switch(hdr->proto) + { + case 6: // TCP + 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); + break; + case 33: // DCCP + deltaChecksumIPv6TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, nDstIP); + break; + } + } } // namespace net } // namespace llarp From 72b1ea613c9a13c8bb8bf608f5ecd89e87f98644 Mon Sep 17 00:00:00 2001 From: cathugger Date: Wed, 12 Jun 2019 00:28:55 +0300 Subject: [PATCH 6/6] make format --- llarp/ev/ev_libuv.cpp | 2 +- llarp/exit/endpoint.cpp | 3 +- llarp/handlers/tun.cpp | 15 +++--- llarp/handlers/tun.hpp | 7 +-- llarp/net/ip.cpp | 110 +++++++++++++++++++++------------------- llarp/net/ip.hpp | 2 +- 6 files changed, 73 insertions(+), 66 deletions(-) diff --git a/llarp/ev/ev_libuv.cpp b/llarp/ev/ev_libuv.cpp index bb34fd4bd..2b281c359 100644 --- a/llarp/ev/ev_libuv.cpp +++ b/llarp/ev/ev_libuv.cpp @@ -613,7 +613,7 @@ namespace libuv m_CloseFuncs.emplace_back(std::bind(&tun_glue ::Close, glue)); return true; } - + delete glue; return false; } diff --git a/llarp/exit/endpoint.cpp b/llarp/exit/endpoint.cpp index 68f1362ea..a000ed848 100644 --- a/llarp/exit/endpoint.cpp +++ b/llarp/exit/endpoint.cpp @@ -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(); diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index a87976d73..b4f7ce7e2 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -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 @@ -404,7 +405,7 @@ namespace llarp else if(HasAddress(addr)) { huint128_t ip = ObtainIPForAddr(addr, false); - msg.AddINReply(ip, isV6); + msg.AddINReply(ip, isV6); } else { @@ -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,9 +780,8 @@ namespace llarp { return false; } - pkt.UpdateIPv4Address( - xhtonl(net::IPPacket::TruncateV6(themIP)), - xhtonl(net::IPPacket::TruncateV6(usIP))); + pkt.UpdateIPv4Address(xhtonl(net::IPPacket::TruncateV6(themIP)), + xhtonl(net::IPPacket::TruncateV6(usIP))); } else if(pkt.IsV6()) { @@ -873,7 +874,7 @@ namespace llarp void TunEndpoint::MarkIPActive(huint128_t ip) { - llarp::LogDebug(Name(), " address " , ip, " is active"); + llarp::LogDebug(Name(), " address ", ip, " is active"); m_IPActivity[ip] = std::max(Now(), m_IPActivity[ip]); } diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index b2e131688..c26153d87 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -210,7 +210,7 @@ namespace llarp if(pkt.IsV4()) { pkt.UpdateIPv6Address(net::IPPacket::ExpandV4(pkt.srcv4()), - m_OurIP); + m_OurIP); } else { @@ -220,8 +220,9 @@ namespace llarp else { if(pkt.IsV4()) - pkt.UpdateIPv4Address(xhtonl(pkt.srcv4()), - xhtonl(net::IPPacket::TruncateV6(m_OurIP))); + pkt.UpdateIPv4Address( + xhtonl(pkt.srcv4()), + xhtonl(net::IPPacket::TruncateV6(m_OurIP))); else return false; } diff --git a/llarp/net/ip.cpp b/llarp/net/ip.cpp index 6f132cf57..33c4b022d 100644 --- a/llarp/net/ip.cpp +++ b/llarp/net/ip.cpp @@ -20,12 +20,12 @@ namespace llarp { #if __BYTE_ORDER == __BIG_ENDIAN return huint128_t{addr.s6_addr32[0]} - | (huint128_t{addr.s6_addr32[1]} << 32) + | (huint128_t{addr.s6_addr32[1]} << 32) | (huint128_t{addr.s6_addr32[2]} << 64) | (huint128_t{addr.s6_addr32[3]} << 96); #else return huint128_t{ntohl(addr.s6_addr32[3])} - | (huint128_t{ntohl(addr.s6_addr32[2])} << 32) + | (huint128_t{ntohl(addr.s6_addr32[2])} << 32) | (huint128_t{ntohl(addr.s6_addr32[1])} << 64) | (huint128_t{ntohl(addr.s6_addr32[0])} << 96); #endif @@ -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,11 +195,10 @@ 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, - nuint32_t oDstIP, nuint32_t nSrcIP, nuint32_t nDstIP) + size_t fragoff, size_t chksumoff, nuint32_t oSrcIP, + nuint32_t oDstIP, nuint32_t nSrcIP, nuint32_t nDstIP) { if(fragoff > chksumoff) return; @@ -213,9 +216,9 @@ namespace llarp static void deltaChecksumIPv6TCP(byte_t *pld, ABSL_ATTRIBUTE_UNUSED size_t psz, - size_t fragoff, size_t chksumoff, - const uint32_t oSrcIP[4], const uint32_t oDstIP[4], - const uint32_t nSrcIP[4], const uint32_t nDstIP[4]) + size_t fragoff, size_t chksumoff, + const uint32_t oSrcIP[4], const uint32_t oDstIP[4], + const uint32_t nSrcIP[4], const uint32_t nDstIP[4]) { if(fragoff > chksumoff) return; @@ -231,11 +234,10 @@ 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, - nuint32_t nSrcIP, nuint32_t nDstIP) + size_t fragoff, nuint32_t oSrcIP, nuint32_t oDstIP, + nuint32_t nSrcIP, nuint32_t nDstIP) { if(fragoff > 6) return; @@ -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) { @@ -310,16 +311,16 @@ namespace llarp { case 6: // TCP deltaChecksumIPv4TCP(pld, psz, fragoff, 16, oSrcIP, oDstIP, nSrcIP, - nDstIP); + nDstIP); break; case 17: // UDP case 136: // UDP-Lite - same checksum place, same 0->0xFFff condition deltaChecksumIPv4UDP(pld, psz, fragoff, oSrcIP, oDstIP, nSrcIP, - nDstIP); + nDstIP); break; case 33: // DCCP deltaChecksumIPv4TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, - nDstIP); + nDstIP); break; } } @@ -342,36 +343,39 @@ namespace llarp if(sz <= ihs) return; - auto hdr = HeaderV6(); + auto hdr = HeaderV6(); - const auto oldSrcIP = hdr->srcaddr; - const auto oldDstIP = hdr->dstaddr; + const auto oldSrcIP = hdr->srcaddr; + const auto oldDstIP = hdr->dstaddr; const uint32_t *oSrcIP = oldSrcIP.s6_addr32; const uint32_t *oDstIP = oldDstIP.s6_addr32; // IPv6 address - hdr->srcaddr = HUIntToIn6(src); - hdr->dstaddr = HUIntToIn6(dst); + hdr->srcaddr = HUIntToIn6(src); + hdr->dstaddr = HUIntToIn6(dst); const uint32_t *nSrcIP = hdr->srcaddr.s6_addr32; const uint32_t *nDstIP = hdr->dstaddr.s6_addr32; // TODO IPv6 header options - auto pld = buf + ihs; - auto psz = sz - ihs; + auto pld = buf + ihs; + auto psz = sz - ihs; const size_t fragoff = 0; switch(hdr->proto) { - case 6: // TCP - 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); - break; - case 33: // DCCP - deltaChecksumIPv6TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, nDstIP); - break; + case 6: // TCP + 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); + break; + case 33: // DCCP + deltaChecksumIPv6TCP(pld, psz, fragoff, 6, oSrcIP, oDstIP, nSrcIP, + nDstIP); + break; } } } // namespace net diff --git a/llarp/net/ip.hpp b/llarp/net/ip.hpp index a4fcb8a35..49f062e2b 100644 --- a/llarp/net/ip.hpp +++ b/llarp/net/ip.hpp @@ -78,7 +78,7 @@ struct ipv6_header { unsigned char version : 4; unsigned char pad_small : 4; - uint8_t pad [3]; + uint8_t pad[3]; uint16_t payload_len; uint8_t proto; uint8_t hoplimit;