summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go11
-rw-r--r--server/server.go61
2 files changed, 47 insertions, 25 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 6d3ddf29..b3da4b3d 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -88,6 +88,7 @@ const (
REQ_VRFS
REQ_VRF_MOD
REQ_MOD_PATH
+ REQ_GLOBAL_POLICY
)
const GRPC_PORT = 8080
@@ -269,7 +270,15 @@ func (s *Server) ModPath(stream api.GobgpApi_ModPathServer) error {
}
func (s *Server) GetNeighborPolicy(ctx context.Context, arg *api.Arguments) (*api.ApplyPolicy, error) {
- req := NewGrpcRequest(REQ_NEIGHBOR_POLICY, arg.Name, bgp.RouteFamily(arg.Rf), nil)
+ if arg.Resource != api.Resource_LOCAL && arg.Resource != api.Resource_GLOBAL {
+ return nil, fmt.Errorf("unsupported resource: %s", arg.Resource)
+ }
+ var req *GrpcRequest
+ if arg.Resource == api.Resource_LOCAL {
+ req = NewGrpcRequest(REQ_NEIGHBOR_POLICY, arg.Name, bgp.RouteFamily(arg.Rf), nil)
+ } else {
+ req = NewGrpcRequest(REQ_GLOBAL_POLICY, "", bgp.RouteFamily(arg.Rf), nil)
+ }
s.bgpServerCh <- req
res := <-req.ResponseCh
diff --git a/server/server.go b/server/server.go
index 7557cf70..cc5349a8 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1539,11 +1539,9 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
grpcReq.ResponseCh <- result
close(grpcReq.ResponseCh)
- case REQ_NEIGHBOR_POLICY:
- peer, err := server.checkNeighborRequest(grpcReq)
- if err != nil {
- break
- }
+ case REQ_NEIGHBOR_POLICY, REQ_GLOBAL_POLICY:
+ var in, imp, exp []*api.PolicyDefinition
+ var inD, impD, expD api.RouteAction
extract := func(policyNames []string) []*api.PolicyDefinition {
pdList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList
@@ -1565,31 +1563,46 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
return extracted
}
- // Add importpolies that has been set in the configuration file to the list.
- // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
- conImportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ImportPolicy
- resImportPolicies := extract(conImportPolicyNames)
+ if grpcReq.RequestType == REQ_NEIGHBOR_POLICY {
+ peer, err := server.checkNeighborRequest(grpcReq)
+ if err != nil {
+ break
+ }
+ // Add importpolies that has been set in the configuration file to the list.
+ // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
+ conImportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ImportPolicy
+ imp = extract(conImportPolicyNames)
+
+ // Add importpolies that has been set in the configuration file to the list.
+ // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
+ conExportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ExportPolicy
+ exp = extract(conExportPolicyNames)
- // Add importpolies that has been set in the configuration file to the list.
- // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
- conExportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ExportPolicy
- resExportPolicies := extract(conExportPolicyNames)
+ inPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.InPolicy
+ in = extract(inPolicyNames)
- inPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.InPolicy
- resInPolicies := extract(inPolicyNames)
+ impD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_IMPORT).ToApiStruct()
+ expD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_EXPORT).ToApiStruct()
+ inD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_IN).ToApiStruct()
+ } else {
+ names := server.bgpConfig.Global.ApplyPolicy.ApplyPolicyConfig.ImportPolicy
+ imp = extract(names)
- defaultImportPolicy := peer.GetDefaultPolicy(table.POLICY_DIRECTION_IMPORT).ToApiStruct()
- defaultExportPolicy := peer.GetDefaultPolicy(table.POLICY_DIRECTION_EXPORT).ToApiStruct()
- defaultInPolicy := peer.GetDefaultPolicy(table.POLICY_DIRECTION_IN).ToApiStruct()
+ names = server.bgpConfig.Global.ApplyPolicy.ApplyPolicyConfig.ExportPolicy
+ exp = extract(names)
+
+ impD = server.globalRib.GetDefaultPolicy(table.POLICY_DIRECTION_IMPORT).ToApiStruct()
+ expD = server.globalRib.GetDefaultPolicy(table.POLICY_DIRECTION_EXPORT).ToApiStruct()
+ }
result := &GrpcResponse{
Data: &api.ApplyPolicy{
- DefaultImportPolicy: defaultImportPolicy,
- ImportPolicies: resImportPolicies,
- DefaultExportPolicy: defaultExportPolicy,
- ExportPolicies: resExportPolicies,
- DefaultInPolicy: defaultInPolicy,
- InPolicies: resInPolicies,
+ DefaultImportPolicy: impD,
+ ImportPolicies: imp,
+ DefaultExportPolicy: expD,
+ ExportPolicies: exp,
+ DefaultInPolicy: inD,
+ InPolicies: in,
},
}
grpcReq.ResponseCh <- result