summaryrefslogtreecommitdiffhomepage
path: root/config/util.go
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-10-19 16:32:34 +0900
committerSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-11-08 10:14:21 +0900
commitab9532119159e36cadf1ace3cf44773d40971729 (patch)
tree96bee97ac3144367992dae43e29817c6f4ac4333 /config/util.go
parent5c16d53c7fa0fc19cb7087d61fbf8c7bfa94910f (diff)
config: Properly set config of PeerGroup member
Currently, the config of PeerGroup members are not set properly. For example, if LocalAs of the neighbor is not set in the config file, LocalAs will be set to Global.As as a default value. After this, however, if the neighbor is a member of a peer group, LocalAs will be unexpectedly overwritten by the peer group config. This commit fixes this by setting default values after applying the peer group config. Adding to this, this commit avoids unnecessary applying the peer group config. Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'config/util.go')
-rw-r--r--config/util.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/config/util.go b/config/util.go
index 3bbddca9..bcb5f2a7 100644
--- a/config/util.go
+++ b/config/util.go
@@ -40,6 +40,32 @@ func detectConfigFileType(path, def string) string {
}
}
+func (b *BgpConfigSet) getPeerGroup(n string) (*PeerGroup, error) {
+ if n == "" {
+ return nil, nil
+ }
+ for _, pg := range b.PeerGroups {
+ if n == pg.Config.PeerGroupName {
+ return &pg, nil
+ }
+ }
+ return nil, fmt.Errorf("no such peer-group: %s", n)
+}
+
+func (d *DynamicNeighbor) validate(b *BgpConfigSet) error {
+ if d.Config.PeerGroup == "" {
+ return fmt.Errorf("dynamic neighbor requires the peer group config")
+ }
+
+ if _, err := b.getPeerGroup(d.Config.PeerGroup); err != nil {
+ return err
+ }
+ if _, _, err := net.ParseCIDR(d.Config.Prefix); err != nil {
+ return fmt.Errorf("invalid dynamic neighbor prefix %s", d.Config.Prefix)
+ }
+ return nil
+}
+
func (n *Neighbor) IsConfederationMember(g *Global) bool {
for _, member := range g.Confederation.Config.MemberAsList {
if member == n.Config.PeerAs {