diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-08 01:40:36 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-08 01:46:11 +0900 |
commit | eb08d749cd4e2e624bfa222912a4b1d9d8546689 (patch) | |
tree | e987feed2a803473f70e832ff6fdc968d6b18374 | |
parent | 64d2821d8bc27494dab0bf36418cb60ba9814e9c (diff) |
cli: enable to flag match/not for tcp-flag when adding flowspec path
$ gobgp global rib -a ipv4-flowspec add match tcp-flags not match rst then accept
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | gobgp/cmd/global.go | 2 | ||||
-rw-r--r-- | packet/bgp.go | 13 |
2 files changed, 11 insertions, 4 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index 08dc2249..bfc18adb 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -530,7 +530,7 @@ func modPath(resource api.Resource, name, modtype string, args []string) error { fsHelpMsgFmt := fmt.Sprintf(`err: %s usage: %s rib %s match <MATCH_EXPR> then <THEN_EXPR> -a %%s <MATCH_EXPR> : { %s <PREFIX> [<OFFSET>] | %s <PREFIX> [<OFFSET>] | - %s <PROTO>... | %s <FRAGMENT_TYPE> | %s <TCPFLAG>... | + %s <PROTO>... | %s <FRAGMENT_TYPE> | %s [not] [match] <TCPFLAG>... | { %s | %s | %s | %s | %s | %s | %s | %s } <ITEM>... }... <PROTO> : %s <FRAGMENT_TYPE> : not-a-fragment, is-a-fragment, first-fragment, last-fragment diff --git a/packet/bgp.go b/packet/bgp.go index 86fde0a2..022dcbd5 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -2107,18 +2107,25 @@ func flowSpecTcpFlagParser(rf RouteFamily, args []string) (FlowSpecComponentInte ss = append(ss, v) } protos := strings.Join(ss, "|") - exp := regexp.MustCompile(fmt.Sprintf("^%s ((((%s)\\&)*(%s) )*(((%s)\\&)*(%s)))$", FlowSpecNameMap[FLOW_SPEC_TYPE_TCP_FLAG], protos, protos, protos, protos)) + exp := regexp.MustCompile(fmt.Sprintf("^%s (not )?(match )?((((%s)\\&)*(%s) )*(((%s)\\&)*(%s)))$", FlowSpecNameMap[FLOW_SPEC_TYPE_TCP_FLAG], protos, protos, protos, protos)) elems := exp.FindStringSubmatch(strings.Join(args, " ")) if len(elems) < 1 { return nil, fmt.Errorf("invalid flag format") } items := make([]*FlowSpecComponentItem, 0) - for _, v := range strings.Split(elems[1], " ") { + op := 0 + if elems[2] != "" { + op |= 0x1 + } + if elems[1] != "" { + op |= 0x2 + } + for _, v := range strings.Split(elems[3], " ") { flag := 0 for _, e := range strings.Split(v, "&") { flag |= int(TCPFlagValueMap[e]) } - items = append(items, NewFlowSpecComponentItem(0, flag)) + items = append(items, NewFlowSpecComponentItem(op, flag)) } return NewFlowSpecComponent(FLOW_SPEC_TYPE_TCP_FLAG, items), nil } |