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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user