summaryrefslogtreecommitdiffhomepage
path: root/gobgpd/main.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-04-05 16:26:23 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-04-19 11:12:44 +0000
commitdaaa9302baae4259eb89c23f65cfcfc361d547bc (patch)
tree83442f77ab9889b4d2a6d83cb01a9bf1f66c2daf /gobgpd/main.go
parent642270bb32db2a0a55badf6a53076aeac2dfb215 (diff)
config/gobgpd: refactoring
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'gobgpd/main.go')
-rw-r--r--gobgpd/main.go57
1 files changed, 24 insertions, 33 deletions
diff --git a/gobgpd/main.go b/gobgpd/main.go
index f6788cab..d955599f 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -159,7 +159,7 @@ func main() {
log.SetFormatter(&log.JSONFormatter{})
}
- configCh := make(chan config.BgpConfigSet)
+ configCh := make(chan *config.BgpConfigSet)
if opts.Dry {
go config.ReadConfigfileServe(opts.ConfigFile, opts.ConfigType, configCh)
c := <-configCh
@@ -193,26 +193,32 @@ func main() {
go config.ReadConfigfileServe(opts.ConfigFile, opts.ConfigType, configCh)
}
- var bgpConfig *config.Bgp = nil
- var policyConfig *config.RoutingPolicy = nil
+ var c *config.BgpConfigSet = nil
for {
select {
case newConfig := <-configCh:
var added, deleted, updated []config.Neighbor
- if bgpConfig == nil {
- if err := bgpServer.SetGlobalType(newConfig.Bgp.Global); err != nil {
+ if c == nil {
+ c = newConfig
+ if err := bgpServer.SetGlobalType(newConfig.Global); err != nil {
log.Fatalf("failed to set global config: %s", err)
}
- bgpConfig = &newConfig.Bgp
- bgpServer.SetRpkiConfig(newConfig.Bgp.RpkiServers)
- if err := bgpServer.SetBmpConfig(newConfig.Bgp.BmpServers); err != nil {
- log.Fatalf("failed to set global config: %s", err)
+ if err := bgpServer.SetRpkiConfig(newConfig.RpkiServers); err != nil {
+ log.Fatalf("failed to set rpki config: %s", err)
}
- if err := bgpServer.SetMrtConfig(newConfig.Bgp.MrtDump); err != nil {
- log.Fatalf("failed to set global config: %s", err)
+ if err := bgpServer.SetBmpConfig(newConfig.BmpServers); err != nil {
+ log.Fatalf("failed to set bmp config: %s", err)
+ }
+ if err := bgpServer.SetMrtConfig(newConfig.MrtDump); err != nil {
+ log.Fatalf("failed to set mrt config: %s", err)
}
- added = newConfig.Bgp.Neighbors
+ p := config.ConfigSetToRoutingPolicy(newConfig)
+ if err := bgpServer.SetRoutingPolicy(*p); err != nil {
+ log.Fatalf("failed to set routing policy: %s", err)
+ }
+
+ added = newConfig.Neighbors
if opts.GracefulRestart {
for i, n := range added {
if n.GracefulRestart.Config.Enabled {
@@ -220,31 +226,16 @@ func main() {
}
}
}
- deleted = []config.Neighbor{}
- updated = []config.Neighbor{}
- } else {
- bgpConfig, added, deleted, updated = config.UpdateConfig(bgpConfig, &newConfig.Bgp)
- }
- if policyConfig == nil {
- policyConfig = &newConfig.Policy
- // FIXME: Currently the following code
- // is safe because the above
- // SetRpkiConfig will be blocked
- // because the length of rpkiConfigCh
- // is zero. So server.GlobalRib is
- // allocated before the above
- // SetPolicy. But this should be
- // handled more cleanly.
- if err := bgpServer.SetRoutingPolicy(newConfig.Policy); err != nil {
- log.Fatal(err)
- }
} else {
- if config.CheckPolicyDifference(policyConfig, &newConfig.Policy) {
+ var updatePolicy bool
+ c, added, deleted, updated, updatePolicy = config.UpdateConfig(c, newConfig)
+ if updatePolicy {
log.Info("Policy config is updated")
- bgpServer.UpdatePolicy(newConfig.Policy)
- policyConfig = &newConfig.Policy
+ p := config.ConfigSetToRoutingPolicy(newConfig)
+ bgpServer.UpdatePolicy(*p)
}
+
}
for _, p := range added {