From 3356dafb162448e1a42ab4573c5596f717cbfd79 Mon Sep 17 00:00:00 2001
From: Oliver Herms <oliver.herms@exaring.de>
Date: Tue, 29 May 2018 13:54:27 +0200
Subject: [PATCH] Adding support for empty AS paths

---
 protocols/bgp/packet/path_attributes.go        | 4 ++++
 protocols/bgp/packet/path_attributes_test.go   | 9 +++++++++
 protocols/bgp/server/update_sender_add_path.go | 4 ++++
 3 files changed, 17 insertions(+)

diff --git a/protocols/bgp/packet/path_attributes.go b/protocols/bgp/packet/path_attributes.go
index 45451c5d..672d42c0 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 15f78fe3..a547178a 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 e7b46577..755e9c73 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,
+					},
 				},
 			},
 		},
-- 
GitLab