mirror of
https://github.com/mirage/qubes-mirage-firewall.git
synced 2024-09-28 19:55:39 +00:00
Simplify code slightly
This commit is contained in:
parent
86b31f7f4b
commit
4032a5d776
@ -35,7 +35,7 @@ let classify t ip =
|
|||||||
match ip with
|
match ip with
|
||||||
| Ipaddr.V6 _ -> `External ip
|
| Ipaddr.V6 _ -> `External ip
|
||||||
| Ipaddr.V4 ip4 ->
|
| Ipaddr.V4 ip4 ->
|
||||||
if ip4 === t.client_gw then `Client_gateway
|
if ip4 = t.client_gw then `Client_gateway
|
||||||
else match lookup t ip4 with
|
else match lookup t ip4 with
|
||||||
| Some client_link -> `Client client_link
|
| Some client_link -> `Client client_link
|
||||||
| None when Ipaddr.V4.Prefix.mem ip4 t.prefix -> `Unknown_client ip
|
| None when Ipaddr.V4.Prefix.mem ip4 t.prefix -> `Unknown_client ip
|
||||||
@ -48,7 +48,7 @@ module ARP = struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
let lookup t ip =
|
let lookup t ip =
|
||||||
if ip === t.net.client_gw then Some t.client_link#my_mac
|
if ip = t.net.client_gw then Some t.client_link#my_mac
|
||||||
else match IpMap.find ip t.net.iface_of_ip with
|
else match IpMap.find ip t.net.iface_of_ip with
|
||||||
| Some client_iface -> Some client_iface#other_mac
|
| Some client_iface -> Some client_iface#other_mac
|
||||||
| None -> None
|
| None -> None
|
||||||
@ -97,7 +97,7 @@ module ARP = struct
|
|||||||
let open Arpv4_wire in
|
let open Arpv4_wire in
|
||||||
let req_ipv4 = Ipaddr.V4.of_int32 (get_arp_tpa frame) in
|
let req_ipv4 = Ipaddr.V4.of_int32 (get_arp_tpa frame) in
|
||||||
Log.info "who-has %s?" (fun f -> f (Ipaddr.V4.to_string req_ipv4));
|
Log.info "who-has %s?" (fun f -> f (Ipaddr.V4.to_string req_ipv4));
|
||||||
if req_ipv4 === t.client_link#other_ip then (
|
if req_ipv4 = t.client_link#other_ip then (
|
||||||
Log.info "ignoring request for client's own IP" Logs.unit;
|
Log.info "ignoring request for client's own IP" Logs.unit;
|
||||||
None
|
None
|
||||||
) else match lookup t req_ipv4 with
|
) else match lookup t req_ipv4 with
|
||||||
|
@ -30,7 +30,7 @@ let input_arp ~fixed_arp ~eth request =
|
|||||||
(** Handle an IPv4 packet from the client. *)
|
(** Handle an IPv4 packet from the client. *)
|
||||||
let input_ipv4 ~client_ip ~router frame packet =
|
let input_ipv4 ~client_ip ~router frame packet =
|
||||||
let src = Wire_structs.Ipv4_wire.get_ipv4_src packet |> Ipaddr.V4.of_int32 in
|
let src = Wire_structs.Ipv4_wire.get_ipv4_src packet |> Ipaddr.V4.of_int32 in
|
||||||
if src === client_ip then Firewall.ipv4_from_client router frame
|
if src = client_ip then Firewall.ipv4_from_client router frame
|
||||||
else (
|
else (
|
||||||
Log.warn "Incorrect source IP %a in IP packet from %a (dropping)"
|
Log.warn "Incorrect source IP %a in IP packet from %a (dropping)"
|
||||||
(fun f -> f Ipaddr.V4.pp_hum src Ipaddr.V4.pp_hum client_ip);
|
(fun f -> f Ipaddr.V4.pp_hum src Ipaddr.V4.pp_hum client_ip);
|
||||||
|
@ -62,7 +62,7 @@ module Main (Clock : V1.CLOCK) = struct
|
|||||||
Log.info "agents connected in %.3f s (CPU time used since boot: %.3f s)"
|
Log.info "agents connected in %.3f s (CPU time used since boot: %.3f s)"
|
||||||
(fun f -> f (Clock.time () -. start_time) (Sys.time ()));
|
(fun f -> f (Clock.time () -. start_time) (Sys.time ()));
|
||||||
(* Watch for shutdown requests from Qubes *)
|
(* Watch for shutdown requests from Qubes *)
|
||||||
let shutdown_rq = OS.Lifecycle.await_shutdown () >|= function `Poweroff | `Reboot -> () in
|
let shutdown_rq = OS.Lifecycle.await_shutdown () >>= function `Poweroff | `Reboot -> return () in
|
||||||
(* Set up networking *)
|
(* Set up networking *)
|
||||||
let net_listener = network qubesDB in
|
let net_listener = network qubesDB in
|
||||||
(* Run until something fails or we get a shutdown request. *)
|
(* Run until something fails or we get a shutdown request. *)
|
||||||
|
@ -44,11 +44,7 @@ module Make(Clock : V1.CLOCK) = struct
|
|||||||
|
|
||||||
let connect config =
|
let connect config =
|
||||||
let ip = config.Dao.uplink_our_ip in
|
let ip = config.Dao.uplink_our_ip in
|
||||||
Netif.connect "tap0" >>= function
|
Netif.connect "tap0" >>= or_fail "Can't connect uplink device" >>= fun net ->
|
||||||
| `Error (`Unknown msg) -> failwith msg
|
|
||||||
| `Error `Disconnected -> failwith "Disconnected"
|
|
||||||
| `Error `Unimplemented -> failwith "Unimplemented"
|
|
||||||
| `Ok net ->
|
|
||||||
Eth.connect net >>= or_fail "Can't make Ethernet device for tap" >>= fun eth ->
|
Eth.connect net >>= or_fail "Can't make Ethernet device for tap" >>= fun eth ->
|
||||||
Arp.connect eth >>= or_fail "Can't add ARP" >>= fun arp ->
|
Arp.connect eth >>= or_fail "Can't add ARP" >>= fun arp ->
|
||||||
Arp.add_ip arp ip >>= fun () ->
|
Arp.add_ip arp ip >>= fun () ->
|
||||||
|
2
utils.ml
2
utils.ml
@ -52,8 +52,6 @@ let fixup_checksums frame =
|
|||||||
in
|
in
|
||||||
[just_headers; higherlevel_data]
|
[just_headers; higherlevel_data]
|
||||||
|
|
||||||
let (===) a b = (Ipaddr.V4.compare a b = 0)
|
|
||||||
|
|
||||||
let error fmt =
|
let error fmt =
|
||||||
let err s = Failure s in
|
let err s = Failure s in
|
||||||
Printf.ksprintf err fmt
|
Printf.ksprintf err fmt
|
||||||
|
Loading…
Reference in New Issue
Block a user