From 6ad92e40e16d7b4282a8b7fe572da49071b8d679 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Thu, 28 Jul 2022 18:07:03 +0200 Subject: [PATCH] Propagate peer parameters to AdjRIBIn (#341) Signed-off-by: Maximilian Wilhelm --- protocols/bgp/server/bgp_api_test.go | 12 +++++++--- protocols/bgp/server/bmp_router.go | 3 ++- protocols/bgp/server/fsm.go | 4 +++- protocols/bgp/server/fsm_address_family.go | 27 ++++++++++++++++++---- routingtable/adjRIBIn/adj_rib_in.go | 21 +++++++++++++---- routingtable/adjRIBIn/adj_rib_in_test.go | 20 +++++++++++++--- 6 files changed, 70 insertions(+), 17 deletions(-) diff --git a/protocols/bgp/server/bgp_api_test.go b/protocols/bgp/server/bgp_api_test.go index daa4661d..f6e673af 100644 --- a/protocols/bgp/server/bgp_api_test.go +++ b/protocols/bgp/server/bgp_api_test.go @@ -24,6 +24,12 @@ import ( ) func TestDumpRIBInOut(t *testing.T) { + peerParams := adjRIBIn.PeerParameters{ + RouterID: 0, + ClusterID: 0, + AddPathRX: true, + } + tests := []struct { name string apisrv *BGPAPIServer @@ -60,7 +66,7 @@ func TestDumpRIBInOut(t *testing.T) { fsms: []*FSM{ 0: { ipv4Unicast: &fsmAddressFamily{ - adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, 0, 0, true), + adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, peerParams), adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType}, filter.NewAcceptAllFilterChain(), true), }, }, @@ -90,7 +96,7 @@ func TestDumpRIBInOut(t *testing.T) { fsms: []*FSM{ 0: { ipv4Unicast: &fsmAddressFamily{ - adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, 0, 0, true), + adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, peerParams), adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType, RouteServerClient: true, Address: bnet.IPv4(0).Ptr()}, filter.NewAcceptAllFilterChain(), false), }, }, @@ -150,7 +156,7 @@ func TestDumpRIBInOut(t *testing.T) { fsms: []*FSM{ 0: { ipv4Unicast: &fsmAddressFamily{ - adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), 0, 0, true), + adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), peerParams), adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType, RouteServerClient: true, Address: bnet.IPv4(123).Ptr()}, filter.NewAcceptAllFilterChain(), false), }, }, diff --git a/protocols/bgp/server/bmp_router.go b/protocols/bgp/server/bmp_router.go index 85a8a317..11f9dfaa 100644 --- a/protocols/bgp/server/bmp_router.go +++ b/protocols/bgp/server/bmp_router.go @@ -307,7 +307,8 @@ func (r *Router) processPeerUpNotification(msg *bmppkt.PeerUpNotification) error localAddress, _ := bnet.IPFromBytes(msg.LocalAddress[16-addrLen:]) fsm := &FSM{ - isBMP: true, + isBMP: true, + bmpRouterAddress: r.address, peer: &peer{ routerID: sentOpen.BGPIdentifier, addr: peerAddress.Dedup(), diff --git a/protocols/bgp/server/fsm.go b/protocols/bgp/server/fsm.go index 49e42cad..c97da7ea 100644 --- a/protocols/bgp/server/fsm.go +++ b/protocols/bgp/server/fsm.go @@ -40,7 +40,9 @@ type state interface { type FSM struct { counters fsmCounters - isBMP bool + isBMP bool + bmpRouterAddress net.IP + peer *peer eventCh chan int con net.Conn diff --git a/protocols/bgp/server/fsm_address_family.go b/protocols/bgp/server/fsm_address_family.go index 935b6b3c..40584546 100644 --- a/protocols/bgp/server/fsm_address_family.go +++ b/protocols/bgp/server/fsm_address_family.go @@ -78,19 +78,19 @@ func (f *fsmAddressFamily) dumpRIBIn() []*route.Route { } type adjRIBInFactoryI interface { - New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, routerID uint32, clusterID uint32, addPathRX bool) routingtable.AdjRIBIn + New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, peerParams adjRIBIn.PeerParameters) routingtable.AdjRIBIn } type adjRIBInFactory struct{} -func (a adjRIBInFactory) New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, routerID uint32, clusterID uint32, addPathRX bool) routingtable.AdjRIBIn { - return adjRIBIn.New(exportFilterChain, contributingASNs, routerID, clusterID, addPathRX) +func (a adjRIBInFactory) New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, peerParams adjRIBIn.PeerParameters) routingtable.AdjRIBIn { + return adjRIBIn.New(exportFilterChain, contributingASNs, peerParams) } func (f *fsmAddressFamily) init(n *routingtable.Neighbor) { contributingASNs := f.rib.GetContributingASNs() - f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(f.importFilterChain, contributingASNs, f.fsm.peer.routerID, f.fsm.peer.clusterID, f.addPathRX) + f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(f.importFilterChain, contributingASNs, f.peerParameters()) contributingASNs.Add(f.fsm.peer.localASN) f.adjRIBIn.Register(f.rib) @@ -106,8 +106,25 @@ func (f *fsmAddressFamily) init(n *routingtable.Neighbor) { f.initialized = true } +func (f *fsmAddressFamily) peerParameters() adjRIBIn.PeerParameters { + rip, _ := bnet.IPFromBytes(f.fsm.bmpRouterAddress) + + return adjRIBIn.PeerParameters{ + RouterID: f.fsm.peer.routerID, + ClusterID: f.fsm.peer.clusterID, + AddPathRX: f.addPathRX, + + // Only relevant for BMP use + RouterIP: rip, + LocalIP: f.fsm.peer.localAddr, + PeerIP: f.fsm.peer.addr, + LocalASN: f.fsm.peer.localASN, + PeerASN: f.fsm.peer.peerASN, + } +} + func (f *fsmAddressFamily) bmpInit() { - f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(filter.NewAcceptAllFilterChain(), &routingtable.ContributingASNs{}, f.fsm.peer.routerID, f.fsm.peer.clusterID, f.addPathRX) + f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(filter.NewAcceptAllFilterChain(), &routingtable.ContributingASNs{}, f.peerParameters()) if f.rib != nil { f.adjRIBIn.Register(f.rib) diff --git a/routingtable/adjRIBIn/adj_rib_in.go b/routingtable/adjRIBIn/adj_rib_in.go index c972dcfe..41baa312 100644 --- a/routingtable/adjRIBIn/adj_rib_in.go +++ b/routingtable/adjRIBIn/adj_rib_in.go @@ -22,15 +22,28 @@ type AdjRIBIn struct { addPathRX bool } +type PeerParameters struct { + RouterID uint32 + ClusterID uint32 + AddPathRX bool + + // Only relevant for BMP use + RouterIP net.IP + LocalIP *net.IP + PeerIP *net.IP + LocalASN uint32 + PeerASN uint32 +} + // New creates a new Adjacency RIB In -func New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, routerID uint32, clusterID uint32, addPathRX bool) *AdjRIBIn { +func New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, peerParams PeerParameters) *AdjRIBIn { a := &AdjRIBIn{ rt: routingtable.NewRoutingTable(), exportFilterChain: exportFilterChain, contributingASNs: contributingASNs, - routerID: routerID, - clusterID: clusterID, - addPathRX: addPathRX, + routerID: peerParams.RouterID, + clusterID: peerParams.ClusterID, + addPathRX: peerParams.AddPathRX, } a.clientManager = routingtable.NewClientManager(a) return a diff --git a/routingtable/adjRIBIn/adj_rib_in_test.go b/routingtable/adjRIBIn/adj_rib_in_test.go index e82b671e..42b3c052 100644 --- a/routingtable/adjRIBIn/adj_rib_in_test.go +++ b/routingtable/adjRIBIn/adj_rib_in_test.go @@ -176,7 +176,12 @@ func TestAddPath(t *testing.T) { } for _, test := range tests { - adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), routerID, clusterID, test.addPath) + peerParams := PeerParameters{ + RouterID: routerID, + ClusterID: clusterID, + AddPathRX: test.addPath, + } + adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), peerParams) mc := routingtable.NewRTMockClient() adjRIBIn.clientManager.RegisterWithOptions(mc, routingtable.ClientOptions{BestOnly: true}) @@ -401,7 +406,12 @@ func TestRemovePath(t *testing.T) { } for _, test := range tests { - adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), 1, 2, test.addPath) + peerParams := PeerParameters{ + RouterID: 1, + ClusterID: 2, + AddPathRX: test.addPath, + } + adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), peerParams) for _, route := range test.routes { adjRIBIn.AddPath(route.Prefix().Ptr(), route.Paths()[0]) } @@ -429,7 +439,11 @@ func TestRemovePath(t *testing.T) { } func TestUnregister(t *testing.T) { - adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), 0, 0, false) + peerParams := PeerParameters{ + RouterID: 0, + ClusterID: 0, + AddPathRX: false} + adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), peerParams) mc := routingtable.NewRTMockClient() adjRIBIn.Register(mc)