diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index e409f4a..f315825 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -295,7 +295,7 @@ func main() { } n.multicast.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) // 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 { logger.Errorln("An error occurred starting TUN/TAP:", err) } @@ -325,6 +325,7 @@ func main() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) // Capture the service being stopped on Windows. + <-c minwinsvc.SetOnExit(n.shutdown) n.shutdown() } diff --git a/src/tuntap/icmpv6.go b/src/tuntap/icmpv6.go index 67c10e5..59d07af 100644 --- a/src/tuntap/icmpv6.go +++ b/src/tuntap/icmpv6.go @@ -40,13 +40,6 @@ func ipv6Header_Marshal(h *ipv6.Header) ([]byte, error) { 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 // parameters, complete with IP headers only, which can be written directly to // a TUN adapter, or called directly by the CreateICMPv6L2 function when diff --git a/src/tuntap/iface.go b/src/tuntap/iface.go index c722226..30eaf32 100644 --- a/src/tuntap/iface.go +++ b/src/tuntap/iface.go @@ -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:]) diff --git a/src/tuntap/tun.go b/src/tuntap/tun.go index 1618506..8c8cbf1 100644 --- a/src/tuntap/tun.go +++ b/src/tuntap/tun.go @@ -29,8 +29,6 @@ import ( type MTU = types.MTU -const tun_IPv6_HEADER_LENGTH = 40 - // TunAdapter represents a running TUN interface and extends the // yggdrasil.Adapter type. In order to use the TUN adapter with Yggdrasil, you // should pass this object to the yggdrasil.SetRouterAdapter() function before @@ -43,7 +41,6 @@ type TunAdapter struct { addr address.Address subnet address.Subnet ckr cryptokey - icmpv6 ICMPv6 mtu MTU iface tun.Device 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 } -type TunOptions struct { - //Listener *yggdrasil.Listener - //Dialer *yggdrasil.Dialer -} - // Gets the maximum supported MTU for the platform based on the defaults in // defaults.GetDefaults(). func getSupportedMTU(mtu MTU) MTU { @@ -105,12 +97,6 @@ func MaximumMTU() MTU { // 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. 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.store.init(tun) 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 { return fmt.Errorf("tun.core.SetOutOfBandHander: %w", err) } - return nil }