Skip to content

Commit 8f55e15

Browse files
committed
IPv4 routing: adapt to what FreeBSD does
1 parent 7d5f952 commit 8f55e15

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/ipv4/routing.ml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
type r = Mac of Macaddr.t | Arp of Ipaddr.V4.t
22

33
let routing network gateway ~src ~dst =
4-
(* avoid packets to 0.0.0.0/8 *)
5-
if Ipaddr.V4.Prefix.(mem dst relative) then Error `Any
6-
(* avoid packets to 127.0.0.0/8 *)
7-
else if Ipaddr.V4.Prefix.(mem dst loopback) then Error `Loopback
8-
(* avoid packets from 127.0.0.0/8 *)
9-
else if Ipaddr.V4.Prefix.(mem src loopback) then Error `Loopback
10-
(* avoid packet from broadcast address *)
11-
else if
12-
Ipaddr.V4.(compare broadcast) src == 0
13-
|| Ipaddr.V4.(compare (Prefix.broadcast network)) src == 0
14-
then Error `Broadcast (* use broadcast mac *)
4+
if Ipaddr.V4.Prefix.(mem dst loopback) || Ipaddr.V4.Prefix.(mem src loopback)
5+
then
6+
(* avoid packets to or from 127.0.0.0/8 *)
7+
Error `Loopback
158
else if
169
Ipaddr.V4.(compare broadcast) dst == 0
1710
|| Ipaddr.V4.(compare (Prefix.broadcast network)) dst == 0
18-
then Ok (Mac Macaddr.broadcast) (* filter multicast *)
11+
then
12+
(* use broadcast mac *)
13+
Ok (Mac Macaddr.broadcast)
1914
else if Ipaddr.V4.is_multicast dst then
20-
Ok (Mac (Ipaddr.V4.multicast_to_mac dst)) (* direct to this network *)
21-
else if Ipaddr.V4.Prefix.mem dst network then Ok (Arp dst)
22-
(* go through gateway *)
23-
else
15+
(* filter multicast *)
16+
Ok (Mac (Ipaddr.V4.multicast_to_mac dst))
17+
else if Ipaddr.V4.Prefix.mem dst network then
18+
(* direct to this network *)
19+
Ok (Arp dst)
20+
else
21+
(* send to gateway *)
2422
match gateway with
2523
| None -> Error `Gateway
2624
| Some gateway -> Ok (Arp gateway)

0 commit comments

Comments
 (0)