aregm / nff-go

NFF-Go -Network Function Framework for GO (former YANFF)
BSD 3-Clause "New" or "Revised" License
1.38k stars 156 forks source link

Correct usage of packet.NewPacket() method #681

Closed AlekseyKanaev closed 4 years ago

AlekseyKanaev commented 4 years ago

Hello! I have an issue with packet.NewPacket() method, but I don't know whether it is a bug or method misuse. Below is code snippet, which results in segmentation violation error.

package main

import (
    "github.com/intel-go/nff-go/packet"
)

var pkt, err interface{}

func main() {
    pkt, err = packet.NewPacket()

}

Here is the error:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x44 pc=0x4eba47]

runtime stack:
runtime.throw(0x75519d, 0x2a)
    /usr/local/go/src/runtime/panic.go:774 +0x72
runtime.sigpanic()
    /usr/local/go/src/runtime/signal_unix.go:378 +0x47c

goroutine 1 [syscall]:
runtime.cgocall(0x4ee8f0, 0xc000058e60, 0xc0000c41f0)
    /usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc000058e30 sp=0xc000058df8 pc=0x439bdb
github.com/intel-go/nff-go/internal/low._Cfunc_allocateMbufs(0x0, 0xc0000b6240, 0x1, 0x0)
    _cgo_gotypes.go:401 +0x4d fp=0xc000058e60 sp=0xc000058e30 pc=0x4e415d
github.com/intel-go/nff-go/internal/low.AllocateMbuf.func1(0x0, 0xc0000b6240, 0xc0000c41e0)
    /home/secret/go/pkg/mod/github.com/intel-go/nff-go@v0.9.2/internal/low/low.go:679 +0x97 fp=0xc000058e98 sp=0xc000058e60 pc=0x4e4547
github.com/intel-go/nff-go/internal/low.AllocateMbuf(0xc0000b6240, 0x0, 0xc000058f50, 0x43c4cf)
    /home/secret/go/pkg/mod/github.com/intel-go/nff-go@v0.9.2/internal/low/low.go:679 +0x39 fp=0xc000058f00 sp=0xc000058e98 pc=0x4e43c9
github.com/intel-go/nff-go/packet.NewPacket(0x0, 0x8e000, 0xc00008c058)
    /home/secret/go/pkg/mod/github.com/intel-go/nff-go@v0.9.2/packet/packet.go:834 +0x50 fp=0xc000058f38 sp=0xc000058f00 pc=0x4e5000
main.main()
    /home/secret/go/src/github.com/MyProject/main.go:10 +0x26 fp=0xc000058f60 sp=0xc000058f38 pc=0x4e52c6
runtime.main()
    /usr/local/go/src/runtime/proc.go:203 +0x21e fp=0xc000058fe0 sp=0xc000058f60 pc=0x4630fe
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc000058fe8 sp=0xc000058fe0 pc=0x48b7b1

My environment params are:

gshimansky commented 4 years ago

I don't think this function would work correctly before NFF-Go framework is at least initialized, maybe it should be even started to work correctly.

aregm commented 4 years ago

@AlekseyKanaev thanks for pointing this out - we should update the documentation to reflect the situation better. Packets are allocated in the memory which is addressable after the NFF-Go is initialized. As a reference example, please look into https://github.com/intel-go/nff-go/blob/master/examples/generate.go It shows how to do the whole flow correctly.

AlekseyKanaev commented 4 years ago

@AlekseyKanaev thanks for pointing this out - we should update the documentation to reflect the situation better. Packets are allocated in the memory which is addressable after the NFF-Go is initialized. As a reference example, please look into https://github.com/intel-go/nff-go/blob/master/examples/generate.go It shows how to do the whole flow correctly.

Thanks!!! That example helped me to resolve the issue.