diff --git a/main.go b/main.go index ae2b9ba87782f6d78468b9b2a3b4ab3e5f456700..e311932915a7f33c7135d45b804ca4ee429a1544 100644 --- a/main.go +++ b/main.go @@ -13,8 +13,15 @@ import ( "github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable/filter" "github.com/bio-routing/bio-rd/routingtable/locRIB" + + bnet "github.com/bio-routing/bio-rd/net" ) +func strAddr(s string) uint32 { + ret, _ := bnet.StrToAddr(s) + return ret +} + func main() { logrus.Printf("This is a BGP speaker\n") diff --git a/protocols/bgp/server/fsm_established.go b/protocols/bgp/server/fsm_established.go index f1195dad2f5bc21ac16f8cfe94d3fd7a8e75b1c8..ca68aecc2fe61957bc10d3582e6c7855a2ef0b0f 100644 --- a/protocols/bgp/server/fsm_established.go +++ b/protocols/bgp/server/fsm_established.go @@ -58,8 +58,10 @@ func (s *establishedState) init() { s.fsm.adjRIBIn.Register(s.fsm.peer.importFilter) n := &routingtable.Neighbor{ - Type: route.BGPPathType, - Address: tnet.IPv4ToUint32(s.fsm.peer.addr), + Type: route.BGPPathType, + Address: tnet.IPv4ToUint32(s.fsm.peer.addr), + IBGP: s.fsm.peer.localASN == s.fsm.peer.peerASN, + LocalASN: s.fsm.peer.localASN, } clientOptions := routingtable.ClientOptions{} diff --git a/protocols/bgp/server/update_helper.go b/protocols/bgp/server/update_helper.go index fdb73fee2aead719b76a7bef7ba9209e46891857..e0a24a6e3bbf1369b59b25d04f1f6c3c16930844 100644 --- a/protocols/bgp/server/update_helper.go +++ b/protocols/bgp/server/update_helper.go @@ -10,8 +10,8 @@ import ( log "github.com/sirupsen/logrus" ) -func pathAttribues(p *route.Path, fsm *FSM) (*packet.PathAttribute, error) { - asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", fsm.peer.localASN, p.BGPPath.ASPath), " ")) +func pathAttribues(p *route.Path) (*packet.PathAttribute, error) { + asPathPA, err := packet.ParseASPathStr(strings.TrimRight(p.BGPPath.ASPath, " ")) if err != nil { return nil, fmt.Errorf("Unable to parse AS path: %v", err) } diff --git a/protocols/bgp/server/update_sender.go b/protocols/bgp/server/update_sender.go index 76c4eadc827ab809af23d09df9e809f1ed4b4a47..67fb6662febaec64942dd48c6164ad00b0441bc4 100644 --- a/protocols/bgp/server/update_sender.go +++ b/protocols/bgp/server/update_sender.go @@ -28,7 +28,7 @@ func newUpdateSender(fsm *FSM) *UpdateSender { // AddPath serializes a new path and sends out a BGP update message func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error { - pathAttrs, err := pathAttribues(p, u.fsm) + pathAttrs, err := pathAttribues(p) if err != nil { log.Errorf("Unable to create BGP Update: %v", err) return nil diff --git a/protocols/bgp/server/update_sender_add_path.go b/protocols/bgp/server/update_sender_add_path.go index 0dac801374e167c3bd5e8a38304ba12f8af74f3c..7abef161e4f5accd6b49b423849fbbd3d4a56742 100644 --- a/protocols/bgp/server/update_sender_add_path.go +++ b/protocols/bgp/server/update_sender_add_path.go @@ -25,7 +25,7 @@ func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath { // AddPath serializes a new path and sends out a BGP update message func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error { - pathAttrs, err := pathAttribues(p, u.fsm) + pathAttrs, err := pathAttribues(p) if err != nil { log.Errorf("Unable to create BGP Update: %v", err) diff --git a/routingtable/adjRIBOut/adj_rib_out.go b/routingtable/adjRIBOut/adj_rib_out.go index fe728f0e64981276e38322ec3985b467180ee05f..5c15e446f20692c4375ea2b27aa8061fca32faf4 100644 --- a/routingtable/adjRIBOut/adj_rib_out.go +++ b/routingtable/adjRIBOut/adj_rib_out.go @@ -39,6 +39,11 @@ func (a *AdjRIBOut) AddPath(pfx net.Prefix, p *route.Path) error { return nil } + p = p.Copy() + if !a.neighbor.IBGP { + p.BGPPath.ASPath = fmt.Sprintf("%d %s", a.neighbor.LocalASN, p.BGPPath.ASPath) + } + a.mu.Lock() defer a.mu.Unlock() diff --git a/routingtable/adjRIBOutAddPath/adj_rib_out_add_path.go b/routingtable/adjRIBOutAddPath/adj_rib_out_add_path.go index f0c75c0b74ac84d43a6b2cb257ed18504ccc51ef..30c20c4bc8b612e8788838da5a0180fa4f3d3166 100644 --- a/routingtable/adjRIBOutAddPath/adj_rib_out_add_path.go +++ b/routingtable/adjRIBOutAddPath/adj_rib_out_add_path.go @@ -41,6 +41,11 @@ func (a *AdjRIBOutAddPath) AddPath(pfx net.Prefix, p *route.Path) error { return nil } + p = p.Copy() + if !a.neighbor.IBGP { + p.BGPPath.ASPath = fmt.Sprintf("%d %s", a.neighbor.LocalASN, p.BGPPath.ASPath) + } + a.mu.Lock() defer a.mu.Unlock() diff --git a/routingtable/neighbor.go b/routingtable/neighbor.go index 7ae0f7395637c3a2f7bcf9de4a890edf804c982b..11b8c8de65a54e768c4a852cb87dcbfe44d6c55a 100644 --- a/routingtable/neighbor.go +++ b/routingtable/neighbor.go @@ -10,4 +10,7 @@ type Neighbor struct { // IBGP returns if local ASN is equal to remote ASN IBGP bool + + // Local ASN of session + LocalASN uint32 }