diff --git a/protocols/bgp/packet/path_attributes.go b/protocols/bgp/packet/path_attributes.go index 45451c5d9791ad4b3ee4ae093b3a60e09317b005..672d42c07378d7d1481b8cceff1f6b221bfa3333 100644 --- a/protocols/bgp/packet/path_attributes.go +++ b/protocols/bgp/packet/path_attributes.go @@ -452,6 +452,10 @@ func ParseASPathStr(asPathString string) (*PathAttribute, error) { newSegmentNeeded := true currentSegment := -1 for _, asn := range strings.Split(asPathString, " ") { + if asn == "" { + continue + } + if isBeginOfASSet(asn) { currentType = ASSet newSegmentNeeded = true diff --git a/protocols/bgp/packet/path_attributes_test.go b/protocols/bgp/packet/path_attributes_test.go index 15f78fe39a763b86eb31281cbee5e30e54a84585..a547178a7c2422ba5dc1b653735d590f3b69973b 100644 --- a/protocols/bgp/packet/path_attributes_test.go +++ b/protocols/bgp/packet/path_attributes_test.go @@ -1298,6 +1298,15 @@ func TestParseASPathStr(t *testing.T) { wantFail bool expected *PathAttribute }{ + { + name: "Empty AS Path", + input: "", + wantFail: false, + expected: &PathAttribute{ + TypeCode: ASPathAttr, + Value: ASPath{}, + }, + }, { name: "Simple AS_SEQUENCE", input: "3320 15169", diff --git a/protocols/bgp/server/update_sender_add_path.go b/protocols/bgp/server/update_sender_add_path.go index e7b46577c594c5b5f84e115981ac560777899d11..755e9c738446d1c5b8c25e96a8b0c334867f6cc3 100644 --- a/protocols/bgp/server/update_sender_add_path.go +++ b/protocols/bgp/server/update_sender_add_path.go @@ -41,6 +41,10 @@ func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error { Next: &packet.PathAttribute{ TypeCode: packet.NextHopAttr, Value: p.BGPPath.NextHop, + Next: &packet.PathAttribute{ + TypeCode: packet.LocalPrefAttr, + Value: p.BGPPath.LocalPref, + }, }, }, },