Skip to content

Commit

Permalink
Updated parameter handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Sep 5, 2021
1 parent e628bf9 commit 35302ad
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 17 deletions.
15 changes: 10 additions & 5 deletions src/raspberrypi/devices/ctapdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ using namespace std;
// Constructor
//
//---------------------------------------------------------------------------
CTapDriver::CTapDriver(const string& interfaces)
CTapDriver::CTapDriver(const list<string>& params)
{
stringstream s(!interfaces.empty() ? interfaces : DEFAULT_INTERFACES);
string interface;
while (getline(s, interface, ',')) {
this->interfaces.push_back(interface);
if (!params.empty()) {
interfaces = params;
}
else {
stringstream s(DEFAULT_INTERFACES);
string interface;
while (getline(s, interface, ',')) {
interfaces.push_back(interface);
}
}

// Initialization
Expand Down
10 changes: 6 additions & 4 deletions src/raspberrypi/devices/ctapdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

#include <pcap/pcap.h>
#include "filepath.h"
#include <vector>
#include <list>
#include <string>

#ifndef ETH_FRAME_LEN
#define ETH_FRAME_LEN 1514
#endif

using namespace std;

//===========================================================================
//
// Linux Tap Driver
Expand All @@ -32,7 +34,7 @@
class CTapDriver
{
public:
CTapDriver(const std::string&);
CTapDriver(const list<string>&);
~CTapDriver() {};

bool Init();
Expand All @@ -57,7 +59,7 @@ class CTapDriver
pcap_t *m_pcap;
pcap_dumper_t *m_pcap_dumper;

// Prioritized comma-separated list of interfaces to create the bridge for
std::vector<std::string> interfaces;
// Prioritized list of interfaces to create the bridge for
list<string> interfaces;
};

3 changes: 2 additions & 1 deletion src/raspberrypi/devices/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#pragma once

#include <list>
#include <string>

using namespace std;
Expand Down Expand Up @@ -92,7 +93,7 @@ class Device
virtual ~Device() {};

// Override for device specific initializations, to be called after all device properties have been set
virtual bool Init(const string&) { return true; };
virtual bool Init(const list<string>&) { return true; };

virtual bool Dispatch(SCSIDEV *) = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/raspberrypi/devices/scsi_daynaport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ bool SCSIDaynaPort::Dispatch(SCSIDEV *controller)
return Disk::Dispatch(controller);
}

bool SCSIDaynaPort::Init(const string& interfaces)
bool SCSIDaynaPort::Init(const list<string>& params)
{
#ifdef __linux__
// TAP Driver Generation
m_tap = new CTapDriver(interfaces);
m_tap = new CTapDriver(params);
m_bTapEnable = m_tap->Init();
if(!m_bTapEnable){
LOGERROR("Unable to open the TAP interface");
Expand Down
3 changes: 2 additions & 1 deletion src/raspberrypi/devices/scsi_daynaport.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "os.h"
#include "disk.h"
#include "ctapdriver.h"
#include <list>
#include <map>
#include <string>
#include "../rascsi.h"
Expand Down Expand Up @@ -60,7 +61,7 @@ class SCSIDaynaPort: public Disk
SCSIDaynaPort();
~SCSIDaynaPort();

bool Init(const string&) override;
bool Init(const list<string>&) override;
void Open(const Filepath& path) override;

// Commands
Expand Down
4 changes: 2 additions & 2 deletions src/raspberrypi/devices/scsi_host_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ SCSIBR::~SCSIBR()
}
}

bool SCSIBR::Init(const string& interfaces)
bool SCSIBR::Init(const list<string>& params)
{
#ifdef __linux__
// TAP Driver Generation
tap = new CTapDriver(interfaces);
tap = new CTapDriver(params);
m_bTapEnable = tap->Init();

// Generate MAC Address
Expand Down
3 changes: 2 additions & 1 deletion src/raspberrypi/devices/scsi_host_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "os.h"
#include "disk.h"
#include <list>
#include <string>
#include "../rascsi.h"

Expand Down Expand Up @@ -50,7 +51,7 @@ class SCSIBR : public Disk
SCSIBR();
~SCSIBR();

bool Init(const string&) override;
bool Init(const list<string>&) override;
bool Dispatch(SCSIDEV *) override;

// Commands
Expand Down
3 changes: 2 additions & 1 deletion src/raspberrypi/rascsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ bool Attach(int fd, const PbDeviceDefinition& pb_device, Device *map[], bool dry
return true;
}

if (!device->Init(pb_device.params_size() > 0 ? pb_device.params().Get(0) : "")) {
const list<string> params = { pb_device.params().begin(), pb_device.params().end() };
if (!device->Init(params)) {
error << "Initialization of " << device->GetType() << " device, ID " << id << ", unit " << unit << " failed";

delete device;
Expand Down

0 comments on commit 35302ad

Please sign in to comment.