From 4aee642874a29f4f77704c97286f201d3c4bd2c3 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 23 Oct 2024 18:50:46 -0500 Subject: T6718: move vyos1x-adapter into subdirectory The vyos1x-adapter provides access to the legacy CStore set/delete functions using ctypes. Developed as a separate package, include as a subdir, to be retired when full replacements are available. --- src/adapter/vy_delete.ml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/adapter/vy_delete.ml (limited to 'src/adapter/vy_delete.ml') diff --git a/src/adapter/vy_delete.ml b/src/adapter/vy_delete.ml new file mode 100644 index 0000000..652fdad --- /dev/null +++ b/src/adapter/vy_delete.ml @@ -0,0 +1,40 @@ +let path_opt = ref [] + +let usage = "Usage: " ^ Sys.argv.(0) ^ " [options]" + +let read_path p = + path_opt := p::!path_opt + +let speclist = [ + ] + +let () = + let () = Arg.parse speclist read_path usage in + let path_list = List.rev !path_opt in + let () = + if List.length path_list = 0 then + (Printf.printf "no path specified\n"; exit 1) + in + let handle = + let h = Vyos1x_adapter.cstore_handle_init () in + if not (Vyos1x_adapter.cstore_in_config_session_handle h) then + (Vyos1x_adapter.cstore_handle_free h; + Printf.printf "not in config session\n"; exit 1) + else Some h + in + let output = + match handle with + | Some h -> Vyos1x_adapter.cstore_delete_path h path_list + | None -> "missing session handle" + in + let ret = + if output = "" then 0 + else 1 + in + let () = + match handle with + | Some h -> Vyos1x_adapter.cstore_handle_free h + | None -> () + in + let () = print_endline output in + exit ret -- cgit v1.2.3 From 7c093d7465438590ebcf142557f357762ab17698 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Thu, 24 Oct 2024 13:35:36 -0500 Subject: T6718: read argv explicity instead of using Arg The standard package Arg is understandably confused by paths such as: interfaces openvpn vtun0 openvpn-option --persist-tun Collect args from Sys.argv and use env vars for debug options. --- src/adapter/vy_delete.ml | 14 ++------------ src/adapter/vy_set.ml | 36 +++++++++++++++++------------------- 2 files changed, 19 insertions(+), 31 deletions(-) (limited to 'src/adapter/vy_delete.ml') diff --git a/src/adapter/vy_delete.ml b/src/adapter/vy_delete.ml index 652fdad..304e74b 100644 --- a/src/adapter/vy_delete.ml +++ b/src/adapter/vy_delete.ml @@ -1,16 +1,6 @@ -let path_opt = ref [] - -let usage = "Usage: " ^ Sys.argv.(0) ^ " [options]" - -let read_path p = - path_opt := p::!path_opt - -let speclist = [ - ] - let () = - let () = Arg.parse speclist read_path usage in - let path_list = List.rev !path_opt in + let path_list = Array.to_list (Array.sub Sys.argv 1 (Array.length Sys.argv - 1)) + in let () = if List.length path_list = 0 then (Printf.printf "no path specified\n"; exit 1) diff --git a/src/adapter/vy_set.ml b/src/adapter/vy_set.ml index 1fb29aa..b631de0 100644 --- a/src/adapter/vy_set.ml +++ b/src/adapter/vy_set.ml @@ -1,18 +1,4 @@ -let legacy = ref false -let no_set = ref false let valid = ref false -let output = ref "" -let path_opt = ref [] - -let usage = "Usage: " ^ Sys.argv.(0) ^ " [options]" - -let read_path p = - path_opt := p::!path_opt - -let speclist = [ - ("--legacy", Arg.Unit (fun _ -> legacy := true), "Use legacy validation"); - ("--no-set", Arg.Unit (fun _ -> no_set := true), "Do not set path"); - ] let format_out l = let fl = List.filter (fun s -> (String.length s) > 0) l in @@ -27,14 +13,26 @@ let valid_err v = Option.value v ~default:"" let () = - let () = Arg.parse speclist read_path usage in - let path_list = List.rev !path_opt in + let path_list = Array.to_list (Array.sub Sys.argv 1 (Array.length Sys.argv - 1)) + in let () = if List.length path_list = 0 then (Printf.printf "no path specified\n"; exit 1) in + let legacy = + try + let _ = Sys.getenv "LEGACY_VALIDATE" in + true + with Not_found -> false + in + let no_set = + try + let _ = Sys.getenv "LEGACY_NO_SET" in + true + with Not_found -> false + in let handle = - if !legacy || not !no_set then + if legacy || not no_set then let h = Vyos1x_adapter.cstore_handle_init () in if not (Vyos1x_adapter.cstore_in_config_session_handle h) then (Vyos1x_adapter.cstore_handle_free h; @@ -43,7 +41,7 @@ let () = else None in let valid = - if not !legacy then + if not legacy then Vyos1x_adapter.vyconf_validate_path path_list else begin @@ -58,7 +56,7 @@ let () = end in let res = - if not !no_set && (is_valid valid) then + if not no_set && (is_valid valid) then match handle with | Some h -> Vyos1x_adapter.cstore_set_path h path_list -- cgit v1.2.3