Browse Source

Move all callouts in the same file, to simplify code sharing

Baptiste Jonglez 7 years ago
parent
commit
b7cabeec0f
3 changed files with 21 additions and 38 deletions
  1. 2 3
      Makefile
  2. 19 0
      src/pkt_receive.cc
  3. 0 35
      src/lease_select.cc

+ 2 - 3
Makefile

@@ -1,5 +1,5 @@
 
-OBJECTS = src/load.o src/runscript.o src/pkt_receive.o src/lease_select.o src/version.o
+OBJECTS = src/load.o src/runscript.o src/callouts.o src/version.o
 CXXFLAGS = -I /usr/include/kea -fPIC -Wno-deprecated
 LDFLAGS = -L /usr/lib/kea/lib -shared -lkea-dhcpsrv -lkea-dhcp++ -lkea-hooks -lkea-log -lkea-util -lkea-exceptions
 
@@ -9,8 +9,7 @@ kea-hook-runscript.so: $(OBJECTS)
 %.o: %.cc
 	g++ -c $(CXXFLAGS) -o $@ $<
 
-src/pkt_receive.o: src/runscript.h
-src/lease_select.o: src/runscript.h
+src/callouts.o: src/runscript.h
 src/load.o: src/common.h
 src/runscript.o: src/common.h
 

+ 19 - 0
src/pkt_receive.cc

@@ -2,6 +2,8 @@
 #include <dhcp/pkt4.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/pkt6.h>
+#include <dhcpsrv/subnet.h>
+#include <dhcpsrv/lease.h>
 
 #include <string>
 #include <vector>
@@ -33,4 +35,21 @@ int pkt4_receive(CalloutHandle& handle) {
     return 0;
 }
 
+int lease4_select(CalloutHandle& handle) {
+    std::vector<std::string> env;
+    Pkt4Ptr query;
+    Subnet4Ptr subnet;
+    bool fake_allocation;
+    Lease4Ptr lease;
+    handle.getArgument("query4", query);
+    handle.getArgument("subnet4", subnet);
+    handle.getArgument("fake_allocation", fake_allocation);
+    handle.getArgument("lease4", lease);
+    /* Run script */
+    int ret;
+    ret = run_script("lease4_select", env);
+    fprintf(stderr, "ret = %d\n", ret);
+    return 0;
+}
+
 } // end extern "C"

+ 0 - 35
src/lease_select.cc

@@ -1,35 +0,0 @@
-#include <hooks/hooks.h>
-#include <dhcp/pkt4.h>
-#include <dhcp/dhcp6.h>
-#include <dhcp/pkt6.h>
-#include <dhcpsrv/subnet.h>
-#include <dhcpsrv/lease.h>
-
-#include <string>
-#include <vector>
-
-#include "runscript.h"
-
-using namespace isc::dhcp;
-using namespace isc::hooks;
-
-extern "C" {
-
-int lease4_select(CalloutHandle& handle) {
-    std::vector<std::string> env;
-    Pkt4Ptr query;
-    Subnet4Ptr subnet;
-    bool fake_allocation;
-    Lease4Ptr lease;
-    handle.getArgument("query4", query);
-    handle.getArgument("subnet4", subnet);
-    handle.getArgument("fake_allocation", fake_allocation);
-    handle.getArgument("lease4", lease);
-    /* Run script */
-    int ret;
-    ret = run_script("lease4_select", env);
-    fprintf(stderr, "ret = %d\n", ret);
-    return 0;
-}
-
-} // end extern "C"