summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-12-12 11:35:43 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-12-16 22:10:33 +0900
commit61cdca78d7ee84ac2f0384f2096a42fa54acb6b7 (patch)
treef5383109893e78f0d8504a7b26da8dbe7e63b255
parenteb5e3b8ff21726f819e431751777b489ba7da546 (diff)
config/util: Refactor to make arguments to receivers
For code readability, this commit make some arguments to receivers. Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
-rw-r--r--config/util.go68
-rw-r--r--server/fsm.go2
-rw-r--r--server/server.go12
3 files changed, 41 insertions, 41 deletions
diff --git a/config/util.go b/config/util.go
index bcb5f2a7..dfe60d6c 100644
--- a/config/util.go
+++ b/config/util.go
@@ -86,19 +86,9 @@ func (n *Neighbor) IsEBGPPeer(g *Global) bool {
return n.Config.PeerAs != g.Config.As
}
-type AfiSafis []AfiSafi
-
-func (c AfiSafis) ToRfList() ([]bgp.RouteFamily, error) {
- rfs := make([]bgp.RouteFamily, 0, len(c))
- for _, af := range c {
- rfs = append(rfs, af.State.Family)
- }
- return rfs, nil
-}
-
-func CreateRfMap(p *Neighbor) map[bgp.RouteFamily]bgp.BGPAddPathMode {
+func (n *Neighbor) CreateRfMap() map[bgp.RouteFamily]bgp.BGPAddPathMode {
rfMap := make(map[bgp.RouteFamily]bgp.BGPAddPathMode)
- for _, af := range p.AfiSafis {
+ for _, af := range n.AfiSafis {
mode := bgp.BGP_ADD_PATH_NONE
if af.AddPaths.State.Receive {
mode |= bgp.BGP_ADD_PATH_RECEIVE
@@ -111,8 +101,8 @@ func CreateRfMap(p *Neighbor) map[bgp.RouteFamily]bgp.BGPAddPathMode {
return rfMap
}
-func GetAfiSafi(p *Neighbor, family bgp.RouteFamily) *AfiSafi {
- for _, a := range p.AfiSafis {
+func (n *Neighbor) GetAfiSafi(family bgp.RouteFamily) *AfiSafi {
+ for _, a := range n.AfiSafis {
if string(a.Config.AfiSafiName) == family.String() {
return &a
}
@@ -120,6 +110,36 @@ func GetAfiSafi(p *Neighbor, family bgp.RouteFamily) *AfiSafi {
return nil
}
+func (n *Neighbor) ExtractNeighborAddress() (string, error) {
+ addr := n.State.NeighborAddress
+ if addr == "" {
+ addr = n.Config.NeighborAddress
+ if addr == "" {
+ return "", fmt.Errorf("NeighborAddress is not configured")
+ }
+ }
+ return addr, nil
+}
+
+func (n *Neighbor) IsAddPathReceiveEnabled(family bgp.RouteFamily) bool {
+ for _, af := range n.AfiSafis {
+ if af.State.Family == family {
+ return af.AddPaths.State.Receive
+ }
+ }
+ return false
+}
+
+type AfiSafis []AfiSafi
+
+func (c AfiSafis) ToRfList() ([]bgp.RouteFamily, error) {
+ rfs := make([]bgp.RouteFamily, 0, len(c))
+ for _, af := range c {
+ rfs = append(rfs, af.State.Family)
+ }
+ return rfs, nil
+}
+
func CheckAfiSafisChange(x, y []AfiSafi) bool {
if len(x) != len(y) {
return true
@@ -173,23 +193,3 @@ func ParseMaskLength(prefix, mask string) (int, int, error) {
}
return min, max, nil
}
-
-func ExtractNeighborAddress(c *Neighbor) (string, error) {
- addr := c.State.NeighborAddress
- if addr == "" {
- addr = c.Config.NeighborAddress
- if addr == "" {
- return "", fmt.Errorf("NeighborAddress is not configured")
- }
- }
- return addr, nil
-}
-
-func (n *Neighbor) IsAddPathReceiveEnabled(family bgp.RouteFamily) bool {
- for _, af := range n.AfiSafis {
- if af.State.Family == family {
- return af.AddPaths.State.Receive
- }
- }
- return false
-}
diff --git a/server/fsm.go b/server/fsm.go
index 556e1029..c3c2910e 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -999,7 +999,7 @@ func open2Cap(open *bgp.BGPOpen, n *config.Neighbor) (map[bgp.BGPCapabilityCode]
capMap[bgp.BGP_CAP_MULTIPROTOCOL] = []bgp.ParameterCapabilityInterface{bgp.NewCapMultiProtocol(bgp.RF_IPv4_UC)}
}
- local := config.CreateRfMap(n)
+ local := n.CreateRfMap()
remote := make(map[bgp.RouteFamily]bgp.BGPAddPathMode)
for _, c := range capMap[bgp.BGP_CAP_MULTIPROTOCOL] {
family := c.(*bgp.CapMultiProtocol).CapValue
diff --git a/server/server.go b/server/server.go
index edea141d..8e3b362f 100644
--- a/server/server.go
+++ b/server/server.go
@@ -951,7 +951,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) {
// any routes (and EORs) before we send ours (or deferral-timer expires).
var pathList []*table.Path
_, y := peer.fsm.rfMap[bgp.RF_RTC_UC]
- if c := config.GetAfiSafi(peer.fsm.pConf, bgp.RF_RTC_UC); y && !peer.fsm.pConf.GracefulRestart.State.PeerRestarting && c.RouteTargetMembership.Config.DeferralTime > 0 {
+ if c := peer.fsm.pConf.GetAfiSafi(bgp.RF_RTC_UC); y && !peer.fsm.pConf.GracefulRestart.State.PeerRestarting && c.RouteTargetMembership.Config.DeferralTime > 0 {
pathList, _ = peer.getBestFromLocal([]bgp.RouteFamily{bgp.RF_RTC_UC})
t := c.RouteTargetMembership.Config.DeferralTime
for _, f := range peer.configuredRFlist() {
@@ -1102,7 +1102,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) {
// received EOR of route-target address family
// outbound filter is now ready, let's flash non-route-target NLRIs
- if c := config.GetAfiSafi(peer.fsm.pConf, bgp.RF_RTC_UC); rtc && c != nil && c.RouteTargetMembership.Config.DeferralTime > 0 {
+ if c := peer.fsm.pConf.GetAfiSafi(bgp.RF_RTC_UC); rtc && c != nil && c.RouteTargetMembership.Config.DeferralTime > 0 {
log.WithFields(log.Fields{
"Topic": "Peer",
"Key": peer.ID(),
@@ -1559,7 +1559,7 @@ func (s *BgpServer) softResetOut(addr string, family bgp.RouteFamily, deferral b
"Key": peer.ID(),
"Families": families,
}).Debug("deferral timer expired")
- } else if c := config.GetAfiSafi(peer.fsm.pConf, bgp.RF_RTC_UC); y && !c.MpGracefulRestart.State.EndOfRibReceived {
+ } else if c := peer.fsm.pConf.GetAfiSafi(bgp.RF_RTC_UC); y && !c.MpGracefulRestart.State.EndOfRibReceived {
log.WithFields(log.Fields{
"Topic": "Peer",
"Key": peer.ID(),
@@ -1775,7 +1775,7 @@ func (server *BgpServer) addPeerGroup(c *config.PeerGroup) error {
}
func (server *BgpServer) addNeighbor(c *config.Neighbor) error {
- addr, err := config.ExtractNeighborAddress(c)
+ addr, err := c.ExtractNeighborAddress()
if err != nil {
return err
}
@@ -1905,7 +1905,7 @@ func (server *BgpServer) deleteNeighbor(c *config.Neighbor, code, subcode uint8)
}
}
- addr, err := config.ExtractNeighborAddress(c)
+ addr, err := c.ExtractNeighborAddress()
if err != nil {
return err
}
@@ -1999,7 +1999,7 @@ func (s *BgpServer) updateNeighbor(c *config.Neighbor) (needsSoftResetIn bool, e
}
}
- addr, err := config.ExtractNeighborAddress(c)
+ addr, err := c.ExtractNeighborAddress()
if err != nil {
return needsSoftResetIn, err
}