Skip to content

Commit 800fe96

Browse files
committed
Error on attempts at writing martian packets
If we try to write to a loopback address we error out. This is perhaps not ideal, but sending IP packets with loopback addresses is not allowed according to RFC 1122.
1 parent c230b14 commit 800fe96

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/ipv4/routing.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module Make(Log : Logs.LOG) (A : Arp.S) = struct
3636
Log.info (fun f -> f "IP.output: %a" A.pp_error e);
3737
Error `Local
3838
end
39+
|ip when Ipaddr.V4.Prefix.mem ip Ipaddr.V4.Prefix.loopback -> (* Loopback *)
40+
Lwt.return (Error `Loopback)
3941
|ip -> (* Gateway *)
4042
match gateway with
4143
| None ->

src/ipv4/static_ipv4.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ module Make (Ethernet: Ethernet.S) (Arpv4 : Arp.S) = struct
5050
| Error `Local ->
5151
Log.warn (fun f -> f "Could not find %a on the local network" Ipaddr.V4.pp dst);
5252
Lwt.return @@ Error (`No_route "no response for IP on local network")
53+
| Error `Loopback ->
54+
Log.warn (fun f -> f "Write to loopback %a dropped" Ipaddr.V4.pp dst);
55+
Lwt.return @@ Error (`No_route "Loopback address")
5356
| Error `Gateway when t.gateway = None ->
5457
Log.warn (fun f -> f "Write to %a would require an external route, which was not provided" Ipaddr.V4.pp dst);
5558
Lwt.return @@ Ok ()

0 commit comments

Comments
 (0)