diff options
-rw-r--r-- | api/gobgp.pb.go | 16 | ||||
-rw-r--r-- | api/gobgp.proto | 4 | ||||
-rw-r--r-- | gobgp/neighbor.go | 10 | ||||
-rw-r--r-- | server/peer.go | 48 | ||||
-rw-r--r-- | server/server.go | 76 |
5 files changed, 77 insertions, 77 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index ef4afabe..9ef9cbef 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -666,12 +666,12 @@ func (m *PolicyDefinition) GetStatementList() []*Statement { } type ApplyPolicy struct { - ImportPolicies []*PolicyDefinition `protobuf:"bytes,1,rep,name=import_policies" json:"import_policies,omitempty"` - DefaultImportPolicy string `protobuf:"bytes,2,opt,name=default_import_policy" json:"default_import_policy,omitempty"` - ExportPolicies []*PolicyDefinition `protobuf:"bytes,3,rep,name=export_policies" json:"export_policies,omitempty"` - DefaultExportPolicy string `protobuf:"bytes,4,opt,name=default_export_policy" json:"default_export_policy,omitempty"` - DistributePolicies []*PolicyDefinition `protobuf:"bytes,5,rep,name=distribute_policies" json:"distribute_policies,omitempty"` - DefaultDistributePolicy string `protobuf:"bytes,6,opt,name=default_distribute_policy" json:"default_distribute_policy,omitempty"` + ImportPolicies []*PolicyDefinition `protobuf:"bytes,1,rep,name=import_policies" json:"import_policies,omitempty"` + DefaultImportPolicy string `protobuf:"bytes,2,opt,name=default_import_policy" json:"default_import_policy,omitempty"` + ExportPolicies []*PolicyDefinition `protobuf:"bytes,3,rep,name=export_policies" json:"export_policies,omitempty"` + DefaultExportPolicy string `protobuf:"bytes,4,opt,name=default_export_policy" json:"default_export_policy,omitempty"` + InPolicies []*PolicyDefinition `protobuf:"bytes,5,rep,name=in_policies" json:"in_policies,omitempty"` + DefaultInPolicy string `protobuf:"bytes,6,opt,name=default_in_policy" json:"default_in_policy,omitempty"` } func (m *ApplyPolicy) Reset() { *m = ApplyPolicy{} } @@ -692,9 +692,9 @@ func (m *ApplyPolicy) GetExportPolicies() []*PolicyDefinition { return nil } -func (m *ApplyPolicy) GetDistributePolicies() []*PolicyDefinition { +func (m *ApplyPolicy) GetInPolicies() []*PolicyDefinition { if m != nil { - return m.DistributePolicies + return m.InPolicies } return nil } diff --git a/api/gobgp.proto b/api/gobgp.proto index 93e7d6a8..259bdfff 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -283,8 +283,8 @@ message ApplyPolicy { string default_import_policy = 2; repeated PolicyDefinition export_policies = 3; string default_export_policy = 4; - repeated PolicyDefinition distribute_policies = 5; - string default_distribute_policy = 6; + repeated PolicyDefinition in_policies = 5; + string default_in_policy = 6; } message MrtMessage { diff --git a/gobgp/neighbor.go b/gobgp/neighbor.go index 401714fe..adc2b9fb 100644 --- a/gobgp/neighbor.go +++ b/gobgp/neighbor.go @@ -529,7 +529,7 @@ func showNeighborPolicy(remoteIP net.IP) error { fmt.Printf("DefaultImportPolicy: %s\n", ap.DefaultImportPolicy) fmt.Printf("DefaultExportPolicy: %s\n", ap.DefaultExportPolicy) - fmt.Printf("DefaultDistributePolicy: %s\n", ap.DefaultDistributePolicy) + fmt.Printf("DefaultInPolicy: %s\n", ap.DefaultInPolicy) fmt.Printf("ImportPolicies:\n") for _, inPolicy := range ap.ImportPolicies { fmt.Printf(" PolicyName %s:\n", inPolicy.PolicyDefinitionName) @@ -540,8 +540,8 @@ func showNeighborPolicy(remoteIP net.IP) error { fmt.Printf(" PolicyName %s:\n", outPolicy.PolicyDefinitionName) showPolicyStatement(2, outPolicy) } - fmt.Printf("DistributePolicies:\n") - for _, distPolicy := range ap.DistributePolicies { + fmt.Printf("InPolicies:\n") + for _, distPolicy := range ap.InPolicies { fmt.Printf(" PolicyName %s:\n", distPolicy.PolicyDefinitionName) showPolicyStatement(2, distPolicy) } @@ -583,8 +583,8 @@ func modNeighborPolicy(remoteIP net.IP, cmdType string, eArg []string) error { pol.ExportPolicies = policies pol.DefaultExportPolicy = defaultPolicy case CMD_DISTRIBUTE: - pol.DistributePolicies = policies - pol.DefaultDistributePolicy = defaultPolicy + pol.InPolicies = policies + pol.DefaultInPolicy = defaultPolicy } operation = api.Operation_ADD diff --git a/server/peer.go b/server/peer.go index 43a9d32a..1d77ed51 100644 --- a/server/peer.go +++ b/server/peer.go @@ -33,18 +33,18 @@ const ( ) type Peer struct { - gConf config.Global - conf config.Neighbor - fsm *FSM - rfMap map[bgp.RouteFamily]bool - capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface - adjRib *table.AdjRib - peerInfo *table.PeerInfo - outgoing chan *bgp.BGPMessage - distPolicies []*policy.Policy - defaultDistributePolicy config.DefaultPolicyType - isConfederationMember bool - isEBGP bool + gConf config.Global + conf config.Neighbor + fsm *FSM + rfMap map[bgp.RouteFamily]bool + capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface + adjRib *table.AdjRib + peerInfo *table.PeerInfo + outgoing chan *bgp.BGPMessage + inPolicies []*policy.Policy + defaultInPolicy config.DefaultPolicyType + isConfederationMember bool + isEBGP bool } func NewPeer(g config.Global, conf config.Neighbor) *Peer { @@ -281,8 +281,8 @@ func (peer *Peer) ToApiStruct() *api.Peer { received += uint32(peer.adjRib.GetInCount(rf)) // FIXME: we should store 'accepted' in memory for _, p := range peer.adjRib.GetInPathList(rf) { - applied, path := peer.applyDistributePolicies(p) - if applied && path == nil || !applied && peer.defaultDistributePolicy != config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { + applied, path := peer.applyPolicies(POLICY_DIRECTION_IN, p) + if applied && path == nil || !applied && peer.defaultInPolicy != config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { continue } accepted += 1 @@ -334,10 +334,10 @@ func (peer *Peer) ToApiStruct() *api.Peer { } } -func (peer *Peer) setDistributePolicy(policyMap map[string]*policy.Policy) { +func (peer *Peer) setPolicy(policyMap map[string]*policy.Policy) { // configure distribute policy policyConf := peer.conf.ApplyPolicy - distPolicies := make([]*policy.Policy, 0) + inPolicies := make([]*policy.Policy, 0) for _, policyName := range policyConf.ApplyPolicyConfig.InPolicy { log.WithFields(log.Fields{ "Topic": "Peer", @@ -346,17 +346,19 @@ func (peer *Peer) setDistributePolicy(policyMap map[string]*policy.Policy) { }).Info("distribute policy installed") if pol, ok := policyMap[policyName]; ok { log.Debug("distribute policy : ", pol) - distPolicies = append(distPolicies, pol) + inPolicies = append(inPolicies, pol) } } - peer.distPolicies = distPolicies - peer.defaultDistributePolicy = policyConf.ApplyPolicyConfig.DefaultInPolicy + peer.inPolicies = inPolicies + peer.defaultInPolicy = policyConf.ApplyPolicyConfig.DefaultInPolicy } -func (peer *Peer) applyDistributePolicies(original *table.Path) (bool, *table.Path) { - policies := peer.distPolicies - var d Direction = POLICY_DIRECTION_DISTRIBUTE - +func (peer *Peer) applyPolicies(d Direction, original *table.Path) (bool, *table.Path) { + var policies []*policy.Policy + switch d { + case POLICY_DIRECTION_IN: + policies = peer.inPolicies + } return applyPolicy("Peer", peer.conf.NeighborConfig.NeighborAddress.String(), d, policies, original) } diff --git a/server/server.go b/server/server.go index e365790c..366708a3 100644 --- a/server/server.go +++ b/server/server.go @@ -39,9 +39,9 @@ const ( type Direction string const ( - POLICY_DIRECTION_IMPORT Direction = "import" - POLICY_DIRECTION_EXPORT = "export" - POLICY_DIRECTION_DISTRIBUTE = "distribute" + POLICY_DIRECTION_IMPORT Direction = "import" + POLICY_DIRECTION_EXPORT = "export" + POLICY_DIRECTION_IN = "in" ) type SenderMsg struct { @@ -253,8 +253,8 @@ func (server *BgpServer) Serve() { loc := NewLocalRib(name, peer.configuredRFlist(), make(map[string]*policy.Policy)) server.addLocalRib(loc) loc.setPolicy(peer, server.policyMap) - // set distribute policy - peer.setDistributePolicy(server.policyMap) + // set in policy + peer.setPolicy(server.policyMap) pathList := make([]*table.Path, 0) for _, p := range server.neighborMap { @@ -309,7 +309,7 @@ func (server *BgpServer) Serve() { peer.conf.ApplyPolicy = config.ApplyPolicy loc := server.localRibMap[addr] loc.setPolicy(peer, server.policyMap) - peer.setDistributePolicy(server.policyMap) + peer.setPolicy(server.policyMap) } case e := <-incoming: peer, found := server.neighborMap[e.MsgSrc] @@ -456,8 +456,8 @@ func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Pat defaultPolicy = loc.defaultExportPolicy case POLICY_DIRECTION_IMPORT: defaultPolicy = loc.defaultImportPolicy - case POLICY_DIRECTION_DISTRIBUTE: - defaultPolicy = peer.defaultDistributePolicy + case POLICY_DIRECTION_IN: + defaultPolicy = peer.defaultInPolicy default: log.WithFields(log.Fields{ "Topic": "Server", @@ -469,9 +469,10 @@ func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Pat for _, path := range pathList { if !path.IsWithdraw { var applied bool = false - if d == POLICY_DIRECTION_DISTRIBUTE { - applied, path = peer.applyDistributePolicies(path) - } else { + switch d { + case POLICY_DIRECTION_IN: + applied, path = peer.applyPolicies(d, path) + case POLICY_DIRECTION_IMPORT, POLICY_DIRECTION_EXPORT: applied, path = loc.applyPolicies(d, path) } @@ -566,7 +567,7 @@ func (server *BgpServer) propagateUpdate(neighborAddress string, RouteServerClie if RouteServerClient { p := server.neighborMap[neighborAddress] - newPathList := applyPolicies(p, nil, POLICY_DIRECTION_DISTRIBUTE, pathList) + newPathList := applyPolicies(p, nil, POLICY_DIRECTION_IN, pathList) for _, loc := range server.localRibMap { targetPeer := server.neighborMap[loc.OwnerName()] if loc.isGlobal() || loc.OwnerName() == neighborAddress { @@ -750,7 +751,7 @@ func (server *BgpServer) handlePolicy(pl config.RoutingPolicy) { }).Info("call set policy") loc.setPolicy(targetPeer, server.policyMap) // set distribute policy - targetPeer.setDistributePolicy(server.policyMap) + targetPeer.setPolicy(server.policyMap) } } @@ -1274,13 +1275,10 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { close(grpcReq.ResponseCh) break } - resInPolicies := []*api.PolicyDefinition{} - resOutPolicies := []*api.PolicyDefinition{} - resDistPolicies := []*api.PolicyDefinition{} - pdList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList - df := server.routingPolicy.DefinedSets extract := func(policyNames []string) []*api.PolicyDefinition { + pdList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList + df := server.routingPolicy.DefinedSets extracted := []*api.PolicyDefinition{} for _, policyName := range policyNames { match := false @@ -1300,37 +1298,37 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { // 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. - conInPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ImportPolicy - resInPolicies = extract(conInPolicyNames) + conImportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ImportPolicy + resImportPolicies := 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. - conOutPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ExportPolicy - resOutPolicies = extract(conOutPolicyNames) + conExportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ExportPolicy + resExportPolicies := extract(conExportPolicyNames) - distPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.InPolicy - resDistPolicies = extract(distPolicyNames) + inPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.InPolicy + resInPolicies := extract(inPolicyNames) + defaultImportPolicy := policy.ROUTE_REJECT + defaultExportPolicy := policy.ROUTE_REJECT defaultInPolicy := policy.ROUTE_REJECT - defaultOutPolicy := policy.ROUTE_REJECT - defaultDistPolicy := policy.ROUTE_REJECT if loc.defaultImportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { - defaultInPolicy = policy.ROUTE_ACCEPT + defaultImportPolicy = policy.ROUTE_ACCEPT } if loc.defaultExportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { - defaultOutPolicy = policy.ROUTE_ACCEPT + defaultExportPolicy = policy.ROUTE_ACCEPT } - if peer.defaultDistributePolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { - defaultDistPolicy = policy.ROUTE_ACCEPT + if peer.defaultInPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { + defaultInPolicy = policy.ROUTE_ACCEPT } result := &GrpcResponse{ Data: &api.ApplyPolicy{ - DefaultImportPolicy: defaultInPolicy, - ImportPolicies: resInPolicies, - DefaultExportPolicy: defaultOutPolicy, - ExportPolicies: resOutPolicies, - DefaultDistributePolicy: defaultDistPolicy, - DistributePolicies: resDistPolicies, + DefaultImportPolicy: defaultImportPolicy, + ImportPolicies: resImportPolicies, + DefaultExportPolicy: defaultExportPolicy, + ExportPolicies: resExportPolicies, + DefaultInPolicy: defaultInPolicy, + InPolicies: resInPolicies, }, } grpcReq.ResponseCh <- result @@ -1359,11 +1357,11 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { applyPolicy.DefaultExportPolicy = defOutPolicy applyPolicy.ExportPolicy = policy.PoliciesToString(reqApplyPolicy.ExportPolicies) } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE { - if reqApplyPolicy.DefaultDistributePolicy != policy.ROUTE_ACCEPT { + if reqApplyPolicy.DefaultInPolicy != policy.ROUTE_ACCEPT { defDistPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE } applyPolicy.DefaultInPolicy = defDistPolicy - applyPolicy.InPolicy = policy.PoliciesToString(reqApplyPolicy.DistributePolicies) + applyPolicy.InPolicy = policy.PoliciesToString(reqApplyPolicy.InPolicies) } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_IMPORT { applyPolicy.DefaultImportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE applyPolicy.ImportPolicy = make([]string, 0) @@ -1377,7 +1375,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE || grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE { - peer.setDistributePolicy(reqPolicyMap) + peer.setPolicy(reqPolicyMap) } else { loc := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()] loc.setPolicy(peer, reqPolicyMap) |