summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp
diff options
context:
space:
mode:
Diffstat (limited to 'packet/bgp')
-rw-r--r--packet/bgp/bgp.go25
-rw-r--r--packet/bgp/helper.go2
2 files changed, 21 insertions, 6 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index c013f23a..7c6fb582 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -7217,18 +7217,19 @@ type UnknownExtended struct {
}
func (e *UnknownExtended) Serialize() ([]byte, error) {
- buf := make([]byte, 8)
+ if len(e.Value) != 7 {
+ return nil, fmt.Errorf("invalid value length for unknown extended community: %d", len(e.Value))
+ }
+ buf := make([]byte, 8, 8)
buf[0] = uint8(e.Type)
copy(buf[1:], e.Value)
- e.Value = buf[1:]
return buf, nil
}
func (e *UnknownExtended) String() string {
buf := make([]byte, 8)
copy(buf[1:], e.Value)
- v := binary.BigEndian.Uint64(buf)
- return fmt.Sprintf("%d", v)
+ return fmt.Sprintf("%d", binary.BigEndian.Uint64(buf))
}
func (e *UnknownExtended) MarshalJSON() ([]byte, error) {
@@ -7245,7 +7246,21 @@ func (e *UnknownExtended) MarshalJSON() ([]byte, error) {
}
func (e *UnknownExtended) GetTypes() (ExtendedCommunityAttrType, ExtendedCommunityAttrSubType) {
- return ExtendedCommunityAttrType(0xFF), ExtendedCommunityAttrSubType(0xFF)
+ var subType ExtendedCommunityAttrSubType
+ if len(e.Value) > 0 {
+ // Use the first byte of value as the sub type
+ subType = ExtendedCommunityAttrSubType(e.Value[0])
+ }
+ return e.Type, subType
+}
+
+func NewUnknownExtended(typ ExtendedCommunityAttrType, value []byte) *UnknownExtended {
+ v := make([]byte, 7, 7)
+ copy(v, value)
+ return &UnknownExtended{
+ Type: typ,
+ Value: v,
+ }
}
type PathAttributeExtendedCommunities struct {
diff --git a/packet/bgp/helper.go b/packet/bgp/helper.go
index 851332fd..3b152628 100644
--- a/packet/bgp/helper.go
+++ b/packet/bgp/helper.go
@@ -67,7 +67,7 @@ func NewTestBGPUpdateMessage() *BGPMessage {
NewIPv4AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, "192.2.1.2", 3000, isTransitive),
NewOpaqueExtended(false, []byte{1, 2, 3, 4, 5, 6, 7}),
NewValidationExtended(VALIDATION_STATE_INVALID),
- &UnknownExtended{Type: 99, Value: []byte{0, 1, 2, 3, 4, 5, 6, 7}},
+ NewUnknownExtended(99, []byte{0, 1, 2, 3, 4, 5, 6, 7}),
NewESILabelExtended(1000, true),
NewESImportRouteTarget("11:22:33:44:55:66"),
NewMacMobilityExtended(123, false),