diff --git a/modules/packet_proxy/packet_proxy_linux_amd64.go b/modules/packet_proxy/packet_proxy_linux_amd64.go index 0f4f7243..4d92dbb1 100644 --- a/modules/packet_proxy/packet_proxy_linux_amd64.go +++ b/modules/packet_proxy/packet_proxy_linux_amd64.go @@ -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 @@ -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 }) } diff --git a/network/net.go b/network/net.go index 2971d831..e117bcb9 100644 --- a/network/net.go +++ b/network/net.go @@ -101,10 +101,10 @@ func ParseTargets(targets string, aliasMap *data.UnsortedKV) (ips []net.IP, macs // first isolate MACs and parse them for _, mac := range macParser.FindAllString(targets, -1) { - mac = NormalizeMac(mac) - hw, err := net.ParseMAC(mac) + normalizedMac := NormalizeMac(mac) + hw, err := net.ParseMAC(normalizedMac) if err != nil { - return nil, nil, fmt.Errorf("error while parsing MAC '%s': %s", mac, err) + return nil, nil, fmt.Errorf("error while parsing MAC '%s': %s", normalizedMac, err) } macs = append(macs, hw) diff --git a/network/net_test.go b/network/net_test.go index 827d14d1..dcf08d8e 100644 --- a/network/net_test.go +++ b/network/net_test.go @@ -37,6 +37,14 @@ func TestNormalizeMac(t *testing.T) { // TODO: refactor to parse targets with an actual alias map func TestParseTargets(t *testing.T) { + aliasMap, err := data.NewMemUnsortedKV() + if err != nil { + panic(err) + } + + aliasMap.Set("5c:00:0b:90:a9:f0", "test_alias") + aliasMap.Set("5c:00:0b:90:a9:f1", "Home_Laptop") + cases := []struct { Name string InputTargets string @@ -57,9 +65,17 @@ func TestParseTargets(t *testing.T) { }, { "MACs are parsed", - "192.168.1.2, 192.168.1.3, 5c:00:0b:90:a9:f0, 6c:00:0b:90:a9:f0", + "192.168.1.2, 192.168.1.3, 5c:00:0b:90:a9:f0, 6c:00:0b:90:a9:f0, 6C:00:0B:90:A9:F0", &data.UnsortedKV{}, 2, + 3, + false, + }, + { + "Aliases are parsed", + "test_alias, Home_Laptop", + aliasMap, + 0, 2, false, },