diff --git a/.travis.yml b/.travis.yml index 117682db1..beb37baa5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,4 @@ language: c script: bash -ex .travis-ci.sh env: - OCAML_VERSION=4.02 PACKAGE=tcpip MIRAGE_MODE=unix - - UPDATE_GCC_BINUTILS=1 OCAML_VERSION=4.01 PACKAGE=tcpip MIRAGE_MODE=xen + - UPDATE_GCC_BINUTILS=1 OCAML_VERSION=4.02 PACKAGE=tcpip MIRAGE_MODE=xen diff --git a/_oasis b/_oasis index ab0a80a84..5a5798aa5 100644 --- a/_oasis +++ b/_oasis @@ -21,7 +21,7 @@ Library tcpip Modules: Wire_structs, Tcpip_checksum CSources: checksum_stubs.c CCOpt: -O2 -fno-stack-protector - BuildDepends: io-page,mirage-types,ipaddr,cstruct,mirage-profile,bytes + BuildDepends: io-page,mirage-types,ipaddr,cstruct (>= 1.9.0),cstruct.ppx,mirage-profile,bytes XMETAExtraLines: xen_linkopts = "-ltcpip_xen_stubs" Library tcpip_xen @@ -47,7 +47,7 @@ Library arpv4 Findlibparent: tcpip Findlibname: arpv4 Modules: Arpv4, Arpv4_wire - BuildDepends: tcpip,io-page,mirage-types,ipaddr,cstruct,lwt,cstruct.syntax + BuildDepends: tcpip,io-page,mirage-types,ipaddr,cstruct,cstruct.ppx,lwt Library ipv4 CompiledObject: best @@ -86,6 +86,7 @@ Library tcp mirage-types, ipaddr, cstruct, + cstruct.ppx, lwt, tcpip, tcpip.ipv4, @@ -102,6 +103,7 @@ Library dhcpv4 mirage-types, ipaddr, cstruct, + cstruct.ppx, lwt, tcpip.udp diff --git a/_tags b/_tags index 23bab04f3..f39bb3d02 100644 --- a/_tags +++ b/_tags @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: b9afd8f7c25862ce87cac4dd55d2c26b) +# DO NOT EDIT (digest: 6a44a55461c4e9df093a8f9c75510319) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -21,6 +21,7 @@ true: annot, bin_annot : use_libtcpip_stubs "lib/checksum_stubs.c": pkg_bytes "lib/checksum_stubs.c": pkg_cstruct +"lib/checksum_stubs.c": pkg_cstruct.ppx "lib/checksum_stubs.c": pkg_io-page "lib/checksum_stubs.c": pkg_ipaddr "lib/checksum_stubs.c": pkg_mirage-profile @@ -57,6 +58,7 @@ true: annot, bin_annot "tcp/log.cmx": for-pack(Tcp) : pkg_bytes : pkg_cstruct +: pkg_cstruct.ppx : pkg_io-page : pkg_ipaddr : pkg_lwt @@ -69,6 +71,7 @@ true: annot, bin_annot "dhcp/dhcpv4.cmxs": use_dhcpv4 : pkg_bytes : pkg_cstruct +: pkg_cstruct.ppx : pkg_io-page : pkg_ipaddr : pkg_lwt @@ -80,7 +83,7 @@ true: annot, bin_annot "lib/tcpip-stack-direct.cmxs": use_tcpip-stack-direct : pkg_bytes : pkg_cstruct -: pkg_cstruct.syntax +: pkg_cstruct.ppx : pkg_io-page : pkg_ipaddr : pkg_lwt @@ -121,7 +124,6 @@ true: annot, bin_annot # Library tcpip-stack-unix "unix/tcpip-stack-unix.cmxs": use_tcpip-stack-unix : pkg_channel -: pkg_cstruct.syntax : pkg_mirage-clock-unix : pkg_mirage-console.unix : pkg_mirage-net-unix @@ -146,6 +148,7 @@ true: annot, bin_annot : pkg_bytes : pkg_cstruct : pkg_cstruct.lwt +: pkg_cstruct.ppx : pkg_io-page : pkg_io-page.unix : pkg_ipaddr @@ -164,6 +167,7 @@ true: annot, bin_annot : pkg_alcotest : pkg_bytes : pkg_cstruct +: pkg_cstruct.ppx : pkg_io-page : pkg_io-page.unix : pkg_ipaddr @@ -185,6 +189,7 @@ true: annot, bin_annot : pkg_alcotest : pkg_bytes : pkg_cstruct +: pkg_cstruct.ppx : pkg_io-page : pkg_io-page.unix : pkg_ipaddr @@ -206,7 +211,3 @@ true: annot, bin_annot : custom # OASIS_STOP true: annot, bin_annot, principal, strict_sequence, debug -: pkg_cstruct.syntax -: pkg_cstruct.syntax -: pkg_cstruct.syntax -: pkg_cstruct.syntax diff --git a/dhcp/dhcp_clientv4.ml b/dhcp/dhcp_clientv4.ml index 701810f1d..cf67a13a9 100644 --- a/dhcp/dhcp_clientv4.ml +++ b/dhcp/dhcp_clientv4.ml @@ -47,28 +47,31 @@ module Make (Console : V1_LWT.CONSOLE) new_offer: offer -> unit Lwt.t; } - cstruct dhcp { - uint8_t op; - uint8_t htype; - uint8_t hlen; - uint8_t hops; - uint32_t xid; - uint16_t secs; - uint16_t flags; - uint32_t ciaddr; - uint32_t yiaddr; - uint32_t siaddr; - uint32_t giaddr; - uint8_t chaddr[16]; - uint8_t sname[64]; - uint8_t file[128]; - uint32_t cookie - } as big_endian - - cenum mode { - BootRequest = 1; - BootReply - } as uint8_t + [%%cstruct + type dhcp = { + op: uint8_t; + htype: uint8_t; + hlen: uint8_t; + hops: uint8_t; + xid: uint32_t; + secs: uint16_t; + flags: uint16_t; + ciaddr: uint32_t; + yiaddr: uint32_t; + siaddr: uint32_t; + giaddr: uint32_t; + chaddr: uint8_t [@len 16]; + sname: uint8_t [@len 64]; + file: uint8_t [@len 128]; + cookie: uint32_t; + } [@@big_endian] + ] + [%%cenum + type mode = + | BootRequest [@id 1] + | BootReply + [@@uint8_t] + ] (* Send a client broadcast packet *) let output_broadcast t ~xid ~yiaddr ~siaddr ~options = diff --git a/lib/META b/lib/META index f8e0c7ce9..0a936b096 100644 --- a/lib/META +++ b/lib/META @@ -1,8 +1,9 @@ # OASIS_START -# DO NOT EDIT (digest: 06d8e8b17cbfae174a9767c2a28f3f58) +# DO NOT EDIT (digest: 3f12cfe87c7d547b44dcc966f9839ab9) version = "2.6.1" description = "Ethernet, TCP/IPv4 and DHCPv4 library" -requires = "io-page mirage-types ipaddr cstruct mirage-profile bytes" +requires = +"io-page mirage-types ipaddr cstruct cstruct.ppx mirage-profile bytes" archive(byte) = "tcpip.cma" archive(byte, plugin) = "tcpip.cma" archive(native) = "tcpip.cmxa" @@ -126,7 +127,7 @@ package "tcp" ( version = "2.6.1" description = "Ethernet, TCP/IPv4 and DHCPv4 library" requires = - "io-page mirage-types ipaddr cstruct lwt tcpip tcpip.ipv4 tcpip.ipv6 mirage-profile" + "io-page mirage-types ipaddr cstruct cstruct.ppx lwt tcpip tcpip.ipv4 tcpip.ipv6 mirage-profile" archive(byte) = "tcp.cma" archive(byte, plugin) = "tcp.cma" archive(native) = "tcp.cmxa" @@ -239,7 +240,8 @@ package "ethif" ( package "dhcpv4" ( version = "2.6.1" description = "Ethernet, TCP/IPv4 and DHCPv4 library" - requires = "io-page bytes mirage-types ipaddr cstruct lwt tcpip.udp" + requires = + "io-page bytes mirage-types ipaddr cstruct cstruct.ppx lwt tcpip.udp" archive(byte) = "dhcpv4.cma" archive(byte, plugin) = "dhcpv4.cma" archive(native) = "dhcpv4.cmxa" @@ -261,7 +263,7 @@ package "arpv4-unix" ( package "arpv4" ( version = "2.6.1" description = "Ethernet, TCP/IPv4 and DHCPv4 library" - requires = "tcpip io-page mirage-types ipaddr cstruct lwt cstruct.syntax" + requires = "tcpip io-page mirage-types ipaddr cstruct cstruct.ppx lwt" archive(byte) = "arpv4.cma" archive(byte, plugin) = "arpv4.cma" archive(native) = "arpv4.cmxa" diff --git a/lib/arpv4_wire.ml b/lib/arpv4_wire.ml index f32122eeb..a209185e2 100644 --- a/lib/arpv4_wire.ml +++ b/lib/arpv4_wire.ml @@ -1,16 +1,20 @@ -cstruct arp { - uint16_t htype; - uint16_t ptype; - uint8_t hlen; - uint8_t plen; - uint16_t op; - uint8_t sha[6]; - uint32_t spa; - uint8_t tha[6]; - uint32_t tpa -} as big_endian +[%%cstruct +type arp = { + htype: uint16_t; + ptype: uint16_t; + hlen: uint8_t; + plen: uint8_t; + op: uint16_t; + sha: uint8_t [@len 6]; + spa: uint32_t; + tha: uint8_t [@len 6]; + tpa: uint32_t; +} [@@big_endian] +] -cenum op { - Op_request = 1; - Op_reply -} as uint16_t +[@@cenum +type op = + | Op_request [@id 1] + | Op_reply + [@@uint16_t] +] diff --git a/lib/wire_structs.ml b/lib/wire_structs.ml index 9f1e700ee..169956018 100644 --- a/lib/wire_structs.ml +++ b/lib/wire_structs.ml @@ -1,14 +1,18 @@ -cstruct ethernet { - uint8_t dst[6]; - uint8_t src[6]; - uint16_t ethertype - } as big_endian - -cenum ethertype { - ARP = 0x0806; - IPv4 = 0x0800; - IPv6 = 0x86dd; - } as uint16_t +[%%cstruct +type ethernet = { + dst: uint8_t [@len 6]; + src: uint8_t [@len 6]; + ethertype: uint16_t; + } [@@big_endian] +] + +[%%cenum +type ethertype = + | ARP [@id 0x0806] + | IPv4 [@id 0x0800] + | IPv6 [@id 0x86dd] + [@@uint16_t] +] let parse_ethernet_frame frame = if Cstruct.len frame >= 14 then @@ -22,35 +26,39 @@ let parse_ethernet_frame frame = None -cstruct udp { - uint16_t source_port; - uint16_t dest_port; - uint16_t length; - uint16_t checksum - } as big_endian +[%%cstruct +type udp = { + source_port: uint16_t; + dest_port: uint16_t; + length: uint16_t; + checksum: uint16_t; + } [@@big_endian] +] module Ipv4_wire = struct - cstruct ipv4 { - uint8_t hlen_version; - uint8_t tos; - uint16_t len; - uint16_t id; - uint16_t off; - uint8_t ttl; - uint8_t proto; - uint16_t csum; - uint32_t src; - uint32_t dst - } as big_endian - - cstruct icmpv4 { - uint8_t ty; - uint8_t code; - uint16_t csum; - uint16_t id; - uint16_t seq - } as big_endian - + [%%cstruct + type ipv4 = { + hlen_version: uint8_t; + tos: uint8_t; + len: uint16_t; + id: uint16_t; + off: uint16_t; + ttl: uint8_t; + proto: uint8_t; + csum: uint16_t; + src: uint32_t; + dst: uint32_t; + } [@@big_endian] + ] + [%%cstruct + type icmpv4 = { + ty: uint8_t; + code: uint8_t; + csum: uint16_t; + id: uint16_t; + seq: uint16_t; + } [@@big_endian] + ] let int_to_protocol = function | 1 -> Some `ICMP | 6 -> Some `TCP @@ -77,25 +85,29 @@ module Ipv4_wire = struct end module Tcp_wire = struct - cstruct tcp { - uint16_t src_port; - uint16_t dst_port; - uint32_t sequence; - uint32_t ack_number; - uint8_t dataoff; - uint8_t flags; - uint16_t window; - uint16_t checksum; - uint16_t urg_ptr - } as big_endian - - cstruct tcpv4_pseudo_header { - uint32_t src; - uint32_t dst; - uint8_t res; - uint8_t proto; - uint16_t len - } as big_endian + [%%cstruct + type tcp = { + src_port: uint16_t; + dst_port: uint16_t; + sequence: uint32_t; + ack_number: uint32_t; + dataoff: uint8_t; + flags: uint8_t; + window: uint16_t; + checksum: uint16_t; + urg_ptr: uint16_t; + } [@@big_endian] + ] + + [%%cstruct + type tcpv4_pseudo_header = { + src: uint32_t; + dst: uint32_t; + res: uint8_t; + proto: uint8_t; + len: uint16_t; + } [@@big_endian] + ] (* XXX note that we overwrite the lower half of dataoff * with 0, so be careful when implemented CWE flag which @@ -131,14 +143,16 @@ module Tcp_wire = struct end module Ipv6_wire = struct - cstruct ipv6 { - uint32_t version_flow; - uint16_t len; (* payload length (includes extensions) *) - uint8_t nhdr; (* next header *) - uint8_t hlim; (* hop limit *) - uint8_t src[16]; - uint8_t dst[16] - } as big_endian + [%%cstruct + type ipv6 = { + version_flow: uint32_t; + len: uint16_t; (* payload length (includes extensions) *) + nhdr: uint8_t; (* next header *) + hlim: uint8_t; (* hop limit *) + src: uint8_t [@len 16]; + dst: uint8_t [@len 16]; + } [@@big_endian] + ] let int_to_protocol = function | 58 -> Some `ICMP @@ -151,37 +165,42 @@ module Ipv6_wire = struct | `TCP -> 6 | `UDP -> 17 - cstruct icmpv6 { - uint8_t ty; - uint8_t code; - uint16_t csum; - uint32_t reserved - } as big_endian - - cstruct pingv6 { - uint8_t ty; - uint8_t code; - uint16_t csum; - uint16_t id; - uint16_t seq - } as big_endian - - cstruct ns { - uint8_t ty; - uint8_t code; - uint16_t csum; - uint32_t reserved; - uint8_t target[16] - } as big_endian - - cstruct na { - uint8_t ty; - uint8_t code; - uint16_t csum; - uint32_t reserved; - uint8_t target[16] - } as big_endian - + [%%cstruct + type icmpv6 = { + ty: uint8_t; + code: uint8_t; + csum: uint16_t; + reserved: uint32_t; + } [@@big_endian] + ] + + [%%cstruct + type pingv6 = { + ty: uint8_t; + code: uint8_t; + csum: uint16_t; + id: uint16_t; + seq: uint16_t; + } [@@big_endian] + ] + [%%cstruct + type ns = { + ty: uint8_t; + code: uint8_t; + csum: uint16_t; + reserved: uint32_t; + target: uint8_t [@len 16]; + } [@@big_endian] + ] + [%%cstruct + type na = { + ty: uint8_t; + code: uint8_t; + csum: uint16_t; + reserved: uint32_t; + target: uint8_t [@len 16]; + } [@@big_endian] + ] let get_na_router buf = (Cstruct.get_uint8 buf 4 land 0x80) <> 0 @@ -191,51 +210,57 @@ module Ipv6_wire = struct let get_na_override buf = (Cstruct.get_uint8 buf 4 land 0x20) <> 0 - cstruct rs { - uint8_t ty; - uint8_t code; - uint16_t csum; - uint32_t reserved - } as big_endian - - cstruct opt_prefix { - uint8_t ty; - uint8_t len; - uint8_t prefix_len; - uint8_t reserved1; - uint32_t valid_lifetime; - uint32_t preferred_lifetime; - uint32_t reserved2; - uint8_t prefix[16] - } as big_endian - + [%%cstruct + type rs = { + ty: uint8_t; + code: uint8_t; + csum: uint16_t; + reserved: uint32_t; + } [@@big_endian] + ] + [%%cstruct + type opt_prefix = { + ty: uint8_t; + len: uint8_t; + prefix_len: uint8_t; + reserved1: uint8_t; + valid_lifetime: uint32_t; + preferred_lifetime: uint32_t; + reserved2: uint32_t; + prefix: uint8_t [@len 16]; + } [@@big_endian] + ] let get_opt_prefix_on_link buf = get_opt_prefix_reserved1 buf land 0x80 <> 0 let get_opt_prefix_autonomous buf = get_opt_prefix_reserved1 buf land 0x40 <> 0 - cstruct opt { - uint8_t ty; - uint8_t len - } as big_endian - - cstruct llopt { - uint8_t ty; - uint8_t len; - uint8_t addr[6] - } as big_endian - - cstruct ra { - uint8_t ty; - uint8_t code; - uint16_t csum; - uint8_t cur_hop_limit; - uint8_t reserved; - uint16_t router_lifetime; - uint32_t reachable_time; - uint32_t retrans_timer - } as big_endian - + [%%cstruct + type opt = { + ty: uint8_t; + len: uint8_t; + } [@@big_endian] + ] + [%%cstruct + type llopt = { + ty: uint8_t; + len: uint8_t; + addr: uint8_t [@len 6]; + } [@@big_endian] + ] + + [%%cstruct + type ra = { + ty: uint8_t; + code: uint8_t; + csum: uint16_t; + cur_hop_limit: uint8_t; + reserved: uint8_t; + router_lifetime: uint16_t; + reachable_time: uint32_t; + retrans_timer: uint32_t; + } [@@big_endian] + ] let sizeof_ipv6_pseudo_header = 16 + 16 + 4 + 4 end diff --git a/opam b/opam index 6b6243b21..8893cbbc6 100644 --- a/opam +++ b/opam @@ -29,7 +29,8 @@ install: [make "install"] remove: ["ocamlfind" "remove" "tcpip"] depends: [ "ocamlfind" {build} - "cstruct" {>= "1.6.0"} + "cstruct" {>= "1.9.0"} + "ppx_tools" "channel" "mirage-types" {>= "2.6.0"} "mirage-unix" {>= "1.1.0"} diff --git a/setup.ml b/setup.ml index f149cac01..85d1151f7 100644 --- a/setup.ml +++ b/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.4.5 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 1da3910312b5ae7779af64e068743ba1) *) +(* DO NOT EDIT (digest: 4d4812ef99aa0612194432681173cd76) *) (* Regenerated by OASIS v0.4.5 Visit http://oasis.forge.ocamlcore.org for more information and @@ -6942,7 +6942,10 @@ let setup_t = FindlibPackage ("io-page", None); FindlibPackage ("mirage-types", None); FindlibPackage ("ipaddr", None); - FindlibPackage ("cstruct", None); + FindlibPackage + ("cstruct", + Some (OASISVersion.VGreaterEqual "1.9.0")); + FindlibPackage ("cstruct.ppx", None); FindlibPackage ("mirage-profile", None); FindlibPackage ("bytes", None) ]; @@ -7059,8 +7062,8 @@ let setup_t = FindlibPackage ("mirage-types", None); FindlibPackage ("ipaddr", None); FindlibPackage ("cstruct", None); - FindlibPackage ("lwt", None); - FindlibPackage ("cstruct.syntax", None) + FindlibPackage ("cstruct.ppx", None); + FindlibPackage ("lwt", None) ]; bs_build_tools = [ExternalTool "ocamlbuild"]; bs_c_sources = []; @@ -7211,6 +7214,7 @@ let setup_t = FindlibPackage ("mirage-types", None); FindlibPackage ("ipaddr", None); FindlibPackage ("cstruct", None); + FindlibPackage ("cstruct.ppx", None); FindlibPackage ("lwt", None); InternalLibrary "tcpip"; InternalLibrary "ipv4"; @@ -7268,6 +7272,7 @@ let setup_t = FindlibPackage ("mirage-types", None); FindlibPackage ("ipaddr", None); FindlibPackage ("cstruct", None); + FindlibPackage ("cstruct.ppx", None); FindlibPackage ("lwt", None); InternalLibrary "udp" ]; @@ -7951,7 +7956,7 @@ let setup_t = }; oasis_fn = Some "_oasis"; oasis_version = "0.4.5"; - oasis_digest = Some "j\128xw\129+\tÐrË!¶à\014ÅÌ"; + oasis_digest = Some "\152\001QçÂ\030MC¥\153VÂTIqÔ"; oasis_exec = None; oasis_setup_args = []; setup_update = false @@ -7959,6 +7964,6 @@ let setup_t = let setup () = BaseSetup.setup setup_t;; -# 7963 "setup.ml" +# 7968 "setup.ml" (* OASIS_STOP *) let () = setup ();; diff --git a/tcp/pcb.ml b/tcp/pcb.ml index 538d3305c..58c90b5e0 100644 --- a/tcp/pcb.ml +++ b/tcp/pcb.ml @@ -41,14 +41,15 @@ let info = Log.create ~enabled:true ~stats:false "PCB" module Tcp_wire = Wire_structs.Tcp_wire -cstruct pseudo_header { - uint32_t src; - uint32_t dst; - uint8_t res; - uint8_t proto; - uint16_t len - } as big_endian - +[%%cstruct +type pseudo_header = { + src: uint32_t; + dst: uint32_t; + res: uint8_t; + proto: uint8_t; + len: uint16_t; + } [@@big_endian] +] module Make(Ip:V1_LWT.IP)(Time:V1_LWT.TIME)(Clock:V1.CLOCK)(Random:V1.RANDOM) = struct