moved bridge setup into ctapdriver

This commit is contained in:
Tony Kuker 2021-02-07 16:46:59 -06:00
parent 99538d8225
commit 0d25785f03
5 changed files with 64 additions and 11 deletions

View File

@ -19,6 +19,8 @@
#include "ctapdriver.h"
#include "log.h"
const char rascsi_bridge_string[] = "rascsi_bridge";
//---------------------------------------------------------------------------
//
// Constructor
@ -43,6 +45,7 @@ BOOL FASTCALL CTapDriver::Init()
LOGTRACE("%s",__PRETTY_FUNCTION__);
char dev[IFNAMSIZ] = "ras0";
char cmd_output[256] = "";
struct ifreq ifr;
int ret;
@ -69,6 +72,29 @@ BOOL FASTCALL CTapDriver::Init()
}
LOGTRACE("return code from ioctl was %d", ret);
LOGTRACE("Going to see if the bridge is created");
ret = run_system_cmd_with_output("brctl show | grep rascsi_bridge", cmd_output, sizeof(cmd_output));
if(ret != EXIT_SUCCESS){
LOGTRACE("Unable to run brctl show command");
}
LOGTRACE("%s brctl show returned %s", __PRETTY_FUNCTION__, cmd_output);
// Check if the bridge is already created
if(strncmp(rascsi_bridge_string, cmd_output, strlen(rascsi_bridge_string)) != 0){
LOGINFO("Creating the rascsi_bridge...");
LOGDEBUG("brctl addbr rascsi_bridge");
ret = run_system_cmd("brctl addbr rascsi_bridge");
LOGDEBUG("brctl addif rascsi_bridge eth0");
ret = run_system_cmd("brctl addif rascsi_bridge eth0");
LOGDEBUG("ip link set dev rascsi_bridge up");
ret = run_system_cmd("ip link set dev rascsi_bridge up");
}
else
{
LOGINFO("Note: rascsi_bridge already created");
}
LOGDEBUG("ip link set ras0 up");
ret = run_system_cmd("ip link set ras0 up");
LOGTRACE("return code from ip link set ras0 up was %d", ret);

View File

@ -12,6 +12,7 @@
//---------------------------------------------------------------------------
#include "os.h"
#include "log.h"
#include <sys/wait.h>
@ -32,4 +33,31 @@ int run_system_cmd(const char* command)
}
waitpid(pid, &status, 0);
return status;
}
//---------------------------------------------------------------------------
//
// Run system command and save the output to a string
//
//---------------------------------------------------------------------------
int run_system_cmd_with_output(const char* command, char* output_str, size_t max_size)
{
FILE *fp;
char str_buff[1024];
fp = popen(command,"r");
if(fp == NULL)
{
LOGWARN("%s Unable to run command %s", __PRETTY_FUNCTION__, command);
return EXIT_FAILURE;
}
while((fgets(str_buff, sizeof(str_buff), fp) != NULL) && (strlen(output_str) < max_size))
{
strncat(output_str, str_buff, max_size);
}
pclose(fp);
return EXIT_SUCCESS;
}

View File

@ -158,4 +158,8 @@ typedef const char *LPCSTR;
// Run system command and wait for it to finish
extern int run_system_cmd(const char* command);
// Run system command and wait for it to finish and keep the output
extern int run_system_cmd_with_output(const char* command, char* output_str, size_t max_size);
#endif // os_h

View File

@ -925,13 +925,15 @@ bool ParseArgument(int argc, char* argv[])
|| has_suffix(path, ".hdi")
|| has_suffix(path, ".hda")
|| has_suffix(path, ".nhd")) {
type = 0;
type = rasctl_dev_sasi_hd;
} else if (has_suffix(path, ".mos")) {
type = 2;
type = rasctl_dev_mo;
} else if (has_suffix(path, ".iso")) {
type = 3;
type = rasctl_dev_cd;
} else if (xstrcasecmp(path, "bridge") == 0) {
type = 4;
type = rasctl_dev_br;
} else if (xstrcasecmp(path, "daynaport") == 0) {
type = rasctl_dev_daynaport;
} else {
// Cannot determine the file type
fprintf(stderr,

View File

@ -1,7 +0,0 @@
#!/bin/bash
sudo brctl addbr rascsi_bridge
sudo brctl addif rascsi_bridge eth0
sudo ip link set dev rascsi_bridge up
echo Bridge config:
brctl show