diff --git a/.travis.yml b/.travis.yml index 328ef6089..61e20d882 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ script: bash -ex .travis-ci.sh sudo: required env: global: - - PINS="mirage mirage-types mirage-types-lwt" + - PINS="mirage mirage-types mirage-types-lwt dns:git://github.com/yomimono/ocaml-dns.git#standardize_record_fields" matrix: - OCAML_VERSION=4.02 PACKAGE=tcpip MIRAGE_MODE=unix - UPDATE_GCC_BINUTILS=1 OCAML_VERSION=4.02 PACKAGE=tcpip MIRAGE_MODE=xen diff --git a/lib/dhcp/dhcp_clientv4.ml b/lib/dhcp/dhcp_clientv4.ml index ae7200d55..5c3cb8055 100644 --- a/lib/dhcp/dhcp_clientv4.ml +++ b/lib/dhcp/dhcp_clientv4.ml @@ -95,7 +95,7 @@ module Make Cstruct.blit_from_string options 0 buf sizeof_dhcp options_len; let buf = Cstruct.set_len buf (sizeof_dhcp + options_len) in Log.info (fun f -> f "Sending DHCP broadcast (length %d)" total_len); - Udp.write ~dest_ip:Ipaddr.V4.broadcast ~source_port:68 ~dest_port:67 t.udp buf + Udp.write ~dst:Ipaddr.V4.broadcast ~src_port:68 ~dst_port:67 t.udp buf (* Receive a DHCP UDP packet *) let input t ~src:_ ~dst:_ ~src_port:_ buf = diff --git a/lib/ipv4/ipv4.ml b/lib/ipv4/ipv4.ml index ca583cb1c..4d88ad6e1 100644 --- a/lib/ipv4/ipv4.ml +++ b/lib/ipv4/ipv4.ml @@ -200,7 +200,7 @@ module Make(Ethif: V1_LWT.ETHIF) (Arpv4 : V1_LWT.ARP) = struct Ipv4_wire.set_ipv4_csum packet 0; Tcpip_checksum.ones_complement_list (packet :: bufs) - let get_source t ~dst:_ = + let src t ~dst:_ = t.ip type uipaddr = Ipaddr.t diff --git a/lib/ipv6/ipv6.ml b/lib/ipv6/ipv6.ml index cef368df1..c0760a1df 100644 --- a/lib/ipv6/ipv6.ml +++ b/lib/ipv6/ipv6.ml @@ -80,7 +80,7 @@ module Make (E : V1_LWT.ETHIF) (T : V1_LWT.TIME) (C : V1.CLOCK) = struct let checksum = Ndpv6.checksum - let get_source t ~dst = Ndpv6.select_source t.ctx dst + let src t ~dst = Ndpv6.select_source t.ctx dst let set_ip t ip = let now = C.time () in @@ -111,7 +111,7 @@ module Make (E : V1_LWT.ETHIF) (T : V1_LWT.TIME) (C : V1.CLOCK) = struct let pseudoheader t ~dst ~proto len = let ph = Cstruct.create (16 + 16 + 8) in - let src = get_source t ~dst in + let src = src t ~dst in Ndpv6.ipaddr_to_cstruct_raw src ph 0; Ndpv6.ipaddr_to_cstruct_raw dst ph 16; Cstruct.BE.set_uint32 ph 32 (Int32.of_int len); diff --git a/lib/tcp/flow.ml b/lib/tcp/flow.ml index 18b92de16..882527968 100644 --- a/lib/tcp/flow.ml +++ b/lib/tcp/flow.ml @@ -70,7 +70,7 @@ module Make(IP:V1_LWT.IP)(TM:V1_LWT.TIME)(C:V1.CLOCK)(R:V1.RANDOM) = struct | Result.Ok () -> Lwt.return_unit let id = Pcb.ip - let get_dest = Pcb.get_dest + let dst = Pcb.dst let close t = Pcb.close t let input = Pcb.input @@ -88,7 +88,7 @@ module Make(IP:V1_LWT.IP)(TM:V1_LWT.TIME)(C:V1.CLOCK)(R:V1.RANDOM) = struct let disconnect _ = Lwt.return_unit let create_connection tcp (daddr, dport) = - Pcb.connect tcp ~dest_ip:daddr ~dest_port:dport >>= function + Pcb.connect tcp ~dst:daddr ~dst_port:dport >>= function | `Timeout -> err_timeout daddr dport | `Rst -> err_refused daddr dport | `Ok (fl, _) -> ok fl diff --git a/lib/tcp/pcb.ml b/lib/tcp/pcb.ml index 99ac39e89..0c1ffc758 100644 --- a/lib/tcp/pcb.ml +++ b/lib/tcp/pcb.ml @@ -412,7 +412,7 @@ struct let process_syn t id ~listeners ~tx_wnd ~ack_number ~sequence ~options ~syn ~fin = Logs.(log_with_stats Debug "process-syn" t); - match listeners @@ WIRE.local_port_of_id id with + match listeners @@ WIRE.src_port_of_id id with | Some pushf -> let tx_isn = Sequence.of_int ((Random.int 65535) + 0x1AFE0000) in (* TODO: make this configurable per listener *) @@ -481,7 +481,7 @@ struct | Result.Error s -> Log.debug (fun f -> f "parsing TCP header failed: %s" s); Lwt.return_unit | Result.Ok (pkt, payload) -> - let id = WIRE.wire ~local_port:pkt.dest_port ~dest_port:pkt.source_port ~dest_ip:src ~local_ip:dst in + let id = WIRE.wire ~src_port:pkt.dst_port ~dst_port:pkt.src_port ~dst:src ~src:dst in (* Lookup connection from the active PCB hash *) with_hashtbl t.channels id (* PCB exists, so continue the connection state machine in tcp_input *) @@ -538,9 +538,9 @@ struct (* Close - no more will be written *) let close pcb = Tx.close pcb - let get_dest pcb = WIRE.dest_of_id pcb.id + let dst pcb = WIRE.dst_of_id pcb.id - let getid t dest_ip dest_port = + let getid t dst dst_port = (* TODO: make this more robust and recognise when all ports are gone *) let islistener _t _port = (* TODO keep a list of active listen ports *) @@ -550,13 +550,13 @@ struct Hashtbl.mem t.connects id || Hashtbl.mem t.listens id in - let inuse t id = islistener t (WIRE.local_port_of_id id) || idinuse t id in + let inuse t id = islistener t (WIRE.src_port_of_id id) || idinuse t id in let rec bumpport t = (match t.localport with | 65535 -> t.localport <- 10000 | _ -> t.localport <- t.localport + 1); - let id = WIRE.wire ~local_ip:(Ip.get_source t.ip dest_ip) - ~local_port:t.localport ~dest_ip ~dest_port in + let id = WIRE.wire ~src:(Ip.src t.ip dst) + ~src_port:t.localport ~dst ~dst_port in if inuse t id then bumpport t else id in bumpport t @@ -582,8 +582,8 @@ struct ) else Lwt.return_unit - let connect t ~dest_ip ~dest_port = - let id = getid t dest_ip dest_port in + let connect t ~dst ~dst_port = + let id = getid t dst dst_port in let tx_isn = Sequence.of_int ((Random.int 65535) + 0x1BCD0000) in (* TODO: This is hardcoded for now - make it configurable *) let rx_wnd_scaleoffer = wscale_default in diff --git a/lib/tcp/pcb.mli b/lib/tcp/pcb.mli index 9017a9983..55ccdb6e3 100644 --- a/lib/tcp/pcb.mli +++ b/lib/tcp/pcb.mli @@ -31,11 +31,11 @@ module Make(Ip:V1_LWT.IP)(Time:V1_LWT.TIME)(Clock:V1.CLOCK)(Random:V1.RANDOM) : val input: t -> listeners:(int -> (pcb -> unit Lwt.t) option) -> src:Ip.ipaddr -> dst:Ip.ipaddr -> Cstruct.t -> unit Lwt.t - val connect: t -> dest_ip:Ip.ipaddr -> dest_port:int -> connection_result Lwt.t + val connect: t -> dst:Ip.ipaddr -> dst_port:int -> connection_result Lwt.t val close: pcb -> unit Lwt.t - val get_dest: pcb -> (Ip.ipaddr * int) + val dst: pcb -> (Ip.ipaddr * int) (* Blocking read for a segment *) val read: pcb -> Cstruct.t option Lwt.t diff --git a/lib/tcp/tcp_packet.ml b/lib/tcp/tcp_packet.ml index a5947450d..4921416ed 100644 --- a/lib/tcp/tcp_packet.ml +++ b/lib/tcp/tcp_packet.ml @@ -9,8 +9,8 @@ type t = { options : Options.t list; sequence : Sequence.t; ack_number : Sequence.t; - source_port : Cstruct.uint16; - dest_port : Cstruct.uint16; + src_port : Cstruct.uint16; + dst_port : Cstruct.uint16; } let equal p q = (p = q) @@ -58,11 +58,11 @@ module Unmarshal = struct let syn = get_syn pkt in let fin = get_fin pkt in let window = get_tcp_window pkt in - let source_port = get_tcp_src_port pkt in - let dest_port = get_tcp_dst_port pkt in + let src_port = get_tcp_src_port pkt in + let dst_port = get_tcp_dst_port pkt in let data = Cstruct.shift pkt data_offset in Result.Ok ({ urg; ack; psh; rst; syn; fin; window; options; - sequence; ack_number; source_port; dest_port }, data) + sequence; ack_number; src_port; dst_port }, data) end module Marshal = struct open Rresult @@ -72,8 +72,8 @@ module Marshal = struct let unsafe_fill ~pseudoheader ~payload t buf options_len = let data_off = (sizeof_tcp / 4) + (options_len / 4) in - set_tcp_src_port buf t.source_port; - set_tcp_dst_port buf t.dest_port; + set_tcp_src_port buf t.src_port; + set_tcp_dst_port buf t.dst_port; set_tcp_sequence buf (Sequence.to_int32 t.sequence); set_tcp_ack_number buf (Sequence.to_int32 t.ack_number); set_data_offset buf data_off; diff --git a/lib/tcp/tcp_packet.mli b/lib/tcp/tcp_packet.mli index 4a3f27dd3..ceb818c1c 100644 --- a/lib/tcp/tcp_packet.mli +++ b/lib/tcp/tcp_packet.mli @@ -9,8 +9,8 @@ type t = { options : Options.t list; sequence : Sequence.t; ack_number : Sequence.t; - source_port : Cstruct.uint16; - dest_port : Cstruct.uint16; + src_port : Cstruct.uint16; + dst_port : Cstruct.uint16; } val pp : Format.formatter -> t -> unit diff --git a/lib/tcp/wire.ml b/lib/tcp/wire.ml index 8d8e53afc..7c07d65c8 100644 --- a/lib/tcp/wire.ml +++ b/lib/tcp/wire.ml @@ -26,25 +26,25 @@ let set_options buf ts = module Make (Ip:V1_LWT.IP) = struct type id = { - dest_port: int; (* Remote TCP port *) - dest_ip: Ip.ipaddr; (* Remote IP address *) - local_port: int; (* Local TCP port *) - local_ip: Ip.ipaddr; (* Local IP address *) + dst_port: int; (* Remote TCP port *) + dst: Ip.ipaddr; (* Remote IP address *) + src_port: int; (* Local TCP port *) + src: Ip.ipaddr; (* Local IP address *) } - let wire ~local_ip ~local_port ~dest_ip ~dest_port = - { dest_port ; dest_ip; local_port ; local_ip } + let wire ~src ~src_port ~dst ~dst_port = + { dst_port ; dst ; src_port ; src } - let local_port_of_id id = id.local_port + let src_port_of_id id = id.src_port - let dest_of_id id = (id.dest_ip, id.dest_port) + let dst_of_id id = (id.dst, id.dst_port) let pp_id fmt id = let uip = Ip.to_uipaddr in Format.fprintf fmt "remote %a,%d to local %a, %d" - Ipaddr.pp_hum (uip id.dest_ip) id.dest_port Ipaddr.pp_hum (uip id.local_ip) id.local_port + Ipaddr.pp_hum (uip id.dst) id.dst_port Ipaddr.pp_hum (uip id.src) id.src_port - let xmit ~ip ~id ?(rst=false) ?(syn=false) ?(fin=false) ?(psh=false) + let xmit ~ip ~(id:id) ?(rst=false) ?(syn=false) ?(fin=false) ?(psh=false) ~rx_ack ~seq ~window ~options payload = let (ack, ack_number) = match rx_ack with | None -> (false, Sequence.zero) @@ -54,13 +54,13 @@ module Make (Ip:V1_LWT.IP) = struct sequence = seq; ack_number; window; urg = false; ack; psh; rst; syn; fin; options; - source_port = id.local_port; dest_port = id.dest_port; + src_port = id.src_port; dst_port = id.dst_port; }) in (* Make a TCP/IP header frame *) - let frame, header_len = Ip.allocate_frame ip ~dst:id.dest_ip ~proto:`TCP in + let frame, header_len = Ip.allocate_frame ip ~dst:id.dst ~proto:`TCP in (* Shift this out by the combined ethernet + IP header sizes *) let tcp_buf = Cstruct.shift frame header_len in - let pseudoheader = Ip.pseudoheader ip ~dst:id.dest_ip ~proto:`TCP (Cstruct.len payload) in + let pseudoheader = Ip.pseudoheader ip ~dst:id.dst ~proto:`TCP (Cstruct.len payload) in match Tcp_packet.Marshal.into_cstruct header tcp_buf ~pseudoheader ~payload with | Result.Error s -> Log.info (fun fmt -> fmt "Error transmitting TCP packet: %s" s); diff --git a/lib/tcp/wire.mli b/lib/tcp/wire.mli index 3dfb30bce..30f978b48 100644 --- a/lib/tcp/wire.mli +++ b/lib/tcp/wire.mli @@ -17,11 +17,11 @@ module Make(Ip:V1_LWT.IP) : sig type id - val local_port_of_id : id -> int + val src_port_of_id : id -> int - val dest_of_id : id -> (Ip.ipaddr * int) + val dst_of_id : id -> (Ip.ipaddr * int) - val wire : local_ip:Ip.ipaddr -> local_port:int -> dest_ip:Ip.ipaddr -> dest_port:int -> id + val wire : src:Ip.ipaddr -> src_port:int -> dst:Ip.ipaddr -> dst_port:int -> id val pp_id : Format.formatter -> id -> unit diff --git a/lib/udp/udp.ml b/lib/udp/udp.ml index 4460c52c0..b2eff8178 100644 --- a/lib/udp/udp.ml +++ b/lib/udp/udp.ml @@ -52,16 +52,16 @@ module Make(Ip: V1_LWT.IP) = struct | Some fn -> fn ~src ~dst ~src_port payload - let writev ?source_port ~dest_ip ~dest_port t bufs = - begin match source_port with + let writev ?src_port ~dst ~dst_port t bufs = + begin match src_port with | None -> Lwt.fail (Failure "TODO; random source port") | Some p -> Lwt.return p - end >>= fun source_port -> - let frame, header_len = Ip.allocate_frame t.ip ~dst:dest_ip ~proto:`UDP in + end >>= fun src_port -> + let frame, header_len = Ip.allocate_frame t.ip ~dst:dst ~proto:`UDP in let frame = Cstruct.set_len frame (header_len + Udp_wire.sizeof_udp) in let udp_buf = Cstruct.shift frame header_len in - let ph = Ip.pseudoheader t.ip ~dst:dest_ip ~proto:`UDP (Cstruct.lenv bufs) in - let udp_header = Udp_packet.({ src_port = source_port; dst_port = dest_port; }) in + let ph = Ip.pseudoheader t.ip ~dst ~proto:`UDP (Cstruct.lenv bufs) in + let udp_header = Udp_packet.({ src_port = src_port; dst_port = dst_port; }) in match Udp_packet.Marshal.into_cstruct udp_header udp_buf ~pseudoheader:ph ~payload:(Cstruct.concat bufs) with | Ok () -> @@ -69,8 +69,8 @@ module Make(Ip: V1_LWT.IP) = struct | Error s -> Log.debug (fun f -> f "Discarding transmitted UDP message: error writing: %s" s); Lwt.return_unit - let write ?source_port ~dest_ip ~dest_port t buf = - writev ?source_port ~dest_ip ~dest_port t [buf] + let write ?src_port ~dst ~dst_port t buf = + writev ?src_port ~dst ~dst_port t [buf] let connect ip = let ips = List.map Ip.to_uipaddr @@ Ip.get_ip ip in diff --git a/lib_test/test_connect.ml b/lib_test/test_connect.ml index 3cd7a9cad..84d825909 100644 --- a/lib_test/test_connect.ml +++ b/lib_test/test_connect.ml @@ -44,7 +44,7 @@ module Test_connect (B : Vnetif_backends.Backend) = struct fail "client tried to write, got %s" err let accept c flow expected = - let ip, port = V.Stackv4.TCPV4.get_dest flow in + let ip, port = V.Stackv4.TCPV4.dst flow in log_s c "Accepted connection from %s:%d" (Ipaddr.V4.to_string ip) port >>= fun () -> V.Stackv4.TCPV4.read flow >>= function diff --git a/lib_test/test_rfc5961.ml b/lib_test/test_rfc5961.ml index 5a77a16dd..cc7b8f902 100644 --- a/lib_test/test_rfc5961.ml +++ b/lib_test/test_rfc5961.ml @@ -127,7 +127,7 @@ let run backend fsm sut () = let reply_id_from ~src ~dst data = let sport = Tcp_wire.get_tcp_src_port data in let dport = Tcp_wire.get_tcp_dst_port data in - WIRE.wire ~dest_port:sport ~dest_ip:src ~local_port:dport ~local_ip:dst + WIRE.wire ~dst_port:sport ~dst:src ~src_port:dport ~src:dst let ack_for data = match Tcp_unmarshal.of_cstruct data with diff --git a/unix/ipv4_socket.ml b/unix/ipv4_socket.ml index 7472e988c..a20235aa8 100644 --- a/unix/ipv4_socket.ml +++ b/unix/ipv4_socket.ml @@ -46,6 +46,6 @@ let get_ip_netmasks _ = [Ipaddr.V4.of_string_exn "255.255.255.0"] let get_ip_gateways _ = raise (Failure "Not implemented") let set_ip_netmask _ _ = fail (Failure "Not implemented") let set_ip_gateways _ _ = fail (Failure "Not implemented") -let get_source _ ~dst:_ = raise (Failure "Not implemented") +let src _ ~dst:_ = raise (Failure "Not implemented") let checksum _ _ = raise (Failure "Not implemented") let pseudoheader _ ~dst:_ ~proto:_ _ = raise (Failure "Not implemented") diff --git a/unix/ipv6_socket.ml b/unix/ipv6_socket.ml index cef8a0674..1d2a5a0b2 100644 --- a/unix/ipv6_socket.ml +++ b/unix/ipv6_socket.ml @@ -46,4 +46,4 @@ let get_ip_gateways _ = raise (Failure "Not implemented") let set_ip_gateways _ _ = fail (Failure "Not implemented") let checksum _ _ = raise (Failure "Not implemented") -let get_source _ ~dst:_ = raise (Failure "Not implemented") +let src _ ~dst:_ = raise (Failure "Not implemented") diff --git a/unix/tcpv4_socket.ml b/unix/tcpv4_socket.ml index 32f14183c..2db19929c 100644 --- a/unix/tcpv4_socket.ml +++ b/unix/tcpv4_socket.ml @@ -56,7 +56,7 @@ let id {interface} = | None -> None | Some i -> Some (Ipaddr_unix.V4.of_inet_addr_exn i) -let get_dest fd = +let dst fd = match Lwt_unix.getpeername fd with | Unix.ADDR_UNIX _ -> raise (Failure "unexpected: got a unix instead of tcp sock") diff --git a/unix/tcpv6_socket.ml b/unix/tcpv6_socket.ml index 8d93aef92..54bb2ba51 100644 --- a/unix/tcpv6_socket.ml +++ b/unix/tcpv6_socket.ml @@ -57,7 +57,7 @@ let id {interface} = | None -> None | Some i -> Some (Ipaddr_unix.V6.of_inet_addr_exn i) -let get_dest fd = +let dst fd = match Lwt_unix.getpeername fd with | Unix.ADDR_UNIX _ -> raise (Failure "unexpected: got a unix instead of tcp sock") diff --git a/unix/udpv4_socket.ml b/unix/udpv4_socket.ml index 33dca40f6..5549fed53 100644 --- a/unix/udpv4_socket.ml +++ b/unix/udpv4_socket.ml @@ -66,13 +66,13 @@ let id { interface; _ } = let t, _ = Lwt.task () in t -let write ?source_port ~dest_ip ~dest_port t buf = +let write ?src_port ~dst ~dst_port t buf = let open Lwt_unix in let fd = - match source_port with + match src_port with | None -> get_udpv4_listening_fd t 0 | Some port -> get_udpv4_listening_fd t port in - Lwt_cstruct.sendto fd buf [] (ADDR_INET ((Ipaddr_unix.V4.to_inet_addr dest_ip), dest_port)) + Lwt_cstruct.sendto fd buf [] (ADDR_INET ((Ipaddr_unix.V4.to_inet_addr dst), dst_port)) >>= fun _ -> return_unit