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:
chenlelin 2021-04-29 10:54:21 +08:00 committed by GitHub
commit d554e18ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 62 deletions

View File

@ -166,6 +166,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
ui->leName->setText(connName);
lastConnName = connName;
lastIpv4 = v4addr;
lastIpv6 = v6addr;
netUuid = uuidName;
qDebug() << Q_FUNC_INFO << __LINE__ << connName << uuidName;
@ -175,7 +176,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
isActWifi = isWiFi;
}
if (v4method == "auto" || v4method == "") {
if ((v4method == "auto" || v4method == "") && (v6method == "auto" || v6method == "")) {
ui->cbType->setCurrentIndex(0);
cbTypeChanged(0);
} else {
@ -245,19 +246,29 @@ void ConfForm::on_btnCreate_clicked()
mIfname = kylindbus.multiWiredIfName.at(0);
}
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
if (ui->cbType->currentIndex() == 1) {
//在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
if (!ui->leAddr->text().isEmpty()|| !ui->leAddr_ipv6->text().isEmpty()) {
if (check_ip_conflict(mIfname)) {
return;
}
}
}
QString name = ui->leName->text().trimmed();
QString cmdStr;
if(ui->cbType->currentIndex() == 0){
cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet";
}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();
} 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()){
cmdStr += " ipv4.gateway " + ui->leGateway->text();
}
@ -281,13 +292,13 @@ void ConfForm::on_btnCreate_clicked()
kylindbus.showDesktopNotify(txt);
}
if (!ui->leAddr_ipv6->text().isEmpty()) {
QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
Utils::m_system(cmdStr.toUtf8().data());
} else {
QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method auto";
Utils::m_system(cmdStr.toUtf8().data());
}
// if (!ui->leAddr_ipv6->text().isEmpty()) {
// QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
// Utils::m_system(cmdStr.toUtf8().data());
// } else {
// QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method auto";
// Utils::m_system(cmdStr.toUtf8().data());
// }
onConfformHide();
}
@ -307,12 +318,14 @@ void ConfForm::on_btnSave_clicked()
kylindbus.showDesktopNotify(notifyTxt);
return;
}
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
if (ui->cbType->currentIndex() == 1) {
//在手动配置网络的情况下以及当前的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)) {
return;
}
}
}
this->saveNetworkConfiguration();
} else {
@ -358,12 +371,14 @@ void ConfForm::on_btnSave_clicked()
int pos = str.indexOf(regExpTest);
newUuid = str.mid(pos,36); //36是uuid的长度
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
if (ui->cbType->currentIndex() == 1) {
//在手动配置网络的情况下以及当前的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)) {
return;
}
}
}
this->saveNetworkConfiguration();
});
@ -372,28 +387,19 @@ void ConfForm::on_btnSave_clicked()
this->isCreateNewNet = false;
newUuid = "--";
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
if (ui->cbType->currentIndex() == 1) {
//在手动配置网络的情况下以及当前的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)) {
return;
}
}
}
qDebug() << Q_FUNC_INFO;
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"));
kylindbus.showDesktopNotify(txt);
}
@ -427,14 +433,33 @@ void ConfForm::saveNetworkConfiguration()
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(netUuid.toUtf8().data());
kylin_network_set_ipv6_automethod(netUuid.toUtf8().data());
}
else {
if (newUuid != "--" && newUuid != "" && !newUuid.isEmpty()) {
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());
} 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 {
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());
} 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;
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();
fp = popen(arp_all_cmd.toUtf8().data(),"r");
if(!fp)
@ -494,19 +521,20 @@ bool ConfForm::check_ip_conflict(QString ifname)
ret[strlen(ret)-1]=0;
if ( ret != NULL ) {
// if (!strcmp(ret,"0")) {
// //printf("正常连接");
// return false;
// } else {
// if (!strcmp(ret,"0")) {
// //printf("正常连接");
// return false;
// } else {
if (strcmp(ret,"0")) {
//printf("ipv4地址冲突");
QString strInfo = tr("IPV4 address conflict, Please change IP");
// QString buffer = "notify-send -i network-offline " + strInfo;
// QString buffer = "notify-send -i network-offline " + strInfo;
showNotify(strInfo);
return true;
}
}
}
}
if (ui->leAddr_ipv6->text().isEmpty() || ui->leAddr_ipv6->text() == "") {
//未配置ipv6地址跳过ipv6地址冲突检测
return false;
@ -684,7 +712,13 @@ void ConfForm::setEnableOfBtn()
}
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();
return;
}

View File

@ -96,7 +96,7 @@ private:
bool isActConf; //是否对已经连接的网络进行的更改
bool isCreateNewNet = false; //是否是创建的新网络
bool isShowSaveBtn = true; //是否显示保存按钮,即是否是编辑网络界面
QString lastConnName, lastIpv4, netUuid, newUuid;
QString lastConnName, lastIpv4, netUuid, newUuid, lastIpv6;
bool isActWifi; //是否是wifi网络
bool canCheckIpConflict = true; //当前是否可以执行IP冲突的检测
bool isIpv6Conflict = false; //ipv6地址是否冲突

View File

@ -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");}
}
//设置动态分配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
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");}
}
//设置手动分配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
void kylin_network_set_manualall(char *con_name, char *addr, char *mask, char *gateway, char *dns)
{

View File

@ -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_ipv6_automethod(char *con_name);
/*
* Set up manual IP assignment.
* @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_ipv6_manualmethod(char *con_name,char *ip);
/*
* Set up manual all prop.
*/

View File

@ -259,7 +259,7 @@ void OneLancForm::setLanInfo(QString str1, QString str2, QString str3, QString s
if (str1 == "" || str1 == "auto") {
str1 = tr("No Configuration");
str2 = tr("No Configuration");
// str2 = tr("No Configuration");
}
if (str4 == "--" || str4 == "") {