Simplify code slightly

This commit is contained in:
Thomas Leonard 2016-01-01 10:55:34 +00:00
parent 86b31f7f4b
commit 4032a5d776
5 changed files with 6 additions and 12 deletions

View File

@ -35,7 +35,7 @@ let classify t ip =
match ip with
| Ipaddr.V6 _ -> `External ip
| 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
| Some client_link -> `Client client_link
| None when Ipaddr.V4.Prefix.mem ip4 t.prefix -> `Unknown_client ip
@ -48,7 +48,7 @@ module ARP = struct
}
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
| Some client_iface -> Some client_iface#other_mac
| None -> None
@ -97,7 +97,7 @@ module ARP = struct
let open Arpv4_wire 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));
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;
None
) else match lookup t req_ipv4 with

View File

@ -30,7 +30,7 @@ let input_arp ~fixed_arp ~eth request =
(** Handle an IPv4 packet from the client. *)
let input_ipv4 ~client_ip ~router frame packet =
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 (
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);

View File

@ -62,7 +62,7 @@ module Main (Clock : V1.CLOCK) = struct
Log.info "agents connected in %.3f s (CPU time used since boot: %.3f s)"
(fun f -> f (Clock.time () -. start_time) (Sys.time ()));
(* 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 *)
let net_listener = network qubesDB in
(* Run until something fails or we get a shutdown request. *)

View File

@ -44,11 +44,7 @@ module Make(Clock : V1.CLOCK) = struct
let connect config =
let ip = config.Dao.uplink_our_ip in
Netif.connect "tap0" >>= function
| `Error (`Unknown msg) -> failwith msg
| `Error `Disconnected -> failwith "Disconnected"
| `Error `Unimplemented -> failwith "Unimplemented"
| `Ok net ->
Netif.connect "tap0" >>= or_fail "Can't connect uplink device" >>= fun net ->
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.add_ip arp ip >>= fun () ->

View File

@ -52,8 +52,6 @@ let fixup_checksums frame =
in
[just_headers; higherlevel_data]
let (===) a b = (Ipaddr.V4.compare a b = 0)
let error fmt =
let err s = Failure s in
Printf.ksprintf err fmt