NetworkManagerQt

ipv6setting.cpp
1/*
2 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com>
3 SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "ipv6setting.h"
9#include "ipv6setting_p.h"
10
11#include "../ipconfig.h"
12#include "generictypes.h"
13#include "utils.h"
14
15#include <arpa/inet.h>
16
17NetworkManager::Ipv6SettingPrivate::Ipv6SettingPrivate()
18 : name(NMQT_SETTING_IP6_CONFIG_SETTING_NAME)
19 , method(NetworkManager::Ipv6Setting::Automatic)
20 , routeMetric(-1)
21 , ignoreAutoRoutes(false)
22 , ignoreAutoDns(false)
23 , neverDefault(false)
24 , mayFail(true)
25 , privacy(NetworkManager::Ipv6Setting::Unknown)
26 , dadTimeout(-1)
27 , addressGenMode(NetworkManager::Ipv6Setting::StablePrivacy)
28 , dhcpTimeout(0)
29 , routeTable(0)
30{
31}
32
33NetworkManager::Ipv6Setting::Ipv6Setting()
34 : Setting(Setting::Ipv6)
35 , d_ptr(new Ipv6SettingPrivate())
36{
37}
38
39NetworkManager::Ipv6Setting::Ipv6Setting(const Ptr &other)
40 : Setting(other)
41 , d_ptr(new Ipv6SettingPrivate())
42{
43 setMethod(other->method());
44 setDns(other->dns());
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());
63}
64
65NetworkManager::Ipv6Setting::~Ipv6Setting()
66{
67 delete d_ptr;
68}
69
71{
72 Q_D(const Ipv6Setting);
73
74 return d->name;
75}
76
77void NetworkManager::Ipv6Setting::setMethod(NetworkManager::Ipv6Setting::ConfigMethod type)
78{
80
81 d->method = type;
82}
83
84NetworkManager::Ipv6Setting::ConfigMethod NetworkManager::Ipv6Setting::method() const
85{
86 Q_D(const Ipv6Setting);
87
88 return d->method;
89}
90
91void NetworkManager::Ipv6Setting::setDns(const QList<QHostAddress> &dns)
92{
93 Q_D(Ipv6Setting);
94
95 d->dns = dns;
96}
97
98QList<QHostAddress> NetworkManager::Ipv6Setting::dns() const
99{
100 Q_D(const Ipv6Setting);
101
102 return d->dns;
103}
104
105void NetworkManager::Ipv6Setting::setDnsSearch(const QStringList &domains)
106{
107 Q_D(Ipv6Setting);
108
109 d->dnsSearch = domains;
110}
111
112QStringList NetworkManager::Ipv6Setting::dnsSearch() const
113{
114 Q_D(const Ipv6Setting);
115
116 return d->dnsSearch;
117}
118
119void NetworkManager::Ipv6Setting::setAddresses(const QList<IpAddress> ipv6addresses)
120{
121 Q_D(Ipv6Setting);
122
123 d->addresses = ipv6addresses;
124}
125
126QList<NetworkManager::IpAddress> NetworkManager::Ipv6Setting::addresses() const
127{
128 Q_D(const Ipv6Setting);
129
130 return d->addresses;
131}
132
133void NetworkManager::Ipv6Setting::setRoutes(const QList<NetworkManager::IpRoute> ipv6routes)
134{
135 Q_D(Ipv6Setting);
136
137 d->routes = ipv6routes;
138}
139
140QList<NetworkManager::IpRoute> NetworkManager::Ipv6Setting::routes() const
141{
142 Q_D(const Ipv6Setting);
143
144 return d->routes;
145}
146
147void NetworkManager::Ipv6Setting::setRouteMetric(int metric)
148{
149 Q_D(Ipv6Setting);
150
151 d->routeMetric = metric;
152}
153
154int NetworkManager::Ipv6Setting::routeMetric() const
155{
156 Q_D(const Ipv6Setting);
157
158 return d->routeMetric;
159}
160
161void NetworkManager::Ipv6Setting::setIgnoreAutoRoutes(bool ignore)
162{
163 Q_D(Ipv6Setting);
164
165 d->ignoreAutoRoutes = ignore;
166}
167
168bool NetworkManager::Ipv6Setting::ignoreAutoRoutes() const
169{
170 Q_D(const Ipv6Setting);
171
172 return d->ignoreAutoRoutes;
173}
174
175void NetworkManager::Ipv6Setting::setIgnoreAutoDns(bool ignore)
176{
177 Q_D(Ipv6Setting);
178
179 d->ignoreAutoDns = ignore;
180}
181
182bool NetworkManager::Ipv6Setting::ignoreAutoDns() const
183{
184 Q_D(const Ipv6Setting);
185
186 return d->ignoreAutoDns;
187}
188
189void NetworkManager::Ipv6Setting::setNeverDefault(bool neverDefault)
190{
191 Q_D(Ipv6Setting);
192
193 d->neverDefault = neverDefault;
194}
195
196bool NetworkManager::Ipv6Setting::neverDefault() const
197{
198 Q_D(const Ipv6Setting);
199
200 return d->neverDefault;
201}
202
203void NetworkManager::Ipv6Setting::setMayFail(bool mayFail)
204{
205 Q_D(Ipv6Setting);
206
207 d->mayFail = mayFail;
208}
209
210bool NetworkManager::Ipv6Setting::mayFail() const
211{
212 Q_D(const Ipv6Setting);
213
214 return d->mayFail;
215}
216
217void NetworkManager::Ipv6Setting::setPrivacy(IPv6Privacy privacy)
218{
219 Q_D(Ipv6Setting);
220
221 d->privacy = privacy;
222}
223
224NetworkManager::Ipv6Setting::IPv6Privacy NetworkManager::Ipv6Setting::privacy() const
225{
226 Q_D(const Ipv6Setting);
227
228 return d->privacy;
229}
230
231void NetworkManager::Ipv6Setting::setDadTimeout(qint32 timeout)
232{
233 Q_D(Ipv6Setting);
234
235 d->dadTimeout = timeout;
236}
237
238qint32 NetworkManager::Ipv6Setting::dadTimeout() const
239{
240 Q_D(const Ipv6Setting);
241
242 return d->dadTimeout;
243}
244
245void NetworkManager::Ipv6Setting::setDhcpTimeout(qint32 timeout)
246{
247 Q_D(Ipv6Setting);
248
249 d->dhcpTimeout = timeout;
250}
251
252qint32 NetworkManager::Ipv6Setting::dhcpTimeout() const
253{
254 Q_D(const Ipv6Setting);
255
256 return d->dhcpTimeout;
257}
258
259void NetworkManager::Ipv6Setting::setDhcpHostname(const QString &hostname)
260{
261 Q_D(Ipv6Setting);
262
263 d->dhcpHostname = hostname;
264}
265
266QString NetworkManager::Ipv6Setting::dhcpHostname() const
267{
268 Q_D(const Ipv6Setting);
269
270 return d->dhcpHostname;
271}
272
273void NetworkManager::Ipv6Setting::setDhcpDuid(const QString &duid)
274{
275 Q_D(Ipv6Setting);
276
277 d->dhcpDuid = duid;
278}
279
280QString NetworkManager::Ipv6Setting::dhcpDuid() const
281{
282 Q_D(const Ipv6Setting);
283
284 return d->dhcpDuid;
285}
286
287void NetworkManager::Ipv6Setting::setDnsOptions(const QStringList &options)
288{
289 Q_D(Ipv6Setting);
290
291 d->dnsOptions = options;
292}
293
294QStringList NetworkManager::Ipv6Setting::dnsOptions() const
295{
296 Q_D(const Ipv6Setting);
297
298 return d->dnsOptions;
299}
300
301void NetworkManager::Ipv6Setting::setAddressData(const NMVariantMapList &addressData)
302{
303 Q_D(Ipv6Setting);
304
305 d->addressData = addressData;
306}
307
308NMVariantMapList NetworkManager::Ipv6Setting::addressData() const
309{
310 Q_D(const Ipv6Setting);
311
312 return d->addressData;
313}
314
315void NetworkManager::Ipv6Setting::setAddressGenMode(IPv6AddressGenMode mode)
316{
317 Q_D(Ipv6Setting);
318
319 d->addressGenMode = mode;
320}
321
322NetworkManager::Ipv6Setting::IPv6AddressGenMode NetworkManager::Ipv6Setting::addressGenMode() const
323{
324 Q_D(const Ipv6Setting);
325
326 return d->addressGenMode;
327}
328
329void NetworkManager::Ipv6Setting::setRouteData(const NMVariantMapList &routeData)
330{
331 Q_D(Ipv6Setting);
332
333 d->routeData = routeData;
334}
335
336NMVariantMapList NetworkManager::Ipv6Setting::routeData() const
337{
338 Q_D(const Ipv6Setting);
339
340 return d->routeData;
341}
342
343void NetworkManager::Ipv6Setting::setToken(const QString &token)
344{
345 Q_D(Ipv6Setting);
346
347 d->token = token;
348}
349
350QString NetworkManager::Ipv6Setting::token() const
351{
352 Q_D(const Ipv6Setting);
353
354 return d->token;
355}
356
357void NetworkManager::Ipv6Setting::setRouteTable(quint32 routeTable)
358{
359 Q_D(Ipv6Setting);
360
361 d->routeTable = routeTable;
362}
363
364quint32 NetworkManager::Ipv6Setting::routeTable() const
365{
366 Q_D(const Ipv6Setting);
367
368 return d->routeTable;
369}
370
371void NetworkManager::Ipv6Setting::fromMap(const QVariantMap &setting)
372{
373 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD))) {
374 const QString methodType = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD)).toString();
375
376 if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_AUTO)) {
377 setMethod(Automatic);
378 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DHCP)) {
379 setMethod(Dhcp);
380 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) {
381 setMethod(LinkLocal);
382 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
383 setMethod(Manual);
384 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
385 setMethod(Ignored);
386 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DISABLED)) {
387 setMethod(ConfigDisabled);
388 } else {
389 setMethod(Automatic);
390 }
391 }
392
393 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS))) {
394 QList<QHostAddress> dbusDns;
396 if (setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).canConvert<QDBusArgument>()) {
397 QDBusArgument dnsArg = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).value<QDBusArgument>();
398 temp = qdbus_cast<QList<QByteArray>>(dnsArg);
399 } else {
400 temp = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).value<QList<QByteArray>>();
401 }
402
403 for (const QByteArray &utmp : std::as_const(temp)) {
404 dbusDns << ipv6AddressAsHostAddress(utmp);
405 }
406
407 setDns(dbusDns);
408 }
409
410 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH))) {
411 setDnsSearch(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH)).toStringList());
412 }
413
414 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES))) {
416 if (setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES)).canConvert<QDBusArgument>()) {
417 QDBusArgument addressArg = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES)).value<QDBusArgument>();
418 temp = qdbus_cast<QList<IpV6DBusAddress>>(addressArg);
419 } else {
420 temp = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES)).value<QList<IpV6DBusAddress>>();
421 }
423
424 for (const IpV6DBusAddress &addressMap : std::as_const(temp)) {
425 if (addressMap.address.isEmpty() || !addressMap.prefix || addressMap.gateway.isEmpty()) {
426 continue;
427 }
428
430 address.setIp(ipv6AddressAsHostAddress(addressMap.address));
431 address.setPrefixLength(addressMap.prefix);
432 address.setGateway(ipv6AddressAsHostAddress(addressMap.gateway));
433 if (!address.isValid()) {
434 continue;
435 }
436
437 addresses << address;
438 }
439
440 setAddresses(addresses);
441 }
442
443 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES))) {
445 if (setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).canConvert<QDBusArgument>()) {
446 QDBusArgument routeArg = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).value<QDBusArgument>();
447 temp = qdbus_cast<QList<IpV6DBusRoute>>(routeArg);
448 } else {
449 temp = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).value<QList<IpV6DBusRoute>>();
450 }
452
453 for (const IpV6DBusRoute &routeMap : std::as_const(temp)) {
454 if (routeMap.destination.isEmpty() || !routeMap.prefix || routeMap.nexthop.isEmpty() || !routeMap.metric) {
455 continue;
456 }
457
459 route.setIp(ipv6AddressAsHostAddress(routeMap.destination));
460 route.setPrefixLength(routeMap.prefix);
461 route.setNextHop(ipv6AddressAsHostAddress(routeMap.nexthop));
462 route.setMetric(routeMap.metric);
463 if (!route.isValid()) {
464 continue;
465 }
466
467 routes << route;
468 }
469 setRoutes(routes);
470 }
471
472 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC))) {
473 setRouteMetric(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC)).toInt());
474 }
475
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());
478 }
479
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());
482 }
483
484 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT))) {
485 setNeverDefault(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT)).toBool());
486 }
487
488 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL))) {
489 setMayFail(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL)).toBool());
490 }
491
492 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY))) {
493 setPrivacy((IPv6Privacy)setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY)).toUInt());
494 }
495
496 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT))) {
497 setDadTimeout(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT)).toUInt());
498 }
499
500 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT))) {
501 setDhcpTimeout(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT)).toUInt());
502 }
503
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()));
506 }
507
508 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME))) {
509 setDhcpHostname(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME)).toString());
510 }
511
512 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID))) {
513 setDhcpDuid(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID)).toString());
514 }
515
516 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN))) {
517 setToken(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN)).toString());
518 }
519
520 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS))) {
521 setDnsOptions(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS)).toStringList());
522 }
523
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))));
526 }
527
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))));
530 }
531
532 if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE))) {
533 setRouteTable(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE)).toUInt());
534 }
535}
536
538{
539 QVariantMap setting;
540
541 if (method() == Automatic) {
542 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_AUTO));
543 } else if (method() == Dhcp) {
544 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DHCP));
545 } else if (method() == LinkLocal) {
546 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL));
547 } else if (method() == Manual) {
548 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_MANUAL));
549 } else if (method() == Ignored) {
550 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_IGNORE));
551 } else if (method() == ConfigDisabled) {
552 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DISABLED));
553 }
554
555 if (!dns().isEmpty()) {
556 QList<QByteArray> dbusDns;
557 const QList<QHostAddress> dnsList = dns();
558 for (const QHostAddress &dns : dnsList) {
559 dbusDns << ipv6AddressFromHostAddress(dns);
560 }
561 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS), QVariant::fromValue(dbusDns));
562 }
563
564 if (!dnsSearch().isEmpty()) {
565 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH), dnsSearch());
566 }
567
568 if (!addresses().isEmpty()) {
569 QList<IpV6DBusAddress> dbusAddresses;
570 const QList<NetworkManager::IpAddress> addressesList = addresses();
571 for (const NetworkManager::IpAddress &addr : addressesList) {
572 IpV6DBusAddress dbusAddress;
573 dbusAddress.address = ipv6AddressFromHostAddress(addr.ip());
574 dbusAddress.prefix = addr.prefixLength();
575 dbusAddress.gateway = ipv6AddressFromHostAddress(addr.gateway());
576 dbusAddresses << dbusAddress;
577 }
578
579 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES), QVariant::fromValue(dbusAddresses));
580 }
581
582 if (!routes().isEmpty()) {
583 QList<IpV6DBusRoute> dbusRoutes;
584 const QList<NetworkManager::IpRoute> routesList = routes();
585 for (const NetworkManager::IpRoute &route : routesList) {
586 IpV6DBusRoute dbusRoute;
587 dbusRoute.destination = ipv6AddressFromHostAddress(route.ip());
588 dbusRoute.prefix = route.prefixLength();
589 dbusRoute.nexthop = ipv6AddressFromHostAddress(route.nextHop());
590 dbusRoute.metric = route.metric();
591 dbusRoutes << dbusRoute;
592 }
593
594 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES), QVariant::fromValue(dbusRoutes));
595 }
596
597 if (routeMetric() >= 0) {
598 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC), routeMetric());
599 }
600
601 if (ignoreAutoRoutes()) {
602 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES), ignoreAutoRoutes());
603 }
604
605 if (ignoreAutoDns()) {
606 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS), ignoreAutoDns());
607 }
608
609 if (neverDefault()) {
610 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT), neverDefault());
611 }
612
613 if (!mayFail()) {
614 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL), mayFail());
615 }
616
617 if (privacy() != Unknown) {
618 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY), privacy());
619 }
620
621 if (dadTimeout() >= 0) {
622 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT), dadTimeout());
623 }
624
625 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE), addressGenMode());
626
627 if (dhcpTimeout() > 0) {
628 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT), dhcpTimeout());
629 }
630
631 if (!dhcpHostname().isEmpty()) {
632 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME), dhcpHostname());
633 }
634
635 if (!dhcpDuid().isEmpty()) {
636 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID), dhcpDuid());
637 }
638
639 if (!token().isEmpty()) {
640 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN), token());
641 }
642
643 if (!dnsOptions().isEmpty()) {
644 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS), dnsOptions());
645 }
646
647 if (!addressData().empty()) {
648 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA), QVariant::fromValue(addressData()));
649 }
650
651 if (!routeData().empty()) {
652 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA), QVariant::fromValue(routeData()));
653 }
654
655 if (routeTable() > 0) {
656 setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE), routeTable());
657 }
658
659 return setting;
660}
661
662QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::Ipv6Setting &setting)
663{
664 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
665 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
666
667 dbg.nospace() << NMQT_SETTING_IP6_CONFIG_METHOD << ": " << setting.method() << '\n';
668 dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DNS << '\n';
669 const QList<QHostAddress> hostAdresses = setting.dns();
670 for (const QHostAddress &address : hostAdresses) {
671 dbg.nospace() << address.toString() << '\n';
672 }
673 dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DNS_SEARCH << ": " << setting.dnsSearch() << '\n';
674 dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ADDRESSES << '\n';
675 const QList<NetworkManager::IpAddress> ipList = setting.addresses();
676 for (const NetworkManager::IpAddress &address : ipList) {
677 dbg.nospace() << address.ip().toString() << ": " << address.gateway().toString() << ": " << address.netmask() << '\n';
678 }
679 dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ROUTES << '\n';
680 const QList<NetworkManager::IpRoute> routesList = setting.routes();
681 for (const NetworkManager::IpRoute &route : routesList) {
682 dbg.nospace() << route.ip().toString() << ": " << route.metric() << ": " << route.nextHop().toString() << ": " << route.metric() << '\n';
683 }
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';
703 }
704 }
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';
711 }
712 }
713 dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE << ": " << setting.routeTable() << '\n';
714
715 return dbg.maybeSpace();
716}
This class represents IP address.
Definition ipaddress.h:21
This class represents IP route.
Definition iproute.h:22
void setMetric(quint32 metric)
Defines the metric of the given route, lower values have higher priority.
Definition iproute.cpp:52
bool isValid() const
Returns true if the route IP is defined.
Definition iproute.cpp:74
void setNextHop(const QHostAddress &nextHop) const
Defines the next hop of the given route.
Definition iproute.cpp:42
Represents ipv6 setting.
Definition ipv6setting.h:71
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...
Definition accesspoint.h:21
@ Unknown
the networking system is not active or unable to report its status - proceed with caution
Definition manager.h:33
NETWORKMANAGERQT_EXPORT QByteArray ipv6AddressFromHostAddress(const QHostAddress &address)
Definition utils.cpp:26
NETWORKMANAGERQT_EXPORT QString hostname()
Returns hostname of the machine.
Definition settings.cpp:260
NETWORKMANAGERQT_EXPORT QHostAddress ipv6AddressAsHostAddress(const QByteArray &address)
Definition utils.cpp:13
QDebug & maybeSpace()
QDebug & nospace()
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)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.