Network Switch support

Co-Authored-By: Alexander Babikov <2708460+lemondrops@users.noreply.github.com>
Co-Authored-By: cold-brewed <47337035+cold-brewed@users.noreply.github.com>
This commit is contained in:
Jasmine Iwanek
2025-06-26 20:53:17 -04:00
parent be8dc5f488
commit 2dc28d39b1
20 changed files with 6846 additions and 5 deletions

View File

@@ -1181,6 +1181,12 @@ MediaMenu::nicUpdateMenu(int i)
case NET_TYPE_TAP:
netType = "TAP";
break;
case NET_TYPE_NMSWITCH:
netType = "Local Switch";
break;
case NET_TYPE_NRSWITCH:
netType = "Remote Switch";
break;
}
QString devName = DeviceConfig::DeviceName(network_card_getdevice(net_cards_conf[i].device_num), network_card_get_internal_name(net_cards_conf[i].device_num), 1);

View File

@@ -51,11 +51,43 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui)
auto *option_list_label = findChild<QLabel *>(QString("labelOptionList%1").arg(i + 1));
auto *option_list_line = findChild<QWidget *>(QString("lineOptionList%1").arg(i + 1));
// Switch group
auto *switch_group_label = findChild<QLabel *>(QString("labelSwitch%1").arg(i + 1));
// auto *switch_group_hlayout = findChild<QHBoxLayout *>(QString("HLayoutSwitch%1").arg(i + 1));
// auto *switch_group_hspacer = findChild<QWidget *>(QString("horizontalSpacerSwitch%1").arg(i + 1));
auto *switch_group_value = findChild<QSpinBox *>(QString("spinnerSwitch%1").arg(i + 1));
switch_group_value->setMinimum(1);
switch_group_value->setMaximum(10);
// Promiscuous option
auto *promisc_label = findChild<QLabel *>(QString("labelPromisc%1").arg(i + 1));
auto *promisc_value = findChild<QCheckBox *>(QString("boxPromisc%1").arg(i + 1));
// Remote switch hostname
auto *hostname_label = findChild<QLabel *>(QString("labelHostname%1").arg(i + 1));
auto *hostname_value = findChild<QLineEdit *>(QString("hostnameSwitch%1").arg(i + 1));
bridge_line->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_TAP);
intf_cbox->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_PCAP);
conf_btn->setEnabled(network_card_has_config(nic_cbox->currentData().toInt()));
// net_type_conf_btn->setEnabled(network_type_has_config(netType));
// NEW STUFF
// Make all options invisible by default
// Switch group
switch_group_label->setVisible(false);
switch_group_value->setVisible(false);
// switch_group_hspacer->setVisible(false);
// Promiscuous options
promisc_label->setVisible(false);
promisc_value->setVisible(false);
// Hostname
hostname_label->setVisible(false);
hostname_value->setVisible(false);
// Option list label and line
option_list_label->setVisible(false);
option_list_line->setVisible(false);
@@ -107,6 +139,36 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui)
break;
#endif
case NET_TYPE_NMSWITCH:
// option_list_label->setText("Local Switch Options");
option_list_label->setVisible(true);
option_list_line->setVisible(true);
// Switch group
switch_group_label->setVisible(true);
switch_group_value->setVisible(true);
// switch_group_hspacer->setVisible(false);
// Promiscuous options
promisc_label->setVisible(true);
promisc_value->setVisible(true);
break;
case NET_TYPE_NRSWITCH:
// option_list_label->setText("Remote Switch Options");
option_list_label->setVisible(true);
option_list_line->setVisible(true);
// Switch group
switch_group_label->setVisible(true);
switch_group_value->setVisible(true);
// switch_group_hspacer->setVisible(false);
// Hostname
hostname_label->setVisible(true);
hostname_value->setVisible(true);
break;
case NET_TYPE_SLIRP:
default:
break;
@@ -151,6 +213,9 @@ SettingsNetwork::save()
cbox = findChild<QComboBox *>(QString("comboBoxNet%1").arg(i + 1));
net_cards_conf[i].net_type = cbox->currentData().toInt();
cbox = findChild<QComboBox *>(QString("comboBoxIntf%1").arg(i + 1));
auto *hostname_value = findChild<QLineEdit *>(QString("hostnameSwitch%1").arg(i + 1));
auto *promisc_value = findChild<QCheckBox *>(QString("boxPromisc%1").arg(i + 1));
auto *switch_group_value = findChild<QSpinBox *>(QString("spinnerSwitch%1").arg(i + 1));
memset(net_cards_conf[i].host_dev_name, '\0', sizeof(net_cards_conf[i].host_dev_name));
if (net_cards_conf[i].net_type == NET_TYPE_PCAP)
strncpy(net_cards_conf[i].host_dev_name, network_devs[cbox->currentData().toInt()].device, sizeof(net_cards_conf[i].host_dev_name) - 1);
@@ -162,6 +227,14 @@ SettingsNetwork::save()
else if (net_cards_conf[i].net_type == NET_TYPE_TAP)
strncpy(net_cards_conf[i].host_dev_name, bridge_line->text().toUtf8().constData(), sizeof(net_cards_conf[i].host_dev_name));
#endif
else if (net_cards_conf[i].net_type == NET_TYPE_NRSWITCH) {
memset(net_cards_conf[i].nrs_hostname, '\0', sizeof(net_cards_conf[i].nrs_hostname));
strncpy(net_cards_conf[i].nrs_hostname, hostname_value->text().toUtf8().constData(), sizeof(net_cards_conf[i].nrs_hostname) - 1);
net_cards_conf[i].switch_group = switch_group_value->value() - 1;
} else if (net_cards_conf[i].net_type == NET_TYPE_NMSWITCH) {
net_cards_conf[i].promisc_mode = promisc_value->isChecked();
net_cards_conf[i].switch_group = switch_group_value->value() - 1;
}
}
}
@@ -234,6 +307,11 @@ SettingsNetwork::onCurrentMachineChanged(int machineId)
Models::AddEntry(model, "TAP", NET_TYPE_TAP);
#endif
Models::AddEntry(model, "Local Switch", NET_TYPE_NMSWITCH);
#ifdef ENABLE_NET_NRSWITCH
Models::AddEntry(model, "Remote Switch", NET_TYPE_NRSWITCH);
#endif
model->removeRows(0, removeRows);
cbox->setCurrentIndex(cbox->findData(net_cards_conf[i].net_type));
@@ -268,6 +346,16 @@ SettingsNetwork::onCurrentMachineChanged(int machineId)
auto editline = findChild<QLineEdit *>(QString("bridgeTAPNIC%1").arg(i+1));
editline->setText(currentTapDevice);
#endif
} else if (net_cards_conf[i].net_type == NET_TYPE_NMSWITCH) {
auto *promisc_value = findChild<QCheckBox *>(QString("promiscBox%1").arg(i + 1));
promisc_value->setCheckState(net_cards_conf[i].promisc_mode == 1 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
auto *switch_group_value = findChild<QSpinBox *>(QString("switchSpinner%1").arg(i + 1));
switch_group_value->setValue(net_cards_conf[i].switch_group + 1);
} else if (net_cards_conf[i].net_type == NET_TYPE_NRSWITCH) {
auto *hostname_value = findChild<QLineEdit *>(QString("switchHostname%1").arg(i + 1));
hostname_value->setText(net_cards_conf[i].nrs_hostname);
auto *switch_group_value = findChild<QSpinBox *>(QString("switchSpinner%1").arg(i + 1));
switch_group_value->setValue(net_cards_conf[i].switch_group + 1);
}
}
}

