diff options
author | Mikael Kanstrup <mikael.kanstrup@sony.com> | 2019-03-07 10:47:41 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-03-08 07:30:04 +0000 |
commit | b08003309b9387f4c839b6c4516da602349af177 (patch) | |
tree | aa33e9a9f459d41baff0e117952391981ae3a095 /ui | |
parent | 28c5b73545d33a9eb5fef591bb908b0c0548236e (diff) |
Remove the periodic interface update in wireless toolbar
The wireless toolbar retrieves the full list of network interfaces
every 1.5 seconds to keep its list of interfaces updated. This
not only adds unnecessary load on the system it also generates
plenty of netlink traffic. When capturing packets on nlmon
interfaces they are flooded with packets generated by Wireshark
itself making it hard to understand the traffic that's really present
on the system.
Remove the periodic interface update and instead listen to network
interface change events and update only when something has changed.
The wireless toolbar need to know all when wireless interfaces are
added/removed, not only whether an interface is 'up' or not so
iface_monitor changes were also necessary.
Bug: 15576
Change-Id: I8fb19fd919dfef1b6b35bf48790b105ecd2b60a8
Reviewed-on: https://code.wireshark.org/review/32350
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/wireless_frame.cpp | 56 | ||||
-rw-r--r-- | ui/qt/wireless_frame.h | 7 | ||||
-rw-r--r-- | ui/qt/wireshark_application.cpp | 8 | ||||
-rw-r--r-- | ui/qt/wireshark_application.h | 2 |
4 files changed, 60 insertions, 13 deletions
diff --git a/ui/qt/wireless_frame.cpp b/ui/qt/wireless_frame.cpp index 38e2e4e727..8efcbdfb35 100644 --- a/ui/qt/wireless_frame.cpp +++ b/ui/qt/wireless_frame.cpp @@ -22,6 +22,7 @@ #include "ui/ws_ui_util.h" #include <wsutil/utf8_entities.h> #include <wsutil/frequency-utils.h> +#include "wireshark_application.h" #include <QProcess> #include <QAbstractItemView> @@ -68,8 +69,9 @@ WirelessFrame::WirelessFrame(QWidget *parent) : ui->fcsFilterFrame->setVisible(ws80211_has_fcs_filter()); - getInterfaceInfo(); - iface_timer_id_ = startTimer(update_interval_); + updateInterfaceList(); + connect(wsApp, &WiresharkApplication::localInterfaceEvent, + this, &WirelessFrame::handleInterfaceEvent); } WirelessFrame::~WirelessFrame() @@ -84,28 +86,60 @@ void WirelessFrame::setCaptureInProgress(bool capture_in_progress) updateWidgets(); } -// Check to see if the ws80211 interface list matches the one in our -// combobox. Rebuild ours if necessary and select the first interface if -// the current selection goes away. + +int WirelessFrame::startTimer(int interval) +{ + if (iface_timer_id_ != -1) { + killTimer(iface_timer_id_); + iface_timer_id_ = -1; + } + iface_timer_id_ = QFrame::startTimer(interval); + return iface_timer_id_; +} + +void WirelessFrame::handleInterfaceEvent(const char *ifname _U_, int added, int up _U_) +{ + if (!added) { + // Unfortunately when an interface removed event is received the network + // interface is still present for a while in the system. + // To overcome this update the interface list after a while. + startTimer(update_interval_); + } else { + updateInterfaceList(); + } +} + void WirelessFrame::timerEvent(QTimerEvent *event) { if (event->timerId() != iface_timer_id_) { QFrame::timerEvent(event); return; } + killTimer(iface_timer_id_); + iface_timer_id_ = -1; + updateInterfaceList(); +} - // Don't interfere with user activity. - if (ui->interfaceComboBox->view()->isVisible() - || ui->channelComboBox->view()->isVisible() - || ui->channelTypeComboBox->view()->isVisible() - || ui->fcsComboBox->view()->isVisible()) return; - +// Check to see if the ws80211 interface list matches the one in our +// combobox. Rebuild ours if necessary and select the first interface if +// the current selection goes away. +void WirelessFrame::updateInterfaceList() +{ ws80211_free_interfaces(interfaces_); interfaces_ = ws80211_find_interfaces(); const QString old_iface = ui->interfaceComboBox->currentText(); guint iface_count = 0; bool list_changed = false; + // Don't interfere with user activity. + if (ui->interfaceComboBox->view()->isVisible() + || ui->channelComboBox->view()->isVisible() + || ui->channelTypeComboBox->view()->isVisible() + || ui->fcsComboBox->view()->isVisible()) { + startTimer(update_interval_); + return; + } + if (interfaces_ && interfaces_->len > 0) { iface_count = interfaces_->len; } diff --git a/ui/qt/wireless_frame.h b/ui/qt/wireless_frame.h index 9e8d0b9487..b8a32bcc49 100644 --- a/ui/qt/wireless_frame.h +++ b/ui/qt/wireless_frame.h @@ -35,11 +35,16 @@ signals: protected: void timerEvent(QTimerEvent *event); +public slots: + void handleInterfaceEvent(const char *ifname, int added, int up); + private: + int startTimer(int interval); void getInterfaceInfo(); void setInterfaceInfo(); int getCenterFrequency(int control_frequency, int bandwidth); int getBandwidthFromChanType(int chan_type); + void updateInterfaceList(); private slots: void updateWidgets(); @@ -55,7 +60,7 @@ private: Ui::WirelessFrame *ui; GArray *interfaces_; bool capture_in_progress_; - int iface_timer_id_; + int iface_timer_id_ = -1; }; #endif // WIRELESS_FRAME_H diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index a00ef6ba0d..278eb64b8b 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -1053,7 +1053,7 @@ void WiresharkApplication::clearRemovedMenuGroupItems() #ifdef HAVE_LIBPCAP static void -iface_mon_event_cb(const char *iface, int up) +iface_mon_event_cb(const char *iface, int added, int up) { int present = 0; guint ifs, j; @@ -1080,6 +1080,7 @@ iface_mon_event_cb(const char *iface, int up) } } + wsApp->emitLocalInterfaceEvent(iface, added, up); if (present != up) { /* * We've been told that there's a new interface or that an old @@ -1105,6 +1106,11 @@ void WiresharkApplication::ifChangeEventsAvailable() #endif } +void WiresharkApplication::emitLocalInterfaceEvent(const char *ifname, int added, int up) +{ + emit localInterfaceEvent(ifname, added, up); +} + void WiresharkApplication::refreshLocalInterfaces() { extcap_clear_interfaces(); diff --git a/ui/qt/wireshark_application.h b/ui/qt/wireshark_application.h index 82e6955c56..b7a7a0ac90 100644 --- a/ui/qt/wireshark_application.h +++ b/ui/qt/wireshark_application.h @@ -93,6 +93,7 @@ public: void clearRemovedMenuGroupItems(); void allSystemsGo(); + void emitLocalInterfaceEvent(const char *ifname, int added, int up); void refreshLocalInterfaces(); struct _e_prefs * readConfigurationFiles(bool reset); QList<recent_item_status *> recentItems() const; @@ -163,6 +164,7 @@ protected: signals: void appInitialized(); + void localInterfaceEvent(const char *ifname, int added, int up); void localInterfaceListChanged(); void openCaptureFile(QString cf_path, QString display_filter, unsigned int type); void openCaptureOptions(); |