summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp/constant.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-18 23:37:01 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-24 12:55:34 +0900
commit68d2478e2ea1d8607f85e6ab3d4a792e054ce6c2 (patch)
tree3c04819270fdccc355b1094463fb9db23fd47e53 /packet/bgp/constant.go
parent35c79d833feafb7fa12afa90e984e6f1f474675e (diff)
packet/bgp: Use regexp to parse FlowSpec rules
Currently, the parser for the string representation of FlowSpec rules splits the given string into characters and validates them character by character. So we need to handle the unexpected white spaces carefully. This patch introduces the regular expressions to parse the FlowSpec rules and simplify the parsers. Also improves robustness for the unexpectedly inserted white spaces like "& == tcp". Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet/bgp/constant.go')
-rw-r--r--packet/bgp/constant.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/packet/bgp/constant.go b/packet/bgp/constant.go
index f743e331..d4120471 100644
--- a/packet/bgp/constant.go
+++ b/packet/bgp/constant.go
@@ -145,6 +145,21 @@ var BitmaskFlagOpNameMap = map[BitmaskFlagOp]string{
BITMASK_FLAG_OP_MATCH: "=",
}
+// Note: Meaning of "" is different from that of the numeric operator because
+// RFC5575 says if the Match bit in the bitmask operand is set, it should be
+// "strictly" matching against the given value.
+var BitmaskFlagOpValueMap = map[string]BitmaskFlagOp{
+ " ": BITMASK_FLAG_OP_OR,
+ "": BITMASK_FLAG_OP_OR,
+ "==": BITMASK_FLAG_OP_MATCH,
+ "=": BITMASK_FLAG_OP_MATCH,
+ "!": BITMASK_FLAG_OP_NOT,
+ "!=": BITMASK_FLAG_OP_NOT_MATCH,
+ "=!": BITMASK_FLAG_OP_NOT_MATCH, // For the backward compatibility
+ "&": BITMASK_FLAG_OP_AND,
+ "E": BITMASK_FLAG_OP_END,
+}
+
func (f BitmaskFlagOp) String() string {
ops := make([]string, 0)
if f&BITMASK_FLAG_OP_AND > 0 {
@@ -230,6 +245,24 @@ var DECNumOpNameMap = map[DECNumOp]string{
DEC_NUM_OP_END: "E",
}
+var DECNumOpValueMap = map[string]DECNumOp{
+ "true": DEC_NUM_OP_TRUE,
+ "": DEC_NUM_OP_EQ,
+ "==": DEC_NUM_OP_EQ,
+ "=": DEC_NUM_OP_EQ,
+ ">": DEC_NUM_OP_GT,
+ ">=": DEC_NUM_OP_GT_EQ,
+ "<": DEC_NUM_OP_LT,
+ "<=": DEC_NUM_OP_LT_EQ,
+ "!=": DEC_NUM_OP_NOT_EQ,
+ "=!": DEC_NUM_OP_NOT_EQ,
+ "!": DEC_NUM_OP_NOT_EQ,
+ "false": DEC_NUM_OP_FALSE,
+ " ": DEC_NUM_OP_OR,
+ "&": DEC_NUM_OP_AND,
+ "E": DEC_NUM_OP_END,
+}
+
func (f DECNumOp) String() string {
ops := make([]string, 0)
logicFlag := DECNumOp(f & 0xc0) // higher 2 bits