package charrua

  1. Overview
  2. Docs

DHCP general data

val client_port : int

DHCP client port 68

val server_port : int

DHCP server port 67

DHCP header opcodes

type op =
  1. | BOOTREQUEST
  2. | BOOTREPLY

Conversions of ops.

val int_to_op : int -> op option
val int_to_op_exn : int -> op
val op_to_int : op -> int
val op_to_string : op -> string

DHCP message type option values

type msgtype =
  1. | DHCPDISCOVER
  2. | DHCPOFFER
  3. | DHCPREQUEST
  4. | DHCPDECLINE
  5. | DHCPACK
  6. | DHCPNAK
  7. | DHCPRELEASE
  8. | DHCPINFORM
  9. | DHCPFORCERENEW
  10. | DHCPLEASEQUERY
  11. | DHCPLEASEUNASSIGNED
  12. | DHCPLEASEUNKNOWN
  13. | DHCPLEASEACTIVE
  14. | DHCPBULKLEASEQUERY
  15. | DHCPLEASEQUERYDONE

Conversions of msgtypes.

val msgtype_to_int : msgtype -> int
val int_to_msgtype : int -> msgtype option
val int_to_msgtype_exn : int -> msgtype
val msgtype_to_string : msgtype -> string

DHCP option codes (names only, for use in parameter requests)

type option_code =
  1. | PAD
  2. | SUBNET_MASK
  3. | TIME_OFFSET
  4. | ROUTERS
  5. | DNS_SERVERS
  6. | LOG_SERVERS
  7. | LPR_SERVERS
  8. | HOSTNAME
  9. | BOOTFILE_SIZE
  10. | DOMAIN_NAME
  11. | SWAP_SERVER
  12. | ROOT_PATH
  13. | EXTENSION_PATH
  14. | IPFORWARDING
  15. | NLSR
  16. | POLICY_FILTERS
  17. | MAX_DATAGRAM
  18. | DEFAULT_IP_TTL
  19. | INTERFACE_MTU
  20. | ALL_SUBNETS_LOCAL
  21. | BROADCAST_ADDR
  22. | PERFORM_ROUTER_DISC
  23. | ROUTER_SOL_ADDR
  24. | STATIC_ROUTES
  25. | TRAILER_ENCAPSULATION
  26. | ARP_CACHE_TIMO
  27. | ETHERNET_ENCAPSULATION
  28. | TCP_DEFAULT_TTL
  29. | TCP_KEEPALIVE_INTERVAL
  30. | NIS_DOMAIN
  31. | NIS_SERVERS
  32. | NTP_SERVERS
  33. | VENDOR_SPECIFIC
  34. | NETBIOS_NAME_SERVERS
  35. | NETBIOS_DATAGRAM_DISTRIB_SERVERS
  36. | NETBIOS_NODE
  37. | NETBIOS_SCOPE
  38. | XWINDOW_FONT_SERVERS
  39. | XWINDOW_DISPLAY_MANAGERS
  40. | REQUEST_IP
  41. | IP_LEASE_TIME
  42. | OPTION_OVERLOAD
  43. | MESSAGE_TYPE
  44. | SERVER_IDENTIFIER
  45. | PARAMETER_REQUESTS
  46. | MESSAGE
  47. | MAX_MESSAGE
  48. | RENEWAL_T1
  49. | REBINDING_T2
  50. | VENDOR_CLASS_ID
  51. | CLIENT_ID
  52. | NIS_PLUS_DOMAIN
  53. | NIS_PLUS_SERVERS
  54. | TFTP_SERVER_NAME
  55. | BOOTFILE_NAME
  56. | MOBILE_IP_HOME_AGENT
  57. | SMTP_SERVERS
  58. | POP3_SERVERS
  59. | NNTP_SERVERS
  60. | IRC_SERVERS
  61. | USER_CLASS
  62. | RAPID_COMMIT
  63. | CLIENT_FQDN
  64. | RELAY_AGENT_INFORMATION
  65. | CLIENT_SYSTEM
  66. | CLIENT_NDI
  67. | UUID_GUID
  68. | PCODE
  69. | TCODE
  70. | IPV6ONLY
  71. | SUBNET_SELECTION
  72. | SIP_SERVERS
  73. | CLASSLESS_STATIC_ROUTE
  74. | VI_VENDOR_INFO
  75. | MISC_150
  76. | PRIVATE_CLASSLESS_STATIC_ROUTE
  77. | WEB_PROXY_AUTO_DISC
  78. | END
  79. | OTHER of int
    (*

    The type of a dhcp parameter request, these are all the values according to iana

    *)

