From ab9532119159e36cadf1ace3cf44773d40971729 Mon Sep 17 00:00:00 2001 From: Satoshi Fujimoto Date: Thu, 19 Oct 2017 16:32:34 +0900 Subject: 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 --- config/util.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'config/util.go') 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 { -- cgit v1.2.3