mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 18:11:35 +00:00
use dhcp_client_lwt instead of dhcp_client_mirage
Use the `with-cdhcpc` branch of charrua-client, which exposes `Dhcp_client_lwt`. Dhcp_client_lwt exposes similar functions to `Dhcp_client_mirage`, but does not impose the structure of a Mirage_types_lwt.ipv4_config on the returned object, rather returning the full lease; the engine can then expose whatever information from the lease it finds to be pertinent. Signed-off-by: Mindy Preston <mindy.preston@docker.com>
This commit is contained in:
parent
bcb0c52fff
commit
1ab32f9ca7
@ -13,7 +13,7 @@ services:
|
|||||||
- name: rngd
|
- name: rngd
|
||||||
image: mobylinux/rngd:3dad6dd43270fa632ac031e99d1947f20b22eec9
|
image: mobylinux/rngd:3dad6dd43270fa632ac031e99d1947f20b22eec9
|
||||||
- name: dhcp-client
|
- name: dhcp-client
|
||||||
image: mobylinux/dhcp-client:a7a6b49b0ff51ffa2f44ac848cd649e29f946e0c
|
image: linuxkitprojects/dhcp-client:6c231135a88d42e7d18d2ba952f0798910550cbd
|
||||||
net: host
|
net: host
|
||||||
capabilities:
|
capabilities:
|
||||||
- CAP_NET_ADMIN # to bring eth0 up
|
- CAP_NET_ADMIN # to bring eth0 up
|
||||||
|
@ -18,7 +18,6 @@ RUN which capnp
|
|||||||
### SDK
|
### SDK
|
||||||
|
|
||||||
FROM ocaml/opam:alpine-3.5_ocaml-4.04.0 as sdk
|
FROM ocaml/opam:alpine-3.5_ocaml-4.04.0 as sdk
|
||||||
RUN git -C /home/opam/opam-repository pull && opam update -u
|
|
||||||
|
|
||||||
COPY --from=capnp /usr/local/bin/capnp /usr/local/bin/
|
COPY --from=capnp /usr/local/bin/capnp /usr/local/bin/
|
||||||
COPY --from=capnp /usr/local/lib/libcapnpc-0.6.0.so /usr/local/lib/
|
COPY --from=capnp /usr/local/lib/libcapnpc-0.6.0.so /usr/local/lib/
|
||||||
@ -29,7 +28,8 @@ RUN sudo mkdir -p /src
|
|||||||
USER opam
|
USER opam
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
RUN opam pin add jbuilder 1.0+beta9 -n
|
RUN git -C /home/opam/opam-repository pull && opam update -u
|
||||||
|
RUN opam pin add jbuilder 1.0+beta10 -n
|
||||||
|
|
||||||
RUN opam depext -uiy cstruct cstruct-lwt lwt lwt logs irmin-git rawlink tuntap astring rresult \
|
RUN opam depext -uiy cstruct cstruct-lwt lwt lwt logs irmin-git rawlink tuntap astring rresult \
|
||||||
mirage-flow-lwt mirage-channel-lwt io-page decompress capnp
|
mirage-flow-lwt mirage-channel-lwt io-page decompress capnp
|
||||||
@ -64,7 +64,7 @@ RUN sudo cp /src/_build/default/dhcp-client/main.exe /bin/dhcp-client
|
|||||||
|
|
||||||
FROM sdk as calf
|
FROM sdk as calf
|
||||||
|
|
||||||
RUN opam pin add charrua-client https://github.com/yomimono/charrua-client.git#state-halfway -n
|
RUN opam pin add charrua-client https://github.com/yomimono/charrua-client.git#with-cdhcpc -n
|
||||||
RUN opam pin add mirage-net-fd 0.2.0 -n
|
RUN opam pin add mirage-net-fd 0.2.0 -n
|
||||||
RUN opam depext -iy mirage-net-fd charrua-client lwt mirage-types-lwt cmdliner
|
RUN opam depext -iy mirage-net-fd charrua-client lwt mirage-types-lwt cmdliner
|
||||||
|
|
||||||
@ -77,6 +77,7 @@ RUN sudo chown opam -R /src
|
|||||||
RUN opam config exec -- jbuilder build dhcp-client-calf/unikernel.exe
|
RUN opam config exec -- jbuilder build dhcp-client-calf/unikernel.exe
|
||||||
RUN sudo mkdir -p /bin/calf
|
RUN sudo mkdir -p /bin/calf
|
||||||
RUN sudo cp /src/_build/default/dhcp-client-calf/unikernel.exe /bin/calf/dhcp-client-calf
|
RUN sudo cp /src/_build/default/dhcp-client-calf/unikernel.exe /bin/calf/dhcp-client-calf
|
||||||
|
USER 0
|
||||||
|
|
||||||
### Final build
|
### Final build
|
||||||
|
|
||||||
|
@ -23,13 +23,13 @@ hash: Makefile Dockerfile $(FILES) .build
|
|||||||
| sha1sum | sed 's/ .*//' > $@
|
| sha1sum | sed 's/ .*//' > $@
|
||||||
|
|
||||||
tag: .build
|
tag: .build
|
||||||
docker tag $(IMAGE) mobylinux/$(IMAGE):$(shell cat hash)
|
docker tag $(IMAGE) linuxkitprojects/$(IMAGE):$(shell cat hash)
|
||||||
|
|
||||||
push: hash .build
|
push: hash .build
|
||||||
docker pull $(BASE)
|
docker pull $(BASE)
|
||||||
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
docker pull linuxkitprojects/$(IMAGE):$(shell cat hash) || \
|
||||||
(docker tag $(IMAGE) mobylinux/$(IMAGE):$(shell cat hash) && \
|
(docker tag $(IMAGE) linuxkitprojects/$(IMAGE):$(shell cat hash) && \
|
||||||
docker push mobylinux/$(IMAGE):$(shell cat hash))
|
docker push linuxkitprojects/$(IMAGE):$(shell cat hash))
|
||||||
|
|
||||||
clean::
|
clean::
|
||||||
rm -rf hash .build
|
rm -rf hash .build
|
||||||
|
@ -13,13 +13,17 @@ type t = {
|
|||||||
nameservers: Ipaddr.V4.t list;
|
nameservers: Ipaddr.V4.t list;
|
||||||
}
|
}
|
||||||
|
|
||||||
(* FIXME: we loose lots of info here *)
|
(* FIXME: we (still) lose lots of info here *)
|
||||||
let of_ipv4_config (t: Mirage_protocols_lwt.ipv4_config) =
|
let of_lease (t: Dhcp_wire.pkt) =
|
||||||
{ address = t.Mirage_protocols_lwt.address;
|
let gateway = match Dhcp_wire.collect_routers t.Dhcp_wire.options with
|
||||||
gateway = t.Mirage_protocols_lwt.gateway;
|
| [] -> None
|
||||||
domain = None;
|
| n::_ -> Some n
|
||||||
search = None;
|
in
|
||||||
nameservers = [] }
|
{ address = t.Dhcp_wire.yiaddr;
|
||||||
|
gateway;
|
||||||
|
domain = Dhcp_wire.find_domain_name t.Dhcp_wire.options;
|
||||||
|
search = Dhcp_wire.find_domain_search t.Dhcp_wire.options;
|
||||||
|
nameservers = Dhcp_wire.collect_dns_servers t.Dhcp_wire.options }
|
||||||
|
|
||||||
let pp ppf t =
|
let pp ppf t =
|
||||||
Fmt.pf ppf "\n\
|
Fmt.pf ppf "\n\
|
||||||
@ -32,24 +36,6 @@ let pp ppf t =
|
|||||||
Fmt.(option ~none:(unit "--") string) t.search
|
Fmt.(option ~none:(unit "--") string) t.search
|
||||||
Fmt.(list ~sep:(unit " ") Ipaddr.V4.pp_hum) t.nameservers
|
Fmt.(list ~sep:(unit " ") Ipaddr.V4.pp_hum) t.nameservers
|
||||||
|
|
||||||
let of_pkt lease =
|
|
||||||
let open Dhcp_wire in
|
|
||||||
(* ipv4_config expects a single IP address and the information
|
|
||||||
* needed to construct a prefix. It can optionally use one router. *)
|
|
||||||
let address = lease.yiaddr in
|
|
||||||
let gateway = match Dhcp_wire.collect_routers lease.options with
|
|
||||||
| [] -> None
|
|
||||||
| h::_ -> Some h
|
|
||||||
in
|
|
||||||
let domain = Dhcp_wire.find_domain_name lease.options in
|
|
||||||
let search = Dhcp_wire.find_domain_search lease.options in
|
|
||||||
let nameservers = Dhcp_wire.collect_name_servers lease.options in
|
|
||||||
{ address; gateway; domain; search; nameservers }
|
|
||||||
|
|
||||||
let of_pkt_opt = function
|
|
||||||
| None -> None
|
|
||||||
| Some lease -> Some (of_pkt lease)
|
|
||||||
|
|
||||||
let parse_option_code str =
|
let parse_option_code str =
|
||||||
match Dhcp_wire.string_to_option_code str with
|
match Dhcp_wire.string_to_option_code str with
|
||||||
| Some x -> Ok x
|
| Some x -> Ok x
|
||||||
@ -173,7 +159,7 @@ let setup_log =
|
|||||||
|
|
||||||
(* FIXME: module Main ... *)
|
(* FIXME: module Main ... *)
|
||||||
|
|
||||||
module Dhcp_client = Dhcp_client_mirage.Make(Time)(Net)
|
module Dhcp_client = Dhcp_client_lwt.Make(Time)(Net)
|
||||||
|
|
||||||
let pp_path = Fmt.(list ~sep:(unit "/") string)
|
let pp_path = Fmt.(list ~sep:(unit "/") string)
|
||||||
|
|
||||||
@ -209,7 +195,7 @@ let start () dhcp_codes net ctl =
|
|||||||
in
|
in
|
||||||
Dhcp_client.connect ~requests net >>= fun stream ->
|
Dhcp_client.connect ~requests net >>= fun stream ->
|
||||||
Lwt_stream.last_new stream >>= fun result ->
|
Lwt_stream.last_new stream >>= fun result ->
|
||||||
let result = of_ipv4_config result in
|
let result = of_lease result in
|
||||||
Log.info (fun l -> l "found lease: %a" pp result);
|
Log.info (fun l -> l "found lease: %a" pp result);
|
||||||
set_ip ctl ["ip"] result.address >>= fun () ->
|
set_ip ctl ["ip"] result.address >>= fun () ->
|
||||||
set_ip_opt ctl ["gateway"] result.gateway
|
set_ip_opt ctl ["gateway"] result.gateway
|
||||||
|
Loading…
Reference in New Issue
Block a user