Re-add ICMPv6 packet too big handling

This commit is contained in:
Neil Alexander 2019-05-29 20:16:17 +01:00
parent 3b6c726a3c
commit 0096d1ae3e
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 44 additions and 8 deletions

View file

@ -7,6 +7,8 @@ import (
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/util"
"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
"golang.org/x/net/icmp"
"golang.org/x/net/ipv6"
)
type tunConn struct {
@ -97,7 +99,21 @@ func (s *tunConn) writer() error {
}
// TODO write timeout and close
if _, err := s.conn.Write(b); err != nil {
s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn write error:", err)
e, eok := err.(yggdrasil.ConnError)
if !eok {
s.tun.log.Errorln(s.conn.String(), "TUN/TAP generic write error:", err)
} else if ispackettoobig, maxsize := e.PacketTooBig(); ispackettoobig {
// TODO: This currently isn't aware of IPv4 for CKR
ptb := &icmp.PacketTooBig{
MTU: int(maxsize),
Data: b[:900],
}
if packet, err := CreateICMPv6(b[8:24], b[24:40], ipv6.ICMPTypePacketTooBig, 0, ptb); err == nil {
s.tun.send <- packet
}
} else {
s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn write error:", err)
}
}
util.PutBytes(b)
s.stillAlive()