diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-11-09 05:07:37 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-11-09 05:07:37 -0800 |
commit | d621be037478fe1f92eafb03356339459bd84bd6 (patch) | |
tree | a5afcff26a47016c6959780bff50d0a967914143 /server | |
parent | 344e575502102352ee448463763badc16e1ffdfd (diff) |
server: call ValidateUpdateMsg() in fsm instead of peer
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/fsm.go | 19 | ||||
-rw-r--r-- | server/peer.go | 48 |
2 files changed, 31 insertions, 36 deletions
diff --git a/server/fsm.go b/server/fsm.go index 16745fb4..d20de598 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -79,6 +79,7 @@ type FSM struct { getActiveCh chan struct{} h *FSMHandler rfMap map[bgp.RouteFamily]bool + confedCheck bool } func (fsm *FSM) bgpMessageStateUpdate(MessageType uint8, isIn bool) { @@ -145,6 +146,7 @@ func NewFSM(gConf *config.Global, pConf *config.Neighbor) *FSM { adminStateCh: make(chan AdminState, 1), getActiveCh: make(chan struct{}), rfMap: make(map[bgp.RouteFamily]bool), + confedCheck: !config.IsConfederationMember(gConf, pConf) && config.IsEBGPPeer(gConf, pConf), } fsm.t.Go(fsm.connectLoop) return fsm @@ -487,14 +489,27 @@ func (h *FSMHandler) recvMessageWithError() error { MsgData: m, } if h.fsm.state == bgp.BGP_FSM_ESTABLISHED { - if m.Header.Type == bgp.BGP_MSG_KEEPALIVE || m.Header.Type == bgp.BGP_MSG_UPDATE { + switch m.Header.Type { + case bgp.BGP_MSG_UPDATE: + body := m.Body.(*bgp.BGPUpdate) + _, err := bgp.ValidateUpdateMsg(body, h.fsm.rfMap, h.fsm.confedCheck) + if err != nil { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": h.fsm.pConf.NeighborConfig.NeighborAddress.String(), + "error": err, + }).Warn("malformed BGP update message") + fmsg.MsgData = err + } + fallthrough + case bgp.BGP_MSG_KEEPALIVE: // if the lenght of h.holdTimerResetCh // isn't zero, the timer will be reset // soon anyway. if len(h.holdTimerResetCh) == 0 { h.holdTimerResetCh <- true } - } else if m.Header.Type == bgp.BGP_MSG_NOTIFICATION { + case bgp.BGP_MSG_NOTIFICATION: h.reason = "Notification received" } } diff --git a/server/peer.go b/server/peer.go index 17e40dee..6f9627a7 100644 --- a/server/peer.go +++ b/server/peer.go @@ -32,21 +32,20 @@ const ( ) type Peer struct { - gConf config.Global - conf config.Neighbor - fsm *FSM - rfMap map[bgp.RouteFamily]bool - capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface - adjRib *table.AdjRib - peerInfo *table.PeerInfo - outgoing chan *bgp.BGPMessage - inPolicies []*table.Policy - defaultInPolicy table.RouteType - accepted uint32 - staleAccepted bool - isConfederationMember bool - recvOpen *bgp.BGPMessage - localRib *table.TableManager + gConf config.Global + conf config.Neighbor + fsm *FSM + rfMap map[bgp.RouteFamily]bool + capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface + adjRib *table.AdjRib + peerInfo *table.PeerInfo + outgoing chan *bgp.BGPMessage + inPolicies []*table.Policy + defaultInPolicy table.RouteType + accepted uint32 + staleAccepted bool + recvOpen *bgp.BGPMessage + localRib *table.TableManager } func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager) *Peer { @@ -72,14 +71,9 @@ func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager) *Pe } peer.adjRib = table.NewAdjRib(peer.configuredRFlist()) peer.fsm = NewFSM(&g, &conf) - peer.isConfederationMember = config.IsConfederationMember(&g, &conf) return peer } -func (peer *Peer) isEBGPPeer() bool { - return peer.conf.NeighborConfig.PeerAs != peer.gConf.GlobalConfig.As -} - func (peer *Peer) isIBGPPeer() bool { return peer.conf.NeighborConfig.PeerAs == peer.gConf.GlobalConfig.As } @@ -212,20 +206,6 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b update = true peer.conf.Timers.TimersState.UpdateRecvTime = time.Now().Unix() body := m.Body.(*bgp.BGPUpdate) - confedCheckRequired := !peer.isConfederationMember && peer.isEBGPPeer() - _, err := bgp.ValidateUpdateMsg(body, peer.rfMap, confedCheckRequired) - if err != nil { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": peer.conf.NeighborConfig.NeighborAddress, - "error": err, - }).Warn("malformed BGP update message") - m := err.(*bgp.MessageError) - if m.TypeCode != 0 { - bgpMsgList = append(bgpMsgList, bgp.NewBGPNotificationMessage(m.TypeCode, m.SubTypeCode, m.Data)) - } - break - } table.UpdatePathAttrs4ByteAs(body) pathList = table.ProcessMessage(m, peer.peerInfo) if len(pathList) > 0 { |