Also add a missing step to run-in-tempdir that copies the Ganeti library
into the test tempdir.

Signed-off-by: Balazs Lecz <[email protected]>
---
 Makefile.am              |    1 +
 autotools/run-in-tempdir |    1 +
 lib/nflog_dispatcher.py  |   57 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 lib/nflog_dispatcher.py

diff --git a/Makefile.am b/Makefile.am
index 474c904..9c37d84 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -30,6 +30,7 @@ pkgpython_PYTHON = \
        lib/config.py \
        lib/iptables.py \
        lib/networktables.py \
+       lib/nflog_dispatcher.py \
        lib/server.py
 
 nodist_pkgpython_PYTHON = \
diff --git a/autotools/run-in-tempdir b/autotools/run-in-tempdir
index 6f620e6..468ddc3 100755
--- a/autotools/run-in-tempdir
+++ b/autotools/run-in-tempdir
@@ -7,5 +7,6 @@ trap "rm -rf $tmpdir" EXIT
 
 cp -r scripts lib test $tmpdir
 mv $tmpdir/lib $tmpdir/ganeti_nbma
+cp -r ganeti.git/lib $tmpdir/ganeti
 
 cd $tmpdir && "$@"
diff --git a/lib/nflog_dispatcher.py b/lib/nflog_dispatcher.py
new file mode 100644
index 0000000..fb67559
--- /dev/null
+++ b/lib/nflog_dispatcher.py
@@ -0,0 +1,57 @@
+#
+#
+
+# Copyright (C) 2009 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+
+"""Async NFLOG interface
+
+"""
+
+import asyncore
+import logging
+import nflog
+
+from socket import AF_INET
+
+def NFLogLoggingCallback(i, payload):
+  logging.debug("NFLogLoggingCallback() called. i: %s payload length: %s",
+                i, payload.get_length())
+  return 1
+
+
+class AsyncNFLog(asyncore.file_dispatcher):
+  """An asyncore dispatcher of NFLOG events.
+
+  """
+
+  def __init__(self, callback, log_group=0, family=AF_INET,
+               asyncore_channel_map=None):
+    self._q = nflog.log()
+    self._q.set_callback(callback)
+    self._q.fast_open(log_group, family)
+    self.fd = self._q.get_fd()
+    asyncore.file_dispatcher.__init__(self, self.fd, asyncore_channel_map)
+    self._q.set_mode(nflog.NFULNL_COPY_PACKET)
+
+  def handle_read(self):
+    self._q.process_pending(5)
+
+  # We don't need to check for the socket to be ready for writing
+  def writable(self):
+    return False
-- 
1.7.0.1

Reply via email to