summaryrefslogtreecommitdiffhomepage
path: root/config/serve.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-10 15:53:49 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-02-12 14:17:38 -0800
commite9bc2a896075edd991fd59334dbbab4b3c5b2f68 (patch)
treeafe2489f07cd34451d1ff881b3e02a0a4e36d810 /config/serve.go
parent9f54df220808370dd34d0dab802330c2b4bb81d4 (diff)
config: validate when unmarshalling configuration
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'config/serve.go')
-rw-r--r--config/serve.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/config/serve.go b/config/serve.go
index 10eed911..8c7d833c 100644
--- a/config/serve.go
+++ b/config/serve.go
@@ -17,32 +17,42 @@ func ReadConfigfileServe(path, format string, configCh chan BgpConfigSet, reload
<-reloadCh
b := Bgp{}
- p := RoutingPolicy{}
v := viper.New()
v.SetConfigFile(path)
v.SetConfigType(format)
err := v.ReadInConfig()
+ c := struct {
+ Global Global `mapstructure:"global"`
+ Neighbors []Neighbor `mapstructure:"neighbors"`
+ RpkiServers []RpkiServer `mapstructure:"rpki-servers"`
+ DefinedSets DefinedSets `mapstructure:"defined-sets"`
+ PolicyDefinitions []PolicyDefinition `mapstructure:"policy-definitions"`
+ }{}
if err != nil {
goto ERROR
}
- err = v.Unmarshal(&b)
+ err = v.UnmarshalExact(&c)
if err != nil {
goto ERROR
}
+ b.Global = c.Global
+ b.Neighbors = c.Neighbors
+ b.RpkiServers = c.RpkiServers
err = SetDefaultConfigValues(v, &b)
if err != nil {
goto ERROR
}
- err = v.Unmarshal(&p)
- if err != nil {
- goto ERROR
- }
-
if cnt == 0 {
log.Info("finished reading the config file")
}
cnt++
- configCh <- BgpConfigSet{Bgp: b, Policy: p}
+ configCh <- BgpConfigSet{
+ Bgp: b,
+ Policy: RoutingPolicy{
+ DefinedSets: c.DefinedSets,
+ PolicyDefinitions: c.PolicyDefinitions,
+ },
+ }
continue
ERROR: