Integrate XdpPort more cleanly into port manager

* No ugly #ifdef TURBO
* Turbo ports need to be specified explicitly in drone.ini
* If a port is not a turbo port, fall back to LinuxPort
* Turbo ports set their description as 'Turbo' which shows up in GUI
* Some XdpPort creation/destruction error checks
This commit is contained in:
Srivats P 2021-02-26 20:39:07 +05:30
parent eb2ca12f32
commit c949dc6682
4 changed files with 69 additions and 10 deletions

View File

@ -61,6 +61,7 @@ SOURCES += \
linuxhostdevice.cpp \
linuxport.cpp \
params.cpp \
turbo.cpp \
winhostdevice.cpp \
winpcapport.cpp
SOURCES += myservice.cpp

View File

@ -17,10 +17,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifdef TURBO
#include "xdpport.h" // MUST be included first - see why in xdpport.h
#endif
#include "portmanager.h"
#include "bsdport.h"
@ -28,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "linuxport.h"
#include "pcapport.h"
#include "settings.h"
#include "turbo.h"
#include "winpcapport.h"
#include <QHostAddress>
@ -97,18 +94,17 @@ PortManager::PortManager()
#if defined(Q_OS_WIN32)
port = new WinPcapPort(i, device->name, device->description);
#elif defined(Q_OS_LINUX)
#ifdef TURBO
port = new XdpPort(i, device->name);
#else
port = new LinuxPort(i, device->name);
#endif
if (isTurboPort(device->name))
port = createTurboPort(i, device->name);
else
port = new LinuxPort(i, device->name);
#elif defined(Q_OS_BSD4)
port = new BsdPort(i, device->name);
#else
port = new PcapPort(i, device->name);
#endif
if (!port->isUsable())
if (port && !port->isUsable())
{
qDebug("%s: unable to open %s. Skipping!", __FUNCTION__,
device->name);

33
server/turbo.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
Copyright (C) 2021 Srivats P.
This file is part of "Ostinato"
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include "turbo.h"
bool isTurboPort(const char* device)
{
return false;
}
AbstractPort* createTurboPort(int id, const char* device)
{
return nullptr;
}
#endif

29
server/turbo.h Normal file
View File

@ -0,0 +1,29 @@
/*
Copyright (C) 2021 Srivats P.
This file is part of "Ostinato"
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef _TURBO_H
#define _TURBO_H
class AbstractPort;
bool isTurboPort(const char* device);
AbstractPort* createTurboPort(int id, const char* device);
#endif