diff options
-rw-r--r-- | server/server.go | 16 | ||||
-rw-r--r-- | table/policy.go | 5 |
2 files changed, 20 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 diff --git a/table/policy.go b/table/policy.go index 424a8562..66416931 100644 --- a/table/policy.go +++ b/table/policy.go @@ -2690,11 +2690,16 @@ func (r *RoutingPolicy) GetAssignmentFromConfig(dir PolicyDirection, a config.Ap def = ROUTE_TYPE_REJECT } ps := make([]*Policy, 0, len(names)) + seen := make(map[string]bool) for _, name := range names { p, ok := r.PolicyMap[name] if !ok { return nil, def, fmt.Errorf("not found policy %s", name) } + if seen[name] { + return nil, def, fmt.Errorf("duplicated policy %s", name) + } + seen[name] = true ps = append(ps, p) } return ps, def, nil |