Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 26, 2024
1 parent fb2e865 commit d3673c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
22 changes: 11 additions & 11 deletions cpp/devices/ctapdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool CTapDriver::Init(const param_map &const_params)
// IFF_NO_PI for no extra packet information
ifreq ifr = { };
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy(ifr.ifr_name, DEFAULT_BRIDGE_IF.c_str(), IFNAMSIZ - 1); // NOSONAR Using strncpy is safe
strncpy(ifr.ifr_name, BRIDGE_INTERFACE_NAME.c_str(), IFNAMSIZ - 1); // NOSONAR Using strncpy is safe

if (const int ret = ioctl(tap_fd, TUNSETIFF, (void*)&ifr); ret == -1) {
LogErrno("Can't ioctl TUNSETIFF");
Expand Down Expand Up @@ -150,20 +150,20 @@ bool CTapDriver::Init(const param_map &const_params)
info(BRIDGE_NAME + " already exists");
}

trace(">ip link set " + DEFAULT_BRIDGE_IF + " up");
if (const string error = ip_link(ip_fd, DEFAULT_BRIDGE_IF.c_str(), true); !error.empty()) {
trace(">ip link set " + BRIDGE_INTERFACE_NAME + " up");
if (const string error = ip_link(ip_fd, BRIDGE_INTERFACE_NAME.c_str(), true); !error.empty()) {
return cleanUp(error);
}

trace(">brctl addif " + BRIDGE_NAME + " " + DEFAULT_BRIDGE_IF);
if (const string error = br_setif(br_socket_fd, BRIDGE_NAME, DEFAULT_BRIDGE_IF, true); !error.empty()) {
trace(">brctl addif " + BRIDGE_NAME + " " + BRIDGE_INTERFACE_NAME);
if (const string error = br_setif(br_socket_fd, BRIDGE_NAME, BRIDGE_INTERFACE_NAME, true); !error.empty()) {
return cleanUp(error);
}

close(ip_fd);
close(br_socket_fd);

info("Tap device " + DEFAULT_BRIDGE_IF + " created");
info("Tap device " + BRIDGE_INTERFACE_NAME + " created");

return true;
#endif
Expand All @@ -175,9 +175,9 @@ void CTapDriver::CleanUp() const
if (const int fd = socket(AF_LOCAL, SOCK_STREAM, 0); fd == -1) {
LogErrno("Can't open bridge socket");
} else {
trace(">brctl delif " + BRIDGE_NAME + " " + DEFAULT_BRIDGE_IF);
if (const string error = br_setif(fd, BRIDGE_NAME, DEFAULT_BRIDGE_IF, false); !error.empty()) {
warn("Removing " + DEFAULT_BRIDGE_IF + " from the bridge failed: " + error);
trace(">brctl delif " + BRIDGE_NAME + " " + BRIDGE_INTERFACE_NAME);
if (const string error = br_setif(fd, BRIDGE_NAME, BRIDGE_INTERFACE_NAME, false); !error.empty()) {
warn("Removing " + BRIDGE_INTERFACE_NAME + " from the bridge failed: " + error);
warn("You may need to manually remove the tap device");
}

Expand Down Expand Up @@ -306,8 +306,8 @@ string CTapDriver::AddBridge(int fd)
string CTapDriver::IpLink(bool enable)
{
const int fd = socket(PF_INET, SOCK_DGRAM, 0);
trace(string(">ip link set " + DEFAULT_BRIDGE_IF + " ") + (enable ? "up" : "down"));
const string result = ip_link(fd, DEFAULT_BRIDGE_IF.c_str(), enable);
trace(string(">ip link set " + BRIDGE_INTERFACE_NAME + " ") + (enable ? "up" : "down"));
const string result = ip_link(fd, BRIDGE_INTERFACE_NAME.c_str(), enable);
close(fd);

return result;
Expand Down
4 changes: 1 addition & 3 deletions cpp/devices/ctapdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ using namespace std;

class CTapDriver
{
const inline static string BRIDGE_INTERFACE_NAME = "piscsi0";
const inline static string BRIDGE_NAME = "piscsi_bridge";

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

const inline static string DEFAULT_NETMASK = "255.255.255.0"; // NOSONAR This hardcoded netmask is safe

const inline static string DEFAULT_BRIDGE_IF = "piscsi0";

public:

CTapDriver() = default;
Expand Down

0 comments on commit d3673c9

Please sign in to comment.