From 2130352fd969e0d07dee19aa93d5f3369e89baa5 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Extract 'struct net' (for net namespaces). --- MANIFEST | 2 + extract/codegen/kerneldb_to_parser.ml | 8 +- lib/.depend | 11 +- lib/Makefile.in | 1 + lib/kernel_net.ml | 343 ++++++++++++++++++++++++++++++++++ lib/kernel_net.mli | 11 ++ 6 files changed, 371 insertions(+), 5 deletions(-) create mode 100644 lib/kernel_net.ml create mode 100644 lib/kernel_net.mli diff --git a/MANIFEST b/MANIFEST index 2da119d..dfaccfd 100644 --- a/MANIFEST +++ b/MANIFEST @@ -18,6 +18,8 @@ ifconfig/Makefile.in ifconfig/virt_ifconfig.ml install-sh lib/.depend +lib/kernel_net.ml +lib/kernel_net.mli lib/kernel_net_device.ml lib/kernel_net_device.mli lib/kernel_task_struct.ml diff --git a/extract/codegen/kerneldb_to_parser.ml b/extract/codegen/kerneldb_to_parser.ml index d78c108..4bda418 100644 --- a/extract/codegen/kerneldb_to_parser.ml +++ b/extract/codegen/kerneldb_to_parser.ml @@ -69,7 +69,13 @@ let structs = [ "name", { mandatory_field = true }; "dev_addr", { mandatory_field = true }; ] - } + }; + "net", { + opener = "struct net {"; closer = "};"; mandatory_struct = false; + fields = [ + "dev_base_head'next", { mandatory_field = true }; + ] + }; ] let debug = false diff --git a/lib/.depend b/lib/.depend index ccea623..3fbd7c9 100644 --- a/lib/.depend +++ b/lib/.depend @@ -1,17 +1,20 @@ kernel_net_device.cmi: virt_mem_types.cmi virt_mem_mmap.cmi +kernel_net.cmi: virt_mem_types.cmi virt_mem_mmap.cmi kernel_task_struct.cmi: virt_mem_types.cmi virt_mem_mmap.cmi virt_mem_kallsyms.cmi: virt_mem_types.cmi virt_mem_ksyms.cmi: virt_mem_types.cmi virt_mem.cmi: virt_mem_types.cmi virt_mem_mmap.cmi: virt_mem_utils.cmo -virt_mem_net_devices.cmi: virt_mem_types.cmi virt_mem_mmap.cmi -virt_mem_tasks.cmi: virt_mem_types.cmi virt_mem_mmap.cmi +virt_mem_net_devices.cmi: virt_mem_types.cmi +virt_mem_tasks.cmi: virt_mem_types.cmi virt_mem_types.cmi: virt_mem_utils.cmo virt_mem_mmap.cmi virt_mem_utsname.cmi: virt_mem_types.cmi kernel_net_device.cmo: virt_mem_types.cmi virt_mem_mmap.cmi \ kernel_net_device.cmi kernel_net_device.cmx: virt_mem_types.cmx virt_mem_mmap.cmx \ kernel_net_device.cmi +kernel_net.cmo: virt_mem_types.cmi virt_mem_mmap.cmi kernel_net.cmi +kernel_net.cmx: virt_mem_types.cmx virt_mem_mmap.cmx kernel_net.cmi kernel_task_struct.cmo: virt_mem_types.cmi virt_mem_mmap.cmi \ kernel_task_struct.cmi kernel_task_struct.cmx: virt_mem_types.cmx virt_mem_mmap.cmx \ @@ -42,10 +45,10 @@ virt_mem_mmap.cmo: virt_mem_utils.cmo virt_mem_mmap.cmi virt_mem_mmap.cmx: virt_mem_utils.cmx virt_mem_mmap.cmi virt_mem_net_devices.cmo: virt_mem_utils.cmo virt_mem_types.cmi \ virt_mem_mmap.cmi virt_mem_gettext.cmo kernel_net_device.cmi \ - virt_mem_net_devices.cmi + kernel_net.cmi virt_mem_net_devices.cmi virt_mem_net_devices.cmx: virt_mem_utils.cmx virt_mem_types.cmx \ virt_mem_mmap.cmx virt_mem_gettext.cmx kernel_net_device.cmx \ - virt_mem_net_devices.cmi + kernel_net.cmx virt_mem_net_devices.cmi virt_mem_tasks.cmo: virt_mem_utils.cmo virt_mem_types.cmi virt_mem_mmap.cmi \ virt_mem_gettext.cmo kernel_task_struct.cmi virt_mem_tasks.cmi virt_mem_tasks.cmx: virt_mem_utils.cmx virt_mem_types.cmx virt_mem_mmap.cmx \ diff --git a/lib/Makefile.in b/lib/Makefile.in index ee387f8..5232ee7 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -56,6 +56,7 @@ OBJS = virt_mem_gettext.cmo \ virt_mem_types.cmo \ kernel_task_struct.cmo \ kernel_net_device.cmo \ + kernel_net.cmo \ virt_mem_ksyms.cmo \ virt_mem_kallsyms.cmo \ virt_mem_utsname.cmo \ diff --git a/lib/kernel_net.ml b/lib/kernel_net.ml new file mode 100644 index 0000000..df4882c --- /dev/null +++ b/lib/kernel_net.ml @@ -0,0 +1,343 @@ +(* WARNING: This file and the corresponding mli (interface) are + * automatically generated by the extract/codegen/kerneldb_to_parser.ml + * program. + * + * Any edits you make to this file will be lost. + * + * To update this file from the latest kernel database, it is recommended + * that you do 'make update-kernel-structs'. + *) + +let zero = 0;; +let struct_name = "net";; +let match_err = "failed to match kernel structure";; +type t = { net_dev_base_head'next : Virt_mem_mmap.addr };; +type fs_t = { __fs_net_dev_base_head'next : Virt_mem_types.fieldsig };; +let fieldsig_1 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 64; }; + };; +let fieldsig_2 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 48; }; + };; +let fieldsig_3 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 72; }; + };; +let fieldsig_4 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 128; }; + };; +let fieldsig_5 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 48; }; + };; +let fieldsig_6 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 88; }; + };; +let fieldsig_7 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 120; }; + };; +let fieldsig_8 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 52; }; + };; +let fieldsig_9 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 96; }; + };; +let fieldsig_10 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 96; }; + };; +let fieldsig_11 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 56; }; + };; +let fieldsig_12 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 144; }; + };; +let fieldsig_13 = + { + (()) + with + __fs_net_dev_base_head'next = + { Virt_mem_types.field_available = true; field_offset = 144; }; + };; +let parser_1 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+32 : offset(512), littleendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 64L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_1", match_err));; +let parser_2 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+32 : offset(384), littleendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 48L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_2", match_err));; +let parser_3 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+32 : offset(576), littleendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 72L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_3", match_err));; +let parser_4 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+64 : offset(1024), littleendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 128L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_4", match_err));; +let parser_5 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+32 : offset(384), bigendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 48L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_5", match_err));; +let parser_6 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+64 : offset(704), bigendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 88L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_6", match_err));; +let parser_7 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+64 : offset(960), littleendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 120L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_7", match_err));; +let parser_8 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+32 : offset(416), littleendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 52L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_8", match_err));; +let parser_9 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+64 : offset(768), littleendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 96L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_9", match_err));; +let parser_10 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+64 : offset(768), bigendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 96L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_10", match_err));; +let parser_11 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+32 : offset(448), bigendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 56L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_11", match_err));; +let parser_12 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+64 : offset(1152), bigendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 144L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_12", match_err));; +let parser_13 bits = + bitmatch bits with + | { net_dev_base_head'next : zero+64 : offset(1152), littleendian } -> + { net_dev_base_head'next = Int64.sub net_dev_base_head'next 144L } + | { _ } -> + raise (Virt_mem_types.ParseError (struct_name, "parser_13", match_err));; +module StringMap = Map.Make(String);; +let map = StringMap.empty;; +let v = (parser_1, 732, fieldsig_1);; +let map = StringMap.add "2.6.26.2-2.fc8.i686" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-0.167.rc8.git4.fc9.i686" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-7.fc9.i686" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-9.fc9.i686" v map;; +let v = (parser_2, 660, fieldsig_2);; +let map = StringMap.add "2.6.26.2-2.fc8.i686" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.231.rc1.git6.fc10.i686" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.237.rc2.fc10.i686" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.238.rc2.fc10.i686" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.241.rc2.git1.fc10.i686" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.244.rc2.git1.fc10.i686" v map;; +let v = (parser_1, 732, fieldsig_1);; +let map = StringMap.add "2.6.26.2-2.fc8.i686" v map;; +let v = (parser_4, 1352, fieldsig_4);; +let map = StringMap.add "2.6.26.2-2.fc8.x86_64" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-0.167.rc8.git4.fc9.i586" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-0.167.rc8.git4.fc9.i686" v map;; +let v = (parser_5, 64, fieldsig_5);; +let map = StringMap.add "2.6.24-0.167.rc8.git4.fc9.ppc" v map;; +let v = (parser_6, 120, fieldsig_6);; +let map = StringMap.add "2.6.24-0.167.rc8.git4.fc9.ppc64" v map;; +let v = (parser_7, 152, fieldsig_7);; +let map = StringMap.add "2.6.24-0.167.rc8.git4.fc9.x86_64" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-7.fc9.i586" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-7.fc9.i686" v map;; +let v = (parser_5, 64, fieldsig_5);; +let map = StringMap.add "2.6.24-7.fc9.ppc" v map;; +let v = (parser_6, 120, fieldsig_6);; +let map = StringMap.add "2.6.24-7.fc9.ppc64" v map;; +let v = (parser_7, 152, fieldsig_7);; +let map = StringMap.add "2.6.24-7.fc9.x86_64" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-9.fc9.i586" v map;; +let v = (parser_1, 80, fieldsig_1);; +let map = StringMap.add "2.6.24-9.fc9.i686" v map;; +let v = (parser_5, 64, fieldsig_5);; +let map = StringMap.add "2.6.24-9.fc9.ppc" v map;; +let v = (parser_6, 120, fieldsig_6);; +let map = StringMap.add "2.6.24-9.fc9.ppc64" v map;; +let v = (parser_7, 152, fieldsig_7);; +let map = StringMap.add "2.6.24-9.fc9.x86_64" v map;; +let v = (parser_8, 284, fieldsig_8);; +let map = StringMap.add "2.6.25.11-97.fc9.i686" v map;; +let v = (parser_9, 488, fieldsig_9);; +let map = StringMap.add "2.6.25.11-97.fc9.x86_64" v map;; +let v = (parser_2, 660, fieldsig_2);; +let map = StringMap.add "2.6.26.2-2.fc8.i586" v map;; +let v = (parser_2, 660, fieldsig_2);; +let map = StringMap.add "2.6.26.2-2.fc8.i686" v map;; +let v = (parser_5, 652, fieldsig_5);; +let map = StringMap.add "2.6.26.2-2.fc8.ppc" v map;; +let v = (parser_10, 1224, fieldsig_10);; +let map = StringMap.add "2.6.26.2-2.fc8.ppc64" v map;; +let v = (parser_9, 1224, fieldsig_9);; +let map = StringMap.add "2.6.26.2-2.fc8.x86_64" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.231.rc1.git6.fc10.i686" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.237.rc2.fc10.i586" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.237.rc2.fc10.i686" v map;; +let v = (parser_11, 860, fieldsig_11);; +let map = StringMap.add "2.6.27-0.237.rc2.fc10.ppc" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.237.rc2.fc10.ppc64" v map;; +let v = (parser_13, 1680, fieldsig_13);; +let map = StringMap.add "2.6.27-0.237.rc2.fc10.x86_64" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.238.rc2.fc10.i586" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.238.rc2.fc10.i686" v map;; +let v = (parser_11, 860, fieldsig_11);; +let map = StringMap.add "2.6.27-0.238.rc2.fc10.ppc" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.238.rc2.fc10.ppc64" v map;; +let v = (parser_13, 1680, fieldsig_13);; +let map = StringMap.add "2.6.27-0.238.rc2.fc10.x86_64" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.241.rc2.git1.fc10.i586" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.241.rc2.git1.fc10.i686" v map;; +let v = (parser_11, 860, fieldsig_11);; +let map = StringMap.add "2.6.27-0.241.rc2.git1.fc10.ppc" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.241.rc2.git1.fc10.ppc64" v map;; +let v = (parser_13, 1680, fieldsig_13);; +let map = StringMap.add "2.6.27-0.241.rc2.git1.fc10.x86_64" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.244.rc2.git1.fc10.i586" v map;; +let v = (parser_3, 912, fieldsig_3);; +let map = StringMap.add "2.6.27-0.244.rc2.git1.fc10.i686" v map;; +let v = (parser_11, 860, fieldsig_11);; +let map = StringMap.add "2.6.27-0.244.rc2.git1.fc10.ppc" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.244.rc2.git1.fc10.ppc64" v map;; +let v = (parser_13, 1680, fieldsig_13);; +let map = StringMap.add "2.6.27-0.244.rc2.git1.fc10.x86_64" v map;; +let v = (parser_6, 120, fieldsig_6);; +let map = StringMap.add "2.6.24-0.167.rc8.git4.fc9.ppc64" v map;; +let v = (parser_6, 120, fieldsig_6);; +let map = StringMap.add "2.6.24-7.fc9.ppc64" v map;; +let v = (parser_6, 120, fieldsig_6);; +let map = StringMap.add "2.6.24-9.fc9.ppc64" v map;; +let v = (parser_10, 1224, fieldsig_10);; +let map = StringMap.add "2.6.26.2-2.fc8.ppc64" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.231.rc1.git6.fc10.ppc64" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.237.rc2.fc10.ppc64" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.238.rc2.fc10.ppc64" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.241.rc2.git1.fc10.ppc64" v map;; +let v = (parser_12, 1680, fieldsig_12);; +let map = StringMap.add "2.6.27-0.244.rc2.git1.fc10.ppc64" v map;; +let v = (parser_5, 64, fieldsig_5);; +let map = StringMap.add "2.6.24-0.167.rc8.git4.fc9.ppc" v map;; +let v = (parser_5, 64, fieldsig_5);; +let map = StringMap.add "2.6.24-7.fc9.ppc" v map;; +let v = (parser_5, 64, fieldsig_5);; +let map = StringMap.add "2.6.24-9.fc9.ppc" v map;; +let v = (parser_5, 660, fieldsig_5);; +let map = StringMap.add "2.6.26.2-2.fc8.ppc" v map;; +let v = (parser_11, 864, fieldsig_11);; +let map = StringMap.add "2.6.27-0.237.rc2.fc10.ppc" v map;; +let v = (parser_11, 864, fieldsig_11);; +let map = StringMap.add "2.6.27-0.238.rc2.fc10.ppc" v map;; +let v = (parser_11, 864, fieldsig_11);; +let map = StringMap.add "2.6.27-0.241.rc2.git1.fc10.ppc" v map;; +let v = (parser_11, 864, fieldsig_11);; +let map = StringMap.add "2.6.27-0.244.rc2.git1.fc10.ppc" v map;; +type kernel_version = string;; +let net_known version = StringMap.mem version map;; +let net_size version = + let (_, size, _) = StringMap.find version map in size;; +let net_of_bits version bits = + let (parsefn, _, _) = StringMap.find version map in parsefn bits;; +let get_net version mem addr = + let (parsefn, size, _) = StringMap.find version map in + let bytes = Virt_mem_mmap.get_bytes mem addr size in + let bits = Bitstring.bitstring_of_string bytes in parsefn bits;; +let field_signature_of_net_dev_base_head'next version = + let (_, _, fs) = StringMap.find version map + in fs.__fs_net_dev_base_head'next;; diff --git a/lib/kernel_net.mli b/lib/kernel_net.mli new file mode 100644 index 0000000..2a0ffa7 --- /dev/null +++ b/lib/kernel_net.mli @@ -0,0 +1,11 @@ +type t = { net_dev_base_head'next : Virt_mem_mmap.addr };; +val struct_name : string;; +type kernel_version = string;; +val net_known : kernel_version -> bool;; +val net_size : kernel_version -> int;; +val net_of_bits : kernel_version -> Bitstring.bitstring -> t;; +val get_net : + kernel_version -> + ('a, 'b, [ | `HasMapping ]) Virt_mem_mmap.t -> Virt_mem_mmap.addr -> t;; +val field_signature_of_net_dev_base_head'next : + kernel_version -> Virt_mem_types.fieldsig;; -- 1.8.3.1