From 675ea7481aeef903a8583458f43c12def75da222 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Mon, 31 Jul 2023 15:31:23 -0500 Subject: T5421: add arg to filter out subinterfaces --- src/iface/list_interfaces.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') 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] " 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 -- cgit v1.2.3