diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-18 20:43:54 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-20 10:33:10 +0900 |
commit | d1411bbec404a82cf5ccbc4632fba2c367c2b8de (patch) | |
tree | 395b736ad7082ace06997df093d78ae090a3258a | |
parent | 95188d08e1f53b8393659a7fe8c0cb57799ce1d9 (diff) |
cli: kill unused code
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | gobgp/cmd/neighbor.go | 11 | ||||
-rw-r--r-- | 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 <ipaddr> policy %s %s [<policy name>...] [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 <ipaddr> policy %s %s [<policy name>...] [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 <match option>[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 <value>,<operator>", 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 <option>[<comunity>,<comunity>,...]" - return nil, fmt.Errorf("%s", e) - } - - var op int32 - switch strings.ToLower(elems[1]) { - case "add": - op = int32(config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD) - case "remove": - op = int32(config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE) - case "replace": - op = int32(config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE) - default: - return nil, fmt.Errorf("invalid community action option") - } - return &api.CommunityAction{ - Communities: strings.Split(elems[2], ","), - Option: op, - }, nil -} - -func parseAsPrependAction(communityStr string) (*api.AsPrependAction, error) { - exp := regexp.MustCompile("^([0-9]+|last-as),([0-9]+)$") - elems := exp.FindStringSubmatch(communityStr) - if len(elems) != 3 { - return nil, fmt.Errorf("invalid asprepend action format") - } - asn, err := strconv.Atoi(elems[1]) - var lastAs bool - if err != nil { - lastAs = true - } - repeat, err := strconv.Atoi(elems[2]) - if err != nil { - return nil, fmt.Errorf("%s", "invalid repeat count") - } - return &api.AsPrependAction{ - Asn: uint32(asn), - Repeat: uint32(repeat), - UseLeftMost: lastAs, - }, nil -} - -func parseMedAction(arg string) (*api.MedAction, error) { - exp := regexp.MustCompile("^(\\+|\\-)?([0-9]+)$") - elems := exp.FindStringSubmatch(arg) - if len(elems) != 3 { - return nil, fmt.Errorf("invalid med action format") - } - typ := int32(table.MED_ACTION_MOD) - if elems[1] == "" { - typ = int32(table.MED_ACTION_REPLACE) - } - value, _ := strconv.Atoi(elems[2]) - return &api.MedAction{ - Type: typ, - Value: int64(value), - }, nil -} - -func checkAsPrependAction(asStr string) error { - regPrepend, _ := regexp.Compile("^([0-9]+|last-as),([0-9]+)$") - if !regPrepend.MatchString(asStr) { - e := fmt.Sprintf("invalid format: %s\n", asStr) - e += "please enter as <AS>,<repeat count>" - return fmt.Errorf("%s", e) - } - return nil -} - -func parseActions() (*api.Actions, error) { - actions := &api.Actions{} - if actionOpts.RouteAction != "" { - routeAction, e := parseRouteAction(actionOpts.RouteAction) - if e != nil { - return nil, e - } - actions.RouteAction = routeAction - } - if actionOpts.CommunityAction != "" { - community, e := parseCommunityAction(actionOpts.CommunityAction) - if e != nil { - return nil, e - } - actions.Community = community - } - if actionOpts.MedAction != "" { - med, e := parseMedAction(actionOpts.MedAction) - if e != nil { - return nil, e - } - actions.Med = med - } - if actionOpts.AsPathPrependAction != "" { - - s := actionOpts.AsPathPrependAction - e := checkAsPrependAction(s) - if e != nil { - return nil, e - } - - p, e := parseAsPrependAction(s) - if e != nil { - return nil, e - } - actions.AsPrepend = p - } - return actions, nil -} - func showStatement(args []string) error { m := []*api.Statement{} if len(args) > 0 { |