diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-06-15 08:56:11 +0900 |
---|---|---|
committer | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-06-16 15:53:18 +0900 |
commit | d75edf18d7febd3f687393e8b0707e57438931eb (patch) | |
tree | 387a5f11b64b11cddf2c988eeff85a7ce6eb269c /config | |
parent | 369626d2221bb175fbf81bd59738104f77aca835 (diff) |
server: Support Dynamic Neighbor
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'config')
-rw-r--r-- | config/default.go | 50 | ||||
-rw-r--r-- | config/serve.go | 1 |
2 files changed, 41 insertions, 10 deletions
diff --git a/config/default.go b/config/default.go index 1ff57adb..9daba924 100644 --- a/config/default.go +++ b/config/default.go @@ -276,15 +276,38 @@ func validatePeerGroupConfig(n *Neighbor, b *BgpConfigSet) error { if name == "" { return nil } + + pg, err := getPeerGroup(name, b) + if err != nil { + return err + } + + if pg.Config.PeerAs != 0 && n.Config.PeerAs != 0 { + return fmt.Errorf("Cannot configure remote-as for members. PeerGroup AS %d.", pg.Config.PeerAs) + } + return nil +} + +func getPeerGroup(n string, b *BgpConfigSet) (*PeerGroup, error) { + if n == "" { + return nil, fmt.Errorf("peer-group name is not configured") + } for _, pg := range b.PeerGroups { - if name == pg.Config.PeerGroupName { - if pg.Config.PeerAs != 0 && n.Config.PeerAs != 0 { - return fmt.Errorf("Cannot configure remote-as for members. Peer-group AS %d.", pg.Config.PeerAs) - } - return nil + if n == pg.Config.PeerGroupName { + return &pg, nil } } - return fmt.Errorf("No such peer-group: %s", name) + return nil, fmt.Errorf("No such peer-group: %s", n) +} + +func validateDynamicNeighborConfig(d *DynamicNeighborConfig, b *BgpConfigSet) error { + if _, err := getPeerGroup(d.PeerGroup, b); err != nil { + return err + } + if _, _, err := net.ParseCIDR(d.Prefix); err != nil { + return fmt.Errorf("Invalid Dynamic Neighbor prefix %s", d.Prefix) + } + return nil } func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error { @@ -344,6 +367,12 @@ func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error { } } + for _, d := range b.DynamicNeighbors { + if err := validateDynamicNeighborConfig(&d.Config, b); err != nil { + return err + } + } + for idx, r := range b.RpkiServers { if r.Config.Port == 0 { b.RpkiServers[idx].Config.Port = rtr.RPKI_DEFAULT_PORT @@ -372,11 +401,12 @@ func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error { func OverwriteNeighborConfigWithPeerGroup(c *Neighbor, pg *PeerGroup) error { v := viper.New() - val, ok := configuredFields[c.Config.NeighborAddress] - if !ok { - return fmt.Errorf("No such neighbor %s", c.Config.NeighborAddress) + val, ok := configuredFields[c.State.NeighborAddress] + if ok { + v.Set("neighbor", val) + } else { + v.Set("neighbor.config.peer-group", c.Config.PeerGroup) } - v.Set("neighbor", val) overwriteConfig(&c.Config, &pg.Config, "neighbor.config", v) overwriteConfig(&c.Timers.Config, &pg.Timers.Config, "neighbor.timers.config", v) diff --git a/config/serve.go b/config/serve.go index 8dfda75e..73e2c7bb 100644 --- a/config/serve.go +++ b/config/serve.go @@ -19,6 +19,7 @@ type BgpConfigSet struct { Collector Collector `mapstructure:"collector"` DefinedSets DefinedSets `mapstructure:"defined-sets"` PolicyDefinitions []PolicyDefinition `mapstructure:"policy-definitions"` + DynamicNeighbors []DynamicNeighbor `mapstructure:"dynamic-neighbors"` } func ReadConfigfileServe(path, format string, configCh chan *BgpConfigSet) { |