Pull request: dhcpd: fix interface ipv6 check

Merge in DNS/adguard-home from 2355-dhcpcheck-ipv6 to master

Updates #2335.

Squashed commit of the following:

commit 5ce1cc7bc244ba5dd4a065d47dec8884fa3d45e7
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Nov 25 14:03:24 2020 +0300

    dhcpd: fix loop exit condition

commit 32b4b946bfa30159326dc295fa1a2607b78172af
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Nov 25 13:26:50 2020 +0300

    dhcpd: fix interface ipv6 check
This commit is contained in:
Ainar Garipov
2020-11-25 14:26:26 +03:00
parent 284da7c91b
commit 36c7735b85
9 changed files with 103 additions and 66 deletions

View File

@@ -281,7 +281,7 @@ func (b UDP) Checksum() uint16 {
// CalculateChecksum calculates the checksum of the udp packet, given the total
// length of the packet and the checksum of the network-layer pseudo-header
// (excluding the total length) and the checksum of the payload.
func (b UDP) CalculateChecksum(partialChecksum uint16, totalLen uint16) uint16 {
func (b UDP) CalculateChecksum(partialChecksum, totalLen uint16) uint16 {
// Add the length portion of the checksum to the pseudo-checksum.
tmp := make([]byte, 2)
binary.BigEndian.PutUint16(tmp, totalLen)
@@ -336,13 +336,13 @@ func ChecksumCombine(a, b uint16) uint16 {
// given destination protocol and network address, ignoring the length
// field. Pseudo-headers are needed by transport layers when calculating
// their own checksum.
func PseudoHeaderChecksum(protocol TransportProtocolNumber, srcAddr net.IP, dstAddr net.IP) uint16 {
func PseudoHeaderChecksum(protocol TransportProtocolNumber, srcAddr, dstAddr net.IP) uint16 {
xsum := Checksum([]byte(srcAddr), 0)
xsum = Checksum([]byte(dstAddr), xsum)
return Checksum([]byte{0, uint8(protocol)}, xsum)
}
func udp4pkt(packet []byte, dest *net.UDPAddr, src *net.UDPAddr) []byte {
func udp4pkt(packet []byte, dest, src *net.UDPAddr) []byte {
ipLen := IPv4MinimumSize
udpLen := UDPMinimumSize