summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-07-31 15:50:38 -0500
committerGitHub <noreply@github.com>2023-07-31 15:50:38 -0500
commitb479b6258a582d6b74e38b9a2b966a5bb62dd15a (patch)
tree816560dd4311c7a713b3143e1003e66bae52660c
parent2b1455a460c3e2a538d01f29782217f45e3c2124 (diff)
parent675ea7481aeef903a8583458f43c12def75da222 (diff)
downloadvyos-utils-b479b6258a582d6b74e38b9a2b966a5bb62dd15a.tar.gz
vyos-utils-b479b6258a582d6b74e38b9a2b966a5bb62dd15a.zip
Merge pull request #13 from jestabro/no-vlan
T5421: add arg to filter out subinterfaces
-rw-r--r--src/iface/list_interfaces.ml14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/iface/list_interfaces.ml b/src/iface/list_interfaces.ml
index 2daa509..063e344 100644
--- a/src/iface/list_interfaces.ml
+++ b/src/iface/list_interfaces.ml
@@ -4,12 +4,14 @@ let intf_type = ref ""
let broadcast = ref false
let bridgeable = ref false
let bondable = ref false
+let no_vlan = ref false
let args = [
("--type", Arg.String (fun s -> intf_type := s), "List interfaces of specified type");
("--broadcast", Arg.Unit (fun () -> broadcast := true), "List broadcast interfaces");
("--bridgeable", Arg.Unit (fun () -> bridgeable := true), "List bridgeable interfaces");
("--bondable", Arg.Unit (fun () -> bondable := true), "List bondable interfaces");
+ ("--no-vlan-subinterfaces", Arg.Unit (fun () -> no_vlan := true), "List only parent interfaces");
]
let usage = Printf.sprintf "Usage: %s [OPTIONS] <number>" Sys.argv.(0)
@@ -89,6 +91,14 @@ let filter_bondable s =
true
with Not_found -> false
+let filter_no_vlan s =
+ let pattern = {|^([^.]+)(\.\d+)+$|}
+ in
+ try
+ let _ = Pcre.exec ~pat:pattern s in
+ false
+ with Not_found -> true
+
let get_interfaces =
let intf_type = !intf_type in
let fltr =
@@ -110,6 +120,10 @@ let get_interfaces =
if !bondable then List.filter filter_bondable res
else res
in
+ let res =
+ if !no_vlan then List.filter filter_no_vlan res
+ else res
+ in
let res = List.filter filter_section res in
match fltr with
| Some f -> List.filter f res