diff --git a/protocols/bgp/packet/decoder_test.go b/protocols/bgp/packet/decoder_test.go index 01d4e01596040cdab68d7cd5abdfb30b846fe3fa..a69b4acbcc8e985fad6a9a58637214d4c3496c49 100644 --- a/protocols/bgp/packet/decoder_test.go +++ b/protocols/bgp/packet/decoder_test.go @@ -1243,6 +1243,25 @@ func TestDecodeUpdateMsg(t *testing.T) { explicitLength: 5, wantFail: true, }, + { + // Unknown attribute + testNum: 16, + input: []byte{ + 0, 0, // No Withdraws + 0, 7, // Total Path Attributes Length + 64, 111, 4, 1, 1, 1, 1, // Unknown attribute + }, + wantFail: false, + expected: &BGPUpdate{ + TotalPathAttrLen: 7, + PathAttributes: &PathAttribute{ + Length: 4, + Transitive: true, + TypeCode: 111, + Value: []byte{1, 1, 1, 1}, + }, + }, + }, } for _, test := range tests { diff --git a/protocols/bgp/packet/path_attributes.go b/protocols/bgp/packet/path_attributes.go index 45451c5d9791ad4b3ee4ae093b3a60e09317b005..8175f0400e343ed97653a0f0555c482b3a354927 100644 --- a/protocols/bgp/packet/path_attributes.go +++ b/protocols/bgp/packet/path_attributes.go @@ -6,7 +6,6 @@ import ( "strconv" "strings" - "github.com/sirupsen/logrus" "github.com/taktv6/tflow2/convert" ) @@ -20,11 +19,10 @@ func decodePathAttrs(buf *bytes.Buffer, tpal uint16) (*PathAttribute, error) { p := uint16(0) for p < tpal { pa, consumed, err = decodePathAttr(buf) - p += consumed if err != nil { - logrus.Errorf("Unable to decode path attr: %v", err) - continue + return nil, fmt.Errorf("Unable to decode path attr: %v", err) } + p += consumed if ret == nil { ret = pa @@ -87,12 +85,29 @@ func decodePathAttr(buf *bytes.Buffer) (pa *PathAttribute, consumed uint16, err case AtomicAggrAttr: // Nothing to do for 0 octet long attribute default: - return nil, consumed, fmt.Errorf("Invalid Attribute Type Code: %v", pa.TypeCode) + if err := pa.decodeUnknown(buf); err != nil { + return nil, consumed, fmt.Errorf("Failed to decode unknown attribute: %v", err) + } } return pa, consumed + pa.Length, nil } +func (pa *PathAttribute) decodeUnknown(buf *bytes.Buffer) error { + u := make([]byte, pa.Length) + + p := uint16(0) + err := decode(buf, []interface{}{&u}) + if err != nil { + return fmt.Errorf("Unable to decode: %v", err) + } + + pa.Value = u + p += pa.Length + + return nil +} + func (pa *PathAttribute) decodeOrigin(buf *bytes.Buffer) error { origin := uint8(0)