1/*
2 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "bridgesetting.h"
8#include "bridgesetting_p.h"
9
10#define NM_SETTING_BRIDGE_INTERFACE_NAME "interface-name"
11
12#include <QDebug>
13
14NetworkManager::BridgeSettingPrivate::BridgeSettingPrivate()
15 : name(NM_SETTING_BRIDGE_SETTING_NAME)
16 , multicastSnooping(true)
17 , stp(true)
18 , priority(128)
19 , forwardDelay(15)
20 , helloTime(2)
21 , maxAge(20)
22 , agingTime(300)
23{
24}
25
26NetworkManager::BridgeSetting::BridgeSetting()
27 : Setting(Setting::Bridge)
28 , d_ptr(new BridgeSettingPrivate())
29{
30}
31
32NetworkManager::BridgeSetting::BridgeSetting(const Ptr &other)
33 : Setting(other)
34 , d_ptr(new BridgeSettingPrivate())
35{
36 setInterfaceName(other->interfaceName());
37 setStp(other->stp());
38 setPriority(other->priority());
39 setForwardDelay(other->forwardDelay());
40 setHelloTime(other->helloTime());
41 setMaxAge(other->maxAge());
42 setAgingTime(other->agingTime());
43 setMulticastSnooping(other->multicastSnooping());
44 setMacAddress(other->macAddress());
45}
46
47NetworkManager::BridgeSetting::~BridgeSetting()
48{
49 delete d_ptr;
50}
51
52QString NetworkManager::BridgeSetting::name() const
53{
54 Q_D(const BridgeSetting);
55
56 return d->name;
57}
58
59void NetworkManager::BridgeSetting::setInterfaceName(const QString &name)
60{
61 Q_D(BridgeSetting);
62
63 d->interfaceName = name;
64}
65
66QString NetworkManager::BridgeSetting::interfaceName() const
67{
68 Q_D(const BridgeSetting);
69
70 return d->interfaceName;
71}
72
73void NetworkManager::BridgeSetting::setStp(bool enabled)
74{
75 Q_D(BridgeSetting);
76
77 d->stp = enabled;
78}
79
80bool NetworkManager::BridgeSetting::stp() const
81{
82 Q_D(const BridgeSetting);
83
84 return d->stp;
85}
86
87void NetworkManager::BridgeSetting::setPriority(quint32 priority)
88{
89 Q_D(BridgeSetting);
90
91 d->priority = priority;
92}
93
94quint32 NetworkManager::BridgeSetting::priority() const
95{
96 Q_D(const BridgeSetting);
97
98 return d->priority;
99}
100
101void NetworkManager::BridgeSetting::setForwardDelay(quint32 delay)
102{
103 Q_D(BridgeSetting);
104
105 d->forwardDelay = delay;
106}
107
108quint32 NetworkManager::BridgeSetting::forwardDelay() const
109{
110 Q_D(const BridgeSetting);
111
112 return d->forwardDelay;
113}
114
115void NetworkManager::BridgeSetting::setHelloTime(quint32 time)
116{
117 Q_D(BridgeSetting);
118
119 d->helloTime = time;
120}
121
122quint32 NetworkManager::BridgeSetting::helloTime() const
123{
124 Q_D(const BridgeSetting);
125
126 return d->helloTime;
127}
128
129void NetworkManager::BridgeSetting::setMaxAge(quint32 age)
130{
131 Q_D(BridgeSetting);
132
133 d->maxAge = age;
134}
135
136quint32 NetworkManager::BridgeSetting::maxAge() const
137{
138 Q_D(const BridgeSetting);
139
140 return d->maxAge;
141}
142
143void NetworkManager::BridgeSetting::setAgingTime(quint32 time)
144{
145 Q_D(BridgeSetting);
146
147 d->agingTime = time;
148}
149
150quint32 NetworkManager::BridgeSetting::agingTime() const
151{
152 Q_D(const BridgeSetting);
153
154 return d->agingTime;
155}
156
157void NetworkManager::BridgeSetting::setMulticastSnooping(bool snooping)
158{
159 Q_D(BridgeSetting);
160
161 d->multicastSnooping = snooping;
162}
163
164bool NetworkManager::BridgeSetting::multicastSnooping() const
165{
166 Q_D(const BridgeSetting);
167
168 return d->multicastSnooping;
169}
170
171void NetworkManager::BridgeSetting::setMacAddress(const QByteArray &address)
172{
173 Q_D(BridgeSetting);
174
175 d->macAddress = address;
176}
177
178QByteArray NetworkManager::BridgeSetting::macAddress() const
179{
180 Q_D(const BridgeSetting);
181
182 return d->macAddress;
183}
184
185void NetworkManager::BridgeSetting::fromMap(const QVariantMap &setting)
186{
187 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_INTERFACE_NAME))) {
188 setInterfaceName(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_INTERFACE_NAME)).toString());
189 }
190 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_STP))) {
191 setStp(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_STP)).toBool());
192 }
193
194 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_PRIORITY))) {
195 setPriority(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_PRIORITY)).toUInt());
196 }
197
198 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_FORWARD_DELAY))) {
199 setForwardDelay(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_FORWARD_DELAY)).toUInt());
200 }
201
202 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_HELLO_TIME))) {
203 setHelloTime(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_HELLO_TIME)).toUInt());
204 }
205
206 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_MAX_AGE))) {
207 setMaxAge(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_MAX_AGE)).toUInt());
208 }
209
210 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_AGEING_TIME))) {
211 setAgingTime(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_AGEING_TIME)).toUInt());
212 }
213
214 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_MULTICAST_SNOOPING))) {
215 setMulticastSnooping(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_MULTICAST_SNOOPING)).toBool());
216 }
217
218 if (setting.contains(key: QLatin1String(NM_SETTING_BRIDGE_MAC_ADDRESS))) {
219 setMacAddress(setting.value(key: QLatin1String(NM_SETTING_BRIDGE_MAC_ADDRESS)).toByteArray());
220 }
221}
222
223QVariantMap NetworkManager::BridgeSetting::toMap() const
224{
225 QVariantMap setting;
226
227 if (!interfaceName().isEmpty()) {
228 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_INTERFACE_NAME), value: interfaceName());
229 }
230 if (!stp()) {
231 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_STP), value: stp());
232 }
233
234 if (priority() != 128) {
235 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_PRIORITY), value: priority());
236 }
237
238 if (forwardDelay() != 15) {
239 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_FORWARD_DELAY), value: forwardDelay());
240 }
241
242 if (helloTime() != 2) {
243 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_HELLO_TIME), value: helloTime());
244 }
245
246 if (maxAge() != 20) {
247 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_MAX_AGE), value: maxAge());
248 }
249
250 if (agingTime() != 300) {
251 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_AGEING_TIME), value: agingTime());
252 }
253
254 if (!multicastSnooping()) {
255 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_MULTICAST_SNOOPING), value: multicastSnooping());
256 }
257
258 if (!macAddress().isEmpty()) {
259 setting.insert(key: QLatin1String(NM_SETTING_BRIDGE_MAC_ADDRESS), value: macAddress());
260 }
261
262 return setting;
263}
264
265QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BridgeSetting &setting)
266{
267 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
268 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
269
270 dbg.nospace() << NM_SETTING_BRIDGE_INTERFACE_NAME << ": " << setting.interfaceName() << '\n';
271 dbg.nospace() << NM_SETTING_BRIDGE_STP << ": " << setting.stp() << '\n';
272 dbg.nospace() << NM_SETTING_BRIDGE_PRIORITY << ": " << setting.priority() << '\n';
273 dbg.nospace() << NM_SETTING_BRIDGE_FORWARD_DELAY << ": " << setting.forwardDelay() << '\n';
274 dbg.nospace() << NM_SETTING_BRIDGE_HELLO_TIME << ": " << setting.helloTime() << '\n';
275 dbg.nospace() << NM_SETTING_BRIDGE_MAX_AGE << ": " << setting.maxAge() << '\n';
276 dbg.nospace() << NM_SETTING_BRIDGE_AGEING_TIME << ": " << setting.agingTime() << '\n';
277 dbg.nospace() << NM_SETTING_BRIDGE_MULTICAST_SNOOPING << ": " << setting.multicastSnooping() << '\n';
278 dbg.nospace() << NM_SETTING_BRIDGE_MAC_ADDRESS << ": " << setting.macAddress() << '\n';
279
280 return dbg.maybeSpace();
281}
282

source code of networkmanager-qt/src/settings/bridgesetting.cpp