Allow to filter interface types

Allow to only use interface types, that are allowed by the implementing applications.
This commit is contained in:
Roland Knall 2022-04-19 09:19:50 +00:00
parent 5c7c723feb
commit 2d48d49524
6 changed files with 82 additions and 4 deletions

View File

@ -123,6 +123,17 @@ get_iface_display_name(const gchar *description, const if_info_t *if_info)
*/
void
scan_local_interfaces(void (*update_cb)(void))
{
scan_local_interfaces_filtered((GList *)0, update_cb);
}
/*
* Fetch the list of local interfaces with capture_interface_list()
* and set the list of "all interfaces" in *capture_opts to include
* those interfaces.
*/
void
scan_local_interfaces_filtered(GList * allowed_types, void (*update_cb)(void))
{
GList *if_entry, *lt_entry, *if_list;
if_info_t *if_info, temp;
@ -202,6 +213,14 @@ scan_local_interfaces(void (*update_cb)(void))
if (strstr(if_info->name, "rpcap:")) {
continue;
}
/* Filter out all interfaces, which are not allowed to be scanned */
if (allowed_types != NULL)
{
if(g_list_find(allowed_types, GUINT_TO_POINTER((guint) if_info->type)) == NULL) {
continue;
}
}
device.name = g_strdup(if_info->name);
device.friendly_name = g_strdup(if_info->friendly_name);
device.vendor_description = g_strdup(if_info->vendor_description);
@ -370,6 +389,12 @@ scan_local_interfaces(void (*update_cb)(void))
found = FALSE;
for (i = 0; i < (int)global_capture_opts.all_ifaces->len; i++) {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
/* Filter out all interfaces, which are not allowed to be scanned */
if (allowed_types != NULL && g_list_find(allowed_types, GINT_TO_POINTER(interface_opts->if_type)) == NULL) {
continue;
}
if (strcmp(device.name, interface_opts->name) == 0) {
found = TRUE;
break;
@ -426,6 +451,17 @@ scan_local_interfaces(void (*update_cb)(void))
*/
void
fill_in_local_interfaces(void(*update_cb)(void))
{
fill_in_local_interfaces_filtered((GList *)0, update_cb);
}
/*
* Get the global interface list. Generate it if we haven't done so
* already. This can be quite time consuming the first time, so
* record how long it takes in the info log.
*/
void
fill_in_local_interfaces_filtered(GList * filter_list, void(*update_cb)(void))
{
gint64 start_time;
double elapsed;
@ -437,7 +473,7 @@ fill_in_local_interfaces(void(*update_cb)(void))
if (!initialized) {
/* do the actual work */
scan_local_interfaces(update_cb);
scan_local_interfaces_filtered(filter_list, update_cb);
initialized = TRUE;
}
/* log how long it took */

View File

@ -24,11 +24,24 @@ extern "C" {
*/
extern void fill_in_local_interfaces(void(*update_cb)(void));
/*
* Get the global interface list. Generate it if we haven't
* done so already.
* @param allowed_types only fill in types provided by the list
*/
extern void fill_in_local_interfaces_filtered(GList * allowed_types, void(*update_cb)(void));
/*
* Update the global interface list.
*/
extern void scan_local_interfaces(void (*update_cb)(void));
/*
* Update the global interface list.
* @param allowed_types only fill in types provided by the list
*/
extern void scan_local_interfaces_filtered(GList * allowed_types, void (*update_cb)(void));
/*
* Hide the interfaces
*/

View File

@ -9,6 +9,10 @@
#include "logwolf_application.h"
#include "extcap.h"
#include "ui/iface_lists.h"
#include "ui/ws_ui_util.h"
LogwolfApplication *lwApp = NULL;
LogwolfApplication::LogwolfApplication(int &argc, char **argv) :
@ -23,3 +27,19 @@ LogwolfApplication::~LogwolfApplication()
{
lwApp = NULL;
}
void LogwolfApplication::refreshLocalInterfaces()
{
extcap_clear_interfaces();
#ifdef HAVE_LIBPCAP
GList * filter_list = NULL;
filter_list = g_list_append(filter_list, GUINT_TO_POINTER((guint) IF_EXTCAP));
scan_local_interfaces_filtered(filter_list, main_window_update);
g_list_free(filter_list);
emit localInterfaceListChanged();
#endif
}

View File

@ -21,6 +21,8 @@ class LogwolfApplication : public MainApplication
public:
explicit LogwolfApplication(int &argc, char **argv);
~LogwolfApplication();
void refreshLocalInterfaces() override;
};
extern LogwolfApplication *lwApp;

View File

@ -817,8 +817,13 @@ int main(int argc, char *qt_argv[])
#endif
splash_update(RA_INTERFACES, NULL, NULL);
if (!global_commandline_info.cf_name && !prefs.capture_no_interface_load)
fill_in_local_interfaces(main_window_update);
if (!global_commandline_info.cf_name && !prefs.capture_no_interface_load) {
/* Allow only extcap interfaces to be found */
GList * filter_list = NULL;
filter_list = g_list_append(filter_list, GUINT_TO_POINTER((guint) IF_EXTCAP));
fill_in_local_interfaces_filtered(filter_list, main_window_update);
g_list_free(filter_list);
}
if (global_commandline_info.list_link_layer_types)
caps_queries |= CAPS_QUERY_LINK_TYPES;

View File

@ -102,7 +102,9 @@ public:
void allSystemsGo();
void emitLocalInterfaceEvent(const char *ifname, int added, int up);
void refreshLocalInterfaces();
virtual void refreshLocalInterfaces();
struct _e_prefs * readConfigurationFiles(bool reset);
QList<recent_item_status *> recentItems() const;
void addRecentItem(const QString filename, qint64 size, bool accessible);