diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-07 00:05:13 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-08 01:25:40 +0900 |
commit | d0b26ae700e8c0d424f666b44c473d1ee52a96a2 (patch) | |
tree | c87a2e80f0c0714c3f562ebf3229073b811b68b2 | |
parent | bf98af5a968491059c01729d613098133eb32788 (diff) |
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 <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | packet/bgp.go | 18 | ||||
-rw-r--r-- | packet/constant.go | 6 |
2 files changed, 12 insertions, 12 deletions
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 } diff --git a/packet/constant.go b/packet/constant.go index c8de8007..65101dc1 100644 --- a/packet/constant.go +++ b/packet/constant.go @@ -125,9 +125,9 @@ var TCPFlagValueMap = map[string]TCPFlag{ func (f TCPFlag) String() string { ss := make([]string, 0, 6) - for k, v := range TCPFlagNameMap { - if f&k > 0 { - ss = append(ss, v) + for _, v := range []TCPFlag{TCP_FLAG_FIN, TCP_FLAG_SYN, TCP_FLAG_RST, TCP_FLAG_PUSH, TCP_FLAG_ACK, TCP_FLAG_URGENT} { + if f&v > 0 { + ss = append(ss, TCPFlagNameMap[v]) } } return strings.Join(ss, "|") |