summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--config/default.go4
-rw-r--r--server/server.go35
-rw-r--r--server/zclient.go27
3 files changed, 34 insertions, 32 deletions
diff --git a/config/default.go b/config/default.go
index 21b95758..536b7a1e 100644
--- a/config/default.go
+++ b/config/default.go
@@ -33,6 +33,10 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
}
}
+ if !v.IsSet("global.zebra.url") {
+ b.Global.Zebra.Url = "unix:/var/run/quagga/zserv.api"
+ }
+
if !v.IsSet("global.afi-safis") {
b.Global.AfiSafis = []AfiSafi{}
for k, _ := range AfiSafiTypeToIntMap {
diff --git a/server/server.go b/server/server.go
index fc60ef63..a03fd92e 100644
--- a/server/server.go
+++ b/server/server.go
@@ -30,7 +30,6 @@ import (
"net"
"os"
"strconv"
- "strings"
"sync"
"time"
)
@@ -235,14 +234,12 @@ func (server *BgpServer) Serve() {
w, _ := newGrpcIncomingWatcher()
server.watchers[WATCHER_GRPC_INCOMING] = w
- if g.Zebra.Enabled == true {
- if g.Zebra.Url == "" {
- g.Zebra.Url = "unix:/var/run/quagga/zserv.api"
- }
- err := server.NewZclient(g.Zebra.Url, g.Zebra.RedistributeRouteTypeList)
+ if g.Zebra.Enabled {
+ cli, err := NewZclient(g.Zebra.Url, g.Zebra.RedistributeRouteTypeList)
if err != nil {
log.Error(err)
}
+ server.zclient = cli
}
senderCh := make(chan *SenderMsg, 1<<16)
@@ -3059,29 +3056,3 @@ func (server *BgpServer) mkMrtRibMsgs(tbl *table.Table, t uint32) ([]*bgp.MRTMes
}
return msgs, nil
}
-
-func (server *BgpServer) NewZclient(url string, redistRouteTypes []config.InstallProtocolType) error {
- l := strings.SplitN(url, ":", 2)
- if len(l) != 2 {
- return fmt.Errorf("unsupported url: %s", url)
- }
- cli, err := zebra.NewClient(l[0], l[1], zebra.ROUTE_BGP)
- if err != nil {
- return err
- }
- cli.SendHello()
- cli.SendRouterIDAdd()
- cli.SendInterfaceAdd()
- for _, typ := range redistRouteTypes {
- t, err := zebra.RouteTypeFromString(string(typ))
- if err != nil {
- return err
- }
- cli.SendRedistribute(t)
- }
- if e := cli.SendCommand(zebra.REDISTRIBUTE_DEFAULT_ADD, nil); e != nil {
- return e
- }
- server.zclient = cli
- return nil
-}
diff --git a/server/zclient.go b/server/zclient.go
index 6cf0af4f..b380e90e 100644
--- a/server/zclient.go
+++ b/server/zclient.go
@@ -16,7 +16,9 @@
package server
import (
+ "fmt"
log "github.com/Sirupsen/logrus"
+ "github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
"github.com/osrg/gobgp/table"
"github.com/osrg/gobgp/zebra"
@@ -164,3 +166,28 @@ func handleZapiMsg(msg *zebra.Message, server *BgpServer) []*SenderMsg {
return nil
}
+
+func NewZclient(url string, redistRouteTypes []config.InstallProtocolType) (*zebra.Client, error) {
+ l := strings.SplitN(url, ":", 2)
+ if len(l) != 2 {
+ return nil, fmt.Errorf("unsupported url: %s", url)
+ }
+ cli, err := zebra.NewClient(l[0], l[1], zebra.ROUTE_BGP)
+ if err != nil {
+ return nil, err
+ }
+ cli.SendHello()
+ cli.SendRouterIDAdd()
+ cli.SendInterfaceAdd()
+ for _, typ := range redistRouteTypes {
+ t, err := zebra.RouteTypeFromString(string(typ))
+ if err != nil {
+ return nil, err
+ }
+ cli.SendRedistribute(t)
+ }
+ if e := cli.SendCommand(zebra.REDISTRIBUTE_DEFAULT_ADD, nil); e != nil {
+ return nil, e
+ }
+ return cli, nil
+}