Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cpp/devices/ctapdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ using namespace std;
using namespace piscsi_util;
using namespace network_util;

const string CTapDriver::BRIDGE_NAME = "piscsi_bridge";
// const string CTapDriver::BRIDGE_NAME = "piscsi_bridge";

#if 0
static string br_setif(int br_socket_fd, const string& bridgename, const string& ifname, bool add) {
#ifndef __linux__
return "if_nametoindex: Linux is required";
Expand All @@ -47,6 +48,7 @@ static string br_setif(int br_socket_fd, const string& bridgename, const string&
return "";
#endif
}
#endif

string ip_link(int fd, const char* ifname, bool up) {
#ifndef __linux__
Expand Down Expand Up @@ -113,6 +115,7 @@ bool CTapDriver::Init(const param_map& const_params)
return false;
}

#if 0
const int br_socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (br_socket_fd < 0) {
LogErrno("Can't open bridge socket");
Expand All @@ -121,15 +124,17 @@ bool CTapDriver::Init(const param_map& const_params)
close(ip_fd);
return false;
}
#endif

auto cleanUp = [&] (const string& error) {
LogErrno(error);
close(m_hTAP);
close(ip_fd);
close(br_socket_fd);
// close(br_socket_fd);
return false;
};

#if 0
// Check if the bridge has already been created
// TODO Find an alternative to accessing a file, there is most likely a system call/ioctl
if (access(string("/sys/class/net/" + BRIDGE_NAME).c_str(), F_OK)) {
Expand Down Expand Up @@ -162,18 +167,21 @@ bool CTapDriver::Init(const param_map& const_params)
else {
spdlog::info(BRIDGE_NAME + " is already available");
}
#endif

spdlog::trace(">ip link set piscsi0 up");

if (const string error = ip_link(ip_fd, "piscsi0", true); !error.empty()) {
return cleanUp(error);
}

#if 0
spdlog::trace(">brctl addif " + BRIDGE_NAME + " piscsi0");

if (const string error = br_setif(br_socket_fd, BRIDGE_NAME, "piscsi0", true); !error.empty()) {
return cleanUp(error);
}
#endif

spdlog::trace("Getting the MAC address");

Expand All @@ -186,7 +194,7 @@ bool CTapDriver::Init(const param_map& const_params)
memcpy(m_MacAddr.data(), ifr.ifr_hwaddr.sa_data, m_MacAddr.size());

close(ip_fd);
close(br_socket_fd);
// close(br_socket_fd);

spdlog::info("Tap device " + string(ifr.ifr_name) + " created");

Expand All @@ -197,6 +205,7 @@ bool CTapDriver::Init(const param_map& const_params)
void CTapDriver::CleanUp() const
{
if (m_hTAP != -1) {
#if 0
if (const int br_socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0); br_socket_fd < 0) {
LogErrno("Can't open bridge socket");
} else {
Expand All @@ -207,6 +216,7 @@ void CTapDriver::CleanUp() const
}
close(br_socket_fd);
}
#endif

// Release TAP device
close(m_hTAP);
Expand Down Expand Up @@ -243,6 +253,7 @@ pair<string, string> CTapDriver::ExtractAddressAndMask(const string& s)
return { address, netmask };
}

#if 0
string CTapDriver::SetUpEth0(int socket_fd, const string& bridge_interface)
{
#ifdef __linux__
Expand All @@ -261,7 +272,9 @@ string CTapDriver::SetUpEth0(int socket_fd, const string& bridge_interface)

return "";
}
#endif

#if 0
string CTapDriver::SetUpNonEth0(int socket_fd, int ip_fd, const string& s)
{
#ifdef __linux__
Expand Down Expand Up @@ -301,6 +314,7 @@ string CTapDriver::SetUpNonEth0(int socket_fd, int ip_fd, const string& s)

return "";
}
#endif

string CTapDriver::IpLink(bool enable) const
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/devices/ctapdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace std;

class CTapDriver
{
static const string BRIDGE_NAME;
// static const string BRIDGE_NAME;

const inline static string DEFAULT_IP = "10.10.20.1/24"; //NOSONAR This hardcoded IP address is safe

Expand All @@ -56,7 +56,7 @@ class CTapDriver

private:

static string SetUpEth0(int, const string&);
//static string SetUpEth0(int, const string&);
static string SetUpNonEth0(int, int, const string&);
static pair<string, string> ExtractAddressAndMask(const string&);

Expand Down
2 changes: 2 additions & 0 deletions cpp/devices/scsi_daynaport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ bool SCSIDaynaPort::Init(const param_map& params)
return true;
}

#if 0
void SCSIDaynaPort::CleanUp()
{
tap.CleanUp();
}
#endif

vector<uint8_t> SCSIDaynaPort::InquiryInternal() const
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/scsi_daynaport.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SCSIDaynaPort : public PrimaryDevice
~SCSIDaynaPort() override = default;

bool Init(const param_map&) override;
void CleanUp() override;
// void CleanUp() override;

param_map GetDefaultParams() const override { return tap.GetDefaultParams(); }

Expand Down
2 changes: 2 additions & 0 deletions cpp/devices/scsi_host_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ bool SCSIBR::Init(const param_map& params)
#endif
}

#if 0
void SCSIBR::CleanUp()
{
tap.CleanUp();
}
#endif

vector<uint8_t> SCSIBR::InquiryInternal() const
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/scsi_host_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SCSIBR : public PrimaryDevice
~SCSIBR() override = default;

bool Init(const param_map&) override;
void CleanUp() override;
// void CleanUp() override;

param_map GetDefaultParams() const override { return tap.GetDefaultParams(); }

Expand Down