Skip to content

Commit

Permalink
Do not assert if there are trailing bytes in an IP frame
Browse files Browse the repository at this point in the history
Alternative fix for mirage#121 to avoid raising Assert_failure

See also mirage/mirage-net-xen#24
  • Loading branch information
avsm committed Mar 31, 2015
1 parent b3f7cde commit 1edda52
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/ipv4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ module Make(Ethif : V1_LWT.ETHIF) = struct
let src = Ipaddr.V4.of_int32 (Wire_structs.Ipv4_wire.get_ipv4_src buf) in
let dst = Ipaddr.V4.of_int32 (Wire_structs.Ipv4_wire.get_ipv4_dst buf) in
let payload_len = Wire_structs.Ipv4_wire.get_ipv4_len buf - ihl in
(* XXX this will raise exception for 0-length payload *)
let hdr, data = Cstruct.split buf ihl in
assert (Cstruct.len data = payload_len);
let proto = Wire_structs.Ipv4_wire.get_ipv4_proto buf in
match Wire_structs.Ipv4_wire.int_to_protocol proto with
| Some `ICMP -> icmp_input t src hdr data
| Some `TCP -> tcp ~src ~dst data
| Some `UDP -> udp ~src ~dst data
| None -> default ~proto ~src ~dst data
if Cstruct.len data >= payload_len then begin
let proto = Wire_structs.Ipv4_wire.get_ipv4_proto buf in
match Wire_structs.Ipv4_wire.int_to_protocol proto with
| Some `ICMP -> icmp_input t src hdr data
| Some `TCP -> tcp ~src ~dst data
| Some `UDP -> udp ~src ~dst data
| None -> default ~proto ~src ~dst data
end

let connect ethif =
let ip = Ipaddr.V4.any in
Expand Down

0 comments on commit 1edda52

Please sign in to comment.