/src/PcapPlusPlus/Packet++/header/StpLayer.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "Layer.h" |
4 | | #include "MacAddress.h" |
5 | | |
6 | | /// @file |
7 | | |
8 | | /** |
9 | | * \namespace pcpp |
10 | | * \brief The main namespace for the PcapPlusPlus lib |
11 | | */ |
12 | | namespace pcpp |
13 | | { |
14 | | |
15 | | /** |
16 | | * @struct stp_tcn_bpdu |
17 | | * Represents payload of network changes announcements of BPDU |
18 | | */ |
19 | | #pragma pack(push, 1) |
20 | | struct stp_tcn_bpdu |
21 | | { |
22 | | /// Protocol ID. Fixed at 0x0, which represents IEEE 802.1d |
23 | | uint16_t protoId; |
24 | | /// Protocol version. 0x0 for STP, 0x2 for RSTP, 0x3 for MSTP |
25 | | uint8_t version; |
26 | | /// Type of the BPDU. 0x0 for configuration, 0x2 for RSTP/MSTP, 0x80 for TCN |
27 | | uint8_t type; |
28 | | }; |
29 | | #pragma pack(pop) |
30 | | |
31 | | /// Spanning Tree protocol common header |
32 | | typedef stp_tcn_bpdu stp_header; |
33 | | |
34 | | /** |
35 | | * @struct stp_conf_bpdu |
36 | | * Represents payload configuration of BPDU for STP |
37 | | */ |
38 | | #pragma pack(push, 1) |
39 | | struct stp_conf_bpdu : stp_tcn_bpdu |
40 | | { |
41 | | /// Flag for indicate purpose of BPDU |
42 | | uint8_t flag; |
43 | | /// Root bridge ID |
44 | | uint64_t rootId; |
45 | | /// Cost of path |
46 | | uint32_t pathCost; |
47 | | /// Bridge ID |
48 | | uint64_t bridgeId; |
49 | | /// Port ID |
50 | | uint16_t portId; |
51 | | /// Age of the BPDU |
52 | | uint16_t msgAge; |
53 | | /// Maximum age of the BPDU |
54 | | uint16_t maxAge; |
55 | | /// BPDU transmission interval |
56 | | uint16_t helloTime; |
57 | | /// Delay for STP |
58 | | uint16_t forwardDelay; |
59 | | }; |
60 | | #pragma pack(pop) |
61 | | |
62 | | /** |
63 | | * @struct rstp_conf_bpdu |
64 | | * Represents payload configuration of BPDU for Rapid STP (RSTP) |
65 | | */ |
66 | | #pragma pack(push, 1) |
67 | | struct rstp_conf_bpdu : stp_conf_bpdu |
68 | | { |
69 | | /// Version1 length. The value is 0x0 |
70 | | uint8_t version1Len; |
71 | | }; |
72 | | #pragma pack(pop) |
73 | | |
74 | | /** |
75 | | * @struct mstp_conf_bpdu |
76 | | * Represents payload configuration of BPDU for Multiple STP (MSTP) |
77 | | */ |
78 | | #pragma pack(push, 1) |
79 | | struct mstp_conf_bpdu : rstp_conf_bpdu |
80 | | { |
81 | | /// Version3 length. |
82 | | uint16_t version3Len; |
83 | | /// Configuration id format selector |
84 | | uint8_t mstConfigFormatSelector; |
85 | | /// Configuration id name |
86 | | uint8_t mstConfigName[32]; |
87 | | /// Configuration id revision |
88 | | uint16_t mstConfigRevision; |
89 | | /// Configuration id digest |
90 | | uint8_t mstConfigDigest[16]; |
91 | | /// CIST internal root path cost |
92 | | uint32_t irpc; |
93 | | /// CIST bridge id |
94 | | uint64_t cistBridgeId; |
95 | | /// CIST remaining hop count |
96 | | uint8_t remainId; |
97 | | }; |
98 | | #pragma pack(pop) |
99 | | |
100 | | /** |
101 | | * @struct msti_conf_msg |
102 | | * Represents MSTI configuration messages. Each message contains 16 bytes and MSTP can contain 0 to 64 MSTI messages. |
103 | | */ |
104 | | #pragma pack(push, 1) |
105 | | struct msti_conf_msg |
106 | | { |
107 | | /// MSTI flags |
108 | | uint8_t flags; |
109 | | /// Regional root switching id (Priority (4 bits) + ID (12 bits) + Regional root (48 bits - MAC address)) |
110 | | uint64_t regionalRootId; |
111 | | /// Total path cost from local port to regional port |
112 | | uint32_t pathCost; |
113 | | /// Priority value of switching device |
114 | | uint8_t bridgePriority; |
115 | | /// Priority value of port |
116 | | uint8_t portPriority; |
117 | | /// Remaining hops of BPDU |
118 | | uint8_t remainingHops; |
119 | | }; |
120 | | #pragma pack(pop) |
121 | | |
122 | | /** |
123 | | * @class StpLayer |
124 | | * Represents an Spanning Tree Protocol Layer |
125 | | */ |
126 | | class StpLayer : public Layer |
127 | | { |
128 | | protected: |
129 | | StpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) |
130 | | : Layer(data, dataLen, prevLayer, packet) |
131 | 3.18k | { |
132 | 3.18k | m_Protocol = STP; |
133 | 3.18k | } |
134 | | |
135 | | explicit StpLayer(size_t dataLen) |
136 | 0 | { |
137 | 0 | m_DataLen = dataLen; |
138 | 0 | m_Data = new uint8_t[dataLen]; |
139 | 0 | memset(m_Data, 0, dataLen); |
140 | 0 | m_Protocol = STP; |
141 | 0 | } |
142 | | |
143 | | static pcpp::MacAddress IDtoMacAddress(uint64_t id); |
144 | | static uint64_t macAddressToID(const pcpp::MacAddress &addr); |
145 | | |
146 | | public: |
147 | | /// STP protocol uses "01:80:C2:00:00:00" multicast address as destination MAC |
148 | | static pcpp::MacAddress StpMulticastDstMAC; |
149 | | /// STP Uplink Fast protocol uses "01:00:0C:CD:CD:CD" as destination MAC |
150 | | static pcpp::MacAddress StpUplinkFastMulticastDstMAC; |
151 | | |
152 | | /** |
153 | | * Get a pointer to base Spanning tree header |
154 | | * @return A pointer to spanning tree header |
155 | | */ |
156 | 0 | stp_header *getStpHeader() const { return (stp_header *)(m_Data); } |
157 | | |
158 | | /** |
159 | | * Returns the protocol id. Fixed at 0x0 for STP messages which represents IEEE 802.1d |
160 | | * @return ID of the protocol |
161 | | */ |
162 | 0 | uint16_t getProtoId() const { return getStpHeader()->protoId; } |
163 | | |
164 | | /** |
165 | | * Sets the protocol id |
166 | | * @param[in] value ID of the protocol |
167 | | */ |
168 | 0 | void setProtoId(uint16_t value) { getStpHeader()->protoId = value; } |
169 | | |
170 | | /** |
171 | | * Returns the version. Fixed at 0x0 for STP messages |
172 | | * @return Version number |
173 | | */ |
174 | 0 | uint8_t getVersion() const { return getStpHeader()->version; } |
175 | | |
176 | | /** |
177 | | * Sets the version |
178 | | * @param[in] value Version number |
179 | | */ |
180 | 0 | void setVersion(uint8_t value) { getStpHeader()->version = value; } |
181 | | |
182 | | /** |
183 | | * Returns the type of configuration message. |
184 | | * @return Type of configuration message |
185 | | */ |
186 | 0 | uint8_t getType() const { return getStpHeader()->type; } |
187 | | |
188 | | /** |
189 | | * Sets the type of configuration message |
190 | | * @param[in] value Type of configuration message |
191 | | */ |
192 | 0 | void setType(uint8_t value) { getStpHeader()->type = value; } |
193 | | |
194 | | // overridden methods |
195 | | |
196 | | /** |
197 | | * @return The size of STP packet |
198 | | */ |
199 | 0 | size_t getHeaderLen() const { return m_DataLen; } |
200 | | |
201 | | /// Does nothing for this layer |
202 | 530 | void computeCalculateFields() {} |
203 | | |
204 | | /** |
205 | | * @return The OSI layer level of STP (Data Link Layer). |
206 | | */ |
207 | 530 | OsiModelLayer getOsiModelLayer() const { return OsiModelDataLinkLayer; } |
208 | | |
209 | | /** |
210 | | * A static method that validates the input data |
211 | | * @param[in] data The pointer to the beginning of a byte stream of an Spanning Tree packet |
212 | | * @param[in] dataLen The length of the byte stream |
213 | | * @return True if the data is valid and can represent an Spanning Tree packet |
214 | | */ |
215 | | static bool isDataValid(const uint8_t *data, size_t dataLen); |
216 | | |
217 | | /** |
218 | | * A method to create STP layer from existing packet |
219 | | * @param[in] data A pointer to the raw data |
220 | | * @param[in] dataLen Size of the data in bytes |
221 | | * @param[in] prevLayer A pointer to the previous layer |
222 | | * @param[in] packet A pointer to the Packet instance where layer will be stored |
223 | | * @return A newly allocated STP layer of one of the following types (according to the message type): |
224 | | * StpConfigurationBPDULayer, StpTopologyChangeBPDULayer, RapidStpLayer, MultipleStpLayer |
225 | | */ |
226 | | static StpLayer *parseStpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet); |
227 | | }; |
228 | | |
229 | | /** |
230 | | * @class StpTopologyChangeBPDULayer |
231 | | * Represents network topology change BPDU message of Spanning Tree Protocol |
232 | | */ |
233 | | class StpTopologyChangeBPDULayer : public StpLayer |
234 | | { |
235 | | protected: |
236 | 0 | explicit StpTopologyChangeBPDULayer(size_t dataLen) : StpLayer(dataLen) {} |
237 | | |
238 | | public: |
239 | | /** |
240 | | * A constructor that creates the layer from an existing packet raw data |
241 | | * @param[in] data A pointer to the raw data |
242 | | * @param[in] dataLen Size of the data in bytes |
243 | | * @param[in] prevLayer A pointer to the previous layer |
244 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
245 | | */ |
246 | | StpTopologyChangeBPDULayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) |
247 | | : StpLayer(data, dataLen, prevLayer, packet) |
248 | 3.18k | { |
249 | 3.18k | } |
250 | | |
251 | | /** |
252 | | * Empty c'tor to create a new network topology change (TCN) BPDU layer. |
253 | | * Initializes the protocol identifier, version and STP type fields with correct values |
254 | | */ |
255 | | StpTopologyChangeBPDULayer(); |
256 | | |
257 | | /** |
258 | | * Get a pointer to network topology change (TCN) BPDU message |
259 | | * @return A pointer to TCN BPDU message |
260 | | */ |
261 | 0 | stp_tcn_bpdu* getStpTcnHeader() { return getStpHeader(); } |
262 | | |
263 | | // overridden methods |
264 | | |
265 | | /** |
266 | | * @return The size of STP TCN message |
267 | | */ |
268 | 8 | size_t getHeaderLen() const { return sizeof(stp_tcn_bpdu); } |
269 | | |
270 | | /// Parses next layer |
271 | | void parseNextLayer(); |
272 | | |
273 | | /** |
274 | | * @return Returns the protocol info as readable string |
275 | | */ |
276 | 16 | std::string toString() const { return "Spanning Tree Topology Change Notification"; } |
277 | | |
278 | | /** |
279 | | * A static method that validates the input data |
280 | | * @param[in] data The pointer to the beginning of a byte stream of an Spanning Tree Topology Change BPDU packet |
281 | | * @param[in] dataLen The length of the byte stream |
282 | | * @return True if the data is valid and can represent an Spanning Tree packet |
283 | | */ |
284 | 48 | static bool isDataValid(const uint8_t *data, size_t dataLen) { return data && dataLen >= sizeof(stp_tcn_bpdu); } |
285 | | }; |
286 | | |
287 | | /** |
288 | | * @class StpConfigurationBPDULayer |
289 | | * Represents configuration BPDU message of Spanning Tree Protocol |
290 | | */ |
291 | | class StpConfigurationBPDULayer : public StpTopologyChangeBPDULayer |
292 | | { |
293 | | protected: |
294 | 0 | explicit StpConfigurationBPDULayer(size_t dataLen) : StpTopologyChangeBPDULayer(dataLen) {} |
295 | | |
296 | | public: |
297 | | /** |
298 | | * A constructor that creates the layer from an existing packet raw data |
299 | | * @param[in] data A pointer to the raw data |
300 | | * @param[in] dataLen Size of the data in bytes |
301 | | * @param[in] prevLayer A pointer to the previous layer |
302 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
303 | | */ |
304 | | StpConfigurationBPDULayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) |
305 | | : StpTopologyChangeBPDULayer(data, dataLen, prevLayer, packet) |
306 | 3.13k | { |
307 | 3.13k | } |
308 | | |
309 | | /** |
310 | | * Empty c'tor to create a new configuration BPDU layer. |
311 | | * Initializes the protocol identifier, version and STP type fields with correct values |
312 | | */ |
313 | | StpConfigurationBPDULayer(); |
314 | | |
315 | | /** |
316 | | * Get a pointer to configuration BPDU message |
317 | | * @return A pointer to configuration BPDU message |
318 | | */ |
319 | 0 | stp_conf_bpdu *getStpConfHeader() const { return (stp_conf_bpdu *)(m_Data); } |
320 | | |
321 | | /** |
322 | | * Returns the flags of configuration message which indicates purpose of BPDU |
323 | | * @return Flags of the configuration message |
324 | | */ |
325 | 0 | uint8_t getFlag() const { return getStpConfHeader()->flag; } |
326 | | |
327 | | /** |
328 | | * Returns the flags of configuration message which indicates purpose of BPDU |
329 | | * @param[in] value Flags of the configuration message |
330 | | */ |
331 | 0 | void setFlag(uint8_t value) { getStpConfHeader()->flag = value; } |
332 | | |
333 | | /** |
334 | | * Returns the root bridge identifier |
335 | | * @return Root bridge identifier |
336 | | */ |
337 | | uint64_t getRootId() const; |
338 | | |
339 | | /** |
340 | | * Sets the root bridge identifier |
341 | | * @param[in] value Root bridge identifier |
342 | | */ |
343 | | void setRootId(uint64_t value); |
344 | | |
345 | | /** |
346 | | * Returns the priority of root bridge |
347 | | * @return Priority of root bridge |
348 | | */ |
349 | | uint16_t getRootPriority() const; |
350 | | |
351 | | /** |
352 | | * Sets the priority of root bridge |
353 | | * @param[in] value Priority of root bridge |
354 | | */ |
355 | | void setRootPriority(uint16_t value); |
356 | | |
357 | | /** |
358 | | * Returns the system identifier extension of root bridge |
359 | | * @return System extension of root bridge |
360 | | */ |
361 | | uint16_t getRootSystemIDExtension() const; |
362 | | |
363 | | /** |
364 | | * Sets the system identifier extension of root bridge |
365 | | * @param[in] value System extension of root bridge |
366 | | */ |
367 | | void setRootSystemIDExtension(uint16_t value); |
368 | | |
369 | | /** |
370 | | * Returns the system identifier of root bridge |
371 | | * @return System identifier of root bridge |
372 | | */ |
373 | 0 | pcpp::MacAddress getRootSystemID() const { return IDtoMacAddress(getRootId()); } |
374 | | |
375 | | /** |
376 | | * Sets the system identifier of root bridge |
377 | | * @param[in] value System identifier of root bridge |
378 | | */ |
379 | | void setRootSystemID(const pcpp::MacAddress &value); |
380 | | |
381 | | /** |
382 | | * Returns the value of the cost of path |
383 | | * @return Cost of path |
384 | | */ |
385 | | uint32_t getPathCost() const; |
386 | | |
387 | | /** |
388 | | * Sets the value of the cost of path |
389 | | * @param[in] value Cost of path |
390 | | */ |
391 | | void setPathCost(uint32_t value); |
392 | | |
393 | | /** |
394 | | * Returns the bridge identifier |
395 | | * @return Bridge identifier |
396 | | */ |
397 | | uint64_t getBridgeId() const; |
398 | | |
399 | | /** |
400 | | * Sets the bridge identifier |
401 | | * @param[in] value Bridge identifier |
402 | | */ |
403 | | void setBridgeId(uint64_t value); |
404 | | |
405 | | /** |
406 | | * Returns the priority of bridge |
407 | | * @return Priority of bridge |
408 | | */ |
409 | | uint16_t getBridgePriority() const; |
410 | | |
411 | | /** |
412 | | * Sets the priority of bridge |
413 | | * @param[in] value Priority of bridge |
414 | | */ |
415 | | void setBridgePriority(uint16_t value); |
416 | | |
417 | | /** |
418 | | * Returns the system identifier extension of bridge |
419 | | * @return System extension of bridge |
420 | | */ |
421 | | uint16_t getBridgeSystemIDExtension() const; |
422 | | |
423 | | /** |
424 | | * Sets the system identifier extension of bridge |
425 | | * @param[in] value System extension of bridge |
426 | | */ |
427 | | void setBridgeSystemIDExtension(uint16_t value); |
428 | | |
429 | | /** |
430 | | * Returns the system identifier of bridge |
431 | | * @return System identifier of bridge |
432 | | */ |
433 | 0 | pcpp::MacAddress getBridgeSystemID() const { return IDtoMacAddress(getBridgeId()); } |
434 | | |
435 | | /** |
436 | | * Sets the system identifier of bridge |
437 | | * @param[in] value System identifier of bridge |
438 | | */ |
439 | | void setBridgeSystemID(const pcpp::MacAddress &value); |
440 | | |
441 | | /** |
442 | | * Returns the port identifier |
443 | | * @return Port identifier |
444 | | */ |
445 | | uint16_t getPortId() const; |
446 | | |
447 | | /** |
448 | | * Sets the port identifier |
449 | | * @param[in] value Port identifier |
450 | | */ |
451 | | void setPortId(uint16_t value); |
452 | | |
453 | | /** |
454 | | * Returns age of the BPDU message |
455 | | * @return Age of BPDU in seconds |
456 | | */ |
457 | | double getMessageAge() const; |
458 | | |
459 | | /** |
460 | | * Sets age of the BPDU message |
461 | | * @param[in] value Age of BPDU in seconds |
462 | | */ |
463 | | void setMessageAge(double value); |
464 | | |
465 | | /** |
466 | | * Returns maximum age of the BPDU message |
467 | | * @return Maximum age of BPDU in seconds |
468 | | */ |
469 | | double getMaximumAge() const; |
470 | | |
471 | | /** |
472 | | * Sets maximum age of the BPDU message |
473 | | * @param[in] value Maximum age of BPDU in seconds |
474 | | */ |
475 | | void setMaximumAge(double value); |
476 | | |
477 | | /** |
478 | | * Returns the BPDU transmission interval |
479 | | * @return Value of the transmission interval in seconds |
480 | | */ |
481 | | double getTransmissionInterval() const; |
482 | | |
483 | | /** |
484 | | * Sets the BPDU transmission interval |
485 | | * @param[in] value Value of the transmission interval in seconds |
486 | | */ |
487 | | void setTransmissionInterval(double value); |
488 | | |
489 | | /** |
490 | | * Returns the delay for STP message |
491 | | * @return Value of the forward delay in seconds |
492 | | */ |
493 | | double getForwardDelay() const; |
494 | | |
495 | | /** |
496 | | * Sets the delay for STP message |
497 | | * @param[in] value Value of the forward delay in seconds |
498 | | */ |
499 | | void setForwardDelay(double value); |
500 | | |
501 | | // overridden methods |
502 | | |
503 | | /** |
504 | | * @return The size of STP configuration BPDU message |
505 | | */ |
506 | 521 | size_t getHeaderLen() const { return sizeof(stp_conf_bpdu); } |
507 | | |
508 | | /// Parses next layer |
509 | | void parseNextLayer(); |
510 | | |
511 | | /** |
512 | | * @return Returns the protocol info as readable string |
513 | | */ |
514 | 1.04k | std::string toString() const { return "Spanning Tree Configuration"; } |
515 | | |
516 | | /** |
517 | | * A static method that validates the input data |
518 | | * @param[in] data The pointer to the beginning of a byte stream of an Spanning Tree Configuration BPDU packet |
519 | | * @param[in] dataLen The length of the byte stream |
520 | | * @return True if the data is valid and can represent an Spanning Tree packet |
521 | | */ |
522 | | static bool isDataValid(const uint8_t *data, size_t dataLen) |
523 | 3.63k | { |
524 | 3.63k | return data && dataLen >= sizeof(stp_conf_bpdu); |
525 | 3.63k | } |
526 | | }; |
527 | | |
528 | | /** |
529 | | * @class RapidStpLayer |
530 | | * Represents Rapid Spanning Tree Protocol (RSTP) |
531 | | */ |
532 | | class RapidStpLayer : public StpConfigurationBPDULayer |
533 | | { |
534 | | protected: |
535 | 0 | explicit RapidStpLayer(size_t dataLen) : StpConfigurationBPDULayer(dataLen) {} |
536 | | |
537 | | public: |
538 | | /** |
539 | | * A constructor that creates the layer from an existing packet raw data |
540 | | * @param[in] data A pointer to the raw data |
541 | | * @param[in] dataLen Size of the data in bytes |
542 | | * @param[in] prevLayer A pointer to the previous layer |
543 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
544 | | */ |
545 | | RapidStpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) |
546 | | : StpConfigurationBPDULayer(data, dataLen, prevLayer, packet) |
547 | 6 | { |
548 | 6 | } |
549 | | |
550 | | /** |
551 | | * Empty c'tor to create a new Rapid STP layer. |
552 | | * Initializes the protocol identifier, version and STP type fields with correct values |
553 | | */ |
554 | | RapidStpLayer(); |
555 | | |
556 | | /** |
557 | | * Get a pointer to Rapid STP header |
558 | | * @return A pointer to Rapid STP header |
559 | | */ |
560 | 0 | rstp_conf_bpdu *getRstpConfHeader() const { return (rstp_conf_bpdu *)(m_Data); } |
561 | | |
562 | | /** |
563 | | * Returns the length of version1 field. Fixed at 0x0 for Rapid STP |
564 | | * @return Length of the version1 field |
565 | | */ |
566 | 0 | uint8_t getVersion1Len() const { return getRstpConfHeader()->version1Len; } |
567 | | |
568 | | /** |
569 | | * Returns the length of version1 field |
570 | | * @param[in] value Length of the version1 field |
571 | | */ |
572 | 0 | void setVersion1Len(uint8_t value) { getRstpConfHeader()->version1Len = value; } |
573 | | |
574 | | // overridden methods |
575 | | |
576 | | /** |
577 | | * @return The size of Rapid STP message |
578 | | */ |
579 | 1 | size_t getHeaderLen() const { return sizeof(rstp_conf_bpdu); } |
580 | | |
581 | | /// Parses next layer |
582 | | void parseNextLayer(); |
583 | | |
584 | | /** |
585 | | * @return Returns the protocol info as readable string |
586 | | */ |
587 | 2 | std::string toString() const { return "Rapid Spanning Tree"; } |
588 | | |
589 | | /** |
590 | | * A static method that validates the input data |
591 | | * @param[in] data The pointer to the beginning of a byte stream of an Rapid STP packet |
592 | | * @param[in] dataLen The length of the byte stream |
593 | | * @return True if the data is valid and can represent an Spanning Tree packet |
594 | | */ |
595 | | static bool isDataValid(const uint8_t *data, size_t dataLen) |
596 | 6 | { |
597 | 6 | return data && dataLen >= sizeof(rstp_conf_bpdu); |
598 | 6 | } |
599 | | }; |
600 | | |
601 | | /** |
602 | | * @class MultipleStpLayer |
603 | | * Represents Multiple Spanning Tree Protocol (MSTP). It has limited capabilities (no crafting / limited editing) over MSTI configuration |
604 | | */ |
605 | | class MultipleStpLayer : public RapidStpLayer |
606 | | { |
607 | | public: |
608 | | /** |
609 | | * A constructor that creates the layer from an existing packet raw data |
610 | | * @param[in] data A pointer to the raw data |
611 | | * @param[in] dataLen Size of the data in bytes |
612 | | * @param[in] prevLayer A pointer to the previous layer |
613 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
614 | | */ |
615 | | MultipleStpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) |
616 | | : RapidStpLayer(data, dataLen, prevLayer, packet) |
617 | 0 | { |
618 | 0 | } |
619 | | |
620 | | /** |
621 | | * Empty c'tor to create a new Multiple STP layer. |
622 | | * Initializes the protocol identifier, version and STP type fields with correct values |
623 | | */ |
624 | | MultipleStpLayer(); |
625 | | |
626 | | /** |
627 | | * Get a pointer to Multiple STP header |
628 | | * @return A pointer to Multiple STP header |
629 | | */ |
630 | 0 | mstp_conf_bpdu *getMstpHeader() const { return (mstp_conf_bpdu *)(m_Data); } |
631 | | |
632 | | /** |
633 | | * @return Length of version3 field |
634 | | */ |
635 | | uint16_t getVersion3Len() const; |
636 | | |
637 | | /** |
638 | | * Sets the length of version3 field |
639 | | * @param[in] value Length of version3 field |
640 | | */ |
641 | | void setVersion3Len(uint16_t value); |
642 | | |
643 | | /** |
644 | | * Returns the configuration ID format selector |
645 | | * @return Configuration ID of format selector |
646 | | */ |
647 | 0 | uint8_t getMstConfigurationFormatSelector() const { return getMstpHeader()->mstConfigFormatSelector; } |
648 | | |
649 | | /** |
650 | | * Sets the configuration ID format selector |
651 | | * @param[in] value Configuration ID of format selector |
652 | | */ |
653 | 0 | void setMstConfigurationFormatSelector(uint8_t value) { getMstpHeader()->mstConfigFormatSelector = value; } |
654 | | |
655 | | /** |
656 | | * Returns the pointer to configuration name field |
657 | | * @return Configuration name |
658 | | */ |
659 | | std::string getMstConfigurationName() const; |
660 | | |
661 | | /** |
662 | | * Sets the configuration name field |
663 | | * @param[in] value Configuration name. Length should be less than 32, if longer value provided first 32 |
664 | | * characters are used |
665 | | */ |
666 | | void setMstConfigurationName(const std::string &value); |
667 | | |
668 | | /** |
669 | | * Returns the revision of configuration ID |
670 | | * @return Revision of configuration ID |
671 | | */ |
672 | | uint16_t getMstConfigRevision() const; |
673 | | |
674 | | /** |
675 | | * Sets the revision of configuration ID |
676 | | * @param[in] value Revision of configuration ID |
677 | | */ |
678 | | void setMstConfigRevision(uint16_t value); |
679 | | |
680 | | /** |
681 | | * Returns the pointer to configuration message digest. The field itself always 16 bytes long. |
682 | | * @return A pointer to configuration digest |
683 | | */ |
684 | 0 | uint8_t *getMstConfigDigest() const { return getMstpHeader()->mstConfigDigest; } |
685 | | |
686 | | /** |
687 | | * Sets the pointer to configuration message digest. The field itself always 16 bytes long. |
688 | | * @param[in] value Pointer to digest |
689 | | * @param[in] len Length of the digest, should be less than 16. If longer first 16 bytes are used |
690 | | */ |
691 | | void setMstConfigDigest(const uint8_t *value, uint8_t len); |
692 | | |
693 | | /** |
694 | | * Returns CIST internal root path cost |
695 | | * @return Value of the internal root path cost |
696 | | */ |
697 | | uint32_t getCISTIrpc() const; |
698 | | |
699 | | /** |
700 | | * Sets CIST internal root path cost |
701 | | * @param[in] value Value of the internal root path cost |
702 | | */ |
703 | | void setCISTIrpc(uint32_t value); |
704 | | |
705 | | /** |
706 | | * Returns CIST bridge identifier |
707 | | * @return Value of the bridge identifier |
708 | | */ |
709 | | uint64_t getCISTBridgeId() const; |
710 | | |
711 | | /** |
712 | | * Sets CIST bridge identifier |
713 | | * @param[in] value Value of the bridge identifier |
714 | | */ |
715 | | void setCISTBridgeId(uint64_t value); |
716 | | |
717 | | /** |
718 | | * Returns the priority of CIST bridge |
719 | | * @return Priority of CIST bridge |
720 | | */ |
721 | | uint16_t getCISTBridgePriority() const; |
722 | | |
723 | | /** |
724 | | * Sets the priority of CIST bridge |
725 | | * @param[in] value Priority of CIST bridge |
726 | | */ |
727 | | void setCISTBridgePriority(uint16_t value); |
728 | | |
729 | | /** |
730 | | * Returns the system identifier extension of CIST bridge |
731 | | * @return System extension of CIST bridge |
732 | | */ |
733 | | uint16_t getCISTBridgeSystemIDExtension() const; |
734 | | |
735 | | /** |
736 | | * Sets the system identifier extension of CIST bridge |
737 | | * @param[in] value System extension of CIST bridge |
738 | | */ |
739 | | void setCISTBridgeSystemIDExtension(uint16_t value); |
740 | | |
741 | | /** |
742 | | * Returns the system identifier of CIST bridge |
743 | | * @return System identifier of CIST bridge |
744 | | */ |
745 | 0 | pcpp::MacAddress getCISTBridgeSystemID() const { return IDtoMacAddress(getCISTBridgeId()); } |
746 | | |
747 | | /** |
748 | | * Sets the system identifier of CIST bridge |
749 | | * @param[in] value System identifier of CIST bridge |
750 | | */ |
751 | | void setCISTBridgeSystemID(const pcpp::MacAddress &value); |
752 | | |
753 | | /** |
754 | | * Returns the remaining hop count |
755 | | * @return Value of remaining hop count |
756 | | */ |
757 | 0 | uint8_t getRemainingHopCount() const { return getMstpHeader()->remainId; } |
758 | | |
759 | | /** |
760 | | * Returns the remaining hop count |
761 | | * @param[in] value Value of remaining hop count |
762 | | */ |
763 | 0 | void setRemainingHopCount(uint8_t value) { getMstpHeader()->remainId = value; } |
764 | | |
765 | | /** |
766 | | * Returns the total number of MSTI configuration messages |
767 | | * @return Number of MSTI configuration messages. Can be between 0 and 64. |
768 | | */ |
769 | 0 | uint8_t getNumberOfMSTIConfMessages() const { return (getVersion3Len() - (sizeof(mstp_conf_bpdu) - sizeof(rstp_conf_bpdu) - sizeof(uint16_t))) / sizeof(msti_conf_msg); } |
770 | | |
771 | | /** |
772 | | * Returns a reference to MSTI configuration messages. An MSTP packet can contain between 0 to 64 MSTI messages. |
773 | | * The number of messages can be obtained by using getNumberOfMSTIConfMessages() |
774 | | * @return An array pointer to MSTI configuration messages. Returns nullptr if there is no MSTI message. |
775 | | */ |
776 | | msti_conf_msg *getMstiConfMessages() const; |
777 | | |
778 | | // overridden methods |
779 | | |
780 | | /// Parses next layer |
781 | 0 | void parseNextLayer() {} |
782 | | |
783 | | /** |
784 | | * @return Returns the protocol info as readable string |
785 | | */ |
786 | 0 | std::string toString() const { return "Multiple Spanning Tree"; } |
787 | | |
788 | | /** |
789 | | * A static method that validates the input data |
790 | | * @param[in] data The pointer to the beginning of a byte stream of an Multiple STP packet |
791 | | * @param[in] dataLen The length of the byte stream |
792 | | * @return True if the data is valid and can represent an Spanning Tree packet |
793 | | */ |
794 | | static bool isDataValid(const uint8_t *data, size_t dataLen) |
795 | 0 | { |
796 | 0 | return data && dataLen >= sizeof(mstp_conf_bpdu); |
797 | 0 | } |
798 | | }; |
799 | | } // namespace pcpp |