@@ -16,21 +16,11 @@ import (
1616)
1717
1818type STPSwitchID struct {
19- Priority STPPriority // Bridge priority
20- SysID uint16 // VLAN ID
19+ Priority uint16 // Bridge priority
20+ SysID uint16 // VLAN ID
2121 HwAddr net.HardwareAddr
2222}
2323
24- type STPPriority uint16
25-
26- // Potential values for STPSwitchID.Priority.
27- const (
28- STPPriorityMax STPPriority = 32768
29- STPPriorityHigh STPPriority = 16384
30- STPPriorityLow STPPriority = 8192
31- STPPriorityMin STPPriority = 4046
32- )
33-
3424// STP decode spanning tree protocol packets to transport BPDU (bridge protocol data unit) message.
3525type STP struct {
3626 BaseLayer
@@ -68,11 +58,11 @@ func (stp *STP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
6858 stp .Type = uint8 (data [3 ])
6959 stp .TC = data [4 ]& 0x01 != 0
7060 stp .TCA = data [4 ]& 0x80 != 0
71- stp .RouteID .Priority = STPPriority ( binary .BigEndian .Uint16 (data [5 :7 ]) & 0xf000 )
61+ stp .RouteID .Priority = binary .BigEndian .Uint16 (data [5 :7 ]) & 0xf000
7262 stp .RouteID .SysID = binary .BigEndian .Uint16 (data [5 :7 ]) & 0x0fff
7363 stp .RouteID .HwAddr = net .HardwareAddr (data [7 :13 ])
7464 stp .Cost = binary .BigEndian .Uint32 (data [13 :17 ])
75- stp .BridgeID .Priority = STPPriority ( binary .BigEndian .Uint16 (data [17 :19 ]) & 0xf000 )
65+ stp .BridgeID .Priority = binary .BigEndian .Uint16 (data [17 :19 ]) & 0xf000
7666 stp .BridgeID .SysID = binary .BigEndian .Uint16 (data [17 :19 ]) & 0x0fff
7767 stp .BridgeID .HwAddr = net .HardwareAddr (data [19 :25 ])
7868 stp .PortID = binary .BigEndian .Uint16 (data [25 :27 ])
@@ -92,18 +82,14 @@ func (stp *STP) NextLayerType() gopacket.LayerType {
9282}
9383
9484// Check if the priority value is correct.
95- func checkPriority (prio STPPriority ) (uint16 , error ) {
96- switch prio {
97- case STPPriorityMax :
98- return uint16 (prio ), nil
99- case STPPriorityHigh :
100- return uint16 (prio ), nil
101- case STPPriorityLow :
102- return uint16 (prio ), nil
103- case STPPriorityMin :
104- return uint16 (prio ), nil
105- default :
106- return uint16 (prio ), errors .New ("Invalid Priority value must be one of the following:\n 32768\n 16384\n 8192\n 4096\n " )
85+ func checkPriority (prio uint16 ) (uint16 , error ) {
86+ if prio == 0 {
87+ return prio , errors .New ("Invalid Priority value must be in the rage <4096-61440> with an increment of 4096" )
88+ }
89+ if prio % 4096 == 0 {
90+ return prio , nil
91+ } else {
92+ return prio , errors .New ("Invalid Priority value must be in the rage <4096-61440> with an increment of 4096" )
10793 }
10894}
10995
0 commit comments