diff --git a/example_test.go b/example_test.go index a866875..0c5c8e0 100644 --- a/example_test.go +++ b/example_test.go @@ -9,6 +9,7 @@ import ( "time" nfqueue "github.com/florianl/go-nfqueue" + "github.com/mdlayher/netlink" ) func ExampleNfqueue_RegisterWithErrorFunc() { @@ -31,6 +32,13 @@ func ExampleNfqueue_RegisterWithErrorFunc() { } defer nf.Close() + // Avoid receiving ENOBUFS errors. + if err := nf.SetOption(netlink.NoENOBUFS, true); err != nil { + fmt.Printf("failed to set netlink option %v: %v\n", + netlink.NoENOBUFS, err) + return + } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() diff --git a/nfqueue.go b/nfqueue.go index 527c829..25f8f91 100644 --- a/nfqueue.go +++ b/nfqueue.go @@ -131,6 +131,11 @@ func (nfqueue *Nfqueue) SetVerdictBatch(id uint32, verdict int) error { return nfqueue.setVerdict(id, verdict, true, []byte{}) } +// SetOption allows to enable or disable netlink socket options. +func (nfqueue *Nfqueue) SetOption(o netlink.ConnOption, enable bool) error { + return nfqueue.Con.SetOption(o, enable) +} + // Register your own function as callback for a netfilter queue. // // The registered callback will stop receiving data if an error