Also, remove unnecessary imports.
Signed-off-by: Balazs Lecz <[email protected]>
---
daemons/ganeti-nld | 20 ++++++++++++++++++++
lib/nflog_dispatcher.py | 3 +--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/daemons/ganeti-nld b/daemons/ganeti-nld
index 7f16cdf..c6755ba 100755
--- a/daemons/ganeti-nld
+++ b/daemons/ganeti-nld
@@ -36,6 +36,7 @@ Ganeti, on the cluster hmac key and master candidate list
being available.
import os
import sys
import logging
+import ip
from optparse import OptionParser
@@ -375,6 +376,20 @@ class NLDPeriodicUpdater(object):
self.confd_client.SendRequest(req)
+class MisroutedPacketHandler(object):
+ """Callback called when a packet is received via the NFLOG target.
+
+ """
+ def __call__(self, i, nflog_payload):
+ ip_packet = ip.disassemble(nflog_payload.get_data())
+ logging.debug("misrouted packet detected. source IP: %s", ip_packet.src)
+ # TODO: notify the endpoint(s) via an NLD request (preferably by iterating
+ # over the private IPs of the endpoints)
+ # TODO: look up the source IP in the peer list and if found, notify the
+ # relevant node
+ return 1
+
+
class NetworkLookupDaemon(object):
"""Main Ganeti NLD class
@@ -436,6 +451,11 @@ class NetworkLookupDaemon(object):
NLDPeriodicUpdater(cluster_name, mainloop, self.config,
hmac_key, mc_list, peer_set_manager)
)
+
+ misrouted_packet_callback = MisroutedPacketHandler()
+ # TODO: we should get the log_group number from the config
+ nflog_dispatcher.AsyncNFLog(misrouted_packet_callback, log_group=0)
+
mainloop.Run()
diff --git a/lib/nflog_dispatcher.py b/lib/nflog_dispatcher.py
index 857bac0..fb67559 100644
--- a/lib/nflog_dispatcher.py
+++ b/lib/nflog_dispatcher.py
@@ -26,9 +26,8 @@
import asyncore
import logging
import nflog
-import sys
-from socket import AF_INET, inet_ntoa
+from socket import AF_INET
def NFLogLoggingCallback(i, payload):
logging.debug("NFLogLoggingCallback() called. i: %s payload length: %s",
--
1.6.6.2