summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-11 07:24:08 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-12 08:04:31 +0900
commit819e87cd53657e3b2e44389928455f51639faddf (patch)
treea0fc0d79207edc250d4db4508c3c0f6cda1c6245
parent565f7b95b6464e230b37ace34e4748fecfd4d28b (diff)
packet: fix flowspec parser to parse >= and <=
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--packet/bgp.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index 5f1723ba..3c477ae4 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -1859,7 +1859,7 @@ func flowSpecTcpFlagParser(args []string) (FlowSpecComponentInterface, error) {
}
func flowSpecNumericParser(args []string) (FlowSpecComponentInterface, error) {
- exp := regexp.MustCompile("^(([<>=])(\\d+)&)?([<>=])(\\d+)$")
+ exp := regexp.MustCompile("^((<=|>=|[<>=])(\\d+)&)?(<=|>=|[<>=])(\\d+)$")
items := make([]*FlowSpecComponentItem, 0)
f := func(and bool, o, v string) *FlowSpecComponentItem {
@@ -1867,13 +1867,15 @@ func flowSpecNumericParser(args []string) (FlowSpecComponentInterface, error) {
if and {
op |= 0x40
}
- switch o {
- case ">":
- op |= 0x2
- case "<":
- op |= 0x4
- case "=":
- op |= 0x1
+ for _, oo := range o {
+ switch oo {
+ case '>':
+ op |= 0x2
+ case '<':
+ op |= 0x4
+ case '=':
+ op |= 0x1
+ }
}
value, err := strconv.Atoi(v)
if err != nil {
@@ -1945,6 +1947,9 @@ func ParseFlowSpecComponents(input string) ([]FlowSpecComponentInterface, error)
}{t, idx})
}
}
+ if len(idxs) == 0 {
+ return nil, fmt.Errorf("failed to parse: %s", input)
+ }
cmps := make([]FlowSpecComponentInterface, 0, len(idxs))
for i, idx := range idxs {
var a []string