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 | |
17 | NetworkManager::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 | |
31 | NetworkManager::Ipv4Setting::Ipv4Setting() |
32 | : Setting(Setting::Ipv4) |
33 | , d_ptr(new Ipv4SettingPrivate()) |
34 | { |
35 | } |
36 | |
37 | NetworkManager::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 | |
62 | NetworkManager::Ipv4Setting::~Ipv4Setting() |
63 | { |
64 | delete d_ptr; |
65 | } |
66 | |
67 | QString NetworkManager::Ipv4Setting::name() const |
68 | { |
69 | Q_D(const Ipv4Setting); |
70 | |
71 | return d->name; |
72 | } |
73 | |
74 | void NetworkManager::Ipv4Setting::setMethod(NetworkManager::Ipv4Setting::ConfigMethod type) |
75 | { |
76 | Q_D(Ipv4Setting); |
77 | |
78 | d->method = type; |
79 | } |
80 | |
81 | NetworkManager::Ipv4Setting::ConfigMethod NetworkManager::Ipv4Setting::method() const |
82 | { |
83 | Q_D(const Ipv4Setting); |
84 | |
85 | return d->method; |
86 | } |
87 | |
88 | void NetworkManager::Ipv4Setting::setDns(const QList<QHostAddress> &dns) |
89 | { |
90 | Q_D(Ipv4Setting); |
91 | |
92 | d->dns = dns; |
93 | } |
94 | |
95 | QList<QHostAddress> NetworkManager::Ipv4Setting::dns() const |
96 | { |
97 | Q_D(const Ipv4Setting); |
98 | |
99 | return d->dns; |
100 | } |
101 | |
102 | void NetworkManager::Ipv4Setting::setDnsSearch(const QStringList &domains) |
103 | { |
104 | Q_D(Ipv4Setting); |
105 | |
106 | d->dnsSearch = domains; |
107 | } |
108 | |
109 | QStringList NetworkManager::Ipv4Setting::dnsSearch() const |
110 | { |
111 | Q_D(const Ipv4Setting); |
112 | |
113 | return d->dnsSearch; |
114 | } |
115 | |
116 | void NetworkManager::Ipv4Setting::setAddresses(const QList<IpAddress> &ipv4addresses) |
117 | { |
118 | Q_D(Ipv4Setting); |
119 | |
120 | d->addresses = ipv4addresses; |
121 | } |
122 | |
123 | QList<NetworkManager::IpAddress> NetworkManager::Ipv4Setting::addresses() const |
124 | { |
125 | Q_D(const Ipv4Setting); |
126 | |
127 | return d->addresses; |
128 | } |
129 | |
130 | void NetworkManager::Ipv4Setting::setRoutes(const QList<IpRoute> &ipv4routes) |
131 | { |
132 | Q_D(Ipv4Setting); |
133 | |
134 | d->routes = ipv4routes; |
135 | } |
136 | |
137 | QList<NetworkManager::IpRoute> NetworkManager::Ipv4Setting::routes() const |
138 | { |
139 | Q_D(const Ipv4Setting); |
140 | |
141 | return d->routes; |
142 | } |
143 | |
144 | void NetworkManager::Ipv4Setting::setRouteMetric(int metric) |
145 | { |
146 | Q_D(Ipv4Setting); |
147 | |
148 | d->routeMetric = metric; |
149 | } |
150 | |
151 | int NetworkManager::Ipv4Setting::routeMetric() const |
152 | { |
153 | Q_D(const Ipv4Setting); |
154 | |
155 | return d->routeMetric; |
156 | } |
157 | |
158 | void NetworkManager::Ipv4Setting::setIgnoreAutoRoutes(bool ignore) |
159 | { |
160 | Q_D(Ipv4Setting); |
161 | |
162 | d->ignoreAutoRoutes = ignore; |
163 | } |
164 | |
165 | bool NetworkManager::Ipv4Setting::ignoreAutoRoutes() const |
166 | { |
167 | Q_D(const Ipv4Setting); |
168 | |
169 | return d->ignoreAutoRoutes; |
170 | } |
171 | |
172 | void NetworkManager::Ipv4Setting::setIgnoreAutoDns(bool ignore) |
173 | { |
174 | Q_D(Ipv4Setting); |
175 | |
176 | d->ignoreAutoDns = ignore; |
177 | } |
178 | |
179 | bool NetworkManager::Ipv4Setting::ignoreAutoDns() const |
180 | { |
181 | Q_D(const Ipv4Setting); |
182 | |
183 | return d->ignoreAutoDns; |
184 | } |
185 | |
186 | void NetworkManager::Ipv4Setting::setDhcpClientId(const QString &id) |
187 | { |
188 | Q_D(Ipv4Setting); |
189 | |
190 | d->dhcpClientId = id; |
191 | } |
192 | |
193 | QString NetworkManager::Ipv4Setting::dhcpClientId() const |
194 | { |
195 | Q_D(const Ipv4Setting); |
196 | |
197 | return d->dhcpClientId; |
198 | } |
199 | |
200 | void NetworkManager::Ipv4Setting::setDhcpSendHostname(bool send) |
201 | { |
202 | Q_D(Ipv4Setting); |
203 | |
204 | d->dhcpSendHostname = send; |
205 | } |
206 | |
207 | bool NetworkManager::Ipv4Setting::dhcpSendHostname() const |
208 | { |
209 | Q_D(const Ipv4Setting); |
210 | |
211 | return d->dhcpSendHostname; |
212 | } |
213 | |
214 | void NetworkManager::Ipv4Setting::setDhcpHostname(const QString &hostname) |
215 | { |
216 | Q_D(Ipv4Setting); |
217 | |
218 | d->dhcpHostname = hostname; |
219 | } |
220 | |
221 | QString NetworkManager::Ipv4Setting::dhcpHostname() const |
222 | { |
223 | Q_D(const Ipv4Setting); |
224 | |
225 | return d->dhcpHostname; |
226 | } |
227 | |
228 | void NetworkManager::Ipv4Setting::setNeverDefault(bool neverDefault) |
229 | { |
230 | Q_D(Ipv4Setting); |
231 | |
232 | d->neverDefault = neverDefault; |
233 | } |
234 | |
235 | bool NetworkManager::Ipv4Setting::neverDefault() const |
236 | { |
237 | Q_D(const Ipv4Setting); |
238 | |
239 | return d->neverDefault; |
240 | } |
241 | |
242 | void NetworkManager::Ipv4Setting::setMayFail(bool mayFail) |
243 | { |
244 | Q_D(Ipv4Setting); |
245 | |
246 | d->mayFail = mayFail; |
247 | } |
248 | |
249 | bool NetworkManager::Ipv4Setting::mayFail() const |
250 | { |
251 | Q_D(const Ipv4Setting); |
252 | |
253 | return d->mayFail; |
254 | } |
255 | |
256 | void NetworkManager::Ipv4Setting::setDadTimeout(qint32 timeout) |
257 | { |
258 | Q_D(Ipv4Setting); |
259 | |
260 | d->dadTimeout = timeout; |
261 | } |
262 | |
263 | qint32 NetworkManager::Ipv4Setting::dadTimeout() const |
264 | { |
265 | Q_D(const Ipv4Setting); |
266 | |
267 | return d->dadTimeout; |
268 | } |
269 | |
270 | void NetworkManager::Ipv4Setting::setDhcpFqdn(const QString &fqdn) |
271 | { |
272 | Q_D(Ipv4Setting); |
273 | |
274 | d->dhcpFqdn = fqdn; |
275 | } |
276 | |
277 | QString NetworkManager::Ipv4Setting::dhcpFqdn() const |
278 | { |
279 | Q_D(const Ipv4Setting); |
280 | |
281 | return d->dhcpFqdn; |
282 | } |
283 | |
284 | void NetworkManager::Ipv4Setting::setDnsOptions(const QStringList &options) |
285 | { |
286 | Q_D(Ipv4Setting); |
287 | |
288 | d->dnsOptions = options; |
289 | } |
290 | |
291 | QStringList NetworkManager::Ipv4Setting::dnsOptions() const |
292 | { |
293 | Q_D(const Ipv4Setting); |
294 | |
295 | return d->dnsOptions; |
296 | } |
297 | |
298 | void NetworkManager::Ipv4Setting::setDnsPriority(qint32 priority) |
299 | { |
300 | Q_D(Ipv4Setting); |
301 | |
302 | d->dnsPriority = priority; |
303 | } |
304 | |
305 | qint32 NetworkManager::Ipv4Setting::dnsPriority() const |
306 | { |
307 | Q_D(const Ipv4Setting); |
308 | |
309 | return d->dnsPriority; |
310 | } |
311 | |
312 | void NetworkManager::Ipv4Setting::setGateway(const QString &gateway) |
313 | { |
314 | Q_D(Ipv4Setting); |
315 | |
316 | d->gateway = gateway; |
317 | } |
318 | |
319 | QString NetworkManager::Ipv4Setting::gateway() const |
320 | { |
321 | Q_D(const Ipv4Setting); |
322 | |
323 | return d->gateway; |
324 | } |
325 | |
326 | void NetworkManager::Ipv4Setting::setAddressData(const NMVariantMapList &addressData) |
327 | { |
328 | Q_D(Ipv4Setting); |
329 | |
330 | d->addressData = addressData; |
331 | } |
332 | |
333 | NMVariantMapList NetworkManager::Ipv4Setting::addressData() const |
334 | { |
335 | Q_D(const Ipv4Setting); |
336 | |
337 | return d->addressData; |
338 | } |
339 | |
340 | void NetworkManager::Ipv4Setting::setRouteData(const NMVariantMapList &routeData) |
341 | { |
342 | Q_D(Ipv4Setting); |
343 | |
344 | d->routeData = routeData; |
345 | } |
346 | |
347 | NMVariantMapList NetworkManager::Ipv4Setting::routeData() const |
348 | { |
349 | Q_D(const Ipv4Setting); |
350 | |
351 | return d->routeData; |
352 | } |
353 | |
354 | void NetworkManager::Ipv4Setting::fromMap(const QVariantMap &setting) |
355 | { |
356 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD))) { |
357 | const QString methodType = setting.value(key: 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(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS))) { |
375 | QList<QHostAddress> dbusDns; |
376 | QList<uint> temp; |
377 | if (setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).canConvert<QDBusArgument>()) { |
378 | QDBusArgument dnsArg = setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).value<QDBusArgument>(); |
379 | temp = qdbus_cast<QList<uint>>(arg: dnsArg); |
380 | } else { |
381 | temp = setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).value<QList<uint>>(); |
382 | } |
383 | |
384 | for (const uint utmp : std::as_const(t&: temp)) { |
385 | QHostAddress tmpHost(ntohl(netlong: utmp)); |
386 | dbusDns << tmpHost; |
387 | } |
388 | |
389 | setDns(dbusDns); |
390 | } |
391 | |
392 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH))) { |
393 | setDnsSearch(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH)).toStringList()); |
394 | } |
395 | |
396 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES))) { |
397 | QList<NetworkManager::IpAddress> addresses; |
398 | QList<QList<uint>> temp; |
399 | if (setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).canConvert<QDBusArgument>()) { |
400 | QDBusArgument addressArg = setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).value<QDBusArgument>(); |
401 | temp = qdbus_cast<QList<QList<uint>>>(arg: addressArg); |
402 | } else { |
403 | temp = setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).value<QList<QList<uint>>>(); |
404 | } |
405 | |
406 | for (const QList<uint> &uintList : std::as_const(t&: temp)) { |
407 | if (uintList.count() != 3) { |
408 | continue; |
409 | } |
410 | |
411 | NetworkManager::IpAddress address; |
412 | address.setIp(QHostAddress(ntohl(netlong: uintList.at(i: 0)))); |
413 | address.setPrefixLength(uintList.at(i: 1)); |
414 | address.setGateway(QHostAddress(ntohl(netlong: uintList.at(i: 2)))); |
415 | if (!address.isValid()) { |
416 | continue; |
417 | } |
418 | |
419 | addresses << address; |
420 | } |
421 | |
422 | setAddresses(addresses); |
423 | } |
424 | |
425 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES))) { |
426 | QList<NetworkManager::IpRoute> routes; |
427 | QList<QList<uint>> temp; |
428 | if (setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).canConvert<QDBusArgument>()) { |
429 | QDBusArgument routeArg = setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).value<QDBusArgument>(); |
430 | temp = qdbus_cast<QList<QList<uint>>>(arg: routeArg); |
431 | } else { |
432 | temp = setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).value<QList<QList<uint>>>(); |
433 | } |
434 | |
435 | for (const QList<uint> &uintList : std::as_const(t&: temp)) { |
436 | if (uintList.count() != 4) { |
437 | continue; |
438 | } |
439 | |
440 | NetworkManager::IpRoute route; |
441 | route.setIp(QHostAddress(ntohl(netlong: uintList.at(i: 0)))); |
442 | route.setPrefixLength(uintList.at(i: 1)); |
443 | route.setNextHop(QHostAddress(ntohl(netlong: uintList.at(i: 2)))); |
444 | route.setMetric((quint32)uintList.at(i: 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(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC))) { |
457 | setRouteMetric(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC)).toInt()); |
458 | } |
459 | |
460 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES))) { |
461 | setIgnoreAutoRoutes(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES)).toBool()); |
462 | } |
463 | |
464 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS))) { |
465 | setIgnoreAutoDns(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS)).toBool()); |
466 | } |
467 | |
468 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID))) { |
469 | setDhcpClientId(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID)).toString()); |
470 | } |
471 | |
472 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME))) { |
473 | setDhcpSendHostname(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME)).toBool()); |
474 | } |
475 | |
476 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME))) { |
477 | setDhcpHostname(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME)).toString()); |
478 | } |
479 | |
480 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT))) { |
481 | setNeverDefault(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT)).toBool()); |
482 | } |
483 | |
484 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL))) { |
485 | setMayFail(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL)).toBool()); |
486 | } |
487 | |
488 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT))) { |
489 | setDadTimeout(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT)).toUInt()); |
490 | } |
491 | |
492 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN))) { |
493 | setDhcpFqdn(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN)).toString()); |
494 | } |
495 | |
496 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS))) { |
497 | setDnsOptions(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS)).toStringList()); |
498 | } |
499 | |
500 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY))) { |
501 | setDnsPriority(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY)).toInt()); |
502 | } |
503 | |
504 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY))) { |
505 | setGateway(setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY)).toString()); |
506 | } |
507 | |
508 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA))) { |
509 | setRouteData(qdbus_cast<NMVariantMapList>(v: setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA)))); |
510 | } |
511 | |
512 | if (setting.contains(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA))) { |
513 | setAddressData(qdbus_cast<NMVariantMapList>(v: setting.value(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA)))); |
514 | } |
515 | } |
516 | |
517 | QVariantMap NetworkManager::Ipv4Setting::toMap() const |
518 | { |
519 | QVariantMap setting; |
520 | |
521 | if (method() == Automatic) { |
522 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_AUTO)); |
523 | } else if (method() == LinkLocal) { |
524 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)); |
525 | } else if (method() == Manual) { |
526 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_MANUAL)); |
527 | } else if (method() == Shared) { |
528 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), value: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_SHARED)); |
529 | } else if (method() == Disabled) { |
530 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), value: 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(hostlong: dns.toIPv4Address()); |
538 | } |
539 | |
540 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS), value: QVariant::fromValue(value: dbusDns)); |
541 | } |
542 | |
543 | if (!dnsSearch().isEmpty()) { |
544 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH), value: 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(hostlong: addr.ip().toIPv4Address()) << addr.prefixLength() << htonl(hostlong: addr.gateway().toIPv4Address()); |
553 | dbusAddresses << dbusAddress; |
554 | } |
555 | |
556 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES), value: QVariant::fromValue(value: 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(hostlong: route.ip().toIPv4Address()) << route.prefixLength() << htonl(hostlong: route.nextHop().toIPv4Address()) << route.metric(); |
565 | dbusRoutes << dbusRoute; |
566 | } |
567 | |
568 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES), value: QVariant::fromValue(value: dbusRoutes)); |
569 | } |
570 | |
571 | if (routeMetric() >= 0) { |
572 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC), value: routeMetric()); |
573 | } |
574 | |
575 | if (ignoreAutoRoutes()) { |
576 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES), value: ignoreAutoRoutes()); |
577 | } |
578 | |
579 | if (ignoreAutoDns()) { |
580 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS), value: ignoreAutoDns()); |
581 | } |
582 | |
583 | if (!dhcpClientId().isEmpty()) { |
584 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID), value: dhcpClientId()); |
585 | } |
586 | |
587 | if (!dhcpSendHostname()) { |
588 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME), value: dhcpSendHostname()); |
589 | } |
590 | |
591 | if (!dhcpHostname().isEmpty()) { |
592 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME), value: dhcpHostname()); |
593 | } |
594 | |
595 | if (neverDefault()) { |
596 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT), value: neverDefault()); |
597 | } |
598 | |
599 | if (!mayFail()) { |
600 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL), value: mayFail()); |
601 | } |
602 | |
603 | if (dadTimeout() >= 0) { |
604 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT), value: dadTimeout()); |
605 | } |
606 | |
607 | if (!dhcpFqdn().isEmpty()) { |
608 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN), value: dhcpFqdn()); |
609 | } |
610 | |
611 | if (!dnsOptions().isEmpty()) { |
612 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS), value: dnsOptions()); |
613 | } |
614 | |
615 | if (dnsPriority() != 0) { |
616 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY), value: dnsPriority()); |
617 | } |
618 | |
619 | if (!gateway().isEmpty()) { |
620 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY), value: gateway()); |
621 | } |
622 | |
623 | if (!addressData().empty()) { |
624 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA), value: QVariant::fromValue(value: addressData())); |
625 | } |
626 | |
627 | if (!routeData().empty()) { |
628 | setting.insert(key: QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA), value: QVariant::fromValue(value: routeData())); |
629 | } |
630 | |
631 | return setting; |
632 | } |
633 | |
634 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::Ipv4Setting &setting) |
635 | { |
636 | dbg.nospace() << "type: " << setting.typeAsString(type: 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 | } |
688 | |