8#include "ipv6setting.h"
9#include "ipv6setting_p.h"
11#include "../ipconfig.h"
12#include "generictypes.h"
17NetworkManager::Ipv6SettingPrivate::Ipv6SettingPrivate()
18 : name(NMQT_SETTING_IP6_CONFIG_SETTING_NAME)
21 , ignoreAutoRoutes(false)
22 , ignoreAutoDns(false)
33NetworkManager::Ipv6Setting::Ipv6Setting()
34 : Setting(Setting::Ipv6)
35 , d_ptr(new Ipv6SettingPrivate())
39NetworkManager::Ipv6Setting::Ipv6Setting(
const Ptr &other)
41 , d_ptr(new Ipv6SettingPrivate())
43 setMethod(other->method());
45 setDnsSearch(other->dnsSearch());
46 setAddresses(other->addresses());
47 setRoutes(other->routes());
48 setRouteMetric(other->routeMetric());
49 setIgnoreAutoRoutes(other->ignoreAutoRoutes());
50 setIgnoreAutoDns(other->ignoreAutoDns());
51 setNeverDefault(other->neverDefault());
52 setMayFail(other->mayFail());
53 setDadTimeout(other->dadTimeout());
54 setAddressGenMode(other->addressGenMode());
55 setDhcpTimeout(other->dhcpTimeout());
56 setDhcpHostname(other->dhcpHostname());
57 setDhcpDuid(other->dhcpDuid());
58 setToken(other->token());
59 setDnsOptions(other->dnsOptions());
60 setAddressData(other->addressData());
61 setRouteData(other->routeData());
62 setRouteTable(other->routeTable());
65NetworkManager::Ipv6Setting::~Ipv6Setting()
77void NetworkManager::Ipv6Setting::setMethod(NetworkManager::Ipv6Setting::ConfigMethod type)
84NetworkManager::Ipv6Setting::ConfigMethod NetworkManager::Ipv6Setting::method()
const
86 Q_D(
const Ipv6Setting);
100 Q_D(
const Ipv6Setting);
105void NetworkManager::Ipv6Setting::setDnsSearch(
const QStringList &domains)
109 d->dnsSearch = domains;
112QStringList NetworkManager::Ipv6Setting::dnsSearch()
const
114 Q_D(
const Ipv6Setting);
119void NetworkManager::Ipv6Setting::setAddresses(
const QList<IpAddress> ipv6addresses)
123 d->addresses = ipv6addresses;
128 Q_D(
const Ipv6Setting);
137 d->routes = ipv6routes;
142 Q_D(
const Ipv6Setting);
147void NetworkManager::Ipv6Setting::setRouteMetric(
int metric)
151 d->routeMetric = metric;
154int NetworkManager::Ipv6Setting::routeMetric()
const
156 Q_D(
const Ipv6Setting);
158 return d->routeMetric;
161void NetworkManager::Ipv6Setting::setIgnoreAutoRoutes(
bool ignore)
165 d->ignoreAutoRoutes = ignore;
168bool NetworkManager::Ipv6Setting::ignoreAutoRoutes()
const
170 Q_D(
const Ipv6Setting);
172 return d->ignoreAutoRoutes;
175void NetworkManager::Ipv6Setting::setIgnoreAutoDns(
bool ignore)
179 d->ignoreAutoDns = ignore;
182bool NetworkManager::Ipv6Setting::ignoreAutoDns()
const
184 Q_D(
const Ipv6Setting);
186 return d->ignoreAutoDns;
189void NetworkManager::Ipv6Setting::setNeverDefault(
bool neverDefault)
193 d->neverDefault = neverDefault;
196bool NetworkManager::Ipv6Setting::neverDefault()
const
198 Q_D(
const Ipv6Setting);
200 return d->neverDefault;
203void NetworkManager::Ipv6Setting::setMayFail(
bool mayFail)
207 d->mayFail = mayFail;
210bool NetworkManager::Ipv6Setting::mayFail()
const
212 Q_D(
const Ipv6Setting);
217void NetworkManager::Ipv6Setting::setPrivacy(IPv6Privacy privacy)
221 d->privacy = privacy;
224NetworkManager::Ipv6Setting::IPv6Privacy NetworkManager::Ipv6Setting::privacy()
const
226 Q_D(
const Ipv6Setting);
231void NetworkManager::Ipv6Setting::setDadTimeout(qint32 timeout)
235 d->dadTimeout = timeout;
238qint32 NetworkManager::Ipv6Setting::dadTimeout()
const
240 Q_D(
const Ipv6Setting);
242 return d->dadTimeout;
245void NetworkManager::Ipv6Setting::setDhcpTimeout(qint32 timeout)
249 d->dhcpTimeout = timeout;
252qint32 NetworkManager::Ipv6Setting::dhcpTimeout()
const
254 Q_D(
const Ipv6Setting);
256 return d->dhcpTimeout;
259void NetworkManager::Ipv6Setting::setDhcpHostname(
const QString &
hostname)
266QString NetworkManager::Ipv6Setting::dhcpHostname()
const
268 Q_D(
const Ipv6Setting);
270 return d->dhcpHostname;
273void NetworkManager::Ipv6Setting::setDhcpDuid(
const QString &duid)
280QString NetworkManager::Ipv6Setting::dhcpDuid()
const
282 Q_D(
const Ipv6Setting);
287void NetworkManager::Ipv6Setting::setDnsOptions(
const QStringList &options)
291 d->dnsOptions = options;
294QStringList NetworkManager::Ipv6Setting::dnsOptions()
const
296 Q_D(
const Ipv6Setting);
298 return d->dnsOptions;
301void NetworkManager::Ipv6Setting::setAddressData(
const NMVariantMapList &addressData)
305 d->addressData = addressData;
310 Q_D(
const Ipv6Setting);
312 return d->addressData;
315void NetworkManager::Ipv6Setting::setAddressGenMode(IPv6AddressGenMode mode)
319 d->addressGenMode = mode;
322NetworkManager::Ipv6Setting::IPv6AddressGenMode NetworkManager::Ipv6Setting::addressGenMode()
const
324 Q_D(
const Ipv6Setting);
326 return d->addressGenMode;
329void NetworkManager::Ipv6Setting::setRouteData(
const NMVariantMapList &routeData)
333 d->routeData = routeData;
338 Q_D(
const Ipv6Setting);
343void NetworkManager::Ipv6Setting::setToken(
const QString &token)
350QString NetworkManager::Ipv6Setting::token()
const
352 Q_D(
const Ipv6Setting);
357void NetworkManager::Ipv6Setting::setRouteTable(quint32 routeTable)
361 d->routeTable = routeTable;
364quint32 NetworkManager::Ipv6Setting::routeTable()
const
366 Q_D(
const Ipv6Setting);
368 return d->routeTable;
373 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD))) {
374 const QString methodType = setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD)).toString();
377 setMethod(Automatic);
381 setMethod(LinkLocal);
387 setMethod(ConfigDisabled);
389 setMethod(Automatic);
393 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS))) {
396 if (setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).canConvert<QDBusArgument>()) {
398 temp = qdbus_cast<QList<QByteArray>>(dnsArg);
403 for (
const QByteArray &utmp : std::as_const(temp)) {
410 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH))) {
411 setDnsSearch(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH)).toStringList());
414 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES))) {
416 if (setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES)).canConvert<QDBusArgument>()) {
418 temp = qdbus_cast<QList<IpV6DBusAddress>>(addressArg);
424 for (
const IpV6DBusAddress &addressMap : std::as_const(temp)) {
425 if (addressMap.address.isEmpty() || !addressMap.prefix || addressMap.gateway.isEmpty()) {
431 address.setPrefixLength(addressMap.prefix);
433 if (!address.isValid()) {
437 addresses << address;
440 setAddresses(addresses);
443 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES))) {
445 if (setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).canConvert<QDBusArgument>()) {
447 temp = qdbus_cast<QList<IpV6DBusRoute>>(routeArg);
453 for (
const IpV6DBusRoute &routeMap : std::as_const(temp)) {
454 if (routeMap.destination.isEmpty() || !routeMap.prefix || routeMap.nexthop.isEmpty() || !routeMap.metric) {
472 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC))) {
473 setRouteMetric(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC)).toInt());
476 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES))) {
477 setIgnoreAutoRoutes(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES)).toBool());
480 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS))) {
481 setIgnoreAutoDns(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS)).toBool());
484 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT))) {
485 setNeverDefault(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT)).toBool());
488 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL))) {
489 setMayFail(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL)).toBool());
492 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY))) {
493 setPrivacy((IPv6Privacy)setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY)).toUInt());
496 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT))) {
497 setDadTimeout(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT)).toUInt());
500 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT))) {
501 setDhcpTimeout(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT)).toUInt());
504 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE))) {
505 setAddressGenMode(
static_cast<IPv6AddressGenMode
>(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE)).toUInt()));
508 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME))) {
509 setDhcpHostname(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME)).toString());
512 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID))) {
513 setDhcpDuid(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID)).toString());
516 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN))) {
517 setToken(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN)).toString());
520 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS))) {
521 setDnsOptions(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS)).toStringList());
524 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA))) {
525 setRouteData(qdbus_cast<NMVariantMapList>(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA))));
528 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA))) {
529 setAddressData(qdbus_cast<NMVariantMapList>(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA))));
532 if (setting.contains(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE))) {
533 setRouteTable(setting.value(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE)).toUInt());
541 if (method() == Automatic) {
543 }
else if (method() == Dhcp) {
545 }
else if (method() == LinkLocal) {
547 }
else if (method() == Manual) {
549 }
else if (method() == Ignored) {
551 }
else if (method() == ConfigDisabled) {
555 if (!dns().isEmpty()) {
564 if (!dnsSearch().isEmpty()) {
565 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH), dnsSearch());
568 if (!addresses().isEmpty()) {
572 IpV6DBusAddress dbusAddress;
574 dbusAddress.prefix = addr.prefixLength();
576 dbusAddresses << dbusAddress;
582 if (!routes().isEmpty()) {
586 IpV6DBusRoute dbusRoute;
588 dbusRoute.prefix = route.prefixLength();
590 dbusRoute.metric = route.metric();
591 dbusRoutes << dbusRoute;
597 if (routeMetric() >= 0) {
598 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC), routeMetric());
601 if (ignoreAutoRoutes()) {
602 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES), ignoreAutoRoutes());
605 if (ignoreAutoDns()) {
606 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS), ignoreAutoDns());
609 if (neverDefault()) {
610 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT), neverDefault());
614 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL), mayFail());
618 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY), privacy());
621 if (dadTimeout() >= 0) {
622 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT), dadTimeout());
625 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE), addressGenMode());
627 if (dhcpTimeout() > 0) {
628 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT), dhcpTimeout());
631 if (!dhcpHostname().isEmpty()) {
632 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME), dhcpHostname());
635 if (!dhcpDuid().isEmpty()) {
636 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID), dhcpDuid());
639 if (!token().isEmpty()) {
640 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN), token());
643 if (!dnsOptions().isEmpty()) {
644 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS), dnsOptions());
647 if (!addressData().empty()) {
651 if (!routeData().empty()) {
655 if (routeTable() > 0) {
656 setting.insert(
QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE), routeTable());
664 dbg.
nospace() <<
"type: " << setting.typeAsString(setting.type()) <<
'\n';
665 dbg.
nospace() <<
"initialized: " << !setting.isNull() <<
'\n';
667 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_METHOD <<
": " << setting.method() <<
'\n';
668 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_DNS <<
'\n';
671 dbg.
nospace() << address.toString() <<
'\n';
673 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_DNS_SEARCH <<
": " << setting.dnsSearch() <<
'\n';
674 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_ADDRESSES <<
'\n';
677 dbg.
nospace() << address.ip().toString() <<
": " << address.gateway().toString() <<
": " << address.netmask() <<
'\n';
679 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_ROUTES <<
'\n';
682 dbg.
nospace() << route.ip().
toString() <<
": " << route.metric() <<
": " << route.nextHop().toString() <<
": " << route.metric() <<
'\n';
684 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC <<
":" << setting.routeMetric() <<
'\n';
685 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES <<
": " << setting.ignoreAutoRoutes() <<
'\n';
686 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS <<
": " << setting.ignoreAutoDns() <<
'\n';
687 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT <<
": " << setting.neverDefault() <<
'\n';
688 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_MAY_FAIL <<
": " << setting.mayFail() <<
'\n';
689 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY <<
": " << setting.privacy() <<
'\n';
690 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT <<
": " << setting.dadTimeout() <<
'\n';
691 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE <<
": " << setting.addressGenMode() <<
'\n';
692 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT <<
": " << setting.dhcpTimeout() <<
'\n';
693 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME <<
": " << setting.dhcpHostname() <<
'\n';
694 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_DHCP_DUID <<
": " << setting.dhcpDuid() <<
'\n';
695 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_TOKEN <<
": " << setting.token() <<
'\n';
696 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS <<
": " << setting.dnsOptions() <<
'\n';
697 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA <<
": " <<
'\n';
698 const auto dataList = setting.addressData();
699 for (
const QVariantMap &addressData : dataList) {
700 QVariantMap::const_iterator i = addressData.constBegin();
701 while (i != addressData.constEnd()) {
702 dbg.
nospace() << i.key() <<
": " << i.value() <<
'\n';
705 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_ROUTE_DATA <<
": " <<
'\n';
706 const auto routeDataList = setting.routeData();
707 for (
const QVariantMap &routeData : routeDataList) {
708 QVariantMap::const_iterator i = routeData.constBegin();
709 while (i != routeData.constEnd()) {
710 dbg.
nospace() << i.key() <<
": " << i.value() <<
'\n';
713 dbg.
nospace() << NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE <<
": " << setting.routeTable() <<
'\n';
This class represents IP address.
This class represents IP route.
void setMetric(quint32 metric)
Defines the metric of the given route, lower values have higher priority.
bool isValid() const
Returns true if the route IP is defined.
void setNextHop(const QHostAddress &nextHop) const
Defines the next hop of the given route.
QString name() const override
Must be reimplemented, default implementationd does nothing.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
This class allows querying the underlying system to discover the available network interfaces and rea...
@ Unknown
the networking system is not active or unable to report its status - proceed with caution
NETWORKMANAGERQT_EXPORT QByteArray ipv6AddressFromHostAddress(const QHostAddress &address)
NETWORKMANAGERQT_EXPORT QString hostname()
Returns hostname of the machine.
NETWORKMANAGERQT_EXPORT QHostAddress ipv6AddressAsHostAddress(const QByteArray &address)
QString toString(T &&object)
T value(qsizetype i) const const
void setIp(const QHostAddress &newIp)
void setPrefixLength(int length)
QString toLower() const const
QVariant fromValue(T &&value)