diff options
-rw-r--r-- | docs/sources/cli-command-syntax.md | 16 | ||||
-rw-r--r-- | gobgp/policy.go | 22 |
2 files changed, 30 insertions, 8 deletions
diff --git a/docs/sources/cli-command-syntax.md b/docs/sources/cli-command-syntax.md index a1ade65f..cd565b74 100644 --- a/docs/sources/cli-command-syntax.md +++ b/docs/sources/cli-command-syntax.md @@ -208,11 +208,17 @@ If you want to add the AsPathSet: ```shell % gobgp policy aspath add ass1 ^65100 ``` - You can specify the position using regexp-like expression as follows: - - From: "^65100" means the route is passed from AS 65100 directly. - - Any: "65100" means the route comes through AS 65100. - - Origin: "65100$" means the route is originated by AS 65100. - - Only: "^65100$" means the route is originated by AS 65100 and comes from it directly. + +You can specify the position using regexp-like expression as follows: +- From: "^65100" means the route is passed from AS 65100 directly. +- Any: "65100" means the route comes through AS 65100. +- Origin: "65100$" means the route is originated by AS 65100. +- Only: "^65100$" means the route is originated by AS 65100 and comes from it directly. + +Further you can specify the consecutive aspath and use regexp in each element as follows: +- ^65100_65001 +- 65100_[0-9]+_.*$ +- ^6[0-9]_5.*_65.?00$ An AsPathSet it is possible to have multiple as path, if you want to remove the AsPathSet to specify only AsPathSet name. ```shell diff --git a/gobgp/policy.go b/gobgp/policy.go index 07c73ef1..3bcc7d34 100644 --- a/gobgp/policy.go +++ b/gobgp/policy.go @@ -552,9 +552,25 @@ func showPolicyAsPath(args []string) error { } func parseAsPathSet(eArgs []string) (*api.AsPathSet, error) { - regAsn, _ := regexp.Compile("^(\\^?)([0-9]+)(\\$?)$") - if !regAsn.MatchString(eArgs[1]) { - return nil, fmt.Errorf("invalid aspath: %s\nplease enter aspath format", eArgs[1]) + as := eArgs[1] + isTop := as[:1] == "^" + if isTop { + as = as[1:] + } + isEnd := as[len(as)-1:] == "$" + if isEnd { + as = as[:len(as)-1] + } + elems := strings.Split(as, "_") + for _, el := range elems { + if len(el) == 0 { + return nil, fmt.Errorf("invalid aspath element: %s \ndo not enter a blank", eArgs[1]) + } + _, err := regexp.Compile(el) + if err != nil { + return nil, fmt.Errorf("invalid aspath element: %s \n"+ + "can not comple aspath values to regular expressions.", eArgs[1]) + } } asPathSet := &api.AsPathSet{ AsPathSetName: eArgs[0], |