View File

@@ -169,7 +169,69 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelSwitch1">
<property name="text">
<string>Switch:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="HLayoutSwitch1">
<item>
<widget class="QSpinBox" name="spinnerSwitch1">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacerSwitch1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelPromisc1">
<property name="text">
<string>Hub Mode</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="boxPromisc1">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelHostname1">
<property name="text">
<string>Hostname:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="hostnameSwitch1">
<property name="maxLength">
<number>128</number>
</property>
</widget>
</item>
<item row="10" column="1">
<spacer name="verticalSpacerNIC1">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -322,7 +384,69 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelSwitch2">
<property name="text">
<string>Switch:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="HLayoutSwitch2">
<item>
<widget class="QSpinBox" name="spinnerSwitch2">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacerSwitch2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelPromisc2">
<property name="text">
<string>Hub Mode</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="boxPromisc2">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelHostname2">
<property name="text">
<string>Hostname:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="hostnameSwitch2">
<property name="maxLength">
<number>128</number>
</property>
</widget>
</item>
<item row="10" column="1">
<spacer name="verticalSpacerNIC2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -475,7 +599,69 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelSwitch3">
<property name="text">
<string>Switch:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="HLayoutSwitch3">
<item>
<widget class="QSpinBox" name="spinnerSwitch3">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacerSwitch3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelPromisc3">
<property name="text">
<string>Hub Mode</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="boxPromisc3">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelHostname3">
<property name="text">
<string>Hostname:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="hostnameSwitch3">
<property name="maxLength">
<number>128</number>
</property>
</widget>
</item>
<item row="10" column="1">
<spacer name="verticalSpacerNIC3">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -628,7 +814,69 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelSwitch4">
<property name="text">
<string>Switch:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="HLayoutSwitch4">
<item>
<widget class="QSpinBox" name="spinnerSwitch4">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacerSwitch4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelPromisc4">
<property name="text">
<string>Hub Mode</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="boxPromisc4">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelHostname4">
<property name="text">
<string>Hostname:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="hostnameSwitch4">
<property name="maxLength">
<number>128</number>
</property>
</widget>
</item>
<item row="10" column="1">
<spacer name="verticalSpacerNIC4">
<property name="orientation">
<enum>Qt::Vertical</enum>