Merge pull request #124 from mammonsama666/0427-dev
fix(configuration): It's not permitted to save configuration when only set ipv6 address.
This commit is contained in:
commit
d554e18ece
|
@ -166,6 +166,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
|
||||||
ui->leName->setText(connName);
|
ui->leName->setText(connName);
|
||||||
lastConnName = connName;
|
lastConnName = connName;
|
||||||
lastIpv4 = v4addr;
|
lastIpv4 = v4addr;
|
||||||
|
lastIpv6 = v6addr;
|
||||||
netUuid = uuidName;
|
netUuid = uuidName;
|
||||||
qDebug() << Q_FUNC_INFO << __LINE__ << connName << uuidName;
|
qDebug() << Q_FUNC_INFO << __LINE__ << connName << uuidName;
|
||||||
|
|
||||||
|
@ -175,7 +176,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
|
||||||
isActWifi = isWiFi;
|
isActWifi = isWiFi;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v4method == "auto" || v4method == "") {
|
if ((v4method == "auto" || v4method == "") && (v6method == "auto" || v6method == "")) {
|
||||||
ui->cbType->setCurrentIndex(0);
|
ui->cbType->setCurrentIndex(0);
|
||||||
cbTypeChanged(0);
|
cbTypeChanged(0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -245,19 +246,29 @@ void ConfForm::on_btnCreate_clicked()
|
||||||
mIfname = kylindbus.multiWiredIfName.at(0);
|
mIfname = kylindbus.multiWiredIfName.at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
|
if (ui->cbType->currentIndex() == 1) {
|
||||||
//在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突
|
//在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突
|
||||||
|
if (!ui->leAddr->text().isEmpty()|| !ui->leAddr_ipv6->text().isEmpty()) {
|
||||||
if (check_ip_conflict(mIfname)) {
|
if (check_ip_conflict(mIfname)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
QString name = ui->leName->text().trimmed();
|
QString name = ui->leName->text().trimmed();
|
||||||
QString cmdStr;
|
QString cmdStr;
|
||||||
if(ui->cbType->currentIndex() == 0){
|
if(ui->cbType->currentIndex() == 0){
|
||||||
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet";
|
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet";
|
||||||
}else{
|
}else{
|
||||||
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet ipv4.method manual ipv4.address "
|
if (ui->leAddr->text().isEmpty()) { //只配置了ipv6地址
|
||||||
|
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet ipv4.method auto ipv6.method manual ipv6.address "
|
||||||
|
+ ui->leAddr_ipv6->text();
|
||||||
|
} else if (ui->leAddr_ipv6->text().isEmpty()) { //只配置了ipv4地址
|
||||||
|
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet ipv6.method auto ipv4.method manual ipv4.address "
|
||||||
+ ui->leAddr->text() + "/" + mask.toUtf8().data();
|
+ ui->leAddr->text() + "/" + mask.toUtf8().data();
|
||||||
|
} else {
|
||||||
|
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet ipv6.method manual ipv6.address " + ui->leAddr_ipv6->text()
|
||||||
|
+ " ipv4.method manual ipv4.address " + ui->leAddr->text() + "/" + mask.toUtf8().data();
|
||||||
|
}
|
||||||
if(!ui->leGateway->text().isEmpty()){
|
if(!ui->leGateway->text().isEmpty()){
|
||||||
cmdStr += " ipv4.gateway " + ui->leGateway->text();
|
cmdStr += " ipv4.gateway " + ui->leGateway->text();
|
||||||
}
|
}
|
||||||
|
@ -281,13 +292,13 @@ void ConfForm::on_btnCreate_clicked()
|
||||||
kylindbus.showDesktopNotify(txt);
|
kylindbus.showDesktopNotify(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ui->leAddr_ipv6->text().isEmpty()) {
|
// if (!ui->leAddr_ipv6->text().isEmpty()) {
|
||||||
QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
|
// QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
|
||||||
Utils::m_system(cmdStr.toUtf8().data());
|
// Utils::m_system(cmdStr.toUtf8().data());
|
||||||
} else {
|
// } else {
|
||||||
QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method auto";
|
// QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method auto";
|
||||||
Utils::m_system(cmdStr.toUtf8().data());
|
// Utils::m_system(cmdStr.toUtf8().data());
|
||||||
}
|
// }
|
||||||
|
|
||||||
onConfformHide();
|
onConfformHide();
|
||||||
}
|
}
|
||||||
|
@ -307,12 +318,14 @@ void ConfForm::on_btnSave_clicked()
|
||||||
kylindbus.showDesktopNotify(notifyTxt);
|
kylindbus.showDesktopNotify(notifyTxt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
|
if (ui->cbType->currentIndex() == 1) {
|
||||||
//在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突
|
//在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突
|
||||||
|
if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) {
|
||||||
if (check_ip_conflict(mWifiIfname)) {
|
if (check_ip_conflict(mWifiIfname)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this->saveNetworkConfiguration();
|
this->saveNetworkConfiguration();
|
||||||
} else {
|
} else {
|
||||||
|
@ -358,12 +371,14 @@ void ConfForm::on_btnSave_clicked()
|
||||||
int pos = str.indexOf(regExpTest);
|
int pos = str.indexOf(regExpTest);
|
||||||
newUuid = str.mid(pos,36); //36是uuid的长度
|
newUuid = str.mid(pos,36); //36是uuid的长度
|
||||||
|
|
||||||
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
|
if (ui->cbType->currentIndex() == 1) {
|
||||||
//在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突
|
//在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突
|
||||||
|
if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) {
|
||||||
if (check_ip_conflict(mIfname)) {
|
if (check_ip_conflict(mIfname)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this->saveNetworkConfiguration();
|
this->saveNetworkConfiguration();
|
||||||
});
|
});
|
||||||
|
@ -372,28 +387,19 @@ void ConfForm::on_btnSave_clicked()
|
||||||
this->isCreateNewNet = false;
|
this->isCreateNewNet = false;
|
||||||
newUuid = "--";
|
newUuid = "--";
|
||||||
|
|
||||||
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
|
if (ui->cbType->currentIndex() == 1) {
|
||||||
//在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突
|
//在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突
|
||||||
|
if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) {
|
||||||
if (check_ip_conflict(mIfname)) {
|
if (check_ip_conflict(mIfname)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
this->saveNetworkConfiguration();
|
this->saveNetworkConfiguration();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui->cbType->currentIndex() == 1) {
|
|
||||||
//对于已保存连接修改ipv6地址,使用UUID区分各网络配置(排除名称含空格或特殊字符的干扰)
|
|
||||||
if (!ui->leAddr_ipv6->text().isEmpty()) {
|
|
||||||
QString cmdStr = "nmcli connection modify '" + netUuid + "' ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
|
|
||||||
Utils::m_system(cmdStr.toUtf8().data());
|
|
||||||
} else {
|
|
||||||
QString cmdStr = "nmcli connection modify '" + netUuid + "' ipv6.method auto";
|
|
||||||
Utils::m_system(cmdStr.toUtf8().data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QString txt(tr("New network settings already finished"));
|
QString txt(tr("New network settings already finished"));
|
||||||
kylindbus.showDesktopNotify(txt);
|
kylindbus.showDesktopNotify(txt);
|
||||||
}
|
}
|
||||||
|
@ -427,14 +433,33 @@ void ConfForm::saveNetworkConfiguration()
|
||||||
qDebug() << Q_FUNC_INFO << __LINE__ << name << newUuid << ui->leAddr->text() << mask << ui->leGateway->text();
|
qDebug() << Q_FUNC_INFO << __LINE__ << name << newUuid << ui->leAddr->text() << mask << ui->leGateway->text();
|
||||||
//kylin_network_set_automethod(name.toUtf8().data());
|
//kylin_network_set_automethod(name.toUtf8().data());
|
||||||
kylin_network_set_automethod(netUuid.toUtf8().data());
|
kylin_network_set_automethod(netUuid.toUtf8().data());
|
||||||
|
kylin_network_set_ipv6_automethod(netUuid.toUtf8().data());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (newUuid != "--" && newUuid != "" && !newUuid.isEmpty()) {
|
if (newUuid != "--" && newUuid != "" && !newUuid.isEmpty()) {
|
||||||
qDebug() << Q_FUNC_INFO << __LINE__ << name << newUuid << ui->leAddr->text() << mask << ui->leGateway->text() << dnss;
|
qDebug() << Q_FUNC_INFO << __LINE__ << name << newUuid << ui->leAddr->text() << mask << ui->leGateway->text() << dnss;
|
||||||
|
if (!ui->leAddr->text().isEmpty()) {
|
||||||
kylin_network_set_manualall(newUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
|
kylin_network_set_manualall(newUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
|
||||||
|
} else {
|
||||||
|
kylin_network_set_automethod(newUuid.toUtf8().data());
|
||||||
|
}
|
||||||
|
if (!ui->leAddr_ipv6->text().isEmpty()) {
|
||||||
|
kylin_network_set_ipv6_manualmethod(newUuid.toUtf8().data(), ui->leAddr_ipv6->text().toUtf8().data());
|
||||||
|
} else {
|
||||||
|
kylin_network_set_ipv6_automethod(newUuid.toUtf8().data());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << Q_FUNC_INFO << __LINE__ << name << netUuid << ui->leAddr->text() << mask << ui->leGateway->text() << dnss;
|
qDebug() << Q_FUNC_INFO << __LINE__ << name << netUuid << ui->leAddr->text() << mask << ui->leGateway->text() << dnss;
|
||||||
|
if (!ui->leAddr->text().isEmpty()) {
|
||||||
kylin_network_set_manualall(netUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
|
kylin_network_set_manualall(netUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
|
||||||
|
} else {
|
||||||
|
kylin_network_set_automethod(netUuid.toUtf8().data());
|
||||||
|
}
|
||||||
|
if (!ui->leAddr_ipv6->text().isEmpty()) {
|
||||||
|
kylin_network_set_ipv6_manualmethod(netUuid.toUtf8().data(), ui->leAddr_ipv6->text().toUtf8().data());
|
||||||
|
} else {
|
||||||
|
kylin_network_set_ipv6_automethod(netUuid.toUtf8().data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,6 +500,8 @@ bool ConfForm::check_ip_conflict(QString ifname)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char ret[10], arp_all[1024];
|
char ret[10], arp_all[1024];
|
||||||
|
|
||||||
|
if (!ui->leAddr_ipv6->text().isEmpty() && ui->leAddr_ipv6->text() != "") {
|
||||||
|
//ipv4地址不为空,需要验证是否冲突
|
||||||
QString arp_all_cmd = "arping -c 3 -f -I " + ifname + " -D " + ui->leAddr->text();
|
QString arp_all_cmd = "arping -c 3 -f -I " + ifname + " -D " + ui->leAddr->text();
|
||||||
fp = popen(arp_all_cmd.toUtf8().data(),"r");
|
fp = popen(arp_all_cmd.toUtf8().data(),"r");
|
||||||
if(!fp)
|
if(!fp)
|
||||||
|
@ -507,6 +534,7 @@ bool ConfForm::check_ip_conflict(QString ifname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (ui->leAddr_ipv6->text().isEmpty() || ui->leAddr_ipv6->text() == "") {
|
if (ui->leAddr_ipv6->text().isEmpty() || ui->leAddr_ipv6->text() == "") {
|
||||||
//未配置ipv6地址,跳过ipv6地址冲突检测
|
//未配置ipv6地址,跳过ipv6地址冲突检测
|
||||||
return false;
|
return false;
|
||||||
|
@ -684,7 +712,13 @@ void ConfForm::setEnableOfBtn()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui->cbType->currentIndex() == 1) {
|
if (ui->cbType->currentIndex() == 1) {
|
||||||
if (!this->getTextEditState(ui->leAddr->text()) ) {
|
if (ui->leAddr->text().isEmpty() && ui->leAddr_ipv6->text().isEmpty()) {
|
||||||
|
//当ipv4和ipv6地址均未设置时,禁止保存
|
||||||
|
this->setBtnEnableFalse();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ui->leAddr->text().isEmpty() && !this->getTextEditState(ui->leAddr->text()) ) {
|
||||||
this->setBtnEnableFalse();
|
this->setBtnEnableFalse();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ private:
|
||||||
bool isActConf; //是否对已经连接的网络进行的更改
|
bool isActConf; //是否对已经连接的网络进行的更改
|
||||||
bool isCreateNewNet = false; //是否是创建的新网络
|
bool isCreateNewNet = false; //是否是创建的新网络
|
||||||
bool isShowSaveBtn = true; //是否显示保存按钮,即是否是编辑网络界面
|
bool isShowSaveBtn = true; //是否显示保存按钮,即是否是编辑网络界面
|
||||||
QString lastConnName, lastIpv4, netUuid, newUuid;
|
QString lastConnName, lastIpv4, netUuid, newUuid, lastIpv6;
|
||||||
bool isActWifi; //是否是wifi网络
|
bool isActWifi; //是否是wifi网络
|
||||||
bool canCheckIpConflict = true; //当前是否可以执行IP冲突的检测
|
bool canCheckIpConflict = true; //当前是否可以执行IP冲突的检测
|
||||||
bool isIpv6Conflict = false; //ipv6地址是否冲突
|
bool isIpv6Conflict = false; //ipv6地址是否冲突
|
||||||
|
|
|
@ -367,6 +367,16 @@ void kylin_network_set_automethod(char *con_name)
|
||||||
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_automethod' failed");}
|
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_automethod' failed");}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设置动态分配ipv6地址
|
||||||
|
void kylin_network_set_ipv6_automethod(char *con_name)
|
||||||
|
{
|
||||||
|
char str[256];
|
||||||
|
char *automethod="auto";
|
||||||
|
sprintf(str,"nmcli connection modify '%s' ipv6.method %s ipv6.address ''",con_name,automethod);
|
||||||
|
int status = system(str);
|
||||||
|
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_ipv6_automethod' failed");}
|
||||||
|
}
|
||||||
|
|
||||||
//设置手动分配ip
|
//设置手动分配ip
|
||||||
void kylin_network_set_manualmethod(char *con_name,char *ip)
|
void kylin_network_set_manualmethod(char *con_name,char *ip)
|
||||||
{
|
{
|
||||||
|
@ -377,6 +387,16 @@ void kylin_network_set_manualmethod(char *con_name,char *ip)
|
||||||
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_manualmethod' failed");}
|
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_manualmethod' failed");}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设置手动分配ipv6地址
|
||||||
|
void kylin_network_set_ipv6_manualmethod(char *con_name,char *ip)
|
||||||
|
{
|
||||||
|
char str[256];
|
||||||
|
char *method="manual";
|
||||||
|
sprintf(str,"nmcli connection modify '%s' ipv6.method %s ipv6.address '%s'",con_name,method,ip);
|
||||||
|
int status = system(str);
|
||||||
|
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_ipv6_manualmethod' failed");}
|
||||||
|
}
|
||||||
|
|
||||||
// 设置手动分配all
|
// 设置手动分配all
|
||||||
void kylin_network_set_manualall(char *con_name, char *addr, char *mask, char *gateway, char *dns)
|
void kylin_network_set_manualall(char *con_name, char *addr, char *mask, char *gateway, char *dns)
|
||||||
{
|
{
|
||||||
|
|
|
@ -101,6 +101,7 @@ void kylin_network_del_ethernet_con(char *con_name);
|
||||||
*/
|
*/
|
||||||
void kylin_network_set_automethod(char *con_name);
|
void kylin_network_set_automethod(char *con_name);
|
||||||
|
|
||||||
|
void kylin_network_set_ipv6_automethod(char *con_name);
|
||||||
/*
|
/*
|
||||||
* Set up manual IP assignment.
|
* Set up manual IP assignment.
|
||||||
* @con_name is the connection name.
|
* @con_name is the connection name.
|
||||||
|
@ -108,6 +109,8 @@ void kylin_network_set_automethod(char *con_name);
|
||||||
*/
|
*/
|
||||||
void kylin_network_set_manualmethod(char *con_name,char *ip);
|
void kylin_network_set_manualmethod(char *con_name,char *ip);
|
||||||
|
|
||||||
|
void kylin_network_set_ipv6_manualmethod(char *con_name,char *ip);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up manual all prop.
|
* Set up manual all prop.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -259,7 +259,7 @@ void OneLancForm::setLanInfo(QString str1, QString str2, QString str3, QString s
|
||||||
|
|
||||||
if (str1 == "" || str1 == "auto") {
|
if (str1 == "" || str1 == "auto") {
|
||||||
str1 = tr("No Configuration");
|
str1 = tr("No Configuration");
|
||||||
str2 = tr("No Configuration");
|
// str2 = tr("No Configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str4 == "--" || str4 == "") {
|
if (str4 == "--" || str4 == "") {
|
||||||
|
|
Loading…
Reference in New Issue