|
1 | 1 | type r = Mac of Macaddr.t | Arp of Ipaddr.V4.t |
2 | 2 |
|
3 | 3 | 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 |
15 | 8 | else if |
16 | 9 | Ipaddr.V4.(compare broadcast) dst == 0 |
17 | 10 | || 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) |
19 | 14 | 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 *) |
24 | 22 | match gateway with |
25 | 23 | | None -> Error `Gateway |
26 | 24 | | Some gateway -> Ok (Arp gateway) |
|
0 commit comments