summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp/bgp.go22
-rw-r--r--packet/bgp/validate.go17
2 files changed, 27 insertions, 12 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index 2fea8b44..ef2e3e20 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -5213,6 +5213,8 @@ var asPathParamFormatMap = map[uint8]*AsPathParamFormat{
}
type AsPathParamInterface interface {
+ GetType() uint8
+ GetAS() []uint32
Serialize() ([]byte, error)
DecodeFromBytes([]byte) error
Len() int
@@ -5227,6 +5229,18 @@ type AsPathParam struct {
AS []uint16
}
+func (a *AsPathParam) GetType() uint8 {
+ return a.Type
+}
+
+func (a *AsPathParam) GetAS() []uint32 {
+ nums := make([]uint32, 0, len(a.AS))
+ for _, as := range a.AS {
+ nums = append(nums, uint32(as))
+ }
+ return nums
+}
+
func (a *AsPathParam) Serialize() ([]byte, error) {
buf := make([]byte, 2+len(a.AS)*2)
buf[0] = uint8(a.Type)
@@ -5314,6 +5328,14 @@ type As4PathParam struct {
AS []uint32
}
+func (a *As4PathParam) GetType() uint8 {
+ return a.Type
+}
+
+func (a *As4PathParam) GetAS() []uint32 {
+ return a.AS
+}
+
func (a *As4PathParam) Serialize() ([]byte, error) {
buf := make([]byte, 2+len(a.AS)*4)
buf[0] = a.Type
diff --git a/packet/bgp/validate.go b/packet/bgp/validate.go
index ecc67067..1b8f27c9 100644
--- a/packet/bgp/validate.go
+++ b/packet/bgp/validate.go
@@ -173,23 +173,16 @@ func ValidateAttribute(a PathAttributeInterface, rfs map[RouteFamily]BGPAddPathM
}
}
case *PathAttributeAsPath:
- getSegType := func(p AsPathParamInterface) uint8 {
- asParam, y := p.(*As4PathParam)
- if y {
- return asParam.Type
- } else {
- return p.(*AsPathParam).Type
- }
- }
if isEBGP {
if isConfed {
- if segType := getSegType(p.Value[0]); segType != BGP_ASPATH_ATTR_TYPE_CONFED_SEQ {
+ if segType := p.Value[0].GetType(); segType != BGP_ASPATH_ATTR_TYPE_CONFED_SEQ {
return false, NewMessageError(eCode, eSubCodeMalformedAspath, nil, fmt.Sprintf("segment type is not confederation seq (%d)", segType))
}
} else {
- for _, paramIf := range p.Value {
- segType := getSegType(paramIf)
- if segType == BGP_ASPATH_ATTR_TYPE_CONFED_SET || segType == BGP_ASPATH_ATTR_TYPE_CONFED_SEQ {
+ for _, param := range p.Value {
+ segType := param.GetType()
+ switch segType {
+ case BGP_ASPATH_ATTR_TYPE_CONFED_SET, BGP_ASPATH_ATTR_TYPE_CONFED_SEQ:
err := NewMessageErrorWithErrorHandling(
eCode, eSubCodeMalformedAspath, nil, getErrorHandlingFromPathAttribute(p.GetType()), nil, fmt.Sprintf("segment type confederation(%d) found", segType))
if err.(*MessageError).Stronger(strongestError) {