diff options
-rw-r--r-- | gobgpd/main.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gobgpd/main.go b/gobgpd/main.go index 8ecc8877..4ee76bd7 100644 --- a/gobgpd/main.go +++ b/gobgpd/main.go @@ -24,6 +24,7 @@ import ( "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" "github.com/osrg/gobgp/server" + "github.com/osrg/gobgp/table" "io/ioutil" "log/syslog" "net/http" @@ -250,6 +251,40 @@ func main() { p := config.ConfigSetToRoutingPolicy(newConfig) bgpServer.UpdatePolicy(*p) } + // global policy update + if !newConfig.Global.ApplyPolicy.Config.Equal(&c.Global.ApplyPolicy.Config) { + a := newConfig.Global.ApplyPolicy.Config + toDefaultTable := func(r config.DefaultPolicyType) table.RouteType { + var def table.RouteType + switch r { + case config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE: + def = table.ROUTE_TYPE_ACCEPT + case config.DEFAULT_POLICY_TYPE_REJECT_ROUTE: + def = table.ROUTE_TYPE_REJECT + } + return def + } + toPolicyDefinitions := func(r []string) []*config.PolicyDefinition { + p := make([]*config.PolicyDefinition, 0, len(r)) + for _, n := range r { + p = append(p, &config.PolicyDefinition{ + Name: n, + }) + } + return p + } + + def := toDefaultTable(a.DefaultImportPolicy) + ps := toPolicyDefinitions(a.ImportPolicyList) + bgpServer.ReplacePolicyAssignment("", table.POLICY_DIRECTION_IMPORT, ps, def) + + def = toDefaultTable(a.DefaultExportPolicy) + ps = toPolicyDefinitions(a.ExportPolicyList) + bgpServer.ReplacePolicyAssignment("", table.POLICY_DIRECTION_EXPORT, ps, def) + + updatePolicy = true + + } c = newConfig } |