Skip to content

Commit

Permalink
Move DeliverNetworkPacket into separate goroutine
Browse files Browse the repository at this point in the history
... as it may write in the same ironwood context as the reader
if packet destination is unknown or some other condition requires
replyWithReset

Thanks to @Arceliar for hint!

Signed-off-by: Vasyl Gello <[email protected]>
  • Loading branch information
basilgello committed Jul 17, 2024
1 parent b232781 commit 8b8710c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/netstack/yggdrasil.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ 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 string
writeBuf []byte
}

func (s *YggdrasilNetstack) NewYggdrasilNIC(ygg *core.Core) tcpip.Error {
rwc := ipv6rwc.NewReadWriteCloser(ygg)
mtu := rwc.MTU()
nic := &YggdrasilNIC{
ipv6rwc: rwc,
readBuf: make([]byte, mtu),
readBufChan: make(chan stack.PacketBuffer, 100),

Check failure on line 30 in src/netstack/yggdrasil.go

View workflow job for this annotation

GitHub Actions / Build Windows/Linux/MacOS/FreeBSD/Android

cannot use make(chan stack.PacketBuffer, 100) (value of type chan stack.PacketBuffer) as chan string value in struct literal
writeBuf: make([]byte, mtu),
}
if err := s.stack.CreateNIC(1, nic); err != nil {
Expand All @@ -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]),

Check failure on line 47 in src/netstack/yggdrasil.go

View workflow job for this annotation

GitHub Actions / Build Windows/Linux/MacOS/FreeBSD/Android

nic.readBuf undefined (type *YggdrasilNIC has no field or method readBuf)
})
go nic.dispatcher.DeliverNetworkPacket(ipv6.ProtocolNumber, pkb)
nic.readBufChan <- pkb

Check failure on line 49 in src/netstack/yggdrasil.go

View workflow job for this annotation

GitHub Actions / Build Windows/Linux/MacOS/FreeBSD/Android

cannot use pkb (variable of type *stack.PacketBuffer) as string value in send
}
}()
go func() {
for {
nic.dispatcher.DeliverNetworkPacket(ipv6.ProtocolNumber, <- nic.readBufChan)

Check failure on line 54 in src/netstack/yggdrasil.go

View workflow job for this annotation

GitHub Actions / Build Windows/Linux/MacOS/FreeBSD/Android

cannot use <-nic.readBufChan (comma, ok expression of type string) as *stack.PacketBuffer value in argument to nic.dispatcher.DeliverNetworkPacket
}
}()
_, snet, err := net.ParseCIDR("0200::/7")
Expand Down

0 comments on commit 8b8710c

Please sign in to comment.