mirror of
https://github.com/osrg/gobgp.git
synced 2024-05-11 05:55:10 +00:00
server: add rfmap to fsm too
rfmap is necessary to validate BGP messages. Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
@@ -15,6 +15,10 @@
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/osrg/gobgp/packet"
|
||||
)
|
||||
|
||||
func IsConfederationMember(g *Global, p *Neighbor) bool {
|
||||
if p.NeighborConfig.PeerAs != g.GlobalConfig.As {
|
||||
for _, member := range g.Confederation.ConfederationConfig.MemberAs {
|
||||
@@ -25,3 +29,12 @@ func IsConfederationMember(g *Global, p *Neighbor) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func CreateRfMap(p *Neighbor) map[bgp.RouteFamily]bool {
|
||||
rfMap := make(map[bgp.RouteFamily]bool)
|
||||
for _, rf := range p.AfiSafis.AfiSafiList {
|
||||
k, _ := bgp.GetRouteFamily(rf.AfiSafiName)
|
||||
rfMap[k] = true
|
||||
}
|
||||
return rfMap
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ type FSM struct {
|
||||
adminStateCh chan AdminState
|
||||
getActiveCh chan struct{}
|
||||
h *FSMHandler
|
||||
rfMap map[bgp.RouteFamily]bool
|
||||
}
|
||||
|
||||
func (fsm *FSM) bgpMessageStateUpdate(MessageType uint8, isIn bool) {
|
||||
@@ -143,6 +144,7 @@ func NewFSM(gConf *config.Global, pConf *config.Neighbor) *FSM {
|
||||
adminState: adminState,
|
||||
adminStateCh: make(chan AdminState, 1),
|
||||
getActiveCh: make(chan struct{}),
|
||||
rfMap: make(map[bgp.RouteFamily]bool),
|
||||
}
|
||||
fsm.t.Go(fsm.connectLoop)
|
||||
return fsm
|
||||
@@ -550,6 +552,7 @@ func (h *FSMHandler) opensent() bgp.FSMState {
|
||||
fsm.sendNotificatonFromErrorMsg(h.conn, err.(*bgp.MessageError))
|
||||
return bgp.BGP_FSM_IDLE
|
||||
}
|
||||
_, fsm.rfMap = open2Cap(body, fsm.pConf)
|
||||
|
||||
e := &fsmMsg{
|
||||
MsgType: FSM_MSG_BGP_MESSAGE,
|
||||
|
||||
+30
-27
@@ -61,10 +61,6 @@ func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager) *Pe
|
||||
|
||||
conf.NeighborState.SessionState = uint32(bgp.BGP_FSM_IDLE)
|
||||
conf.Timers.TimersState.Downtime = time.Now().Unix()
|
||||
for _, rf := range conf.AfiSafis.AfiSafiList {
|
||||
k, _ := bgp.GetRouteFamily(rf.AfiSafiName)
|
||||
peer.rfMap[k] = true
|
||||
}
|
||||
id := net.ParseIP(string(conf.RouteReflector.RouteReflectorConfig.RouteReflectorClusterId)).To4()
|
||||
peer.peerInfo = &table.PeerInfo{
|
||||
AS: conf.NeighborConfig.PeerAs,
|
||||
@@ -125,6 +121,35 @@ func (peer *Peer) getBestFromLocal(rfList []bgp.RouteFamily) ([]*table.Path, []*
|
||||
return pathList, filtered
|
||||
}
|
||||
|
||||
func open2Cap(open *bgp.BGPOpen, n *config.Neighbor) (map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface, map[bgp.RouteFamily]bool) {
|
||||
capMap := make(map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface)
|
||||
rfMap := config.CreateRfMap(n)
|
||||
r := make(map[bgp.RouteFamily]bool)
|
||||
for _, p := range open.OptParams {
|
||||
if paramCap, y := p.(*bgp.OptionParameterCapability); y {
|
||||
for _, c := range paramCap.Capability {
|
||||
m, ok := capMap[c.Code()]
|
||||
if !ok {
|
||||
m = make([]bgp.ParameterCapabilityInterface, 0, 1)
|
||||
}
|
||||
capMap[c.Code()] = append(m, c)
|
||||
|
||||
if c.Code() == bgp.BGP_CAP_MULTIPROTOCOL {
|
||||
m := c.(*bgp.CapMultiProtocol)
|
||||
r[m.CapValue] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for rf, _ := range rfMap {
|
||||
if _, y := r[rf]; !y {
|
||||
delete(rfMap, rf)
|
||||
}
|
||||
}
|
||||
return capMap, rfMap
|
||||
}
|
||||
|
||||
func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*bgp.BGPMessage) {
|
||||
bgpMsgList := []*bgp.BGPMessage{}
|
||||
pathList := []*table.Path{}
|
||||
@@ -140,29 +165,7 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b
|
||||
peer.recvOpen = m
|
||||
body := m.Body.(*bgp.BGPOpen)
|
||||
peer.peerInfo.ID = m.Body.(*bgp.BGPOpen).ID
|
||||
r := make(map[bgp.RouteFamily]bool)
|
||||
for _, p := range body.OptParams {
|
||||
if paramCap, y := p.(*bgp.OptionParameterCapability); y {
|
||||
for _, c := range paramCap.Capability {
|
||||
m, ok := peer.capMap[c.Code()]
|
||||
if !ok {
|
||||
m = make([]bgp.ParameterCapabilityInterface, 0, 1)
|
||||
}
|
||||
peer.capMap[c.Code()] = append(m, c)
|
||||
|
||||
if c.Code() == bgp.BGP_CAP_MULTIPROTOCOL {
|
||||
m := c.(*bgp.CapMultiProtocol)
|
||||
r[m.CapValue] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for rf, _ := range peer.rfMap {
|
||||
if _, y := r[rf]; !y {
|
||||
delete(peer.rfMap, rf)
|
||||
}
|
||||
}
|
||||
peer.capMap, peer.rfMap = open2Cap(body, &peer.conf)
|
||||
|
||||
// calculate HoldTime
|
||||
// RFC 4271 P.13
|
||||
|
||||
Reference in New Issue
Block a user