summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-11-08 06:31:49 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-11-08 06:31:49 -0800
commit344e575502102352ee448463763badc16e1ffdfd (patch)
tree1cc17bab815a383d2c4e28d1a835892034cb819d
parent2f6db55c6743cdd568f1555b91017a6f2c09695d (diff)
server: add rfmap to fsm too
rfmap is necessary to validate BGP messages. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--config/util.go13
-rw-r--r--server/fsm.go3
-rw-r--r--server/peer.go57
3 files changed, 46 insertions, 27 deletions
diff --git a/config/util.go b/config/util.go
index 26ab7004..85a36e38 100644
--- a/config/util.go
+++ b/config/util.go
@@ -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
+}
diff --git a/server/fsm.go b/server/fsm.go
index fcd8b5b0..16745fb4 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -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,
diff --git a/server/peer.go b/server/peer.go
index cc695859..17e40dee 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -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