Respond with ICMPv6 Packet Too Big over network

This commit is contained in:
Neil Alexander 2021-05-10 23:09:59 +01:00
parent 57ea61b338
commit 815f2a2822
4 changed files with 16 additions and 23 deletions

View file

@ -4,6 +4,9 @@ import (
"crypto/ed25519"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"golang.org/x/net/icmp"
"golang.org/x/net/ipv6"
//"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
//"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
@ -70,6 +73,17 @@ func (tun *TunAdapter) write() {
if len(bs) < 40 {
continue
}
tun.log.Println(len(bs), tun.MTU())
if len(bs) > int(tun.MTU()) {
ptb := &icmp.PacketTooBig{
MTU: int(tun.mtu),
Data: bs[:40],
}
if packet, err := CreateICMPv6(bs[8:24], bs[24:40], ipv6.ICMPTypePacketTooBig, 0, ptb); err == nil {
_, _ = tun.core.WriteTo(packet, from)
}
continue
}
var srcAddr, dstAddr address.Address
var srcSubnet, dstSubnet address.Subnet
copy(srcAddr[:], bs[8:])