diff --git a/src/settings/iptunnelsetting.cpp b/src/settings/iptunnelsetting.cpp index f5620a9..77d4c49 100644 --- a/src/settings/iptunnelsetting.cpp +++ b/src/settings/iptunnelsetting.cpp @@ -1,392 +1,392 @@ /* Copyright Pranav Gade This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "iptunnelsetting.h" #include "iptunnelsetting_p.h" #include #if NM_CHECK_VERSION(1, 12, 0) #define NM_SETTING_IP_TUNNEL_FLAGS "flags" #endif NetworkManager::IpTunnelSettingPrivate::IpTunnelSettingPrivate() : name(NM_SETTING_IP_TUNNEL_SETTING_NAME) , mode(IpTunnelSetting::Unknown) , pathMtuDiscovery(true) , encapsulationLimit(0) - , flags(IpTunnelSetting::Unknown) + , flags(IpTunnelSetting::None) , flowLabel(0) , mtu(0) , tos(0) , ttl(0) { } NetworkManager::IpTunnelSetting::IpTunnelSetting() : Setting(Setting::IpTunnel) , d_ptr(new IpTunnelSettingPrivate()) { } NetworkManager::IpTunnelSetting::IpTunnelSetting(const Ptr &other) : Setting(other) , d_ptr(new IpTunnelSettingPrivate()) { setMode(other->mode()); setPathMtuDiscovery(other->pathMtuDiscovery()); setEncapsulationLimit(other->encapsulationLimit()); setFlags(other->flags()); setFlowLabel(other->flowLabel()); setMtu(other->mtu()); setTos(other->tos()); setTtl(other->ttl()); setInputKey(other->inputKey()); setLocal(other->local()); setOutputKey(other->outputKey()); setParent(other->parent()); setRemote(other->remote()); } NetworkManager::IpTunnelSetting::~IpTunnelSetting() { delete d_ptr; } QString NetworkManager::IpTunnelSetting::name() const { Q_D(const IpTunnelSetting); return d->name; } void NetworkManager::IpTunnelSetting::setMode(NetworkManager::IpTunnelSetting::Mode mode) { Q_D(IpTunnelSetting); d->mode = mode; } NetworkManager::IpTunnelSetting::Mode NetworkManager::IpTunnelSetting::mode() const { Q_D(const IpTunnelSetting); return d->mode; } void NetworkManager::IpTunnelSetting::setPathMtuDiscovery(bool discovery) { Q_D(IpTunnelSetting); d->pathMtuDiscovery = discovery; } bool NetworkManager::IpTunnelSetting::pathMtuDiscovery() const { Q_D(const IpTunnelSetting); return d->pathMtuDiscovery; } void NetworkManager::IpTunnelSetting::setEncapsulationLimit(quint32 limit) { Q_D(IpTunnelSetting); d->encapsulationLimit = limit; } quint32 NetworkManager::IpTunnelSetting::encapsulationLimit() const { Q_D(const IpTunnelSetting); return d->encapsulationLimit; } void NetworkManager::IpTunnelSetting::setFlags(NetworkManager::IpTunnelSetting::Flags flags) { Q_D(IpTunnelSetting); d->flags = flags; } NetworkManager::IpTunnelSetting::Flags NetworkManager::IpTunnelSetting::flags() const { Q_D(const IpTunnelSetting); return d->flags; } void NetworkManager::IpTunnelSetting::setFlowLabel(quint32 label) { Q_D(IpTunnelSetting); d->flowLabel = label; } quint32 NetworkManager::IpTunnelSetting::flowLabel() const { Q_D(const IpTunnelSetting); return d->flowLabel; } void NetworkManager::IpTunnelSetting::setMtu(quint32 mtu) { Q_D(IpTunnelSetting); d->mtu = mtu; } quint32 NetworkManager::IpTunnelSetting::mtu() const { Q_D(const IpTunnelSetting); return d->mtu; } void NetworkManager::IpTunnelSetting::setTos(quint32 tos) { Q_D(IpTunnelSetting); d->tos = tos; } quint32 NetworkManager::IpTunnelSetting::tos() const { Q_D(const IpTunnelSetting); return d->tos; } void NetworkManager::IpTunnelSetting::setTtl(quint32 ttl) { Q_D(IpTunnelSetting); d->ttl = ttl; } quint32 NetworkManager::IpTunnelSetting::ttl() const { Q_D(const IpTunnelSetting); return d->ttl; } void NetworkManager::IpTunnelSetting::setInputKey(const QString &key) { Q_D(IpTunnelSetting); d->inputKey = key; } QString NetworkManager::IpTunnelSetting::inputKey() const { Q_D(const IpTunnelSetting); return d->inputKey; } void NetworkManager::IpTunnelSetting::setLocal(const QString &local) { Q_D(IpTunnelSetting); d->local = local; } QString NetworkManager::IpTunnelSetting::local() const { Q_D(const IpTunnelSetting); return d->local; } void NetworkManager::IpTunnelSetting::setParent(const QString &parent) { Q_D(IpTunnelSetting); d->parent = parent; } QString NetworkManager::IpTunnelSetting::parent() const { Q_D(const IpTunnelSetting); return d->parent; } void NetworkManager::IpTunnelSetting::setOutputKey(const QString &key) { Q_D(IpTunnelSetting); d->outputKey = key; } QString NetworkManager::IpTunnelSetting::outputKey() const { Q_D(const IpTunnelSetting); return d->outputKey; } void NetworkManager::IpTunnelSetting::setRemote(const QString &remote) { Q_D(IpTunnelSetting); d->remote = remote; } QString NetworkManager::IpTunnelSetting::remote() const { Q_D(const IpTunnelSetting); return d->remote; } void NetworkManager::IpTunnelSetting::fromMap(const QVariantMap &setting) { if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_MODE))) { setMode((Mode)setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_MODE)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY))) { setPathMtuDiscovery(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY)).toBool()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT))) { setEncapsulationLimit(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS))) { setFlags((Flag)setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL))) { setFlowLabel(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_MTU))) { setMtu(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_MTU)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_TOS))) { setTos(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_TOS)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_TTL))) { setTtl(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_TTL)).toUInt()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY))) { setInputKey(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY)).toString()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL))) { setLocal(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL)).toString()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT))) { setParent(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT)).toString()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY))) { setOutputKey(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY)).toString()); } if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE))) { setRemote(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE)).toString()); } } QVariantMap NetworkManager::IpTunnelSetting::toMap() const { QVariantMap setting; setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY), pathMtuDiscovery()); if (mode() != Unknown) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_MODE), (int)mode()); } if (encapsulationLimit() > 0) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT), encapsulationLimit()); } if (flags() > None) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS), (int)flags()); } if (flowLabel() > 0) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL), flowLabel()); } if (mtu() > 0) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_MTU), mtu()); } if (tos() > 0) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_TOS), tos()); } if (ttl() > 0) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_TTL), ttl()); } if (!inputKey().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY), inputKey()); } if (!local().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL), local()); } if (!parent().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT), parent()); } if (!outputKey().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY), outputKey()); } if (!remote().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE), remote()); } return setting; } QDebug NetworkManager::operator <<(QDebug dbg, const NetworkManager::IpTunnelSetting &setting) { dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_MODE << ": " << setting.mode() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY << ": " << setting.pathMtuDiscovery() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT << ": " << setting.encapsulationLimit() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_FLAGS << ": " << setting.flags() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_FLOW_LABEL << ": " << setting.flowLabel() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_MTU << ": " << setting.mtu() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_TOS << ": " << setting.tos() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_TTL << ": " << setting.ttl() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_INPUT_KEY << ": " << setting.inputKey() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_LOCAL << ": " << setting.local() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_PARENT << ": " << setting.parent() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_OUTPUT_KEY << ": " << setting.outputKey() << '\n'; dbg.nospace() << NM_SETTING_IP_TUNNEL_REMOTE << ": " << setting.remote() << '\n'; return dbg.maybeSpace(); } diff --git a/src/settings/iptunnelsetting.h b/src/settings/iptunnelsetting.h index a8e0711..8070828 100644 --- a/src/settings/iptunnelsetting.h +++ b/src/settings/iptunnelsetting.h @@ -1,126 +1,136 @@ /* Copyright 2018 Pranav Gade This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef NETWORKMANAGERQT_IPTUNNEL_SETTING_H #define NETWORKMANAGERQT_IPTUNNEL_SETTING_H #include #include "setting.h" +#if !NM_CHECK_VERSION(1, 12, 0) +#define NM_IP_TUNNEL_FLAG_NONE 0x0 +#define NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT 0x1 +#define NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS 0x2 +#define NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL 0x4 +#define NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV 0x8 +#define NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY 0x10 +#define NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK 0x20 +#endif + namespace NetworkManager { class IpTunnelSettingPrivate; /** * Represents IpTunnel setting */ class NETWORKMANAGERQT_EXPORT IpTunnelSetting : public Setting { public: typedef QSharedPointer Ptr; typedef QList List; enum Mode { Unknown = NM_IP_TUNNEL_MODE_UNKNOWN, Ipip = NM_IP_TUNNEL_MODE_IPIP, Gre = NM_IP_TUNNEL_MODE_GRE, Sit = NM_IP_TUNNEL_MODE_SIT, Isatap = NM_IP_TUNNEL_MODE_ISATAP, Vti = NM_IP_TUNNEL_MODE_VTI, Ip6ip6 = NM_IP_TUNNEL_MODE_IP6IP6, Ipip6 = NM_IP_TUNNEL_MODE_IPIP6, Ip6gre = NM_IP_TUNNEL_MODE_IP6GRE, Vti6 = NM_IP_TUNNEL_MODE_VTI }; enum Flag { None = NM_IP_TUNNEL_FLAG_NONE, Ip6IgnEncapLimit = NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT, Ip6UseOrigTclass = NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS, Ip6UseOrigFlowlabel = NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL, Ip6Mip6Dev = NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV, Ip6RcvDscpCopy = NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY, Ip6UseOrigFwmark = NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK }; Q_DECLARE_FLAGS(Flags, Flag) IpTunnelSetting(); explicit IpTunnelSetting(const Ptr &other); ~IpTunnelSetting() override; QString name() const override; void setMode(Mode mode); Mode mode() const; void setPathMtuDiscovery(bool discovery); bool pathMtuDiscovery() const; void setEncapsulationLimit(quint32 limit); quint32 encapsulationLimit() const; void setFlags(Flags flags); Flags flags() const; void setFlowLabel(quint32 label); quint32 flowLabel() const; void setMtu(quint32 mtu); quint32 mtu() const; void setTos(quint32 tos); quint32 tos() const; void setTtl(quint32 ttl); quint32 ttl() const; void setInputKey(const QString &key); QString inputKey() const; void setLocal(const QString &local); QString local() const; void setParent(const QString &parent); QString parent() const; void setOutputKey(const QString &key); QString outputKey() const; void setRemote(const QString &remote); QString remote() const; void fromMap(const QVariantMap &setting) override; QVariantMap toMap() const override; protected: IpTunnelSettingPrivate *d_ptr; private: Q_DECLARE_PRIVATE(IpTunnelSetting) }; Q_DECLARE_OPERATORS_FOR_FLAGS(IpTunnelSetting::Flags) NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const IpTunnelSetting &setting); } #endif // NETWORKMANAGERQT_IP_TUNNEL_SETTING_H