diff --git a/src/netstack/yggdrasil.go b/src/netstack/yggdrasil.go index e2e9b3b..18b4768 100644 --- a/src/netstack/yggdrasil.go +++ b/src/netstack/yggdrasil.go @@ -15,11 +15,11 @@ import ( ) type YggdrasilNIC struct { - stack *YggdrasilNetstack - ipv6rwc *ipv6rwc.ReadWriteCloser - dispatcher stack.NetworkDispatcher - readBuf []byte - writeBuf []byte + stack *YggdrasilNetstack + ipv6rwc *ipv6rwc.ReadWriteCloser + dispatcher stack.NetworkDispatcher + readBufChan chan *stack.PacketBuffer + writeBuf []byte } func (s *YggdrasilNetstack) NewYggdrasilNIC(ygg *core.Core) tcpip.Error { @@ -27,7 +27,7 @@ func (s *YggdrasilNetstack) NewYggdrasilNIC(ygg *core.Core) tcpip.Error { mtu := rwc.MTU() nic := &YggdrasilNIC{ ipv6rwc: rwc, - readBuf: make([]byte, mtu), + readBufChan: make(chan *stack.PacketBuffer, 100), writeBuf: make([]byte, mtu), } if err := s.stack.CreateNIC(1, nic); err != nil { @@ -36,16 +36,22 @@ func (s *YggdrasilNetstack) NewYggdrasilNIC(ygg *core.Core) tcpip.Error { go func() { var rx int var err error + readBuf := make([]byte, mtu) for { - rx, err = nic.ipv6rwc.Read(nic.readBuf) + rx, err = nic.ipv6rwc.Read(readBuf) if err != nil { log.Println(err) break } pkb := stack.NewPacketBuffer(stack.PacketBufferOptions{ - Payload: buffer.MakeWithData(nic.readBuf[:rx]), + Payload: buffer.MakeWithData(readBuf[:rx]), }) - go nic.dispatcher.DeliverNetworkPacket(ipv6.ProtocolNumber, pkb) + nic.readBufChan <- pkb + } + }() + go func() { + for { + nic.dispatcher.DeliverNetworkPacket(ipv6.ProtocolNumber, <- nic.readBufChan) } }() _, snet, err := net.ParseCIDR("0200::/7")