From 9d47bf993932c064c60ea79592a06f0ffd383fd6 Mon Sep 17 00:00:00 2001 From: Roland Knall Date: Tue, 27 Dec 2016 10:14:32 +0100 Subject: [PATCH] InterfaceList: Add check for remote interface Add a check, to allow the filtering of remote only interfaces. Also add the necessary options to the type menu. Change-Id: Ib82519362454094f64abf1cbe6d7bc917990d7ac Reviewed-on: https://code.wireshark.org/review/19438 Petri-Dish: Roland Knall Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- epan/prefs.c | 10 +++++ epan/prefs.h | 3 ++ ui/qt/interface_frame.cpp | 19 +++++++++ ui/qt/interface_frame.h | 3 ++ ui/qt/interface_sort_filter_model.cpp | 60 +++++++++++++++++++++++++++ ui/qt/interface_sort_filter_model.h | 11 +++++ ui/qt/interface_tree_model.cpp | 10 +++++ ui/qt/interface_tree_model.h | 4 ++ 8 files changed, 120 insertions(+) diff --git a/epan/prefs.c b/epan/prefs.c index f0dd59bc7a..9528d16bf8 100644 --- a/epan/prefs.c +++ b/epan/prefs.c @@ -2527,6 +2527,13 @@ prefs_register_modules(void) "Show all interfaces, including interfaces marked as hidden", &prefs.gui_interfaces_show_hidden); +#ifdef HAVE_PCAP_REMOTE + prefs_register_bool_preference(gui_module, "interfaces_remote_display", + "Show Remote interfaces", + "Show remote interfaces in the interface selection", + &prefs.gui_interfaces_remote_display); +#endif + register_string_like_preference(gui_module, "interfaces_hidden_types", "Hide interface types in list", "Hide the given interface types in the startup list", &prefs.gui_interfaces_hide_types, PREF_STRING, NULL, TRUE); @@ -3202,6 +3209,9 @@ pre_init_prefs(void) if (prefs.gui_interfaces_hide_types) g_free (prefs.gui_interfaces_hide_types); prefs.gui_interfaces_hide_types = g_strdup(""); prefs.gui_interfaces_show_hidden = FALSE; +#ifdef HAVE_PCAP_REMOTE + prefs.gui_interfaces_remote_display = TRUE; +#endif prefs.gui_qt_packet_list_separator = FALSE; diff --git a/epan/prefs.h b/epan/prefs.h index a64d363e58..93094c048c 100644 --- a/epan/prefs.h +++ b/epan/prefs.h @@ -193,6 +193,9 @@ typedef struct _e_prefs { layout_pane_content_e gui_layout_content_3; gchar *gui_interfaces_hide_types; gboolean gui_interfaces_show_hidden; +#ifdef HAVE_PCAP_REMOTE + gboolean gui_interfaces_remote_display; +#endif gint console_log_level; gchar *capture_device; gchar *capture_devices_linktypes; diff --git a/ui/qt/interface_frame.cpp b/ui/qt/interface_frame.cpp index 64af22da68..58175143a2 100644 --- a/ui/qt/interface_frame.cpp +++ b/ui/qt/interface_frame.cpp @@ -133,6 +133,17 @@ QMenu * InterfaceFrame::getSelectionMenu() ++it; } +#ifdef HAVE_PCAP_REMOTE + if ( proxyModel->remoteInterfacesExist() ) + { + QAction * toggleRemoteAction = new QAction(tr("Remote interfaces"), this); + toggleRemoteAction->setCheckable(true); + toggleRemoteAction->setChecked(! proxyModel->remoteDisplay()); + connect(toggleRemoteAction, SIGNAL(triggered()), this, SLOT(toggleRemoteInterfaces())); + contextMenu->addAction(toggleRemoteAction); + } +#endif + contextMenu->addSeparator(); QAction * toggleHideAction = new QAction(tr("Show hidden interfaces"), this); toggleHideAction->setCheckable(true); @@ -214,6 +225,14 @@ void InterfaceFrame::toggleHiddenInterfaces() emit typeSelectionChanged(); } +#ifdef HAVE_PCAP_REMOTE +void InterfaceFrame::toggleRemoteInterfaces() +{ + proxyModel->toggleRemoteDisplay(); + emit typeSelectionChanged(); +} +#endif + void InterfaceFrame::resetInterfaceTreeDisplay() { if ( proxyModel->rowCount() == 0 ) diff --git a/ui/qt/interface_frame.h b/ui/qt/interface_frame.h index 6cc2537ff8..7c2bc579bb 100644 --- a/ui/qt/interface_frame.h +++ b/ui/qt/interface_frame.h @@ -66,6 +66,9 @@ public slots: void updateSelectedInterfaces(); void interfaceListChanged(); void toggleHiddenInterfaces(); +#ifdef HAVE_PCAP_REMOTE + void toggleRemoteInterfaces(); +#endif void getPoints(int idx, PointList *pts); protected: diff --git a/ui/qt/interface_sort_filter_model.cpp b/ui/qt/interface_sort_filter_model.cpp index 9b850e151b..0ea989e1bd 100644 --- a/ui/qt/interface_sort_filter_model.cpp +++ b/ui/qt/interface_sort_filter_model.cpp @@ -46,6 +46,9 @@ void InterfaceSortFilterModel::resetAllFilter() _filterTypes = true; _invertTypeFilter = false; _storeOnChange = false; +#ifdef HAVE_PCAP_REMOTE + _remoteDisplay = true; +#endif /* Adding all columns, to have a default setting */ for ( int col = 0; col < IFTREE_COL_MAX; col++ ) @@ -72,6 +75,48 @@ void InterfaceSortFilterModel::setFilterHidden(bool filter) invalidate(); } +#ifdef HAVE_PCAP_REMOTE +void InterfaceSortFilterModel::setRemoteDisplay(bool remoteDisplay) +{ + _remoteDisplay = remoteDisplay; + + invalidate(); +} + +bool InterfaceSortFilterModel::remoteDisplay() +{ + return _remoteDisplay; +} + +void InterfaceSortFilterModel::toggleRemoteDisplay() +{ + _remoteDisplay = ! _remoteDisplay; + + if ( _storeOnChange ) + { + prefs.gui_interfaces_remote_display = ! _remoteDisplay; + + prefs_main_write(); + } + + invalidateFilter(); + invalidate(); +} + +bool InterfaceSortFilterModel::remoteInterfacesExist() +{ + bool exist = false; + + if ( sourceModel()->rowCount() == 0 ) + return exist; + + for (int idx = 0; idx < sourceModel()->rowCount() && ! exist; idx++) + exist = ((InterfaceTreeModel *)sourceModel())->isRemote(idx); + + return exist; +} +#endif + void InterfaceSortFilterModel::setFilterByType(bool filter, bool invert) { _filterTypes = filter; @@ -98,6 +143,9 @@ void InterfaceSortFilterModel::resetPreferenceData() } _filterHidden = ! prefs.gui_interfaces_show_hidden; +#ifdef HAVE_PCAP_REMOTE + _remoteDisplay = prefs.gui_interfaces_remote_display; +#endif invalidate(); } @@ -243,7 +291,19 @@ bool InterfaceSortFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex return false; if ( _filterTypes && ! isInterfaceTypeShown(type) ) + { +#ifdef HAVE_PCAP_REMOTE + /* Remote interfaces have the if type IF_WIRED, therefore would be filtered, if not explicitly checked here */ + if ( ! _remoteDisplay || ! ((InterfaceTreeModel *)sourceModel())->isRemote(idx) ) +#endif return false; + } + +#ifdef HAVE_PCAP_REMOTE + if ( _remoteDisplay && ! ((InterfaceTreeModel *)sourceModel())->isRemote(idx) ) + return false; +#endif + #endif return true; diff --git a/ui/qt/interface_sort_filter_model.h b/ui/qt/interface_sort_filter_model.h index 7f28eb0151..8d421563aa 100644 --- a/ui/qt/interface_sort_filter_model.h +++ b/ui/qt/interface_sort_filter_model.h @@ -45,6 +45,13 @@ public: int interfacesHidden(); void toggleFilterHidden(); +#ifdef HAVE_PCAP_REMOTE + void setRemoteDisplay(bool remoteDisplay); + bool remoteDisplay(); + void toggleRemoteDisplay(); + bool remoteInterfacesExist(); +#endif + void setInterfaceTypeVisible(int ifType, bool visible); bool isInterfaceTypeShown(int ifType) const; void setFilterByType(bool filter, bool invert = false); @@ -71,6 +78,10 @@ private: bool _invertTypeFilter; bool _storeOnChange; +#ifdef HAVE_PCAP_REMOTE + bool _remoteDisplay; +#endif + QList displayHiddenTypes; QList _columns; diff --git a/ui/qt/interface_tree_model.cpp b/ui/qt/interface_tree_model.cpp index 511bb14cec..d55ff7ffe4 100644 --- a/ui/qt/interface_tree_model.cpp +++ b/ui/qt/interface_tree_model.cpp @@ -319,6 +319,16 @@ QVariant InterfaceTreeModel::getColumnContent(int idx, int col, int role) return InterfaceTreeModel::data(index(idx, col), role); } +#ifdef HAVE_PCAP_REMOTE +bool InterfaceTreeModel::isRemote(int idx) +{ + interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); + if ( device.remote_opts.src_type == CAPTURE_IFREMOTE ) + return true; + return false; +} +#endif + /** * The interface list has changed. global_capture_opts.all_ifaces may have been reloaded * or changed with current data. beginResetModel() and endResetModel() will signalize the diff --git a/ui/qt/interface_tree_model.h b/ui/qt/interface_tree_model.h index 5517308791..33daff9eed 100644 --- a/ui/qt/interface_tree_model.h +++ b/ui/qt/interface_tree_model.h @@ -88,6 +88,10 @@ public: QVariant getColumnContent(int idx, int col, int role = Qt::DisplayRole); +#ifdef HAVE_PCAP_REMOTE + bool isRemote(int idx); +#endif + static const QString DefaultNumericValue; public slots: