This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
14
unikernel/duniverse/ocaml-dns/resolvconf/dns_resolvconf.ml
Normal file
14
unikernel/duniverse/ocaml-dns/resolvconf/dns_resolvconf.ml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
let parse buf =
|
||||
try
|
||||
Resolvconf_state.reset ();
|
||||
let buf =
|
||||
if String.(get buf (pred (length buf))) = '\n' then buf else buf ^ "\n"
|
||||
in
|
||||
let lexbuf = Lexing.from_string buf in
|
||||
Ok (Resolvconf_parser.resolvconf Resolvconf_lexer.lex lexbuf)
|
||||
with
|
||||
| Parsing.Parse_error ->
|
||||
Error (`Msg (Fmt.str "parse error at line %d" Resolvconf_state.(state.lineno)))
|
||||
| exn ->
|
||||
Error (`Msg (Fmt.str "error at line %d: %s" Resolvconf_state.(state.lineno)
|
||||
(Printexc.to_string exn)))
|
||||
|
|
@ -0,0 +1 @@
|
|||
val parse : string -> ([ `Nameserver of Ipaddr.t ] list, [> `Msg of string ]) result
|
||||
9
unikernel/duniverse/ocaml-dns/resolvconf/dune
Normal file
9
unikernel/duniverse/ocaml-dns/resolvconf/dune
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(library
|
||||
(name dns_resolvconv)
|
||||
(public_name dns-client.resolvconf)
|
||||
(private_modules resolvconf_lexer resolvconf_parser resolvconf_state)
|
||||
(libraries ipaddr fmt)
|
||||
(wrapped false))
|
||||
|
||||
(ocamlyacc resolvconf_parser)
|
||||
(ocamllex resolvconf_lexer)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
open Resolvconf_state
|
||||
open Resolvconf_parser
|
||||
}
|
||||
|
||||
let ipv4 = (['0'-'9']+ '.' ['0'-'9']+ '.' ['0'-'9']+ '.' ['0'-'9']+) as contents
|
||||
let ipv6 = (['0'-'9' 'a'-'f' 'A'-'F' ':']+) as contents
|
||||
|
||||
let zone_id = (['0'-'9' 'a'-'z' 'A'-'Z' '.' ]+) as contents
|
||||
|
||||
(* inspired by https://github.com/tailhook/resolv-conf/blob/master/src/grammar.rs *)
|
||||
|
||||
rule lex = parse
|
||||
| "nameserver" { SNAMESERVER }
|
||||
| "options" ([^'\n']*) '\n' { state.lineno <- state.lineno + 1 ; EOL }
|
||||
| "search" ([^'\n']*) '\n' { state.lineno <- state.lineno + 1 ; EOL }
|
||||
| "domain" ([^'\n']*) '\n' { state.lineno <- state.lineno + 1 ; EOL }
|
||||
| "sortlist" ([^'\n']*) '\n' { state.lineno <- state.lineno + 1 ; EOL }
|
||||
| "lookup" ([^'\n']*) '\n' { state.lineno <- state.lineno + 1 ; EOL }
|
||||
| "family" ([^'\n']*) '\n' { state.lineno <- state.lineno + 1 ; EOL }
|
||||
| [' ' '\t']+ { SPACE }
|
||||
| ipv4 { IPV4 contents }
|
||||
| ipv6 { IPV6 contents }
|
||||
| '.' { DOT }
|
||||
| ':' { COLON }
|
||||
| '%' { PERCENT }
|
||||
| [' ' '\t']* ('#' [^'\n']*)? '\n' { state.lineno <- state.lineno + 1 ; EOL }
|
||||
| [' ' '\t']* (';' [^'\n']*)? '\n' { state.lineno <- state.lineno + 1 ; EOL }
|
||||
| zone_id { ZONE_ID contents }
|
||||
| eof { EOF }
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
%{
|
||||
%}
|
||||
|
||||
%token EOF
|
||||
%token EOL
|
||||
%token SPACE
|
||||
%token SNAMESERVER
|
||||
%token DOT
|
||||
%token COLON
|
||||
%token PERCENT
|
||||
%token <string> IPV4
|
||||
%token <string> IPV6
|
||||
%token <string> ZONE_ID
|
||||
|
||||
%start resolvconf
|
||||
%type <[ `Nameserver of Ipaddr.t ] list> resolvconf
|
||||
|
||||
%%
|
||||
|
||||
resolvconf: lines EOF { List.rev $1 }
|
||||
|
||||
lines:
|
||||
/* nothing */ { [] }
|
||||
| lines EOL { $1 }
|
||||
| lines nameserver EOL { $2 :: $1 }
|
||||
|
||||
s: SPACE {} | s SPACE {}
|
||||
|
||||
ipv4: IPV4 { Ipaddr.V4.of_string_exn $1 }
|
||||
|
||||
ipv6:
|
||||
IPV6 { Ipaddr.V6.of_string_exn $1 }
|
||||
| IPV6 PERCENT ZONE_ID { Ipaddr.V6.of_string_exn $1 }
|
||||
|
||||
nameserver:
|
||||
SNAMESERVER s ipv4 { `Nameserver (Ipaddr.V4 $3) }
|
||||
| SNAMESERVER s ipv6 { `Nameserver (Ipaddr.V6 $3) }
|
||||
11
unikernel/duniverse/ocaml-dns/resolvconf/resolvconf_state.ml
Normal file
11
unikernel/duniverse/ocaml-dns/resolvconf/resolvconf_state.ml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(* State variables for the parser & lexer *)
|
||||
type parserstate = {
|
||||
mutable lineno : int ;
|
||||
}
|
||||
|
||||
let state = {
|
||||
lineno = 1 ;
|
||||
}
|
||||
|
||||
let reset () =
|
||||
state.lineno <- 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue