mirror of
https://github.com/bettercap/bettercap
synced 2025-07-30 03:29:57 -07:00
Add start/stop callbacks to packet proxy
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.
This commit is contained in:
parent
17799c0357
commit
ce5c5eb592
1 changed files with 25 additions and 1 deletions
|
@ -161,6 +161,18 @@ func (mod *PacketProxy) Configure() (err error) {
|
||||||
return fmt.Errorf("Symbol OnPacket is not a valid callback function.")
|
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)
|
mod.queue = new(nfqueue.Queue)
|
||||||
if err = mod.queue.SetCallback(dummyCallback); err != nil {
|
if err = mod.queue.SetCallback(dummyCallback); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -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() {
|
return mod.SetRunning(false, func() {
|
||||||
mod.queue.StopLoop()
|
mod.queue.StopLoop()
|
||||||
mod.runRule(false)
|
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
|
<-mod.done
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue