NetworkManagerQt

ipv4setting.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 "ipv4setting.h"
9#include "ipv4setting_p.h"
10
11#include "generictypes.h"
12
13#include <arpa/inet.h>
14
15#include <QDebug>
16
17NetworkManager::Ipv4SettingPrivate::Ipv4SettingPrivate()
18 : name(NMQT_SETTING_IP4_CONFIG_SETTING_NAME)
19 , method(NetworkManager::Ipv4Setting::Automatic)
20 , routeMetric(-1)
21 , ignoreAutoRoutes(false)
22 , ignoreAutoDns(false)
23 , dhcpSendHostname(true)
24 , neverDefault(false)
25 , mayFail(true)
26 , dadTimeout(-1)
27 , dnsPriority(0)
28{
29}
30
31NetworkManager::Ipv4Setting::Ipv4Setting()
32 : Setting(Setting::Ipv4)
33 , d_ptr(new Ipv4SettingPrivate())
34{
35}
36
37NetworkManager::Ipv4Setting::Ipv4Setting(const Ptr &other)
38 : Setting(other)
39 , d_ptr(new Ipv4SettingPrivate())
40{
41 setMethod(other->method());
42 setDns(other->dns());
43 setDnsSearch(other->dnsSearch());
44 setAddresses(other->addresses());
45 setRoutes(other->routes());
46 setRouteMetric(other->routeMetric());
47 setIgnoreAutoRoutes(other->ignoreAutoRoutes());
48 setIgnoreAutoDns(other->ignoreAutoDns());
49 setDhcpClientId(other->dhcpClientId());
50 setDhcpSendHostname(other->dhcpSendHostname());
51 setDhcpHostname(other->dhcpHostname());
52 setNeverDefault(other->neverDefault());
53 setMayFail(other->mayFail());
54 setDadTimeout(other->dadTimeout());
55 setDhcpFqdn(other->dhcpFqdn());
56 setDnsOptions(other->dnsOptions());
57 setDnsPriority(other->dnsPriority());
58 setAddressData(other->addressData());
59 setRouteData(other->routeData());
60}
61
62NetworkManager::Ipv4Setting::~Ipv4Setting()
63{
64 delete d_ptr;
65}
66
68{
69 Q_D(const Ipv4Setting);
70
71 return d->name;
72}
73
74void NetworkManager::Ipv4Setting::setMethod(NetworkManager::Ipv4Setting::ConfigMethod type)
75{
77
78 d->method = type;
79}
80
81NetworkManager::Ipv4Setting::ConfigMethod NetworkManager::Ipv4Setting::method() const
82{
83 Q_D(const Ipv4Setting);
84
85 return d->method;
86}
87
88void NetworkManager::Ipv4Setting::setDns(const QList<QHostAddress> &dns)
89{
90 Q_D(Ipv4Setting);
91
92 d->dns = dns;
93}
94
95QList<QHostAddress> NetworkManager::Ipv4Setting::dns() const
96{
97 Q_D(const Ipv4Setting);
98
99 return d->dns;
100}
101
102void NetworkManager::Ipv4Setting::setDnsSearch(const QStringList &domains)
103{
104 Q_D(Ipv4Setting);
105
106 d->dnsSearch = domains;
107}
108
109QStringList NetworkManager::Ipv4Setting::dnsSearch() const
110{
111 Q_D(const Ipv4Setting);
112
113 return d->dnsSearch;
114}
115
116void NetworkManager::Ipv4Setting::setAddresses(const QList<IpAddress> &ipv4addresses)
117{
118 Q_D(Ipv4Setting);
119
120 d->addresses = ipv4addresses;
121}
122
123QList<NetworkManager::IpAddress> NetworkManager::Ipv4Setting::addresses() const
124{
125 Q_D(const Ipv4Setting);
126
127 return d->addresses;
128}
129
130void NetworkManager::Ipv4Setting::setRoutes(const QList<IpRoute> &ipv4routes)
131{
132 Q_D(Ipv4Setting);
133
134 d->routes = ipv4routes;
135}
136
137QList<NetworkManager::IpRoute> NetworkManager::Ipv4Setting::routes() const
138{
139 Q_D(const Ipv4Setting);
140
141 return d->routes;
142}
143
144void NetworkManager::Ipv4Setting::setRouteMetric(int metric)
145{
146 Q_D(Ipv4Setting);
147
148 d->routeMetric = metric;
149}
150
151int NetworkManager::Ipv4Setting::routeMetric() const
152{
153 Q_D(const Ipv4Setting);
154
155 return d->routeMetric;
156}
157
158void NetworkManager::Ipv4Setting::setIgnoreAutoRoutes(bool ignore)
159{
160 Q_D(Ipv4Setting);
161
162 d->ignoreAutoRoutes = ignore;
163}
164
165bool NetworkManager::Ipv4Setting::ignoreAutoRoutes() const
166{
167 Q_D(const Ipv4Setting);
168
169 return d->ignoreAutoRoutes;
170}
171
172void NetworkManager::Ipv4Setting::setIgnoreAutoDns(bool ignore)
173{
174 Q_D(Ipv4Setting);
175
176 d->ignoreAutoDns = ignore;
177}
178
179bool NetworkManager::Ipv4Setting::ignoreAutoDns() const
180{
181 Q_D(const Ipv4Setting);
182
183 return d->ignoreAutoDns;
184}
185
186void NetworkManager::Ipv4Setting::setDhcpClientId(const QString &id)
187{
188 Q_D(Ipv4Setting);
189
190 d->dhcpClientId = id;
191}
192
193QString NetworkManager::Ipv4Setting::dhcpClientId() const
194{
195 Q_D(const Ipv4Setting);
196
197 return d->dhcpClientId;
198}
199
200void NetworkManager::Ipv4Setting::setDhcpSendHostname(bool send)
201{
202 Q_D(Ipv4Setting);
203
204 d->dhcpSendHostname = send;
205}
206
207bool NetworkManager::Ipv4Setting::dhcpSendHostname() const
208{
209 Q_D(const Ipv4Setting);
210
211 return d->dhcpSendHostname;
212}
213
214void NetworkManager::Ipv4Setting::setDhcpHostname(const QString &hostname)
215{
216 Q_D(Ipv4Setting);
217
218 d->dhcpHostname = hostname;
219}
220
221QString NetworkManager::Ipv4Setting::dhcpHostname() const
222{
223 Q_D(const Ipv4Setting);
224
225 return d->dhcpHostname;
226}
227
228void NetworkManager::Ipv4Setting::setNeverDefault(bool neverDefault)
229{
230 Q_D(Ipv4Setting);
231
232 d->neverDefault = neverDefault;
233}
234
235bool NetworkManager::Ipv4Setting::neverDefault() const
236{
237 Q_D(const Ipv4Setting);
238
239 return d->neverDefault;
240}
241
242void NetworkManager::Ipv4Setting::setMayFail(bool mayFail)
243{
244 Q_D(Ipv4Setting);
245
246 d->mayFail = mayFail;
247}
248
249bool NetworkManager::Ipv4Setting::mayFail() const
250{
251 Q_D(const Ipv4Setting);
252
253 return d->mayFail;
254}
255
256void NetworkManager::Ipv4Setting::setDadTimeout(qint32 timeout)
257{
258 Q_D(Ipv4Setting);
259
260 d->dadTimeout = timeout;
261}
262
263qint32 NetworkManager::Ipv4Setting::dadTimeout() const
264{
265 Q_D(const Ipv4Setting);
266
267 return d->dadTimeout;
268}
269
270void NetworkManager::Ipv4Setting::setDhcpFqdn(const QString &fqdn)
271{
272 Q_D(Ipv4Setting);
273
274 d->dhcpFqdn = fqdn;
275}
276
277QString NetworkManager::Ipv4Setting::dhcpFqdn() const
278{
279 Q_D(const Ipv4Setting);
280
281 return d->dhcpFqdn;
282}
283
284void NetworkManager::Ipv4Setting::setDnsOptions(const QStringList &options)
285{
286 Q_D(Ipv4Setting);
287
288 d->dnsOptions = options;
289}
290
291QStringList NetworkManager::Ipv4Setting::dnsOptions() const
292{
293 Q_D(const Ipv4Setting);
294
295 return d->dnsOptions;
296}
297
298void NetworkManager::Ipv4Setting::setDnsPriority(qint32 priority)
299{
300 Q_D(Ipv4Setting);
301
302 d->dnsPriority = priority;
303}
304
305qint32 NetworkManager::Ipv4Setting::dnsPriority() const
306{
307 Q_D(const Ipv4Setting);
308
309 return d->dnsPriority;
310}
311
312void NetworkManager::Ipv4Setting::setGateway(const QString &gateway)
313{
314 Q_D(Ipv4Setting);
315
316 d->gateway = gateway;
317}
318
319QString NetworkManager::Ipv4Setting::gateway() const
320{
321 Q_D(const Ipv4Setting);
322
323 return d->gateway;
324}
325
326void NetworkManager::Ipv4Setting::setAddressData(const NMVariantMapList &addressData)
327{
328 Q_D(Ipv4Setting);
329
330 d->addressData = addressData;
331}
332
333NMVariantMapList NetworkManager::Ipv4Setting::addressData() const
334{
335 Q_D(const Ipv4Setting);
336
337 return d->addressData;
338}
339
340void NetworkManager::Ipv4Setting::setRouteData(const NMVariantMapList &routeData)
341{
342 Q_D(Ipv4Setting);
343
344 d->routeData = routeData;
345}
346
347NMVariantMapList NetworkManager::Ipv4Setting::routeData() const
348{
349 Q_D(const Ipv4Setting);
350
351 return d->routeData;
352}
353
354void NetworkManager::Ipv4Setting::fromMap(const QVariantMap &setting)
355{
356 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD))) {
357 const QString methodType = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD)).toString();
358
359 if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_AUTO)) {
360 setMethod(Automatic);
361 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) {
362 setMethod(LinkLocal);
363 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_MANUAL)) {
364 setMethod(Manual);
365 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_SHARED)) {
366 setMethod(Shared);
367 } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
368 setMethod(Disabled);
369 } else {
370 setMethod(Automatic);
371 }
372 }
373
374 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS))) {
375 QList<QHostAddress> dbusDns;
376 QList<uint> temp;
377 if (setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).canConvert<QDBusArgument>()) {
378 QDBusArgument dnsArg = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).value<QDBusArgument>();
379 temp = qdbus_cast<QList<uint>>(dnsArg);
380 } else {
381 temp = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).value<QList<uint>>();
382 }
383
384 for (const uint utmp : std::as_const(temp)) {
385 QHostAddress tmpHost(ntohl(utmp));
386 dbusDns << tmpHost;
387 }
388
389 setDns(dbusDns);
390 }
391
392 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH))) {
393 setDnsSearch(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH)).toStringList());
394 }
395
396 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES))) {
398 QList<QList<uint>> temp;
399 if (setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).canConvert<QDBusArgument>()) {
400 QDBusArgument addressArg = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).value<QDBusArgument>();
401 temp = qdbus_cast<QList<QList<uint>>>(addressArg);
402 } else {
403 temp = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).value<QList<QList<uint>>>();
404 }
405
406 for (const QList<uint> &uintList : std::as_const(temp)) {
407 if (uintList.count() != 3) {
408 continue;
409 }
410
412 address.setIp(QHostAddress(ntohl(uintList.at(0))));
413 address.setPrefixLength(uintList.at(1));
414 address.setGateway(QHostAddress(ntohl(uintList.at(2))));
415 if (!address.isValid()) {
416 continue;
417 }
418
419 addresses << address;
420 }
421
422 setAddresses(addresses);
423 }
424
425 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES))) {
427 QList<QList<uint>> temp;
428 if (setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).canConvert<QDBusArgument>()) {
429 QDBusArgument routeArg = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).value<QDBusArgument>();
430 temp = qdbus_cast<QList<QList<uint>>>(routeArg);
431 } else {
432 temp = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).value<QList<QList<uint>>>();
433 }
434
435 for (const QList<uint> &uintList : std::as_const(temp)) {
436 if (uintList.count() != 4) {
437 continue;
438 }
439
441 route.setIp(QHostAddress(ntohl(uintList.at(0))));
442 route.setPrefixLength(uintList.at(1));
443 route.setNextHop(QHostAddress(ntohl(uintList.at(2))));
444 route.setMetric((quint32)uintList.at(3));
445 if (!route.isValid()) {
446 continue;
447 }
448 routes << route;
449 }
450
451 if (!routes.isEmpty()) {
452 setRoutes(routes);
453 }
454 }
455
456 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC))) {
457 setRouteMetric(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC)).toInt());
458 }
459
460 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES))) {
461 setIgnoreAutoRoutes(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES)).toBool());
462 }
463
464 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS))) {
465 setIgnoreAutoDns(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS)).toBool());
466 }
467
468 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID))) {
469 setDhcpClientId(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID)).toString());
470 }
471
472 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME))) {
473 setDhcpSendHostname(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME)).toBool());
474 }
475
476 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME))) {
477 setDhcpHostname(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME)).toString());
478 }
479
480 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT))) {
481 setNeverDefault(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT)).toBool());
482 }
483
484 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL))) {
485 setMayFail(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL)).toBool());
486 }
487
488 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT))) {
489 setDadTimeout(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT)).toUInt());
490 }
491
492 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN))) {
493 setDhcpFqdn(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN)).toString());
494 }
495
496 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS))) {
497 setDnsOptions(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS)).toStringList());
498 }
499
500 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY))) {
501 setDnsPriority(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY)).toInt());
502 }
503
504 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY))) {
505 setGateway(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY)).toString());
506 }
507
508 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA))) {
509 setRouteData(qdbus_cast<NMVariantMapList>(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA))));
510 }
511
512 if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA))) {
513 setAddressData(qdbus_cast<NMVariantMapList>(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA))));
514 }
515}
516
518{
519 QVariantMap setting;
520
521 if (method() == Automatic) {
522 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_AUTO));
523 } else if (method() == LinkLocal) {
524 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL));
525 } else if (method() == Manual) {
526 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_MANUAL));
527 } else if (method() == Shared) {
528 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_SHARED));
529 } else if (method() == Disabled) {
530 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_DISABLED));
531 }
532
533 if (!dns().isEmpty()) {
534 QList<uint> dbusDns;
535 const QList<QHostAddress> dnsList = dns();
536 for (const QHostAddress &dns : dnsList) {
537 dbusDns << htonl(dns.toIPv4Address());
538 }
539
540 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS), QVariant::fromValue(dbusDns));
541 }
542
543 if (!dnsSearch().isEmpty()) {
544 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH), dnsSearch());
545 }
546
547 if (!addresses().isEmpty()) {
548 QList<QList<uint>> dbusAddresses;
549 const auto addressesList = addresses();
550 for (const NetworkManager::IpAddress &addr : addressesList) {
551 QList<uint> dbusAddress;
552 dbusAddress << htonl(addr.ip().toIPv4Address()) << addr.prefixLength() << htonl(addr.gateway().toIPv4Address());
553 dbusAddresses << dbusAddress;
554 }
555
556 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES), QVariant::fromValue(dbusAddresses));
557 }
558
559 if (!routes().isEmpty()) {
560 QList<QList<uint>> dbusRoutes;
561 const auto routesList = routes();
562 for (const NetworkManager::IpRoute &route : routesList) {
563 QList<uint> dbusRoute;
564 dbusRoute << htonl(route.ip().toIPv4Address()) << route.prefixLength() << htonl(route.nextHop().toIPv4Address()) << route.metric();
565 dbusRoutes << dbusRoute;
566 }
567
568 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES), QVariant::fromValue(dbusRoutes));
569 }
570
571 if (routeMetric() >= 0) {
572 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC), routeMetric());
573 }
574
575 if (ignoreAutoRoutes()) {
576 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES), ignoreAutoRoutes());
577 }
578
579 if (ignoreAutoDns()) {
580 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS), ignoreAutoDns());
581 }
582
583 if (!dhcpClientId().isEmpty()) {
584 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID), dhcpClientId());
585 }
586
587 if (!dhcpSendHostname()) {
588 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME), dhcpSendHostname());
589 }
590
591 if (!dhcpHostname().isEmpty()) {
592 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME), dhcpHostname());
593 }
594
595 if (neverDefault()) {
596 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT), neverDefault());
597 }
598
599 if (!mayFail()) {
600 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL), mayFail());
601 }
602
603 if (dadTimeout() >= 0) {
604 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT), dadTimeout());
605 }
606
607 if (!dhcpFqdn().isEmpty()) {
608 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN), dhcpFqdn());
609 }
610
611 if (!dnsOptions().isEmpty()) {
612 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS), dnsOptions());
613 }
614
615 if (dnsPriority() != 0) {
616 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY), dnsPriority());
617 }
618
619 if (!gateway().isEmpty()) {
620 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY), gateway());
621 }
622
623 if (!addressData().empty()) {
624 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA), QVariant::fromValue(addressData()));
625 }
626
627 if (!routeData().empty()) {
628 setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA), QVariant::fromValue(routeData()));
629 }
630
631 return setting;
632}
633
634QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::Ipv4Setting &setting)
635{
636 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
637 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
638
639 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_METHOD << ": " << setting.method() << '\n';
640 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DNS << ":\n";
641 const QList<QHostAddress> dnsList = setting.dns();
642 for (const QHostAddress &address : dnsList) {
643 dbg.nospace() << address.toString() << '\n';
644 }
645 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DNS_SEARCH << ": " << setting.dnsSearch() << '\n';
646 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ADDRESSES << '\n';
647 const auto addressesList = setting.addresses();
648 for (const NetworkManager::IpAddress &address : addressesList) {
649 dbg.nospace() << address.ip() << ": " << address.gateway() << ": " << address.netmask() << '\n';
650 }
651 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ROUTES << '\n';
652 const auto routesList = setting.routes();
653 for (const NetworkManager::IpRoute &route : routesList) {
654 dbg.nospace() << route.ip() << ": " << route.netmask() << ": " << route.nextHop() << ": " << route.metric() << '\n';
655 }
656 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC << ":" << setting.routeMetric() << '\n';
657 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES << ": " << setting.ignoreAutoRoutes() << '\n';
658 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS << ": " << setting.ignoreAutoDns() << '\n';
659 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID << ": " << setting.dhcpClientId() << '\n';
660 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME << ": " << setting.dhcpSendHostname() << '\n';
661 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME << ": " << setting.dhcpHostname() << '\n';
662 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT << ": " << setting.neverDefault() << '\n';
663 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_MAY_FAIL << ": " << setting.mayFail() << '\n';
664 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT << ": " << setting.dadTimeout() << '\n';
665 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DHCP_FQDN << ": " << setting.dhcpFqdn() << '\n';
666 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS << ": " << setting.dnsOptions() << '\n';
667 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY << ": " << setting.dnsPriority() << '\n';
668 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_GATEWAY << ": " << setting.gateway() << '\n';
669 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA << ": " << '\n';
670 const NMVariantMapList addDataList = setting.addressData();
671 for (const QVariantMap &addressData : addDataList) {
672 QVariantMap::const_iterator i = addressData.constBegin();
673 while (i != addressData.constEnd()) {
674 dbg.nospace() << i.key() << ": " << i.value() << '\n';
675 }
676 }
677 dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ROUTE_DATA << ": " << '\n';
678 const NMVariantMapList routeDataList = setting.routeData();
679 for (const QVariantMap &routeData : routeDataList) {
680 QVariantMap::const_iterator i = routeData.constBegin();
681 while (i != routeData.constEnd()) {
682 dbg.nospace() << i.key() << ": " << i.value() << '\n';
683 }
684 }
685
686 return dbg.maybeSpace();
687}
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 ipv4 setting.
Definition ipv4setting.h:53
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
This class allows querying the underlying system to discover the available network interfaces and rea...
Definition accesspoint.h:21
NETWORKMANAGERQT_EXPORT QString hostname()
Returns hostname of the machine.
Definition settings.cpp:260
QDebug & maybeSpace()
QDebug & nospace()
bool isEmpty() const const
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 Sat Dec 21 2024 16:56:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.