summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-08-16 18:09:07 +0000
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-08-16 18:09:07 +0000
commitf52f3245c5d09d7a8e86c3654d1ceed23fc0de36 (patch)
tree44dd975bc6040bddc16602602eacfeb15141f3bd /packet/bgp
parent0a9375a40e84a1bb83aafdaf8a164bdf29f1513f (diff)
cli: support setting flowspec "procotol" in octet
$ gobgp global rib -a ipv4-flowspec add match protocol 100 then discard close #1052 Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp')
-rw-r--r--packet/bgp/bgp.go28
1 files changed, 13 insertions, 15 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index b74aa838..cd767937 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -2218,28 +2218,26 @@ func flowSpecPrefixParser(rf RouteFamily, args []string) (FlowSpecComponentInter
}
func flowSpecIpProtoParser(rf RouteFamily, args []string) (FlowSpecComponentInterface, error) {
- ss := make([]string, 0, len(ProtocolNameMap))
- for _, v := range ProtocolNameMap {
- ss = append(ss, v)
- }
- protos := strings.Join(ss, "|")
- exp := regexp.MustCompile(fmt.Sprintf("^%s (((%s) )*)(%s)$", FlowSpecNameMap[FLOW_SPEC_TYPE_IP_PROTO], protos, protos))
- elems := exp.FindStringSubmatch(strings.Join(args, " "))
- if len(elems) < 2 {
+ if len(args) < 2 || args[0] != FlowSpecNameMap[FLOW_SPEC_TYPE_IP_PROTO] {
return nil, fmt.Errorf("invalid ip-proto format")
}
items := make([]*FlowSpecComponentItem, 0)
eq := 0x1
- if elems[1] != "" {
- for _, v := range strings.Split(elems[1], " ") {
- p, ok := ProtocolValueMap[v]
- if !ok {
- continue
- }
+ for _, v := range args[1:] {
+ if v == "" {
+ continue
+ }
+ p, ok := ProtocolValueMap[v]
+ if ok {
items = append(items, NewFlowSpecComponentItem(eq, int(p)))
+ continue
+ }
+ i, err := strconv.ParseUint(v, 10, 8)
+ if err != nil {
+ return nil, fmt.Errorf("invalid ip-proto format: failed to parse %s", v)
}
+ items = append(items, NewFlowSpecComponentItem(eq, int(i)))
}
- items = append(items, NewFlowSpecComponentItem(eq, int(ProtocolValueMap[elems[4]])))
return NewFlowSpecComponent(FLOW_SPEC_TYPE_IP_PROTO, items), nil
}