2015-12-30 16:07:16 +00:00
|
|
|
(* Copyright (C) 2015, Thomas Leonard <thomas.leonard@unikernel.com>
|
|
|
|
See the README file for details. *)
|
|
|
|
|
2017-03-02 14:52:55 +00:00
|
|
|
open Fw_utils
|
2015-12-30 16:07:16 +00:00
|
|
|
|
|
|
|
type port = int
|
|
|
|
|
|
|
|
type ports = {
|
|
|
|
sport : port; (* Source port *)
|
|
|
|
dport : port; (* Destination *)
|
|
|
|
}
|
|
|
|
|
|
|
|
type host =
|
2016-09-25 13:38:17 +00:00
|
|
|
[ `Client of client_link | `Client_gateway | `Firewall_uplink | `NetVM | `External of Ipaddr.t ]
|
2015-12-30 16:07:16 +00:00
|
|
|
|
2019-04-11 11:25:19 +00:00
|
|
|
(* Note: 'a is either [host], or the result of applying [Rules.clients] and [Rules.externals] to a host. *)
|
|
|
|
type 'a info = {
|
2017-03-05 16:31:04 +00:00
|
|
|
packet : Nat_packet.t;
|
2019-04-11 11:25:19 +00:00
|
|
|
src : 'a;
|
|
|
|
dst : 'a;
|
2015-12-30 16:07:16 +00:00
|
|
|
proto : [ `UDP of ports | `TCP of ports | `ICMP | `Unknown ];
|
|
|
|
}
|
2019-04-11 11:25:19 +00:00
|
|
|
|
|
|
|
(* The first message in a TCP connection has SYN set and ACK clear. *)
|
|
|
|
let is_tcp_start = function
|
|
|
|
| `IPv4 (_ip, `TCP (hdr, _body)) -> Tcp.Tcp_packet.(hdr.syn && not hdr.ack)
|
|
|
|
| _ -> false
|