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

@ -295,7 +295,7 @@ func main() {
} }
n.multicast.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) n.multicast.SetupAdminHandlers(n.admin.(*admin.AdminSocket))
// Start the TUN/TAP interface // Start the TUN/TAP interface
n.tuntap.Init(&n.core, n.state, logger, tuntap.TunOptions{}) n.tuntap.Init(&n.core, n.state, logger, nil)
if err := n.tuntap.Start(); err != nil { if err := n.tuntap.Start(); err != nil {
logger.Errorln("An error occurred starting TUN/TAP:", err) logger.Errorln("An error occurred starting TUN/TAP:", err)
} }
@ -325,6 +325,7 @@ func main() {
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
// Capture the service being stopped on Windows. // Capture the service being stopped on Windows.
<-c
minwinsvc.SetOnExit(n.shutdown) minwinsvc.SetOnExit(n.shutdown)
n.shutdown() n.shutdown()
} }

View File

@ -40,13 +40,6 @@ func ipv6Header_Marshal(h *ipv6.Header) ([]byte, error) {
return b, nil return b, nil
} }
// Initialises the ICMPv6 module by assigning our link-local IPv6 address and
// our MAC address. ICMPv6 messages will always appear to originate from these
// addresses.
func (i *ICMPv6) Init(t *TunAdapter) {
i.tun = t
}
// Creates an ICMPv6 packet based on the given icmp.MessageBody and other // Creates an ICMPv6 packet based on the given icmp.MessageBody and other
// parameters, complete with IP headers only, which can be written directly to // parameters, complete with IP headers only, which can be written directly to
// a TUN adapter, or called directly by the CreateICMPv6L2 function when // a TUN adapter, or called directly by the CreateICMPv6L2 function when

View File

@ -4,6 +4,9 @@ import (
"crypto/ed25519" "crypto/ed25519"
"github.com/yggdrasil-network/yggdrasil-go/src/address" "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/crypto"
//"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" //"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
@ -70,6 +73,17 @@ func (tun *TunAdapter) write() {
if len(bs) < 40 { if len(bs) < 40 {
continue 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 srcAddr, dstAddr address.Address
var srcSubnet, dstSubnet address.Subnet var srcSubnet, dstSubnet address.Subnet
copy(srcAddr[:], bs[8:]) copy(srcAddr[:], bs[8:])

View File

@ -29,8 +29,6 @@ import (
type MTU = types.MTU type MTU = types.MTU
const tun_IPv6_HEADER_LENGTH = 40
// TunAdapter represents a running TUN interface and extends the // TunAdapter represents a running TUN interface and extends the
// yggdrasil.Adapter type. In order to use the TUN adapter with Yggdrasil, you // yggdrasil.Adapter type. In order to use the TUN adapter with Yggdrasil, you
// should pass this object to the yggdrasil.SetRouterAdapter() function before // should pass this object to the yggdrasil.SetRouterAdapter() function before
@ -43,7 +41,6 @@ type TunAdapter struct {
addr address.Address addr address.Address
subnet address.Subnet subnet address.Subnet
ckr cryptokey ckr cryptokey
icmpv6 ICMPv6
mtu MTU mtu MTU
iface tun.Device iface tun.Device
phony.Inbox // Currently only used for _handlePacket from the reader, TODO: all the stuff that currently needs a mutex below phony.Inbox // Currently only used for _handlePacket from the reader, TODO: all the stuff that currently needs a mutex below
@ -51,11 +48,6 @@ type TunAdapter struct {
isOpen bool isOpen bool
} }
type TunOptions struct {
//Listener *yggdrasil.Listener
//Dialer *yggdrasil.Dialer
}
// Gets the maximum supported MTU for the platform based on the defaults in // Gets the maximum supported MTU for the platform based on the defaults in
// defaults.GetDefaults(). // defaults.GetDefaults().
func getSupportedMTU(mtu MTU) MTU { func getSupportedMTU(mtu MTU) MTU {
@ -105,12 +97,6 @@ func MaximumMTU() MTU {
// Init initialises the TUN module. You must have acquired a Listener from // Init initialises the TUN module. You must have acquired a Listener from
// the Yggdrasil core before this point and it must not be in use elsewhere. // the Yggdrasil core before this point and it must not be in use elsewhere.
func (tun *TunAdapter) Init(core *yggdrasil.Core, config *config.NodeState, log *log.Logger, options interface{}) error { func (tun *TunAdapter) Init(core *yggdrasil.Core, config *config.NodeState, log *log.Logger, options interface{}) error {
/* TODO
tunoptions, ok := options.(TunOptions)
if !ok {
return fmt.Errorf("invalid options supplied to TunAdapter module")
}
*/
tun.core = core tun.core = core
tun.store.init(tun) tun.store.init(tun)
tun.config = config tun.config = config
@ -118,7 +104,6 @@ func (tun *TunAdapter) Init(core *yggdrasil.Core, config *config.NodeState, log
if err := tun.core.SetOutOfBandHandler(tun.oobHandler); err != nil { if err := tun.core.SetOutOfBandHandler(tun.oobHandler); err != nil {
return fmt.Errorf("tun.core.SetOutOfBandHander: %w", err) return fmt.Errorf("tun.core.SetOutOfBandHander: %w", err)
} }
return nil return nil
} }