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
70QString NetworkManager::Ipv6Setting::name() const
71{
72 Q_D(const Ipv6Setting);
73
74 return d->name;
75}
76
77void NetworkManager::Ipv6Setting::setMethod(NetworkManager::Ipv6Setting::ConfigMethod type)
78{
79 Q_D(Ipv6Setting);
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(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD))) {
374 const QString methodType = setting.value(key: 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(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS))) {
394 QList<QHostAddress> dbusDns;
395 QList<QByteArray> temp;
396 if (setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).canConvert<QDBusArgument>()) {
397 QDBusArgument dnsArg = setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).value<QDBusArgument>();
398 temp = qdbus_cast<QList<QByteArray>>(arg: dnsArg);
399 } else {
400 temp = setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).value<QList<QByteArray>>();
401 }
402
403 for (const QByteArray &utmp : std::as_const(t&: temp)) {
404 dbusDns << ipv6AddressAsHostAddress(address: utmp);
405 }
406
407 setDns(dbusDns);
408 }
409
410 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH))) {
411 setDnsSearch(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH)).toStringList());
412 }
413
414 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES))) {
415 QList<IpV6DBusAddress> temp;
416 if (setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).canConvert<QDBusArgument>()) {
417 QDBusArgument addressArg = setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES)).value<QDBusArgument>();
418 temp = qdbus_cast<QList<IpV6DBusAddress>>(arg: addressArg);
419 } else {
420 temp = setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES)).value<QList<IpV6DBusAddress>>();
421 }
422 QList<NetworkManager::IpAddress> addresses;
423
424 for (const IpV6DBusAddress &addressMap : std::as_const(t&: temp)) {
425 if (addressMap.address.isEmpty() || !addressMap.prefix || addressMap.gateway.isEmpty()) {
426 continue;
427 }
428
429 NetworkManager::IpAddress address;
430 address.setIp(ipv6AddressAsHostAddress(address: addressMap.address));
431 address.setPrefixLength(addressMap.prefix);
432 address.setGateway(ipv6AddressAsHostAddress(address: addressMap.gateway));
433 if (!address.isValid()) {
434 continue;
435 }
436
437 addresses << address;
438 }
439
440 setAddresses(addresses);
441 }
442
443 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES))) {
444 QList<IpV6DBusRoute> temp;
445 if (setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).canConvert<QDBusArgument>()) {
446 QDBusArgument routeArg = setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).value<QDBusArgument>();
447 temp = qdbus_cast<QList<IpV6DBusRoute>>(arg: routeArg);
448 } else {
449 temp = setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).value<QList<IpV6DBusRoute>>();
450 }
451 QList<NetworkManager::IpRoute> routes;
452
453 for (const IpV6DBusRoute &routeMap : std::as_const(t&: temp)) {
454 if (routeMap.destination.isEmpty() || !routeMap.prefix || routeMap.nexthop.isEmpty() || !routeMap.metric) {
455 continue;
456 }
457
458 NetworkManager::IpRoute route;
459 route.setIp(ipv6AddressAsHostAddress(address: routeMap.destination));
460 route.setPrefixLength(routeMap.prefix);
461 route.setNextHop(ipv6AddressAsHostAddress(address: 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(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC))) {
473 setRouteMetric(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC)).toInt());
474 }
475
476 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES))) {
477 setIgnoreAutoRoutes(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES)).toBool());
478 }
479
480 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS))) {
481 setIgnoreAutoDns(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS)).toBool());
482 }
483
484 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT))) {
485 setNeverDefault(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT)).toBool());
486 }
487
488 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL))) {
489 setMayFail(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL)).toBool());
490 }
491
492 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY))) {
493 setPrivacy((IPv6Privacy)setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY)).toUInt());
494 }
495
496 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT))) {
497 setDadTimeout(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT)).toUInt());
498 }
499
500 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT))) {
501 setDhcpTimeout(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT)).toUInt());
502 }
503
504 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE))) {
505 setAddressGenMode(static_cast<IPv6AddressGenMode>(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE)).toUInt()));
506 }
507
508 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME))) {
509 setDhcpHostname(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME)).toString());
510 }
511
512 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID))) {
513 setDhcpDuid(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID)).toString());
514 }
515
516 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN))) {
517 setToken(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN)).toString());
518 }
519
520 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS))) {
521 setDnsOptions(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS)).toStringList());
522 }
523
524 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA))) {
525 setRouteData(qdbus_cast<NMVariantMapList>(v: setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA))));
526 }
527
528 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA))) {
529 setAddressData(qdbus_cast<NMVariantMapList>(v: setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA))));
530 }
531
532 if (setting.contains(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE))) {
533 setRouteTable(setting.value(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE)).toUInt());
534 }
535}
536
537QVariantMap NetworkManager::Ipv6Setting::toMap() const
538{
539 QVariantMap setting;
540
541 if (method() == Automatic) {
542 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_AUTO));
543 } else if (method() == Dhcp) {
544 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DHCP));
545 } else if (method() == LinkLocal) {
546 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL));
547 } else if (method() == Manual) {
548 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_MANUAL));
549 } else if (method() == Ignored) {
550 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_IGNORE));
551 } else if (method() == ConfigDisabled) {
552 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), value: 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(address: dns);
560 }
561 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS), value: QVariant::fromValue(value: dbusDns));
562 }
563
564 if (!dnsSearch().isEmpty()) {
565 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH), value: 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(address: addr.ip());
574 dbusAddress.prefix = addr.prefixLength();
575 dbusAddress.gateway = ipv6AddressFromHostAddress(address: addr.gateway());
576 dbusAddresses << dbusAddress;
577 }
578
579 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES), value: QVariant::fromValue(value: 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(address: route.ip());
588 dbusRoute.prefix = route.prefixLength();
589 dbusRoute.nexthop = ipv6AddressFromHostAddress(address: route.nextHop());
590 dbusRoute.metric = route.metric();
591 dbusRoutes << dbusRoute;
592 }
593
594 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES), value: QVariant::fromValue(value: dbusRoutes));
595 }
596
597 if (routeMetric() >= 0) {
598 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC), value: routeMetric());
599 }
600
601 if (ignoreAutoRoutes()) {
602 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES), value: ignoreAutoRoutes());
603 }
604
605 if (ignoreAutoDns()) {
606 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS), value: ignoreAutoDns());
607 }
608
609 if (neverDefault()) {
610 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT), value: neverDefault());
611 }
612
613 if (!mayFail()) {
614 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL), value: mayFail());
615 }
616
617 if (privacy() != Unknown) {
618 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY), value: privacy());
619 }
620
621 if (dadTimeout() >= 0) {
622 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT), value: dadTimeout());
623 }
624
625 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE), value: addressGenMode());
626
627 if (dhcpTimeout() > 0) {
628 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT), value: dhcpTimeout());
629 }
630
631 if (!dhcpHostname().isEmpty()) {
632 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME), value: dhcpHostname());
633 }
634
635 if (!dhcpDuid().isEmpty()) {
636 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID), value: dhcpDuid());
637 }
638
639 if (!token().isEmpty()) {
640 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN), value: token());
641 }
642
643 if (!dnsOptions().isEmpty()) {
644 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS), value: dnsOptions());
645 }
646
647 if (!addressData().empty()) {
648 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA), value: QVariant::fromValue(value: addressData()));
649 }
650
651 if (!routeData().empty()) {
652 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA), value: QVariant::fromValue(value: routeData()));
653 }
654
655 if (routeTable() > 0) {
656 setting.insert(key: QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE), value: routeTable());
657 }
658
659 return setting;
660}
661
662QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::Ipv6Setting &setting)
663{
664 dbg.nospace() << "type: " << setting.typeAsString(type: 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}
717

source code of networkmanager-qt/src/settings/ipv6setting.cpp