Skip to content

Commit 8220f11

Browse files
committed
Also error in ipv6 when attempting to write to ::1
1 parent 800fe96 commit 8220f11

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

src/ipv6/ipv6.ml

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,38 @@ module Make (N : Mirage_net.S)
6565
let mtu t ~dst:_ = E.mtu t.ethif - Ipv6_wire.sizeof_ipv6
6666

6767
let write t ?fragment:_ ?ttl:_ ?src dst proto ?(size = 0) headerf bufs =
68-
let now = Mirage_mtime.elapsed_ns () in
69-
(* TODO fragmentation! *)
70-
let payload = Cstruct.concat bufs in
71-
let size' = size + Cstruct.length payload in
72-
let fillf _ip6hdr buf =
73-
let h_len = headerf buf in
74-
if h_len > size then begin
75-
Log.err (fun m -> m "provided headerf exceeds size") ;
76-
invalid_arg "headerf exceeds size"
77-
end ;
78-
Cstruct.blit payload 0 buf h_len (Cstruct.length payload);
79-
h_len + Cstruct.length payload
80-
in
81-
let ctx, outs = Ndpv6.send ~now t.ctx ?src dst proto size' fillf in
82-
t.ctx <- ctx;
83-
let fail_any progress data =
84-
let squeal = function
85-
| Ok () as ok -> Lwt.return ok
86-
| Error e ->
87-
Log.warn (fun f -> f "ethif write errored: %a" E.pp_error e);
88-
Lwt.return @@ Error (`Ethif e)
68+
if Ipaddr.V6.(compare localhost) dst = 0 then
69+
Lwt.return (Error (`No_route "Loopback address"))
70+
else
71+
let now = Mirage_mtime.elapsed_ns () in
72+
(* TODO fragmentation! *)
73+
let payload = Cstruct.concat bufs in
74+
let size' = size + Cstruct.length payload in
75+
let fillf _ip6hdr buf =
76+
let h_len = headerf buf in
77+
if h_len > size then begin
78+
Log.err (fun m -> m "provided headerf exceeds size") ;
79+
invalid_arg "headerf exceeds size"
80+
end ;
81+
Cstruct.blit payload 0 buf h_len (Cstruct.length payload);
82+
h_len + Cstruct.length payload
8983
in
90-
match progress with
91-
| Ok () -> output t data >>= squeal
92-
| Error e -> Lwt.return @@ Error e
93-
in
94-
(* MCP - it's not totally clear to me that this the right behavior
95-
for writev. *)
96-
Lwt_list.fold_left_s fail_any (Ok ()) outs
84+
let ctx, outs = Ndpv6.send ~now t.ctx ?src dst proto size' fillf in
85+
t.ctx <- ctx;
86+
let fail_any progress data =
87+
let squeal = function
88+
| Ok () as ok -> Lwt.return ok
89+
| Error e ->
90+
Log.warn (fun f -> f "ethif write errored: %a" E.pp_error e);
91+
Lwt.return @@ Error (`Ethif e)
92+
in
93+
match progress with
94+
| Ok () -> output t data >>= squeal
95+
| Error e -> Lwt.return @@ Error e
96+
in
97+
(* MCP - it's not totally clear to me that this the right behavior
98+
for writev. *)
99+
Lwt_list.fold_left_s fail_any (Ok ()) outs
97100

98101
let input t ~tcp ~udp ~default buf =
99102
let now = Mirage_mtime.elapsed_ns () in

0 commit comments

Comments
 (0)