Conversions of DHCP option_codes.

val int_to_option_code : int -> option_code option
val int_to_option_code_exn : int -> option_code
val option_code_to_int : option_code -> int
val option_code_to_string : option_code -> string

DHCP hardware type

type htype =
  1. | Ethernet_10mb
  2. | Other

Conversions of htype.

val htype_to_string : htype -> string

DHCP header flags

type flags =
  1. | Broadcast
  2. | Unicast

Conversions of flags.

val flags_to_string : flags -> string

DHCP Client identifier

type client_id =
  1. | Hwaddr of Macaddr.t
  2. | Id of int * string
    (*

    A client_id is usually a mac address from a dhcp_option, but it can also be an opaque string. See client_id_of_pkt.

    *)

Conversions of client_id.

val client_id_to_string : client_id -> string
val string_to_client_id : string -> client_id option

DHCP options

type dhcp_option =
  1. | Pad
  2. | Subnet_mask of Ipaddr.V4.t
  3. | Time_offset of int32
  4. | Routers of Ipaddr.V4.t list
  5. | Dns_servers of Ipaddr.V4.t list
  6. | Log_servers of Ipaddr.V4.t list
  7. | Lpr_servers of Ipaddr.V4.t list
  8. | Hostname of string
  9. | Bootfile_size of int
  10. | Domain_name of string
  11. | Swap_server of Ipaddr.V4.t
  12. | Root_path of string
  13. | Extension_path of string
  14. | Ipforwarding of bool
  15. | Nlsr of bool
  16. | Policy_filters of Ipaddr.V4.Prefix.t list
  17. | Max_datagram of int
  18. | Default_ip_ttl of int
  19. | Interface_mtu of int
  20. | All_subnets_local of bool
  21. | Broadcast_addr of Ipaddr.V4.t
  22. | Perform_router_disc of bool
  23. | Router_sol_addr of Ipaddr.V4.t
  24. | Static_routes of (Ipaddr.V4.t * Ipaddr.V4.t) list
  25. | Trailer_encapsulation of bool
  26. | Arp_cache_timo of int32
  27. | Ethernet_encapsulation of bool
  28. | Tcp_default_ttl of int
  29. | Tcp_keepalive_interval of int32
  30. | Nis_domain of string
  31. | Nis_servers of Ipaddr.V4.t list
  32. | Ntp_servers of Ipaddr.V4.t list
  33. | Vendor_specific of string
  34. | Netbios_name_servers of Ipaddr.V4.t list
  35. | Netbios_datagram_distrib_servers of Ipaddr.V4.t list
  36. | Netbios_node of int
  37. | Netbios_scope of string
  38. | Xwindow_font_servers of Ipaddr.V4.t list
  39. | Xwindow_display_managers of Ipaddr.V4.t list
  40. | Request_ip of Ipaddr.V4.t
  41. | Ip_lease_time of int32
  42. | Option_overload of int
  43. | Message_type of msgtype
  44. | Server_identifier of Ipaddr.V4.t
  45. | Parameter_requests of option_code list
  46. | Message of string
  47. | Max_message of int
  48. | Renewal_t1 of int32
  49. | Rebinding_t2 of int32
  50. | Vendor_class_id of string
  51. | Client_id of client_id
  52. | Nis_plus_domain of string
  53. | Nis_plus_servers of Ipaddr.V4.t list
  54. | Tftp_server_name of string
  55. | Bootfile_name of string
  56. | Mobile_ip_home_agent of Ipaddr.V4.t list
  57. | Smtp_servers of Ipaddr.V4.t list
  58. | Pop3_servers of Ipaddr.V4.t list
  59. | Nntp_servers of Ipaddr.V4.t list
  60. | Irc_servers of Ipaddr.V4.t list
  61. | User_class of string
  62. | Rapid_commit
  63. | Client_fqdn of string
  64. | Relay_agent_information of string
  65. | Client_system of string
  66. | Client_ndi of string
  67. | Uuid_guid of string
  68. | Pcode of string
  69. | Tcode of string
  70. | IPv6_only of int32
  71. | Subnet_selection of Ipaddr.V4.t
  72. | Sip_servers of string
  73. | Classless_static_route of string
  74. | Vi_vendor_info of string
  75. | Misc_150 of string
  76. | Private_classless_static_route of string
  77. | Web_proxy_auto_disc of string
  78. | End
  79. | Other of int * string
    (*

    Not all options are currently implemented.

    *)

