Skip to content

Commit

Permalink
Allow optional argument to be erased in Dhcp_server.make. (#111)
Browse files Browse the repository at this point in the history
* Allow optional argument to be erased in Dhcp_server.make.

Changes public API, might will break users.

* maxleasetime -> max-lease-time like ISC dhcpd.conf.

* Fix handling of DHCPRELEASE, DHCPDECLINE probably still broken.

RELEASE doesn't have a request ip, the interesting address is in pkt.ciaddr.
Can't really test decline, but this improves the current situation at least.

* Rewrite server lease database and fix a bunch of bugs.

The double reference between old Id_map and Addr_map is too confusing and prone
to mistakes, this rewrites so that Addr_map now only gives a Client_id and
Lease_map gives a Lease.t.

Instead of trying to recycle old leases on the fly and introducing unecessary
complications, just remove it all over. Code gets considerably simpler and the
caller is responsible for calling Lease.garbage_collect once in a while.

Expired leases are kept even if expire, if a client does a discover later on, it
might re-active/renew the old lease, this is desirable since he gets to have his
same old ip back.

Fix a bug where the server *MUST NOT* ack a lease during INIT-REBOOT, it should
remain silent, it should ack only when SELECTING or RENEW/REBIDING. With this
every ack becomes a lease renew, so we don't need the extra logic of ack ~renew.

* Garbage collect in charruad.

Once every minute try to prune old leases. This should be configurable in the
future. No need for a timer, use packet input as a tick.

* Write pid file in charruad.

/run is what linux uses theses days, can and probably should be modified via -p.

* Implement -u/--user and -g/--group in charruad.

Forcing people to run as _charruad is bad.

* Shut opam-dune-lint up.

* opam: bump lower ocaml bound to 4.08 (module Int in stdlib)

* Remove sanity_check from Dhcp_server.replace.

Code is good, have some faith brother.

Co-authored-by: Hannes Mehnert <hannes@mehnert.org>
  • Loading branch information
haesbaert and hannesm committed Jul 19, 2021
1 parent e03510c commit 72d3e7f
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 165 deletions.
44 changes: 21 additions & 23 deletions charrua-client.opam
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
opam-version: "2.0"
maintainer: ["Mindy Preston"]
authors : ["Mindy Preston"]
homepage: "https://github.com/mirage/charrua"
bug-reports: "https://github.com/mirage/charrua/issues"
dev-repo: "git+https://github.com/mirage/charrua.git"
tags: [ "org:mirage"]
doc: "https://docs.mirage.io"

build: [
[ "dune" "subst" ] {pinned}
[ "dune" "build" "-p" name "-j" jobs ]
[ "dune" "runtest" "-p" name "-j" jobs ] {with-test}
]
synopsis: "DHCP client implementation"
description: """\
charrua-client is a DHCP client powered by [charrua](https://github.com/mirage/charrua).

The base library exposes a simple state machine in `Dhcp_client`
for use in acquiring a DHCP lease."""
maintainer: "Mindy Preston"
authors: "Mindy Preston"
tags: "org:mirage"
homepage: "https://github.com/mirage/charrua"
doc: "https://docs.mirage.io"
bug-reports: "https://github.com/mirage/charrua/issues"
depends: [
"dune" {>= "1.4.0"}
"ocaml" {>= "4.06.0"}
"alcotest" {with-test}
"ocaml" {>= "4.08.0"}
"alcotest" {with-test}
"cstruct-unix" {with-test}
"mirage-random-test" {with-test & >= "0.1.0"}
"charrua-server" {= version & with-test}
"charrua" {= version}
"cstruct" {>="3.0.2"}
"cstruct" {>= "3.0.2"}
"ipaddr" {>= "5.0.0"}
"macaddr" {>= "4.0.0"}
"mirage-random" {>= "2.0.0"}
Expand All @@ -33,11 +31,11 @@ depends: [
"logs"
"fmt"
"lwt" {>= "4.0.0"}
"tcpip" {>= "6.1.0" & with-test}
]
synopsis: "DHCP client implementation"
description: """
charrua-client is a DHCP client powered by [charrua](https://github.com/mirage/charrua).

The base library exposes a simple state machine in `Dhcp_client`
for use in acquiring a DHCP lease.
"""
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
dev-repo: "git+https://github.com/mirage/charrua.git"
61 changes: 30 additions & 31 deletions charrua-server.opam
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
opam-version: "2.0"
maintainer: "Christiano F. Haesbaert <haesbaert@haesbaert.org>"
authors: "Christiano F. Haesbaert <haesbaert@haesbaert.org>"
license: "ISC"
homepage: "https://github.com/mirage/charrua"
bug-reports: "https://github.com/mirage/charrua/issues"
dev-repo: "git+https://github.com/mirage/charrua.git"
doc: "https://mirage.github.io/charrua/"

build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]

depends: [
"ocaml" {>= "4.06.0"}
"dune" {>= "1.4.0"}
"ppx_sexp_conv" {>= "v0.9.0"}
"menhir" {build}
"charrua" {= version}
"cstruct" {>= "3.0.1"}
"sexplib"
"ipaddr" {>= "5.0.0"}
"macaddr" {>= "4.0.0"}
"ipaddr-sexp"
"macaddr-sexp"
"cstruct-unix" {with-test}
]
synopsis: "DHCP server"
description: """
description: """\
Charrua-server consists of a single `Dhcp_server` module used for constructing DHCP
servers.

Expand All @@ -47,5 +19,32 @@ is a Mirage DHCP unikernel server based on charrua, included as a part of the Mi
* It's in OCaml, so it's pretty cool.

The name `charrua` is a reference to the, now extinct, semi-nomadic people of
southern South America.
"""
southern South America."""
maintainer: "Christiano F. Haesbaert <haesbaert@haesbaert.org>"
authors: "Christiano F. Haesbaert <haesbaert@haesbaert.org>"
license: "ISC"
homepage: "https://github.com/mirage/charrua"
doc: "https://mirage.github.io/charrua/"
bug-reports: "https://github.com/mirage/charrua/issues"
depends: [
"ocaml" {>= "4.08.0"}
"dune" {>= "1.4.0"}
"ppx_sexp_conv" {>= "v0.9.0"}
"menhir" {build}
"charrua" {= version}
"cstruct" {>= "3.0.1"}
"sexplib"
"ipaddr" {>= "5.0.0"}
"macaddr" {>= "4.0.0"}
"ipaddr-sexp"
"macaddr-sexp"
"cstruct-unix" {with-test}
"ppx_cstruct" {>= "6.0.0" & with-test}
"tcpip" {>= "6.1.0" & with-test}
]
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
dev-repo: "git+https://github.com/mirage/charrua.git"
30 changes: 16 additions & 14 deletions charrua-unix.opam
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
opam-version: "2.0"
synopsis: "Unix DHCP daemon"
description: """\
charrua-unix is an _ISC-licensed_ Unix DHCP daemon based on
[charrua](http://www.github.com/mirage/charrua)."""
maintainer: "Christiano F. Haesbaert <haesbaert@haesbaert.org>"
authors: "Christiano F. Haesbaert <haesbaert@haesbaert.org>"
license: "ISC"
homepage: "https://github.com/mirage/charrua"
bug-reports: "https://github.com/mirage/charrua/issues"
license: "ISC"
dev-repo: "git+https://github.com/mirage/charrua.git"
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
]
depends: [
"dune" {>= "1.4.0"}
"ocaml" {>= "4.06.0"}
"lwt" {>="3.0.0"}
"ocaml" {>= "4.08.0"}
"lwt" {>= "3.0.0"}
"lwt_log"
"charrua" {= version}
"charrua-server" {= version}
"cstruct-unix"
"cmdliner"
"rawlink" {>= "1.0"}
"tuntap" {>= "2.0.0"}
"mtime" {>="1.0.0"}
"mtime" {>= "1.0.0"}
"cstruct-lwt" {>= "6.0.0"}
"ipaddr" {>= "5.1.0"}
"tcpip" {>= "6.1.0"}
]
synopsis: "Unix DHCP daemon"
description: """
charrua-unix is an _ISC-licensed_ Unix DHCP daemon based on
[charrua](http://www.github.com/mirage/charrua).
"""
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
]
dev-repo: "git+https://github.com/mirage/charrua.git"
2 changes: 1 addition & 1 deletion charrua.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build: [
]

depends: [
"ocaml" {>= "4.06.0"}
"ocaml" {>= "4.08.0"}
"dune" {>= "1.4.0"}
"ppx_sexp_conv" {>="v0.10.0"}
"ppx_cstruct"
Expand Down
2 changes: 1 addition & 1 deletion server/dhcp_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ rule lex = parse
| "fixed-address" { FIXEDADDRESS }
| "hardware" { HARDWARE }
| "host" { HOST }
| "maxleasetime" { MAXLEASETIME }
| "max-lease-time" { MAXLEASETIME }
| "netmask" { NETMASK }
| "option" { OPTION }
| "range" { RANGE }
Expand Down

0 comments on commit 72d3e7f

Please sign in to comment.