Skip to content

Commit

Permalink
Add start/stop callbacks to packet proxy
Browse files Browse the repository at this point in the history
This adds support for two additional functions in go plugins in the
`packet_proxy` module:

* `func OnStart() int`
* `func OnStop()`

These will be called when the packet proxy module is turned on and
off, respectively.
  • Loading branch information
drautb committed Mar 5, 2021
1 parent 17799c0 commit ce5c5eb
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion modules/packet_proxy/packet_proxy_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ func (mod *PacketProxy) Configure() (err error) {
return fmt.Errorf("Symbol OnPacket is not a valid callback function.")
}

if sym, err = mod.plugin.Lookup("OnStart"); err == nil {
var onStartCb func() int
if onStartCb, ok = sym.(func() int); !ok {
return fmt.Errorf("OnStart signature does not match expected signature: 'func() int'")
} else {
var result int
if result = onStartCb(); result != 0 {
return fmt.Errorf("OnStart returned non-zero result. result=%d", result)
}
}
}

mod.queue = new(nfqueue.Queue)
if err = mod.queue.SetCallback(dummyCallback); err != nil {
return
Expand Down Expand Up @@ -206,10 +218,22 @@ func (mod *PacketProxy) Start() error {
})
}

func (mod *PacketProxy) Stop() error {
func (mod *PacketProxy) Stop() (err error) {
return mod.SetRunning(false, func() {
mod.queue.StopLoop()
mod.runRule(false)

var sym plugin.Symbol
if sym, err = mod.plugin.Lookup("OnStop"); err == nil {
var onStopCb func()
var ok bool
if onStopCb, ok = sym.(func()); !ok {
mod.Error("OnStop signature does not match expected signature: 'func()', unable to call OnStop.")
} else {
onStopCb()
}
}

<-mod.done
})
}

0 comments on commit ce5c5eb

Please sign in to comment.