Finish static approach in favour of a simpler, more dynamic version.
[virt-mem.git] / extract / codegen / compile_kerneldb.ml
index 4ad221f..b9d3306 100644 (file)
@@ -92,6 +92,35 @@ let good_structs = [
   };
 ]
 
+(*----------------------------------------------------------------------
+ * These are the code fragments which run over kernel structures.
+ *----------------------------------------------------------------------*)
+
+let fragments = [
+  <:str_item<
+    let get_net_devices net_device =
+      let rec loop dev acc =
+       let ipv4 = net_device.ip_ptr.ifa_list in
+       let ipv4_addresses =
+         let rec loop2 ipv4 acc =
+           let addr = ipv4.ifa_address :: acc in
+           let ipv4 = ipv4.ifa_next in
+           loop2 ipv4
+         in
+         loop ipv4 [] in
+       let acc = ipv4_addresses :: acc in
+       let next = get_net_devices net_device.dev_list'next in
+       if next <> net_device then loop next
+       else acc
+  >>;
+
+  <:str_item<
+    let get_net_devices_from_init_net net =
+      get_net_devices net.dev_base_head'next
+  >>;
+
+]
+
 let debug = false
 
 open Camlp4.PreCast