diff options
-rw-r--r-- | api/policy.go | 79 | ||||
-rw-r--r-- | client/client.go | 141 | ||||
-rw-r--r-- | gobgp/cmd/neighbor.go | 3 | ||||
-rw-r--r-- | gobgp/cmd/policy.go | 439 |
4 files changed, 352 insertions, 310 deletions
diff --git a/api/policy.go b/api/policy.go new file mode 100644 index 00000000..7296f012 --- /dev/null +++ b/api/policy.go @@ -0,0 +1,79 @@ +// Copyright (C) 2018 Nippon Telegraph and Telephone Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gobgpapi + +import ( + "fmt" + "regexp" + "strconv" + "strings" + + "github.com/osrg/gobgp/packet/bgp" +) + +var ( + repexpCommunity = regexp.MustCompile("(\\d+.)*\\d+:\\d+") + regexpLargeCommunity = regexp.MustCompile("\\d+:\\d+:\\d+") +) + +func ParseCommunityRegexp(arg string) (*regexp.Regexp, error) { + i, err := strconv.ParseUint(arg, 10, 32) + if err == nil { + return regexp.Compile(fmt.Sprintf("^%d:%d$", i>>16, i&0x0000ffff)) + } + if repexpCommunity.MatchString(arg) { + return regexp.Compile(fmt.Sprintf("^%s$", arg)) + } + for i, v := range bgp.WellKnownCommunityNameMap { + if strings.Replace(strings.ToLower(arg), "_", "-", -1) == v { + return regexp.Compile(fmt.Sprintf("^%d:%d$", i>>16, i&0x0000ffff)) + } + } + exp, err := regexp.Compile(arg) + if err != nil { + return nil, fmt.Errorf("invalid community format: %s", arg) + } + return exp, nil +} + +func ParseExtCommunityRegexp(arg string) (bgp.ExtendedCommunityAttrSubType, *regexp.Regexp, error) { + var subtype bgp.ExtendedCommunityAttrSubType + elems := strings.SplitN(arg, ":", 2) + if len(elems) < 2 { + return subtype, nil, fmt.Errorf("invalid ext-community format([rt|soo]:<value>)") + } + switch strings.ToLower(elems[0]) { + case "rt": + subtype = bgp.EC_SUBTYPE_ROUTE_TARGET + case "soo": + subtype = bgp.EC_SUBTYPE_ROUTE_ORIGIN + default: + return subtype, nil, fmt.Errorf("unknown ext-community subtype. rt, soo is supported") + } + exp, err := ParseCommunityRegexp(elems[1]) + return subtype, exp, err +} + +func ParseLargeCommunityRegexp(arg string) (*regexp.Regexp, error) { + if regexpLargeCommunity.MatchString(arg) { + return regexp.Compile(fmt.Sprintf("^%s$", arg)) + } + exp, err := regexp.Compile(arg) + if err != nil { + return nil, fmt.Errorf("invalid large-community format: %s", arg) + } + return exp, nil +} diff --git a/client/client.go b/client/client.go index 60fbee1c..3e1cd235 100644 --- a/client/client.go +++ b/client/client.go @@ -29,7 +29,6 @@ import ( api "github.com/osrg/gobgp/api" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" - "github.com/osrg/gobgp/table" ) type Client struct { @@ -474,7 +473,7 @@ func (cli *Client) DeleteVRF(name string) error { return err } -func (cli *Client) getDefinedSet(typ table.DefinedType, name string) ([]table.DefinedSet, error) { +func (cli *Client) getDefinedSet(typ api.DefinedType, name string) ([]*api.DefinedSet, error) { ret, err := cli.cli.GetDefinedSet(context.Background(), &api.GetDefinedSetRequest{ Type: api.DefinedType(typ), Name: name, @@ -482,22 +481,14 @@ func (cli *Client) getDefinedSet(typ table.DefinedType, name string) ([]table.De if err != nil { return nil, err } - ds := make([]table.DefinedSet, 0, len(ret.Sets)) - for _, s := range ret.Sets { - d, err := api.NewDefinedSetFromApiStruct(s) - if err != nil { - return nil, err - } - ds = append(ds, d) - } - return ds, nil + return ret.Sets, nil } -func (cli *Client) GetDefinedSet(typ table.DefinedType) ([]table.DefinedSet, error) { +func (cli *Client) GetDefinedSet(typ api.DefinedType) ([]*api.DefinedSet, error) { return cli.getDefinedSet(typ, "") } -func (cli *Client) GetDefinedSetByName(typ table.DefinedType, name string) (table.DefinedSet, error) { +func (cli *Client) GetDefinedSetByName(typ api.DefinedType, name string) (*api.DefinedSet, error) { sets, err := cli.getDefinedSet(typ, name) if err != nil { return nil, err @@ -510,99 +501,67 @@ func (cli *Client) GetDefinedSetByName(typ table.DefinedType, name string) (tabl return sets[0], nil } -func (cli *Client) AddDefinedSet(d table.DefinedSet) error { - a, err := api.NewAPIDefinedSetFromTableStruct(d) - if err != nil { - return err - } - _, err = cli.cli.AddDefinedSet(context.Background(), &api.AddDefinedSetRequest{ - Set: a, +func (cli *Client) AddDefinedSet(d *api.DefinedSet) error { + _, err := cli.cli.AddDefinedSet(context.Background(), &api.AddDefinedSetRequest{ + Set: d, }) return err } -func (cli *Client) DeleteDefinedSet(d table.DefinedSet, all bool) error { - a, err := api.NewAPIDefinedSetFromTableStruct(d) - if err != nil { - return err - } - _, err = cli.cli.DeleteDefinedSet(context.Background(), &api.DeleteDefinedSetRequest{ - Set: a, +func (cli *Client) DeleteDefinedSet(d *api.DefinedSet, all bool) error { + _, err := cli.cli.DeleteDefinedSet(context.Background(), &api.DeleteDefinedSetRequest{ + Set: d, All: all, }) return err } -func (cli *Client) ReplaceDefinedSet(d table.DefinedSet) error { - a, err := api.NewAPIDefinedSetFromTableStruct(d) - if err != nil { - return err - } - _, err = cli.cli.ReplaceDefinedSet(context.Background(), &api.ReplaceDefinedSetRequest{ - Set: a, +func (cli *Client) ReplaceDefinedSet(d *api.DefinedSet) error { + _, err := cli.cli.ReplaceDefinedSet(context.Background(), &api.ReplaceDefinedSetRequest{ + Set: d, }) return err } -func (cli *Client) GetStatement() ([]*table.Statement, error) { +func (cli *Client) GetStatement() ([]*api.Statement, error) { ret, err := cli.cli.GetStatement(context.Background(), &api.GetStatementRequest{}) if err != nil { return nil, err } - sts := make([]*table.Statement, 0, len(ret.Statements)) - for _, s := range ret.Statements { - st, err := api.NewStatementFromApiStruct(s) - if err != nil { - return nil, err - } - sts = append(sts, st) - } - return sts, nil + return ret.Statements, nil } -func (cli *Client) AddStatement(t *table.Statement) error { - a := api.NewAPIStatementFromTableStruct(t) +func (cli *Client) AddStatement(t *api.Statement) error { _, err := cli.cli.AddStatement(context.Background(), &api.AddStatementRequest{ - Statement: a, + Statement: t, }) return err } -func (cli *Client) DeleteStatement(t *table.Statement, all bool) error { - a := api.NewAPIStatementFromTableStruct(t) +func (cli *Client) DeleteStatement(t *api.Statement, all bool) error { _, err := cli.cli.DeleteStatement(context.Background(), &api.DeleteStatementRequest{ - Statement: a, + Statement: t, All: all, }) return err } -func (cli *Client) ReplaceStatement(t *table.Statement) error { - a := api.NewAPIStatementFromTableStruct(t) +func (cli *Client) ReplaceStatement(t *api.Statement) error { _, err := cli.cli.ReplaceStatement(context.Background(), &api.ReplaceStatementRequest{ - Statement: a, + Statement: t, }) return err } -func (cli *Client) GetPolicy() ([]*table.Policy, error) { +func (cli *Client) GetPolicy() ([]*api.Policy, error) { ret, err := cli.cli.GetPolicy(context.Background(), &api.GetPolicyRequest{}) if err != nil { return nil, err } - pols := make([]*table.Policy, 0, len(ret.Policies)) - for _, p := range ret.Policies { - pol, err := api.NewPolicyFromApiStruct(p) - if err != nil { - return nil, err - } - pols = append(pols, pol) - } - return pols, nil + return ret.Policies, nil } -func (cli *Client) AddPolicy(t *table.Policy, refer bool) error { - a := api.NewAPIPolicyFromTableStruct(t) +func (cli *Client) AddPolicy(a *api.Policy, refer bool) error { _, err := cli.cli.AddPolicy(context.Background(), &api.AddPolicyRequest{ Policy: a, ReferExistingStatements: refer, @@ -610,8 +569,7 @@ func (cli *Client) AddPolicy(t *table.Policy, refer bool) error { return err } -func (cli *Client) DeletePolicy(t *table.Policy, all, preserve bool) error { - a := api.NewAPIPolicyFromTableStruct(t) +func (cli *Client) DeletePolicy(a *api.Policy, all, preserve bool) error { _, err := cli.cli.DeletePolicy(context.Background(), &api.DeletePolicyRequest{ Policy: a, All: all, @@ -620,8 +578,7 @@ func (cli *Client) DeletePolicy(t *table.Policy, all, preserve bool) error { return err } -func (cli *Client) ReplacePolicy(t *table.Policy, refer, preserve bool) error { - a := api.NewAPIPolicyFromTableStruct(t) +func (cli *Client) ReplacePolicy(a *api.Policy, refer, preserve bool) error { _, err := cli.cli.ReplacePolicy(context.Background(), &api.ReplacePolicyRequest{ Policy: a, ReferExistingStatements: refer, @@ -630,14 +587,7 @@ func (cli *Client) ReplacePolicy(t *table.Policy, refer, preserve bool) error { return err } -func (cli *Client) getPolicyAssignment(name string, dir table.PolicyDirection) (*table.PolicyAssignment, error) { - var typ api.PolicyType - switch dir { - case table.POLICY_DIRECTION_IMPORT: - typ = api.PolicyType_IMPORT - case table.POLICY_DIRECTION_EXPORT: - typ = api.PolicyType_EXPORT - } +func (cli *Client) getPolicyAssignment(name string, typ api.PolicyType) (*api.PolicyAssignment, error) { resource := api.Resource_GLOBAL if name != "" { resource = api.Resource_LOCAL @@ -654,41 +604,28 @@ func (cli *Client) getPolicyAssignment(name string, dir table.PolicyDirection) ( return nil, err } - def := table.ROUTE_TYPE_ACCEPT - if ret.Assignment.Default == api.RouteAction_REJECT { - def = table.ROUTE_TYPE_REJECT - } - - pols := make([]*table.Policy, 0, len(ret.Assignment.Policies)) - for _, p := range ret.Assignment.Policies { - pol, err := api.NewPolicyFromApiStruct(p) - if err != nil { - return nil, err - } - pols = append(pols, pol) - } - return &table.PolicyAssignment{ + return &api.PolicyAssignment{ Name: name, - Type: dir, - Policies: pols, - Default: def, + Type: typ, + Policies: ret.Assignment.Policies, + Default: ret.Assignment.Default, }, nil } -func (cli *Client) GetImportPolicy() (*table.PolicyAssignment, error) { - return cli.getPolicyAssignment("", table.POLICY_DIRECTION_IMPORT) +func (cli *Client) GetImportPolicy() (*api.PolicyAssignment, error) { + return cli.getPolicyAssignment("", api.PolicyType_IMPORT) } -func (cli *Client) GetExportPolicy() (*table.PolicyAssignment, error) { - return cli.getPolicyAssignment("", table.POLICY_DIRECTION_EXPORT) +func (cli *Client) GetExportPolicy() (*api.PolicyAssignment, error) { + return cli.getPolicyAssignment("", api.PolicyType_EXPORT) } -func (cli *Client) GetRouteServerImportPolicy(name string) (*table.PolicyAssignment, error) { - return cli.getPolicyAssignment(name, table.POLICY_DIRECTION_IMPORT) +func (cli *Client) GetRouteServerImportPolicy(name string) (*api.PolicyAssignment, error) { + return cli.getPolicyAssignment(name, api.PolicyType_IMPORT) } -func (cli *Client) GetRouteServerExportPolicy(name string) (*table.PolicyAssignment, error) { - return cli.getPolicyAssignment(name, table.POLICY_DIRECTION_EXPORT) +func (cli *Client) GetRouteServerExportPolicy(name string) (*api.PolicyAssignment, error) { + return cli.getPolicyAssignment(name, api.PolicyType_EXPORT) } func (cli *Client) AddPolicyAssignment(assignment *api.PolicyAssignment) error { diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go index cd513744..c0642c26 100644 --- a/gobgp/cmd/neighbor.go +++ b/gobgp/cmd/neighbor.go @@ -29,7 +29,6 @@ import ( "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" - "github.com/osrg/gobgp/table" api "github.com/osrg/gobgp/api" ) @@ -918,7 +917,7 @@ func stateChangeNeighbor(cmd string, remoteIP string, args []string) error { } func showNeighborPolicy(remoteIP, policyType string, indent int) error { - var assignment *table.PolicyAssignment + var assignment *api.PolicyAssignment var err error switch strings.ToLower(policyType) { diff --git a/gobgp/cmd/policy.go b/gobgp/cmd/policy.go index 7e9c08b2..84da805c 100644 --- a/gobgp/cmd/policy.go +++ b/gobgp/cmd/policy.go @@ -21,19 +21,19 @@ import ( "fmt" "net" "regexp" - "sort" "strconv" "strings" "github.com/spf13/cobra" + api "github.com/osrg/gobgp/api" "github.com/osrg/gobgp/config" - "github.com/osrg/gobgp/table" + "github.com/osrg/gobgp/packet/bgp" ) var _regexpCommunity = regexp.MustCompile(`\^\^(\S+)\$\$`) -func formatDefinedSet(head bool, typ string, indent int, list []table.DefinedSet) string { +func formatDefinedSet(head bool, typ string, indent int, list []*api.DefinedSet) string { if len(list) == 0 { return "Nothing defined yet\n" } @@ -41,8 +41,8 @@ func formatDefinedSet(head bool, typ string, indent int, list []table.DefinedSet sIndent := strings.Repeat(" ", indent) maxNameLen := 0 for _, s := range list { - if len(s.Name()) > maxNameLen { - maxNameLen = len(s.Name()) + if len(s.GetName()) > maxNameLen { + maxNameLen = len(s.GetName()) } } if head { @@ -55,16 +55,16 @@ func formatDefinedSet(head bool, typ string, indent int, list []table.DefinedSet buff.WriteString(fmt.Sprintf(format, "NAME", typ)) } for _, s := range list { - l := s.List() + l := s.GetList() if len(l) == 0 { - buff.WriteString(fmt.Sprintf(format, s.Name(), "")) + buff.WriteString(fmt.Sprintf(format, s.GetName(), "")) } for i, x := range l { if typ == "COMMUNITY" || typ == "EXT-COMMUNITY" || typ == "LARGE-COMMUNITY" { x = _regexpCommunity.ReplaceAllString(x, "$1") } if i == 0 { - buff.WriteString(fmt.Sprintf(format, s.Name(), x)) + buff.WriteString(fmt.Sprintf(format, s.GetName(), x)) } else { buff.WriteString(fmt.Sprint(sIndent)) buff.WriteString(fmt.Sprintf(format, "", x)) @@ -75,30 +75,30 @@ func formatDefinedSet(head bool, typ string, indent int, list []table.DefinedSet } func showDefinedSet(v string, args []string) error { - var typ table.DefinedType + var typ api.DefinedType switch v { case CMD_PREFIX: - typ = table.DEFINED_TYPE_PREFIX + typ = api.DefinedType_PREFIX case CMD_NEIGHBOR: - typ = table.DEFINED_TYPE_NEIGHBOR + typ = api.DefinedType_NEIGHBOR case CMD_ASPATH: - typ = table.DEFINED_TYPE_AS_PATH + typ = api.DefinedType_AS_PATH case CMD_COMMUNITY: - typ = table.DEFINED_TYPE_COMMUNITY + typ = api.DefinedType_COMMUNITY case CMD_EXTCOMMUNITY: - typ = table.DEFINED_TYPE_EXT_COMMUNITY + typ = api.DefinedType_EXT_COMMUNITY case CMD_LARGECOMMUNITY: - typ = table.DEFINED_TYPE_LARGE_COMMUNITY + typ = api.DefinedType_LARGE_COMMUNITY default: return fmt.Errorf("unknown defined type: %s", v) } - var m table.DefinedSetList + var m []*api.DefinedSet if len(args) > 0 { d, err := client.GetDefinedSetByName(typ, args[0]) if err != nil { return err } - m = table.DefinedSetList([]table.DefinedSet{d}) + m = []*api.DefinedSet{d} } else { var err error m, err = client.GetDefinedSet(typ) @@ -116,12 +116,11 @@ func showDefinedSet(v string, args []string) error { fmt.Println(m) } else { for _, p := range m { - fmt.Println(p.Name()) + fmt.Println(p.GetName()) } } return nil } - sort.Sort(m) var output string switch v { case CMD_PREFIX: @@ -141,13 +140,13 @@ func showDefinedSet(v string, args []string) error { return nil } -func parsePrefixSet(args []string) (table.DefinedSet, error) { +func parsePrefixSet(args []string) (*api.DefinedSet, error) { if len(args) < 1 { return nil, fmt.Errorf("empty neighbor set name") } name := args[0] args = args[1:] - var list []config.Prefix + var list []*api.Prefix if len(args) > 0 { mask := "" if len(args) > 1 { @@ -157,40 +156,48 @@ func parsePrefixSet(args []string) (table.DefinedSet, error) { if err != nil { return nil, err } - prefix := config.Prefix{ - IpPrefix: args[0], - MasklengthRange: fmt.Sprintf("%d..%d", min, max), + prefix := &api.Prefix{ + IpPrefix: args[0], + MaskLengthMax: uint32(max), + MaskLengthMin: uint32(min), } - list = []config.Prefix{prefix} + list = []*api.Prefix{prefix} } - return table.NewPrefixSet(config.PrefixSet{ - PrefixSetName: name, - PrefixList: list, - }) + return &api.DefinedSet{ + Type: api.DefinedType_PREFIX, + Name: name, + Prefixes: list, + }, nil } -func parseNeighborSet(args []string) (table.DefinedSet, error) { +func parseNeighborSet(args []string) (*api.DefinedSet, error) { if len(args) < 1 { return nil, fmt.Errorf("empty neighbor set name") } name := args[0] args = args[1:] + list := make([]string, 0, len(args[1:])) for _, arg := range args { address := net.ParseIP(arg) - if address.To4() == nil && address.To16() == nil { + if address.To4() != nil { + list = append(list, fmt.Sprintf("%s/32", arg)) + } else if address.To16() != nil { + list = append(list, fmt.Sprintf("%s/128", arg)) + } else { _, _, err := net.ParseCIDR(arg) if err != nil { return nil, fmt.Errorf("invalid address or prefix: %s\nplease enter ipv4 or ipv6 format", arg) } } } - return table.NewNeighborSet(config.NeighborSet{ - NeighborSetName: name, - NeighborInfoList: args, - }) + return &api.DefinedSet{ + Type: api.DefinedType_NEIGHBOR, + Name: name, + List: list, + }, nil } -func parseAsPathSet(args []string) (table.DefinedSet, error) { +func parseAsPathSet(args []string) (*api.DefinedSet, error) { if len(args) < 1 { return nil, fmt.Errorf("empty as-path set name") } @@ -202,64 +209,72 @@ func parseAsPathSet(args []string) (table.DefinedSet, error) { return nil, err } } - return table.NewAsPathSet(config.AsPathSet{ - AsPathSetName: name, - AsPathList: args, - }) + return &api.DefinedSet{ + Type: api.DefinedType_AS_PATH, + Name: name, + List: args, + }, nil } -func parseCommunitySet(args []string) (table.DefinedSet, error) { +func parseCommunitySet(args []string) (*api.DefinedSet, error) { if len(args) < 1 { return nil, fmt.Errorf("empty community set name") } name := args[0] args = args[1:] for _, arg := range args { - if _, err := table.ParseCommunityRegexp(arg); err != nil { + if _, err := api.ParseCommunityRegexp(arg); err != nil { return nil, err } } - return table.NewCommunitySet(config.CommunitySet{ - CommunitySetName: name, - CommunityList: args, - }) + return &api.DefinedSet{ + Type: api.DefinedType_COMMUNITY, + Name: name, + List: args, + }, nil } -func parseExtCommunitySet(args []string) (table.DefinedSet, error) { +func parseExtCommunitySet(args []string) (*api.DefinedSet, error) { if len(args) < 1 { return nil, fmt.Errorf("empty ext-community set name") } name := args[0] args = args[1:] for _, arg := range args { - if _, _, err := table.ParseExtCommunityRegexp(arg); err != nil { + if _, _, err := api.ParseExtCommunityRegexp(arg); err != nil { return nil, err } } - return table.NewExtCommunitySet(config.ExtCommunitySet{ - ExtCommunitySetName: name, - ExtCommunityList: args, - }) + return &api.DefinedSet{ + Type: api.DefinedType_EXT_COMMUNITY, + Name: name, + List: args, + }, nil } -func parseLargeCommunitySet(args []string) (table.DefinedSet, error) { +func parseLargeCommunitySet(args []string) (*api.DefinedSet, error) { if len(args) < 1 { return nil, fmt.Errorf("empty large-community set name") } name := args[0] args = args[1:] for _, arg := range args { - if _, err := table.ParseLargeCommunityRegexp(arg); err != nil { + if _, err := api.ParseLargeCommunityRegexp(arg); err != nil { return nil, err } } - return table.NewLargeCommunitySet(config.LargeCommunitySet{ - LargeCommunitySetName: name, - LargeCommunityList: args, - }) + return &api.DefinedSet{ + Type: api.DefinedType_LARGE_COMMUNITY, + Name: name, + List: args, + }, nil } -func parseDefinedSet(settype string, args []string) (table.DefinedSet, error) { +func parseDefinedSet(settype string, args []string) (*api.DefinedSet, error) { + if len(args) < 1 { + return nil, fmt.Errorf("empty large-community set name") + } + switch settype { case CMD_PREFIX: return parsePrefixSet(args) @@ -288,7 +303,7 @@ var modPolicyUsageFormat = map[string]string{ } func modDefinedSet(settype string, modtype string, args []string) error { - var d table.DefinedSet + var d *api.DefinedSet var err error if len(args) < 1 { return fmt.Errorf(modPolicyUsageFormat[settype], modtype) @@ -311,7 +326,7 @@ func modDefinedSet(settype string, modtype string, args []string) error { return err } -func printStatement(indent int, s *table.Statement) { +func printStatement(indent int, s *api.Statement) { sIndent := func(indent int) string { return strings.Repeat(" ", indent) } @@ -320,67 +335,71 @@ func printStatement(indent int, s *table.Statement) { ind := sIndent(indent + 4) - for _, c := range s.Conditions { - switch t := c.(type) { - case *table.PrefixCondition: - fmt.Printf("%sPrefixSet: %s %s\n", ind, t.Option(), t.Name()) - case *table.NeighborCondition: - fmt.Printf("%sNeighborSet: %s %s\n", ind, t.Option(), t.Name()) - case *table.AsPathCondition: - fmt.Printf("%sAsPathSet: %s %s\n", ind, t.Option(), t.Name()) - case *table.CommunityCondition: - fmt.Printf("%sCommunitySet: %s %s\n", ind, t.Option(), t.Name()) - case *table.ExtCommunityCondition: - fmt.Printf("%sExtCommunitySet: %s %s\n", ind, t.Option(), t.Name()) - case *table.LargeCommunityCondition: - fmt.Printf("%sLargeCommunitySet: %s %s\n", ind, t.Option(), t.Name()) - case *table.NextHopCondition: - fmt.Printf("%sNextHopInList: %s\n", ind, t.String()) - case *table.AsPathLengthCondition: - fmt.Printf("%sAsPathLength: %s\n", ind, t.String()) - case *table.RpkiValidationCondition: - fmt.Printf("%sRPKI result: %s\n", ind, t.String()) - case *table.RouteTypeCondition: - fmt.Printf("%sRoute Type: %s\n", ind, t.String()) - case *table.AfiSafiInCondition: - fmt.Printf("%sAFI SAFI In: %s\n", ind, t.String()) - } + c := s.Conditions + if c.PrefixSet != nil { + fmt.Printf("%sPrefixSet: %s %s\n", ind, c.PrefixSet.GetType(), c.PrefixSet.GetName()) + } else if c.NeighborSet != nil { + fmt.Printf("%sNeighborSet: %s %s\n", ind, c.NeighborSet.GetType(), c.NeighborSet.GetName()) + } else if c.AsPathSet != nil { + fmt.Printf("%sAsPathSet: %s %s\n", ind, c.AsPathSet.GetType(), c.AsPathSet.GetName()) + } else if c.CommunitySet != nil { + fmt.Printf("%sCommunitySet: %s %s\n", ind, c.CommunitySet.GetType(), c.CommunitySet.GetName()) + } else if c.ExtCommunitySet != nil { + fmt.Printf("%sExtCommunitySet: %s %s\n", ind, c.ExtCommunitySet.GetType(), c.ExtCommunitySet.GetName()) + } else if c.LargeCommunitySet != nil { + fmt.Printf("%sLargeCommunitySet: %s %s\n", ind, c.LargeCommunitySet.GetType(), c.LargeCommunitySet.GetName()) + } else if c.NextHopInList != nil { + fmt.Printf("%sNextHopInList: %s\n", ind, "[ "+strings.Join(c.NextHopInList, ", ")+" ]") + } else if c.AsPathLength != nil { + fmt.Printf("%sAsPathLength: %s\n", ind, fmt.Sprintf("%s%d", c.AsPathLength.Type, c.AsPathLength.Length)) + } else if c.RpkiResult != -1 { + fmt.Println(c.RpkiResult) + var result string + switch c.RpkiResult { + case 0: + result = "none" + case 1: + result = "valid" + case 2: + result = "invalid" + case 3: + result = "not-found" + } + fmt.Printf("%sRPKI result: %s\n", ind, result) + } else if c.RouteType != api.Conditions_ROUTE_TYPE_NONE { + fmt.Printf("%sRoute Type: %s\n", ind, c.RouteType.String()) + } else if c.AfiSafiIn != nil { + fmt.Printf("%sAFI SAFI In: %s\n", ind, c.AfiSafiIn) } fmt.Printf("%sActions:\n", sIndent(indent+2)) - for _, a := range s.ModActions { - switch t := a.(type) { - case *table.RoutingAction: - action := "accept" - if !t.AcceptRoute { - action = "reject" - } - fmt.Println(ind, action) - case *table.CommunityAction: - fmt.Println(ind, "Community: ", t.String()) - case *table.ExtCommunityAction: - fmt.Println(ind, "ExtCommunity: ", t.String()) - case *table.LargeCommunityAction: - fmt.Println(ind, "LargeCommunity: ", t.String()) - case *table.MedAction: - fmt.Println(ind, "MED: ", t.String()) - case *table.LocalPrefAction: - fmt.Println(ind, "LocalPref: ", t.String()) - case *table.AsPathPrependAction: - fmt.Println(ind, "ASPathPrepend: ", t.String()) - case *table.NexthopAction: - fmt.Println(ind, "Nexthop: ", t.String()) - } - } - - if s.RouteAction != nil && s.RouteAction.(*table.RoutingAction) != nil { - t := s.RouteAction.(*table.RoutingAction) - fmt.Println(ind, t.String()) + a := s.Actions + if a.Community != nil { + fmt.Println(ind, "Community: ", a.Community.String()) + } else if a.ExtCommunity != nil { + fmt.Println(ind, "ExtCommunity: ", a.ExtCommunity.String()) + } else if a.LargeCommunity != nil { + fmt.Println(ind, "LargeCommunity: ", a.LargeCommunity.String()) + } else if a.Med != nil { + fmt.Println(ind, "MED: ", a.Med.String()) + } else if a.LocalPref != nil { + fmt.Println(ind, "LocalPref: ", a.LocalPref.String()) + } else if a.AsPrepend != nil { + fmt.Println(ind, "ASPathPrepend: ", a.AsPrepend.String()) + } else if a.Nexthop != nil { + fmt.Println(ind, "Nexthop: ", a.Nexthop.String()) + } + + if a.RouteAction != api.RouteAction_NONE { + action := "accept" + if a.RouteAction == api.RouteAction_REJECT { + action = "reject" + } + fmt.Println(ind, action) } - } -func printPolicy(indent int, pd *table.Policy) { +func printPolicy(indent int, pd *api.Policy) { for _, s := range pd.Statements { printStatement(indent, s) } @@ -391,7 +410,7 @@ func showPolicy(args []string) error { if err != nil { return err } - var m table.Policies + var m []*api.Policy if len(args) > 0 { for _, p := range policies { if args[0] == p.Name { @@ -416,7 +435,7 @@ func showPolicy(args []string) error { } return nil } - sort.Sort(m) + for _, pd := range m { fmt.Printf("Name %s:\n", pd.Name) printPolicy(4, pd) @@ -429,7 +448,7 @@ func showStatement(args []string) error { if err != nil { return err } - var m []*table.Statement + var m []*api.Statement if len(args) > 0 { for _, s := range stmts { if args[0] == s.Name { @@ -464,7 +483,7 @@ func modStatement(op string, args []string) error { if len(args) < 1 { return fmt.Errorf("usage: gobgp policy statement %s <name>", op) } - stmt := &table.Statement{ + stmt := &api.Statement{ Name: args[0], } var err error @@ -480,8 +499,9 @@ func modStatement(op string, args []string) error { } func modCondition(name, op string, args []string) error { - stmt := config.Statement{ - Name: name, + stmt := &api.Statement{ + Name: name, + Conditions: &api.Conditions{}, } usage := fmt.Sprintf("usage: gobgp policy statement %s %s condition", name, op) if len(args) < 1 { @@ -491,110 +511,117 @@ func modCondition(name, op string, args []string) error { args = args[1:] switch typ { case "prefix": + stmt.Conditions.PrefixSet = &api.MatchSet{} if len(args) < 1 { return fmt.Errorf("%s prefix <set-name> [{ any | invert }]", usage) } - stmt.Conditions.MatchPrefixSet.PrefixSet = args[0] + stmt.Conditions.PrefixSet.Name = args[0] if len(args) == 1 { break } switch strings.ToLower(args[1]) { case "any": - stmt.Conditions.MatchPrefixSet.MatchSetOptions = config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY + stmt.Conditions.PrefixSet.Type = api.MatchType_ANY case "invert": - stmt.Conditions.MatchPrefixSet.MatchSetOptions = config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT + stmt.Conditions.PrefixSet.Type = api.MatchType_INVERT default: return fmt.Errorf("%s prefix <set-name> [{ any | invert }]", usage) } case "neighbor": + stmt.Conditions.NeighborSet = &api.MatchSet{} if len(args) < 1 { return fmt.Errorf("%s neighbor <set-name> [{ any | invert }]", usage) } - stmt.Conditions.MatchNeighborSet.NeighborSet = args[0] + stmt.Conditions.NeighborSet.Name = args[0] if len(args) == 1 { break } switch strings.ToLower(args[1]) { case "any": - stmt.Conditions.MatchNeighborSet.MatchSetOptions = config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY + stmt.Conditions.NeighborSet.Type = api.MatchType_ANY case "invert": - stmt.Conditions.MatchNeighborSet.MatchSetOptions = config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT + stmt.Conditions.NeighborSet.Type = api.MatchType_INVERT default: return fmt.Errorf("%s neighbor <set-name> [{ any | invert }]", usage) } case "as-path": + stmt.Conditions.AsPathSet = &api.MatchSet{} if len(args) < 1 { return fmt.Errorf("%s as-path <set-name> [{ any | all | invert }]", usage) } - stmt.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = args[0] + stmt.Conditions.AsPathSet.Name = args[0] if len(args) == 1 { break } switch strings.ToLower(args[1]) { case "any": - stmt.Conditions.BgpConditions.MatchAsPathSet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_ANY + stmt.Conditions.AsPathSet.Type = api.MatchType_ANY case "all": - stmt.Conditions.BgpConditions.MatchAsPathSet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_ALL + stmt.Conditions.AsPathSet.Type = api.MatchType_ALL case "invert": - stmt.Conditions.BgpConditions.MatchAsPathSet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_INVERT + stmt.Conditions.AsPathSet.Type = api.MatchType_INVERT default: return fmt.Errorf("%s as-path <set-name> [{ any | all | invert }]", usage) } case "community": + stmt.Conditions.CommunitySet = &api.MatchSet{} if len(args) < 1 { return fmt.Errorf("%s community <set-name> [{ any | all | invert }]", usage) } - stmt.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = args[0] + stmt.Conditions.CommunitySet.Name = args[0] if len(args) == 1 { break } switch strings.ToLower(args[1]) { case "any": - stmt.Conditions.BgpConditions.MatchCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_ANY + stmt.Conditions.CommunitySet.Type = api.MatchType_ANY case "all": - stmt.Conditions.BgpConditions.MatchCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_ALL + stmt.Conditions.CommunitySet.Type = api.MatchType_ALL case "invert": - stmt.Conditions.BgpConditions.MatchCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_INVERT + stmt.Conditions.CommunitySet.Type = api.MatchType_INVERT default: return fmt.Errorf("%s community <set-name> [{ any | all | invert }]", usage) } case "ext-community": + stmt.Conditions.ExtCommunitySet = &api.MatchSet{} if len(args) < 1 { return fmt.Errorf("%s ext-community <set-name> [{ any | all | invert }]", usage) } - stmt.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet = args[0] + stmt.Conditions.ExtCommunitySet.Name = args[0] if len(args) == 1 { break } switch strings.ToLower(args[1]) { case "any": - stmt.Conditions.BgpConditions.MatchExtCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_ANY + stmt.Conditions.ExtCommunitySet.Type = api.MatchType_ANY case "all": - stmt.Conditions.BgpConditions.MatchExtCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_ALL + stmt.Conditions.ExtCommunitySet.Type = api.MatchType_ALL case "invert": - stmt.Conditions.BgpConditions.MatchExtCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_INVERT + stmt.Conditions.ExtCommunitySet.Type = api.MatchType_INVERT default: return fmt.Errorf("%s ext-community <set-name> [{ any | all | invert }]", usage) } case "large-community": + stmt.Conditions.LargeCommunitySet = &api.MatchSet{} if len(args) < 1 { return fmt.Errorf("%s large-community <set-name> [{ any | all | invert }]", usage) } - stmt.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCommunitySet = args[0] + stmt.Conditions.LargeCommunitySet.Name = args[0] if len(args) == 1 { break } switch strings.ToLower(args[1]) { case "any": - stmt.Conditions.BgpConditions.MatchLargeCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_ANY + stmt.Conditions.LargeCommunitySet.Type = api.MatchType_ANY case "all": - stmt.Conditions.BgpConditions.MatchLargeCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_ALL + stmt.Conditions.LargeCommunitySet.Type = api.MatchType_ALL case "invert": - stmt.Conditions.BgpConditions.MatchLargeCommunitySet.MatchSetOptions = config.MATCH_SET_OPTIONS_TYPE_INVERT + stmt.Conditions.LargeCommunitySet.Type = api.MatchType_INVERT default: return fmt.Errorf("%s large-community <set-name> [{ any | all | invert }]", usage) } case "as-path-length": + stmt.Conditions.AsPathLength = &api.AsPathLength{} if len(args) < 2 { return fmt.Errorf("%s as-path-length <length> { eq | ge | le }", usage) } @@ -602,14 +629,14 @@ func modCondition(name, op string, args []string) error { if err != nil { return err } - stmt.Conditions.BgpConditions.AsPathLength.Value = uint32(length) + stmt.Conditions.AsPathLength.Length = uint32(length) switch strings.ToLower(args[1]) { case "eq": - stmt.Conditions.BgpConditions.AsPathLength.Operator = config.ATTRIBUTE_COMPARISON_EQ + stmt.Conditions.AsPathLength.Type = api.AsPathLengthType_EQ case "ge": - stmt.Conditions.BgpConditions.AsPathLength.Operator = config.ATTRIBUTE_COMPARISON_GE + stmt.Conditions.AsPathLength.Type = api.AsPathLengthType_GE case "le": - stmt.Conditions.BgpConditions.AsPathLength.Operator = config.ATTRIBUTE_COMPARISON_LE + stmt.Conditions.AsPathLength.Type = api.AsPathLengthType_LE default: return fmt.Errorf("%s as-path-length <length> { eq | ge | le }", usage) } @@ -619,11 +646,11 @@ func modCondition(name, op string, args []string) error { } switch strings.ToLower(args[0]) { case "valid": - stmt.Conditions.BgpConditions.RpkiValidationResult = config.RPKI_VALIDATION_RESULT_TYPE_VALID + stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_VALID]) case "invalid": - stmt.Conditions.BgpConditions.RpkiValidationResult = config.RPKI_VALIDATION_RESULT_TYPE_INVALID + stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_INVALID]) case "not-found": - stmt.Conditions.BgpConditions.RpkiValidationResult = config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND + stmt.Conditions.RpkiResult = int32(config.RpkiValidationResultTypeToIntMap[config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND]) default: return fmt.Errorf("%s rpki { valid | invalid | not-found }", usage) } @@ -634,41 +661,34 @@ func modCondition(name, op string, args []string) error { } switch strings.ToLower(args[0]) { case "internal": - stmt.Conditions.BgpConditions.RouteType = config.ROUTE_TYPE_INTERNAL + stmt.Conditions.RouteType = api.Conditions_ROUTE_TYPE_INTERNAL case "external": - stmt.Conditions.BgpConditions.RouteType = config.ROUTE_TYPE_EXTERNAL + stmt.Conditions.RouteType = api.Conditions_ROUTE_TYPE_EXTERNAL case "local": - stmt.Conditions.BgpConditions.RouteType = config.ROUTE_TYPE_LOCAL + stmt.Conditions.RouteType = api.Conditions_ROUTE_TYPE_LOCAL default: return err } case "next-hop-in-list": - stmt.Conditions.BgpConditions.NextHopInList = args + stmt.Conditions.NextHopInList = args case "afi-safi-in": - afiSafisInList := make([]config.AfiSafiType, 0, len(args)) + afiSafisInList := make([]api.Family, 0, len(args)) for _, arg := range args { - afiSafi := config.AfiSafiType(arg) - if err := afiSafi.Validate(); err != nil { - return err - } - afiSafisInList = append(afiSafisInList, afiSafi) + afiSafisInList = append(afiSafisInList, api.Family(bgp.AddressFamilyValueMap[arg])) } - stmt.Conditions.BgpConditions.AfiSafiInList = afiSafisInList + stmt.Conditions.AfiSafiIn = afiSafisInList default: return fmt.Errorf("%s { prefix | neighbor | as-path | community | ext-community | large-community | as-path-length | rpki | route-type | next-hop-in-list | afi-safi-in }", usage) } - t, err := table.NewStatement(stmt) - if err != nil { - return err - } + var err error switch op { case CMD_ADD: - err = client.AddStatement(t) + err = client.AddStatement(stmt) case CMD_DEL: - err = client.DeleteStatement(t, false) + err = client.DeleteStatement(stmt, false) case CMD_SET: - err = client.ReplaceStatement(t) + err = client.ReplaceStatement(stmt) default: return fmt.Errorf("invalid operation: %s", op) } @@ -676,8 +696,9 @@ func modCondition(name, op string, args []string) error { } func modAction(name, op string, args []string) error { - stmt := config.Statement{ - Name: name, + stmt := &api.Statement{ + Name: name, + Actions: &api.Actions{}, } usage := fmt.Sprintf("usage: gobgp policy statement %s %s action", name, op) if len(args) < 1 { @@ -687,73 +708,80 @@ func modAction(name, op string, args []string) error { args = args[1:] switch typ { case "reject": - stmt.Actions.RouteDisposition = config.ROUTE_DISPOSITION_REJECT_ROUTE + stmt.Actions.RouteAction = api.RouteAction_REJECT case "accept": - stmt.Actions.RouteDisposition = config.ROUTE_DISPOSITION_ACCEPT_ROUTE + stmt.Actions.RouteAction = api.RouteAction_ACCEPT case "community": + stmt.Actions.Community = &api.CommunityAction{} if len(args) < 1 { return fmt.Errorf("%s community { add | remove | replace } <value>...", usage) } - stmt.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList = args[1:] + stmt.Actions.Community.Communities = args[1:] switch strings.ToLower(args[0]) { case "add": - stmt.Actions.BgpActions.SetCommunity.Options = string(config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD) + stmt.Actions.Community.Type = api.CommunityActionType_COMMUNITY_ADD case "remove": - stmt.Actions.BgpActions.SetCommunity.Options = string(config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE) + stmt.Actions.Community.Type = api.CommunityActionType_COMMUNITY_REMOVE case "replace": - stmt.Actions.BgpActions.SetCommunity.Options = string(config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE) + stmt.Actions.Community.Type = api.CommunityActionType_COMMUNITY_REPLACE default: return fmt.Errorf("%s community { add | remove | replace } <value>...", usage) } case "ext-community": + stmt.Actions.ExtCommunity = &api.CommunityAction{} if len(args) < 1 { return fmt.Errorf("%s ext-community { add | remove | replace } <value>...", usage) } - stmt.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.CommunitiesList = args[1:] + stmt.Actions.ExtCommunity.Communities = args[1:] switch strings.ToLower(args[0]) { case "add": - stmt.Actions.BgpActions.SetExtCommunity.Options = string(config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD) + stmt.Actions.ExtCommunity.Type = api.CommunityActionType_COMMUNITY_ADD case "remove": - stmt.Actions.BgpActions.SetExtCommunity.Options = string(config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE) + stmt.Actions.ExtCommunity.Type = api.CommunityActionType_COMMUNITY_REMOVE case "replace": - stmt.Actions.BgpActions.SetExtCommunity.Options = string(config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE) + stmt.Actions.ExtCommunity.Type = api.CommunityActionType_COMMUNITY_REPLACE default: return fmt.Errorf("%s ext-community { add | remove | replace } <value>...", usage) } case "large-community": + stmt.Actions.LargeCommunity = &api.CommunityAction{} if len(args) < 1 { return fmt.Errorf("%s large-community { add | remove | replace } <value>...", usage) } - stmt.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityMethod.CommunitiesList = args[1:] + stmt.Actions.LargeCommunity.Communities = args[1:] switch strings.ToLower(args[0]) { case "add": - stmt.Actions.BgpActions.SetLargeCommunity.Options = config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD + stmt.Actions.LargeCommunity.Type = api.CommunityActionType_COMMUNITY_ADD case "remove": - stmt.Actions.BgpActions.SetLargeCommunity.Options = config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE + stmt.Actions.LargeCommunity.Type = api.CommunityActionType_COMMUNITY_REMOVE case "replace": - stmt.Actions.BgpActions.SetLargeCommunity.Options = config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE + stmt.Actions.LargeCommunity.Type = api.CommunityActionType_COMMUNITY_REPLACE default: return fmt.Errorf("%s large-community { add | remove | replace } <value>...", usage) } case "med": + stmt.Actions.Med = &api.MedAction{} if len(args) < 2 { return fmt.Errorf("%s med { add | sub | set } <value>", usage) } - med, err := strconv.ParseUint(args[1], 10, 32) + med, err := strconv.ParseInt(args[1], 10, 32) if err != nil { return err } + stmt.Actions.Med.Value = int64(med) switch strings.ToLower(args[0]) { case "add": - stmt.Actions.BgpActions.SetMed = config.BgpSetMedType(fmt.Sprintf("+%d", med)) + stmt.Actions.Med.Type = api.MedActionType_MED_MOD case "sub": - stmt.Actions.BgpActions.SetMed = config.BgpSetMedType(fmt.Sprintf("-%d", med)) + stmt.Actions.Med.Type = api.MedActionType_MED_MOD + stmt.Actions.Med.Value = -1 * stmt.Actions.Med.Value case "set": - stmt.Actions.BgpActions.SetMed = config.BgpSetMedType(fmt.Sprintf("%d", med)) + stmt.Actions.Med.Type = api.MedActionType_MED_REPLACE default: return fmt.Errorf("%s med { add | sub | set } <value>", usage) } case "local-pref": + stmt.Actions.LocalPref = &api.LocalPrefAction{} if len(args) < 1 { return fmt.Errorf("%s local-pref <value>", usage) } @@ -761,34 +789,34 @@ func modAction(name, op string, args []string) error { if err != nil { return err } - stmt.Actions.BgpActions.SetLocalPref = uint32(value) + stmt.Actions.LocalPref.Value = uint32(value) case "as-prepend": + stmt.Actions.AsPrepend = &api.AsPrependAction{} if len(args) < 2 { return fmt.Errorf("%s as-prepend { <asn> | last-as } <repeat-value>", usage) } - stmt.Actions.BgpActions.SetAsPathPrepend.As = args[0] + asn, _ := strconv.ParseUint(args[0], 10, 32) + stmt.Actions.AsPrepend.Asn = uint32(asn) repeat, err := strconv.ParseUint(args[1], 10, 8) if err != nil { return err } - stmt.Actions.BgpActions.SetAsPathPrepend.RepeatN = uint8(repeat) + stmt.Actions.AsPrepend.Repeat = uint32(repeat) case "next-hop": + stmt.Actions.Nexthop = &api.NexthopAction{} if len(args) != 1 { return fmt.Errorf("%s next-hop { <value> | self }", usage) } - stmt.Actions.BgpActions.SetNextHop = config.BgpNextHopType(args[0]) - } - t, err := table.NewStatement(stmt) - if err != nil { - return err + stmt.Actions.Nexthop.Address = args[0] } + var err error switch op { case CMD_ADD: - err = client.AddStatement(t) + err = client.AddStatement(stmt) case CMD_DEL: - err = client.DeleteStatement(t, false) + err = client.DeleteStatement(stmt, false) case CMD_SET: - err = client.ReplaceStatement(t) + err = client.ReplaceStatement(stmt) default: return fmt.Errorf("invalid operation: %s", op) } @@ -801,17 +829,16 @@ func modPolicy(modtype string, args []string) error { } name := args[0] args = args[1:] - stmts := make([]config.Statement, 0, len(args)) + stmts := make([]*api.Statement, 0, len(args)) for _, n := range args { - stmts = append(stmts, config.Statement{Name: n}) + stmts = append(stmts, &api.Statement{Name: n}) } - policy, err := table.NewPolicy(config.PolicyDefinition{ + policy := &api.Policy{ Name: name, Statements: stmts, - }) - if err != nil { - return err } + + var err error switch modtype { case CMD_ADD: err = client.AddPolicy(policy, true) |