Commit 0fbf2b36 authored by Alfred Toth's avatar Alfred Toth Committed by Jan Grulich
Browse files

Add support for the OpenVPN parameter compress

This adds support for the OpenVPN parameter compress. With this, it is
possible to use compression algorithms like lz4 or lz4-v2.

BUG: 387715
parent 60f7c2e9
......@@ -32,6 +32,7 @@
#define NM_OPENVPN_KEY_CERT "cert"
#define NM_OPENVPN_KEY_CIPHER "cipher"
#define NM_OPENVPN_KEY_KEYSIZE "keysize"
#define NM_OPENVPN_KEY_COMPRESS "compress"
#define NM_OPENVPN_KEY_COMP_LZO "comp-lzo"
#define NM_OPENVPN_KEY_CONNECTION_TYPE "connection-type"
#define NM_OPENVPN_KEY_FLOAT "float"
......
......@@ -50,6 +50,7 @@ K_PLUGIN_CLASS_WITH_JSON(OpenVpnUiPlugin, "plasmanetworkmanagement_openvpnui.jso
#define CERT_TAG "cert"
#define CIPHER_TAG "cipher"
#define CLIENT_TAG "client"
#define COMPRESS_TAG "compress"
#define COMP_TAG "comp-lzo"
#define DEV_TAG "dev"
#define FRAGMENT_TAG "fragment"
......@@ -300,6 +301,26 @@ NMVariantMapMap OpenVpnUiPlugin::importConnectionSettings(const QString &fileNam
dataMap.insert(QLatin1String(NM_OPENVPN_KEY_COMP_LZO), "yes");
continue;
}
if (key_value[0] == COMPRESS_TAG) {
if (key_value.count() > 1) {
if (key_value[1] == "yes") {
dataMap.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), "yes");
continue;
} else if (key_value[1] == "lzo") {
dataMap.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), "lzo");
continue;
} else if (key_value[1] == "lz4") {
dataMap.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), "lz4");
continue;
} else if (key_value[1] == "lz4-v2") {
dataMap.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), "lz4-v2");
continue;
}
} else {
dataMap.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), "yes");
continue;
}
}
if (key_value[0] == RENEG_SEC_TAG) {
if (key_value.count() == 2) {
dataMap.insert(QLatin1String(NM_OPENVPN_KEY_RENEG_SECONDS), key_value[1]);
......@@ -811,8 +832,24 @@ bool OpenVpnUiPlugin::exportConnectionSettings(const NetworkManager::ConnectionS
line = QString(CIPHER_TAG) + ' ' + dataMap[NM_OPENVPN_KEY_CIPHER] + '\n';
expFile.write(line.toLatin1());
}
if (dataMap[NM_OPENVPN_KEY_COMP_LZO] == "yes") {
line = QString(COMP_TAG) + " yes\n";
if (dataMap[NM_OPENVPN_KEY_COMP_LZO] == "adaptive") {
line = QString(COMP_TAG) + " adaptive\n";
expFile.write(line.toLatin1());
}
if (dataMap[NM_OPENVPN_KEY_COMPRESS] == "yes") {
line = QString(COMPRESS_TAG) + " yes\n";
expFile.write(line.toLatin1());
}
if (dataMap[NM_OPENVPN_KEY_COMPRESS] == "lzo") {
line = QString(COMPRESS_TAG) + " lzo\n";
expFile.write(line.toLatin1());
}
if (dataMap[NM_OPENVPN_KEY_COMPRESS] == "lz4") {
line = QString(COMPRESS_TAG) + " lz4\n";
expFile.write(line.toLatin1());
}
if (dataMap[NM_OPENVPN_KEY_COMPRESS] == "lz4-v2") {
line = QString(COMPRESS_TAG) + " lz4-v2\n";
expFile.write(line.toLatin1());
}
if (dataMap[NM_OPENVPN_KEY_MSSFIX] == "yes") {
......
......@@ -91,22 +91,22 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QCheckBox" name="chkUseLZO">
<widget class="QCheckBox" name="chkUseCompression">
<property name="toolTip">
<string>Use fast LZO compression.</string>
<string>Use compression.</string>
</property>
<property name="text">
<string>Use LZO compression</string>
<string>Use compression</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbUseLZO">
<widget class="QComboBox" name="cmbUseCompression">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Use fast LZO compression.</string>
<string>Use compression.</string>
</property>
<item>
<property name="text">
......@@ -115,7 +115,17 @@
</item>
<item>
<property name="text">
<string>Yes</string>
<string>LZO</string>
</property>
</item>
<item>
<property name="text">
<string>LZ4</string>
</property>
</item>
<item>
<property name="text">
<string>LZ4 v2</string>
</property>
</item>
<item>
......@@ -123,6 +133,11 @@
<string>Adaptive</string>
</property>
</item>
<item>
<property name="text">
<string>Automatic</string>
</property>
</item>
</widget>
</item>
</layout>
......@@ -1179,7 +1194,7 @@ to protect against DoS attacks.</string>
<tabstop>cmbDeviceType</tabstop>
<tabstop>chkUseVirtualDeviceName</tabstop>
<tabstop>leVirtualDeviceName</tabstop>
<tabstop>chkUseLZO</tabstop>
<tabstop>chkUseCompression</tabstop>
<tabstop>chkUseTCP</tabstop>
<tabstop>chkMssRestrict</tabstop>
<tabstop>chkRandRemHosts</tabstop>
......@@ -1395,9 +1410,9 @@ to protect against DoS attacks.</string>
</hints>
</connection>
<connection>
<sender>chkUseLZO</sender>
<sender>chkUseCompression</sender>
<signal>toggled(bool)</signal>
<receiver>cmbUseLZO</receiver>
<receiver>cmbUseCompression</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
......
......@@ -56,6 +56,10 @@ public:
public:
enum HashingAlgorithms {Default = 0, None, Md4, Md5, Sha1, Sha224, Sha256, Sha384, Sha512, Ripemd160};
};
class EnumCompression {
public:
enum Compression {None = 0, LZO, LZ4, LZ4v2, Adaptive, Automatic};
};
};
OpenVpnAdvancedWidget::OpenVpnAdvancedWidget(const NetworkManager::VpnSetting::Ptr &setting, QWidget *parent)
......@@ -288,13 +292,28 @@ void OpenVpnAdvancedWidget::loadConfig()
if (dataMap.contains(QLatin1String(NM_OPENVPN_KEY_COMP_LZO))) {
const QString compLzo = dataMap[QLatin1String(NM_OPENVPN_KEY_COMP_LZO)];
if (compLzo == QLatin1String("no-by-default")) {
m_ui->cmbUseLZO->setCurrentIndex(0);
m_ui->cmbUseCompression->setCurrentIndex(Private::EnumCompression::None);
} else if (compLzo == QLatin1String("yes")) {
m_ui->cmbUseLZO->setCurrentIndex(1);
m_ui->cmbUseCompression->setCurrentIndex(Private::EnumCompression::LZO);
} else {
m_ui->cmbUseCompression->setCurrentIndex(Private::EnumCompression::Adaptive);
}
m_ui->chkUseCompression->setChecked(true);
}
if (dataMap.contains(QLatin1String(NM_OPENVPN_KEY_COMPRESS))) {
const QString compress = dataMap[QLatin1String(NM_OPENVPN_KEY_COMPRESS)];
if (compress == QLatin1String("lz4")) {
m_ui->cmbUseCompression->setCurrentIndex(Private::EnumCompression::LZ4);
} else if (compress == QLatin1String("lz4-v2")) {
m_ui->cmbUseCompression->setCurrentIndex(Private::EnumCompression::LZ4v2);
} else if (compress == QLatin1String("lzo")) {
m_ui->cmbUseCompression->setCurrentIndex(Private::EnumCompression::LZO);
} else if (compress == QLatin1String("yes")) {
m_ui->cmbUseCompression->setCurrentIndex(Private::EnumCompression::Automatic);
} else {
m_ui->cmbUseLZO->setCurrentIndex(2);
m_ui->cmbUseCompression->setCurrentIndex(Private::EnumCompression::Automatic);
}
m_ui->chkUseLZO->setChecked(true);
m_ui->chkUseCompression->setChecked(true);
}
m_ui->chkUseTCP->setChecked(dataMap[QLatin1String(NM_OPENVPN_KEY_PROTO_TCP)] == QLatin1String("yes"));
if (dataMap.contains(QLatin1String(NM_OPENVPN_KEY_DEV_TYPE))) {
......@@ -483,17 +502,26 @@ NetworkManager::VpnSetting::Ptr OpenVpnAdvancedWidget::setting() const
}
data.insert(QLatin1String(NM_OPENVPN_KEY_PROTO_TCP), m_ui->chkUseTCP->isChecked() ? QLatin1String("yes") : QLatin1String("no"));
if (m_ui->chkUseLZO->isChecked()) {
switch (m_ui->cmbUseLZO->currentIndex()) {
case 0:
if (m_ui->chkUseCompression->isChecked()) {
switch (m_ui->cmbUseCompression->currentIndex()) {
case Private::EnumCompression::None:
data.insert(QLatin1String(NM_OPENVPN_KEY_COMP_LZO), QLatin1String("no-by-default"));
break;
case 1:
data.insert(QLatin1String(NM_OPENVPN_KEY_COMP_LZO), QLatin1String("yes"));
case Private::EnumCompression::LZO:
data.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), QLatin1String("lzo"));
break;
case 2:
case Private::EnumCompression::LZ4:
data.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), QLatin1String("lz4"));
break;
case Private::EnumCompression::LZ4v2:
data.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), QLatin1String("lz4-v2"));
break;
case Private::EnumCompression::Adaptive:
data.insert(QLatin1String(NM_OPENVPN_KEY_COMP_LZO), QLatin1String("adaptive"));
break;
case Private::EnumCompression::Automatic:
data.insert(QLatin1String(NM_OPENVPN_KEY_COMPRESS), QLatin1String("yes"));
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment