diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-04-20 08:39:13 +0000 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-04-20 09:17:22 +0000 |
commit | 733b05b83185d3c1dd0c783462d91a10400c0ae2 (patch) | |
tree | 4c6a8f869634c42b38eda6ada4f1608c8afebb8e /server | |
parent | e21e48410a6ff36db38973c59aca0b8f89083809 (diff) |
policy: don't allow same policy assigned twice
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/server.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/server/server.go b/server/server.go index 0a447783..5f6068a5 100644 --- a/server/server.go +++ b/server/server.go @@ -2830,20 +2830,34 @@ func (server *BgpServer) handleGrpcModPolicyAssignment(grpcReq *GrpcRequest) err return err } ps := make([]*table.Policy, 0, len(assignment.Policies)) + seen := make(map[string]bool) for _, x := range assignment.Policies { p, ok := server.policy.PolicyMap[x.Name] if !ok { return fmt.Errorf("not found policy %s", x.Name) } + if seen[x.Name] { + return fmt.Errorf("duplicated policy %s", x.Name) + } + seen[x.Name] = true ps = append(ps, p) } cur := server.policy.GetPolicy(id, dir) + switch arg.Operation { case api.Operation_ADD, api.Operation_REPLACE: if arg.Operation == api.Operation_REPLACE || cur == nil { err = server.policy.SetPolicy(id, dir, ps) } else { - err = server.policy.SetPolicy(id, dir, append(cur, ps...)) + seen = make(map[string]bool) + ps = append(cur, ps...) + for _, x := range ps { + if seen[x.Name()] { + return fmt.Errorf("duplicated policy %s", x.Name()) + } + seen[x.Name()] = true + } + err = server.policy.SetPolicy(id, dir, ps) } if err != nil { return err |