summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-06-23 14:42:05 -0500
committerJohn Estabrook <jestabro@vyos.io>2025-07-06 18:26:21 -0500
commit1e4f661b8c29edf0b03eac4adf032735d6a885a7 (patch)
treec2289b3cce8da53e03c7f75d7cddd7b564a48465
parent97641ae54f7a7bd377caead3b2fe1e6080e8357f (diff)
downloadvyconf-1e4f661b8c29edf0b03eac4adf032735d6a885a7.tar.gz
vyconf-1e4f661b8c29edf0b03eac4adf032735d6a885a7.zip
T7499: allow load from internal representation to avoid re-parsing
-rw-r--r--data/vyconf.proto3
-rw-r--r--src/session.ml12
-rw-r--r--src/session.mli2
-rw-r--r--src/vyconf_pbt.ml20
-rw-r--r--src/vyconf_pbt.mli2
-rw-r--r--src/vyconfd.ml2
6 files changed, 34 insertions, 7 deletions
diff --git a/data/vyconf.proto b/data/vyconf.proto
index 30f213c..4466837 100644
--- a/data/vyconf.proto
+++ b/data/vyconf.proto
@@ -85,7 +85,8 @@ message Request {
message Load {
required string Location = 1;
- optional ConfigFormat format = 2;
+ required bool cached = 2;
+ optional ConfigFormat format = 3;
}
message Merge {
diff --git a/src/session.ml b/src/session.ml
index 9ce2807..72e766d 100644
--- a/src/session.ml
+++ b/src/session.ml
@@ -127,8 +127,16 @@ let session_changed w s =
let del_tree = CT.get_subtree diff ["del"] in
(del_tree <> CT.default) || (add_tree <> CT.default)
-let load w s file =
- let ct = Vyos1x.Config_file.load_config file in
+let load w s file cached =
+ let ct =
+ if cached then
+ try
+ Ok (IC.read_internal file)
+ with Vyos1x.Internal.Read_error e ->
+ Error e
+ else
+ Vyos1x.Config_file.load_config file
+ in
match ct with
| Error e -> raise (Session_error (Printf.sprintf "Error loading config: %s" e))
| Ok config ->
diff --git a/src/session.mli b/src/session.mli
index 8e5805d..0398bb1 100644
--- a/src/session.mli
+++ b/src/session.mli
@@ -37,7 +37,7 @@ val discard : world -> session_data -> session_data
val session_changed : world -> session_data -> bool
-val load : world -> session_data -> string -> session_data
+val load : world -> session_data -> string -> bool -> session_data
val save : world -> session_data -> string -> session_data
diff --git a/src/vyconf_pbt.ml b/src/vyconf_pbt.ml
index 0afa0bd..facf9f5 100644
--- a/src/vyconf_pbt.ml
+++ b/src/vyconf_pbt.ml
@@ -83,6 +83,7 @@ type request_rollback = {
type request_load = {
location : string;
+ cached : bool;
format : request_config_format option;
}
@@ -313,9 +314,11 @@ let rec default_request_rollback
let rec default_request_load
?location:((location:string) = "")
+ ?cached:((cached:bool) = false)
?format:((format:request_config_format option) = None)
() : request_load = {
location;
+ cached;
format;
}
@@ -567,11 +570,13 @@ let default_request_rollback_mutable () : request_rollback_mutable = {
type request_load_mutable = {
mutable location : string;
+ mutable cached : bool;
mutable format : request_config_format option;
}
let default_request_load_mutable () : request_load_mutable = {
location = "";
+ cached = false;
format = None;
}
@@ -819,6 +824,7 @@ let rec pp_request_rollback fmt (v:request_rollback) =
let rec pp_request_load fmt (v:request_load) =
let pp_i fmt () =
Pbrt.Pp.pp_record_field ~first:true "location" Pbrt.Pp.pp_string fmt v.location;
+ Pbrt.Pp.pp_record_field ~first:false "cached" Pbrt.Pp.pp_bool fmt v.cached;
Pbrt.Pp.pp_record_field ~first:false "format" (Pbrt.Pp.pp_option pp_request_config_format) fmt v.format;
in
Pbrt.Pp.pp_brk pp_i fmt ()
@@ -1137,10 +1143,12 @@ let rec encode_pb_request_rollback (v:request_rollback) encoder =
let rec encode_pb_request_load (v:request_load) encoder =
Pbrt.Encoder.string v.location encoder;
Pbrt.Encoder.key 1 Pbrt.Bytes encoder;
+ Pbrt.Encoder.bool v.cached encoder;
+ Pbrt.Encoder.key 2 Pbrt.Varint encoder;
begin match v.format with
| Some x ->
encode_pb_request_config_format x encoder;
- Pbrt.Encoder.key 2 Pbrt.Varint encoder;
+ Pbrt.Encoder.key 3 Pbrt.Varint encoder;
| None -> ();
end;
()
@@ -1784,6 +1792,7 @@ let rec decode_pb_request_rollback d =
let rec decode_pb_request_load d =
let v = default_request_load_mutable () in
let continue__= ref true in
+ let cached_is_set = ref false in
let location_is_set = ref false in
while !continue__ do
match Pbrt.Decoder.key d with
@@ -1795,15 +1804,22 @@ let rec decode_pb_request_load d =
| Some (1, pk) ->
Pbrt.Decoder.unexpected_payload "Message(request_load), field(1)" pk
| Some (2, Pbrt.Varint) -> begin
- v.format <- Some (decode_pb_request_config_format d);
+ v.cached <- Pbrt.Decoder.bool d; cached_is_set := true;
end
| Some (2, pk) ->
Pbrt.Decoder.unexpected_payload "Message(request_load), field(2)" pk
+ | Some (3, Pbrt.Varint) -> begin
+ v.format <- Some (decode_pb_request_config_format d);
+ end
+ | Some (3, pk) ->
+ Pbrt.Decoder.unexpected_payload "Message(request_load), field(3)" pk
| Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind
done;
+ begin if not !cached_is_set then Pbrt.Decoder.missing_field "cached" end;
begin if not !location_is_set then Pbrt.Decoder.missing_field "location" end;
({
location = v.location;
+ cached = v.cached;
format = v.format;
} : request_load)
diff --git a/src/vyconf_pbt.mli b/src/vyconf_pbt.mli
index d9eb8ef..42a4af6 100644
--- a/src/vyconf_pbt.mli
+++ b/src/vyconf_pbt.mli
@@ -90,6 +90,7 @@ type request_rollback = {
type request_load = {
location : string;
+ cached : bool;
format : request_config_format option;
}
@@ -315,6 +316,7 @@ val default_request_rollback :
val default_request_load :
?location:string ->
+ ?cached:bool ->
?format:request_config_format option ->
unit ->
request_load
diff --git a/src/vyconfd.ml b/src/vyconfd.ml
index 0b92fd1..379a55e 100644
--- a/src/vyconfd.ml
+++ b/src/vyconfd.ml
@@ -217,7 +217,7 @@ let discard world token (_req: request_discard) =
let load world token (req: request_load) =
try
- let session = Session.load world (find_session token) req.location
+ let session = Session.load world (find_session token) req.location req.cached
in
Hashtbl.replace sessions token session;
response_tmpl