From d0b26ae700e8c0d424f666b44c473d1ee52a96a2 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Wed, 7 Oct 2015 00:05:13 +0900 Subject: packet: support cisco-ish flowspec tcp-flag serializing // same as juniper matching ack+syn $ gobgp global rib -a ipv4-flowspec match tcp-flags ack syn then discard // [NEW] same as cisco matching ack+syn $ gobgp global rib -a ipv4-flowspec match tcp-flags 'ack&syn' then discard Signed-off-by: ISHIDA Wataru --- packet/bgp.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'packet/bgp.go') diff --git a/packet/bgp.go b/packet/bgp.go index 3dd18be3..aeab46f8 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -2107,19 +2107,19 @@ func flowSpecTcpFlagParser(rf RouteFamily, args []string) (FlowSpecComponentInte ss = append(ss, v) } protos := strings.Join(ss, "|") - exp := regexp.MustCompile(fmt.Sprintf("^%s (((%s) )*)(%s)$", FlowSpecNameMap[FLOW_SPEC_TYPE_TCP_FLAG], protos, protos)) + exp := regexp.MustCompile(fmt.Sprintf("^%s ((((%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) - if elems[1] != "" { - for _, v := range strings.Split(elems[1], " ") { - p, ok := TCPFlagValueMap[v] - if !ok { - continue - } - items = append(items, NewFlowSpecComponentItem(0, int(p))) + for _, v := range strings.Split(elems[1], " ") { + flag := 0 + for _, e := range strings.Split(v, "&") { + flag |= int(TCPFlagValueMap[e]) } + items = append(items, NewFlowSpecComponentItem(0, flag)) } - items = append(items, NewFlowSpecComponentItem(0, int(TCPFlagValueMap[elems[4]]))) return NewFlowSpecComponent(FLOW_SPEC_TYPE_TCP_FLAG, items), nil } -- cgit v1.2.3