Conversions of dhcp_option.

val dhcp_option_to_string : dhcp_option -> string
val buf_of_options : Cstruct.t -> dhcp_option list -> Cstruct.t
val options_of_buf : Cstruct.t -> int -> dhcp_option list
val find_option : (dhcp_option -> 'b option) -> dhcp_option list -> 'b option

find_option f l finds the first option where f evaluates to Some value on list l

val collect_options : ('a -> 'b list option) -> 'a list -> 'b list

collect_options f l collects all options where f evaluates to Some value on list l, this is useful for list options like Routers, if multiple list options are found, the resulting list is flattened.

val collect_dns_servers : dhcp_option list -> Ipaddr.V4.t list
val collect_irc_servers : dhcp_option list -> Ipaddr.V4.t list
val collect_log_servers : dhcp_option list -> Ipaddr.V4.t list
val collect_lpr_servers : dhcp_option list -> Ipaddr.V4.t list
val collect_netbios_datagram_distrib_servers : dhcp_option list -> Ipaddr.V4.t list
val collect_netbios_name_servers : dhcp_option list -> Ipaddr.V4.t list
val collect_nis_plus_servers : dhcp_option list -> Ipaddr.V4.t list
val collect_nis_servers : dhcp_option list -> Ipaddr.V4.t list
val collect_ntp_servers : dhcp_option list -> Ipaddr.V4.t list
val find_parameter_requests : dhcp_option list -> option_code list option
val collect_policy_filters : dhcp_option list -> Ipaddr.V4.Prefix.t list
val collect_routers : dhcp_option list -> Ipaddr.V4.t list
val collect_static_routes : dhcp_option list -> (Ipaddr.V4.t * Ipaddr.V4.t) list
val collect_xwindow_display_managers : dhcp_option list -> Ipaddr.V4.t list
val collect_xwindow_font_servers : dhcp_option list -> Ipaddr.V4.t list
val find_all_subnets_local : dhcp_option list -> bool option
val find_arp_cache_timo : dhcp_option list -> int32 option
val find_bootfile_name : dhcp_option list -> string option
val find_bootfile_size : dhcp_option list -> int option
val find_broadcast_addr : dhcp_option list -> Ipaddr.V4.t option
val find_classless_static_route : dhcp_option list -> string option
val find_client_fqdn : dhcp_option list -> string option
val find_client_id : dhcp_option list -> client_id option
val find_client_ndi : dhcp_option list -> string option
val find_client_system : dhcp_option list -> string option
val find_default_ip_ttl : dhcp_option list -> int option
val find_domain_name : dhcp_option list -> string option
val find_ethernet_encapsulation : dhcp_option list -> bool option
val find_extension_path : dhcp_option list -> string option
val find_hostname : dhcp_option list -> string option
val find_interface_mtu : dhcp_option list -> int option
val find_ip_lease_time : dhcp_option list -> int32 option
val find_ipforwarding : dhcp_option list -> bool option
val find_max_datagram : dhcp_option list -> int option
val find_max_message : dhcp_option list -> int option
val find_message : dhcp_option list -> string option
val find_message_type : dhcp_option list -> msgtype option
val find_misc_150 : dhcp_option list -> string option
val collect_mobile_ip_home_agent : dhcp_option list -> Ipaddr.V4.t list
val find_netbios_node : dhcp_option list -> int option
val find_netbios_scope : dhcp_option list -> string option
val find_nis_domain : dhcp_option list -> string option
val find_nis_plus_domain : dhcp_option list -> string option
val find_nlsr : dhcp_option list -> bool option
val collect_nntp_servers : dhcp_option list -> Ipaddr.V4.t list
val find_option_overload : dhcp_option list -> int option
val find_pcode : dhcp_option list -> string option
val find_perform_router_disc : dhcp_option list -> bool option
val collect_pop3_servers : dhcp_option list -> Ipaddr.V4.t list
val find_rapid_commit : dhcp_option list -> dhcp_option option
val find_rebinding_t2 : dhcp_option list -> int32 option
val find_relay_agent_information : dhcp_option list -> string option
val find_renewal_t1 : dhcp_option list -> int32 option
val find_request_ip : dhcp_option list -> Ipaddr.V4.t option
val find_root_path : dhcp_option list -> string option
val find_router_sol_addr : dhcp_option list -> Ipaddr.V4.t option
val find_server_identifier : dhcp_option list -> Ipaddr.V4.t option
val find_sip_servers : dhcp_option list -> string option
val collect_smtp_servers : dhcp_option list -> Ipaddr.V4.t list
val find_subnet_mask : dhcp_option list -> Ipaddr.V4.t option
val find_subnet_selection : dhcp_option list -> Ipaddr.V4.t option
val find_swap_server : dhcp_option list -> Ipaddr.V4.t option
val find_tcode : dhcp_option list -> string option
val find_ipv6only : dhcp_option list -> int32 option
val find_tcp_default_ttl : dhcp_option list -> int option
val find_tcp_keepalive_interval : dhcp_option list -> int32 option
val find_tftp_server_name : dhcp_option list -> string option
val find_time_offset : dhcp_option list -> int32 option
val find_trailer_encapsulation : dhcp_option list -> bool option
val find_user_class : dhcp_option list -> string option
val find_uuid_guid : dhcp_option list -> string option
val find_vendor_class_id : dhcp_option list -> string option
val find_vendor_specific : dhcp_option list -> string option
val find_vi_vendor_info : dhcp_option list -> string option
val find_web_proxy_auto_disc : dhcp_option list -> string option
val find_private_classless_static_route : dhcp_option list -> string option
val find_other : int -> dhcp_option list -> (int * string) option
val collect_other : int -> dhcp_option list -> (int * string) list

DHCP Packet - fixed-length fields, plus a variable-length list of options

type pkt = {
  1. srcmac : Macaddr.t;
  2. dstmac : Macaddr.t;
  3. srcip : Ipaddr.V4.t;
  4. dstip : Ipaddr.V4.t;
  5. srcport : int;
  6. dstport : int;
  7. op : op;
  8. htype : htype;
  9. hlen : int;
  10. hops : int;
  11. xid : int32;
  12. secs : int;
  13. flags : flags;
  14. ciaddr : Ipaddr.V4.t;
  15. yiaddr : Ipaddr.V4.t;
  16. siaddr : Ipaddr.V4.t;
  17. giaddr : Ipaddr.V4.t;
  18. chaddr : Macaddr.t;
  19. sname : string;
  20. file : string;
  21. options : dhcp_option list;
}

Conversions for pkt.

val pkt_of_buf : Cstruct.t -> int -> (pkt, string) result
val buf_of_pkt : pkt -> Cstruct.t
val pkt_into_buf : pkt -> Cstruct.t -> int
val pp_pkt : pkt Fmt.t
val client_id_of_pkt : pkt -> client_id

Helpers.

val is_dhcp : Cstruct.t -> int -> bool

is_dhcp buf len is true if buf is an Ethernet frame containing an IPv4 header, UDP header, and DHCP packet.

OCaml

Innovation. Community. Security.