1 | /* |
2 | SPDX-FileCopyrightText: 2018 Billy Laws <blaws05@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 "vxlansetting.h" |
8 | #include "vxlansetting_p.h" |
9 | |
10 | #include <QDebug> |
11 | |
12 | NetworkManager::VxlanSettingPrivate::VxlanSettingPrivate() |
13 | : name(NM_SETTING_VXLAN_SETTING_NAME) |
14 | , ageing(32) |
15 | , destinationPort(8472) |
16 | , id(0) |
17 | , l2Miss(false) |
18 | , l3Miss(false) |
19 | , learning(true) |
20 | , limit(0) |
21 | , proxy(false) |
22 | , rsc(false) |
23 | , sourcePortMax(0) |
24 | , sourcePortMin(0) |
25 | , tos(0) |
26 | , ttl(0) |
27 | { |
28 | } |
29 | |
30 | NetworkManager::VxlanSetting::VxlanSetting() |
31 | : Setting(Setting::Vxlan) |
32 | , d_ptr(new VxlanSettingPrivate()) |
33 | { |
34 | } |
35 | |
36 | NetworkManager::VxlanSetting::VxlanSetting(const NetworkManager::VxlanSetting::Ptr &other) |
37 | : Setting(other) |
38 | , d_ptr(new VxlanSettingPrivate()) |
39 | { |
40 | setAgeing(other->ageing()); |
41 | setDestinationPort(other->destinationPort()); |
42 | setId(other->id()); |
43 | setL2Miss(other->l2Miss()); |
44 | setL3Miss(other->l3Miss()); |
45 | setLearning(other->learning()); |
46 | setLimit(other->limit()); |
47 | setLocal(other->local()); |
48 | setParent(other->parent()); |
49 | setProxy(other->proxy()); |
50 | setRemote(other->remote()); |
51 | setRsc(other->rsc()); |
52 | setSourcePortMax(other->sourcePortMax()); |
53 | setSourcePortMin(other->sourcePortMin()); |
54 | setTos(other->tos()); |
55 | setTtl(other->ttl()); |
56 | } |
57 | |
58 | NetworkManager::VxlanSetting::~VxlanSetting() |
59 | { |
60 | delete d_ptr; |
61 | } |
62 | |
63 | QString NetworkManager::VxlanSetting::name() const |
64 | { |
65 | Q_D(const VxlanSetting); |
66 | |
67 | return d->name; |
68 | } |
69 | |
70 | void NetworkManager::VxlanSetting::setAgeing(quint32 ageing) |
71 | { |
72 | Q_D(VxlanSetting); |
73 | |
74 | d->ageing = ageing; |
75 | } |
76 | |
77 | quint32 NetworkManager::VxlanSetting::ageing() const |
78 | { |
79 | Q_D(const VxlanSetting); |
80 | |
81 | return d->ageing; |
82 | } |
83 | |
84 | void NetworkManager::VxlanSetting::setDestinationPort(quint32 port) |
85 | { |
86 | Q_D(VxlanSetting); |
87 | |
88 | d->destinationPort = port; |
89 | } |
90 | |
91 | quint32 NetworkManager::VxlanSetting::destinationPort() const |
92 | { |
93 | Q_D(const VxlanSetting); |
94 | |
95 | return d->destinationPort; |
96 | } |
97 | |
98 | void NetworkManager::VxlanSetting::setId(quint32 id) |
99 | { |
100 | Q_D(VxlanSetting); |
101 | |
102 | d->id = id; |
103 | } |
104 | |
105 | quint32 NetworkManager::VxlanSetting::id() const |
106 | { |
107 | Q_D(const VxlanSetting); |
108 | |
109 | return d->id; |
110 | } |
111 | |
112 | void NetworkManager::VxlanSetting::setL2Miss(bool enable) |
113 | { |
114 | Q_D(VxlanSetting); |
115 | |
116 | d->l2Miss = enable; |
117 | } |
118 | |
119 | bool NetworkManager::VxlanSetting::l2Miss() const |
120 | { |
121 | Q_D(const VxlanSetting); |
122 | |
123 | return d->l2Miss; |
124 | } |
125 | |
126 | void NetworkManager::VxlanSetting::setL3Miss(bool enable) |
127 | { |
128 | Q_D(VxlanSetting); |
129 | |
130 | d->l3Miss = enable; |
131 | } |
132 | |
133 | bool NetworkManager::VxlanSetting::l3Miss() const |
134 | { |
135 | Q_D(const VxlanSetting); |
136 | |
137 | return d->l3Miss; |
138 | } |
139 | |
140 | void NetworkManager::VxlanSetting::setLearning(bool enable) |
141 | { |
142 | Q_D(VxlanSetting); |
143 | |
144 | d->learning = enable; |
145 | } |
146 | |
147 | bool NetworkManager::VxlanSetting::learning() const |
148 | { |
149 | Q_D(const VxlanSetting); |
150 | |
151 | return d->learning; |
152 | } |
153 | |
154 | void NetworkManager::VxlanSetting::setLimit(quint32 limit) |
155 | { |
156 | Q_D(VxlanSetting); |
157 | |
158 | d->limit = limit; |
159 | } |
160 | |
161 | quint32 NetworkManager::VxlanSetting::limit() const |
162 | { |
163 | Q_D(const VxlanSetting); |
164 | |
165 | return d->limit; |
166 | } |
167 | |
168 | void NetworkManager::VxlanSetting::setLocal(QString local) |
169 | { |
170 | Q_D(VxlanSetting); |
171 | |
172 | d->local = local; |
173 | } |
174 | |
175 | QString NetworkManager::VxlanSetting::local() const |
176 | { |
177 | Q_D(const VxlanSetting); |
178 | |
179 | return d->local; |
180 | } |
181 | |
182 | void NetworkManager::VxlanSetting::setParent(QString parent) |
183 | { |
184 | Q_D(VxlanSetting); |
185 | |
186 | d->parent = parent; |
187 | } |
188 | |
189 | QString NetworkManager::VxlanSetting::parent() const |
190 | { |
191 | Q_D(const VxlanSetting); |
192 | |
193 | return d->parent; |
194 | } |
195 | |
196 | void NetworkManager::VxlanSetting::setProxy(bool enable) |
197 | { |
198 | Q_D(VxlanSetting); |
199 | |
200 | d->proxy = enable; |
201 | } |
202 | |
203 | bool NetworkManager::VxlanSetting::proxy() const |
204 | { |
205 | Q_D(const VxlanSetting); |
206 | |
207 | return d->proxy; |
208 | } |
209 | |
210 | void NetworkManager::VxlanSetting::setRemote(QString remote) |
211 | { |
212 | Q_D(VxlanSetting); |
213 | |
214 | d->remote = remote; |
215 | } |
216 | |
217 | QString NetworkManager::VxlanSetting::remote() const |
218 | { |
219 | Q_D(const VxlanSetting); |
220 | |
221 | return d->remote; |
222 | } |
223 | |
224 | void NetworkManager::VxlanSetting::setRsc(bool enable) |
225 | { |
226 | Q_D(VxlanSetting); |
227 | |
228 | d->rsc = enable; |
229 | } |
230 | |
231 | bool NetworkManager::VxlanSetting::rsc() const |
232 | { |
233 | Q_D(const VxlanSetting); |
234 | |
235 | return d->rsc; |
236 | } |
237 | |
238 | void NetworkManager::VxlanSetting::setSourcePortMax(quint32 maxPort) |
239 | { |
240 | Q_D(VxlanSetting); |
241 | |
242 | d->sourcePortMax = maxPort; |
243 | } |
244 | |
245 | quint32 NetworkManager::VxlanSetting::sourcePortMax() const |
246 | { |
247 | Q_D(const VxlanSetting); |
248 | |
249 | return d->sourcePortMax; |
250 | } |
251 | |
252 | void NetworkManager::VxlanSetting::setSourcePortMin(quint32 minPort) |
253 | { |
254 | Q_D(VxlanSetting); |
255 | |
256 | d->sourcePortMin = minPort; |
257 | } |
258 | |
259 | quint32 NetworkManager::VxlanSetting::sourcePortMin() const |
260 | { |
261 | Q_D(const VxlanSetting); |
262 | |
263 | return d->sourcePortMin; |
264 | } |
265 | |
266 | void NetworkManager::VxlanSetting::setTos(quint32 tos) |
267 | { |
268 | Q_D(VxlanSetting); |
269 | |
270 | d->tos = tos; |
271 | } |
272 | |
273 | quint32 NetworkManager::VxlanSetting::tos() const |
274 | { |
275 | Q_D(const VxlanSetting); |
276 | |
277 | return d->tos; |
278 | } |
279 | |
280 | void NetworkManager::VxlanSetting::setTtl(quint32 ttl) |
281 | { |
282 | Q_D(VxlanSetting); |
283 | |
284 | d->ttl = ttl; |
285 | } |
286 | |
287 | quint32 NetworkManager::VxlanSetting::ttl() const |
288 | { |
289 | Q_D(const VxlanSetting); |
290 | |
291 | return d->ttl; |
292 | } |
293 | void NetworkManager::VxlanSetting::fromMap(const QVariantMap &setting) |
294 | { |
295 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_AGEING))) { |
296 | setAgeing(setting.value(key: QLatin1String(NM_SETTING_VXLAN_AGEING)).toUInt()); |
297 | } |
298 | |
299 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT))) { |
300 | setDestinationPort(setting.value(key: QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT)).toUInt()); |
301 | } |
302 | |
303 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_ID))) { |
304 | setId(setting.value(key: QLatin1String(NM_SETTING_VXLAN_ID)).toUInt()); |
305 | } |
306 | |
307 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_L2_MISS))) { |
308 | setL2Miss(setting.value(key: QLatin1String(NM_SETTING_VXLAN_L2_MISS)).toBool()); |
309 | } |
310 | |
311 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_L3_MISS))) { |
312 | setL3Miss(setting.value(key: QLatin1String(NM_SETTING_VXLAN_L3_MISS)).toBool()); |
313 | } |
314 | |
315 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_LEARNING))) { |
316 | setLearning(setting.value(key: QLatin1String(NM_SETTING_VXLAN_LEARNING)).toBool()); |
317 | } |
318 | |
319 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_LIMIT))) { |
320 | setLimit(setting.value(key: QLatin1String(NM_SETTING_VXLAN_LIMIT)).toUInt()); |
321 | } |
322 | |
323 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_LOCAL))) { |
324 | setLocal(setting.value(key: QLatin1String(NM_SETTING_VXLAN_LOCAL)).toString()); |
325 | } |
326 | |
327 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_PARENT))) { |
328 | setParent(setting.value(key: QLatin1String(NM_SETTING_VXLAN_PARENT)).toString()); |
329 | } |
330 | |
331 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_PROXY))) { |
332 | setProxy(setting.value(key: QLatin1String(NM_SETTING_VXLAN_PROXY)).toBool()); |
333 | } |
334 | |
335 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_REMOTE))) { |
336 | setRemote(setting.value(key: QLatin1String(NM_SETTING_VXLAN_REMOTE)).toString()); |
337 | } |
338 | |
339 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_RSC))) { |
340 | setRsc(setting.value(key: QLatin1String(NM_SETTING_VXLAN_RSC)).toBool()); |
341 | } |
342 | |
343 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX))) { |
344 | setSourcePortMax(setting.value(key: QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX)).toUInt()); |
345 | } |
346 | |
347 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN))) { |
348 | setSourcePortMin(setting.value(key: QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN)).toUInt()); |
349 | } |
350 | |
351 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_TOS))) { |
352 | setTos(setting.value(key: QLatin1String(NM_SETTING_VXLAN_TOS)).toUInt()); |
353 | } |
354 | |
355 | if (setting.contains(key: QLatin1String(NM_SETTING_VXLAN_TTL))) { |
356 | setTtl(setting.value(key: QLatin1String(NM_SETTING_VXLAN_TTL)).toUInt()); |
357 | } |
358 | } |
359 | |
360 | QVariantMap NetworkManager::VxlanSetting::toMap() const |
361 | { |
362 | QVariantMap setting; |
363 | |
364 | if (ageing() != 32) { |
365 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_AGEING), value: ageing()); |
366 | } |
367 | |
368 | if (destinationPort() != 8472) { |
369 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT), value: destinationPort()); |
370 | } |
371 | |
372 | if (id()) { |
373 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_ID), value: id()); |
374 | } |
375 | |
376 | if (l2Miss()) { |
377 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_L2_MISS), value: l2Miss()); |
378 | } |
379 | |
380 | if (l3Miss()) { |
381 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_L3_MISS), value: l3Miss()); |
382 | } |
383 | |
384 | if (!learning()) { |
385 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_LEARNING), value: learning()); |
386 | } |
387 | |
388 | if (limit()) { |
389 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_LIMIT), value: limit()); |
390 | } |
391 | |
392 | if (!local().isEmpty()) { |
393 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_LOCAL), value: local()); |
394 | } |
395 | |
396 | if (!parent().isEmpty()) { |
397 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_PARENT), value: parent()); |
398 | } |
399 | |
400 | if (proxy()) { |
401 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_PROXY), value: proxy()); |
402 | } |
403 | |
404 | if (!remote().isEmpty()) { |
405 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_REMOTE), value: remote()); |
406 | } |
407 | |
408 | if (rsc()) { |
409 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_RSC), value: rsc()); |
410 | } |
411 | |
412 | if (sourcePortMax()) { |
413 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX), value: sourcePortMax()); |
414 | } |
415 | |
416 | if (sourcePortMin()) { |
417 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN), value: sourcePortMin()); |
418 | } |
419 | |
420 | if (tos()) { |
421 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_TOS), value: tos()); |
422 | } |
423 | |
424 | if (ttl()) { |
425 | setting.insert(key: QLatin1String(NM_SETTING_VXLAN_TTL), value: ttl()); |
426 | } |
427 | |
428 | return setting; |
429 | } |
430 | |
431 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::VxlanSetting &setting) |
432 | { |
433 | dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n'; |
434 | dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; |
435 | |
436 | dbg.nospace() << NM_SETTING_VXLAN_AGEING << ": " << setting.ageing() << '\n'; |
437 | dbg.nospace() << NM_SETTING_VXLAN_DESTINATION_PORT << ": " << setting.destinationPort() << '\n'; |
438 | dbg.nospace() << NM_SETTING_VXLAN_ID << ": " << setting.id() << '\n'; |
439 | dbg.nospace() << NM_SETTING_VXLAN_L2_MISS << ": " << setting.l2Miss() << '\n'; |
440 | dbg.nospace() << NM_SETTING_VXLAN_L3_MISS << ": " << setting.l3Miss() << '\n'; |
441 | dbg.nospace() << NM_SETTING_VXLAN_LEARNING << ": " << setting.learning() << '\n'; |
442 | dbg.nospace() << NM_SETTING_VXLAN_LIMIT << ": " << setting.limit() << '\n'; |
443 | dbg.nospace() << NM_SETTING_VXLAN_LOCAL << ": " << setting.local() << '\n'; |
444 | dbg.nospace() << NM_SETTING_VXLAN_PARENT << ": " << setting.parent() << '\n'; |
445 | dbg.nospace() << NM_SETTING_VXLAN_PROXY << ": " << setting.proxy() << '\n'; |
446 | dbg.nospace() << NM_SETTING_VXLAN_REMOTE << ": " << setting.remote() << '\n'; |
447 | dbg.nospace() << NM_SETTING_VXLAN_RSC << ": " << setting.rsc() << '\n'; |
448 | dbg.nospace() << NM_SETTING_VXLAN_SOURCE_PORT_MAX << ": " << setting.sourcePortMax() << '\n'; |
449 | dbg.nospace() << NM_SETTING_VXLAN_SOURCE_PORT_MIN << ": " << setting.sourcePortMin() << '\n'; |
450 | dbg.nospace() << NM_SETTING_VXLAN_TOS << ": " << setting.tos() << '\n'; |
451 | dbg.nospace() << NM_SETTING_VXLAN_TTL << ": " << setting.ttl() << '\n'; |
452 | |
453 | return dbg.maybeSpace(); |
454 | } |
455 | |