diff options
author | John Estabrook <jestabro@vyos.io> | 2023-07-31 15:31:23 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-07-31 15:32:04 -0500 |
commit | 675ea7481aeef903a8583458f43c12def75da222 (patch) | |
tree | 816560dd4311c7a713b3143e1003e66bae52660c | |
parent | 2b1455a460c3e2a538d01f29782217f45e3c2124 (diff) | |
download | vyos-utils-675ea7481aeef903a8583458f43c12def75da222.tar.gz vyos-utils-675ea7481aeef903a8583458f43c12def75da222.zip |
T5421: add arg to filter out subinterfaces
-rw-r--r-- | src/iface/list_interfaces.ml | 14 |
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 |