1 | /* |
2 | SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com> |
3 | SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com> |
4 | SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
7 | */ |
8 | |
9 | #include "connectionsettings.h" |
10 | #include "connectionsettings_p.h" |
11 | |
12 | #include "adslsetting.h" |
13 | #include "bluetoothsetting.h" |
14 | #include "bondsetting.h" |
15 | #include "bridgeportsetting.h" |
16 | #include "bridgesetting.h" |
17 | #include "cdmasetting.h" |
18 | #include "gsmsetting.h" |
19 | #include "infinibandsetting.h" |
20 | #include "iptunnelsetting.h" |
21 | #include "ipv4setting.h" |
22 | #include "ipv6setting.h" |
23 | #include "olpcmeshsetting.h" |
24 | #include "pppoesetting.h" |
25 | #include "pppsetting.h" |
26 | #include "security8021xsetting.h" |
27 | #include "serialsetting.h" |
28 | #include "tunsetting.h" |
29 | #include "vlansetting.h" |
30 | #include "vpnsetting.h" |
31 | #include "wimaxsetting.h" |
32 | #include "wiredsetting.h" |
33 | #include "wireguardsetting.h" |
34 | #include "wirelesssecuritysetting.h" |
35 | #include "wirelesssetting.h" |
36 | |
37 | #undef signals |
38 | |
39 | #if !NM_CHECK_VERSION(1, 6, 0) |
40 | #define NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES "autoconnect-retries" |
41 | #endif |
42 | |
43 | #if !NM_CHECK_VERSION(1, 12, 0) |
44 | #define NM_SETTING_CONNECTION_MDNS "mdns" |
45 | #endif |
46 | |
47 | #if !NM_CHECK_VERSION(1, 16, 0) |
48 | #define NM_SETTING_WIREGUARD_SETTING_NAME "wireguard" |
49 | #endif |
50 | |
51 | #include "genericsetting.h" |
52 | #include "teamsetting.h" |
53 | |
54 | #include <QUuid> |
55 | |
56 | namespace NetworkManager |
57 | { |
58 | extern bool checkVersion(const int x, const int y, const int z); |
59 | } |
60 | |
61 | NetworkManager::ConnectionSettingsPrivate::ConnectionSettingsPrivate(ConnectionSettings *q) |
62 | : name(NM_SETTING_CONNECTION_SETTING_NAME) |
63 | , uuid(QUuid().toString()) |
64 | , type(ConnectionSettings::Wired) |
65 | , autoconnect(true) |
66 | , readOnly(false) |
67 | , gatewayPingTimeout(0) |
68 | , autoconnectPriority(0) |
69 | , autoconnectRetries(-1) |
70 | , autoconnectSlaves(ConnectionSettings::SlavesDefault) |
71 | , lldp(ConnectionSettings::LldpDefault) |
72 | , metered(ConnectionSettings::MeteredUnknown) |
73 | , mdns(ConnectionSettings::MdnsDefault) |
74 | , q_ptr(q) |
75 | { |
76 | } |
77 | |
78 | void NetworkManager::ConnectionSettingsPrivate::addSetting(const NetworkManager::Setting::Ptr &setting) |
79 | { |
80 | settings.push_back(t: setting); |
81 | } |
82 | |
83 | void NetworkManager::ConnectionSettingsPrivate::clearSettings() |
84 | { |
85 | settings.clear(); |
86 | } |
87 | |
88 | void NetworkManager::ConnectionSettingsPrivate::initSettings(NMBluetoothCapabilities bt_cap) |
89 | { |
90 | clearSettings(); |
91 | |
92 | switch (type) { |
93 | case ConnectionSettings::Adsl: |
94 | addSetting(setting: Setting::Ptr(new AdslSetting())); |
95 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
96 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
97 | break; |
98 | case ConnectionSettings::Bond: |
99 | addSetting(setting: Setting::Ptr(new BondSetting())); |
100 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
101 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
102 | break; |
103 | case ConnectionSettings::Bluetooth: |
104 | addSetting(setting: Setting::Ptr(new BluetoothSetting())); |
105 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
106 | // addSetting(Setting::Ptr(new Ipv6Setting())); |
107 | if (bt_cap == NM_BT_CAPABILITY_DUN) { |
108 | addSetting(setting: Setting::Ptr(new GsmSetting())); |
109 | addSetting(setting: Setting::Ptr(new PppSetting())); |
110 | addSetting(setting: Setting::Ptr(new SerialSetting())); |
111 | } |
112 | break; |
113 | case ConnectionSettings::Bridge: |
114 | addSetting(setting: Setting::Ptr(new BridgeSetting())); |
115 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
116 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
117 | break; |
118 | case ConnectionSettings::Cdma: |
119 | addSetting(setting: Setting::Ptr(new CdmaSetting())); |
120 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
121 | if (NetworkManager::checkVersion(x: 1, y: 0, z: 0)) { |
122 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
123 | } |
124 | addSetting(setting: Setting::Ptr(new PppSetting())); |
125 | break; |
126 | case ConnectionSettings::Gsm: |
127 | addSetting(setting: Setting::Ptr(new GsmSetting())); |
128 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
129 | if (NetworkManager::checkVersion(x: 1, y: 0, z: 0)) { |
130 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
131 | } |
132 | addSetting(setting: Setting::Ptr(new PppSetting())); |
133 | break; |
134 | case ConnectionSettings::Infiniband: |
135 | addSetting(setting: Setting::Ptr(new InfinibandSetting())); |
136 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
137 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
138 | break; |
139 | case ConnectionSettings::OLPCMesh: |
140 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
141 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
142 | addSetting(setting: Setting::Ptr(new OlpcMeshSetting())); |
143 | break; |
144 | case ConnectionSettings::Pppoe: |
145 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
146 | // addSetting(new Ipv6Setting())); |
147 | addSetting(setting: Setting::Ptr(new PppSetting())); |
148 | addSetting(setting: Setting::Ptr(new PppoeSetting())); |
149 | addSetting(setting: Setting::Ptr(new WiredSetting())); |
150 | break; |
151 | case ConnectionSettings::Vlan: |
152 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
153 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
154 | addSetting(setting: Setting::Ptr(new VlanSetting())); |
155 | break; |
156 | case ConnectionSettings::Vpn: |
157 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
158 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
159 | addSetting(setting: Setting::Ptr(new VpnSetting())); |
160 | break; |
161 | case ConnectionSettings::Wimax: |
162 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
163 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
164 | addSetting(setting: Setting::Ptr(new WimaxSetting())); |
165 | break; |
166 | case ConnectionSettings::Wired: |
167 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
168 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
169 | addSetting(setting: Setting::Ptr(new Security8021xSetting())); |
170 | addSetting(setting: Setting::Ptr(new WiredSetting())); |
171 | break; |
172 | case ConnectionSettings::Wireless: |
173 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
174 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
175 | addSetting(setting: Setting::Ptr(new Security8021xSetting())); |
176 | addSetting(setting: Setting::Ptr(new WirelessSetting())); |
177 | addSetting(setting: Setting::Ptr(new WirelessSecuritySetting())); |
178 | break; |
179 | case ConnectionSettings::Team: |
180 | addSetting(setting: Setting::Ptr(new TeamSetting())); |
181 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
182 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
183 | break; |
184 | case ConnectionSettings::Generic: |
185 | addSetting(setting: Setting::Ptr(new GenericSetting())); |
186 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
187 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
188 | break; |
189 | case ConnectionSettings::Tun: |
190 | addSetting(setting: Setting::Ptr(new TunSetting())); |
191 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
192 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
193 | break; |
194 | case ConnectionSettings::IpTunnel: |
195 | addSetting(setting: Setting::Ptr(new IpTunnelSetting())); |
196 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
197 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
198 | break; |
199 | case ConnectionSettings::WireGuard: |
200 | addSetting(setting: Setting::Ptr(new WireGuardSetting())); |
201 | addSetting(setting: Setting::Ptr(new Ipv4Setting())); |
202 | addSetting(setting: Setting::Ptr(new Ipv6Setting())); |
203 | break; |
204 | case ConnectionSettings::Unknown: |
205 | default: |
206 | break; |
207 | } |
208 | } |
209 | |
210 | void NetworkManager::ConnectionSettingsPrivate::initSettings(const NetworkManager::ConnectionSettings::Ptr &connectionSettings) |
211 | { |
212 | Q_Q(ConnectionSettings); |
213 | |
214 | clearSettings(); |
215 | |
216 | switch (type) { |
217 | case ConnectionSettings::Adsl: |
218 | addSetting(setting: connectionSettings->setting(Setting::Adsl)); |
219 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
220 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
221 | break; |
222 | case ConnectionSettings::Bond: |
223 | addSetting(setting: connectionSettings->setting(Setting::Bond)); |
224 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
225 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
226 | break; |
227 | case ConnectionSettings::Bluetooth: |
228 | addSetting(setting: connectionSettings->setting(Setting::Bluetooth)); |
229 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
230 | if (NetworkManager::checkVersion(x: 1, y: 0, z: 0)) { |
231 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
232 | } |
233 | if (q->setting(Setting::Gsm) && q->setting(Setting::Ppp) && q->setting(Setting::Serial)) { |
234 | addSetting(setting: connectionSettings->setting(Setting::Gsm)); |
235 | addSetting(setting: connectionSettings->setting(Setting::Ppp)); |
236 | addSetting(setting: connectionSettings->setting(Setting::Serial)); |
237 | } |
238 | break; |
239 | case ConnectionSettings::Bridge: |
240 | addSetting(setting: connectionSettings->setting(Setting::Bridge)); |
241 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
242 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
243 | break; |
244 | case ConnectionSettings::Cdma: |
245 | addSetting(setting: connectionSettings->setting(Setting::Cdma)); |
246 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
247 | if (NetworkManager::checkVersion(x: 1, y: 0, z: 0)) { |
248 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
249 | } |
250 | addSetting(setting: connectionSettings->setting(Setting::Ppp)); |
251 | break; |
252 | case ConnectionSettings::Gsm: |
253 | addSetting(setting: connectionSettings->setting(Setting::Gsm)); |
254 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
255 | if (NetworkManager::checkVersion(x: 1, y: 0, z: 0)) { |
256 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
257 | } |
258 | addSetting(setting: connectionSettings->setting(Setting::Ppp)); |
259 | break; |
260 | case ConnectionSettings::Infiniband: |
261 | addSetting(setting: connectionSettings->setting(Setting::Infiniband)); |
262 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
263 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
264 | break; |
265 | case ConnectionSettings::OLPCMesh: |
266 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
267 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
268 | addSetting(setting: connectionSettings->setting(Setting::OlpcMesh)); |
269 | break; |
270 | case ConnectionSettings::Pppoe: |
271 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
272 | // addSetting(Ipv6Setting(connectionSettings->setting(Setting::Ipv6)); |
273 | addSetting(setting: connectionSettings->setting(Setting::Ppp)); |
274 | addSetting(setting: connectionSettings->setting(Setting::Pppoe)); |
275 | addSetting(setting: connectionSettings->setting(Setting::Wired)); |
276 | break; |
277 | case ConnectionSettings::Vlan: |
278 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
279 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
280 | addSetting(setting: connectionSettings->setting(Setting::Vlan)); |
281 | break; |
282 | case ConnectionSettings::Vpn: |
283 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
284 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
285 | addSetting(setting: connectionSettings->setting(Setting::Vpn)); |
286 | break; |
287 | case ConnectionSettings::Wimax: |
288 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
289 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
290 | addSetting(setting: connectionSettings->setting(Setting::Wimax)); |
291 | break; |
292 | case ConnectionSettings::Wired: |
293 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
294 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
295 | addSetting(setting: connectionSettings->setting(Setting::Security8021x)); |
296 | addSetting(setting: connectionSettings->setting(Setting::Wired)); |
297 | break; |
298 | case ConnectionSettings::Wireless: |
299 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
300 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
301 | addSetting(setting: connectionSettings->setting(Setting::Security8021x)); |
302 | addSetting(setting: connectionSettings->setting(Setting::Wireless)); |
303 | addSetting(setting: connectionSettings->setting(Setting::WirelessSecurity)); |
304 | break; |
305 | case ConnectionSettings::Team: |
306 | addSetting(setting: connectionSettings->setting(Setting::Team)); |
307 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
308 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
309 | break; |
310 | case ConnectionSettings::Generic: |
311 | addSetting(setting: connectionSettings->setting(Setting::Generic)); |
312 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
313 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
314 | break; |
315 | case ConnectionSettings::Tun: |
316 | addSetting(setting: connectionSettings->setting(Setting::Tun)); |
317 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
318 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
319 | break; |
320 | case ConnectionSettings::IpTunnel: |
321 | addSetting(setting: connectionSettings->setting(Setting::IpTunnel)); |
322 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
323 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
324 | break; |
325 | case ConnectionSettings::WireGuard: |
326 | addSetting(setting: connectionSettings->setting(Setting::WireGuard)); |
327 | addSetting(setting: connectionSettings->setting(Setting::Ipv4)); |
328 | addSetting(setting: connectionSettings->setting(Setting::Ipv6)); |
329 | break; |
330 | case ConnectionSettings::Unknown: |
331 | default: |
332 | break; |
333 | } |
334 | } |
335 | |
336 | NetworkManager::ConnectionSettings::ConnectionType NetworkManager::ConnectionSettings::typeFromString(const QString &typeString) |
337 | { |
338 | ConnectionSettings::ConnectionType type = Wired; |
339 | |
340 | if (typeString == QLatin1String(NM_SETTING_ADSL_SETTING_NAME)) { |
341 | type = Adsl; |
342 | } else if (typeString == QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME)) { |
343 | type = Bluetooth; |
344 | } else if (typeString == QLatin1String(NM_SETTING_BOND_SETTING_NAME)) { |
345 | type = Bond; |
346 | } else if (typeString == QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME)) { |
347 | type = Bridge; |
348 | } else if (typeString == QLatin1String(NM_SETTING_CDMA_SETTING_NAME)) { |
349 | type = Cdma; |
350 | } else if (typeString == QLatin1String(NM_SETTING_GSM_SETTING_NAME)) { |
351 | type = Gsm; |
352 | } else if (typeString == QLatin1String(NM_SETTING_INFINIBAND_SETTING_NAME)) { |
353 | type = Infiniband; |
354 | } else if (typeString == QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME)) { |
355 | type = OLPCMesh; |
356 | } else if (typeString == QLatin1String(NM_SETTING_PPPOE_SETTING_NAME)) { |
357 | type = Pppoe; |
358 | } else if (typeString == QLatin1String(NM_SETTING_VLAN_SETTING_NAME)) { |
359 | type = Vlan; |
360 | } else if (typeString == QLatin1String(NM_SETTING_VPN_SETTING_NAME)) { |
361 | type = Vpn; |
362 | } else if (typeString == QLatin1String(NM_SETTING_WIMAX_SETTING_NAME)) { |
363 | type = Wimax; |
364 | } else if (typeString == QLatin1String(NM_SETTING_WIRED_SETTING_NAME)) { |
365 | type = Wired; |
366 | } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME)) { |
367 | type = Wireless; |
368 | } else if (typeString == QLatin1String(NM_SETTING_TEAM_SETTING_NAME)) { |
369 | type = Team; |
370 | } else if (typeString == QLatin1String(NM_SETTING_GENERIC_SETTING_NAME)) { |
371 | type = Generic; |
372 | } else if (typeString == QLatin1String(NM_SETTING_TUN_SETTING_NAME)) { |
373 | type = Tun; |
374 | } else if (typeString == QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME)) { |
375 | type = IpTunnel; |
376 | } else if (typeString == QLatin1String(NM_SETTING_WIREGUARD_SETTING_NAME)) { |
377 | type = WireGuard; |
378 | } |
379 | |
380 | return type; |
381 | } |
382 | |
383 | QString NetworkManager::ConnectionSettings::typeAsString(NetworkManager::ConnectionSettings::ConnectionType type) |
384 | { |
385 | QString typeString; |
386 | |
387 | switch (type) { |
388 | case Adsl: |
389 | typeString = QLatin1String(NM_SETTING_ADSL_SETTING_NAME); |
390 | break; |
391 | case Bond: |
392 | typeString = QLatin1String(NM_SETTING_BOND_SETTING_NAME); |
393 | break; |
394 | case Bluetooth: |
395 | typeString = QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME); |
396 | break; |
397 | case Bridge: |
398 | typeString = QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME); |
399 | break; |
400 | case Cdma: |
401 | typeString = QLatin1String(NM_SETTING_CDMA_SETTING_NAME); |
402 | break; |
403 | case Gsm: |
404 | typeString = QLatin1String(NM_SETTING_GSM_SETTING_NAME); |
405 | break; |
406 | case Infiniband: |
407 | typeString = QLatin1String(NM_SETTING_INFINIBAND_SETTING_NAME); |
408 | break; |
409 | case OLPCMesh: |
410 | typeString = QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME); |
411 | break; |
412 | case Pppoe: |
413 | typeString = QLatin1String(NM_SETTING_PPPOE_SETTING_NAME); |
414 | break; |
415 | case Vlan: |
416 | typeString = QLatin1String(NM_SETTING_VLAN_SETTING_NAME); |
417 | break; |
418 | case Vpn: |
419 | typeString = QLatin1String(NM_SETTING_VPN_SETTING_NAME); |
420 | break; |
421 | case Wimax: |
422 | typeString = QLatin1String(NM_SETTING_WIMAX_SETTING_NAME); |
423 | break; |
424 | case Wired: |
425 | typeString = QLatin1String(NM_SETTING_WIRED_SETTING_NAME); |
426 | break; |
427 | case Wireless: |
428 | typeString = QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME); |
429 | break; |
430 | case Team: |
431 | typeString = QLatin1String(NM_SETTING_TEAM_SETTING_NAME); |
432 | break; |
433 | case Generic: |
434 | typeString = QLatin1String(NM_SETTING_GENERIC_SETTING_NAME); |
435 | break; |
436 | case Tun: |
437 | typeString = QLatin1String(NM_SETTING_TUN_SETTING_NAME); |
438 | break; |
439 | case IpTunnel: |
440 | typeString = QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME); |
441 | break; |
442 | case WireGuard: |
443 | typeString = QLatin1String(NM_SETTING_WIREGUARD_SETTING_NAME); |
444 | break; |
445 | default: |
446 | break; |
447 | }; |
448 | |
449 | return typeString; |
450 | } |
451 | |
452 | QString NetworkManager::ConnectionSettings::createNewUuid() |
453 | { |
454 | return QUuid::createUuid().toString().mid(position: 1, n: QUuid::createUuid().toString().length() - 2); |
455 | } |
456 | |
457 | NetworkManager::ConnectionSettings::ConnectionSettings() |
458 | : d_ptr(new ConnectionSettingsPrivate(this)) |
459 | { |
460 | } |
461 | |
462 | NetworkManager::ConnectionSettings::ConnectionSettings(NetworkManager::ConnectionSettings::ConnectionType type, NMBluetoothCapabilities bt_cap) |
463 | : d_ptr(new ConnectionSettingsPrivate(this)) |
464 | { |
465 | setConnectionType(type, bt_cap); |
466 | } |
467 | |
468 | NetworkManager::ConnectionSettings::ConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &other) |
469 | : d_ptr(new ConnectionSettingsPrivate(this)) |
470 | { |
471 | Q_D(ConnectionSettings); |
472 | |
473 | setId(other->id()); |
474 | setUuid(other->uuid()); |
475 | setInterfaceName(other->interfaceName()); |
476 | setConnectionType(type: other->connectionType()); |
477 | setPermissions(other->permissions()); |
478 | setAutoconnect(other->autoconnect()); |
479 | setAutoconnectPriority(other->autoconnectPriority()); |
480 | setTimestamp(other->timestamp()); |
481 | setReadOnly(other->readOnly()); |
482 | setZone(other->zone()); |
483 | setMaster(other->master()); |
484 | setSlaveType(other->slaveType()); |
485 | setGatewayPingTimeout(other->gatewayPingTimeout()); |
486 | setAutoconnectRetries(other->autoconnectRetries()); |
487 | setAutoconnectSlaves(other->autoconnectSlaves()); |
488 | setLldp(other->lldp()); |
489 | setMetered(other->metered()); |
490 | setMdns(other->mdns()); |
491 | setStableId(other->stableId()); |
492 | |
493 | d->initSettings(connectionSettings: other); |
494 | } |
495 | |
496 | NetworkManager::ConnectionSettings::ConnectionSettings(const NMVariantMapMap &map) |
497 | : d_ptr(new ConnectionSettingsPrivate(this)) |
498 | { |
499 | fromMap(map); |
500 | } |
501 | |
502 | NetworkManager::ConnectionSettings::~ConnectionSettings() |
503 | { |
504 | d_ptr->clearSettings(); |
505 | |
506 | delete d_ptr; |
507 | } |
508 | |
509 | void NetworkManager::ConnectionSettings::fromMap(const NMVariantMapMap &map) |
510 | { |
511 | QVariantMap connectionSettings = map.value(key: QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME)); |
512 | |
513 | setId(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_ID)).toString()); |
514 | setUuid(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_UUID)).toString()); |
515 | setConnectionType(type: typeFromString(typeString: connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_TYPE)).toString())); |
516 | |
517 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_INTERFACE_NAME))) { |
518 | setInterfaceName(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_INTERFACE_NAME)).toString()); |
519 | } |
520 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS))) { |
521 | const QStringList permissions = connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS)).toStringList(); |
522 | for (const QString &permission : permissions) { |
523 | const QStringList split = permission.split(sep: QLatin1Char(':'), behavior: Qt::KeepEmptyParts); |
524 | addToPermissions(user: split.at(i: 1), type: split.at(i: 2)); |
525 | } |
526 | } |
527 | |
528 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT))) { |
529 | setAutoconnect(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT)).toBool()); |
530 | } |
531 | |
532 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY))) { |
533 | setAutoconnectPriority(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY)).toInt()); |
534 | } |
535 | |
536 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_TIMESTAMP))) { |
537 | const int timestamp = connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_TIMESTAMP)).toInt(); |
538 | setTimestamp(QDateTime::fromSecsSinceEpoch(secs: timestamp)); |
539 | } |
540 | |
541 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_READ_ONLY))) { |
542 | setReadOnly(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_READ_ONLY)).toBool()); |
543 | } |
544 | |
545 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_ZONE))) { |
546 | setZone(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_ZONE)).toString()); |
547 | } |
548 | |
549 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_MASTER))) { |
550 | setMaster(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_MASTER)).toString()); |
551 | } |
552 | |
553 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_SLAVE_TYPE))) { |
554 | setSlaveType(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_SLAVE_TYPE)).toString()); |
555 | } |
556 | |
557 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_SECONDARIES))) { |
558 | setSecondaries(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_SECONDARIES)).toStringList()); |
559 | } |
560 | |
561 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT))) { |
562 | setGatewayPingTimeout(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT)).toUInt()); |
563 | } |
564 | |
565 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES))) { |
566 | setAutoconnectRetries(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES)).toInt()); |
567 | } |
568 | |
569 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES))) { |
570 | setAutoconnectSlaves( |
571 | (NetworkManager::ConnectionSettings::AutoconnectSlaves)connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES)).toInt()); |
572 | } |
573 | |
574 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_LLDP))) { |
575 | setLldp((NetworkManager::ConnectionSettings::Lldp)connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_LLDP)).toInt()); |
576 | } |
577 | |
578 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_METERED))) { |
579 | setMetered((NetworkManager::ConnectionSettings::Metered)connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_METERED)).toInt()); |
580 | } |
581 | |
582 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_MDNS))) { |
583 | setMdns((NetworkManager::ConnectionSettings::Mdns)connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_MDNS)).toInt()); |
584 | } |
585 | |
586 | if (connectionSettings.contains(key: QLatin1String(NM_SETTING_CONNECTION_STABLE_ID))) { |
587 | setStableId(connectionSettings.value(key: QLatin1String(NM_SETTING_CONNECTION_STABLE_ID)).toString()); |
588 | } |
589 | |
590 | const auto settingsList = settings(); |
591 | for (const Setting::Ptr &setting : settingsList) { |
592 | if (map.contains(key: setting->name())) { |
593 | setting->fromMap(map: map.value(key: setting->name())); |
594 | setting->setInitialized(true); |
595 | } else { |
596 | setting->setInitialized(false); |
597 | } |
598 | } |
599 | } |
600 | |
601 | static struct { |
602 | const char *name; |
603 | NetworkManager::Security8021xSetting::EapMethod method; |
604 | } constexpr const eap_methods[] = { |
605 | {.name: "PEAP" , .method: NetworkManager::Security8021xSetting::EapMethodPeap}, |
606 | {.name: "PWD" , .method: NetworkManager::Security8021xSetting::EapMethodPwd}, |
607 | {.name: "TLS" , .method: NetworkManager::Security8021xSetting::EapMethodTls}, |
608 | {.name: "TTLS" , .method: NetworkManager::Security8021xSetting::EapMethodTtls}, |
609 | }; |
610 | |
611 | static struct { |
612 | const char *name; |
613 | NetworkManager::Security8021xSetting::AuthMethod method; |
614 | } constexpr const auth_methods[] = { |
615 | {.name: "GTC" , .method: NetworkManager::Security8021xSetting::AuthMethodGtc}, |
616 | {.name: "MSCHAP" , .method: NetworkManager::Security8021xSetting::AuthMethodMschap}, |
617 | {.name: "MSCHAPV2" , .method: NetworkManager::Security8021xSetting::AuthMethodMschapv2}, |
618 | {.name: "PAP" , .method: NetworkManager::Security8021xSetting::AuthMethodPap}, |
619 | }; |
620 | |
621 | void NetworkManager::ConnectionSettings::fromMeCard(const QVariantMap &map) |
622 | { |
623 | const auto ssid = map.value(key: QLatin1String("S" )).toString(); |
624 | setId(ssid); |
625 | |
626 | auto wifiSetting = setting(Setting::Wireless).dynamicCast<WirelessSetting>(); |
627 | wifiSetting->setInitialized(true); |
628 | wifiSetting->setSsid(ssid.toUtf8()); |
629 | |
630 | auto wifiSecurity = setting(Setting::WirelessSecurity).dynamicCast<WirelessSecuritySetting>(); |
631 | const auto securityType = map.value(key: QLatin1String("T" )).toString(); |
632 | |
633 | if (!securityType.isEmpty() && securityType != QLatin1String("nopass" )) { |
634 | wifiSecurity->setInitialized(true); |
635 | } |
636 | |
637 | if (securityType == QLatin1String("WPA" ) || securityType == QLatin1String("WEP" )) { |
638 | wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk); |
639 | wifiSecurity->setPsk(map.value(key: QLatin1String("P" )).toString()); |
640 | wifiSecurity->setPskFlags(NetworkManager::Setting::AgentOwned); |
641 | } else if (securityType == QLatin1String("WPA2-EAP" )) { |
642 | wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap); |
643 | auto sec8021x = setting(Setting::Security8021x).dynamicCast<Security8021xSetting>(); |
644 | sec8021x->setAnonymousIdentity(map.value(key: QLatin1String("A" )).toString()); |
645 | sec8021x->setIdentity(map.value(key: QLatin1String("I" )).toString()); |
646 | sec8021x->setPassword(map.value(key: QLatin1String("P" )).toString()); |
647 | |
648 | const auto eapMethod = map.value(key: QLatin1String("E" )).toString(); |
649 | for (const auto &method : eap_methods) { |
650 | if (eapMethod == QLatin1String(method.name)) { |
651 | sec8021x->setEapMethods({method.method}); |
652 | break; |
653 | } |
654 | } |
655 | const auto phase2AuthMethod = map.value(key: QLatin1String("PH2" )).toString(); |
656 | for (const auto &method : auth_methods) { |
657 | if (phase2AuthMethod == QLatin1String(method.name)) { |
658 | sec8021x->setPhase2AuthMethod(method.method); |
659 | break; |
660 | } |
661 | } |
662 | } |
663 | } |
664 | |
665 | NMVariantMapMap NetworkManager::ConnectionSettings::toMap() const |
666 | { |
667 | NMVariantMapMap result; |
668 | QVariantMap connectionSetting; |
669 | |
670 | if (!id().isEmpty()) { |
671 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_ID), value: id()); |
672 | } |
673 | |
674 | if (!uuid().isEmpty()) { |
675 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_UUID), value: uuid()); |
676 | } |
677 | |
678 | if (connectionType()) { |
679 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_TYPE), value: typeAsString(type: connectionType())); |
680 | } |
681 | |
682 | if (!interfaceName().isEmpty()) { |
683 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_INTERFACE_NAME), value: interfaceName()); |
684 | } |
685 | |
686 | if (!permissions().isEmpty()) { |
687 | QStringList perm; |
688 | QHash<QString, QString> perms = permissions(); |
689 | QHash<QString, QString>::const_iterator it = perms.constBegin(); |
690 | while (it != perms.constEnd()) { |
691 | const QString tmp = "user:" + it.key() + ':' + it.value(); |
692 | perm << tmp; |
693 | ++it; |
694 | } |
695 | |
696 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS), value: perm); |
697 | } |
698 | |
699 | if (!autoconnect()) { |
700 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT), value: autoconnect()); |
701 | } |
702 | |
703 | if (autoconnectPriority()) { |
704 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), value: autoconnectPriority()); |
705 | } |
706 | |
707 | if (timestamp().isValid()) { |
708 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_TIMESTAMP), value: timestamp().toSecsSinceEpoch()); |
709 | } |
710 | |
711 | if (readOnly()) { |
712 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_READ_ONLY), value: readOnly()); |
713 | } |
714 | |
715 | if (!zone().isEmpty()) { |
716 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_ZONE), value: zone()); |
717 | } |
718 | |
719 | if (!master().isEmpty()) { |
720 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_MASTER), value: master()); |
721 | } |
722 | |
723 | if (!slaveType().isEmpty()) { |
724 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_SLAVE_TYPE), value: slaveType()); |
725 | } |
726 | |
727 | if (!secondaries().isEmpty()) { |
728 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_SECONDARIES), value: secondaries()); |
729 | } |
730 | |
731 | if (gatewayPingTimeout()) { |
732 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), value: gatewayPingTimeout()); |
733 | } |
734 | |
735 | if (autoconnectRetries() >= 0) { |
736 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES), value: autoconnectRetries()); |
737 | } |
738 | |
739 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), value: autoconnectSlaves()); |
740 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_LLDP), value: lldp()); |
741 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_METERED), value: metered()); |
742 | |
743 | if (mdns() != MdnsDefault) { |
744 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_MDNS), value: mdns()); |
745 | } |
746 | |
747 | if (!stableId().isEmpty()) { |
748 | connectionSetting.insert(key: QLatin1String(NM_SETTING_CONNECTION_STABLE_ID), value: stableId()); |
749 | } |
750 | |
751 | result.insert(key: QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME), value: connectionSetting); |
752 | |
753 | const auto settingsList = settings(); |
754 | for (const Setting::Ptr &setting : settingsList) { |
755 | QVariantMap map = setting->toMap(); |
756 | if (!setting->isNull()) { |
757 | result.insert(key: setting->name(), value: map); |
758 | } |
759 | } |
760 | return result; |
761 | } |
762 | |
763 | QString NetworkManager::ConnectionSettings::name() const |
764 | { |
765 | Q_D(const ConnectionSettings); |
766 | |
767 | return d->name; |
768 | } |
769 | |
770 | void NetworkManager::ConnectionSettings::setId(const QString &id) |
771 | { |
772 | Q_D(ConnectionSettings); |
773 | |
774 | d->id = id; |
775 | } |
776 | |
777 | QString NetworkManager::ConnectionSettings::id() const |
778 | { |
779 | Q_D(const ConnectionSettings); |
780 | |
781 | return d->id; |
782 | } |
783 | |
784 | void NetworkManager::ConnectionSettings::setUuid(const QString &uuid) |
785 | { |
786 | Q_D(ConnectionSettings); |
787 | |
788 | d->uuid = uuid; |
789 | } |
790 | |
791 | QString NetworkManager::ConnectionSettings::uuid() const |
792 | { |
793 | Q_D(const ConnectionSettings); |
794 | |
795 | return d->uuid; |
796 | } |
797 | |
798 | void NetworkManager::ConnectionSettings::setInterfaceName(const QString &interfaceName) |
799 | { |
800 | Q_D(ConnectionSettings); |
801 | |
802 | d->interfaceName = interfaceName; |
803 | } |
804 | |
805 | QString NetworkManager::ConnectionSettings::interfaceName() const |
806 | { |
807 | Q_D(const ConnectionSettings); |
808 | |
809 | return d->interfaceName; |
810 | } |
811 | |
812 | void NetworkManager::ConnectionSettings::setConnectionType(NetworkManager::ConnectionSettings::ConnectionType type, NMBluetoothCapabilities bt_cap) |
813 | { |
814 | Q_D(ConnectionSettings); |
815 | |
816 | d->type = type; |
817 | d->initSettings(bt_cap); |
818 | } |
819 | |
820 | NetworkManager::ConnectionSettings::ConnectionType NetworkManager::ConnectionSettings::connectionType() const |
821 | { |
822 | Q_D(const ConnectionSettings); |
823 | |
824 | return d->type; |
825 | } |
826 | |
827 | void NetworkManager::ConnectionSettings::addToPermissions(const QString &user, const QString &type) |
828 | { |
829 | Q_D(ConnectionSettings); |
830 | |
831 | d->permissions.insert(key: user, value: type); |
832 | } |
833 | |
834 | void NetworkManager::ConnectionSettings::setPermissions(const QHash<QString, QString> &perm) |
835 | { |
836 | Q_D(ConnectionSettings); |
837 | |
838 | d->permissions = perm; |
839 | } |
840 | |
841 | QHash<QString, QString> NetworkManager::ConnectionSettings::permissions() const |
842 | { |
843 | Q_D(const ConnectionSettings); |
844 | |
845 | return d->permissions; |
846 | } |
847 | |
848 | void NetworkManager::ConnectionSettings::setAutoconnect(bool autoconnect) |
849 | { |
850 | Q_D(ConnectionSettings); |
851 | |
852 | d->autoconnect = autoconnect; |
853 | } |
854 | |
855 | bool NetworkManager::ConnectionSettings::autoconnect() const |
856 | { |
857 | Q_D(const ConnectionSettings); |
858 | |
859 | return d->autoconnect; |
860 | } |
861 | |
862 | void NetworkManager::ConnectionSettings::setAutoconnectPriority(int priority) |
863 | { |
864 | Q_D(ConnectionSettings); |
865 | |
866 | d->autoconnectPriority = priority; |
867 | } |
868 | |
869 | int NetworkManager::ConnectionSettings::autoconnectPriority() const |
870 | { |
871 | Q_D(const ConnectionSettings); |
872 | |
873 | return d->autoconnectPriority; |
874 | } |
875 | |
876 | void NetworkManager::ConnectionSettings::setTimestamp(const QDateTime ×tamp) |
877 | { |
878 | Q_D(ConnectionSettings); |
879 | |
880 | d->timestamp = timestamp; |
881 | } |
882 | |
883 | QDateTime NetworkManager::ConnectionSettings::timestamp() const |
884 | { |
885 | Q_D(const ConnectionSettings); |
886 | |
887 | return d->timestamp; |
888 | } |
889 | |
890 | void NetworkManager::ConnectionSettings::setReadOnly(bool readonly) |
891 | { |
892 | Q_D(ConnectionSettings); |
893 | |
894 | d->readOnly = readonly; |
895 | } |
896 | |
897 | bool NetworkManager::ConnectionSettings::readOnly() const |
898 | { |
899 | Q_D(const ConnectionSettings); |
900 | |
901 | return d->readOnly; |
902 | } |
903 | |
904 | void NetworkManager::ConnectionSettings::setZone(const QString &zone) |
905 | { |
906 | Q_D(ConnectionSettings); |
907 | |
908 | d->zone = zone; |
909 | } |
910 | |
911 | QString NetworkManager::ConnectionSettings::zone() const |
912 | { |
913 | Q_D(const ConnectionSettings); |
914 | |
915 | return d->zone; |
916 | } |
917 | |
918 | bool NetworkManager::ConnectionSettings::isSlave() const |
919 | { |
920 | Q_D(const ConnectionSettings); |
921 | |
922 | return !d->master.isEmpty() && !d->slaveType.isEmpty(); |
923 | } |
924 | |
925 | void NetworkManager::ConnectionSettings::setMaster(const QString &master) |
926 | { |
927 | Q_D(ConnectionSettings); |
928 | |
929 | d->master = master; |
930 | } |
931 | |
932 | QString NetworkManager::ConnectionSettings::master() const |
933 | { |
934 | Q_D(const ConnectionSettings); |
935 | |
936 | return d->master; |
937 | } |
938 | |
939 | void NetworkManager::ConnectionSettings::setSlaveType(const QString &type) |
940 | { |
941 | Q_D(ConnectionSettings); |
942 | |
943 | d->slaveType = type; |
944 | } |
945 | |
946 | QString NetworkManager::ConnectionSettings::slaveType() const |
947 | { |
948 | Q_D(const ConnectionSettings); |
949 | |
950 | return d->slaveType; |
951 | } |
952 | |
953 | void NetworkManager::ConnectionSettings::setSecondaries(const QStringList &secondaries) |
954 | { |
955 | Q_D(ConnectionSettings); |
956 | |
957 | d->secondaries = secondaries; |
958 | } |
959 | |
960 | QStringList NetworkManager::ConnectionSettings::secondaries() const |
961 | { |
962 | Q_D(const ConnectionSettings); |
963 | |
964 | return d->secondaries; |
965 | } |
966 | |
967 | void NetworkManager::ConnectionSettings::setGatewayPingTimeout(quint32 timeout) |
968 | { |
969 | Q_D(ConnectionSettings); |
970 | |
971 | d->gatewayPingTimeout = timeout; |
972 | } |
973 | |
974 | quint32 NetworkManager::ConnectionSettings::gatewayPingTimeout() const |
975 | { |
976 | Q_D(const ConnectionSettings); |
977 | |
978 | return d->gatewayPingTimeout; |
979 | } |
980 | |
981 | int NetworkManager::ConnectionSettings::autoconnectRetries() const |
982 | { |
983 | Q_D(const ConnectionSettings); |
984 | |
985 | return d->autoconnectRetries; |
986 | } |
987 | |
988 | void NetworkManager::ConnectionSettings::setAutoconnectRetries(int retries) |
989 | { |
990 | Q_D(ConnectionSettings); |
991 | |
992 | d->autoconnectRetries = retries; |
993 | } |
994 | |
995 | NetworkManager::ConnectionSettings::AutoconnectSlaves NetworkManager::ConnectionSettings::autoconnectSlaves() const |
996 | { |
997 | Q_D(const ConnectionSettings); |
998 | |
999 | return d->autoconnectSlaves; |
1000 | } |
1001 | |
1002 | void NetworkManager::ConnectionSettings::setAutoconnectSlaves(NetworkManager::ConnectionSettings::AutoconnectSlaves autoconnectSlaves) |
1003 | { |
1004 | Q_D(ConnectionSettings); |
1005 | |
1006 | d->autoconnectSlaves = autoconnectSlaves; |
1007 | } |
1008 | |
1009 | NetworkManager::ConnectionSettings::Lldp NetworkManager::ConnectionSettings::lldp() const |
1010 | { |
1011 | Q_D(const ConnectionSettings); |
1012 | |
1013 | return d->lldp; |
1014 | } |
1015 | |
1016 | void NetworkManager::ConnectionSettings::setLldp(NetworkManager::ConnectionSettings::Lldp lldp) |
1017 | { |
1018 | Q_D(ConnectionSettings); |
1019 | |
1020 | d->lldp = lldp; |
1021 | } |
1022 | |
1023 | NetworkManager::ConnectionSettings::Metered NetworkManager::ConnectionSettings::metered() const |
1024 | { |
1025 | Q_D(const ConnectionSettings); |
1026 | |
1027 | return d->metered; |
1028 | } |
1029 | |
1030 | void NetworkManager::ConnectionSettings::setMetered(NetworkManager::ConnectionSettings::Metered metered) |
1031 | { |
1032 | Q_D(ConnectionSettings); |
1033 | |
1034 | d->metered = metered; |
1035 | } |
1036 | |
1037 | NetworkManager::ConnectionSettings::Mdns NetworkManager::ConnectionSettings::mdns() const |
1038 | { |
1039 | Q_D(const ConnectionSettings); |
1040 | |
1041 | return d->mdns; |
1042 | } |
1043 | |
1044 | void NetworkManager::ConnectionSettings::setMdns(NetworkManager::ConnectionSettings::Mdns mdns) |
1045 | { |
1046 | Q_D(ConnectionSettings); |
1047 | |
1048 | d->mdns = mdns; |
1049 | } |
1050 | |
1051 | QString NetworkManager::ConnectionSettings::stableId() const |
1052 | { |
1053 | Q_D(const ConnectionSettings); |
1054 | |
1055 | return d->stableId; |
1056 | } |
1057 | |
1058 | void NetworkManager::ConnectionSettings::setStableId(const QString &stableId) |
1059 | { |
1060 | Q_D(ConnectionSettings); |
1061 | |
1062 | d->stableId = stableId; |
1063 | } |
1064 | |
1065 | NetworkManager::Setting::Ptr NetworkManager::ConnectionSettings::setting(Setting::SettingType type) const |
1066 | { |
1067 | const auto settingsList = settings(); |
1068 | for (const Setting::Ptr &setting : settingsList) { |
1069 | if (setting->type() == type) { |
1070 | return setting; |
1071 | } |
1072 | } |
1073 | |
1074 | return Setting::Ptr(); |
1075 | } |
1076 | |
1077 | NetworkManager::Setting::Ptr NetworkManager::ConnectionSettings::setting(const QString &type) const |
1078 | { |
1079 | return setting(Setting::typeFromString(type)); |
1080 | } |
1081 | |
1082 | NetworkManager::Setting::List NetworkManager::ConnectionSettings::settings() const |
1083 | { |
1084 | Q_D(const ConnectionSettings); |
1085 | |
1086 | return d->settings; |
1087 | } |
1088 | |
1089 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::ConnectionSettings &setting) |
1090 | { |
1091 | dbg.nospace() << "CONNECTION SETTINGS\n" ; |
1092 | dbg.nospace() << "===================\n" ; |
1093 | |
1094 | dbg.nospace() << NM_SETTING_CONNECTION_ID << ": " << setting.id() << '\n'; |
1095 | dbg.nospace() << NM_SETTING_CONNECTION_UUID << ": " << setting.uuid() << '\n'; |
1096 | dbg.nospace() << NM_SETTING_CONNECTION_INTERFACE_NAME << ": " << setting.interfaceName() << '\n'; |
1097 | dbg.nospace() << NM_SETTING_CONNECTION_TYPE << ": " << setting.typeAsString(type: setting.connectionType()) << '\n'; |
1098 | dbg.nospace() << NM_SETTING_CONNECTION_PERMISSIONS << ": " << setting.permissions() << '\n'; |
1099 | dbg.nospace() << NM_SETTING_CONNECTION_AUTOCONNECT << ": " << setting.autoconnect() << '\n'; |
1100 | dbg.nospace() << NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY << ": " << setting.autoconnectPriority() << '\n'; |
1101 | dbg.nospace() << NM_SETTING_CONNECTION_TIMESTAMP << ": " << setting.timestamp().toSecsSinceEpoch() << '\n'; |
1102 | dbg.nospace() << NM_SETTING_CONNECTION_READ_ONLY << ": " << setting.readOnly() << '\n'; |
1103 | dbg.nospace() << NM_SETTING_CONNECTION_ZONE << ": " << setting.zone() << '\n'; |
1104 | dbg.nospace() << NM_SETTING_CONNECTION_MASTER << ": " << setting.master() << '\n'; |
1105 | dbg.nospace() << NM_SETTING_CONNECTION_SLAVE_TYPE << ": " << setting.slaveType() << '\n'; |
1106 | dbg.nospace() << NM_SETTING_CONNECTION_SECONDARIES << ": " << setting.secondaries() << '\n'; |
1107 | dbg.nospace() << NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT << ": " << setting.gatewayPingTimeout() << '\n'; |
1108 | dbg.nospace() << NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES << ": " << setting.autoconnectRetries() << '\n'; |
1109 | dbg.nospace() << NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES << ": " << setting.autoconnectSlaves() << '\n'; |
1110 | dbg.nospace() << NM_SETTING_CONNECTION_LLDP << ": " << setting.lldp() << '\n'; |
1111 | dbg.nospace() << NM_SETTING_CONNECTION_METERED << ": " << setting.metered() << '\n'; |
1112 | dbg.nospace() << NM_SETTING_CONNECTION_MDNS << ": " << setting.mdns() << '\n'; |
1113 | dbg.nospace() << NM_SETTING_CONNECTION_STABLE_ID << ": " << setting.stableId() << '\n'; |
1114 | dbg.nospace() << "===================\n" ; |
1115 | const auto settingsList = setting.settings(); |
1116 | for (const Setting::Ptr &settingPtr : settingsList) { |
1117 | dbg.nospace() << settingPtr->typeAsString(type: settingPtr->type()).toUpper() << " SETTINGS\n" ; |
1118 | dbg.nospace() << "---------------------------\n" ; |
1119 | switch (settingPtr->type()) { |
1120 | case Setting::Adsl: |
1121 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::AdslSetting>().data()); |
1122 | break; |
1123 | case Setting::Bond: |
1124 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::BondSetting>().data()); |
1125 | break; |
1126 | case Setting::Bluetooth: |
1127 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::BluetoothSetting>().data()); |
1128 | break; |
1129 | case Setting::Bridge: |
1130 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::BridgeSetting>().data()); |
1131 | break; |
1132 | case Setting::BridgePort: |
1133 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::BridgePortSetting>().data()); |
1134 | break; |
1135 | case Setting::Cdma: |
1136 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::CdmaSetting>().data()); |
1137 | break; |
1138 | case Setting::Gsm: |
1139 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::GsmSetting>().data()); |
1140 | break; |
1141 | case Setting::Infiniband: |
1142 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::InfinibandSetting>().data()); |
1143 | break; |
1144 | case Setting::Ipv4: |
1145 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::Ipv4Setting>().data()); |
1146 | break; |
1147 | case Setting::Ipv6: |
1148 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::Ipv6Setting>().data()); |
1149 | break; |
1150 | case Setting::OlpcMesh: |
1151 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::OlpcMeshSetting>().data()); |
1152 | break; |
1153 | case Setting::Ppp: |
1154 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::PppSetting>().data()); |
1155 | break; |
1156 | case Setting::Pppoe: |
1157 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::PppoeSetting>().data()); |
1158 | break; |
1159 | case Setting::Security8021x: |
1160 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::Security8021xSetting>().data()); |
1161 | break; |
1162 | case Setting::Serial: |
1163 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::SerialSetting>().data()); |
1164 | break; |
1165 | case Setting::Vlan: |
1166 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::VlanSetting>().data()); |
1167 | break; |
1168 | case Setting::Vpn: |
1169 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::VpnSetting>().data()); |
1170 | break; |
1171 | case Setting::Wimax: |
1172 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::WimaxSetting>().data()); |
1173 | break; |
1174 | case Setting::Wired: |
1175 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::WiredSetting>().data()); |
1176 | break; |
1177 | case Setting::Wireless: |
1178 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::WirelessSetting>().data()); |
1179 | break; |
1180 | case Setting::WirelessSecurity: |
1181 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::WirelessSecuritySetting>().data()); |
1182 | break; |
1183 | case Setting::Team: |
1184 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::TeamSetting>().data()); |
1185 | break; |
1186 | case Setting::Tun: |
1187 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::TunSetting>().data()); |
1188 | break; |
1189 | case Setting::IpTunnel: |
1190 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::IpTunnelSetting>().data()); |
1191 | break; |
1192 | case Setting::WireGuard: |
1193 | dbg.nospace() << *(settingPtr.staticCast<NetworkManager::WireGuardSetting>().data()); |
1194 | break; |
1195 | default: |
1196 | dbg.nospace() << *settingPtr.data(); |
1197 | } |
1198 | |
1199 | dbg.nospace() << '\n'; |
1200 | } |
1201 | return dbg.maybeSpace(); |
1202 | } |
1203 | |