From d1411bbec404a82cf5ccbc4632fba2c367c2b8de Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Sun, 18 Oct 2015 20:43:54 +0900 Subject: cli: kill unused code Signed-off-by: ISHIDA Wataru --- gobgp/cmd/neighbor.go | 11 ++- gobgp/cmd/policy.go | 235 -------------------------------------------------- 2 files changed, 7 insertions(+), 239 deletions(-) diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go index 3df9183d..44a31445 100644 --- a/gobgp/cmd/neighbor.go +++ b/gobgp/cmd/neighbor.go @@ -678,12 +678,15 @@ func modNeighborPolicy(remoteIP net.IP, policyType, cmdType string, eArg []strin if len(eArg) < 3 { return fmt.Errorf("Usage: gobgp neighbor policy %s %s [...] [default {%s|%s}]", policyType, cmdType, "accept", "reject") } - defaultPolicy, err := parseRouteAction(eArg[1]) - if err != nil { - return err + switch eArg[1] { + case "accept": + p.Default = api.RouteAction_ACCEPT + case "reject": + p.Default = api.RouteAction_REJECT + default: + return fmt.Errorf("Usage: gobgp neighbor policy %s %s [...] [default {%s|%s}]", policyType, cmdType, "accept", "reject") } p.Policies = []string{eArg[0]} - p.Default = defaultPolicy operation = api.Operation_ADD case CMD_DEL: operation = api.Operation_DEL diff --git a/gobgp/cmd/policy.go b/gobgp/cmd/policy.go index 589ecac0..fd429c2a 100644 --- a/gobgp/cmd/policy.go +++ b/gobgp/cmd/policy.go @@ -520,241 +520,6 @@ func showPolicy(args []string) error { return nil } -func parseConditions() (*api.Conditions, error) { - checkFormat := func(option string, isRestricted bool) (int32, string, error) { - regStr, _ := regexp.Compile("^(.*)\\[(.*)\\]$") - isMatched := regStr.MatchString(option) - var op int32 - var name string - if !isMatched { - return op, name, fmt.Errorf("Please enter the [condition name]") - } - group := regStr.FindStringSubmatch(option) - switch strings.ToLower(group[1]) { - case "any": - op = int32(table.MATCH_OPTION_ANY) - case "invert": - op = int32(table.MATCH_OPTION_INVERT) - case "all": - if isRestricted { - return op, name, fmt.Errorf("can't use 'all' for the condition option") - } - op = int32(table.MATCH_OPTION_ALL) - default: - return op, name, fmt.Errorf("unknown condition option") - } - name = group[2] - return op, name, nil - } - - conditions := &api.Conditions{} - if conditionOpts.Prefix != "" { - op, name, err := checkFormat(conditionOpts.Prefix, true) - if err != nil { - return nil, fmt.Errorf("invalid prefix option format\n%s", err) - } - conditions.PrefixSet = &api.MatchSet{ - Name: name, - Option: op, - } - } - if conditionOpts.Neighbor != "" { - op, name, err := checkFormat(conditionOpts.Neighbor, true) - if err != nil { - return nil, fmt.Errorf("invalid neighbor option format\n%s", err) - } - conditions.NeighborSet = &api.MatchSet{ - Name: name, - Option: op, - } - } - if conditionOpts.AsPath != "" { - op, name, err := checkFormat(conditionOpts.AsPath, false) - if err != nil { - return nil, fmt.Errorf("invalid aspath option format\n%s", err) - } - conditions.AsPathSet = &api.MatchSet{ - Name: name, - Option: op, - } - } - if conditionOpts.Community != "" { - op, name, err := checkFormat(conditionOpts.Community, false) - if err != nil { - return nil, fmt.Errorf("invalid community option format\n%s", err) - } - conditions.CommunitySet = &api.MatchSet{ - Name: name, - Option: op, - } - } - if conditionOpts.ExtCommunity != "" { - op, name, err := checkFormat(conditionOpts.ExtCommunity, false) - if err != nil { - return nil, fmt.Errorf("invalid extended community option format\n%s", err) - } - conditions.ExtCommunitySet = &api.MatchSet{ - Name: name, - Option: op, - } - } - if conditionOpts.AsPathLength != "" { - asPathLen := conditionOpts.AsPathLength - elems := strings.Split(asPathLen, ",") - if len(elems) != 2 { - return nil, fmt.Errorf("invalid as path length: %s\nPlease enter the ,", asPathLen) - } - var typ int32 - switch strings.ToLower(elems[0]) { - case "eq": - typ = int32(table.ATTRIBUTE_EQ) - case "ge": - typ = int32(table.ATTRIBUTE_GE) - case "le": - typ = int32(table.ATTRIBUTE_LE) - default: - return nil, fmt.Errorf("invalid aspath length action type") - - } - length, err := strconv.Atoi(elems[1]) - if err != nil { - return nil, fmt.Errorf("invalid as path length: %s\nPlease enter a numeric", elems[1]) - } - conditions.AsPathLength = &api.AsPathLength{ - Type: typ, - Length: uint32(length), - } - } - return conditions, nil -} - -func parseRouteAction(rType string) (api.RouteAction, error) { - routeActionUpper := strings.ToUpper(rType) - switch routeActionUpper { - case "ACCEPT": - return api.RouteAction_ACCEPT, nil - case "REJECT": - return api.RouteAction_REJECT, nil - default: - return api.RouteAction_NONE, fmt.Errorf("invalid route action: %s\nPlease enter the accept or reject", rType) - } -} - -func parseCommunityAction(communityStr string) (*api.CommunityAction, error) { - exp := regexp.MustCompile("^(.*)\\[(.*)\\]$") - elems := exp.FindStringSubmatch(communityStr) - if len(elems) != 3 { - e := fmt.Sprintf("invalid format: %s\n", communityStr) - e += "please enter the