summaryrefslogtreecommitdiffhomepage
path: root/api/grpc_server.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/grpc_server.go')
-rw-r--r--api/grpc_server.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index 161bc826..5b10b055 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -1606,17 +1606,24 @@ func toStatementApi(s *config.Statement) *Statement {
Communities: s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList}
}(),
Med: func() *MedAction {
- if len(string(s.Actions.BgpActions.SetMed)) == 0 {
+ medStr := strings.TrimSpace(string(s.Actions.BgpActions.SetMed))
+ if len(medStr) == 0 {
+ return nil
+ }
+ re := regexp.MustCompile("([+-]?)(\\d+)")
+ matches := re.FindStringSubmatch(medStr)
+ if len(matches) == 0 {
return nil
}
- exp := regexp.MustCompile("^(\\+|\\-)?(\\d+)$")
- elems := exp.FindStringSubmatch(string(s.Actions.BgpActions.SetMed))
action := MedActionType_MED_REPLACE
- switch elems[1] {
+ switch matches[1] {
case "+", "-":
action = MedActionType_MED_MOD
}
- value, _ := strconv.Atoi(string(s.Actions.BgpActions.SetMed))
+ value, err := strconv.Atoi(matches[1] + matches[2])
+ if err != nil {
+ return nil
+ }
return &MedAction{
Value: int64(value),
Type: action,