2020-08-28 14:18:02 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SCSI Target Emulator RaSCSI (*^..^*)
|
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Powered by XM6 TypeG Technology.
|
|
|
|
// Copyright (C) 2016-2020 GIMONS
|
2021-02-07 19:00:48 +00:00
|
|
|
// Copyright (C) akuker
|
2020-08-28 14:18:02 +00:00
|
|
|
//
|
2021-02-07 19:00:48 +00:00
|
|
|
// Imported NetBSD support and some optimisation patches by Rin Okuyama.
|
2020-08-28 14:18:02 +00:00
|
|
|
//
|
|
|
|
// [ TAP Driver ]
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-04-04 21:45:23 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <linux/sockios.h>
|
|
|
|
#endif
|
2021-02-07 19:00:48 +00:00
|
|
|
#include <zlib.h> // For crc32()
|
2020-08-28 14:18:02 +00:00
|
|
|
#include "os.h"
|
|
|
|
#include "xm6.h"
|
|
|
|
#include "ctapdriver.h"
|
2021-02-07 19:00:48 +00:00
|
|
|
#include "log.h"
|
2021-08-09 23:56:13 +00:00
|
|
|
#include "exceptions.h"
|
2021-02-07 22:46:59 +00:00
|
|
|
|
2020-08-28 14:18:02 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-12-28 02:13:21 +00:00
|
|
|
// Constructor
|
2020-08-28 14:18:02 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
CTapDriver::CTapDriver()
|
|
|
|
{
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("%s",__PRETTY_FUNCTION__);
|
2020-12-28 02:13:21 +00:00
|
|
|
// Initialization
|
2021-07-05 00:50:24 +00:00
|
|
|
m_bTxValid = FALSE;
|
2020-08-28 14:18:02 +00:00
|
|
|
m_hTAP = -1;
|
|
|
|
memset(&m_MacAddr, 0, sizeof(m_MacAddr));
|
2021-04-03 19:02:20 +00:00
|
|
|
m_pcap = NULL;
|
|
|
|
m_pcap_dumper = NULL;
|
2020-08-28 14:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-12-28 02:13:21 +00:00
|
|
|
// Initialization
|
2020-08-28 14:18:02 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#ifdef __linux__
|
2021-04-04 21:45:23 +00:00
|
|
|
|
|
|
|
static BOOL br_setif(int br_socket_fd, const char* bridgename, const char* ifname, BOOL add) {
|
|
|
|
struct ifreq ifr;
|
|
|
|
ifr.ifr_ifindex = if_nametoindex(ifname);
|
|
|
|
if (ifr.ifr_ifindex == 0) {
|
|
|
|
LOGERROR("Error: can't if_nametoindex. Errno: %d %s", errno, strerror(errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
strncpy(ifr.ifr_name, bridgename, IFNAMSIZ);
|
|
|
|
if (ioctl(br_socket_fd, add ? SIOCBRADDIF : SIOCBRDELIF, &ifr) < 0) {
|
|
|
|
LOGERROR("Error: can't ioctl %s. Errno: %d %s", add ? "SIOCBRADDIF" : "SIOCBRDELIF", errno, strerror(errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL ip_link(int fd, const char* ifname, BOOL up) {
|
|
|
|
struct ifreq ifr;
|
2021-04-05 17:14:51 +00:00
|
|
|
strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1); // Need to save room for null terminator
|
Refactoring, device handling extensions, additional settings, improved error handling, 64 bit OS support, fixed issues (#184)
* Device type unification, support of removable media
* Added support for .hdr extension
* Removable flag cleanup
* Manpage update
* Enriched PbOperation with PbDevice
* Added file size to PbImageFile
* Added device list support
* Set image_file
* Make remote interface more robust by ignoring SIGPIPE
* Return status only once
* Fixed typo
* Error handling update
* When starting rascsi parse everything before attaching devices
* Added dry run mode
* Comment update
* Updated logging
* Added Device base class, Disk class inherits from it
* Renaming
* Use vectors for controllers and disks, as preparation for using maps
* Updated file support handling
* Comment update
* DaynaPort and Bridge inherit from Device instead of Disk
* ProcessCmd() now works with devices instead of disks
* Renaming
* Added DeviceFactory
* Improved factory
* Comment update
* protected disk_t
* Code cleanup, added translations
* Device name can be set for rascsi
* rasctl can set device name
* Manpage update
* Manpage update
* Formatting update
* Check for missing name
* Initialize fd
* Initialize type
* Fixed string length issue
* Updated capacity formatting
* Fixed typo
* Split PbDevice into device and device definition
* Added TODO
* Renaming
* Renaming
* Device types can be explicitly specified with -t (no FILE:TYPE syntax anymore)
* Fixed compile-time issue
* Removed unused Append mode, updated read-only handling
* Type handling and manpage update
* Cleanup
* rasctl parser cleanup
* Review
* Constructor update
* Added .hdr (SCRM) support to web interface, tested web interface
* Default folder can be set remotely
* Removed deprecated operation
* DETACH supports all parameters in order to detach all devices
* include cleanup
* Logging should not depend on NDEBUG, for RaSCSI it is not peformance-critical
* INFO is default log level
* Exception renaming
* Updated GetPaddedName()
* Inheritance update
* Added BlockDevice class
* Removed unused code
* Updated typedefs
* Revert "Updated typedefs"
This reverts commit 546b46215a4d9b65067a11698e59ab1123cc6d64.
* Removed unused code
* Fixed warnign
* Use standard C++ integer types, use streams to resolve printf data type issues
* Added TODOs
* Added TODO
* Renaming
* Added TODO
* Added TODO
* Improved dry-run
* Code cleanup
* Updated handling of unknown options, code review and cleanup
* Manpage update
* Added PrimaryDevice
* Include cleanup
* Added pure virtual methods
* Comment updates
* Split rasutil
* Replaced some occurrences of BOOL
* Removed obsolete RASCSI definition in xm6.h
* Removed unused code, updated TODOs, replaced BOOL
* Added capacity check (issue #192)
* Fixed (most likely) https://github.com/akuker/RASCSI/issues/191
* Fixed wrong error messages
* For root the default image folder is /home/pi/images, updated error handling
* Dynaport code review
* Improved error handling
* Implemented READ CAPACITY(16)
* Comment update
* Commands can be 16 bytes long
* Implemented READ/WRITE/VERIFY(16)
* Comment update
* Renamed method to reflect the name of the respective SCSI command
* Do not created devices during dryRun
* Fixed padding of SCSIHD_APPLE vendor and product
* Initial implementation
* Updated ReportLuns
* Byte count update
* Fixed typo
* Finalized REPORT LUNS
* Removed TODO
* Updated TODO
* TODO update
* Updated device factory
* Comment update
* 64 bit update, tested on Ubuntu 64 bit system
* Removed assertion
* SCSI hard disks always have Apple specific mode pages (resolves issue #193)
* Error messsage update, 64 bit cleanup
* Reduced streams usage
* Updated handling of device flags
* MOs are protectable
* Removed duplicate error code handling
* Removed duplicate code
* Fixed CmdReadToc buffer overflow (https://github.com/akuker/RASCSI/issues/194)
* Added naive implementation of GET EVENT STATUS NOTIFICATION to avoid wranings
* HD must set removable device bit if the media is removable
* Removed duplicate logging
* Updated daynaport additional length
* Removed broken daynaport REQUEST SENSE. Successfully tested with my Mac.
* EnableInterface should not always return TRUE
* Updated Inquiry
* Updated LUN handling
* Replaced incorrect free by delete
* Updated comments and write-protection handling
* Made default HD name consistent
* STATUS_NOERROR is default
* Fixed Eject
* More eject handling updates
* Manpage updates
* Logging update
* Changed debug level
* Logging update
* Log capacity of all media types
* Logging update
* Encapsulated disk.blocks
* Encapsulated sector size
* Added overrides
* Added more overrides
* Fixed error message
* Fixed typos
* Fixed logging
* Added logging
* Use PrimaryDevice when calling Inquiry
* Comment update
* Changed default buffer size for testing
* Reverted last change
* Removed debug output
* De-inlined methods because optimized code did not work with them inlined
* Web interface can attach Daynaport again
* Improved handling of read-only hard disks
* Fixed issue with "all" semantics of DETACH
* rasctl supports adding removable media devices without providing a filename
* Removed unused flag in PbDeviceDefinition
* Updated rasctl output for ecjected media (resolves issue #199)
* Validate default folder name when changing default folder
2021-08-21 21:45:30 +00:00
|
|
|
int err = ioctl(fd, SIOCGIFFLAGS, &ifr);
|
2021-04-04 21:45:23 +00:00
|
|
|
if (err) {
|
|
|
|
LOGERROR("Error: can't ioctl SIOCGIFFLAGS. Errno: %d %s", errno, strerror(errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ifr.ifr_flags &= ~IFF_UP;
|
|
|
|
if (up) {
|
|
|
|
ifr.ifr_flags |= IFF_UP;
|
|
|
|
}
|
|
|
|
err = ioctl(fd, SIOCSIFFLAGS, &ifr);
|
|
|
|
if (err) {
|
|
|
|
LOGERROR("Error: can't ioctl SIOCSIFFLAGS. Errno: %d %s", errno, strerror(errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-07-26 18:33:36 +00:00
|
|
|
BOOL CTapDriver::Init()
|
2020-08-28 14:18:02 +00:00
|
|
|
{
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("%s",__PRETTY_FUNCTION__);
|
|
|
|
|
2020-08-28 14:18:02 +00:00
|
|
|
char dev[IFNAMSIZ] = "ras0";
|
|
|
|
struct ifreq ifr;
|
|
|
|
int ret;
|
|
|
|
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("Opening Tap device");
|
2020-12-28 02:13:21 +00:00
|
|
|
// TAP device initilization
|
2020-08-28 14:18:02 +00:00
|
|
|
if ((m_hTAP = open("/dev/net/tun", O_RDWR)) < 0) {
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGERROR("Error: can't open tun. Errno: %d %s", errno, strerror(errno));
|
2020-08-28 14:18:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("Opened tap device %d",m_hTAP);
|
2020-08-28 14:18:02 +00:00
|
|
|
|
2021-02-07 19:00:48 +00:00
|
|
|
|
2020-08-28 14:18:02 +00:00
|
|
|
// IFF_NO_PI for no extra packet information
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
|
|
|
|
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("Going to open %s", ifr.ifr_name);
|
2020-08-28 14:18:02 +00:00
|
|
|
if ((ret = ioctl(m_hTAP, TUNSETIFF, (void *)&ifr)) < 0) {
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGERROR("Error: can't ioctl TUNSETIFF. Errno: %d %s", errno, strerror(errno));
|
2020-08-28 14:18:02 +00:00
|
|
|
close(m_hTAP);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("return code from ioctl was %d", ret);
|
2020-08-28 14:18:02 +00:00
|
|
|
|
2021-04-04 21:45:23 +00:00
|
|
|
int ip_fd;
|
|
|
|
if ((ip_fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
|
|
|
|
LOGERROR("Error: can't open ip socket. Errno: %d %s", errno, strerror(errno));
|
|
|
|
close(m_hTAP);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-02-07 22:46:59 +00:00
|
|
|
|
2021-04-04 21:45:23 +00:00
|
|
|
int br_socket_fd = -1;
|
|
|
|
if ((br_socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
|
|
|
|
LOGERROR("Error: can't open bridge socket. Errno: %d %s", errno, strerror(errno));
|
|
|
|
close(m_hTAP);
|
|
|
|
close(ip_fd);
|
|
|
|
return FALSE;
|
2021-02-07 22:46:59 +00:00
|
|
|
}
|
2021-04-04 21:45:23 +00:00
|
|
|
|
|
|
|
LOGTRACE("Going to see if the bridge is created");
|
2021-02-07 22:46:59 +00:00
|
|
|
|
|
|
|
// Check if the bridge is already created
|
2021-04-04 21:45:23 +00:00
|
|
|
if (access("/sys/class/net/rascsi_bridge", F_OK) != 0) {
|
2021-02-07 22:46:59 +00:00
|
|
|
LOGINFO("Creating the rascsi_bridge...");
|
|
|
|
LOGDEBUG("brctl addbr rascsi_bridge");
|
2021-04-04 21:45:23 +00:00
|
|
|
if ((ret = ioctl(br_socket_fd, SIOCBRADDBR, "rascsi_bridge")) < 0) {
|
|
|
|
LOGERROR("Error: can't ioctl SIOCBRADDBR. Errno: %d %s", errno, strerror(errno));
|
|
|
|
close(m_hTAP);
|
|
|
|
close(ip_fd);
|
|
|
|
close(br_socket_fd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-02-07 22:46:59 +00:00
|
|
|
LOGDEBUG("brctl addif rascsi_bridge eth0");
|
2021-04-04 21:45:23 +00:00
|
|
|
if (!br_setif(br_socket_fd, "rascsi_bridge", "eth0", TRUE)) {
|
|
|
|
close(m_hTAP);
|
|
|
|
close(ip_fd);
|
|
|
|
close(br_socket_fd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-02-07 22:46:59 +00:00
|
|
|
LOGDEBUG("ip link set dev rascsi_bridge up");
|
2021-04-04 21:45:23 +00:00
|
|
|
if (!ip_link(ip_fd, "rascsi_bridge", TRUE)) {
|
|
|
|
close(m_hTAP);
|
|
|
|
close(ip_fd);
|
|
|
|
close(br_socket_fd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-02-07 22:46:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOGINFO("Note: rascsi_bridge already created");
|
|
|
|
}
|
|
|
|
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGDEBUG("ip link set ras0 up");
|
2021-04-04 21:45:23 +00:00
|
|
|
if (!ip_link(ip_fd, "ras0", TRUE)) {
|
|
|
|
close(m_hTAP);
|
|
|
|
close(ip_fd);
|
|
|
|
close(br_socket_fd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGDEBUG("brctl addif rascsi_bridge ras0");
|
2021-04-04 21:45:23 +00:00
|
|
|
if (!br_setif(br_socket_fd, "rascsi_bridge", "ras0", TRUE)) {
|
|
|
|
close(m_hTAP);
|
|
|
|
close(ip_fd);
|
|
|
|
close(br_socket_fd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Get MAC address
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("Getting the MAC address");
|
2020-08-28 14:18:02 +00:00
|
|
|
ifr.ifr_addr.sa_family = AF_INET;
|
|
|
|
if ((ret = ioctl(m_hTAP, SIOCGIFHWADDR, &ifr)) < 0) {
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGERROR("Error: can't ioctl SIOCGIFHWADDR. Errno: %d %s", errno, strerror(errno));
|
2020-08-28 14:18:02 +00:00
|
|
|
close(m_hTAP);
|
2021-04-04 21:45:23 +00:00
|
|
|
close(ip_fd);
|
|
|
|
close(br_socket_fd);
|
2020-08-28 14:18:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("got the mac");
|
2020-08-28 14:18:02 +00:00
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Save MAC address
|
2020-08-28 14:18:02 +00:00
|
|
|
memcpy(m_MacAddr, ifr.ifr_hwaddr.sa_data, sizeof(m_MacAddr));
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGINFO("Tap device %s created", ifr.ifr_name);
|
2021-04-04 21:45:23 +00:00
|
|
|
|
|
|
|
close(ip_fd);
|
|
|
|
close(br_socket_fd);
|
|
|
|
|
2020-08-28 14:18:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif // __linux__
|
|
|
|
|
|
|
|
#ifdef __NetBSD__
|
2021-07-26 18:33:36 +00:00
|
|
|
BOOL CTapDriver::Init()
|
2020-08-28 14:18:02 +00:00
|
|
|
{
|
|
|
|
struct ifreq ifr;
|
|
|
|
struct ifaddrs *ifa, *a;
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// TAP Device Initialization
|
2020-08-28 14:18:02 +00:00
|
|
|
if ((m_hTAP = open("/dev/tap", O_RDWR)) < 0) {
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGERROR("Error: can't open tap. Errno: %d %s", errno, strerror(errno));
|
2020-08-28 14:18:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Get device name
|
2020-08-28 14:18:02 +00:00
|
|
|
if (ioctl(m_hTAP, TAPGIFNAME, (void *)&ifr) < 0) {
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGERROR("Error: can't ioctl TAPGIFNAME. Errno: %d %s", errno, strerror(errno));
|
2020-08-28 14:18:02 +00:00
|
|
|
close(m_hTAP);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Get MAC address
|
2020-08-28 14:18:02 +00:00
|
|
|
if (getifaddrs(&ifa) == -1) {
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGERROR("Error: can't getifaddrs. Errno: %d %s", errno, strerror(errno));
|
2020-08-28 14:18:02 +00:00
|
|
|
close(m_hTAP);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
for (a = ifa; a != NULL; a = a->ifa_next)
|
|
|
|
if (strcmp(ifr.ifr_name, a->ifa_name) == 0 &&
|
|
|
|
a->ifa_addr->sa_family == AF_LINK)
|
|
|
|
break;
|
|
|
|
if (a == NULL) {
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGERROR("Error: can't get MAC addressErrno: %d %s", errno, strerror(errno));
|
2020-08-28 14:18:02 +00:00
|
|
|
close(m_hTAP);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Save MAC address
|
2020-08-28 14:18:02 +00:00
|
|
|
memcpy(m_MacAddr, LLADDR((struct sockaddr_dl *)a->ifa_addr),
|
|
|
|
sizeof(m_MacAddr));
|
|
|
|
freeifaddrs(ifa);
|
|
|
|
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGINFO("Tap device : %s\n", ifr.ifr_name);
|
2020-08-28 14:18:02 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif // __NetBSD__
|
|
|
|
|
2021-08-09 23:56:13 +00:00
|
|
|
void CTapDriver::OpenDump(const Filepath& path) {
|
2021-04-03 19:02:20 +00:00
|
|
|
if (m_pcap == NULL) {
|
|
|
|
m_pcap = pcap_open_dead(DLT_EN10MB, 65535);
|
|
|
|
}
|
|
|
|
if (m_pcap_dumper != NULL) {
|
|
|
|
pcap_dump_close(m_pcap_dumper);
|
|
|
|
}
|
|
|
|
m_pcap_dumper = pcap_dump_open(m_pcap, path.GetPath());
|
|
|
|
if (m_pcap_dumper == NULL) {
|
|
|
|
LOGERROR("Error: can't open pcap file: %s", pcap_geterr(m_pcap));
|
Refactoring, device handling extensions, additional settings, improved error handling, 64 bit OS support, fixed issues (#184)
* Device type unification, support of removable media
* Added support for .hdr extension
* Removable flag cleanup
* Manpage update
* Enriched PbOperation with PbDevice
* Added file size to PbImageFile
* Added device list support
* Set image_file
* Make remote interface more robust by ignoring SIGPIPE
* Return status only once
* Fixed typo
* Error handling update
* When starting rascsi parse everything before attaching devices
* Added dry run mode
* Comment update
* Updated logging
* Added Device base class, Disk class inherits from it
* Renaming
* Use vectors for controllers and disks, as preparation for using maps
* Updated file support handling
* Comment update
* DaynaPort and Bridge inherit from Device instead of Disk
* ProcessCmd() now works with devices instead of disks
* Renaming
* Added DeviceFactory
* Improved factory
* Comment update
* protected disk_t
* Code cleanup, added translations
* Device name can be set for rascsi
* rasctl can set device name
* Manpage update
* Manpage update
* Formatting update
* Check for missing name
* Initialize fd
* Initialize type
* Fixed string length issue
* Updated capacity formatting
* Fixed typo
* Split PbDevice into device and device definition
* Added TODO
* Renaming
* Renaming
* Device types can be explicitly specified with -t (no FILE:TYPE syntax anymore)
* Fixed compile-time issue
* Removed unused Append mode, updated read-only handling
* Type handling and manpage update
* Cleanup
* rasctl parser cleanup
* Review
* Constructor update
* Added .hdr (SCRM) support to web interface, tested web interface
* Default folder can be set remotely
* Removed deprecated operation
* DETACH supports all parameters in order to detach all devices
* include cleanup
* Logging should not depend on NDEBUG, for RaSCSI it is not peformance-critical
* INFO is default log level
* Exception renaming
* Updated GetPaddedName()
* Inheritance update
* Added BlockDevice class
* Removed unused code
* Updated typedefs
* Revert "Updated typedefs"
This reverts commit 546b46215a4d9b65067a11698e59ab1123cc6d64.
* Removed unused code
* Fixed warnign
* Use standard C++ integer types, use streams to resolve printf data type issues
* Added TODOs
* Added TODO
* Renaming
* Added TODO
* Added TODO
* Improved dry-run
* Code cleanup
* Updated handling of unknown options, code review and cleanup
* Manpage update
* Added PrimaryDevice
* Include cleanup
* Added pure virtual methods
* Comment updates
* Split rasutil
* Replaced some occurrences of BOOL
* Removed obsolete RASCSI definition in xm6.h
* Removed unused code, updated TODOs, replaced BOOL
* Added capacity check (issue #192)
* Fixed (most likely) https://github.com/akuker/RASCSI/issues/191
* Fixed wrong error messages
* For root the default image folder is /home/pi/images, updated error handling
* Dynaport code review
* Improved error handling
* Implemented READ CAPACITY(16)
* Comment update
* Commands can be 16 bytes long
* Implemented READ/WRITE/VERIFY(16)
* Comment update
* Renamed method to reflect the name of the respective SCSI command
* Do not created devices during dryRun
* Fixed padding of SCSIHD_APPLE vendor and product
* Initial implementation
* Updated ReportLuns
* Byte count update
* Fixed typo
* Finalized REPORT LUNS
* Removed TODO
* Updated TODO
* TODO update
* Updated device factory
* Comment update
* 64 bit update, tested on Ubuntu 64 bit system
* Removed assertion
* SCSI hard disks always have Apple specific mode pages (resolves issue #193)
* Error messsage update, 64 bit cleanup
* Reduced streams usage
* Updated handling of device flags
* MOs are protectable
* Removed duplicate error code handling
* Removed duplicate code
* Fixed CmdReadToc buffer overflow (https://github.com/akuker/RASCSI/issues/194)
* Added naive implementation of GET EVENT STATUS NOTIFICATION to avoid wranings
* HD must set removable device bit if the media is removable
* Removed duplicate logging
* Updated daynaport additional length
* Removed broken daynaport REQUEST SENSE. Successfully tested with my Mac.
* EnableInterface should not always return TRUE
* Updated Inquiry
* Updated LUN handling
* Replaced incorrect free by delete
* Updated comments and write-protection handling
* Made default HD name consistent
* STATUS_NOERROR is default
* Fixed Eject
* More eject handling updates
* Manpage updates
* Logging update
* Changed debug level
* Logging update
* Log capacity of all media types
* Logging update
* Encapsulated disk.blocks
* Encapsulated sector size
* Added overrides
* Added more overrides
* Fixed error message
* Fixed typos
* Fixed logging
* Added logging
* Use PrimaryDevice when calling Inquiry
* Comment update
* Changed default buffer size for testing
* Reverted last change
* Removed debug output
* De-inlined methods because optimized code did not work with them inlined
* Web interface can attach Daynaport again
* Improved handling of read-only hard disks
* Fixed issue with "all" semantics of DETACH
* rasctl supports adding removable media devices without providing a filename
* Removed unused flag in PbDeviceDefinition
* Updated rasctl output for ecjected media (resolves issue #199)
* Validate default folder name when changing default folder
2021-08-21 21:45:30 +00:00
|
|
|
throw io_exception("Can't open pcap file");
|
2021-04-03 19:02:20 +00:00
|
|
|
}
|
2021-08-09 23:56:13 +00:00
|
|
|
|
2021-04-05 17:14:51 +00:00
|
|
|
LOGTRACE("%s Opened %s for dumping", __PRETTY_FUNCTION__, path.GetPath());
|
2021-04-03 19:02:20 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 14:18:02 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-12-28 02:13:21 +00:00
|
|
|
// Cleanup
|
2020-08-28 14:18:02 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2021-07-26 18:33:36 +00:00
|
|
|
void CTapDriver::Cleanup()
|
2020-08-28 14:18:02 +00:00
|
|
|
{
|
2021-04-04 21:45:23 +00:00
|
|
|
int br_socket_fd = -1;
|
|
|
|
if ((br_socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
|
|
|
|
LOGERROR("Error: can't open bridge socket. Errno: %d %s", errno, strerror(errno));
|
|
|
|
} else {
|
|
|
|
LOGDEBUG("brctl delif rascsi_bridge ras0");
|
|
|
|
if (!br_setif(br_socket_fd, "rascsi_bridge", "ras0", FALSE)) {
|
|
|
|
LOGWARN("Warning: Removing ras0 from the bridge failed.");
|
|
|
|
LOGWARN("You may need to manually remove the ras0 tap device from the bridge");
|
|
|
|
}
|
|
|
|
close(br_socket_fd);
|
2021-02-07 19:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Release TAP defice
|
2020-08-28 14:18:02 +00:00
|
|
|
if (m_hTAP != -1) {
|
|
|
|
close(m_hTAP);
|
|
|
|
m_hTAP = -1;
|
|
|
|
}
|
2021-04-03 19:02:20 +00:00
|
|
|
|
|
|
|
if (m_pcap_dumper != NULL) {
|
|
|
|
pcap_dump_close(m_pcap_dumper);
|
|
|
|
m_pcap_dumper = NULL;
|
|
|
|
}
|
|
|
|
if (m_pcap != NULL) {
|
|
|
|
pcap_close(m_pcap);
|
|
|
|
}
|
2021-01-27 21:16:52 +00:00
|
|
|
}
|
|
|
|
|
2021-02-07 19:00:48 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Enable
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
Refactoring, device handling extensions, additional settings, improved error handling, 64 bit OS support, fixed issues (#184)
* Device type unification, support of removable media
* Added support for .hdr extension
* Removable flag cleanup
* Manpage update
* Enriched PbOperation with PbDevice
* Added file size to PbImageFile
* Added device list support
* Set image_file
* Make remote interface more robust by ignoring SIGPIPE
* Return status only once
* Fixed typo
* Error handling update
* When starting rascsi parse everything before attaching devices
* Added dry run mode
* Comment update
* Updated logging
* Added Device base class, Disk class inherits from it
* Renaming
* Use vectors for controllers and disks, as preparation for using maps
* Updated file support handling
* Comment update
* DaynaPort and Bridge inherit from Device instead of Disk
* ProcessCmd() now works with devices instead of disks
* Renaming
* Added DeviceFactory
* Improved factory
* Comment update
* protected disk_t
* Code cleanup, added translations
* Device name can be set for rascsi
* rasctl can set device name
* Manpage update
* Manpage update
* Formatting update
* Check for missing name
* Initialize fd
* Initialize type
* Fixed string length issue
* Updated capacity formatting
* Fixed typo
* Split PbDevice into device and device definition
* Added TODO
* Renaming
* Renaming
* Device types can be explicitly specified with -t (no FILE:TYPE syntax anymore)
* Fixed compile-time issue
* Removed unused Append mode, updated read-only handling
* Type handling and manpage update
* Cleanup
* rasctl parser cleanup
* Review
* Constructor update
* Added .hdr (SCRM) support to web interface, tested web interface
* Default folder can be set remotely
* Removed deprecated operation
* DETACH supports all parameters in order to detach all devices
* include cleanup
* Logging should not depend on NDEBUG, for RaSCSI it is not peformance-critical
* INFO is default log level
* Exception renaming
* Updated GetPaddedName()
* Inheritance update
* Added BlockDevice class
* Removed unused code
* Updated typedefs
* Revert "Updated typedefs"
This reverts commit 546b46215a4d9b65067a11698e59ab1123cc6d64.
* Removed unused code
* Fixed warnign
* Use standard C++ integer types, use streams to resolve printf data type issues
* Added TODOs
* Added TODO
* Renaming
* Added TODO
* Added TODO
* Improved dry-run
* Code cleanup
* Updated handling of unknown options, code review and cleanup
* Manpage update
* Added PrimaryDevice
* Include cleanup
* Added pure virtual methods
* Comment updates
* Split rasutil
* Replaced some occurrences of BOOL
* Removed obsolete RASCSI definition in xm6.h
* Removed unused code, updated TODOs, replaced BOOL
* Added capacity check (issue #192)
* Fixed (most likely) https://github.com/akuker/RASCSI/issues/191
* Fixed wrong error messages
* For root the default image folder is /home/pi/images, updated error handling
* Dynaport code review
* Improved error handling
* Implemented READ CAPACITY(16)
* Comment update
* Commands can be 16 bytes long
* Implemented READ/WRITE/VERIFY(16)
* Comment update
* Renamed method to reflect the name of the respective SCSI command
* Do not created devices during dryRun
* Fixed padding of SCSIHD_APPLE vendor and product
* Initial implementation
* Updated ReportLuns
* Byte count update
* Fixed typo
* Finalized REPORT LUNS
* Removed TODO
* Updated TODO
* TODO update
* Updated device factory
* Comment update
* 64 bit update, tested on Ubuntu 64 bit system
* Removed assertion
* SCSI hard disks always have Apple specific mode pages (resolves issue #193)
* Error messsage update, 64 bit cleanup
* Reduced streams usage
* Updated handling of device flags
* MOs are protectable
* Removed duplicate error code handling
* Removed duplicate code
* Fixed CmdReadToc buffer overflow (https://github.com/akuker/RASCSI/issues/194)
* Added naive implementation of GET EVENT STATUS NOTIFICATION to avoid wranings
* HD must set removable device bit if the media is removable
* Removed duplicate logging
* Updated daynaport additional length
* Removed broken daynaport REQUEST SENSE. Successfully tested with my Mac.
* EnableInterface should not always return TRUE
* Updated Inquiry
* Updated LUN handling
* Replaced incorrect free by delete
* Updated comments and write-protection handling
* Made default HD name consistent
* STATUS_NOERROR is default
* Fixed Eject
* More eject handling updates
* Manpage updates
* Logging update
* Changed debug level
* Logging update
* Log capacity of all media types
* Logging update
* Encapsulated disk.blocks
* Encapsulated sector size
* Added overrides
* Added more overrides
* Fixed error message
* Fixed typos
* Fixed logging
* Added logging
* Use PrimaryDevice when calling Inquiry
* Comment update
* Changed default buffer size for testing
* Reverted last change
* Removed debug output
* De-inlined methods because optimized code did not work with them inlined
* Web interface can attach Daynaport again
* Improved handling of read-only hard disks
* Fixed issue with "all" semantics of DETACH
* rasctl supports adding removable media devices without providing a filename
* Removed unused flag in PbDeviceDefinition
* Updated rasctl output for ecjected media (resolves issue #199)
* Validate default folder name when changing default folder
2021-08-21 21:45:30 +00:00
|
|
|
bool CTapDriver::Enable(){
|
2021-04-04 21:45:23 +00:00
|
|
|
int fd = socket(PF_INET, SOCK_DGRAM, 0);
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGDEBUG("%s: ip link set ras0 up", __PRETTY_FUNCTION__);
|
Refactoring, device handling extensions, additional settings, improved error handling, 64 bit OS support, fixed issues (#184)
* Device type unification, support of removable media
* Added support for .hdr extension
* Removable flag cleanup
* Manpage update
* Enriched PbOperation with PbDevice
* Added file size to PbImageFile
* Added device list support
* Set image_file
* Make remote interface more robust by ignoring SIGPIPE
* Return status only once
* Fixed typo
* Error handling update
* When starting rascsi parse everything before attaching devices
* Added dry run mode
* Comment update
* Updated logging
* Added Device base class, Disk class inherits from it
* Renaming
* Use vectors for controllers and disks, as preparation for using maps
* Updated file support handling
* Comment update
* DaynaPort and Bridge inherit from Device instead of Disk
* ProcessCmd() now works with devices instead of disks
* Renaming
* Added DeviceFactory
* Improved factory
* Comment update
* protected disk_t
* Code cleanup, added translations
* Device name can be set for rascsi
* rasctl can set device name
* Manpage update
* Manpage update
* Formatting update
* Check for missing name
* Initialize fd
* Initialize type
* Fixed string length issue
* Updated capacity formatting
* Fixed typo
* Split PbDevice into device and device definition
* Added TODO
* Renaming
* Renaming
* Device types can be explicitly specified with -t (no FILE:TYPE syntax anymore)
* Fixed compile-time issue
* Removed unused Append mode, updated read-only handling
* Type handling and manpage update
* Cleanup
* rasctl parser cleanup
* Review
* Constructor update
* Added .hdr (SCRM) support to web interface, tested web interface
* Default folder can be set remotely
* Removed deprecated operation
* DETACH supports all parameters in order to detach all devices
* include cleanup
* Logging should not depend on NDEBUG, for RaSCSI it is not peformance-critical
* INFO is default log level
* Exception renaming
* Updated GetPaddedName()
* Inheritance update
* Added BlockDevice class
* Removed unused code
* Updated typedefs
* Revert "Updated typedefs"
This reverts commit 546b46215a4d9b65067a11698e59ab1123cc6d64.
* Removed unused code
* Fixed warnign
* Use standard C++ integer types, use streams to resolve printf data type issues
* Added TODOs
* Added TODO
* Renaming
* Added TODO
* Added TODO
* Improved dry-run
* Code cleanup
* Updated handling of unknown options, code review and cleanup
* Manpage update
* Added PrimaryDevice
* Include cleanup
* Added pure virtual methods
* Comment updates
* Split rasutil
* Replaced some occurrences of BOOL
* Removed obsolete RASCSI definition in xm6.h
* Removed unused code, updated TODOs, replaced BOOL
* Added capacity check (issue #192)
* Fixed (most likely) https://github.com/akuker/RASCSI/issues/191
* Fixed wrong error messages
* For root the default image folder is /home/pi/images, updated error handling
* Dynaport code review
* Improved error handling
* Implemented READ CAPACITY(16)
* Comment update
* Commands can be 16 bytes long
* Implemented READ/WRITE/VERIFY(16)
* Comment update
* Renamed method to reflect the name of the respective SCSI command
* Do not created devices during dryRun
* Fixed padding of SCSIHD_APPLE vendor and product
* Initial implementation
* Updated ReportLuns
* Byte count update
* Fixed typo
* Finalized REPORT LUNS
* Removed TODO
* Updated TODO
* TODO update
* Updated device factory
* Comment update
* 64 bit update, tested on Ubuntu 64 bit system
* Removed assertion
* SCSI hard disks always have Apple specific mode pages (resolves issue #193)
* Error messsage update, 64 bit cleanup
* Reduced streams usage
* Updated handling of device flags
* MOs are protectable
* Removed duplicate error code handling
* Removed duplicate code
* Fixed CmdReadToc buffer overflow (https://github.com/akuker/RASCSI/issues/194)
* Added naive implementation of GET EVENT STATUS NOTIFICATION to avoid wranings
* HD must set removable device bit if the media is removable
* Removed duplicate logging
* Updated daynaport additional length
* Removed broken daynaport REQUEST SENSE. Successfully tested with my Mac.
* EnableInterface should not always return TRUE
* Updated Inquiry
* Updated LUN handling
* Replaced incorrect free by delete
* Updated comments and write-protection handling
* Made default HD name consistent
* STATUS_NOERROR is default
* Fixed Eject
* More eject handling updates
* Manpage updates
* Logging update
* Changed debug level
* Logging update
* Log capacity of all media types
* Logging update
* Encapsulated disk.blocks
* Encapsulated sector size
* Added overrides
* Added more overrides
* Fixed error message
* Fixed typos
* Fixed logging
* Added logging
* Use PrimaryDevice when calling Inquiry
* Comment update
* Changed default buffer size for testing
* Reverted last change
* Removed debug output
* De-inlined methods because optimized code did not work with them inlined
* Web interface can attach Daynaport again
* Improved handling of read-only hard disks
* Fixed issue with "all" semantics of DETACH
* rasctl supports adding removable media devices without providing a filename
* Removed unused flag in PbDeviceDefinition
* Updated rasctl output for ecjected media (resolves issue #199)
* Validate default folder name when changing default folder
2021-08-21 21:45:30 +00:00
|
|
|
bool result = ip_link(fd, "ras0", TRUE);
|
2021-04-04 21:45:23 +00:00
|
|
|
close(fd);
|
|
|
|
return result;
|
2021-02-07 19:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Disable
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
Refactoring, device handling extensions, additional settings, improved error handling, 64 bit OS support, fixed issues (#184)
* Device type unification, support of removable media
* Added support for .hdr extension
* Removable flag cleanup
* Manpage update
* Enriched PbOperation with PbDevice
* Added file size to PbImageFile
* Added device list support
* Set image_file
* Make remote interface more robust by ignoring SIGPIPE
* Return status only once
* Fixed typo
* Error handling update
* When starting rascsi parse everything before attaching devices
* Added dry run mode
* Comment update
* Updated logging
* Added Device base class, Disk class inherits from it
* Renaming
* Use vectors for controllers and disks, as preparation for using maps
* Updated file support handling
* Comment update
* DaynaPort and Bridge inherit from Device instead of Disk
* ProcessCmd() now works with devices instead of disks
* Renaming
* Added DeviceFactory
* Improved factory
* Comment update
* protected disk_t
* Code cleanup, added translations
* Device name can be set for rascsi
* rasctl can set device name
* Manpage update
* Manpage update
* Formatting update
* Check for missing name
* Initialize fd
* Initialize type
* Fixed string length issue
* Updated capacity formatting
* Fixed typo
* Split PbDevice into device and device definition
* Added TODO
* Renaming
* Renaming
* Device types can be explicitly specified with -t (no FILE:TYPE syntax anymore)
* Fixed compile-time issue
* Removed unused Append mode, updated read-only handling
* Type handling and manpage update
* Cleanup
* rasctl parser cleanup
* Review
* Constructor update
* Added .hdr (SCRM) support to web interface, tested web interface
* Default folder can be set remotely
* Removed deprecated operation
* DETACH supports all parameters in order to detach all devices
* include cleanup
* Logging should not depend on NDEBUG, for RaSCSI it is not peformance-critical
* INFO is default log level
* Exception renaming
* Updated GetPaddedName()
* Inheritance update
* Added BlockDevice class
* Removed unused code
* Updated typedefs
* Revert "Updated typedefs"
This reverts commit 546b46215a4d9b65067a11698e59ab1123cc6d64.
* Removed unused code
* Fixed warnign
* Use standard C++ integer types, use streams to resolve printf data type issues
* Added TODOs
* Added TODO
* Renaming
* Added TODO
* Added TODO
* Improved dry-run
* Code cleanup
* Updated handling of unknown options, code review and cleanup
* Manpage update
* Added PrimaryDevice
* Include cleanup
* Added pure virtual methods
* Comment updates
* Split rasutil
* Replaced some occurrences of BOOL
* Removed obsolete RASCSI definition in xm6.h
* Removed unused code, updated TODOs, replaced BOOL
* Added capacity check (issue #192)
* Fixed (most likely) https://github.com/akuker/RASCSI/issues/191
* Fixed wrong error messages
* For root the default image folder is /home/pi/images, updated error handling
* Dynaport code review
* Improved error handling
* Implemented READ CAPACITY(16)
* Comment update
* Commands can be 16 bytes long
* Implemented READ/WRITE/VERIFY(16)
* Comment update
* Renamed method to reflect the name of the respective SCSI command
* Do not created devices during dryRun
* Fixed padding of SCSIHD_APPLE vendor and product
* Initial implementation
* Updated ReportLuns
* Byte count update
* Fixed typo
* Finalized REPORT LUNS
* Removed TODO
* Updated TODO
* TODO update
* Updated device factory
* Comment update
* 64 bit update, tested on Ubuntu 64 bit system
* Removed assertion
* SCSI hard disks always have Apple specific mode pages (resolves issue #193)
* Error messsage update, 64 bit cleanup
* Reduced streams usage
* Updated handling of device flags
* MOs are protectable
* Removed duplicate error code handling
* Removed duplicate code
* Fixed CmdReadToc buffer overflow (https://github.com/akuker/RASCSI/issues/194)
* Added naive implementation of GET EVENT STATUS NOTIFICATION to avoid wranings
* HD must set removable device bit if the media is removable
* Removed duplicate logging
* Updated daynaport additional length
* Removed broken daynaport REQUEST SENSE. Successfully tested with my Mac.
* EnableInterface should not always return TRUE
* Updated Inquiry
* Updated LUN handling
* Replaced incorrect free by delete
* Updated comments and write-protection handling
* Made default HD name consistent
* STATUS_NOERROR is default
* Fixed Eject
* More eject handling updates
* Manpage updates
* Logging update
* Changed debug level
* Logging update
* Log capacity of all media types
* Logging update
* Encapsulated disk.blocks
* Encapsulated sector size
* Added overrides
* Added more overrides
* Fixed error message
* Fixed typos
* Fixed logging
* Added logging
* Use PrimaryDevice when calling Inquiry
* Comment update
* Changed default buffer size for testing
* Reverted last change
* Removed debug output
* De-inlined methods because optimized code did not work with them inlined
* Web interface can attach Daynaport again
* Improved handling of read-only hard disks
* Fixed issue with "all" semantics of DETACH
* rasctl supports adding removable media devices without providing a filename
* Removed unused flag in PbDeviceDefinition
* Updated rasctl output for ecjected media (resolves issue #199)
* Validate default folder name when changing default folder
2021-08-21 21:45:30 +00:00
|
|
|
bool CTapDriver::Disable(){
|
2021-04-04 21:45:23 +00:00
|
|
|
int fd = socket(PF_INET, SOCK_DGRAM, 0);
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGDEBUG("%s: ip link set ras0 down", __PRETTY_FUNCTION__);
|
Refactoring, device handling extensions, additional settings, improved error handling, 64 bit OS support, fixed issues (#184)
* Device type unification, support of removable media
* Added support for .hdr extension
* Removable flag cleanup
* Manpage update
* Enriched PbOperation with PbDevice
* Added file size to PbImageFile
* Added device list support
* Set image_file
* Make remote interface more robust by ignoring SIGPIPE
* Return status only once
* Fixed typo
* Error handling update
* When starting rascsi parse everything before attaching devices
* Added dry run mode
* Comment update
* Updated logging
* Added Device base class, Disk class inherits from it
* Renaming
* Use vectors for controllers and disks, as preparation for using maps
* Updated file support handling
* Comment update
* DaynaPort and Bridge inherit from Device instead of Disk
* ProcessCmd() now works with devices instead of disks
* Renaming
* Added DeviceFactory
* Improved factory
* Comment update
* protected disk_t
* Code cleanup, added translations
* Device name can be set for rascsi
* rasctl can set device name
* Manpage update
* Manpage update
* Formatting update
* Check for missing name
* Initialize fd
* Initialize type
* Fixed string length issue
* Updated capacity formatting
* Fixed typo
* Split PbDevice into device and device definition
* Added TODO
* Renaming
* Renaming
* Device types can be explicitly specified with -t (no FILE:TYPE syntax anymore)
* Fixed compile-time issue
* Removed unused Append mode, updated read-only handling
* Type handling and manpage update
* Cleanup
* rasctl parser cleanup
* Review
* Constructor update
* Added .hdr (SCRM) support to web interface, tested web interface
* Default folder can be set remotely
* Removed deprecated operation
* DETACH supports all parameters in order to detach all devices
* include cleanup
* Logging should not depend on NDEBUG, for RaSCSI it is not peformance-critical
* INFO is default log level
* Exception renaming
* Updated GetPaddedName()
* Inheritance update
* Added BlockDevice class
* Removed unused code
* Updated typedefs
* Revert "Updated typedefs"
This reverts commit 546b46215a4d9b65067a11698e59ab1123cc6d64.
* Removed unused code
* Fixed warnign
* Use standard C++ integer types, use streams to resolve printf data type issues
* Added TODOs
* Added TODO
* Renaming
* Added TODO
* Added TODO
* Improved dry-run
* Code cleanup
* Updated handling of unknown options, code review and cleanup
* Manpage update
* Added PrimaryDevice
* Include cleanup
* Added pure virtual methods
* Comment updates
* Split rasutil
* Replaced some occurrences of BOOL
* Removed obsolete RASCSI definition in xm6.h
* Removed unused code, updated TODOs, replaced BOOL
* Added capacity check (issue #192)
* Fixed (most likely) https://github.com/akuker/RASCSI/issues/191
* Fixed wrong error messages
* For root the default image folder is /home/pi/images, updated error handling
* Dynaport code review
* Improved error handling
* Implemented READ CAPACITY(16)
* Comment update
* Commands can be 16 bytes long
* Implemented READ/WRITE/VERIFY(16)
* Comment update
* Renamed method to reflect the name of the respective SCSI command
* Do not created devices during dryRun
* Fixed padding of SCSIHD_APPLE vendor and product
* Initial implementation
* Updated ReportLuns
* Byte count update
* Fixed typo
* Finalized REPORT LUNS
* Removed TODO
* Updated TODO
* TODO update
* Updated device factory
* Comment update
* 64 bit update, tested on Ubuntu 64 bit system
* Removed assertion
* SCSI hard disks always have Apple specific mode pages (resolves issue #193)
* Error messsage update, 64 bit cleanup
* Reduced streams usage
* Updated handling of device flags
* MOs are protectable
* Removed duplicate error code handling
* Removed duplicate code
* Fixed CmdReadToc buffer overflow (https://github.com/akuker/RASCSI/issues/194)
* Added naive implementation of GET EVENT STATUS NOTIFICATION to avoid wranings
* HD must set removable device bit if the media is removable
* Removed duplicate logging
* Updated daynaport additional length
* Removed broken daynaport REQUEST SENSE. Successfully tested with my Mac.
* EnableInterface should not always return TRUE
* Updated Inquiry
* Updated LUN handling
* Replaced incorrect free by delete
* Updated comments and write-protection handling
* Made default HD name consistent
* STATUS_NOERROR is default
* Fixed Eject
* More eject handling updates
* Manpage updates
* Logging update
* Changed debug level
* Logging update
* Log capacity of all media types
* Logging update
* Encapsulated disk.blocks
* Encapsulated sector size
* Added overrides
* Added more overrides
* Fixed error message
* Fixed typos
* Fixed logging
* Added logging
* Use PrimaryDevice when calling Inquiry
* Comment update
* Changed default buffer size for testing
* Reverted last change
* Removed debug output
* De-inlined methods because optimized code did not work with them inlined
* Web interface can attach Daynaport again
* Improved handling of read-only hard disks
* Fixed issue with "all" semantics of DETACH
* rasctl supports adding removable media devices without providing a filename
* Removed unused flag in PbDeviceDefinition
* Updated rasctl output for ecjected media (resolves issue #199)
* Validate default folder name when changing default folder
2021-08-21 21:45:30 +00:00
|
|
|
bool result = ip_link(fd, "ras0", FALSE);
|
2021-04-04 21:45:23 +00:00
|
|
|
close(fd);
|
|
|
|
return result;
|
2021-02-07 19:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Flush
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2021-07-26 18:33:36 +00:00
|
|
|
BOOL CTapDriver::Flush(){
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("%s", __PRETTY_FUNCTION__);
|
|
|
|
while(PendingPackets()){
|
|
|
|
(void)Rx(m_garbage_buffer);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-08-28 14:18:02 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-12-28 02:13:21 +00:00
|
|
|
// MGet MAC Address
|
2020-08-28 14:18:02 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2021-07-26 18:33:36 +00:00
|
|
|
void CTapDriver::GetMacAddr(BYTE *mac)
|
2020-08-28 14:18:02 +00:00
|
|
|
{
|
|
|
|
ASSERT(mac);
|
|
|
|
|
|
|
|
memcpy(mac, m_MacAddr, sizeof(m_MacAddr));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-12-28 02:13:21 +00:00
|
|
|
// Receive
|
2020-08-28 14:18:02 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2021-07-26 18:33:36 +00:00
|
|
|
BOOL CTapDriver::PendingPackets()
|
2020-08-28 14:18:02 +00:00
|
|
|
{
|
|
|
|
struct pollfd fds;
|
|
|
|
|
|
|
|
ASSERT(m_hTAP != -1);
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Check if there is data that can be received
|
2020-08-28 14:18:02 +00:00
|
|
|
fds.fd = m_hTAP;
|
|
|
|
fds.events = POLLIN | POLLERR;
|
|
|
|
fds.revents = 0;
|
|
|
|
poll(&fds, 1, 0);
|
2021-02-07 19:00:48 +00:00
|
|
|
LOGTRACE("%s %u revents", __PRETTY_FUNCTION__, fds.revents);
|
2020-08-28 14:18:02 +00:00
|
|
|
if (!(fds.revents & POLLIN)) {
|
2021-02-07 19:00:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Receive
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2021-07-26 18:33:36 +00:00
|
|
|
int CTapDriver::Rx(BYTE *buf)
|
2021-02-07 19:00:48 +00:00
|
|
|
{
|
|
|
|
ASSERT(m_hTAP != -1);
|
|
|
|
|
|
|
|
// Check if there is data that can be received
|
|
|
|
if(!PendingPackets()){
|
2020-08-28 14:18:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Receive
|
2021-07-07 21:46:45 +00:00
|
|
|
DWORD dwReceived = read(m_hTAP, buf, ETH_FRAME_LEN);
|
2020-08-28 14:18:02 +00:00
|
|
|
if (dwReceived == (DWORD)-1) {
|
2021-02-26 17:40:16 +00:00
|
|
|
LOGWARN("%s Error occured while receiving an packet", __PRETTY_FUNCTION__);
|
2020-08-28 14:18:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// If reception is enabled
|
2020-08-28 14:18:02 +00:00
|
|
|
if (dwReceived > 0) {
|
2021-02-07 19:00:48 +00:00
|
|
|
// We need to add the Frame Check Status (FCS) CRC back onto the end of the packet.
|
|
|
|
// The Linux network subsystem removes it, since most software apps shouldn't ever
|
|
|
|
// need it.
|
|
|
|
|
|
|
|
// Initialize the CRC
|
2021-07-07 21:46:45 +00:00
|
|
|
DWORD crc = crc32(0L, Z_NULL, 0);
|
2021-02-07 19:00:48 +00:00
|
|
|
// Calculate the CRC
|
|
|
|
crc = crc32(crc, buf, dwReceived);
|
|
|
|
|
|
|
|
buf[dwReceived + 0] = (BYTE)((crc >> 0) & 0xFF);
|
|
|
|
buf[dwReceived + 1] = (BYTE)((crc >> 8) & 0xFF);
|
|
|
|
buf[dwReceived + 2] = (BYTE)((crc >> 16) & 0xFF);
|
|
|
|
buf[dwReceived + 3] = (BYTE)((crc >> 24) & 0xFF);
|
|
|
|
|
Refactoring, device handling extensions, additional settings, improved error handling, 64 bit OS support, fixed issues (#184)
* Device type unification, support of removable media
* Added support for .hdr extension
* Removable flag cleanup
* Manpage update
* Enriched PbOperation with PbDevice
* Added file size to PbImageFile
* Added device list support
* Set image_file
* Make remote interface more robust by ignoring SIGPIPE
* Return status only once
* Fixed typo
* Error handling update
* When starting rascsi parse everything before attaching devices
* Added dry run mode
* Comment update
* Updated logging
* Added Device base class, Disk class inherits from it
* Renaming
* Use vectors for controllers and disks, as preparation for using maps
* Updated file support handling
* Comment update
* DaynaPort and Bridge inherit from Device instead of Disk
* ProcessCmd() now works with devices instead of disks
* Renaming
* Added DeviceFactory
* Improved factory
* Comment update
* protected disk_t
* Code cleanup, added translations
* Device name can be set for rascsi
* rasctl can set device name
* Manpage update
* Manpage update
* Formatting update
* Check for missing name
* Initialize fd
* Initialize type
* Fixed string length issue
* Updated capacity formatting
* Fixed typo
* Split PbDevice into device and device definition
* Added TODO
* Renaming
* Renaming
* Device types can be explicitly specified with -t (no FILE:TYPE syntax anymore)
* Fixed compile-time issue
* Removed unused Append mode, updated read-only handling
* Type handling and manpage update
* Cleanup
* rasctl parser cleanup
* Review
* Constructor update
* Added .hdr (SCRM) support to web interface, tested web interface
* Default folder can be set remotely
* Removed deprecated operation
* DETACH supports all parameters in order to detach all devices
* include cleanup
* Logging should not depend on NDEBUG, for RaSCSI it is not peformance-critical
* INFO is default log level
* Exception renaming
* Updated GetPaddedName()
* Inheritance update
* Added BlockDevice class
* Removed unused code
* Updated typedefs
* Revert "Updated typedefs"
This reverts commit 546b46215a4d9b65067a11698e59ab1123cc6d64.
* Removed unused code
* Fixed warnign
* Use standard C++ integer types, use streams to resolve printf data type issues
* Added TODOs
* Added TODO
* Renaming
* Added TODO
* Added TODO
* Improved dry-run
* Code cleanup
* Updated handling of unknown options, code review and cleanup
* Manpage update
* Added PrimaryDevice
* Include cleanup
* Added pure virtual methods
* Comment updates
* Split rasutil
* Replaced some occurrences of BOOL
* Removed obsolete RASCSI definition in xm6.h
* Removed unused code, updated TODOs, replaced BOOL
* Added capacity check (issue #192)
* Fixed (most likely) https://github.com/akuker/RASCSI/issues/191
* Fixed wrong error messages
* For root the default image folder is /home/pi/images, updated error handling
* Dynaport code review
* Improved error handling
* Implemented READ CAPACITY(16)
* Comment update
* Commands can be 16 bytes long
* Implemented READ/WRITE/VERIFY(16)
* Comment update
* Renamed method to reflect the name of the respective SCSI command
* Do not created devices during dryRun
* Fixed padding of SCSIHD_APPLE vendor and product
* Initial implementation
* Updated ReportLuns
* Byte count update
* Fixed typo
* Finalized REPORT LUNS
* Removed TODO
* Updated TODO
* TODO update
* Updated device factory
* Comment update
* 64 bit update, tested on Ubuntu 64 bit system
* Removed assertion
* SCSI hard disks always have Apple specific mode pages (resolves issue #193)
* Error messsage update, 64 bit cleanup
* Reduced streams usage
* Updated handling of device flags
* MOs are protectable
* Removed duplicate error code handling
* Removed duplicate code
* Fixed CmdReadToc buffer overflow (https://github.com/akuker/RASCSI/issues/194)
* Added naive implementation of GET EVENT STATUS NOTIFICATION to avoid wranings
* HD must set removable device bit if the media is removable
* Removed duplicate logging
* Updated daynaport additional length
* Removed broken daynaport REQUEST SENSE. Successfully tested with my Mac.
* EnableInterface should not always return TRUE
* Updated Inquiry
* Updated LUN handling
* Replaced incorrect free by delete
* Updated comments and write-protection handling
* Made default HD name consistent
* STATUS_NOERROR is default
* Fixed Eject
* More eject handling updates
* Manpage updates
* Logging update
* Changed debug level
* Logging update
* Log capacity of all media types
* Logging update
* Encapsulated disk.blocks
* Encapsulated sector size
* Added overrides
* Added more overrides
* Fixed error message
* Fixed typos
* Fixed logging
* Added logging
* Use PrimaryDevice when calling Inquiry
* Comment update
* Changed default buffer size for testing
* Reverted last change
* Removed debug output
* De-inlined methods because optimized code did not work with them inlined
* Web interface can attach Daynaport again
* Improved handling of read-only hard disks
* Fixed issue with "all" semantics of DETACH
* rasctl supports adding removable media devices without providing a filename
* Removed unused flag in PbDeviceDefinition
* Updated rasctl output for ecjected media (resolves issue #199)
* Validate default folder name when changing default folder
2021-08-21 21:45:30 +00:00
|
|
|
LOGDEBUG("%s CRC is %08X - %02X %02X %02X %02X\n", __PRETTY_FUNCTION__, crc, buf[dwReceived+0], buf[dwReceived+1], buf[dwReceived+2], buf[dwReceived+3]);
|
2021-02-07 19:00:48 +00:00
|
|
|
|
|
|
|
// Add FCS size to the received message size
|
2020-08-28 14:18:02 +00:00
|
|
|
dwReceived += 4;
|
|
|
|
}
|
|
|
|
|
2021-04-03 19:02:20 +00:00
|
|
|
if (m_pcap_dumper != NULL) {
|
|
|
|
struct pcap_pkthdr h = {
|
|
|
|
.caplen = dwReceived,
|
|
|
|
.len = dwReceived,
|
|
|
|
};
|
|
|
|
gettimeofday(&h.ts, NULL);
|
|
|
|
pcap_dump((u_char*)m_pcap_dumper, &h, buf);
|
|
|
|
LOGTRACE("%s Dumped %d byte packet (first byte: %02x last byte: %02x)", __PRETTY_FUNCTION__, (unsigned int)dwReceived, buf[0], buf[dwReceived-1]);
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Return the number of bytes
|
2020-08-28 14:18:02 +00:00
|
|
|
return dwReceived;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2020-12-28 02:13:21 +00:00
|
|
|
// Send
|
2020-08-28 14:18:02 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2021-07-26 18:33:36 +00:00
|
|
|
int CTapDriver::Tx(const BYTE *buf, int len)
|
2020-08-28 14:18:02 +00:00
|
|
|
{
|
|
|
|
ASSERT(m_hTAP != -1);
|
|
|
|
|
2021-04-03 19:02:20 +00:00
|
|
|
if (m_pcap_dumper != NULL) {
|
|
|
|
struct pcap_pkthdr h = {
|
|
|
|
.caplen = (bpf_u_int32)len,
|
|
|
|
.len = (bpf_u_int32)len,
|
|
|
|
};
|
|
|
|
gettimeofday(&h.ts, NULL);
|
|
|
|
pcap_dump((u_char*)m_pcap_dumper, &h, buf);
|
|
|
|
LOGTRACE("%s Dumped %d byte packet (first byte: %02x last byte: %02x)", __PRETTY_FUNCTION__, (unsigned int)h.len, buf[0], buf[h.len-1]);
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:13:21 +00:00
|
|
|
// Start sending
|
2020-08-28 14:18:02 +00:00
|
|
|
return write(m_hTAP, buf, len);
|
|
|
|
}
|