From e9bc2a896075edd991fd59334dbbab4b3c5b2f68 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Sun, 10 Jan 2016 15:53:49 +0900 Subject: config: validate when unmarshalling configuration Signed-off-by: ISHIDA Wataru --- config/serve.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'config/serve.go') 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: -- cgit v1.2.3