summaryrefslogtreecommitdiffhomepage
path: root/pkg/server
diff options
context:
space:
mode:
authorHitoshi Irino <irino@sfc.wide.ad.jp>2018-12-29 21:53:10 +0900
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2018-12-30 21:52:15 +0900
commit4e862fa8f0017383ecdae22c757753214ba7815c (patch)
tree62700c8b24d6d5c234729d4cd89b6b0384ad9ade /pkg/server
parent67947eeda62ff961208b19f29c652399dd93ea97 (diff)
zebra: Introducing MIN_ZAPIVER and MAX_ZAPIVER. And avoiding double close channel when sequential retry to connect zebra.
- Introducing MIN_ZAPIVER and MAX_ZAPIVER for avoiding editing files except for zapi.go when new ZAPI version will be supported in future. - Fix a bug avoiding panic by double close for a channel. - Changing algorithm for sequential retry to connect zebra.
Diffstat (limited to 'pkg/server')
-rw-r--r--pkg/server/zclient.go31
1 files changed, 27 insertions, 4 deletions
diff --git a/pkg/server/zclient.go b/pkg/server/zclient.go
index a814e20a..3e4fb3e6 100644
--- a/pkg/server/zclient.go
+++ b/pkg/server/zclient.go
@@ -341,6 +341,9 @@ func (z *zebraClient) loop() {
case <-z.dead:
return
case msg := <-z.client.Receive():
+ if msg == nil {
+ break
+ }
switch body := msg.Body.(type) {
case *zebra.IPRouteBody:
if path := newPathFromIPRouteMessage(msg, z.client.Version); path != nil {
@@ -419,19 +422,39 @@ func newZebraClient(s *BgpServer, url string, protos []string, version uint8, nh
}
var cli *zebra.Client
var err error
- for _, ver := range []uint8{version, 2, 3, 4, 5, 6} {
+ var usingVersion uint8
+ var zapivers [zebra.MaxZapiVer - zebra.MinZapiVer + 1]uint8
+ zapivers[0] = version
+ for elem, ver := 1, zebra.MinZapiVer; elem < len(zapivers) && ver <= zebra.MaxZapiVer; elem++ {
+ if version == ver && ver < zebra.MaxZapiVer {
+ ver++
+ }
+ zapivers[elem] = ver
+ ver++
+ }
+ for elem, ver := range zapivers {
cli, err = zebra.NewClient(l[0], l[1], zebra.ROUTE_BGP, ver)
- if err == nil {
+ if cli != nil && err == nil {
+ usingVersion = ver
break
}
// Retry with another Zebra message version
log.WithFields(log.Fields{
"Topic": "Zebra",
- }).Warnf("cannot connect to Zebra with message version %d. going to retry another version...", ver)
+ }).Warnf("cannot connect to Zebra with message version %d.", ver)
+ if elem < len(zapivers)-1 {
+ log.WithFields(log.Fields{
+ "Topic": "Zebra",
+ }).Warnf("going to retry another version %d.", zapivers[elem+1])
+ }
}
- if cli == nil {
+ if cli == nil || err != nil {
return nil, err
}
+ log.WithFields(log.Fields{
+ "Topic": "Zebra",
+ }).Infof("success to connect to Zebra with message version %d.", usingVersion)
+
// Note: HELLO/ROUTER_ID_ADD messages are automatically sent to negotiate
// the Zebra message version in zebra.NewClient().
// cli.SendHello()