diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-06-19 16:25:20 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-07-10 15:39:14 +0900 |
commit | 15cd58e01f47357be5280ef6aa0775f42b811854 (patch) | |
tree | e18aecb1b9f23e9cc906a8084b3d8e235880a594 /packet/bgp | |
parent | cbabf5aa1cddff4754adec4d5e78a4aa3391c46a (diff) |
const: Rename TcpFlagOp to BitmaskFlagOp
This flag format is not only used for "tcp-flag" field,
but also "fragment" field.
To express the above, this patch renames the format.
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'packet/bgp')
-rw-r--r-- | packet/bgp/bgp.go | 30 | ||||
-rw-r--r-- | packet/bgp/constant.go | 36 |
2 files changed, 33 insertions, 33 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 7ccebf88..dd924624 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -2827,24 +2827,24 @@ func parseTcpFlagCmd(myCmd string) ([][2]int, error) { for index < len(myCmd) { myCmdChar := myCmd[index : index+1] switch myCmdChar { - case TCPFlagOpNameMap[TCP_FLAG_OP_MATCH]: - if bit := TCPFlagOpValueMap[myCmdChar]; bit&TCPFlagOp(operatorValue[0]) == 0 { + case BitmaskFlagOpNameMap[BITMASK_FLAG_OP_MATCH]: + if bit := BitmaskFlagOpValueMap[myCmdChar]; bit&BitmaskFlagOp(operatorValue[0]) == 0 { operatorValue[0] |= int(bit) index++ } else { err := fmt.Errorf("Match flag appears multiple time") return nil, err } - case TCPFlagOpNameMap[TCP_FLAG_OP_NOT]: - if bit := TCPFlagOpValueMap[myCmdChar]; bit&TCPFlagOp(operatorValue[0]) == 0 { + case BitmaskFlagOpNameMap[BITMASK_FLAG_OP_NOT]: + if bit := BitmaskFlagOpValueMap[myCmdChar]; bit&BitmaskFlagOp(operatorValue[0]) == 0 { operatorValue[0] |= int(bit) index++ } else { err := fmt.Errorf("Not flag appears multiple time") return nil, err } - case TCPFlagOpNameMap[TCP_FLAG_OP_AND], TCPFlagOpNameMap[TCP_FLAG_OP_OR]: - if bit := TCPFlagOpValueMap[myCmdChar]; bit&TCPFlagOp(operatorValue[0]) == 0 { + case BitmaskFlagOpNameMap[BITMASK_FLAG_OP_AND], BitmaskFlagOpNameMap[BITMASK_FLAG_OP_OR]: + if bit := BitmaskFlagOpValueMap[myCmdChar]; bit&BitmaskFlagOp(operatorValue[0]) == 0 { tcpOperatorsFlagsValues = append(tcpOperatorsFlagsValues, operatorValue) operatorValue[0] = int(bit) operatorValue[1] = 0 @@ -2861,7 +2861,7 @@ func parseTcpFlagCmd(myCmd string) ([][2]int, error) { // we loop till we reach the end of TCP flags description // exit conditions : we reach the end of tcp flags (we find & or ' ') or we reach the end of the line for loopIndex < len(myCmd) && - (myLoopChar != TCPFlagOpNameMap[TCP_FLAG_OP_AND] && myLoopChar != TCPFlagOpNameMap[TCP_FLAG_OP_OR]) { + (myLoopChar != BitmaskFlagOpNameMap[BITMASK_FLAG_OP_AND] && myLoopChar != BitmaskFlagOpNameMap[BITMASK_FLAG_OP_OR]) { // we check if inspected charater is a well known tcp flag and if it doesn't appear twice if bit, isPresent := TCPFlagValueMap[myLoopChar]; isPresent && (bit&TCPFlag(operatorValue[1]) == 0) { operatorValue[1] |= int(bit) // we set this flag @@ -2881,7 +2881,7 @@ func parseTcpFlagCmd(myCmd string) ([][2]int, error) { return nil, err } } - operatorValue[0] |= int(TCPFlagOpValueMap["E"]) + operatorValue[0] |= int(BitmaskFlagOpValueMap["E"]) tcpOperatorsFlagsValues = append(tcpOperatorsFlagsValues, operatorValue) return tcpOperatorsFlagsValues, nil } @@ -3530,21 +3530,21 @@ func formatProto(op int, value int) string { func formatFlag(op int, value int) string { var retString string - if op&TCP_FLAG_OP_MATCH > 0 { - retString = fmt.Sprintf("%s%s", retString, TCPFlagOpNameMap[TCP_FLAG_OP_MATCH]) + if op&BITMASK_FLAG_OP_MATCH > 0 { + retString = fmt.Sprintf("%s%s", retString, BitmaskFlagOpNameMap[BITMASK_FLAG_OP_MATCH]) } - if op&TCP_FLAG_OP_NOT > 0 { - retString = fmt.Sprintf("%s%s", retString, TCPFlagOpNameMap[TCP_FLAG_OP_NOT]) + if op&BITMASK_FLAG_OP_NOT > 0 { + retString = fmt.Sprintf("%s%s", retString, BitmaskFlagOpNameMap[BITMASK_FLAG_OP_NOT]) } for flag, valueFlag := range TCPFlagValueMap { if value&int(valueFlag) > 0 { retString = fmt.Sprintf("%s%s", retString, flag) } } - if op&TCP_FLAG_OP_AND > 0 { - retString = fmt.Sprintf("%s%s", TCPFlagOpNameMap[TCP_FLAG_OP_AND], retString) + if op&BITMASK_FLAG_OP_AND > 0 { + retString = fmt.Sprintf("%s%s", BitmaskFlagOpNameMap[BITMASK_FLAG_OP_AND], retString) } else { // default is or - retString = fmt.Sprintf("%s%s", TCPFlagOpNameMap[TCP_FLAG_OP_OR], retString) + retString = fmt.Sprintf("%s%s", BitmaskFlagOpNameMap[BITMASK_FLAG_OP_OR], retString) } return retString } diff --git a/packet/bgp/constant.go b/packet/bgp/constant.go index faa156e1..2cee1f31 100644 --- a/packet/bgp/constant.go +++ b/packet/bgp/constant.go @@ -128,30 +128,30 @@ var TCPFlagValueMap = map[string]TCPFlag{ TCPFlagNameMap[TCP_FLAG_ECE]: TCP_FLAG_ECE, } -type TCPFlagOp int +type BitmaskFlagOp int const ( - TCP_FLAG_OP_OR = 0x00 - TCP_FLAG_OP_AND = 0x40 - TCP_FLAG_OP_END = 0x80 - TCP_FLAG_OP_NOT = 0x02 - TCP_FLAG_OP_MATCH = 0x01 + BITMASK_FLAG_OP_OR = 0x00 + BITMASK_FLAG_OP_AND = 0x40 + BITMASK_FLAG_OP_END = 0x80 + BITMASK_FLAG_OP_NOT = 0x02 + BITMASK_FLAG_OP_MATCH = 0x01 ) -var TCPFlagOpNameMap = map[TCPFlagOp]string{ - TCP_FLAG_OP_OR: " ", - TCP_FLAG_OP_AND: "&", - TCP_FLAG_OP_END: "E", - TCP_FLAG_OP_NOT: "!", - TCP_FLAG_OP_MATCH: "=", +var BitmaskFlagOpNameMap = map[BitmaskFlagOp]string{ + BITMASK_FLAG_OP_OR: " ", + BITMASK_FLAG_OP_AND: "&", + BITMASK_FLAG_OP_END: "E", + BITMASK_FLAG_OP_NOT: "!", + BITMASK_FLAG_OP_MATCH: "=", } -var TCPFlagOpValueMap = map[string]TCPFlagOp{ - TCPFlagOpNameMap[TCP_FLAG_OP_OR]: TCP_FLAG_OP_OR, - TCPFlagOpNameMap[TCP_FLAG_OP_AND]: TCP_FLAG_OP_AND, - TCPFlagOpNameMap[TCP_FLAG_OP_END]: TCP_FLAG_OP_END, - TCPFlagOpNameMap[TCP_FLAG_OP_NOT]: TCP_FLAG_OP_NOT, - TCPFlagOpNameMap[TCP_FLAG_OP_MATCH]: TCP_FLAG_OP_MATCH, +var BitmaskFlagOpValueMap = map[string]BitmaskFlagOp{ + BitmaskFlagOpNameMap[BITMASK_FLAG_OP_OR]: BITMASK_FLAG_OP_OR, + BitmaskFlagOpNameMap[BITMASK_FLAG_OP_AND]: BITMASK_FLAG_OP_AND, + BitmaskFlagOpNameMap[BITMASK_FLAG_OP_END]: BITMASK_FLAG_OP_END, + BitmaskFlagOpNameMap[BITMASK_FLAG_OP_NOT]: BITMASK_FLAG_OP_NOT, + BitmaskFlagOpNameMap[BITMASK_FLAG_OP_MATCH]: BITMASK_FLAG_OP_MATCH, } type DECNumOp int |