summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--internal/pkg/config/util.go12
-rw-r--r--pkg/server/grpc_server.go15
2 files changed, 22 insertions, 5 deletions
diff --git a/internal/pkg/config/util.go b/internal/pkg/config/util.go
index cc9ea059..d18deb50 100644
--- a/internal/pkg/config/util.go
+++ b/internal/pkg/config/util.go
@@ -299,14 +299,22 @@ func newAfiSafiConfigFromConfigStruct(c *AfiSafi) *api.AfiSafiConfig {
}
func newApplyPolicyFromConfigStruct(c *ApplyPolicy) *api.ApplyPolicy {
+ f := func(t DefaultPolicyType) api.RouteAction {
+ if t == DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
+ return api.RouteAction_ACCEPT
+ } else if t == DEFAULT_POLICY_TYPE_REJECT_ROUTE {
+ return api.RouteAction_REJECT
+ }
+ return api.RouteAction_NONE
+ }
applyPolicy := &api.ApplyPolicy{
ImportPolicy: &api.PolicyAssignment{
Direction: api.PolicyDirection_IMPORT,
- DefaultAction: api.RouteAction(c.Config.DefaultImportPolicy.ToInt()),
+ DefaultAction: f(c.Config.DefaultImportPolicy),
},
ExportPolicy: &api.PolicyAssignment{
Direction: api.PolicyDirection_EXPORT,
- DefaultAction: api.RouteAction(c.Config.DefaultExportPolicy.ToInt()),
+ DefaultAction: f(c.Config.DefaultExportPolicy),
},
}
diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go
index 3a7121f7..06425dfa 100644
--- a/pkg/server/grpc_server.go
+++ b/pkg/server/grpc_server.go
@@ -504,20 +504,29 @@ func readApplyPolicyFromAPIStruct(c *config.ApplyPolicy, a *api.ApplyPolicy) {
if c == nil || a == nil {
return
}
+ f := func(a api.RouteAction) config.DefaultPolicyType {
+ if a == api.RouteAction_ACCEPT {
+ return config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
+ } else if a == api.RouteAction_REJECT {
+ return config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
+ }
+ return ""
+ }
+
if a.ImportPolicy != nil {
- c.Config.DefaultImportPolicy = config.IntToDefaultPolicyTypeMap[int(a.ImportPolicy.DefaultAction)]
+ c.Config.DefaultImportPolicy = f(a.ImportPolicy.DefaultAction)
for _, p := range a.ImportPolicy.Policies {
c.Config.ImportPolicyList = append(c.Config.ImportPolicyList, p.Name)
}
}
if a.ExportPolicy != nil {
- c.Config.DefaultExportPolicy = config.IntToDefaultPolicyTypeMap[int(a.ExportPolicy.DefaultAction)]
+ c.Config.DefaultExportPolicy = f(a.ExportPolicy.DefaultAction)
for _, p := range a.ExportPolicy.Policies {
c.Config.ExportPolicyList = append(c.Config.ExportPolicyList, p.Name)
}
}
if a.InPolicy != nil {
- c.Config.DefaultInPolicy = config.IntToDefaultPolicyTypeMap[int(a.InPolicy.DefaultAction)]
+ c.Config.DefaultInPolicy = f(a.InPolicy.DefaultAction)
for _, p := range a.InPolicy.Policies {
c.Config.InPolicyList = append(c.Config.InPolicyList, p.Name)
}