/src/PcapPlusPlus/Packet++/src/StpLayer.cpp
Line | Count | Source |
1 | 0 | #define LOG_MODULE PacketLogModuleStpLayer |
2 | | |
3 | | #include "StpLayer.h" |
4 | | #include "GeneralUtils.h" |
5 | | #include "PayloadLayer.h" |
6 | | #include "EndianPortable.h" |
7 | | #include "Logger.h" |
8 | | |
9 | | namespace pcpp |
10 | | { |
11 | | const FieldDescriptor StpLayer::SerializedFields::ProtoId{ Layer::SerializedFields::MaxID + 1, "protoId" }; |
12 | | const FieldDescriptor StpLayer::SerializedFields::Version{ Layer::SerializedFields::MaxID + 2, "version" }; |
13 | | const FieldDescriptor StpLayer::SerializedFields::Type{ Layer::SerializedFields::MaxID + 3, "type" }; |
14 | | |
15 | | void StpLayer::serializeLayer(ObjectScope& serializer) const |
16 | 0 | { |
17 | 0 | serializer.writeField(SerializedFields::ProtoId, be16toh(getProtoId())); |
18 | 0 | serializer.writeField(SerializedFields::Version, getVersion()); |
19 | 0 | serializer.writeField(SerializedFields::Type, getType()); |
20 | 0 | } |
21 | | |
22 | | const FieldDescriptor StpConfigurationBPDULayer::SerializedFields::Flags{ |
23 | | StpLayer::SerializedFields::MaxStpFieldID + 1, "flags" |
24 | | }; |
25 | | const ObjectFieldDescriptor<StpConfigurationBPDULayer::BridgeIdSerializedFields> |
26 | | StpConfigurationBPDULayer::SerializedFields::RootId{ StpLayer::SerializedFields::MaxStpFieldID + 2, "rootId" }; |
27 | | const FieldDescriptor StpConfigurationBPDULayer::SerializedFields::PathCost{ |
28 | | StpLayer::SerializedFields::MaxStpFieldID + 3, "pathCost" |
29 | | }; |
30 | | const ObjectFieldDescriptor<StpConfigurationBPDULayer::BridgeIdSerializedFields> |
31 | | StpConfigurationBPDULayer::SerializedFields::BridgeId{ StpLayer::SerializedFields::MaxStpFieldID + 4, |
32 | | "bridgeId" }; |
33 | | const FieldDescriptor StpConfigurationBPDULayer::SerializedFields::PortId{ |
34 | | StpLayer::SerializedFields::MaxStpFieldID + 5, "portId" |
35 | | }; |
36 | | const FieldDescriptor StpConfigurationBPDULayer::SerializedFields::MessageAge{ |
37 | | StpLayer::SerializedFields::MaxStpFieldID + 6, "messageAge" |
38 | | }; |
39 | | const FieldDescriptor StpConfigurationBPDULayer::SerializedFields::MaximumAge{ |
40 | | StpLayer::SerializedFields::MaxStpFieldID + 7, "maximumAge" |
41 | | }; |
42 | | const FieldDescriptor StpConfigurationBPDULayer::SerializedFields::TransmissionInterval{ |
43 | | StpLayer::SerializedFields::MaxStpFieldID + 8, "transmissionInterval" |
44 | | }; |
45 | | const FieldDescriptor StpConfigurationBPDULayer::SerializedFields::ForwardDelay{ |
46 | | StpLayer::SerializedFields::MaxStpFieldID + 9, "forwardDelay" |
47 | | }; |
48 | | |
49 | | const FieldDescriptor StpConfigurationBPDULayer::BridgeIdSerializedFields::Priority{ 0, "priority" }; |
50 | | const FieldDescriptor StpConfigurationBPDULayer::BridgeIdSerializedFields::SystemIdExtension{ 1, |
51 | | "systemIdExtension" }; |
52 | | const FieldDescriptor StpConfigurationBPDULayer::BridgeIdSerializedFields::SystemId{ 2, "systemId" }; |
53 | | |
54 | | void StpConfigurationBPDULayer::serializeLayer(ObjectScope& serializer) const |
55 | 0 | { |
56 | 0 | StpLayer::serializeLayer(serializer); |
57 | 0 | serializer.writeField(SerializedFields::Flags, getFlag()); |
58 | 0 | { |
59 | 0 | auto identifier = serializer.writeObject(SerializedFields::RootId); |
60 | 0 | identifier.writeField(BridgeIdSerializedFields::Priority, getRootPriority()); |
61 | 0 | identifier.writeField(BridgeIdSerializedFields::SystemIdExtension, getRootSystemIDExtension()); |
62 | 0 | identifier.writeField(BridgeIdSerializedFields::SystemId, getRootSystemID().toString()); |
63 | 0 | } |
64 | 0 | serializer.writeField(SerializedFields::PathCost, getPathCost()); |
65 | 0 | { |
66 | 0 | auto identifier = serializer.writeObject(SerializedFields::BridgeId); |
67 | 0 | identifier.writeField(BridgeIdSerializedFields::Priority, getBridgePriority()); |
68 | 0 | identifier.writeField(BridgeIdSerializedFields::SystemIdExtension, getBridgeSystemIDExtension()); |
69 | 0 | identifier.writeField(BridgeIdSerializedFields::SystemId, getBridgeSystemID().toString()); |
70 | 0 | } |
71 | 0 | serializer.writeField(SerializedFields::PortId, getPortId()); |
72 | 0 | serializer.writeField(SerializedFields::MessageAge, getMessageAge()); |
73 | 0 | serializer.writeField(SerializedFields::MaximumAge, getMaximumAge()); |
74 | 0 | serializer.writeField(SerializedFields::TransmissionInterval, getTransmissionInterval()); |
75 | 0 | serializer.writeField(SerializedFields::ForwardDelay, getForwardDelay()); |
76 | 0 | } |
77 | | |
78 | | const FieldDescriptor RapidStpLayer::SerializedFields::Version1Length{ |
79 | | StpConfigurationBPDULayer::SerializedFields::MaxConfigurationFieldID + 1, "version1Length" |
80 | | }; |
81 | | |
82 | | void RapidStpLayer::serializeLayer(ObjectScope& serializer) const |
83 | 0 | { |
84 | 0 | StpConfigurationBPDULayer::serializeLayer(serializer); |
85 | 0 | serializer.writeField(SerializedFields::Version1Length, getVersion1Len()); |
86 | 0 | } |
87 | | |
88 | | const FieldDescriptor MultipleStpLayer::SerializedFields::Version3Length{ |
89 | | RapidStpLayer::SerializedFields::MaxRapidFieldID + 1, "version3Length" |
90 | | }; |
91 | | const FieldDescriptor MultipleStpLayer::SerializedFields::ConfigFormatSelector{ |
92 | | RapidStpLayer::SerializedFields::MaxRapidFieldID + 2, "configFormatSelector" |
93 | | }; |
94 | | const FieldDescriptor MultipleStpLayer::SerializedFields::ConfigName{ |
95 | | RapidStpLayer::SerializedFields::MaxRapidFieldID + 3, "configName" |
96 | | }; |
97 | | const FieldDescriptor MultipleStpLayer::SerializedFields::ConfigRevision{ |
98 | | RapidStpLayer::SerializedFields::MaxRapidFieldID + 4, "configRevision" |
99 | | }; |
100 | | const FieldDescriptor MultipleStpLayer::SerializedFields::ConfigDigest{ |
101 | | RapidStpLayer::SerializedFields::MaxRapidFieldID + 5, "configDigest" |
102 | | }; |
103 | | const FieldDescriptor MultipleStpLayer::SerializedFields::CistInternalRootPathCost{ |
104 | | RapidStpLayer::SerializedFields::MaxRapidFieldID + 6, "cistInternalRootPathCost" |
105 | | }; |
106 | | const ObjectFieldDescriptor<StpConfigurationBPDULayer::BridgeIdSerializedFields> |
107 | | MultipleStpLayer::SerializedFields::CistBridgeId{ RapidStpLayer::SerializedFields::MaxRapidFieldID + 7, |
108 | | "cistBridgeId" }; |
109 | | const FieldDescriptor MultipleStpLayer::SerializedFields::RemainingHopCount{ |
110 | | RapidStpLayer::SerializedFields::MaxRapidFieldID + 8, "remainingHopCount" |
111 | | }; |
112 | | |
113 | | void MultipleStpLayer::serializeLayer(ObjectScope& serializer) const |
114 | 0 | { |
115 | 0 | RapidStpLayer::serializeLayer(serializer); |
116 | 0 | serializer.writeField(SerializedFields::Version3Length, getVersion3Len()); |
117 | 0 | serializer.writeField(SerializedFields::ConfigFormatSelector, getMstConfigurationFormatSelector()); |
118 | 0 | serializer.writeField(SerializedFields::ConfigName, getMstConfigurationName()); |
119 | 0 | serializer.writeField(SerializedFields::ConfigRevision, getMstConfigRevision()); |
120 | 0 | serializer.writeField(SerializedFields::ConfigDigest, byteArrayToHexString(getMstConfigDigest(), 16)); |
121 | 0 | serializer.writeField(SerializedFields::CistInternalRootPathCost, getCISTIrpc()); |
122 | 0 | { |
123 | 0 | auto identifier = serializer.writeObject(SerializedFields::CistBridgeId); |
124 | 0 | identifier.writeField(BridgeIdSerializedFields::Priority, getCISTBridgePriority()); |
125 | 0 | identifier.writeField(BridgeIdSerializedFields::SystemIdExtension, getCISTBridgeSystemIDExtension()); |
126 | 0 | identifier.writeField(BridgeIdSerializedFields::SystemId, getCISTBridgeSystemID().toString()); |
127 | 0 | } |
128 | 0 | serializer.writeField(SerializedFields::RemainingHopCount, getRemainingHopCount()); |
129 | 0 | } |
130 | | |
131 | | // ---------------------- Class STPLayer ---------------------- |
132 | | MacAddress StpLayer::StpMulticastDstMAC("01:80:C2:00:00:00"); |
133 | | MacAddress StpLayer::StpUplinkFastMulticastDstMAC("01:00:0C:CD:CD:CD"); |
134 | | |
135 | | MacAddress StpLayer::IDtoMacAddress(uint64_t id) |
136 | 0 | { |
137 | 0 | return MacAddress((id >> 40) & 0xFF, (id >> 32) & 0xFF, (id >> 24) & 0xFF, (id >> 16) & 0xFF, (id >> 8) & 0xFF, |
138 | 0 | id & 0xFF); |
139 | 0 | } |
140 | | |
141 | | uint64_t StpLayer::macAddressToID(const pcpp::MacAddress& addr) |
142 | 0 | { |
143 | 0 | uint8_t value[6] = { 0 }; |
144 | 0 | addr.copyTo(value); |
145 | 0 | return ((uint64_t(value[0]) << 40) | (uint64_t(value[1]) << 32) | (uint64_t(value[2]) << 24) | |
146 | 0 | (uint64_t(value[3]) << 16) | (uint64_t(value[4]) << 8) | (uint64_t(value[5]))); |
147 | 0 | } |
148 | | |
149 | | bool StpLayer::isDataValid(const uint8_t* data, size_t dataLen) |
150 | 0 | { |
151 | 0 | return data && dataLen; |
152 | 0 | } |
153 | | |
154 | | StpLayer* StpLayer::parseStpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) |
155 | 0 | { |
156 | 0 | if (dataLen >= sizeof(stp_tcn_bpdu)) |
157 | 0 | { |
158 | 0 | stp_tcn_bpdu* ptr = reinterpret_cast<stp_tcn_bpdu*>(data); |
159 | 0 | switch (ptr->type) |
160 | 0 | { |
161 | 0 | case 0x00: |
162 | 0 | return StpConfigurationBPDULayer::isDataValid(data, dataLen) |
163 | 0 | ? new StpConfigurationBPDULayer(data, dataLen, prevLayer, packet) |
164 | 0 | : nullptr; |
165 | 0 | case 0x02: |
166 | 0 | if (ptr->version == 0x2) |
167 | 0 | return RapidStpLayer::isDataValid(data, dataLen) |
168 | 0 | ? new RapidStpLayer(data, dataLen, prevLayer, packet) |
169 | 0 | : nullptr; |
170 | 0 | if (ptr->version == 0x3) |
171 | 0 | return MultipleStpLayer::isDataValid(data, dataLen) |
172 | 0 | ? new MultipleStpLayer(data, dataLen, prevLayer, packet) |
173 | 0 | : nullptr; |
174 | 0 | PCPP_LOG_DEBUG("Unknown Spanning Tree Version"); |
175 | 0 | return nullptr; |
176 | 0 | case 0x80: |
177 | 0 | return StpTopologyChangeBPDULayer::isDataValid(data, dataLen) |
178 | 0 | ? new StpTopologyChangeBPDULayer(data, dataLen, prevLayer, packet) |
179 | 0 | : nullptr; |
180 | | // TODO: Per VLAN Spanning Tree+ (PVST+) |
181 | | // TODO: Rapid Per VLAN Spanning Tree+ (RPVST+) |
182 | | // TODO: Cisco Uplink Fast |
183 | 0 | default: |
184 | 0 | PCPP_LOG_DEBUG("Unknown Spanning Tree Protocol type"); |
185 | 0 | return nullptr; |
186 | 0 | } |
187 | 0 | } |
188 | | |
189 | 0 | PCPP_LOG_DEBUG("Data length is less than any STP header"); |
190 | 0 | return nullptr; |
191 | 0 | } |
192 | | |
193 | | // ---------------------- Class StpTopologyChangeBPDULayer ---------------------- |
194 | 0 | StpTopologyChangeBPDULayer::StpTopologyChangeBPDULayer() : StpLayer(sizeof(stp_tcn_bpdu)) |
195 | 0 | { |
196 | | // Set initial values for TCN |
197 | 0 | setProtoId(0x0); |
198 | 0 | setVersion(0x0); |
199 | 0 | setType(0x80); |
200 | 0 | } |
201 | | |
202 | | void StpTopologyChangeBPDULayer::parseNextLayer() |
203 | 0 | { |
204 | 0 | if (m_DataLen > sizeof(stp_tcn_bpdu)) |
205 | 0 | { |
206 | 0 | constructNextLayer<PayloadLayer>(m_Data, m_DataLen - sizeof(stp_tcn_bpdu)); |
207 | 0 | } |
208 | 0 | } |
209 | | |
210 | | // ---------------------- Class StpConfigurationBPDULayer ---------------------- |
211 | 0 | StpConfigurationBPDULayer::StpConfigurationBPDULayer() : StpTopologyChangeBPDULayer(sizeof(stp_conf_bpdu)) |
212 | 0 | { |
213 | | // Set initial value for configuration BPDU |
214 | 0 | setProtoId(0x0); |
215 | 0 | setVersion(0x0); |
216 | 0 | setType(0x0); |
217 | 0 | } |
218 | | |
219 | | uint64_t StpConfigurationBPDULayer::getRootId() const |
220 | 0 | { |
221 | 0 | return be64toh(getStpConfHeader()->rootId); |
222 | 0 | } |
223 | | |
224 | | void StpConfigurationBPDULayer::setRootId(uint64_t value) |
225 | 0 | { |
226 | 0 | getStpConfHeader()->rootId = htobe64(value); |
227 | 0 | } |
228 | | |
229 | | uint16_t StpConfigurationBPDULayer::getRootPriority() const |
230 | 0 | { |
231 | 0 | return be16toh(getStpConfHeader()->rootId) & 0xf000; |
232 | 0 | } |
233 | | |
234 | | void StpConfigurationBPDULayer::setRootPriority(uint16_t value) |
235 | 0 | { |
236 | 0 | getStpConfHeader()->rootId = (getStpConfHeader()->rootId & ~htobe16(0xf000)) | htobe16(value & 0xf000); |
237 | 0 | } |
238 | | |
239 | | uint16_t StpConfigurationBPDULayer::getRootSystemIDExtension() const |
240 | 0 | { |
241 | 0 | return be16toh(getStpConfHeader()->rootId) & 0x0fff; |
242 | 0 | } |
243 | | |
244 | | void StpConfigurationBPDULayer::setRootSystemIDExtension(uint16_t value) |
245 | 0 | { |
246 | 0 | getStpConfHeader()->rootId = (getStpConfHeader()->rootId & ~htobe16(0x0fff)) | htobe16(value & 0x0fff); |
247 | 0 | } |
248 | | |
249 | | void StpConfigurationBPDULayer::setRootSystemID(const pcpp::MacAddress& value) |
250 | 0 | { |
251 | 0 | setRootId((getRootId() & (uint64_t(0xffff) << 48)) | macAddressToID(value)); |
252 | 0 | }; |
253 | | |
254 | | uint32_t StpConfigurationBPDULayer::getPathCost() const |
255 | 0 | { |
256 | 0 | return be32toh(getStpConfHeader()->pathCost); |
257 | 0 | } |
258 | | |
259 | | void StpConfigurationBPDULayer::setPathCost(uint32_t value) |
260 | 0 | { |
261 | 0 | getStpConfHeader()->pathCost = htobe32(value); |
262 | 0 | } |
263 | | |
264 | | uint64_t StpConfigurationBPDULayer::getBridgeId() const |
265 | 0 | { |
266 | 0 | return be64toh(getStpConfHeader()->bridgeId); |
267 | 0 | } |
268 | | |
269 | | void StpConfigurationBPDULayer::setBridgeId(uint64_t value) |
270 | 0 | { |
271 | 0 | getStpConfHeader()->bridgeId = htobe64(value); |
272 | 0 | } |
273 | | |
274 | | uint16_t StpConfigurationBPDULayer::getBridgePriority() const |
275 | 0 | { |
276 | 0 | return be16toh(getStpConfHeader()->bridgeId) & 0xf000; |
277 | 0 | } |
278 | | |
279 | | void StpConfigurationBPDULayer::setBridgePriority(uint16_t value) |
280 | 0 | { |
281 | 0 | getStpConfHeader()->bridgeId = (getStpConfHeader()->bridgeId & ~htobe16(0xf000)) | htobe16(value & 0xf000); |
282 | 0 | } |
283 | | |
284 | | uint16_t StpConfigurationBPDULayer::getBridgeSystemIDExtension() const |
285 | 0 | { |
286 | 0 | return be16toh(getStpConfHeader()->bridgeId) & 0x0fff; |
287 | 0 | } |
288 | | |
289 | | void StpConfigurationBPDULayer::setBridgeSystemIDExtension(uint16_t value) |
290 | 0 | { |
291 | 0 | getStpConfHeader()->bridgeId = (getStpConfHeader()->bridgeId & ~htobe16(0x0fff)) | htobe16(value & 0x0fff); |
292 | 0 | } |
293 | | |
294 | | void StpConfigurationBPDULayer::setBridgeSystemID(const pcpp::MacAddress& value) |
295 | 0 | { |
296 | 0 | setBridgeId((getBridgeId() & (uint64_t(0xffff) << 48)) | macAddressToID(value)); |
297 | 0 | } |
298 | | |
299 | | uint16_t StpConfigurationBPDULayer::getPortId() const |
300 | 0 | { |
301 | 0 | return be16toh(getStpConfHeader()->portId); |
302 | 0 | } |
303 | | |
304 | | void StpConfigurationBPDULayer::setPortId(uint16_t value) |
305 | 0 | { |
306 | 0 | getStpConfHeader()->portId = htobe16(value); |
307 | 0 | } |
308 | | |
309 | | double StpConfigurationBPDULayer::getMessageAge() const |
310 | 0 | { |
311 | 0 | return getStpConfHeader()->msgAge; |
312 | 0 | } |
313 | | |
314 | | void StpConfigurationBPDULayer::setMessageAge(double value) |
315 | 0 | { |
316 | 0 | getStpConfHeader()->msgAge = value; |
317 | 0 | } |
318 | | |
319 | | double StpConfigurationBPDULayer::getMaximumAge() const |
320 | 0 | { |
321 | 0 | return getStpConfHeader()->maxAge; |
322 | 0 | } |
323 | | |
324 | | void StpConfigurationBPDULayer::setMaximumAge(double value) |
325 | 0 | { |
326 | 0 | getStpConfHeader()->maxAge = value; |
327 | 0 | } |
328 | | |
329 | | double StpConfigurationBPDULayer::getTransmissionInterval() const |
330 | 0 | { |
331 | 0 | return getStpConfHeader()->helloTime; |
332 | 0 | } |
333 | | |
334 | | void StpConfigurationBPDULayer::setTransmissionInterval(double value) |
335 | 0 | { |
336 | 0 | getStpConfHeader()->helloTime = value; |
337 | 0 | } |
338 | | |
339 | | double StpConfigurationBPDULayer::getForwardDelay() const |
340 | 0 | { |
341 | 0 | return getStpConfHeader()->forwardDelay; |
342 | 0 | } |
343 | | |
344 | | void StpConfigurationBPDULayer::setForwardDelay(double value) |
345 | 0 | { |
346 | 0 | getStpConfHeader()->forwardDelay = value; |
347 | 0 | } |
348 | | |
349 | | void StpConfigurationBPDULayer::parseNextLayer() |
350 | 0 | { |
351 | 0 | if (m_DataLen > sizeof(stp_conf_bpdu)) |
352 | 0 | { |
353 | 0 | constructNextLayer<PayloadLayer>(m_Data, m_DataLen - sizeof(stp_conf_bpdu)); |
354 | 0 | } |
355 | 0 | } |
356 | | |
357 | | // ---------------------- Class RapidStpLayer ---------------------- |
358 | 0 | RapidStpLayer::RapidStpLayer() : StpConfigurationBPDULayer(sizeof(rstp_conf_bpdu)) |
359 | 0 | { |
360 | | // Set initial value for Rapid STP |
361 | 0 | setProtoId(0x0); |
362 | 0 | setVersion(0x2); |
363 | 0 | setType(0x2); |
364 | 0 | } |
365 | | |
366 | | void RapidStpLayer::parseNextLayer() |
367 | 0 | { |
368 | 0 | if (m_DataLen > sizeof(rstp_conf_bpdu)) |
369 | 0 | { |
370 | 0 | constructNextLayer<PayloadLayer>(m_Data, m_DataLen - sizeof(rstp_conf_bpdu)); |
371 | 0 | } |
372 | 0 | } |
373 | | |
374 | | // ---------------------- Class MultipleStpLayer ---------------------- |
375 | 0 | MultipleStpLayer::MultipleStpLayer() : RapidStpLayer(sizeof(mstp_conf_bpdu)) |
376 | 0 | { |
377 | | // Set initial value for Multiple STP |
378 | 0 | setProtoId(0x0); |
379 | 0 | setVersion(0x3); |
380 | 0 | setType(0x2); |
381 | 0 | } |
382 | | |
383 | | uint16_t MultipleStpLayer::getVersion3Len() const |
384 | 0 | { |
385 | 0 | return be16toh(getMstpHeader()->version3Len); |
386 | 0 | } |
387 | | |
388 | | void MultipleStpLayer::setVersion3Len(uint16_t value) |
389 | 0 | { |
390 | 0 | getMstpHeader()->version3Len = htobe16(value); |
391 | 0 | } |
392 | | |
393 | | uint32_t MultipleStpLayer::getCISTIrpc() const |
394 | 0 | { |
395 | 0 | return be32toh(getMstpHeader()->irpc); |
396 | 0 | } |
397 | | |
398 | | void MultipleStpLayer::setCISTIrpc(uint32_t value) |
399 | 0 | { |
400 | 0 | getMstpHeader()->irpc = htobe32(value); |
401 | 0 | } |
402 | | |
403 | | uint64_t MultipleStpLayer::getCISTBridgeId() const |
404 | 0 | { |
405 | 0 | return be64toh(getMstpHeader()->cistBridgeId); |
406 | 0 | } |
407 | | |
408 | | void MultipleStpLayer::setCISTBridgeId(uint64_t value) |
409 | 0 | { |
410 | 0 | getMstpHeader()->cistBridgeId = htobe64(value); |
411 | 0 | } |
412 | | |
413 | | uint16_t MultipleStpLayer::getCISTBridgePriority() const |
414 | 0 | { |
415 | 0 | return be16toh(getMstpHeader()->cistBridgeId) & 0xf000; |
416 | 0 | } |
417 | | |
418 | | void MultipleStpLayer::setCISTBridgePriority(uint16_t value) |
419 | 0 | { |
420 | 0 | getMstpHeader()->cistBridgeId = (getMstpHeader()->cistBridgeId & ~htobe16(0xf000)) | htobe16(value & 0xf000); |
421 | 0 | } |
422 | | |
423 | | uint16_t MultipleStpLayer::getCISTBridgeSystemIDExtension() const |
424 | 0 | { |
425 | 0 | return be16toh(getMstpHeader()->cistBridgeId) & 0x0fff; |
426 | 0 | } |
427 | | |
428 | | void MultipleStpLayer::setCISTBridgeSystemIDExtension(uint16_t value) |
429 | 0 | { |
430 | 0 | getMstpHeader()->cistBridgeId = (getMstpHeader()->cistBridgeId & ~htobe16(0x0fff)) | htobe16(value & 0x0fff); |
431 | 0 | } |
432 | | |
433 | | void MultipleStpLayer::setCISTBridgeSystemID(const pcpp::MacAddress& value) |
434 | 0 | { |
435 | 0 | setCISTBridgeId((getCISTBridgeId() & (uint64_t(0xffff) << 48)) | macAddressToID(value)); |
436 | 0 | } |
437 | | |
438 | | std::string MultipleStpLayer::getMstConfigurationName() const |
439 | 0 | { |
440 | 0 | std::string str = std::string(reinterpret_cast<char*>(getMstpHeader()->mstConfigName), 32); |
441 | 0 | str.erase(std::find(str.begin(), str.end(), '\0'), str.end()); |
442 | 0 | return str; |
443 | 0 | } |
444 | | |
445 | | uint16_t MultipleStpLayer::getMstConfigRevision() const |
446 | 0 | { |
447 | 0 | return be16toh(getMstpHeader()->mstConfigRevision); |
448 | 0 | } |
449 | | |
450 | | void MultipleStpLayer::setMstConfigRevision(uint16_t value) |
451 | 0 | { |
452 | 0 | getMstpHeader()->mstConfigRevision = htobe16(value); |
453 | 0 | } |
454 | | |
455 | | void MultipleStpLayer::setMstConfigDigest(const uint8_t* value, uint8_t len) |
456 | 0 | { |
457 | 0 | memset(getMstpHeader()->mstConfigDigest, 0, 16); |
458 | 0 | memcpy(getMstpHeader()->mstConfigDigest, value, std::min<size_t>(len, 16)); |
459 | 0 | } |
460 | | |
461 | | void MultipleStpLayer::setMstConfigurationName(const std::string& value) |
462 | 0 | { |
463 | 0 | memset(getMstpHeader()->mstConfigName, 0, 32); |
464 | 0 | memcpy(getMstpHeader()->mstConfigName, value.c_str(), std::min<size_t>(value.size(), 32)); |
465 | 0 | } |
466 | | |
467 | | msti_conf_msg* MultipleStpLayer::getMstiConfMessages() const |
468 | 0 | { |
469 | 0 | if (getNumberOfMSTIConfMessages()) |
470 | 0 | return reinterpret_cast<msti_conf_msg*>(m_Data + sizeof(mstp_conf_bpdu)); |
471 | 0 | return nullptr; |
472 | 0 | } |
473 | | |
474 | | } // namespace pcpp |