NetworkManagerQt

iptunnelsetting.cpp
1/*
2 SPDX-FileCopyrightText: Pranav Gade <pranavgade20@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "iptunnelsetting.h"
8#include "iptunnelsetting_p.h"
9
10#include <QDebug>
11
12#if !NM_CHECK_VERSION(1, 12, 0)
13#define NM_SETTING_IP_TUNNEL_FLAGS "flags"
14#endif
15
16NetworkManager::IpTunnelSettingPrivate::IpTunnelSettingPrivate()
17 : name(NM_SETTING_IP_TUNNEL_SETTING_NAME)
18 , mode(IpTunnelSetting::Unknown)
19 , pathMtuDiscovery(true)
20 , encapsulationLimit(0)
21 , flags(IpTunnelSetting::None)
22 , flowLabel(0)
23 , mtu(0)
24 , tos(0)
25 , ttl(0)
26{
27}
28
29NetworkManager::IpTunnelSetting::IpTunnelSetting()
30 : Setting(Setting::IpTunnel)
31 , d_ptr(new IpTunnelSettingPrivate())
32{
33}
34
35NetworkManager::IpTunnelSetting::IpTunnelSetting(const Ptr &other)
36 : Setting(other)
37 , d_ptr(new IpTunnelSettingPrivate())
38{
39 setMode(other->mode());
40 setPathMtuDiscovery(other->pathMtuDiscovery());
41 setEncapsulationLimit(other->encapsulationLimit());
42 setFlags(other->flags());
43 setFlowLabel(other->flowLabel());
44 setMtu(other->mtu());
45 setTos(other->tos());
46 setTtl(other->ttl());
47 setInputKey(other->inputKey());
48 setLocal(other->local());
49 setOutputKey(other->outputKey());
50 setParent(other->parent());
51 setRemote(other->remote());
52}
53
54NetworkManager::IpTunnelSetting::~IpTunnelSetting()
55{
56 delete d_ptr;
57}
58
60{
61 Q_D(const IpTunnelSetting);
62
63 return d->name;
64}
65
66void NetworkManager::IpTunnelSetting::setMode(NetworkManager::IpTunnelSetting::Mode mode)
67{
69
70 d->mode = mode;
71}
72
73NetworkManager::IpTunnelSetting::Mode NetworkManager::IpTunnelSetting::mode() const
74{
75 Q_D(const IpTunnelSetting);
76
77 return d->mode;
78}
79
80void NetworkManager::IpTunnelSetting::setPathMtuDiscovery(bool discovery)
81{
82 Q_D(IpTunnelSetting);
83
84 d->pathMtuDiscovery = discovery;
85}
86
87bool NetworkManager::IpTunnelSetting::pathMtuDiscovery() const
88{
89 Q_D(const IpTunnelSetting);
90
91 return d->pathMtuDiscovery;
92}
93
94void NetworkManager::IpTunnelSetting::setEncapsulationLimit(quint32 limit)
95{
96 Q_D(IpTunnelSetting);
97
98 d->encapsulationLimit = limit;
99}
100
101quint32 NetworkManager::IpTunnelSetting::encapsulationLimit() const
102{
103 Q_D(const IpTunnelSetting);
104
105 return d->encapsulationLimit;
106}
107
108void NetworkManager::IpTunnelSetting::setFlags(NetworkManager::IpTunnelSetting::Flags flags)
109{
110 Q_D(IpTunnelSetting);
111
112 d->flags = flags;
113}
114
115NetworkManager::IpTunnelSetting::Flags NetworkManager::IpTunnelSetting::flags() const
116{
117 Q_D(const IpTunnelSetting);
118
119 return d->flags;
120}
121
122void NetworkManager::IpTunnelSetting::setFlowLabel(quint32 label)
123{
124 Q_D(IpTunnelSetting);
125
126 d->flowLabel = label;
127}
128
129quint32 NetworkManager::IpTunnelSetting::flowLabel() const
130{
131 Q_D(const IpTunnelSetting);
132
133 return d->flowLabel;
134}
135
136void NetworkManager::IpTunnelSetting::setMtu(quint32 mtu)
137{
138 Q_D(IpTunnelSetting);
139
140 d->mtu = mtu;
141}
142
143quint32 NetworkManager::IpTunnelSetting::mtu() const
144{
145 Q_D(const IpTunnelSetting);
146
147 return d->mtu;
148}
149
150void NetworkManager::IpTunnelSetting::setTos(quint32 tos)
151{
152 Q_D(IpTunnelSetting);
153
154 d->tos = tos;
155}
156
157quint32 NetworkManager::IpTunnelSetting::tos() const
158{
159 Q_D(const IpTunnelSetting);
160
161 return d->tos;
162}
163
164void NetworkManager::IpTunnelSetting::setTtl(quint32 ttl)
165{
166 Q_D(IpTunnelSetting);
167
168 d->ttl = ttl;
169}
170
171quint32 NetworkManager::IpTunnelSetting::ttl() const
172{
173 Q_D(const IpTunnelSetting);
174
175 return d->ttl;
176}
177
178void NetworkManager::IpTunnelSetting::setInputKey(const QString &key)
179{
180 Q_D(IpTunnelSetting);
181
182 d->inputKey = key;
183}
184
185QString NetworkManager::IpTunnelSetting::inputKey() const
186{
187 Q_D(const IpTunnelSetting);
188
189 return d->inputKey;
190}
191
192void NetworkManager::IpTunnelSetting::setLocal(const QString &local)
193{
194 Q_D(IpTunnelSetting);
195
196 d->local = local;
197}
198
199QString NetworkManager::IpTunnelSetting::local() const
200{
201 Q_D(const IpTunnelSetting);
202
203 return d->local;
204}
205
206void NetworkManager::IpTunnelSetting::setParent(const QString &parent)
207{
208 Q_D(IpTunnelSetting);
209
210 d->parent = parent;
211}
212
213QString NetworkManager::IpTunnelSetting::parent() const
214{
215 Q_D(const IpTunnelSetting);
216
217 return d->parent;
218}
219
220void NetworkManager::IpTunnelSetting::setOutputKey(const QString &key)
221{
222 Q_D(IpTunnelSetting);
223
224 d->outputKey = key;
225}
226
227QString NetworkManager::IpTunnelSetting::outputKey() const
228{
229 Q_D(const IpTunnelSetting);
230
231 return d->outputKey;
232}
233
234void NetworkManager::IpTunnelSetting::setRemote(const QString &remote)
235{
236 Q_D(IpTunnelSetting);
237
238 d->remote = remote;
239}
240
241QString NetworkManager::IpTunnelSetting::remote() const
242{
243 Q_D(const IpTunnelSetting);
244
245 return d->remote;
246}
247
248void NetworkManager::IpTunnelSetting::fromMap(const QVariantMap &setting)
249{
250 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_MODE))) {
251 setMode((Mode)setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_MODE)).toUInt());
252 }
253
254 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY))) {
255 setPathMtuDiscovery(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY)).toBool());
256 }
257
258 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT))) {
259 setEncapsulationLimit(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT)).toUInt());
260 }
261
262 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS))) {
263 setFlags((Flag)setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS)).toUInt());
264 }
265
266 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL))) {
267 setFlowLabel(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL)).toUInt());
268 }
269
270 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_MTU))) {
271 setMtu(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_MTU)).toUInt());
272 }
273
274 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_TOS))) {
275 setTos(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_TOS)).toUInt());
276 }
277
278 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_TTL))) {
279 setTtl(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_TTL)).toUInt());
280 }
281
282 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY))) {
283 setInputKey(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY)).toString());
284 }
285
286 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL))) {
287 setLocal(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL)).toString());
288 }
289
290 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT))) {
291 setParent(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT)).toString());
292 }
293
294 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY))) {
295 setOutputKey(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY)).toString());
296 }
297
298 if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE))) {
299 setRemote(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE)).toString());
300 }
301}
302
304{
305 QVariantMap setting;
306
307 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY), pathMtuDiscovery());
308
309 if (mode() != Unknown) {
310 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_MODE), (int)mode());
311 }
312
313 if (encapsulationLimit() > 0) {
314 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT), encapsulationLimit());
315 }
316
317 if (flags() > None) {
318 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS), (int)flags());
319 }
320
321 if (flowLabel() > 0) {
322 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL), flowLabel());
323 }
324
325 if (mtu() > 0) {
326 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_MTU), mtu());
327 }
328
329 if (tos() > 0) {
330 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_TOS), tos());
331 }
332
333 if (ttl() > 0) {
334 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_TTL), ttl());
335 }
336
337 if (!inputKey().isEmpty()) {
338 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY), inputKey());
339 }
340
341 if (!local().isEmpty()) {
342 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL), local());
343 }
344
345 if (!parent().isEmpty()) {
346 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT), parent());
347 }
348
349 if (!outputKey().isEmpty()) {
350 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY), outputKey());
351 }
352
353 if (!remote().isEmpty()) {
354 setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE), remote());
355 }
356
357 return setting;
358}
359
360QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::IpTunnelSetting &setting)
361{
362 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
363 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
364
365 dbg.nospace() << NM_SETTING_IP_TUNNEL_MODE << ": " << setting.mode() << '\n';
366 dbg.nospace() << NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY << ": " << setting.pathMtuDiscovery() << '\n';
367 dbg.nospace() << NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT << ": " << setting.encapsulationLimit() << '\n';
368 dbg.nospace() << NM_SETTING_IP_TUNNEL_FLAGS << ": " << setting.flags() << '\n';
369 dbg.nospace() << NM_SETTING_IP_TUNNEL_FLOW_LABEL << ": " << setting.flowLabel() << '\n';
370 dbg.nospace() << NM_SETTING_IP_TUNNEL_MTU << ": " << setting.mtu() << '\n';
371 dbg.nospace() << NM_SETTING_IP_TUNNEL_TOS << ": " << setting.tos() << '\n';
372 dbg.nospace() << NM_SETTING_IP_TUNNEL_TTL << ": " << setting.ttl() << '\n';
373 dbg.nospace() << NM_SETTING_IP_TUNNEL_INPUT_KEY << ": " << setting.inputKey() << '\n';
374 dbg.nospace() << NM_SETTING_IP_TUNNEL_LOCAL << ": " << setting.local() << '\n';
375 dbg.nospace() << NM_SETTING_IP_TUNNEL_PARENT << ": " << setting.parent() << '\n';
376 dbg.nospace() << NM_SETTING_IP_TUNNEL_OUTPUT_KEY << ": " << setting.outputKey() << '\n';
377 dbg.nospace() << NM_SETTING_IP_TUNNEL_REMOTE << ": " << setting.remote() << '\n';
378
379 return dbg.maybeSpace();
380}
Represents IpTunnel setting.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
QString label(StandardShortcut id)
@ Unknown
the networking system is not active or unable to report its status - proceed with caution
Definition manager.h:33
QDebug & maybeSpace()
QDebug & nospace()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:59:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.