Skip to content

Commit

Permalink
Merge pull request #411 from avsm/ipaddr4
Browse files Browse the repository at this point in the history
support ipaddr 4.0 interfaces, use Macaddr_cstruct
  • Loading branch information
yomimono authored Jul 16, 2019
2 parents e4e1b43 + 9524174 commit f358295
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### dev

* support ipaddr/macaddr.4.0.0 interfaces (@avsm)

### v3.7.6 (2019-07-08)

* opam: ensure Xen bindings are built with right mirage-xen-ocaml CFLAGS (@avsm)
Expand Down
4 changes: 2 additions & 2 deletions src/ipv4/routing.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
(* RFC 1112: 01-00-5E-00-00-00 ORed with lower 23 bits of the ip address *)
let mac_of_multicast ip =
let ipb = Ipaddr.V4.to_bytes ip in
let ipb = Ipaddr.V4.to_octets ip in
let macb = Bytes.create 6 in
Bytes.set macb 0 (Char.chr 0x01);
Bytes.set macb 1 (Char.chr 0x00);
Bytes.set macb 2 (Char.chr 0x5E);
Bytes.set macb 3 (Char.chr ((Char.code ipb.[1]) land 0x7F));
Bytes.set macb 4 (String.get ipb 2);
Bytes.set macb 5 (String.get ipb 3);
Macaddr.of_bytes_exn (Bytes.to_string macb)
Macaddr.of_octets_exn (Bytes.to_string macb)

type routing_error = [ `Local | `Gateway ]

Expand Down
2 changes: 1 addition & 1 deletion src/ipv6/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name tcpip_ipv6)
(public_name tcpip.ipv6)
(libraries logs mirage-protocols-lwt mirage-time-lwt
(libraries logs mirage-protocols-lwt mirage-time-lwt macaddr-cstruct
mirage-clock-lwt duration ipaddr cstruct rresult mirage-random tcpip
randomconv)
(preprocess
Expand Down
16 changes: 5 additions & 11 deletions src/ipv6/ndpv6.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,10 @@ let ipaddr_to_cstruct_raw i cs off =
Cstruct.BE.set_uint32 cs (12 + off) d

let macaddr_to_cstruct_raw x cs off =
Cstruct.blit_from_string (Macaddr.to_bytes x) 0 cs off 6

let macaddr_of_cstruct cs =
if Cstruct.len cs <> 6 then invalid_arg "macaddr_of_cstruct";
match Macaddr.of_bytes (Cstruct.to_string cs) with
| Ok x -> x
| Error _ -> assert false
Cstruct.blit_from_string (Macaddr.to_octets x) 0 cs off 6

let interface_addr mac =
let bmac = Macaddr.to_bytes mac in
let bmac = Macaddr.to_octets mac in
let c i = Char.code (String.get bmac i) in
Ipaddr.make
0 0 0 0
Expand All @@ -137,7 +131,7 @@ let multicast_mac =
fun ip ->
let _, _, _, n = Ipaddr.to_int32 ip in
Cstruct.BE.set_uint32 pbuf 2 n;
Macaddr.of_bytes_exn (Cstruct.to_string pbuf)
Macaddr_cstruct.of_cstruct_exn pbuf

(* vary the reachable time by some random factor between 0.5 and 1.5 *)
let compute_reachable_time r reachable_time =
Expand Down Expand Up @@ -746,9 +740,9 @@ module Parser = struct
let opt, opts = Cstruct.split opts (Ipv6_wire.get_opt_len opts * 8) in
match Ipv6_wire.get_opt_ty opt, Ipv6_wire.get_opt_len opt with
| 1, 1 ->
SLLA (macaddr_of_cstruct (Ipv6_wire.get_llopt_addr opt)) :: parse_options1 opts
SLLA (Macaddr_cstruct.of_cstruct_exn (Ipv6_wire.get_llopt_addr opt)) :: parse_options1 opts
| 2, 1 ->
TLLA (macaddr_of_cstruct (Ipv6_wire.get_llopt_addr opt)) :: parse_options1 opts
TLLA (Macaddr_cstruct.of_cstruct_exn (Ipv6_wire.get_llopt_addr opt)) :: parse_options1 opts
| 5, 1 ->
MTU (Int32.to_int (Cstruct.BE.get_uint32 opt 4)) :: parse_options1 opts
| 3, 4 ->
Expand Down
5 changes: 3 additions & 2 deletions tcpip.opam
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ depends: [
"mirage-protocols" {>= "3.0.0"}
"mirage-protocols-lwt" {>= "3.0.0"}
"mirage-time-lwt" {>= "1.0.0"}
"ipaddr" {>= "3.0.0"}
"macaddr"
"ipaddr" {>= "4.0.0"}
"macaddr" {>="4.0.0"}
"macaddr-cstruct"
"mirage-profile" {>= "0.5"}
"fmt"
"lwt" {>= "3.0.0"}
Expand Down

0 comments on commit f358295

Please sign in to comment.