Skip to content

Commit

Permalink
Merge pull request mirage#188 from djs55/cstruct.ppx
Browse files Browse the repository at this point in the history
Remove cstruct.syntax, use cstruct.ppx
  • Loading branch information
avsm committed Mar 19, 2016
2 parents 24ad5f3 + 3fd2264 commit 455a44c
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 203 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -86,6 +86,7 @@ Library tcp
mirage-types,
ipaddr,
cstruct,
cstruct.ppx,
lwt,
tcpip,
tcpip.ipv4,
Expand All @@ -102,6 +103,7 @@ Library dhcpv4
mirage-types,
ipaddr,
cstruct,
cstruct.ppx,
lwt,
tcpip.udp

Expand Down
15 changes: 8 additions & 7 deletions _tags
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +21,7 @@ true: annot, bin_annot
<lib/tcpip.{cma,cmxa}>: 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
Expand Down Expand Up @@ -57,6 +58,7 @@ true: annot, bin_annot
"tcp/log.cmx": for-pack(Tcp)
<tcp/*.ml{,i,y}>: pkg_bytes
<tcp/*.ml{,i,y}>: pkg_cstruct
<tcp/*.ml{,i,y}>: pkg_cstruct.ppx
<tcp/*.ml{,i,y}>: pkg_io-page
<tcp/*.ml{,i,y}>: pkg_ipaddr
<tcp/*.ml{,i,y}>: pkg_lwt
Expand All @@ -69,6 +71,7 @@ true: annot, bin_annot
"dhcp/dhcpv4.cmxs": use_dhcpv4
<dhcp/*.ml{,i,y}>: pkg_bytes
<dhcp/*.ml{,i,y}>: pkg_cstruct
<dhcp/*.ml{,i,y}>: pkg_cstruct.ppx
<dhcp/*.ml{,i,y}>: pkg_io-page
<dhcp/*.ml{,i,y}>: pkg_ipaddr
<dhcp/*.ml{,i,y}>: pkg_lwt
Expand All @@ -80,7 +83,7 @@ true: annot, bin_annot
"lib/tcpip-stack-direct.cmxs": use_tcpip-stack-direct
<lib/*.ml{,i,y}>: pkg_bytes
<lib/*.ml{,i,y}>: pkg_cstruct
<lib/*.ml{,i,y}>: pkg_cstruct.syntax
<lib/*.ml{,i,y}>: pkg_cstruct.ppx
<lib/*.ml{,i,y}>: pkg_io-page
<lib/*.ml{,i,y}>: pkg_ipaddr
<lib/*.ml{,i,y}>: pkg_lwt
Expand Down Expand Up @@ -121,7 +124,6 @@ true: annot, bin_annot
# Library tcpip-stack-unix
"unix/tcpip-stack-unix.cmxs": use_tcpip-stack-unix
<unix/*.ml{,i,y}>: pkg_channel
<unix/*.ml{,i,y}>: pkg_cstruct.syntax
<unix/*.ml{,i,y}>: pkg_mirage-clock-unix
<unix/*.ml{,i,y}>: pkg_mirage-console.unix
<unix/*.ml{,i,y}>: pkg_mirage-net-unix
Expand All @@ -146,6 +148,7 @@ true: annot, bin_annot
<unix/*.ml{,i,y}>: pkg_bytes
<unix/*.ml{,i,y}>: pkg_cstruct
<unix/*.ml{,i,y}>: pkg_cstruct.lwt
<unix/*.ml{,i,y}>: pkg_cstruct.ppx
<unix/*.ml{,i,y}>: pkg_io-page
<unix/*.ml{,i,y}>: pkg_io-page.unix
<unix/*.ml{,i,y}>: pkg_ipaddr
Expand All @@ -164,6 +167,7 @@ true: annot, bin_annot
<lib_test/test.{native,byte}>: pkg_alcotest
<lib_test/test.{native,byte}>: pkg_bytes
<lib_test/test.{native,byte}>: pkg_cstruct
<lib_test/test.{native,byte}>: pkg_cstruct.ppx
<lib_test/test.{native,byte}>: pkg_io-page
<lib_test/test.{native,byte}>: pkg_io-page.unix
<lib_test/test.{native,byte}>: pkg_ipaddr
Expand All @@ -185,6 +189,7 @@ true: annot, bin_annot
<lib_test/*.ml{,i,y}>: pkg_alcotest
<lib_test/*.ml{,i,y}>: pkg_bytes
<lib_test/*.ml{,i,y}>: pkg_cstruct
<lib_test/*.ml{,i,y}>: pkg_cstruct.ppx
<lib_test/*.ml{,i,y}>: pkg_io-page
<lib_test/*.ml{,i,y}>: pkg_io-page.unix
<lib_test/*.ml{,i,y}>: pkg_ipaddr
Expand All @@ -206,7 +211,3 @@ true: annot, bin_annot
<lib_test/test.{native,byte}>: custom
# OASIS_STOP
true: annot, bin_annot, principal, strict_sequence, debug
<tcp/pcb.ml>: pkg_cstruct.syntax
<lib/wire_structs.ml>: pkg_cstruct.syntax
<lib/arpv4.ml>: pkg_cstruct.syntax
<dhcp/dhcp_clientv4.ml>: pkg_cstruct.syntax
47 changes: 25 additions & 22 deletions dhcp/dhcp_clientv4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 7 additions & 5 deletions lib/META
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
34 changes: 19 additions & 15 deletions lib/arpv4_wire.ml
Original file line number Diff line number Diff line change
@@ -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]
]
Loading

0 comments on commit 455a44c

Please sign in to comment.